Loading...
Searching...
No Matches
TreeLayoutSVG.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_LAYOUT_SVG
39#define DRAIN_TREE_LAYOUT_SVG
40
41//
42
43#include <drain/Enum.h>
44#include <drain/util/Frame.h>
45#include <drain/util/Rectangle.h>
46
47#include "AlignAnchorSVG.h"
48#include "LayoutSVG.h"
49#include "TreeSVG.h"
50
51namespace drain {
52
53namespace image {
54
55
57
62//template <>
63// const drain::Enum<AlignSVG_FOO>::dict_t drain::Enum<AlignSVG_FOO>::dict;
64
65template <AlignBase::Axis AX>
66struct CoordSpan {
67
68 inline
69 CoordSpan(svg::coord_t pos = 0, svg::coord_t span = 0) : pos(pos), span(span) {
70 }
71
72 inline
73 CoordSpan(const CoordSpan & cspan) : pos(cspan.pos), span(cspan.span) {
74 }
75
76 // Starting coordinate (x or y).
77 svg::coord_t pos = 0; //BBoxSVG::undefined;
78
79 // Width or height
80 svg::coord_t span = 0; // BBoxSVG::undefined;
81
82 // ? void getTranslatedCoordSpan(const BBoxSVG & bbox);
83 void copyFrom(const NodeSVG & node);
84
85 void copyFrom(const BBoxSVG & bbox);
86
87 inline
88 bool isDefined(){
89 return ! (std::isnan(pos) || std::isnan(span));
90 }
91};
92
93// TODO: separate TreeLayoutUtilsSVG
95
96public:
97
98
100
105 static
106 void detectBox(TreeSVG & group, bool debug = false);
107
108 static inline
109 void getAdjustedBBox(const NodeSVG & node, BBoxSVG & bbox) { //, bool debug = false){
110 //detectBoxNEW(group, debug);
111 bbox = node.getBoundingBox();
112 if (node.typeIs(svg::TEXT)){
113 bbox.width = 0;
114 }
115 else {
116 bbox.x += node.transform.translate.x;
117 bbox.y += node.transform.translate.y;
118 }
119 }
120
121 template <AlignBase::Axis AX>
122 static
123 void adjustLocation(TreeSVG & group, NodeSVG & node, CoordSpan<AX> anchorSpan);
124
126
136 static
137 void addStackLayout(TreeSVG & object, AlignBase::Axis orientation = AlignBase::Axis::HORZ, LayoutSVG::Direction direction = LayoutSVG::Direction::INCR, unsigned short depth=0);
138
140
145 static
146 void setStackLayout(NodeSVG & node, AlignBase::Axis orientation, LayoutSVG::Direction direction);
147
148 static
149 void superAlign(TreeSVG & node);
150
151
152 // Why templated, and not two separate?
153 template <AlignBase::Axis AX>
154 static
155 void realignObject(NodeSVG & node, const CoordSpan<AX> & span);
156
157
158
159
160};
161
162template <>
163void TreeLayoutSVG::realignObject(NodeSVG & node, const CoordSpan<AlignBase::Axis::HORZ> & span);
164
165template <>
166void TreeLayoutSVG::realignObject(NodeSVG & node, const CoordSpan<AlignBase::Axis::VERT> & span);
167
168
169
170
171} // image::
172
173// This is perhaps not used. At least make not much sense
174// Anchor elems are relational (elem-to-elem), hence not general keys for SVG elems.
175template <> // for T (Tree class)
176template <> // for K (path elem arg)
177inline
178const image::TreeSVG::key_t & image::TreeSVG::getKey(const image::AnchorElem::Anchor & type){
180}
181
182template <> // for T (Tree class)
183template <> // for K (path elem arg)
184inline
185const image::TreeSVG::key_t & image::TreeSVG::getKey(const image::AnchorElem & elem){
186 return image::TreeSVG::getKey(elem.str());
187}
188
189} // drain::
190
191
192
193
194#endif // TREESVG_H_
195
Definition TreeSVG.h:144
Direction
Direction for "Stacked", horziontally or vertically sequentially aligned layout.
Definition LayoutSVG.h:65
Definition TreeSVG.h:182
const BBoxSVG & getBoundingBox() const
Get position (x,y), width and height of an object.
Definition TreeSVG.h:291
Definition DataSelector.cpp:1277
A container for a static dictionary of enumeration values.
Definition Enum.h:51
static const std::string & getKey(const std::string &s, bool lenient=true)
Convenience for object.set(...) like commands.
Definition Enum.h:144
SVG classes marking requests of relative horizontal and vertical alignment.
Definition TreeLayoutSVG.h:66
Definition TreeLayoutSVG.h:94
static void superAlign(TreeSVG &node)
Definition TreeLayoutSVG.cpp:472
static void adjustLocation(TreeSVG &group, NodeSVG &node, CoordSpan< AX > anchorSpan)
Definition TreeLayoutSVG.cpp:381
static void detectBox(TreeSVG &group, bool debug=false)
Compute the bounding box recursively in objects of type IMAGE, RECT, POLYGON and G (group).
Definition TreeLayoutSVG.cpp:49
static void setStackLayout(NodeSVG &node, AlignBase::Axis orientation, LayoutSVG::Direction direction)
Sets alignment applying stack layout in a single node.
Definition TreeLayoutSVG.cpp:234
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 TreeLayoutSVG.cpp:175