Board  0.9.4
Board.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
27 #ifndef _BOARD_BOARD_H_
28 #define _BOARD_BOARD_H_
29 
30 #include <ostream>
31 #include <string>
32 #include <vector>
33 
34 #include "BoardConfig.h"
35 #include "board/Point.h"
36 #include "board/Path.h"
37 #include "board/Shapes.h"
38 #include "board/Image.h"
39 #include "board/ShapeList.h"
40 
41 namespace LibBoard {
42 
48 class Board : public ShapeList {
49 
50 public:
51 
52  enum PageSize { BoundingBox = 0,
53  A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10,
54  Letter, Legal, Executive };
55 
56  enum Unit { UPoint, UInche, UCentimeter, UMillimeter };
57  static const double Degree;
58 
59  enum AspectRatioFlag { IgnoreAspectRatio, KeepAspectRatio };
60 
66  Board( const Color & backgroundColor = Color::Null );
67 
73  Board( const Board & other );
74 
75  ~Board();
76 
84  Board & operator=( const Board & other );
85 
86 
94  Board & operator<<( const Shape & shape );
95 
101  void clear( const Color & color = Color::Null );
102 
110  inline void clear( unsigned char red, unsigned char green, unsigned char blue );
111 
112  Board & rotate( double angle, const Point & center );
113 
114  Board & rotate( double angle );
115 
116  Board & translate( double dx, double dy );
117 
118  Board & scale( double sx, double sy );
119 
120  Board & scale( double s );
121 
122  Board rotated( double angle, const Point & center );
123 
124  Board rotated( double angle );
125 
126  Board translated( double dx, double dy );
127 
128  Board scaled( double sx, double sy );
129 
130  Board scaled( double s );
131 
132 
138  void setUnit( Unit unit );
139 
146  void setUnit( double factor, Unit unit );
147 
155  void drawDot( double x, double y, int depth = -1 );
156 
166  void drawLine( double x1, double y1, double x2, double y2,
167  int depth = -1 );
168 
177  void drawLine( Point p, Point q, int depth = -1 );
178 
188  void drawArrow( double x1, double y1, double x2, double y2, int depth = -1 );
189 
197  void drawArrow( Point p, Point q, int depth = -1 );
198 
210  void drawTriangle( double x1, double y1,
211  double x2, double y2,
212  double x3, double y3,
213  int depth = -1 );
214 
223  void drawTriangle( const Point & p1,
224  const Point & p2,
225  const Point & p3,
226  int depth = -1 );
227 
239  void fillTriangle( double x1, double y1,
240  double x2, double y2,
241  double x3, double y3,
242  int depth = -1 );
243 
256  void fillGouraudTriangle( const Point & p1,
257  const Color & color1,
258  const Point & p2,
259  const Color & color2,
260  const Point & p3,
261  const Color & color3,
262  unsigned char divisions = 3,
263  int depth = -1 );
264 
280  inline void fillGouraudTriangle( const double x1, const double y1,
281  const Color & color1,
282  const double x2, const double y2,
283  const Color & color2,
284  const double x3, const double y3,
285  const Color & color3,
286  unsigned char divisions = 3,
287  int depth = -1 );
288 
301  void fillGouraudTriangle( const Point & p1,
302  const float brightness1,
303  const Point & p2,
304  const float brightness2,
305  const Point & p3,
306  const float brightness3,
307  unsigned char divisions = 3,
308  int depth = -1 );
309 
326  inline void fillGouraudTriangle( const double x1, const double y1,
327  const float brightness1,
328  const double x2, const double y2,
329  const float brightness2,
330  const double x3, const double y3,
331  const float brightness3,
332  unsigned char divisions = 3,
333  int depth = -1 );
334 
335 
344  void fillTriangle( const Point & p1,
345  const Point & p2,
346  const Point & p3,
347  int depth = -1 );
348 
358  void drawRectangle( double left, double top,
359  double width, double height,
360  int depth = -1 );
361 
368  void drawRectangle( const Rect & r, int depth = -1 );
369 
379  void fillRectangle( double left, double top,
380  double width, double height,
381  int depth = -1 );
382 
389  void fillRectangle( const Rect & r, int depth = -1 );
390 
399  void drawCircle( double x, double y, double radius,
400  int depth = -1 );
401 
410  void fillCircle( double x, double y, double radius,
411  int depth = -1);
412 
421  void drawEllipse( double x, double y,
422  double xRadius, double yRadius,
423  int depth = -1);
424 
434  void fillEllipse( double x, double y,
435  double xRadius, double yRadius,
436  int depth = -1);
437 
444  void drawPolyline( const std::vector<Point> & points,
445  int depth = -1 );
446 
453  void drawClosedPolyline( const std::vector<Point> & points,
454  int depth = -1 );
455 
462  void fillPolyline( const std::vector<Point> & points,
463  int depth = -1 );
464 
473  void drawText( double x, double y, const char * text, int depth = -1 );
474 
482  void drawText( Point p, const char * text, int depth = -1 );
483 
492  void drawText( double x, double y, const std::string & str, int depth = -1 );
493 
501  void drawText( Point p, const std::string & str, int depth = -1 );
502 
510  Board & setFont( const Fonts::Font font, double fontSize );
511 
518  Board & setFontSize( double fontSize );
519 
528  Board & setPenColorRGBi( unsigned char red,
529  unsigned char green,
530  unsigned char blue,
531  unsigned char alpha = 255 );
532 
542  Board & setPenColorRGBf( float red,
543  float green,
544  float blue,
545  float alpha = 1.0f );
546 
554  Board & setPenColor( const Color & color );
555 
556 
566  Board & setFillColorRGBi( unsigned char red,
567  unsigned char green,
568  unsigned char blue,
569  unsigned char alpha = 255 );
570 
580  Board & setFillColorRGBf( float red, float green, float blue, float alpha = 1.0f );
581 
589  Board & setFillColor( const Color & color );
590 
597  Board & setLineWidth( double width );
598 
605  Board & setLineStyle( Shape::LineStyle style );
606 
615  inline Board & setLineCap( Shape::LineCap cap );
616 
625  inline Board & setLineJoin( Shape::LineJoin join );
626 
632  void backgroundColor( const Color & color );
633 
640  void drawBoundingBox( LineWidthFlag lineWidthFlag, int depth = -1 );
641 
650  void setClippingRectangle( double x, double y, double width, double height );
651 
657  void setClippingRectangle(const Rect & rect );
658 
664  void setClippingPath( const std::vector<Point> & points );
665 
671  void setClippingPath( const Path & path );
672 
683  void addDuplicates( const Shape & shape,
684  std::size_t times,
685  double dx,
686  double dy,
687  double scale = 1.0 );
688 
701  void addDuplicates( const Shape & shape,
702  std::size_t times,
703  double dx, double dy,
704  double scaleX, double scaleY,
705  double angle = 0.0 );
706 
717  void save( const char * filename, PageSize size = Board::BoundingBox, double margin = 0.0, Unit unit = UMillimeter ) const;
718 
730  void save(const char * filename, double pageWidth, double pageHeight, double margin = 0.0, Unit unit = UMillimeter ) const;
731 
742  void saveEPS( std::ostream & out, PageSize size = Board::BoundingBox, double margin = 0.0, Unit unit = UMillimeter, const std::string & title = std::string() ) const ;
743 
754  void saveEPS( const char * filename, PageSize size = Board::BoundingBox, double margin = 0.0, Unit unit = UMillimeter, const std::string & title = std::string() ) const ;
755 
768  void saveEPS( std::ostream & out, double pageWidth, double pageHeight, double margin = 0.0, Unit unit = UMillimeter, const std::string & title = std::string() ) const ;
769 
781  void saveEPS( const char * filename, double pageWidth, double pageHeight, double margin = 0.0, Unit unit = UMillimeter, const std::string & title = std::string() ) const ;
782 
792  void saveFIG( const char * filename, PageSize size = Board::BoundingBox, double margin = 0.0, Unit unit = UMillimeter ) const;
793 
803  void saveFIG( std::ostream & out, PageSize size = Board::BoundingBox, double margin = 0.0, Unit unit = UMillimeter ) const;
804 
816  void saveFIG( const char * filename, double pageWidth, double pageHeight, double margin = 0.0, Unit unit = UMillimeter ) const ;
817 
829  void saveFIG( std::ostream & out, double pageWidth, double pageHeight, double margin = 0.0, Unit unit = UMillimeter ) const ;
830 
840  void saveSVG( const char * filename, PageSize size = Board::BoundingBox, double margin = 0.0, Unit unit = UMillimeter ) const;
841 
851  void saveSVG( std::ostream & out, PageSize size = Board::BoundingBox, double margin = 0.0, Unit unit = UMillimeter ) const;
852 
864  void saveSVG( const char * filename, double pageWidth, double pageHeight, double margin = 0.0, Unit unit = UMillimeter ) const ;
865 
877  void saveSVG( std::ostream & out, double pageWidth, double pageHeight, double margin = 0.0, Unit unit = UMillimeter) const ;
878 
887  void saveTikZ( const char * filename, PageSize size = Board::BoundingBox, double margin = 0.0 ) const;
888 
897  void saveTikZ( std::ostream & out, PageSize size = Board::BoundingBox, double margin = 0.0 ) const;
898 
909  void saveTikZ( const char * filename, double pageWidth, double pageHeight, double margin = 0.0 ) const ;
910 
921  void saveTikZ( std::ostream & out, double pageWidth, double pageHeight, double margin = 0.0 ) const ;
922 
923 
942  static Group makeGrid(Point topLeft,
943  size_t columns, size_t rows,
944  double width, double height,
945  Color penColor,
947  double lineWidth,
948  const LineStyle style = SolidStyle,
949  const LineCap cap = ButtCap,
950  const LineJoin join = MiterJoin,
951  int depth = -1 );
957  Color penColor() const;
958 
964  Color fillColor() const;
965 
966 protected:
967 
968  static double toMillimeter( double x, Unit unit);
969 
970 
975  struct State {
978  double lineWidth;
979  Shape::LineStyle lineStyle;
980  Shape::LineCap lineCap;
981  Shape::LineJoin lineJoin;
982  Fonts::Font font;
983  double fontSize;
984  State();
985  };
988  Path _clippingPath;
989 };
990 } // namespace LibBoard
991 
992 #include "board/Board.ih"
993 
994 #endif
void drawRectangle(double left, double top, double width, double height, int depth=-1)
Definition: Board.cpp:383
Abstract structure for a 2D shape.
Definition: Shapes.h:62
Board & setLineWidth(double width)
Definition: Board.cpp:271
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=0.0, Unit unit=UMillimeter) const
Definition: Board.cpp:1045
Board & operator<<(const Shape &shape)
Definition: Board.cpp:115
Board & rotate(double angle, const Point &center)
Definition: Board.cpp:133
void drawArrow(double x1, double y1, double x2, double y2, int depth=-1)
Definition: Board.cpp:343
Board & setFillColorRGBi(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255)
Definition: Board.cpp:247
Structure representing an RGB triple.
Definition: Color.h:39
void drawText(double x, double y, const char *text, int depth=-1)
Definition: Board.cpp:657
Class for EPS, FIG or SVG drawings.
Definition: Board.h:48
static Group makeGrid(Point topLeft, size_t columns, size_t rows, double width, double height, Color penColor, Color fillColor, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)
Definition: Board.cpp:1205
void fillEllipse(double x, double y, double xRadius, double yRadius, int depth=-1)
Definition: Board.cpp:477
double fontSize
Definition: Board.h:983
void saveTikZ(const char *filename, PageSize size=Board::BoundingBox, double margin=0.0) const
Definition: Board.cpp:1157
void drawTriangle(double x1, double y1, double x2, double y2, double x3, double y3, int depth=-1)
Definition: Board.cpp:534
void saveFIG(const char *filename, PageSize size=Board::BoundingBox, double margin=0.0, Unit unit=UMillimeter) const
Definition: Board.cpp:923
Board & setLineJoin(Shape::LineJoin join)
Shape::LineJoin lineJoin
Definition: Board.h:981
void setClippingPath(const std::vector< Point > &points)
Definition: Board.cpp:728
void save(const char *filename, PageSize size=Board::BoundingBox, double margin=0.0, Unit unit=UMillimeter) const
Definition: Board.cpp:1296
Definition: Board.h:41
Board & operator=(const Board &other)
Definition: Board.cpp:99
The Point structure. @copyright This source code is part of the Board project, a C++ library whose pu...
Classes ShapeList and Group.
A group of shapes. A group is basically a ShapeList except that when rendered in either an SVG of a F...
Definition: ShapeList.h:304
void fillTriangle(double x1, double y1, double x2, double y2, double x3, double y3, int depth=-1)
Definition: Board.cpp:573
void fillRectangle(double left, double top, double width, double height, int depth=-1)
Definition: Board.cpp:411
A path, according to Postscript and SVG definition.
Definition: Path.h:41
void saveEPS(std::ostream &out, PageSize size=Board::BoundingBox, double margin=0.0, Unit unit=UMillimeter, const std::string &title=std::string()) const
Definition: Board.cpp:797
void fillGouraudTriangle(const Point &p1, const Color &color1, const Point &p2, const Color &color2, const Point &p3, const Color &color3, unsigned char divisions=3, int depth=-1)
Definition: Board.cpp:611
Color penColor() const
penColor
Definition: Board.cpp:1232
Struct representing a 2D point.
Definition: Point.h:39
Shape::LineCap lineCap
Definition: Board.h:980
Shape::LineStyle lineStyle
Definition: Board.h:979
Board & setFillColorRGBf(float red, float green, float blue, float alpha=1.0f)
Definition: Board.cpp:257
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
void clear(const Color &color=Color::Null)
Definition: Board.cpp:126
void backgroundColor(const Color &color)
Definition: Board.cpp:293
Color _backgroundColor
Definition: Board.h:987
Board & setLineStyle(Shape::LineStyle style)
Board & setPenColorRGBf(float red, float green, float blue, float alpha=1.0f)
Definition: Board.cpp:230
A group of shapes.
Definition: ShapeList.h:45
void drawCircle(double x, double y, double radius, int depth=-1)
Definition: Board.cpp:441
void setClippingRectangle(double x, double y, double width, double height)
Definition: Board.cpp:712
Board & setFontSize(double fontSize)
Definition: Board.cpp:286
Board & setFillColor(const Color &color)
Definition: Board.cpp:264
void fillCircle(double x, double y, double radius, int depth=-1)
Definition: Board.cpp:452
void addDuplicates(const Shape &shape, std::size_t times, double dx, double dy, double scale=1.0)
Definition: Board.cpp:751
Board(const Color &backgroundColor=Color::Null)
Definition: Board.cpp:86
void drawLine(double x1, double y1, double x2, double y2, int depth=-1)
Definition: Board.cpp:308
void drawEllipse(double x, double y, double xRadius, double yRadius, int depth=-1)
Definition: Board.cpp:462
void fillPolyline(const std::vector< Point > &points, int depth=-1)
Definition: Board.cpp:521
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
Color fillColor() const
fillColor
Definition: Board.cpp:1237
double lineWidth
Definition: Board.h:978
void drawDot(double x, double y, int depth=-1)
Definition: Board.cpp:299
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
Color penColor
Definition: Board.h:976
Board & setFont(const Fonts::Font font, double fontSize)
Definition: Board.cpp:278
Board & scale(double sx, double sy)
Definition: Board.cpp:157
Fonts::Font font
Definition: Board.h:982
Color fillColor
Definition: Board.h:977
State _state
Definition: Board.h:986
Board & translate(double dx, double dy)
Definition: Board.cpp:149
Board & setPenColorRGBi(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255)
Definition: Board.cpp:220
Board & setLineCap(Shape::LineCap cap)
Shape & top()
Definition: ShapeList.cpp:593
virtual Point center(LineWidthFlag lineWidthFlag=IgnoreLineWidth) const
Definition: Shapes.cpp:101
void setUnit(Unit unit)
Definition: Board.h:975
void drawClosedPolyline(const std::vector< Point > &points, int depth=-1)
Definition: Board.cpp:508
Board & setPenColor(const Color &color)
Definition: Board.cpp:240
Struct representing a rectangle on the plane.
Definition: Rect.h:38
void drawBoundingBox(LineWidthFlag lineWidthFlag, int depth=-1)
Definition: Board.cpp:694
void drawPolyline(const std::vector< Point > &points, int depth=-1)
Definition: Board.cpp:492