Board  0.9.5
Shape.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
26 #ifndef BOARD_SHAPE_H
27 #define BOARD_SHAPE_H
28 
29 #include <cmath>
30 #include <iostream>
31 #include <map>
32 #include <memory>
33 #include <string>
34 #include <vector>
35 #include "board/Color.h"
36 #include "board/PSFonts.h"
37 #include "board/Path.h"
38 #include "board/Point.h"
39 #include "board/Rect.h"
40 #include "board/Style.h"
41 #include "board/Tools.h"
42 #include "board/Transforms.h"
43 
44 #ifndef M_PI
45 #define M_PI 3.14159265358979323846
46 #endif
47 
48 #ifndef M_PI_2
49 #define M_PI_2 1.57079632679489661923
50 #endif
51 
52 namespace LibBoard
53 {
54 
55 struct ShapeVisitor;
56 struct ConstShapeVisitor;
57 struct CompositeShapeTransform;
58 
63 struct Shape {
64 
68  inline Shape();
69 
73  virtual ~Shape();
74 
80  virtual const std::string & name() const;
81 
87  virtual Shape * clone() const = 0;
88 
95  virtual Point center(LineWidthFlag lineWidthFlag = IgnoreLineWidth) const;
96 
105  virtual Shape & rotate(double angle, const Point & center) = 0;
106 
114  virtual Shape & rotate(double angle) = 0;
115 
124  inline Shape & rotateDeg(double angle, const Point & center);
125 
133  inline Shape & rotateDeg(double angle);
134 
143  virtual Shape & translate(double dx, double dy) = 0;
144 
154  Shape & moveCenter(double x, double y, LineWidthFlag lineWidthFlag = IgnoreLineWidth);
155 
164  Shape & moveCenter(Point p, LineWidthFlag lineWidthFlag = IgnoreLineWidth);
165 
174  virtual Shape & scale(double sx, double sy) = 0;
175 
183  virtual Shape & scale(double s) = 0;
184 
194  Shape & resize(double width, double height, LineWidthFlag lineWidthFlag);
195 
204  Shape & scaleToWidth(double w, LineWidthFlag lineWidthFlag);
205 
214  Shape & scaleToHeight(double h, LineWidthFlag lineWidthFlag);
215 
221  virtual Rect boundingBox(LineWidthFlag) const = 0;
222 
228  inline Rect bbox(LineWidthFlag) const;
229 
236  virtual void scaleAll(double s) = 0;
237 
245  virtual void flushPostscript(std::ostream & stream, const TransformEPS & transform) const = 0;
246 
255  virtual void flushFIG(std::ostream & stream, const TransformFIG & transform, std::map<Color, int> & colormap) const = 0;
256 
263  virtual void flushSVG(std::ostream & stream, const TransformSVG & transform) const = 0;
264 
271  virtual void flushTikZ(std::ostream & stream, const TransformTikZ & transform) const = 0;
272 
278  virtual void accept(ShapeVisitor & visitor);
279 
285  virtual void accept(const ShapeVisitor & visitor);
286 
292  virtual void accept(ConstShapeVisitor & visitor) const;
293 
299  virtual void accept(const ConstShapeVisitor & visitor) const;
300 
306  virtual Shape * accept(CompositeShapeTransform & transform) const;
307 
313  virtual Shape * accept(const CompositeShapeTransform & transform) const;
314 
315  Shape(const Shape & other);
316 
317 private:
318  static const std::string _name;
319 };
320 
321 } // namespace LibBoard
322 
323 /*
324  * Inline methods
325  */
326 
327 namespace LibBoard
328 {
330 
331 Rect Shape::bbox(LineWidthFlag flag) const
332 {
333  return boundingBox(flag);
334 }
335 
336 Shape & Shape::rotateDeg(double angle, const Point & center)
337 {
338  return rotate(angle * (M_PI / 180.0), center);
339 }
340 
341 Shape & Shape::rotateDeg(double angle)
342 {
343  return rotate(angle * (M_PI / 180.0), center());
344 }
345 
346 } // namespace LibBoard
347 
348 #endif /* BOARD_SHAPE_H */
LibBoard::Shape::rotateDeg
Shape & rotateDeg(double angle, const Point &center)
Definition: Shape.h:336
Style.h
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
Point.h
The Point structure. @copyright This source code is part of the Board project, a C++ library whose pu...
Transforms.h
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
Path.h
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
LibBoard::Shape::scaleToWidth
Shape & scaleToWidth(double w, LineWidthFlag lineWidthFlag)
Definition: Shape.cpp:85
LibBoard::Shape::scaleToHeight
Shape & scaleToHeight(double h, LineWidthFlag lineWidthFlag)
Definition: Shape.cpp:92
LibBoard::Shape::Shape
Shape()
Definition: Shape.h:329
LibBoard::Rect
Struct representing a rectangle on the plane.
Definition: Rect.h:39
PSFonts.h
The Point structure. @copyright This source code is part of the Board project, a C++ library whose pu...
LibBoard::Shape::boundingBox
virtual Rect boundingBox(LineWidthFlag) const =0
LibBoard::CompositeShapeTransform
A CompositeShapeTransform may be used to duplicate/transform a composite shape tree.
Definition: ShapeVisitor.h:103
LibBoard::Shape::scale
virtual Shape & scale(double sx, double sy)=0
LibBoard::Shape::accept
virtual void accept(ShapeVisitor &visitor)
Accepts a visitor object.
Definition: Shape.cpp:99
LibBoard::Point
Struct representing a 2D point.
Definition: Point.h:42
LibBoard::TransformEPS
Structure representing a scaling and translation suitable for an EPS output.
Definition: Transforms.h:71
LibBoard::Shape::moveCenter
Shape & moveCenter(double x, double y, LineWidthFlag lineWidthFlag=IgnoreLineWidth)
Definition: Shape.cpp:64
LibBoard::Shape::bbox
Rect bbox(LineWidthFlag) const
Definition: Shape.h:331
LibBoard::Shape
Abstract structure for a 2D shape.
Definition: Shape.h:63
LibBoard::Shape::flushTikZ
virtual void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const =0
LibBoard::Shape::flushFIG
virtual void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const =0
LibBoard::ConstShapeVisitor
A ConstShapeVisitor may visit const shapes of a composite shape tree in back-to-front order.
Definition: ShapeVisitor.h:78
LibBoard::Shape::flushSVG
virtual void flushSVG(std::ostream &stream, const TransformSVG &transform) const =0
LibBoard::Shape::~Shape
virtual ~Shape()
Definition: Shape.cpp:52
LibBoard::TransformTikZ
Structure representing a scaling and translation suitable for an TikZ output.
Definition: Transforms.h:126
LibBoard::Shape::clone
virtual Shape * clone() const =0
LibBoard::TransformFIG
Structure representing a scaling and translation suitable for an XFig output.
Definition: Transforms.h:87
LibBoard::Shape::resize
Shape & resize(double width, double height, LineWidthFlag lineWidthFlag)
Definition: Shape.cpp:78
LibBoard::Shape::center
virtual Point center(LineWidthFlag lineWidthFlag=IgnoreLineWidth) const
Definition: Shape.cpp:59
LibBoard::Shape::translate
virtual Shape & translate(double dx, double dy)=0
LibBoard::Shape::name
virtual const std::string & name() const
Definition: Shape.cpp:54
LibBoard::Shape::rotate
virtual Shape & rotate(double angle, const Point &center)=0
Color.h
The Color structure. @copyright This source code is part of the Board project, a C++ library whose pu...
LibBoard::Shape::scaleAll
virtual void scaleAll(double s)=0
Rect.h
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
Tools.h
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
LibBoard::Shape::flushPostscript
virtual void flushPostscript(std::ostream &stream, const TransformEPS &transform) const =0
LibBoard::ShapeVisitor
A ShapeVisitor visits all shapes in a composite shape tree in back-to-front order.
Definition: ShapeVisitor.h:53
LibBoard::TransformSVG
Structure representing a scaling and translation suitable for an SVG output.
Definition: Transforms.h:109