Bridges-C++  3.2.0
Bridges(C++API)
Label.h
Go to the documentation of this file.
1 #include "DataStructure.h"
2 #include "Symbol.h"
3 #include <vector>
4 
5 using namespace std;
6 
10 #ifndef LABEL_H
11 
12 #define LABEL_H
13 
14 
15 namespace bridges {
16  namespace datastructure {
25  class Label : public Symbol {
26  private:
27  // height, width of rectangle
28  int fontSize = 12;
29  int textWidth = 100;
30  int textHeight = 50;
31 
32  public:
33 
37  Label() {
38  fontSize = 12;
39  textWidth = 100;
40  textHeight = 50;
41  }
42 
48  Label (string l) {
49  setLabel(l);
50  }
51 
52  /*
53  * @brief Get Data Structure name
54  * @return name of data type
55  */
56 
57  string getDataStructType() {
58  return "label";
59  }
60 
66  string getName() const {
67  return "label";
68  }
69 
76  void setFontSize(int sz) {
77  fontSize = sz;
78  }
79 
86  int getFontSize() {
87  return fontSize;
88  }
89 
96  void setTextWidth(int w) {
97  textWidth = w;
98  }
99 
106  int getTextWidth() {
107  return textWidth;
108  }
109 
116  void setTextHeight(int h) {
117  textHeight = h;
118  }
119 
127  return textHeight;
128  }
129 
130 
137  vector<float> getDimensions() const {
138  vector<float> dims(4);
139 
140  float length = 0.09 * fontSize * getLabel().size();
141 
142  const float *location = getLocation();
143  dims[0] = location[0] - length / 2.;
144  dims[1] = location[1] + length / 2.;
145  dims[2] = dims[3] = location[1];
146 
147  return dims;
148  }
149 
155  const string getSymbolRepresentation() const {
156 
157  string shape_json = getSymbolAttributeRepresentation();
158 
159  shape_json +=
160  QUOTE + "name" + QUOTE + COLON + QUOTE + getLabel() + QUOTE + COMMA +
161  QUOTE + "shape" + QUOTE + COLON + QUOTE + "text" + QUOTE + COMMA +
162  QUOTE + "font-size" + QUOTE + COLON + to_string(fontSize) +
163  CLOSE_CURLY;
164 
165  return shape_json;
166 
167  }
168  };
169  }
170 } // namespace bridges
171 
172 #endif
Label(string l)
Definition: Label.h:48
const string getSymbolRepresentation() const
This method returns the JSON representation of the shape.
Definition: Label.h:155
void setTextHeight(int h)
Definition: Label.h:116
const string COLON
Definition: DataStructure.h:51
STL namespace.
const string CLOSE_CURLY
Definition: DataStructure.h:53
This is an abstract class for deriving a number of Symbol shape objects, for use in a SymbolCollectio...
Definition: Symbol.h:33
void setTextWidth(int w)
This method sets the text width.
Definition: Label.h:96
void setFontSize(int sz)
This method sets the font size.
Definition: Label.h:76
string getName() const
This method gets the name of the shape.
Definition: Label.h:66
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
int getTextWidth()
This method gets the text width.
Definition: Label.h:106
vector< float > getDimensions() const
This method returns the bounding box dimensions of the shape.
Definition: Label.h:137
int getTextHeight()
This method gets the text height.
Definition: Label.h:126
This is a label object and used for defining text labels as part of the symbol collection.
Definition: Label.h:25
const string COMMA
Definition: DataStructure.h:50
const string QUOTE
Definition: DataStructure.h:49
string getDataStructType()
Definition: Label.h:57
Label()
Definition: Label.h:37
int getFontSize()
This method gets the font size.
Definition: Label.h:86