COPASI API  4.16.103
CQLyapResultWidget.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 "CQLyapResultWidget.h"
18 
19 #include <QtGui/QMessageBox>
20 
21 #include "qtUtilities.h"
22 
25 #include "report/CKeyFactory.h"
26 #include "model/CModel.h"
27 #include "lyap/CLyapProblem.h"
29 
30 #include "UI/CopasiFileDialog.h"
31 
32 /*
33  * Constructs a CQLyapResultWidget which is a child of 'parent', with the
34  * name 'name' and widget flags set to 'f'.
35  */
36 CQLyapResultWidget::CQLyapResultWidget(QWidget* parent, const char* name, Qt::WFlags fl)
37  : CopasiWidget(parent, name, fl)
38 {
39  setupUi(this);
40 
41  init();
42 }
43 
44 /*
45  * Destroys the object and frees any allocated resources
46  */
48 {}
49 
51 {
52  /*
53  mSaveButton->setEnabled(false);
54  mSaveButton->hide();
55  */
56 }
57 
58 /* This function loads the optimization result widget when its name is
59  clicked in the tree */
61 {
62  //bool success = true;
63  //std::ostringstream os;
64 
65  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
66  mpTask = dynamic_cast<CLyapTask*>((*(*CCopasiRootContainer::getDatamodelList())[0]->getTaskList())["Lyapunov Exponents"]);
67 
68  if (!mpTask) return false;
69 
70  CLyapProblem * pProblem = dynamic_cast< CLyapProblem * >(mpTask->getProblem());
71 
72  if (!pProblem) return false;
73 
74  if (!mpTask->resultAvailable())
75  {
76  mTableExponents->setEnabled(false);
77  mTableExponents->setRowCount(0);
78  mLineEditSum->setEnabled(false);
79  mLineEditSum->setText("");
80  mLineEditDivergence->setEnabled(false);
81  mLineEditDivergence->setText("");
82  mLabelComment->setText("No result available.");
83  return false;
84  }
85 
86  mTableExponents->setEnabled(true);
87  mLineEditSum->setEnabled(true);
88  mLineEditDivergence->setEnabled(true);
89 
90  unsigned C_INT32 i, imax = pProblem->getExponentNumber();
91 
92  mTableExponents->setRowCount(imax);
93 
94  for (i = 0; i < imax; ++i)
95  {
96  QTableWidgetItem *pItem = mTableExponents->item(i, 0);
97 
98  if (pItem == NULL)
99  {
100  pItem = new QTableWidgetItem(QString::number(mpTask->exponents()[i]));
101  pItem->setFlags(Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
102  mTableExponents->setItem(i, 0, pItem);
103  }
104  else
105  {
106  pItem->setText(QString::number(mpTask->exponents()[i]));
107  }
108  }
109 
110  mLineEditSum->setText(QString::number(mpTask->sumOfExponents()));
111 
113  {
114  mLineEditDivergence->setEnabled(true);
115  mLineEditDivergence->setText(QString::number(mpTask->averageDivergence()));
116  }
117  else
118  {
119  mLineEditDivergence->setEnabled(false);
120  mLineEditDivergence->setText("");
121  }
122 
123  //comment
124  mLabelComment->setText("");
125 
128  {
129  if ((mpTask->sumOfExponents() < 0.0) && (mpTask->averageDivergence() < 0.0))
130  {
132 
133  if (factor > 1.01)
134  mLabelComment->setText("Warning: Divergence differs from sum of exponents. This may indicate that the strongly negative exponents are calculated inaccuratly.");
135  }
136  }
137 
138  return true;
139 }
140 
142  C_UNUSED(action), const std::string & C_UNUSED(key))
143 {
144  if (this->isVisible())
145  return loadFromBackend();
146  else
147  return true;
148 }
149 
151 {
152  return true;
153 }
154 
156 {
157  return loadFromBackend();
158 }
159 
161 {
162  C_INT32 Answer = QMessageBox::No;
163  QString fileName;
164 
165  while (Answer == QMessageBox::No)
166  {
167  fileName =
168  CopasiFileDialog::getSaveFileName(this, "Save File Dialog",
169  "untitled.txt", "TEXT Files (*.txt)", "Save to");
170 
171  if (fileName.isEmpty()) return;
172 
173  // Checks whether the file exists
174  Answer = checkSelection(fileName);
175 
176  if (Answer == QMessageBox::Cancel) return;
177  }
178 
179  std::ofstream file(CLocaleString::fromUtf8(TO_UTF8(fileName)).c_str());
180 
181  if (file.fail())
182  return;
183 
184  if (mpTask != NULL)
185  mpTask->printResult(&file);
186 
187  return;
188 }
const C_FLOAT64 & averageDivergence() const
Definition: CLyapTask.h:135
const CVector< C_FLOAT64 > & exponents() const
Definition: CLyapTask.h:126
size_t modelVariablesInResult() const
Definition: CLyapTask.cpp:330
objectType
CCopasiProblem * getProblem()
virtual bool update(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
size_t numberOfExponentsCalculated() const
Definition: CLyapTask.cpp:335
bool resultAvailable() const
Definition: CLyapTask.cpp:320
virtual bool enterProtected()
#define C_UNUSED(p)
Definition: copasi.h:220
#define C_INT32
Definition: copasi.h:90
C_INT32 checkSelection(const QString &file)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
const unsigned C_INT32 & getExponentNumber() const
const C_FLOAT64 & sumOfExponents() const
Definition: CLyapTask.h:132
void printResult(std::ostream *ostream) const
Definition: CLyapTask.cpp:292
#define C_FLOAT64
Definition: copasi.h:92
bool fl(const C_FLOAT64 &d1, const C_FLOAT64 &d2)
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
bool resultHasDivergence() const
Definition: CLyapTask.cpp:325
static CLocaleString fromUtf8(const std::string &utf8)
CQLyapResultWidget(QWidget *parent=0, const char *name=0, Qt::WFlags fl=0)
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)