Board 0.9.6
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/Globals.h>
37#include <board/PSFonts.h>
38#include <board/Path.h>
39#include <board/Point.h>
40#include <board/Rect.h>
41#include <board/Style.h>
42#include <board/Tools.h>
43#include <board/Transforms.h>
44
45#ifndef M_PI
46#define M_PI 3.14159265358979323846
47#endif
48
49#ifndef M_PI_2
50#define M_PI_2 1.57079632679489661923
51#endif
52
53namespace LibBoard
54{
55
56struct ShapeVisitor;
57struct ConstShapeVisitor;
58struct CompositeShapeTransform;
59
64struct Shape {
65
69 inline Shape();
70
74 virtual ~Shape();
75
81 virtual const std::string & name() const;
82
88 virtual Shape * clone() const = 0;
89
96 virtual Point center(LineWidthFlag lineWidthFlag = IgnoreLineWidth) const;
97
106 virtual Shape & rotate(double angle, const Point & center) = 0;
107
115 virtual Shape & rotate(double angle) = 0;
116
125 inline Shape & rotateDeg(double angle, const Point & center);
126
134 inline Shape & rotateDeg(double angle);
135
144 virtual Shape & translate(double dx, double dy) = 0;
145
155 Shape & moveCenter(double x, double y, LineWidthFlag lineWidthFlag = IgnoreLineWidth);
156
165 Shape & moveCenter(Point p, LineWidthFlag lineWidthFlag = IgnoreLineWidth);
166
175 virtual Shape & scale(double sx, double sy) = 0;
176
184 virtual Shape & scale(double s) = 0;
185
195 Shape & resize(double width, double height, LineWidthFlag lineWidthFlag);
196
205 Shape & scaleToWidth(double w, LineWidthFlag lineWidthFlag);
206
215 Shape & scaleToHeight(double h, LineWidthFlag lineWidthFlag);
216
222 virtual Rect boundingBox(LineWidthFlag) const = 0;
223
229 inline Rect bbox(LineWidthFlag) const;
230
237 virtual void scaleAll(double s) = 0;
238
246 virtual void flushPostscript(std::ostream & stream, const TransformEPS & transform) const = 0;
247
256 virtual void flushFIG(std::ostream & stream, const TransformFIG & transform, std::map<Color, int> & colormap) const = 0;
257
264 virtual void flushSVG(std::ostream & stream, const TransformSVG & transform) const = 0;
265
272 virtual void flushTikZ(std::ostream & stream, const TransformTikZ & transform) const = 0;
273
279 virtual void accept(ShapeVisitor & visitor);
280
286 virtual void accept(const ShapeVisitor & visitor);
287
293 virtual void accept(ConstShapeVisitor & visitor) const;
294
300 virtual void accept(const ConstShapeVisitor & visitor) const;
301
307 virtual Shape * accept(CompositeShapeTransform & transform) const;
308
314 virtual Shape * accept(const CompositeShapeTransform & transform) const;
315
316 Shape(const Shape & other);
317
318private:
319 static const std::string _name;
320};
321
322} // namespace LibBoard
323
324/*
325 * Inline methods
326 */
327
328namespace LibBoard
329{
331
333{
334 return boundingBox(flag);
335}
336
337Shape & Shape::rotateDeg(double angle, const Point & center)
338{
339 return rotate(angle * (M_PI / 180.0), center);
340}
341
342Shape & Shape::rotateDeg(double angle)
343{
344 return rotate(angle * (M_PI / 180.0), center());
345}
346
347} // namespace LibBoard
348
349#endif /* BOARD_SHAPE_H */
The Color structure. @copyright This source code is part of the Board project, a C++ library whose pu...
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
The Point structure. @copyright This source code is part of the Board project, a C++ library whose pu...
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
The Point structure. @copyright This source code is part of the Board project, a C++ library whose pu...
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
#define M_PI
Definition Shape.h:46
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
Definition Board.h:55
LineWidthFlag
Definition Style.h:57
@ IgnoreLineWidth
Definition Style.h:58
A CompositeShapeTransform may be used to duplicate/transform a composite shape tree.
Definition ShapeVisitor.h:104
A ConstShapeVisitor may visit const shapes of a composite shape tree in back-to-front order.
Definition ShapeVisitor.h:79
Struct representing a 2D point.
Definition Point.h:42
Struct representing a rectangle on the plane.
Definition Rect.h:40
A ShapeVisitor visits all shapes in a composite shape tree in back-to-front order.
Definition ShapeVisitor.h:54
Abstract structure for a 2D shape.
Definition Shape.h:64
Shape & moveCenter(double x, double y, LineWidthFlag lineWidthFlag=IgnoreLineWidth)
Definition Shape.cpp:64
Shape()
Definition Shape.h:330
virtual void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const =0
virtual Rect boundingBox(LineWidthFlag) const =0
virtual Point center(LineWidthFlag lineWidthFlag=IgnoreLineWidth) const
Definition Shape.cpp:59
virtual void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const =0
virtual void scaleAll(double s)=0
virtual void flushPostscript(std::ostream &stream, const TransformEPS &transform) const =0
virtual Shape & scale(double sx, double sy)=0
virtual Shape & translate(double dx, double dy)=0
Shape & resize(double width, double height, LineWidthFlag lineWidthFlag)
Definition Shape.cpp:78
virtual const std::string & name() const
Definition Shape.cpp:54
Shape & rotateDeg(double angle, const Point &center)
Definition Shape.h:337
Shape & scaleToWidth(double w, LineWidthFlag lineWidthFlag)
Definition Shape.cpp:85
Rect bbox(LineWidthFlag) const
Definition Shape.h:332
virtual Shape * clone() const =0
virtual void accept(ShapeVisitor &visitor)
Accepts a visitor object.
Definition Shape.cpp:99
virtual ~Shape()
Definition Shape.cpp:52
virtual Shape & rotate(double angle)=0
virtual Shape & scale(double s)=0
virtual void flushSVG(std::ostream &stream, const TransformSVG &transform) const =0
virtual Shape & rotate(double angle, const Point &center)=0
Shape & scaleToHeight(double h, LineWidthFlag lineWidthFlag)
Definition Shape.cpp:92
Structure representing a scaling and translation suitable for an EPS output.
Definition Transforms.h:71
Structure representing a scaling and translation suitable for an XFig output.
Definition Transforms.h:87
Structure representing a scaling and translation suitable for an SVG output.
Definition Transforms.h:109
Structure representing a scaling and translation suitable for an TikZ output.
Definition Transforms.h:126