COPASI API  4.16.103
CQSimpleSelectionTree.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/UI/CQSimpleSelectionTree.cpp,v $
3 // $Revision: 1.7 $
4 // $Name: $
5 // $Author: nsimus $
6 // $Date: 2012/06/04 11:09:39 $
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 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
20 // Properties, Inc. and EML Research, gGmbH.
21 // All rights reserved.
22 
23 #include "copasi.h"
24 
25 #include "CQSimpleSelectionTree.h"
26 #include "model/CModel.h"
27 #include "model/CMetab.h"
28 #include "model/CReaction.h"
31 #include "report/CCopasiObject.h"
33 #include "report/CCopasiTimer.h"
35 #include "qtUtilities.h"
36 
40 #include "utilities/CCopasiTask.h"
41 #include "steadystate/CMCAMethod.h"
44 #include "tssanalysis/CCSPMethod.h"
45 #include "tssanalysis/CTSSATask.h"
46 
47 
49  QTreeWidget(parent), mpOutputVector(NULL)
50 {
51  setSelectionMode(QAbstractItemView::ExtendedSelection);
52  setSortingEnabled(true);
53  sortByColumn(0, Qt::AscendingOrder);
54  setHeaderLabels(QStringList("Sort"));
55  setRootIsDecorated(true);
56  setSizePolicy(QSizePolicy((QSizePolicy::Policy)7, (QSizePolicy::Policy)7));
57  mpExpertSubtree = new QTreeWidgetItem(this, QStringList("Expert"));
58 
59  mpResultMatrixSubtree = new QTreeWidgetItem(this, QStringList("Results"));
60  mpResultSteadyStateSubtree = new QTreeWidgetItem(mpResultMatrixSubtree, QStringList("Steady State"));
61  mpResultSensitivitySubtree = new QTreeWidgetItem(mpResultMatrixSubtree, QStringList("Sensitivity"));
62  mpResultMCASubtree = new QTreeWidgetItem(mpResultMatrixSubtree, QStringList("Metabolic Control Analysis"));
63  mpResultTSSASubtree = new QTreeWidgetItem(mpResultMatrixSubtree, QStringList("Time Scale Separation Analysis"));
64 
65  mpModelMatrixSubtree = new QTreeWidgetItem(this, QStringList("Matrices"));
66 
67  mpModelQuantitySubtree = new QTreeWidgetItem(this, QStringList("Global Quantities"));
69  new QTreeWidgetItem(mpModelQuantitySubtree, QStringList("Rates"));
71  new QTreeWidgetItem(mpModelQuantitySubtree, QStringList("Transient Values"));
73  new QTreeWidgetItem(mpModelQuantitySubtree, QStringList("Initial Values"));
74 
75  mpReactionSubtree = new QTreeWidgetItem(this, QStringList("Reactions"));
77  new QTreeWidgetItem(mpReactionSubtree, QStringList("Fluxes (Particle Numbers)"));
79  new QTreeWidgetItem(mpReactionSubtree, QStringList("Fluxes (Amount)"));
81  new QTreeWidgetItem(mpReactionSubtree, QStringList("Reaction Parameters"));
82 
83  mpMetaboliteSubtree = new QTreeWidgetItem(this, QStringList("Species"));
85  new QTreeWidgetItem(mpMetaboliteSubtree, QStringList("Rates (Particle Numbers)"));
87  new QTreeWidgetItem(mpMetaboliteSubtree, QStringList("Rates (Concentrations)"));
89  new QTreeWidgetItem(mpMetaboliteSubtree, QStringList("Transient Particle Numbers"));
91  new QTreeWidgetItem(mpMetaboliteSubtree, QStringList("Transient Concentrations"));
93  new QTreeWidgetItem(mpMetaboliteSubtree, QStringList("Initial Particle Numbers"));
95  new QTreeWidgetItem(mpMetaboliteSubtree, QStringList("Initial Concentrations"));
96 
97  mpCompartmentSubtree = new QTreeWidgetItem(this, QStringList("Compartments"));
99  new QTreeWidgetItem(mpCompartmentSubtree, QStringList("Rates"));
101  new QTreeWidgetItem(mpCompartmentSubtree, QStringList("Transient Volumes"));
103  new QTreeWidgetItem(mpCompartmentSubtree, QStringList("Initial Volumes"));
104 
105  mpTimeSubtree = new QTreeWidgetItem(this, QStringList("Time"));
106 }
107 
108 /// Destructor
110 {}
111 
112 /*
113  * build the population tree
114  */
116  const ObjectClasses & classes)
117 {
118  if (!pModel) return;
119 
120  const CCopasiObject * pObject;
121  QTreeWidgetItem * pItem;
122 
123  // find all kinds of time
124  pObject = pModel->getValueReference();
125 
126  if (filter(classes, pObject))
127  {
128  pItem = new QTreeWidgetItem(mpTimeSubtree, QStringList("Model Time"));
129  treeItems[pItem] = pObject;
130  }
131 
132  pObject = pModel->getInitialValueReference();
133 
134  if (filter(classes, pObject))
135  {
136  pItem = new QTreeWidgetItem(mpTimeSubtree, QStringList("Model Initial Time"));
137  treeItems[pItem] = pObject;
138  }
139 
140  pObject = pModel->getObjectDataModel()->getDataObject(CCopasiObjectName("Timer=CPU Time"));
141 
142  if (filter(classes, pObject))
143  {
144  pItem = new QTreeWidgetItem(mpTimeSubtree, QStringList("CPU time"));
145  treeItems[pItem] = pObject;
146  }
147 
148  pObject = pModel->getObjectDataModel()->getDataObject(CCopasiObjectName("Timer=Wall Clock Time"));
149 
150  if (filter(classes, pObject))
151  {
152  pItem = new QTreeWidgetItem(mpTimeSubtree, QStringList("real time"));
153  treeItems[pItem] = pObject;
154  }
155 
157 
158  // find all species (aka metabolites) and create items in the metabolite subtree
159  const CCopasiVector<CMetab>& metabolites = pModel->getMetabolites();
160  size_t counter;
161  size_t maxCount = metabolites.size();
162 
163  for (counter = maxCount; counter != 0; --counter)
164  {
165  const CMetab* metab = metabolites[counter - 1];
166  std::string name = metab->getObjectName();
167  bool unique = isMetaboliteNameUnique(name, metabolites);
168 
169  if (!unique)
170  {
171  const CCompartment* comp = metab->getCompartment();
172 
173  if (comp)
174  {
175  name = name + "(" + comp->getObjectName() + ")";
176  }
177  }
178 
179  pObject = metab->getInitialValueReference();
180 
181  if (filter(classes, pObject))
182  {
183  pItem = new QTreeWidgetItem(mpMetaboliteInitialNumberSubtree, QStringList(FROM_UTF8(name + "(t=0)")));
184  treeItems[pItem] = pObject;
185  }
186 
187  pObject = metab->getValueReference();
188 
189  if (filter(classes, pObject))
190  {
191  pItem = new QTreeWidgetItem(mpMetaboliteTransientNumberSubtree, QStringList(FROM_UTF8(name + "(t)")));
192  treeItems[pItem] = pObject;
193  }
194 
195  if (metab->getStatus() != CModelEntity::ASSIGNMENT)
196  {
197  pObject = metab->getRateReference();
198 
199  if (filter(classes, pObject))
200  {
201  pItem = new QTreeWidgetItem(mpMetaboliteRateNumberSubtree, QStringList(FROM_UTF8("d(" + name + ")/dt")));
202  treeItems[pItem] = pObject;
203  }
204  }
205 
206  name = "[" + name + "]"; // Concentration
207  pObject = metab->getInitialConcentrationReference();
208 
209  if (filter(classes, pObject))
210  {
211  pItem = new QTreeWidgetItem(mpMetaboliteInitialConcentrationSubtree, QStringList(FROM_UTF8(name + "(t=0)")));
212  treeItems[pItem] = pObject;
213  }
214 
215  pObject = metab->getConcentrationReference();
216 
217  if (filter(classes, pObject))
218  {
219  pItem = new QTreeWidgetItem(mpMetaboliteTransientConcentrationSubtree, QStringList(FROM_UTF8(name + "(t)")));
220  treeItems[pItem] = pObject;
221  }
222 
223  if (metab->getStatus() != CModelEntity::ASSIGNMENT)
224  {
225  pObject = metab->getConcentrationRateReference();
226 
227  if (filter(classes, pObject))
228  {
229  pItem = new QTreeWidgetItem(mpMetaboliteRateConcentrationSubtree, QStringList(FROM_UTF8("d(" + name + ")/dt")));
230  treeItems[pItem] = pObject;
231  }
232  }
233  }
234 
242 
243  // find all reactions and create items in the reaction subtree
244  const CCopasiVectorNS<CReaction>& reactions = pModel->getReactions();
245  maxCount = reactions.size();
246 
247  for (counter = maxCount; counter != 0; --counter)
248  {
249  const CReaction* react = reactions[counter - 1];
250  std::string name = "flux(" + react->getObjectName() + ")";
251 
252  pObject = static_cast< const CCopasiObject * >(react->getObject(CCopasiObjectName("Reference=Flux")));
253 
254  if (filter(classes, pObject))
255  {
256  pItem = new QTreeWidgetItem(mpReactionFluxConcentrationSubtree, QStringList(FROM_UTF8(name)));
257  treeItems[pItem] = pObject;
258  }
259 
260  pObject = static_cast< const CCopasiObject * >(react->getObject(CCopasiObjectName("Reference=ParticleFlux")));
261 
262  if (filter(classes, pObject))
263  {
264  pItem = new QTreeWidgetItem(mpReactionFluxNumberSubtree, QStringList(FROM_UTF8("particle " + name)));
265  treeItems[pItem] = pObject;
266  }
267 
268  // create items for the reaction parameters
269 
270  pItem = new QTreeWidgetItem(mpReactionParameterSubtree,
271  QStringList(FROM_UTF8(react->getObjectName())));
273  size_t j;
274  size_t numParameters = Parameters.size();
275 
276  for (j = numParameters; j != 0; --j)
277  {
278  const CCopasiParameter * pParameter = Parameters.getParameter(j - 1);
279 
280  // We skip local parameters which ar covered by global parameters
281  if (!react->isLocalParameter(pParameter->getObjectName()))
282  continue;
283 
284  pObject = static_cast< const CCopasiObject * >(pParameter->getObject(CCopasiObjectName("Reference=Value")));
285 
286  if (filter(classes, pObject))
287  {
288  QTreeWidgetItem * pParameterItem =
289  new QTreeWidgetItem(pItem, QStringList(FROM_UTF8(pParameter->getObjectName())));
290  treeItems[pParameterItem] = pObject;
291  }
292  }
293 
294  removeEmptySubTree(&pItem);
295  }
296 
301 
302  // find all global parameters (aka model values) variables
303  const CCopasiVector<CModelValue>& objects = pModel->getModelValues();
304  maxCount = objects.size();
305 
306  for (counter = maxCount; counter != 0; --counter)
307  {
308  const CModelEntity* object = objects[counter - 1];
309  std::string name = object->getObjectName();
310 
311  pObject = object->getInitialValueReference();
312 
313  if (filter(classes, pObject))
314  {
315  pItem = new QTreeWidgetItem(mpModelQuantityInitialValueSubtree, QStringList(FROM_UTF8(name + "(t=0)")));
316  treeItems[pItem] = pObject;
317  }
318 
319  pObject = object->getValueReference();
320 
321  if (filter(classes, pObject))
322  {
323  pItem = new QTreeWidgetItem(mpModelQuantityTransientValueSubtree, QStringList(FROM_UTF8(name + "(t)")));
324  treeItems[pItem] = pObject;
325  }
326 
327  if (object->getStatus() != CModelEntity::ASSIGNMENT)
328  {
329  pObject = object->getRateReference();
330 
331  if (filter(classes, pObject))
332  {
333  pItem = new QTreeWidgetItem(mpModelQuantityRateSubtree, QStringList(FROM_UTF8("d(" + name + ")/dt")));
334  treeItems[pItem] = pObject;
335  }
336  }
337  }
338 
343 
344  // find all compartments
345  const CCopasiVector<CCompartment>& objects2 = pModel->getCompartments();
346  maxCount = objects2.size();
347 
348  for (counter = maxCount; counter != 0; --counter)
349  {
350  const CModelEntity* object = objects2[counter - 1];
351  std::string name = object->getObjectName();
352 
353  pObject = object->getInitialValueReference();
354 
355  if (filter(classes, pObject))
356  {
357  pItem = new QTreeWidgetItem(mpCompartmentInitialVolumeSubtree, QStringList(FROM_UTF8(name + "(t=0)")));
358  treeItems[pItem] = pObject;
359  }
360 
361  pObject = object->getValueReference();
362 
363  if (filter(classes, pObject))
364  {
365  pItem = new QTreeWidgetItem(mpCompartmentTransientVolumeSubtree, QStringList(FROM_UTF8(name + "(t)")));
366  treeItems[pItem] = pObject;
367  }
368 
369  if (object->getStatus() != CModelEntity::ASSIGNMENT)
370  {
371  pObject = object->getRateReference();
372 
373  if (filter(classes, pObject))
374  {
375  pItem = new QTreeWidgetItem(mpCompartmentRateSubtree, QStringList(FROM_UTF8("d(" + name + ")/dt")));
376  treeItems[pItem] = pObject;
377  }
378  }
379  }
380 
385 
386  pObject = static_cast< const CCopasiObject * >(pModel->getObject(CCopasiObjectName("Reference=Avogadro Constant")));
387 
388  if (filter(classes, pObject))
389  {
390  pItem = new QTreeWidgetItem(this, QStringList("Avogadro Constant"));
391  treeItems[pItem] = pObject;
392  }
393 
394  pObject = static_cast< const CCopasiObject * >(pModel->getObject(CCopasiObjectName("Reference=Quantity Conversion Factor")));
395 
396  if (filter(classes, pObject))
397  {
398  pItem = new QTreeWidgetItem(this, QStringList("Quantity Conversion Factor"));
399  treeItems[pItem] = pObject;
400  }
401 
402  // find all model matrices
403  const CMatrix<C_FLOAT64> &StoiMatrix = pModel->getStoi();
404 
405  if (StoiMatrix.array())
406  {
407  pObject = static_cast< const CCopasiObject * >(pModel->getObject(CCopasiObjectName("Array=Stoichiometry(ann)")));
408 
409  if (filter(classes, pObject))
410  {
411  // pItem = new QListViewItem(matrixSubtree, "Stoichiometry(ann)");
412  pItem = new QTreeWidgetItem(mpModelMatrixSubtree, QStringList(FROM_UTF8(pObject->getObjectName())));
413  treeItems[pItem] = pObject;
414  }
415  }
416 
417  const CMatrix<C_FLOAT64> &RedStoiMatrix = pModel->getRedStoi();
418 
419  if (RedStoiMatrix.array())
420  {
421  pObject = static_cast< const CCopasiObject * >(pModel->getObject(CCopasiObjectName("Array=Reduced stoichiometry(ann)")));
422 
423  if (filter(classes, pObject))
424  {
425  // pItem = new QListViewItem(matrixSubtree, "Reduced stoichiometry(ann)");
426  pItem = new QTreeWidgetItem(mpModelMatrixSubtree, QStringList(FROM_UTF8(pObject->getObjectName())));
427  treeItems[pItem] = pObject;
428  }
429  }
430 
431  const CMatrix<C_FLOAT64> &LinkMatrix = pModel->getL0();
432 
433  if (LinkMatrix.array())
434  {
435  pObject = static_cast< const CCopasiObject * >(pModel->getObject(CCopasiObjectName("Array=Link matrix(ann)")));
436 
437  if (filter(classes, pObject))
438  {
439  // pItem = new QListViewItem(matrixSubtree, "Link matrix(ann)");
440  pItem = new QTreeWidgetItem(mpModelMatrixSubtree, QStringList(FROM_UTF8(pObject->getObjectName())));
441  treeItems[pItem] = pObject;
442  }
443  }
444 
446 
447  // find all result matrices
448  // Metabolic Control Analysis
449  CCopasiTask *task;
450  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
452  assert(pDataModel != NULL);
453  // MCA
454  task = dynamic_cast<CCopasiTask*>((*pDataModel->getTaskList())["Metabolic Control Analysis"]);
455 
456  try
457  {
458  if (task && task->updateMatrices())
459  {
460  //for mca the result is in the method
461  CMCAMethod* pMethod = dynamic_cast<CMCAMethod *>(task->getMethod());
462 
463  const CCopasiContainer::objectMap * pObjects = & pMethod->getObjects();
464  CCopasiContainer::objectMap::const_iterator its = pObjects->begin();
465  CArrayAnnotation *ann;
466 
467  for (; its != pObjects->end(); ++its)
468  {
469  ann = dynamic_cast<CArrayAnnotation*>(its->second);
470 
471  if (!ann) continue;
472 
473  if (!ann->isEmpty() && filter(classes, ann))
474  {
475  pItem = new QTreeWidgetItem(this->mpResultMCASubtree, QStringList(FROM_UTF8(ann->getObjectName())));
476  treeItems[pItem] = ann;
477  }
478  }
479  }
480  }
481  catch (...)
482  {}
483 
484 // TSSA
485  task = dynamic_cast<CCopasiTask*>((*pDataModel->getTaskList())["Time Scale Separation Analysis"]);
486 
487  try
488  {
489  if (task && task->updateMatrices())
490  {
491 
492  CTSSAMethod* pMethod = dynamic_cast<CTSSAMethod *>(task->getMethod());
493 
494  if (pMethod->getSubType() == CTSSAMethod::tssCSP)
495  {
496  const CCopasiContainer::objectMap * pObjects = & pMethod->getObjects();
497  CCopasiContainer::objectMap::const_iterator its = pObjects->begin();
498  CArrayAnnotation *ann;
499 
500  for (; its != pObjects->end(); ++its)
501  {
502  ann = dynamic_cast<CArrayAnnotation*>(its->second);
503 
504  if (!ann) continue;
505 
506  if (ann->getObjectName() == "Fast Participation Index")
507  if (!ann->isEmpty() && filter(classes, ann))
508  {
509  pItem = new QTreeWidgetItem(this->mpResultTSSASubtree, QStringList(FROM_UTF8(ann->getObjectName())));
510  treeItems[pItem] = ann;
511 
512  }
513 
514  if (ann->getObjectName() == "Slow Participation Index")
515  if (!ann->isEmpty() && filter(classes, ann))
516  {
517  pItem = new QTreeWidgetItem(this->mpResultTSSASubtree, QStringList(FROM_UTF8(ann->getObjectName())));
518  treeItems[pItem] = ann;
519 
520  }
521 
522 
523  if (ann->getObjectName() == "Importance Index")
524  if (!ann->isEmpty() && filter(classes, ann))
525  {
526  pItem = new QTreeWidgetItem(this->mpResultTSSASubtree, QStringList(FROM_UTF8(ann->getObjectName())));
527  treeItems[pItem] = ann;
528 
529 
530  }
531  }
532  }
533 
534  }
535  }
536  catch (...)
537  {}
538 
539 
540  // Steady State
541  task = dynamic_cast<CCopasiTask *>((*pDataModel->getTaskList())["Steady-State"]);
542 
543  try
544  {
545  if (task && task->updateMatrices())
546  {
547  //for steady state the results are in the task
548  const CCopasiContainer::objectMap * pObjects = & task->getObjects();
549  CCopasiContainer::objectMap::const_iterator its = pObjects->begin();
550  CArrayAnnotation *ann;
551 
552  for (; its != pObjects->end(); ++its)
553  {
554  ann = dynamic_cast<CArrayAnnotation*>(its->second);
555 
556  if (!ann) continue;
557 
558  if (!ann->isEmpty() && filter(classes, ann))
559  {
560  pItem = new QTreeWidgetItem(this->mpResultSteadyStateSubtree, QStringList(FROM_UTF8(ann->getObjectName())));
561  treeItems[pItem] = ann;
562  }
563  }
564  }
565  }
566  catch (...)
567  {}
568 
569  // Sensitivities
570  task = dynamic_cast<CCopasiTask *>((*pDataModel->getTaskList())["Sensitivities"]);
571 
572  try
573  {
574  if (task && task->updateMatrices())
575  {
576  //for sensitivities the result is in the problem
577  CSensProblem *sens = dynamic_cast<CSensProblem *>(task->getProblem());
578 
579  const CCopasiContainer::objectMap * pObjects = & sens->getObjects();
580  CCopasiContainer::objectMap::const_iterator its = pObjects->begin();
581  CArrayAnnotation *ann;
582 
583  for (; its != pObjects->end(); ++its)
584  {
585  ann = dynamic_cast<CArrayAnnotation*>(its->second);
586 
587  if (!ann) continue;
588 
589  if (!ann->isEmpty() && filter(classes, ann))
590  {
591  pItem = new QTreeWidgetItem(this->mpResultSensitivitySubtree, QStringList(FROM_UTF8(ann->getObjectName())));
592  treeItems[pItem] = (CCopasiObject *) ann;
593  }
594  }
595  }
596  }
597  catch (...)
598  {}
599 
605 
606  if (selectionMode() == QAbstractItemView::NoSelection)
607  {
608  // see if some objects are there, if yes set to single selection
609  QTreeWidgetItemIterator it(this);
610 
611  while (*it)
612  {
613  if (treeItems.find(*it) != treeItems.end())
614  {
615  setSelectionMode(QAbstractItemView::SingleSelection);
616  setCurrentItem(*it);
617  (*it)->setSelected(true);
618  QTreeWidgetItem* parent = (*it)->parent();
619 
620  while (parent)
621  {
622  parent->setExpanded(true);
623  parent = parent->parent();
624  }
625 
626  break;
627  }
628 
629  ++it;
630  }
631  }
632 }
633 
635 {
636  bool hasSelection = false;
637  QTreeWidgetItemIterator it(this);
638 
639  while (*it)
640  {
641  if ((*it)->isSelected())
642  {
643  hasSelection = true;
644  break;
645  }
646 
647  ++it;
648  }
649 
650  return hasSelection;
651 }
652 
653 std::vector<const CCopasiObject * > * CQSimpleSelectionTree::getTreeSelection()
654 {
655  std::vector<const CCopasiObject * > * selection = new std::vector<const CCopasiObject * >();
656  std::map< std::string, const CCopasiObject * > SelectionMap;
657 
658  if (selectedItems().isEmpty())
659  return selection;
660 
661  if (selectionMode() == QAbstractItemView::SingleSelection)
662  {
663  selection->push_back(treeItems[selectedItems()[0]]);
664  }
665  else
666  {
667  // go through the whole tree and check for selected items.
668  // if the selected item has children, add all children that are leaves
669  // and are connected to an object.
670  // If the item is a leave and is connected to an object, add it directly
671  QTreeWidgetItemIterator it(this);
672  QTreeWidgetItem* currentItem = *it;
673 
674  while (currentItem)
675  {
676  if (currentItem->isSelected())
677  {
678  if (currentItem->childCount() == 0)
679  {
680  if (treeItems.find(currentItem) != treeItems.end())
681  SelectionMap[treeItems[currentItem]->getObjectDisplayName()] = treeItems[currentItem];
682  }
683  else
684  {
685  QTreeWidgetItemIterator it2(currentItem);
686  QTreeWidgetItem* tmpItem = *it2;
687  QTreeWidgetItem* Ancestor;
688 
689  while (tmpItem)
690  {
691  if ((tmpItem->childCount() == 0) &&
692  (treeItems.find(tmpItem) != treeItems.end()))
693  SelectionMap[treeItems[tmpItem]->getObjectDisplayName()] = treeItems[tmpItem];
694 
695  ++it2;
696  tmpItem = *it2;
697 
698  if (!tmpItem) break;
699 
700  // We continue as long as the current item is an
701  // ancestor of the tmp item, i.e., it is in the branch
702  // originating from current item.
703  for (Ancestor = tmpItem->parent();
704  Ancestor != currentItem && Ancestor;
705  Ancestor = Ancestor->parent()) ;
706 
707  if (!Ancestor) break;
708  }
709  }
710  }
711 
712  ++it;
713  currentItem = *it;
714  }
715 
716  // Copy the selection set to the selection
717  selection->resize(SelectionMap.size());
718  std::vector< const CCopasiObject * >::iterator itSelection = selection->begin();
719  std::map< std::string, const CCopasiObject * >::const_iterator itSet = SelectionMap.begin();
720  std::map< std::string, const CCopasiObject * >::const_iterator endSet = SelectionMap.end();
721 
722  for (; itSet != endSet; ++itSet, ++itSelection)
723  *itSelection = itSet->second;
724  }
725 
726  return selection;
727 }
728 
729 bool CQSimpleSelectionTree::isMetaboliteNameUnique(const std::string & name, const CCopasiVector<CMetab> & metabolites)
730 {
731  bool unique = true;
732  bool found = false;
733  size_t counter;
734 
735  for (counter = 0; counter < metabolites.size(); ++counter)
736  {
737  const std::string& thisName = metabolites[counter]->getObjectName();
738 
739  if (name == thisName)
740  {
741  if (found)
742  {
743  unique = false;
744  break;
745  }
746 
747  found = true;
748  }
749  }
750 
751  return unique;
752 }
753 
755 {
756  QTreeWidgetItem* item = NULL;
757  std::map< QTreeWidgetItem *, const CCopasiObject * >::iterator it = treeItems.begin();
758  std::map< QTreeWidgetItem *, const CCopasiObject * >::iterator endPos = treeItems.end();
759 
760  while (it != endPos)
761  {
762  if (it->second == object)
763  {
764  item = it->first;
765  break;
766  }
767 
768  ++it;
769  }
770 
771  return item;
772 }
773 
774 void CQSimpleSelectionTree::selectObjects(std::vector< const CCopasiObject * > * objects)
775 {
776  // clear selection on tree and select new objects
777  clearSelection();
778  size_t i;
779  size_t iMax = objects->size();
780 
781  if ((selectionMode() == QAbstractItemView::SingleSelection || selectionMode() == QAbstractItemView::NoSelection) && iMax > 1)
782  {
783  iMax = 1;
784  }
785 
786  for (i = 0; i < iMax; ++i)
787  {
788  const CCopasiObject * object = objects->at(i);
789  QTreeWidgetItem* item = findListViewItem(object);
790 
791  if (!item && mpExpertSubtree)
792  {
793  // add the item to the expert branch
794  item = new QTreeWidgetItem(mpExpertSubtree,
795  QStringList(FROM_UTF8(object->getObjectDisplayName())));
796  treeItems[item] = object;
797  }
798 
799  // open the whole branch that contains item.
800  QTreeWidgetItem* parent = item->parent();
801 
802  if (parent && !(parent->isExpanded()))
803  {
804  while (parent)
805  {
806  parent->setExpanded(true);
807  parent = parent->parent();
808  }
809  }
810 
811  setCurrentItem(item);
812  }
813 
815 }
816 
818 {
819  if (mpOutputVector)
820  {
821  std::vector< const CCopasiObject * >* treeSelection = getTreeSelection();
822  mpOutputVector->assign(treeSelection->begin(), treeSelection->end());
823  std::vector< const CCopasiObject * >::iterator it = mpOutputVector->begin();
824 
825  while (it != mpOutputVector->end())
826  {
827  if (*it == NULL)
828  {
829  it = mpOutputVector->erase(it);
830  }
831  else
832  {
833  ++it;
834  }
835  }
836 
837  delete treeSelection;
838  }
839 }
840 
841 void CQSimpleSelectionTree::setOutputVector(std::vector< const CCopasiObject * > * outputVector)
842 {
843  mpOutputVector = outputVector;
844 
845  if (mpOutputVector)
846  {
848  }
849 }
850 
851 // static
852 bool CQSimpleSelectionTree::filter(const ObjectClasses & classes, const CCopasiObject * pObject)
853 {
854  if (pObject == NULL)
855  return false;
856 
857  if (classes & AnyObject)
858  return true;
859 
860  // Check whether the value is of the desired numeric type.
861  if ((classes & NumericValues) &&
862  (pObject->isValueDbl() ||
863  pObject->isValueInt() ||
864  pObject->isValueInt64() ||
865  pObject->isArray()))
866  return true;
867 
868  const CCopasiObject * pCheckedObject = pObject;
869 
870  // Elements of an array are checked as the array itself.
871  if (pObject->getObjectParent()->isArray())
872  pCheckedObject = pObject->getObjectParent();
873 
874  const std::string ObjectName = pObject->getObjectName();
875 
876  // CModelEntity needs to be check more thoroughly
877  const CModelEntity * pEntity =
878  dynamic_cast< const CModelEntity * >(pCheckedObject->getObjectParent());
879 
880  if (pEntity)
881  {
882  CModelEntity::Status Status = pEntity->getStatus();
883 
884  if ((classes & InitialTime) &&
885  Status == CModelEntity::TIME &&
886  !static_cast<const CModel *>(pEntity)->isAutonomous() &&
887  ObjectName == "Initial Time")
888  return true;
889 
890  if ((classes & Parameters) &&
891  Status != CModelEntity::TIME &&
892  Status != CModelEntity::ASSIGNMENT &&
893  ObjectName.compare(0, 7, "Initial") == 0 &&
894  pEntity->getInitialExpression() == "")
895  return true;
896 
897  if ((classes & Variables) &&
898  Status != CModelEntity::TIME &&
899  Status != CModelEntity::ASSIGNMENT &&
900  (ObjectName == "Value" ||
901  ObjectName == "Volume" ||
902  ObjectName == "ParticleNumber" ||
903  ObjectName == "Concentration"))
904  return true;
905 
906  if ((classes & EventTarget) &&
907  Status != CModelEntity::TIME &&
908  Status != CModelEntity::ASSIGNMENT &&
909  (ObjectName == "Value" ||
910  ObjectName == "Volume" ||
911  ObjectName == "Concentration"))
912  return true;
913 
914  if ((classes & ObservedConstants) &&
915  ((Status == CModelEntity::TIME &&
916  (ObjectName == "Avogadro Constant" ||
917  ObjectName == "Quantity Conversion Factor")) ||
918  // TODO Until we have not changed to named array elements we do not support matrix elements
919  // || pCheckedObject->isArray())) ||
920  (Status == CModelEntity::ASSIGNMENT &&
921  ObjectName.compare(0, 7, "Initial") == 0) ||
922  ((Status == CModelEntity::ODE ||
923  Status == CModelEntity::REACTIONS ||
924  Status == CModelEntity::FIXED) &&
925  ObjectName.compare(0, 7, "Initial") == 0 &&
926  pEntity->getInitialExpression() != "")))
927  return true;
928 
929  if ((classes & Time) &&
930  Status == CModelEntity::TIME &&
931  ObjectName == "Time")
932  return true;
933 
934  if ((classes & ObservedValues) &&
935  ((Status != CModelEntity::TIME &&
936  Status != CModelEntity::ASSIGNMENT &&
937  (ObjectName.find("Rate") != std::string::npos ||
938  ObjectName == "TransitionTime")) ||
939  (Status == CModelEntity::ASSIGNMENT &&
940  (ObjectName == "Value" ||
941  ObjectName == "Volume" ||
942  ObjectName == "ParticleNumber" ||
943  ObjectName == "Concentration"))))
944  return true;
945  }
946 
947  // Descendants of CReaction need to be check more thoroughly
948  const CReaction * pReaction =
949  dynamic_cast< const CReaction * >(pCheckedObject->getObjectAncestor("Reaction"));
950 
951  if (pReaction)
952  {
953  if ((classes & Parameters) &&
954  pReaction->isLocalParameter(pCheckedObject->getObjectParent()->getObjectName()))
955  return true;
956 
957  if ((classes & ObservedValues) &&
958  ObjectName.find("Flux") != std::string::npos)
959  return true;
960  }
961 
962  const CCopasiTask * pTask =
963  dynamic_cast<const CCopasiTask *>(pCheckedObject->getObjectAncestor("Task"));
964 
965  if (pTask)
966  {
967  // TODO we need to filter out non results
968  if ((classes & Results) &&
969  (pCheckedObject->isValueDbl() ||
970  pCheckedObject->isValueInt() ||
971  pCheckedObject->isValueInt64() ||
972  pCheckedObject->isArray()))
973  return true;
974  }
975 
976  // All tests failed
977  return false;
978 }
979 
980 /*
981  * remove all empty subtree
982  */
983 void CQSimpleSelectionTree::removeEmptySubTree(QTreeWidgetItem ** ppSubTree)
984 {
985  if (ppSubTree != NULL &&
986  *ppSubTree != NULL &&
987  (*ppSubTree)->childCount() == 0)
988  pdelete(*ppSubTree);
989 }
QTreeWidgetItem * mpCompartmentInitialVolumeSubtree
QTreeWidgetItem * mpMetaboliteTransientNumberSubtree
CCopasiDataModel * getObjectDataModel()
CCopasiContainer * getObjectAncestor(const std::string &type) const
QTreeWidgetItem * mpReactionSubtree
CCopasiObject * getDataObject(const CCopasiObjectName &CN) const
bool isValueInt() const
QTreeWidgetItem * mpModelQuantityTransientValueSubtree
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
#define pdelete(p)
Definition: copasi.h:215
QTreeWidgetItem * mpModelMatrixSubtree
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
CCopasiProblem * getProblem()
QTreeWidgetItem * mpCompartmentSubtree
const CCopasiVector< CMetab > & getMetabolites() const
Definition: CModel.cpp:1051
QTreeWidgetItem * mpTimeSubtree
const std::string & getObjectName() const
const CCopasiVectorN< CModelValue > & getModelValues() const
Definition: CModel.cpp:1060
virtual size_t size() const
QTreeWidgetItem * mpMetaboliteInitialConcentrationSubtree
QTreeWidgetItem * mpCompartmentRateSubtree
CCopasiObject * getInitialValueReference() const
void selectObjects(std::vector< const CCopasiObject * > *objects)
virtual const objectMap & getObjects() const
bool isMetaboliteNameUnique(const std::string &name, const CCopasiVector< CMetab > &metabolites)
bool isLocalParameter(const size_t &index) const
Definition: CReaction.cpp:449
void setOutputVector(std::vector< const CCopasiObject * > *outputVector)
CQSimpleSelectionTree(QWidget *parent)
QTreeWidgetItem * mpResultMCASubtree
QTreeWidgetItem * mpResultMatrixSubtree
const CCopasiMethod::SubType & getSubType() const
virtual const CObjectInterface * getObject(const CCopasiObjectName &cn) const
Definition: CReaction.cpp:479
Definition: CMetab.h:178
QTreeWidgetItem * mpMetaboliteInitialNumberSubtree
const CMatrix< C_FLOAT64 > & getRedStoi() const
Definition: CModel.cpp:1154
QTreeWidgetItem * mpModelQuantityRateSubtree
static bool filter(const ObjectClasses &classes, const CCopasiObject *pObject)
QTreeWidgetItem * mpMetaboliteTransientConcentrationSubtree
CTSSATask * pTask
std::multimap< std::string, CCopasiObject * > objectMap
QTreeWidgetItem * mpMetaboliteRateNumberSubtree
virtual bool updateMatrices()
Definition: CCopasiTask.h:347
QTreeWidgetItem * mpResultSteadyStateSubtree
QTreeWidgetItem * mpResultTSSASubtree
std::vector< const CCopasiObject * > * getTreeSelection()
QTreeWidgetItem * mpReactionFluxNumberSubtree
CCopasiObject * getConcentrationRateReference() const
Definition: CMetab.cpp:867
std::string getInitialExpression() const
QTreeWidgetItem * mpCompartmentTransientVolumeSubtree
CCopasiVectorN< CCopasiTask > * getTaskList()
QTreeWidgetItem * mpModelQuantitySubtree
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
QTreeWidgetItem * findListViewItem(const CCopasiObject *object)
QTreeWidgetItem * mpMetaboliteRateConcentrationSubtree
QTreeWidgetItem * mpMetaboliteSubtree
QTreeWidgetItem * mpReactionParameterSubtree
Header file of class CCopasiContainer.
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
CCopasiMethod * getMethod()
Header file of class CArrayAnnotation.
const CCopasiParameterGroup & getParameters() const
Definition: CReaction.cpp:333
std::vector< const CCopasiObject * > * mpOutputVector
bool isValueInt64() const
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
QTreeWidgetItem * mpModelQuantityInitialValueSubtree
bool isArray() const
void populateTree(const CModel *pModel, const ObjectClasses &classes)
bool isValueDbl() const
const CLinkMatrix & getL0() const
Definition: CModel.cpp:1169
Definition: CModel.h:50
virtual const CObjectInterface * getObject(const CCopasiObjectName &cn) const
const CModelEntity::Status & getStatus() const
const CMatrix< C_FLOAT64 > & getStoi() const
Definition: CModel.cpp:1160
CConcentrationReference * getInitialConcentrationReference() const
Definition: CMetab.cpp:861
void removeEmptySubTree(QTreeWidgetItem **ppSubTree)
QTreeWidgetItem * mpExpertSubtree
CCopasiObject * getRateReference() const
QTreeWidgetItem * mpResultSensitivitySubtree
const CCompartment * getCompartment() const
Definition: CMetab.cpp:222
virtual CType * array()
Definition: CMatrix.h:337
CCopasiContainer * getObjectParent() const
std::map< QTreeWidgetItem *, const CCopasiObject * > treeItems
CConcentrationReference * getConcentrationReference() const
Definition: CMetab.cpp:864
CCopasiObject * getValueReference() const
QTreeWidgetItem * mpReactionFluxConcentrationSubtree