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#ifndef RACK_GRAPHICS_SVG
33#define RACK_GRAPHICS_SVG
34
35//#include <string>
36//#include <drain/prog/CommandBank.h>
37#include <drain/prog/CommandInstaller.h>
38
39//#include <drain/util/FileInfo.h>
40//#include "hi5/Hi5.h"
41//#include "resources.h"
42
43// Notice: role of graphics.cpp and fileio-svg.cpp is currently equivalent
44
45#include "resources.h"
46
47// Notice: role of graphics.cpp and fileio-svg.cpp is currently equivalent
48
49namespace rack {
50
51
52
54class RackSVG {
55
56
57public:
58
59 //typedef drain::StyleSelectorXML<NodeSVG> Select;
60
61 // Identifier for the anchor background
62 // static const std::string BACKGROUND_RECT; // = "mainRect";
63
64 enum ElemClass {
65 NONE = 0,
66 MAIN_TITLE = 1, // Main title in SVG image
67 GROUP_TITLE = 2, // Group title
68 IMAGE_TITLE = 4, // Image title: small text (time, location) in corners of radar images
69 // Topical
70 TIME = 8, // Date and time attributes
71 LOCATION = 16, // Place (coordinates, municipality)
72 GENERAL = 32, // Default type
73 ALL = (63),
74 // MAIN,
75 IMAGE_PANEL,
76 IMAGE_BORDER, // RECT surrounding the image
77 BACKGROUND_RECT, // invisible RECT used for aligning
78 SIDE_PANEL,
79 BORDER, // Overall image border (RECT, invisible by default)
80 // SHARED_METADATA, // Something that should not be repeated in panels.
81 // --- unused ? ---
82 // TITLE, // Default title
83 };
84
85
87
90 static
91 drain::image::TreeSVG & getStyle(RackContext & ctx);
92
94 static
95 const std::string & guessFormat(const std::string & key);
96
98
102 static
103 drain::image::TreeSVG & getMainGroup(RackContext & ctx);
104
105 static
106 drain::image::TreeSVG & getCurrentAlignedGroup(RackContext & ctx);
107
108 static
109 drain::image::TreeSVG & getImagePanelGroup(RackContext & ctx, const drain::FilePath & filepath);
110
111 static
112 drain::image::TreeSVG & getImagePanelGroup(RackContext & ctx);
113
114
118 static
119 drain::image::TreeSVG & getAdapterGroup(drain::image::TreeSVG & group);
120
121
122 static
123 //void applyAlignment(RackContext & ctx, drain::image::TreeSVG & group);
125
126 static
127 bool applyInclusion(RackContext & cxt, const drain::FilePath & filepath); // , IncludePolicy fileFormat);
128
129 static
130 // drain::image::TreeSVG &
131 void addImage(RackContext & ctx, const drain::image::Image & src, const drain::FilePath & filepath);
132
134 static
135 // drain::image::TreeSVG &
136 void addImage(RackContext & ctx, const drain::image::TreeSVG & svg, const drain::FilePath & filepath);
137
139
142 static
143 // drain::image::TreeSVG &
144 void addImage(RackContext & ctx, const drain::Frame2D<drain::image::svg::coord_t> & frame, const drain::FilePath & filepath, const std::string & styleClass = "");
145
146
148
151 static
152 drain::image::TreeSVG & addTitleBox(const ConfSVG & conf, drain::image::TreeSVG & object, RackSVG::ElemClass elemClass);
153
154 // TODO: title area "filling order", by group class.
156
157 static
158 drain::image::TreeSVG & appendTitleElements(const ConfSVG &conf, drain::image::TreeSVG &group, const std::string &anchor, RackSVG::ElemClass elemClass);
159
160 static inline
161 drain::image::TreeSVG & appendTitleElements(const ConfSVG &conf, drain::image::TreeSVG &group, const char * anchor, RackSVG::ElemClass elemClass){
162 return appendTitleElements(conf, group, std::string(anchor), elemClass);
163 }
164
165 template <class T>
166 static inline
167 drain::image::TreeSVG & appendTitleElements(const ConfSVG &conf, drain::image::TreeSVG &group, const T & anchorId, RackSVG::ElemClass elemClass){
168 //const drain::StringWrapper<T> anchor(anchorId);
169 const drain::EnumWrapper<T> anchor(anchorId);
170 // const std::string & s = anchor;
171 return appendTitleElements(conf, group, (const std::string &)anchor, elemClass);
172 }
173
174
176 static
177 drain::image::TreeSVG & addRectangleGroup(RackContext & ctx, const drain::Frame2D<double> & frame = {200,200});
178
179
181
184 static
185 drain::image::TreeSVG & addImageBorder(drain::image::TreeSVG & imagePanel); // , const drain::Frame2D<double> & frame = {200,200});
186
187
188protected:
189
190
191};
192
193} // rack
194
195
196
197namespace drain {
198
199DRAIN_ENUM_DICT(rack::RackSVG::ElemClass);
200DRAIN_ENUM_OSTREAM(rack::RackSVG::ElemClass);
201
202template <> // for T (Tree class)
203template <> // for K (path elem arg)
204bool image::TreeSVG::hasChild(const rack::RackSVG::ElemClass & key) const ;
205
207template <> // for T (Tree class)
208template <> // for K (path elem arg)
209const image::TreeSVG & image::TreeSVG::operator[](const rack::RackSVG::ElemClass & value) const;
210
211
212template <> // for T (Tree class)
213template <> // for K (path elem arg)
214image::TreeSVG & image::TreeSVG::operator[](const rack::RackSVG::ElemClass & key);
215
216//
217/*
218template <> // for T (Tree class)
219template <> // for K (path elem arg)
220image::TreeSVG & image::TreeSVG::operator[](const rack::GraphicsContext::ElemClass &x);
221*/
222
224
232//template <>
233//const drain::Enum<RackSVG::TitleClass>::dict_t drain::Enum<RackSVG::TitleClass>::dict;
234
235/*
236template <>
237const std::string std::static_cast<std::string>(const RackSVG::ElemClass & e){
238 return drain::Enum<RackSVG::ElemClass>::dict.getKey(e);
239}
240*/
241
242}
243
244
245
246namespace rack {
247
248
249/*
250
251Komentoja!
252
253 */
254
255// struct GraphicsSection;
257
258 inline GraphicsSection(): CommandSection("graphics"){
259 };
260
261};
262
263class GraphicsModule : public drain::CommandModule<'g',GraphicsSection> {
264public:
266};
267
268
270/*
271class CmdOutputPanel : public drain::BasicCommand {
272
273public:
274
275 inline
276 CmdOutputPanel() : drain::BasicCommand(__FUNCTION__, "Save SVG panel of latest images. See also: --image, --outputRawImages.") {
277 getParameters().link("filename", filename="");
278 getParameters().link("layout", layout, "basic");
279 };
280
281 inline
282 CmdOutputPanel(const CmdOutputPanel & cmd) : drain::BasicCommand(cmd) {
283 getParameters().copyStruct(cmd.getParameters(), cmd, *this);
284 }
285
286
287 void exec() const;
288
289
290 std::string layout;
291 std::string filename;
292
293 void appendImage(TreeSVG & group, const std::string & prefix, drain::VariableMap & vmap,
294 const drain::Point2D<double> & location, const drain::image::Image & image, drain::BBox & bbox) const;
295};
296*/
297
298
299} // rack::
300
301
302#endif
303
Combines command installation and sectioning.
Definition CommandInstaller.h:153
Definition CommandSections.h:54
Definition Enum.h:223
Extracts and stores directory path, base filename and extension.
Definition FilePath.h:58
Something that has width and height.
Definition Frame.h:55
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition Image.h:193
Definition TreeSVG.h:182
Definition graphics.h:263
Resources provided separately for each thread.
Definition resources.h:67
SVG support for creating aligned image panels.
Definition graphics.h:54
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:611
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:643
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:468
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:335
static drain::image::TreeSVG & addImageBorder(drain::image::TreeSVG &imagePanel)
Add.
Definition graphics.cpp:600
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:220
static drain::image::TreeSVG & getAdapterGroup(drain::image::TreeSVG &group)
Return current row or column of image panels.
Definition graphics.cpp:384
static void addImage(RackContext &ctx, const drain::image::Image &src, const drain::FilePath &filepath)
Add pixel image (PNG).
Definition graphics.cpp:502
static void consumeAlignRequest(RackContext &ctx, drain::image::NodeSVG &node)
Apply an alignment, to next object only.
Definition graphics.cpp:250
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:64
Definition DataSelector.cpp:1277
Definition DataSelector.cpp:44
Definition TreeSVG.h:104
Definition resources-image.h:56
Definition graphics.h:256