COPASI API  4.16.103
CQTrajectoryWidget.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) 2006 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #include "copasi.h"
16 
17 #include "CQTrajectoryWidget.h"
18 
19 #include "CQTaskBtnWidget.h"
20 #include "CQTaskHeaderWidget.h"
21 #include "CQTaskMethodWidget.h"
22 #include "CProgressBar.h"
23 #include "CQValidator.h"
24 #include "CQMessageBox.h"
25 #include "qtUtilities.h"
26 #include "CQTimeSeriesWidget.h"
27 
30 #include "model/CModel.h"
31 #include "report/CKeyFactory.h"
34 
35 /*
36  * Constructs a CQTrajectoryWidget which is a child of 'parent', with the
37  * name 'name'.'
38  */
39 CQTrajectoryWidget::CQTrajectoryWidget(QWidget* parent, const char* name)
40  : TaskWidget(parent, name)
41 {
42  setupUi(this);
43 
44  init();
45 }
46 
47 /*
48  * Destroys the object and frees any allocated resources
49  */
51 {
52  destroy();
53  // no need to delete child widgets, Qt does it all for us
54 }
55 
57 {
58  mpTrajectoryProblem = NULL;
59 
60  mpHeaderWidget->setTaskName("Time Course");
61 
62  verticalLayout->insertWidget(0, mpHeaderWidget); // header
63  // verticalLayout->insertSpacing(1, 14); // space between header and body
64 
67  verticalLayout->addWidget(mpMethodWidget);
68 
69  verticalLayout->addWidget(mpBtnWidget); // 'footer'
70 
71  slotOutputDelay(false);
72 
73  mpValidatorDuration = new CQValidatorDouble(mpEditDuration);
74  mpEditDuration->setValidator(mpValidatorDuration);
75 
76  mpValidatorIntervalSize = new CQValidatorDouble(mpEditIntervalSize);
78  mpEditIntervalSize->setValidator(mpValidatorIntervalSize);
79 
80  mpValidatorIntervals = new CQValidatorInt(mpEditIntervals);
82  mpEditIntervals->setValidator(mpValidatorIntervals);
83 
84  mpValidatorDelay = new CQValidatorDouble(mpEditDelay);
85  mpEditDelay->setValidator(mpValidatorDelay);
86 }
87 
89 {
91 }
92 
94 {
95  if (!mpEditDuration->hasAcceptableInput())
96  return;
97 
98  try
99  {
100  mpTrajectoryProblem->setDuration(mpEditDuration->text().toDouble());
101  }
102  catch (...)
103  {
104  CQMessageBox::information(this, QString("Information"),
106  QMessageBox::Ok, QMessageBox::Ok);
107  }
108 
109  mpEditIntervalSize->setText(QString::number(mpTrajectoryProblem->getStepSize()));
111  mpEditIntervals->setText(QString::number(mpTrajectoryProblem->getStepNumber()));
113 
114  checkTimeSeries();
115  updateIntervals();
116 }
117 
119 {
120  if (!mpEditIntervalSize->hasAcceptableInput())
121  return;
122 
123  try
124  {
125  mpTrajectoryProblem->setStepSize(mpEditIntervalSize->text().toDouble());
126  }
127 
128  catch (...)
129  {
130  CQMessageBox::information(this, QString("Information"),
132  QMessageBox::Ok, QMessageBox::Ok);
133  }
134 
135  mpEditIntervalSize->setText(QString::number(mpTrajectoryProblem->getStepSize()));
137  mpEditIntervals->setText(QString::number(mpTrajectoryProblem->getStepNumber()));
139 
140  checkTimeSeries();
141  updateIntervals();
142 }
143 
145 {
146  if (!mpEditIntervals->hasAcceptableInput())
147  return;
148 
149  try
150  {
151  mpTrajectoryProblem->setStepNumber(mpEditIntervals->text().toULong());
152  }
153  catch (...)
154  {
155  CQMessageBox::information(this, QString("Information"),
157  QMessageBox::Ok, QMessageBox::Ok);
158  }
159 
160  mpEditIntervalSize->setText(QString::number(mpTrajectoryProblem->getStepSize()));
162 
163  checkTimeSeries();
164  updateIntervals();
165 }
166 
168 {
169  mpEditDelay->setEnabled(checked);
170  updateIntervals();
171 }
172 
174 {
176  dynamic_cast< CTrajectoryTask * >(mpTask);
177 
178  if (!pTask) return false;
179 
180  saveCommon();
181  saveMethod();
182 
183  CTrajectoryProblem* trajectoryproblem =
184  dynamic_cast<CTrajectoryProblem *>(pTask->getProblem());
185  assert(trajectoryproblem);
186 
187  //numbers
188  if (mpEditIntervalSize->hasAcceptableInput() &&
189  trajectoryproblem->getStepSize() != mpEditIntervalSize->text().toDouble())
190  {
191  trajectoryproblem->setStepSize(mpEditIntervalSize->text().toDouble());
192  mChanged = true;
193  }
194  else if (mpEditIntervals->hasAcceptableInput() &&
195  trajectoryproblem->getStepNumber() != mpEditIntervals->text().toULong())
196  {
197  trajectoryproblem->setStepNumber(mpEditIntervals->text().toLong());
198  mChanged = true;
199  }
200 
201  if (mpEditDuration->hasAcceptableInput() &&
202  trajectoryproblem->getDuration() != mpEditDuration->text().toDouble())
203  {
204  trajectoryproblem->setDuration(mpEditDuration->text().toDouble());
205  mChanged = true;
206  }
207 
208  C_FLOAT64 StartTime = mpEditDelay->text().toDouble();
209 
210  if (mpCheckDelay->isChecked())
211  {
212  if (mpEditDelay->hasAcceptableInput() &&
213  StartTime != trajectoryproblem->getOutputStartTime())
214  {
215  trajectoryproblem->setOutputStartTime(StartTime);
216  mChanged = true;
217  }
218  }
219  else
220  {
221  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
222  C_FLOAT64 InitialTime =
223  (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getInitialTime();
224 
225  if (trajectoryproblem->getStepSize() > 0.0)
226  {
227  if (StartTime > InitialTime)
228  {
229  trajectoryproblem->setOutputStartTime(InitialTime);
230  mChanged = true;
231  }
232  }
233  else
234  {
235  if (StartTime < InitialTime)
236  {
237  trajectoryproblem->setOutputStartTime(InitialTime);
238  mChanged = true;
239  }
240  }
241  }
242 
243  if (trajectoryproblem->timeSeriesRequested() != mpCheckSave->isChecked())
244  {
245  trajectoryproblem->setTimeSeriesRequested(mpCheckSave->isChecked());
246  mChanged = true;
247  }
248 
249  if (trajectoryproblem->getOutputEvent() != mpCheckOutputEvent->isChecked())
250  {
251  trajectoryproblem->setOutputEvent(mpCheckOutputEvent->isChecked());
252  mChanged = true;
253  }
254 
255  if (trajectoryproblem->getContinueSimultaneousEvents() != mpCheckContinueEvents->isChecked())
256  {
257  trajectoryproblem->setContinueSimultaneousEvents(mpCheckContinueEvents->isChecked());
258  mChanged = true;
259  }
260 
265  return true;
266 }
267 
269 {
271  dynamic_cast< CTrajectoryTask * >(mpTask);
272 
273  if (!pTask) return false;
274 
275  loadCommon();
276  loadMethod();
277 
278  showUnits();
279 
280  CTrajectoryProblem* trajectoryproblem =
281  dynamic_cast<CTrajectoryProblem *>(pTask->getProblem());
282  assert(trajectoryproblem);
283 
285  mpTrajectoryProblem = new CTrajectoryProblem(*trajectoryproblem);
286 
287  //numbers
288  mpEditIntervalSize->setText(QString::number(trajectoryproblem->getStepSize()));
289  mpEditIntervals->setText(QString::number(trajectoryproblem->getStepNumber()));
290  mpEditDuration->setText(QString::number(trajectoryproblem->getDuration()));
291 
292  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
293  C_FLOAT64 InitialTime = (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getInitialTime();
294 
295  bool Delayed;
296 
297  if (trajectoryproblem->getStepSize() > 0.0)
298  Delayed = (trajectoryproblem->getOutputStartTime() - InitialTime) > std::numeric_limits< C_FLOAT64 >::min();
299  else
300  Delayed = (InitialTime - trajectoryproblem->getOutputStartTime()) > std::numeric_limits< C_FLOAT64 >::min();
301 
302  mpCheckDelay->setChecked(Delayed);
303  mpEditDelay->setEnabled(Delayed);
304 
305  mpEditDelay->setText(QString::number(trajectoryproblem->getOutputStartTime()));
306 
307  mpCheckOutputEvent->setChecked(trajectoryproblem->getOutputEvent());
308  mpCheckContinueEvents->setChecked(trajectoryproblem->getContinueSimultaneousEvents());
309 
310  //store time series checkbox
311  mpCheckSave->setChecked(trajectoryproblem->timeSeriesRequested());
312 
313  checkTimeSeries();
314 
315  updateIntervals();
316 
321  return true;
322 }
323 
325 {
326  return CTrajectoryMethod::createMethod(type);
327 }
328 
330 {
331  checkTimeSeries();
332 
333  if (!commonBeforeRunTask()) return false;
334 
335  bool success = true;
336 
337  if (!commonRunTask()) success = false;
338 
339  return success;
340 }
341 
343 {
344  bool success = true;
345  // We need to load the result here as this is the only place where
346  // we know that it is correct.
348  dynamic_cast< CQTimeSeriesWidget * >(mpListView->findWidgetFromId(231));
349 
350  if (pResult == NULL)
351  return false;
352 
353  success &= pResult->loadResult(mpTask);
354 
355  return success;
356 }
357 
359 {
360  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
361 
362  if (mpEditIntervals->text().toLong() * (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getStateTemplate().getNumVariable() > TSMAX)
363  {
364  mpCheckSave->setChecked(false);
365  mpCheckSave->setEnabled(false);
366  }
367  else
368  {
369  mpCheckSave->setEnabled(true);
370  }
371 }
372 
374 {
375  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
376  C_FLOAT64 InitialTime = (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getInitialTime();
377  C_FLOAT64 Duration = mpEditDuration->text().toDouble();
378  C_FLOAT64 OutputStartTime = InitialTime;
379 
380  if (mpCheckDelay->isChecked())
381  {
382  if (!mpEditIntervalSize->hasAcceptableInput())
383  return;
384 
385  OutputStartTime = mpEditDelay->text().toDouble();
386  }
387 
388  mpEditIntegrationInterval->setText(QString::number(InitialTime) +
389  " to " +
390  QString::number(InitialTime + Duration));
391 
392  if (Duration > 0.0)
393  {
394  if (std::max(InitialTime, OutputStartTime) > InitialTime + Duration)
395  mpEditOutputInterval->setText("empty");
396  else if (InitialTime < OutputStartTime)
397  {
398  C_FLOAT64 StepSize = mpEditIntervalSize->text().toDouble();
399  OutputStartTime = InitialTime + (ceil((OutputStartTime - InitialTime) / StepSize)) * StepSize;
400  mpEditOutputInterval->setText(QString::number(OutputStartTime) +
401  " to " +
402  QString::number(InitialTime + Duration));
403  }
404  else
405  {
406  mpEditOutputInterval->setText(QString::number(InitialTime) +
407  " to " +
408  QString::number(InitialTime + Duration));
409  }
410  }
411  else
412  {
413  if (std::min(InitialTime, OutputStartTime) < InitialTime + Duration)
414  mpEditOutputInterval->setText("empty");
415  else if (InitialTime > OutputStartTime)
416  {
417  C_FLOAT64 StepSize = mpEditIntervalSize->text().toDouble();
418  OutputStartTime = InitialTime + (ceil((OutputStartTime - InitialTime) / StepSize)) * StepSize;
419  mpEditOutputInterval->setText(QString::number(OutputStartTime) +
420  " to " +
421  QString::number(InitialTime + Duration));
422  }
423  else
424  mpEditOutputInterval->setText(QString::number(InitialTime) +
425  " to " +
426  QString::number(InitialTime + Duration));
427  }
428 }
429 
430 // virtual
432 {
433  switch (objectType)
434  {
435  case ListViews::MODEL:
436 
437  if (action == ListViews::CHANGE)
438  {
439  showUnits();
440  }
441 
442  break;
443 
444  default:
445  break;
446  }
447 
448  return true;
449 }
450 
452 {
453  const CModel * pModel = NULL;
454 
455  QString TimeUnits;
456 
457  if (mpDataModel != NULL &&
458  (pModel = mpDataModel->getModel()) != NULL)
459  {
460  TimeUnits = " (" + FROM_UTF8(pModel->getTimeUnitsDisplayString()) + ")";
461  }
462 
463  mpLblDuration->setText("Duration" + TimeUnits);
464  mpLblIntervalSize->setText("Interval Size" + TimeUnits);
465  mpCheckDelay->setText("Suppress Output Before" + TimeUnits);
466  mpLblIntegrationInterval->setText("Integration Interval" + TimeUnits);
467  mpLblOutputInterval->setText("Output Interval" + TimeUnits);
468 }
CQValidatorDouble * mpValidatorDelay
bool saveMethod()
Definition: TaskWidget.cpp:308
#define pdelete(p)
Definition: copasi.h:215
objectType
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
CCopasiProblem * getProblem()
std::string getTimeUnitsDisplayString() const
Definition: CModel.cpp:4531
bool loadCommon()
Definition: TaskWidget.cpp:247
void setContinueSimultaneousEvents(const bool &continueSimultaneousEvents)
static const unsigned int ValidMethods[]
const unsigned C_INT32 & getStepNumber() const
static std::string getAllMessageText(const bool &chronological=true)
bool saveCommon()
Definition: TaskWidget.cpp:258
bool loadMethod()
Definition: TaskWidget.cpp:284
CQValidatorInt * mpValidatorIntervals
static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void setDuration(const C_FLOAT64 &duration)
CQValidatorDouble * mpValidatorDuration
CQValidatorDouble * mpValidatorIntervalSize
CTrajectoryProblem * mpTrajectoryProblem
bool setTaskName(const std::string &name)
bool mChanged
Definition: TaskWidget.h:133
virtual bool loadResult(const CCopasiTask *pTask)
virtual bool update(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
CTSSATask * pTask
const C_FLOAT64 & getStepSize() const
CopasiWidget * findWidgetFromId(const size_t &id) const
Definition: listviews.cpp:678
void setStepSize(const C_FLOAT64 &stepSize)
virtual void saved() const
Definition: CQValidator.h:71
virtual State revalidate()
Definition: CQValidator.h:63
ListViews * mpListView
Definition: copasiWidget.h:62
const C_FLOAT64 & getDuration() const
void setOutputEvent(const bool &outputEvent)
void setTimeSeriesRequested(bool flag)
void setStepNumber(const unsigned C_INT32 &stepNumber)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
CCopasiTask * mpTask
Definition: TaskWidget.h:130
void showMethodParameters(const bool &show)
CQTaskMethodWidget * mpMethodWidget
Definition: TaskWidget.h:123
CQTrajectoryWidget(QWidget *parent=0, const char *name=0)
#define TSMAX
virtual CCopasiMethod * createMethod(const CCopasiMethod::SubType &type)
static CTrajectoryMethod * createMethod(CCopasiMethod::SubType subType=CCopasiMethod::deterministic)
const CArrayAnnotation * pResult
CCopasiDataModel * mpDataModel
Definition: copasiWidget.h:65
bool commonRunTask()
Definition: TaskWidget.cpp:395
const C_FLOAT64 & getOutputStartTime() const
CQTaskBtnWidget * mpBtnWidget
Definition: TaskWidget.h:124
bool timeSeriesRequested() const
#define C_FLOAT64
Definition: copasi.h:92
CQTaskHeaderWidget * mpHeaderWidget
Definition: TaskWidget.h:122
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
void slotOutputDelay(bool checked)
void setOutputStartTime(const C_FLOAT64 &endTime)
Definition: CModel.h:50
bool commonBeforeRunTask()
Definition: TaskWidget.cpp:317
const bool & getContinueSimultaneousEvents() const
virtual bool taskFinishedEvent()
#define min(a, b)
Definition: f2c.h:175
void setValidMethods(const unsigned int *validMethods)
const bool & getOutputEvent() const
#define max(a, b)
Definition: f2c.h:176