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
46#include "TreeSVG.h"
47#include "CoordsSVG.h"
48#include "AlignAnchorSVG.h"
49#include "LayoutSVG.h"
50
51namespace drain {
52
53namespace image {
54
55
56
57// TODO: separate TreeLayoutUtilsSVG
59
60public:
61
62
64
69 static
70 void detectBox(TreeSVG & group, bool debug = false);
71
72 static inline
73 void getAdjustedBBox(const NodeSVG & node, BBoxSVG & bbox) { //, bool debug = false){
74 //detectBoxNEW(group, debug);
75 bbox = node.getBoundingBox();
76 if (node.typeIs(svg::TEXT)){
77 bbox.width = 0;
78 }
79 else {
80 bbox.x += node.transform.translate.x;
81 bbox.y += node.transform.translate.y;
82 }
83 }
84
85 template <AlignBase::Axis AX>
86 static
87 void adjustLocation(TreeSVG & group, NodeSVG & node, CoordSpan<AX> anchorSpan);
88
90
100 static
101 //void addStackLayout(TreeSVG & object, AlignBase::Axis orientation = AlignBase::Axis::HORZ, LayoutSVG::Direction direction = LayoutSVG::Direction::INCR, unsigned short depth=0);
102 void addStackLayout(TreeSVG & object,
103 AlignBase::Axis orientation = AlignBase::Axis::HORZ,
104 LayoutSVG::DirectionHorz directionHorz = LayoutSVG::DirectionHorz::RIGHT,
105 LayoutSVG::DirectionVert directionVert = LayoutSVG::DirectionVert::DOWN,
106 unsigned short depth=0);
107
109
114 static
115 void setStackLayout(NodeSVG & node, AlignBase::Axis orientation, LayoutSVG::DirectionHorz dirHorz, LayoutSVG::DirectionVert dirVert);
116 // void setStackLayout(NodeSVG & node, AlignBase::Axis orientation, LayoutSVG::Direction direction);
117
118 static
119 void superAlign(TreeSVG & node);
120
121
122 // Why templated, and not two separate?
123 template <AlignBase::Axis AX>
124 static
125 void realignObject(NodeSVG & node, const CoordSpan<AX> & span);
126
127
128
129
130};
131
132template <>
133void TreeLayoutSVG::realignObject(NodeSVG & node, const CoordSpan<AlignBase::Axis::HORZ> & span);
134
135template <>
136void TreeLayoutSVG::realignObject(NodeSVG & node, const CoordSpan<AlignBase::Axis::VERT> & span);
137
138
139
140
141} // image::
142
143// This is perhaps not used. At least make not much sense
144// Anchor elems are relational (elem-to-elem), hence not general keys for SVG elems.
145template <> // for T (Tree class)
146template <> // for K (path elem arg)
147inline
148const image::TreeSVG::key_t & image::TreeSVG::getKey(const image::AnchorElem::Anchor & type){
150}
151
152template <> // for T (Tree class)
153template <> // for K (path elem arg)
154inline
155const image::TreeSVG::key_t & image::TreeSVG::getKey(const image::AnchorElem & elem){
156 return image::TreeSVG::getKey(elem.str());
157}
158
159} // drain::
160
161
162
163
164#endif // TREESVG_H_
165
bool typeIs(const T2 &arg, const T3... args) const
Return true, if type is any of the arguments.
Definition XML.h:230
Definition SVG.h:91
Definition TreeSVG.h:135
const BBoxSVG & getBoundingBox() const
Set attribute value, handling units in string arguments, like in "50%" or "640px".
Definition TreeSVG.h:228
Definition Data.h:1473
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
Definition CoordsSVG.h:92
Definition TreeLayoutSVG.h:58
static void superAlign(TreeSVG &node)
Definition TreeLayoutSVG.cpp:379
static void addStackLayout(TreeSVG &object, AlignBase::Axis orientation=AlignBase::Axis::HORZ, LayoutSVG::DirectionHorz directionHorz=LayoutSVG::DirectionHorz::RIGHT, LayoutSVG::DirectionVert directionVert=LayoutSVG::DirectionVert::DOWN, unsigned short depth=0)
Set stack layout as a default in a subtree.
Definition TreeLayoutSVG.cpp:156
static void setStackLayout(NodeSVG &node, AlignBase::Axis orientation, LayoutSVG::DirectionHorz dirHorz, LayoutSVG::DirectionVert dirVert)
Sets alignment applying stack layout in a single node.
Definition TreeLayoutSVG.cpp:209
static void adjustLocation(TreeSVG &group, NodeSVG &node, CoordSpan< AX > anchorSpan)
Definition TreeLayoutSVG.cpp:293
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:44