QCAD
Open Source 2D CAD
RPolyline.h
Go to the documentation of this file.
1 
20 #ifndef RPOLYLINE_H
21 #define RPOLYLINE_H
22 
23 #include "../core_global.h"
24 
25 #include <QSharedPointer>
26 
27 #include "RDirected.h"
28 #include "RExplodable.h"
29 #include "RPainterPath.h"
30 #include "RShape.h"
31 #include "RVector.h"
32 
33 class RBox;
34 
35 #ifndef RDEFAULT_MIN1
36 #define RDEFAULT_MIN1 -1
37 #endif
38 
49 class QCADCORE_EXPORT RPolyline: public RShape, public RExplodable, public RDirected {
50 public:
51  RPolyline();
52  RPolyline(const QList<RVector>& vertices, bool closed);
53  RPolyline(const QList<QSharedPointer<RShape> >& segments);
54  virtual ~RPolyline();
55 
56  virtual RPolyline* clone() const {
57  return new RPolyline(*this);
58  }
59 
60  virtual void to2D();
61 
62  void clear();
63  void normalize();
64 
65  void prependShape(const RShape& shape);
66  void appendShape(const RShape& shape, bool prepend = false);
67 
68  void appendVertex(const RVector& vertex, double bulge = 0.0);
69  void prependVertex(const RVector& vertex, double bulge = 0.0);
70  void insertVertex(int index, const RVector& vertex);
71  void removeLastVertex();
72  void removeVertex(int index);
73 
74  void setVertices(const QList<RVector>& vertices);
75  QList<RVector> getVertices() const;
76  void setVertexAt(int i, const RVector& v);
77  RVector getVertexAt(int i) const;
78  int getVertexIndex(const RVector& v, double tolerance=RS::PointTolerance) const;
79  RVector getLastVertex() const;
80  int countVertices() const;
81 
82  void setBulges(const QList<double>& b);
83  QList<double> getBulges() const;
84  double getBulgeAt(int i) const;
85  void setBulgeAt(int i, double b);
86  bool hasArcSegments() const;
87 
88  void setClosed(bool on);
89  bool isClosed() const;
90  bool isGeometricallyClosed(double tolerance=RS::PointTolerance) const;
91  RS::Orientation getOrientation() const;
92 
93  bool contains(const RVector& point, bool borderIsInside=false, double tolerance=RS::PointTolerance) const;
94  // TODO:
95  //bool contains(const RShape& shape) const;
96 
97  virtual RVector getStartPoint() const;
98  virtual RVector getEndPoint() const;
99 
100  virtual double getDirection1() const;
101  virtual double getDirection2() const;
102 
103  virtual RBox getBoundingBox() const;
104 
105  virtual double getLength() const;
106 
107  virtual QList<RVector> getEndPoints() const;
108  virtual QList<RVector> getMiddlePoints() const;
109  virtual QList<RVector> getCenterPoints() const;
110  virtual QList<RVector> getPointsWithDistanceToEnd(
111  double distance, RS::From from = RS::FromAny) const;
112 
113  virtual double getAngleAt(double distance, RS::From from = RS::FromStart) const;
114 
115  virtual RVector getVectorTo(const RVector& point,
116  bool limited = true, double strictRange = RMAXDOUBLE) const;
117 
118  virtual bool move(const RVector& offset);
119  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
120  virtual bool scale(double scaleFactor, const RVector& center = RDEFAULT_RVECTOR);
121  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
122  virtual bool mirror(const RLine& axis);
123  virtual bool reverse();
124  virtual bool stretch(const RPolyline& area, const RVector& offset);
125 
126  virtual QSharedPointer<RShape> getTransformed(const QTransform& transform) const;
127 
128  virtual RS::Ending getTrimEnd(const RVector& coord, const RVector& trimPoint);
129  virtual void trimStartPoint(const RVector& p);
130  virtual void trimEndPoint(const RVector& p);
131 
132  virtual QList<QSharedPointer<RShape> > getExploded(int segments = RDEFAULT_MIN1) const;
133  virtual bool isInterpolated() const {
134  return false;
135  }
136  int countSegments() const;
137  QSharedPointer<RShape> getSegmentAt(int i) const;
138 
139  static bool isStraight(double bulge);
140 
141  RPainterPath toPainterPath() const;
142 
143  bool simplify(double angleTolerance = RS::AngleTolerance);
144 
145 protected:
146  bool isLineSegment(int i) const;
147 
148  void print(QDebug dbg) const;
149 
150 protected:
155  QList<RVector> vertices;
156 
157  QList<double> bulges;
158 
163  bool closed;
164 
165 private:
166  // TODO caching:
167  //QList<QSharedPointer<RShape> > subShapes;
168 };
169 
173 Q_DECLARE_METATYPE(QSharedPointer<RPolyline>)
174 Q_DECLARE_METATYPE(QSharedPointer<RPolyline>*)
175 
176 #endif
static const double AngleTolerance
Definition: RS.h:525
Represents a box e.g.
Definition: RBox.h:43
Ending
Entity ending.
Definition: RS.h:136
virtual RVector getVectorTo(const RVector &point, bool limited=true, double strictRange=RMAXDOUBLE) const =0
virtual void to2D()=0
Flattens this shape to the X/Y plane.
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
virtual QList< RVector > getEndPoints() const =0
virtual double getDirection1() const =0
virtual RVector getEndPoint() const =0
virtual bool rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)=0
#define QCADCORE_EXPORT
Definition: core_global.h:10
virtual void trimStartPoint(const RVector &p)=0
virtual bool isInterpolated() const
Reimplement and return true if this shape relies on interpolation for geometrical operations such as ...
Definition: RPolyline.h:133
virtual RS::Ending getTrimEnd(const RVector &coord, const RVector &trimPoint)=0
virtual double getLength() const =0
virtual RBox getBoundingBox() const =0
Start or end.
Definition: RS.h:187
QList< RVector > vertices
Getter function for this property: getVertices.
Definition: RPolyline.h:155
virtual bool move(const RVector &offset)=0
bool closed
Getter function for this property: isClosed.
Definition: RPolyline.h:163
virtual double getAngleAt(double distance, RS::From from=RS::FromStart) const
Definition: RShape.h:135
static const double PointTolerance
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RS.h:524
virtual bool stretch(const RBox &area, const RVector &offset)
Definition: RShape.cpp:1608
virtual RPolyline * clone() const
Definition: RPolyline.h:56
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, RS::From from=RS::FromAny) const =0
Q_DECLARE_METATYPE(RMath *)
virtual QList< QSharedPointer< RShape > > getExploded(int segments=RDEFAULT_MIN1) const =0
virtual void trimEndPoint(const RVector &p)=0
virtual QList< RVector > getMiddlePoints() const =0
Extended painter path with a z-level and a pen.
Definition: RPainterPath.h:45
#define RMAXDOUBLE
Definition: RMath.h:50
Definition: RS.h:185
virtual bool mirror(const RLine &axis)=0
Low-level mathematical representation of a line.
Definition: RLine.h:42
#define RDEFAULT_MIN1
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RExplodable.h:30
Interface for explodable shape classes.
Definition: RExplodable.h:40
virtual RVector getStartPoint() const =0
virtual bool reverse()=0
virtual QSharedPointer< RShape > getTransformed(const QTransform &transform) const =0
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RDirected.h:36
From
End used to specify from which end of a shape to measure a distance.
Definition: RS.h:184
virtual double getDirection2() const =0
Orientation
Definition: RS.h:468
virtual bool scale(double scaleFactor, const RVector &center=RVector())
Definition: RShape.cpp:1619
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:49
Interface for geometrical shape classes.
Definition: RShape.h:52
virtual QList< RVector > getCenterPoints() const =0
virtual void print(QDebug dbg) const
Definition: RShape.cpp:1623
QList< double > bulges
Definition: RPolyline.h:157
#define RDEFAULT_RVECTOR
Definition: RVector.h:37