COPASI API  4.16.103
CLRenderInformationBase.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 #define USE_LAYOUT 1
7 #define USE_RENDER 1
8 
9 #include <sbml/packages/render/sbml/RenderInformationBase.h>
10 #include <sbml/packages/render/sbml/ColorDefinition.h>
11 #include <sbml/packages/render/sbml/GradientBase.h>
12 #include <sbml/packages/render/sbml/LinearGradient.h>
13 #include <sbml/packages/render/sbml/RadialGradient.h>
14 #include <sbml/packages/render/sbml/LineEnding.h>
15 
17 #include "CLGradientBase.h"
18 #include "CLLinearGradient.h"
19 #include "CLRadialGradient.h"
20 
23 
24 /**
25  * Constructor.
26  */
28  CLBase(),
29  CCopasiContainer(name, pParent),
30  mKey(""),
31  mName("")
32 {
33 }
34 
35 /**
36  * Copy constructor.
37  */
39  CLBase(source),
40  CCopasiContainer(source, pParent),
41  mReferenceRenderInformation(source.mReferenceRenderInformation),
42  mBackgroundColor(source.mBackgroundColor),
43  mListOfColorDefinitions(source.mListOfColorDefinitions, this),
44  mListOfGradientDefinitions(source.mListOfGradientDefinitions, this),
45  mListOfLineEndings(source.mListOfLineEndings, this),
46  mKey(""),
47  mName(source.mName)
48 {
49 }
50 
51 /**
52  * Constructor to generate object from the corresponding SBML object.
53  */
54 CLRenderInformationBase::CLRenderInformationBase(const RenderInformationBase& source,
55  const std::string& name,
56  /*
57  std::map<std::string,std::string>& colorIdToKeyMap,
58  std::map<std::string,std::string>& gradientIdToKeyMap,
59  std::map<std::string,std::string>& lineEndingIdToKeyMap,
60  */
61  CCopasiContainer* pParent):
62 
63  CLBase(),
64  CCopasiContainer(name, pParent),
65  mReferenceRenderInformation(source.getReferenceRenderInformationId()),
66  mBackgroundColor(source.getBackgroundColor()),
67  mKey(""),
68  mName(source.getName())
69 {
70  size_t i, iMax = source.getNumColorDefinitions();
71  const ColorDefinition* pCD = NULL;
72  CLColorDefinition* pLCD = NULL;
73 
74  for (i = 0; i < iMax; ++i)
75  {
76  pCD = source.getColorDefinition((unsigned int) i);
77  pLCD = new CLColorDefinition(*pCD);
78  this->mListOfColorDefinitions.add(pLCD, true);
79  //colorIdToKeyMap.insert(std::pair<std::string,std::string>(pCD->getId(),pLCD->getKey()));
80  }
81 
82  const GradientBase* pGD = NULL;
83 
84  CLGradientBase* pLGD = NULL;
85 
86  iMax = source.getNumGradientDefinitions();
87 
88  for (i = 0; i < iMax; ++i)
89  {
90  pGD = source.getGradientDefinition((unsigned int) i);
91 
92  if (dynamic_cast<const LinearGradient*>(pGD))
93  {
94  pLGD = new CLLinearGradient(*static_cast<const LinearGradient*>(pGD));
95  this->mListOfGradientDefinitions.add(pLGD, true);
96  }
97  else if (dynamic_cast<const RadialGradient*>(source.getGradientDefinition((unsigned int) i)))
98  {
99  pLGD = new CLRadialGradient(*static_cast<const RadialGradient*>(pGD));
100  this->mListOfGradientDefinitions.add(pLGD, true);
101  }
102 
103  //gradientIdToKeyMap.insert(std::pair<std::string,std::string>(pGD->getId(),pLGD->getKey()));
104  }
105 
106  const LineEnding* pLE = NULL;
107 
108  CLLineEnding* pLLE = NULL;
109 
110  iMax = source.getNumLineEndings();
111 
112  for (i = 0; i < iMax; ++i)
113  {
114  pLE = source.getLineEnding((unsigned int) i);
115  pLLE = new CLLineEnding(*pLE);
116  this->mListOfLineEndings.add(pLLE, true);
117  //lineEndingIdToKeyMap.insert(std::pair<std::string,std::string>(pLE->getId(),pLLE->getKey()));
118  }
119 }
120 
121 /**
122  * Destructor
123  */
125 {
127 }
128 
129 /**
130  * Returns the id of the referenced render information object..
131  */
133 {
134  return this->mReferenceRenderInformation;
135 }
136 
137 /**
138  * Sets the id of the referenced render information object.
139  */
141 {
142  this->mReferenceRenderInformation = key;
143 }
144 
145 /**
146  * Returns the number of color definitions.
147  */
149 {
150  return this->mListOfColorDefinitions.size();
151 }
152 
153 /**
154  * Returns a pointer to the list of color definitions.
155  */
157 {
158  return &(this->mListOfColorDefinitions);
159 }
160 
161 /**
162  * Returns a const pointer to the list of color definitions.
163  */
165 {
166  return &(this->mListOfColorDefinitions);
167 }
168 
169 /**
170  * Returns a pointer to the color definition with the given index, or NULL
171  *if the index is invalid.
172  */
174 {
175  return (index < this->mListOfColorDefinitions.size()) ? this->mListOfColorDefinitions[index] : NULL;
176 }
177 
178 /**
179  * Returns a const pointer to the color definition with the given index, or NULL
180  *if the index is invalid.
181  */
183 {
184  return (index < this->mListOfColorDefinitions.size()) ? this->mListOfColorDefinitions[index] : NULL;
185 }
186 
187 /**
188  * Creates a new color definition.
189  */
191 {
193  this->mListOfColorDefinitions.add(pCD, true);
194  return pCD;
195 }
196 
197 /**
198  * Removes the color definition with the given index.
199  */
201 {
202  if (index < this->mListOfColorDefinitions.size())
203  {
204  this->mListOfColorDefinitions.remove(index);
205  }
206 }
207 
208 /**
209  * Adds a copy of the given color definition to the end of the list of
210  * color definitions.
211  */
213 {
214  this->mListOfColorDefinitions.add(new CLColorDefinition(*pCD), true);
215 }
216 
217 /**
218  * Returns the number of gradient definitions.
219  */
221 {
222  return this->mListOfGradientDefinitions.size();
223 }
224 
225 /**
226  * Returns a pointer to the list of gradient definitions.
227  */
229 {
230  return &(this->mListOfGradientDefinitions);
231 }
232 
233 /**
234  * Returns a const pointer to the list of gradient definitions.
235  */
237 {
238  return &(this->mListOfGradientDefinitions);
239 }
240 
241 /**
242  * Returns a pointer to the gradient definition with the given index, or NULL
243  *if the index is invalid.
244  */
246 {
247  return (index < this->mListOfGradientDefinitions.size()) ? this->mListOfGradientDefinitions[index] : NULL;
248 }
249 
250 /**
251  * Returns a const pointer to the gradient definition with the given index, or NULL
252  *if the index is invalid.
253  */
255 {
256  return (index < this->mListOfGradientDefinitions.size()) ? this->mListOfGradientDefinitions[index] : NULL;
257 }
258 
259 /**
260  * Creates a new radial gradient definition.
261  */
263 {
264  CLRadialGradient* pRG = new CLRadialGradient();
265  this->mListOfGradientDefinitions.add(pRG, true);
266  return pRG;
267 }
268 
269 /**
270  * Creates a new linear gradient definition.
271  */
273 {
274  CLLinearGradient* pLG = new CLLinearGradient();
275  this->mListOfGradientDefinitions.add(pLG, true);
276  return pLG;
277 }
278 
279 /**
280  * Removes the gradient definition with the given index.
281  */
283 {
284  if (index < this->mListOfGradientDefinitions.size())
285  {
286  this->mListOfGradientDefinitions.remove(index);
287  }
288 }
289 
290 /**
291  * Adds a copy of the given gradient definition to the end of the list of
292  * gradient definitions.
293  */
295 {
296  if (dynamic_cast<const CLLinearGradient*>(pGradient))
297  {
298  this->mListOfGradientDefinitions.add(new CLLinearGradient(*static_cast<const CLLinearGradient*>(pGradient)), true);
299  }
300  else if (dynamic_cast<const CLRadialGradient*>(pGradient))
301  {
302  this->mListOfGradientDefinitions.add(new CLRadialGradient(*static_cast<const CLRadialGradient*>(pGradient)), true);
303  }
304 }
305 
306 /**
307  * Returns the number of line endings.
308  */
310 {
311  return this->mListOfLineEndings.size();
312 }
313 
314 /**
315  * Returns a pointer to the list of line endings.
316  */
318 {
319  return &(this->mListOfLineEndings);
320 }
321 
322 /**
323  * Returns a const pointer to the list of line endings.
324  */
326 {
327  return &(this->mListOfLineEndings);
328 }
329 
330 /**
331  * Returns a pointer to the line ending with the given index, or NULL
332  *if the index is invalid.
333  */
335 {
336  return (index < this->mListOfLineEndings.size()) ? this->mListOfLineEndings[index] : NULL;
337 }
338 
339 /**
340  * Returns a const pointer to the line ending with the given index, or NULL
341  *if the index is invalid.
342  */
344 {
345  return (index < this->mListOfLineEndings.size()) ? this->mListOfLineEndings[index] : NULL;
346 }
347 
348 /**
349  * Creates a new line ending.
350  */
352 {
353  CLLineEnding* pLE = new CLLineEnding();
354  this->mListOfLineEndings.add(pLE, true);
355  return pLE;
356 }
357 
358 /**
359  * Removes the line ending with the given index.
360  */
362 {
363  if (index < this->mListOfLineEndings.size())
364  {
365  this->mListOfLineEndings.remove(index);
366  }
367 }
368 
369 /**
370  * Adds a copy of the given line ending to the end of the list of line
371  *endings.
372  */
374 {
375  this->mListOfLineEndings.add(new CLLineEnding(*pLE), true);
376 }
377 
379 {
380  return mBackgroundColor;
381 }
382 
384 {
385  this->mBackgroundColor = bg;
386 }
387 
388 /**
389  * Returns the key of the color definition.
390  */
391 const std::string& CLRenderInformationBase::getKey() const
392 {
393  return this->mKey;
394 }
395 
396 /**
397  * Adds the attributes for a graphical primitive 1D object to the passed in.
398  * object.
399  */
400 void CLRenderInformationBase::addSBMLAttributes(RenderInformationBase* pBase
401  /*
402  ,std::map<std::string,std::string>& colorKeyToIdMap
403  ,std::map<std::string,std::string>& gradientKeyToIdMap
404  ,std::map<std::string,std::string>& lineEndingKeyToIdMap
405  */
406  ) const
407 {
408  pBase->setReferenceRenderInformationId(this->getReferenceRenderInformationKey());
409  pBase->setBackgroundColor(this->getBackgroundColor());
410  pBase->setId(getKey());
411 
412  if (!mName.empty())
413  {
414  pBase->setName(mName);
415  }
416 
417  size_t i, iMax = this->mListOfColorDefinitions.size();
418  int result;
419 
420  unsigned int level = pBase->getLevel();
421  unsigned int version = pBase->getVersion();
422 
423  for (i = 0; i < iMax; ++i)
424  {
425  ColorDefinition* pCD = this->getColorDefinition(i)->toSBML(level, version);
426  result = pBase->addColorDefinition(pCD);
427  assert(result == LIBSBML_OPERATION_SUCCESS);
428  //colorKeyToIdMap.insert(std::pair<std::string,std::string>(this->getColorDefinition(i)->getKey(),pCD->getId()));
429  delete pCD;
430  }
431 
432  iMax = this->mListOfGradientDefinitions.size();
433  GradientBase* pGB = NULL;
434  const CLGradientBase* pLGB = NULL;
435 
436  for (i = 0; i < iMax; ++i)
437  {
438  pLGB = this->getGradientDefinition(i);
439 
440  if (dynamic_cast<const CLRadialGradient*>(pLGB))
441  {
442  pGB = static_cast<const CLRadialGradient*>(pLGB)->toSBML(level, version);
443  }
444  else
445  {
446  pGB = static_cast<const CLLinearGradient*>(pLGB)->toSBML(level, version);
447  }
448 
449  result = pBase->addGradientDefinition(pGB);
450  assert(result == LIBSBML_OPERATION_SUCCESS);
451  //gradientKeyToIdMap.insert(std::pair<std::string,std::string>(pLGB->getKey(),pGB->getId()));
452  delete pGB;
453  }
454 
455  iMax = this->mListOfLineEndings.size();
456 
457  for (i = 0; i < iMax; ++i)
458  {
459  const CLLineEnding* lineEnding = this->getLineEnding(i);
460  LineEnding* pLE = lineEnding->toSBML(level, version);
461  result = pBase->addLineEnding(pLE);
462  assert(result == LIBSBML_OPERATION_SUCCESS);
463  //lineEndingKeyToIdMap.insert(std::pair<std::string,std::string>(this->getLineEnding(i)->getKey(),pLE->getId()));
464  delete pLE;
465  }
466 }
467 
468 /**
469  * Sets the name of the object.
470  */
471 void CLRenderInformationBase::setName(const std::string& name)
472 {
473  this->mName = name;
474 }
475 
476 /**
477  * Returns the name of the object.
478  */
479 const std::string& CLRenderInformationBase::getName() const
480 {
481  return this->mName;
482 }
void addLineEnding(const CLLineEnding *le)
void removeGradientDefinition(size_t index)
bool remove(const std::string &key)
CCopasiVector< CLColorDefinition > mListOfColorDefinitions
void addSBMLAttributes(RenderInformationBase *pBase) const
CCopasiVector< CLLineEnding > * getListOfLineEndings()
virtual size_t size() const
const std::string & getBackgroundColor() const
CLRadialGradient * createRadialGradientDefinition()
void addGradientDefinition(const CLGradientBase *gradient)
void setBackgroundColor(const std::string &bg)
CCopasiVector< CLLineEnding > mListOfLineEndings
CLColorDefinition * getColorDefinition(size_t index)
const std::string & getReferenceRenderInformationKey() const
CLRenderInformationBase(const std::string &name, CCopasiContainer *pParent=NULL)
void removeColorDefinition(size_t index)
CLLineEnding * getLineEnding(size_t index)
virtual bool add(const CType &src)
Definition: CLBase.h:33
void setName(const std::string &name)
CCopasiVector< CLGradientBase > mListOfGradientDefinitions
CLColorDefinition * createColorDefinition()
void setReferenceRenderInformationKey(const std::string &key)
LineEnding * toSBML(unsigned int level, unsigned int version) const
virtual void remove(const size_t &index)
static CKeyFactory * getKeyFactory()
void addColorDefinition(const CLColorDefinition *cd)
const std::string & getKey() const
const std::string & getName() const
CLLinearGradient * createLinearGradientDefinition()
CCopasiVector< CLGradientBase > * getListOfGradientDefinitions()
CLGradientBase * getGradientDefinition(size_t index)
CCopasiVector< CLColorDefinition > * getListOfColorDefinitions()
ColorDefinition * toSBML(unsigned int level, unsigned int version) const