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/image/AlignAnchorSVG.h>
44#include <drain/util/Frame.h>
45#include <drain/util/EnumFlags.h>
46#include <drain/util/Rectangle.h>
47#include "LayoutSVG.h"
48#include "TreeSVG.h"
49
50namespace drain {
51
52namespace image {
53/*
54struct PanelConfSVG {
55
57 bool absolutePaths = true;
58
59 // Currently, applications are recommended to handle "false" and "none". Or "auto"?
60 // std::string title;
61 // FontSizes fontSize;
62
63 inline // maxPerGroup(10), layout(Alignment::HORZ, LayoutSVG::INCR), legend(LEFT, EMBED),
64 PanelConfSVG() : absolutePaths(true){
65 }
66
67};
68*/
69
71
76//template <>
77// const drain::EnumDict<AlignSVG_FOO>::dict_t drain::EnumDict<AlignSVG_FOO>::dict;
78
79template <AlignBase::Axis AX>
80struct CoordSpan {
81
82 inline
83 CoordSpan(svg::coord_t pos = 0, svg::coord_t span = 0) : pos(pos), span(span) {
84 }
85
86 inline
87 CoordSpan(const CoordSpan & cspan) : pos(cspan.pos), span(cspan.span) {
88 }
89
90 // Starting coordinate (x or y).
91 svg::coord_t pos = 0; //BBoxSVG::undefined;
92
93 // Width or height
94 svg::coord_t span = 0; // BBoxSVG::undefined;
95
96 // ? void getTranslatedCoordSpan(const BBoxSVG & bbox);
97 void copyFrom(const NodeSVG & node);
98
99 void copyFrom(const BBoxSVG & bbox);
100
101 /*
102 inline
103 bool isUndefined(){
104 return std::isnan(pos) || std::isnan(span);
105 }
106 */
107
108 inline
109 bool isDefined(){
110 return ! (std::isnan(pos) || std::isnan(span));
111 }
112};
113
114
116
117public:
118
119
120
122
127 static
128 void detectBox(TreeSVG & group, bool debug = false);
129
130 static inline
131 void getAdjustedBBox(const NodeSVG & node, BBoxSVG & bbox) { //, bool debug = false){
132 //detectBoxNEW(group, debug);
133 bbox = node.getBoundingBox();
134 bbox.x += node.transform.translate.x;
135 bbox.y += node.transform.translate.y;
136 }
137
138 template <AlignBase::Axis AX>
139 static
140 void adjustLocation(TreeSVG & group, NodeSVG & node, CoordSpan<AX> anchorSpan);
141
143
153 static
154 void addStackLayout(TreeSVG & object, AlignBase::Axis orientation = AlignBase::Axis::HORZ, LayoutSVG::Direction direction = LayoutSVG::Direction::INCR, unsigned short depth=0);
155
157
162 static
163 void setStackLayout(NodeSVG & node, AlignBase::Axis orientation, LayoutSVG::Direction direction);
164
165 static
166 void superAlign(TreeSVG & node);
167
168
169 // TODO: templated
170 template <AlignBase::Axis AX>
171 static
172 void realignObject(NodeSVG & node, const CoordSpan<AX> & span);
173
174
175
176
177};
178
179template <>
180void TreeUtilsSVG::realignObject(NodeSVG & node, const CoordSpan<AlignBase::Axis::HORZ> & span);
181
182template <>
183void TreeUtilsSVG::realignObject(NodeSVG & node, const CoordSpan<AlignBase::Axis::VERT> & span);
184
185
186
188
189public:
190
191 // Leading path, maybe partial, to be pruned
192 const std::string dir;
193
194 // String starting the modified path, for example "file://"
195 const std::string prefix;
196
197 inline
198 RelativePathSetterSVG(const drain::FilePath & filepath, const std::string & prefix = "") :
199 dir(filepath.dir.empty() ? "" : filepath.dir.str()+'/'),
200 prefix(prefix) {
201 }
202
203 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override;
204
205
206};
207
208
213
214public:
215
216 static
217 const std::string LOCAL;
218
219 static
220 const std::string SHARED;
221
222 /*
223 enum MetaDataType {
224 LOCAL,
225 SHARED
226 };
227 */
228
229 inline
230 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override {
231 // always continue
232 return 0;
233 }
234
235 int visitPostfix(TreeSVG & tree, const TreeSVG::path_t & path) override;
236
237 // Also
238 //GraphicsContext::TitleFlagger titles;
239
240protected:
241
242 typedef std::map<std::string, unsigned short> variableStat_t;
243
244};
245
246// DRAIN_ENUM_DICT(MetaDataCollectorSVG::MetaDataType);
247
266} // image::
267
268} // drain::
269
270
271
272
273#endif // TREESVG_H_
274
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 TreeSVG.h:91
Direction
Direction for "Stacked", horziontally or vertically sequentially aligned layout.
Definition LayoutSVG.h:64
Definition TreeUtilsSVG.h:212
int visitPostfix(TreeSVG &tree, const TreeSVG::path_t &path) override
Iterate children and their attributes: check which attributes (key and value) are shared by all the c...
Definition TreeUtilsSVG.cpp:934
Definition TreeSVG.h:129
const BBoxSVG & getBoundingBox() const
Get position (x,y), width and height of an object.
Definition TreeSVG.h:232
Definition TreeUtilsSVG.h:187
Definition DataSelector.cpp:1277
SVG classes marking requests of relative horizontal and vertical alignment.
Definition TreeUtilsSVG.h:80
Definition TreeUtilsSVG.h:115
static void superAlign(TreeSVG &node)
Definition TreeUtilsSVG.cpp:470
static void adjustLocation(TreeSVG &group, NodeSVG &node, CoordSpan< AX > anchorSpan)
Definition TreeUtilsSVG.cpp:389
static void detectBox(TreeSVG &group, bool debug=false)
Compute the bounding box recursively in objects of type IMAGE, RECT, POLYGON and G (group).
Definition TreeUtilsSVG.cpp:63
static void setStackLayout(NodeSVG &node, AlignBase::Axis orientation, LayoutSVG::Direction direction)
Sets alignment applying stack layout in a single node.
Definition TreeUtilsSVG.cpp:246
static void addStackLayout(TreeSVG &object, AlignBase::Axis orientation=AlignBase::Axis::HORZ, LayoutSVG::Direction direction=LayoutSVG::Direction::INCR, unsigned short depth=0)
Set stack layout as a default in a subtree.
Definition TreeUtilsSVG.cpp:191