QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
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
33class RBox;
34class RLine;
35
36#ifndef RDEFAULT_MIN1
37#define RDEFAULT_MIN1 -1
38#endif
39
51public:
52 RPolyline();
53 RPolyline(const QList<RVector>& vertices, bool closed);
54 RPolyline(const QList<QSharedPointer<RShape> >& segments);
55 virtual ~RPolyline();
56
57 virtual RShape::Type getShapeType() const {
58 return Polyline;
59 }
60
61 virtual QSharedPointer<RShape> clone() const {
62 return QSharedPointer<RShape>(new RPolyline(*this));
63 }
64
65 QSharedPointer<RPolyline> cloneToPolyline() const {
66 return QSharedPointer<RPolyline>(new RPolyline(*this));
67 }
68
69 virtual bool isDirected() const {
70 return true;
71 }
72
73 virtual void setZ(double z);
74 bool isFlat() const;
75
76 virtual QList<RVector> getVectorProperties() const;
77 virtual QList<double> getDoubleProperties() const;
78 virtual QList<bool> getBoolProperties() const;
79
80 void clear();
81 void normalize(double tolerance = RS::PointTolerance);
82
83 bool prependShape(const RShape& shape);
84 bool appendShape(const RShape& shape, bool prepend = false);
85 bool appendShapeAuto(const RShape& shape);
86 bool appendShapeTrim(const RShape& shape);
87 bool closeTrim();
88
89 void appendVertex(const RVector& vertex, double bulge = 0.0, double w1 = 0.0, double w2 = 0.0);
90 void appendVertex(double x, double y, double bulge = 0.0, double w1 = 0.0, double w2 = 0.0);
91 void prependVertex(const RVector& vertex, double bulge = 0.0, double w1 = 0.0, double w2 = 0.0);
92 void insertVertex(int index, const RVector& vertex, double bulgeBefore = 0.0, double bulgeAfter = 0.0);
93 void insertVertexAt(const RVector& point);
94 RVector insertVertexAtDistance(double dist);
95 void removeFirstVertex();
96 void removeLastVertex();
97 void removeVertex(int index);
98 void removeVerticesAfter(int index);
99 void removeVerticesBefore(int index);
100
101 bool isEmpty() const {
102 return countVertices()==0;
103 }
104
105 void setVertices(const QList<RVector>& vertices);
106 QList<RVector> getVertices() const;
107 void setVertexAt(int i, const RVector& v);
108 void moveVertexAt(int i, const RVector& offset);
109 RVector getVertexAt(int i) const;
110 int getVertexIndex(const RVector& v, double tolerance=RS::PointTolerance) const;
111 RVector getLastVertex() const;
112 int countVertices() const;
113
114 void setBulges(const QList<double>& b);
115 QList<double> getBulges() const;
116 double getBulgeAt(int i) const;
117 void setBulgeAt(int i, double b);
118 bool hasArcSegments() const;
119
120 QList<double> getVertexAngles() const;
121 double getVertexAngle(int i, RS::Orientation orientation = RS::UnknownOrientation) const;
122
123 void setGlobalWidth(double w);
124 void setStartWidthAt(int i, double w);
125 double getStartWidthAt(int i) const;
126 void setEndWidthAt(int i, double w);
127 double getEndWidthAt(int i) const;
128 bool hasWidths() const;
129 void setStartWidths(const QList<double>& sw);
130 QList<double> getStartWidths() const;
131 void setEndWidths(const QList<double>& ew);
132 QList<double> getEndWidths() const;
133
134 void setClosed(bool on);
135 bool isClosed() const;
136 bool isGeometricallyClosed(double tolerance=RS::PointTolerance) const;
137 bool autoClose(double tolerance=RS::PointTolerance) {
138 return toLogicallyClosed(tolerance);
139 }
140 bool toLogicallyClosed(double tolerance=RS::PointTolerance);
141 bool toLogicallyOpen();
142
143 QList<RVector> getSelfIntersectionPoints(double tolerance=RS::PointTolerance) const;
144
145 RS::Orientation getOrientation(bool implicitelyClosed = false) const;
146 bool setOrientation(RS::Orientation orientation);
147
148 RPolyline convertArcToLineSegments(int segments) const;
149 RPolyline convertArcToLineSegmentsLength(double segmentLength) const;
150
151 virtual bool contains(const RVector& point, bool borderIsInside=false, double tolerance=RS::PointTolerance) const;
152 bool containsShape(const RShape& shape) const;
153
154 RVector getPointInside() const;
155
156 virtual RVector getStartPoint() const;
157 virtual RVector getEndPoint() const;
158 virtual RVector getMiddlePoint() const;
159
160 void moveStartPoint(const RVector& pos);
161 void moveEndPoint(const RVector& pos);
162
163 void moveSegmentAt(int i, const RVector& offset);
164
165 virtual double getDirection1() const;
166 virtual double getDirection2() const;
167
168 virtual RS::Side getSideOfPoint(const RVector& point) const;
169
170 virtual RBox getBoundingBox() const;
171
172 double getArea() const;
173
174 virtual double getLength() const;
175
176 virtual double getDistanceFromStart(const RVector& p) const {
177 QList<double> res = getDistancesFromStart(p);
178 if (res.isEmpty()) {
179 return RMAXDOUBLE;
180 }
181 return res.first();
182 }
183 virtual QList<double> getDistancesFromStart(const RVector& p) const;
184 double getLengthTo(const RVector& p, bool limited = true) const;
185 double getSegmentsLength(int fromIndex, int toIndex) const;
186
187 virtual QList<RVector> getEndPoints() const;
188 virtual QList<RVector> getMiddlePoints() const;
189 virtual QList<RVector> getCenterPoints() const;
190 virtual RVector getPointAtPercent(double p) const;
191 virtual QList<RVector> getPointsWithDistanceToEnd(
192 double distance, int from = RS::FromAny) const;
193 virtual QList<RVector> getPointCloud(double segmentLength) const;
194
195 virtual double getAngleAt(double distance, RS::From from = RS::FromStart) const;
196
197 virtual RVector getVectorTo(const RVector& point,
198 bool limited = true, double strictRange = RMAXDOUBLE) const;
199 virtual double getDistanceTo(const RVector& point, bool limited = true, double strictRange = RMAXDOUBLE) const;
200
201 int getClosestSegment(const RVector& point) const;
202 int getClosestVertex(const RVector& point) const;
203
204 virtual bool move(const RVector& offset);
205 virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
206 virtual bool scale(double scaleFactor, const RVector& center = RDEFAULT_RVECTOR);
207 virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
208 virtual bool mirror(const RLine& axis);
209 virtual bool reverse();
210 virtual RPolyline getReversed() const;
211 virtual bool stretch(const RPolyline& area, const RVector& offset);
212
213 virtual QSharedPointer<RShape> getTransformed(const QTransform& transform) const;
214
215 virtual RS::Ending getTrimEnd(const RVector& trimPoint, const RVector& clickPoint);
216 virtual bool trimStartPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid, bool extend = false);
217 virtual bool trimEndPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid, bool extend = false);
218 virtual bool trimStartPoint(double trimDist);
219 virtual bool trimEndPoint(double trimDist);
220
221 virtual QList<QSharedPointer<RShape> > getExploded(int segments = RDEFAULT_MIN1) const;
222 QList<RPolyline> getOutline() const;
223 QList<QPair<RPolyline, RPolyline> > getLeftRightOutline() const;
224 QList<RPolyline> getLeftOutline() const {
225 QList<QPair<RPolyline, RPolyline> > lr = getLeftRightOutline();
226 QList<RPolyline> ret;
227 for (int i=0; i<lr.length(); i++) {
228 ret.append(lr[i].first);
229 }
230 return ret;
231 }
232 QList<RPolyline> getRightOutline() const {
233 QList<QPair<RPolyline, RPolyline> > lr = getLeftRightOutline();
234 QList<RPolyline> ret;
235 for (int i=0; i<lr.length(); i++) {
236 ret.append(lr[i].second);
237 }
238 return ret;
239 }
240 virtual bool isInterpolated() const {
241 return false;
242 }
243 int countSegments() const;
244 QSharedPointer<RShape> getSegmentAt(int i) const;
245 bool isArcSegmentAt(int i) const;
246 QSharedPointer<RShape> getLastSegment() const;
247 QSharedPointer<RShape> getFirstSegment() const;
248
249 static bool isStraight(double bulge);
250
251 RPainterPath toPainterPath(bool addOriginalShapes = false) const;
252
253 bool simplify(double tolerance = RS::PointTolerance);
254 QList<RVector> verifyTangency(double toleranceMin = RS::AngleTolerance, double toleranceMax = M_PI_4);
255
256 void stripWidths();
257 void setMinimumWidth(double w);
258
259 int getSegmentAtDist(double dist);
260 bool relocateStartPoint(const RVector& p);
261 bool relocateStartPoint(double dist);
262 bool convertToClosed();
263 bool convertToOpen();
264
265 RPolyline modifyPolylineCorner(
266 const RShape& trimmedShape1, RS::Ending ending1, int segmentIndex1,
267 const RShape& trimmedShape2, RS::Ending ending2, int segmentIndex2,
268 const RShape* cornerShape = NULL) const;
269
270 bool isConcave() const;
271 QList<RVector> getConvexVertices(bool convex = true) const;
272 QList<RVector> getConcaveVertices() const;
273
274 RVector getCentroid() const;
275
276 QList<RPolyline> splitAtDiscontinuities(double tolerance) const;
277 QList<RPolyline> splitAtSegmentTypeChange() const;
278 bool insertVerticesAtSelfIntersections();
279
280 double getBaseAngle() const;
281 double getWidth() const;
282 bool setWidth(double v);
283 double getHeight() const;
284 bool setHeight(double v);
285
286 QList<RPolyline> morph(const RPolyline& target, int steps, RS::Easing easing = RS::Linear, bool zLinear = true, double customFactor = RNANDOUBLE) const;
287 RPolyline roundAllCorners(double radius) const;
288 RPolyline getPolygon(double segmentLength) const;
289 RPolyline getPolygonHull(double angle, double tolerance, bool inner = false) const;
290
291 static bool hasProxy() {
292 return polylineProxy!=NULL;
293 }
294
299 if (polylineProxy!=NULL) {
300 delete polylineProxy;
301 }
302 polylineProxy = p;
303 }
304
309 return polylineProxy;
310 }
311
312#if QT_VERSION >= 0x060000
317 RPolyline copy() const {
318 return *this;
319 }
320#endif
321
322protected:
323 bool isLineSegment(int i) const;
324
325 void print(QDebug dbg) const;
326
327protected:
332 QList<RVector> vertices;
333
334 QList<double> bulges;
335
336 QList<double> endWidths;
337 QList<double> startWidths;
338
343 bool closed;
344
345private:
346 // TODO caching:
347 //QList<QSharedPointer<RShape> > subShapes;
349};
350
354Q_DECLARE_METATYPE(QSharedPointer<RPolyline>)
355Q_DECLARE_METATYPE(QSharedPointer<RPolyline>*)
356
357#endif
#define RDEFAULT_MIN1
Copyright (c) 2011-2018 by Andrew Mustun.
Definition RExplodable.h:30
#define RNANDOUBLE
Definition RMath.h:74
Q_DECLARE_METATYPE(RMath *)
#define RMAXDOUBLE
Definition RMath.h:66
#define M_PI_4
Definition RMath.h:46
#define RDEFAULT_RVECTOR
Definition RVector.h:38
int i
Copyright (c) 2011-2018 by Andrew Mustun.
Definition autostart.js:32
Represents a box e.g.
Definition RBox.h:46
Interface for explodable shape classes.
Definition RExplodable.h:40
virtual QList< QSharedPointer< RShape > > getExploded(int segments=RDEFAULT_MIN1) const =0
Low-level mathematical representation of a line.
Definition RLine.h:41
Extended painter path with a z-level and a pen.
Definition RPainterPath.h:48
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition RPolyline.h:50
virtual RShape::Type getShapeType() const
Definition RPolyline.h:57
static bool hasProxy()
Definition RPolyline.h:291
QList< double > startWidths
Definition RPolyline.h:337
bool closed
Getter function for this property: isClosed Setter function for this property: setClosed
Definition RPolyline.h:343
static void setPolylineProxy(RPolylineProxy *p)
Definition RPolyline.h:298
QSharedPointer< RPolyline > cloneToPolyline() const
Definition RPolyline.h:65
QList< double > endWidths
Definition RPolyline.h:336
virtual bool isDirected() const
Definition RPolyline.h:69
QList< RVector > vertices
Getter function for this property: getVertices Setter function for this property: setVertices
Definition RPolyline.h:332
QList< RPolyline > getRightOutline() const
Definition RPolyline.h:232
static RPolylineProxy * polylineProxy
Copyright (c) 2011-2018 by Andrew Mustun.
Definition RPolyline.h:348
virtual QSharedPointer< RShape > clone() const
Definition RPolyline.h:61
bool isEmpty() const
Definition RPolyline.h:101
QList< double > bulges
Definition RPolyline.h:334
virtual bool isInterpolated() const
Reimplement and return true if this shape relies on interpolation for geometrical operations such as ...
Definition RPolyline.h:240
QList< RPolyline > getLeftOutline() const
Definition RPolyline.h:224
static RPolylineProxy * getPolylineProxy()
Definition RPolyline.h:308
bool autoClose(double tolerance=RS::PointTolerance)
Definition RPolyline.h:137
virtual double getDistanceFromStart(const RVector &p) const
Definition RPolyline.h:176
Proxy for advanced polyline functionality.
Definition RPolylineProxy.h:42
Orientation
Definition RS.h:700
@ UnknownOrientation
Definition RS.h:701
From
End used to specify from which end of a shape to measure a distance.
Definition RS.h:371
@ FromStart
Definition RS.h:372
@ FromAny
Start or end.
Definition RS.h:374
static const double PointTolerance
Copyright (c) 2011-2018 by Andrew Mustun.
Definition RS.h:920
static const double AngleTolerance
Definition RS.h:921
Side
Side used for side of a point relative to an entity (right hand or left hand side)
Definition RS.h:313
Ending
Entity ending.
Definition RS.h:323
Easing
Definition RS.h:722
@ Linear
Definition RS.h:723
Interface for geometrical shape classes.
Definition RShape.h:72
virtual RVector getVectorTo(const RVector &point, bool limited=true, double strictRange=RMAXDOUBLE) const =0
virtual QList< RVector > getPointCloud(double segmentLength) const =0
virtual bool trimStartPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)
Definition RShape.h:309
virtual RVector getStartPoint() const
Definition RShape.h:289
virtual bool stretch(const RBox &area, const RVector &offset)
Definition RShape.cpp:1741
virtual QList< double > getDistancesFromStart(const RVector &p) const
Definition RShape.h:365
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, int from=RS::FromAny) const =0
virtual RVector getEndPoint() const
Definition RShape.h:292
virtual bool trimEndPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)
Definition RShape.h:328
Type
Definition RShape.h:74
@ Polyline
Definition RShape.h:81
virtual QList< RVector > getCenterPoints() const =0
virtual bool move(const RVector &offset)=0
virtual QList< double > getDoubleProperties() const
Definition RShape.h:172
virtual double getAngleAt(double distance, RS::From from=RS::FromStart) const
Definition RShape.h:249
virtual bool rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)=0
virtual void print(QDebug dbg) const
Definition RShape.cpp:1760
virtual bool mirror(const RLine &axis)=0
virtual double getDirection1() const
Definition RShape.h:277
virtual QList< RVector > getEndPoints() const =0
virtual RVector getMiddlePoint() const
Definition RShape.h:295
virtual QList< RVector > getSelfIntersectionPoints(double tolerance=RS::PointTolerance) const
Definition RShape.h:268
virtual double getDirection2() const
Definition RShape.h:280
virtual RS::Side getSideOfPoint(const RVector &point) const
Definition RShape.h:284
virtual QList< RVector > getVectorProperties() const
Definition RShape.h:170
virtual RVector getPointAtPercent(double p) const
Definition RShape.cpp:191
virtual QList< RVector > getMiddlePoints() const =0
virtual bool reverse()
Definition RShape.h:299
virtual void setZ(double z)=0
virtual QSharedPointer< RShape > getTransformed(const QTransform &transform) const =0
virtual RBox getBoundingBox() const =0
virtual double getDistanceTo(const RVector &point, bool limited=true, double strictRange=RMAXDOUBLE) const
Definition RShape.cpp:57
virtual RS::Ending getTrimEnd(const RVector &trimPoint, const RVector &clickPoint)
Definition RShape.h:345
virtual bool scale(double scaleFactor, const RVector &center=RVector())
Definition RShape.cpp:1756
virtual QList< bool > getBoolProperties() const
Definition RShape.h:173
virtual double getLength() const =0
Represents a 3d vector (x/y/z).
Definition RVector.h:47
static const RVector invalid
invalid vector
Definition RVector.h:335
#define QCADCORE_EXPORT
Definition core_global.h:10
#define NULL
Definition opennurbs_system.h:256