DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 
162  Shape & top();
163 
164 private:
165  static const std::string _name;
167 protected:
168 
169  void addShape( const Shape & shape, double scaleFactor );
170 
171  std::vector<Shape*> _shapes;
172  int _nextDepth;
177  void free();
178 };
179 
185 struct Group : public ShapeList {
186 
187  Group( int depthValue = -1 )
188  : ShapeList( depthValue ), _clippingPath( true /* closed path */ ) { }
189 
190  Group( const Group & other )
191  : ShapeList( other ), _clippingPath( other._clippingPath ) { }
192 
193  ~Group() { };
194 
200  const std::string & name() const;
201 
202  Shape & rotate( double angle, const Point & center );
203 
204  Shape & rotate( double angle );
205 
206  Group rotated( double angle, const Point & center );
207 
208  Group rotated( double angle );
209 
210  Shape & translate( double dx, double dy );
211 
212  Group translated( double dx, double dy );
213 
214  Shape & scale( double sx, double sy );
215 
216  Shape & scale( double s );
217 
218  Group scaled( double sx, double sy );
219 
220  Group scaled( double s );
221 
230  void setClippingRectangle( float x, float y,
231  float width, float height );
232 
238  void setClippingPath( const std::vector<Point> & points );
239 
245  void setClippingPath( const Path & path );
246 
247 
248  void flushPostscript( std::ostream & stream,
249  const TransformEPS & transform ) const;
250 
251  void flushFIG( std::ostream & stream,
252  const TransformFIG & transform,
253  std::map<DGtal::Color,int> & colormap ) const;
254 
255  void flushSVG( std::ostream & stream,
256  const TransformSVG & transform ) const;
257 
258 #ifdef WITH_CAIRO
259  void flushCairo( cairo_t *cr,
260  const TransformCairo & transform ) const;
261 #endif
262 
263  void flushTikZ( std::ostream & stream,
264  const TransformTikZ & transform ) const;
265 
266  Group & operator=( const Group & other );
267 
268  Shape * clone() const;
269 
270  Rect boundingBox() const;
271 
272 private:
273  static const std::string _name;
274  Path _clippingPath;
275  static unsigned int _clippingCount;
276 };
277 
278 
279 #include "ShapeList.ih"
280 
281 
282 } // namespace LibBoard
283 
284 #endif /* _SHAPELIST_H_ */
285