1 /****************************************************************************
2 ** $Id: rs_spline.h 1914 2004-09-19 11:05:34Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
6 ** This file is part of the qcadlib Library project.
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.
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.
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.
20 ** See http://www.ribbonsoft.com for further details.
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
25 **********************************************************************/
31 #include "rs_entitycontainer.h"
34 * Holds the data that defines a line.
40 * Default constructor. Leaves the data object uninitialized.
44 RS_SplineData(int degree, bool closed)
46 this->degree = degree;
47 this->closed = closed;
50 friend std::ostream & operator<<(std::ostream & os, const RS_SplineData & ld)
52 os << "( degree: " << ld.degree << " closed: " << ld.closed << ")";
57 /** Degree of the spline (1, 2, 3) */
61 /** Control points of the spline. */
62 // Q3ValueList<Vector> controlPoints;
63 QList<Vector> controlPoints;
67 * Class for a spline entity.
69 * @author Andrew Mustun
71 class RS_Spline: public RS_EntityContainer
74 RS_Spline(RS_EntityContainer * parent, const RS_SplineData & d);
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);
83 int getNumberOfKnots();
84 int getNumberOfControlPoints();
86 void setClosed(bool c);
88 virtual VectorSolutions getRefPoints();
89 virtual Vector getNearestRef(const Vector & coord, double * dist = NULL);
90 virtual Vector getNearestSelectedRef(const Vector & coord, double * dist = NULL);
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);
99 virtual void addControlPoint(const Vector & v);
100 virtual void removeLastControlPoint();
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);
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();
113 friend std::ostream & operator<<(std::ostream & os, const RS_Spline & l);
115 virtual void calculateBorders();
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[]);