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 "RPolylineProxy.h"
31 #include "RShape.h"
32 #include "RVector.h"
33 
34 class RBox;
35 
36 #ifndef RDEFAULT_MIN1
37 #define RDEFAULT_MIN1 -1
38 #endif
39 
50 class QCADCORE_EXPORT RPolyline: public RShape, public RExplodable, public RDirected {
51 public:
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 getType() const {
58  return Polyline;
59  }
60 
61  virtual RPolyline* clone() const {
62  return new RPolyline(*this);
63  }
64 
65  virtual void to2D();
66 
67  void clear();
68  void normalize(double tolerance = RS::PointTolerance);
69 
70  bool prependShape(const RShape& shape);
71  bool appendShape(const RShape& shape, bool prepend = false);
72  bool appendShapeAuto(const RShape& shape);
73 
74  void appendVertex(const RVector& vertex, double bulge = 0.0, double w1 = 0.0, double w2 = 0.0);
75  void prependVertex(const RVector& vertex, double bulge = 0.0, double w1 = 0.0, double w2 = 0.0);
76  void insertVertex(int index, const RVector& vertex);
77  void insertVertexAt(const RVector& point);
78  void removeFirstVertex();
79  void removeLastVertex();
80  void removeVertex(int index);
81  void removeVerticesAfter(int index);
82  void removeVerticesBefore(int index);
83 
84  bool isEmpty() {
85  return countVertices()==0;
86  }
87 
88  void setVertices(const QList<RVector>& vertices);
89  QList<RVector> getVertices() const;
90  void setVertexAt(int i, const RVector& v);
91  RVector getVertexAt(int i) const;
92  int getVertexIndex(const RVector& v, double tolerance=RS::PointTolerance) const;
93  RVector getLastVertex() const;
94  int countVertices() const;
95 
96  void setBulges(const QList<double>& b);
97  QList<double> getBulges() const;
98  double getBulgeAt(int i) const;
99  void setBulgeAt(int i, double b);
100  bool hasArcSegments() const;
101 
102  QList<double> getVertexAngles() const;
103  double getVertexAngle(int i, RS::Orientation orientation = RS::UnknownOrientation) const;
104 
105  void setGlobalWidth(double w);
106  void setStartWidthAt(int i, double w);
107  double getStartWidthAt(int i) const;
108  void setEndWidthAt(int i, double w);
109  double getEndWidthAt(int i) const;
110  bool hasWidths() const;
111  void setStartWidths(const QList<double>& sw);
112  QList<double> getStartWidths() const;
113  void setEndWidths(const QList<double>& ew);
114  QList<double> getEndWidths() const;
115 
116  void setClosed(bool on);
117  bool isClosed() const;
118  bool isGeometricallyClosed(double tolerance=RS::PointTolerance) const;
119  bool autoClose();
120 
121  RS::Orientation getOrientation(bool implicitelyClosed = false) const;
122 
123  bool contains(const RVector& point, bool borderIsInside=false, double tolerance=RS::PointTolerance) const;
124  bool containsShape(const RShape& shape) const;
125 
126  RVector getPointInside() const;
127 
128  virtual RVector getStartPoint() const;
129  virtual RVector getEndPoint() const;
130  virtual RVector getMiddlePoint() const;
131 
132  void moveStartPoint(const RVector& pos);
133  void moveEndPoint(const RVector& pos);
134 
135  virtual double getDirection1() const;
136  virtual double getDirection2() const;
137 
138  virtual RS::Side getSideOfPoint(const RVector& point) const;
139 
140  virtual RBox getBoundingBox() const;
141 
142  double getArea() const;
143 
144  virtual double getLength() const;
145  double getLengthTo(const RVector& p, bool limited = true) const;
146 
147  virtual QList<RVector> getEndPoints() const;
148  virtual QList<RVector> getMiddlePoints() const;
149  virtual QList<RVector> getCenterPoints() const;
150  virtual QList<RVector> getPointsWithDistanceToEnd(
151  double distance, int from = RS::FromAny) const;
152 
153  virtual double getAngleAt(double distance, RS::From from = RS::FromStart) const;
154 
155  virtual RVector getVectorTo(const RVector& point,
156  bool limited = true, double strictRange = RMAXDOUBLE) const;
157  virtual double getDistanceTo(const RVector& point, bool limited = true, double strictRange = RMAXDOUBLE) const;
158 
159  int getClosestSegment(const RVector& point) const;
160  int getClosestVertex(const RVector& point) const;
161 
162  virtual bool move(const RVector& offset);
163  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
164  virtual bool scale(double scaleFactor, const RVector& center = RDEFAULT_RVECTOR);
165  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
166  virtual bool mirror(const RLine& axis);
167  virtual bool reverse();
168  virtual bool stretch(const RPolyline& area, const RVector& offset);
169 
170  virtual QSharedPointer<RShape> getTransformed(const QTransform& transform) const;
171 
172  virtual RS::Ending getTrimEnd(const RVector& trimPoint, const RVector& clickPoint);
173  virtual bool trimStartPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid, bool extend = false);
174  virtual bool trimEndPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid, bool extend = false);
175 
176  virtual QList<QSharedPointer<RShape> > getExploded(int segments = RDEFAULT_MIN1) const;
177  QList<RPolyline> getOutline() const;
178  virtual bool isInterpolated() const {
179  return false;
180  }
181  int countSegments() const;
182  QSharedPointer<RShape> getSegmentAt(int i) const;
183  bool isArcSegmentAt(int i) const;
184  QSharedPointer<RShape> getLastSegment() const;
185  QSharedPointer<RShape> getFirstSegment() const;
186 
187  static bool isStraight(double bulge);
188 
189  RPainterPath toPainterPath() const;
190 
191  bool simplify(double angleTolerance = RS::AngleTolerance);
192  QList<RVector> verifyTangency(double toleranceMin = RS::AngleTolerance, double toleranceMax = M_PI_4);
193 
194  void stripWidths();
195 
196  bool relocateStartPoint(const RVector& p);
197  bool convertToClosed();
198  bool convertToOpen();
199 
200  RPolyline modifyPolylineCorner(
201  const RShape& trimmedShape1, RS::Ending ending1, int segmentIndex1,
202  const RShape& trimmedShape2, RS::Ending ending2, int segmentIndex2,
203  const RShape* cornerShape = NULL) const;
204 
205  static bool hasProxy() {
206  return polylineProxy!=NULL;
207  }
208 
213  if (polylineProxy!=NULL) {
214  delete polylineProxy;
215  }
216  polylineProxy = p;
217  }
218 
223  return polylineProxy;
224  }
225 
226 protected:
227  bool isLineSegment(int i) const;
228 
229  void print(QDebug dbg) const;
230 
231 protected:
236  QList<RVector> vertices;
237 
238  QList<double> bulges;
239 
240  QList<double> endWidths;
241  QList<double> startWidths;
242 
247  bool closed;
248 
249 private:
250  // TODO caching:
251  //QList<QSharedPointer<RShape> > subShapes;
253 };
254 
258 Q_DECLARE_METATYPE(QSharedPointer<RPolyline>)
259 Q_DECLARE_METATYPE(QSharedPointer<RPolyline>*)
260 
261 #endif
static const double AngleTolerance
Definition: RS.h:552
Represents a box e.g.
Definition: RBox.h:43
Ending
Entity ending.
Definition: RS.h:150
Definition: RS.h:494
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 double getDirection1() const =0
static RPolylineProxy * polylineProxy
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RPolyline.h:252
QList< double > endWidths
Definition: RPolyline.h:240
virtual RVector getEndPoint() const =0
void mirror(void e, void axis)
Mirrors the given entity or shape at the given axis.
Definition: simple_modify.js:109
#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:58
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, int from=RS::FromAny) const =0
static bool hasProxy()
Definition: RPolyline.h:205
virtual bool isInterpolated() const
Reimplement and return true if this shape relies on interpolation for geometrical operations such as ...
Definition: RPolyline.h:178
virtual double getLength() const =0
virtual RShape::Type getType() const
Definition: RPolyline.h:57
virtual RBox getBoundingBox() const =0
Start or end.
Definition: RS.h:201
QList< double > startWidths
Definition: RPolyline.h:241
virtual bool trimEndPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)=0
QList< RVector > vertices
Getter function for this property: getVertices.
Definition: RPolyline.h:236
Side
Side used for side of a point relativ to an entity (right hand or left hand side) ...
Definition: RS.h:140
bool closed
Getter function for this property: isClosed.
Definition: RPolyline.h:247
virtual double getAngleAt(double distance, RS::From from=RS::FromStart) const
Definition: RShape.h:202
static const double PointTolerance
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RS.h:551
virtual bool stretch(const RBox &area, const RVector &offset)
Definition: RShape.cpp:1669
virtual RPolyline * clone() const
Definition: RPolyline.h:61
Q_DECLARE_METATYPE(RMath *)
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:72
bool isEmpty()
Definition: RPolyline.h:84
virtual QList< RVector > getMiddlePoints() const =0
Extended painter path with a z-level and a pen.
Definition: RPainterPath.h:46
Type
Definition: RShape.h:54
#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:15
virtual double getDistanceTo(const RVector &point, bool limited=true, double strictRange=RMAXDOUBLE) const
Definition: RShape.cpp:47
Definition: RS.h:199
Definition: RShape.h:61
Low-level mathematical representation of a line.
Definition: RLine.h:42
virtual RS::Side getSideOfPoint(const RVector &point) const =0
#define RDEFAULT_MIN1
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RExplodable.h:30
Interface for explodable shape classes.
Definition: RExplodable.h:40
virtual bool trimStartPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)=0
virtual RVector getStartPoint() const =0
virtual bool reverse()=0
virtual QSharedPointer< RShape > getTransformed(const QTransform &transform) const =0
Copyright (c) 2011-2016 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:198
virtual double getDirection2() const =0
Orientation
Definition: RS.h:493
Proxy for advanced polyline functionality.
Definition: RPolylineProxy.h:41
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:50
virtual RVector getMiddlePoint() const =0
Interface for geometrical shape classes.
Definition: RShape.h:52
virtual QList< RVector > getCenterPoints() const =0
virtual void print(QDebug dbg) const
Definition: RShape.cpp:1684
static const RVector invalid
invalid vector
Definition: RVector.h:309
virtual RS::Ending getTrimEnd(const RVector &trimPoint, const RVector &clickPoint)=0
QList< double > bulges
Definition: RPolyline.h:238
#define RDEFAULT_RVECTOR
Definition: RVector.h:37
static void setPolylineProxy(RPolylineProxy *p)
Definition: RPolyline.h:212
static RPolylineProxy * getPolylineProxy()
Definition: RPolyline.h:222