COPASI API  4.16.103
CLGlyphs.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/layout/CLGlyphs.cpp,v $
3 // $Revision: 1.18 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/04/23 15:44:52 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 - 2011 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<iostream>
24 
25 #define USE_LAYOUT 1
26 
27 #include <sbml/packages/layout/sbml/SpeciesGlyph.h>
28 #include <sbml/packages/layout/sbml/CompartmentGlyph.h>
29 #include <sbml/packages/layout/sbml/TextGlyph.h>
30 
31 #include "CLGlyphs.h"
32 
33 #include "report/CKeyFactory.h"
35 
36 CLMetabGlyph::CLMetabGlyph(const std::string & name,
37  const CCopasiContainer * pParent)
38  : CLGraphicalObject(name, pParent)
39 {}
40 
42  const CCopasiContainer * pParent)
43  : CLGraphicalObject(src, pParent)
44 {}
45 
46 CLMetabGlyph::CLMetabGlyph(const SpeciesGlyph & sbml,
47  const std::map<std::string, std::string> & modelmap,
48  std::map<std::string, std::string> & layoutmap,
49  const CCopasiContainer * pParent)
50  : CLGraphicalObject(sbml, layoutmap, pParent)
51 {
52  //get the copasi key corresponding to the sbml id for the species
53  if (sbml.getSpeciesId() != "")
54  {
55  std::map<std::string, std::string>::const_iterator it = modelmap.find(sbml.getSpeciesId());
56 
57  if (it != modelmap.end())
58  setModelObjectKey(it->second);
59  }
60 }
61 
63 {
64  if (this == &rhs) return * this; //do nothing if lhs and rhs are the same
65 
67 
68  //nothing to be done here
69 
70  return *this;
71 }
72 
73 void CLMetabGlyph::exportToSBML(SpeciesGlyph * g,
74  const std::map<const CCopasiObject*, SBase*> & copasimodelmap,
75  std::map<std::string, const SBase*>& sbmlIDs) const
76 {
77  if (!g) return;
78 
79  //call the coresponding method of the base class
80  CLGraphicalObject::exportToSBML(g, copasimodelmap, sbmlIDs);
81 
82  //reference to model objects
84 
85  if (tmp)
86  {
87  std::map<const CCopasiObject*, SBase*>::const_iterator it = copasimodelmap.find(tmp);
88 
89  if (it != copasimodelmap.end())
90  {
91  if (it->second)
92  g->setSpeciesId(it->second->getId());
93  }
94  }
95 }
96 
97 std::ostream & operator<<(std::ostream &os, const CLMetabGlyph & g)
98 {
99  os << "MetabGlyph: " << dynamic_cast<const CLGraphicalObject&>(g);
100  return os;
101 }
102 
103 void CLMetabGlyph::print(std::ostream * ostream) const
104 {*ostream << *this;}
105 
106 //********* CLCompartmentGlyph ************************************************
107 
108 CLCompartmentGlyph::CLCompartmentGlyph(const std::string & name,
109  const CCopasiContainer * pParent)
110  : CLGraphicalObject(name, pParent)
111 {}
112 
114  const CCopasiContainer * pParent)
115  : CLGraphicalObject(src, pParent)
116 {}
117 
118 CLCompartmentGlyph::CLCompartmentGlyph(const CompartmentGlyph & sbml,
119  const std::map<std::string, std::string> & modelmap,
120  std::map<std::string, std::string> & layoutmap,
121  const CCopasiContainer * pParent)
122  : CLGraphicalObject(sbml, layoutmap, pParent)
123 {
124  //get the copasi key corresponding to the sbml id for the compartment
125  if (sbml.getCompartmentId() != "")
126  {
127  std::map<std::string, std::string>::const_iterator it = modelmap.find(sbml.getCompartmentId());
128 
129  if (it != modelmap.end())
130  setModelObjectKey(it->second);
131  }
132 }
133 
135 {
136  if (this == &rhs) return * this; //do nothing if lhs and rhs are the same
137 
139 
140  //nothing to be done here
141 
142  return *this;
143 }
144 
145 void CLCompartmentGlyph::exportToSBML(CompartmentGlyph * cg,
146  const std::map<const CCopasiObject*, SBase*> & copasimodelmap,
147  std::map<std::string, const SBase*>& sbmlIDs) const
148 {
149  if (!cg) return;
150 
151  //call the coresponding method of the base class
152  CLGraphicalObject::exportToSBML(cg, copasimodelmap, sbmlIDs);
153 
154  //reference to model objects
155  CCopasiObject* tmp = getModelObject();
156 
157  if (tmp)
158  {
159  std::map<const CCopasiObject*, SBase*>::const_iterator it = copasimodelmap.find(tmp);
160 
161  if (it != copasimodelmap.end())
162  {
163  if (it->second)
164  cg->setCompartmentId(it->second->getId());
165  }
166  }
167 }
168 
169 std::ostream & operator<<(std::ostream &os, const CLCompartmentGlyph & g)
170 {
171  os << "CompartmentGlyph: " << dynamic_cast<const CLGraphicalObject&>(g);
172  return os;
173 }
174 
175 void CLCompartmentGlyph::print(std::ostream * ostream) const
176 {*ostream << *this;}
177 
178 //********** CLTextGlyph ******************************************************
179 
180 CLTextGlyph::CLTextGlyph(const std::string & name,
181  const CCopasiContainer * pParent)
182  : CLGraphicalObject(name, pParent),
183  mIsTextSet(false),
184  mText(""),
185  mGraphicalObjectKey("")
186 {}
187 
189  const CCopasiContainer * pParent)
190  : CLGraphicalObject(src, pParent),
191  mIsTextSet(src.mIsTextSet),
192  mText(src.mText),
193  mGraphicalObjectKey(src.mGraphicalObjectKey)
194 {}
195 
196 CLTextGlyph::CLTextGlyph(const TextGlyph & sbml,
197  const std::map<std::string, std::string> & modelmap,
198  std::map<std::string, std::string> & layoutmap,
199  const CCopasiContainer * pParent)
200  : CLGraphicalObject(sbml, layoutmap, pParent),
201  mIsTextSet(sbml.isSetText()),
202  mText(sbml.getText()),
203  mGraphicalObjectKey("")
204 {
205  //get the copasi key corresponding to the sbml id for the graphical object
206  /* if (sbml.getGraphicalObjectId() != "")
207  {
208  std::map<std::string, std::string>::const_iterator it = m.find(sbml.getGraphicalObjectId());
209  if (it != m.end())
210  mGraphicalObjectKey = it->second;
211  }*/
212 
213  //get the copasi key corresponding to the sbml id for the model element (OriginOfText)
214  if (sbml.getOriginOfTextId() != "")
215  {
216  std::map<std::string, std::string>::const_iterator it = modelmap.find(sbml.getOriginOfTextId());
217 
218  if (it != modelmap.end())
219  setModelObjectKey(it->second);
220  }
221 }
222 
224 {
225  if (this == &rhs) return * this; //do nothing if lhs and rhs are the same
226 
228 
229  //handle the specific text glyph stuff:
230  mIsTextSet = rhs.mIsTextSet;
231  mText = rhs.mText;
232 
234 
235  return *this;
236 }
237 
238 std::string CLTextGlyph::getText() const
239 {
240  if (mIsTextSet)
241  {
242  return mText;
243  }
244  else
245  {
246  return getModelObjectDisplayName();
247  }
248 }
249 
250 void CLTextGlyph::setText(const std::string & t)
251 {
252  mIsTextSet = true;
253  mText = t;
254 }
255 
257 {
258  mIsTextSet = false;
259  mText = "";
260 }
261 
263 {
265 }
266 
267 void CLTextGlyph::exportToSBML(TextGlyph * g,
268  const std::map<const CCopasiObject*, SBase*> & copasimodelmap,
269  std::map<std::string, const SBase*>& sbmlIDs) const
270 {
271  if (!g) return;
272 
273  //call the coresponding method of the base class
274  CLGraphicalObject::exportToSBML(g, copasimodelmap, sbmlIDs);
275 
276  //reference to model objects
277  CCopasiObject* tmp = getModelObject();
278 
279  if (tmp)
280  {
281  std::map<const CCopasiObject*, SBase*>::const_iterator it = copasimodelmap.find(tmp);
282 
283  if (it != copasimodelmap.end())
284  {
285  if (it->second)
286  g->setOriginOfTextId(it->second->getId());
287  }
288  }
289 
290  //explicit text
291  if (isTextSet())
292  {
293  g->setText(mText);
294  }
295 }
296 
297 void CLTextGlyph::exportReferenceToSBML(TextGlyph * g, const std::map<const CLBase*, const SBase*> & layoutmap) const
298 {
299  if (!g) return;
300 
301  //reference to layout object
303 
304  if (tmp)
305  {
306  std::map<const CLBase*, const SBase*>::const_iterator it = layoutmap.find(tmp);
307 
308  if (it != layoutmap.end() && it->second)
309  {
310  //we need to cast here since layout objects in libsbml donĀ“t inherit the getId() method
311  //from SBase
312  const GraphicalObject* pGO = dynamic_cast<const GraphicalObject*>(it->second);
313 
314  if (pGO)
315  g->setGraphicalObjectId(pGO->getId());
316  }
317  }
318 }
319 
320 std::ostream & operator<<(std::ostream &os, const CLTextGlyph & g)
321 {
322  os << "TextGlyph: " << dynamic_cast<const CLGraphicalObject&>(g);
323 
324  if (g.mIsTextSet)
325  os << " Explicit text is: \"" << g.mText << "\"\n";
326 
328 
329  if (tmp)
330  os << " Label for: \"" << tmp->getObjectName() << "\"\n";
331 
332  return os;
333 }
334 
335 void CLTextGlyph::print(std::ostream * ostream) const
336 {*ostream << *this;}
337 
338 void CLTextGlyph::setGraphicalObjectKey(const std::string & k)
339 {
341 }
void print(std::ostream *ostream) const
Definition: CLGlyphs.cpp:335
std::string getModelObjectDisplayName(bool regular=true, bool richtext=false) const
bool isTextSet() const
Definition: CLGlyphs.h:161
std::string mGraphicalObjectKey
Definition: CLGlyphs.h:133
const std::string & getObjectName() const
CLCompartmentGlyph(const std::string &name="CompartmentGlyph", const CCopasiContainer *pParent=NULL)
Definition: CLGlyphs.cpp:108
virtual std::string getText() const
Definition: CLGlyphs.cpp:238
std::ostream & operator<<(std::ostream &os, const CLMetabGlyph &g)
Definition: CLGlyphs.cpp:97
CCopasiObject * get(const std::string &key)
CLTextGlyph(const std::string &name="TextGlyph", const CCopasiContainer *pParent=NULL)
Definition: CLGlyphs.cpp:180
CLCompartmentGlyph & operator=(const CLCompartmentGlyph &rhs)
Definition: CLGlyphs.cpp:134
bool mIsTextSet
Definition: CLGlyphs.h:126
virtual void exportToSBML(CompartmentGlyph *cg, const std::map< const CCopasiObject *, SBase * > &copasimodelmap, std::map< std::string, const SBase * > &sbmlIDs) const
Definition: CLGlyphs.cpp:145
void setModelObjectKey(const std::string &k)
virtual void exportToSBML(GraphicalObject *sbmlobject, const std::map< const CCopasiObject *, SBase * > &copasimodelmap, std::map< std::string, const SBase * > &sbmlIDs) const
virtual void exportToSBML(SpeciesGlyph *g, const std::map< const CCopasiObject *, SBase * > &copasimodelmap, std::map< std::string, const SBase * > &sbmlIDs) const
Definition: CLGlyphs.cpp:73
void setGraphicalObjectKey(const std::string &k)
Definition: CLGlyphs.cpp:338
CLGraphicalObject * getGraphicalObject() const
Definition: CLGlyphs.cpp:262
void print(std::ostream *ostream) const
Definition: CLGlyphs.cpp:175
CLTextGlyph & operator=(const CLTextGlyph &rhs)
Definition: CLGlyphs.cpp:223
CLGraphicalObject & operator=(const CLGraphicalObject &rhs)
CCopasiObject * getModelObject() const
static CKeyFactory * getKeyFactory()
void setText(const std::string &t)
Definition: CLGlyphs.cpp:250
void exportReferenceToSBML(TextGlyph *g, const std::map< const CLBase *, const SBase * > &layoutmap) const
Definition: CLGlyphs.cpp:297
virtual void exportToSBML(TextGlyph *g, const std::map< const CCopasiObject *, SBase * > &copasimodelmap, std::map< std::string, const SBase * > &sbmlIDs) const
Definition: CLGlyphs.cpp:267
std::string mText
Definition: CLGlyphs.h:127
void print(std::ostream *ostream) const
Definition: CLGlyphs.cpp:103
void clearText()
Definition: CLGlyphs.cpp:256
CLMetabGlyph(const std::string &name="MetabGlyph", const CCopasiContainer *pParent=NULL)
Definition: CLGlyphs.cpp:36
CLMetabGlyph & operator=(const CLMetabGlyph &rhs)
Definition: CLGlyphs.cpp:62