COPASI API  4.16.103
CQSteadyStateResult.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/UI/CQSteadyStateResult.cpp,v $
3 // $Revision: 1.4 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/04/16 19:25:47 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 - 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 #include "UI/CopasiFileDialog.h"
15 #include "UI/CQMessageBox.h"
16 #include "UI/qtUtilities.h"
17 #include "CQSteadyStateResult.h"
18 
19 #include "copasi.h"
20 
24 #include "model/CModel.h"
26 
27 /*
28  * Constructs a CQSteadyStateResult which is a child of 'parent', with the
29  * name 'name'.'
30  */
31 CQSteadyStateResult::CQSteadyStateResult(QWidget* parent, const char* name)
32  : CopasiWidget(parent, name)
33 {
34  setupUi(this);
35 
36  init();
37 }
38 
39 /*
40  * Destroys the object and frees any allocated resources
41  */
43 {
44  // no need to delete child widgets, Qt does it all for us
45 }
46 
48 {
49  mpProblem = NULL;
50  mpTask = NULL;
51  mUpToDate = false;
52 }
53 
55  ListViews::Action /* action */,
56  const std::string & /* key */)
57 {
58  if (objectType != ListViews::STATE)
59  mUpToDate = false;
60 
61  return true;
62 }
63 
65 {
66  return true;
67 }
68 
70 {
71  return true;
72 }
73 
75 {
76  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
77  mpTask =
78  dynamic_cast<CSteadyStateTask *>((*(*CCopasiRootContainer::getDatamodelList())[0]->getTaskList())["Steady-State"]);
79 
80  if (!mpTask) return;
81 
82  mpProblem = dynamic_cast<const CSteadyStateProblem *>(mpTask->getProblem());
83 
84  if (!mpProblem) return;
85 
86  if (!mpTask) return;
87 
88  if (!mpTask->getState())
89  {
90  mpCentralWidget->clear();
91  mUpToDate = false;
92  return;
93  }
94 
95  mpCentralWidget->loadAll(mpTask);
96  mUpToDate = true;
97 
98  return;
99 }
100 
101 
103 {
104  C_INT32 Answer = QMessageBox::No;
105  QString fileName;
106 
107  while (Answer == QMessageBox::No)
108  {
109  fileName =
110  CopasiFileDialog::getSaveFileName(this, "Save File Dialog",
111  "untitled.txt", "TEXT Files (*.txt)", "Save to");
112 
113  if (fileName.isEmpty()) return;
114 
115  // Checks whether the file exists
116  Answer = checkSelection(fileName);
117 
118  if (Answer == QMessageBox::Cancel) return;
119  }
120 
121  std::ofstream file(CLocaleString::fromUtf8(TO_UTF8(fileName)).c_str());
122 
123  if (file.fail()) return;
124 
125  if (mpTask != NULL)
126  file << *mpTask;
127 
128  return;
129 }
130 
132 {
133  if (mUpToDate &&
134  mpTask != NULL &&
135  mpProblem != NULL &&
136  mpTask->getState() != NULL)
137  {
138  CModel *pModel = mpProblem->getModel();
139 
140  if (pModel != NULL)
141  {
142  pModel->compileIfNecessary(NULL);
143 
144  if (mpTask->isUpdateModel())
145  {
146  mpTask->restore();
147  }
148  else
149  {
150  mpTask->setUpdateModel(true);
151  mpTask->restore();
152  mpTask->setUpdateModel(false);
153  }
154 
156  }
157  }
158 }
objectType
virtual bool update(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
CCopasiProblem * getProblem()
const bool & isUpdateModel() const
const CState * getState() const
#define C_INT32
Definition: copasi.h:90
C_INT32 checkSelection(const QString &file)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
const std::string & getKey() const
Definition: CModel.cpp:1142
virtual bool protectedNotify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
CQSteadyStateResult(QWidget *parent=0, const char *name=0)
bool compileIfNecessary(CProcessReport *pProcessReport)
Definition: CModel.cpp:612
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
Definition: CModel.h:50
const CSteadyStateProblem * mpProblem
static CLocaleString fromUtf8(const std::string &utf8)
void setUpdateModel(const bool &updateModel)
virtual bool enterProtected()
virtual bool restore()
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)
CSteadyStateTask * mpTask