1 //                                               -*- C++ -*-
2 /**
3  *  @brief Abstract top-level class for all Drawable
4  *
5  *  Copyright 2005-2021 Airbus-EDF-IMACS-ONERA-Phimeca
6  *
7  *  This library is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU Lesser General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This library is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU Lesser General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Lesser General Public License
18  *  along with this library.  If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 #include "openturns/Drawable.hxx"
22 #include "openturns/Curve.hxx"
23 
24 BEGIN_NAMESPACE_OPENTURNS
25 
CLASSNAMEINIT(Drawable)26 CLASSNAMEINIT(Drawable)
27 
28 /* Default constructor */
29 Drawable::Drawable():
30   TypedInterfaceObject<DrawableImplementation>(Curve(Sample(1, 2)).clone())
31 {
32   // Nothing to do
33 }
34 
35 /* Default constructor */
Drawable(const DrawableImplementation & implementation)36 Drawable::Drawable(const DrawableImplementation & implementation):
37   TypedInterfaceObject<DrawableImplementation>(implementation.clone())
38 {
39   // Nothing to do
40 }
41 
42 /* String converter */
__repr__() const43 String Drawable::__repr__() const
44 {
45   OSS oss;
46   oss << "class=" << Drawable::GetClassName()
47       << " name=" << getName()
48       << " implementation=" << getImplementation()->__repr__();
49   return oss;
50 }
51 
52 /* Here is the interface */
53 
54 /* Accessor for bounding box of the drawable */
getBoundingBox() const55 Interval Drawable::getBoundingBox() const
56 {
57   return getImplementation()->getBoundingBox();
58 }
59 
60 /* Accessor for legend */
getLegend() const61 String Drawable::getLegend() const
62 {
63   return getImplementation()->getLegend();
64 }
65 
66 /* Accessor for legend */
setLegend(const String & legend)67 void Drawable::setLegend(const String & legend)
68 {
69   copyOnWrite();
70   getImplementation()->setLegend(legend);
71 }
72 
73 /* Accessor for legend line style */
getLineStyle() const74 String Drawable::getLineStyle() const
75 {
76   return getImplementation()->getLineStyle();
77 }
78 
79 /* Accessor for legend point style */
setLineStyle(const String & lineStyle)80 void Drawable::setLineStyle(const String & lineStyle)
81 {
82   copyOnWrite();
83   getImplementation()->setLineStyle(lineStyle);
84 }
85 
86 /* Accessor for legend point style */
getPointStyle() const87 String Drawable::getPointStyle() const
88 {
89   return getImplementation()->getPointStyle();
90 }
91 
92 /* Accessor for legend point style */
setPointStyle(const String & pointStyle)93 void Drawable::setPointStyle(const String & pointStyle)
94 {
95   copyOnWrite();
96   getImplementation()->setPointStyle(pointStyle);
97 }
98 
99 /* Accessor for legend fill style */
getFillStyle() const100 String Drawable::getFillStyle() const
101 {
102   return getImplementation()->getFillStyle();
103 }
104 
105 /* Accessor for legend fill style */
setFillStyle(const String & fillStyle)106 void Drawable::setFillStyle(const String & fillStyle)
107 {
108   copyOnWrite();
109   getImplementation()->setFillStyle(fillStyle);
110 }
111 
112 /* Accessor for color */
getColor() const113 String Drawable::getColor() const
114 {
115   return getImplementation()->getColor();
116 }
117 
getColorCode() const118 String Drawable::getColorCode() const
119 {
120   return getImplementation()->getColorCode();
121 }
122 
123 /* Accessor for color */
setColor(const String & color)124 void Drawable::setColor(const String & color)
125 {
126   copyOnWrite();
127   getImplementation()->setColor(color);
128 }
129 
getEdgeColor() const130 String Drawable::getEdgeColor() const
131 {
132   return getImplementation()->getEdgeColor();
133 }
134 
135 /* Accessor for line width */
getLineWidth() const136 Scalar Drawable::getLineWidth() const
137 {
138   return getImplementation()->getLineWidth();
139 }
140 
141 /* Accessor for line width */
setLineWidth(const Scalar lineWidth)142 void Drawable::setLineWidth(const Scalar lineWidth)
143 {
144   copyOnWrite();
145   getImplementation()->setLineWidth(lineWidth);
146 }
147 
148 /* Accessor for pattern */
getPattern() const149 String Drawable::getPattern() const
150 {
151   return getImplementation()->getPattern();
152 }
153 
setPattern(const String style)154 void Drawable::setPattern(const String style)
155 {
156   copyOnWrite();
157   getImplementation()->setPattern(style);
158 }
159 
160 /* Accessor for center */
getCenter() const161 Point Drawable::getCenter() const
162 {
163   return getImplementation()->getCenter();
164 }
165 
setCenter(const Point & center)166 void Drawable::setCenter(const Point & center)
167 {
168   copyOnWrite();
169   getImplementation()->setCenter(center);
170 }
171 
172 /* Accessor for radius */
getRadius() const173 Scalar Drawable::getRadius() const
174 {
175   return getImplementation()->getRadius();
176 }
177 
setRadius(const Scalar radius)178 void Drawable::setRadius(const Scalar radius)
179 {
180   copyOnWrite();
181   getImplementation()->setRadius(radius);
182 }
183 
184 /* Accessor for labels */
getLabels() const185 Description Drawable::getLabels() const
186 {
187   return getImplementation()->getLabels();
188 }
189 
setLabels(const Description & labels)190 void Drawable::setLabels(const Description & labels)
191 {
192   copyOnWrite();
193   getImplementation()->setLabels(labels);
194 }
195 
196 /* Accessor for color palette */
getPalette() const197 Description Drawable::getPalette() const
198 {
199   return getImplementation()->getPalette();
200 }
201 
setPalette(const Description & palette)202 void Drawable::setPalette(const Description & palette)
203 {
204   copyOnWrite();
205   getImplementation()->setPalette(palette);
206 }
207 
getPaletteAsNormalizedRGBA() const208 Sample Drawable::getPaletteAsNormalizedRGBA() const
209 {
210   return getImplementation()->getPaletteAsNormalizedRGBA();
211 }
212 
213 /* Accessor for origin */
getOrigin() const214 Scalar Drawable::getOrigin() const
215 {
216   return getImplementation()->getOrigin();
217 }
218 
setOrigin(const Scalar origin)219 void Drawable::setOrigin(const Scalar origin)
220 {
221   copyOnWrite();
222   getImplementation()->setOrigin(origin);
223 }
224 
225 /* Accessor for first coordinate */
getX() const226 Sample Drawable::getX() const
227 {
228   return getImplementation()->getX();
229 }
230 
setX(const Sample & x)231 void Drawable::setX(const Sample & x)
232 {
233   copyOnWrite();
234   getImplementation()->setX(x);
235 }
236 
237 /* Accessor for second coordinate */
getY() const238 Sample Drawable::getY() const
239 {
240   return getImplementation()->getY();
241 }
242 
setY(const Sample & y)243 void Drawable::setY(const Sample & y)
244 {
245   copyOnWrite();
246   getImplementation()->setY(y);
247 }
248 
249 /* Accessor for levels */
getLevels() const250 Point Drawable::getLevels() const
251 {
252   return getImplementation()->getLevels();
253 }
254 
setLevels(const Point & levels)255 void Drawable::setLevels(const Point & levels)
256 {
257   copyOnWrite();
258   getImplementation()->setLevels(levels);
259 }
260 
261 /* Accessor for drawLabels */
getDrawLabels() const262 Bool Drawable::getDrawLabels() const
263 {
264   return getImplementation()->getDrawLabels();
265 }
266 
setDrawLabels(const Bool & drawLabels)267 void Drawable::setDrawLabels(const Bool & drawLabels)
268 {
269   copyOnWrite();
270   getImplementation()->setDrawLabels(drawLabels);
271 }
272 
273 /* Accessor for textAnnotations */
getTextAnnotations() const274 Description Drawable::getTextAnnotations() const
275 {
276   return getImplementation()->getTextAnnotations();
277 }
278 
setTextAnnotations(const Description & textAnnotations)279 void Drawable::setTextAnnotations(const Description & textAnnotations)
280 {
281   copyOnWrite();
282   getImplementation()->setTextAnnotations(textAnnotations);
283 }
284 
285 /* Accessor for textPositions */
getTextPositions() const286 Description Drawable::getTextPositions() const
287 {
288   return getImplementation()->getTextPositions();
289 }
290 
setTextPositions(const Description & textPositions)291 void Drawable::setTextPositions(const Description & textPositions)
292 {
293   copyOnWrite();
294   getImplementation()->setTextPositions(textPositions);
295 }
296 
297 /* Accessor for font size */
getTextSize() const298 Scalar Drawable::getTextSize() const
299 {
300   return getImplementation()->getTextSize();
301 }
302 
setTextSize(const Scalar size)303 void Drawable::setTextSize(const Scalar size)
304 {
305   copyOnWrite();
306   getImplementation()->setTextSize(size);
307 }
308 
309 /* Accessor for data */
getData() const310 Sample Drawable::getData() const
311 {
312   return getImplementation()->getData();
313 }
314 
315 /* Generate de R commands for plotting  the graphic */
draw() const316 String Drawable::draw() const
317 {
318   return getImplementation()->draw();
319 }
320 
321 /* Clean all the temporary data created by draw() method */
clean() const322 void Drawable::clean() const
323 {
324   return getImplementation()->clean();
325 }
326 
327 /* Get R point code from key */
getPointCode(const String key) const328 UnsignedInteger Drawable::getPointCode(const String key) const
329 {
330   return getImplementation()->getPointCode(key);
331 }
332 
333 /* Give the colors name */
GetValidColors()334 Description Drawable::GetValidColors()
335 {
336   return DrawableImplementation::GetValidColors();
337 }
338 
339 /* Give the line style names */
GetValidLineStyles()340 Description Drawable::GetValidLineStyles()
341 {
342   return DrawableImplementation::GetValidLineStyles();
343 }
344 
345 /* Give the fill style names */
GetValidFillStyles()346 Description Drawable::GetValidFillStyles()
347 {
348   return DrawableImplementation::GetValidFillStyles();
349 }
350 
351 /* Give the point style names */
GetValidPointStyles()352 Description Drawable::GetValidPointStyles()
353 {
354   return DrawableImplementation::GetValidPointStyles();
355 }
356 
357 /* Convert an hexadecimal code into an RGB triplet  */
ConvertToRGB(const String & key)358 Indices Drawable::ConvertToRGB(const String & key)
359 {
360   return DrawableImplementation::ConvertToRGB(key);
361 }
362 
363 /* Convert an hexadecimal code into an RGBA quadruplet  */
ConvertToRGBA(const String & key)364 Indices Drawable::ConvertToRGBA(const String & key)
365 {
366   return DrawableImplementation::ConvertToRGBA(key);
367 }
368 
369 /* Convert an RGB triplet to a valid hexadecimal code */
ConvertFromName(const String & name)370 String Drawable::ConvertFromName(const String & name)
371 {
372   return DrawableImplementation::ConvertFromName(name);
373 }
374 
375 /* Convert an RGB triplet to a valid hexadecimal code */
ConvertFromRGB(const UnsignedInteger red,const UnsignedInteger green,const UnsignedInteger blue)376 String Drawable::ConvertFromRGB(const UnsignedInteger red,
377                                 const UnsignedInteger green,
378                                 const UnsignedInteger blue)
379 {
380   return DrawableImplementation::ConvertFromRGB(red, green, blue);
381 }
382 
383 /* Convert an RGBA quadruplet to a valid hexadecimal code */
ConvertFromRGBA(const UnsignedInteger red,const UnsignedInteger green,const UnsignedInteger blue,const UnsignedInteger alpha)384 String Drawable::ConvertFromRGBA(const UnsignedInteger red,
385                                  const UnsignedInteger green,
386                                  const UnsignedInteger blue,
387                                  const UnsignedInteger alpha)
388 {
389   return DrawableImplementation::ConvertFromRGBA(red, green, blue, alpha);
390 }
391 
392 /* Convert an RGB triplet to a valid hexadecimal code */
ConvertFromRGB(const Scalar red,const Scalar green,const Scalar blue)393 String Drawable::ConvertFromRGB(const Scalar red,
394                                 const Scalar green,
395                                 const Scalar blue)
396 {
397   return DrawableImplementation::ConvertFromRGB(red, green, blue);
398 }
399 
400 /* Convert an RGBA quadruplet to a valid hexadecimal code */
ConvertFromRGBA(const Scalar red,const Scalar green,const Scalar blue,const Scalar alpha)401 String Drawable::ConvertFromRGBA(const Scalar red,
402                                  const Scalar green,
403                                  const Scalar blue,
404                                  const Scalar alpha)
405 {
406   return DrawableImplementation::ConvertFromRGBA(red, green, blue, alpha);
407 }
408 
409 /* Convert an HSV triplet into an RGB triplet */
ConvertFromHSVIntoRGB(const Scalar hue,const Scalar saturation,const Scalar value)410 Point Drawable::ConvertFromHSVIntoRGB(const Scalar hue,
411                                       const Scalar saturation,
412                                       const Scalar value)
413 {
414   return DrawableImplementation::ConvertFromHSVIntoRGB(hue, saturation, value);
415 }
416 
417 /* Convert an RGB triplet into an HSV triplet */
ConvertFromRGBIntoHSV(const UnsignedInteger red,const UnsignedInteger green,const UnsignedInteger blue)418 Point Drawable::ConvertFromRGBIntoHSV(const UnsignedInteger red,
419                                       const UnsignedInteger green,
420                                       const UnsignedInteger blue)
421 {
422   return DrawableImplementation::ConvertFromRGBIntoHSV(red, green, blue);
423 }
424 
425 /* Convert an RGB triplet into an HSV triplet */
ConvertFromRGBIntoHSV(const Scalar red,const Scalar green,const Scalar blue)426 Point Drawable::ConvertFromRGBIntoHSV(const Scalar red,
427                                       const Scalar green,
428                                       const Scalar blue)
429 {
430   return DrawableImplementation::ConvertFromRGBIntoHSV(red, green, blue);
431 }
432 
433 /* Convert an HSV triplet to a valid hexadecimal code */
ConvertFromHSV(const Scalar hue,const Scalar saturation,const Scalar value)434 String Drawable::ConvertFromHSV(const Scalar hue,
435                                 const Scalar saturation,
436                                 const Scalar value)
437 {
438   return DrawableImplementation::ConvertFromHSV(hue, saturation, value);
439 }
440 
441 /* Convert an HSVA quadruplet to a valid hexadecimal code */
ConvertFromHSVA(const Scalar hue,const Scalar saturation,const Scalar value,const Scalar alpha)442 String Drawable::ConvertFromHSVA(const Scalar hue,
443                                  const Scalar saturation,
444                                  const Scalar value,
445                                  const Scalar alpha)
446 {
447   return DrawableImplementation::ConvertFromHSVA(hue, saturation, value, alpha);
448 }
449 
450 /* Build default palette */
BuildDefaultPalette(const UnsignedInteger size)451 Description Drawable::BuildDefaultPalette(const UnsignedInteger size)
452 {
453   return DrawableImplementation::BuildDefaultPalette(size);
454 }
455 
456 /* Build rainbow palette
457    Cycle through the hue wheel with 10 nuances and increasing darkness */
BuildRainbowPalette(const UnsignedInteger size)458 Description Drawable::BuildRainbowPalette(const UnsignedInteger size)
459 {
460   return DrawableImplementation::BuildRainbowPalette(size);
461 }
462 
463 /* Build tableau palette
464    Use 10 colors from Tableau palette. */
BuildTableauPalette(const UnsignedInteger size)465 Description Drawable::BuildTableauPalette(const UnsignedInteger size)
466 {
467   return DrawableImplementation::BuildTableauPalette(size);
468 }
469 
470 END_NAMESPACE_OPENTURNS
471