COPASI API  4.16.103
CLRenderCurve.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/RenderCurve.h>
10 
11 #include "CLRenderCurve.h"
12 
13 #include "CLRenderPoint.h"
14 #include "CLRenderCubicBezier.h"
15 
18 
19 /**
20  * Constructor.
21  */
24  CCopasiObject("RenderCurve", pParent),
25  mStartHead(""),
26  mEndHead(""),
27  mKey("")
28 {
29  this->mKey = CCopasiRootContainer::getKeyFactory()->add("RenderCurve", this);
30 }
31 
32 /**
33  * Copy constructor
34  */
36  CLGraphicalPrimitive1D(source),
37  CCopasiObject(source, pParent),
38  mStartHead(source.mStartHead),
39  mEndHead(source.mEndHead),
40  mKey("")
41 {
42  this->mKey = CCopasiRootContainer::getKeyFactory()->add("RenderCurve", this);
43  size_t i, iMax = source.mListOfElements.size();
44 
45  for (i = 0; i < iMax; ++i)
46  {
47  if (dynamic_cast<const CLRenderCubicBezier*>(source.mListOfElements[i]))
48  {
49  this->mListOfElements.push_back(new CLRenderCubicBezier(*static_cast<const CLRenderCubicBezier*>(source.mListOfElements[i])));
50  }
51  else
52  {
53  this->mListOfElements.push_back(new CLRenderPoint(*source.mListOfElements[i]));
54  }
55  }
56 }
57 
58 /**
59  * Constructor to generate object from the corresponding SBML object.
60  */
61 CLRenderCurve::CLRenderCurve(const RenderCurve& source, CCopasiContainer* pParent):
62  CLGraphicalPrimitive1D(source),
63  CCopasiObject("RenderCurve", pParent),
64  mStartHead(source.getStartHead()),
65  mEndHead(source.getEndHead()),
66  mKey("")
67 {
68  this->mKey = CCopasiRootContainer::getKeyFactory()->add("RenderCurve", this);
69  size_t i, iMax = source.getNumElements();
70 
71  for (i = 0; i < iMax; ++i)
72  {
73  CLRenderPoint* pElement = NULL;
74 
75  if (dynamic_cast<const RenderCubicBezier*>(source.getElement((unsigned int) i)))
76  {
77  pElement = new CLRenderCubicBezier(*static_cast<const RenderCubicBezier*>(source.getElement((unsigned int) i)));
78  }
79  else
80  {
81  pElement = new CLRenderPoint(*source.getElement((unsigned int) i));
82  }
83 
84  this->mListOfElements.push_back(pElement);
85  }
86 }
87 
88 /**
89  * Destructor
90  */
92 {
94  size_t i, iMax = this->mListOfElements.size();
95 
96  for (i = 0; i < iMax; ++i)
97  {
98  delete this->mListOfElements[i];
99  }
100 }
101 
102 /**
103  * Sets the id of the start head.
104  */
105 void CLRenderCurve::setStartHead(const std::string& startHead)
106 {
107  this->mStartHead = startHead;
108 }
109 
110 /**
111  * Sets the id of the end head.
112  */
113 void CLRenderCurve::setEndHead(const std::string& endHead)
114 {
115  this->mEndHead = endHead;
116 }
117 
118 /**
119  * Returns the id of the start head.
120  */
121 const std::string& CLRenderCurve::getStartHead() const
122 {
123  return this->mStartHead;
124 }
125 
126 /**
127  * Returns the id of the end head.
128  */
129 const std::string& CLRenderCurve::getEndHead() const
130 {
131  return this->mEndHead;
132 }
133 
134 /**
135  * Returns the number of curve segments.
136  */
138 {
139  return this->mListOfElements.size();
140 }
141 
142 /**
143  * Creates a new cubic bezier curve segment.
144  */
146 {
148  this->mListOfElements.push_back(pCS);
149  return pCS;
150 }
151 
152 /**
153  * Creates a new curve segment.
154  */
156 {
157  CLRenderPoint* pCS = new CLRenderPoint();
158  this->mListOfElements.push_back(pCS);
159  return pCS;
160 }
161 
162 /**
163  * Returns a const pointer to the curve segment with the given index or NULL if
164  * the id is invalid.
165  */
167 {
168  return (index < this->mListOfElements.size()) ? (this->mListOfElements[index]) : NULL;
169 }
170 
171 /**
172  * Returns a pointer to the curve segment with the given index or NULL if
173  * the id is invalid.
174  */
176 {
177  return (index < this->mListOfElements.size()) ? (this->mListOfElements[index]) : NULL;
178 }
179 
180 /**
181  * Adds a copy of the given curve segment to the end of the list of
182  *curve segments.
183  */
185 {
186  if (dynamic_cast<const CLRenderCubicBezier*>(pCS))
187  {
188  this->mListOfElements.push_back(new CLRenderCubicBezier(*static_cast<const CLRenderCubicBezier*>(pCS)));
189  }
190  else
191  {
192  this->mListOfElements.push_back(new CLRenderPoint(*pCS));
193  }
194 }
195 
196 /**
197  * Removes the curve segment with the given index.
198  */
200 {
201  if (i < this->mListOfElements.size())
202  {
203  std::vector<CLRenderPoint*>::iterator it = this->mListOfElements.begin();
204  it += i;
205  delete *it;
206  this->mListOfElements.erase(it);
207  }
208 }
209 
210 /**
211  * Returns a const pointer to the list of curve segments.
212  */
213 const std::vector<CLRenderPoint*>* CLRenderCurve::getListOfCurveElements() const
214 {
215  return &(this->mListOfElements);
216 }
217 
218 /**
219  * Returns a pointer to the list of curve segments.
220  */
221 std::vector<CLRenderPoint*>* CLRenderCurve::getListOfCurveElements()
222 {
223  return &(this->mListOfElements);
224 }
225 
226 /**
227  * Returns true if the start head is set or false otherwise.
228  */
230 {
231  return (!this->mStartHead.empty() && this->mStartHead != "none");
232 }
233 
234 /**
235  * Returns true if the start head is set or false otherwise.
236  */
238 {
239  return (!this->mEndHead.empty() && this->mEndHead != "none");
240 }
241 
242 /**
243  * Returns the key of the color definition.
244  */
245 const std::string& CLRenderCurve::getKey() const
246 {
247  return this->mKey;
248 }
249 
250 /**
251  * Converts this object to the corresponding SBML object.
252  */
253 RenderCurve* CLRenderCurve::toSBML(unsigned int level, unsigned int version) const
254 {
255  RenderCurve* pCurve = new RenderCurve(level, version);
256  this->addSBMLAttributes(pCurve);
257  pCurve->setStartHead(this->mStartHead);
258  pCurve->setEndHead(this->mEndHead);
259  size_t i, iMax = this->mListOfElements.size();
260 
261  for (i = 0; i < iMax; ++i)
262  {
263  const RenderPoint* pP = this->mListOfElements[i]->toSBML(level, version);
264  pCurve->addElement(pP);
265  delete pP;
266  }
267 
268  return pCurve;
269 }
bool remove(const std::string &key)
void addCurveElement(const CLRenderPoint *cs)
void setStartHead(const std::string &startHead)
const std::string & getStartHead() const
size_t getNumElements() const
CLRenderPoint * createPoint()
void setEndHead(const std::string &endHead)
const CLRenderPoint * getCurveElement(size_t index) const
const std::string & getEndHead() const
RenderCurve * toSBML(unsigned int level, unsigned int version) const
std::string add(const std::string &prefix, CCopasiObject *pObject)
bool isSetStartHead() const
std::string mStartHead
Definition: CLRenderCurve.h:34
const std::string & getKey() const
static CKeyFactory * getKeyFactory()
bool isSetEndHead() const
std::vector< CLRenderPoint * > mListOfElements
Definition: CLRenderCurve.h:36
void removeCurveElement(size_t i)
std::string mKey
Definition: CLRenderCurve.h:41
const std::vector< CLRenderPoint * > * getListOfCurveElements() const
std::string mEndHead
Definition: CLRenderCurve.h:35
CLRenderCubicBezier * createCubicBezier()
CLRenderCurve(CCopasiContainer *pParent=NULL)
virtual void addSBMLAttributes(GraphicalPrimitive1D *pPrimitive) const