COPASI API  4.16.103
CQExpandModelData.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) 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 
12 #include "model/CModelExpansion.h"
14 //#include "UI/CCopasiSelectionDialog.h"
15 
16 #include "UI/qtUtilities.h"
17 
18 #include <QtCore/QString>
19 #include <QtGui/QIntValidator>
20 #include "CQExpandModelData.h"
21 
22 CQExpandModelData::CQExpandModelData(QWidget* parent, Qt::WindowFlags fl)
23  : QDialog(parent, fl)
24 {
25  setupUi(this);
26 
27  mpLineEditSizeX->setValidator(new QIntValidator(1, 10000, this));
28  mpLineEditSizeY->setValidator(new QIntValidator(1, 10000, this));
29 
30  load();
31 }
32 
34 {
35  // no need to delete child widgets, Qt does it all for us
36 }
37 
39 {
40  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
41 
42  pModel = (*CCopasiRootContainer::getDatamodelList())[0]->getModel();
43 
44  size_t i, imax = pModel->getCompartments().size();
45 
46  for (i = 0; i < imax; ++i)
47  {
48  QTreeWidgetItem * pItem = new QTreeWidgetItem((QTreeWidget*)NULL, 1000);
49  pItem->setText(0, FROM_UTF8(pModel->getCompartments()[i]->getObjectName()));
50  pItem->setCheckState(0, Qt::Unchecked);
52  mpTreeWidget->addTopLevelItem(pItem);
53  }
54 
55  connect(mpTreeWidget, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotCompartmentActivated(QTreeWidgetItem*, int)));
56 
57  connect(mpRadioButtonLin, SIGNAL(toggled(bool)), this, SLOT(slotMode()));
58  connect(mpRadioButtonRec, SIGNAL(toggled(bool)), this, SLOT(slotMode()));
59 }
60 
61 void CQExpandModelData::slotCompartmentActivated(QTreeWidgetItem* pItem, int col)
62 {
63  //only do something if a checkbox in the first column is clicked
64  if (col != 0)
65  return;
66 
67  const CCompartment* pComp = NULL;
68  std::map<QTreeWidgetItem*, const CCompartment*>::const_iterator it = mItemCompartmentMap.find(pItem);
69 
70  if (it != mItemCompartmentMap.end())
71  pComp = it->second;
72 
73  if (!pComp)
74  return;
75 
76  //checked
77  if (pItem->checkState(0) == Qt::Checked)
78  {
79  size_t i, imax = pComp->getMetabolites().size();
80 
81  for (i = 0; i < imax; ++i)
82  {
83  QTreeWidgetItem * pChild = new QTreeWidgetItem(pItem, 1001);
84  pChild->setText(0, FROM_UTF8(pComp->getMetabolites()[i]->getObjectName()));
85  pChild->setCheckState(1, Qt::Unchecked);
86  mItemMetabMap[pChild] = pComp->getMetabolites()[i];
87  }
88 
89  pItem->setExpanded(true);
90  }
91 
92  //unchecked
93  if (pItem->checkState(0) == Qt::Unchecked)
94  {
95  //remove children
96  size_t i, imax = pItem->childCount();
97 
98  for (i = 0; i < imax; ++i)
99  {
100  pItem->removeChild(pItem->child(0));
101  }
102  }
103 }
104 
106 {
108  std::set<std::string> metabkeys;
109 
110  std::map<QTreeWidgetItem*, const CCompartment*>::const_iterator it;
111 
112  for (it = mItemCompartmentMap.begin(); it != mItemCompartmentMap.end(); ++it)
113  {
114  if (it->first->checkState(0) == Qt::Checked)
115  {
116  //the compartment is included
117  modelelements.addCompartment(it->second);
118 
119  //check whether diffusion is requested for the metabolites inside
120  size_t i;
121 
122  for (i = 0; i < it->first->childCount(); ++i)
123  {
124  if (it->first->child(i)->checkState(1) == Qt::Checked)
125  {
126  std::map<QTreeWidgetItem*, const CMetab*>::const_iterator itMetab = mItemMetabMap.find(it->first->child(i));
127  //const CMetab* pMetab = NULL;
128 
129  if (itMetab != mItemMetabMap.end())
130  metabkeys.insert(itMetab->second->getKey());
131  }
132  }
133  }
134  }
135 
137  modelelements.fillDependencies(pModel);
138 
139  int multx, multy;
140  multx = mpLineEditSizeX->text().toInt();
141  multy = mpLineEditSizeY->text().toInt();
142 
143  if (mpRadioButtonLin->isChecked())
144  me.createLinearArray(modelelements, multx, metabkeys);
145  else if (mpRadioButtonRec->isChecked())
146  me.createRectangularArray(modelelements, multx, multy, metabkeys);
147 
148  accept();
149 
150  // std::string name = static_cast<std::string >(mpBoxCompartmentName->currentText().toUtf8()); //toStdString();
151 }
152 
154 {
155  reject();
156 }
157 
159 {
160  if (mpRadioButtonLin->isChecked())
161  {
162  mpLabelCross->setEnabled(false);
163  mpLineEditSizeY->setEnabled(false);
164  }
165  else if (mpRadioButtonRec->isChecked())
166  {
167  mpLabelCross->setEnabled(true);
168  mpLineEditSizeY->setEnabled(true);
169  }
170 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
CCopasiVectorNS< CMetab > & getMetabolites()
const std::string & getObjectName() const
virtual size_t size() const
void slotMode()
handles change of linear/rectangular mode
void slotCompartmentActivated(QTreeWidgetItem *pItem, int col)
handles activation or deactivation of a compartment
void createRectangularArray(const SetOfModelElements &source, size_t nx, size_t ny, const std::set< std::string > &setOfMetabolites)
std::map< QTreeWidgetItem *, const CMetab * > mItemMetabMap
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
void createLinearArray(const SetOfModelElements &source, size_t n, const std::set< std::string > &setOfMetabolites)
void fillDependencies(const CModel *pModel)
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
void addCompartment(const CCompartment *x)
bool fl(const C_FLOAT64 &d1, const C_FLOAT64 &d2)
std::map< QTreeWidgetItem *, const CCompartment * > mItemCompartmentMap
CQExpandModelData(QWidget *parent=0, Qt::WindowFlags fl=0)
if(!yymsg) yymsg