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// Vector graphics (mainly SVG) – EXPERIMENTAL
33
34#ifndef RACK_GRAPHICS
35#define RACK_GRAPHICS
36
37// #include <drain/prog/CommandInstaller.h>
38
39#include "resources-image.h"
40#include "resources.h"
41
42// Notice: role of graphics.cpp and fileio-svg.cpp is currently equivalent
43
44namespace rack {
45
46
47
49class RackSVG { // : public drain::BasicCommand {
50
51
52public:
53
54 //typedef drain::StyleSelectorXML<NodeSVG> Select;
55
56 // Identifier for the anchor background
57 static const std::string BACKGROUND_RECT; // = "mainRect";
58
59 // static const std::string TECH_PANEL;
61 /*
62 enum ElemClass {
63 NONE = 0,
64 MAIN_TITLE = 1, // Main title in SVG image
65 GROUP_TITLE = 2,
66 IMAGE_TITLE = 4, // Small title in a corner of radar image (time, location)
67 TIME = 8, // Date and time attributes
68 LOCATION = 16, // Place (coordinates, municipality)
69 GENERAL = 32, // Default type
70 ALL = (63),
71 MAIN,
72 IMAGE_PANEL,
73 IMAGE_BORDER, // RECT surrounding the image
74 SHARED_METADATA, // Something that should not be repeated in panels.
75 // --- unused ? ---
76 TITLE, // Default title
77 };
78 */
79
80 // Selected CSS classes corresponding to above element classes
81 /*
82 static const drain::ClassSelectorXML clsTITLE;// ('.', RackSVG::TITLE);
83 static const drain::ClassSelectorXML clsIMAGE_TITLE;// ('.', RackSVG::IMAGE_TITLE);
84 static const drain::ClassSelectorXML clsGROUP_TITLE;// ('.', RackSVG::GROUP_TITLE);
85 static const drain::ClassSelectorXML clsMAIN_TITLE;// ('.', RackSVG::MAIN_TITLE);
86 static const drain::ClassSelectorXML clsTIME;// ('.', RackSVG::TIME);
87 static const drain::ClassSelectorXML clsLOCATION;// ('.', RackSVG::LOCATION);
88 static const drain::ClassSelectorXML clsIMAGE_BORDER;// ('.', RackSVG::IMAGE_BORDER);
89 */
90
91 // typedef drain::EnumFlagger<drain::MultiFlagger<ElemClass> > TitleFlagger;
92 //TitleFlagger svgTitles = ElemClass::NONE;
93
95
98 static
99 drain::image::TreeSVG & getStyle(RackContext & ctx);
100
102 static
103 const std::string & guessFormat(const std::string & key);
104
106
110 static
111 drain::image::TreeSVG & getMainGroup(RackContext & ctx);
112
113 //drain::image::TreeSVG & getCurrentAlignedGroup();
114
115 // virtual
116 // std::string getFormattedStatus(RackContext & ctx, const std::string & format) const = 0;
117
118 static
119 drain::image::TreeSVG & getCurrentAlignedGroup(RackContext & ctx);
120
121 static
122 drain::image::TreeSVG & getImagePanelGroup(RackContext & ctx, const drain::FilePath & filepath);
123
124
125 static
126 void applyAlignment(RackContext & ctx, drain::image::TreeSVG & group);
127
128 static
129 bool applyInclusion(RackContext & cxt, const drain::FilePath & filepath); // , SvgInclude fileFormat);
130
131 static
132 // drain::image::TreeSVG &
133 void addImage(RackContext & ctx, const drain::image::Image & src, const drain::FilePath & filepath);
134
136 static
137 // drain::image::TreeSVG &
138 void addImage(RackContext & ctx, const drain::image::TreeSVG & svg, const drain::FilePath & filepath);
139
141
144 static
145 // drain::image::TreeSVG &
146 void addImage(RackContext & ctx, const drain::Frame2D<drain::image::svg::coord_t> & frame, const drain::FilePath & filepath, const std::string & styleClass = "");
147
148
150 static
151 void addTitleBox(const PanelConfSVG & conf, drain::image::TreeSVG & object, PanelConfSVG::ElemClass elemClass);
152
153 static
154 void addTitles(const PanelConfSVG & conf, drain::image::TreeSVG & object, const std::string & anchor, PanelConfSVG::ElemClass elemClass);
155
157 static
158 drain::image::TreeSVG & addRectangleGroup(RackContext & ctx, const drain::Frame2D<double> & frame = {200,200});
159
160
162
165 static
166 drain::image::TreeSVG & addImageBorder(drain::image::TreeSVG & imagePanel); // , const drain::Frame2D<double> & frame = {200,200});
167
168
169 // static
170 // void generateTitles(RackContext & ctx);
171
173 // Re-align elements etc
174 static
175 void completeSVG(RackContext & ctx); // , const drain::FilePath & filepath);
176
178 // static
179 // const std::string & getTextClass(const std::string & key, const std::string & defaultClass = "");
180
181protected:
182
183 // Under construction...
184 // static
185 // void createTitleBox(TreeSVG & tree);
186
187};
188
189//DRAIN_ENUM_OSTREAM(RackSVG::ElemClass);
190
191}
192
193namespace drain {
194
195//
196/*
197template <> // for T (Tree class)
198template <> // for K (path elem arg)
199image::TreeSVG & image::TreeSVG::operator[](const rack::GraphicsContext::ElemClass &x);
200*/
201
203
211//template <>
212//const drain::EnumDict<RackSVG::TitleClass>::dict_t drain::EnumDict<RackSVG::TitleClass>::dict;
213
214/*
215template <>
216const std::string std::static_cast<std::string>(const RackSVG::ElemClass & e){
217 return drain::EnumDict<RackSVG::ElemClass>::dict.getKey(e);
218}
219*/
220
221}
222
223
224namespace rack {
225
226
231
232public:
233
234 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override;
235
236 int visitPostfix(TreeSVG & tree, const TreeSVG::path_t & path) override;
237
238protected:
239
240 typedef std::map<std::string, unsigned short> variableStat_t;
241
242};
243
247class MetaDataPrunerSVG : public drain::TreeVisitor<TreeSVG> {
248
249public:
250
251 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override;
252
253 int visitPostfix(TreeSVG & tree, const TreeSVG::path_t & path) override;
254
255 // Also
256 //GraphicsContext::TitleFlagger titles;
257
258protected:
259
260 typedef std::map<std::string, unsigned short> variableStat_t;
261
262};
263
264
266
271class TitleCreatorSVG : public drain::TreeVisitor<TreeSVG> {
272
273public:
274
275
276 inline
277 TitleCreatorSVG(const PanelConfSVG & svgConf) : svgConf(svgConf) {
278 //titles.set(0xff);
279 /*
280 if (!svgConf.mainTitle.empty()){
281 titles.set(PanelConfSVG::ElemClass::MAIN_TITLE);
282 }
283
284 if (!svgConf.groupTitleSyntax.empty()){
285 titles.set(PanelConfSVG::ElemClass::GROUP_TITLE);
286 }
287
288 titles.set(PanelConfSVG::ElemClass::IMAGE_TITLE);
289 */
290 /*
291 if (!svgConf.groupNameSyntax.empty()){
292 titles.set(RackSVG::ElemClass::GROUP_TITLE);
293 }
294 */
295
296 };
297
298 int visitPostfix(TreeSVG & tree, const TreeSVG::path_t & odimPath) override;
299
300
304 static
305 void writeTitles(TreeSVG & group, const NodeSVG::map_t & attributes);
306
307 const PanelConfSVG & svgConf;
308
309 // Conf
310 // int mainHeaderHeight;
311
312protected:
313 // RackSVG::TitleFlagger::ivalue_t titles;
314
315 // Conf
316 // RackSVG::TitleFlagger titles;
317
318
319};
320
321
322} // rack::
323
324
325#endif
Extracts and stores directory path, base filename and extension.
Definition FilePath.h:58
Something that has width and height.
Definition Frame.h:53
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:184
Definition graphics.h:230
Definition graphics.h:247
int visitPostfix(TreeSVG &tree, const TreeSVG::path_t &path) override
Definition graphics.cpp:737
Resources provided separately for each thread.
Definition resources.h:67
SVG panel utils.
Definition graphics.h:49
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:360
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:206
static void completeSVG(RackContext &ctx)
Traverse groups, collecting info, recognizing common (shared) variables and pruning them recursively.
Definition graphics.cpp:671
static drain::image::TreeSVG & getCurrentAlignedGroup(RackContext &ctx)
Return current row or column of image panels.
Definition graphics.cpp:325
static const std::string BACKGROUND_RECT
Group identifiers for elements which be automatically aligned (stacked horizontally or vertically)
Definition graphics.h:57
static drain::image::TreeSVG & addImageBorder(drain::image::TreeSVG &imagePanel)
Add.
Definition graphics.cpp:491
static void addTitleBox(const PanelConfSVG &conf, drain::image::TreeSVG &object, PanelConfSVG::ElemClass elemClass)
Add TEXT elements: MAINTITLE, LOCATION, TIME, GENERAL.
Definition graphics.cpp:501
static void addTitles(const PanelConfSVG &conf, drain::image::TreeSVG &object, const std::string &anchor, PanelConfSVG::ElemClass elemClass)
Definition graphics.cpp:539
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:183
static void addImage(RackContext &ctx, const drain::image::Image &src, const drain::FilePath &filepath)
Add pixel image (PNG)
Definition graphics.cpp:401
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:85
"Collects" titles from metadata. Invoked by drain::TreeUtils::traverse()
Definition graphics.h:271
static void writeTitles(TreeSVG &group, const NodeSVG::map_t &attributes)
Definition graphics.cpp:951
Definition DataSelector.cpp:1277
Definition DataSelector.cpp:44
Definition TreeSVG.h:56
Definition resources-image.h:86