Board  0.9.4
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 #if __cplusplus<201100
34 #define override
35 #endif
36 
37 namespace LibBoard {
38 
39 struct Group;
40 
45 struct ShapeList : public Shape {
46 
47  enum Direction { Top, Right, Bottom, Left };
48  enum Alignment { AlignTop, AlignBottom, AlignCenter, AlignLeft, AlignRight };
49 
50  inline ShapeList( int depth = -1 );
51 
52  ShapeList( const ShapeList & other );
53 
54  ShapeList & operator=( const ShapeList & other );
55 
56 #if __cplusplus > 201100
57 
58  ShapeList( ShapeList && other );
59 
60  ShapeList & operator=( ShapeList && other );
61 
62 #endif
63 
64 
73  ShapeList( const Shape & shape,
74  unsigned int times,
75  double dx, double dy,
76  double scale );
77 
88  ShapeList( const Shape & shape,
89  unsigned int times,
90  double dx, double dy,
91  double scaleX, double scaleY,
92  double angle );
93 
94  ~ShapeList();
95 
101  const std::string & name() const;
102 
103  ShapeList & clear();
104 
105  ShapeList & rotate( double angle, const Point & center );
106 
107  ShapeList rotated( double angle, const Point & center );
108 
109  ShapeList & rotate( double angle );
110 
111  ShapeList rotated( double angle );
112 
113  ShapeList & translate( double dx, double dy );
114 
115  ShapeList translated( double dx, double dy );
116 
117  ShapeList & scale( double sx, double sy );
118 
119  ShapeList & scale( double s );
120 
121  ShapeList scaled( double sx, double sy );
122 
123  ShapeList scaled( double s );
124 
131  void scaleAll( double s );
132 
133  void flushPostscript( std::ostream & stream,
134  const TransformEPS & transform ) const;
135 
136  void flushFIG( std::ostream & stream,
137  const TransformFIG & transform,
138  std::map<Color,int> & colormap ) const;
139 
140  void flushSVG( std::ostream & stream,
141  const TransformSVG & transform ) const;
142 
143  void flushTikZ( std::ostream & stream,
144  const TransformTikZ & transform ) const;
145 
146  Rect boundingBox(LineWidthFlag) const;
147 
148  virtual int minDepth() const;
149 
150  virtual int maxDepth() const;
151 
152  void shiftDepth( int shift );
153 
154  ShapeList * clone() const;
155 
165  ShapeList & operator<<( const Shape & shape );
166 
174  ShapeList & operator+=( const Shape & shape );
175 
176 
187  ShapeList & append( const Shape & shape,
188  Direction direction,
189  Alignment alignment,
190  double margin = 0.0,
191  LineWidthFlag lineWidthFlag = UseLineWidth );
192 
193 
206  Group & addTiling( const Shape & shape,
207  Point topLeftCorner,
208  std::size_t columns,
209  std::size_t rows,
210  double spacing = 0.0,
211  LineWidthFlag lineWidthFlag = UseLineWidth );
212 
223  void repeat( const Shape & shape,
224  unsigned int times,
225  double dx, double dy,
226  double scaleX = 1.0, double scaleY = 1.0,
227  double angle = 0.0 );
228 
229 
239  ShapeList & insert( const Shape & shape, int depth );
240 
246  ShapeList & dup( std::size_t copies = 1 );
247 
254  template<typename T>
255  T & last( const std::size_t position = 0 );
256 
257  Shape & last( const std::size_t position = 0 );
258 
266  Shape & top();
267 
273  virtual void accept( ShapeVisitor & visitor );
274 
280  virtual void accept( const ShapeVisitor & visitor );
281 
282 private:
283 
284  static const std::string _name;
286 protected:
287 
288  void addShape( const Shape & shape, double scaleFactor );
289 
290  std::vector<Shape*> _shapes;
296  void free();
297 };
298 
304 struct Group : public ShapeList {
305 
306  Group( int depth = -1 )
307  : ShapeList( depth ), _clippingPath( true /* closed path */ ) { }
308 
309  Group( const Group & other )
310  : ShapeList( other ), _clippingPath( other._clippingPath ) { }
311 
312  ~Group() { }
313 
319  const std::string & name() const;
320 
321  Group & rotate( double angle, const Point & center );
322 
323  Group & rotate( double angle );
324 
325  Group rotated( double angle, const Point & center );
326 
327  Group rotated( double angle );
328 
329  Group & translate( double dx, double dy );
330 
331  Group translated( double dx, double dy );
332 
333  Group & scale( double sx, double sy );
334 
335  Group & scale( double s );
336 
337  Group scaled( double sx, double sy );
338 
339  Group scaled( double s );
340 
349  void setClippingRectangle( float x, float y,
350  float width, float height );
351 
357  void setClippingPath( const std::vector<Point> & points );
358 
364  void setClippingPath( const Path & path );
365 
366  void flushPostscript( std::ostream & stream,
367  const TransformEPS & transform ) const;
368 
369  void flushFIG( std::ostream & stream,
370  const TransformFIG & transform,
371  std::map<Color,int> & colormap ) const;
372 
373  void flushSVG( std::ostream & stream,
374  const TransformSVG & transform ) const;
375 
376  void flushTikZ( std::ostream & stream,
377  const TransformTikZ & transform ) const;
378 
379  Group & operator=( const Group & other );
380 
381  Group * clone() const;
382 
383  Rect boundingBox(LineWidthFlag) const;
384 
385 private:
386  static const std::string _name;
387  Path _clippingPath;
388  static std::size_t _clippingCount;
389 };
390 
391 
392 #include "ShapeList.ih"
393 
394 } // namespace LibBoard
395 
396 
397 #if __cplusplus<201100
398 #undef override
399 #endif
400 
401 
402 #endif /* _SHAPELIST_H_ */
403 
Abstract structure for a 2D shape.
Definition: Shapes.h:62
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: ShapeList.cpp:803
void setClippingPath(const std::vector< Point > &points)
Definition: ShapeList.cpp:720
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: ShapeList.cpp:497
Structure representing a scaling and translation suitable for an TikZ output.
Definition: Transforms.h:137
Definition: Board.h:41
ShapeList & operator<<(const Shape &shape)
Definition: ShapeList.cpp:167
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 setClippingRectangle(float x, float y, float width, float height)
Definition: ShapeList.cpp:710
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const
Definition: ShapeList.cpp:763
ShapeList & operator+=(const Shape &shape)
Definition: ShapeList.cpp:241
A path, according to Postscript and SVG definition.
Definition: Path.h:41
void repeat(const Shape &shape, unsigned int times, double dx, double dy, double scaleX=1.0, double scaleY=1.0, double angle=0.0)
Definition: ShapeList.cpp:286
ShapeList & dup(std::size_t copies=1)
Definition: ShapeList.cpp:228
Struct representing a 2D point.
Definition: Point.h:39
Structure representing a scaling and translation suitable for an XFig output.
Definition: Transforms.h:93
ShapeList & insert(const Shape &shape, int depth)
Definition: ShapeList.cpp:349
void scaleAll(double s)
Definition: ShapeList.cpp:441
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: ShapeList.cpp:481
const std::string & name() const
Definition: ShapeList.cpp:625
ShapeList & rotate(double angle, const Point &center)
Definition: ShapeList.cpp:356
Structure representing a scaling and translation suitable for an SVG output.
Definition: Transforms.h:116
ShapeList & append(const Shape &shape, Direction direction, Alignment alignment, double margin=0.0, LineWidthFlag lineWidthFlag=UseLineWidth)
Definition: ShapeList.cpp:299
Group & rotate(double angle, const Point &center)
Definition: ShapeList.cpp:631
Group & addTiling(const Shape &shape, Point topLeftCorner, std::size_t columns, std::size_t rows, double spacing=0.0, LineWidthFlag lineWidthFlag=UseLineWidth)
Definition: ShapeList.cpp:259
A group of shapes.
Definition: ShapeList.h:45
ShapeList * clone() const
Definition: ShapeList.cpp:581
virtual void accept(ShapeVisitor &visitor)
Accepts a visitor object.
Definition: ShapeList.cpp:599
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: ShapeList.cpp:780
void free()
Definition: ShapeList.cpp:102
int _nextDepth
Definition: ShapeList.h:291
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
Rect boundingBox(LineWidthFlag) const
Definition: ShapeList.cpp:813
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const
Definition: ShapeList.cpp:466
T & last(const std::size_t position=0)
Definition: ShapeList.h:40
ShapeList & translate(double dx, double dy)
Definition: ShapeList.cpp:387
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: ShapeList.cpp:451
Rect boundingBox(LineWidthFlag) const
Definition: ShapeList.cpp:513
@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:290
const std::string & name() const
Definition: ShapeList.cpp:47
Shape & top()
Definition: ShapeList.cpp:593
Structure representing a scaling and translation suitable for an EPS output.
Definition: Transforms.h:73
virtual Point center(LineWidthFlag lineWidthFlag=IgnoreLineWidth) const
Definition: Shapes.cpp:101
Group * clone() const
Definition: ShapeList.cpp:823
Definition: ShapeVisitor.h:40
Struct representing a rectangle on the plane.
Definition: Rect.h:38
Group & scale(double sx, double sy)
Definition: ShapeList.cpp:655
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: ShapeList.cpp:743
ShapeList & scale(double sx, double sy)
Definition: ShapeList.cpp:405
Group & translate(double dx, double dy)
Definition: ShapeList.cpp:647