TreeUtilsSVG.h
1 /*
2 
3 MIT License
4 
5 Copyright (c) 2023 FMI Open Development / Markus Peura, first.last@fmi.fi
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 SOFTWARE.
24 
25 */
26 /*
27 Part of Rack development has been done in the BALTRAD projects part-financed
28 by the European Union (European Regional Development Fund and European
29 Neighbourhood 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/util/Frame.h>
44 #include <drain/util/Flags.h>
45 #include <drain/util/Rectangle.h>
46 #include "TreeSVG.h"
47 
48 namespace drain {
49 
50 namespace image {
51 
52 class FontSizes : public drain::UniTuple<double,4> {
53 
54 
55 public:
56 
58 
59  double & titles;
60  double & header;
61  double & leftHeader;
62  double & rightHeader;
63 
64  inline
65  FontSizes() : base_t(12,10,8,6), titles(next()), header(next()), leftHeader(next()), rightHeader(next()) {
66  }
67 
68  inline
69  FontSizes(const FontSizes & fs) : base_t(fs), titles(next()), header(next()), leftHeader(next()), rightHeader(next()) {
70  }
71 
72 };
73 
74 struct PanelConfSVG {
75 
76  enum Orientation {UNDEFINED_ORIENTATION=0, HORZ, VERT};
78  OrientationFlagger orientation = HORZ;
79 
80  enum Direction {UNDEFINED_DIRECTION=0, INCR, DECR};
82  DirectionFlagger direction = INCR;
83 
84  enum Legend {NO_LEGEND=0, LEFT=1, RIGHT=2, EMBED=4};
86  //LegendFlagger legend = LEFT | EMBED;
87  LegendFlagger legend; // (PanelConfSVG::Legend::LEFT, PanelConfSVG::Legend::EMBED);
88 
90  // Current
91  std::string groupName;
92  int maxPerGroup = 10;
93  bool absolutePaths = false;
94 
95  // Currently, applications are recommended to handle "false" and "none". Or "auto"?
96  std::string title;
97  FontSizes fontSize;
98 
99  inline
100  PanelConfSVG() : orientation(HORZ), direction(INCR), legend(LEFT, EMBED), maxPerGroup(10), absolutePaths(false){
101  }
102 
103  /*
104  inline
105  PanelConfSVG(const PanelConfSVG & c) : orientation(c.orientation), direction(c.direction), legend(LEFT, EMBED), maxPerGroup(10), absolutePaths(false){
106  }
107  */
108 
109 
110 };
111 
112 
113 struct TreeUtilsSVG {
114 
115 
116  static PanelConfSVG defaultConf;
117 
118  /*
119  enum Orientation {UNDEFINED_ORIENTATION=0, HORZ, VERT};
120  typedef drain::EnumFlagger<drain::SingleFlagger<Orientation> > OrientationFlagger;
121  static OrientationFlagger defaultOrientation;
122 
123  enum Direction {UNDEFINED_DIRECTION=0, INCR, DECR};
124  typedef drain::EnumFlagger<drain::SingleFlagger<Direction> > DirectionFlagger;
125  static DirectionFlagger defaultDirection;
126 
128  static std::string defaultGroupName;
129 
130  static std::string defaultTitle;
131  */
132 
134  static
135  bool getRect(TreeSVG & group, drain::Box<double> & rect);
136 
138 
142  static
143  void getBoundingFrame(TreeSVG & group, drain::Frame2D<int> & frame, PanelConfSVG::Orientation orientation=PanelConfSVG::UNDEFINED_ORIENTATION);
144 
146  static
147  void alignSequence(TreeSVG & group, const drain::Frame2D<int> & frame, const drain::Point2D<int> & start={0,0},
148  PanelConfSVG::Orientation orientation=PanelConfSVG::UNDEFINED_ORIENTATION, PanelConfSVG::Direction direction=PanelConfSVG::UNDEFINED_DIRECTION);
149 
151  static
152  void alignText(TreeSVG & group);
153 
154 
155 };
156 
157 
158 
177 } // image::
178 
179 template <>
181 
182 template <>
184 
185 } // drain::
186 
187 
188 
189 
190 #endif // TREESVG_H_
191 
Flagger accepting values of enum type E.
Definition: Flags.h:763
Tuple of N elements of type T.
Definition: UniTuple.h:65
Definition: TreeUtilsSVG.h:52
Definition: DataSelector.cpp:1277
Something that has coordinates (x,y) and dimensions (width, height).
Definition: Frame.h:139
Definition: Flags.h:744
Definition: TreeUtilsSVG.h:74
std::string groupName
SVG file may contain several "modules", for example rows or columns of IMAGE:s. This is the name of t...
Definition: TreeUtilsSVG.h:91
Definition: TreeUtilsSVG.h:113
static void getBoundingFrame(TreeSVG &group, drain::Frame2D< int > &frame, PanelConfSVG::Orientation orientation=PanelConfSVG::UNDEFINED_ORIENTATION)
Computes the width and height for a bounding box IMAGE and RECT elements.
Definition: TreeUtilsSVG.cpp:77
static bool getRect(TreeSVG &group, drain::Box< double > &rect)
Returns the bounding box defined here as (x,y,width,height) of a single element.
Definition: TreeUtilsSVG.cpp:67
static void alignSequence(TreeSVG &group, const drain::Frame2D< int > &frame, const drain::Point2D< int > &start={0, 0}, PanelConfSVG::Orientation orientation=PanelConfSVG::UNDEFINED_ORIENTATION, PanelConfSVG::Direction direction=PanelConfSVG::UNDEFINED_DIRECTION)
Stack IMAGE and RECT elements within a frame (width x height) to a row or column.
Definition: TreeUtilsSVG.cpp:143
static void alignText(TreeSVG &group)
Moves TEXT elems to desired positions, esp corners (LEFT|RIGHT), (TOP|BOTTOM)
Definition: TreeUtilsSVG.cpp:277