DGtal  1.3.beta
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 
LibBoard::ShapeList::translate
Shape & translate(double dx, double dy)
Definition: ShapeList.cpp:236
LibBoard::ShapeList::flushCairo
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
Definition: ShapeList.cpp:347
LibBoard::Group::setClippingPath
void setClippingPath(const std::vector< Point > &points)
Definition: ShapeList.cpp:577
LibBoard::Group::flushPostscript
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: ShapeList.cpp:600
LibBoard::Group::Group
Group(const Group &other)
Definition: ShapeList.h:188
LibBoard::Group::flushCairo
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
Definition: ShapeList.cpp:661
LibBoard::Group::scaled
Group scaled(double sx, double sy)
Definition: ShapeList.cpp:554
LibBoard::ShapeList::dup
ShapeList & dup(unsigned int copies=1)
Definition: ShapeList.cpp:153
LibBoard::Group::_clippingCount
static unsigned int _clippingCount
Definition: ShapeList.h:273
LibBoard::Rect
Struct representing a rectangle on the plane.
Definition: Rect.h:26
LibBoard::ShapeList::addShape
void addShape(const Shape &shape, double scaleFactor)
Definition: ShapeList.cpp:122
LibBoard::Group::scale
Shape & scale(double sx, double sy)
Definition: ShapeList.cpp:511
LibBoard::ShapeList::maxDepth
virtual int maxDepth() const
Definition: ShapeList.cpp:421
LibBoard::TransformCairo
Structure representing a scaling and translation suitable for an Cairo output.
Definition: Transforms.h:112
LibBoard::ShapeList::flushPostscript
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: ShapeList.cpp:300
LibBoard::ShapeList::flushSVG
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: ShapeList.cpp:330
LibBoard::ShapeList::~ShapeList
~ShapeList()
Definition: ShapeList.cpp:37
LibBoard::Group::flushTikZ
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: ShapeList.cpp:670
LibBoard::Group::setClippingRectangle
void setClippingRectangle(float x, float y, float width, float height)
Definition: ShapeList.cpp:567
LibBoard::ShapeList::last
T & last(const unsigned int position=0)
LibBoard::Group::~Group
~Group()
Definition: ShapeList.h:191
LibBoard::Group::rotated
Group rotated(double angle, const Point &center)
Definition: ShapeList.cpp:536
LibBoard::ShapeList::scaleAll
void scaleAll(double s)
Definition: ShapeList.cpp:290
LibBoard::ShapeList::insert
ShapeList & insert(const Shape &shape, int depth)
Definition: ShapeList.cpp:184
LibBoard::ShapeList::clone
Shape * clone() const
Definition: ShapeList.cpp:456
LibBoard::ShapeList::ShapeList
ShapeList(int depth=-1)
LibBoard::Group::flushSVG
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: ShapeList.cpp:637
LibBoard::ShapeList::flushFIG
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
Definition: ShapeList.cpp:315
LibBoard::Group::boundingBox
Rect boundingBox() const
Definition: ShapeList.cpp:680
LibBoard::Point
Struct representing a 2D point.
Definition: Point.h:27
LibBoard::ShapeList::operator=
ShapeList & operator=(const ShapeList &other)
Definition: ShapeList.cpp:77
LibBoard::ShapeList::minDepth
virtual int minDepth() const
Definition: ShapeList.cpp:395
LibBoard::TransformEPS
Structure representing a scaling and translation suitable for an EPS output.
Definition: Transforms.h:59
LibBoard::Shape
Abstract structure for a 2D shape.
Definition: Board/Shapes.h:58
LibBoard::Group::translate
Shape & translate(double dx, double dy)
Definition: ShapeList.cpp:503
LibBoard::Group::clone
Shape * clone() const
Definition: ShapeList.cpp:690
LibBoard::ShapeList::_nextDepth
int _nextDepth
Definition: ShapeList.h:170
LibBoard::ShapeList::rotate
Shape & rotate(double angle, const Point &center)
Definition: ShapeList.cpp:205
LibBoard::ShapeList::top
Shape & top()
Definition: ShapeList.cpp:468
LibBoard::ShapeList::translated
ShapeList translated(double dx, double dy)
Definition: ShapeList.cpp:248
LibBoard::Path
A path, according to Postscript and SVG definition.
Definition: Path.h:43
LibBoard
Definition: Board.cpp:87
LibBoard::ShapeList::clear
ShapeList & clear()
Definition: ShapeList.cpp:43
LibBoard::ShapeList::_name
static const std::string _name
Definition: ShapeList.h:163
LibBoard::ShapeList::boundingBox
Rect boundingBox() const
Definition: ShapeList.cpp:379
LibBoard::TransformTikZ
Structure representing a scaling and translation suitable for an TikZ output.
Definition: Transforms.h:129
LibBoard::Group::_clippingPath
Path _clippingPath
Definition: ShapeList.h:272
LibBoard::Group
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
LibBoard::TransformFIG
Structure representing a scaling and translation suitable for an XFig output.
Definition: Transforms.h:73
LibBoard::Group::flushFIG
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
Definition: ShapeList.cpp:620
LibBoard::Group::name
const std::string & name() const
Definition: ShapeList.cpp:481
LibBoard::ShapeList
A group of shapes.
Definition: ShapeList.h:28
LibBoard::ShapeList::center
Point center() const
Definition: ShapeList.cpp:192
LibBoard::ShapeList::flushTikZ
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: ShapeList.cpp:363
LibBoard::ShapeList::scale
Shape & scale(double sx, double sy)
Definition: ShapeList.cpp:254
LibBoard::Group::Group
Group(int depthValue=-1)
Definition: ShapeList.h:185
LibBoard::ShapeList::rotated
ShapeList rotated(double angle, const Point &center)
Definition: ShapeList.cpp:217
LibBoard::ShapeList::scaled
ShapeList scaled(double sx, double sy)
Definition: ShapeList.cpp:278
LibBoard::ShapeList::operator<<
ShapeList & operator<<(const Shape &shape)
Definition: ShapeList.cpp:94
LibBoard::ShapeList::_shapes
std::vector< Shape * > _shapes
Definition: ShapeList.h:169
LibBoard::Group::translated
Group translated(double dx, double dy)
Definition: ShapeList.cpp:548
LibBoard::Group::rotate
Shape & rotate(double angle, const Point &center)
Definition: ShapeList.cpp:487
LibBoard::ShapeList::name
const std::string & name() const
Definition: ShapeList.cpp:32
LibBoard::ShapeList::operator+=
ShapeList & operator+=(const Shape &shape)
Definition: ShapeList.cpp:166
LibBoard::Group::_name
static const std::string _name
Definition: ShapeList.h:271
LibBoard::TransformSVG
Structure representing a scaling and translation suitable for an SVG output.
Definition: Transforms.h:95
LibBoard::ShapeList::free
void free()
Definition: ShapeList.cpp:52
LibBoard::Group::operator=
Group & operator=(const Group &other)
Definition: ShapeList.cpp:696
LibBoard::ShapeList::shiftDepth
void shiftDepth(int shift)
Definition: ShapeList.cpp:446