Loading...
Searching...
No Matches
resources-svg.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// # pragma once
33#ifndef RACK_RESOURCES_SVG
34#define RACK_RESOURCES_SVG
35
36#include <string>
37
38#include <drain/image/Image.h>
39#include <drain/image/LayoutSVG.h>
40#include <drain/image/TreeSVG.h>
41#include <drain/image/Alignment.h>
42#include <drain/image/TreeUtilsSVG.h>
43
44
45namespace rack {
46
47
48struct ConfSVG {
49
51
52 IncludeFlagger svgIncludes;
53
56
57 PathPolicyFlagger pathPolicyFlagger = drain::image::FileSVG::ABSOLUTE;
58 std::string pathPolicy = "ABSOLUTE";
59
60 // Could be better here:
61 // bool absolutePaths = true;
62
63 std::string mainTitle = "AUTO"; // redesign?
64 std::string groupIdentifier = ""; // NEW = "AUTO"; // redesign?
65 std::string groupTitle = "AUTO"; // NEW
66 // std::string groupTitleFormatted; dynamic, so better store in data-title attribute
67
68 // On hold...
69 /*
70 typedef drain::EnumFlagger<drain::MultiFlagger<ElemClass> > TitleFlagger;
71 TitleFlagger svgImageTitles; // = ElemClass::TIME|ElemClass::LOCATION|ElemClass::GENERAL;
72 */
73
75
82 sizeConf fontSizes = {15.0, 12.0, 10.0};
83
88 sizeConf boxHeights = {30.0, 25.0, 15.0};
89
90 // int debug = 0;
91
92 inline // maxPerGroup(10), layout(Alignment::HORZ, LayoutSVG::INCR), legend(LEFT, EMBED),
93 ConfSVG() : svgIncludes(drain::image::FileSVG::IncludePolicy::ALL), pathPolicyFlagger(drain::image::FileSVG::PathPolicy::ABSOLUTE), pathPolicy("ABSOLUTE") { // absolutePaths(true){
94 }
95
97
98};
99
100
101
102
103using namespace drain::image;
104
105class GraphicsContext { // : public drain::BasicCommand {
106
107 //
108
109public:
110
111
114
117
119 inline virtual
121
122 // To be protected:
123 drain::image::TreeSVG svgTrack;
124
125 inline
126 drain::image::TreeSVG & getSVG(){
127 return svgTrack;
128 }
129
131
137 inline
138 void ensureScript(const std::string & label, const std::string & code){
139 //drain::JavaScriptXML::ensureJavaScriptFunction()
140 drain::UtilsXML::getHeaderObject(getSVG(), svg::SCRIPT, label) = code;
141 }
142
143
144 // SVG output configuration (layout)
145 ConfSVG svgPanelConf; // under constr
146
147 AlignBase::Axis mainOrientation = AlignBase::Axis::HORZ;
148 //LayoutSVG::Direction mainDirection = LayoutSVG::Direction::INCR;
149 LayoutSVG::DirectionHorz mainDirectionHorz = LayoutSVG::DirectionHorz::RIGHT;
150 LayoutSVG::DirectionVert mainDirectionVert = LayoutSVG::DirectionVert::DOWN;
151
152 // Here AlignSVG::HorzAlign and AlignSVG::VertAlign unused, as they contain no Topol(ogy).
153 CompleteAlignment<const AlignBase::Axis, AlignBase::Axis::HORZ> alignHorz = {MutualAlign::Topol::INSIDE, AlignBase::Pos::UNDEFINED_POS};
154 CompleteAlignment<const AlignBase::Axis, AlignBase::Axis::VERT> alignVert = {MutualAlign::Topol::INSIDE, AlignBase::Pos::UNDEFINED_POS};
155
156 AlignAnchorSVG::anchor_t anchorHorz;
157 AlignAnchorSVG::anchor_t anchorVert;
158
159 //int svgDebug = 0;
160 std::string currentImagePanel;
161
162
164
167 inline
168 drain::image::TreeSVG & getStyle(){
169 return svgTrack[drain::image::svg::STYLE](drain::image::svg::STYLE);
170 };
171
172
173 //drain::image::TreeSVG & getOnLoadScript();
174 drain::image::TreeSVG & ensureOnLoad(const std::string & function);
175
184 drain::image::TreeSVG & getJavaScriptDefs(); //, const std::string & section="cls");
185
187
190 drain::image::TreeSVG & addJavaScripsDef(const std::string & key, const std::string & section="cls");
192
193
194
195
196
197 // TODO: Move to graphicsCtx
202
203 // ?? TODO: Move to graphicsCtx?
204 bool applyInclusion(const drain::FilePath & filepath); // , IncludePolicy fileFormat);
205
209 static
210 drain::image::TreeSVG & ensureAdapterGroup(drain::image::TreeSVG & group);
211
212
213 drain::image::TreeSVG & getCurrentAdapterGroup();
214
216 drain::image::TreeSVG & getImagePanelGroup(const drain::FilePath & filepath, bool unique=false);
217
219 drain::image::TreeSVG & getImagePanelGroup();
220
221 drain::image::TreeSVG & getImagePanelGroup(const drain::Frame2D<int> & frame);
222
224
228 //static
229 drain::image::TreeSVG & getMainGroup();
230
231protected:
232
233 //static
234 virtual
235 drain::image::TreeSVG & getStackedGroup() = 0;
236
237
238};
239
240
241
242
243
244} // rack::
245
246#endif /* RACK */
Flagger accepting values of enum type E.
Definition EnumFlagger.h:56
Extracts and stores directory path, base filename and extension.
Definition FilePath.h:54
Something that has width and height.
Definition Frame.h:53
Tuple of N elements of type T.
Definition UniTuple.h:65
DOC: Add class description.
Definition TreeSVG.h:64
Definition TreeSVG.h:135
Definition TransformSVG.h:103
A map of radar data, indexed by quantity code (DBZH, VRAD, etc).
Definition Data.h:1293
Definition resources-svg.h:105
bool consumeAlignRequest(drain::image::NodeSVG &node)
Some SVG style classes. Identifiers for IMAGE and RECT elements over which TEXT elements will be alig...
Definition resources-svg.cpp:152
GraphicsContext()
Default constructor.
Definition resources-svg.cpp:47
drain::image::TreeSVG & addJavaScripsDef(const std::string &key, const std::string &section="cls")
key => Rack.cls.key = 'key';
Definition resources-svg.cpp:117
static drain::image::TreeSVG & ensureAdapterGroup(drain::image::TreeSVG &group)
Definition resources-svg.cpp:134
drain::image::TreeSVG & getImagePanelGroup()
Returns the last applicable.
Definition resources-svg.cpp:276
drain::image::TreeSVG & getMainGroup()
Top-level GROUP used by Rack. All the graphic elements will be created inside this element.
Definition resources-svg.cpp:203
drain::image::TreeSVG & getStyle()
Some SVG style classes. Identifiers for IMAGE and RECT elements over which TEXT elements will be alig...
Definition resources-svg.h:168
virtual ~GraphicsContext()
Destructor.
Definition resources-svg.h:120
void ensureScript(const std::string &label, const std::string &code)
Reserve slot for JavaScript code.
Definition resources-svg.h:138
drain::image::TreeSVG & getJavaScriptDefs()
Definition resources-svg.cpp:106
Namespace for images and image processing tools.
Definition AccumulationArray.cpp:45
Definition Data.h:1473
Definition AltitudeOp.cpp:42
Definition AlignAnchorSVG.h:77
"Alternative" partial alignment configuration for single object. Partial means that either OBJECT its...
Definition Alignment.h:245
Definition resources-svg.h:48
drain::EnumFlagger< drain::MultiFlagger< drain::image::FileSVG::PathPolicy > > PathPolicyFlagger
SVG file may contain several "modules", for example rows or columns of IMAGE:s. This is the name of t...
Definition resources-svg.h:55
sizeConf boxHeights
Definition resources-svg.h:88
sizeConf fontSizes
Definition resources-svg.h:82