COPASI API  4.16.103
SensitivitiesWidget.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2014 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2005 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #include <QtGui/QImage>
16 #include <QtGui/QFrame>
17 #include <QtCore/QtDebug>
18 
19 #include <algorithm>
20 
21 #include "SensitivitiesWidget.h"
22 #include "DataModelGUI.h"
23 #include "qtUtilities.h"
24 #include "CQTaskBtnWidget.h"
25 #include "CQTaskHeaderWidget.h"
26 #include "CQTaskMethodWidget.h"
27 #include "CCopasiSelectionDialog.h"
29 
35 #include "model/CModel.h"
37 #include "report/CKeyFactory.h"
38 #include "CQSensResultWidget.h"
39 
40 /**
41  * Constructs a SensitivitiesWidget which is a child of 'parent', with the
42  * name 'name' and widget flags set to 'f'.
43  */
44 SensitivitiesWidget::SensitivitiesWidget(QWidget* parent, const char* name, Qt::WFlags fl)
45  : TaskWidget(parent, name, fl),
46  mpSingleFunction(NULL),
47  mpSingleVariable(NULL),
48  mpSingleVariable2(NULL)
49 {
50  setupUi(this);
51 
52  init();
53  retranslateUi(this);
54 }
55 
56 /*
57  * Destroys the object and frees any allocated resources
58  */
60 {}
61 
63 {
64  mpHeaderWidget->setTaskName("Sensitivities");
65 
66  verticalLayout->insertWidget(0, mpHeaderWidget); // header
67  // verticalLayout->insertSpacing(1, 14); // space between header and body
68 
70  verticalLayout->addWidget(mpMethodWidget);
71 
72  verticalLayout->addWidget(mpBtnWidget); // 'footer'
73 
74  // icons
75  SingleFunctionChooser->setIcon(CQIconResource::icon(CQIconResource::copasi));
76  SingleVariableChooser->setIcon(CQIconResource::icon(CQIconResource::copasi));
77  SingleVariable2Chooser->setIcon(CQIconResource::icon(CQIconResource::copasi));
78 
79  // initialization
80  initCombos();
81 }
82 
84 {
85  saveCommon();
86  saveMethod();
87 
88  CSensTask* sensTask =
90 
91  if (sensTask == NULL)
92  return false;
93 
94  CSensProblem* problem =
95  dynamic_cast<CSensProblem *>(sensTask->getProblem());
96 
97  if (problem == NULL)
98  return false;
99 
100  CSensMethod* method =
101  dynamic_cast<CSensMethod *>(sensTask->getMethod());
102 
103  if (method == NULL)
104  return false;
105 
106  // subtask
107  problem->setSubTaskType((CSensProblem::SubTaskType)SubTaskChooser->currentIndex());
108 
109  CSensItem tmp;
110 
111  // target function
112  if (FunctionChooser->getCurrentObjectList() == CObjectLists::SINGLE_OBJECT)
113  {
114  if (mpSingleFunction)
116  }
117  else
118  tmp.setListType(FunctionChooser->getCurrentObjectList());
119 
120  problem->changeTargetFunctions(tmp);
121 
122  // variables 1
123  if (VariableChooser->getCurrentObjectList() == CObjectLists::SINGLE_OBJECT)
124  {
125  if (mpSingleVariable)
127  }
128  else
129  tmp.setListType(VariableChooser->getCurrentObjectList());
130 
131  problem->removeVariables();
132 
134  problem->addVariables(tmp);
135  else
136  return true;
137 
138  //variables 2
139  CSensItem tmp2;
140 
141  if (Variable2Chooser->getCurrentObjectList() == CObjectLists::SINGLE_OBJECT)
142  {
143  if (mpSingleVariable2)
145  }
146  else
147  tmp2.setListType(Variable2Chooser->getCurrentObjectList());
148 
149  // write variables to problem
150  problem->removeVariables();
151 
153  {
154  problem->addVariables(tmp);
155 
157  problem->addVariables(tmp2);
158  }
159 
160  // :TODO Bug 322: This should only be called when actual changes have been saved.
161  // However we do not track the changes for the variables we just delete them and add them again.
162  if (true)
163  {
164  if (mpDataModel != NULL)
165  {
166  mpDataModel->changed();
167  }
168 
169  mChanged = false;
170  }
171 
172  return true;
173 }
174 
176 {return CSensMethod::createMethod(type);}
177 
179 {
180  if (FunctionChooser->getCurrentObjectList() != CObjectLists::SINGLE_OBJECT)
181  FunctionLineEdit->setText(QApplication::translate("SensitivitiesWidget", "[Please Choose Object.] --->", 0, QApplication::UnicodeUTF8));
182 
183  if (!commonBeforeRunTask()) return false;
184 
185  bool success = true;
186 
187  if (!commonRunTask()) success = false;
188 
189  return success;
190 }
191 
193 {
194  bool success = true;
195  //setup the result widget
197  dynamic_cast<CQSensResultWidget*>(mpListView->findWidgetFromId(341));
198 
199  if (pResult) pResult->newResult();
200 
201  if (success && isVisible()) mpListView->switchToOtherWidget(341, ""); //change to the results window
202 
203  return success;
204 }
205 
207 {
208  loadCommon();
209  loadMethod();
210 
211  CSensTask* sensTask =
213  assert(sensTask);
214 
215  CSensProblem* problem =
216  dynamic_cast<CSensProblem *>(sensTask->getProblem());
217  assert(problem);
218 
219  //CSensMethod* method =
220  // dynamic_cast<CSensMethod *>(sensTask->getMethod());
221  //assert(method);
222 
223  //mSubTaskType = problem->getSubTaskType();
224  SubTaskChooser->setCurrentIndex((int)problem->getSubTaskType());
225  updateComboBoxes(problem->getSubTaskType());
226 
227  CSensItem tmp = problem->getTargetFunctions();
228 
229  //target function
230  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
232  assert(pDataModel != NULL);
233 
234  if (tmp.isSingleObject())
235  {
236  FunctionChooser->setCurrentObjectList(CObjectLists::SINGLE_OBJECT);
237  mpSingleFunction = pDataModel->getDataObject(tmp.getSingleObjectCN());
238 
239  if (mpSingleFunction)
240  FunctionLineEdit->setText(FROM_UTF8(mpSingleFunction->getObjectDisplayName()));
241  }
242  else
243  {
244  mpSingleFunction = NULL;
245  FunctionChooser->setCurrentObjectList(tmp.getListType());
246  }
247 
248  //variables 1
249  if (problem->getNumberOfVariables() > 0)
250  {
251  tmp = problem->getVariables(0);
252 
253  if (tmp.isSingleObject())
254  {
255  VariableChooser->setCurrentObjectList(CObjectLists::SINGLE_OBJECT);
256  mpSingleVariable = pDataModel->getDataObject(tmp.getSingleObjectCN());
257 
258  if (mpSingleVariable)
259  VariableLineEdit->setText(FROM_UTF8(mpSingleVariable->getObjectDisplayName()));
260  }
261  else
262  VariableChooser->setCurrentObjectList(tmp.getListType());
263  }
264  else
265  {
266  VariableChooser->setCurrentObjectList(CObjectLists::EMPTY_LIST);
267  mpSingleVariable = NULL;
268  }
269 
270  //variables 2
271  if (problem->getNumberOfVariables() > 1)
272  {
273  tmp = problem->getVariables(1);
274 
275  if (tmp.isSingleObject())
276  {
277  Variable2Chooser->setCurrentObjectList(CObjectLists::SINGLE_OBJECT);
278  mpSingleVariable2 = pDataModel->getDataObject(tmp.getSingleObjectCN());
279 
280  if (mpSingleVariable2)
281  Variable2LineEdit->setText(FROM_UTF8(mpSingleVariable2->getObjectDisplayName()));
282  }
283  else
284  Variable2Chooser->setCurrentObjectList(tmp.getListType());
285  }
286  else
287  {
288  Variable2Chooser->setCurrentObjectList(CObjectLists::EMPTY_LIST);
289  mpSingleVariable2 = NULL;
290  }
291 
292  // initCombos(problem);
293 
294  mChanged = false;
295 
297  return true;
298 }
299 
300 //**************************************************************************
301 
302 void SensitivitiesWidget::updateLineeditEnable(const SensWidgetComboBox* box, QWidget* w1, QWidget* w2)
303 {
304  if (!box) return;
305 
306  bool enable = false;
307 
309  enable = true;
310 
311  if (w1) w1->setVisible(enable);
312 
313  if (w2) w2->setVisible(enable);
314 }
315 
317 {
318  /*
319  updateLineeditEnable(FunctionChooser, FunctionLineEdit, SingleFunctionChooserButton);
320  updateLineeditEnable(VariableChooser, VariableLineEdit, SingleVariableChooserButton);
321  updateLineeditEnable(Variable2Chooser, Variable2LineEdit, SingleVariable2ChooserButton);
322  */
323  updateLineeditEnable(FunctionChooser, FunctionLineEdit, SingleFunctionChooser);
324  updateLineeditEnable(VariableChooser, VariableLineEdit, SingleVariableChooser);
325  updateLineeditEnable(Variable2Chooser, Variable2LineEdit, SingleVariable2Chooser);
326 }
327 
328 void
330 {
331  QStringList StringList;
332  //std::vector<int> mFunctionIndexTable, mVariableIndexTable;
333 
334  // SubTaskChooser combo
335  int i = 0;
336 
337  while (CSensProblem::SubTaskName[i].length() > 0)
338  {
339  StringList.append(FROM_UTF8(CSensProblem::SubTaskName[i]));
340  ++i;
341  }
342 
343  SubTaskChooser->insertItems(SubTaskChooser->count(), StringList);
344  SubTaskChooser->setCurrentIndex(0);
346 }
347 
349 {
350  FunctionChooser->fillFromList(CSensProblem::getPossibleTargetFunctions(type));
351  VariableChooser->fillFromList(CSensProblem::getPossibleVariables(type));
352  Variable2Chooser->fillFromList(CSensProblem::getPossibleVariables(type));
353 }
354 
355 // ******************* SLOTs *******************************+
356 
357 void
358 //SensitivitiesWidget::on_SubTaskChooser_activated(int)
360 {
361  CSensProblem::SubTaskType subTaskType = (CSensProblem::SubTaskType)SubTaskChooser->currentIndex();
362  updateComboBoxes(subTaskType);
363 
365 }
366 
367 void
368 //SensitivitiesWidget::on_FunctionChooser_activated(int a)
370 {
372 }
373 
374 void
375 //SensitivitiesWidget::on_VariableChooser_activated(int)
377 {
379 }
380 
381 void
382 //SensitivitiesWidget::on_Variable2Chooser_activated(int)
384 {
386 }
387 
388 void
389 //SensitivitiesWidget::on_SingleFunctionChooser_clicked()
391 {
392  const CCopasiObject * pObject =
396 
397  if (pObject)
398  {
399  FunctionLineEdit->setText(FROM_UTF8(pObject->getObjectDisplayName()));
400  mpSingleFunction = pObject;
401  FunctionChooser->setCurrentObjectList(CObjectLists::SINGLE_OBJECT);
402  }
403 }
404 
405 void
406 //SensitivitiesWidget::on_SingleVariableChooser_clicked()
408 {
409  const CCopasiObject * pObject =
413 
414  if (pObject)
415  {
416  VariableLineEdit->setText(FROM_UTF8(pObject->getObjectDisplayName()));
417  mpSingleVariable = pObject;
418  VariableChooser->setCurrentObjectList(CObjectLists::SINGLE_OBJECT);
419  }
420 }
421 
422 void
423 //SensitivitiesWidget::on_SingleVariable2Chooser_clicked()
425 {
426  const CCopasiObject * pObject =
430 
431  if (pObject)
432  {
433  Variable2LineEdit->setText(FROM_UTF8(pObject->getObjectDisplayName()));
434  mpSingleVariable2 = pObject;
435  Variable2Chooser->setCurrentObjectList(CObjectLists::SINGLE_OBJECT);
436  }
437 }
CCopasiObject * getDataObject(const CCopasiObjectName &CN) const
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
bool saveMethod()
Definition: TaskWidget.cpp:308
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
size_t getNumberOfVariables() const
CCopasiProblem * getProblem()
void switchToOtherWidget(const size_t &id, const std::string &key)
Definition: listviews.cpp:926
bool loadCommon()
Definition: TaskWidget.cpp:247
virtual CCopasiObjectName getCN() const
CSensItem getVariables(size_t index) const
CCopasiObject * get(const std::string &key)
static const std::string SubTaskName[]
Definition: CSensProblem.h:82
bool saveCommon()
Definition: TaskWidget.cpp:258
bool loadMethod()
Definition: TaskWidget.cpp:284
CSensProblem::SubTaskType getSubTaskType() const
virtual CCopasiMethod * createMethod(const CCopasiMethod::SubType &type)
void changeTargetFunctions(const CSensItem item)
static std::vector< CObjectLists::ListType > getPossibleVariables(CSensProblem::SubTaskType)
void changed(const bool &changed=true)
SensitivitiesWidget(QWidget *parent=0, const char *name=0, Qt::WFlags fl=0)
void setSingleObjectCN(const CCopasiObjectName &cn)
bool setTaskName(const std::string &name)
bool mChanged
Definition: TaskWidget.h:133
void updateLineeditEnable(const SensWidgetComboBox *box, QWidget *w1, QWidget *w2)
void updateComboBoxes(CSensProblem::SubTaskType type)
CopasiWidget * findWidgetFromId(const size_t &id) const
Definition: listviews.cpp:678
CSensItem getTargetFunctions() const
CObjectLists::ListType getCurrentObjectList() const
static CSensMethod * createMethod(CCopasiMethod::SubType subType=CCopasiMethod::sensMethod)
Definition: CSensMethod.cpp:34
const CObjectLists::ListType & getListType() const
static std::vector< CObjectLists::ListType > getPossibleTargetFunctions(CSensProblem::SubTaskType)
ListViews * mpListView
Definition: copasiWidget.h:62
const CCopasiObject * mpSingleFunction
static const QIcon & icon(const IconID &id)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
void showMethodParameters(const bool &show)
CQTaskMethodWidget * mpMethodWidget
Definition: TaskWidget.h:123
virtual bool taskFinishedEvent()
const CArrayAnnotation * pResult
CCopasiDataModel * mpDataModel
Definition: copasiWidget.h:65
CCopasiMethod * getMethod()
static CKeyFactory * getKeyFactory()
bool commonRunTask()
Definition: TaskWidget.cpp:395
CQTaskBtnWidget * mpBtnWidget
Definition: TaskWidget.h:124
CQTaskHeaderWidget * mpHeaderWidget
Definition: TaskWidget.h:122
bool fl(const C_FLOAT64 &d1, const C_FLOAT64 &d2)
void addVariables(const CSensItem &item)
void setListType(CObjectLists::ListType lt)
bool removeVariables(size_t index)
bool commonBeforeRunTask()
Definition: TaskWidget.cpp:317
const CCopasiObject * mpSingleVariable
void setSubTaskType(const CSensProblem::SubTaskType &type)
std::string mKey
Definition: copasiWidget.h:63
const CCopasiObject * mpSingleVariable2
static const CCopasiObject * getObjectSingle(QWidget *pParent, const CQSimpleSelectionTree::ObjectClasses &classes, const CCopasiObject *pCurrentObject=NULL)