Go to the documentation of this file.
27 #ifndef BOARD_SHAPELIST_H
28 #define BOARD_SHAPELIST_H
48 typedef std::vector<Shape *>::size_type size_type;
96 ShapeList(
const Shape & shape,
unsigned int times,
double dx,
double dy,
double scaleX,
double scaleY,
double angle);
105 const std::string &
name()
const override;
171 void flushFIG(std::ostream & stream,
const TransformFIG & transform, std::map<Color, int> & colormap)
const override;
219 ShapeList &
append(
const Shape & shape, Direction direction = ShapeList::Right, Alignment alignment = ShapeList::AlignCenter,
double margin = 0.0, LineWidthFlag lineWidthFlag = UseLineWidth);
233 Group &
addTiling(
const Shape & shape,
Point topLeftCorner, std::size_t columns, std::size_t rows,
double spacing = 0.0, LineWidthFlag lineWidthFlag = UseLineWidth);
245 void repeat(
const Shape & shape,
unsigned int times,
double dx,
double dy,
double scaleX = 1.0,
double scaleY = 1.0,
double angle = 0.0);
260 template <
typename T> T &
last(
const std::size_t position = 0);
268 Shape &
last(
const std::size_t position = 0);
331 inline Shape & operator*();
332 inline Shape * operator->();
333 inline Shape * pointer();
340 std::vector<Shape *>::iterator _it;
350 inline const Shape & operator*();
351 inline const Shape * operator->();
352 inline const Shape * pointer();
359 std::vector<Shape *>::const_iterator _it;
369 inline Shape & operator*();
370 inline Shape * operator->();
371 inline Shape * pointer();
378 void moveToFirstActuelShape();
379 void moveToNextActualShape();
380 std::stack<ShapeList *> _shapeListsStack;
381 std::stack<TopLevelIterator> _iteratorsStack;
391 inline Shape & operator*();
392 inline Shape * operator->();
393 inline Shape * pointer();
400 void moveToFirstActuelShape();
401 void moveToNextActualShape();
402 std::queue<ShapeList *> _shapeListsQueue;
403 std::queue<TopLevelIterator> _iteratorsQueue;
476 inline std::size_t
size()
const;
479 static const std::string _name;
482 void addShape(
const Shape & shape,
double scaleFactor);
496 #define HAS_MSVC_MAX true
499 ShapeList::ShapeList() {}
503 if (position <
_shapes.size()) {
504 std::vector<Shape *>::reverse_iterator it =
_shapes.rbegin() +
static_cast<std::vector<Shape *>::difference_type
>(position);
505 Shape * pshape = *it;
506 T * result =
dynamic_cast<T *
>(pshape);
508 std::cerr <<
"Error: ShapeList::last<> called with invalid result type\n";
511 return dynamic_cast<T &
>(*result);
513 Tools::error <<
"Trying to access an element that does not exist (" << position <<
"/" <<
_shapes.size() <<
").\n";
520 std::vector<Shape *>::reverse_iterator it =
_shapes.rbegin();
522 T * shape =
dynamic_cast<T *
>(*it);
532 throw Exception(
"topLevelFindLast<T>(): no such shape type found (" + std::string(
typeid(T).
name()) +
")");
535 ShapeList::TopLevelIterator::TopLevelIterator(std::vector<Shape *>::iterator it) : _it(it) {}
537 Shape & ShapeList::TopLevelIterator::operator*()
542 Shape * ShapeList::TopLevelIterator::operator->()
547 Shape * ShapeList::TopLevelIterator::pointer()
552 ShapeList::TopLevelIterator & ShapeList::TopLevelIterator::operator++()
558 ShapeList::TopLevelIterator ShapeList::TopLevelIterator::operator++(
int)
560 TopLevelIterator previous(*
this);
565 bool ShapeList::TopLevelIterator::operator==(
const TopLevelIterator & other)
567 return _it == other._it;
570 bool ShapeList::TopLevelIterator::operator!=(
const TopLevelIterator & other)
572 return _it != other._it;
575 ShapeList::TopLevelConstIterator::TopLevelConstIterator(std::vector<Shape *>::const_iterator it) : _it(it) {}
577 const Shape & ShapeList::TopLevelConstIterator::operator*()
582 const Shape * ShapeList::TopLevelConstIterator::operator->()
587 const Shape * ShapeList::TopLevelConstIterator::pointer()
592 ShapeList::TopLevelConstIterator & ShapeList::TopLevelConstIterator::operator++()
598 ShapeList::TopLevelConstIterator ShapeList::TopLevelConstIterator::operator++(
int)
600 TopLevelConstIterator previous(*
this);
605 bool ShapeList::TopLevelConstIterator::operator==(
const TopLevelConstIterator & other)
607 return _it == other._it;
610 bool ShapeList::TopLevelConstIterator::operator!=(
const TopLevelConstIterator & other)
612 return _it != other._it;
627 return TopLevelConstIterator(
_shapes.begin());
637 return TopLevelConstIterator(
_shapes.end());
670 ShapeList::DepthFirstIterator::DepthFirstIterator() {}
672 ShapeList::DepthFirstIterator::DepthFirstIterator(ShapeList * list)
674 _shapeListsStack.push(list);
675 _iteratorsStack.push(list->begin());
676 moveToFirstActuelShape();
679 Shape & ShapeList::DepthFirstIterator::operator*()
681 return *(_iteratorsStack.top());
684 Shape * ShapeList::DepthFirstIterator::operator->()
689 Shape * ShapeList::DepthFirstIterator::pointer()
691 return _iteratorsStack.top().pointer();
694 bool ShapeList::DepthFirstIterator::operator==(
const DepthFirstIterator & other)
696 return (_shapeListsStack.empty() && other._shapeListsStack.empty()) ||
697 ((!_shapeListsStack.empty() && !other._shapeListsStack.empty()) && (_shapeListsStack.top() == other._shapeListsStack.top()) && (_iteratorsStack.top() == other._iteratorsStack.top()));
700 bool ShapeList::DepthFirstIterator::operator!=(
const DepthFirstIterator & other)
702 return !(*
this == other);
705 ShapeList::DepthFirstIterator & ShapeList::DepthFirstIterator::operator++()
707 moveToNextActualShape();
711 ShapeList::DepthFirstIterator ShapeList::DepthFirstIterator::operator++(
int)
713 DepthFirstIterator currentValue(*
this);
714 moveToNextActualShape();
718 ShapeList::BreadthFirstIterator::BreadthFirstIterator() {}
720 ShapeList::BreadthFirstIterator::BreadthFirstIterator(ShapeList * list)
722 _shapeListsQueue.push(list);
723 _iteratorsQueue.push(list->begin());
724 moveToFirstActuelShape();
727 Shape & ShapeList::BreadthFirstIterator::operator*()
729 return *(_iteratorsQueue.front());
732 Shape * ShapeList::BreadthFirstIterator::operator->()
737 Shape * ShapeList::BreadthFirstIterator::pointer()
739 return _iteratorsQueue.front().pointer();
742 bool ShapeList::BreadthFirstIterator::operator==(
const BreadthFirstIterator & other)
744 return (_shapeListsQueue.empty() && other._shapeListsQueue.empty()) ||
745 ((!_shapeListsQueue.empty() && !other._shapeListsQueue.empty()) && (_shapeListsQueue.front() == other._shapeListsQueue.front()) && (_iteratorsQueue.front() == other._iteratorsQueue.front()));
748 bool ShapeList::BreadthFirstIterator::operator!=(
const BreadthFirstIterator & other)
750 return !(*
this == other);
753 ShapeList::BreadthFirstIterator & ShapeList::BreadthFirstIterator::operator++()
755 moveToNextActualShape();
759 ShapeList::BreadthFirstIterator ShapeList::BreadthFirstIterator::operator++(
int)
761 BreadthFirstIterator currentValue(*
this);
762 moveToNextActualShape();
766 #if defined(HAS_MSVC_MAX)
767 #define max(A, B) ((A) > (B) ? (A) : (B))
void accept(ShapeVisitor &visitor) override
Accepts a visitor object.
Definition: ShapeList.cpp:457
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
DepthFirstIterator depthFirstBegin()
depthFirstBegin
Definition: ShapeList.h:645
T & last(const std::size_t position=0)
Definition: ShapeList.h:501
T & topLevelFindLast(std::size_t position=0)
Definition: ShapeList.h:518
Definition: Exception.h:36
std::size_t deepSize() const
Recursively counts the number of shapes in the list.
Definition: ShapeList.cpp:515
TopLevelIterator begin()
begin
Definition: ShapeList.h:615
Shape()
Definition: Shape.h:329
BreadthFirstIterator breadthFirstEnd()
breadthFirstEnd
Definition: ShapeList.h:660
void flushSVG(std::ostream &stream, const TransformSVG &transform) const override
Definition: ShapeList.cpp:401
Struct representing a rectangle on the plane.
Definition: Rect.h:39
ShapeList & push_back(Shape *shape)
Definition: ShapeList.cpp:441
void repeat(const Shape &shape, unsigned int times, double dx, double dy, double scaleX=1.0, double scaleY=1.0, double angle=0.0)
Definition: ShapeList.cpp:231
ShapeList & rotate(double angle, const Point ¢er) override
Definition: ShapeList.cpp:301
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const override
Definition: ShapeList.cpp:394
DepthFirstIterator depthFirstEnd()
depthFirstEnd
Definition: ShapeList.h:650
ShapeList & dup(std::size_t copies=1)
Definition: ShapeList.cpp:181
The Exception type. @copyright This source code is part of the Board project, a C++ library whose pur...
The TopLevelConstIterator struct.
Definition: ShapeList.h:348
Struct representing a 2D point.
Definition: Point.h:42
The BreadthFirstIterator struct allows to traverse the shape tree using a breadth-first strategy.
Definition: ShapeList.h:388
std::vector< Shape * > _shapes
Definition: ShapeList.h:484
Group & addTiling(const Shape &shape, Point topLeftCorner, std::size_t columns, std::size_t rows, double spacing=0.0, LineWidthFlag lineWidthFlag=UseLineWidth)
Definition: ShapeList.cpp:210
Abstract structure for a 2D shape.
Definition: Shape.h:63
ShapeList & translate(double dx, double dy) override
Definition: ShapeList.cpp:328
Shape & top()
Definition: ShapeList.cpp:452
A ConstShapeVisitor may visit const shapes of a composite shape tree in back-to-front order.
Definition: ShapeVisitor.h:78
ShapeList translated(double dx, double dy)
Definition: ShapeList.cpp:339
BreadthFirstIterator breadthFirstBegin()
breadthFirstBegin
Definition: ShapeList.h:655
ShapeList & clear()
Definition: ShapeList.cpp:86
A group of shapes. A group is basically a ShapeList except that when rendered in either an SVG of a F...
Definition: Group.h:40
std::size_t size() const
The number of shapes in the list (at top level).
Definition: ShapeList.h:665
A group of shapes.
Definition: ShapeList.h:46
TopLevelConstIterator cbegin() const
cbegin
Definition: ShapeList.h:630
ShapeList & scale(double sx, double sy) override
Definition: ShapeList.cpp:344
virtual Point center(LineWidthFlag lineWidthFlag=IgnoreLineWidth) const
Definition: Shape.cpp:59
The TopLevelIterator struct.
Definition: ShapeList.h:329
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const override
Definition: ShapeList.cpp:410
TopLevelIterator end()
end
Definition: ShapeList.h:620
TopLevelConstIterator cend() const
cend
Definition: ShapeList.h:640
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const override
Definition: ShapeList.cpp:385
ShapeList rotated(double angle, const Point ¢er)
Definition: ShapeList.cpp:312
void deleteShapes()
Definition: ShapeList.cpp:93
The DepthFirstIterator struct allows to traverse the shape tree using a depth-first strategy.
Definition: ShapeList.h:366
void scaleAll(double s) override
Definition: ShapeList.cpp:376
ShapeList * clone() const override
Definition: ShapeList.cpp:436
ShapeList scaled(double sx, double sy) const
Definition: ShapeList.cpp:366
ShapeList & operator<<(const Shape &shape)
Definition: ShapeList.cpp:146
const std::string & name() const override
Definition: ShapeList.cpp:49
ShapeList & operator+=(const Shape &shape)
Definition: ShapeList.cpp:193
ShapeList & append(const Shape &shape, Direction direction=ShapeList::Right, Alignment alignment=ShapeList::AlignCenter, double margin=0.0, LineWidthFlag lineWidthFlag=UseLineWidth)
Definition: ShapeList.cpp:246
A ShapeVisitor visits all shapes in a composite shape tree in back-to-front order.
Definition: ShapeVisitor.h:53
Rect boundingBox(LineWidthFlag) const override
Definition: ShapeList.cpp:419