A toolkit for working with phylogenetic data.
v0.19.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
shapes.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_UTILS_FORMATS_SVG_SHAPES_H_
2 #define GENESIS_UTILS_FORMATS_SVG_SHAPES_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2017 Lucas Czech
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lucas.czech@h-its.org>
23  Exelixis Lab, Heidelberg Institute for Theoretical Studies
24  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
25 */
26 
36 
37 #include <iosfwd>
38 #include <string>
39 #include <vector>
40 
41 namespace genesis {
42 namespace utils {
43 
44 // =================================================================================================
45 // Svg Line
46 // =================================================================================================
47 
48 struct SvgLine
49 {
50 public:
51 
52  // -------------------------------------------------------------
53  // Typedefs and Enums
54  // -------------------------------------------------------------
55 
56  using self_type = SvgLine;
57 
58  // -------------------------------------------------------------
59  // Constructors and Rule of Five
60  // -------------------------------------------------------------
61 
62  SvgLine(
63  SvgPoint const& point_1,
64  SvgPoint const& point_2,
65  SvgStroke const& stroke = SvgStroke()
66  );
67 
68  SvgLine(
69  double x1, double y1,
70  double x2, double y2,
71  SvgStroke const& stroke = SvgStroke()
72  );
73 
74  ~SvgLine() = default;
75 
76  SvgLine( SvgLine const& ) = default;
77  SvgLine( SvgLine&& ) = default;
78 
79  SvgLine& operator= ( SvgLine const& ) = default;
80  SvgLine& operator= ( SvgLine&& ) = default;
81 
82  // -------------------------------------------------------------
83  // Drawing Function
84  // -------------------------------------------------------------
85 
86  SvgBox bounding_box() const;
87 
88  void write(
89  std::ostream& out,
90  size_t indent = 0,
91  SvgDrawingOptions const& options = SvgDrawingOptions()
92  ) const;
93 
94  // -------------------------------------------------------------
95  // Properties
96  // -------------------------------------------------------------
97 
98  std::string id;
103 
104 };
105 
106 // =================================================================================================
107 // Svg Rect
108 // =================================================================================================
109 
110 struct SvgRect
111 {
112 public:
113 
114  // -------------------------------------------------------------
115  // Typedefs and Enums
116  // -------------------------------------------------------------
117 
119 
120  // -------------------------------------------------------------
121  // Constructors and Rule of Five
122  // -------------------------------------------------------------
123 
124  SvgRect(
125  SvgPoint const& position,
126  SvgSize const& size,
127  SvgStroke const& stroke = SvgStroke(),
128  SvgFill const& fill = SvgFill()
129  );
130 
131  SvgRect(
132  double x, double y,
133  double w, double h,
134  SvgStroke const& stroke = SvgStroke(),
135  SvgFill const& fill = SvgFill()
136  );
137 
138  ~SvgRect() = default;
139 
140  SvgRect( SvgRect const& ) = default;
141  SvgRect( SvgRect&& ) = default;
142 
143  SvgRect& operator= ( SvgRect const& ) = default;
144  SvgRect& operator= ( SvgRect&& ) = default;
145 
146  // -------------------------------------------------------------
147  // Drawing Function
148  // -------------------------------------------------------------
149 
150  SvgBox bounding_box() const;
151 
152  void write(
153  std::ostream& out,
154  size_t indent = 0,
155  SvgDrawingOptions const& options = SvgDrawingOptions()
156  ) const;
157 
158  // -------------------------------------------------------------
159  // Properties
160  // -------------------------------------------------------------
161 
162  std::string id;
163 
166 
169 
170  double rx;
171  double ry;
172 
174 
175 };
176 
177 // =================================================================================================
178 // Svg Circle
179 // =================================================================================================
180 
181 struct SvgCircle
182 {
183 public:
184 
185  // -------------------------------------------------------------
186  // Typedefs and Enums
187  // -------------------------------------------------------------
188 
190 
191  // -------------------------------------------------------------
192  // Constructors and Rule of Five
193  // -------------------------------------------------------------
194 
195  SvgCircle(
196  SvgPoint const& center,
197  double radius,
198  SvgStroke const& stroke = SvgStroke(),
199  SvgFill const& fill = SvgFill()
200  );
201 
202  SvgCircle(
203  double cx, double cy,
204  double radius,
205  SvgStroke const& stroke = SvgStroke(),
206  SvgFill const& fill = SvgFill()
207  );
208 
209  ~SvgCircle() = default;
210 
211  SvgCircle( SvgCircle const& ) = default;
212  SvgCircle( SvgCircle&& ) = default;
213 
214  SvgCircle& operator= ( SvgCircle const& ) = default;
215  SvgCircle& operator= ( SvgCircle&& ) = default;
216 
217  // -------------------------------------------------------------
218  // Drawing Function
219  // -------------------------------------------------------------
220 
221  SvgBox bounding_box() const;
222 
223  void write(
224  std::ostream& out,
225  size_t indent = 0,
226  SvgDrawingOptions const& options = SvgDrawingOptions()
227  ) const;
228 
229  // -------------------------------------------------------------
230  // Properties
231  // -------------------------------------------------------------
232 
233  std::string id;
234 
236  double radius;
237 
240 
242 
243 };
244 
245 // =================================================================================================
246 // Svg Ellipse
247 // =================================================================================================
248 
250 {
251 public:
252 
253  // -------------------------------------------------------------
254  // Typedefs and Enums
255  // -------------------------------------------------------------
256 
258 
259  // -------------------------------------------------------------
260  // Constructors and Rule of Five
261  // -------------------------------------------------------------
262 
263  SvgEllipse(
264  SvgPoint const& center,
265  double rx, double ry,
266  SvgStroke const& stroke = SvgStroke(),
267  SvgFill const& fill = SvgFill()
268  );
269 
270  SvgEllipse(
271  double cx, double cy,
272  double rx, double ry,
273  SvgStroke const& stroke = SvgStroke(),
274  SvgFill const& fill = SvgFill()
275  );
276 
277  ~SvgEllipse() = default;
278 
279  SvgEllipse( SvgEllipse const& ) = default;
280  SvgEllipse( SvgEllipse&& ) = default;
281 
282  SvgEllipse& operator= ( SvgEllipse const& ) = default;
283  SvgEllipse& operator= ( SvgEllipse&& ) = default;
284 
285  // -------------------------------------------------------------
286  // Drawing Function
287  // -------------------------------------------------------------
288 
289  SvgBox bounding_box() const;
290 
291  void write(
292  std::ostream& out,
293  size_t indent = 0,
294  SvgDrawingOptions const& options = SvgDrawingOptions()
295  ) const;
296 
297  // -------------------------------------------------------------
298  // Properties
299  // -------------------------------------------------------------
300 
301  std::string id;
302 
304  double rx;
305  double ry;
306 
309 
311 
312 };
313 
314 // =================================================================================================
315 // Svg Polyline
316 // =================================================================================================
317 
319 {
320 public:
321 
322  // -------------------------------------------------------------
323  // Typedefs and Enums
324  // -------------------------------------------------------------
325 
327 
328  // -------------------------------------------------------------
329  // Constructors and Rule of Five
330  // -------------------------------------------------------------
331 
332  SvgPolyline(
333  SvgStroke const& stroke = SvgStroke(),
334  SvgFill const& fill = SvgFill()
335  );
336 
337  SvgPolyline(
338  std::vector< SvgPoint > points,
339  SvgStroke const& stroke = SvgStroke(),
340  SvgFill const& fill = SvgFill()
341  );
342 
343  ~SvgPolyline() = default;
344 
345  SvgPolyline( SvgPolyline const& ) = default;
346  SvgPolyline( SvgPolyline&& ) = default;
347 
348  SvgPolyline& operator= ( SvgPolyline const& ) = default;
349  SvgPolyline& operator= ( SvgPolyline&& ) = default;
350 
351  // -------------------------------------------------------------
352  // Drawing Function
353  // -------------------------------------------------------------
354 
355  self_type& add( double x, double y );
356  self_type& add( SvgPoint p );
357 
359 
360  SvgBox bounding_box() const;
361 
362  void write(
363  std::ostream& out,
364  size_t indent = 0,
365  SvgDrawingOptions const& options = SvgDrawingOptions()
366  ) const;
367 
368  // -------------------------------------------------------------
369  // Properties
370  // -------------------------------------------------------------
371 
372  std::string id;
373 
374  std::vector< SvgPoint > points;
375 
378 
380 
381 };
382 
383 // =================================================================================================
384 // Svg Polygon
385 // =================================================================================================
386 
388 {
389 public:
390 
391  // -------------------------------------------------------------
392  // Typedefs and Enums
393  // -------------------------------------------------------------
394 
396 
397  // -------------------------------------------------------------
398  // Constructors and Rule of Five
399  // -------------------------------------------------------------
400 
401  SvgPolygon(
402  SvgStroke const& stroke = SvgStroke(),
403  SvgFill const& fill = SvgFill()
404  );
405 
406  SvgPolygon(
407  std::vector< SvgPoint > const& points,
408  SvgStroke const& stroke = SvgStroke(),
409  SvgFill const& fill = SvgFill()
410  );
411 
412  ~SvgPolygon() = default;
413 
414  SvgPolygon( SvgPolygon const& ) = default;
415  SvgPolygon( SvgPolygon&& ) = default;
416 
417  SvgPolygon& operator= ( SvgPolygon const& ) = default;
418  SvgPolygon& operator= ( SvgPolygon&& ) = default;
419 
420  // -------------------------------------------------------------
421  // Drawing Function
422  // -------------------------------------------------------------
423 
424  self_type& add( double x, double y );
425  self_type& add( SvgPoint p );
426 
428 
429  SvgBox bounding_box() const;
430 
431  void write(
432  std::ostream& out,
433  size_t indent = 0,
434  SvgDrawingOptions const& options = SvgDrawingOptions()
435  ) const;
436 
437  // -------------------------------------------------------------
438  // Properties
439  // -------------------------------------------------------------
440 
441  std::string id;
442 
443  std::vector< SvgPoint > points;
444 
447 
449 
450 };
451 
452 // =================================================================================================
453 // Svg Path
454 // =================================================================================================
455 
456 struct SvgPath
457 {
458 public:
459 
460  // -------------------------------------------------------------
461  // Typedefs and Enums
462  // -------------------------------------------------------------
463 
465 
466  // -------------------------------------------------------------
467  // Constructors and Rule of Five
468  // -------------------------------------------------------------
469 
470  SvgPath(
471  SvgStroke const& stroke = SvgStroke(),
472  SvgFill const& fill = SvgFill()
473  );
474 
475  SvgPath(
476  std::vector< std::string > const& elements,
477  SvgStroke const& stroke = SvgStroke(),
478  SvgFill const& fill = SvgFill()
479  );
480 
481  ~SvgPath() = default;
482 
483  SvgPath( SvgPath const& ) = default;
484  SvgPath( SvgPath&& ) = default;
485 
486  SvgPath& operator= ( SvgPath const& ) = default;
487  SvgPath& operator= ( SvgPath&& ) = default;
488 
489  // -------------------------------------------------------------
490  // Drawing Function
491  // -------------------------------------------------------------
492 
493  self_type& add( std::string elem );
494 
495  self_type& operator <<( std::string elem );
496 
497  SvgBox bounding_box() const;
498 
499  void write(
500  std::ostream& out,
501  size_t indent = 0,
502  SvgDrawingOptions const& options = SvgDrawingOptions()
503  ) const;
504 
505  // -------------------------------------------------------------
506  // Properties
507  // -------------------------------------------------------------
508 
509  std::string id;
510 
511  std::vector< std::string > elements;
512 
515 
517 
518 };
519 
520 // =================================================================================================
521 // Svg Use
522 // =================================================================================================
523 
524 struct SvgUse
525 {
526 public:
527 
528  // -------------------------------------------------------------
529  // Typedefs and Enums
530  // -------------------------------------------------------------
531 
532  using self_type = SvgUse;
533 
534  // -------------------------------------------------------------
535  // Constructors and Rule of Five
536  // -------------------------------------------------------------
537 
539  std::string const& id,
540  SvgPoint const& offset
541  )
542  : referenced_id( id )
543  , offset( offset )
544  {}
545 
547  std::string const& id,
548  double offset_x,
549  double offset_y
550  )
551  : referenced_id( id )
552  , offset( offset_x, offset_y )
553  {}
554 
555  ~SvgUse() = default;
556 
557  SvgUse( SvgUse const& ) = default;
558  SvgUse( SvgUse&& ) = default;
559 
560  SvgUse& operator= ( SvgUse const& ) = default;
561  SvgUse& operator= ( SvgUse&& ) = default;
562 
563  // -------------------------------------------------------------
564  // Drawing Function
565  // -------------------------------------------------------------
566 
567  SvgBox bounding_box() const;
568 
569  void write(
570  std::ostream& out,
571  size_t indent = 0,
572  SvgDrawingOptions const& options = SvgDrawingOptions()
573  ) const;
574 
575  // -------------------------------------------------------------
576  // Properties
577  // -------------------------------------------------------------
578 
579  std::string referenced_id;
582 
583 };
584 
585 } // namespace utils
586 } // namespace genesis
587 
588 #endif // include guard
self_type & add(double x, double y)
Definition: shapes.cpp:404
void write(std::ostream &out, size_t indent=0, SvgDrawingOptions const &options=SvgDrawingOptions()) const
Definition: shapes.cpp:349
SvgCircle(SvgPoint const &center, double radius, SvgStroke const &stroke=SvgStroke(), SvgFill const &fill=SvgFill())
Definition: shapes.cpp:165
SvgTransform transform
Definition: shapes.hpp:102
SvgPolygon & operator=(SvgPolygon const &)=default
void write(std::ostream &out, size_t indent=0, SvgDrawingOptions const &options=SvgDrawingOptions()) const
Definition: shapes.cpp:259
SvgTransform transform
Definition: shapes.hpp:173
self_type & operator<<(SvgPoint p)
Definition: shapes.cpp:320
SvgBox bounding_box() const
Definition: shapes.cpp:65
SvgTransform transform
Definition: shapes.hpp:516
void write(std::ostream &out, size_t indent=0, SvgDrawingOptions const &options=SvgDrawingOptions()) const
Definition: shapes.cpp:73
SvgPath & operator=(SvgPath const &)=default
SvgTransform transform
Definition: shapes.hpp:448
SvgBox bounding_box() const
Definition: shapes.cpp:546
SvgEllipse(SvgPoint const &center, double rx, double ry, SvgStroke const &stroke=SvgStroke(), SvgFill const &fill=SvgFill())
Definition: shapes.cpp:225
void write(std::ostream &out, size_t indent=0, SvgDrawingOptions const &options=SvgDrawingOptions()) const
Definition: shapes.cpp:132
SvgLine(SvgPoint const &point_1, SvgPoint const &point_2, SvgStroke const &stroke=SvgStroke())
Definition: shapes.cpp:51
SvgBox bounding_box() const
Definition: shapes.cpp:420
SvgTransform transform
Definition: shapes.hpp:581
SvgPolyline & operator=(SvgPolyline const &)=default
self_type & operator<<(SvgPoint p)
Definition: shapes.cpp:415
SvgBox bounding_box() const
Definition: shapes.cpp:190
SvgLine & operator=(SvgLine const &)=default
SvgPath(SvgStroke const &stroke=SvgStroke(), SvgFill const &fill=SvgFill())
Definition: shapes.cpp:477
std::string indent(std::string const &text, std::string const &indentation)
Indent each line of text with indentation and return the result.
Definition: string.cpp:231
SvgRect(SvgPoint const &position, SvgSize const &size, SvgStroke const &stroke=SvgStroke(), SvgFill const &fill=SvgFill())
Definition: shapes.cpp:100
SvgTransform transform
Definition: shapes.hpp:310
SvgRect & operator=(SvgRect const &)=default
self_type & add(double x, double y)
Definition: shapes.cpp:309
SvgBox bounding_box() const
Definition: shapes.cpp:251
void write(std::ostream &out, size_t indent=0, SvgDrawingOptions const &options=SvgDrawingOptions()) const
Definition: shapes.cpp:198
SvgPolygon(SvgStroke const &stroke=SvgStroke(), SvgFill const &fill=SvgFill())
Definition: shapes.cpp:382
self_type & operator<<(std::string elem)
Definition: shapes.cpp:505
void write(std::ostream &out, size_t indent=0, SvgDrawingOptions const &options=SvgDrawingOptions()) const
Definition: shapes.cpp:552
SvgUse & operator=(SvgUse const &)=default
SvgPolyline(SvgStroke const &stroke=SvgStroke(), SvgFill const &fill=SvgFill())
Definition: shapes.cpp:287
SvgEllipse & operator=(SvgEllipse const &)=default
SvgUse(std::string const &id, SvgPoint const &offset)
Definition: shapes.hpp:538
SvgUse(std::string const &id, double offset_x, double offset_y)
Definition: shapes.hpp:546
void write(std::ostream &out, size_t indent=0, SvgDrawingOptions const &options=SvgDrawingOptions()) const
Definition: shapes.cpp:516
std::string referenced_id
Definition: shapes.hpp:579
self_type & add(std::string elem)
Definition: shapes.cpp:499
SvgBox bounding_box() const
Definition: shapes.cpp:325
std::vector< SvgPoint > points
Definition: shapes.hpp:443
SvgCircle & operator=(SvgCircle const &)=default
std::vector< std::string > elements
Definition: shapes.hpp:511
void write(std::ostream &out, size_t indent=0, SvgDrawingOptions const &options=SvgDrawingOptions()) const
Definition: shapes.cpp:444
std::vector< SvgPoint > points
Definition: shapes.hpp:374
SvgTransform transform
Definition: shapes.hpp:241
SvgBox bounding_box() const
Definition: shapes.cpp:127
SvgBox bounding_box() const
Definition: shapes.cpp:510