COPASI API  4.16.103
CLBase.h
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 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #ifndef CLBASE_H_
16 #define CLBASE_H_
17 
18 #include "copasi.h"
19 #include <string>
20 
21 class SBase;
22 
23 class BoundingBox;
24 class Dimensions;
25 class Point;
26 class CLPoint;
27 
28 /**
29  * This class does nothing at all at the moment.
30  * Is is the base of all classes that have an equivalent in the
31  * libsbml layout extension
32  */
33 class CLBase
34 {
35 public:
36  CLBase() : mTag("") {};
37  CLBase(const CLBase &b) : mTag(b.mTag) {};
38  CLBase(const SBase &) : mTag("") {};
39  // make CLBase polymorphic so that we can dynamic cast from CLBase to
40  // CLGraphicalObject
41  virtual ~CLBase() {};
42  virtual void moveBy(const CLPoint &) {};
43  const std::string& getTag() const {return mTag;}
44  void setTag(const std::string& tag) {mTag = tag;}
45  bool hasTag() const {return mTag.empty();}
46 protected:
47  std::string mTag;
48 };
49 
50 /**
51  * This class describes a Point in a layout
52  * It is 2-dimensional at the moment
53  */
54 class CLPoint : public CLBase
55 {
56 protected:
57 
60 
61 public:
62 
64  mX(0.0)
65  , mY(0.0)
66  , mZ(0.0)
67  {};
68 
69  CLPoint(const C_FLOAT64 & x
70  , const C_FLOAT64 & y
71  , const C_FLOAT64 & z = 0.0
72  ):
73  mX(x)
74  , mY(y)
75  , mZ(z)
76  {};
77 
78  /**
79  * constructor from libsbml object
80  */
81  CLPoint(const Point& p);
82 
83  const C_FLOAT64 & getX() const {return mX;};
84  const C_FLOAT64 & getY() const {return mY;};
85  const C_FLOAT64 & getZ() const {return mZ;};
86 
87  C_FLOAT64 & getX() {return mX;};
88  C_FLOAT64 & getY() {return mY;};
89  C_FLOAT64 & getZ() {return mZ;};
90 
91  void setX(const C_FLOAT64 & x) {mX = x;};
92  void setY(const C_FLOAT64 & y) {mY = y;};
93  void setZ(const C_FLOAT64 & z) {mZ = z;};
94 
95  void scale(const double & scaleFactor) {mX *= scaleFactor; mY *= scaleFactor;}
96 
97  bool operator==(const CLPoint & rhs) const
98  {
99  bool result = (mX == rhs.mX) && (mY == rhs.mY);
100  result &= mZ == rhs.mZ;
101  return result;
102  };
103 
104  CLPoint operator-(const CLPoint & rhs) const
105  {
106  return CLPoint(this->mX - rhs.mX,
107  this->mY - rhs.mY
108  , this->mZ - rhs.mZ
109  );
110  };
111 
112  CLPoint operator+(const CLPoint & rhs) const
113  {
114  return CLPoint(this->mX + rhs.mX,
115  this->mY + rhs.mY
116  , this->mZ + rhs.mZ
117  );
118  };
119 
120  virtual void moveBy(const CLPoint &p)
121  {
122  mX += p.mX;
123  mY += p.mY;
124  mZ += p.mZ;
125  };
126 
127  CLPoint operator*(const double & rhs) const
128  {
129  return CLPoint(this->mX * rhs,
130  this->mY * rhs
131  , this->mZ * rhs
132  );
133  };
134 
135  C_FLOAT64 dot(const CLPoint & rhs) const
136  {
137  return this->mX * rhs.mX + this->mY * rhs.mY
138  + this->mZ * rhs.mZ
139  ;
140  };
141 
142  // sort columnwise, point p1 is < point p2 if x-component is <, if x es are equal, check for y
143  bool operator<(const CLPoint & rhs) const
144  {
145  if (mX == rhs.mX)
146  if (mY == rhs.mY)
147  {
148  return (mZ < rhs.mZ);
149  }
150  else
151  {
152  return (mY < rhs.mY);
153  }
154  else
155  return (mX < rhs.mX);
156  };
157 
158  /**
159  * convert to sbml point
160  */
161  Point getSBMLPoint() const;
162 
163  bool isEmpty() const
164  {
165  return mX == 0
166  && mY == 0
167  && mZ == 0
168  ;
169  }
170 
171  /**
172  * insert operator
173  */
174  friend std::ostream & operator<<(std::ostream &os, const CLPoint & p);
175 };
176 
177 /**
178  * This class describes a size in a layout.
179  * It is 2-dimensional at the moment.
180  */
181 class CLDimensions : public CLBase
182 {
183 protected:
184 
187 
188 public:
189 
191  mWidth(0.0)
192  , mHeight(0.0)
193  , mDepth(0.0)
194 
195  {};
196 
198  , const C_FLOAT64 & h
199  , const C_FLOAT64 & d = 0.0
200  ):
201  mWidth(w)
202  , mHeight(h)
203  , mDepth(d)
204  {};
205 
206  /**
207  * constructor from libsbml object
208  */
209  CLDimensions(const Dimensions& d);
210 
211  const C_FLOAT64 & getWidth() const {return mWidth;};
212  const C_FLOAT64 & getHeight() const {return mHeight;};
213  const C_FLOAT64 & getDepth() const {return mDepth;};
214 
215  C_FLOAT64 & getWidth() {return mWidth;};
216  C_FLOAT64 & getHeight() {return mHeight;};
217  C_FLOAT64 & getDepth() {return mDepth;};
218 
219  void setWidth(const C_FLOAT64 & w) {mWidth = w;};
220  void setHeight(const C_FLOAT64 & h) {mHeight = h;};
221  void setDepth(const C_FLOAT64 & d) {mDepth = d;};
222 
223  void scale(const double & scaleFactor)
224  {
225  mWidth *= scaleFactor;
226  mHeight *= scaleFactor;
227  mDepth *= scaleFactor;
228  }
229 
230  /**
231  * convert to sbml dimension
232  */
233  Dimensions getSBMLDimensions() const;
234 
235  /**
236  * insert operator
237  */
238  friend std::ostream & operator<<(std::ostream &os, const CLDimensions & d);
239 };
240 
241 /**
242  * This class describes a bounding box.
243  */
244 class CLBoundingBox : public CLBase
245 {
246 protected:
247 
249 
251 
252 public:
253 
255  : mPosition(), mDimensions() {};
256 
257  CLBoundingBox(const CLPoint & p, const CLDimensions & d)
258  : mPosition(p), mDimensions(d) {};
259 
260  /**
261  * constructor from libsbml object
262  */
263  CLBoundingBox(const BoundingBox & bb);
264 
265  const CLPoint & getPosition() const {return mPosition;};
266  const CLDimensions & getDimensions() const {return mDimensions;};
267 
271 
272  void setPosition(const CLPoint & p) {mPosition = p;};
273  void setDimensions(const CLDimensions & d) {mDimensions = d;};
274 
275  virtual void moveBy(const CLPoint &p)
276  {
277  mPosition.moveBy(p);
278  };
279 
280  /**
281  * convert to sbml bounding box
282  */
283  BoundingBox getSBMLBoundingBox() const;
284 
285  void scale(const double & scaleFactor) {mPosition.scale(scaleFactor); mDimensions.scale(scaleFactor);}
286 
287  /**
288  * insert operator
289  */
290  friend std::ostream & operator<<(std::ostream &os, const CLBoundingBox & bb);
291 };
292 
293 #endif
CLDimensions()
Definition: CLBase.h:190
virtual void moveBy(const CLPoint &)
Definition: CLBase.h:42
const C_FLOAT64 & getZ() const
Definition: CLBase.h:85
const C_FLOAT64 & getWidth() const
Definition: CLBase.h:211
const C_FLOAT64 & getDepth() const
Definition: CLBase.h:213
CLBase()
Definition: CLBase.h:36
CLPoint & getPosition()
Definition: CLBase.h:268
CLDimensions(const C_FLOAT64 &w, const C_FLOAT64 &h, const C_FLOAT64 &d=0.0)
Definition: CLBase.h:197
C_FLOAT64 & getZ()
Definition: CLBase.h:89
virtual void moveBy(const CLPoint &p)
Definition: CLBase.h:275
void setX(const C_FLOAT64 &x)
Definition: CLBase.h:91
void setPosition(const CLPoint &p)
Definition: CLBase.h:272
Point getSBMLPoint() const
Definition: CLBase.cpp:29
CLBoundingBox()
Definition: CLBase.h:254
void scale(const double &scaleFactor)
Definition: CLBase.h:285
CLPoint operator-(const CLPoint &rhs) const
Definition: CLBase.h:104
CLBase(const CLBase &b)
Definition: CLBase.h:37
friend std::ostream & operator<<(std::ostream &os, const CLBoundingBox &bb)
Definition: CLBase.cpp:80
Dimensions getSBMLDimensions() const
Definition: CLBase.cpp:43
CLPoint operator*(const double &rhs) const
Definition: CLBase.h:127
bool hasTag() const
Definition: CLBase.h:45
void setY(const C_FLOAT64 &y)
Definition: CLBase.h:92
CLBoundingBox(const CLPoint &p, const CLDimensions &d)
Definition: CLBase.h:257
void setZ(const C_FLOAT64 &z)
Definition: CLBase.h:93
C_FLOAT64 mZ
Definition: CLBase.h:59
C_FLOAT64 mWidth
Definition: CLBase.h:185
const CLDimensions & getDimensions() const
Definition: CLBase.h:266
void setHeight(const C_FLOAT64 &h)
Definition: CLBase.h:220
bool operator<(const CLPoint &rhs) const
Definition: CLBase.h:143
void setDepth(const C_FLOAT64 &d)
Definition: CLBase.h:221
CLPoint operator+(const CLPoint &rhs) const
Definition: CLBase.h:112
const C_FLOAT64 & getX() const
Definition: CLBase.h:83
void setDimensions(const CLDimensions &d)
Definition: CLBase.h:273
Definition: CLBase.h:54
bool isEmpty() const
Definition: CLBase.h:163
const CLPoint & getPosition() const
Definition: CLBase.h:265
Definition: CLBase.h:33
CLDimensions & getDimensions()
Definition: CLBase.h:270
C_FLOAT64 mY
Definition: CLBase.h:58
C_FLOAT64 dot(const CLPoint &rhs) const
Definition: CLBase.h:135
CLPoint getCenter() const
Definition: CLBase.h:269
C_FLOAT64 & getDepth()
Definition: CLBase.h:217
C_FLOAT64 mX
Definition: CLBase.h:58
friend std::ostream & operator<<(std::ostream &os, const CLPoint &p)
Definition: CLBase.cpp:68
std::string mTag
Definition: CLBase.h:47
C_FLOAT64 & getX()
Definition: CLBase.h:87
C_FLOAT64 & getWidth()
Definition: CLBase.h:215
const C_FLOAT64 & getY() const
Definition: CLBase.h:84
const std::string & getTag() const
Definition: CLBase.h:43
friend std::ostream & operator<<(std::ostream &os, const CLDimensions &d)
Definition: CLBase.cpp:74
CLPoint()
Definition: CLBase.h:63
C_FLOAT64 & getY()
Definition: CLBase.h:88
const C_FLOAT64 & getHeight() const
Definition: CLBase.h:212
#define C_FLOAT64
Definition: copasi.h:92
C_FLOAT64 mDepth
Definition: CLBase.h:186
virtual ~CLBase()
Definition: CLBase.h:41
C_FLOAT64 mHeight
Definition: CLBase.h:185
void scale(const double &scaleFactor)
Definition: CLBase.h:95
void setTag(const std::string &tag)
Definition: CLBase.h:44
C_FLOAT64 & getHeight()
Definition: CLBase.h:216
void scale(const double &scaleFactor)
Definition: CLBase.h:223
CLPoint(const C_FLOAT64 &x, const C_FLOAT64 &y, const C_FLOAT64 &z=0.0)
Definition: CLBase.h:69
BoundingBox getSBMLBoundingBox() const
Definition: CLBase.cpp:60
virtual void moveBy(const CLPoint &p)
Definition: CLBase.h:120
CLPoint mPosition
Definition: CLBase.h:248
CLBase(const SBase &)
Definition: CLBase.h:38
void setWidth(const C_FLOAT64 &w)
Definition: CLBase.h:219
CLDimensions mDimensions
Definition: CLBase.h:250
bool operator==(const CLPoint &rhs) const
Definition: CLBase.h:97