COPASI API  4.16.103
CQSensResultWidget.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) 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 "CQSensResultWidget.h"
18 
19 #include <QtGui/QMessageBox>
20 
21 #include "qtUtilities.h"
24 
28 
29 #include "UI/CopasiFileDialog.h"
32 
33 /*
34  * Constructs a CQSensResultWidget which is a child of 'parent', with the
35  * name 'name' and widget flags set to 'f'.
36  */
37 CQSensResultWidget::CQSensResultWidget(QWidget* parent, const char* name, Qt::WFlags fl)
38  : CopasiWidget(parent, name, fl),
39  mpResult(NULL)
40 {
41  setupUi(this);
42 
43  init();
44 }
45 
46 /*
47  * Destroys the object and frees any allocated resources
48  */
50 {}
51 
53 {
54  // unscaled array
55  CColorScaleBiLog * tcs = new CColorScaleBiLog();
56  mArrayWidget->setColorCoding(tcs);
57  mArrayWidget->setColorScalingAutomatic(true);
58 
59  //scaled array
61  mArrayWidgetScaled->setColorCoding(tcs2);
62  tcs2->setFactor(3.0);
63  mArrayWidgetScaled->setColorScalingAutomatic(true);
64 
65  //scaled array
67  mArrayWidgetCollapsed->setColorCoding(tcs3);
68  tcs3->setFactor(3.0);
69  mArrayWidgetCollapsed->setColorScalingAutomatic(true);
70 }
71 
73 {
74  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
75 
76  // clear the old one
77  clearArrays();
78 
79  CSensTask * pTask =
80  dynamic_cast<CSensTask*>((*(*CCopasiRootContainer::getDatamodelList())[0]->getTaskList())["Sensitivities"]);
81 
82  if (!pTask)
83  return;
84 
85  CSensProblem * pProblem = dynamic_cast< CSensProblem * >(pTask->getProblem());
86 
87  if (!pProblem)
88  return;
89 
90  mpResult = pProblem->getResultAnnotated();
92 
93  mArrayWidget->setArrayAnnotation(mpResult);
94  mArrayWidgetScaled->setArrayAnnotation(mpScaledResult);
95 
96  //tab for collapsed result
97  if (pProblem->collapsRequested())
98  {
100  mpTab->setTabEnabled(mpTab->indexOf(mArrayWidgetCollapsed), true);
101  }
102  else
103  {
104  mpCollapsedResult = NULL;
105  mpTab->setTabEnabled(mpTab->indexOf(mArrayWidgetCollapsed), false);
106  }
107 
108  mArrayWidgetCollapsed->setArrayAnnotation(mpCollapsedResult);
109 }
110 
112 {
113  mArrayWidget->setArrayAnnotation(NULL);
114  mArrayWidgetScaled->setArrayAnnotation(NULL);
115  mArrayWidgetCollapsed->setArrayAnnotation(NULL);
116 }
117 
118 //*************************************
119 
121  C_UNUSED(action), const std::string & C_UNUSED(key))
122 {
123  /* if (this->isShown())
124  return loadFromBackend();
125  else
126  return true;*/
127  return true;
128 }
129 
131 {
132  return true;
133 }
134 
136 {
137  //clear the widget if the pointer to the result has changed
138  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
139  CSensTask * pTask =
140  dynamic_cast<CSensTask*>((*(*CCopasiRootContainer::getDatamodelList())[0]->getTaskList())["Sensitivities"]);
141 
142  if (!pTask)
143  {
144  clearArrays();
145  return false;
146  }
147 
148  CSensProblem * pProblem = dynamic_cast< CSensProblem * >(pTask->getProblem());
149 
150  if (!pProblem)
151  {
152  clearArrays();
153  return false;
154  }
155 
156  if (mpResult != pProblem->getResultAnnotated())
157  {
158  clearArrays();
159  return false;
160  }
161 
162  return true;
163 }
164 
166 {
167  C_INT32 Answer = QMessageBox::No;
168  QString fileName;
169 
170  while (Answer == QMessageBox::No)
171  {
172  fileName =
173  CopasiFileDialog::getSaveFileName(this, "Save File Dialog",
174  "untitled.txt", "TEXT Files (*.txt)", "Save to");
175 
176  if (fileName.isEmpty()) return;
177 
178  // Checks whether the file exists
179  Answer = checkSelection(fileName);
180 
181  if (Answer == QMessageBox::Cancel) return;
182  }
183 
184  std::ofstream file(CLocaleString::fromUtf8(TO_UTF8(fileName)).c_str());
185 
186  if (file.fail())
187  return;
188 
189  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
190  CSensTask * pTask =
191  dynamic_cast<CSensTask*>((*(*CCopasiRootContainer::getDatamodelList())[0]->getTaskList())["Sensitivities"]);
192 
193  if (pTask != NULL)
194  file << pTask->getResult();
195 
196 // pTask->print(&file);
197 
198  return;
199 }
const CArrayAnnotation * mpResult
bool collapsRequested() const
objectType
CCopasiProblem * getProblem()
CArrayAnnotation * getCollapsedResultAnnotated()
const CArrayAnnotation * mpCollapsedResult
#define C_UNUSED(p)
Definition: copasi.h:220
#define C_INT32
Definition: copasi.h:90
CArrayAnnotation * getScaledResultAnnotated()
CTSSATask * pTask
virtual bool update(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
CArrayAnnotation * getResultAnnotated()
C_INT32 checkSelection(const QString &file)
CQSensResultWidget(QWidget *parent=0, const char *name=0, Qt::WFlags fl=0)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
virtual bool enterProtected()
const CArrayAnnotation * mpScaledResult
void setFactor(C_FLOAT64 f)
Definition: CColorScale.h:171
const CResult & getResult() const
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)
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)