COPASI API  4.16.103
CScanWidgetRandom.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2014 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) 2005 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #include <iostream>
16 
17 #include <QtGui/QValidator>
18 
19 #include "copasi.h"
20 
21 #include "CScanWidgetRandom.h"
22 #include "qtUtilities.h"
23 #include "CCopasiSelectionDialog.h"
25 
28 
29 /*
30  * Constructs a CScanWidgetRandom as a child of 'parent', with the
31  * name 'name' and widget flags set to 'f'.
32  */
34  QWidget(parent),
35  CScanItemData(CScanProblem::SCAN_RANDOM)
36 {
37  setupUi(this);
38  buttonObject->setIcon(CQIconResource::icon(CQIconResource::copasi));
39  init();
40  retranslateUi(this);
41 }
42 
44  QWidget(parent),
45  CScanItemData(src)
46 {
47  setupUi(this);
48  buttonObject->setIcon(CQIconResource::icon(CQIconResource::copasi));
49  init();
50  load(mpData);
51  retranslateUi(this);
52 }
53 
54 /*
55  * Destroys the object and frees any allocated resources
56  */
58 {
59  // no need to delete child widgets, Qt does it all for us
60 }
61 
63 {
64  lineEditObject->setReadOnly(true);
65 
66  lineEditMin->setValidator(new QDoubleValidator(lineEditMin));
67  lineEditMax->setValidator(new QDoubleValidator(lineEditMax));
68 
69  mpObject = NULL;
70 }
71 
73 {
74  const CCopasiObject * pObject =
78  mpObject);
79 
80  if (mpObject != pObject) // Object selection changed.
81  initFromObject(pObject);
82 }
83 
85 {
86  mpObject = obj;
87 
88  if (obj)
89  {
90  lineEditObject->setText(FROM_UTF8(obj->getObjectDisplayName()));
91 
92  if (obj->isValueDbl())
93  {
94  C_FLOAT64 value = *(C_FLOAT64*)obj->getValuePointer();
95  C_INT32 type = comboBoxType->currentIndex();
96 
97  if (type == 0) //uniform
98  {
99  lineEditMin->setText(QString::number(value * 0.5));
100  lineEditMax->setText(QString::number(value * 2));
101  }
102 
103  if (type == 1) //normal
104  {
105  lineEditMin->setText(QString::number(value));
106  lineEditMax->setText(QString::number(value * 0.1));
107  }
108 
109  if (type == 2) //poisson
110  {
111  lineEditMin->setText(QString::number(value));
112  lineEditMax->setText("");
113  }
114  }
115  }
116  else
117  {
118  lineEditObject->setText("");
119  lineEditMin->setText("");
120  lineEditMax->setText("");
121  }
122 }
123 
124 // virtual
126 {
127  if (pItem == NULL) return;
128 
129  *mpData = *pItem;
130 
131  unsigned C_INT32 * tmp;
132 
133  if (!(tmp = mpData->getValue("Type").pUINT))
134  return;
135 
137  return;
138 
139  std::string *pString;
140 
141  if (!(pString = mpData->getValue("Object").pSTRING))
142  return;
143 
144  if (*pString == "")
145  mpObject = NULL;
146  else
147  {
148  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
150  assert(pDataModel != NULL);
151  mpObject = pDataModel->getDataObject(*pString);
152  }
153 
154  if (mpObject)
155  lineEditObject->setText(FROM_UTF8(mpObject->getObjectDisplayName()));
156  else
157  lineEditObject->setText("");
158 
159  if (!(tmp = mpData->getValue("Distribution type").pUINT))
160  return;
161 
162  comboBoxType->setCurrentIndex(*tmp);
163  changeType();
164 
165  lineEditMin->setText(getParameterValue(mpData, "Minimum"));
166  lineEditMax->setText(getParameterValue(mpData, "Maximum"));
167 
168  bool * pBool;
169 
170  if (!(pBool = mpData->getValue("log").pBOOL))
171  return;
172 
173  checkBoxLog->setChecked(* pBool);
174 
175  return;
176 }
177 
178 // virtual
180 {
181  mpData->setValue("Distribution type", (unsigned C_INT32) comboBoxType->currentIndex());
182  mpData->setValue("Minimum", lineEditMin->text().toDouble());
183  mpData->setValue("Maximum", lineEditMax->text().toDouble());
184  mpData->setValue("log", checkBoxLog->isChecked());
185 
186  if (mpObject != NULL)
187  {
188  mpData->setValue("Object", mpObject->getCN());
189  }
190  else
191  {
192  mpData->setValue("Object", std::string(""));
193  }
194 
195  if (pItem != NULL)
196  {
197  if (*mpData == *pItem) return false;
198 
199  *pItem = *mpData;
200  return true;
201  }
202 
203  return false;
204 }
205 
207 {
208  C_INT32 type = comboBoxType->currentIndex();
209  C_FLOAT64 value = 0.0;
210 
211  if (mpObject != NULL)
212  value = *(C_FLOAT64*)mpObject->getValuePointer();
213 
214  switch (type)
215  {
216  case 0: // uniform
217  lineEditMin->setEnabled(true);
218  lineEditMax->setEnabled(true);
219 
220  labelMin->setText("min");
221  labelMax->setText("max");
222 
223  if (mpObject != NULL)
224  {
225  lineEditMin->setText(QString::number(value * 0.5));
226  lineEditMax->setText(QString::number(value * 2));
227  }
228  else
229  {
230  lineEditMin->setText("");
231  lineEditMax->setText("");
232  }
233 
234  break;
235 
236  case 1: // normal
237  lineEditMin->setEnabled(true);
238  lineEditMax->setEnabled(true);
239 
240  labelMin->setText("mean");
241  labelMax->setText("standard deviation");
242 
243  if (mpObject != NULL)
244  {
245  lineEditMin->setText(QString::number(value));
246  lineEditMax->setText(QString::number(value * 0.1));
247  }
248  else
249  {
250  lineEditMin->setText("");
251  lineEditMax->setText("");
252  }
253 
254  break;
255 
256  case 2: // Poisson
257  lineEditMin->setEnabled(true);
258  lineEditMax->setEnabled(false);
259 
260  labelMin->setText("mean");
261  labelMax->setText("");
262 
263  if (mpObject != NULL)
264  lineEditMin->setText(QString::number(value));
265  else
266  lineEditMin->setText("");
267 
268  lineEditMax->setText("");
269 
270  break;
271 
272  case 3: // Gamma
273  lineEditMin->setEnabled(true);
274  lineEditMax->setEnabled(true);
275 
276  labelMin->setText("shape");
277  labelMax->setText("scale");
278 
279  if (mpObject != NULL)
280  {
281  lineEditMin->setText(QString::number(1.0 * value));
282  lineEditMax->setText(QString::number(0.1));
283  }
284  else
285  {
286  lineEditMin->setText("");
287  lineEditMax->setText("");
288  }
289 
290  break;
291  }
292 }
CCopasiObject * getDataObject(const CCopasiObjectName &CN) const
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
const CCopasiObject * mpObject
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
void initFromObject(const CCopasiObject *obj)
virtual bool save(CCopasiParameterGroup *pItem) const
virtual CCopasiObjectName getCN() const
virtual void changeType()
CScanWidgetRandom(QWidget *parent=0)
virtual void load(const CCopasiParameterGroup *pItem)
#define C_INT32
Definition: copasi.h:90
static const QIcon & icon(const IconID &id)
CCopasiParameterGroup * mpData
Definition: CScanItemData.h:42
bool setValue(const std::string &name, const CType &value)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
unsigned C_INT32 * pUINT
QString getParameterValue(const CCopasiParameterGroup *group, const size_t &index, CCopasiParameter::Type *type)
Definition: qtUtilities.cpp:28
#define C_FLOAT64
Definition: copasi.h:92
bool isValueDbl() const
const CCopasiParameter::Value & getValue(const std::string &name) const
virtual void * getValuePointer() const
virtual void slotChooseObject()
static const CCopasiObject * getObjectSingle(QWidget *pParent, const CQSimpleSelectionTree::ObjectClasses &classes, const CCopasiObject *pCurrentObject=NULL)