27#ifndef BOARD_SHAPELIST_H
28#define BOARD_SHAPELIST_H
81 ShapeList(
const Shape & shape,
unsigned int times,
double dx,
double dy,
double scaleX,
double scaleY,
double angle);
87 template <
typename S>
ShapeList(
const std::vector<S> & shapes);
96 const std::string &
name()
const override;
184 void flushFIG(std::ostream & stream,
const TransformFIG & transform, std::map<Color, int> & colormap)
const override;
216 template <
typename S>
250 void addRepeated(
const Shape & shape,
unsigned int times,
double dx,
double dy,
double scaleX = 1.0,
double scaleY = 1.0,
double angle = 0.0);
264 template <
typename T> T &
last(
const std::size_t position = 0);
272 Shape &
last(
const std::size_t position = 0);
344 std::vector<Shape *>::iterator _it;
363 std::vector<Shape *>::const_iterator _it;
382 void moveToFirstActuelShape();
383 void moveToNextActualShape();
384 std::stack<ShapeList *> _shapeListsStack;
385 std::stack<TopLevelIterator> _iteratorsStack;
404 void moveToFirstActuelShape();
405 void moveToNextActualShape();
406 std::queue<ShapeList *> _shapeListsQueue;
407 std::queue<TopLevelIterator> _iteratorsQueue;
480 inline std::size_t
size()
const;
483 static const std::string _name;
500#define HAS_MSVC_MAX true
507 if (position <
_shapes.size()) {
508 std::vector<Shape *>::reverse_iterator it =
_shapes.rbegin() +
static_cast<std::vector<Shape *>::difference_type
>(position);
509 Shape * pshape = *it;
510 T * result =
dynamic_cast<T *
>(pshape);
512 std::cerr <<
"Error: ShapeList::last<> called with invalid result type\n";
515 return dynamic_cast<T &
>(*result);
517 Tools::error <<
"Trying to access an element that does not exist (" << position <<
"/" <<
_shapes.size() <<
").\n";
524 std::vector<Shape *>::reverse_iterator it =
_shapes.rbegin();
526 T * shape =
dynamic_cast<T *
>(*it);
536 throw Exception(
"topLevelFindLast<T>(): no such shape type found (" + std::string(
typeid(T).
name()) +
")");
571 return _it == other._it;
576 return _it != other._it;
611 return _it == other._it;
616 return _it != other._it;
678 _shapeListsStack.push(list);
679 _iteratorsStack.push(list->
begin());
680 moveToFirstActuelShape();
685 return *(_iteratorsStack.top());
695 return _iteratorsStack.top().pointer();
700 return (_shapeListsStack.empty() && other._shapeListsStack.empty()) ||
701 ((!_shapeListsStack.empty() && !other._shapeListsStack.empty()) && (_shapeListsStack.top() == other._shapeListsStack.top()) && (_iteratorsStack.top() == other._iteratorsStack.top()));
706 return !(*
this == other);
711 moveToNextActualShape();
718 moveToNextActualShape();
726 _shapeListsQueue.push(list);
727 _iteratorsQueue.push(list->
begin());
728 moveToFirstActuelShape();
733 return *(_iteratorsQueue.front());
743 return _iteratorsQueue.front().pointer();
748 return (_shapeListsQueue.empty() && other._shapeListsQueue.empty()) ||
749 ((!_shapeListsQueue.empty() && !other._shapeListsQueue.empty()) && (_shapeListsQueue.front() == other._shapeListsQueue.front()) && (_iteratorsQueue.front() == other._iteratorsQueue.front()));
754 return !(*
this == other);
759 moveToNextActualShape();
766 moveToNextActualShape();
780 for (
const S & shape : shapes) {
786#if defined(HAS_MSVC_MAX)
787#define max(A, B) ((A) > (B) ? (A) : (B))
The Exception type. @copyright This source code is part of the Board project, a C++ library whose pur...
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
Definition Exception.h:36
Direction
The Direction enum.
Definition Globals.h:36
Alignment
The Alignment enum.
Definition Globals.h:47
@ Center
Definition Globals.h:50
LineWidthFlag
Definition Style.h:57
@ UseLineWidth
Definition Style.h:59
A ConstShapeVisitor may visit const shapes of a composite shape tree in back-to-front order.
Definition ShapeVisitor.h:79
Struct representing a 2D point.
Definition Point.h:42
Struct representing a rectangle on the plane.
Definition Rect.h:40
The BreadthFirstIterator struct allows to traverse the shape tree using a breadth-first strategy.
Definition ShapeList.h:392
BreadthFirstIterator & operator++()
Definition ShapeList.h:757
Shape * pointer()
Definition ShapeList.h:741
Shape & operator*()
Definition ShapeList.h:731
Shape * operator->()
Definition ShapeList.h:736
bool operator==(const BreadthFirstIterator &other)
Definition ShapeList.h:746
bool operator!=(const BreadthFirstIterator &other)
Definition ShapeList.h:752
BreadthFirstIterator()
Definition ShapeList.h:722
The DepthFirstIterator struct allows to traverse the shape tree using a depth-first strategy.
Definition ShapeList.h:370
Shape & operator*()
Definition ShapeList.h:683
Shape * operator->()
Definition ShapeList.h:688
bool operator!=(const DepthFirstIterator &other)
Definition ShapeList.h:704
DepthFirstIterator & operator++()
Definition ShapeList.h:709
bool operator==(const DepthFirstIterator &other)
Definition ShapeList.h:698
Shape * pointer()
Definition ShapeList.h:693
DepthFirstIterator()
Definition ShapeList.h:674
The TopLevelConstIterator struct.
Definition ShapeList.h:352
TopLevelConstIterator(std::vector< Shape * >::const_iterator it)
Definition ShapeList.h:579
TopLevelConstIterator & operator++()
Definition ShapeList.h:596
const Shape & operator*()
Definition ShapeList.h:581
const Shape * pointer()
Definition ShapeList.h:591
bool operator!=(const TopLevelConstIterator &other)
Definition ShapeList.h:614
const Shape * operator->()
Definition ShapeList.h:586
bool operator==(const TopLevelConstIterator &other)
Definition ShapeList.h:609
The TopLevelIterator struct.
Definition ShapeList.h:333
TopLevelIterator(std::vector< Shape * >::iterator it)
Definition ShapeList.h:539
TopLevelIterator & operator++()
Definition ShapeList.h:556
bool operator!=(const TopLevelIterator &other)
Definition ShapeList.h:574
Shape & operator*()
Definition ShapeList.h:541
Shape * operator->()
Definition ShapeList.h:546
bool operator==(const TopLevelIterator &other)
Definition ShapeList.h:569
Shape * pointer()
Definition ShapeList.h:551
A group of shapes.
Definition ShapeList.h:47
TopLevelConstIterator cbegin() const
cbegin
Definition ShapeList.h:634
void scaleAll(double s) override
Definition ShapeList.cpp:362
void addShape(const Shape &shape, double scaleFactor)
Definition ShapeList.cpp:164
ShapeList & push_back(Shape *shape)
Definition ShapeList.cpp:427
~ShapeList() override
Definition ShapeList.cpp:85
BreadthFirstIterator breadthFirstBegin()
breadthFirstBegin
Definition ShapeList.h:659
ShapeList & duplicateLast(std::size_t copies=1)
Definition ShapeList.cpp:185
BreadthFirstIterator breadthFirstEnd()
breadthFirstEnd
Definition ShapeList.h:664
Rect boundingBox(LineWidthFlag) const override
Definition ShapeList.cpp:405
void addRepeated(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:214
Shape & top()
Definition ShapeList.cpp:438
TopLevelIterator begin()
begin
Definition ShapeList.h:619
const std::string & name() const override
Definition ShapeList.cpp:49
ShapeList scaled(double sx, double sy) const
Definition ShapeList.cpp:352
TopLevelConstIterator cend() const
cend
Definition ShapeList.h:644
TopLevelIterator end()
end
Definition ShapeList.h:624
DepthFirstIterator depthFirstBegin()
depthFirstBegin
Definition ShapeList.h:649
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const override
Definition ShapeList.cpp:396
ShapeList & rotate(double angle, const Point ¢er) override
Definition ShapeList.cpp:287
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const override
Definition ShapeList.cpp:380
ShapeList & append(const Shape &shape, Direction direction=Direction::Right, Alignment alignment=Alignment::Center, double margin=0.0, LineWidthFlag lineWidthFlag=UseLineWidth)
Definition ShapeList.cpp:232
std::size_t size() const
The number of shapes in the list (at top level).
Definition ShapeList.h:669
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const override
Definition ShapeList.cpp:371
ShapeList()
Definition ShapeList.h:503
std::size_t deepSize() const
Recursively counts the number of shapes in the list.
Definition ShapeList.cpp:501
ShapeList translated(double dx, double dy)
Definition ShapeList.cpp:325
DepthFirstIterator depthFirstEnd()
depthFirstEnd
Definition ShapeList.h:654
ShapeList rotated(double angle, const Point ¢er)
Definition ShapeList.cpp:298
std::vector< Shape * >::size_type size_type
Definition ShapeList.h:49
ShapeList & scale(double sx, double sy) override
Definition ShapeList.cpp:330
ShapeList & operator<<(const Shape &shape)
Definition ShapeList.cpp:150
ShapeList & operator+=(const Shape &shape)
Definition ShapeList.cpp:197
T & topLevelFindLast(std::size_t position=0)
Definition ShapeList.h:522
void flushSVG(std::ostream &stream, const TransformSVG &transform) const override
Definition ShapeList.cpp:387
ShapeList & operator=(const ShapeList &other)
Definition ShapeList.cpp:120
ShapeList * clone() const override
Definition ShapeList.cpp:422
ShapeList & translate(double dx, double dy) override
Definition ShapeList.cpp:314
void deleteShapes()
Definition ShapeList.cpp:97
void accept(ShapeVisitor &visitor) override
Accepts a visitor object.
Definition ShapeList.cpp:443
std::vector< Shape * > _shapes
Definition ShapeList.h:488
ShapeList & clear()
Definition ShapeList.cpp:90
T & last(const std::size_t position=0)
Definition ShapeList.h:505
A ShapeVisitor visits all shapes in a composite shape tree in back-to-front order.
Definition ShapeVisitor.h:54
Abstract structure for a 2D shape.
Definition Shape.h:64
virtual Point center(LineWidthFlag lineWidthFlag=IgnoreLineWidth) const
Definition Shape.cpp:59