COPASI API  4.16.103
CQUpdatesWidget.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 // 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 #include <QtGui/QTableWidget>
12 #include <QtGui/QTableWidgetItem>
13 
14 #include "copasi.h"
15 
16 #include "CQUpdatesWidget.h"
17 #include "qtUtilities.h"
18 
21 
22 #include "model/CModel.h"
23 
24 #include <QtGui/QTabWidget>
25 
26 /**
27  * Constructs a CQUpdatesWidget which is a child of 'parent', with the
28  * name 'name' and widget flags set to 'f'.
29  */
30 CQUpdatesWidget::CQUpdatesWidget(QWidget* parent, const char* name, Qt::WFlags fl)
31  : CopasiWidget(parent, name, fl)
32 {
33  if (!name)
34  setObjectName("CQUpdatesWidget");
35 
36  setWindowTitle("CQUpdatesWidget");
37 
38  mWidgetLayout = new QGridLayout(this);
39  mWidgetLayout->setMargin(11);
40  mWidgetLayout->setSpacing(6);
41  mWidgetLayout->setObjectName("CQUpdatesWidgetLayout");
42 
43  // ********** Label **************
44  mLabelTitle = new QLabel(this);
45  mLabelTitle->setObjectName("updatesLabel");
46  mLabelTitle->setText("Sequences of assignments");
47  mLabelTitle->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
48  mLabelTitle->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
49  mWidgetLayout->addWidget(mLabelTitle, 0, 0);
50 
51  //main tab widget
52  mpMainTab = new QTabWidget(this);
53  mpMainTab->setObjectName("MainTabWidget");
54  mWidgetLayout->addWidget(mpMainTab,1,0,2,3);
55 
56  // tab widget
57  mpTab = new QTabWidget(mpMainTab);
58  mpTab->setObjectName("TabWidget");
59  mpMainTab->addTab(mpTab, "Update Sequences");
60 
61  // 0
62  mpTable0 = new QTableWidget(mpTab);
63  mpTab->addTab(mpTable0, "Initial Assignments");
64 
65  // 1
66  mpTable1 = new QTableWidget(mpTab);
67  mpTab->addTab(mpTable1, "Constant Assignments");
68 
69  // 2
70  mpTable2 = new QTableWidget(mpTab);
71  mpTab->addTab(mpTable2, "Assignments during Simulation");
72 
73  // 3
74  mpTable3 = new QTableWidget(mpTab);
75  mpTab->addTab(mpTable3, "Assignments for output");
76 
77  // tab widget 2
78  mpTab2 = new QTabWidget(mpMainTab);
79  mpTab2->setObjectName("TabWidget2");
80  mpMainTab->addTab(mpTab2, "Object Lists");
81 
82  //objects table
83  mpTableObj = new QTableWidget(mpTab2);
84  mpTab2->addTab(mpTableObj, "Species");
85 
86  //state table
87  mpTableState = new QTableWidget(mpTab2);
88  mpTab2->addTab(mpTableState, "State");
89 }
90 
92 {}
93 
95 {
96  if (obj->getRefresh())
97  mRefreshsMap[obj->getRefresh()] = obj;
98 
99  //recursion
100  if (obj->isContainer())
101  {
102  CCopasiContainer* container;
103  container = (CCopasiContainer*)obj;
104 
105  CCopasiContainer::objectMap::const_iterator it = container->getObjects().begin();
106  // int cnt = container->getObjects().size();
107 
108  for (; it != container->getObjects().end(); ++it)
109  {
110  //the next line skips name references...
111  if (it->second->getObjectName() == "Name") continue;
112 
113  if (it->second->getObjectType() == "Function") continue;
114 
115  //skip if the contained object is not owned by this container
116  if (it->second->getObjectParent() != container) continue;
117 
118  fillRefreshsMapRecursively(it->second);
119  }
120 
121  //return;
122  }
123 }
124 
126 {
127 
128  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
129  CModel* pModel = (*CCopasiRootContainer::getDatamodelList())[0]->getModel();
130 
131  if (!pModel) return;
132 
133  pModel->compileIfNecessary(NULL);
134  mRefreshsMap.clear();
136 
141 
142  loadObjectsTable(pModel);
143 }
144 
145 void CQUpdatesWidget::loadOneTable(QTableWidget * pTable, const std::vector< Refresh * > & list)
146 {
147  pTable->setColumnCount(2);
148 
149  size_t i, imax = list.size();
150  pTable->setRowCount((int) imax);
151 
152  for (i = 0; i < imax; ++i)
153  {
154  std::map<const Refresh*, const CCopasiObject*>::const_iterator it = mRefreshsMap.find(list[i]);
155 
156  if (it != mRefreshsMap.end() && it->second)
157  pTable->setItem((int) i, 0, new QTableWidgetItem(FROM_UTF8(it->second->getObjectDisplayName())));
158 
159  const CCopasiObject* tmp = list[i]->getObject();
160 
161  if (tmp)
162  pTable->setItem((int) i, 1, new QTableWidgetItem(FROM_UTF8(tmp->getObjectDisplayName())));
163  }
164 }
165 
167 {}
168 
170 {
171  if (!pModel) return;
172 
173  mpTableObj->setColumnCount(5);
174  mpTableObj->setRowCount(0);
175 
176  mpTableObj->setHorizontalHeaderItem(0, new QTableWidgetItem("User order"));
177  mpTableObj->setHorizontalHeaderItem(1, new QTableWidgetItem("status"));
178  mpTableObj->setHorizontalHeaderItem(2, new QTableWidgetItem(""));
179  mpTableObj->setHorizontalHeaderItem(3, new QTableWidgetItem("Reduced system"));
180  mpTableObj->setHorizontalHeaderItem(4, new QTableWidgetItem("status"));
181 
182  size_t i, imax;
183 
184  //metabolites
185  imax = pModel->getMetabolites().size();
186 
187  if ((int) imax > mpTableObj->rowCount()) mpTableObj->setRowCount((int) imax);
188 
189  for (i = 0; i < imax; ++i)
190  {
191  mpTableObj->setVerticalHeaderItem((int) i, new QTableWidgetItem(QString::number(i)));
192 
193  CMetab* pM = pModel->getMetabolites()[i];
194 
195  QColor c(100, 100, 100);
196 
197  if (pM->getStatus() == CModelEntity::FIXED) c = QColor(150, 150, 150);
198 
199  if (pM->getStatus() == CModelEntity::ASSIGNMENT) c = QColor(250, 150, 250);
200 
201  if (pM->getStatus() == CModelEntity::REACTIONS) c = QColor(250, 250, 200);
202 
203  if (pM->getStatus() == CModelEntity::ODE) c = QColor(150, 250, 250);
204 
205  if (pM->getStatus() == CModelEntity::TIME) c = QColor(250, 150, 150);
206 
207  mpTableObj->setItem((int) i, 0, new QTableWidgetItem(FROM_UTF8(pM->getObjectName())));
208 
209  //mpTableObj->setText(i, 0, FROM_UTF8(pM->getObjectName()));
210  std::string tmpString = CModelEntity::StatusName[pM->getStatus()];
211 
212  if (pM->isUsed())
213  tmpString += " (Used = true, ";
214  else
215  tmpString += " (Used = false, ";
216 
217  mpTableObj->setItem((int) i, 1, new QTableWidgetItem(FROM_UTF8(tmpString)));
218  //mpTableObj->setText(i, 1, FROM_UTF8(tmpString));
219  }
220 
221  mpTableObj->resizeColumnToContents(0);
222  mpTableObj->resizeColumnToContents(1);
223  mpTableObj->setColumnWidth(2, 10);
224 
225  //metabolitesX
226  imax = pModel->getMetabolitesX().size();
227 
228  if ((int) imax > mpTableObj->rowCount()) mpTableObj->setRowCount((int) imax);
229 
230  for (i = 0; i < imax; ++i)
231  {
232  CMetab* pM = pModel->getMetabolitesX()[i];
233 
234  QColor c(100, 100, 100);
235 
236  if (pM->getStatus() == CModelEntity::FIXED) c = QColor(150, 150, 150);
237 
238  if (pM->getStatus() == CModelEntity::ASSIGNMENT) c = QColor(250, 150, 250);
239 
240  if (pM->getStatus() == CModelEntity::REACTIONS) c = QColor(250, 250, 200);
241 
242  if (pM->getStatus() == CModelEntity::ODE) c = QColor(150, 250, 250);
243 
244  if (pM->getStatus() == CModelEntity::TIME) c = QColor(250, 150, 150);
245 
246  mpTableObj->setItem((int) i, 3, new QTableWidgetItem(FROM_UTF8(pM->getObjectName())));
247  //mpTableObj->setText(i, 3, FROM_UTF8(pM->getObjectName()));
248 
249  std::string tmpString = CModelEntity::StatusName[pM->getStatus()];
250 
251  if (pM->isUsed())
252  tmpString += " (Used = true, ";
253  else
254  tmpString += " (Used = false, ";
255 
256  mpTableObj->setItem((int) i, 4, new QTableWidgetItem(FROM_UTF8(tmpString)));
257  }
258 
259  mpTableObj->resizeColumnToContents(3);
260  mpTableObj->resizeColumnToContents(4);
261 
262  //state
263  const CStateTemplate & st = pModel->getStateTemplate();
264  imax = st.size();
265  mpTableState->setRowCount(0);
266  mpTableState->setRowCount((int)(imax + 1));
267  mpTableState->setColumnCount(5);
268  mpTableState->setHorizontalHeaderItem(0, new QTableWidgetItem("Name"));
269  mpTableState->setHorizontalHeaderItem(1, new QTableWidgetItem("status"));
270  mpTableState->setHorizontalHeaderItem(2, new QTableWidgetItem(""));
271  mpTableState->setHorizontalHeaderItem(3, new QTableWidgetItem("ATol(1)"));
272  mpTableState->setHorizontalHeaderItem(4, new QTableWidgetItem("SS criterion(1)"));
273 
274  for (i = 0; i < imax; ++i)
275  {
276  mpTableState->setVerticalHeaderItem((int) i, new QTableWidgetItem(QString::number(i)));
277 
278  CModelEntity* pME = *(st.getEntities() + i);
279 
280  //first column
281  QColor c(100, 100, 100);
282 
283  if (dynamic_cast<CModel*>(pME)) c = QColor(250, 100, 100);
284 
285  if (dynamic_cast<CMetab*>(pME)) c = QColor(250, 250, 150);
286 
287  if (dynamic_cast<CCompartment*>(pME)) c = QColor(100, 250, 100);
288 
289  if (dynamic_cast<CModelValue*>(pME)) c = QColor(100, 100, 250);
290 
291  mpTableState->setItem((int) i, 0, new QTableWidgetItem(FROM_UTF8(pME->getObjectDisplayName())));
292  // mpTableState->setText(i, 0,FROM_UTF8(pME->getObjectDisplayName()));
293 
294  //second column
295  std::string tmpString = CModelEntity::StatusName[pME->getStatus()];
296 
297  if (pME->isUsed())
298  tmpString += " (Used = true, ";
299  else
300  tmpString += " (Used = false, ";
301 
302  c = QColor(100, 100, 100);
303 
304  if (pME->getStatus() == CModelEntity::FIXED) c = QColor(150, 150, 150);
305 
306  if (pME->getStatus() == CModelEntity::ASSIGNMENT) c = QColor(250, 150, 250);
307 
308  if (pME->getStatus() == CModelEntity::REACTIONS) c = QColor(250, 250, 200);
309 
310  if (pME->getStatus() == CModelEntity::ODE) c = QColor(150, 250, 250);
311 
312  if (pME->getStatus() == CModelEntity::TIME) c = QColor(250, 150, 150);
313 
314  mpTableState->setItem((int) i, 1, new QTableWidgetItem(FROM_UTF8(tmpString)));
315  //mpTableState->setText(i, 1, FROM_UTF8(tmpString));
316  }
317 
318  QColor c(200, 250, 250);
319 
320  for (i = st.beginIndependent() - st.getEntities(); i < (size_t)(st.endIndependent() - st.getEntities()); ++i)
321  mpTableState->setItem((int) i, 2, new QTableWidgetItem(""));
322 
323  c = QColor(250, 200, 250);
324 
325  for (i = st.beginDependent() - st.getEntities(); i < (size_t)(st.endDependent() - st.getEntities()); ++i)
326  mpTableState->setItem((int) i, 2, new QTableWidgetItem(""));
327 
328  c = QColor(200, 200, 200);
329 
330  for (i = st.beginFixed() - st.getEntities(); i < (size_t)(st.endFixed() - st.getEntities()); ++i)
331  mpTableState->setItem((int) i, 2, new QTableWidgetItem(""));
332 
333  int tmpint = st.beginIndependent() - st.getEntities();
334  mpTableState->setItem(tmpint, 2, new QTableWidgetItem("beginIndependent "));
335  tmpint = st.endIndependent() - st.getEntities();
336  mpTableState->setItem(tmpint, 2, new QTableWidgetItem(mpTableState->item(tmpint, 2)->text() + "endIndependent "));
337 
338  tmpint = st.beginDependent() - st.getEntities();
339  mpTableState->setItem(tmpint, 2, new QTableWidgetItem(mpTableState->item(tmpint, 2)->text() + "beginDependent "));
340  tmpint = st.endDependent() - st.getEntities();
341  mpTableState->setItem(tmpint, 2, new QTableWidgetItem(mpTableState->item(tmpint, 2)->text() + "endDependent "));
342 
343  tmpint = st.beginFixed() - st.getEntities();
344  mpTableState->setItem(tmpint, 2, new QTableWidgetItem(mpTableState->item(tmpint, 2)->text() + "beginFixed "));
345  tmpint = st.endFixed() - st.getEntities();
346  mpTableState->setItem(tmpint, 2, new QTableWidgetItem("endFixed "));
347 
348  //add absolute Tolerances to table
349  CVector< C_FLOAT64 > atolv = pModel->initializeAtolVector(1, false);
350  tmpint = st.beginIndependent() - st.getEntities();
351 
352  for (i = 0; i < atolv.size(); ++i)
353  {
354  mpTableState->setItem((int) i + tmpint, 3, new QTableWidgetItem(QString::number(atolv[i])));
355 
356  CModelEntity* pME = *(st.getEntities() + i + 1);
357  C_FLOAT64 tmp = std::min(atolv[i], std::max(100.0 * std::numeric_limits< C_FLOAT64 >::min(), fabs(pME->getInitialValue())));
358  mpTableState->setItem((int) i + tmpint, 4, new QTableWidgetItem(QString::number(tmp)));
359  }
360 
361  mpTableState->resizeColumnToContents(0);
362  mpTableState->resizeColumnToContents(1);
363  mpTableState->resizeColumnToContents(2);
364  mpTableState->resizeColumnToContents(3);
365  mpTableState->resizeColumnToContents(4);
366 }
367 
368 //*************************************
369 
371  C_UNUSED(action), const std::string & C_UNUSED(key))
372 {
373  return true;
374 }
375 
377 {
378  return true;
379 }
380 
382 {
383  loadWidget();
384 
385  return true;
386 }
virtual Refresh * getRefresh() const
bool isContainer() const
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
objectType
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
static const std::string StatusName[]
Definition: CModelValue.h:67
const CCopasiVector< CMetab > & getMetabolites() const
Definition: CModel.cpp:1051
const std::string & getObjectName() const
QGridLayout * mWidgetLayout
virtual size_t size() const
const std::vector< Refresh * > & getListOfConstantRefreshes() const
Definition: CModel.cpp:4139
virtual const objectMap & getObjects() const
QTableWidget * mpTableState
CModelEntity ** endDependent()
Definition: CState.cpp:211
QTableWidget * mpTable3
#define C_UNUSED(p)
Definition: copasi.h:220
Definition: CMetab.h:178
const size_t & size() const
Definition: CState.cpp:242
const std::vector< Refresh * > & getListOfSimulatedRefreshes() const
Definition: CModel.cpp:4136
CModelEntity ** beginDependent()
Definition: CState.cpp:210
const C_FLOAT64 & getInitialValue() const
const std::vector< Refresh * > & getListOfNonSimulatedRefreshes() const
Definition: CModel.cpp:4142
CModelEntity ** endFixed()
Definition: CState.cpp:213
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
CModelEntity ** beginFixed()
Definition: CState.cpp:212
CModelEntity ** beginIndependent()
Definition: CState.cpp:208
CQUpdatesWidget(QWidget *parent=0, const char *name=0, Qt::WFlags fl=0)
void loadOneTable(QTableWidget *pTable, const std::vector< Refresh * > &list)
QTabWidget * mpTab2
const bool & isUsed() const
void fillRefreshsMapRecursively(const CCopasiObject *obj)
QTabWidget * mpMainTab
size_t size() const
Definition: CVector.h:100
virtual bool leave()
void loadObjectsTable(CModel *pModel)
#define C_FLOAT64
Definition: copasi.h:92
bool compileIfNecessary(CProcessReport *pProcessReport)
Definition: CModel.cpp:612
const CStateTemplate & getStateTemplate() const
Definition: CModel.cpp:1172
bool fl(const C_FLOAT64 &d1, const C_FLOAT64 &d2)
virtual bool update(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
CVector< C_FLOAT64 > initializeAtolVector(const C_FLOAT64 &baseTolerance, const bool &reducedModel) const
Definition: CModel.cpp:4368
Definition: CModel.h:50
const std::vector< Refresh * > & getListOfInitialRefreshes() const
Definition: CModel.cpp:4133
const CModelEntity::Status & getStatus() const
const CCopasiVector< CMetab > & getMetabolitesX() const
Definition: CModel.cpp:1057
QTabWidget * mpTab
QLabel * mLabelTitle
QTableWidget * mpTableObj
std::map< const Refresh *, const CCopasiObject * > mRefreshsMap
CModelEntity ** endIndependent()
Definition: CState.cpp:209
#define min(a, b)
Definition: f2c.h:175
virtual bool enterProtected()
CModelEntity ** getEntities()
Definition: CState.cpp:204
QTableWidget * mpTable1
QTableWidget * mpTable0
QTableWidget * mpTable2
#define max(a, b)
Definition: f2c.h:176