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
45#include "AlignAnchorSVG.h"
46#include "LayoutSVG.h"
47#include "TreeSVG.h"
48
49namespace drain {
50
51namespace image {
52
53
55
60//template <>
61// const drain::Enum<AlignSVG_FOO>::dict_t drain::Enum<AlignSVG_FOO>::dict;
62
63template <AlignBase::Axis AX>
64struct CoordSpan {
65
66 inline
67 CoordSpan(svg::coord_t pos = 0, svg::coord_t span = 0) : pos(pos), span(span) {
68 }
69
70 inline
71 CoordSpan(const CoordSpan & cspan) : pos(cspan.pos), span(cspan.span) {
72 }
73
74 // Starting coordinate (x or y).
75 svg::coord_t pos = 0; //BBoxSVG::undefined;
76
77 // Width or height
78 svg::coord_t span = 0; // BBoxSVG::undefined;
79
80 // ? void getTranslatedCoordSpan(const BBoxSVG & bbox);
81 void copyFrom(const NodeSVG & node);
82
83 void copyFrom(const BBoxSVG & bbox);
84
85 inline
86 bool isDefined(){
87 return ! (std::isnan(pos) || std::isnan(span));
88 }
89};
90
91// TODO: separate TreeLayoutUtilsSVG
93
94public:
95
96
98
103 static
104 void detectBox(TreeSVG & group, bool debug = false);
105
106 static inline
107 void getAdjustedBBox(const NodeSVG & node, BBoxSVG & bbox) { //, bool debug = false){
108 //detectBoxNEW(group, debug);
109 bbox = node.getBoundingBox();
110 if (node.typeIs(svg::TEXT)){
111 bbox.width = 0;
112 }
113 else {
114 bbox.x += node.transform.translate.x;
115 bbox.y += node.transform.translate.y;
116 }
117 }
118
119 template <AlignBase::Axis AX>
120 static
121 void adjustLocation(TreeSVG & group, NodeSVG & node, CoordSpan<AX> anchorSpan);
122
124
134 static
135 void addStackLayout(TreeSVG & object, AlignBase::Axis orientation = AlignBase::Axis::HORZ, LayoutSVG::Direction direction = LayoutSVG::Direction::INCR, unsigned short depth=0);
136
138
143 static
144 void setStackLayout(NodeSVG & node, AlignBase::Axis orientation, LayoutSVG::Direction direction);
145
146 static
147 void superAlign(TreeSVG & node);
148
149
150 // Why templated, and not two separate?
151 template <AlignBase::Axis AX>
152 static
153 void realignObject(NodeSVG & node, const CoordSpan<AX> & span);
154
155
156
157
158};
159
160template <>
161void TreeLayoutSVG::realignObject(NodeSVG & node, const CoordSpan<AlignBase::Axis::HORZ> & span);
162
163template <>
164void TreeLayoutSVG::realignObject(NodeSVG & node, const CoordSpan<AlignBase::Axis::VERT> & span);
165
166
167
168
169} // image::
170
171// This is perhaps not used. At least make not much sense
172// Anchor elems are relational (elem-to-elem), hence not general keys for SVG elems.
173template <> // for T (Tree class)
174template <> // for K (path elem arg)
175inline
176const image::TreeSVG::key_t & image::TreeSVG::getKey(const image::AnchorElem::Anchor & type){
178}
179
180template <> // for T (Tree class)
181template <> // for K (path elem arg)
182inline
183const image::TreeSVG::key_t & image::TreeSVG::getKey(const image::AnchorElem & elem){
184 return image::TreeSVG::getKey(elem.str());
185}
186
187} // drain::
188
189
190
191
192#endif // TREESVG_H_
193
Definition TreeSVG.h:144
Direction
Direction for "Stacked", horziontally or vertically sequentially aligned layout.
Definition LayoutSVG.h:64
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:64
Definition TreeLayoutSVG.h:92
static void superAlign(TreeSVG &node)
Definition TreeLayoutSVG.cpp:469
static void adjustLocation(TreeSVG &group, NodeSVG &node, CoordSpan< AX > anchorSpan)
Definition TreeLayoutSVG.cpp:378
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:46
static void setStackLayout(NodeSVG &node, AlignBase::Axis orientation, LayoutSVG::Direction direction)
Sets alignment applying stack layout in a single node.
Definition TreeLayoutSVG.cpp:231
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:172