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 "RExplodable.h"
28 #include "RPainterPath.h"
29 #include "RPolylineProxy.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 
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 RShape::Type getShapeType() const {
57  return Polyline;
58  }
59 
60  virtual RPolyline* clone() const {
61  return new RPolyline(*this);
62  }
63 
64  virtual bool isDirected() const {
65  return true;
66  }
67 
68  virtual void to2D();
69 
70  virtual QList<RVector> getVectorProperties() const;
71  virtual QList<double> getDoubleProperties() const;
72  virtual QList<bool> getBoolProperties() const;
73 
74  void clear();
75  void normalize(double tolerance = RS::PointTolerance);
76 
77  bool prependShape(const RShape& shape);
78  bool appendShape(const RShape& shape, bool prepend = false);
79  bool appendShapeAuto(const RShape& shape);
80 
81  void appendVertex(const RVector& vertex, double bulge = 0.0, double w1 = 0.0, double w2 = 0.0);
82  void prependVertex(const RVector& vertex, double bulge = 0.0, double w1 = 0.0, double w2 = 0.0);
83  void insertVertex(int index, const RVector& vertex);
84  void insertVertexAt(const RVector& point);
85  void removeFirstVertex();
86  void removeLastVertex();
87  void removeVertex(int index);
88  void removeVerticesAfter(int index);
89  void removeVerticesBefore(int index);
90 
91  bool isEmpty() {
92  return countVertices()==0;
93  }
94 
95  void setVertices(const QList<RVector>& vertices);
96  QList<RVector> getVertices() const;
97  void setVertexAt(int i, const RVector& v);
98  RVector getVertexAt(int i) const;
99  int getVertexIndex(const RVector& v, double tolerance=RS::PointTolerance) const;
100  RVector getLastVertex() const;
101  int countVertices() const;
102 
103  void setBulges(const QList<double>& b);
104  QList<double> getBulges() const;
105  double getBulgeAt(int i) const;
106  void setBulgeAt(int i, double b);
107  bool hasArcSegments() const;
108 
109  QList<double> getVertexAngles() const;
110  double getVertexAngle(int i, RS::Orientation orientation = RS::UnknownOrientation) const;
111 
112  void setGlobalWidth(double w);
113  void setStartWidthAt(int i, double w);
114  double getStartWidthAt(int i) const;
115  void setEndWidthAt(int i, double w);
116  double getEndWidthAt(int i) const;
117  bool hasWidths() const;
118  void setStartWidths(const QList<double>& sw);
119  QList<double> getStartWidths() const;
120  void setEndWidths(const QList<double>& ew);
121  QList<double> getEndWidths() const;
122 
123  void setClosed(bool on);
124  bool isClosed() const;
125  bool isGeometricallyClosed(double tolerance=RS::PointTolerance) const;
126  bool autoClose() {
127  return toLogicallyClosed();
128  }
129  bool toLogicallyClosed(double tolerance=RS::PointTolerance);
130  bool toLogicallyOpen();
131 
132  QList<RVector> getSelfIntersectionPoints() const;
133 
134  RS::Orientation getOrientation(bool implicitelyClosed = false) const;
135 
136  bool contains(const RVector& point, bool borderIsInside=false, double tolerance=RS::PointTolerance) const;
137  bool containsShape(const RShape& shape) const;
138 
139  RVector getPointInside() const;
140 
141  virtual RVector getStartPoint() const;
142  virtual RVector getEndPoint() const;
143  virtual RVector getMiddlePoint() const;
144 
145  void moveStartPoint(const RVector& pos);
146  void moveEndPoint(const RVector& pos);
147 
148  virtual double getDirection1() const;
149  virtual double getDirection2() const;
150 
151  virtual RS::Side getSideOfPoint(const RVector& point) const;
152 
153  virtual RBox getBoundingBox() const;
154 
155  double getArea() const;
156 
157  virtual double getLength() const;
158 
159  virtual double getDistanceFromStart(const RVector& p) const {
160  QList<double> res = getDistancesFromStart(p);
161  if (res.isEmpty()) {
162  return RMAXDOUBLE;
163  }
164  return res.first();
165  }
166  virtual QList<double> getDistancesFromStart(const RVector& p) const;
167  double getLengthTo(const RVector& p, bool limited = true) const;
168  double getSegmentsLength(int fromIndex, int toIndex) const;
169 
170  virtual QList<RVector> getEndPoints() const;
171  virtual QList<RVector> getMiddlePoints() const;
172  virtual QList<RVector> getCenterPoints() const;
173  virtual QList<RVector> getPointsWithDistanceToEnd(
174  double distance, int from = RS::FromAny) const;
175 
176  virtual double getAngleAt(double distance, RS::From from = RS::FromStart) const;
177 
178  virtual RVector getVectorTo(const RVector& point,
179  bool limited = true, double strictRange = RMAXDOUBLE) const;
180  virtual double getDistanceTo(const RVector& point, bool limited = true, double strictRange = RMAXDOUBLE) const;
181 
182  int getClosestSegment(const RVector& point) const;
183  int getClosestVertex(const RVector& point) const;
184 
185  virtual bool move(const RVector& offset);
186  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
187  virtual bool scale(double scaleFactor, const RVector& center = RDEFAULT_RVECTOR);
188  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
189  virtual bool mirror(const RLine& axis);
190  virtual bool reverse();
191  virtual bool stretch(const RPolyline& area, const RVector& offset);
192 
193  virtual QSharedPointer<RShape> getTransformed(const QTransform& transform) const;
194 
195  virtual RS::Ending getTrimEnd(const RVector& trimPoint, const RVector& clickPoint);
196  virtual bool trimStartPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid, bool extend = false);
197  virtual bool trimEndPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid, bool extend = false);
198  virtual bool trimStartPoint(double trimDist);
199  virtual bool trimEndPoint(double trimDist);
200 
201  virtual QList<QSharedPointer<RShape> > getExploded(int segments = RDEFAULT_MIN1) const;
202  QList<RPolyline> getOutline() const;
203  virtual bool isInterpolated() const {
204  return false;
205  }
206  int countSegments() const;
207  QSharedPointer<RShape> getSegmentAt(int i) const;
208  bool isArcSegmentAt(int i) const;
209  QSharedPointer<RShape> getLastSegment() const;
210  QSharedPointer<RShape> getFirstSegment() const;
211 
212  static bool isStraight(double bulge);
213 
214  RPainterPath toPainterPath() const;
215 
216  bool simplify(double angleTolerance = RS::AngleTolerance);
217  QList<RVector> verifyTangency(double toleranceMin = RS::AngleTolerance, double toleranceMax = M_PI_4);
218 
219  void stripWidths();
220 
221  int getSegmentAtDist(double dist);
222  bool relocateStartPoint(const RVector& p);
223  bool relocateStartPoint(double dist);
224  bool convertToClosed();
225  bool convertToOpen();
226 
227  RPolyline modifyPolylineCorner(
228  const RShape& trimmedShape1, RS::Ending ending1, int segmentIndex1,
229  const RShape& trimmedShape2, RS::Ending ending2, int segmentIndex2,
230  const RShape* cornerShape = NULL) const;
231 
232  QList<RVector> getConvexVertices(bool convex = true) const;
233  QList<RVector> getConcaveVertices() const;
234 
235  static bool hasProxy() {
236  return polylineProxy!=NULL;
237  }
238 
243  if (polylineProxy!=NULL) {
244  delete polylineProxy;
245  }
246  polylineProxy = p;
247  }
248 
253  return polylineProxy;
254  }
255 
256 protected:
257  bool isLineSegment(int i) const;
258 
259  void print(QDebug dbg) const;
260 
261 protected:
266  QList<RVector> vertices;
267 
268  QList<double> bulges;
269 
270  QList<double> endWidths;
271  QList<double> startWidths;
272 
277  bool closed;
278 
279 private:
280  // TODO caching:
281  //QList<QSharedPointer<RShape> > subShapes;
283 };
284 
288 Q_DECLARE_METATYPE(QSharedPointer<RPolyline>)
289 Q_DECLARE_METATYPE(QSharedPointer<RPolyline>*)
290 
291 #endif
static const double AngleTolerance
Definition: RS.h:575
Represents a box e.g.
Definition: RBox.h:43
Ending
Entity ending.
Definition: RS.h:152
Definition: RS.h:517
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.
#define M_PI_4
Definition: RMath.h:43
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
virtual QList< RVector > getEndPoints() const =0
virtual RVector getEndPoint() const
Definition: RShape.h:249
virtual QList< RVector > getVectorProperties() const
Definition: RShape.h:141
virtual QList< double > getDoubleProperties() const
Definition: RShape.h:143
virtual QList< bool > getBoolProperties() const
Definition: RShape.h:144
static RPolylineProxy * polylineProxy
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RPolyline.h:282
QList< double > endWidths
Definition: RPolyline.h:270
void mirror(void e, void axis)
Mirrors the given entity or shape at the given axis.
Definition: simple_modify.js:109
virtual bool reverse()
Definition: RShape.h:256
#define QCADCORE_EXPORT
Definition: core_global.h:10
void move(void e, void offset)
Moves the given entity or shape by the given offset.
Definition: simple_modify.js:92
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, int from=RS::FromAny) const =0
static bool hasProxy()
Definition: RPolyline.h:235
virtual bool isDirected() const
Definition: RPolyline.h:64
virtual bool isInterpolated() const
Reimplement and return true if this shape relies on interpolation for geometrical operations such as ...
Definition: RPolyline.h:203
bool autoClose()
Definition: RPolyline.h:126
virtual RShape::Type getShapeType() const
Definition: RPolyline.h:56
virtual double getLength() const =0
virtual RBox getBoundingBox() const =0
Start or end.
Definition: RS.h:203
QList< double > startWidths
Definition: RPolyline.h:271
virtual double getDirection1() const
Definition: RShape.h:234
QList< RVector > vertices
Getter function for this property: getVertices.
Definition: RPolyline.h:266
Side
Side used for side of a point relativ to an entity (right hand or left hand side) ...
Definition: RS.h:142
bool closed
Getter function for this property: isClosed.
Definition: RPolyline.h:277
virtual double getDirection2() const
Definition: RShape.h:237
virtual double getAngleAt(double distance, RS::From from=RS::FromStart) const
Definition: RShape.h:208
static const double PointTolerance
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RS.h:574
virtual bool stretch(const RBox &area, const RVector &offset)
Definition: RShape.cpp:1704
virtual RPolyline * clone() const
Definition: RPolyline.h:60
Q_DECLARE_METATYPE(RMath *)
virtual RVector getMiddlePoint() const
Definition: RShape.h:252
virtual QList< QSharedPointer< RShape > > getExploded(int segments=RDEFAULT_MIN1) const =0
void rotate(void e, void angle, void center)
Rotates the given entity or shape by the given angle around the given center.
Definition: simple_modify.js:78
bool isEmpty()
Definition: RPolyline.h:91
virtual QList< RVector > getMiddlePoints() const =0
Extended painter path with a z-level and a pen.
Definition: RPainterPath.h:46
virtual QList< double > getDistancesFromStart(const RVector &p) const
Definition: RShape.h:322
Type
Definition: RShape.h:54
void trimEndPoint(void shape, void trimPoint, void clickPoint)
Definition: library.js:513
#define RMAXDOUBLE
Definition: RMath.h:63
void scale(void e, void factor, void focusPoint)
Scales the given entity or shape by the given factor with the given focus point.
Definition: simple_modify.js:64
virtual double getDistanceTo(const RVector &point, bool limited=true, double strictRange=RMAXDOUBLE) const
Definition: RShape.cpp:47
Definition: RS.h:201
Definition: RShape.h:61
Low-level mathematical representation of a line.
Definition: RLine.h:41
void trimStartPoint(void shape, void trimPoint, void clickPoint)
Definition: library.js:463
virtual RS::Side getSideOfPoint(const RVector &point) const
Definition: RShape.h:241
#define RDEFAULT_MIN1
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RExplodable.h:30
virtual RS::Ending getTrimEnd(const RVector &trimPoint, const RVector &clickPoint)
Definition: RShape.h:302
Interface for explodable shape classes.
Definition: RExplodable.h:40
virtual QSharedPointer< RShape > getTransformed(const QTransform &transform) const =0
From
End used to specify from which end of a shape to measure a distance.
Definition: RS.h:200
Orientation
Definition: RS.h:516
Proxy for advanced polyline functionality.
Definition: RPolylineProxy.h:41
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:1719
virtual double getDistanceFromStart(const RVector &p) const
Definition: RPolyline.h:159
static const RVector invalid
invalid vector
Definition: RVector.h:317
virtual RVector getStartPoint() const
Definition: RShape.h:246
QList< double > bulges
Definition: RPolyline.h:268
#define RDEFAULT_RVECTOR
Definition: RVector.h:37
static void setPolylineProxy(RPolylineProxy *p)
Definition: RPolyline.h:242
virtual QList< RVector > getSelfIntersectionPoints() const
Definition: RShape.h:226
static RPolylineProxy * getPolylineProxy()
Definition: RPolyline.h:252