COPASI API  4.16.103
CLGradientBase.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/layout/CLGradientBase.cpp,v $
3 // $Revision: 1.5 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/04/23 15:44:52 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 #include <assert.h>
15 
16 #include <sbml/packages/render/sbml/GradientBase.h>
17 
18 #include "CLGradientBase.h"
19 
20 #include "CLLinearGradient.h"
21 #include "CLRadialGradient.h"
22 
25 
26 /**
27  * Constructor.
28  */
29 CLGradientBase::CLGradientBase(const std::string& name, CCopasiContainer* pParent):
30  CLBase(),
31  CCopasiContainer(name, pParent),
32  mSpreadMethod(CLGradientBase::PAD),
33  mKey(""),
34  mId("")
35 {
36 }
37 
38 /**
39  * Copy Constructor.
40  */
42  CLBase(source),
43  CCopasiContainer(source, pParent),
44  mSpreadMethod(source.mSpreadMethod),
45  mGradientStops(source.mGradientStops, this),
46  mKey(""),
47  mId(source.mId)
48 {
49 }
50 
51 /**
52  * Constructor to generate object from the corresponding SBML object.
53  */
54 CLGradientBase::CLGradientBase(const GradientBase& source, const std::string& name, CCopasiContainer* pParent):
55  CLBase(),
56  CCopasiContainer(name, pParent),
57  mKey(""),
58  mId(source.getId())
59 {
60  switch (source.getSpreadMethod())
61  {
62  case GradientBase::REFLECT:
64  break;
65  case GradientBase::REPEAT:
67  break;
68  default:
70  break;
71  }
72 
73  size_t i, iMax = source.getNumGradientStops();
74 
75  for (i = 0; i < iMax; ++i)
76  {
77  CLGradientStop* pStop = new CLGradientStop(*source.getGradientStop((unsigned int) i));
78  this->addGradientStop(pStop);
79  delete pStop;
80  }
81 }
82 
83 /**
84  * Destructor.
85  */
87 {
89 }
90 
91 /**
92  * Returns the spreadmethod of he gradient.
93  */
95 {
96  return this->mSpreadMethod;
97 }
98 
99 /**
100  * Sets the spread method.
101  */
103 {
104  this->mSpreadMethod = method;
105 }
106 
107 /**
108  * Returns the number of gradient stops.
109  */
111 {
112  return this->mGradientStops.size();
113 }
114 
115 /**
116  * Returns a pointer to the gradient stop vector.
117  */
119 {
120  return &(this->mGradientStops);
121 }
122 
123 /**
124  * Returns a const pointer to the gradient stop vector.
125  */
127 {
128  return &(this->mGradientStops);
129 }
130 
131 /**
132  * Returns a pointer to the gradient stop with the given index or NULL
133  * if the index is invalid.
134  */
136 {
137  return (i < this->mGradientStops.size()) ? (this->mGradientStops[i]) : NULL;
138 }
139 
140 /**
141  * Returns a const pointer to the gradient stop with the given index or NULL
142  * if the index is invalid.
143  */
145 {
146  return (i < this->mGradientStops.size()) ? (this->mGradientStops[i]) : NULL;
147 }
148 
149 /**
150  * Creates a new CLGradientStop.
151  */
153 {
154  CLGradientStop* pStop = new CLGradientStop();
155  this->mGradientStops.add(pStop, true);
156  return pStop;
157 }
158 
159 /**
160  * Adds a copy of the given CLGradientStop object.
161  */
163 {
164  this->mGradientStops.add(new CLGradientStop(*pStop, this), true);
165 }
166 
167 /**
168  * Returns the key of the color definition.
169  */
170 const std::string& CLGradientBase::getKey() const
171 {
172  return this->mKey;
173 }
174 
175 /**
176  * Returns the id of the object.
177  */
178 const std::string& CLGradientBase::getId() const
179 {
180  return this->mId;
181 }
182 
183 /**
184  * Sets the id of the object.
185  */
186 void CLGradientBase::setId(const std::string& id)
187 {
188  this->mId = id;
189 }
190 
191 /**
192  * Adds gradient base attributes to the gradient passed as the argument.
193  */
194 void CLGradientBase::addSBMLAttributes(GradientBase* pBase) const
195 {
196  pBase->setId(this->mId);
197 
198  switch (this->mSpreadMethod)
199  {
201  pBase->setSpreadMethod(GradientBase::REFLECT);
202  break;
204  pBase->setSpreadMethod(GradientBase::REPEAT);
205  break;
206  default:
207  pBase->setSpreadMethod(GradientBase::PAD);
208  break;
209  }
210 
211  size_t i, iMax = this->mGradientStops.size();
212 
213  for (i = 0; i < iMax; ++i)
214  {
215  pBase->addGradientStop(this->mGradientStops[i]->toSBML(pBase->getLevel(), pBase->getVersion()));
216  }
217 }
bool remove(const std::string &key)
virtual ~CLGradientBase()
void setSpreadMethod(SPREADMETHOD method)
CCopasiVector< CLGradientStop > mGradientStops
virtual size_t size() const
const std::string & getId() const
CLGradientStop * getGradientStop(size_t i)
CLGradientBase(const std::string &name, CCopasiContainer *pParent=NULL)
size_t getNumGradientStops() const
void addGradientStop(const CLGradientStop *pStop)
virtual void addSBMLAttributes(GradientBase *pBase) const
std::string mKey
const std::string & getKey() const
virtual bool add(const CType &src)
CCopasiVector< CLGradientStop > * getListOfGradientStops()
Definition: CLBase.h:33
SPREADMETHOD mSpreadMethod
std::string mId
static CKeyFactory * getKeyFactory()
CLGradientStop * createGradientStop()
SPREADMETHOD getSpreadMethod() const
void setId(const std::string &id)