QCAD
Open Source 2D CAD
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 appendShape(const RShape& shape);
66 
67  void appendVertex(const RVector& vertex, double bulge = 0.0);
68  void prependVertex(const RVector& vertex, double bulge = 0.0);
69  void insertVertex(int index, const RVector& vertex);
70  void removeLastVertex();
71  void removeVertex(int index);
72 
73  void setVertices(const QList<RVector>& vertices);
74  QList<RVector> getVertices() const;
75  void setVertexAt(int i, const RVector& v);
76  RVector getVertexAt(int i) const;
77  int getVertexIndex(const RVector& v, double tolerance=RS::PointTolerance) const;
78  RVector getLastVertex() const;
79  int countVertices() const;
80 
81  void setBulges(const QList<double>& b);
82  QList<double> getBulges() const;
83  double getBulgeAt(int i) const;
84  void setBulgeAt(int i, double b);
85  bool hasArcSegments() const;
86 
87  void setClosed(bool on);
88  bool isClosed() const;
89  bool isLogicallyClosed(double tolerance=RS::PointTolerance) const;
90  RS::Orientation getOrientation() const;
91 
92  bool contains(const RVector& point, bool borderIsInside=false, double tolerance=RS::PointTolerance) const;
93  // TODO:
94  //bool contains(const RShape& shape) const;
95 
96  virtual RVector getStartPoint() const;
97  virtual RVector getEndPoint() const;
98 
99  virtual double getDirection1() const;
100  virtual double getDirection2() const;
101 
102  virtual RBox getBoundingBox() const;
103 
104  virtual double getLength() const;
105 
106  virtual QList<RVector> getEndPoints() const;
107  virtual QList<RVector> getMiddlePoints() const;
108  virtual QList<RVector> getCenterPoints() const;
109  virtual QList<RVector> getPointsWithDistanceToEnd(
110  double distance, RS::From from = RS::FromAny) const;
111 
112  virtual double getAngleAt(double distance, RS::From from = RS::FromStart) const;
113 
114  virtual RVector getVectorTo(const RVector& point,
115  bool limited = true, double strictRange = RMAXDOUBLE) const;
116 
117  virtual bool move(const RVector& offset);
118  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
119  virtual bool scale(double scaleFactor, const RVector& center = RDEFAULT_RVECTOR);
120  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
121  virtual bool mirror(const RLine& axis);
122  virtual bool reverse();
123  virtual bool stretch(const RPolyline& area, const RVector& offset);
124 
125  virtual QSharedPointer<RShape> getTransformed(const QTransform& transform) const;
126 
127  virtual RS::Ending getTrimEnd(const RVector& coord, const RVector& trimPoint);
128  virtual void trimStartPoint(const RVector& p);
129  virtual void trimEndPoint(const RVector& p);
130 
131  virtual QList<QSharedPointer<RShape> > getExploded(int segments = RDEFAULT_MIN1) const;
132  virtual bool isInterpolated() const {
133  return false;
134  }
135  int countSegments() const;
136  QSharedPointer<RShape> getSegmentAt(int i) const;
137 
138  static bool isStraight(double bulge);
139 
140  RPainterPath toPainterPath() const;
141 
142  bool simplify(double angleTolerance = RS::AngleTolerance);
143 
144 protected:
145  bool isLineSegment(int i) const;
146 
147  void print(QDebug dbg) const;
148 
149 protected:
154  QList<RVector> vertices;
155 
156  QList<double> bulges;
157 
162  bool closed;
163 
164 private:
165  // TODO caching:
166  //QList<QSharedPointer<RShape> > subShapes;
167 };
168 
172 Q_DECLARE_METATYPE(QSharedPointer<RPolyline>)
173 Q_DECLARE_METATYPE(QSharedPointer<RPolyline>*)
174 
175 #endif