COPASI API  4.16.103
BandedGraphWidget.cpp
Go to the documentation of this file.
1 // Copyright (C) 2011 - 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 #include "BandedGraphWidget.h"
7 
9 #include "UI/qtUtilities.h"
10 #include "CQPlotEditWidget.h"
11 
12 #include "copasi.h"
13 
15 #include "plot/CPlotItem.h"
17 
18 /**
19  * In multiple edit mode, we don't want to edit name & channels
20  */
22 {
23  mpEditTitle->setEnabled(!mode);
24  mpEditX->setEnabled(!mode);
25  mpEditYone->setEnabled(!mode);
26  mpEditYtwo->setEnabled(!mode);
27  mpBtnX->setEnabled(!mode);
28  mpBtnYone->setEnabled(!mode);
29  mpBtnYtwo->setEnabled(!mode);
30 }
31 
32 /*
33  * Constructs a BandedGraphWidget as a child of 'parent', with the
34  * name 'name' and widget flags set to 'f'.
35  */
36 BandedGraphWidget::BandedGraphWidget(QWidget* parent, const char* /* name */, Qt::WindowFlags fl):
37  CQPlotEditWidget(parent, fl),
38  mpObjectYone(NULL),
39  mpObjectYtwo(NULL),
40  mpObjectX(NULL)
41 {
42  setupUi(this);
43 
45  mpBtnYone->setIcon(CQIconResource::icon(CQIconResource::copasi));
46  mpBtnYtwo->setIcon(CQIconResource::icon(CQIconResource::copasi));
47 }
48 
49 /*
50  * Destroys the object and frees any allocated resources
51  */
53 {
54  // no need to delete child widgets, Qt does it all for us
55 }
56 
57 bool
59 {
60  if (!curve)
61  {
62  // We need to reset the widget to defaults
63  mpEditTitle->setText("");
64 
66 
67  mpEditX->setText("");
68  mpEditYone->setText("");
69  mpEditYtwo->setText("");
70 
71  mpCheckBefore->setChecked(false);
72  mpCheckDuring->setChecked(true);
73  mpCheckAfter->setChecked(false);
74 
75  return true;
76  }
77 
78  if (curve->getType() != CPlotItem::bandedGraph) return false;
79 
80  //if (curve->getChannels().getSize != 3) return false;
81 
82  mpEditTitle->setText(FROM_UTF8(curve->getTitle()));
83 
84  //TODO: check if objects exist....
85  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
87  assert(pDataModel != NULL);
89 
90  if (curve->getChannels().size() >= 1)
91  mpObjectX = pDataModel->getDataObject(curve->getChannels()[0]);
92 
93  if (curve->getChannels().size() >= 2)
94  mpObjectYone = pDataModel->getDataObject(curve->getChannels()[1]);
95 
96  if (curve->getChannels().size() >= 3)
97  {
98  mpObjectYtwo = pDataModel->getDataObject(curve->getChannels()[2]);
99 
100  if ((mpObjectYtwo->getObjectDisplayName() == "(CN)Root") && mpObjectYone)
101  mpObjectYtwo = mpObjectYone; // as long as we haven't a second Y-axis chooser, this has to suffice.
102  }
103 
104  if (mpObjectX)
105  mpEditX->setText(FROM_UTF8(mpObjectX->getObjectDisplayName()));
106 
107  if (mpObjectYone)
108  mpEditYone->setText(FROM_UTF8(mpObjectYone->getObjectDisplayName()));
109 
110  if (mpObjectYtwo)
111  mpEditYtwo->setText(FROM_UTF8(mpObjectYtwo->getObjectDisplayName()));
112 
113  const void* tmp;
114 
115  if (!(tmp = curve->getValue("Line type").pVOID)) return false;
116 
117  mpCheckBefore->setChecked(curve->getActivity() & COutputInterface::BEFORE);
118  mpCheckDuring->setChecked(curve->getActivity() & COutputInterface::DURING);
119  mpCheckAfter->setChecked(curve->getActivity() & COutputInterface::AFTER);
120 
121  return true;
122 }
123 
124 bool
125 BandedGraphWidget::SaveToCurveSpec(CPlotItem * curve, const CPlotItem *original /*= NULL*/) const
126 {
127  //curve->setType(CPlotItem::bandedGraph);
128 
129  std::string title = TO_UTF8(mpEditTitle->text());
130 
134 
135  C_INT32 Activity = 0;
136 
137  if (mpCheckBefore->isChecked()) Activity += COutputInterface::BEFORE;
138 
139  if (mpCheckDuring->isChecked()) Activity += COutputInterface::DURING;
140 
141  if (mpCheckAfter->isChecked()) Activity += COutputInterface::AFTER;
142 
143  bool thingsChanged = false;
144 
145  if (original != NULL)
146  {
147  // compare whether things changed
148  if (original->getTitle() != title)
149  thingsChanged = true;
150 
151  if (thingsChanged || original->getType() != CPlotItem::bandedGraph)
152  thingsChanged = true;
153 
154  if (thingsChanged || original->getActivity() != Activity)
155  thingsChanged = true;
156 
157  if (thingsChanged || original->getChannels().size() != 3)
158  thingsChanged = true;
159 
160  if (thingsChanged || original->getChannels()[0] != xName)
161  thingsChanged = true;
162 
163  if (thingsChanged || original->getChannels()[1] != yName1)
164  thingsChanged = true;
165 
166  if (thingsChanged || original->getChannels()[2] != yName2)
167  thingsChanged = true;
168  }
169  else thingsChanged = true;
170 
171  if (!thingsChanged)
172  return false;
173 
174  //title
175  curve->setTitle(title);
176 
177  //channels
178  curve->getChannels().clear();
179  curve->getChannels().push_back(CPlotDataChannelSpec(xName));
180  curve->getChannels().push_back(CPlotDataChannelSpec(yName1));
181  curve->getChannels().push_back(CPlotDataChannelSpec(yName2));
182 
183  curve->setActivity((COutputInterface::Activity) Activity);
184 
185  return true;
186 }
187 
188 void
190 {
191  if (!mpModel) return;
192 
195  mpObjectX);
196 
197  if (mpObjectX)
198  {
199  mpEditX->setText(FROM_UTF8(mpObjectX->getObjectDisplayName()));
200 
201  if (mpObjectYone)
203  mpEditTitle->setText(FROM_UTF8(mpObjectYone->getObjectDisplayName()
204  + "/"
206  + "|"
208  else
209  mpEditTitle->setText(FROM_UTF8(mpObjectYone->getObjectDisplayName()
210  + "|"
212 
213  //TODO update tab title
214  }
215  else
216  mpEditX->setText("");
217 }
218 
219 void
221 {
222  if (!mpModel) return;
223 
226  mpObjectYone);
227 
228  if (mpObjectYone)
229  {
230  mpEditYone->setText(FROM_UTF8(mpObjectYone->getObjectDisplayName()));
231 
232  if (mpObjectX)
234  mpEditTitle->setText(FROM_UTF8(mpObjectYone->getObjectDisplayName()
235  + "/"
237  + "|"
239  else
240  mpEditTitle->setText(FROM_UTF8(mpObjectYone->getObjectDisplayName()
241  + "|"
243 
244  //TODO update tab title
245  }
246  else
247  mpEditYone->setText("");
248 }
249 
250 void
252 {
253  if (!mpModel) return;
254 
257  mpObjectYtwo);
258 
259  if (mpObjectYtwo)
260  {
261  mpEditYtwo->setText(FROM_UTF8(mpObjectYtwo->getObjectDisplayName()));
262 
263  if (mpObjectX)
265  mpEditTitle->setText(FROM_UTF8(mpObjectYone->getObjectDisplayName()
266  + "/"
268  + "|"
270  else
271  mpEditTitle->setText(FROM_UTF8(mpObjectYtwo->getObjectDisplayName()
272  + "|"
274 
275  //TODO update tab title
276  }
277  else
278  mpEditYtwo->setText("");
279 }
CCopasiObject * getDataObject(const CCopasiObjectName &CN) const
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
const CModel * mpModel
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
virtual CCopasiObjectName getCN() const
std::vector< CPlotDataChannelSpec > & getChannels()
Definition: CPlotItem.cpp:214
BandedGraphWidget(QWidget *parent=0, const char *name=0, Qt::WindowFlags fl=0)
void setActivity(const COutputInterface::Activity &activity)
Definition: CPlotItem.cpp:161
#define C_INT32
Definition: copasi.h:90
virtual void buttonPressedX()
const CCopasiObject * mpObjectYone
const CCopasiObject * mpObjectYtwo
static const QIcon & icon(const IconID &id)
const CPlotItem::Type & getType() const
Definition: CPlotItem.cpp:158
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
const COutputInterface::Activity & getActivity() const
Definition: CPlotItem.cpp:179
const CCopasiObject * mpObjectX
virtual bool SaveToCurveSpec(CPlotItem *curve, const CPlotItem *original=NULL) const
bool fl(const C_FLOAT64 &d1, const C_FLOAT64 &d2)
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
const CCopasiParameter::Value & getValue(const std::string &name) const
virtual void setMultipleEditMode(bool mode)
const std::string & getTitle() const
Definition: CPlotItem.cpp:228
virtual bool LoadFromCurveSpec(const CPlotItem *curve)
void setTitle(const std::string &title)
Definition: CPlotItem.cpp:233
static const CCopasiObject * getObjectSingle(QWidget *pParent, const CQSimpleSelectionTree::ObjectClasses &classes, const CCopasiObject *pCurrentObject=NULL)