COPASI API  4.16.103
CQTSSAResultSubWidget.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 // Copyright (C) 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #include "CQTSSAResultSubWidget.h"
16 #include "CQMessageBox.h"
17 
18 #include "qtUtilities.h"
19 #include "CopasiFileDialog.h"
20 
22 #include "tssanalysis/CTSSATask.h"
26 #include "model/CModel.h"
27 
29 
30 /*
31  * Constructs a CQTSSAResultSubWidget as a child of 'parent', with the
32  * name 'name' and widget flags set to 'f'.
33  */
34 CQTSSAResultSubWidget::CQTSSAResultSubWidget(QWidget* parent, const char* name, Qt::WindowFlags fl)
35  : CopasiWidget(parent, name, fl)
36 {
37  setupUi(this);
38 
39  init();
40 }
41 
42 /*
43  * Destroys the object and frees any allocated resources
44  */
46 {
47  // no need to delete child widgets, Qt does it all for us
48 }
49 
51 {
52  C_INT32 Answer = QMessageBox::No;
53  QString fileName;
54 
55  while (Answer == QMessageBox::No)
56  {
57  fileName =
58  CopasiFileDialog::getSaveFileName(this, "Save File Dialog",
59  "untitled.txt", "Text Files (*.txt)", "Save to");
60 
61  if (fileName.isEmpty()) return;
62 
63  // Checks whether the file exists
64  Answer = checkSelection(fileName);
65 
66  if (Answer == QMessageBox::Cancel) return;
67  }
68 
69  std::ofstream file(CLocaleString::fromUtf8(TO_UTF8(fileName)).c_str());
70 
71  if (file.fail()) return;
72 
73  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
74  CCopasiTask* mpTask =
75  dynamic_cast<CTSSATask *>((*(*CCopasiRootContainer::getDatamodelList())[0]->getTaskList())["Time Scale Separation Analysis"]);
76 
77  if (!mpTask) return;
78 
79  CCopasiProblem* mpProblem = mpTask->getProblem();
80 
81  mpProblem->printResult(&file);
82 
83 
84  return;
85 }
86 
87 
89 {
90 
91  std::string name = static_cast<std::string >(mpBox1->currentText().toUtf8());
92 
93 
94  if (name == "Reactions slow space" ||
95  name == "Reactions contribution to the mode" ||
96  name == "Reactions distribution between modes " ||
97  name == "Reactions fast space" ||
98  name == "Participation Index" ||
99  name == "Fast Participation Index" ||
100  name == "Slow Participation Index" ||
101  name == "Normed Participation Index (by column)" ||
102  name == "Normed Participation Index (by row)" ||
103  name == "Importance Index" ||
104  name == "Normed Importance Index (by row)")
105  {
107  tcs->setSymmetric(true);
108  mpArrayWidget->setColorCoding(tcs);
109  mpArrayWidget->setColorScalingAutomatic(true);
110  }
111  else
112  {
113  //CColorScaleAdvanced * tcs = new CColorScaleAdvanced() ;
114  //tcs->setColorMin(QColor(240, 240, 240));
115  //tcs->setColorMax(QColor(0, 255, 0));
116 
118  tcs->setSymmetric(true);
119 
120  mpArrayWidget->setColorCoding(tcs);
121  mpArrayWidget->setColorScalingAutomatic(true);
122 
123  }
124 
125 
126  pResult = pMethod->getTable(name);
127  mpArrayWidget->setArrayAnnotation(pResult);
128 
129 
130 }
131 
132 
133 //set time and step number
135 {
136 
137  int s = mpSlider->value();
138 
139  if (s > 1)
140  mpLabelTime->setNum((double)pMethod->returnCurrentTime(s - 1));
141  else
142  mpLabelTime->setNum(0);
143 
144  mpLabelStep->setNum(s);
145 }
146 
147 //switch between time scale and table views
149 {
150 
151  if (mpIndex == 0)
152  {
153 
154  mpTimeScaleWidget->show();
155  mpArrayWidget->hide();
156  mpBox1->hide();
157  mpButton->setText("Show Tables");
158  mpIndex = 1;
159 
160  }
161  else
162  {
163  mpTimeScaleWidget->hide();
164  mpBox1->show();
165  mpArrayWidget->show();
166  mpButton->setText("Show Time scales");
167  mpIndex = 0;
168  }
169 }
170 
172 {
173  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
174  pTSSATask =
175  dynamic_cast<CTSSATask *>((*(*CCopasiRootContainer::getDatamodelList())[0]->getTaskList())["Time Scale Separation Analysis"]);
176 
177  if (!pTSSATask) return;
178 
179  pProblem = dynamic_cast<CTSSAProblem*>(pTSSATask->getProblem());
180  pModel = pProblem->getModel();
181 
182  pMethod = dynamic_cast<CTSSAMethod*>(pTSSATask->getMethod());
183 
184  mpLabelTime->setNum(0);
185  mpLabelStep->setNum(0);
186 
187  connect(mpBox1, SIGNAL(currentIndexChanged(int)), this, SLOT(slotTableChanged(/* int */)));
188 
189  //set colorsettings for ArrayAnnotationWidgets
190 
192  tcs->setColorMin(QColor(240, 240, 240));
193  tcs->setColorMax(QColor(0, 255, 0));
194  mpArrayWidget->setColorCoding(tcs);
195  mpArrayWidget->setColorScalingAutomatic(true);
196 
197 
198  connect(mpSlider, SIGNAL(valueChanged(int)), this, SLOT(changeInterval()));
199  connect(mpButton, SIGNAL(clicked()), this, SLOT(changeContents()));
200  connect(ButtonSaveData, SIGNAL(clicked()), this, SLOT(saveDataToFile()));
201 
202  mpBox1->setEditable(false);
203 
204  mpIndex = 0;
205  mpTimeScaleWidget->hide();
206  mpBox1->show();
207  mpArrayWidget->show();
208 
209 }
210 
212 {
213 
214  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
215  pTSSATask =
216  dynamic_cast<CTSSATask *>((*(*CCopasiRootContainer::getDatamodelList())[0]->getTaskList())["Time Scale Separation Analysis"]);
217 
218  if (!pTSSATask) return;
219 
220  pProblem = dynamic_cast<CTSSAProblem*>(pTSSATask->getProblem());
221 
222  pModel = pProblem->getModel();
223 
224  pMethod = dynamic_cast<CTSSAMethod*>(pTSSATask->getMethod());
225 
226  QString a = FROM_UTF8(pModel->getTimeUnitName());
227 
228  mpSlider->setRange(1, pProblem->getStepNumber());
229 
230  mpSlider->setValue(mpSlider->minimum());
231 
232 
233  mpBox1->clear();
234 
235  unsigned C_INT i;
236 
237  for (i = 0; i < pMethod->getTableName().size(); i++)
238  {
239  mpBox1->insertItem(0, FROM_UTF8(pMethod->getTableName()[i]));
240  }
241 
242  mpArrayWidget->switchToTable();
243  mpSlider->setDisabled(false);
244 
245  changeInterval();
246 }
247 
248 /**
249  * Clear ArrayAnnotation-widgets.
250  **/
252 {
253  mpArrayWidget->setArrayAnnotation(NULL);
254  mpArrayWidget->clearWidget();
255  mpTimeScaleWidget->clearWidget();
256 }
257 
258 /**
259  * Get the results for the requested step from the method.
260  * Fill widgets with this results.
261  **/
262 
264 {
265 
267 
268  int s = mpSlider->value();
269 
270  if (pMethod->setAnnotationM(s - 1))
271  {
272  std::string name = static_cast<std::string >(mpBox1->currentText().toUtf8());
273  pResult = pMethod->getTable(name);
274 
275  mpArrayWidget->setArrayAnnotation(pResult);
276 
278  mpTimeScaleWidget->paintTimeScale(vec);
279  }
280  else
281  {
282 
283  //mpSlider->setDisabled(true);
284  mpArrayWidget->setArrayAnnotation(NULL);
285  mpTimeScaleWidget->clearWidget();
286 
287  }
288 }
289 
290 
void setSymmetric(bool s)
Definition: CColorScale.h:120
#define C_INT
Definition: copasi.h:115
const CArrayAnnotation * getTable(std::string name)
Definition: CTSSAMethod.h:103
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
CCopasiProblem * getProblem()
void setColorMax(QColor col)
std::string getTimeUnitName() const
Definition: CModel.cpp:2238
#define C_INT32
Definition: copasi.h:90
const std::vector< std::string > getTableName() const
Definition: CTSSAMethod.h:100
C_INT32 checkSelection(const QString &file)
const unsigned C_INT32 & getStepNumber() const
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
void setColorMin(QColor col)
virtual bool setAnnotationM(size_t s)=0
CVector< C_FLOAT64 > getVec_TimeScale(int step)
CQTSSAResultSubWidget(QWidget *parent=0, const char *name=0, Qt::WindowFlags fl=0)
const CArrayAnnotation * pResult
CCopasiMethod * getMethod()
Header file of class CArrayAnnotation.
C_FLOAT64 returnCurrentTime(int step)
bool fl(const C_FLOAT64 &d1, const C_FLOAT64 &d2)
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
static CLocaleString fromUtf8(const std::string &utf8)
virtual void printResult(std::ostream *ostream) const
CModel * getModel() const
static QString getSaveFileName(QWidget *parent=0, const char *name=0, const QString &startWith=QString::null, const QString &filter=QString::null, const QString &caption=QString::null, QString *pSelectedFilter=NULL, QFileDialog::Options options=0)