DGtal  1.2.0
ShapeList.h
1 /* -*- mode: c++ -*- */
10 /*
11  * \@copyright This File is part of the Board library which is
12  * licensed under the terms of the GNU Lesser General Public Licence.
13  * See the LICENCE file for further details.
14  */
15 #ifndef _BOARD_SHAPELIST_H_
16 #define _BOARD_SHAPELIST_H_
17 
18 #include "Board/Shapes.h"
19 #include "Board/Tools.h"
20 
21 namespace LibBoard {
22 
23 
28 struct ShapeList : public Shape {
29 
30 
31  inline ShapeList( int depth = -1 );
32 
33  ShapeList( const ShapeList & other );
34 
35  ~ShapeList();
36 
42  const std::string & name() const;
43 
44  ShapeList & clear();
45 
46  Point center() const;
47 
48  Shape & rotate( double angle, const Point & center );
49 
50  ShapeList rotated( double angle, const Point & center );
51 
52  Shape & rotate( double angle );
53 
54  ShapeList rotated( double angle );
55 
56  Shape & translate( double dx, double dy );
57 
58  ShapeList translated( double dx, double dy );
59 
60  Shape & scale( double sx, double sy );
61 
62  Shape & scale( double s );
63 
64  ShapeList scaled( double sx, double sy );
65 
66  ShapeList scaled( double s );
67 
74  void scaleAll( double s );
75 
76  void flushPostscript( std::ostream & stream,
77  const TransformEPS & transform ) const;
78 
79  void flushFIG( std::ostream & stream,
80  const TransformFIG & transform,
81  std::map<DGtal::Color,int> & colormap ) const;
82 
83  void flushSVG( std::ostream & stream,
84  const TransformSVG & transform ) const;
85 
86 #ifdef WITH_CAIRO
87  void flushCairo( cairo_t *cr,
88  const TransformCairo & transform ) const;
89 #endif
90 
91  void flushTikZ( std::ostream & stream,
92  const TransformTikZ & transform ) const;
93 
94  Rect boundingBox() const;
95 
96  virtual int minDepth() const;
97 
98  virtual int maxDepth() const;
99 
100  void shiftDepth( int shift );
101 
102  Shape * clone() const;
103 
104  ShapeList & operator=( const ShapeList & other );
105 
115  ShapeList & operator<<( const Shape & shape );
116 
124  ShapeList & operator+=( const Shape & shape );
125 
135  ShapeList & insert( const Shape & shape, int depth );
136 
142  ShapeList & dup( unsigned int copies = 1 );
143 
150  template<typename T>
151  T & last( const unsigned int position = 0 );
152 
153  Shape & last( const unsigned int position = 0 );
154 
160  Shape & top();
161 
162 private:
163  static const std::string _name;
165 protected:
166 
167  void addShape( const Shape & shape, double scaleFactor );
168 
169  std::vector<Shape*> _shapes;
175  void free();
176 };
177 
183 struct Group : public ShapeList {
184 
185  Group( int depthValue = -1 )
186  : ShapeList( depthValue ), _clippingPath( true /* closed path */ ) { }
187 
188  Group( const Group & other )
189  : ShapeList( other ), _clippingPath( other._clippingPath ) { }
190 
191  ~Group() { };
192 
198  const std::string & name() const;
199 
200  Shape & rotate( double angle, const Point & center );
201 
202  Shape & rotate( double angle );
203 
204  Group rotated( double angle, const Point & center );
205 
206  Group rotated( double angle );
207 
208  Shape & translate( double dx, double dy );
209 
210  Group translated( double dx, double dy );
211 
212  Shape & scale( double sx, double sy );
213 
214  Shape & scale( double s );
215 
216  Group scaled( double sx, double sy );
217 
218  Group scaled( double s );
219 
228  void setClippingRectangle( float x, float y,
229  float width, float height );
230 
236  void setClippingPath( const std::vector<Point> & points );
237 
243  void setClippingPath( const Path & path );
244 
245 
246  void flushPostscript( std::ostream & stream,
247  const TransformEPS & transform ) const;
248 
249  void flushFIG( std::ostream & stream,
250  const TransformFIG & transform,
251  std::map<DGtal::Color,int> & colormap ) const;
252 
253  void flushSVG( std::ostream & stream,
254  const TransformSVG & transform ) const;
255 
256 #ifdef WITH_CAIRO
257  void flushCairo( cairo_t *cr,
258  const TransformCairo & transform ) const;
259 #endif
260 
261  void flushTikZ( std::ostream & stream,
262  const TransformTikZ & transform ) const;
263 
264  Group & operator=( const Group & other );
265 
266  Shape * clone() const;
267 
268  Rect boundingBox() const;
269 
270 private:
271  static const std::string _name;
273  static unsigned int _clippingCount;
274 };
275 
276 
277 #include "ShapeList.ih"
278 
279 
280 } // namespace LibBoard
281 
282 #endif /* _SHAPELIST_H_ */
283 
A group of shapes. A group is basically a ShapeList except that when rendered in either an SVG of a F...
Definition: ShapeList.h:183
static unsigned int _clippingCount
Definition: ShapeList.h:273
Path _clippingPath
Definition: ShapeList.h:272
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: ShapeList.cpp:637
Shape & rotate(double angle, const Point &center)
Definition: ShapeList.cpp:487
Group(const Group &other)
Definition: ShapeList.h:188
Group rotated(double angle, const Point &center)
Definition: ShapeList.cpp:536
static const std::string _name
Definition: ShapeList.h:271
const std::string & name() const
Definition: ShapeList.cpp:481
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
Definition: ShapeList.cpp:620
Shape * clone() const
Definition: ShapeList.cpp:690
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
Definition: ShapeList.cpp:661
Rect boundingBox() const
Definition: ShapeList.cpp:680
Group(int depthValue=-1)
Definition: ShapeList.h:185
Group scaled(double sx, double sy)
Definition: ShapeList.cpp:554
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: ShapeList.cpp:600
Group & operator=(const Group &other)
Definition: ShapeList.cpp:696
Group translated(double dx, double dy)
Definition: ShapeList.cpp:548
Shape & translate(double dx, double dy)
Definition: ShapeList.cpp:503
Shape & scale(double sx, double sy)
Definition: ShapeList.cpp:511
void setClippingPath(const std::vector< Point > &points)
Definition: ShapeList.cpp:577
void setClippingRectangle(float x, float y, float width, float height)
Definition: ShapeList.cpp:567
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: ShapeList.cpp:670
A path, according to Postscript and SVG definition.
Definition: Path.h:43
Struct representing a 2D point.
Definition: Point.h:27
Struct representing a rectangle on the plane.
Definition: Rect.h:26
A group of shapes.
Definition: ShapeList.h:28
void addShape(const Shape &shape, double scaleFactor)
Definition: ShapeList.cpp:122
ShapeList scaled(double sx, double sy)
Definition: ShapeList.cpp:278
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
Definition: ShapeList.cpp:347
const std::string & name() const
Definition: ShapeList.cpp:32
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: ShapeList.cpp:300
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
Definition: ShapeList.cpp:315
Shape & rotate(double angle, const Point &center)
Definition: ShapeList.cpp:205
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: ShapeList.cpp:330
virtual int minDepth() const
Definition: ShapeList.cpp:395
std::vector< Shape * > _shapes
Definition: ShapeList.h:169
T & last(const unsigned int position=0)
ShapeList(int depth=-1)
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: ShapeList.cpp:363
Shape & translate(double dx, double dy)
Definition: ShapeList.cpp:236
void shiftDepth(int shift)
Definition: ShapeList.cpp:446
ShapeList & insert(const Shape &shape, int depth)
Definition: ShapeList.cpp:184
ShapeList & dup(unsigned int copies=1)
Definition: ShapeList.cpp:153
Shape & scale(double sx, double sy)
Definition: ShapeList.cpp:254
ShapeList translated(double dx, double dy)
Definition: ShapeList.cpp:248
static const std::string _name
Definition: ShapeList.h:163
Point center() const
Definition: ShapeList.cpp:192
ShapeList rotated(double angle, const Point &center)
Definition: ShapeList.cpp:217
Rect boundingBox() const
Definition: ShapeList.cpp:379
virtual int maxDepth() const
Definition: ShapeList.cpp:421
ShapeList & operator<<(const Shape &shape)
Definition: ShapeList.cpp:94
ShapeList & operator+=(const Shape &shape)
Definition: ShapeList.cpp:166
ShapeList & operator=(const ShapeList &other)
Definition: ShapeList.cpp:77
Shape * clone() const
Definition: ShapeList.cpp:456
void scaleAll(double s)
Definition: ShapeList.cpp:290
ShapeList & clear()
Definition: ShapeList.cpp:43
Abstract structure for a 2D shape.
Definition: Board/Shapes.h:58
Structure representing a scaling and translation suitable for an Cairo output.
Definition: Transforms.h:112
Structure representing a scaling and translation suitable for an EPS output.
Definition: Transforms.h:59
Structure representing a scaling and translation suitable for an XFig output.
Definition: Transforms.h:73
Structure representing a scaling and translation suitable for an SVG output.
Definition: Transforms.h:95
Structure representing a scaling and translation suitable for an TikZ output.
Definition: Transforms.h:129