Board  0.9.5
Arrow.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
26 #ifndef BOARD_ARROW_H
27 #define BOARD_ARROW_H
28 
29 #include "board/Line.h"
30 
31 namespace LibBoard
32 {
33 
38 struct Arrow : public Line {
39 
41  {
45  };
46 
62  inline Arrow(double x1, double y1, double x2, double y2, ExtremityType type = Plain, Color penColor = Style::defaultPenColor(), Color fillColor = Style::defaultFillColor(),
63  double lineWidth = Style::defaultLineWidth(), //
64  const LineStyle lineStyle = Style::defaultLineStyle(), const LineCap cap = Style::defaultLineCap(), const LineJoin join = Style::defaultLineJoin());
65 
76  inline Arrow(double x1, double y1, double x2, double y2, ExtremityType type, const Style & style);
77 
91  inline Arrow(Point p1, Point p2, ExtremityType type = Plain, //
92  Color penColor = Style::defaultPenColor(),
93  Color fillColor = Style::defaultFillColor(), //
94  double lineWidth = Style::defaultLineWidth(), //
95  const LineStyle lineStyle = Style::defaultLineStyle(), const LineCap cap = Style::defaultLineCap(), const LineJoin join = Style::defaultLineJoin());
96 
105  inline Arrow(Point p1, Point p2, ExtremityType type, const Style & style);
106 
112  const std::string & name() const override;
113 
122  Arrow rotated(double angle, const Point & center) const;
123 
131  Arrow rotated(double angle) const;
132 
141  Arrow translated(double dx, double dy) const;
142 
151  Arrow scaled(double sx, double sy) const;
152 
160  Arrow scaled(double s) const;
161 
170  Arrow resized(double w, double h, LineWidthFlag lineWidthFlag) const;
171 
177  Rect boundingBox(LineWidthFlag) const override;
178 
179  void flushPostscript(std::ostream & stream, const TransformEPS & transform) const override;
180 
181  void flushFIG(std::ostream & stream, const TransformFIG & transform, std::map<Color, int> & colormap) const override;
182 
183  void flushSVG(std::ostream & stream, const TransformSVG & transform) const override;
184 
185  void flushTikZ(std::ostream & stream, const TransformTikZ & transform) const override;
186 
192  virtual void accept(ShapeVisitor & visitor) override;
193 
199  virtual void accept(const ShapeVisitor & visitor) override;
200 
206  virtual void accept(ConstShapeVisitor & visitor) const override;
207 
213  virtual void accept(const ConstShapeVisitor & visitor) const override;
214 
220  virtual Shape * accept(CompositeShapeTransform & transform) const override;
221 
227  virtual Shape * accept(const CompositeShapeTransform & transform) const override;
228 
229  Arrow * clone() const override;
230 
231  Path extremity() const;
232 
233  Arrow(const Arrow &) = default;
234  Arrow(Arrow &&) = default;
235  Arrow & operator=(Arrow &&) = default;
236  Arrow & operator=(const Arrow &) = default;
237  ~Arrow() override = default;
238 
239  inline ExtremityType type() const;
240 
241 private:
242  static const std::string _name;
243  ExtremityType _type;
244 };
245 
246 } // namespace LibBoard
247 
248 /*
249  * Inline methods
250  */
251 
252 namespace LibBoard
253 {
254 
255 Arrow::Arrow(double x1, double y1, double x2, double y2, ExtremityType type, Color penColor, Color fillColor, double lineWidth, const LineStyle style, const LineCap cap, const LineJoin join)
256  : Line(x1, y1, x2, y2, penColor, lineWidth, style, cap, join), _type(type)
257 {
258  // FIXME : Handle fill color of the tip properly
259  if (fillColor == Color::Null) {
260  _style.fillColor = penColor;
261  } else {
262  _style.fillColor = fillColor;
263  }
264 }
265 
266 Arrow::Arrow(double x1, double y1, double x2, double y2, ExtremityType type, const Style & style) //
267  : Line(x1, y1, x2, y2, style), _type(type)
268 {
269  if (style.fillColor == Color::Null) {
270  _style.fillColor = style.penColor;
271  } else {
272  _style.fillColor = style.fillColor;
273  }
274 }
275 
277  Color penColor, Color fillColor, double lineWidth, //
278  const LineStyle style, const LineCap cap, const LineJoin join) //
279  : Line(p1, p2, penColor, lineWidth, style, cap, join), _type(type)
280 {
281  if (fillColor == Color::Null) {
282  _style.fillColor = penColor;
283  } else {
284  _style.fillColor = fillColor;
285  }
286 }
287 
288 Arrow::Arrow(Point p1, Point p2, ExtremityType type, const Style & style) //
289  : Line(p1, p2, style), _type(type)
290 {
291  if (style.fillColor == Color::Null) {
292  _style.fillColor = style.penColor;
293  } else {
294  _style.fillColor = style.fillColor;
295  }
296 }
297 
298 Arrow::ExtremityType Arrow::type() const
299 {
300  return _type;
301 }
302 } // namespace LibBoard
303 
304 #endif /* BOARD_ARROW_H */
LibBoard::Style::defaultPenColor
static const Color & defaultPenColor()
defaultPenColor
Definition: Style.h:281
LibBoard::Arrow::translated
Arrow translated(double dx, double dy) const
Definition: Arrow.cpp:66
LibBoard::Style
Definition: Style.h:69
LibBoard::Arrow::Arrow
Arrow(double x1, double y1, double x2, double y2, ExtremityType type=Plain, Color penColor=Style::defaultPenColor(), Color fillColor=Style::defaultFillColor(), double lineWidth=Style::defaultLineWidth(), const LineStyle lineStyle=Style::defaultLineStyle(), const LineCap cap=Style::defaultLineCap(), const LineJoin join=Style::defaultLineJoin())
Definition: Arrow.h:255
LibBoard::Style::defaultLineWidth
static const double & defaultLineWidth()
defaultLineWidth
Definition: Style.h:276
LibBoard::Arrow::boundingBox
Rect boundingBox(LineWidthFlag) const override
Definition: Arrow.cpp:86
LibBoard::Arrow
A line between two points with an arrow at one extremity.
Definition: Arrow.h:38
LibBoard::Arrow::flushTikZ
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const override
Definition: Arrow.cpp:237
LibBoard::Arrow::name
const std::string & name() const override
Definition: Arrow.cpp:51
LibBoard::Rect
Struct representing a rectangle on the plane.
Definition: Rect.h:39
LibBoard::Arrow::ExtremityType
ExtremityType
Definition: Arrow.h:40
LibBoard::Arrow::Closed
@ Closed
Definition: Arrow.h:43
LibBoard::Style::defaultFillColor
static const Color & defaultFillColor()
defaultFillColor
Definition: Style.h:286
LibBoard::Arrow::flushFIG
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const override
Definition: Arrow.cpp:154
LibBoard::Arrow::Plain
@ Plain
Definition: Arrow.h:44
LibBoard::CompositeShapeTransform
A CompositeShapeTransform may be used to duplicate/transform a composite shape tree.
Definition: ShapeVisitor.h:103
LibBoard::Point
Struct representing a 2D point.
Definition: Point.h:42
Line.h
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
LibBoard::Arrow::flushSVG
void flushSVG(std::ostream &stream, const TransformSVG &transform) const override
Definition: Arrow.cpp:197
LibBoard::TransformEPS
Structure representing a scaling and translation suitable for an EPS output.
Definition: Transforms.h:71
LibBoard::Line
A line between two points.
Definition: Line.h:38
LibBoard::Arrow::rotated
Arrow rotated(double angle, const Point &center) const
Definition: Arrow.cpp:56
LibBoard::Style::defaultLineCap
static const LineCap & defaultLineCap()
defaultLineCap
Definition: Style.h:296
LibBoard::Shape
Abstract structure for a 2D shape.
Definition: Shape.h:63
LibBoard::ConstShapeVisitor
A ConstShapeVisitor may visit const shapes of a composite shape tree in back-to-front order.
Definition: ShapeVisitor.h:78
LibBoard::Arrow::clone
Arrow * clone() const override
Definition: Arrow.cpp:95
LibBoard::Path
A path, according to Postscript and SVG definition.
Definition: Path.h:45
LibBoard::Arrow::scaled
Arrow scaled(double sx, double sy) const
Definition: Arrow.cpp:71
LibBoard::Arrow::Stick
@ Stick
Definition: Arrow.h:42
LibBoard::TransformTikZ
Structure representing a scaling and translation suitable for an TikZ output.
Definition: Transforms.h:126
LibBoard::TransformFIG
Structure representing a scaling and translation suitable for an XFig output.
Definition: Transforms.h:87
LibBoard::Arrow::accept
virtual void accept(ShapeVisitor &visitor) override
Accepts a visitor object.
Definition: Arrow.cpp:245
LibBoard::Shape::center
virtual Point center(LineWidthFlag lineWidthFlag=IgnoreLineWidth) const
Definition: Shape.cpp:59
LibBoard::Style::defaultLineJoin
static const LineJoin & defaultLineJoin()
defaultLineJoin
Definition: Style.h:301
LibBoard::Arrow::flushPostscript
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const override
Definition: Arrow.cpp:112
LibBoard::Style::defaultLineStyle
static const LineStyle & defaultLineStyle()
defaultLineStyle
Definition: Style.h:291
LibBoard::Arrow::resized
Arrow resized(double w, double h, LineWidthFlag lineWidthFlag) const
Definition: Arrow.cpp:81
LibBoard::ShapeVisitor
A ShapeVisitor visits all shapes in a composite shape tree in back-to-front order.
Definition: ShapeVisitor.h:53
LibBoard::TransformSVG
Structure representing a scaling and translation suitable for an SVG output.
Definition: Transforms.h:109
LibBoard::Color
Structure representing an RGB triple.
Definition: Color.h:43