COPASI API  4.16.103
CLPolygon.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/Polygon.h>
10 
11 #define sbmlPolygon Polygon
12 #include "CLPolygon.h"
13 
14 #include "CLRenderPoint.h"
15 #include "CLRenderCubicBezier.h"
16 
19 
20 /**
21  * Constructor.
22  */
25  CCopasiObject("Polygon", pParent),
26  mKey("")
27 {
28  this->mKey = CCopasiRootContainer::getKeyFactory()->add("Polygon", this);
29 }
30 
31 /**
32  * Copy constructor
33  */
35  CLGraphicalPrimitive2D(source),
36  CCopasiObject(source, pParent),
37  mKey("")
38 {
39  this->mKey = CCopasiRootContainer::getKeyFactory()->add("Polygon", this);
40  size_t i, iMax = source.mListOfElements.size();
41 
42  for (i = 0; i < iMax; ++i)
43  {
44  if (dynamic_cast<const CLRenderCubicBezier*>(source.mListOfElements[i]))
45  {
46  this->mListOfElements.push_back(new CLRenderCubicBezier(*static_cast<const CLRenderCubicBezier*>(source.mListOfElements[i])));
47  }
48  else
49  {
50  this->mListOfElements.push_back(new CLRenderPoint(*source.mListOfElements[i]));
51  }
52  }
53 }
54 
55 /**
56  * Constructor to generate object from the corresponding SBML object.
57  */
58 CLPolygon::CLPolygon(const Polygon& source, CCopasiContainer* pParent):
59  CLGraphicalPrimitive2D(source),
60  CCopasiObject("Polygon", pParent),
61  mKey("")
62 {
63  this->mKey = CCopasiRootContainer::getKeyFactory()->add("Polygon", this);
64  size_t i, iMax = source.getNumElements();
65 
66  for (i = 0; i < iMax; ++i)
67  {
68  CLRenderPoint* pElement = NULL;
69 
70  if (dynamic_cast<const RenderCubicBezier*>(source.getElement((unsigned int) i)))
71  {
72  pElement = new CLRenderCubicBezier(*static_cast<const RenderCubicBezier*>(source.getElement((unsigned int) i)));
73  }
74  else
75  {
76  pElement = new CLRenderPoint(*source.getElement((unsigned int) i));
77  }
78 
79  this->mListOfElements.push_back(pElement);
80  }
81 }
82 
83 /**
84  * Destructor.
85  */
87 {
89  size_t i, iMax = this->mListOfElements.size();
90 
91  for (i = 0; i < iMax; ++i)
92  {
93  delete this->mListOfElements[i];
94  }
95 }
96 
97 /**
98  * Returns the number of line segments.
99  */
101 {
102  return this->mListOfElements.size();
103 }
104 
105 /**
106  * Returns a pointer to the list of curve segments.
107  */
108 std::vector<CLRenderPoint*>* CLPolygon::getListOfElements()
109 {
110  return &(this->mListOfElements);
111 }
112 
113 /**
114  * Returns a const pointer to the list of curve segments.
115  */
116 const std::vector<CLRenderPoint*>* CLPolygon::getListOfElements() const
117 {
118  return &(this->mListOfElements);
119 }
120 
121 /**
122  * Creates a new point object and adds it to the list of curve
123  * segments.
124  */
126 {
127  this->mListOfElements.push_back(new CLRenderPoint());
128  return this->mListOfElements.back();
129 }
130 
131 /**
132  * Creates a new cubicbezier object and adds it to the list of curve
133  * segments.
134  */
136 {
137  this->mListOfElements.push_back(new CLRenderCubicBezier());
138  return static_cast<CLRenderCubicBezier*>(this->mListOfElements.back());
139 }
140 
141 /**
142  * Returns a pointer to the line segement with with the given index or
143  * NULL if the index is invalid.
144  */
146 {
147  return (index < this->mListOfElements.size()) ? (this->mListOfElements[index]) : NULL;
148 }
149 
150 /**
151  * Returns const a pointer to the line segement with with the given index or
152  * NULL if the index is invalid.
153  */
154 const CLRenderPoint* CLPolygon::getElement(size_t index) const
155 {
156  return (index < this->mListOfElements.size()) ? (this->mListOfElements[index]) : NULL;
157 }
158 
159 /**
160  * Adds a copy of the given line segment to the list of line segements.
161  */
163 {
164  if (dynamic_cast<const CLRenderCubicBezier*>(pLS))
165  {
166  this->mListOfElements.push_back(new CLRenderCubicBezier(*static_cast<const CLRenderCubicBezier*>(pLS)));
167  }
168  else
169  {
170  this->mListOfElements.push_back(new CLRenderPoint(*pLS));
171  }
172 }
173 
174 /**
175  * Removes the curve segment with the given index.
176  */
178 {
179  if (i < this->mListOfElements.size())
180  {
181  std::vector<CLRenderPoint*>::iterator it = this->mListOfElements.begin();
182  it += i;
183  delete *it;
184  this->mListOfElements.erase(it);
185  }
186 }
187 
188 /**
189  * Returns the key of the color definition.
190  */
191 const std::string& CLPolygon::getKey() const
192 {
193  return this->mKey;
194 }
195 
196 /**
197  * Converts this object to the corresponding SBML object.
198  */
199 Polygon* CLPolygon::toSBML(unsigned int level, unsigned int version) const
200 {
201  Polygon* pPolygon = new Polygon(level, version);
202  this->addSBMLAttributes(pPolygon);
203  size_t i, iMax = this->mListOfElements.size();
204 
205  for (i = 0; i < iMax; ++i)
206  {
207  const RenderPoint* pP = this->mListOfElements[i]->toSBML(level, version);
208  pPolygon->addElement(pP);
209  delete pP;
210  }
211 
212  return pPolygon;
213 }
bool remove(const std::string &key)
CLPolygon(CCopasiContainer *pParent=NULL)
Definition: CLPolygon.cpp:23
CLRenderPoint * getElement(size_t index)
Definition: CLPolygon.cpp:145
void removeElement(size_t i)
Definition: CLPolygon.cpp:177
CLRenderPoint * createPoint()
Definition: CLPolygon.cpp:125
size_t getNumElements() const
Definition: CLPolygon.cpp:100
std::vector< CLRenderPoint * > mListOfElements
Definition: CLPolygon.h:34
virtual void addSBMLAttributes(GraphicalPrimitive2D *pPrimitive) const
std::string add(const std::string &prefix, CCopasiObject *pObject)
static CKeyFactory * getKeyFactory()
const std::string & getKey() const
Definition: CLPolygon.cpp:191
std::string mKey
Definition: CLPolygon.h:39
std::vector< CLRenderPoint * > * getListOfElements()
Definition: CLPolygon.cpp:108
sbmlPolygon * toSBML(unsigned int level, unsigned int version) const
Definition: CLPolygon.cpp:199
CLRenderCubicBezier * createCubicBezier()
Definition: CLPolygon.cpp:135
void addElement(const CLRenderPoint *ls)
Definition: CLPolygon.cpp:162