COPASI API  4.16.103
CQCrossSectionTaskWidget.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 /*
7  * Created by Paul Willy on 5/21/10.
8  */
9 
11 #include "CQTimeSeriesWidget.h"
12 #include "listviews.h"
13 #include "CQTaskBtnWidget.h"
14 #include "CQTaskHeaderWidget.h"
15 #include "CQTaskMethodWidget.h"
16 #include "CQMessageBox.h"
17 #include "CQValidator.h"
18 
20 
21 #include "copasi.h"
22 
23 #include "DataModelGUI.h"
24 #include "qtUtilities.h"
25 #include "CCopasiSelectionDialog.h"
26 
29 #include "model/CModel.h"
31 #include "report/CKeyFactory.h"
32 
35 //#include "crosssection/CCrossSectionMethod.h"
36 
37 /*
38  * Constructs a CQCrossSectionWidget which is a child of 'parent', with the
39  * name 'name'.'
40  */
41 CQCrossSectionTaskWidget::CQCrossSectionTaskWidget(QWidget* parent, const char* name)
42  : TaskWidget(parent, name)
43  , mpSingleVariable(NULL)
44  , mpCrossSectionProblem(NULL)
45  , mpValidatorLC(NULL)
46  , mpValidatorTime(NULL)
47  , mpValidatorTolerance(NULL)
48  , mpValidatorOutLC(NULL)
49  , mpValidatorOutTime(NULL)
50  , mpValidatorOutTolerance(NULL)
51  , mpValidatorCrossing(NULL)
52 
53 {
54  setupUi(this);
55  mpButtonVariable->setIcon(CQIconResource::icon(CQIconResource::copasi));
56 
57  init();
58 }
59 
60 /*
61  * Destroys the object and frees any allocated resources
62  */
64 {
65  destroy();
66  // no need to delete child widgets, Qt does it all for us
67 }
68 
70 {
71  mpCrossSectionProblem = NULL;
72 
73  mpHeaderWidget->setTaskName("Cross Section");
74 
75  verticalLayout->insertWidget(0, mpHeaderWidget);
76 
78  mpGridLayout->addWidget(mpMethodWidget->mpLblParameter, 11, 0, 1, 1);
79  mpGridLayout->addWidget(mpMethodWidget->mpTableParameter, 11, 1, 1, 2);
80 
81  // unsigned int ValidMethods = CCopasiMethod::unset;
82  // mpMethodWidget->setValidMethods(&ValidMethods);
83  // mpMethodWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
84 
85  // verticalLayout->addWidget(mpMethodWidget);
86  verticalLayout->addWidget(mpBtnWidget);
87 
88  mpValidatorCrossing = new CQValidatorDouble(mpLineEditValue);
89  mpLineEditValue->setValidator(mpValidatorCrossing);
90 
91  mpValidatorLC = new CQValidatorInt(mpTxtCrossings);
93  mpTxtCrossings->setValidator(mpValidatorLC);
94 
95  mpValidatorTime = new CQValidatorDouble(mpTxtTime);
97  mpTxtTime->setValidator(mpValidatorTime);
98 
99  mpValidatorOutTime = new CQValidatorDouble(mpTxtOutTime);
100  mpTxtOutTime->setValidator(mpValidatorOutTime);
101 
102  mpValidatorTolerance = new CQValidatorDouble(mpTxtConvergence);
103  mpTxtConvergence->setValidator(mpValidatorTolerance);
104 
105  mpValidatorOutLC = new CQValidatorInt(mpTxtOutCrossings);
107  mpTxtOutCrossings->setValidator(mpValidatorOutLC);
108 
109  mpValidatorOutTolerance = new CQValidatorDouble(mpTxtOutConvergence);
110  mpTxtOutConvergence->setValidator(mpValidatorOutTolerance);
111 
113  dynamic_cast< CQTimeSeriesWidget * >(mpListView->findWidgetFromId(281));
114 
115  if (pResult != NULL)
116  pResult->setTitle("<h2>Cross Section Result</h2>");
117 }
118 
120 {
122 }
123 
125 {
126  if (!mpCrossSectionProblem) return;
127 
128  mpCrossSectionProblem->setFlagLimitCrossings(mpCheckSimCrossings->isChecked());
129  mpCrossSectionProblem->setCrossingsLimit(mpTxtCrossings->text().toULong());
130  mpCrossSectionProblem->setFlagLimitOutCrossings(mpCheckOutputCrossings->isChecked());
131  mpCrossSectionProblem->setOutCrossingsLimit(mpTxtOutCrossings->text().toULong());
132  mpCrossSectionProblem->setTimeLimit(mpTxtTime->text().toDouble());
133  mpCrossSectionProblem->setOutputStartTime(mpTxtOutTime->text().toDouble());
134  mpCrossSectionProblem->setFlagLimitOutTime(mpCheckOutputDelay->isChecked());
135  mpCrossSectionProblem->setFlagLimitConvergence(mpCheckSimConvergence->isChecked());
136  mpCrossSectionProblem->setConvergenceTolerance(mpTxtConvergence->text().toDouble());
137  mpCrossSectionProblem->setFlagLimitOutConvergence(mpCheckOutputConvergence->isChecked());
138  mpCrossSectionProblem->setConvergenceOutTolerance(mpTxtOutConvergence->text().toDouble());
140  mpCrossSectionProblem->setPositiveDirection(mpDirectionPositive->isChecked());
141  mpCrossSectionProblem->setThreshold(mpLineEditValue->text().toDouble());
142 }
143 
145 {
146  commitInput();
147 
148  if (!commonBeforeRunTask()) return false;
149 
150  bool success = true;
151 
152  if (!commonRunTask()) success = false;
153 
154  return success;
155 }
156 
157 /*
158  * Function to save actual changes of the Task
159  */
161 {
162  // check the existence of Task
164  dynamic_cast< CCrossSectionTask * >(mpTask);
165 
166  if (!pTask) return false;
167 
168  // save functions from the Parent, TaskWidget
169  saveCommon();
170  saveMethod();
171 
172  // check the existence of Problem
173  CCrossSectionProblem* pProblem =
174  dynamic_cast<CCrossSectionProblem *>(pTask->getProblem());
175  assert(pProblem);
176 
177  // save the actual changes
178  if (mpCheckSimConvergence->isChecked())
179  pProblem->setCrossingsLimit(mpTxtCrossings->text().toULong());
180 
181  pProblem->setPositiveDirection(mpDirectionPositive->isChecked());
182  pProblem->setThreshold(mpLineEditValue->text().toDouble());
183  //if (mpCheckLT->isChecked())
184  pProblem->setTimeLimit(mpTxtTime->text().toDouble());
185 
187 
188  pProblem->setFlagLimitOutTime(mpCheckOutputDelay->isChecked());
189 
190  if (mpCheckOutputDelay->isChecked())
191  {
192  pProblem->setOutputStartTime(mpTxtOutTime->text().toDouble());
193  }
194 
195  pProblem->setFlagLimitCrossings(mpCheckSimCrossings->isChecked());
196  pProblem->setCrossingsLimit(mpTxtCrossings->text().toULong());
197  pProblem->setFlagLimitOutCrossings(mpCheckOutputCrossings->isChecked());
198  pProblem->setOutCrossingsLimit(mpTxtOutCrossings->text().toULong());
199  pProblem->setFlagLimitConvergence(mpCheckSimConvergence->isChecked());
200  pProblem->setConvergenceTolerance(mpTxtConvergence->text().toDouble());
201  pProblem->setFlagLimitOutConvergence(mpCheckOutputConvergence->isChecked());
202  pProblem->setConvergenceOutTolerance(mpTxtOutConvergence->text().toDouble());
203 
207  mpValidatorLC->saved();
211 
212  return true;
213 }
214 
216 {
217  bool success = true;
218  // We need to load the result here as this is the only place where
219  // we know that it is correct.
221  dynamic_cast< CQTimeSeriesWidget * >(mpListView->findWidgetFromId(281));
222 
223  if (pResult == NULL)
224  return false;
225 
226  success &= pResult->loadResult(mpTask);
227 
228  return success;
229 }
230 
231 /*
232  * Function to load saved values of the Task
233  */
235 {
236  // load Task
238  dynamic_cast< CCrossSectionTask * >(mpTask);
239 
240  if (!pTask) return false;
241 
242  // load functions from the Parent, TaskWidget
243  loadCommon();
244  loadMethod();
245 
246  showUnits();
247 
248  // load Problem
249  CCrossSectionProblem* pProblem =
250  dynamic_cast<CCrossSectionProblem *>(pTask->getProblem());
251  assert(pProblem);
252 
255 
256  //CCrossSectionMethod* pMethod =
257  // dynamic_cast<CCrossSectionMethod *>(pTask->getMethod());
258  //assert(pMethod);
259 
260  //for now, we use a trajectory method
261  //CTrajectoryMethod* pMethod =
262  // dynamic_cast<CTrajectoryMethod *>(pTask->getMethod());
263  //assert(pMethod);
264 
265  // load the saved values
266  const std::string &name = pProblem->getSingleObjectCN();
267 
268  if (name.empty())
269  setSingleObject(NULL);
270  else
271  setSingleObject(static_cast<const CCopasiObject*>(pTask->getObjectDataModel()->getObject(name)));
272 
273  mpLineEditValue->setText(QString::number(pProblem->getThreshold()));
274  mpDirectionPositive->setChecked(mpCrossSectionProblem->isPositiveDirection());
275  mpDirectionNegative->setChecked(!mpCrossSectionProblem->isPositiveDirection());
276 
277  mpCheckSimConvergence->setChecked(pProblem->getFlagLimitConvergence());
278  mpTxtConvergence->setEnabled(pProblem->getFlagLimitConvergence());
279 
280  if (pProblem->getFlagLimitConvergence())
281  mpTxtConvergence->setText(QString::number(pProblem->getConvergenceTolerance()));
282  else
283  mpTxtConvergence->setText("");
284 
285  mpCheckOutputConvergence->setChecked(pProblem->getFlagLimitOutConvergence());
286  mpTxtOutConvergence->setEnabled(pProblem->getFlagLimitOutConvergence());
287 
288  if (pProblem->getFlagLimitOutConvergence())
289  mpTxtOutConvergence->setText(QString::number(pProblem->getConvergenceOutTolerance()));
290  else
291  mpTxtOutConvergence->setText("");
292 
293  mpCheckSimCrossings->setChecked(pProblem->getFlagLimitCrossings());
294  mpTxtCrossings->setEnabled(pProblem->getFlagLimitCrossings());
295 
296  if (pProblem->getFlagLimitCrossings())
297  mpTxtCrossings->setText(QString::number(pProblem->getCrossingsLimit()));
298  else
299  mpTxtCrossings->setText("");
300 
301  mpCheckOutputCrossings->setChecked(pProblem->getFlagLimitOutCrossings());
302  mpTxtOutCrossings->setEnabled(pProblem->getFlagLimitOutCrossings());
303 
304  if (pProblem->getFlagLimitOutCrossings())
305  mpTxtOutCrossings->setText(QString::number(pProblem->getOutCrossingsLimit()));
306  else
307  mpTxtOutCrossings->setText("");
308 
309  //mpCheckLT->setChecked(pProblem->getFlagLimitTime());
310  if (pProblem->getFlagLimitOutTime())
311  {
312  mpCheckOutputDelay->setChecked(true);
313  mpTxtOutTime->setEnabled(true);
314  mpTxtOutTime->setText(QString::number(pProblem->getOutputStartTime()));
315  }
316  else
317  {
318  mpCheckOutputDelay->setChecked(false);
319  mpTxtOutTime->setEnabled(false);
320  mpTxtOutTime->setText("");
321  }
322 
323  mpTxtTime->setText(QString::number(pProblem->getTimeLimit()));
324 
328  mpValidatorLC->saved();
332 
333  return true;
334 }
335 
337 {
338  return NULL;
339 }
340 
342 {
343  const CCopasiObject * pObject =
346 
347  setSingleObject(pObject);
348 }
349 
351 {
352  mpSingleVariable = pSingleVariable;
353 
354  if (pSingleVariable == NULL)
355  mpLineEditVariable->setText(tr("[Please Choose Object.] --->"));
356  else
357  mpLineEditVariable->setText(FROM_UTF8(pSingleVariable->getObjectDisplayName()));
358 }
359 
361 {
362  if (!mpLineEditValue->hasAcceptableInput())
363  return;
364 
365  commitInput();
366 }
367 
369 {
370  mpTxtCrossings->setEnabled(b);
371 
372  if (!mpTxtCrossings->hasAcceptableInput())
373  return;
374 
375  try
376  {
378  mpCrossSectionProblem->setCrossingsLimit(mpTxtCrossings->text().toULong());
379  }
380 
381  catch (...)
382  {
383  CQMessageBox::information(this, QString("Information"),
385  QMessageBox::Ok, QMessageBox::Ok);
386  }
387 
388 // updateValues();
389 }
390 
392 {
393  mpTxtConvergence->setEnabled(b);
394 
395  if (!mpTxtConvergence->hasAcceptableInput())
396  return;
397 
398  try
399  {
400  mpCrossSectionProblem->setConvergenceTolerance(mpTxtConvergence->text().toDouble());
401  }
402 
403  catch (...)
404  {
405  CQMessageBox::information(this, QString("Information"),
407  QMessageBox::Ok, QMessageBox::Ok);
408  }
409 
410 // updateValues();
411 }
412 
414 {
415  mpTxtOutTime->setEnabled(b);
416 
417  if (!mpTxtOutTime->hasAcceptableInput())
418  return;
419 
420  try
421  {
422  mpCrossSectionProblem->setOutputStartTime(mpTxtOutTime->text().toDouble());
423  }
424 
425  catch (...)
426  {
427  CQMessageBox::information(this, QString("Information"),
429  QMessageBox::Ok, QMessageBox::Ok);
430  }
431 
432 // updateValues();
433 }
434 
436 {
437  mpTxtOutCrossings->setEnabled(b);
438 
439  if (!mpTxtOutCrossings->hasAcceptableInput())
440  return;
441 
442  try
443  {
444  mpCrossSectionProblem->setOutCrossingsLimit(mpTxtOutCrossings->text().toDouble());
445  }
446 
447  catch (...)
448  {
449  CQMessageBox::information(this, QString("Information"),
451  QMessageBox::Ok, QMessageBox::Ok);
452  }
453 }
455 {
456  mpTxtOutConvergence->setEnabled(b);
457 
458  if (!mpTxtOutConvergence->hasAcceptableInput())
459  return;
460 
461  try
462  {
463  mpCrossSectionProblem->setConvergenceOutTolerance(mpTxtOutConvergence->text().toDouble());
464  }
465 
466  catch (...)
467  {
468  CQMessageBox::information(this, QString("Information"),
470  QMessageBox::Ok, QMessageBox::Ok);
471  }
472 }
473 
475 {
476  if (!mpTxtTime->hasAcceptableInput())
477  return;
478 
479  commitInput();
480 
481  // TODO: Implement
482 }
484 {
485  if (!mpTxtConvergence->hasAcceptableInput())
486  return;
487 
488  // TODO: Implement
489 }
491 {
492  if (!mpTxtCrossings->hasAcceptableInput())
493  return;
494 
495  // TODO: Implement
496 }
497 
499 {
500  if (!mpTxtOutConvergence->hasAcceptableInput())
501  return;
502 
503  // TODO: Implement
504 }
506 {
507  if (!mpTxtOutCrossings->hasAcceptableInput())
508  return;
509 
510  // TODO: Implement
511 }
513 {
514  if (!mpTxtOutTime->hasAcceptableInput())
515  return;
516 
517  // TODO: Implement
518 }
519 
521 {
522  mpTxtCrossings->setText(QString::number(mpCrossSectionProblem->getCrossingsLimit()));
524 
525  mpTxtOutCrossings->setText(QString::number(mpCrossSectionProblem->getOutCrossingsLimit()));
527 
528  mpTxtTime->setText(QString::number(mpCrossSectionProblem->getTimeLimit()));
530 
531  mpTxtOutTime->setText(QString::number(mpCrossSectionProblem->getOutputStartTime()));
533 
534  mpTxtConvergence->setText(QString::number(mpCrossSectionProblem->getConvergenceTolerance()));
536 
537  mpTxtOutConvergence->setText(QString::number(mpCrossSectionProblem->getConvergenceOutTolerance()));
539 
540  mpLineEditValue->setText(QString::number(mpCrossSectionProblem->getThreshold()));
542 }
543 
544 // virtual
546 {
547  switch (objectType)
548  {
549  case ListViews::MODEL:
550 
551  if (action == ListViews::CHANGE)
552  {
553  showUnits();
554  }
555 
556  break;
557 
558  default:
559  break;
560  }
561 
562  return true;
563 }
564 
566 {
567  const CModel * pModel = NULL;
568 
569  QString TimeUnits;
570 
571  if (mpDataModel != NULL &&
572  (pModel = mpDataModel->getModel()) != NULL)
573  {
574  TimeUnits = "(" + FROM_UTF8(pModel->getTimeUnitsDisplayString()) + ")";
575  }
576 
577  mpLblDurationLimit->setText("if detection time " + TimeUnits + " larger:");
578  mpCheckOutputDelay->setText("if time " + TimeUnits + " larger:");
579 }
CCopasiDataModel * getObjectDataModel()
const C_FLOAT64 & getTimeLimit() const
void setTimeLimit(const C_FLOAT64 &timeLimit)
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
bool saveMethod()
Definition: TaskWidget.cpp:308
#define pdelete(p)
Definition: copasi.h:215
const std::string & getSingleObjectCN() const
objectType
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
void setCrossingsLimit(const unsigned C_INT32 &crossingLimit)
virtual CCopasiMethod * createMethod(const CCopasiMethod::SubType &type)
CCopasiProblem * getProblem()
std::string getTimeUnitsDisplayString() const
Definition: CModel.cpp:4531
bool loadCommon()
Definition: TaskWidget.cpp:247
void setSingleObject(const CCopasiObject *pSingleVariable)
bool getFlagLimitCrossings() const
void setConvergenceTolerance(const C_FLOAT64 &convergenceTolerance)
static std::string getAllMessageText(const bool &chronological=true)
CQValidatorDouble * mpValidatorTime
CQCrossSectionTaskWidget(QWidget *parent=0, const char *name=0)
void setThreshold(const C_FLOAT64 &threshold)
bool saveCommon()
Definition: TaskWidget.cpp:258
void setFlagLimitOutTime(bool flagLimitTime)
bool loadMethod()
Definition: TaskWidget.cpp:284
virtual bool update(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
const C_FLOAT64 & getConvergenceOutTolerance() const
static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void setFlagLimitConvergence(bool flagLimitConvergence)
void setPositiveDirection(bool isPositive)
bool setTaskName(const std::string &name)
bool getFlagLimitConvergence() const
virtual bool loadResult(const CCopasiTask *pTask)
CTSSATask * pTask
CQValidatorDouble * mpValidatorOutTolerance
CopasiWidget * findWidgetFromId(const size_t &id) const
Definition: listviews.cpp:678
virtual void setTitle(const QString &title)
void setFlagLimitOutCrossings(bool flagLimitCrossing)
virtual void saved() const
Definition: CQValidator.h:71
virtual State revalidate()
Definition: CQValidator.h:63
void setFlagLimitCrossings(bool flagLimitCrossing)
ListViews * mpListView
Definition: copasiWidget.h:62
static const QIcon & icon(const IconID &id)
const C_FLOAT64 & getThreshold() const
CQValidatorDouble * mpValidatorCrossing
CCopasiTask * mpTask
Definition: TaskWidget.h:130
void showMethodParameters(const bool &show)
void setConvergenceOutTolerance(const C_FLOAT64 &convergenceTolerance)
CQTaskMethodWidget * mpMethodWidget
Definition: TaskWidget.h:123
const unsigned C_INT32 & getCrossingsLimit() const
const CArrayAnnotation * pResult
const unsigned C_INT32 & getOutCrossingsLimit() const
CCopasiDataModel * mpDataModel
Definition: copasiWidget.h:65
CQValidatorDouble * mpValidatorOutTime
CCrossSectionProblem * mpCrossSectionProblem
bool commonRunTask()
Definition: TaskWidget.cpp:395
const C_FLOAT64 & getOutputStartTime() const
CQTaskBtnWidget * mpBtnWidget
Definition: TaskWidget.h:124
const C_FLOAT64 & getConvergenceTolerance() const
CQValidatorDouble * mpValidatorTolerance
bool getFlagLimitOutCrossings() const
CQTaskHeaderWidget * mpHeaderWidget
Definition: TaskWidget.h:122
void setSingleObjectCN(const std::string &cn)
void setRange(const C_FLOAT64 &lowerBound, const C_FLOAT64 &upperBound)
Definition: CQValidator.cpp:80
void setRange(const int &lowerBound, const int &upperBound)
Definition: CQValidator.cpp:98
bool getFlagLimitOutConvergence() const
void setOutputStartTime(const C_FLOAT64 &endTime)
Definition: CModel.h:50
virtual const CObjectInterface * getObject(const CCopasiObjectName &cn) const
void setFlagLimitOutConvergence(bool flagLimitConvergence)
bool commonBeforeRunTask()
Definition: TaskWidget.cpp:317
const CCopasiObject * mpSingleVariable
static const CCopasiObject * getObjectSingle(QWidget *pParent, const CQSimpleSelectionTree::ObjectClasses &classes, const CCopasiObject *pCurrentObject=NULL)
void setOutCrossingsLimit(const unsigned C_INT32 &crossingLimit)
#define max(a, b)
Definition: f2c.h:176