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 //titles.set(0xff);
76 /*
77 if (!svgConf.mainTitle.empty()){
78 titles.set(PanelConfSVG::ElemClass::MAIN_TITLE);
79 }
80
81 if (!svgConf.groupTitleSyntax.empty()){
82 titles.set(PanelConfSVG::ElemClass::GROUP_TITLE);
83 }
84
85 titles.set(PanelConfSVG::ElemClass::IMAGE_TITLE);
86 */
87 /*
88 if (!svgConf.groupNameSyntax.empty()){
89 titles.set(RackSVG::ElemClass::GROUP_TITLE);
90 }
91 */
92 };
93
96 int visitPostfix(TreeSVG &root, const TreeSVG::path_t &path) override;
97
101 void formatTitle(TreeSVG & group, const NodeSVG::map_t & attributes) const;
102
103 const ConfSVG & svgConf;
104
105
106};
107
108
109// ....
110
112
113public:
114
115 CmdLayout() : drain::BasicCommand(__FUNCTION__, "Set main panel alignment"){
116
117 getParameters().link("orientation", orientation="HORZ",
118 drain::sprinter(drain::Enum<orientation_enum>::dict.getKeys(), {"|"}).str());
119 getParameters().link("directionVert", directionVert="DOWN",
120 drain::sprinter(drain::Enum<dir_vert_enum>::dict.getKeys(), {"|"}).str());
121 getParameters().link("directionHorz", directionHorz="RIGHT",
122 drain::sprinter(drain::Enum<dir_horz_enum>::dict.getKeys(), {"|"}).str());
123
124 }
125
127 getParameters().copyStruct(cmd.getParameters(), cmd, *this);
128 };
129
130
131 virtual
132 void exec() const override;
133
134protected:
135
136 typedef drain::image::AlignBase::Axis orientation_enum;
137 typedef drain::image::LayoutSVG::DirectionVert dir_vert_enum;
138 typedef drain::image::LayoutSVG::DirectionHorz dir_horz_enum;
139
140 //volatile
141 mutable
142 std::string orientation;
143
144 // volatile
145 mutable
146 std::string directionVert;
147
148 mutable
149 std::string directionHorz;
150
151
152};
153
163//class CmdAlign : public drain::SimpleCommand<std::string> {
165
166public:
167
168 /*
169 CmdAlign() : drain::SimpleCommand<std::string>(__FUNCTION__, "Alignment of the next element", "topology", "",
170 drain::sprinter(drain::Enum<AlignSVG::Topol>::dict.getKeys(), {"|"}).str() + ':' +
171 drain::sprinter(drain::Enum<AlignSVG::HorzAlign>::dict.getKeys(), {"|"}).str() + ',' +
172 drain::sprinter(drain::Enum<AlignSVG::Topol>::dict.getKeys(), {"|"}).str() + ':' +
173 drain::sprinter(drain::Enum<AlignSVG::VertAlign>::dict.getKeys(), {"|"}).str()
174 ){
175 //getParameters().link("", x, drain::StringBuilder<':'>());
176 }
177 */
178
179
180 CmdAlign() : drain::BasicCommand(__FUNCTION__, "Alignment of the next element"){
181
182 getParameters().link("position", position,
183 drain::sprinter(drain::Enum<MutualAlign::Topol>::dict.getKeys(), {"|"}).str() + ':' +
184 drain::sprinter(drain::Enum<AlignSVG::HorzAlign>::dict.getKeys(), {"|"}).str() + ',' +
185 drain::sprinter(drain::Enum<MutualAlign::Topol>::dict.getKeys(), {"|"}).str() + ':' +
186 drain::sprinter(drain::Enum<AlignSVG::VertAlign>::dict.getKeys(), {"|"}).str()
187 ).setSeparator(':');
188
189 getParameters().link("anchor", anchor.str(),
190 std::string("<name>|<empty>") + drain::sprinter(drain::Enum<drain::image::AnchorElem::Anchor>::dict.getKeys(), {"|"}).str()
191 );
192 getParameters().link("anchorHorz", anchorHorz.str(),
193 "..."
194 );
195 getParameters().link("anchorVert", anchorVert.str(),
196 "..."
197 );
198 }
199
201 getParameters().copyStruct(cmd.getParameters(), cmd, *this, drain::ReferenceMap::LINK);
202 };
203
204
205 virtual
206 void exec() const override;
207
208protected:
209
210 std::string position;
211
212 mutable
214
215 mutable
216 drain::image::AnchorElem anchorHorz;
217
218 mutable
219 drain::image::AnchorElem anchorVert;
220
221};
231//class CmdAlign : public drain::SimpleCommand<std::string> {
232class CmdTransform : public drain::SimpleCommand<std::string> {
233
234public:
235
236 CmdTransform() : drain::SimpleCommand<std::string>(__FUNCTION__, "Apply SVG transformations to image", "topology", ""){
237 //getParameters().link("", x, drain::StringBuilder<':'>());
238 getParameters().separator = ' '; // rare
239 getParameters().link("translate", transform.translate.tuple());
240 getParameters().link("scale", transform.scale.tuple());
241 getParameters().link("rotate", transform.rotate.tuple());
242 }
243
245 getParameters().copyStruct(cmd.getParameters(), cmd, *this, drain::ReferenceMap::LINK);
246 };
247
248
249 virtual
250 void exec() const override;
251
252protected:
253
255
256};
257
258/*
259class CmdAnchor : public drain::SimpleCommand<std::string> {
260
261public:
262
263 inline
264 CmdAnchor() : drain::SimpleCommand<std::string>(__FUNCTION__, "Alignment of the next element", "topology", "",
265 drain::sprinter(drain::Enum<drain::image::AnchorElem::Anchor>::dict.getKeys(), {"|"}).str()
266 ){
267 //getParameters().link("", x, drain::StringBuilder<':'>());
268 }
269
270 virtual
271 void exec() const override {
272
273 RackContext & ctx = getContext<RackContext>();
274 drain::Logger mout(ctx.log, __FUNCTION__, getName());
275
276 }
277};
278 */
279
281class CmdAdjustSizes : public drain::SimpleCommand<std::string> {
282
283public:
284
285 CmdAdjustSizes(const std::string & name, const std::string & description) : drain::SimpleCommand<std::string>(name, description) {
286 // getParameters().link("sizes", fontSizes);
287 }
288
289 // template <class T, size_t N=2>
290 //ConfSVG::sizeConf
291 void adjust(ConfSVG::sizeConf & tuple, float decay = 0.8) const;
292
293 /*
294 void adjust(drain::UniTuple<T,N> & tuple, float decay = 0.8) const{
295
296 RackContext & ctx = getContext<RackContext>();
297 drain::Logger mout(ctx.log, __FILE__, __FUNCTION__);
298
299 double defaultValue = decay * tuple[0];
300
301 tuple.clear();
302
303 drain::Reference ref(tuple);
304 ref.setFill(false);
305 ref = value;
306 mout.attention(value, " => ", DRAIN_LOG(ref));
307
308 for (double & s: tuple){
309 defaultValue = 0.1 * ::round(10.0 * defaultValue);
310 // mout.attention("font size ", s, ", [", defaultValue, "]");
311 if (s == 0.0){
312 s = defaultValue;
313 }
314 else {
315 if (s > defaultValue){
316 // mout.suspicious<LOG_WARNING>("font size increasing (", s, '>', defaultValue, ") unexpectedly");
317 }
318 defaultValue = s;
319 }
320 defaultValue *= decay;
321 }
322
323 mout.attention("new values: ", DRAIN_LOG(ref));
324 // mout.accept<LOG_WARNING>("new values: ", ctx.svgPanelConf.fontSizes);
325
326
327 }
328 */
329
330};
331
332
333// class CmdFontSizes : public drain::BasicCommand {
335
336public:
337
338 inline
339 CmdFontSizes() : CmdAdjustSizes(__FUNCTION__, "Adjust font sizes in CSS style section.") {
340 }
341
342 virtual
343 void exec() const override;
344
345};
346
347
349
350public:
351
352 inline
353 CmdTitleHeights() : CmdAdjustSizes(__FUNCTION__, "Set title box heights and adjust font sizes. See --gFontSizes") {
354 }
355
356 virtual
357 void exec() const override;
358
359};
360
361class CmdLinkImage : public drain::SimpleCommand<std::string> {
362
363public:
364
365 inline
366 CmdLinkImage() : drain::SimpleCommand<std::string>(__FUNCTION__, "Link arbitrary external image (PNG).") {
367 }
368
369 void exec() const override;
370
371};
372
373
374
375//class CmdGroupTitle : public drain::BasicCommand {
376class CmdGroupTitle : public drain::SimpleCommand<std::string> {
377
378public:
379
380 inline
381 CmdGroupTitle() : drain::SimpleCommand<std::string>(__FUNCTION__, "Set titles, supporting variables", "syntax") {
382 // RackContext & ctx = getContext<RackContext>();
384 // getParameters().link("syntax", ctx.svgPanelConf.groupTitleSyntax, "example: '${what:date|%Y%m} ${NOD}'");
385 }
386
387 inline
388 CmdGroupTitle(const CmdGroupTitle & cmd) : drain::SimpleCommand<std::string>(cmd) { // drain::BasicCommand(cmd) {
389 // getParameters().copyStruct(cmd.getParameters(), cmd, *this, drain::ReferenceMap::LINK);
390 }
391
392 void exec() const override;
393
394};
395
396class CmdGroupId : public drain::SimpleCommand<std::string> {
397
398public:
399
400 //CmdGroupTitle() : drain::BasicCommand(__FUNCTION__, "Set titles automatically") {
401 CmdGroupId() : drain::SimpleCommand<std::string>(__FUNCTION__, "Set grouping criterion based on variables", "syntax") {
403 }
404
405 CmdGroupId(const CmdGroupId & cmd) : drain::SimpleCommand<std::string>(cmd) { // drain::BasicCommand(cmd) {
406 // getParameters().copyStruct(cmd.getParameters(), cmd, *this, drain::ReferenceMap::LINK);
407 }
408
409 inline
410 void exec() const override {
413 // mout.accept<LOG_WARNING>("old value: ", value);
414 drain::StringTools::replace(value, '/', '-', ctx.svgPanelConf.groupIdentifier);
415 // notice if pruned/modified?
416 mout.accept<LOG_WARNING>("new value: ", ctx.svgPanelConf.groupIdentifier);
417 }
418
419};
420
421
422/*
423class CmdImageTitle : public drain::BasicCommand {
424
425public:
426
427 CmdImageTitle() : drain::BasicCommand(__FUNCTION__, "Set titles automatically") {
428 RackContext & ctx = getContext<RackContext>();
429 getParameters().link("title", ctx.svgPanelConf.imageTitle, "'TIME'|'LOCATION'|'GENERAL'");
430 }
431
432 CmdImageTitle(const CmdImageTitle & cmd) : drain::BasicCommand(cmd) {
433 getParameters().copyStruct(cmd.getParameters(), cmd, *this, drain::ReferenceMap::LINK);
434 }
435
436 void exec() const override {
437 RackContext & ctx = getContext<RackContext>();
438 drain::Logger mout(ctx.log, __FILE__, __FUNCTION__);
439 }
440
441};
442*/
443
445
446public:
447
448 // TODO: use unlinked SimpleCommand,
449
450 inline
451 CmdTitle() : drain::BasicCommand(__FUNCTION__, "Set main title") {
454 getParameters().link("title", ctx.svgPanelConf.mainTitle, "<empty>|<string>|'auto'");
455 }
456
457 inline
459 getParameters().copyStruct(cmd.getParameters(), cmd, *this, drain::ReferenceMap::LINK);
460 }
461
462};
463
482/*
483class CmdTitles : public drain::BasicCommand {
484
485public:
486
487 CmdTitles() : drain::BasicCommand(__FUNCTION__, "Set titles automatically") {
488 RackContext & ctx = getContext<RackContext>();
489 getParameters().link("main", ctx.svgPanelConf.mainTitle, "NONE|AUTO|USER");
490 getParameters().link("group", ctx.svgPanelConf.mainTitle, "NONE|AUTO|USER");
491 getParameters().link("image", ctx.svgPanelConf.mainTitle, "NONE|TIME|LOCATION|GENERAL");
492 }
493
494 CmdTitles(const CmdTitles & cmd) : drain::BasicCommand(cmd) {
495 getParameters().copyStruct(cmd.getParameters(), cmd, *this, drain::ReferenceMap::LINK);
496 }
497
498};
499 */
500
501
502class CmdInclude : public drain::SimpleCommand<std::string> {
503
504public:
505
506 CmdInclude() : drain::SimpleCommand<std::string>(__FUNCTION__, "Select images to include in SVG panel", "include",
507 drain::sprinter(drain::Enum<drain::image::FileSVG::IncludePolicy>::dict.getKeys(), '|').str()) {
508 }
509
510 void exec() const override;
511
512};
513
514
515/*
516class CmdTitles : public drain::SimpleCommand<std::string> {
517public:
518
519 CmdTitles() : drain::SimpleCommand<std::string>(__FUNCTION__, "Set titles automatically", "[MAINTITLE|TIME|LOCATION|GENERAL]") {
520 }
521
522 void exec() const {
523
524 RackContext & ctx = getContext<RackContext>();
525 drain::Logger mout(ctx.log, __FILE__, __FUNCTION__);
526
527 mout.unimplemented<LOG_ERR>(__FILE__, __FUNCTION__);
528 //ctx.svgPanelConf.svgTitles.set(value);
529
530 }
531
532};
533 */
534
535
536} // rack::
537
538
539#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:412
@ LINK
Definition ReferenceMap.h:397
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:253
Definition TransformSVG.h:103
"Virtual" command base for FontSizes and HeaderSizes
Definition graphics-panel.h:281
Definition graphics-panel.h:164
virtual void exec() const override
Definition graphics-panel.cpp:478
Definition graphics-panel.h:334
virtual void exec() const override
Run the command with current parameter values.
Definition graphics-panel.cpp:619
Definition graphics-panel.h:396
void exec() const override
Run the command with current parameter values.
Definition graphics-panel.h:410
Definition graphics-panel.h:376
void exec() const override
Run the command with current parameter values.
Definition graphics-panel.cpp:701
Definition graphics-panel.h:502
void exec() const override
Definition graphics-panel.cpp:803
Definition graphics-panel.h:111
virtual void exec() const override
Run the command with current parameter values.
Definition graphics-panel.cpp:419
Definition graphics-panel.h:361
void exec() const override
Run the command with current parameter values.
Definition graphics-panel.cpp:653
Definition graphics-panel.h:348
virtual void exec() const override
Run the command with current parameter values.
Definition graphics-panel.cpp:633
Definition graphics-panel.h:444
Definition graphics-panel.h:232
virtual void exec() const override
Run the command with current parameter values.
Definition graphics-panel.cpp:560
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:231
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