Bridges-C++  3.4.1
Bridges(C++API)
SymbolCollection.h
Go to the documentation of this file.
1 #include <cmath>
2 #include <string>
3 #include <vector>
4 #include <unordered_map>
5 
6 using namespace std;
7 
8 #include "DataStructure.h"
9 #include "Symbol.h"
10 
25 #ifndef SYMBOL_COLLECTION_H
26 
27 #define SYMBOL_COLLECTION_H
28 
29 namespace bridges {
30  namespace datastructure {
39  // keep track of the shape elements; useful
40  // to maintain their properties
41  private:
42 
43  std::vector<std::shared_ptr<Symbol>> symbols;
44 
45  // default domain (assuming square coordinate space)
46  // domain emanates in x and y directions, both positive
47  // and negative,
48  // from 0,0
49 
50  protected:
51  mutable float domainxmin = -100.0;
52  mutable float domainxmax = 100.0;
53  mutable float domainymin = -100.0;
54  mutable float domainymax = 100.0;
55 
56  public:
57 
68  void setViewport(float xmin, float xmax, float ymin, float
69  ymax) {
70  domainxmin = xmin;
71  domainxmax = xmax;
72  domainymin = ymin;
73  domainymax = ymax;
74  }
79  }
80 
86  virtual const string getDStype() const {
87  return "SymbolCollectionV2";
88  }
89 
96  void addSymbolPtr(std::shared_ptr<Symbol> s) {
97  symbols.push_back(s);
98  }
99 
100  template <typename T>
101  void addSymbol(T s) {
102  std::shared_ptr<T> pt = std::make_shared<T>(s);
103  addSymbolPtr ((std::shared_ptr<Symbol>)pt);
104  }
105 
106 
107 
108  private:
109 
110  /*
111  * @brief Get the JSON representation of the the data structure
112  * @return JSON string of the symbol representation
113  */
114  virtual const string getDataStructureRepresentation() const {
115 
116  string symbol_json = string();
117  for (auto& entry : symbols) {
118  symbol_json +=
119  entry->getSymbolRepresentation() + COMMA;
120  }
121  // remove last comma
122  if (symbols.size()) {
123  symbol_json.erase(symbol_json.size() - 1);
124 
125  symbol_json = QUOTE + "domainX" + QUOTE + COLON +
126  OPEN_BOX +
127  to_string(domainxmin) + COMMA + to_string(domainxmax) +
128  CLOSE_BOX + COMMA +
129  QUOTE + "domainY" + QUOTE + COLON +
130  OPEN_BOX +
131  to_string(domainymin) + COMMA + to_string(domainymax) +
132  CLOSE_BOX + COMMA +
133  QUOTE + "symbols" + QUOTE + COLON +
134  OPEN_BOX + symbol_json + CLOSE_BOX + CLOSE_CURLY;
135  }
136  return symbol_json;
137  }
138  };
139  }
140 } // namespace bridges
141 
142 #endif
This is the superclass of all data structure types in BRIDGES.
Definition: DataStructure.h:73
virtual const string getDStype() const
This method gets the data structure type.
Definition: SymbolCollection.h:86
const string COLON
Definition: DataStructure.h:51
void addSymbolPtr(std::shared_ptr< Symbol > s)
This method adds a symbol to the collection.
Definition: SymbolCollection.h:96
const string OPEN_BOX
Definition: DataStructure.h:54
const string CLOSE_CURLY
Definition: DataStructure.h:53
void addSymbol(T s)
Definition: SymbolCollection.h:101
SymbolCollection()
Definition: SymbolCollection.h:78
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 CLOSE_BOX
Definition: DataStructure.h:55
void setViewport(float xmin, float xmax, float ymin, float ymax)
set the dimensions of the view
Definition: SymbolCollection.h:68
the ShapeCollection represents a collection of symbols (shapes, polygons, and text) to visualize in B...
Definition: SymbolCollection.h:38
const string COMMA
Definition: DataStructure.h:50
const string QUOTE
Definition: DataStructure.h:49