]> Shamusworld >> Repos - architektonas/blob - src/base/rs_spline.h
Initial import
[architektonas] / src / base / rs_spline.h
1 /****************************************************************************
2 ** $Id: rs_spline.h 1914 2004-09-19 11:05:34Z andrew $
3 **
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 **
6 ** This file is part of the qcadlib Library project.
7 **
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
12 **
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
16 **
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 **
20 ** See http://www.ribbonsoft.com for further details.
21 **
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26
27 #ifndef RS_SPLINE_H
28 #define RS_SPLINE_H
29
30 #include <QtCore>
31 #include "rs_entitycontainer.h"
32
33 /**
34  * Holds the data that defines a line.
35  */
36 class RS_SplineData
37 {
38         public:
39                 /**
40                  * Default constructor. Leaves the data object uninitialized.
41                  */
42                 RS_SplineData() {}
43
44                 RS_SplineData(int degree, bool closed)
45                 {
46                         this->degree = degree;
47                         this->closed = closed;
48                 }
49
50                 friend std::ostream & operator<<(std::ostream & os, const RS_SplineData & ld)
51                 {
52                         os << "( degree: " << ld.degree << " closed: " << ld.closed << ")";
53                         return os;
54                 }
55
56         public:
57                 /** Degree of the spline (1, 2, 3) */
58                 int degree;
59                 /** Closed flag. */
60                 bool closed;
61                 /** Control points of the spline. */
62 //              Q3ValueList<Vector> controlPoints;
63                 QList<Vector> controlPoints;
64 };
65
66 /**
67  * Class for a spline entity.
68  *
69  * @author Andrew Mustun
70  */
71 class RS_Spline: public RS_EntityContainer
72 {
73 public:
74     RS_Spline(RS_EntityContainer * parent, const RS_SplineData & d);
75     virtual ~RS_Spline();
76
77     virtual RS_Entity * clone();
78     virtual RS2::EntityType rtti() const;
79     virtual bool isEdge() const;
80     RS_SplineData getData() const;
81         void setDegree(int deg);
82         int getDegree();
83     int getNumberOfKnots();
84         int getNumberOfControlPoints();
85         bool isClosed();
86         void setClosed(bool c);
87
88     virtual VectorSolutions getRefPoints();
89     virtual Vector getNearestRef(const Vector & coord, double * dist = NULL);
90     virtual Vector getNearestSelectedRef(const Vector & coord, double * dist = NULL);
91
92         void update();
93
94     virtual Vector getNearestEndpoint(const Vector & coord, double * dist = NULL);
95     virtual Vector getNearestCenter(const Vector & coord, double * dist = NULL);
96     virtual Vector getNearestMiddle(const Vector & coord, double * dist = NULL);
97     virtual Vector getNearestDist(double distance, const Vector & coord,                                      double * dist = NULL);
98
99         virtual void addControlPoint(const Vector & v);
100         virtual void removeLastControlPoint();
101
102     virtual void move(Vector offset);
103     virtual void rotate(Vector center, double angle);
104     virtual void scale(Vector center, Vector factor);
105     virtual void mirror(Vector axisPoint1, Vector axisPoint2);
106         virtual void moveRef(const Vector & ref, const Vector & offset);
107
108 //    virtual void draw(RS_Painter* painter, RS_GraphicView* view, double patternOffset=0.0);
109     virtual void draw(PaintInterface * painter, RS_GraphicView * view, double patternOffset = 0.0);
110 //      Q3ValueList<Vector> getControlPoints();
111         QList<Vector> getControlPoints();
112
113     friend std::ostream & operator<<(std::ostream & os, const RS_Spline & l);
114
115     virtual void calculateBorders();
116
117         static void rbasis(int c, double t, int npts, int x[], double h[], double r[]);
118         static void knot(int num, int order, int knotVector[]);
119         static void rbspline(int npts, int k, int p1, double b[], double h[], double p[]);
120         static void knotu(int num, int order, int knotVector[]);
121         static void rbsplinu(int npts, int k, int p1, double b[], double h[], double p[]);
122
123 protected:
124     RS_SplineData data;
125 };
126
127 #endif