COPASI API  4.16.103
CQTSSAWidget.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/UI/CQTSSAWidget.cpp,v $
3 // $Revision: 1.22 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/04/23 21:12:27 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 #include "CQTSSAWidget.h"
20 
21 #include "copasi.h"
22 
23 #include "CQTSSAResultSubWidget.h"
24 #include "CQTSSAResultWidget.h"
25 #include "CQTaskBtnWidget.h"
26 #include "CQTaskHeaderWidget.h"
27 #include "CQTaskMethodWidget.h"
28 #include "CProgressBar.h"
29 #include "CQValidator.h"
30 #include "CQMessageBox.h"
31 #include "qtUtilities.h"
32 
33 #include "tssanalysis/CTSSATask.h"
35 #include "model/CModel.h"
36 #include "report/CKeyFactory.h"
38 #include "tssanalysis/CCSPMethod.h"
42 
43 /*
44  * Constructs a CQTSSAWidget which is a child of 'parent', with the
45  * name 'name'.'
46  */
47 CQTSSAWidget::CQTSSAWidget(QWidget* parent, const char* name)
48  : TaskWidget(parent, name)
49 {
50  setupUi(this);
51 
52  init();
53 }
54 
55 /*
56  * Destroys the object and frees any allocated resources
57  */
59 {
60  destroy();
61  // no need to delete child widgets, Qt does it all for us
62 }
63 
65 
68 
71 
72 class mpTSSResultSubWidget;
73 class QTabWidget;
74 
76 {
77  mpTSSAProblem = NULL;
78 
79  mpHeaderWidget->setTaskName("Time Scale Separation Analysis");
80 
81  vboxLayout->insertWidget(0, mpHeaderWidget); // header
82  // vboxLayout->insertSpacing(1, 14); // space between header and body
83 
86  vboxLayout->addWidget(mpMethodWidget);
87 
88  vboxLayout->addWidget(mpBtnWidget); // 'footer'
89 
90  mpValidatorDuration = new CQValidatorDouble(mpEditDuration);
91  mpEditDuration->setValidator(mpValidatorDuration);
92 
93  mpValidatorIntervalSize = new CQValidatorDouble(mpEditIntervalSize);
95  mpEditIntervalSize->setValidator(mpValidatorIntervalSize);
96 }
97 
99 {
101 }
102 
104 {
105  try
106  {
107  mpTSSAProblem->setDuration(mpEditDuration->text().toDouble());
108  }
109  catch (...)
110  {
111  CQMessageBox::information(this, QString("Information"),
113  QMessageBox::Ok, QMessageBox::Ok);
114  }
115 
116  mpEditIntervalSize->setText(QString::number(mpTSSAProblem->getStepSize()));
118  mpEditIntervals->setText(QString::number(mpTSSAProblem->getStepNumber()));
119 
120 }
121 
123 {
124  try
125  {
126  mpTSSAProblem->setStepSize(mpEditIntervalSize->text().toDouble());
127  }
128 
129  catch (...)
130  {
131  CQMessageBox::information(this, QString("Information"),
133  QMessageBox::Ok, QMessageBox::Ok);
134  }
135 
136  mpEditIntervalSize->setText(QString::number(mpTSSAProblem->getStepSize()));
138  mpEditIntervals->setText(QString::number(mpTSSAProblem->getStepNumber()));
139 }
140 
142 {
143  try
144  {
145  mpTSSAProblem->setStepNumber(mpEditIntervals->text().toULong());
146  }
147  catch (...)
148  {
149  CQMessageBox::information(this, QString("Information"),
151  QMessageBox::Ok, QMessageBox::Ok);
152  }
153 
154  mpEditIntervalSize->setText(QString::number(mpTSSAProblem->getStepSize()));
156 }
157 
159 {
160  CTSSATask * pTask =
161  dynamic_cast< CTSSATask * >(mpTask);
162 
163  if (!pTask) return false;
164 
165  saveCommon();
166  saveMethod();
167 
168  CTSSAProblem* tssaproblem =
169  dynamic_cast<CTSSAProblem *>(pTask->getProblem());
170  assert(tssaproblem);
171 
172  //numbers
173  if (tssaproblem->getStepSize() != mpEditIntervalSize->text().toDouble())
174  {
175  tssaproblem->setStepSize(mpEditIntervalSize->text().toDouble());
176  mChanged = true;
177  }
178  else if (tssaproblem->getStepNumber() != mpEditIntervals->text().toULong())
179  {
180  tssaproblem->setStepNumber(mpEditIntervals->text().toLong());
181  mChanged = true;
182  }
183 
184  if (tssaproblem->getDuration() != mpEditDuration->text().toDouble())
185  {
186  tssaproblem->setDuration(mpEditDuration->text().toDouble());
187  mChanged = true;
188  }
189 
190 
193 
194  return true;
195 }
196 
198 {
199  CTSSATask * pTask =
200  dynamic_cast< CTSSATask * >(mpTask);
201 
202  if (!pTask) return false;
203 
204  loadCommon();
205  loadMethod();
206 
207  CTSSAProblem* tssaproblem =
208  dynamic_cast<CTSSAProblem *>(pTask->getProblem());
209  assert(tssaproblem);
210 
212  mpTSSAProblem = new CTSSAProblem(*tssaproblem);
213 
214  //numbers
215  mpEditIntervalSize->setText(QString::number(tssaproblem->getStepSize()));
216  mpEditIntervals->setText(QString::number(tssaproblem->getStepNumber()));
217  mpEditDuration->setText(QString::number(tssaproblem->getDuration()));
218 
219 
222 
223  return true;
224 }
225 
227 {
228  return CTSSAMethod::createMethod(type);
229 }
230 
232 {
233  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
234  pCTSSATask =
235  dynamic_cast<CTSSATask *>((*(*CCopasiRootContainer::getDatamodelList())[0]->getTaskList())["Time Scale Separation Analysis"]);
236 
237  if (!pCTSSATask) return false;
238 
239  pTSSMethod = dynamic_cast<CTSSAMethod*>(pCTSSATask->getMethod());
240 
241  if (!pTSSMethod)
242  pTSSMethod->emptyVectors();
243 
244  if (!commonBeforeRunTask()) return false;
245 
246  bool success = true;
247 
248  if (!commonRunTask()) success = false;
249 
250  return success;
251 }
252 
254 {
255  bool success = true;
256  // We need to load the result here as this is the only place where
257  // we know that it is correct.
259  dynamic_cast< CQTSSAResultWidget * >(mpListView->findWidgetFromId(271));
260 
261  if (pResult == NULL)
262  {
263  return false;
264  }
265 
266  success &= pResult->loadFromBackend();
267 
268  pTSSResultSubWidget = pResult->getSubWidget();
269 
270  if (!pTSSResultSubWidget)
271  return false;
272 
273  pTSSResultSubWidget->discardOldResults();
274 
275 
276 
277  if (success)
278  {
279 
280  pTSSResultSubWidget->displayResult();
281 
282  mpListView->switchToOtherWidget(271, ""); //change to the results window
283  }
284 
285  return success;
286 }
287 
CILDMMethod * pILDM_Method
bool saveMethod()
Definition: TaskWidget.cpp:308
#define pdelete(p)
Definition: copasi.h:215
CILDMModifiedMethod * pILDMModiMethod
CQValidatorDouble * mpValidatorIntervalSize
Definition: CQTSSAWidget.h:59
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
CTSSATask * pCTSSATask
CCopasiProblem * getProblem()
void switchToOtherWidget(const size_t &id, const std::string &key)
Definition: listviews.cpp:926
bool loadCommon()
Definition: TaskWidget.cpp:247
void slotDuration()
void setStepNumber(const unsigned C_INT32 &stepNumber)
static std::string getAllMessageText(const bool &chronological=true)
bool saveCommon()
Definition: TaskWidget.cpp:258
static CTSSAMethod * createMethod(CCopasiMethod::SubType subType=CCopasiMethod::unset)
Definition: CTSSAMethod.cpp:44
bool loadMethod()
Definition: TaskWidget.cpp:284
static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
CQTSSAResultSubWidget * pTSSResultSubWidget
void slotIntervals()
void slotIntervalSize()
virtual bool runTask()
bool setTaskName(const std::string &name)
bool mChanged
Definition: TaskWidget.h:133
virtual bool loadTask()
const C_FLOAT64 & getStepSize() const
CTSSATask * pTask
CTSSAMethod * pTSSMethod
CopasiWidget * findWidgetFromId(const size_t &id) const
Definition: listviews.cpp:678
virtual CCopasiMethod * createMethod(const CCopasiMethod::SubType &type)
virtual void saved() const
Definition: CQValidator.h:71
virtual State revalidate()
Definition: CQValidator.h:63
ListViews * mpListView
Definition: copasiWidget.h:62
const unsigned C_INT32 & getStepNumber() const
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
CCopasiTask * mpTask
Definition: TaskWidget.h:130
CQTSSAWidget(QWidget *parent=0, const char *name=0)
void showMethodParameters(const bool &show)
CQTaskMethodWidget * mpMethodWidget
Definition: TaskWidget.h:123
CQTSSAResultSubWidget * getSubWidget()
const CArrayAnnotation * pResult
static const unsigned int ValidMethods[]
Definition: CTSSATask.h:50
virtual bool taskFinishedEvent()
void setStepSize(const C_FLOAT64 &stepSize)
CCopasiMethod * getMethod()
bool commonRunTask()
Definition: TaskWidget.cpp:395
CQTaskBtnWidget * mpBtnWidget
Definition: TaskWidget.h:124
CQTaskHeaderWidget * mpHeaderWidget
Definition: TaskWidget.h:122
void emptyVectors()
virtual bool saveTask()
void setRange(const C_FLOAT64 &lowerBound, const C_FLOAT64 &upperBound)
Definition: CQValidator.cpp:80
void setDuration(const C_FLOAT64 &duration)
bool commonBeforeRunTask()
Definition: TaskWidget.cpp:317
CQValidatorDouble * mpValidatorDuration
Definition: CQTSSAWidget.h:58
CTSSAProblem * mpTSSAProblem
Definition: CQTSSAWidget.h:57
void setValidMethods(const unsigned int *validMethods)
const C_FLOAT64 & getDuration() const
#define max(a, b)
Definition: f2c.h:176