]> Shamusworld >> Repos - architektonas/blob - src/base/rs_spline.h
30e613a7792df0d135549d9498a0a8de6ba0e078
[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     virtual VectorSolutions getRefPoints();
62     virtual Vector getNearestRef(const Vector & coord, double * dist = NULL);
63     virtual Vector getNearestSelectedRef(const Vector & coord, double * dist = NULL);
64         void update();
65     virtual Vector getNearestEndpoint(const Vector & coord, double * dist = NULL);
66     virtual Vector getNearestCenter(const Vector & coord, double * dist = NULL);
67     virtual Vector getNearestMiddle(const Vector & coord, double * dist = NULL);
68     virtual Vector getNearestDist(double distance, const Vector & coord,                                      double * dist = NULL);
69         virtual void addControlPoint(const Vector & v);
70         virtual void removeLastControlPoint();
71     virtual void move(Vector offset);
72     virtual void rotate(Vector center, double angle);
73     virtual void scale(Vector center, Vector factor);
74     virtual void mirror(Vector axisPoint1, Vector axisPoint2);
75         virtual void moveRef(const Vector & ref, const Vector & offset);
76     virtual void draw(PaintInterface * painter, GraphicView * view, double patternOffset = 0.0);
77         QList<Vector> getControlPoints();
78
79     friend std::ostream & operator<<(std::ostream & os, const RS_Spline & l);
80
81     virtual void calculateBorders();
82
83         static void rbasis(int c, double t, int npts, int x[], double h[], double r[]);
84         static void knot(int num, int order, int knotVector[]);
85         static void rbspline(int npts, int k, int p1, double b[], double h[], double p[]);
86         static void knotu(int num, int order, int knotVector[]);
87         static void rbsplinu(int npts, int k, int p1, double b[], double h[], double p[]);
88
89 protected:
90     RS_SplineData data;
91 };
92
93 #endif