COPASI API  4.16.103
CLText.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 #include <limits>
7 
8 #include <sbml/packages/render/sbml/Text.h>
9 
10 #include "CLText.h"
11 
14 
15 // Ctor
18  CCopasiObject("RenderText", pParent),
19  mX(CLRelAbsVector(0.0, 0.0)),
20  mY(CLRelAbsVector(0.0, 0.0)),
21  mZ(CLRelAbsVector(0.0, 0.0)),
22  mFontFamily(""),
23  mFontSize(CLRelAbsVector(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN())),
24  mFontWeight(CLText::WEIGHT_UNSET),
25  mFontStyle(CLText::STYLE_UNSET),
26  mTextAnchor(CLText::ANCHOR_UNSET),
27  mVTextAnchor(CLText::ANCHOR_UNSET),
28  mText(""),
29  mKey("")
30 {
31  this->mKey = CCopasiRootContainer::getKeyFactory()->add("RenderText", this);
32 }
33 
34 /**
35  * Constructor with optional coordinates.
36  */
39  CCopasiObject("RenderText", pParent),
40  mX(x),
41  mY(y),
42  mZ(z),
43  mFontFamily(""),
44  mFontSize(CLRelAbsVector(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN())),
45  mFontWeight(CLText::WEIGHT_UNSET),
46  mFontStyle(CLText::STYLE_UNSET),
47  mTextAnchor(CLText::ANCHOR_UNSET),
48  mVTextAnchor(CLText::ANCHOR_UNSET),
49  mText(""),
50  mKey("")
51 {
52  this->mKey = CCopasiRootContainer::getKeyFactory()->add("RenderText", this);
53 }
54 
55 /**
56  * Copy constructor.
57  */
58 CLText::CLText(const CLText& source, CCopasiContainer* pParent):
59  CLGraphicalPrimitive1D(source),
60  CCopasiObject(source, pParent),
61  mX(source.mX),
62  mY(source.mY),
63  mZ(source.mZ),
64  mFontFamily(source.mFontFamily),
65  mFontSize(source.mFontSize),
66  mFontWeight(source.mFontWeight),
67  mFontStyle(source.mFontStyle),
68  mTextAnchor(source.mTextAnchor),
69  mVTextAnchor(source.mVTextAnchor),
70  mText(source.mText),
71  mKey("")
72 {
73  this->mKey = CCopasiRootContainer::getKeyFactory()->add("RenderText", this);
74 }
75 
76 /**
77  * Constructor to generate object from the corresponding SBML object.
78  */
79 CLText::CLText(const Text& source, CCopasiContainer* pParent):
80  CLGraphicalPrimitive1D(source),
81  CCopasiObject("RenderText", pParent),
82  mX(source.getX()),
83  mY(source.getY()),
84  mZ(source.getZ()),
85  mFontFamily(source.getFontFamily()),
86  mFontSize(source.getFontSize()),
87  mText(source.getText()),
88  mKey("")
89 {
90  this->mKey = CCopasiRootContainer::getKeyFactory()->add("RenderText", this);
91 
92  switch (source.getFontWeight())
93  {
94  case Text::WEIGHT_UNSET:
96  break;
97 
98  case Text::WEIGHT_BOLD:
100  break;
101 
102  default:
104  break;
105  }
106 
107  switch (source.getFontStyle())
108  {
109  case Text::STYLE_UNSET:
111  break;
112 
113  case Text::STYLE_ITALIC:
115  break;
116 
117  default:
119  break;
120  }
121 
122  switch (source.getTextAnchor())
123  {
124  case Text::ANCHOR_UNSET:
126  break;
127 
128  case Text::ANCHOR_END:
130  break;
131 
132  case Text::ANCHOR_MIDDLE:
134  break;
135 
136  default:
138  break;
139  }
140 
141  switch (source.getVTextAnchor())
142  {
143  case Text::ANCHOR_UNSET:
145  break;
146 
147  case Text::ANCHOR_BOTTOM:
149  break;
150 
151  case Text::ANCHOR_MIDDLE:
153  break;
154 
155  default:
157  break;
158  }
159 }
160 
161 /**
162  * Destructor
163  */
165 {
167 }
168 
169 /**
170  * Sets the coordinates.
171  */
173 {
174  this->mX = x;
175  this->mY = y;
176  this->mZ = z;
177 }
178 
179 /**
180  * Sets the x coordinate.
181  */
182 void CLText::setX(const CLRelAbsVector& coord)
183 {
184  this->mX = coord;
185 }
186 
187 /**
188  * Sets the y coordinate.
189  */
190 void CLText::setY(const CLRelAbsVector& coord)
191 {
192  this->mY = coord;
193 }
194 
195 /**
196  * Sets the z coordinate.
197  */
198 void CLText::setZ(const CLRelAbsVector& coord)
199 {
200  this->mZ = coord;
201 }
202 
203 /**
204  * Returns the x coordinate.
205  */
207 {
208  return this->mX;
209 }
210 
211 /**
212  * Returns the y coordinate.
213  */
215 {
216  return this->mY;
217 }
218 
219 /**
220  * Returns the z coordinate.
221  */
223 {
224  return this->mZ;
225 }
226 
227 /**
228  * Returns the x coordinate.
229  */
231 {
232  return this->mX;
233 }
234 
235 /**
236  * Returns the y coordinate.
237  */
239 {
240  return this->mY;
241 }
242 
243 /**
244  * Returns the z coordinate.
245  */
247 {
248  return this->mZ;
249 }
250 
251 /**
252  * Sets the font family.
253  */
254 void CLText::setFontFamily(const std::string& family)
255 {
256  this->mFontFamily = family;
257 }
258 
259 /**
260  * Sets the font size.
261  */
263 {
264  this->mFontSize = size;
265 }
266 
267 /**
268  * Sets the font weight.
269  */
271 {
272  this->mFontWeight = weight;
273 }
274 
275 /**
276  * Sets the font style.
277  */
279 {
280  this->mFontStyle = style;
281 }
282 
283 /**
284  * Sets the text anchor.
285  */
287 {
288  this->mTextAnchor = anchor;
289 }
290 
291 /**
292  * Sets the vertical text anchor.
293  */
295 {
296  this->mVTextAnchor = anchor;
297 }
298 
299 /**
300  * Returns the font family.
301  */
302 const std::string& CLText::getFontFamily() const
303 {
304  return this->mFontFamily;
305 }
306 
307 /**
308  * Returns the font size.
309  */
311 {
312  return this->mFontSize;
313 }
314 
315 /**
316  * Returns the font size.
317  */
319 {
320  return this->mFontSize;
321 }
322 
323 /**
324  * Returns the font weight.
325  */
327 {
328  return this->mFontWeight;
329 }
330 
331 /**
332  * Returns the font style.
333  */
335 {
336  return this->mFontStyle;
337 }
338 
339 /**
340  * Returns the text anchor.
341  */
343 {
344  return this->mTextAnchor;
345 }
346 
347 /**
348  * Returns the vertical text anchor.
349  */
351 {
352  return this->mVTextAnchor;
353 }
354 
355 /**
356  * Returns the text for the text element.
357  */
358 const std::string& CLText::getText() const
359 {
360  return this->mText;
361 }
362 
363 /**
364  * Sets the text for the text element.
365  */
366 void CLText::setText(const std::string& text)
367 {
368  this->mText = text;
369 }
370 
371 /**
372  * Returns true if the text is set to something else than the empty string.
373  */
374 bool CLText::isSetText() const
375 {
376  return !this->mText.empty();
377 }
378 
379 /**
380  * Returns true if the font family has been set or false otherwise.
381  */
383 {
384  return !this->mFontFamily.empty();
385 }
386 
387 /**
388  * Returns true if the font size has been set or false otherwise.
389  */
391 {
393 }
394 
395 /**
396  * Returns true if the font weight has been set or false otherwise.
397  */
399 {
400  return (this->mFontWeight != CLText::WEIGHT_UNSET);
401 }
402 
403 /**
404  * Returns true if the font style has been set or false otherwise.
405  */
407 {
408  return (this->mFontStyle != CLText::STYLE_UNSET);
409 }
410 
411 /**
412  * Returns true if the horizonal alignment attribute has been set.
413  */
415 {
416  return this->mTextAnchor != CLText::ANCHOR_UNSET;
417 }
418 
419 /**
420  * Returns true if the vertical alignment attribute has been set.
421  */
423 {
424  return this->mVTextAnchor != CLText::ANCHOR_UNSET;
425 }
426 
427 /**
428  * Returns the key of the text element
429  */
430 const std::string& CLText::getKey() const
431 {
432  return this->mKey;
433 }
434 
435 /**
436  * Converts this object to the corresponding SBML object.
437  */
438 Text* CLText::toSBML(unsigned int level, unsigned int version) const
439 {
440  Text* pText = new Text(level, version);
441  this->addSBMLAttributes(pText);
442  RelAbsVector* pV1 = this->mX.toSBML();
443  RelAbsVector* pV2 = this->mY.toSBML();
444  RelAbsVector* pV3 = this->mZ.toSBML();
445  pText->setCoordinates(*pV1, *pV2, *pV3);
446  delete pV1;
447  delete pV2;
448  delete pV3;
449  pV1 = this->mFontSize.toSBML();
450  pText->setFontSize(*pV1);
451  delete pV1;
452  pText->setFontFamily(this->getFontFamily());
453  pText->setText(this->getText());
454 
455  switch (this->getFontWeight())
456  {
458  pText->setFontWeight(Text::WEIGHT_UNSET);
459  break;
460 
461  case CLText::WEIGHT_BOLD:
462  pText->setFontWeight(Text::WEIGHT_BOLD);
463  break;
464 
465  default:
466  pText->setFontWeight(Text::WEIGHT_NORMAL);
467  break;
468  }
469 
470  switch (this->getFontStyle())
471  {
472  case CLText::STYLE_UNSET:
473  pText->setFontStyle(Text::STYLE_UNSET);
474  break;
475 
477  pText->setFontStyle(Text::STYLE_ITALIC);
478  break;
479 
480  default:
481  pText->setFontStyle(Text::STYLE_NORMAL);
482  break;
483  }
484 
485  switch (this->getTextAnchor())
486  {
488  pText->setTextAnchor(Text::ANCHOR_UNSET);
489  break;
490 
491  case CLText::ANCHOR_END:
492  pText->setTextAnchor(Text::ANCHOR_END);
493  break;
494 
496  pText->setTextAnchor(Text::ANCHOR_MIDDLE);
497  break;
498 
499  default:
500  pText->setTextAnchor(Text::ANCHOR_START);
501  break;
502  }
503 
504  switch (this->getVTextAnchor())
505  {
507  pText->setVTextAnchor(Text::ANCHOR_UNSET);
508  break;
509 
511  pText->setVTextAnchor(Text::ANCHOR_BOTTOM);
512  break;
513 
515  pText->setVTextAnchor(Text::ANCHOR_MIDDLE);
516  break;
517 
518  default:
519  pText->setVTextAnchor(Text::ANCHOR_TOP);
520  break;
521  }
522 
523  return pText;
524 }
bool remove(const std::string &key)
void setText(const std::string &text)
Definition: CLText.cpp:366
Definition: CLText.h:27
FONT_STYLE mFontStyle
Definition: CLText.h:65
FONT_WEIGHT mFontWeight
Definition: CLText.h:64
const CLRelAbsVector & getZ() const
Definition: CLText.cpp:222
const CLRelAbsVector & getY() const
Definition: CLText.cpp:214
CLText(CCopasiContainer *pParent)
Definition: CLText.cpp:16
std::string mText
Definition: CLText.h:68
double getRelativeValue() const
void setVTextAnchor(CLText::TEXT_ANCHOR anchor)
Definition: CLText.cpp:294
bool isSetFontStyle() const
Definition: CLText.cpp:406
void setTextAnchor(CLText::TEXT_ANCHOR anchor)
Definition: CLText.cpp:286
CLRelAbsVector mZ
Definition: CLText.h:61
const CLRelAbsVector & getFontSize() const
Definition: CLText.cpp:318
void setFontSize(const CLRelAbsVector &size)
Definition: CLText.cpp:262
bool isSetFontSize() const
Definition: CLText.cpp:390
bool isSetFontFamily() const
Definition: CLText.cpp:382
bool isSetVTextAnchor() const
Definition: CLText.cpp:422
FONT_STYLE getFontStyle() const
Definition: CLText.cpp:334
CLRelAbsVector mY
Definition: CLText.h:60
std::string mKey
Definition: CLText.h:73
FONT_STYLE
Definition: CLText.h:41
RelAbsVector * toSBML() const
const std::string & getKey() const
Definition: CLText.cpp:430
void setFontWeight(CLText::FONT_WEIGHT weight)
Definition: CLText.cpp:270
std::string mFontFamily
Definition: CLText.h:62
std::string add(const std::string &prefix, CCopasiObject *pObject)
void setCoordinates(const CLRelAbsVector &x, const CLRelAbsVector &y, const CLRelAbsVector &z=CLRelAbsVector(0.0, 0.0))
Definition: CLText.cpp:172
void setFontFamily(const std::string &family)
Definition: CLText.cpp:254
CLRelAbsVector mX
Definition: CLText.h:59
bool isSetText() const
Definition: CLText.cpp:374
~CLText()
Definition: CLText.cpp:164
double getAbsoluteValue() const
static CKeyFactory * getKeyFactory()
TEXT_ANCHOR
Definition: CLText.h:48
void setX(const CLRelAbsVector &coord)
Definition: CLText.cpp:182
Text * toSBML(unsigned int level, unsigned int version) const
Definition: CLText.cpp:438
TEXT_ANCHOR mVTextAnchor
Definition: CLText.h:67
const std::string & getFontFamily() const
Definition: CLText.cpp:302
TEXT_ANCHOR mTextAnchor
Definition: CLText.h:66
bool isSetTextAnchor() const
Definition: CLText.cpp:414
TEXT_ANCHOR getVTextAnchor() const
Definition: CLText.cpp:350
const std::string & getText() const
Definition: CLText.cpp:358
void setY(const CLRelAbsVector &coord)
Definition: CLText.cpp:190
CLRelAbsVector mFontSize
Definition: CLText.h:63
const CLRelAbsVector & getX() const
Definition: CLText.cpp:206
void setZ(const CLRelAbsVector &coord)
Definition: CLText.cpp:198
bool isSetFontWeight() const
Definition: CLText.cpp:398
FONT_WEIGHT
Definition: CLText.h:34
TEXT_ANCHOR getTextAnchor() const
Definition: CLText.cpp:342
virtual void addSBMLAttributes(GraphicalPrimitive1D *pPrimitive) const
FONT_WEIGHT getFontWeight() const
Definition: CLText.cpp:326
void setFontStyle(CLText::FONT_STYLE style)
Definition: CLText.cpp:278