COPASI API  4.16.103
CCopasiDataModel.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2015 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 #define USE_LAYOUT 1
16 
17 #include <sbml/SBMLDocument.h>
18 
19 #ifdef COPASI_SEDML
20 #include <sedml/SedDocument.h>
21 #include "sedml/SEDMLImporter.h"
22 #include "sedml/CSEDMLExporter.h"
23 #endif
24 
25 #include "copasi.h"
26 #include "CCopasiDataModel.h"
27 
29 #include "commandline/COptions.h"
32 #include "function/CFunctionDB.h"
33 #include "model/CModel.h"
34 #include "optimization/COptTask.h"
37 #include "report/CKeyFactory.h"
39 #include "sbml/CSBMLExporter.h"
40 #include "sbml/SBMLImporter.h"
42 #include "scan/CScanTask.h"
44 #include "steadystate/CMCATask.h"
46 #include "lna/CLNATask.h"
47 #include "lna/CLNAProblem.h"
51 #include "tssanalysis/CTSSATask.h"
53 #include "lyap/CLyapTask.h"
54 #include "tss/CODEExporter.h"
55 #include "tss/CODEExporterC.h"
56 #include "tss/CODEExporterBM.h"
57 #include "tss/CODEExporterXPPAUT.h"
58 #include "moieties/CMoietiesTask.h"
63 #include "utilities/CCopasiTask.h"
65 #include "utilities/CDirEntry.h"
66 #include "xml/CCopasiXML.h"
67 
68 #include "layout/CListOfLayouts.h"
71 
73 
76  mEnabled(true)
77 {}
78 
79 void CDataModelRenameHandler::handle(const std::string & oldCN, const std::string & newCN) const
80 {
81  if (mEnabled)
82  {
83  std::set<CRegisteredObjectName*>::const_iterator it = CRegisteredObjectName::getSet().begin();
84  std::set<CRegisteredObjectName*>::const_iterator itEnd = CRegisteredObjectName::getSet().end();
85 
86  size_t oldSize = oldCN.size();
87  size_t currentSize;
88 
89  for (; it != itEnd; ++it)
90  {
91  currentSize = (*it)->size();
92 
93  // We need to make sure that we not change partial names
94  if ((currentSize == oldSize ||
95  (currentSize > oldSize && (**it)[oldSize] == ',')) &&
96  oldCN.compare(0, oldSize, **it, 0, oldSize) == 0)
97  {
98  (**it).replace(0, oldSize, newCN);
99  }
100  }
101  }
102 
103  return;
104 }
105 
106 void CDataModelRenameHandler::setEnabled(const bool & enabled)
107 {
108  mEnabled = enabled;
109 }
110 
111 //********************************************************************
112 
114  CCopasiContainer("Root", NULL, "CN", CCopasiObject::DataModel),
115  COutputHandler(),
116  mData(withGUI),
117  mOldData(withGUI),
118  mRenameHandler(),
119  pOldMetabolites(new CCopasiVectorS < CMetabOld >)
120 {
121  newModel(NULL, true);
123  new CCopasiTimer(CCopasiTimer::WALL, this);
125 }
126 
127 CCopasiDataModel::CCopasiDataModel(const std::string & name,
128  const CCopasiContainer * pParent,
129  const std::string & type,
130  bool withGUI):
131  CCopasiContainer(name, pParent, type, CCopasiObject::DataModel),
132  COutputHandler(),
133  mData(withGUI),
134  mOldData(withGUI),
135  mRenameHandler(),
136  pOldMetabolites(new CCopasiVectorS < CMetabOld >)
137 {
138  newModel(NULL, true);
140  new CCopasiTimer(CCopasiTimer::WALL, this);
142 }
143 
145 {
147 
148  // Make sure that the old data is deleted
149  deleteOldData();
150 
151  // Delete the current data
152  mOldData = mData;
153  deleteOldData();
154 
156 }
157 
158 bool CCopasiDataModel::loadModel(std::istream & in,
159  const std::string & pwd,
160  CProcessReport* pProcessReport,
161  const bool & deleteOldData)
162 {
163  // During load no objects will be renamed;
164  mRenameHandler.setEnabled(false);
165 
167 
168  std::string Line;
169  in >> Line;
170 
171  if (!Line.compare(0, 8, "Version="))
172  {
173  in.seekg(0, std::ios_base::beg);
174 
175  CReadConfig inbuf(in);
176 
177  if (inbuf.getVersion() >= "4")
178  {
180  "Can't handle Gepasi Files with Version>=4.");
181 
183  return false;
184  }
185 
186  newModel(NULL, deleteOldData);
188 
189  if (mData.pModel->load(inbuf))
190  {
191  popData();
193  return false;
194  }
195 
196  static_cast<CTrajectoryTask *>((*mData.pTaskList)["Time-Course"])->load(inbuf);
197 
198  static_cast<CSteadyStateTask *>((*mData.pTaskList)["Steady-State"])->load(inbuf);
199  }
200  else if (!Line.find("<?xml") != std::string::npos)
201  {
202  in.seekg(0, std::ios_base::beg);
203  pushData();
205 
206  CCopasiXML XML;
207  XML.setFunctionList(&CCopasiRootContainer::getFunctionList()->loadedFunctions());
208  XML.setDatamodel(this);
209 
210  SCopasiXMLGUI *pGUI = NULL;
211 
212  if (mData.mWithGUI)
213  {
214  pGUI = new SCopasiXMLGUI("GUI", this);
215  XML.setGUI(pGUI);
216  }
217 
218  try
219  {
220  if (!XML.load(in, pwd))
221  {
222  XML.freeModel();
223  XML.freeTaskList();
224  XML.freeReportList();
225  XML.freePlotList();
226  XML.freeGUI();
227  XML.freeLayoutList();
228 
229  // restore the OldData
230  popData();
231 
233  return false;
234  }
235  }
236  catch (...)
237  {
238  XML.freeModel();
239  XML.freeTaskList();
240  XML.freeReportList();
241  XML.freePlotList();
242  XML.freeGUI();
243  XML.freeLayoutList();
244 
245  // restore the OldData
246  popData();
247 
248  // rethrow the exception so the program flow should still be
249  // the same as before
251  throw;
252  }
253 
254  if (XML.getModel() != NULL)
255  {
256  mData.pModel = XML.getModel();
257  add(mData.pModel, true);
258  }
259 
260  if (XML.getTaskList() != NULL)
261  {
262  mData.pTaskList = XML.getTaskList();
263  add(mData.pTaskList, true);
264  }
265 
266  if (XML.getReportList() != NULL)
267  {
270  }
271 
272  if (XML.getPlotList() != NULL)
273  {
276  }
277 
278  if (XML.getLayoutList() != NULL)
279  {
281  add(mData.pListOfLayouts, true);
282  }
283 
284  if (mData.mWithGUI)
285  {
286  mData.pGUI = pGUI;
287  }
288  }
289  else
290  {
292 
294  return false;
295  }
296 
297  commonAfterLoad(pProcessReport, deleteOldData);
298 
300  return true;
301 }
302 
303 bool CCopasiDataModel::loadModel(const std::string & fileName,
304  CProcessReport* pProcessReport,
305  const bool & deleteOldData)
306 {
307  std::string PWD;
308  COptions::getValue("PWD", PWD);
309 
310  std::string FileName = fileName;
311 
312  if (CDirEntry::isRelativePath(FileName) &&
313  !CDirEntry::makePathAbsolute(FileName, PWD))
314  FileName = CDirEntry::fileName(FileName);
315 
316  PWD = CDirEntry::dirName(FileName);
317 
318 #ifdef WIN32
319  std::ifstream File(CLocaleString::fromUtf8(FileName).c_str(), std::ios_base::binary);
320 #else
321  std::ifstream File(CLocaleString::fromUtf8(FileName).c_str());
322 #endif
323 
324  if (File.fail())
325  {
327  "File error when opening '%s'.",
328  FileName.c_str());
329  return false;
330  }
331 
332  if (!loadModel(File, PWD, pProcessReport, deleteOldData))
333  {
334  return false;
335  }
336 
337  switch (mData.mFileType)
338  {
339  case CopasiML:
341  // we have to store the reference directory
343  break;
344 
345  case Gepasi:
348  + CDirEntry::baseName(FileName);
349 
350  {
351  std::string Suffix = CDirEntry::suffix(FileName);
352 
353  if (strcasecmp(Suffix.c_str(), ".gps") != 0)
354  mData.mSaveFileName += Suffix;
355  }
356 
357  mData.mSaveFileName += ".cps";
358 
360  // we have to store the reference directory
362  break;
363 
364  default:
365  fatalError();
366  break;
367  }
368 
369  return true;
370 }
371 
372 bool CCopasiDataModel::saveModel(const std::string & fileName, CProcessReport* pProcessReport,
373  bool overwriteFile,
374  const bool & autoSave)
375 {
377 
378  std::string FileName = (fileName != "") ? fileName : mData.mSaveFileName;
379 
380  std::string PWD;
381  COptions::getValue("PWD", PWD);
382 
383  if (CDirEntry::isRelativePath(FileName) &&
384  !CDirEntry::makePathAbsolute(FileName, PWD))
385  FileName = CDirEntry::fileName(FileName);
386 
387  if (CDirEntry::exist(FileName))
388  {
389  if (!overwriteFile)
390  {
392  MCDirEntry + 1,
393  FileName.c_str());
394  return false;
395  }
396 
397  if (!CDirEntry::isWritable(FileName))
398  {
400  MCDirEntry + 2,
401  FileName.c_str());
402  return false;
403  }
404  }
405 
406  try
407  {
408  // We do not care whether the model compiles or not
409  // We just save as much as we can
410  mData.pModel->compileIfNecessary(pProcessReport);
411 
412  // Assure that the parameter set reflects all changes made to the model.
414  }
415 
416  catch (...)
417  {
418  return false;
419  }
420 
421  CCopasiXML XML;
422 
423  XML.setModel(mData.pModel);
427  XML.setGUI(mData.pGUI);
429  XML.setDatamodel(this);
430  bool success = true;
431 
432  if (!autoSave)
433  {
434  // We are first writing to a temporary file to prevent accidental
435  // destruction of an existing file in case the save command fails.
436  std::string TmpFileName;
437  COptions::getValue("Tmp", TmpFileName);
438  TmpFileName = CDirEntry::createTmpName(TmpFileName, ".cps");
439 
440  try
441  {
442  if (!XML.CCopasiXMLInterface::save(TmpFileName, FileName))
443  {
444  CDirEntry::remove(TmpFileName);
445  success = false;
446  }
447  }
448 
449  catch (...)
450  {
451  CDirEntry::remove(TmpFileName);
452  return false;
453  }
454 
455  if (success && !CDirEntry::move(TmpFileName, FileName))
456  success = false;
457  }
458 
459  if (autoSave || !success)
460  {
461  try
462  {
463  if (!XML.CCopasiXMLInterface::save(FileName, FileName))
464  return false;
465  }
466 
467  catch (...)
468  {
469  return false;
470  }
471  }
472 
473  if (!autoSave)
474  {
475  changed(false);
477  }
478 
479  return true;
480 }
481 
483 {
484  if (!mData.mAutoSaveNeeded) return true;
485 
486  std::string AutoSave;
487 
488  COptions::getValue("Tmp", AutoSave);
489 
490  if (AutoSave == "") return false;
491 
492  AutoSave += CDirEntry::Separator + "tmp_";
493 
494  if (mData.mSaveFileName != "")
496  else
497  AutoSave += "untitled";
498 
499  AutoSave += ".cps";
500 
501  try
502  {
503  if (!saveModel(AutoSave, NULL, true, true)) return false;
504  }
505 
506  catch (...)
507  {
508  return false;
509  }
510 
511  mData.mAutoSaveNeeded = false;
512  return true;
513 }
514 
516  const bool & deleteOldData)
517 {
518  //deal with the CModel
519  pushData();
520 
521  commonAfterLoad(pProcessReport, deleteOldData);
522 
523  return true;
524 }
525 
526 bool CCopasiDataModel::importSBMLFromString(const std::string& sbmlDocumentText,
527  CProcessReport* pImportHandler,
528  const bool & deleteOldData)
529 {
530  // During load no objects will be renamed;
531  mRenameHandler.setEnabled(false);
532 
533  pushData();
534 
536 
537  SBMLImporter importer;
538  // Right now we always import the COPASI MIRIAM annotation if it is there.
539  // Later this will be configurable by the user in the preferences dialog
540  importer.setImportCOPASIMIRIAM(true);
541  importer.setImportHandler(pImportHandler);
542  //mCopasi2SBMLMap.clear();
543  CModel* pModel = NULL;
544 
545  SBMLDocument * pSBMLDocument = NULL;
546  std::map<CCopasiObject*, SBase*> Copasi2SBMLMap;
547 
548  CListOfLayouts * pLol = NULL; //
549 
550  try
551  {
552  pModel = importer.parseSBML(sbmlDocumentText, CCopasiRootContainer::getFunctionList(),
553  pSBMLDocument, Copasi2SBMLMap, pLol, this);
554  }
555 
556  catch (CCopasiException & except)
557  {
558  importer.restoreFunctionDB();
559  importer.deleteCopasiModel();
560  popData();
561 
563  throw except;
564  }
565 
566  if (pModel == NULL)
567  {
568  importer.restoreFunctionDB();
569  importer.deleteCopasiModel();
570  popData();
571 
573  return false;
574  }
575 
576  if (pModel != NULL)
577  {
578  mData.pModel = pModel;
579  add(mData.pModel, true);
580  }
581 
582  if (pLol != NULL)
583  {
584  mData.pListOfLayouts = pLol;
585  add(mData.pListOfLayouts, true);
586  }
587 
588  mData.pCurrentSBMLDocument = pSBMLDocument;
589  mData.mCopasi2SBMLMap = Copasi2SBMLMap;
590  mData.mFileType = SBML;
591 
592  commonAfterLoad(pImportHandler, deleteOldData);
593 
594  // when importing from SBML, allow continuation on simultaneous events.
595  static_cast<CTrajectoryProblem *>(
596  static_cast<CTrajectoryTask *>((*mData.pTaskList)["Time-Course"])->getProblem()
597  )->setContinueSimultaneousEvents(true);
598 
600  return true;
601 }
602 
603 bool CCopasiDataModel::importSBML(const std::string & fileName,
604  CProcessReport* pImportHandler,
605  const bool & deleteOldData)
606 {
607  // During load no objects will be renamed;
608  mRenameHandler.setEnabled(false);
610 
611  std::string PWD;
612  COptions::getValue("PWD", PWD);
613 
614  std::string FileName = fileName;
615 
616  if (CDirEntry::isRelativePath(FileName) &&
617  !CDirEntry::makePathAbsolute(FileName, PWD))
618  FileName = CDirEntry::fileName(FileName);
619 
620  std::ifstream File(CLocaleString::fromUtf8(FileName).c_str());
621 
622  SBMLImporter importer;
623  // Right now we always import the COPASI MIRIAM annotation if it is there.
624  // Later this will be settable by the user in the preferences dialog
625  importer.setImportCOPASIMIRIAM(true);
626  importer.setImportHandler(pImportHandler);
627 
628  CModel* pModel = NULL;
629 
630  SBMLDocument * pSBMLDocument = NULL;
631  std::map<CCopasiObject*, SBase*> Copasi2SBMLMap;
632 
633  CListOfLayouts * pLol = NULL;
634 
635  pushData();
636 
637  try
638  {
639  // store the file name and reference dir, so the importer can use it
642 
643  pModel = importer.readSBML(FileName, CCopasiRootContainer::getFunctionList(),
644  pSBMLDocument, Copasi2SBMLMap, pLol, this);
645  }
646 
647  catch (CCopasiException & except)
648  {
649  importer.restoreFunctionDB();
650  importer.deleteCopasiModel();
651  popData();
652 
654  throw except;
655  }
656 
657  if (pModel == NULL)
658  {
659  importer.restoreFunctionDB();
660  importer.deleteCopasiModel();
661  popData();
662 
664  return false;
665  }
666 
667  if (pModel != NULL)
668  {
669  mData.pModel = pModel;
670  add(mData.pModel, true);
671  }
672 
673  if (pLol != NULL)
674  {
675  mData.pListOfLayouts = pLol;
676  add(mData.pListOfLayouts, true);
677  }
678 
679  mData.pCurrentSBMLDocument = pSBMLDocument;
680  mData.mCopasi2SBMLMap = Copasi2SBMLMap;
681  mData.mFileType = SBML;
682 
683  commonAfterLoad(pImportHandler, deleteOldData);
684 
685  // when importing from SBML, allow continuation on simultaneous events.
686  static_cast<CTrajectoryProblem *>(
687  static_cast<CTrajectoryTask *>((*mData.pTaskList)["Time-Course"])->getProblem()
688  )->setContinueSimultaneousEvents(true);
689 
692  + CDirEntry::baseName(FileName);
693 
694  std::string Suffix = CDirEntry::suffix(FileName);
695 
696  if (strcasecmp(Suffix.c_str(), ".xml") != 0)
697  mData.mSaveFileName += Suffix;
698 
699  mData.mSaveFileName += ".cps";
701  // store the reference directory
704 
706  return true;
707 }
708 
709 std::string CCopasiDataModel::exportSBMLToString(CProcessReport* pExportHandler, int sbmlLevel, int sbmlVersion)
710 {
712  SBMLDocument* pOrigSBMLDocument = NULL;
713 
714 #if LIBSBML_VERSION >= 40100
715 
716  // if we export an L2 model to L3 or vice versa, we have to throw away any prior information
717  // about the current sbml document because libsbml does not support the conversion
718  // so we need to make sure that all model elements are created from scratch from the corresponding COPASI elements
719  if (this->mData.pCurrentSBMLDocument != NULL &&
720  ((this->mData.pCurrentSBMLDocument->getLevel() > 2 && sbmlLevel < 3) ||
721  (this->mData.pCurrentSBMLDocument->getLevel() < 3 && sbmlLevel > 2)
722  )
723  )
724  {
725  pOrigSBMLDocument = this->mData.pCurrentSBMLDocument;
726  this->mData.pCurrentSBMLDocument = NULL;
727  }
728 
729 #endif // LIBSBML_VERSION
731  static std::string failedCompile("The model cannot be exported, as it failed to compile. \n%s");
732 
733  try
734  {
735  if (!mData.pModel->compileIfNecessary(pExportHandler))
736  {
738  return "";
739  }
740  }
741  catch (CCopasiException&)
742  {
743  // don't add the exception twice
744  throw;
745  }
746  catch (...)
747  {
749  return "";
750  }
751 
752  CSBMLExporter exporter;
753  // Per default export COPASIs MIRIAM annotation.
754  // This should eventually be determined by a setting in the preferences
755  // dialog.
756  exporter.setExportCOPASIMIRIAM(true);
757  std::string str = exporter.exportModelToString(*this, sbmlLevel, sbmlVersion);
758 
759  // only get the new model if it is not a Level 1 model
760  // During export to Level 1 the function definitions have been deleted and therefore
761  // all information assiociated with the function definitions will be gone if the user exports
762  // to Level 2 after having exported to Level 1
763  // This is actual vital to get around Bug 1086 as well.
764  // Once I have a Level 1 model, all calls to setName on an
765  // SBML object in that model also resets the id, which does not work with the current exporter
766  if ((sbmlLevel != 1 || mData.pCurrentSBMLDocument == NULL) && pOrigSBMLDocument == NULL)
767  {
768  if (mData.pCurrentSBMLDocument != exporter.getSBMLDocument())
769  {
771  }
772 
773  // disown the SBML Document from the exporter so we don't have to copy it
774  exporter.disownSBMLDocument();
776  // we also need to get the new copasi2sbml map otherwise it contains invalid pointers
777  // since the objects
778  mData.mCopasi2SBMLMap.clear();
779  std::map<const CCopasiObject*, SBase*>::const_iterator it = exporter.getCOPASI2SBMLMap().begin();
780  std::map<const CCopasiObject*, SBase*>::const_iterator endit = exporter.getCOPASI2SBMLMap().end();
781 
782  while (it != endit)
783  {
784  mData.mCopasi2SBMLMap.insert(std::pair<CCopasiObject*, SBase*>(const_cast<CCopasiObject*>(it->first), it->second));
785  ++it;
786  }
787  }
788  // if we have saved the original SBML model somewhere
789  // we have to reset it
790  else if (pOrigSBMLDocument != NULL)
791  {
792  mData.pCurrentSBMLDocument = pOrigSBMLDocument;
793  }
794 
795  return str;
796 }
797 
798 bool CCopasiDataModel::exportSBML(const std::string & fileName, bool overwriteFile, int sbmlLevel, int sbmlVersion, bool /*exportIncomplete*/, bool exportCOPASIMIRIAM, CProcessReport* pExportHandler)
799 {
801 
802  if (fileName == "") return false;
803 
804  std::string PWD;
805  COptions::getValue("PWD", PWD);
806 
807  std::string FileName = fileName;
808 
809  if (CDirEntry::isRelativePath(FileName) &&
810  !CDirEntry::makePathAbsolute(FileName, PWD))
811  FileName = CDirEntry::fileName(FileName);
812 
813  if (CDirEntry::exist(FileName))
814  {
815  if (!overwriteFile)
816  {
818  MCDirEntry + 1,
819  FileName.c_str());
820  return false;
821  }
822 
823  if (!CDirEntry::isWritable(FileName))
824  {
826  MCDirEntry + 2,
827  FileName.c_str());
828  return false;
829  }
830  }
831 
833  static std::string failedCompile("The model cannot be exported, as it failed to compile. \n%s");
834 
835  try
836  {
837  if (!mData.pModel->compileIfNecessary(pExportHandler))
838  {
840  return false;
841  }
842  }
843  catch (CCopasiException&)
844  {
845  // don't add the exception twice
846  throw;
847  }
848  catch (...)
849  {
851  return false;
852  }
853 
854  CSBMLExporter exporter;
855  exporter.setExportCOPASIMIRIAM(exportCOPASIMIRIAM);
856  SBMLDocument* pOrigSBMLDocument = NULL;
857 
858 #if LIBSBML_VERSION >= 40100
859 
860  // if we export an L2 model to L3 or vice versa, we have to throw away any prior information
861  // about the current sbml document because libsbml does not support the conversion
862  // so we need to make sure that all model elements are created from scratch from the corresponding COPASI elements
863  if (this->mData.pCurrentSBMLDocument != NULL &&
864  ((this->mData.pCurrentSBMLDocument->getLevel() > 2 && sbmlLevel < 3) ||
865  (this->mData.pCurrentSBMLDocument->getLevel() < 3 && sbmlLevel > 2)
866  )
867  )
868  {
869  pOrigSBMLDocument = this->mData.pCurrentSBMLDocument;
870  this->mData.pCurrentSBMLDocument = NULL;
871  }
872 
873 #endif // LIBSBML_VERSION
874 
875  //exporter.setExportHandler(pExportHandler);
876  if (!exporter.exportModel(*this, FileName, sbmlLevel, sbmlVersion, overwriteFile)) return false;
877 
878  // only get the new model if it is not a Level 1 model
879  // During export to Level 1 the function definitions have been deleted and therefore
880  // all information assiociated with the function definitions will be gone if the user exports
881  // to Level 2 after having exported to Level 1
882  // This is actual vital to get around Bug 1086 as well.
883  // Once I have a Level 1 model, all calls to setName on an
884  // SBML object in that model also resets the id, which does not work with the current exporter
885  if ((sbmlLevel != 1 || mData.pCurrentSBMLDocument == NULL) && pOrigSBMLDocument == NULL)
886  {
887 
888  if (mData.pCurrentSBMLDocument != exporter.getSBMLDocument())
890 
891  // disown the SBML Document from the exporter so we don't have to copy it
892  exporter.disownSBMLDocument();
894  // we also need to get the new copasi2sbml map otherwise it contains invalid pointers
895  // since the objects
896  mData.mCopasi2SBMLMap.clear();
897  std::map<const CCopasiObject*, SBase*>::const_iterator it = exporter.getCOPASI2SBMLMap().begin();
898  std::map<const CCopasiObject*, SBase*>::const_iterator endit = exporter.getCOPASI2SBMLMap().end();
899 
900  while (it != endit)
901  {
902  mData.mCopasi2SBMLMap.insert(std::pair<CCopasiObject*, SBase*>(const_cast<CCopasiObject*>(it->first), it->second));
903  ++it;
904  }
905  }
906  // if we have saved the original SBML model somewhere
907  // we have to reset it
908  else if (pOrigSBMLDocument != NULL)
909  {
910  this->mData.pCurrentSBMLDocument = pOrigSBMLDocument;
911  }
912 
913  mData.mSBMLFileName = FileName;
914  return true;
915 }
916 
917 std::string CCopasiDataModel::exportMathModelToString(CProcessReport* pProcessReport, const std::string & filter)
918 {
919  CODEExporter * pExporter = NULL;
920 
921  if (filter == "C Files (*.c)")
922  {
923  pExporter = new CODEExporterC;
924  }
925  else if (filter == "Berkeley Madonna Files (*.mmd)")
926  {
927  pExporter = new CODEExporterBM();
928  }
929  else if (filter == "XPPAUT (*.ode)")
930  {
931  pExporter = new CODEExporterXPPAUT;
932  }
933 
934  if (pExporter == NULL)
935  {
936  return "";
937  }
938 
939  try
940  {
941  if (!mData.pModel->compileIfNecessary(pProcessReport))
942  return "";
943  }
944 
945  catch (...)
946  {
947  return "";
948  }
949 
952 
953  for (; it != end; ++it)
954  if ((*it)->isUsed()) break;
955 
956  if (it != end)
958 
959  std::ostringstream os;
960 
961  if (!pExporter->exportToStream(this, os))
962  {
963  return "";
964  }
965 
966  return os.str();
967 }
968 
969 bool CCopasiDataModel::exportMathModel(const std::string & fileName, CProcessReport* pProcessReport,
970  const std::string & filter, bool overwriteFile)
971 {
973 
974  if (fileName == "") return false;
975 
976  if (CDirEntry::exist(fileName))
977  {
978  if (!overwriteFile)
979  {
981  MCDirEntry + 1,
982  fileName.c_str());
983  return false;
984  }
985 
986  if (!CDirEntry::isWritable(fileName))
987  {
989  MCDirEntry + 2,
990  fileName.c_str());
991  return false;
992  }
993  }
994  else if (!CDirEntry::isWritable(CDirEntry::dirName(fileName)))
995  {
997  MCDirEntry + 2,
998  fileName.c_str());
999  return false;
1000  }
1001 
1002  try
1003  {
1004  if (!mData.pModel->compileIfNecessary(pProcessReport))
1005  return false;
1006  }
1007 
1008  catch (...)
1009  {
1010  return false;
1011  }
1012 
1015 
1016  for (; it != end; ++it)
1017  if ((*it)->isUsed()) break;
1018 
1019  if (it != end)
1021 
1022  CODEExporter * pExporter = NULL;
1023 
1024  if (filter == "C Files (*.c)")
1025  {
1026  pExporter = new CODEExporterC;
1027  }
1028  else if (filter == "Berkeley Madonna Files (*.mmd)")
1029  {
1030  pExporter = new CODEExporterBM();
1031  }
1032  else if (filter == "XPPAUT (*.ode)")
1033  {
1034  pExporter = new CODEExporterXPPAUT;
1035  }
1036 
1037  if (pExporter == NULL)
1038  {
1039  return false;
1040  }
1041 
1042  std::ofstream os(CLocaleString::fromUtf8(fileName).c_str(), std::ios::out);
1043 
1044  if (!os.good())
1045  {
1047  MCDirEntry + 3,
1048  fileName.c_str());
1049  return false;
1050  }
1051 
1052  return pExporter->exportToStream(this, os);
1053 }
1054 
1055 //TODO SEDML
1056 #ifdef COPASI_SEDML
1057 bool CCopasiDataModel::importSEDMLFromString(const std::string& sedmlDocumentText,
1058  CProcessReport* pImportHandler,
1059  const bool & deleteOldData)
1060 {
1061  // During load no objects will be renamed;
1062  mRenameHandler.setEnabled(false);
1063 
1064  pushData();
1065 
1067 
1068  SEDMLImporter importer;
1069  // Right now we always import the COPASI MIRIAM annotation if it is there.
1070  // Later this will be settable by the user in the preferences dialog
1071 // importer.setImportCOPASIMIRIAM(true);
1072  importer.setImportHandler(pImportHandler);
1073  //mCopasi2SBMLMap.clear();
1074  CModel* pModel = NULL;
1075 
1076  SedDocument * pSEDMLDocument = NULL;
1077  std::map<CCopasiObject*, SedBase*> Copasi2SEDMLMap;
1078  std::map<CCopasiObject*, SBase*> Copasi2SBMLMap;
1079 
1080  SBMLDocument * pSBMLDocument = NULL;
1081  CListOfLayouts * pLol = NULL;
1082  COutputDefinitionVector *pLotList = NULL; // = new COutputDefinitionVector("OutputDefinitions", this);
1083 
1084  try
1085  {
1086  pModel = importer.parseSEDML(sedmlDocumentText, pImportHandler, pSBMLDocument, pSEDMLDocument,
1087  Copasi2SEDMLMap, Copasi2SBMLMap, pLol, pLotList, this);
1088  }
1089 
1090  catch (CCopasiException & except)
1091  {
1092  importer.restoreFunctionDB();
1093  importer.deleteCopasiModel();
1094  popData();
1095 
1096  mRenameHandler.setEnabled(true);
1097  throw except;
1098  }
1099 
1100  if (pModel == NULL)
1101  {
1102  importer.restoreFunctionDB();
1103  importer.deleteCopasiModel();
1104  popData();
1105 
1106  mRenameHandler.setEnabled(true);
1107  return false;
1108  }
1109 
1110  if (pModel != NULL)
1111  {
1112  mData.pModel = pModel;
1113  add(mData.pModel, true);
1114  }
1115 
1116  if (pLol != NULL)
1117  {
1118  mData.pListOfLayouts = pLol;
1119  add(mData.pListOfLayouts, true);
1120  }
1121 
1122  mData.pCurrentSEDMLDocument = pSEDMLDocument;
1123  mData.mCopasi2SEDMLMap = Copasi2SEDMLMap;
1124  mData.mFileType = SEDML;
1125 
1126  commonAfterLoad(pImportHandler, deleteOldData);
1127 
1128  mRenameHandler.setEnabled(true);
1129  return true;
1130 }
1131 
1132 bool CCopasiDataModel::importSEDML(const std::string & fileName,
1133  CProcessReport* pImportHandler,
1134  const bool & deleteOldData)
1135 {
1136  // During load no objects will be renamed;
1137  mRenameHandler.setEnabled(false);
1138 
1140 
1141  std::string PWD;
1142  COptions::getValue("PWD", PWD);
1143 
1144  std::string FileName = fileName;
1145 
1146  if (CDirEntry::isRelativePath(FileName) &&
1147  !CDirEntry::makePathAbsolute(FileName, PWD))
1148  FileName = CDirEntry::fileName(FileName);
1149 
1150  std::ifstream File(CLocaleString::fromUtf8(FileName).c_str());
1151 
1152  SEDMLImporter importer;
1153  // Later this will be settable by the user in the preferences dialog
1154  // Later this will be settable by the user in the preferences dialog
1155 // importer.setImportCOPASIMIRIAM(true);
1156  importer.setImportHandler(pImportHandler);
1157 
1158  CModel* pModel = NULL;
1159 
1160  SedDocument * pSEDMLDocument = NULL;
1161  std::map<CCopasiObject*, SedBase*> Copasi2SEDMLMap;
1162  std::map<CCopasiObject*, SBase*> Copasi2SBMLMap;
1163 
1164  SBMLDocument * pSBMLDocument = NULL;
1165  CTrajectoryTask *trajTask = NULL;
1166  CListOfLayouts * pLol = NULL;
1167  COutputDefinitionVector *pLotList = NULL;
1168 
1169  pushData();
1170 
1171  try
1172  {
1173  // store the file name and reference dir, so the importer can use it
1174  mData.mSEDMLFileName = CDirEntry::normalize(FileName);
1175  mData.mReferenceDir = CDirEntry::dirName(mData.mSEDMLFileName);
1176 
1177  pModel = importer.readSEDML(FileName, pImportHandler, pSBMLDocument, pSEDMLDocument,
1178  Copasi2SEDMLMap, Copasi2SBMLMap, pLol, pLotList, this);
1179  }
1180 
1181  catch (CCopasiException & except)
1182  {
1183  importer.restoreFunctionDB();
1184  importer.deleteCopasiModel();
1185  popData();
1186 
1187  mRenameHandler.setEnabled(true);
1188  throw except;
1189  }
1190 
1191  if (pModel == NULL)
1192  {
1193  importer.restoreFunctionDB();
1194  importer.deleteCopasiModel();
1195  popData();
1196 
1197  mRenameHandler.setEnabled(true);
1198  return false;
1199  }
1200 
1201  if (pModel != NULL)
1202  {
1203  mData.pModel = pModel;
1204  add(mData.pModel, true);
1205  }
1206 
1207  if (pLol != NULL)
1208  {
1209  mData.pListOfLayouts = pLol;
1210  add(mData.pListOfLayouts, true);
1211  }
1212 
1213  if (pLol != NULL)
1214  {
1215  mData.pPlotDefinitionList = pLotList;
1216  add(mData.pPlotDefinitionList, true);
1217  }
1218 
1219  commonAfterLoad(pImportHandler, deleteOldData);
1220  // common after load resets all tasks, so we need to reset them.
1221  importer.importTasks(Copasi2SEDMLMap);
1222 
1223  mData.pCurrentSEDMLDocument = pSEDMLDocument;
1224  mData.mCopasi2SEDMLMap = Copasi2SEDMLMap;
1225  mData.mFileType = SEDML;
1226 
1229  + CDirEntry::baseName(FileName);
1230 
1231  std::string Suffix = CDirEntry::suffix(FileName);
1232 
1233  if (strcasecmp(Suffix.c_str(), ".sedml") != 0)
1234  mData.mSaveFileName += Suffix;
1235 
1236  mData.mSaveFileName += ".cps";
1238  // store the reference directory
1240  mData.mSEDMLFileName = CDirEntry::normalize(FileName);
1241 
1242  mRenameHandler.setEnabled(true);
1243  return true;
1244 }
1245 
1246 SedDocument* CCopasiDataModel::getCurrentSEDMLDocument()
1247 {
1248  return mData.pCurrentSEDMLDocument;
1249 }
1250 
1251 bool CCopasiDataModel::setSEDMLFileName(const std::string & fileName)
1252 {
1253  mData.mSEDMLFileName = CDirEntry::normalize(fileName);
1254 
1255  if (CDirEntry::isRelativePath(mData.mSEDMLFileName) &&
1257  mData.mSEDMLFileName = CDirEntry::fileName(mData.mSEDMLFileName);
1258 
1259  return true;
1260 }
1261 
1262 const std::string & CCopasiDataModel::getSEDMLFileName() const
1263 {return mData.mSEDMLFileName;}
1264 
1265 std::map<CCopasiObject*, SedBase*>& CCopasiDataModel::getCopasi2SEDMLMap()
1266 {
1267  return mData.mCopasi2SEDMLMap;
1268 }
1269 
1270 std::string CCopasiDataModel::exportSEDMLToString(CProcessReport* pExportHandler, int sedmlLevel, int sedmlVersion)
1271 {
1273  SedDocument* pOrigSEDMLDocument = NULL;
1274 
1276  static std::string failedCompile("The model cannot be exported, as it failed to compile. \n%s");
1277 
1278  try
1279  {
1280  if (!mData.pModel->compileIfNecessary(pExportHandler))
1281  {
1283  return "";
1284  }
1285  }
1286  catch (CCopasiException&)
1287  {
1288  // don't add the exception twice
1289  throw;
1290  }
1291  catch (...)
1292  {
1294  return "";
1295  }
1296 
1297  CSEDMLExporter exporter;
1298  std::string sbmlDocument = this->exportSBMLToString(pExportHandler, 2, 4);
1299  std::string str = exporter.exportModelAndTasksToString(*this, sbmlDocument, sedmlLevel, sedmlVersion);
1300 
1301  // if we have saved the original SEDML model somewhere
1302  // we have to reset it
1303  if (pOrigSEDMLDocument != NULL)
1304  {
1305  mData.pCurrentSEDMLDocument = pOrigSEDMLDocument;
1306  }
1307 
1308  return str;
1309 }
1310 
1311 bool CCopasiDataModel::exportSEDML(const std::string & fileName, bool overwriteFile, int sedmlLevel, int sedmlVersion, bool /*exportIncomplete*/, bool exportCOPASIMIRIAM, CProcessReport* pExportHandler)
1312 {
1314 
1315  if (fileName == "") return false;
1316 
1317  std::string PWD;
1318  COptions::getValue("PWD", PWD);
1319 
1320  std::string FileName = fileName;
1321 
1322  if (CDirEntry::isRelativePath(FileName) &&
1323  !CDirEntry::makePathAbsolute(FileName, PWD))
1324  FileName = CDirEntry::fileName(FileName);
1325 
1326  if (CDirEntry::exist(FileName))
1327  {
1328  if (!overwriteFile)
1329  {
1331  MCDirEntry + 1,
1332  FileName.c_str());
1333  return false;
1334  }
1335 
1336  if (!CDirEntry::isWritable(FileName))
1337  {
1339  MCDirEntry + 2,
1340  FileName.c_str());
1341  return false;
1342  }
1343  }
1344 
1346  static std::string failedCompile("The model cannot be exported, as it failed to compile. \n%s");
1347 
1348  try
1349  {
1350  if (!mData.pModel->compileIfNecessary(pExportHandler))
1351  {
1353  return false;
1354  }
1355  }
1356  catch (CCopasiException&)
1357  {
1358  // don't add the exception twice
1359  throw;
1360  }
1361  catch (...)
1362  {
1364  return false;
1365  }
1366 
1367  CSEDMLExporter exporter;
1368  // exporter.setExportCOPASIMIRIAM(exportCOPASIMIRIAM);
1369  SedDocument* pOrigSEDMLDocument = NULL;
1370 
1371  //exporter.setExportHandler(pExportHandler);
1372 // const std::string& SBMLFileName = "";
1373 
1374  std::string sbmlDocument = "";
1375  sbmlDocument = this->exportSBMLToString(pExportHandler, 2, 3);
1376 
1377  // std::cout<<sbmlDocument<<std::endl; //for debuging
1378  if (sbmlDocument == "")
1379  {
1380  CCopasiMessage(CCopasiMessage::EXCEPTION, "No support for exporting SEDML without SBML model");
1381  }
1382 
1383  if (!exporter.exportModelAndTasks(*this, FileName, sbmlDocument, sedmlLevel, sedmlVersion, overwriteFile)) return false;
1384 
1385  return true;
1386 }
1387 #endif
1388 
1390 {
1398 
1399 #ifdef COPASI_SEDML
1400  pdelete(mOldData.pCurrentSEDMLDocument);
1401 #endif
1402 }
1403 
1405 {return mData.pModel;}
1406 
1408 {
1409  if (mData.isValid())
1410  return mData.pModel;
1411 
1412  return mOldData.pModel;
1413 }
1414 
1416 {
1417  if (mData.isValid())
1418  return mData.pTaskList;
1419 
1420  return mOldData.pTaskList;
1421 }
1422 
1424 {
1425  if (mData.isValid())
1426  return mData.pTaskList;
1427 
1428  return mOldData.pTaskList;
1429 }
1430 
1432 {
1433  CCopasiTask * pTask = NULL;
1434 
1435  switch (taskType)
1436  {
1438  pTask = new CSteadyStateTask(mData.pTaskList);
1439  break;
1440 
1442  pTask = new CTrajectoryTask(mData.pTaskList);
1443  break;
1444 
1445  case CCopasiTask::scan:
1446  pTask = new CScanTask(mData.pTaskList);
1447  break;
1448 
1449  case CCopasiTask::fluxMode:
1450  pTask = new CEFMTask(mData.pTaskList);
1451  break;
1452 
1454  pTask = new COptTask(taskType, mData.pTaskList);
1455  break;
1456 
1458  pTask = new CFitTask(taskType, mData.pTaskList);
1459  break;
1460 
1461  case CCopasiTask::mca:
1462  pTask = new CMCATask(mData.pTaskList);
1463  static_cast< CMCAProblem * >(pTask->getProblem())->setSteadyStateRequested(true);
1464  break;
1465 
1466  case CCopasiTask::lna:
1467  pTask = new CLNATask(mData.pTaskList);
1468  static_cast< CLNAProblem * >(pTask->getProblem())->setSteadyStateRequested(true);
1469  break;
1470 
1471  case CCopasiTask::lyap:
1472  pTask = new CLyapTask(mData.pTaskList);
1473  break;
1474 
1475  case CCopasiTask::sens:
1476  pTask = new CSensTask(mData.pTaskList);
1477  break;
1478 
1480  pTask = new CTSSATask(mData.pTaskList);
1481  break;
1482 
1483  case CCopasiTask::moieties:
1484  pTask = new CMoietiesTask(taskType, mData.pTaskList);
1485  break;
1486 
1488  pTask = new CCrossSectionTask(mData.pTaskList);
1489  break;
1490 
1491  default:
1492  return pTask;
1493  }
1494 
1495  pTask->getProblem()->setModel(mData.pModel);
1496  mData.pTaskList->add(pTask);
1497 
1498  return pTask;
1499 }
1500 
1502 {
1503  size_t i;
1504 
1505  for (i = 0; CCopasiTask::TypeName[i] != ""; i++)
1508 
1509  return true;
1510 }
1511 
1512 bool CCopasiDataModel::appendDependentTasks(std::set< const CCopasiObject * > candidates,
1513  std::set< const CCopasiObject * > & dependentTasks) const
1514 {
1515  size_t Size = dependentTasks.size();
1516 
1517  std::set< const CCopasiObject * >::const_iterator it = candidates.begin();
1518  std::set< const CCopasiObject * >::const_iterator end = candidates.end();
1519 
1522 
1523  for (; it != end; ++it)
1524  {
1525  const CReportDefinition * pReportDefinition = dynamic_cast< const CReportDefinition * >(*it);
1526 
1527  if (pReportDefinition == NULL)
1528  continue;
1529 
1530  itTask = mData.pTaskList->begin();
1531 
1532  for (; itTask != endTask; ++itTask)
1533  {
1534  if ((*itTask)->getReport().getReportDefinition() == pReportDefinition)
1535  {
1536  dependentTasks.insert(*itTask);
1537  }
1538  }
1539  }
1540 
1541  return Size < dependentTasks.size();
1542 }
1543 
1545 {
1546  CReportDefinition * pReport = NULL;
1547 
1548  switch (taskType)
1549  {
1551  pReport = new CReportDefinition(CCopasiTask::TypeName[taskType]);
1552  pReport->setTaskType(taskType);
1553  pReport->setComment("Automatically generated report.");
1554  pReport->setIsTable(false);
1555  pReport->setSeparator(CCopasiReportSeparator("\t"));
1556  pReport->getFooterAddr()->push_back(CCopasiObjectName("CN=Root,Vector=TaskList[Steady-State]"));
1557  break;
1558 
1560  // No default report available.
1561  break;
1562 
1563  case CCopasiTask::scan:
1564  // No default report available.
1565  break;
1566 
1567  case CCopasiTask::fluxMode:
1568  pReport = new CReportDefinition(CCopasiTask::TypeName[taskType]);
1569  pReport->setTaskType(taskType);
1570  pReport->setComment("Automatically generated report.");
1571  pReport->setIsTable(false);
1572  pReport->setSeparator(CCopasiReportSeparator("\t"));
1573  pReport->getFooterAddr()->push_back(CCopasiObjectName("CN=Root,Vector=TaskList[Elementary Flux Modes],Object=Result"));
1574  break;
1575 
1577  pReport = new CReportDefinition(CCopasiTask::TypeName[taskType]);
1578  pReport->setTaskType(taskType);
1579  pReport->setComment("Automatically generated report.");
1580  pReport->setIsTable(false);
1581  pReport->setTitle(false);
1582  pReport->setSeparator(CCopasiReportSeparator("\t"));
1583 
1584  // Header
1585  pReport->getHeaderAddr()->push_back(CCopasiObjectName("CN=Root,Vector=TaskList[Optimization],Object=Description"));
1586  pReport->getHeaderAddr()->push_back(CCopasiObjectName("String=\\[Function Evaluations\\]"));
1587  pReport->getHeaderAddr()->push_back(CCopasiObjectName("Separator=\t"));
1588  pReport->getHeaderAddr()->push_back(CCopasiObjectName("String=\\[Best Value\\]"));
1589  pReport->getHeaderAddr()->push_back(CCopasiObjectName("Separator=\t"));
1590  pReport->getHeaderAddr()->push_back(CCopasiObjectName("String=\\[Best Parameters\\]"));
1591 
1592  // Body
1593  pReport->getBodyAddr()->push_back(CCopasiObjectName("CN=Root,Vector=TaskList[Optimization],Problem=Optimization,Reference=Function Evaluations"));
1594  pReport->getBodyAddr()->push_back(CCopasiObjectName("Separator=\t"));
1595  pReport->getBodyAddr()->push_back(CCopasiObjectName("CN=Root,Vector=TaskList[Optimization],Problem=Optimization,Reference=Best Value"));
1596  pReport->getBodyAddr()->push_back(CCopasiObjectName("Separator=\t"));
1597  pReport->getBodyAddr()->push_back(CCopasiObjectName("CN=Root,Vector=TaskList[Optimization],Problem=Optimization,Reference=Best Parameters"));
1598 
1599  // Footer
1600  pReport->getFooterAddr()->push_back(CCopasiObjectName("String=\n"));
1601  pReport->getFooterAddr()->push_back(CCopasiObjectName("CN=Root,Vector=TaskList[Optimization],Object=Result"));
1602  break;
1603 
1604  //**************************************************************************
1606  pReport = new CReportDefinition(CCopasiTask::TypeName[taskType]);
1607  pReport->setTaskType(taskType);
1608  pReport->setComment("Automatically generated report.");
1609  pReport->setIsTable(false);
1610  pReport->setTitle(false);
1611  pReport->setSeparator(CCopasiReportSeparator("\t"));
1612 
1613  // Header
1614  pReport->getHeaderAddr()->push_back(CCopasiObjectName("CN=Root,Vector=TaskList[Parameter Estimation],Object=Description"));
1615  pReport->getHeaderAddr()->push_back(CCopasiObjectName("String=\\[Function Evaluations\\]"));
1616  pReport->getHeaderAddr()->push_back(CCopasiObjectName("Separator=\t"));
1617  pReport->getHeaderAddr()->push_back(CCopasiObjectName("String=\\[Best Value\\]"));
1618  pReport->getHeaderAddr()->push_back(CCopasiObjectName("Separator=\t"));
1619  pReport->getHeaderAddr()->push_back(CCopasiObjectName("String=\\[Best Parameters\\]"));
1620 
1621  // Body
1622  pReport->getBodyAddr()->push_back(CCopasiObjectName("CN=Root,Vector=TaskList[Parameter Estimation],Problem=Parameter Estimation,Reference=Function Evaluations"));
1623  pReport->getBodyAddr()->push_back(CCopasiObjectName("Separator=\t"));
1624  pReport->getBodyAddr()->push_back(CCopasiObjectName("CN=Root,Vector=TaskList[Parameter Estimation],Problem=Parameter Estimation,Reference=Best Value"));
1625  pReport->getBodyAddr()->push_back(CCopasiObjectName("Separator=\t"));
1626  pReport->getBodyAddr()->push_back(CCopasiObjectName("CN=Root,Vector=TaskList[Parameter Estimation],Problem=Parameter Estimation,Reference=Best Parameters"));
1627 
1628  // Footer
1629  pReport->getFooterAddr()->push_back(CCopasiObjectName("String=\n"));
1630  pReport->getFooterAddr()->push_back(CCopasiObjectName("CN=Root,Vector=TaskList[Parameter Estimation],Object=Result"));
1631  break;
1632 
1633  //**************************************************************************
1634  case CCopasiTask::lyap:
1635  pReport = new CReportDefinition(CCopasiTask::TypeName[taskType]);
1636  pReport->setTaskType(taskType);
1637  pReport->setComment("Automatically generated report.");
1638  pReport->setIsTable(false);
1639  pReport->setTitle(false);
1640  pReport->setSeparator(CCopasiReportSeparator("\t"));
1641 
1642  // Header
1643  pReport->getHeaderAddr()->push_back(CCopasiObjectName("CN=Root,Vector=TaskList[Lyapunov Exponents],Object=Description"));
1644 
1645  // Footer
1646  pReport->getFooterAddr()->push_back(CCopasiObjectName("String=\n"));
1647  pReport->getFooterAddr()->push_back(CCopasiObjectName("CN=Root,Vector=TaskList[Lyapunov Exponents],Object=Result"));
1648  break;
1649 
1650  //**************************************************************************
1651  case CCopasiTask::mca:
1652  pReport = new CReportDefinition(CCopasiTask::TypeName[taskType]);
1653  pReport->setTaskType(taskType);
1654  pReport->setComment("Automatically generated report.");
1655  pReport->setIsTable(false);
1656  pReport->setTitle(false);
1657  pReport->setSeparator(CCopasiReportSeparator("\t"));
1658 
1659  // Header
1660  pReport->getHeaderAddr()->push_back(CCopasiObjectName("CN=Root,Vector=TaskList[Metabolic Control Analysis],Object=Description"));
1661 
1662  // Footer
1663  pReport->getFooterAddr()->push_back(CCopasiObjectName("String=\n"));
1664  pReport->getFooterAddr()->push_back(CCopasiObjectName("CN=Root,Vector=TaskList[Metabolic Control Analysis],Object=Result"));
1665  break;
1666 
1667  //**************************************************************************
1668  case CCopasiTask::lna:
1669  pReport = new CReportDefinition(CCopasiTask::TypeName[taskType]);
1670  pReport->setTaskType(taskType);
1671  pReport->setComment("Automatically generated report.");
1672  pReport->setIsTable(false);
1673  pReport->setTitle(false);
1674  pReport->setSeparator(CCopasiReportSeparator("\t"));
1675 
1676  // Header
1677  pReport->getHeaderAddr()->push_back(CCopasiObjectName("CN=Root,Vector=TaskList[Linear Noise Approximation],Object=Description"));
1678 
1679  // Footer
1680  pReport->getFooterAddr()->push_back(CCopasiObjectName("String=\n"));
1681  pReport->getFooterAddr()->push_back(CCopasiObjectName("CN=Root,Vector=TaskList[Linear Noise Approximation],Object=Result"));
1682  break;
1683 
1684  //**************************************************************************
1685  case CCopasiTask::sens:
1686  pReport = new CReportDefinition(CCopasiTask::TypeName[taskType]);
1687  pReport->setTaskType(taskType);
1688  pReport->setComment("Automatically generated report.");
1689  pReport->setIsTable(false);
1690  pReport->setTitle(false);
1691  pReport->setSeparator(CCopasiReportSeparator("\t"));
1692 
1693  // Header
1694  pReport->getHeaderAddr()->push_back(CCopasiObjectName("CN=Root,Vector=TaskList[Sensitivities],Object=Description"));
1695 
1696  // Footer
1697  pReport->getFooterAddr()->push_back(CCopasiObjectName("String=\n"));
1698  pReport->getFooterAddr()->push_back(CCopasiObjectName("CN=Root,Vector=TaskList[Sensitivities],Object=Result"));
1699  break;
1700 
1701  //**************************************************************************
1703  pReport = new CReportDefinition(CCopasiTask::TypeName[taskType]);
1704  pReport->setTaskType(taskType);
1705  pReport->setComment("Automatically generated report.");
1706  pReport->setIsTable(false);
1707  pReport->setTitle(false);
1708  pReport->setSeparator(CCopasiReportSeparator("\t"));
1709 
1710  // Header
1711  pReport->getHeaderAddr()->push_back(CCopasiObjectName("CN=Root,Vector=TaskList[Time Scale Separation Analysis],Object=Description"));
1712 
1713  // Footer
1714  pReport->getFooterAddr()->push_back(CCopasiObjectName("String=\n"));
1715  pReport->getFooterAddr()->push_back(CCopasiObjectName("CN=Root,Vector=TaskList[Time Scale Separation Analysis],Object=Result"));
1716  break;
1717 
1718  default:
1719  return pReport;
1720  }
1721 
1722  if (pReport) mData.pReportDefinitionList->add(pReport, true);
1723 
1724  return pReport;
1725 }
1726 
1728 {
1729  size_t i;
1730 
1731  for (i = 0; CCopasiTask::TypeName[i] != ""; i++)
1732  {
1733  //try to create the report if it doesn't exist
1735  {
1737  }
1738 
1739  //see if the report exists now
1740  CReportDefinition* pReportDef = NULL;
1741 
1744 
1745  //see if the task exists
1746  CCopasiTask* pTask = NULL;
1747 
1749  pTask = (*mData.pTaskList)[CCopasiTask::TypeName[i]];
1750 
1751  if (pTask && pReportDef) //task and report definition exist
1752  {
1753  //if there is no report definition set the default
1754  if (!pTask->getReport().getReportDefinition())
1755  {
1756  pTask->getReport().setReportDefinition(pReportDef);
1757  }
1758 
1759  //TODO: also set the default report if no target file is set
1760  //even if a report is already set?
1761  }
1762  }
1763 
1764  return true;
1765 }
1766 
1768 {
1769  if (mData.isValid())
1771 
1773 }
1774 
1776 {
1777  if (mData.isValid())
1779 
1781 }
1782 
1784 {
1785  if (mData.isValid())
1786  return mData.pPlotDefinitionList;
1787 
1789 }
1790 
1792 {
1793  if (mData.isValid())
1794  return mData.pPlotDefinitionList;
1795 
1797 }
1798 
1800 {
1801  if (mData.isValid())
1802  return mData.pListOfLayouts;
1803 
1804  return mOldData.pListOfLayouts;
1805 }
1806 
1808 {
1809  if (mData.isValid())
1810  return mData.pListOfLayouts;
1811 
1812  return mOldData.pListOfLayouts;
1813 }
1814 
1816 {
1817  if (mData.isValid())
1818  return mData.pGUI;
1819 
1820  return mOldData.pGUI;
1821 }
1822 
1823 const std::string & CCopasiDataModel::getFileName() const
1824 {return mData.mSaveFileName;}
1825 
1827 {return mData.mChanged;}
1828 
1829 void CCopasiDataModel::changed(const bool & changed)
1830 {
1833 }
1834 
1836 {
1837  return mData.pCurrentSBMLDocument;
1838 }
1839 
1840 bool CCopasiDataModel::setSBMLFileName(const std::string & fileName)
1841 {
1843 
1847 
1848  return true;
1849 }
1850 
1851 const std::string & CCopasiDataModel::getSBMLFileName() const
1852 {return mData.mSBMLFileName;}
1853 
1854 std::map<CCopasiObject*, SBase*>& CCopasiDataModel::getCopasi2SBMLMap()
1855 {
1856  return mData.mCopasi2SBMLMap;
1857 }
1858 
1860 {
1862  size_t i, iMax = pFunDB->loadedFunctions().size();
1863 
1864  for (i = 0; i < iMax; ++i)
1865  {
1866  pFunDB->loadedFunctions()[i]->setSBMLId("");
1867  }
1868 }
1869 
1870 bool CCopasiDataModel::removeLayout(const std::string & key)
1871 {
1872  CLayout *pLayout =
1873  dynamic_cast< CLayout * >(CCopasiRootContainer::getKeyFactory()->get(key));
1874 
1875  if (!pLayout)
1876  return false;
1877 
1878  //Check if Layout with that name exists
1879  size_t index =
1880  mData.pListOfLayouts->CCopasiVector< CLayout >::getIndex(pLayout);
1881 
1882  if (index == C_INVALID_INDEX)
1883  return false;
1884 
1885  mData.pListOfLayouts->CCopasiVector< CLayout >::remove(index);
1886 
1887  return true;
1888 }
1889 
1890 CObjectInterface * CCopasiDataModel::ObjectFromCN(const std::vector< CCopasiContainer * > & listOfContainer,
1891  const CCopasiObjectName & objName) const
1892 {
1893  const CObjectInterface * pObject = NULL;
1894  const CCopasiContainer* pContainer;
1895  CCopasiObjectName ContainerName;
1896  size_t containerIndex;
1897  std::string::size_type pos;
1898 
1899  //favor to search the list of container first
1900  for (containerIndex = 0;
1901  containerIndex < listOfContainer.size() && !pObject;
1902  containerIndex++)
1903  {
1904  pContainer = listOfContainer[containerIndex];
1905 
1906  if (pContainer == NULL)
1907  {
1908  continue;
1909  }
1910 
1911  ContainerName = pContainer->getCN();
1912 
1913  while (ContainerName.getRemainder() != "")
1914  {
1915  ContainerName = ContainerName.getRemainder();
1916  }
1917 
1918  if ((pos = objName.find(ContainerName)) == std::string::npos)
1919  continue;
1920 
1921  if (pos + ContainerName.length() == objName.length())
1922  pObject = pContainer;
1923  else
1924  pObject = pContainer->getObject(objName.substr(pos + ContainerName.length() + 1));
1925  }
1926 
1927  // If we have not found the object in the context we search the whole data model.
1928  if (pObject == NULL)
1929  {
1930  pObject = getObject(objName);
1931  }
1932 
1933  // if still not found search the function database in the root container
1934  if (!pObject)
1935  pObject = CCopasiRootContainer::getFunctionList()->getObject(objName);
1936 
1937  return const_cast< CObjectInterface * >(pObject);
1938 }
1939 
1940 CCopasiObject * CCopasiDataModel::ObjectFromName(const std::vector< CCopasiContainer * > & listOfContainer,
1941  const CCopasiObjectName & objName) const
1942 {
1943  // TODO CRITICAL This does not work for math as object ObjectFromCN only returns a CObjectInterface.
1944  return static_cast< CCopasiObject * >(ObjectFromCN(listOfContainer, objName));
1945 }
1946 
1948 {
1949  return dynamic_cast< CCopasiObject *>(const_cast< CObjectInterface * >(getObject(CN)));
1950 }
1951 
1953 {
1954  return mData.mReferenceDir;
1955 }
1956 
1957 CCopasiDataModel::CData::CData(const bool & withGUI):
1958  pModel(NULL),
1959  pTaskList(NULL),
1960  pReportDefinitionList(NULL),
1961  pPlotDefinitionList(NULL),
1962  pListOfLayouts(NULL),
1963  pGUI(NULL),
1964  pCurrentSBMLDocument(NULL),
1965  mWithGUI(withGUI),
1966  mSaveFileName(),
1967  mFileType(unset),
1968  mChanged(false),
1969  mAutoSaveNeeded(false),
1970  mSBMLFileName(""),
1971  mReferenceDir("")
1972 #ifdef COPASI_SEDML
1973  , pCurrentSEDMLDocument(NULL)
1974 #endif
1975 {}
1976 
1978  pModel(src.pModel),
1979  pTaskList(src.pTaskList),
1980  pReportDefinitionList(src.pReportDefinitionList),
1981  pPlotDefinitionList(src.pPlotDefinitionList),
1982  pListOfLayouts(src.pListOfLayouts),
1983  pGUI(src.pGUI),
1984  pCurrentSBMLDocument(src.pCurrentSBMLDocument),
1985  mWithGUI(src.mWithGUI),
1986  mSaveFileName(src.mSaveFileName),
1987  mFileType(src.mFileType),
1988  mChanged(src.mChanged),
1989  mAutoSaveNeeded(src.mAutoSaveNeeded),
1990  mSBMLFileName(src.mSBMLFileName),
1991  mReferenceDir(src.mReferenceDir)
1992 #ifdef COPASI_SEDML
1993  , pCurrentSEDMLDocument(src.pCurrentSEDMLDocument)
1994 #endif
1995 {}
1996 
1998 {}
1999 
2001 {
2002  pModel = rhs.pModel;
2003  pTaskList = rhs.pTaskList;
2004  pReportDefinitionList = rhs.pReportDefinitionList;
2005  pPlotDefinitionList = rhs.pPlotDefinitionList;
2006  pListOfLayouts = rhs.pListOfLayouts;
2007  pGUI = rhs.pGUI;
2008  pCurrentSBMLDocument = rhs.pCurrentSBMLDocument;
2009  mWithGUI = rhs.mWithGUI,
2010  mSaveFileName = rhs.mSaveFileName;
2011  mFileType = rhs.mFileType;
2012  mChanged = rhs.mChanged;
2013  mAutoSaveNeeded = rhs.mAutoSaveNeeded;
2014  mSBMLFileName = rhs.mSBMLFileName;
2015  mReferenceDir = rhs.mReferenceDir;
2016  mCopasi2SBMLMap = rhs.mCopasi2SBMLMap;
2017 #ifdef COPASI_SEDML
2018  pCurrentSEDMLDocument = rhs.pCurrentSEDMLDocument;
2019 #endif
2020  return *this;
2021 }
2022 
2024 {
2025  return (pModel != NULL &&
2026  pTaskList != NULL &&
2027  pReportDefinitionList != NULL &&
2028  pPlotDefinitionList != NULL &&
2029  pListOfLayouts != NULL &&
2030  (pGUI != NULL || mWithGUI == false));
2031 }
2032 
2034 {
2035  bool condition = true;
2036 #ifdef COPASI_SEDML
2037  condition = mOldData.pCurrentSEDMLDocument == NULL;
2038 #endif
2039  // make sure the old data has been deleted.
2040  assert(mOldData.pModel == NULL &&
2041  mOldData.pTaskList == NULL &&
2042  mOldData.pReportDefinitionList == NULL &&
2043  mOldData.pPlotDefinitionList == NULL &&
2044  mOldData.pListOfLayouts == NULL &&
2045  mOldData.pGUI == NULL &&
2046  condition
2047  );
2048 
2049  mOldData = mData;
2051 }
2052 
2054 {
2055  // Make sure the old data is valid
2056  assert(mOldData.pModel != NULL &&
2057  mOldData.pTaskList != NULL &&
2058  mOldData.pReportDefinitionList != NULL &&
2059  mOldData.pPlotDefinitionList != NULL &&
2060  mOldData.pListOfLayouts != NULL &&
2061  (mOldData.pGUI != NULL || mOldData.mWithGUI == false));
2062 
2063  // TODO CRITICAL We need to clean up mData to avoid memory leaks.
2064 
2065  mData = mOldData;
2067 }
2068 
2070  const bool & deleteOldData)
2071 {
2072  if (mData.pModel == NULL)
2073  {
2074  mData.pModel = new CModel(this);
2075  }
2076 
2077  if (mData.pListOfLayouts == NULL)
2078  {
2079  mData.pListOfLayouts = new CListOfLayouts("ListOflayouts", this);
2080  }
2081 
2082  if (mData.pTaskList == NULL)
2083  {
2084  mData.pTaskList = new CCopasiVectorN< CCopasiTask >("TaskList", this);
2085  }
2086 
2087  if (mData.pReportDefinitionList == NULL)
2088  {
2089  mData.pReportDefinitionList = new CReportDefinitionVector("ReportDefinitions", this);
2090  }
2091 
2092  if (mData.pPlotDefinitionList == NULL)
2093  {
2094  mData.pPlotDefinitionList = new COutputDefinitionVector("OutputDefinitions", this);
2095  }
2096 
2097  if (mData.mWithGUI && mData.pGUI == NULL)
2098  {
2099  mData.pGUI = new SCopasiXMLGUI("GUI", this);
2100  }
2101 
2102  // We have at least one task of every type
2103  addDefaultTasks();
2105 
2106  if (mOldData.pModel != NULL &&
2108  {
2110  remove(mOldData.pModel);
2111  }
2112  else
2113  mOldData.pModel = NULL;
2114 
2115  if (mOldData.pTaskList != NULL &&
2117  {
2119  remove(mOldData.pTaskList);
2120  }
2121  else
2122  mOldData.pTaskList = NULL;
2123 
2124  if (mOldData.pReportDefinitionList != NULL &&
2126  {
2129  }
2130  else
2132 
2133  if (mOldData.pPlotDefinitionList != NULL &&
2135  {
2137  remove(mOldData.pPlotDefinitionList);
2138  }
2139  else
2141 
2142  if (mOldData.pListOfLayouts != NULL &&
2144  {
2146  remove(mOldData.pListOfLayouts);
2147  }
2148  else
2149  mOldData.pListOfLayouts = NULL;
2150 
2151  if (mOldData.pGUI != NULL &&
2152  mOldData.pGUI != mData.pGUI)
2153  {
2154  mOldData.pGUI->setObjectParent(NULL);
2155  remove(mOldData.pGUI);
2156  }
2157  else
2158  mOldData.pGUI = NULL;
2159 
2162 
2163 #ifdef COPASI_SEDML
2164 
2165  if (mOldData.pCurrentSEDMLDocument == mData.pCurrentSEDMLDocument)
2166  mOldData.pCurrentSEDMLDocument = NULL;
2167 
2168 #endif
2169 
2171 
2172  // We need to initialize all the task so that results are available
2173 
2174  // We suppress all errors and warnings
2175  size_t Size = CCopasiMessage::size();
2176 
2179 
2180  for (; it != end; ++it)
2181  {
2182  try
2183  {
2184  // need initialize, so that all objects are created for the
2185  // object browser
2186  (*it)->initialize(CCopasiTask::NO_OUTPUT, NULL, NULL);
2187 
2188  // but we should restore any possible changes made to the model
2189  // by the task, without updating the model
2190  bool update = (*it)->isUpdateModel();
2191  (*it)->setUpdateModel(false);
2192  (*it)->restore();
2193  (*it)->setUpdateModel(update);
2194  }
2195 
2196  catch (...) {}
2197  }
2198 
2199  // Remove error messages created by the task initialization as this may fail
2200  // due to incomplete task specification at this time.
2201  while (CCopasiMessage::size() > Size)
2203 
2204  if (mData.pModel)
2205  {
2206  mData.pModel->compileIfNecessary(pProcessReport);
2208  }
2209 
2210  changed(false);
2211 
2212  if (deleteOldData)
2213  {
2215  }
2216 }
bool freePlotList()
Definition: CCopasiXML.cpp:331
virtual bool setObjectParent(const CCopasiContainer *pParent)
void setImportCOPASIMIRIAM(bool import)
SCopasiXMLGUI * getGUI()
CCopasiVectorN< CFunction > & loadedFunctions()
CCopasiObject * getDataObject(const CCopasiObjectName &CN) const
SBMLDocument * getCurrentSBMLDocument()
static bool remove(const std::string &path)
Definition: CDirEntry.cpp:275
const CModelParameterSet & getModelParameterSet() const
Definition: CModel.cpp:1072
bool setSBMLFileName(const std::string &fileName)
#define pdelete(p)
Definition: copasi.h:215
void restoreFunctionDB()
static bool move(const std::string &from, const std::string &to)
Definition: CDirEntry.cpp:233
static const std::string TypeName[]
Definition: CCopasiTask.h:67
CCopasiProblem * getProblem()
CModel * readSEDML(std::string filename, CProcessReport *pImportHandler, SBMLDocument *&pSBMLDocument, SedDocument *&pSedDocument, std::map< CCopasiObject *, SedBase * > &copasi2sedmlmap, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap, CListOfLayouts *&prLol, COutputDefinitionVector *&plotList, CCopasiDataModel *pDataModel)
CData & operator=(const CData &rhs)
virtual CCopasiObjectName getCN() const
bool setTaskType(const CCopasiTask::Type &taskType)
CCopasiObjectName getRemainder() const
static bool isRelativePath(const std::string &path)
Definition: CDirEntry.cpp:414
void commonAfterLoad(CProcessReport *pProcessReport, const bool &deleteOldData)
const CCopasiVectorN< CModelValue > & getModelValues() const
Definition: CModel.cpp:1060
bool appendDependentTasks(std::set< const CCopasiObject * > candidates, std::set< const CCopasiObject * > &dependentTasks) const
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
virtual size_t size() const
bool setModel(CModel *pModel)
Definition: CCopasiXML.cpp:254
bool freeModel()
Definition: CCopasiXML.cpp:264
CCopasiObject * get(const std::string &key)
void setTitle(bool title)
CListOfLayouts * getLayoutList() const
Definition: CCopasiXML.cpp:383
iterator begin()
static std::string getAllMessageText(const bool &chronological=true)
bool newModel(CProcessReport *pProcessReport, const bool &deleteOldData)
CReportDefinitionVector * pReportDefinitionList
void deleteCopasiModel()
#define fatalError()
CObjectInterface * ObjectFromCN(const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiObjectName &objName) const
void setImportHandler(CProcessReport *pHandler)
bool setFunctionList(CCopasiVectorN< CFunction > *pFunctionList)
Definition: CCopasiXML.cpp:270
void deleteCopasiModel()
bool importSBML(const std::string &fileName, CProcessReport *pImportHandler=NULL, const bool &deleteOldData=true)
#define MCXML
static std::string fileName(const std::string &path)
Definition: CDirEntry.cpp:119
#define C_INVALID_INDEX
Definition: copasi.h:222
std::string getVersion()
Definition: CReadConfig.cpp:76
CData(const bool &withGUI=false)
virtual size_t getIndex(const std::string &name) const
void setSeparator(const CCopasiReportSeparator &Separator)
const std::string exportModelAndTasksToString(CCopasiDataModel &dataModel, std::string &sbmldocument, unsigned int sedmlLevel, unsigned int sedmlVersion)
COutputDefinitionVector * getPlotList() const
Definition: CCopasiXML.cpp:325
CModel * parseSEDML(const std::string &sedmlDocumentText, CProcessReport *pImportHandler, SBMLDocument *&pSBMLDocument, SedDocument *&pSEDMLDocument, std::map< CCopasiObject *, SedBase * > &copasi2sedmlmap, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap, CListOfLayouts *&prLol, COutputDefinitionVector *&plotList, CCopasiDataModel *pDataModel)
void changed(const bool &changed=true)
bool freeGUI()
Definition: CCopasiXML.cpp:369
static std::string baseName(const std::string &path)
Definition: CDirEntry.cpp:98
static void clearDeque()
SBMLDocument * getSBMLDocument()
Definition: CSBMLExporter.h:95
void setIsTable(bool table)
static std::string dirName(const std::string &path)
Definition: CDirEntry.cpp:135
virtual bool setModel(CModel *pModel)
COutputDefinitionVector * pPlotDefinitionList
const std::string & getFileName() const
const CReportDefinitionVector * getReportDefinitionList() const
bool freeTaskList()
Definition: CCopasiXML.cpp:311
CCopasiDataModel(const bool withGUI=false)
CTSSATask * pTask
const std::string & getReferenceDirectory() const
virtual void handle(const std::string &oldCN, const std::string &newCN) const
void setExportCOPASIMIRIAM(bool exportMIRIAM)
iterator end()
std::vector< CType * >::const_iterator const_iterator
Definition: CCopasiVector.h:57
bool setDatamodel(CCopasiDataModel *pDataModel)
Definition: CCopasiXML.cpp:299
bool removeLayout(const std::string &key)
virtual bool add(const CType &src)
void setComment(const std::string &comment)
#define MCODEExporter
static bool exist(const std::string &path)
Definition: CDirEntry.cpp:78
std::vector< CRegisteredObjectName > * getFooterAddr()
bool setTaskList(CCopasiVectorN< CCopasiTask > *pTaskList)
Definition: CCopasiXML.cpp:288
static const std::string Separator
Definition: CDirEntry.h:34
struct MESSAGES Message
CModel * parseSBML(const std::string &sbmlDocumentText, CFunctionDB *funDB, SBMLDocument *&pSBMLDocument, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap, CListOfLayouts *&prLol, CCopasiDataModel *pDataModel)
static size_t size()
const std::string & getSBMLFileName() const
CListOfLayouts * pListOfLayouts
CCopasiVectorN< CCopasiTask > * getTaskList()
static bool isWritable(const std::string &path)
Definition: CDirEntry.cpp:95
bool isChanged() const
CReportDefinition * addReport(const CCopasiTask::Type &taskType)
bool freeLayoutList()
Definition: CCopasiXML.cpp:389
bool setPlotList(COutputDefinitionVector *pPlotList)
Definition: CCopasiXML.cpp:319
bool loadModel(std::istream &in, const std::string &pwd, CProcessReport *pProcessReport, const bool &deleteOldData=true)
CListOfLayouts * getListOfLayouts()
void setEnabled(const bool &enabled)
bool saveModel(const std::string &fileName, CProcessReport *pProcessReport, bool overwriteFile=false, const bool &autoSave=false)
static std::string createTmpName(const std::string &dir, const std::string &suffix)
Definition: CDirEntry.cpp:202
bool setLayoutList(const CListOfLayouts &reportList)
Definition: CCopasiXML.cpp:377
CCopasiTask * addTask(const CCopasiTask::Type &taskType)
static CFunctionDB * getFunctionList()
#define MCDirEntry
static void getValue(const std::string &name, CType &value)
Definition: COptions.h:124
CCopasiVectorN< CCopasiTask > * pTaskList
const std::string exportModelToString(CCopasiDataModel &dataModel, unsigned int sbmlLevel, unsigned int sbmlVersion)
CReportDefinitionVector * getReportList() const
Definition: CCopasiXML.cpp:345
SBMLDocument * pCurrentSBMLDocument
void load(CReadConfig &configBuffer)
static const std::set< CRegisteredObjectName * > & getSet()
virtual bool setObjectParent(const CCopasiContainer *pParent)
void setImportHandler(CProcessReport *pHandler)
bool exportSBML(const std::string &fileName, bool overwriteFile=false, int sbmlLevel=2, int sbmlVersion=1, bool exportIncomplete=false, bool exportCOPASIMIRIAM=true, CProcessReport *pExportHandler=NULL)
CModel * getModel() const
Definition: CCopasiXML.cpp:260
bool exportToStream(const CCopasiDataModel *pDataModel, std::ostream &os)
static CKeyFactory * getKeyFactory()
bool setGUI(SCopasiXMLGUI *pGUI)
Definition: CCopasiXML.cpp:359
const COutputDefinitionVector * getPlotDefinitionList() const
CReport & getReport()
bool setReportList(CReportDefinitionVector *pReportList)
Definition: CCopasiXML.cpp:339
bool compileIfNecessary(CProcessReport *pProcessReport)
Definition: CModel.cpp:612
static CCopasiMessage getLastMessage()
std::vector< CRegisteredObjectName > * getBodyAddr()
bool importSBMLFromString(const std::string &sbmlDocumentText, CProcessReport *pImportHandler=NULL, const bool &deleteOldData=true)
bool freeReportList()
Definition: CCopasiXML.cpp:351
virtual bool add(CCopasiObject *pObject, const bool &adopt=true)
static std::string normalize(const std::string &path)
Definition: CDirEntry.cpp:560
bool updateInitialValues()
Definition: CModel.cpp:1461
virtual bool refreshFromModel(const bool &modifyExistence)
bool exportMathModel(const std::string &fileName, CProcessReport *pProcessReport, const std::string &filter, bool overwriteFile=false)
std::map< CCopasiObject *, SBase * > mCopasi2SBMLMap
Definition: CModel.h:50
virtual bool load(std::istream &is, const std::string &pwd)
Definition: CCopasiXML.cpp:169
void disownSBMLDocument()
virtual const CObjectInterface * getObject(const CCopasiObjectName &cn) const
static CLocaleString fromUtf8(const std::string &utf8)
static void setRenameHandler(CRenameHandler *rh)
CReportDefinition * getReportDefinition()
Definition: CReport.cpp:83
static bool makePathAbsolute(std::string &relativePath, const std::string &absoluteTo)
Definition: CDirEntry.cpp:481
void setReportDefinition(CReportDefinition *reportDef)
Definition: CReport.cpp:86
CModel * readSBML(std::string filename, CFunctionDB *funDB, SBMLDocument *&pSBMLDocument, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap, CListOfLayouts *&prLol, CCopasiDataModel *pDataModel)
CDataModelRenameHandler mRenameHandler
std::string exportMathModelToString(CProcessReport *pProcessReport, const std::string &filter)
CCopasiVectorS< CMetabOld > * pOldMetabolites
std::map< CCopasiObject *, SBase * > & getCopasi2SBMLMap()
void load(CReadConfig &configBuffer)
CCopasiVectorN< CCopasiTask > * getTaskList() const
Definition: CCopasiXML.cpp:305
CCopasiObject * ObjectFromName(const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiObjectName &CN) const
std::vector< CRegisteredObjectName > * getHeaderAddr()
bool exportModelAndTasks(CCopasiDataModel &dataModel, const std::string &SEDMLFilename, const std::string &SBMLFilename, unsigned int sedmlLevel=1, unsigned int sedmlVersion=1, bool overwrite=false)
static std::string suffix(const std::string &path)
Definition: CDirEntry.cpp:159
const std::map< const CCopasiObject *, SBase * > & getCOPASI2SBMLMap() const
void importTasks(std::map< CCopasiObject *, SedBase * > &copasi2sedmlmap)
void restoreFunctionDB()
bool exportModel(CCopasiDataModel &dataModel, const std::string &filename, unsigned int sbmlLevel=2, unsigned int sbmlVersion=1, bool overwrite=false)
virtual bool updateModel()
C_INT32 load(CReadConfig &configBuffer)
Definition: CModel.cpp:255