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 <main/graphics-panel.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 <drain/image/TreeSVG.h>
50//#include "resources-image.h"
51
52namespace rack {
53
54using namespace drain::image;
55// Move to graphics.h ?
56
58
63class TitleCreatorSVG : public drain::TreeVisitor<TreeSVG> {
64
65public:
66
67
68 inline
69 TitleCreatorSVG(const ConfSVG & svgConf) : svgConf(svgConf) {
70 //titles.set(0xff);
71 /*
72 if (!svgConf.mainTitle.empty()){
73 titles.set(PanelConfSVG::ElemClass::MAIN_TITLE);
74 }
75
76 if (!svgConf.groupTitleSyntax.empty()){
77 titles.set(PanelConfSVG::ElemClass::GROUP_TITLE);
78 }
79
80 titles.set(PanelConfSVG::ElemClass::IMAGE_TITLE);
81 */
82 /*
83 if (!svgConf.groupNameSyntax.empty()){
84 titles.set(RackSVG::ElemClass::GROUP_TITLE);
85 }
86 */
87 };
88
91 int visitPostfix(TreeSVG &root, const TreeSVG::path_t &path) override;
92
96 void formatTitle(TreeSVG & group, const NodeSVG::map_t & attributes) const;
97
98 const ConfSVG & svgConf;
99
100
101};
102
103
104// ....
105
107
108public:
109
110 CmdLayout() : drain::BasicCommand(__FUNCTION__, "Set main panel alignment"){
111
112 getParameters().link("orientation", orientation="HORZ",
113 drain::sprinter(drain::Enum<orientation_enum>::dict.getKeys(), {"|"}).str());
114 getParameters().link("direction", direction="INCR",
115 drain::sprinter(drain::Enum<direction_enum>::dict.getKeys(), {"|"}).str());
116
117 }
118
119 CmdLayout(const CmdLayout & cmd) : drain::BasicCommand(cmd) {
120 getParameters().copyStruct(cmd.getParameters(), cmd, *this);
121 };
122
123
124 virtual
125 void exec() const override;
126
127protected:
128
129 typedef drain::image::AlignBase::Axis orientation_enum;
131
132 //volatile
133 mutable
134 std::string orientation;
135
136 // volatile
137 mutable
138 std::string direction;
139
140
141};
142
152//class CmdAlign : public drain::SimpleCommand<std::string> {
154
155public:
156
157 /*
158 CmdAlign() : drain::SimpleCommand<std::string>(__FUNCTION__, "Alignment of the next element", "topology", "",
159 drain::sprinter(drain::Enum<AlignSVG::Topol>::dict.getKeys(), {"|"}).str() + ':' +
160 drain::sprinter(drain::Enum<AlignSVG::HorzAlign>::dict.getKeys(), {"|"}).str() + ',' +
161 drain::sprinter(drain::Enum<AlignSVG::Topol>::dict.getKeys(), {"|"}).str() + ':' +
162 drain::sprinter(drain::Enum<AlignSVG::VertAlign>::dict.getKeys(), {"|"}).str()
163 ){
164 //getParameters().link("", x, drain::StringBuilder<':'>());
165 }
166 */
167
168
169 CmdAlign() : drain::BasicCommand(__FUNCTION__, "Alignment of the next element"){
170
171 getParameters().link("position", position,
172 drain::sprinter(drain::Enum<AlignSVG::Topol>::dict.getKeys(), {"|"}).str() + ':' +
173 drain::sprinter(drain::Enum<AlignSVG::HorzAlign>::dict.getKeys(), {"|"}).str() + ',' +
174 drain::sprinter(drain::Enum<AlignSVG::Topol>::dict.getKeys(), {"|"}).str() + ':' +
175 drain::sprinter(drain::Enum<AlignSVG::VertAlign>::dict.getKeys(), {"|"}).str()
176 ).setSeparator(':');
177
178 getParameters().link("anchor", anchor.str(),
179 std::string("<name>|<empty>") + drain::sprinter(drain::Enum<drain::image::AnchorElem::Anchor>::dict.getKeys(), {"|"}).str()
180 );
181 getParameters().link("anchorHorz", anchorHorz.str(),
182 "..."
183 );
184 getParameters().link("anchorVert", anchorVert.str(),
185 "..."
186 );
187 }
188
189 CmdAlign(const CmdAlign & cmd) : drain::BasicCommand(cmd){
190 getParameters().copyStruct(cmd.getParameters(), cmd, *this, drain::ReferenceMap::LINK);
191 };
192
193
194 virtual
195 void exec() const override;
196
197protected:
198
199 std::string position;
200
201 mutable
203
204 mutable
205 drain::image::AnchorElem anchorHorz;
206
207 mutable
208 drain::image::AnchorElem anchorVert;
209
210};
211
212/*
213class CmdAnchor : public drain::SimpleCommand<std::string> {
214
215public:
216
217 inline
218 CmdAnchor() : drain::SimpleCommand<std::string>(__FUNCTION__, "Alignment of the next element", "topology", "",
219 drain::sprinter(drain::Enum<drain::image::AnchorElem::Anchor>::dict.getKeys(), {"|"}).str()
220 ){
221 //getParameters().link("", x, drain::StringBuilder<':'>());
222 }
223
224 virtual
225 void exec() const override {
226
227 RackContext & ctx = getContext<RackContext>();
228 drain::Logger mout(ctx.log, __FUNCTION__, getName());
229
230 }
231};
232 */
233
235class CmdAdjustSizes : public drain::SimpleCommand<std::string> {
236
237public:
238
239 CmdAdjustSizes(const std::string & name, const std::string & description) : drain::SimpleCommand<std::string>(name, description) {
240 // getParameters().link("sizes", fontSizes);
241 }
242
243 template <class T, size_t N=2>
244 void adjust(drain::UniTuple<T,N> & tuple, float decay = 0.8) const{
245
246
247 double defaultValue = decay * tuple[0];
248
249 tuple.clear();
250
251 drain::Reference ref(tuple);
252 ref.setFill(false);
253 ref = value;
254
255 for (double & s: tuple){
256 defaultValue = 0.1 * ::round(10.0 * defaultValue);
257 // mout.attention("font size ", s, ", [", defaultValue, "]");
258 if (s == 0.0){
259 s = defaultValue;
260 }
261 else {
262 if (s > defaultValue){
263 // mout.suspicious<LOG_WARNING>("font size increasing (", s, '>', defaultValue, ") unexpectedly");
264 }
265 defaultValue = s;
266 }
267 defaultValue *= decay;
268 }
269 // mout.accept<LOG_WARNING>("new values: ", ctx.svgPanelConf.fontSizes);
270
271
272 }
273
274
275};
276
277
278// class CmdFontSizes : public drain::BasicCommand {
280
281public:
282
283 inline
284 CmdFontSizes() : CmdAdjustSizes(__FUNCTION__, "Adjust font sizes in CSS style section.") {
285 }
286
287 virtual
288 void exec() const override;
289
290};
291
292
294
295public:
296
297 inline
298 CmdTitleHeights() : CmdAdjustSizes(__FUNCTION__, "Set title box heights and adjust font sizes. See --gFontSizes") {
299 }
300
301 virtual
302 void exec() const override;
303
304};
305
306class CmdLinkImage : public drain::SimpleCommand<std::string> {
307
308public:
309
310 inline
311 CmdLinkImage() : drain::SimpleCommand<std::string>(__FUNCTION__, "Link arbitrary external image (PNG).") {
312 }
313
314 void exec() const override;
315
316};
317
318
319
320//class CmdGroupTitle : public drain::BasicCommand {
321class CmdGroupTitle : public drain::SimpleCommand<std::string> {
322
323public:
324
325 inline
326 CmdGroupTitle() : drain::SimpleCommand<std::string>(__FUNCTION__, "Set titles, supporting variables", "syntax") {
327 // RackContext & ctx = getContext<RackContext>();
328 getParameters().separator = 0;
329 // getParameters().link("syntax", ctx.svgPanelConf.groupTitleSyntax, "example: '${what:date|%Y%m} ${NOD}'");
330 }
331
332 inline
333 CmdGroupTitle(const CmdGroupTitle & cmd) : drain::SimpleCommand<std::string>(cmd) { // drain::BasicCommand(cmd) {
334 // getParameters().copyStruct(cmd.getParameters(), cmd, *this, drain::ReferenceMap::LINK);
335 }
336
337 void exec() const override;
338
339};
340
341class CmdGroupId : public drain::SimpleCommand<std::string> {
342
343public:
344
345 //CmdGroupTitle() : drain::BasicCommand(__FUNCTION__, "Set titles automatically") {
346 CmdGroupId() : drain::SimpleCommand<std::string>(__FUNCTION__, "Set grouping criterion based on variables", "syntax") {
347 getParameters().separator = 0;
348 }
349
350 CmdGroupId(const CmdGroupId & cmd) : drain::SimpleCommand<std::string>(cmd) { // drain::BasicCommand(cmd) {
351 // getParameters().copyStruct(cmd.getParameters(), cmd, *this, drain::ReferenceMap::LINK);
352 }
353
354 inline
355 void exec() const override {
356 RackContext & ctx = getContext<RackContext>();
357 drain::Logger mout(ctx.log, __FILE__, __FUNCTION__);
358 // mout.accept<LOG_WARNING>("old value: ", value);
359 drain::StringTools::replace(value, '/', '-', ctx.svgPanelConf.groupIdentifier);
360 // notice if pruned/modified?
361 mout.accept<LOG_WARNING>("new value: ", ctx.svgPanelConf.groupIdentifier);
362 }
363
364};
365
366
367/*
368class CmdImageTitle : public drain::BasicCommand {
369
370public:
371
372 CmdImageTitle() : drain::BasicCommand(__FUNCTION__, "Set titles automatically") {
373 RackContext & ctx = getContext<RackContext>();
374 getParameters().link("title", ctx.svgPanelConf.imageTitle, "'TIME'|'LOCATION'|'GENERAL'");
375 }
376
377 CmdImageTitle(const CmdImageTitle & cmd) : drain::BasicCommand(cmd) {
378 getParameters().copyStruct(cmd.getParameters(), cmd, *this, drain::ReferenceMap::LINK);
379 }
380
381 void exec() const override {
382 RackContext & ctx = getContext<RackContext>();
383 drain::Logger mout(ctx.log, __FILE__, __FUNCTION__);
384 }
385
386};
387*/
388
390
391public:
392
393 // TODO: use unlinked SimpleCommand,
394
395 inline
396 CmdTitle() : drain::BasicCommand(__FUNCTION__, "Set main title") {
397 RackContext & ctx = getContext<RackContext>();
398 getParameters().separator = 0;
399 getParameters().link("title", ctx.svgPanelConf.mainTitle, "<empty>|<string>|'auto'");
400 }
401
402 inline
403 CmdTitle(const CmdTitle & cmd) : drain::BasicCommand(cmd) {
404 getParameters().copyStruct(cmd.getParameters(), cmd, *this, drain::ReferenceMap::LINK);
405 }
406
407};
408
427/*
428class CmdTitles : public drain::BasicCommand {
429
430public:
431
432 CmdTitles() : drain::BasicCommand(__FUNCTION__, "Set titles automatically") {
433 RackContext & ctx = getContext<RackContext>();
434 getParameters().link("main", ctx.svgPanelConf.mainTitle, "NONE|AUTO|USER");
435 getParameters().link("group", ctx.svgPanelConf.mainTitle, "NONE|AUTO|USER");
436 getParameters().link("image", ctx.svgPanelConf.mainTitle, "NONE|TIME|LOCATION|GENERAL");
437 }
438
439 CmdTitles(const CmdTitles & cmd) : drain::BasicCommand(cmd) {
440 getParameters().copyStruct(cmd.getParameters(), cmd, *this, drain::ReferenceMap::LINK);
441 }
442
443};
444 */
445
446
447class CmdInclude : public drain::SimpleCommand<std::string> {
448
449public:
450
451 CmdInclude() : drain::SimpleCommand<std::string>(__FUNCTION__, "Select images to include in SVG panel", "include",
452 drain::sprinter(drain::Enum<drain::image::FileSVG::IncludePolicy>::dict.getKeys(), '|').str()) {
453 }
454
455 void exec() const override;
456
457};
458
459
460/*
461class CmdTitles : public drain::SimpleCommand<std::string> {
462public:
463
464 CmdTitles() : drain::SimpleCommand<std::string>(__FUNCTION__, "Set titles automatically", "[MAINTITLE|TIME|LOCATION|GENERAL]") {
465 }
466
467 void exec() const {
468
469 RackContext & ctx = getContext<RackContext>();
470 drain::Logger mout(ctx.log, __FILE__, __FUNCTION__);
471
472 mout.unimplemented<LOG_ERR>(__FILE__, __FUNCTION__);
473 //ctx.svgPanelConf.svgTitles.set(value);
474
475 }
476
477};
478 */
479
480
481} // rack::
482
483
484#endif
Simple implementation of Command: adds name , description and parameters .
Definition Command.h:445
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:313
Logger & accept(const TT &... args)
Some input has been accepted, for example by a syntax.
Definition Log.h:583
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:415
@ LINK
Definition ReferenceMap.h:400
A single-parameter command.
Definition Command.h:469
char separator
Default character used for splitting input and output. See setValues.
Definition SmartMap.h:85
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:94
Default implementation of a tree visitor (concept) compatible TreeUtils::traverser()
Definition TreeUtils.h:270
Tuple of N elements of type T.
Definition UniTuple.h:65
VariableT is a final class applied through typedefs Variable, Reference and FlexibleVariable.
Definition VariableT.h:87
Direction
Direction for "Stacked", horziontally or vertically sequentially aligned layout.
Definition LayoutSVG.h:63
"Virtual" command base for FontSizes and HeaderSizes
Definition graphics-panel.h:235
Definition graphics-panel.h:153
virtual void exec() const override
Definition graphics-panel.cpp:360
Definition graphics-panel.h:279
virtual void exec() const override
Run the command with current parameter values.
Definition graphics-panel.cpp:436
Definition graphics-panel.h:341
void exec() const override
Run the command with current parameter values.
Definition graphics-panel.h:355
Definition graphics-panel.h:321
void exec() const override
Run the command with current parameter values.
Definition graphics-panel.cpp:490
Definition graphics-panel.h:447
void exec() const override
Definition graphics-panel.cpp:592
Definition graphics-panel.h:106
virtual void exec() const override
Run the command with current parameter values.
Definition graphics-panel.cpp:333
Definition graphics-panel.h:306
void exec() const override
Run the command with current parameter values.
Definition graphics-panel.cpp:463
Definition graphics-panel.h:293
virtual void exec() const override
Run the command with current parameter values.
Definition graphics-panel.cpp:446
Definition graphics-panel.h:389
Resources provided separately for each thread.
Definition resources.h:67
Formats titles from metadata. Invoked by drain::TreeUtils::traverse()
Definition graphics-panel.h:63
void formatTitle(TreeSVG &group, const NodeSVG::map_t &attributes) const
Group identifiers for elements which be automatically aligned (stacked horizontally or vertically)
Definition graphics-panel.cpp:140
Namespace for images and image processing tools.
Definition AccumulationArray.cpp:45
Definition DataSelector.cpp:44
A container for a static dictionary of enumeration values.
Definition Enum.h:51
Definition AlignAnchorSVG.h:77
Definition resources-image.h:56