Loading...
Searching...
No Matches
graphics.h
1/*
2
3MIT License
4
5Copyright (c) 2017 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
33#ifndef RACK_GRAPHICS
34#define RACK_GRAPHICS
35
36
37//#include "resources-image.h"
38#include "resources.h"
39
40// Notice: role of graphics.cpp and fileio-svg.cpp is currently equivalent
41
42namespace rack {
43
44
45
47class RackSVG {
48
49
50public:
51
52 //typedef drain::StyleSelectorXML<NodeSVG> Select;
53
54 // Identifier for the anchor background
55 // static const std::string BACKGROUND_RECT; // = "mainRect";
56
57 enum ElemClass {
58 NONE = 0,
59 MAIN_TITLE = 1, // Main title in SVG image
60 GROUP_TITLE = 2, // Group title
61 IMAGE_TITLE = 4, // Image title: small text (time, location) in corners of radar images
62 // Topical
63 TIME = 8, // Date and time attributes
64 LOCATION = 16, // Place (coordinates, municipality)
65 GENERAL = 32, // Default type
66 ALL = (63),
67 // MAIN,
68 IMAGE_PANEL,
69 IMAGE_BORDER, // RECT surrounding the image
70 BACKGROUND_RECT, // invisible RECT used for aligning
71 SIDE_PANEL,
72 BORDER, // Overall image border (RECT, invisible by default)
73 // SHARED_METADATA, // Something that should not be repeated in panels.
74 // --- unused ? ---
75 // TITLE, // Default title
76 };
77
78
80
83 static
84 drain::image::TreeSVG & getStyle(RackContext & ctx);
85
87 static
88 const std::string & guessFormat(const std::string & key);
89
91
95 static
96 drain::image::TreeSVG & getMainGroup(RackContext & ctx);
97
98 static
99 drain::image::TreeSVG & getCurrentAlignedGroup(RackContext & ctx);
100
101 static
102 drain::image::TreeSVG & getImagePanelGroup(RackContext & ctx, const drain::FilePath & filepath);
103
104 static
105 drain::image::TreeSVG & getImagePanelGroup(RackContext & ctx);
106
107
108 static
109 //void applyAlignment(RackContext & ctx, drain::image::TreeSVG & group);
111
112 static
113 bool applyInclusion(RackContext & cxt, const drain::FilePath & filepath); // , IncludePolicy fileFormat);
114
115 static
116 // drain::image::TreeSVG &
117 void addImage(RackContext & ctx, const drain::image::Image & src, const drain::FilePath & filepath);
118
120 static
121 // drain::image::TreeSVG &
122 void addImage(RackContext & ctx, const drain::image::TreeSVG & svg, const drain::FilePath & filepath);
123
125
128 static
129 // drain::image::TreeSVG &
130 void addImage(RackContext & ctx, const drain::Frame2D<drain::image::svg::coord_t> & frame, const drain::FilePath & filepath, const std::string & styleClass = "");
131
132
134
137 static
138 drain::image::TreeSVG & addTitleBox(const ConfSVG & conf, drain::image::TreeSVG & object, RackSVG::ElemClass elemClass);
139
140 // TODO: title area "filling order", by group class.
142
143 static
144 drain::image::TreeSVG & appendTitleElements(const ConfSVG &conf, drain::image::TreeSVG &group, const std::string &anchor, RackSVG::ElemClass elemClass);
145
146 static inline
147 drain::image::TreeSVG & appendTitleElements(const ConfSVG &conf, drain::image::TreeSVG &group, const char * anchor, RackSVG::ElemClass elemClass){
148 return appendTitleElements(conf, group, std::string(anchor), elemClass);
149 }
150
151 template <class T>
152 static inline
153 drain::image::TreeSVG & appendTitleElements(const ConfSVG &conf, drain::image::TreeSVG &group, const T & anchorId, RackSVG::ElemClass elemClass){
154 //const drain::StringWrapper<T> anchor(anchorId);
155 const drain::EnumWrapper<T> anchor(anchorId);
156 // const std::string & s = anchor;
157 return appendTitleElements(conf, group, (const std::string &)anchor, elemClass);
158 }
159
160
162 static
163 drain::image::TreeSVG & addRectangleGroup(RackContext & ctx, const drain::Frame2D<double> & frame = {200,200});
164
165
167
170 static
171 drain::image::TreeSVG & addImageBorder(drain::image::TreeSVG & imagePanel); // , const drain::Frame2D<double> & frame = {200,200});
172
173
174protected:
175
176
177};
178
179} // rack
180
181
182
183namespace drain {
184
185DRAIN_ENUM_DICT(rack::RackSVG::ElemClass);
186DRAIN_ENUM_OSTREAM(rack::RackSVG::ElemClass);
187
188template <> // for T (Tree class)
189template <> // for K (path elem arg)
190bool image::TreeSVG::hasChild(const rack::RackSVG::ElemClass & key) const ;
191
193template <> // for T (Tree class)
194template <> // for K (path elem arg)
195const image::TreeSVG & image::TreeSVG::operator[](const rack::RackSVG::ElemClass & value) const;
196
197
198template <> // for T (Tree class)
199template <> // for K (path elem arg)
200image::TreeSVG & image::TreeSVG::operator[](const rack::RackSVG::ElemClass & key);
201
202//
203/*
204template <> // for T (Tree class)
205template <> // for K (path elem arg)
206image::TreeSVG & image::TreeSVG::operator[](const rack::GraphicsContext::ElemClass &x);
207*/
208
210
218//template <>
219//const drain::EnumDict<RackSVG::TitleClass>::dict_t drain::EnumDict<RackSVG::TitleClass>::dict;
220
221/*
222template <>
223const std::string std::static_cast<std::string>(const RackSVG::ElemClass & e){
224 return drain::EnumDict<RackSVG::ElemClass>::dict.getKey(e);
225}
226*/
227
228}
229
230
231namespace rack {
232
233
234
235
237
242class TitleCreatorSVG : public drain::TreeVisitor<TreeSVG> {
243
244public:
245
246
247 inline
248 TitleCreatorSVG(const ConfSVG & svgConf) : svgConf(svgConf) {
249 //titles.set(0xff);
250 /*
251 if (!svgConf.mainTitle.empty()){
252 titles.set(PanelConfSVG::ElemClass::MAIN_TITLE);
253 }
254
255 if (!svgConf.groupTitleSyntax.empty()){
256 titles.set(PanelConfSVG::ElemClass::GROUP_TITLE);
257 }
258
259 titles.set(PanelConfSVG::ElemClass::IMAGE_TITLE);
260 */
261 /*
262 if (!svgConf.groupNameSyntax.empty()){
263 titles.set(RackSVG::ElemClass::GROUP_TITLE);
264 }
265 */
266
267 };
268
271 int visitPostfix(TreeSVG &root, const TreeSVG::path_t &path) override;
272
276 //static
277 void formatTitle(TreeSVG & group, const NodeSVG::map_t & attributes) const;
278
279 const ConfSVG & svgConf;
280
281 // Conf
282 // int mainHeaderHeight;
283
284protected:
285 // RackSVG::TitleFlagger::ivalue_t titles;
286
287 // Conf
288 // RackSVG::TitleFlagger titles;
289
290
291};
292
293
294} // rack::
295
296
297#endif
Definition EnumUtils.h:185
Extracts and stores directory path, base filename and extension.
Definition FilePath.h:58
Something that has width and height.
Definition Frame.h:55
Default implementation of a tree visitor (concept) compatible TreeUtils::traverser()
Definition TreeUtils.h:270
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition Image.h:193
Definition TreeSVG.h:178
Resources provided separately for each thread.
Definition resources.h:77
SVG support for creating aligned image panels.
Definition graphics.h:47
static drain::image::TreeSVG & addTitleBox(const ConfSVG &conf, drain::image::TreeSVG &object, RackSVG::ElemClass elemClass)
Create a title from background rectangle and TEXT elements (MAINTITLE, LOCATION, TIME,...
Definition graphics.cpp:683
static drain::image::TreeSVG & appendTitleElements(const ConfSVG &conf, drain::image::TreeSVG &group, const std::string &anchor, RackSVG::ElemClass elemClass)
Add title elements in given group, to "reserve slots" for actual text content to be added later.
Definition graphics.cpp:715
static drain::image::TreeSVG & getImagePanelGroup(RackContext &ctx, const drain::FilePath &filepath)
For each image an own group is created (for clarity, to contain also title TEXT's etc)
Definition graphics.cpp:541
static drain::image::TreeSVG & getMainGroup(RackContext &ctx)
Top-level GROUP used by Rack. All the graphic elements will be created inside this element.
Definition graphics.cpp:408
static drain::image::TreeSVG & addImageBorder(drain::image::TreeSVG &imagePanel)
Add.
Definition graphics.cpp:672
static drain::image::TreeSVG & addRectangleGroup(RackContext &ctx, const drain::Frame2D< double > &frame={200, 200})
Add rectangle.
static const std::string & guessFormat(const std::string &key)
returns timeformat
Definition graphics.cpp:293
static void addImage(RackContext &ctx, const drain::image::Image &src, const drain::FilePath &filepath)
Add pixel image (PNG).
Definition graphics.cpp:575
static void consumeAlignRequest(RackContext &ctx, drain::image::NodeSVG &node)
Apply an alignment, to next object only.
Definition graphics.cpp:323
static drain::image::TreeSVG & getStyle(RackContext &ctx)
Some SVG style classes. Identifiers for IMAGE and RECT elements over which TEXT elements will be alig...
Definition graphics.cpp:137
Formats titles from metadata. Invoked by drain::TreeUtils::traverse()
Definition graphics.h:242
void formatTitle(TreeSVG &group, const NodeSVG::map_t &attributes) const
Definition graphics.cpp:810
Definition DataSelector.cpp:1277
Definition DataSelector.cpp:44
Definition TreeSVG.h:101
Definition resources-image.h:56