]> Shamusworld >> Repos - architektonas/blob - src/base/rs_spline.h
Changed RS_Graphic to Drawing; this is less confusing as a drawing is
[architektonas] / src / base / rs_spline.h
1 #ifndef RS_SPLINE_H
2 #define RS_SPLINE_H
3
4 #include <QtCore>
5 #include "rs_entitycontainer.h"
6
7 /**
8  * Holds the data that defines a line.
9  */
10 class RS_SplineData
11 {
12         public:
13                 /**
14                  * Default constructor. Leaves the data object uninitialized.
15                  */
16                 RS_SplineData() {}
17
18                 RS_SplineData(int degree, bool closed)
19                 {
20                         this->degree = degree;
21                         this->closed = closed;
22                 }
23
24                 friend std::ostream & operator<<(std::ostream & os, const RS_SplineData & ld)
25                 {
26                         os << "( degree: " << ld.degree << " closed: " << ld.closed << ")";
27                         return os;
28                 }
29
30         public:
31                 /** Degree of the spline (1, 2, 3) */
32                 int degree;
33                 /** Closed flag. */
34                 bool closed;
35                 /** Control points of the spline. */
36 //              Q3ValueList<Vector> controlPoints;
37                 QList<Vector> controlPoints;
38 };
39
40 /**
41  * Class for a spline entity.
42  *
43  * @author Andrew Mustun
44  */
45 class RS_Spline: public RS_EntityContainer
46 {
47 public:
48     RS_Spline(RS_EntityContainer * parent, const RS_SplineData & d);
49     virtual ~RS_Spline();
50
51     virtual RS_Entity * clone();
52     virtual RS2::EntityType rtti() const;
53     virtual bool isEdge() const;
54     RS_SplineData getData() const;
55         void setDegree(int deg);
56         int getDegree();
57     int getNumberOfKnots();
58         int getNumberOfControlPoints();
59         bool isClosed();
60         void setClosed(bool c);
61
62     virtual VectorSolutions getRefPoints();
63     virtual Vector getNearestRef(const Vector & coord, double * dist = NULL);
64     virtual Vector getNearestSelectedRef(const Vector & coord, double * dist = NULL);
65
66         void update();
67
68     virtual Vector getNearestEndpoint(const Vector & coord, double * dist = NULL);
69     virtual Vector getNearestCenter(const Vector & coord, double * dist = NULL);
70     virtual Vector getNearestMiddle(const Vector & coord, double * dist = NULL);
71     virtual Vector getNearestDist(double distance, const Vector & coord,                                      double * dist = NULL);
72
73         virtual void addControlPoint(const Vector & v);
74         virtual void removeLastControlPoint();
75
76     virtual void move(Vector offset);
77     virtual void rotate(Vector center, double angle);
78     virtual void scale(Vector center, Vector factor);
79     virtual void mirror(Vector axisPoint1, Vector axisPoint2);
80         virtual void moveRef(const Vector & ref, const Vector & offset);
81
82 //    virtual void draw(RS_Painter* painter, RS_GraphicView* view, double patternOffset=0.0);
83     virtual void draw(PaintInterface * painter, RS_GraphicView * view, double patternOffset = 0.0);
84 //      Q3ValueList<Vector> getControlPoints();
85         QList<Vector> getControlPoints();
86
87     friend std::ostream & operator<<(std::ostream & os, const RS_Spline & l);
88
89     virtual void calculateBorders();
90
91         static void rbasis(int c, double t, int npts, int x[], double h[], double r[]);
92         static void knot(int num, int order, int knotVector[]);
93         static void rbspline(int npts, int k, int p1, double b[], double h[], double p[]);
94         static void knotu(int num, int order, int knotVector[]);
95         static void rbsplinu(int npts, int k, int p1, double b[], double h[], double p[]);
96
97 protected:
98     RS_SplineData data;
99 };
100
101 #endif