Loading...
Searching...
No Matches
TreeUtilsSVG.h
1/*
2
3MIT License
4
5Copyright (c) 2023 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood 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_UTILS_SVG
39#define DRAIN_TREE_UTILS_SVG
40
41//
42
43#include <drain/util/Frame.h>
44#include <drain/util/EnumFlags.h>
45#include <drain/util/Rectangle.h>
46#include "AlignSVG.h"
47#include "TreeSVG.h"
48
49namespace drain {
50
51namespace image {
52/*
53struct PanelConfSVG {
54
56 bool absolutePaths = true;
57
58 // Currently, applications are recommended to handle "false" and "none". Or "auto"?
59 // std::string title;
60 // FontSizes fontSize;
61
62 inline // maxPerGroup(10), layout(Alignment::HORZ, LayoutSVG::INCR), legend(LEFT, EMBED),
63 PanelConfSVG() : absolutePaths(true){
64 }
65
66};
67*/
68
70
75//template <>
76// const drain::EnumDict<AlignSVG_FOO>::dict_t drain::EnumDict<AlignSVG_FOO>::dict;
77
79
80public:
81
82 // static PanelConfSVG defaultConf; // Consider separating Rack-specific properties.
83
84 /*
85 static
86 const std::set<XML::intval_t> abstractTags;
87
88 static
89 bool isAbstract(XML::intval_t tag);
90 */
91
93
96 static
97 bool computeBoundingBox(const TreeSVG & group, drain::Box<svg::coord_t> & box);
98
100
103 static
104 void finalizeBoundingBox(TreeSVG & svg);
105
106
108
113 // static
114 // void getBoundingFrame(const TreeSVG & group, drain::Frame2D<int> & frame, AlignBase::Axis orientation=AlignBase::Axis::HORZ);
115
116 // replaced with traversing setter
117 // static void setRelativePaths(drain::image::TreeSVG & object, const drain::FilePath & filepath);
118
119
120 // NEW ---------------------
121 static
122 void superAlign(TreeSVG & node, AlignBase::Axis orientation = AlignBase::Axis::HORZ, LayoutSVG::Direction direction = LayoutSVG::Direction::INCR);
123 //const Point2D<svg::coord_t> & offset = {0,0}); // replaces alignSequence
124
125 static
126 void superAlignNEW(TreeSVG & node, AlignBase::Axis orientation = AlignBase::Axis::HORZ, LayoutSVG::Direction direction = LayoutSVG::Direction::INCR);
127
128
129 // static
130 // void realignElem(TreeSVG & elem, const Box<svg::coord_t> & anchorBox);
131
133 // static
134 // void realignObject(const Box<svg::coord_t> & anchorBox, TreeSVG & obj);
135
136 static
137 void realignObject(const Box<svg::coord_t> & anchorBoxHorz, const Box<svg::coord_t> & anchorBoxVert, TreeSVG & obj);
138
139 // static
140 // void realignObject(AlignBase::Axis axis, svg::coord_t pos, svg::coord_t width, TreeSVG & obj, svg::coord_t & newPos); // , Point2D<svg::coord_t> & newLocation);
141
142 // static
143 // void realignObjectHorz(TreeSVG & obj, const Box<svg::coord_t> & anchorBoxHorz, svg::coord_t & coord);
144
145 static
146 void realignObjectHorz(TreeSVG & obj, const Box<svg::coord_t> & anchorBoxHorz);
147
148 // static
149 //void realignObjectVert(TreeSVG & obj, const Box<svg::coord_t> & anchorBoxVert, svg::coord_t & coord);
150
151 static
152 void realignObjectVert(TreeSVG & obj, const Box<svg::coord_t> & anchorBoxVert);
153
154
156 static
157 void translateAll(TreeSVG & group, const Point2D<svg::coord_t> &offset);
158
159};
160
161
162class TranslatorSVG : public drain::TreeVisitor<TreeSVG> {
163
164public:
165
166 const Point2D<svg::coord_t> offset;
167
168 template <class T>
169 inline
170 TranslatorSVG(const Point2D<T> & offset) : offset(offset){};
171
172 template <typename T>
173 inline
174 TranslatorSVG(T dx, T dy) : offset(dx, dy){};
175
176 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override;
177
178 // int visitPostfix(TreeSVG & tree, const TreeSVG::path_t & path) override;
179};
180
181
182class BBoxRetrieverSVG : public drain::TreeVisitor<TreeSVG> {
183
184public:
185
186 BBoxSVG box;
187 // Box<svg::coord_t> box;
188
189 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override;
190
191 int visitPostfix(TreeSVG & tree, const TreeSVG::path_t & path) override;
192};
193
194
196
197public:
198
199 // Leading path, maybe partial, to be pruned
200 const std::string dir;
201
202 // String starting the modified path, for example "file://"
203 const std::string prefix;
204
205 inline
206 RelativePathSetterSVG(const drain::FilePath & filepath, const std::string & prefix = "") :
207 dir(filepath.dir.empty() ? "" : filepath.dir.str()+'/'),
208 prefix(prefix) {
209 }
210
211 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override;
212
213
214};
215
216
217
218
237} // image::
238
239/*
240template <>
241const drain::EnumDict<image::LayoutSVG::Axis>::dict_t drain::EnumDict<image::LayoutSVG::Axis>::dict;
242
243template <>
244const drain::EnumDict<image::LayoutSVG::Direction>::dict_t drain::EnumDict<image::LayoutSVG::Direction>::dict;
245*/
246
247} // drain::
248
249
250
251
252#endif // TREESVG_H_
253
Extracts and stores directory path, base filename and extension.
Definition FilePath.h:58
Default implementation of a tree visitor (concept) compatible TreeUtils::traverser()
Definition TreeUtils.h:270
Definition TreeUtilsSVG.h:182
Definition TreeSVG.h:88
Definition TreeUtilsSVG.h:195
Definition TreeUtilsSVG.h:162
int visitPrefix(TreeSVG &tree, const TreeSVG::path_t &path) override
Definition TreeUtilsSVG.cpp:524
Definition DataSelector.cpp:1277
Something that has coordinates (x,y) and dimensions (width, height).
Definition Frame.h:160
Definition Point.h:48
SVG classes marking requests of relative horizontal and vertical alignment.
Definition TreeUtilsSVG.h:78
static void superAlign(TreeSVG &node, AlignBase::Axis orientation=AlignBase::Axis::HORZ, LayoutSVG::Direction direction=LayoutSVG::Direction::INCR)
Computes the width and height for a bounding box IMAGE and RECT elements.
Definition TreeUtilsSVG.cpp:321
static void finalizeBoundingBox(TreeSVG &svg)
Compute bounding box and set the top-level SVG width, height and viewBox properties.
Definition TreeUtilsSVG.cpp:86
static bool computeBoundingBox(const TreeSVG &group, drain::Box< svg::coord_t > &box)
Compute bounding box of the whole structure.
Definition TreeUtilsSVG.cpp:58
static void realignObjectVert(TreeSVG &obj, const Box< svg::coord_t > &anchorBoxVert)
Definition TreeUtilsSVG.cpp:204
static void translateAll(TreeSVG &group, const Point2D< svg::coord_t > &offset)
Recursively move elements with (x, y).
Definition TreeUtilsSVG.cpp:500
static void realignObject(const Box< svg::coord_t > &anchorBoxHorz, const Box< svg::coord_t > &anchorBoxVert, TreeSVG &obj)
Align object respect to an anchor frame.
Definition TreeSVG.h:56