00001
00011 #ifndef _BOARD_SHAPELIST_H_
00012 #define _BOARD_SHAPELIST_H_
00013
00014 #include "board/Shapes.h"
00015 #include "board/Tools.h"
00016
00017 namespace LibBoard {
00018
00023 struct ShapeList : public Shape {
00024
00025 ShapeList( int depth = -1 )
00026 : Shape( Color::None, Color::None, 1.0, ButtCap, MiterJoin, depth ),
00027 _nextDepth( std::numeric_limits<int>::max() - 1 )
00028 { }
00029
00030 ShapeList( const ShapeList & other );
00031
00032 ~ShapeList();
00033
00039 const std::string & name() const;
00040
00041 ShapeList & clear();
00042
00043 Point center() const;
00044
00045 Shape & rotate( double angle, const Point & center );
00046
00047 ShapeList rotated( double angle, const Point & center );
00048
00049 Shape & rotate( double angle );
00050
00051 ShapeList rotated( double angle );
00052
00053 Shape & translate( double dx, double dy );
00054
00055 ShapeList translated( double dx, double dy );
00056
00057 Shape & scale( double sx, double sy );
00058
00059 Shape & scale( double s );
00060
00061 ShapeList scaled( double sx, double sy );
00062
00063 ShapeList scaled( double s );
00064
00071 void scaleAll( double s );
00072
00073 void flushPostscript( std::ostream & stream,
00074 const TransformEPS & transform ) const;
00075
00076 void flushFIG( std::ostream & stream,
00077 const TransformFIG & transform,
00078 std::map<Color,int> & colormap ) const;
00079
00080 void flushSVG( std::ostream & stream,
00081 const TransformSVG & transform ) const;
00082
00083 Rect boundingBox() const;
00084
00085 virtual int minDepth() const;
00086
00087 virtual int maxDepth() const;
00088
00089 void shiftDepth( int shift );
00090
00091 Shape * clone() const;
00092
00093 ShapeList & operator=( const ShapeList & other );
00094
00104 ShapeList & operator<<( const Shape & shape );
00105
00113 ShapeList & operator+=( const Shape & shape );
00114
00124 ShapeList & insert( const Shape & shape, int depth );
00125
00131 ShapeList & dup( unsigned int copies = 1 );
00132
00139 template<typename T>
00140 T & last( const unsigned int position = 0 );
00141
00142 Shape & last( const unsigned int position = 0 );
00143
00151 Shape & top();
00152
00153 private:
00154 static const std::string _name;
00156 protected:
00157
00158 void addShape( const Shape & shape, double scaleFactor );
00159
00160 std::vector<Shape*> _shapes;
00161 int _nextDepth;
00166 void free();
00167 };
00168
00174 struct Group : public ShapeList {
00175
00176 Group( int depth = -1 ):ShapeList( depth ) { }
00177
00178 Group( const Group & other ) : ShapeList( other ) { };
00179
00180 ~Group() { };
00181
00187 const std::string & name() const;
00188
00189 Group rotated( double angle, const Point & center );
00190
00191 Group rotated( double angle );
00192
00193 Group translated( double dx, double dy );
00194
00195 Group scaled( double sx, double sy );
00196
00197 Group scaled( double s );
00198
00199 void flushPostscript( std::ostream & stream,
00200 const TransformEPS & transform ) const;
00201
00202 void flushFIG( std::ostream & stream,
00203 const TransformFIG & transform,
00204 std::map<Color,int> & colormap ) const;
00205
00206 void flushSVG( std::ostream & stream,
00207 const TransformSVG & transform ) const;
00208
00209 Group & operator=( const Group & other );
00210
00211 Shape * clone() const;
00212
00213 private:
00214 static const std::string _name;
00215 };
00216
00217 template<typename T>
00218 T &
00219 ShapeList::last( const unsigned int position )
00220 {
00221 if ( position < _shapes.size() ) {
00222 std::vector<Shape*>::reverse_iterator it = _shapes.rbegin() + position;
00223 return dynamic_cast<T&>( *(*it) );
00224 } else {
00225 error << "Trying to access an element that does not exist ("
00226 << position << "/" << _shapes.size() << ").\n";
00227 throw -1;
00228 }
00229 }
00230
00231 }
00232
00233 #endif
00234