Loading...
Searching...
No Matches
graphics-interactive.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_SVG_INTERACTIVE
33#define RACK_SVG_INTERACTIVE
34
35
36#include <vector>
37#include <drain/prog/Command.h>
38#include <drain/image/MouseEventXML.h>
39#include <drain/util/Base64.h>
40
41#include "hi5/Hi5.h"
42#include "resources.h"
43#include "graphics-overlay.h"
44
45/*
46typedef MouseEventXML<drain::image::NodeSVG> MouseSVG;
47DRAIN_GETKEY_ENUM(drain::image::TreeSVG, drain::image::MouseXML::ElemClass);
48DRAIN_GETKEY_ENUM(drain::image::TreeSVG, drain::image::MouseXML::EventClass);
49*/
50
51//
52
53namespace rack {
54
56
64
65public:
66
67 // TreeSVG & getInteractiveOverlay(RackContext & ctx, RadarSVG & radarSVG, bool fixedAEQD=true) const;
68
69 bool cursorCoord = false;
70
71
72
73};
74
75
76
77class CmdRect : public CmdPolarBase, InteractiveSVG { // x, public drain::image::MouseXML { // drain::BasicCommand,
78
79public:
80
81
82 CmdRect() : CmdPolarBase(__FUNCTION__, "Draw rectangle or circle", Graphic::GRAPHIC::RECTANGLE) {
84 //getParameters().link("bbox", bbox.tuple(100,200,300,400), "xLL,yLL,xUR,yUR").setFill(false).setSeparator(',');
85 getParameters().link("bbox", bbox, "xLL,yLL,xUR,yUR[px|m|deg] or xLL,yLL,r").setSeparator(',');
86 //getParameters().link("bboxUnits", bboxUnits, "[PIX|M|DEG]");
87 getParameters().link("resolution", resolution.tuple(), "pixel").setFill(true).setSeparator(',');
88 getParameters().link("fixedAEQD", fixedAEQD, "fix origin to the first radar");
89 getParameters().link("cursorCoord", cursorCoord, "show cursor coordinate");
90 linkMask();
91 // getParameters().link("MASK", MASK, "Render outer region with style class '.MASK'");
92 // getParameters().link("panel", panel, "label");
93 // getParameters().link("anchor", myAnchor, drain::sprinter(drain::Enum<drain::image::AnchorElem::Anchor>::dict.getKeys(), "|", "<>").str());
94 }
95
96 inline
97 CmdRect(const CmdRect & cmd) : CmdPolarBase(cmd) {
98 getParameters().copyStruct(cmd.getParameters(), cmd, *this);
99 }
100
101 void exec() const override ;
102
103 std::string bbox = "";
104 drain::Range<int> resolution;
105 bool fixedAEQD = true;
106
107};
108
109class CmdCoords : public CmdPolarBase { // drain::BasicCommand,
110
111public:
112
113
114
115
116
117 CmdCoords() : CmdPolarBase(__FUNCTION__, "SVG test product") {
118 getParameters().link("resolution", resolution.tuple(), "pixel").setFill(true); // .setFill(true)
119 getParameters().link("units", coordinateUnits, drain::sprinter(drain::Enum<rack::CmdCoords::CoordUnit>::dict.getKeys()).str()).setSeparator(':');
120 linkMask();
121 //getParameters().link("MASK", MASK, "Fill outside using CSS class '.MASK'");
122 // getParameters().link("panel", panel, "label");
123 // getParameters().link("anchor", myAnchor, drain::sprinter(drain::Enum<drain::image::AnchorElem::Anchor>::dict.getKeys(), "|", "<>").str());
124 }
125
127 getParameters().copyStruct(cmd.getParameters(), cmd, *this);
128 }
129
130 void exec() const override ;
131
132 //std::string units;
133
134 drain::Range<int> resolution;
135
136
137};
138
139
140}
141
142namespace drain {
143
144DRAIN_ENUM_DICT(rack::CmdCoords::CoordUnit);
145
146}
147
148namespace rack {
149
150
151class CmdData : public CmdPolarBase { // , InteractiveSVG drain::BasicCommand,
152
153public:
154
155 CmdData() : CmdPolarBase(__FUNCTION__, "Save and link encoded data for mouse read.") {
156 getParameters().link("filename", filename, "PNG data file path");
157 }
158
159 CmdData(const CmdData & cmd) : CmdPolarBase(cmd) {
160 getParameters().copyStruct(cmd.getParameters(), cmd, *this);
161 }
162
163 void exec() const override;
164
165protected:
166
167 std::string filename;
168};
169
170
171
172class CmdTestData : public CmdPolarBase {
173
174public:
175
176 CmdTestData() : CmdPolarBase(__FUNCTION__, "Test attaching numeric data as arrays using Base64 encoding") {
177 }
178
180 }
181
182 void exec() const override ;
183
184protected:
185
186 template <typename T>
187 void test(drain::image::TreeSVG & img, const std::vector<T> & v, drain::Logger & mout) const {
188
189 const std::string & typeName = drain::TypeName<T>::str();
190 mout.experimental<LOG_NOTICE>("Testing: vector of ", typeName);
191
192 drain::Base64 bytes;
193 bytes.convertFrom(v);
194 std::string code;
195 drain::Base64::base64_encode(bytes, code);
196 mout.experimental<LOG_INFO>("Code: ", code);
197
198 drain::image::TreeSVG & imgData = img[typeName](svg::METADATA);
199 imgData->set("data-base64", code);
200 imgData->set("data-basetype", typeName);
201
202 }
203
204};
205
206
207// Not interactive...
208
209class CmdDot : public CmdPolarBase { // drain::BasicCommand,
210
212 // drain::Range<double> radius;
213 std::string id;
214 std::string style;
215
216public:
217
218 inline
219 CmdDot() : CmdPolarBase(__FUNCTION__, "Draw a marker circle", LABEL) {
220 getParameters().link("lonlat", coords.tuple(25.0, 60.0), "Coordinate (lon,lat) in degrees(decimal) or metres.");
221 getParameters().link("radius", radiusMetres.range.tuple(0,25000), "metres or relative").setFill(true);
222 getParameters().link("id", id, "XML element id");
223 getParameters().link("style", style, "XML element CSS style");
224 }
225
226 inline
227 CmdDot(const CmdDot & cmd) : CmdPolarBase(cmd) {
228 getParameters().copyStruct(cmd.getParameters(), cmd, *this);
229 }
230
231 void exec() const override;
232
233};
234
235
236/*
237class CmdDotTest : public CmdPolarBase { // drain::BasicCommand,
238
239 drain::Point2D<double> coords;
240 std::string id;
241 std::string style;
242
243public:
244
245 inline
246 CmdDotTest() : CmdPolarBase(__FUNCTION__, "Draw a marker circle", LABEL) {
247 getParameters().link("lonlat", coords.tuple(25.0, 60.0), "Coordinate (lon,lat) in degrees(decimal) or metres.");
248 getParameters().link("radius", radiusMetres.range.tuple(0,25000), "metres or relative").setFill(true);
249 getParameters().link("id", id, "XML element id");
250 getParameters().link("style", style, "XML element CSS style");
251 }
252
253 inline
254 CmdDotTest(const CmdDotTest & cmd) : CmdPolarBase(cmd) {
255 getParameters().copyStruct(cmd.getParameters(), cmd, *this);
256 }
257
258 void exec() const override;
259
260};
261*/
262
263} // rack::
264
265
266namespace drain {
267
268// DRAIN_ENUM_DICT(rack::MouseXML::ElemClass);
269//DRAIN_ENUM_OSTREAM(rack::MouseXML::ElemClass);
270//DRAIN_GETKEY_ENUM(image::TreeSVG, rack::MouseXML::ElemClass);
271
272}
273
274#endif
275
Definition Base64.h:21
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
Definition Range.h:52
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
char separator
Default character used for splitting input and output. See setValues.
Definition SmartMap.h:81
Definition graphics-interactive.h:109
void exec() const override
Run the command with current parameter values.
Definition graphics-interactive.cpp:471
Definition graphics-interactive.h:151
void exec() const override
Run the command with current parameter values.
Definition graphics-interactive.cpp:760
Definition graphics-interactive.h:209
void exec() const override
Definition graphics-interactive.cpp:94
Definition graphics-overlay.h:75
void linkMask()
Definition graphics-overlay.cpp:116
Definition graphics-interactive.h:77
void exec() const override
Run the command with current parameter values.
Definition graphics-interactive.cpp:307
Definition graphics-interactive.h:172
void exec() const override
Run the command with current parameter values.
Definition graphics-interactive.cpp:842
A map of radar data, indexed by quantity code (DBZH, VRAD, etc).
Definition Data.h:1293
Tools for adding user interaction to SVG displays.
Definition graphics-interactive.h:63
Definition Data.h:1473
Definition AltitudeOp.cpp:42
A container for a static dictionary of enumeration values.
Definition Enum.h:51
Definition Point.h:48
static const std::string & str()
Default implementation: name returned by std::type_info::name()
Definition TypeName.h:68