Board  0.9.2
ShapeList.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
27 #ifndef _BOARD_SHAPELIST_H_
28 #define _BOARD_SHAPELIST_H_
29 
30 #include "board/Shapes.h"
31 #include "board/Tools.h"
32 
33 namespace LibBoard {
34 
35 struct Group;
36 
41 struct ShapeList : public Shape {
42 
43  enum Direction { Top, Right, Bottom, Left };
44  enum Alignment { AlignTop, AlignBottom, AlignCenter, AlignLeft, AlignRight };
45 
46  inline ShapeList( int depth = -1 );
47 
48  ShapeList( const ShapeList & other );
49 
50  ShapeList & operator=( const ShapeList & other );
51 
52 #if __cplusplus > 201100
53 
54  ShapeList( ShapeList && other );
55 
56  ShapeList & operator=( ShapeList && other );
57 
58 #endif
59 
60 
69  ShapeList( const Shape & shape,
70  unsigned int times,
71  double dx, double dy, double scale );
72 
83  ShapeList( const Shape & shape,
84  unsigned int times,
85  double dx, double dy,
86  double scaleX, double scaleY,
87  double angle );
88 
89  ~ShapeList();
90 
96  const std::string & name() const;
97 
98  ShapeList & clear();
99 
100  ShapeList & rotate( double angle, const Point & center );
101 
102  ShapeList rotated( double angle, const Point & center );
103 
104  ShapeList & rotate( double angle );
105 
106  ShapeList rotated( double angle );
107 
108  ShapeList & translate( double dx, double dy );
109 
110  ShapeList translated( double dx, double dy );
111 
112  ShapeList & scale( double sx, double sy );
113 
114  ShapeList & scale( double s );
115 
116  ShapeList scaled( double sx, double sy );
117 
118  ShapeList scaled( double s );
119 
126  void scaleAll( double s );
127 
128  void flushPostscript( std::ostream & stream,
129  const TransformEPS & transform ) const;
130 
131  void flushFIG( std::ostream & stream,
132  const TransformFIG & transform,
133  std::map<Color,int> & colormap ) const;
134 
135  void flushSVG( std::ostream & stream,
136  const TransformSVG & transform ) const;
137 
138  void flushTikZ( std::ostream & stream,
139  const TransformTikZ & transform ) const;
140 
141  Rect boundingBox() const;
142 
143  virtual int minDepth() const;
144 
145  virtual int maxDepth() const;
146 
147  void shiftDepth( int shift );
148 
149  ShapeList * clone() const;
150 
160  ShapeList & operator<<( const Shape & shape );
161 
169  ShapeList & operator+=( const Shape & shape );
170 
171 
180  ShapeList & append( const Shape & shape,
181  Direction direction,
182  Alignment alignment );
183 
184 
196  Group & addTiling( const Shape & shape, Point topLeftCorner,
197  std::size_t columns, std::size_t rows,
198  double spacing = 0.0 );
199 
209  ShapeList & insert( const Shape & shape, int depth );
210 
216  ShapeList & dup( std::size_t copies = 1 );
217 
224  template<typename T>
225  T & last( const std::size_t position = 0 );
226 
227  Shape & last( const std::size_t position = 0 );
228 
236  Shape & top();
237 
238 private:
239 
240  static const std::string _name;
242 protected:
243 
244  void addShape( const Shape & shape, double scaleFactor );
245 
246  std::vector<Shape*> _shapes;
252  void free();
253 };
254 
260 struct Group : public ShapeList {
261 
262  Group( int depth = -1 )
263  : ShapeList( depth ), _clippingPath( true /* closed path */ ) { }
264 
265  Group( const Group & other )
266  : ShapeList( other ), _clippingPath( other._clippingPath ) { }
267 
268  ~Group() { }
269 
275  const std::string & name() const;
276 
277  Group & rotate( double angle, const Point & center );
278 
279  Group & rotate( double angle );
280 
281  Group rotated( double angle, const Point & center );
282 
283  Group rotated( double angle );
284 
285  Group & translate( double dx, double dy );
286 
287  Group translated( double dx, double dy );
288 
289  Group & scale( double sx, double sy );
290 
291  Group & scale( double s );
292 
293  Group scaled( double sx, double sy );
294 
295  Group scaled( double s );
296 
305  void setClippingRectangle( float x, float y,
306  float width, float height );
307 
313  void setClippingPath( const std::vector<Point> & points );
314 
320  void setClippingPath( const Path & path );
321 
322  void flushPostscript( std::ostream & stream,
323  const TransformEPS & transform ) const;
324 
325  void flushFIG( std::ostream & stream,
326  const TransformFIG & transform,
327  std::map<Color,int> & colormap ) const;
328 
329  void flushSVG( std::ostream & stream,
330  const TransformSVG & transform ) const;
331 
332  void flushTikZ( std::ostream & stream,
333  const TransformTikZ & transform ) const;
334 
335  Group & operator=( const Group & other );
336 
337  Group * clone() const;
338 
339  Rect boundingBox() const;
340 
341 private:
342  static const std::string _name;
343  Path _clippingPath;
344  static std::size_t _clippingCount;
345 };
346 
347 
348 #include "ShapeList.ih"
349 
350 
351 } // namespace LibBoard
352 
353 #endif /* _SHAPELIST_H_ */
354 
Abstract structure for a 2D shape.
Definition: Shapes.h:56
Group & addTiling(const Shape &shape, Point topLeftCorner, std::size_t columns, std::size_t rows, double spacing=0.0)
Definition: ShapeList.cpp:257
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: ShapeList.cpp:760
Rect boundingBox() const
Definition: ShapeList.cpp:770
void setClippingPath(const std::vector< Point > &points)
Definition: ShapeList.cpp:677
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: ShapeList.cpp:473
Structure representing a scaling and translation suitable for an TikZ output.
Definition: Transforms.h:130
virtual Point center() const
Definition: Shapes.cpp:88
Definition: Board.h:40
ShapeList & operator<<(const Shape &shape)
Definition: ShapeList.cpp:165
A group of shapes. A group is basically a ShapeList except that when rendered in either an SVG of a F...
Definition: ShapeList.h:260
void setClippingRectangle(float x, float y, float width, float height)
Definition: ShapeList.cpp:667
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const
Definition: ShapeList.cpp:720
ShapeList & operator+=(const Shape &shape)
Definition: ShapeList.cpp:239
A path, according to Postscript and SVG definition.
Definition: Path.h:41
ShapeList & dup(std::size_t copies=1)
Definition: ShapeList.cpp:226
Struct representing a 2D point.
Definition: Point.h:38
Structure representing a scaling and translation suitable for an XFig output.
Definition: Transforms.h:87
ShapeList & insert(const Shape &shape, int depth)
Definition: ShapeList.cpp:325
Rect boundingBox() const
Definition: ShapeList.cpp:489
void scaleAll(double s)
Definition: ShapeList.cpp:417
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: ShapeList.cpp:457
const std::string & name() const
Definition: ShapeList.cpp:582
ShapeList & rotate(double angle, const Point &center)
Definition: ShapeList.cpp:332
ShapeList & append(const Shape &shape, Direction direction, Alignment alignment)
Definition: ShapeList.cpp:282
Structure representing a scaling and translation suitable for an SVG output.
Definition: Transforms.h:109
Group & rotate(double angle, const Point &center)
Definition: ShapeList.cpp:588
A group of shapes.
Definition: ShapeList.h:41
ShapeList * clone() const
Definition: ShapeList.cpp:557
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: ShapeList.cpp:737
void free()
Definition: ShapeList.cpp:100
int _nextDepth
Definition: ShapeList.h:247
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const
Definition: ShapeList.cpp:442
T & last(const std::size_t position=0)
Definition: ShapeList.h:40
ShapeList & translate(double dx, double dy)
Definition: ShapeList.cpp:363
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: ShapeList.cpp:427
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
std::vector< Shape * > _shapes
Definition: ShapeList.h:246
const std::string & name() const
Definition: ShapeList.cpp:46
Shape & top()
Definition: ShapeList.cpp:569
Structure representing a scaling and translation suitable for an EPS output.
Definition: Transforms.h:73
Group * clone() const
Definition: ShapeList.cpp:780
Struct representing a rectangle on the plane.
Definition: Rect.h:38
Group & scale(double sx, double sy)
Definition: ShapeList.cpp:612
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: ShapeList.cpp:700
ShapeList & scale(double sx, double sy)
Definition: ShapeList.cpp:381
Group & translate(double dx, double dy)
Definition: ShapeList.cpp:604