DGtal 1.3.0
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Static Private Attributes
LibBoard::ShapeList Struct Reference

A group of shapes. More...

#include <Board/ShapeList.h>

Inheritance diagram for LibBoard::ShapeList:
LibBoard::Shape LibBoard::Board LibBoard::Group DGtal::Board2D

Public Member Functions

 ShapeList (int depth=-1)
 
 ShapeList (const ShapeList &other)
 
 ~ShapeList ()
 
const std::string & name () const
 
ShapeListclear ()
 
Point center () const
 
Shaperotate (double angle, const Point &center)
 
ShapeList rotated (double angle, const Point &center)
 
Shaperotate (double angle)
 
ShapeList rotated (double angle)
 
Shapetranslate (double dx, double dy)
 
ShapeList translated (double dx, double dy)
 
Shapescale (double sx, double sy)
 
Shapescale (double s)
 
ShapeList scaled (double sx, double sy)
 
ShapeList scaled (double s)
 
void scaleAll (double s)
 
void flushPostscript (std::ostream &stream, const TransformEPS &transform) const
 
void flushFIG (std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
 
void flushSVG (std::ostream &stream, const TransformSVG &transform) const
 
void flushCairo (cairo_t *cr, const TransformCairo &transform) const
 
void flushTikZ (std::ostream &stream, const TransformTikZ &transform) const
 
Rect boundingBox () const
 
virtual int minDepth () const
 
virtual int maxDepth () const
 
void shiftDepth (int shift)
 
Shapeclone () const
 
ShapeListoperator= (const ShapeList &other)
 
ShapeListoperator<< (const Shape &shape)
 
ShapeListoperator+= (const Shape &shape)
 
ShapeListinsert (const Shape &shape, int depth)
 
ShapeListdup (unsigned int copies=1)
 
template<typename T >
T & last (const unsigned int position=0)
 
Shapelast (const unsigned int position=0)
 
Shapetop ()
 
- Public Member Functions inherited from LibBoard::Shape
 Shape (DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, LineStyle style, const LineCap cap, const LineJoin join, int depth)
 
virtual ~Shape ()
 
virtual const std::string & name () const
 
virtual Shapeclone () const =0
 
bool filled () const
 
virtual Point center () const =0
 
virtual Shaperotate (double angle, const Point &center)=0
 
virtual Shaperotate (double angle)=0
 
ShaperotateDeg (double angle, const Point &center)
 
ShaperotateDeg (double angle)
 
virtual Shapetranslate (double dx, double dy)=0
 
virtual Shapescale (double sx, double sy)=0
 
virtual Shapescale (double s)=0
 
virtual Rect boundingBox () const =0
 
Rect bbox ()
 
Shapeoperator-- ()
 
Shapeoperator++ ()
 
virtual void scaleAll (double s)=0
 
virtual void flushPostscript (std::ostream &stream, const TransformEPS &transform) const =0
 
virtual void flushFIG (std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const =0
 
virtual void flushSVG (std::ostream &stream, const TransformSVG &transform) const =0
 
virtual void flushCairo (cairo_t *cr, const TransformCairo &transform) const =0
 
virtual void flushTikZ (std::ostream &stream, const TransformTikZ &transform) const =0
 
int depth () const
 
virtual void depth (int)
 
virtual void shiftDepth (int shift)
 
const DGtal::ColorpenColor () const
 
const DGtal::ColorfillColor () const
 

Protected Member Functions

void addShape (const Shape &shape, double scaleFactor)
 
void free ()
 
- Protected Member Functions inherited from LibBoard::Shape
std::string svgProperties (const TransformSVG &transform) const
 
std::string postscriptProperties () const
 
void setCairoDashStyle (cairo_t *cr, LineStyle type) const
 
std::string tikzProperties (const TransformTikZ &transform) const
 

Protected Attributes

std::vector< Shape * > _shapes
 
int _nextDepth
 
- Protected Attributes inherited from LibBoard::Shape
int _depth
 
DGtal::Color _penColor
 
DGtal::Color _fillColor
 
double _lineWidth
 
LineStyle _lineStyle
 
LineCap _lineCap
 
LineJoin _lineJoin
 

Static Private Attributes

static const std::string _name
 

Additional Inherited Members

- Public Types inherited from LibBoard::Shape
enum  LineCap { ButtCap = 0 , RoundCap , SquareCap }
 
enum  LineJoin { MiterJoin = 0 , RoundJoin , BevelJoin }
 
enum  LineStyle {
  SolidStyle = 0 , DashStyle , DotStyle , DashDotStyle ,
  DashDotDotStyle , DashDotDotDotStyle
}
 

Detailed Description

A group of shapes.

The ShapeList structure.

Definition at line 28 of file ShapeList.h.

Constructor & Destructor Documentation

◆ ShapeList() [1/2]

LibBoard::ShapeList::ShapeList ( int  depth = -1)
inline

References rotate().

◆ ShapeList() [2/2]

LibBoard::ShapeList::ShapeList ( const ShapeList other)

Definition at line 62 of file ShapeList.cpp.

62 : Shape( other )
63{
64 if ( ! other._shapes.size() ) return;
65 _shapes.resize( other._shapes.size(), 0 );
66 std::vector<Shape*>::iterator t = _shapes.begin();
67 std::vector<Shape*>::const_iterator i = other._shapes.begin();
68 std::vector<Shape*>::const_iterator end = other._shapes.end();
69 while ( i != end ) {
70 *t = (*i)->clone();
71 ++i;
72 ++t;
73 }
74}
std::vector< Shape * > _shapes
Definition: ShapeList.h:169

References _shapes.

◆ ~ShapeList()

LibBoard::ShapeList::~ShapeList ( )

Definition at line 37 of file ShapeList.cpp.

38{
39 free();
40}

References free().

Member Function Documentation

◆ addShape()

void LibBoard::ShapeList::addShape ( const Shape shape,
double  scaleFactor 
)
protected

Definition at line 122 of file ShapeList.cpp.

123{
124 if ( typeid( shape ) == typeid( ShapeList ) ) {
125 // Insertion on top, respecting the same depth order.
126 const ShapeList & sl = dynamic_cast<const ShapeList &>( shape );
127 std::vector<Shape*> shapes = sl._shapes;
128 stable_sort( shapes.begin(), shapes.end(), shapeGreaterDepth );
129 std::vector<Shape*>::iterator i = shapes.begin();
130 std::vector<Shape*>::iterator end = shapes.end();
131 while ( i != end ) {
132 Shape * s = (*i)->clone();
133 s->depth( _nextDepth-- );
134 if ( scaleFactor != 1.0 )
135 s->scaleAll( scaleFactor );
136 _shapes.push_back( s );
137 ++i;
138 }
139 } else {
140 Shape * s = shape.clone();
141 if ( s->depth() == -1 )
142 s->depth( _nextDepth-- );
143 if ( scaleFactor != 1.0 )
144 s->scaleAll( scaleFactor );
145 _shapes.push_back( s );
146 if ( typeid( shape ) == typeid( Group ) ) {
147 _nextDepth = dynamic_cast<const Group&>(shape).minDepth() - 1;
148 }
149 }
150}
bool shapeGreaterDepth(const Shape *s1, const Shape *s2)
Definition: Shapes.cpp:95
virtual int minDepth() const
Definition: ShapeList.cpp:395
ShapeList(int depth=-1)

References _nextDepth, _shapes, LibBoard::Shape::clone(), LibBoard::Shape::depth(), minDepth(), and LibBoard::shapeGreaterDepth().

Referenced by LibBoard::Board::operator<<().

◆ boundingBox()

Rect LibBoard::ShapeList::boundingBox ( ) const
virtual

Returns the bounding box of the figure.

Returns
The rectangle of the bounding box.

Implements LibBoard::Shape.

Reimplemented in LibBoard::Group.

Definition at line 379 of file ShapeList.cpp.

380{
381 Rect r;
382 std::vector< Shape* >::const_iterator i = _shapes.begin();
383 std::vector< Shape* >::const_iterator end = _shapes.end();
384 if ( i == end ) return r;
385 r = (*i)->boundingBox();
386 ++i;
387 while ( i != end ) {
388 r = r || (*i)->boundingBox();
389 ++i;
390 }
391 return r;
392}

References _shapes.

Referenced by LibBoard::Group::boundingBox(), LibBoard::Board::drawBoundingBox(), LibBoard::Board::saveCairo(), LibBoard::Board::saveEPS(), LibBoard::Board::saveFIG(), LibBoard::Board::saveSVG(), and LibBoard::Board::saveTikZ().

◆ center()

Point LibBoard::ShapeList::center ( ) const
virtual

Returns the gravity center of the shape.

Returns
The center of the shape.

Implements LibBoard::Shape.

Definition at line 192 of file ShapeList.cpp.

192 {
193 std::vector<Shape*>::const_iterator i = _shapes.begin();
194 std::vector<Shape*>::const_iterator end = _shapes.end();
195 double f = 1.0 / _shapes.size();
196 Point r(0,0);
197 while ( i != end ) {
198 r += f * (*i)->center();
199 ++i;
200 }
201 return r;
202}
MyPointD Point
Definition: testClone2.cpp:383

References _shapes.

Referenced by LibBoard::Board::rotate(), rotate(), LibBoard::Group::rotate(), rotated(), LibBoard::Board::scale(), scale(), and LibBoard::Group::scale().

◆ clear()

ShapeList & LibBoard::ShapeList::clear ( )

Definition at line 43 of file ShapeList.cpp.

44{
45 free();
46 _shapes.clear();
47 _nextDepth = std::numeric_limits<int>::max() - 1;
48 return *this;
49}

References _nextDepth, _shapes, and free().

Referenced by LibBoard::Board::clear().

◆ clone()

Shape * LibBoard::ShapeList::clone ( ) const
virtual

Return a copy of the shape.

Returns
copye of the shape.

Implements LibBoard::Shape.

Reimplemented in LibBoard::Group.

Definition at line 456 of file ShapeList.cpp.

457{
458 return new ShapeList( *this );
459}

◆ dup()

ShapeList & LibBoard::ShapeList::dup ( unsigned int  copies = 1)

Duplicates the last inserted shape.

Parameters
copiesThe number of copies.

Definition at line 153 of file ShapeList.cpp.

154{
155 if ( ! _shapes.size() ) {
156 warning << "dup() called with an empty list of shapes.\n";
157 return *this;
158 }
159 while ( count-- ) {
160 (*this) << (*_shapes.back());
161 }
162 return *this;
163}
MessageStream warning

References _shapes, and LibBoard::warning.

◆ flushCairo()

void LibBoard::ShapeList::flushCairo ( cairo_t *  cr,
const TransformCairo transform 
) const
virtual

Writes the cairo code of the shape in a cairo drawing context according to a transform.

Parameters
crThe cairo drawing context.
transformA 2D transform to be applied.

Implements LibBoard::Shape.

Reimplemented in LibBoard::Group.

Definition at line 347 of file ShapeList.cpp.

349{
350 std::vector< Shape* > shapes = _shapes;
351 stable_sort( shapes.begin(), shapes.end(), shapeGreaterDepth );
352 std::vector< Shape* >::const_iterator i = shapes.begin();
353 std::vector< Shape* >::const_iterator end = shapes.end();
354
355 while ( i != end ) {
356 (*i)->flushCairo( cr, transform );
357 ++i;
358 }
359}

References _shapes, and LibBoard::shapeGreaterDepth().

◆ flushFIG()

void LibBoard::ShapeList::flushFIG ( std::ostream &  stream,
const TransformFIG transform,
std::map< DGtal::Color, int > &  colormap 
) const
virtual

Writes the FIG code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.
colormapA colormap.

Implements LibBoard::Shape.

Reimplemented in LibBoard::Group.

Definition at line 315 of file ShapeList.cpp.

318{
319 std::vector< Shape* > shapes = _shapes;
320 stable_sort( shapes.begin(), shapes.end(), shapeGreaterDepth );
321 std::vector< Shape* >::const_iterator i = shapes.begin();
322 std::vector< Shape* >::const_iterator end = shapes.end();
323 while ( i != end ) {
324 (*i)->flushFIG( stream, transform, colormap );
325 ++i;
326 }
327}

References _shapes, and LibBoard::shapeGreaterDepth().

Referenced by LibBoard::Group::flushFIG().

◆ flushPostscript()

void LibBoard::ShapeList::flushPostscript ( std::ostream &  stream,
const TransformEPS transform 
) const
virtual

Writes the EPS code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.

Implements LibBoard::Shape.

Reimplemented in LibBoard::Group.

Definition at line 300 of file ShapeList.cpp.

302{
303 std::vector< Shape* > shapes = _shapes;
304 stable_sort( shapes.begin(), shapes.end(), shapeGreaterDepth );
305 std::vector< Shape* >::const_iterator i = shapes.begin();
306 std::vector< Shape* >::const_iterator end = shapes.end();
307 stream << "%%% Begin ShapeList\n";
308 while ( i != end ) {
309 (*i++)->flushPostscript( stream, transform );
310 }
311 stream << "%%% End ShapeList\n";
312}
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: ShapeList.cpp:300

References _shapes, flushPostscript(), and LibBoard::shapeGreaterDepth().

Referenced by flushPostscript(), and LibBoard::Group::flushPostscript().

◆ flushSVG()

void LibBoard::ShapeList::flushSVG ( std::ostream &  stream,
const TransformSVG transform 
) const
virtual

Writes the SVG code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.

Implements LibBoard::Shape.

Reimplemented in LibBoard::Group.

Definition at line 330 of file ShapeList.cpp.

332{
333 std::vector< Shape* > shapes = _shapes;
334 stable_sort( shapes.begin(), shapes.end(), shapeGreaterDepth );
335 std::vector< Shape* >::const_iterator i = shapes.begin();
336 std::vector< Shape* >::const_iterator end = shapes.end();
337 //stream << "<g>\n";
338 while ( i != end ) {
339 (*i)->flushSVG( stream, transform );
340 ++i;
341 }
342 //stream << "</g>\n";
343}

References _shapes, and LibBoard::shapeGreaterDepth().

Referenced by LibBoard::Group::flushSVG().

◆ flushTikZ()

void LibBoard::ShapeList::flushTikZ ( std::ostream &  stream,
const TransformTikZ transform 
) const
virtual

Writes the TikZ code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.

Implements LibBoard::Shape.

Reimplemented in LibBoard::Group.

Definition at line 363 of file ShapeList.cpp.

365{
366 std::vector< Shape* > shapes = _shapes;
367 stable_sort( shapes.begin(), shapes.end(), shapeGreaterDepth );
368 std::vector< Shape* >::const_iterator i = shapes.begin();
369 std::vector< Shape* >::const_iterator end = shapes.end();
370 stream << "\\begin{scope}\n";
371 while ( i != end ) {
372 (*i)->flushTikZ( stream, transform );
373 ++i;
374 }
375 stream << "\\end{scope}\n";
376}

References _shapes, and LibBoard::shapeGreaterDepth().

Referenced by LibBoard::Group::flushTikZ().

◆ free()

void LibBoard::ShapeList::free ( )
protected

Free the memory used by the shapes in the shape vector.

Definition at line 52 of file ShapeList.cpp.

53{
54 std::vector<Shape*>::const_iterator i = _shapes.begin();
55 std::vector<Shape*>::const_iterator end = _shapes.end();
56 while ( i != end ) {
57 delete *i;
58 ++i;
59 }
60}

References _shapes.

Referenced by clear(), LibBoard::Board::operator=(), operator=(), and ~ShapeList().

◆ insert()

ShapeList & LibBoard::ShapeList::insert ( const Shape shape,
int  depth 
)

Insert the shape at a given depth. If the shape is ShapeList or a Board, then all shapes above it will be shifted.

Parameters
shapeshape
depthdepth
Returns
shapelist
Examples
topology/ctopo-fillContours.cpp.

Definition at line 184 of file ShapeList.cpp.

185{
186 warning << "ShapeList::insert() not implemented yet.\n";
187 return *this;
188}

References LibBoard::warning.

Referenced by main().

◆ last() [1/2]

template<typename T >
T & LibBoard::ShapeList::last ( const unsigned int  position = 0)

Return the last inserted shape with its actual type, if specified (otherwise, a Shape &).

Parameters
positionThe position. 0 is the last inserted shape, 1 is the one before, etc.
Returns
A reference to the addressed shape.

◆ last() [2/2]

Shape & LibBoard::ShapeList::last ( const unsigned int  position = 0)

Definition at line 462 of file ShapeList.cpp.

463{
464 return last<Shape>( position );
465}

◆ maxDepth()

int LibBoard::ShapeList::maxDepth ( ) const
virtual

Definition at line 421 of file ShapeList.cpp.

422{
423 int res = std::numeric_limits<int>::min();
424 int d;
425 ShapeList * sl;
426 std::vector< Shape* >::const_iterator i = _shapes.begin();
427 std::vector< Shape* >::const_iterator end = _shapes.end();
428 while ( i != end ) {
429 sl = dynamic_cast<ShapeList*>( *i );
430 if ( sl ) {
431 d = sl->maxDepth();
432 } else {
433 d = (*i)->depth();
434 }
435 if ( d > res ) res = d;
436 ++i;
437 }
438 return res;
439}

References _shapes, and maxDepth().

Referenced by maxDepth(), and LibBoard::TransformFIG::setDepthRange().

◆ minDepth()

int LibBoard::ShapeList::minDepth ( ) const
virtual

Definition at line 395 of file ShapeList.cpp.

396{
397 int res = std::numeric_limits<int>::max();
398 int d;
399 ShapeList * sl;
400 std::vector< Shape* >::const_iterator i = _shapes.begin();
401 std::vector< Shape* >::const_iterator end = _shapes.end();
402 while ( i != end ) {
403 sl = dynamic_cast<ShapeList*>( *i );
404 if ( sl ) {
405 d = sl->minDepth();
406 } else {
407 d = (*i)->depth();
408 }
409 if ( d < res ) res = d;
410 ++i;
411 }
412 return res;
413}

References _shapes, and minDepth().

Referenced by addShape(), minDepth(), operator<<(), and LibBoard::TransformFIG::setDepthRange().

◆ name()

const std::string & LibBoard::ShapeList::name ( ) const
virtual

Returns the generic name of the shape (e.g., Circle, Rectangle, etc.)

Returns
object name.

Reimplemented from LibBoard::Shape.

Reimplemented in LibBoard::Group.

Definition at line 32 of file ShapeList.cpp.

33{
34 return _name;
35}
static const std::string _name
Definition: ShapeList.h:163

References _name.

◆ operator+=()

ShapeList & LibBoard::ShapeList::operator+= ( const Shape shape)

Adds a shape to the list of shape, always preserving the shape's depth.

Parameters
shapeshape to add.
Returns
updated shapelist.

Definition at line 166 of file ShapeList.cpp.

167{
168 if ( typeid( shape ) == typeid( ShapeList ) ) {
169 const ShapeList & sl = dynamic_cast<const ShapeList &>( shape );
170 std::vector<Shape*>::const_iterator i = sl._shapes.begin();
171 std::vector<Shape*>::const_iterator end = sl._shapes.end();
172 while ( i != end ) {
173 Shape * s = (*i)->clone();
174 _shapes.push_back( s );
175 ++i;
176 }
177 } else {
178 _shapes.push_back( shape.clone() );
179 }
180 return *this;
181}

References _shapes, and LibBoard::Shape::clone().

◆ operator<<()

ShapeList & LibBoard::ShapeList::operator<< ( const Shape shape)

Adds a shape to the shape list. If the shape has no given depth or is a compound shape (ShapeList) then it is placed on top of the shapes stack. Otherwise, the shape depth is left unchanged.

Parameters
shapethe shape to add.
Returns
updated shapelist.

Definition at line 93 of file ShapeList.cpp.

95{
96 if ( typeid( shape ) == typeid( ShapeList ) ) {
97 // Insertion on top, respecting the same depth order.
98 const ShapeList & sl = dynamic_cast<const ShapeList &>( shape );
99 std::vector<Shape*> shapes = sl._shapes;
100 stable_sort( shapes.begin(), shapes.end(), shapeGreaterDepth );
101 std::vector<Shape*>::iterator i = shapes.begin();
102 std::vector<Shape*>::iterator end = shapes.end();
103 while ( i != end ) {
104 Shape * s = (*i)->clone();
105 s->depth( _nextDepth-- );
106 _shapes.push_back( s );
107 ++i;
108 }
109 } else {
110 Shape * s = shape.clone();
111 if ( s->depth() == -1 )
112 s->depth( _nextDepth-- );
113 _shapes.push_back( s );
114 if ( typeid( shape ) == typeid( Group ) ) {
115 _nextDepth = dynamic_cast<const Group&>(shape).minDepth() - 1;
116 }
117 }
118 return *this;
119}

References _nextDepth, _shapes, LibBoard::Shape::clone(), LibBoard::Shape::depth(), minDepth(), and LibBoard::shapeGreaterDepth().

◆ operator=()

ShapeList & LibBoard::ShapeList::operator= ( const ShapeList other)

Definition at line 77 of file ShapeList.cpp.

78{
79 free();
80 if ( ! other._shapes.size() ) return *this;
81 _shapes.resize( other._shapes.size(), 0 );
82 std::vector<Shape*>::iterator t = _shapes.begin();
83 std::vector<Shape*>::const_iterator i = other._shapes.begin();
84 std::vector<Shape*>::const_iterator end = other._shapes.end();
85 while ( i != end ) {
86 *t = (*i)->clone();
87 ++i;
88 ++t;
89 }
90 return *this;
91}

References _shapes, and free().

Referenced by LibBoard::Group::operator=().

◆ rotate() [1/2]

Shape & LibBoard::ShapeList::rotate ( double  angle)
virtual

Rotate the shape around its center.

Parameters
angleThe rotation angle in radian.
Returns
A reference to the shape itself.

Implements LibBoard::Shape.

Reimplemented in LibBoard::Group.

Definition at line 224 of file ShapeList.cpp.

225{
226 return ShapeList::rotate( angle, center() );
227}
Shape & rotate(double angle, const Point &center)
Definition: ShapeList.cpp:205
Point center() const
Definition: ShapeList.cpp:192

References center(), and rotate().

◆ rotate() [2/2]

Shape & LibBoard::ShapeList::rotate ( double  angle,
const Point center 
)
virtual

Rotate the shape around a given center of rotation.

Parameters
angleThe rotation angle in radian.
centerThe center of rotation.
Returns
A reference to the shape itself.

Implements LibBoard::Shape.

Reimplemented in LibBoard::Group.

Definition at line 205 of file ShapeList.cpp.

206{
207 std::vector<Shape*>::iterator i = _shapes.begin();
208 std::vector<Shape*>::iterator end = _shapes.end();
209 while ( i != end ) {
210 (*i)->rotate( angle, rotCenter );
211 ++i;
212 }
213 return *this;
214}

References _shapes.

Referenced by rotate(), LibBoard::Board::rotate(), LibBoard::Group::rotate(), rotated(), and ShapeList().

◆ rotated() [1/2]

ShapeList LibBoard::ShapeList::rotated ( double  angle)

Definition at line 230 of file ShapeList.cpp.

231{
232 return static_cast<ShapeList&>( ShapeList( *this ).rotate( angle, center() ) );
233}

References center(), and rotate().

◆ rotated() [2/2]

ShapeList LibBoard::ShapeList::rotated ( double  angle,
const Point center 
)

Definition at line 217 of file ShapeList.cpp.

218{
219 ShapeList r( *this );
220 return static_cast<ShapeList&>( r.rotate( angle, rotCenter ) );
221}

◆ scale() [1/2]

Shape & LibBoard::ShapeList::scale ( double  s)
virtual

Scale the shape along both axis.

Parameters
sThe scale factor along both axis.
Returns
The shape itself.

Implements LibBoard::Shape.

Reimplemented in LibBoard::Group.

Definition at line 272 of file ShapeList.cpp.

273{
274 return ShapeList::scale( s, s );
275}
Shape & scale(double sx, double sy)
Definition: ShapeList.cpp:254

References scale().

◆ scale() [2/2]

Shape & LibBoard::ShapeList::scale ( double  sx,
double  sy 
)
virtual

Scale the shape along the x an y axis.

Parameters
sxThe scale factor along the x axis.
syThe scale factor along the y axis.
Returns
The shape itself.

Implements LibBoard::Shape.

Reimplemented in LibBoard::Group.

Definition at line 254 of file ShapeList.cpp.

255{
256 Point c = center();
257 Point delta;
258 std::vector<Shape*>::iterator i = _shapes.begin();
259 std::vector<Shape*>::iterator end = _shapes.end();
260 while ( i != end ) {
261 delta = (*i)->center() - c;
262 delta.x *= sx;
263 delta.y *= sy;
264 (*i)->scale( sx, sy );
265 delta = ( c + delta ) - (*i)->center();
266 (*i++)->translate( delta.x, delta.y );
267 }
268 return *this;
269}
Shape & translate(double dx, double dy)
Definition: ShapeList.cpp:236

References _shapes, center(), translate(), LibBoard::Point::x, and LibBoard::Point::y.

Referenced by scale(), LibBoard::Board::scale(), LibBoard::Group::scale(), and scaled().

◆ scaleAll()

void LibBoard::ShapeList::scaleAll ( double  s)
virtual

Scales all the values (positions, dimensions, etc.) associated with the shape.

Parameters
sThe scaling factor.

Implements LibBoard::Shape.

Definition at line 290 of file ShapeList.cpp.

291{
292 std::vector<Shape*>::iterator i = _shapes.begin();
293 std::vector<Shape*>::iterator end = _shapes.end();
294 while ( i != end ) {
295 (*i++)->scaleAll( s );
296 }
297}
void scaleAll(double s)
Definition: ShapeList.cpp:290

References _shapes, and scaleAll().

Referenced by scaleAll().

◆ scaled() [1/2]

ShapeList LibBoard::ShapeList::scaled ( double  s)

Definition at line 284 of file ShapeList.cpp.

285{
286 return static_cast<ShapeList&>( ShapeList( *this ).scale( s, s ) );
287}

References scale().

◆ scaled() [2/2]

ShapeList LibBoard::ShapeList::scaled ( double  sx,
double  sy 
)

Definition at line 278 of file ShapeList.cpp.

279{
280 return static_cast<ShapeList&>( ShapeList( *this ).scale( sx, sy ) );
281}

References scale().

◆ shiftDepth()

void LibBoard::ShapeList::shiftDepth ( int  shift)
virtual

Reimplemented from LibBoard::Shape.

Definition at line 446 of file ShapeList.cpp.

447{
448 std::vector< Shape* >::const_iterator i = _shapes.begin();
449 std::vector< Shape* >::const_iterator end = _shapes.end();
450 while ( i != end ) {
451 (*i++)->shiftDepth( shift );
452 }
453}
void shiftDepth(int shift)
Definition: ShapeList.cpp:446

References _shapes, and shiftDepth().

Referenced by shiftDepth().

◆ top()

Shape & LibBoard::ShapeList::top ( )

Convenience function that simply calls last(0).

Returns
top shape.

Definition at line 468 of file ShapeList.cpp.

469{
470 return last<Shape>( 0 );
471}

◆ translate()

Shape & LibBoard::ShapeList::translate ( double  dx,
double  dy 
)
virtual

Translate the shape by a given offset.

Parameters
dxThe x offset.
dyThe y offset.
Returns
A reference to the shape itself.

Implements LibBoard::Shape.

Reimplemented in LibBoard::Group.

Definition at line 236 of file ShapeList.cpp.

237{
238 std::vector<Shape*>::iterator i = _shapes.begin();
239 std::vector<Shape*>::iterator end = _shapes.end();
240 while ( i != end ) {
241 (*i)->translate( dx, dy );
242 ++i;
243 }
244 return *this;
245}

References _shapes.

Referenced by scale(), LibBoard::Board::translate(), LibBoard::Group::translate(), and translated().

◆ translated()

ShapeList LibBoard::ShapeList::translated ( double  dx,
double  dy 
)

Definition at line 248 of file ShapeList.cpp.

249{
250 return static_cast<ShapeList&>( ShapeList( *this ).translate( dx, dy ) );
251}

References translate().

Field Documentation

◆ _name

const std::string LibBoard::ShapeList::_name
staticprivate

The generic name of the shape.

Definition at line 163 of file ShapeList.h.

Referenced by name().

◆ _nextDepth

int LibBoard::ShapeList::_nextDepth
protected

◆ _shapes

std::vector<Shape*> LibBoard::ShapeList::_shapes
protected

The documentation for this struct was generated from the following files: