TreeSVG.h
1 /*
2 
3 MIT License
4 
5 Copyright (c) 2023 FMI Open Development / Markus Peura, first.last@fmi.fi
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 SOFTWARE.
24 
25 */
26 /*
27 Part of Rack development has been done in the BALTRAD projects part-financed
28 by the European Union (European Regional Development Fund and European
29 Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30 */
31 /*
32  * TreeSVG.h
33  *
34  * Created on: Jun 24, 2012
35  * Author: mpeura
36  */
37 
38 #ifndef DRAIN_TREE_SVG
39 #define DRAIN_TREE_SVG
40 
41 #include "drain/util/FileInfo.h"
42 #include "drain/util/TreeXML.h"
43 
44 namespace drain {
45 
46 namespace image {
47 
48 class NodeSVG;
49 
50 typedef drain::UnorderedMultiTree<NodeSVG,false, NodeXML<>::path_t> TreeSVG;
51 
52 struct svg {
53 
54  enum tag_t {
55  UNDEFINED=NodeXML<>::UNDEFINED,
56  COMMENT=NodeXML<>::COMMENT,
57  CTEXT=NodeXML<>::CTEXT,
58  STYLE=NodeXML<>::STYLE,
59  SCRIPT=NodeXML<>::SCRIPT,
60  SVG, CIRCLE, DESC, GROUP, LINE, IMAGE, METADATA, POLYGON, RECT, TEXT, TITLE, TSPAN };
61  // check CTEXT, maybe implement in XML
62 
63 
64 };
65 
67 
73 class NodeSVG: public svg, public NodeXML<svg::tag_t> {
74 public:
75 
76  // typedef NodeXML<svg::tag_t> xml_node_t;
77 
79  NodeSVG(tag_t t = svg::UNDEFINED);
80 
82  NodeSVG(const NodeSVG & node);
83 
84  inline virtual
85  ~NodeSVG(){};
86 
88  virtual
89  void setType(const tag_t & type);
90 
91  /* Consider this later, for user-defined (not enumerated) tag types.
92  virtual
93  void setType(const std::string & type);
94  */
95 
97  inline
98  NodeSVG & operator=(const NodeSVG & n){
99  if (&n != this){
100  drain::SmartMapTools::setValues<map_t>((map_t &)*this, n);
101  }
102  return *this;
103  }
104 
106  inline
107  NodeSVG & operator=(const tag_t & type){
108  setType(type);
109  return *this;
110  }
111 
113  inline
114  NodeSVG & operator=(const char *s){
115  setText(s);
116  return *this;
117  }
118 
120  inline
121  NodeSVG & operator=(const std::string &s){
122  setText(s);
123  return *this;
124  }
125 
127  inline
128  NodeSVG & operator=(const std::initializer_list<Variable::init_pair_t > &l){
129  set(l);
130  return *this;
131  }
132 
133 
135  static
136  std::string xlink;
137 
139  static
140  std::string svg;
141 
142  static
143  const drain::FileInfo fileInfo;
144 
145 
146 protected:
147 
148  // svg:
149  int x;
150  int y;
151  //std::string width; // can be "240px" or "90%" ?
152  //std::string height;
153  int width;
154  int height;
155  int radius;
156  // std::string style;
157  std::string fill;
158  std::string opacity; // empty
159  std::string text_anchor;
160 
161 };
162 
163 
164 
165 
166 } // image::
167 
168 } // drain::
169 
170 
171 
172 inline
173 std::ostream & operator<<(std::ostream &ostr, const drain::image::TreeSVG & tree){
174  return drain::NodeXML<>::docToStream(ostr, tree);
175  //return drain::image::TreeSVG::node_data_t::docToStream(ostr, tree);
176 }
177 
178 
179 namespace drain {
180 
181 DRAIN_TYPENAME(image::NodeSVG);
182 
183 template <>
184 template <>
185 image::TreeSVG & image::TreeSVG::operator()(const image::svg::tag_t & type);
186 /*{
187  this->data.setType(type);
188  return *this;
189 }*/
190 
191 
192 }
193 
194 
195 #endif // TREESVG_H_
196 
Definition: FileInfo.h:48
Definition: TreeXML.h:135
NodeXML & setText(const S &value)
Assign the text content of this node. If the node type is undefined, set it to CTEXT.
Definition: TreeXML.h:521
Definition: TreeSVG.h:73
NodeSVG & operator=(const std::string &s)
Set text (CTEXT).
Definition: TreeSVG.h:121
NodeSVG & operator=(const char *s)
Set text (CTEXT).
Definition: TreeSVG.h:114
static std::string xlink
In opening SVG tag, referred to by attribute "xmlns:xlink".
Definition: TreeSVG.h:136
NodeSVG & operator=(const NodeSVG &n)
Copy data from a node. (Does not copy subtree.)
Definition: TreeSVG.h:98
NodeSVG & operator=(const std::initializer_list< Variable::init_pair_t > &l)
Set attributes.
Definition: TreeSVG.h:128
NodeSVG & operator=(const tag_t &type)
Set type.
Definition: TreeSVG.h:107
NodeSVG(tag_t t=svg::UNDEFINED)
Default constructor. Create a node of given type.
Definition: TreeSVG.cpp:84
static std::string svg
In opening SVG tag, referred to by attributes "xmlns" and "xmlns:svg".
Definition: TreeSVG.h:140
Definition: DataSelector.cpp:1277
Definition: TreeSVG.h:52