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  RVector getLastVertex() const;
78  int countVertices() const;
79 
80  void setBulges(const QList<double>& b);
81  QList<double> getBulges() const;
82  double getBulgeAt(int i) const;
83  void setBulgeAt(int i, double b);
84  bool hasArcSegments() const;
85 
86  void setClosed(bool on);
87  bool isClosed() const;
88  bool isLogicallyClosed() const;
89 
90  bool contains(const RVector& point, bool borderIsInside=false, double tolerance=RS::PointTolerance) const;
91  // TODO:
92  //bool contains(const RShape& shape) const;
93 
94  virtual RVector getStartPoint() const;
95  virtual RVector getEndPoint() const;
96 
97  virtual double getDirection1() const;
98  virtual double getDirection2() const;
99 
100  virtual RBox getBoundingBox() const;
101 
102  virtual double getLength() const;
103 
104  virtual QList<RVector> getEndPoints() const;
105  virtual QList<RVector> getMiddlePoints() const;
106  virtual QList<RVector> getCenterPoints() const;
107  virtual QList<RVector> getPointsWithDistanceToEnd(
108  double distance, RS::From from = RS::FromAny) const;
109 
110  virtual RVector getVectorTo(const RVector& point,
111  bool limited = true) const;
112 
113  virtual bool move(const RVector& offset);
114  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
115  virtual bool scale(double scaleFactor, const RVector& center = RDEFAULT_RVECTOR);
116  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
117  virtual bool mirror(const RLine& axis);
118  virtual bool reverse();
119  virtual bool stretch(const RPolyline& area, const RVector& offset);
120 
121  virtual QSharedPointer<RShape> getTransformed(const QTransform& transform) const;
122 
123  virtual RS::Ending getTrimEnd(const RVector& coord, const RVector& trimPoint);
124  virtual void trimStartPoint(const RVector& p);
125  virtual void trimEndPoint(const RVector& p);
126 
127  virtual QList<QSharedPointer<RShape> > getExploded(int segments = RDEFAULT_MIN1) const;
128  virtual bool isInterpolated() const {
129  return false;
130  }
131  int countSegments() const;
132  QSharedPointer<RShape> getSegmentAt(int i) const;
133 
134  static bool isStraight(double bulge);
135 
136  RPainterPath toPainterPath() const;
137 
138  bool simplify(double angleTolerance = RS::AngleTolerance);
139 
140 protected:
141  bool isLineSegment(int i) const;
142 
143  void print(QDebug dbg) const;
144 
145 protected:
150  QList<RVector> vertices;
151 
152  QList<double> bulges;
153 
158  bool closed;
159 
160 private:
161  // TODO caching:
162  //QList<QSharedPointer<RShape> > subShapes;
163 };
164 
168 Q_DECLARE_METATYPE(QSharedPointer<RPolyline>)
169 Q_DECLARE_METATYPE(QSharedPointer<RPolyline>*)
170 
171 #endif