# Hurricane Documentation

# Hurricane Design Viewer

DisplayStyle.h
1 // -*- C++ -*-
2 //
3 // This file is part of the Coriolis Software.
4 // Copyright (c) UPMC 2008-2020, All Rights Reserved
5 //
6 // +-----------------------------------------------------------------+
7 // | H U R R I C A N E |
8 // | V L S I B a c k e n d D a t a - B a s e |
9 // | |
10 // | Author : Jean-Paul CHAPUT |
11 // | E-mail : Jean-Paul.Chaput@lip6.fr |
12 // | =============================================================== |
13 // | C++ Header : "./hurricane/viewer/DisplayStyle.h" |
14 // +-----------------------------------------------------------------+
15
16
17 #ifndef HURRICANE_DISPLAYSTYLE_H
18 #define HURRICANE_DISPLAYSTYLE_H
19
20 #include <memory>
21 #include <string>
22 #include <QColor>
23 #include <QPen>
24 #include <QBrush>
25 #include "hurricane/Commons.h"
26 #include "hurricane/Name.h"
27 #include "hurricane/viewer/ScreenUtilities.h"
28
29
30 namespace Hurricane {
31
32 class RawDrawingStyle;
33 typedef std::shared_ptr<RawDrawingStyle> DrawingStyle;
34 typedef std::vector <DrawingStyle> DrawingStyles;
35
36
37 // -------------------------------------------------------------------
38 // Class : "DrawingGroup".
39
40 class DrawingGroup {
41 public:
42 // Constructors & Destructors.
43 DrawingGroup ( const Name& name );
44 ~DrawingGroup ();
45 DrawingGroup* getClone ();
46 void qtAllocate ();
47 void qtFree ();
48 // Methods.
49 inline const Name& getName () const;
50 inline const DrawingStyles& getDrawingStyles () const;
51 size_t findIndex ( const Name& key ) const;
52 DrawingStyle find ( const Name& key ) const;
53 DrawingStyle addDrawingStyle ( const Name& key
54 , const std::string& pattern
55 , int red
56 , int green
57 , int blue
58 , int borderWidth
59 , float threshold
60 , bool goMatched
61 );
62 void addDrawingStyle ( DrawingStyle );
63 void toJson ( JsonWriter* ) const;
64 protected:
65 const Name _name;
66 DrawingStyles _drawingStyles;
67 protected:
68 DrawingGroup ( const DrawingGroup& );
69 DrawingGroup& operator= ( const DrawingGroup& );
70
71 };
72
73
74 // -------------------------------------------------------------------
75 // Class : "JsonDrawingGroup".
76
77 class JsonDrawingGroup : public JsonObject {
78 public:
79 static void initialize ();
80 JsonDrawingGroup ( unsigned long flags );
81 ~JsonDrawingGroup ();
82 virtual string getTypeName () const;
83 virtual JsonDrawingGroup* clone ( unsigned long ) const;
84 virtual void toData ( JsonStack& );
85 };
86
87
88 // -------------------------------------------------------------------
89 // Class : "DisplayStyle".
90
91 class DisplayStyle {
92 public:
93 class HSVr {
94 public:
95 inline HSVr ( float hue=1.0, float saturation=1.0, float value=1.0 );
96 inline bool isId () const;
97 inline float getHue () const;
98 inline float getSaturation () const;
99 inline float getValue () const;
100 inline void setHue ( float );
101 inline void setSaturation ( float );
102 inline void setValue ( float );
103 inline void toJson ( JsonWriter* ) const;
104 inline std::string _getString () const;
105 private:
106 float _hue;
107 float _saturation;
108 float _value;
109 };
110
111 public:
112 // Static Members.
113 static const Name Viewer;
114 static const Name Fallback;
115 static const Name Background;
116 static const Name Foreground;
117 static const Name Rubber;
118 static const Name Phantom;
119 static const Name Boundaries;
120 static const Name Marker;
121 static const Name SelectionDraw;
122 static const Name SelectionFill;
123 static const Name Grid;
124 static const Name Spot;
125 static const Name Ghost;
126 static const Name TextRuler;
127 static const Name TextCell;
128 static const Name TextInstance;
129 static const Name TextComponent;
130 static const Name TextReference;
131 static const Name Undef;
132 static const Name UnmatchedGroup;
133
134 static QColor darken ( const QColor& color, const DisplayStyle::HSVr& darkening );
135 // Constructor & Destructor.
136 DisplayStyle ( const Name& name );
137 ~DisplayStyle ();
138
139 // Accessors.
140 const Name& getName () const;
141 inline const std::string& getDescription () const;
142 inline const HSVr& getDarkening () const;
143 const Name& getGroup ( const Name& key ) const;
144 const std::string& getPattern ( const Name& key ) const;
145 QColor getColor ( const Name& key, const HSVr& ) const;
146 QPen getPen ( const Name& key, const HSVr& ) const;
147 QBrush getBrush ( const Name& key, const HSVr& ) const;
148 float getThreshold ( const Name& key ) const;
149 inline const std::vector<DrawingGroup*>& getDrawingGroups () const;
150 DrawingStyle find ( const Name& key ) const;
151
152 // Modifiers.
153 void qtAllocate ();
154 void qtFree ();
155 inline void setDescription ( const std::string& description );
156 inline void setDescription ( const char* description );
157 void inheritFrom ( const DisplayStyle* base );
158 void setDarkening ( const HSVr& );
159 void addDrawingStyle ( const Name& groupKey
160 , const Name& key
161 , const std::string& pattern
162 , int red
163 , int green
164 , int blue
165 , int borderWidth
166 , float threshold
167 , bool goMatched =true
168 );
169 DrawingGroup* findGroup ( const Name& groupKey );
170 void findOrCreate ( const Name& groupKey, size_t& gi );
171 void toJson ( JsonWriter* ) const;
172
173 protected:
174 // Internals - Attributes.
175 const Name _name;
176 std::string _description;
177 std::vector<DrawingGroup*> _groups;
178 HSVr _darkening;
179
180 // Internals - Methods.
181 void find ( const Name& groupKey
182 , const Name& key
183 , size_t& gi
184 , size_t& si ) const;
185
186 };
187
188
189 // -------------------------------------------------------------------
190 // Class : "JsonDisplayStyle".
191
192 class JsonDisplayStyle : public JsonObject {
193 public:
194 static void initialize ();
195 JsonDisplayStyle ( unsigned long flags );
196 ~JsonDisplayStyle ();
197 virtual string getTypeName () const;
198 virtual JsonDisplayStyle* clone ( unsigned long ) const;
199 virtual void toData ( JsonStack& );
200 };
201
202
203 // -------------------------------------------------------------------
204 // Class : "JsonHSVr".
205
206 class JsonHSVr : public JsonObject {
207 public:
208 static void initialize ();
209 JsonHSVr ( unsigned long flags );
210 ~JsonHSVr ();
211 virtual string getTypeName () const;
212 virtual JsonHSVr* clone ( unsigned long ) const;
213 virtual void toData ( JsonStack& );
214 };
215
216
217 // -------------------------------------------------------------------
218 // Class : "RawDrawingStyle".
219
220 class RawDrawingStyle {
221 public:
222 // Constructors & Destructors.
223 static DrawingStyle create ( const Name& name
224 , const std::string& pattern ="FFFFFFFFFFFFFFFF"
225 , int red =0
226 , int green =0
227 , int blue =0
228 , int borderWidth=0
229 , float threshold =1.0
230 , bool goMatched =true
231 );
232 public:
233 // Accessors.
234 void qtAllocate ();
235 void qtFree ();
236 inline bool isGoMatched () const;
237 inline const Name& getName () const;
238 inline const std::string& getPattern () const;
239 QColor getColor ( const DisplayStyle::HSVr& ) const;
240 QPen getPen ( const DisplayStyle::HSVr& ) const;
241 QBrush getBrush ( const DisplayStyle::HSVr& ) const;
242 inline float getThreshold () const;
243 void toJson ( JsonWriter* ) const;
244 private:
245 // Internal - Attributes.
246 const Name _name;
247 int _red;
248 int _green;
249 int _blue;
250 int _borderWidth;
251 std::string _pattern;
252 QColor* _color;
253 QPen* _pen;
254 QBrush* _brush;
255 float _threshold;
256 bool _goMatched;
257 public:
258 // Internal - Constructors & Destructors.
259 RawDrawingStyle ( const Name& name
260 , const std::string& pattern
261 , int red
262 , int green
263 , int blue
264 , int borderWidth
265 , float threshold
266 , bool goMatched
267 );
268 RawDrawingStyle ( const RawDrawingStyle& );
269 ~RawDrawingStyle ();
270 private:
271 RawDrawingStyle& operator= ( const RawDrawingStyle& );
272 };
273
274
275 // -------------------------------------------------------------------
276 // Class : "JsonDrawingStyle".
277
278 class JsonDrawingStyle : public JsonObject {
279 public:
280 static void initialize ();
281 JsonDrawingStyle ( unsigned long flags );
282 ~JsonDrawingStyle ();
283 virtual string getTypeName () const;
284 virtual JsonDrawingStyle* clone ( unsigned long ) const;
285 virtual void toData ( JsonStack& );
286 };
287
288
289 // -------------------------------------------------------------------
290 // Inline Functions.
291
292 inline bool RawDrawingStyle::isGoMatched () const { return _goMatched; }
293 inline const Name& RawDrawingStyle::getName () const { return _name; }
294 inline const std::string& RawDrawingStyle::getPattern () const { return _pattern; }
295 inline float RawDrawingStyle::getThreshold () const { return _threshold; }
296
297 inline const Name& DisplayStyle::getName () const { return _name; }
298 inline const std::vector<DrawingGroup*>& DisplayStyle::getDrawingGroups () const { return _groups; }
299 inline const DisplayStyle::HSVr& DisplayStyle::getDarkening () const { return _darkening; }
300 inline const std::string& DisplayStyle::getDescription () const { return _description; }
301 inline void DisplayStyle::setDescription ( const std::string& description ) { _description = description; }
302 inline void DisplayStyle::setDescription ( const char* description ) { _description = description; }
303
304 inline DisplayStyle::HSVr::HSVr ( float hue, float saturation, float value )
305 : _hue(hue), _saturation(saturation), _value(value) { }
306
307 inline const Name& DrawingGroup::getName () const { return _name; }
308 inline const DrawingStyles& DrawingGroup::getDrawingStyles () const { return _drawingStyles; }
309
310 inline bool DisplayStyle::HSVr::isId () const { return (_hue==1.0) and (_saturation==1.0) and (_value==1.0); }
311 inline float DisplayStyle::HSVr::getHue () const { return _hue; }
312 inline float DisplayStyle::HSVr::getSaturation () const { return _saturation; }
313 inline float DisplayStyle::HSVr::getValue () const { return _value; }
314 inline void DisplayStyle::HSVr::setHue ( float hue ) { _hue=hue; }
315 inline void DisplayStyle::HSVr::setSaturation ( float saturation ) { _saturation=saturation; }
316 inline void DisplayStyle::HSVr::setValue ( float value ) { _value=value; }
317
318 inline std::string DisplayStyle::HSVr::_getString () const
319 {
320 std::string s = "<HSVr " + getString(_hue)
321 + " " + getString(_saturation)
322 + " " + getString(_value) + ">";
323 return s;
324 }
325
326 inline void DisplayStyle::HSVr::toJson ( JsonWriter* w ) const
327 {
328 w->startObject();
329 jsonWrite( w, "@typename", "HSVr" );
330 jsonWrite( w, "_hue" , _hue );
331 jsonWrite( w, "_saturation", _saturation );
332 jsonWrite( w, "_value" , _value );
333 w->endObject();
334 }
335
336 } // Hurricane namespace.
337
338
339 GETSTRING_VALUE_SUPPORT(Hurricane::DisplayStyle::HSVr);
340
341
342 #endif // HURRICANE_DISPLAYSTYLE_H
Hurricane::DisplayStyle::addDrawingStyle
void addDrawingStyle(const Name &groupKey, const Name &key, const std::string &pattern, int red, int green, int blue, int borderWidth, float threshold, bool goMatched=true)
Hurricane::DisplayStyle::getDarkening
const HSVr & getDarkening() const
Definition: DisplayStyle.h:299
Hurricane::DisplayStyle::getDescription
const std::string & getDescription() const
Definition: DisplayStyle.h:300
Hurricane::DisplayStyle::getPattern
const std::string & getPattern(const Name &key) const
Hurricane::DisplayStyle::getColor
QColor getColor(const Name &key, const HSVr &) const
Hurricane::DisplayStyle::inheritFrom
void inheritFrom(const DisplayStyle *base)
Hurricane::DisplayStyle::darken
static QColor darken(const QColor &color, const DisplayStyle::HSVr &darkening)
Hurricane::DisplayStyle::getName
const Name & getName() const
Definition: DisplayStyle.h:297
Hurricane::JsonObject
Hurricane::Name
Hurricane::DisplayStyle::getBrush
QBrush getBrush(const Name &key, const HSVr &) const
Hurricane::JsonStack
Hurricane::DisplayStyle::qtAllocate
void qtAllocate()
Hurricane::DisplayStyle::getPen
QPen getPen(const Name &key, const HSVr &) const
Hurricane::DisplayStyle::DisplayStyle
DisplayStyle(const Name &name)
Hurricane::DisplayStyle::setDescription
void setDescription(const std::string &description)
Definition: DisplayStyle.h:301
Hurricane::DisplayStyle::setDarkening
void setDarkening(const HSVr &)
Hurricane::DisplayStyle::getGroup
const Name & getGroup(const Name &key) const
Hurricane::DisplayStyle::getDrawingGroups
const std::vector< DrawingGroup * > & getDrawingGroups() const
Definition: DisplayStyle.h:298
Hurricane
Hurricane::DisplayStyle::find
DrawingStyle find(const Name &key) const
Hurricane::DisplayStyle
A complete set of DrawinStyles to uses with the CellWidget.
Definition: DisplayStyle.h:91
Hurricane::DisplayStyle::getThreshold
float getThreshold(const Name &key) const
Hurricane::DisplayStyle::~DisplayStyle
~DisplayStyle()
Hurricane::Rubber