COPASI API  4.16.103
CQMCAWidget.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/UI/CQMCAWidget.cpp,v $
3 // $Revision: 1.14 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/01/06 19:13:44 $
7 // End CVS Header
8 
9 // Copyright (C) 2011 - 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 "CQMCAWidget.h"
20 
21 #include "CMCAResultWidget.h"
22 #include "CQTaskBtnWidget.h"
23 #include "CQTaskHeaderWidget.h"
24 #include "CQTaskMethodWidget.h"
25 #include "CProgressBar.h"
26 #include "qtUtilities.h"
27 
29 #include "steadystate/CMCATask.h"
31 #include "steadystate/CMCAMethod.h"
32 #include "model/CModel.h"
33 #include "report/CKeyFactory.h"
36 
37 /*
38  * Constructs a CQMCAWidget which is a child of 'parent', with the
39  * name 'name'.'
40  */
41 CQMCAWidget::CQMCAWidget(QWidget* parent, const char* name)
42  : TaskWidget(parent, name)
43 {
44  setupUi(this);
45 
46  init();
47 }
48 
49 /*
50  * Destroys the object and frees any allocated resources
51  */
53 {
54  // no need to delete child widgets, Qt does it all for us
55 }
56 
58 {
60 }
61 
63 {
64  CMCATask * pTask =
66 
67  if (!pTask) return false;
68 
69  if (!commonBeforeRunTask()) return false;
70 
71  bool success = commonRunTask();
72 
73  return success;
74 }
75 
77 {
78  bool success = true;
80 
81  if (pResult) pResult->loadFromBackend();
82 
83  if (success && pResult)
84  mpListView->switchToOtherWidget(241, ""); //change to the results window
85 
86  return success;
87 }
88 
90 {return new CMCAMethod;}
91 
93 {
94  CMCATask * pTask = dynamic_cast< CMCATask * >(mpTask);
95 
96  if (!pTask) return false;
97 
98  loadCommon();
99 // loadMethod(); --> we cannot do that because of different structure -- 08.04.09
100 
101  CMCAProblem * pProblem =
102  dynamic_cast< CMCAProblem * >(mpTask->getProblem());
103 
104  if (!pProblem) return false;
105 
106  // instead calling loadMethod(), the following codes is used
107  mpCheckSteadyState->setChecked(pProblem->isSteadyStateRequested());
108 
109  bool success = loadParameterTable();
110 
111  mChanged = false;
112 
113  return success;
114 }
115 
117 {
118  CMCATask * pTask = dynamic_cast< CMCATask * >(mpTask);
119 
120  if (!pTask) return false;
121 
122  saveCommon();
123  // saveMethod();
124 
125  CMCAProblem * pProblem =
126  dynamic_cast< CMCAProblem * >(mpTask->getProblem());
127 
128  if (!pProblem) return false;
129 
130  if (mpCheckSteadyState->isChecked() != pProblem->isSteadyStateRequested())
131  {
132  pProblem->setSteadyStateRequested(mpCheckSteadyState->isChecked());
133  mChanged = true;
134  }
135 
136  bool success = saveParameterTable();
137 
138  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
139 
140  if (mChanged)(*CCopasiRootContainer::getDatamodelList())[0]->changed();
141 
142  mChanged = false;
143  return success;
144 }
145 
147 {
148  mpHeaderWidget->setTaskName("Metabolic Control Analysis");
149  mpHeaderWidget->mpUpdateModel->hide();
150 
151  vboxLayout->insertWidget(0, mpHeaderWidget); // header
152  // vboxLayout->insertSpacing(1, 14); // space between header and body
153 
155  vboxLayout->addWidget(mpMethodWidget);
156 
157  vboxLayout->addWidget(mpBtnWidget); // 'footer'
158 }
159 
161 {
162 
163  bool init = (mpMethodWidget->mpTableParameter->rowCount() == 0);
164 
165  size_t NumRows = mpMethod->size();
166  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
167 
168  if (mpCheckSteadyState->isChecked())
169  {
170  CSteadyStateTask * pSteadyStateTask =
171  dynamic_cast<CSteadyStateTask *>((*(*CCopasiRootContainer::getDatamodelList())[0]->getTaskList())["Steady-State"]);
172 
173  if (!pSteadyStateTask) return false;
174 
175  NumRows += pSteadyStateTask->getMethod()->size();
176  }
177 
178  mpMethodWidget->mpTableParameter->setRowCount((int) NumRows);
179 
180  size_t i, k;
182  QString value;
183 
184  for (i = 0; i < mpMethod->size() && init; i++)
185  {
186  mpMethodWidget->mpTableParameter->setVerticalHeaderItem((int) i, new QTableWidgetItem());
187  mpMethodWidget->mpTableParameter->verticalHeaderItem((int) i)->setText(FROM_UTF8(mpMethod->getName(i)));
188 
189  value = getParameterValue(mpMethod, i, &Type);
190  QTableWidgetItem *itemValue = new QTableWidgetItem(value);
191  itemValue->setTextAlignment(Qt::AlignRight);
192  mpMethodWidget->mpTableParameter->setItem((int) i, 0, itemValue);
193  }
194 
195  if (mpCheckSteadyState->isChecked())
196  {
197  CSteadyStateTask * pSteadyStateTask =
198  dynamic_cast<CSteadyStateTask *>((*(*CCopasiRootContainer::getDatamodelList())[0]->getTaskList())["Steady-State"]);
199 
200  if (!pSteadyStateTask) return false;
201 
202  CCopasiMethod * pMethod = pSteadyStateTask->getMethod();
203 
204  for (i = mpMethod->size(), k = 0; k < pMethod->size(); k++, i++)
205  {
206  // create item of the current row and give it a name
207  mpMethodWidget->mpTableParameter->setVerticalHeaderItem((int) i, new QTableWidgetItem());
208  mpMethodWidget->mpTableParameter->verticalHeaderItem((int) i)->setText(FROM_UTF8(pMethod->getName(k)));
209 
210  value = getParameterValue(pMethod, k, &Type);
211  QTableWidgetItem *itemValue = new QTableWidgetItem(value);
212  itemValue->setTextAlignment(Qt::AlignRight);
213  mpMethodWidget->mpTableParameter->setItem((int) i, 0, itemValue);
214  }
215  }
216 
217  // the table will be automatically adjusted -> 31.10.09
218 
219  return true;
220 }
221 
223 {
224  size_t i, k;
225  QString value;
227 
228  for (i = 0; i < mpMethod->size(); i++)
229  {
230  value = mpMethodWidget->mpTableParameter->item((int) i, 0)->text();
231 
232  if (value != getParameterValue(mpMethod, i, &Type))
233  {
234  setParameterValue(mpMethod, i, value);
235  mChanged = true;
236  }
237  }
238 
239  if (mpCheckSteadyState->isChecked())
240  {
241  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
242  CSteadyStateTask * pSteadyStateTask =
243  dynamic_cast<CSteadyStateTask *>((*(*CCopasiRootContainer::getDatamodelList())[0]->getTaskList())["Steady-State"]);
244 
245  if (!pSteadyStateTask) return false;
246 
247  CCopasiMethod * pMethod = pSteadyStateTask->getMethod();
248 
249  for (i = mpMethod->size(), k = 0; k < pMethod->size(); i++, k++)
250  {
251  value = mpMethodWidget->mpTableParameter->item((int) i, 0)->text();
252 
253  if (value != getParameterValue(pMethod, k, &Type))
254  {
255  setParameterValue(pMethod, k, value);
256  mChanged = true;
257  }
258  }
259  }
260 
261  return true;
262 }
virtual const std::string & getName(const size_t &index) const
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
CCopasiProblem * getProblem()
void switchToOtherWidget(const size_t &id, const std::string &key)
Definition: listviews.cpp:926
bool loadCommon()
Definition: TaskWidget.cpp:247
void setSteadyStateRequested(const bool &steadyStateRequested)
CCopasiObject * get(const std::string &key)
bool saveCommon()
Definition: TaskWidget.cpp:258
CQMCAWidget(QWidget *parent=0, const char *name=0)
Definition: CQMCAWidget.cpp:41
bool setParameterValue(CCopasiParameterGroup *group, const size_t &index, const QString &value)
Definition: qtUtilities.cpp:94
bool setTaskName(const std::string &name)
bool mChanged
Definition: TaskWidget.h:133
virtual void slotSteadyStateChecked()
Definition: CQMCAWidget.cpp:57
CTSSATask * pTask
CopasiWidget * findWidgetFromId(const size_t &id) const
Definition: listviews.cpp:678
bool isSteadyStateRequested() const
ListViews * mpListView
Definition: copasiWidget.h:62
virtual bool taskFinishedEvent()
Definition: CQMCAWidget.cpp:76
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
bool saveParameterTable()
CCopasiTask * mpTask
Definition: TaskWidget.h:130
QString getParameterValue(const CCopasiParameterGroup *group, const size_t &index, CCopasiParameter::Type *type)
Definition: qtUtilities.cpp:28
void showMethodParameters(const bool &show)
CQTaskMethodWidget * mpMethodWidget
Definition: TaskWidget.h:123
virtual bool runTask()
Definition: CQMCAWidget.cpp:62
const CArrayAnnotation * pResult
CCopasiMethod * getMethod()
static CKeyFactory * getKeyFactory()
bool commonRunTask()
Definition: TaskWidget.cpp:395
CQTaskBtnWidget * mpBtnWidget
Definition: TaskWidget.h:124
CQTaskHeaderWidget * mpHeaderWidget
Definition: TaskWidget.h:122
virtual bool loadTask()
Definition: CQMCAWidget.cpp:92
virtual bool saveTask()
CCopasiMethod * mpMethod
Definition: TaskWidget.h:131
bool commonBeforeRunTask()
Definition: TaskWidget.cpp:317
std::string mKey
Definition: copasiWidget.h:63
bool loadParameterTable()
virtual CCopasiMethod * createMethod(const CCopasiMethod::SubType &type)
Definition: CQMCAWidget.cpp:89