COPASI API  4.16.103
CCopasiDataModel.h
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2014 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2005 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #ifndef COPASI_CCopasiDataModel
16 #define COPASI_CCopasiDataModel
17 
18 #include <map>
19 
21 #include "utilities/CCopasiTask.h"
22 
23 class CModel;
26 class CFunctionDB;
27 class CFunction;
28 class SCopasiXMLGUI;
29 class SBMLDocument;
30 class SBase;
31 class CProcessReport;
32 class CConfigurationFile;
34 class CListOfLayouts;
35 
36 //TODO SEDML
37 #ifdef COPASI_SEDML
38 class SedBase;
39 class SedDocument;
40 class CPlotItem;
41 #endif
42 
43 // :TODO: remove
44 class CMetabOld;
45 
46 template <class CType> class CCopasiVectorS;
47 template <class CType> class CCopasiVectorN;
48 
49 //******************************************************************************
50 
52 class CCopasiDataModel;
53 
55 {
56 public:
58 
60 
61  virtual void handle(const std::string & oldCN, const std::string & newCN) const;
62 
63  /**
64  * Enable and disable the rename handler
65  * @param const bool & enabled
66  */
67  void setEnabled(const bool & enabled);
68 
69 private:
70  /**
71  * Flag whether the rename handler is enable or not
72  */
73  bool mEnabled;
74 };
75 
76 //******************************************************************************
77 
79 {
80  enum FileType
81  {
82  CopasiML = 0,
87  };
88 
89 private:
90  class CData
91  {
92  public:
93 
94  CData(const bool & withGUI = false);
95 
96  CData(const CData & src);
97 
98  ~CData();
99 
100  CData & operator = (const CData & rhs);
101  bool isValid() const;
102 
109  SBMLDocument* pCurrentSBMLDocument;
110 
111  bool mWithGUI;
112 
113  std::string mSaveFileName;
115  bool mChanged;
117 
118  /**
119  * The name of the referenced SBML file
120  */
121  std::string mSBMLFileName;
122 
123  /**
124  * This will map each COPASI object to the
125  * corresponding SBML object if the current model
126  * was created by an SBML import.
127  */
128  std::map<CCopasiObject*, SBase*> mCopasi2SBMLMap;
129 
130  // if we want to display images in the render extension,
131  // those images can be png or jpg files with a relative path name.
132  // If the path is relative, it is considered to be relative to the
133  // path of the filename it came from.
134  // Because of this, I need to know the reference directory where
135  // the render information came from because it can either come from
136  // an imported SBML file or from a loaded cps file.
137  std::string mReferenceDir;
138 
139  //TODO SEDML
140 #ifdef COPASI_SEDML
141  SedDocument* pCurrentSEDMLDocument;
142 
143  /**
144  * This will map each COPASI object to the
145  * corresponding SEDML object if the current model
146  * was created by an SEDML import.
147  */
148  std::map<CCopasiObject*, SedBase*> mCopasi2SEDMLMap;
149 
150  /**
151  * The name of the referenced SEDML file
152  */
153  std::string mSEDMLFileName;
154 
155 #endif
156  };
157 
158  // Operations
159 public:
160  CCopasiDataModel(const bool withGUI = false);
161 
162  CCopasiDataModel(const std::string & name,
163  const CCopasiContainer * pParent = NULL,
164  const std::string & type = "CN",
165  bool withGUI = false);
166 
167  virtual ~CCopasiDataModel();
168 
169  bool loadModel(std::istream & in,
170  const std::string & pwd,
171  CProcessReport* pProcessReport,
172  const bool & deleteOldData = true);
173 
174  bool loadModel(const std::string & fileName,
175  CProcessReport* pProcessReport,
176  const bool & deleteOldData = true);
177 
178  bool saveModel(const std::string & fileName,
179  CProcessReport* pProcessReport,
180  bool overwriteFile = false,
181  const bool & autoSave = false);
182 
183  bool autoSave();
184 
185  bool newModel(CProcessReport* pProcessReport,
186  const bool & deleteOldData);
187 
188  bool importSBMLFromString(const std::string & sbmlDocumentText,
189  CProcessReport* pImportHandler = NULL,
190  const bool & deleteOldData = true);
191 
192  bool importSBML(const std::string & fileName,
193  CProcessReport* pImportHandler = NULL,
194  const bool & deleteOldData = true);
195 
196  std::string exportSBMLToString(CProcessReport* pExportHandler, int sbmlLevel, int sbmlVersion);
197  bool exportSBML(const std::string & fileName, bool overwriteFile = false, int sbmlLevel = 2, int sbmlVersion = 1, bool exportIncomplete = false, bool exportCOPASIMIRIAM = true, CProcessReport* pExportHandler = NULL);
198 
199  std::string exportMathModelToString(CProcessReport* pProcessReport, const std::string & filter);
200  bool exportMathModel(const std::string & fileName, CProcessReport* pProcessReport,
201  const std::string & filter, bool overwriteFile = false);
202 
203  void deleteOldData();
204 
205  CModel * getModel();
206  const CModel * getModel() const;
209  CCopasiTask * addTask(const CCopasiTask::Type & taskType);
210  bool addDefaultTasks();
211  /**
212  * Appends pointers to tasks, which are dependent on any of the candidates
213  * to the list dependentTasks.
214  * @param std::set< const CCopasiObject * > candidates
215  * @param std::set< const CCopasiObject * > & dependentTasks
216  * @return bool functionsAppended
217  */
218  bool appendDependentTasks(std::set< const CCopasiObject * > candidates,
219  std::set< const CCopasiObject * > & dependentTasks) const;
220 
223  CReportDefinition * addReport(const CCopasiTask::Type & taskType);
224  bool addDefaultReports();
225 
228 
230  const CListOfLayouts * getListOfLayouts() const;
231  bool removeLayout(const std::string& key);
232 
233  SCopasiXMLGUI * getGUI();
234  const std::string & getFileName() const;
235 
236  bool isChanged() const;
237  void changed(const bool & changed = true);
238 
239  SBMLDocument* getCurrentSBMLDocument();
240  bool setSBMLFileName(const std::string & fileName);
241  const std::string & getSBMLFileName() const;
242 
243  std::map<CCopasiObject*, SBase*>& getCopasi2SBMLMap();
244 
245  /**
246  * Retrieve the object with the given CN
247  * @param const std::vector< CCopasiContainer * > &listOfContainer
248  * @param const CCopasiObjectName& objName
249  * @return CObjectInterface * pObject
250  */
251  CObjectInterface * ObjectFromCN(const std::vector< CCopasiContainer * > & listOfContainer,
252  const CCopasiObjectName & objName) const;
253 
254  /**
255  * Retrieve the data object with the given CN
256  * @param const std::vector< CCopasiContainer * > &listOfContainer
257  * @param const CCopasiObjectName& CN
258  * @return CCopasiObject * pObject
259  */
260  CCopasiObject * ObjectFromName(const std::vector< CCopasiContainer * > & listOfContainer,
261  const CCopasiObjectName & CN) const;
262 
263  /**
264  * Retrieve the data object with the given CN
265  * @param const CCopasiObjectName & CN
266  * @return CCopasiObject * pObject
267  */
268  CCopasiObject * getDataObject(const CCopasiObjectName & CN) const;
269 
270  const std::string& getReferenceDirectory() const;
271 
272  //TODO SEDML by JO Dada
273 #ifdef COPASI_SEDML
274  bool importSEDMLFromString(const std::string & sedmlDocumentText,
275  CProcessReport* pImportHandler = NULL,
276  const bool & deleteOldData = true);
277 
278  bool importSEDML(const std::string & fileName,
279  CProcessReport* pImportHandler = NULL,
280  const bool & deleteOldData = true);
281 
282  std::string exportSEDMLToString(CProcessReport* pExportHandler, int sedmlLevel, int sedmlVersion);
283  bool exportSEDML(const std::string & fileName, bool overwriteFile = false, int sedmlLevel = 1, int sedmlVersion = 1, bool exportIncomplete = false, bool exportCOPASIMIRIAM = true, CProcessReport* pExportHandler = NULL);
284 
285  SedDocument* getCurrentSEDMLDocument();
286  bool setSEDMLFileName(const std::string & fileName);
287  const std::string & getSEDMLFileName() const;
288 
289  std::map<CCopasiObject*, SedBase*>& getCopasi2SEDMLMap();
290 
291 #endif
292 
293 protected:
294  void pushData();
295  void popData();
296  void commonAfterLoad(CProcessReport* pProcessReport,
297  const bool & deleteOldData);
298 
299  // Attributes
300 protected:
304 
305 public:
306  /**
307  * This is a hack at the moment to be able to read Gepasi model files
308  */
310 
311  //the objects that were added by the last model adding action.
312  std::set<CCopasiObject*> mLastAddedObjects;
313 
314 protected:
316 };
317 
318 #endif // COPASI_CCopasiDataModel
SCopasiXMLGUI * getGUI()
CCopasiObject * getDataObject(const CCopasiObjectName &CN) const
SBMLDocument * getCurrentSBMLDocument()
bool setSBMLFileName(const std::string &fileName)
std::set< CCopasiObject * > mLastAddedObjects
CData & operator=(const CData &rhs)
void commonAfterLoad(CProcessReport *pProcessReport, const bool &deleteOldData)
bool appendDependentTasks(std::set< const CCopasiObject * > candidates, std::set< const CCopasiObject * > &dependentTasks) const
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
bool newModel(CProcessReport *pProcessReport, const bool &deleteOldData)
CReportDefinitionVector * pReportDefinitionList
CObjectInterface * ObjectFromCN(const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiObjectName &objName) const
bool importSBML(const std::string &fileName, CProcessReport *pImportHandler=NULL, const bool &deleteOldData=true)
CData(const bool &withGUI=false)
void changed(const bool &changed=true)
COutputDefinitionVector * pPlotDefinitionList
const std::string & getFileName() const
const CReportDefinitionVector * getReportDefinitionList() const
CCopasiDataModel(const bool withGUI=false)
const std::string & getReferenceDirectory() const
virtual void handle(const std::string &oldCN, const std::string &newCN) const
bool removeLayout(const std::string &key)
const std::string & getSBMLFileName() const
CListOfLayouts * pListOfLayouts
CCopasiVectorN< CCopasiTask > * getTaskList()
bool isChanged() const
CReportDefinition * addReport(const CCopasiTask::Type &taskType)
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)
CCopasiTask * addTask(const CCopasiTask::Type &taskType)
CCopasiVectorN< CCopasiTask > * pTaskList
SBMLDocument * pCurrentSBMLDocument
bool exportSBML(const std::string &fileName, bool overwriteFile=false, int sbmlLevel=2, int sbmlVersion=1, bool exportIncomplete=false, bool exportCOPASIMIRIAM=true, CProcessReport *pExportHandler=NULL)
const COutputDefinitionVector * getPlotDefinitionList() const
bool importSBMLFromString(const std::string &sbmlDocumentText, CProcessReport *pImportHandler=NULL, const bool &deleteOldData=true)
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
bool exportMathModel(const std::string &fileName, CProcessReport *pProcessReport, const std::string &filter, bool overwriteFile=false)
std::map< CCopasiObject *, SBase * > mCopasi2SBMLMap
Definition: CModel.h:50
CDataModelRenameHandler mRenameHandler
std::string exportMathModelToString(CProcessReport *pProcessReport, const std::string &filter)
CCopasiVectorS< CMetabOld > * pOldMetabolites
std::map< CCopasiObject *, SBase * > & getCopasi2SBMLMap()
CCopasiObject * ObjectFromName(const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiObjectName &CN) const