Board  0.9.4
Shapes.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
26 #ifndef _BOARD_SHAPES_H_
27 #define _BOARD_SHAPES_H_
28 
29 #include "board/Point.h"
30 #include "board/Rect.h"
31 #include "board/Path.h"
32 #include "board/Color.h"
33 #include "board/PSFonts.h"
34 #include "board/Tools.h"
35 #include "board/Transforms.h"
36 #include <string>
37 #include <vector>
38 #include <iostream>
39 #include <map>
40 #include <cmath>
41 
42 #ifndef M_PI
43 #define M_PI 3.14159265358979323846
44 #endif
45 
46 #ifndef M_PI_2
47 #define M_PI_2 1.57079632679489661923
48 #endif
49 
50 #if __cplusplus<201100
51 #define override
52 #endif
53 
54 namespace LibBoard {
55 
56 struct ShapeVisitor;
57 
62 struct Shape {
63 
64  enum LineCap { ButtCap = 0, RoundCap, SquareCap };
65  enum LineJoin { MiterJoin = 0, RoundJoin, BevelJoin };
66  enum LineStyle { SolidStyle = 0,
67  DashStyle,
68  DotStyle,
69  DashDotStyle,
70  DashDotDotStyle,
71  DashDotDotDotStyle };
72 
73  enum LineWidthFlag { IgnoreLineWidth, UseLineWidth };
74 
83  inline Shape( Color penColor, Color fillColor,
84  double lineWidth,
85  LineStyle style,
86  const LineCap cap,
87  const LineJoin join,
88  int depth );
89 
93  virtual ~Shape() { }
94 
100  virtual const std::string & name() const;
101 
107  virtual Shape * clone() const = 0;
108 
114  inline bool filled() const { return _fillColor != Color::Null; }
115 
122  virtual Point center(LineWidthFlag lineWidthFlag = IgnoreLineWidth) const;
123 
132  virtual Shape & rotate( double angle, const Point & center ) = 0;
133 
141  virtual Shape & rotate( double angle ) = 0;
142 
151  inline Shape & rotateDeg( double angle, const Point & center );
152 
161  inline Shape & rotateDeg( double angle );
162 
171  virtual Shape & translate( double dx, double dy ) = 0;
172 
182  Shape & moveCenter( double x, double y, LineWidthFlag lineWidthFlag = IgnoreLineWidth);
183 
192  Shape & moveCenter( Point p, LineWidthFlag lineWidthFlag = IgnoreLineWidth );
193 
202  virtual Shape & scale( double sx, double sy ) = 0;
203 
211  virtual Shape & scale( double s ) = 0;
212 
221  Shape & scaleToWidth( double w, LineWidthFlag lineWidthFlag );
222 
231  Shape & scaleToHeight( double h, LineWidthFlag lineWidthFlag );
232 
238  virtual Rect boundingBox( LineWidthFlag ) const = 0;
239 
245  inline Rect bbox( LineWidthFlag ) const;
246 
252  inline Shape & operator--();
253 
259  inline Shape & operator++();
260 
267  virtual void scaleAll( double s ) = 0;
268 
276  virtual void flushPostscript( std::ostream & stream,
277  const TransformEPS & transform ) const = 0;
278 
286  virtual void flushFIG( std::ostream & stream,
287  const TransformFIG & transform,
288  std::map<Color,int> & colormap ) const = 0;
289 
296  virtual void flushSVG( std::ostream & stream,
297  const TransformSVG & transform ) const = 0;
298 
305  virtual void flushTikZ( std::ostream & stream,
306  const TransformTikZ & transform ) const = 0;
307 
308 
312  static void enableLineWidthScaling();
313 
317  static void disableLineWidthScaling();
318 
322  static void setLineWidthScaling(bool );
323 
324  inline int depth() const;
325 
326  virtual void depth( int );
327 
328  virtual void shiftDepth( int shift );
329 
330  inline const Color & penColor() const;
331 
332  inline const Color & fillColor() const;
333 
334  static void setDefaultLineWidth( double );
335  static void setDefaultPenColor( Color );
336  static void setDefaultFillColor( Color );
337  static void setDefaultLineStyle( Shape::LineStyle );
338  static void setDefaultLineCap( Shape::LineCap );
339  static void setDefaultLineJoin( Shape::LineJoin );
340 
345  static double defaultLineWidth();
346 
351  static Color defaultPenColor();
352 
357  static Color defaultFillColor();
358 
363  static Shape::LineStyle defaultLineStyle();
364 
369  static Shape::LineCap defaultLineCap();
370 
375  static Shape::LineJoin defaultLineJoin();
376 
382  virtual void accept( ShapeVisitor & visitor );
383 
389  virtual void accept( const ShapeVisitor & visitor );
390 
391 
392 
393 private:
394 
395  static const std::string _name;
397 protected:
398 
399  static bool _lineWidthScaling;
402  static double _defaultLineWidth;
403  static Color _defaultPenColor;
404  static Color _defaultFillColor;
405  static Shape::LineStyle _defaultLineStyle;
406  static Shape::LineCap _defaultLineCap;
407  static Shape::LineJoin _defaultLineJoin;
408 
409  inline void updateLineWidth(double s);
410 
411  int _depth;
414  double _lineWidth;
415  LineStyle _lineStyle;
416  LineCap _lineCap;
417  LineJoin _lineJoin;
425  std::string svgProperties( const TransformSVG & transform ) const;
426 
427 
433  std::string postscriptProperties( const TransformEPS & transform ) const;
434 
440  std::string tikzProperties( const TransformTikZ & transform ) const;
441 
442 };
443 
452 struct Dot : public Shape {
453 
454  inline Dot( double x, double y,
455  Color color,
456  double lineWidth = Shape::defaultLineWidth(),
457  int depth = -1 );
458 
464  const std::string & name() const override;
465 
466  Point center(LineWidthFlag flage = IgnoreLineWidth) const override;
467 
476  Dot & rotate( double angle, const Point & center ) override;
477 
486  Dot rotated( double angle, const Point & center ) const;
487 
495  Dot & rotate( double angle ) override;
496 
504  Dot rotated( double angle ) const;
505 
514  Dot & translate( double dx, double dy ) override;
515 
524  Dot translated( double dx, double dy ) const;
525 
534  Dot & scale( double sx, double sy ) override;
535 
543  Dot & scale( double s ) override;
544 
555  Dot scaled( double sx, double sy ) const;
556 
566  Dot scaled( double s ) const;
567 
574  void scaleAll( double s ) override;
575 
576  void flushPostscript( std::ostream & stream,
577  const TransformEPS & transform ) const override;
578 
579  void flushFIG( std::ostream & stream,
580  const TransformFIG & transform,
581  std::map<Color,int> & colormap ) const override;
582 
583  void flushSVG( std::ostream & stream,
584  const TransformSVG & transform ) const override;
585 
586  void flushTikZ( std::ostream & stream,
587  const TransformTikZ & transform ) const override;
588 
594  Rect boundingBox( LineWidthFlag ) const override;
595 
596  Dot * clone() const override;
597 
598 private:
599 
600  static const std::string _name;
602 protected:
603  double _x;
604  double _y;
605 };
606 
611 struct Line : public Shape {
612 
624  inline Line( double x1, double y1, double x2, double y2,
625  Color color,
626  double lineWidth = Shape::defaultLineWidth(),
627  const LineStyle lineStyle = Shape::defaultLineStyle(),
628  const LineCap cap = Shape::defaultLineCap(),
629  const LineJoin join = Shape::defaultLineJoin(),
630  int depth = -1 );
631 
641  inline Line( Point a,
642  Point b,
643  Color color,
644  double lineWidth = Shape::defaultLineWidth(),
645  const LineStyle lineStyle = Shape::defaultLineStyle(),
646  const LineCap cap = Shape::defaultLineCap(),
647  const LineJoin join = Shape::defaultLineJoin(),
648  int depth = -1 );
649 
655  const std::string & name() const override;
656 
657  Line & rotate( double angle, const Point & center ) override;
658 
667  Line rotated( double angle, const Point & center ) const;
668 
669  Line & rotate( double angle ) override;
670 
678  Line rotated( double angle ) const;
679 
680 
689  Line & translate( double dx, double dy ) override;
690 
699  Line translated( double dx, double dy ) const;
700 
709  Line & scale( double sx, double sy ) override;
710 
718  Line & scale( double s ) override;
719 
728  Line scaled( double sx, double sy ) const;
729 
737  Line scaled( double s ) const;
738 
745  void scaleAll( double s ) override;
746 
752  Rect boundingBox( LineWidthFlag ) const override;
753 
754  Line * clone() const override;
755 
756  void flushPostscript( std::ostream & stream,
757  const TransformEPS & transform ) const override;
758 
759  void flushFIG( std::ostream & stream,
760  const TransformFIG & transform,
761  std::map<Color,int> & colormap ) const override;
762 
763  void flushSVG( std::ostream & stream,
764  const TransformSVG & transform ) const override;
765 
766  void flushTikZ( std::ostream & stream,
767  const TransformTikZ & transform ) const override;
768 
769 private:
770  static const std::string _name;
772 protected:
773  double _x1;
774  double _y1;
775  double _x2;
776  double _y2;
777 };
778 
783 struct Arrow : public Line {
784 
797  inline Arrow( double x1, double y1, double x2, double y2,
798  Color penColor = Shape::defaultPenColor(),
799  Color fillColor = Shape::defaultFillColor(),
800  double lineWidth = Shape::defaultLineWidth(),
801  const LineStyle lineStyle = Shape::defaultLineStyle(),
802  const LineCap cap = Shape::defaultLineCap(),
803  const LineJoin join = Shape::defaultLineJoin(),
804  int depth = -1 );
805 
811  const std::string & name() const override;
812 
821  Arrow rotated( double angle, const Point & center ) const;
822 
830  Arrow rotated( double angle ) const;
831 
840  Arrow translated( double dx, double dy ) const;
841 
850  Arrow scaled( double sx, double sy ) const;
851 
859  Arrow scaled( double s ) const;
860 
866  Rect boundingBox( LineWidthFlag ) const override;
867 
868  void flushPostscript( std::ostream & stream,
869  const TransformEPS & transform ) const override;
870 
871  void flushFIG( std::ostream & stream,
872  const TransformFIG & transform,
873  std::map<Color,int> & colormap ) const override;
874 
875  void flushSVG( std::ostream & stream,
876  const TransformSVG & transform ) const override;
877 
878  void flushTikZ( std::ostream & stream,
879  const TransformTikZ & transform ) const override;
880 
881  Arrow * clone() const override;
882 
883 private:
884  static const std::string _name;
885 };
886 
891 struct Polyline : public Shape {
892 
893  inline Polyline( const std::vector<Point> & points,
894  bool closed,
895  Color penColor = Shape::defaultPenColor(),
896  Color fillColor = Shape::defaultFillColor(),
897  double lineWidth = Shape::defaultLineWidth(),
898  const LineStyle lineStyle = Shape::defaultLineStyle(),
899  const LineCap cap = Shape::defaultLineCap(),
900  const LineJoin join = Shape::defaultLineJoin(),
901  int depth = -1 );
902 
903  inline Polyline( const Path & path,
904  Color penColor = Shape::defaultPenColor(),
905  Color fillColor = Shape::defaultFillColor(),
906  double lineWidth = Shape::defaultLineWidth(),
907  const LineStyle lineStyle = Shape::defaultLineStyle(),
908  const LineCap cap = Shape::defaultLineCap(),
909  const LineJoin join = Shape::defaultLineJoin(),
910  int depth = -1 );
911 
912  inline Polyline( bool closed,
913  Color penColor = Shape::defaultPenColor(),
914  Color fillColor = Shape::defaultFillColor(),
915  double lineWidth = Shape::defaultLineWidth(),
916  const LineStyle lineStyle = Shape::defaultLineStyle(),
917  const LineCap cap = Shape::defaultLineCap(),
918  const LineJoin join = Shape::defaultLineJoin(),
919  int depth = -1 );
920 
926  const std::string & name() const override;
927 
935  Polyline & operator<<( const Point & p );
936 
944  Point & operator[]( const std::size_t n ) {
945  return _path[ n ];
946  }
947 
955  const Point & operator[]( const std::size_t n ) const {
956  return _path[ n ];
957  }
958 
959  Polyline & rotate( double angle, const Point & center ) override;
960 
969  Polyline rotated( double angle, const Point & center ) const;
970 
971  Polyline & rotate( double angle ) override;
972 
980  Polyline rotated( double angle ) const;
981 
990  Polyline & translate( double dx, double dy ) override;
991 
1000  Polyline translated( double dx, double dy ) const;
1001 
1010  Polyline & scale( double sx, double sy ) override;
1011 
1019  Polyline & scale( double s ) override;
1020 
1029  Polyline scaled( double sx, double sy ) const;
1030 
1038  Polyline scaled( double s ) const;
1039 
1046  void scaleAll( double s ) override;
1047 
1048  void flushPostscript( std::ostream & stream,
1049  const TransformEPS & transform ) const override;
1050 
1051  void flushFIG( std::ostream & stream,
1052  const TransformFIG & transform,
1053  std::map<Color,int> & colormap ) const override;
1054 
1055  void flushSVG( std::ostream & stream,
1056  const TransformSVG & transform ) const override;
1057 
1058  void flushTikZ( std::ostream & stream,
1059  const TransformTikZ & transform ) const override;
1060 
1061  Rect boundingBox( LineWidthFlag ) const override;
1062 
1063  Polyline * clone() const override;
1064 
1065  inline std::size_t vertexCount() const;
1066 
1067  inline const Path & path() const;
1068 
1069 private:
1070  static const std::string _name;
1072 protected:
1073  Path _path;
1074 };
1075 
1080 struct Rectangle : public Polyline {
1081 
1082  inline Rectangle( double left, double top, double width, double height,
1083  Color penColor = Shape::defaultPenColor(),
1084  Color fillColor = Shape::defaultFillColor(),
1085  double lineWidth = Shape::defaultLineWidth(),
1086  const LineStyle lineStyle = Shape::defaultLineStyle(),
1087  const LineCap cap = Shape::defaultLineCap(),
1088  const LineJoin join = Shape::defaultLineJoin(),
1089  int depth = -1 );
1090 
1091  inline Rectangle( const Rect & rect,
1092  Color penColor = Shape::defaultPenColor(),
1093  Color fillColor = Shape::defaultFillColor(),
1094  double lineWidth = Shape::defaultLineWidth(),
1095  const LineStyle lineStyle = Shape::defaultLineStyle(),
1096  const LineCap cap = Shape::defaultLineCap(),
1097  const LineJoin join = Shape::defaultLineJoin(),
1098  int depth = -1 );
1099 
1105  const std::string & name() const override;
1106  double x() const { return _path[0].x; }
1107  double y() const { return _path[0].y; }
1108  double width() const { return (_path[1] - _path[0]).norm(); }
1109  double height() const { return (_path[0] - _path[3]).norm(); }
1110  Point topLeft() const { return Point( _path[0].x, _path[0].y ); }
1111  Point topRight() const { return Point( _path[1].x, _path[1].y ); }
1112  Point bottomLeft() const { return Point( _path[3].x, _path[3].y ); }
1113  Point bottomRight() const { return Point( _path[2].x, _path[2].y ); }
1114 
1123  Rectangle rotated( double angle, const Point & center ) const;
1124 
1132  Rectangle rotated( double angle ) const;
1133 
1142  Rectangle translated( double dx, double dy ) const;
1143 
1152  Rectangle scaled( double sx, double sy ) const;
1153 
1161  Rectangle scaled( double s ) const;
1162 
1169  void scaleAll( double s ) override;
1170 
1171  void flushFIG( std::ostream & stream,
1172  const TransformFIG & transform,
1173  std::map<Color,int> & colormap ) const override;
1174 
1175  void flushSVG( std::ostream & stream,
1176  const TransformSVG & transform ) const override;
1177 
1178  void flushTikZ( std::ostream & stream,
1179  const TransformTikZ & transform ) const override;
1180 
1181  Rectangle * clone() const override;
1182 
1183 private:
1184  static const std::string _name;
1186 protected:
1187  bool _isRectangle;
1188 };
1189 
1190 
1195 struct Triangle : public Polyline {
1196 
1197  Triangle( const Point & p1, const Point & p2, const Point & p3,
1198  Color penColor = Shape::defaultPenColor(),
1199  Color fillColor = Shape::defaultFillColor(),
1200  double lineWidth = Shape::defaultLineWidth(),
1201  const LineStyle lineStyle = Shape::defaultLineStyle(),
1202  const LineCap cap = Shape::defaultLineCap(),
1203  const LineJoin join = Shape::defaultLineJoin(),
1204  int depth = -1 )
1205  : Polyline( std::vector<Point>(), true, penColor, fillColor, lineWidth, lineStyle, cap, join, depth ) {
1206  _path << p1;
1207  _path << p2;
1208  _path << p3;
1209  }
1210 
1211  Triangle( const double x1, const double y1,
1212  const double x2, const double y2,
1213  const double x3, const double y3,
1214  Color penColor = Shape::defaultPenColor(),
1215  Color fillColor = Shape::defaultFillColor(),
1216  double lineWidth = Shape::defaultLineWidth(),
1217  const LineStyle lineStyle = Shape::defaultLineStyle(),
1218  const LineCap cap = Shape::defaultLineCap(),
1219  const LineJoin join = Shape::defaultLineJoin(),
1220  int depth = -1 )
1221  : Polyline( std::vector<Point>(), true, penColor, fillColor, lineWidth, lineStyle, cap, join, depth ) {
1222  _path << Point( x1, y1 );
1223  _path << Point( x2, y2 );
1224  _path << Point( x3, y3 );
1225  }
1226 
1232  const std::string & name() const override;
1233 
1234  Triangle rotated( double angle ) const;
1235 
1244  Triangle translated( double dx, double dy ) const;
1245 
1254  Triangle scaled( double sx, double sy ) const;
1255 
1263  Triangle scaled( double s ) const;
1264 
1265  Triangle * clone() const override;
1266 
1267 private:
1268  static const std::string _name;
1270 protected:
1271 };
1272 
1273 
1278 struct GouraudTriangle : public Polyline {
1279 
1280 
1281  GouraudTriangle( const Point & p0, const Color & color0,
1282  const Point & p1, const Color & color1,
1283  const Point & p2, const Color & color2,
1284  int subdivisions,
1285  int depth = -1 );
1286 
1287  GouraudTriangle( const Point & p0, float brightness0,
1288  const Point & p1, float brightness1,
1289  const Point & p2, float brightness2,
1290  const Color & fillColor,
1291  int subdivisions,
1292  int depth = -1 );
1293 
1299  const std::string & name() const override;
1300 
1301  GouraudTriangle & rotate( double angle, const Point & center ) override;
1302 
1303  GouraudTriangle rotated( double angle, const Point & center ) const;
1304 
1305  GouraudTriangle & rotate( double angle ) override;
1306 
1307  GouraudTriangle rotated( double angle ) const;
1308 
1317  GouraudTriangle translated( double dx, double dy ) const;
1318 
1327  GouraudTriangle scaled( double sx, double sy ) const;
1328 
1336  GouraudTriangle scaled( double s ) const;
1337 
1338 
1345  void scaleAll( double s ) override;
1346 
1353  void flushPostscript( std::ostream & stream,
1354  const TransformEPS & transform ) const override;
1355 
1368  void flushFIG( std::ostream & stream,
1369  const TransformFIG & transform,
1370  std::map<Color,int> & colormap ) const override;
1371 
1372  void flushSVG( std::ostream & stream,
1373  const TransformSVG & transform ) const override;
1374 
1375  void flushTikZ( std::ostream & stream,
1376  const TransformTikZ & transform ) const override;
1377 
1378  GouraudTriangle * clone() const override;
1379 
1380 private:
1381  static const std::string _name;
1383 protected:
1384  Color _color0;
1385  Color _color1;
1386  Color _color2;
1387  int _subdivisions;
1388 };
1389 
1394 struct Ellipse : public Shape {
1395 
1396  Ellipse( double x, double y,
1397  double xRadius, double yRadius,
1398  Color penColor = Shape::defaultPenColor(),
1399  Color fillColor = Shape::defaultFillColor(),
1400  double lineWidth = Shape::defaultLineWidth(),
1401  const LineStyle lineStyle = Shape::defaultLineStyle(),
1402  int depth = -1 )
1403  : Shape( penColor, fillColor,
1404  lineWidth, lineStyle, ButtCap, MiterJoin, depth ),
1405  _center( x, y ), _xRadius( xRadius ), _yRadius( yRadius ),
1406  _angle( 0.0 ),
1407  _circle( false ) {
1408  while ( _angle > M_PI_2 ) _angle -= M_PI;
1409  while ( _angle < -M_PI_2 ) _angle += M_PI;
1410  }
1411 
1412  Ellipse( Point center,
1413  double xRadius, double yRadius,
1414  Color penColor = Shape::defaultPenColor(),
1415  Color fillColor = Shape::defaultFillColor(),
1416  double lineWidth = Shape::defaultLineWidth(),
1417  const LineStyle lineStyle = Shape::defaultLineStyle(),
1418  int depth = -1 )
1419  : Shape( penColor, fillColor,
1420  lineWidth, lineStyle, ButtCap, MiterJoin, depth ),
1421  _center( center ), _xRadius( xRadius ), _yRadius( yRadius ),
1422  _angle( 0.0 ),
1423  _circle( false ) {
1424  while ( _angle > M_PI_2 ) _angle -= M_PI;
1425  while ( _angle < -M_PI_2 ) _angle += M_PI;
1426  }
1427 
1433  const std::string & name() const override;
1434 
1435  Point center(LineWidthFlag lineWidthFlag = IgnoreLineWidth) const override;
1436 
1437  Ellipse & rotate( double angle, const Point & center ) override;
1438 
1447  Ellipse rotated( double angle, const Point & center ) const;
1448 
1449  Ellipse & rotate( double angle ) override;
1450 
1458  Ellipse rotated( double angle ) const;
1459 
1468  Ellipse & translate( double dx, double dy ) override;
1469 
1478  Ellipse translated( double dx, double dy ) const;
1479 
1488  Ellipse & scale( double sx, double sy ) override;
1489 
1497  Ellipse & scale( double s ) override;
1498 
1507  Ellipse scaled( double sx, double sy ) const;
1508 
1516  Ellipse scaled( double s ) const;
1517 
1524  void scaleAll( double s ) override;
1525 
1526  void flushPostscript( std::ostream & stream,
1527  const TransformEPS & transform ) const override;
1528 
1529  void flushFIG( std::ostream & stream,
1530  const TransformFIG & transform,
1531  std::map<Color,int> & colormap ) const override;
1532 
1533  void flushSVG( std::ostream & stream,
1534  const TransformSVG & transform ) const override;
1535 
1536  void flushTikZ( std::ostream & stream,
1537  const TransformTikZ & transform ) const override;
1538 
1539  Rect boundingBox( LineWidthFlag ) const override;
1540 
1541  Ellipse * clone() const override;
1542 
1543 private:
1544  static const std::string _name;
1546 protected:
1547  Point _center;
1548  double _xRadius;
1549  double _yRadius;
1550  double _angle;
1551  bool _circle;
1552 };
1553 
1558 struct Circle : public Ellipse {
1559 
1560  Circle( double x, double y, double radius,
1561  Color penColor = Shape::defaultPenColor(),
1562  Color fillColor = Shape::defaultFillColor(),
1563  double lineWidth = Shape::defaultLineWidth(),
1564  const LineStyle lineStyle = Shape::defaultLineStyle(),
1565  int depth = -1 )
1566  : Ellipse( x, y, radius, radius, penColor, fillColor, lineWidth, lineStyle, depth )
1567  { _circle = true; }
1568 
1569  Circle( Point center, double radius,
1570  Color penColor = Shape::defaultPenColor(),
1571  Color fillColor = Shape::defaultFillColor(),
1572  double lineWidth = Shape::defaultLineWidth(),
1573  const LineStyle lineStyle = Shape::defaultLineStyle(),
1574  int depth = -1 )
1575  : Ellipse( center, radius, radius, penColor, fillColor, lineWidth, lineStyle, depth )
1576  { _circle = true; }
1577 
1583  const std::string & name() const override;
1584 
1585  Point center(LineWidthFlag lineWidthFlag = IgnoreLineWidth) const override;
1586 
1587  Circle & rotate( double angle, const Point & center ) override;
1588 
1589  Circle rotated( double angle, const Point & center ) const;
1590 
1591  Circle & rotate( double angle ) override;
1592 
1593  Circle rotated( double angle ) const;
1594 
1603  Circle & translate( double dx, double dy ) override;
1604 
1613  Circle translated( double dx, double dy ) const;
1614 
1623  Circle & scale( double sx, double sy ) override;
1624 
1632  Circle & scale( double s ) override;
1633 
1642  Circle scaled( double sx, double sy ) const;
1643 
1651  Circle scaled( double s ) const;
1652 
1659  void scaleAll( double s ) override;
1660 
1661  void flushSVG( std::ostream & stream,
1662  const TransformSVG & transform ) const override;
1663 
1664  void flushTikZ( std::ostream & stream,
1665  const TransformTikZ & transform ) const override;
1666 
1667  Circle * clone() const override;
1668 
1669 private:
1670  static const std::string _name;
1671 };
1672 
1677 struct Text : public Shape {
1678 
1692  Text( double x, double y,
1693  const std::string & text,
1694  const Fonts::Font font,
1695  double size,
1696  Color color = Color::Black,
1697  int depth = -1 );
1698 
1711  Text( Point p,
1712  const std::string & text,
1713  const Fonts::Font font,
1714  double size,
1715  Color color = Color::Black,
1716  int depth = -1 );
1717 
1732  Text( double x, double y,
1733  const std::string & text,
1734  const Fonts::Font font,
1735  const std::string & svgFont,
1736  double size,
1737  Color color = Color::Black,
1738  int depth = -1 );
1739 
1753  Text( Point p,
1754  const std::string & text,
1755  const Fonts::Font font,
1756  const std::string & svgFont,
1757  double size,
1758  Color color = Color::Black,
1759  int depth = -1 );
1760 
1766  const std::string & name() const override;
1767 
1768  Point center(LineWidthFlag lineWidthFlag = IgnoreLineWidth) const override;
1769 
1770  Text & rotate( double angle, const Point & center ) override;
1771 
1772  Text rotated( double angle, const Point & center ) const;
1773 
1774  Text & rotate( double angle ) override;
1775 
1776  Text rotated( double angle ) const;
1777 
1786  Text & translate( double dx, double dy ) override;
1787 
1796  Text translated( double dx, double dy ) const;
1797 
1806  Text & scale( double sx, double sy ) override;
1807 
1815  Text & scale( double s ) override;
1816 
1825  Text scaled( double sx, double sy ) const;
1826 
1834  Text scaled( double s ) const;
1835 
1842  void scaleAll( double s ) override;
1843 
1844  void flushPostscript( std::ostream & stream,
1845  const TransformEPS & transform ) const override;
1846 
1847  void flushFIG( std::ostream & stream,
1848  const TransformFIG & transform,
1849  std::map<Color,int> & colormap ) const override;
1850 
1851  void flushSVG( std::ostream & stream,
1852  const TransformSVG & transform ) const override;
1853 
1854  void flushTikZ( std::ostream & stream,
1855  const TransformTikZ & transform ) const override;
1856 
1857  Rect boundingBox( LineWidthFlag ) const override;
1858 
1859  Text * clone() const override;
1860 
1861 private:
1862 
1863  static const std::string _name;
1865  double boxHeight(const Transform &) const;
1866  double boxLength(const Transform &) const;
1867 
1868  double angle() const;
1869 
1870  Point position() const;
1871 
1872 protected:
1873  std::string _text;
1874  Fonts::Font _font;
1875  std::string _svgFont;
1876  double _size;
1877  double _xScale;
1878  double _yScale;
1879  Path _box; // Rectangle around the text
1880 };
1881 
1890 bool shapeGreaterDepth( const Shape *s1, const Shape *s2 );
1891 
1892 
1893 } // namespace LibBoard
1894 
1895 /*
1896  * Inline methods
1897  */
1898 #include "Shapes.ih"
1899 
1900 #if __cplusplus<201100
1901 #undef override
1902 #endif
1903 
1904 
1905 #endif /* _SHAPE_H_ */
Point center(LineWidthFlag lineWidthFlag=IgnoreLineWidth) const override
Definition: Shapes.cpp:884
void flushSVG(std::ostream &stream, const TransformSVG &transform) const override
Definition: Shapes.cpp:2147
A circle.
Definition: Shapes.h:1558
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const override
Definition: Shapes.cpp:1434
Abstract structure for a 2D shape.
Definition: Shapes.h:62
Arrow translated(double dx, double dy) const
Definition: Shapes.cpp:687
GouraudTriangle translated(double dx, double dy) const
Definition: Shapes.cpp:1708
Polyline & rotate(double angle, const Point &center) override
Definition: Shapes.cpp:1285
A line between two points.
Definition: Shapes.h:452
static double defaultLineWidth()
defaultLineWidth
Definition: Shapes.cpp:253
Ellipse & rotate(double angle, const Point &center) override
Definition: Shapes.cpp:889
Line * clone() const override
Definition: Shapes.cpp:565
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const override
Definition: Shapes.cpp:1362
virtual Shape & rotate(double angle, const Point &center)=0
static Shape::LineCap defaultLineCap()
defaultLineCap
Definition: Shapes.cpp:269
Definition: Transforms.h:44
Ellipse scaled(double sx, double sy) const
Definition: Shapes.cpp:990
Structure representing an RGB triple.
Definition: Color.h:39
Shape(Color penColor, Color fillColor, double lineWidth, LineStyle style, const LineCap cap, const LineJoin join, int depth)
int _depth
Definition: Shapes.h:411
A piece of text.
Definition: Shapes.h:1677
Circle & translate(double dx, double dy) override
Definition: Shapes.cpp:1183
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const override
Definition: Shapes.cpp:2123
A polygonal line described by a series of 2D points.
Definition: Shapes.h:891
Point center(LineWidthFlag lineWidthFlag=IgnoreLineWidth) const override
Definition: Shapes.cpp:1146
An ellipse.
Definition: Shapes.h:1394
Shape & scaleToHeight(double h, LineWidthFlag lineWidthFlag)
Definition: Shapes.cpp:132
Structure representing a scaling and translation suitable for an TikZ output.
Definition: Transforms.h:137
virtual void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const =0
virtual Shape & scale(double sx, double sy)=0
Rect boundingBox(LineWidthFlag) const override
Definition: Shapes.cpp:2239
Dot rotated(double angle, const Point &center) const
Definition: Shapes.cpp:313
A line between two points with an arrow at one extremity.
Definition: Shapes.h:783
Shape & scaleToWidth(double w, LineWidthFlag lineWidthFlag)
Definition: Shapes.cpp:124
double _x1
Definition: Shapes.h:773
A triangle. Basically a Polyline with a convenient constructor.
Definition: Shapes.h:1195
Color _fillColor
Definition: Shapes.h:413
Line & rotate(double angle, const Point &center) override
Definition: Shapes.cpp:473
Rect bbox(LineWidthFlag) const
void scaleAll(double s) override
Definition: Shapes.cpp:1351
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const override
Definition: Shapes.cpp:376
Definition: Board.h:41
const std::string & name() const override
Definition: Shapes.cpp:1632
virtual void flushSVG(std::ostream &stream, const TransformSVG &transform) const =0
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const override
Definition: Shapes.cpp:585
Arrow(double x1, double y1, double x2, double y2, Color penColor=Shape::defaultPenColor(), Color fillColor=Shape::defaultFillColor(), double lineWidth=Shape::defaultLineWidth(), const LineStyle lineStyle=Shape::defaultLineStyle(), const LineCap cap=Shape::defaultLineCap(), const LineJoin join=Shape::defaultLineJoin(), int depth=-1)
The Point structure. @copyright This source code is part of the Board project, a C++ library whose pu...
Shape & moveCenter(double x, double y, LineWidthFlag lineWidthFlag=IgnoreLineWidth)
Definition: Shapes.cpp:108
Triangle scaled(double sx, double sy) const
Definition: Shapes.cpp:1868
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const override
Definition: Shapes.cpp:1766
virtual void accept(ShapeVisitor &visitor)
Accepts a visitor object.
Definition: Shapes.cpp:277
Line & translate(double dx, double dy) override
Definition: Shapes.cpp:506
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const override
Definition: Shapes.cpp:1836
Arrow * clone() const override
Definition: Shapes.cpp:732
Arrow rotated(double angle, const Point &center) const
Definition: Shapes.cpp:668
Point center(LineWidthFlag lineWidthFlag=IgnoreLineWidth) const override
Definition: Shapes.cpp:1976
Rectangle * clone() const override
Definition: Shapes.cpp:1513
Color _penColor
Definition: Shapes.h:412
void scaleAll(double s) override
Definition: Shapes.cpp:1223
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const override
Definition: Shapes.cpp:1618
A path, according to Postscript and SVG definition.
Definition: Path.h:41
LineCap _lineCap
Definition: Shapes.h:416
static Shape::LineStyle defaultLineStyle()
defaultLineStyle
Definition: Shapes.cpp:265
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const override
Definition: Shapes.cpp:626
Polyline & scale(double sx, double sy) override
Definition: Shapes.cpp:1324
std::string tikzProperties(const TransformTikZ &transform) const
Definition: Shapes.cpp:200
void flushSVG(std::ostream &stream, const TransformSVG &transform) const override
Definition: Shapes.cpp:418
Line rotated(double angle, const Point &center) const
Definition: Shapes.cpp:487
Text & translate(double dx, double dy) override
Definition: Shapes.cpp:2022
Dot translated(double dx, double dy) const
Definition: Shapes.cpp:339
Text scaled(double sx, double sy) const
Definition: Shapes.cpp:2054
static Color defaultFillColor()
defaultFillColor
Definition: Shapes.cpp:261
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const override
Definition: Shapes.cpp:777
virtual void flushPostscript(std::ostream &stream, const TransformEPS &transform) const =0
void scaleAll(double s) override
Definition: Shapes.cpp:556
void scaleAll(double s) override
Definition: Shapes.cpp:2066
A line between two points.
Definition: Shapes.h:611
Struct representing a 2D point.
Definition: Point.h:39
Shape & operator--()
Structure representing a scaling and translation suitable for an XFig output.
Definition: Transforms.h:93
Ellipse * clone() const override
Definition: Shapes.cpp:1010
void scaleAll(double s) override
Definition: Shapes.cpp:1002
static bool _lineWidthScaling
Definition: Shapes.h:399
Rect boundingBox(LineWidthFlag) const override
Definition: Shapes.cpp:439
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const override
Definition: Shapes.cpp:2181
static Shape::LineJoin defaultLineJoin()
defaultLineJoin
Definition: Shapes.cpp:273
Polyline * clone() const override
Definition: Shapes.cpp:1357
Ellipse & translate(double dx, double dy) override
Definition: Shapes.cpp:920
static void setLineWidthScaling(bool)
Definition: Shapes.cpp:151
Circle & rotate(double angle, const Point &center) override
Definition: Shapes.cpp:1151
Polyline & operator<<(const Point &p)
Definition: Shapes.cpp:1278
const std::string & name() const override
Definition: Shapes.cpp:1140
Polyline rotated(double angle, const Point &center) const
Definition: Shapes.cpp:1292
Arrow scaled(double sx, double sy) const
Definition: Shapes.cpp:693
Dot & translate(double dx, double dy) override
Definition: Shapes.cpp:331
Circle & scale(double sx, double sy) override
Definition: Shapes.cpp:1196
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const override
Definition: Shapes.cpp:430
Line & scale(double sx, double sy) override
Definition: Shapes.cpp:523
void scaleAll(double s) override
Definition: Shapes.cpp:1507
void flushSVG(std::ostream &stream, const TransformSVG &transform) const override
Definition: Shapes.cpp:614
Circle translated(double dx, double dy) const
Definition: Shapes.cpp:1190
Shape & rotateDeg(double angle, const Point &center)
double _y1
Definition: Shapes.h:774
Line translated(double dx, double dy) const
Definition: Shapes.cpp:514
void flushSVG(std::ostream &stream, const TransformSVG &transform) const override
Definition: Shapes.cpp:1803
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
Dot & scale(double sx, double sy) override
Definition: Shapes.cpp:345
Line(double x1, double y1, double x2, double y2, Color color, double lineWidth=Shape::defaultLineWidth(), const LineStyle lineStyle=Shape::defaultLineStyle(), const LineCap cap=Shape::defaultLineCap(), const LineJoin join=Shape::defaultLineJoin(), int depth=-1)
Polyline translated(double dx, double dy) const
Definition: Shapes.cpp:1318
const std::string & name() const override
Definition: Shapes.cpp:1970
Structure representing a scaling and translation suitable for an SVG output.
Definition: Transforms.h:116
const std::string & name() const override
Definition: Shapes.cpp:467
Text translated(double dx, double dy) const
Definition: Shapes.cpp:2029
static Color defaultPenColor()
defaultPenColor
Definition: Shapes.cpp:257
virtual Shape & translate(double dx, double dy)=0
virtual ~Shape()
Definition: Shapes.h:93
Rect boundingBox(LineWidthFlag) const override
Definition: Shapes.cpp:637
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
LineJoin _lineJoin
Definition: Shapes.h:417
double _x2
Definition: Shapes.h:775
void flushSVG(std::ostream &stream, const TransformSVG &transform) const override
Definition: Shapes.cpp:1562
Rect boundingBox(LineWidthFlag) const override
Definition: Shapes.cpp:704
Point & operator[](const std::size_t n)
Definition: Shapes.h:944
The Point structure. @copyright This source code is part of the Board project, a C++ library whose pu...
double _y2
Definition: Shapes.h:776
Point center(LineWidthFlag flage=IgnoreLineWidth) const override
Definition: Shapes.cpp:301
GouraudTriangle * clone() const override
Definition: Shapes.cpp:1732
const std::string & name() const override
Definition: Shapes.cpp:878
const std::string & name() const override
Definition: Shapes.cpp:295
Rect boundingBox(LineWidthFlag) const override
Definition: Shapes.cpp:1106
Ellipse translated(double dx, double dy) const
Definition: Shapes.cpp:927
void flushSVG(std::ostream &stream, const TransformSVG &transform) const override
Definition: Shapes.cpp:810
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const override
Definition: Shapes.cpp:2108
virtual Rect boundingBox(LineWidthFlag) const =0
Circle scaled(double sx, double sy) const
Definition: Shapes.cpp:1211
A rectangle.
Definition: Shapes.h:1080
The Color structure. @copyright This source code is part of the Board project, a C++ library whose pu...
Triangle translated(double dx, double dy) const
Definition: Shapes.cpp:1862
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const override
Definition: Shapes.cpp:737
Dot * clone() const override
Definition: Shapes.cpp:456
Shape & operator++()
const Point & operator[](const std::size_t n) const
Definition: Shapes.h:955
Polyline & translate(double dx, double dy) override
Definition: Shapes.cpp:1311
static void enableLineWidthScaling()
Definition: Shapes.cpp:140
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const override
Definition: Shapes.cpp:1518
virtual void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const =0
Dot scaled(double sx, double sy) const
Definition: Shapes.cpp:357
double _x
Definition: Shapes.h:603
GouraudTriangle scaled(double sx, double sy) const
Definition: Shapes.cpp:1714
Rectangle translated(double dx, double dy) const
Definition: Shapes.cpp:1489
Ellipse & scale(double sx, double sy) override
Definition: Shapes.cpp:933
std::string svgProperties(const TransformSVG &transform) const
Definition: Shapes.cpp:157
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const override
Definition: Shapes.cpp:570
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const override
Definition: Shapes.cpp:1090
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
virtual void scaleAll(double s)=0
GouraudTriangle & rotate(double angle, const Point &center) override
Definition: Shapes.cpp:1683
bool filled() const
Definition: Shapes.h:114
const std::string & name() const override
Definition: Shapes.cpp:662
Line scaled(double sx, double sy) const
Definition: Shapes.cpp:544
Circle * clone() const override
Definition: Shapes.cpp:1231
Text & scale(double sx, double sy) override
Definition: Shapes.cpp:2035
Text(double x, double y, const std::string &text, const Fonts::Font font, double size, Color color=Color::Black, int depth=-1)
Definition: Shapes.cpp:1891
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const override
Definition: Shapes.cpp:1386
const std::string & name() const override
Definition: Shapes.cpp:1850
void flushSVG(std::ostream &stream, const TransformSVG &transform) const override
Definition: Shapes.cpp:1236
Ellipse rotated(double angle, const Point &center) const
Definition: Shapes.cpp:902
void flushSVG(std::ostream &stream, const TransformSVG &transform) const override
Definition: Shapes.cpp:1418
const std::string & name() const override
Definition: Shapes.cpp:1272
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
void flushSVG(std::ostream &stream, const TransformSVG &transform) const override
Definition: Shapes.cpp:1072
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const override
Definition: Shapes.cpp:391
Polyline scaled(double sx, double sy) const
Definition: Shapes.cpp:1339
Structure representing a scaling and translation suitable for an EPS output.
Definition: Transforms.h:73
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const override
Definition: Shapes.cpp:1251
Text * clone() const override
Definition: Shapes.cpp:2072
virtual Point center(LineWidthFlag lineWidthFlag=IgnoreLineWidth) const
Definition: Shapes.cpp:101
Triangle * clone() const override
Definition: Shapes.cpp:1880
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const override
Definition: Shapes.cpp:860
Rect boundingBox(LineWidthFlag) const override
Definition: Shapes.cpp:1448
double _lineWidth
Definition: Shapes.h:414
const std::string & name() const override
Definition: Shapes.cpp:1471
Dot & rotate(double angle, const Point &center) override
Definition: Shapes.cpp:306
Definition: ShapeVisitor.h:40
std::string postscriptProperties(const TransformEPS &transform) const
Definition: Shapes.cpp:188
static void disableLineWidthScaling()
Definition: Shapes.cpp:146
Text & rotate(double angle, const Point &center) override
Definition: Shapes.cpp:1981
Struct representing a rectangle on the plane.
Definition: Rect.h:38
Rectangle rotated(double angle, const Point &center) const
Definition: Shapes.cpp:1477
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const override
Definition: Shapes.cpp:1737
double _y
Definition: Shapes.h:604
virtual Shape * clone() const =0
void scaleAll(double s) override
Definition: Shapes.cpp:369
LineStyle _lineStyle
Definition: Shapes.h:415
Rectangle scaled(double sx, double sy) const
Definition: Shapes.cpp:1495
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const override
Definition: Shapes.cpp:1044
void scaleAll(double s) override
Definition: Shapes.cpp:1726
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const override
Definition: Shapes.cpp:1015
virtual const std::string & name() const
Definition: Shapes.cpp:95
A triangle with shaded filling according to colors given for each vertex.
Definition: Shapes.h:1278