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/util/EnumUtils.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::EnumDict<AlignSVG_FOO>::dict_t drain::EnumDict<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 bbox.x += node.transform.translate.x;
113 bbox.y += node.transform.translate.y;
114 }
115
116 template <AlignBase::Axis AX>
117 static
118 void adjustLocation(TreeSVG & group, NodeSVG & node, CoordSpan<AX> anchorSpan);
119
121
131 static
132 void addStackLayout(TreeSVG & object, AlignBase::Axis orientation = AlignBase::Axis::HORZ, LayoutSVG::Direction direction = LayoutSVG::Direction::INCR, unsigned short depth=0);
133
135
140 static
141 void setStackLayout(NodeSVG & node, AlignBase::Axis orientation, LayoutSVG::Direction direction);
142
143 static
144 void superAlign(TreeSVG & node);
145
146
147 // Why templated, and not two separate?
148 template <AlignBase::Axis AX>
149 static
150 void realignObject(NodeSVG & node, const CoordSpan<AX> & span);
151
152
153
154
155};
156
157template <>
158void TreeLayoutSVG::realignObject(NodeSVG & node, const CoordSpan<AlignBase::Axis::HORZ> & span);
159
160template <>
161void TreeLayoutSVG::realignObject(NodeSVG & node, const CoordSpan<AlignBase::Axis::VERT> & span);
162
163
164
165
166} // image::
167
168} // drain::
169
170
171
172
173#endif // TREESVG_H_
174
Definition TreeSVG.h:140
Direction
Direction for "Stacked", horziontally or vertically sequentially aligned layout.
Definition LayoutSVG.h:64
Definition TreeSVG.h:178
const BBoxSVG & getBoundingBox() const
Get position (x,y), width and height of an object.
Definition TreeSVG.h:285
Definition DataSelector.cpp:1277
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:460
static void adjustLocation(TreeSVG &group, NodeSVG &node, CoordSpan< AX > anchorSpan)
Definition TreeLayoutSVG.cpp:379
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:236
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:177