Loading...
Searching...
No Matches
graphics-panel.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_PANEL
34#define RACK_GRAPHICS_PANEL
35
36
37#include <drain/image/FilePng.h>
38#include <drain/image/TreeSVG.h>
39#include <drain/prog/Command.h>
40#include <drain/prog/CommandInstaller.h>
41#include <drain/prog/CommandBank.h>
42#include <drain/util/Output.h>
43#include <drain/image/TreeSVG.h>
44#include "data/SourceODIM.h" // for NOD
45
46#include "resources.h"
47//#include "fileio-svg.h"
48#include "graphics-radar.h"
49#include "graphics-panel.h"
50//#include "resources-image.h"
51
52
53
54
55
56
57namespace rack {
58
59using namespace drain::image;
60// Move to graphics.h ?
61
63
68class TitleCreatorSVG : public drain::TreeVisitor<TreeSVG> {
69
70public:
71
72
73 inline
74 TitleCreatorSVG(const ConfSVG & svgConf) : svgConf(svgConf) {
75 };
76
79 int visitPostfix(TreeSVG &root, const TreeSVG::path_t &path) override;
80
84 void formatTitle(TreeSVG & group, const NodeSVG::map_t & attributes) const;
85
86 const ConfSVG & svgConf;
87
88
89};
90
91
92// ....
93
95
96public:
97
98 CmdLayout() : drain::BasicCommand(__FUNCTION__, "Set main panel alignment"){
99
100 getParameters().link("orientation", orientation="HORZ",
101 drain::sprinter(drain::Enum<orientation_enum>::dict.getKeys(), {"|"}).str());
102 getParameters().link("directionVert", directionVert="DOWN",
103 drain::sprinter(drain::Enum<dir_vert_enum>::dict.getKeys(), {"|"}).str());
104 getParameters().link("directionHorz", directionHorz="RIGHT",
105 drain::sprinter(drain::Enum<dir_horz_enum>::dict.getKeys(), {"|"}).str());
106
107 }
108
110 getParameters().copyStruct(cmd.getParameters(), cmd, *this);
111 };
112
113
114 virtual
115 void exec() const override;
116
117protected:
118
119 typedef drain::image::AlignBase::Axis orientation_enum;
120 typedef drain::image::LayoutSVG::DirectionVert dir_vert_enum;
121 typedef drain::image::LayoutSVG::DirectionHorz dir_horz_enum;
122
123 //volatile
124 mutable
125 std::string orientation;
126
127 // volatile
128 mutable
129 std::string directionVert;
130
131 mutable
132 std::string directionHorz;
133
134
135};
136
146//class CmdAlign : public drain::SimpleCommand<std::string> {
148
149public:
150
151 /*
152 CmdAlign() : drain::SimpleCommand<std::string>(__FUNCTION__, "Alignment of the next element", "topology", "",
153 drain::sprinter(drain::Enum<AlignSVG::Topol>::dict.getKeys(), {"|"}).str() + ':' +
154 drain::sprinter(drain::Enum<AlignSVG::HorzAlign>::dict.getKeys(), {"|"}).str() + ',' +
155 drain::sprinter(drain::Enum<AlignSVG::Topol>::dict.getKeys(), {"|"}).str() + ':' +
156 drain::sprinter(drain::Enum<AlignSVG::VertAlign>::dict.getKeys(), {"|"}).str()
157 ){
158 //getParameters().link("", x, drain::StringBuilder<':'>());
159 }
160 */
161
162
163 CmdAlign() : drain::BasicCommand(__FUNCTION__, "Alignment of the next element"){
164
165 getParameters().link("position", position,
166 drain::sprinter(drain::Enum<MutualAlign::Topol>::dict.getKeys(), {"|"}).str() + ':' +
167 drain::sprinter(drain::Enum<AlignSVG::HorzAlign>::dict.getKeys(), {"|"}).str() + ',' +
168 drain::sprinter(drain::Enum<MutualAlign::Topol>::dict.getKeys(), {"|"}).str() + ':' +
169 drain::sprinter(drain::Enum<AlignSVG::VertAlign>::dict.getKeys(), {"|"}).str()
170 ).setSeparator(':');
171
172 getParameters().link("anchor", anchor.str(),
173 std::string("<name>|<empty>") + drain::sprinter(drain::Enum<drain::image::AnchorElem::Anchor>::dict.getKeys(), {"|"}).str()
174 );
175 getParameters().link("anchorHorz", anchorHorz.str(),
176 "..."
177 );
178 getParameters().link("anchorVert", anchorVert.str(),
179 "..."
180 );
181 }
182
184 getParameters().copyStruct(cmd.getParameters(), cmd, *this, drain::ReferenceMap::LINK);
185 };
186
187
188 virtual
189 void exec() const override;
190
191protected:
192
193 std::string position;
194
195 mutable
197
198 mutable
199 drain::image::AnchorElem anchorHorz;
200
201 mutable
202 drain::image::AnchorElem anchorVert;
203
204};
214//class CmdAlign : public drain::SimpleCommand<std::string> {
215class CmdTransform : public drain::SimpleCommand<std::string> {
216
217public:
218
219 CmdTransform() : drain::SimpleCommand<std::string>(__FUNCTION__, "Apply SVG transformations to image", "topology", ""){
220 //getParameters().link("", x, drain::StringBuilder<':'>());
221 getParameters().separator = ' '; // rare
222 getParameters().link("translate", transform.translate.tuple());
223 getParameters().link("scale", transform.scale.tuple());
224 getParameters().link("rotate", transform.rotate.tuple());
225 }
226
228 getParameters().copyStruct(cmd.getParameters(), cmd, *this, drain::ReferenceMap::LINK);
229 };
230
231
232 virtual
233 void exec() const override;
234
235protected:
236
238
239};
240
241/*
242class CmdAnchor : public drain::SimpleCommand<std::string> {
243
244public:
245
246 inline
247 CmdAnchor() : drain::SimpleCommand<std::string>(__FUNCTION__, "Alignment of the next element", "topology", "",
248 drain::sprinter(drain::Enum<drain::image::AnchorElem::Anchor>::dict.getKeys(), {"|"}).str()
249 ){
250 //getParameters().link("", x, drain::StringBuilder<':'>());
251 }
252
253 virtual
254 void exec() const override {
255
256 RackContext & ctx = getContext<RackContext>();
257 drain::Logger mout(ctx.log, __FUNCTION__, getName());
258
259 }
260};
261 */
262
264class CmdAdjustSizes : public drain::SimpleCommand<std::string> {
265
266public:
267
268 CmdAdjustSizes(const std::string & name, const std::string & description) : drain::SimpleCommand<std::string>(name, description) {
269 // getParameters().link("sizes", fontSizes);
270 }
271
272 // template <class T, size_t N=2>
273 //ConfSVG::sizeConf
274 void adjust(ConfSVG::sizeConf & tuple, float decay = 0.8) const;
275
276 /*
277 void adjust(drain::UniTuple<T,N> & tuple, float decay = 0.8) const{
278
279 RackContext & ctx = getContext<RackContext>();
280 drain::Logger mout(ctx.log, __FILE__, __FUNCTION__);
281
282 double defaultValue = decay * tuple[0];
283
284 tuple.clear();
285
286 drain::Reference ref(tuple);
287 ref.setFill(false);
288 ref = value;
289 mout.attention(value, " => ", DRAIN_LOG(ref));
290
291 for (double & s: tuple){
292 defaultValue = 0.1 * ::round(10.0 * defaultValue);
293 // mout.attention("font size ", s, ", [", defaultValue, "]");
294 if (s == 0.0){
295 s = defaultValue;
296 }
297 else {
298 if (s > defaultValue){
299 // mout.suspicious<LOG_WARNING>("font size increasing (", s, '>', defaultValue, ") unexpectedly");
300 }
301 defaultValue = s;
302 }
303 defaultValue *= decay;
304 }
305
306 mout.attention("new values: ", DRAIN_LOG(ref));
307 // mout.accept<LOG_WARNING>("new values: ", ctx.svgPanelConf.fontSizes);
308
309
310 }
311 */
312
313};
314
315
316// class CmdFontSizes : public drain::BasicCommand {
318
319public:
320
321 inline
322 CmdFontSizes() : CmdAdjustSizes(__FUNCTION__, "Adjust font sizes in CSS style section.") {
323 }
324
325 virtual
326 void exec() const override;
327
328};
329
330
332
333public:
334
335 inline
336 CmdTitleHeights() : CmdAdjustSizes(__FUNCTION__, "Set title box heights and adjust font sizes. See --gFontSizes") {
337 }
338
339 virtual
340 void exec() const override;
341
342};
343
344class CmdLinkImage : public drain::SimpleCommand<std::string> {
345
346public:
347
348 inline
349 CmdLinkImage() : drain::SimpleCommand<std::string>(__FUNCTION__, "Link arbitrary external image (PNG).") {
350 }
351
352 void exec() const override;
353
354};
355
356
357
358//class CmdGroupTitle : public drain::BasicCommand {
359class CmdGroupTitle : public drain::SimpleCommand<std::string> {
360
361public:
362
363 inline
364 CmdGroupTitle() : drain::SimpleCommand<std::string>(__FUNCTION__, "Set titles, supporting variables", "syntax") {
365 // RackContext & ctx = getContext<RackContext>();
367 // getParameters().link("syntax", ctx.svgPanelConf.groupTitleSyntax, "example: '${what:date|%Y%m} ${NOD}'");
368 }
369
370 inline
371 CmdGroupTitle(const CmdGroupTitle & cmd) : drain::SimpleCommand<std::string>(cmd) { // drain::BasicCommand(cmd) {
372 // getParameters().copyStruct(cmd.getParameters(), cmd, *this, drain::ReferenceMap::LINK);
373 }
374
375 void exec() const override;
376
377};
378
379class CmdGroupId : public drain::SimpleCommand<std::string> {
380
381public:
382
383 //CmdGroupTitle() : drain::BasicCommand(__FUNCTION__, "Set titles automatically") {
384 CmdGroupId() : drain::SimpleCommand<std::string>(__FUNCTION__, "Set grouping criterion based on variables", "syntax") {
386 }
387
388 CmdGroupId(const CmdGroupId & cmd) : drain::SimpleCommand<std::string>(cmd) { // drain::BasicCommand(cmd) {
389 // getParameters().copyStruct(cmd.getParameters(), cmd, *this, drain::ReferenceMap::LINK);
390 }
391
392 inline
393 void exec() const override {
396 // mout.accept<LOG_WARNING>("old value: ", value);
397 drain::StringTools::replace(value, '/', '-', ctx.svgPanelConf.groupIdentifier);
398 // notice if pruned/modified?
399 mout.accept<LOG_WARNING>("new value: ", ctx.svgPanelConf.groupIdentifier);
400 }
401
402};
403
404
405/*
406class CmdImageTitle : public drain::BasicCommand {
407
408public:
409
410 CmdImageTitle() : drain::BasicCommand(__FUNCTION__, "Set titles automatically") {
411 RackContext & ctx = getContext<RackContext>();
412 getParameters().link("title", ctx.svgPanelConf.imageTitle, "'TIME'|'LOCATION'|'GENERAL'");
413 }
414
415 CmdImageTitle(const CmdImageTitle & cmd) : drain::BasicCommand(cmd) {
416 getParameters().copyStruct(cmd.getParameters(), cmd, *this, drain::ReferenceMap::LINK);
417 }
418
419 void exec() const override {
420 RackContext & ctx = getContext<RackContext>();
421 drain::Logger mout(ctx.log, __FILE__, __FUNCTION__);
422 }
423
424};
425*/
426
428
429public:
430
431 // TODO: use unlinked SimpleCommand,
432
433 inline
434 CmdTitle() : drain::BasicCommand(__FUNCTION__, "Set main title") {
437 getParameters().link("title", ctx.svgPanelConf.mainTitle, "<empty>|<string>|'auto'");
438 }
439
440 inline
442 getParameters().copyStruct(cmd.getParameters(), cmd, *this, drain::ReferenceMap::LINK);
443 }
444
445};
446
465/*
466class CmdTitles : public drain::BasicCommand {
467
468public:
469
470 CmdTitles() : drain::BasicCommand(__FUNCTION__, "Set titles automatically") {
471 RackContext & ctx = getContext<RackContext>();
472 getParameters().link("main", ctx.svgPanelConf.mainTitle, "NONE|AUTO|USER");
473 getParameters().link("group", ctx.svgPanelConf.mainTitle, "NONE|AUTO|USER");
474 getParameters().link("image", ctx.svgPanelConf.mainTitle, "NONE|TIME|LOCATION|GENERAL");
475 }
476
477 CmdTitles(const CmdTitles & cmd) : drain::BasicCommand(cmd) {
478 getParameters().copyStruct(cmd.getParameters(), cmd, *this, drain::ReferenceMap::LINK);
479 }
480
481};
482 */
483
484
485class CmdInclude : public drain::SimpleCommand<std::string> {
486
487public:
488
489 CmdInclude() : drain::SimpleCommand<std::string>(__FUNCTION__, "Select images to include in SVG panel", "include",
490 drain::sprinter(drain::Enum<drain::image::FileSVG::IncludePolicy>::dict.getKeys(), '|').str()) {
491 }
492
493 void exec() const override;
494
495};
496
497
498/*
499class CmdTitles : public drain::SimpleCommand<std::string> {
500public:
501
502 CmdTitles() : drain::SimpleCommand<std::string>(__FUNCTION__, "Set titles automatically", "[MAINTITLE|TIME|LOCATION|GENERAL]") {
503 }
504
505 void exec() const {
506
507 RackContext & ctx = getContext<RackContext>();
508 drain::Logger mout(ctx.log, __FILE__, __FUNCTION__);
509
510 mout.unimplemented<LOG_ERR>(__FILE__, __FUNCTION__);
511 //ctx.svgPanelConf.svgTitles.set(value);
512
513 }
514
515};
516 */
517
518
519} // rack::
520
521
522#endif
Simple implementation of Command: adds name , description and parameters .
Definition Command.h:461
virtual const drain::ReferenceMap & getParameters() const
Returns the command parameters.
Definition Command.h:396
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:326
void copyStruct(const ReferenceMap &m, const T &src, T &dst, extLinkPolicy policy=RESERVE)
Experimental. Copies references and values of a structure to another.
Definition ReferenceMap.h:425
@ LINK
Definition ReferenceMap.h:410
A single-parameter command.
Definition Command.h:487
char separator
Default character used for splitting input and output. See setValues.
Definition SmartMap.h:81
static void replace(const std::string &src, char search, char repl, std::ostream &ostr)
Replaces instances of 'search' to 'repl' in src.
Definition StringTools.cpp:93
Default implementation of a tree visitor (concept) compatible TreeUtils::traverser()
Definition TreeUtils.h:266
Definition TransformSVG.h:103
"Virtual" command base for FontSizes and HeaderSizes
Definition graphics-panel.h:264
Definition graphics-panel.h:147
virtual void exec() const override
Definition graphics-panel.cpp:499
Definition graphics-panel.h:317
virtual void exec() const override
Run the command with current parameter values.
Definition graphics-panel.cpp:640
Definition graphics-panel.h:379
void exec() const override
Run the command with current parameter values.
Definition graphics-panel.h:393
Definition graphics-panel.h:359
void exec() const override
Run the command with current parameter values.
Definition graphics-panel.cpp:721
Definition graphics-panel.h:485
void exec() const override
Definition graphics-panel.cpp:823
Definition graphics-panel.h:94
virtual void exec() const override
Run the command with current parameter values.
Definition graphics-panel.cpp:440
Definition graphics-panel.h:344
void exec() const override
Run the command with current parameter values.
Definition graphics-panel.cpp:673
Definition graphics-panel.h:331
virtual void exec() const override
Run the command with current parameter values.
Definition graphics-panel.cpp:653
Definition graphics-panel.h:427
Definition graphics-panel.h:215
virtual void exec() const override
Run the command with current parameter values.
Definition graphics-panel.cpp:581
A map of radar data, indexed by quantity code (DBZH, VRAD, etc).
Definition Data.h:1293
Resources provided separately for each thread.
Definition resources.h:70
Formats titles from metadata. Invoked by drain::TreeUtils::traverse()
Definition graphics-panel.h:68
void formatTitle(TreeSVG &group, const NodeSVG::map_t &attributes) const
Definition graphics-panel.cpp:249
Namespace for images and image processing tools.
Definition AccumulationArray.cpp:45
Definition AltitudeOp.cpp:42
A container for a static dictionary of enumeration values.
Definition Enum.h:51
Definition AlignAnchorSVG.h:77
Definition resources-svg.h:48