Bridges-C++  3.4.2
Bridges(C++ API)
Text.h
Go to the documentation of this file.
1 
2 #ifndef LABEL_H
3 
4 #define LABEL_H
5 
6 #include "DataStructure.h"
7 #include "Symbol.h"
8 #include <vector>
9 #include <cmath>
10 
11 using namespace std;
12 
18 namespace bridges {
19  namespace datastructure {
28  class Text : public Symbol {
29  private:
30  // label anchor location
31  double origin[2];
32 
33  // label attributes
34  double fontSize = 12;
35  string *anchorType = nullptr,
36  *anchorAlignmentLR = nullptr,
37  *anchorAlignmentTB = nullptr;
38 
39  string label_text = string();
40 
41  public:
42 
46  Text() :
47  anchorType(nullptr),
48  anchorAlignmentLR(nullptr),
49  anchorAlignmentTB(nullptr) {
50 
51  origin[0] = origin[1] = 0.0f;
52  }
53 
54  Text(const Text& t):
55  Symbol(t) {
56  this->label_text = t.label_text;
57  this->origin[0] = t.origin[0];
58  this->origin[1] = t.origin[1];
59  this->fontSize = t.fontSize;
60 
61  if (t.anchorType)
62  this->anchorType = new string(*(t.anchorType));
63  if (t.anchorAlignmentTB)
64  this->anchorAlignmentTB = new string(*(t.anchorAlignmentTB));
65  if (t.anchorAlignmentLR)
66  this->anchorAlignmentLR = new string(*(t.anchorAlignmentLR));
67  }
68 
69  Text& operator= (const Text& t) {
70  Symbol::operator=(t);
71 
72  this->label_text = t.label_text;
73  this->origin[0] = t.origin[0];
74  this->origin[1] = t.origin[1];
75 
76  if (anchorType) {
77  delete anchorType;
78  anchorType = nullptr;
79  }
80  if (anchorAlignmentLR) {
81  delete anchorAlignmentLR;
82  anchorAlignmentLR = nullptr;
83  }
84  if (anchorAlignmentTB) {
85  delete anchorAlignmentTB;
86  anchorAlignmentTB = nullptr;
87  }
88 
89  this->fontSize = t.fontSize;
90  if (t.anchorType)
91  this->anchorType = new string(*(t.anchorType));
92  if (t.anchorAlignmentTB)
93  this->anchorAlignmentTB = new string(*(t.anchorAlignmentTB));
94  if (t.anchorAlignmentLR)
95  this->anchorAlignmentLR = new string(*(t.anchorAlignmentLR));
96 
97  return *this;
98  }
99 
105  Text (string l): Text() {
106  label_text = l;
107  }
108 
109  ~Text() {
110  if (anchorType)
111  delete anchorType;
112  if (anchorAlignmentLR)
113  delete anchorAlignmentLR;
114  if (anchorAlignmentTB)
115  delete anchorAlignmentTB;
116  }
117 
118  /*
119  * @brief Get Data Structure name
120  * @return name of data type
121  */
122  virtual string getShapeType() const override {
123  return "text";
124  }
130  Text& setText(string lbl) {
131  label_text = lbl;
132 
133  return *this;
134  }
135 
141  string getText() const {
142  return label_text;
143  }
144 
151  Text& setAnchorLocation(float *loc) {
152  origin[0] = loc[0];
153  origin[1] = loc[1];
154 
155  return *this;
156  }
157 
165  Text& setAnchorLocation(float locx, float locy) {
166  origin[0] = locx;
167  origin[1] = locy;
168 
169  return *this;
170  }
171 
181  Text& setAnchorAlignment(string typeLR, string typeTB) {
182  if (!anchorAlignmentLR)
183  anchorAlignmentLR = new string;
184  if (!anchorAlignmentTB)
185  anchorAlignmentTB = new string;
186 
187 
188  *anchorAlignmentLR = typeLR;
189  *anchorAlignmentTB = typeTB;
190 
191  return *this;
192  }
193 
201  return origin[0];
202  }
203 
211  return origin[1];
212  }
213 
221  Symbol& setAnchorType(string type) {
222  if (!anchorType)
223  anchorType = new string;
224 
225  *anchorType = type;
226 
227  return *this;
228  }
229 
236  string getAnchorType() {
237  if (!anchorType)
238  throw "Anchor type not set!";
239 
240  return *anchorType;
241  }
242 
250  Symbol& setFontSize(double sz) {
251  fontSize = sz;
252 
253  return *this;
254  }
255 
262  double getFontSize() {
263  return fontSize;
264  }
265 
266 
272  const string getSymbolRepresentation() const override {
273 
274  string shape_json = getSymbolAttributeRepresentation();
275  if (anchorType)
276  shape_json += QUOTE + "anchorType" + QUOTE + COLON +
277  QUOTE + *anchorType + QUOTE + COMMA;
278 
279  if (anchorAlignmentLR)
280  shape_json += QUOTE + "anchor-alignmentLR" + QUOTE + COLON +
281  QUOTE + *anchorAlignmentLR + QUOTE + COMMA;
282 
283  if (anchorAlignmentTB)
284  shape_json += QUOTE + "anchor-alignmentTB" + QUOTE + COLON +
285  QUOTE + *anchorAlignmentTB + QUOTE + COMMA;
286 
287  shape_json += QUOTE + "font-size" + QUOTE + COLON +
288  to_string(fontSize) + COMMA;
289 
290  shape_json +=
291  QUOTE + "anchor-location" + QUOTE + COLON +
292  OPEN_BOX +
293  to_string(origin[0]) + COMMA + to_string(origin[1]) +
294  CLOSE_BOX + COMMA +
295  QUOTE + "text" + QUOTE + COLON + QUOTE + label_text + QUOTE +
296  CLOSE_CURLY;
297 
298 
299  return shape_json;
300  }
301  };
302  }
303 } // namespace bridges
304 
305 #endif
This is an abstract class for deriving a number of Symbol shape objects, for use in a SymbolCollectio...
Definition: Symbol.h:32
This is a label object and used for defining text labels as part of the symbol collection.
Definition: Text.h:28
virtual string getShapeType() const override
Definition: Text.h:122
~Text()
Definition: Text.h:109
string getText() const
Get the symbol label.
Definition: Text.h:141
string getAnchorType()
This method gets the label's anchor type.
Definition: Text.h:236
Text & setText(string lbl)
Set the label text.
Definition: Text.h:130
double getFontSize()
This method gets the font size.
Definition: Text.h:262
double getAnchorLocationX()
This method gets the label anchor location.
Definition: Text.h:200
Text & setAnchorAlignment(string typeLR, string typeTB)
Definition: Text.h:181
Text(string l)
Definition: Text.h:105
double getAnchorLocationY()
This method gets the label anchor location.
Definition: Text.h:210
Text()
Definition: Text.h:46
Symbol & setFontSize(double sz)
This method sets the font size.
Definition: Text.h:250
const string getSymbolRepresentation() const override
This method returns the JSON representation of the shape.
Definition: Text.h:272
Text & setAnchorLocation(float locx, float locy)
This method sets the label origin;.
Definition: Text.h:165
Symbol & setAnchorType(string type)
This method sets the label's anchor type.
Definition: Text.h:221
Text & setAnchorLocation(float *loc)
This method sets the label origin;.
Definition: Text.h:151
Text(const Text &t)
Definition: Text.h:54
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
const string COLON
Definition: DataStructure.h:51
const string OPEN_BOX
Definition: DataStructure.h:54
const string COMMA
Definition: DataStructure.h:50
const string CLOSE_BOX
Definition: DataStructure.h:55
const string CLOSE_CURLY
Definition: DataStructure.h:53
const string QUOTE
Definition: DataStructure.h:49