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/util/Base64.h>
39
40#include "hi5/Hi5.h"
41#include "resources.h" // ctx
42//#include "graphics-radar.h" // ctx
43#include "graphics-overlay.h" // ctx
44
45
46
47namespace rack {
48
49
50
51
52class CmdRect : public CmdPolarBase { // drain::BasicCommand,
53
54public:
55
56 CmdRect() : CmdPolarBase(__FUNCTION__, "Draw rectangle or circle", Graphic::GRAPHIC::RECTANGLE) {
57 getParameters().separator = ':';
58 //getParameters().link("bbox", bbox.tuple(100,200,300,400), "xLL,yLL,xUR,yUR").setFill(false).setSeparator(',');
59 getParameters().link("bbox", bbox, "xLL,yLL,xUR,yUR[px|m|deg] or xLL,yLL,r").setSeparator(',');
60 //getParameters().link("bboxUnits", bboxUnits, "[PIX|M|DEG]");
61 getParameters().link("resolution", resolution.tuple(), "pixel").setFill(true).setSeparator(',');
62 getParameters().link("MASK", MASK, "Render outer region with style class '.MASK'");
63 // getParameters().link("panel", panel, "label");
64 // getParameters().link("anchor", myAnchor, drain::sprinter(drain::Enum<drain::image::AnchorElem::Anchor>::dict.getKeys(), "|", "<>").str());
65 }
66
67 inline
68 CmdRect(const CmdRect & cmd) : CmdPolarBase(cmd) {
69 getParameters().copyStruct(cmd.getParameters(), cmd, *this);
70 }
71
72 void exec() const override ;
73
74 std::string bbox = "";
75 drain::Range<int> resolution;
76
77};
78
79class CmdCoords : public CmdPolarBase { // drain::BasicCommand,
80
81public:
82
83 CmdCoords() : CmdPolarBase(__FUNCTION__, "SVG test product") {
84 getParameters().link("resolution", resolution.tuple(), "pixel").setFill(true);
85 getParameters().link("MASK", MASK, "Fill outside using CSS class '.MASK'");
86 // getParameters().link("panel", panel, "label");
87 // getParameters().link("anchor", myAnchor, drain::sprinter(drain::Enum<drain::image::AnchorElem::Anchor>::dict.getKeys(), "|", "<>").str());
88 }
89
90 CmdCoords(const CmdCoords & cmd) : CmdPolarBase(cmd) {
91 getParameters().copyStruct(cmd.getParameters(), cmd, *this);
92 }
93
94 void exec() const override ;
95
96 drain::Range<int> resolution;
97
98
99};
100
101class CmdData : public CmdPolarBase { // drain::BasicCommand,
102
103public:
104
105 CmdData() : CmdPolarBase(__FUNCTION__, "Save and link encoded data for mouse read.") {
106 getParameters().link("filename", filename, "PNG data file path");
107 }
108
109 CmdData(const CmdData & cmd) : CmdPolarBase(cmd) {
110 getParameters().copyStruct(cmd.getParameters(), cmd, *this);
111 }
112
113 void exec() const override;
114
115protected:
116
117 std::string filename;
118};
119
120
121
122class CmdTestData : public CmdPolarBase {
123
124public:
125
126 CmdTestData() : CmdPolarBase(__FUNCTION__, "Test attaching numeric data as arrays using Base64 encoding") {
127 }
128
129 CmdTestData(const CmdTestData & cmd) : CmdPolarBase(cmd) {
130 }
131
132 void exec() const override ;
133
134protected:
135
136 template <typename T>
137 void test(drain::image::TreeSVG & img, const std::vector<T> & v, drain::Logger & mout) const {
138
139 const std::string & typeName = drain::TypeName<T>::str();
140 mout.experimental<LOG_NOTICE>("Testing: vector of ", typeName);
141
142 drain::Base64 bytes;
143 bytes.convertFrom(v);
144 std::string code;
145 drain::Base64::base64_encode(bytes, code);
146 mout.experimental<LOG_INFO>("Code: ", code);
147
148 drain::image::TreeSVG & imgData = img[typeName](svg::METADATA);
149 imgData->set("data-base64", code);
150 imgData->set("data-basetype", typeName);
151
152 }
153
154};
155
156
157
158class CmdDot : public CmdPolarBase { // drain::BasicCommand,
159
161 // drain::Range<double> radius;
162 std::string id;
163 std::string style;
164
165public:
166
167 inline
168 CmdDot() : CmdPolarBase(__FUNCTION__, "Draw a marker circle", LABEL) {
169 getParameters().link("lonlat", coords.tuple(25.0, 60.0), "Coordinate (lon,lat) in degrees(decimal) or metres.");
170 getParameters().link("radius", radiusMetres.range.tuple(0,25000), "metres or relative").setFill(true);
171 getParameters().link("id", id, "XML element id");
172 getParameters().link("style", style, "XML element CSS style");
173 }
174
175 inline
176 CmdDot(const CmdDot & cmd) : CmdPolarBase(cmd) {
177 getParameters().copyStruct(cmd.getParameters(), cmd, *this);
178 }
179
180 void exec() const override;
181
182};
183
184} // rack::
185
186
187#endif
188
Definition Base64.h:22
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:313
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:415
char separator
Default character used for splitting input and output. See setValues.
Definition SmartMap.h:85
Definition graphics-interactive.h:79
void exec() const override
Run the command with current parameter values.
Definition graphics-interactive.cpp:365
Definition graphics-interactive.h:101
void exec() const override
Run the command with current parameter values.
Definition graphics-interactive.cpp:457
Definition graphics-interactive.h:158
void exec() const override
Definition graphics-interactive.cpp:78
Definition graphics-overlay.h:52
Definition graphics-interactive.h:52
void exec() const override
Run the command with current parameter values.
Definition graphics-interactive.cpp:201
Definition graphics-interactive.h:122
void exec() const override
Run the command with current parameter values.
Definition graphics-interactive.cpp:567
Definition DataSelector.cpp:44
Definition Point.h:48
Default implementation.
Definition TypeName.h:57