1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include <Standard_Stream.hxx>
24 #include <GEOMImpl_SplineDriver.hxx>
25 #include <GEOMImpl_ISpline.hxx>
26 #include <GEOMImpl_Types.hxx>
27 #include <GEOM_Function.hxx>
29 #include <BRepBuilderAPI_MakeEdge.hxx>
30 #include <BRep_Tool.hxx>
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Edge.hxx>
37 #include <TopoDS_Vertex.hxx>
39 #include <Geom_BezierCurve.hxx>
40 //#include <GeomAPI_PointsToBSpline.hxx>
41 #include <GeomAPI_Interpolate.hxx>
45 #include <gp_Circ.hxx>
46 #include <Precision.hxx>
47 #include <TColgp_Array1OfPnt.hxx>
48 #include <TColgp_HArray1OfPnt.hxx>
50 //=======================================================================
53 //=======================================================================
54 const Standard_GUID& GEOMImpl_SplineDriver::GetID()
56 static Standard_GUID aSplineDriver("FF1BBB33-5D14-4df2-980B-3A668264EA16");
61 //=======================================================================
62 //function : GEOMImpl_SplineDriver
64 //=======================================================================
65 GEOMImpl_SplineDriver::GEOMImpl_SplineDriver()
69 //=======================================================================
72 //=======================================================================
73 Standard_Integer GEOMImpl_SplineDriver::Execute(TFunction_Logbook& log) const
75 if (Label().IsNull()) return 0;
76 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
78 GEOMImpl_ISpline aCI (aFunction);
79 Standard_Integer aType = aFunction->GetType();
83 if (aType == SPLINE_BEZIER || aType == SPLINE_INTERPOLATION) {
84 int ind, aLen = aCI.GetLength();
85 if (aLen < 2) return 0;
86 Standard_Boolean isSeveral = Standard_False;
88 TColgp_Array1OfPnt CurvePoints (1, aLen);
89 for (ind = 1; ind <= aLen; ind++) {
90 Handle(GEOM_Function) aRefPoint = aCI.GetPoint(ind);
91 TopoDS_Shape aShapePnt = aRefPoint->GetValue();
92 if (aShapePnt.ShapeType() == TopAbs_VERTEX) {
93 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
94 if (!isSeveral && ind > 1) {
95 if (aP.Distance(aPrevP) > Precision::Confusion()) {
96 isSeveral = Standard_True;
99 CurvePoints.SetValue(ind, aP);
103 if (aType == SPLINE_BEZIER) {
105 Standard_ConstructionError::Raise("Points for Bezier Curve are too close");
107 Handle(Geom_BezierCurve) GBC = new Geom_BezierCurve(CurvePoints);
108 aShape = BRepBuilderAPI_MakeEdge(GBC).Edge();
110 // GeomAPI_PointsToBSpline GBC (CurvePoints);
111 // aShape = BRepBuilderAPI_MakeEdge(GBC).Edge();
112 Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt(1, aLen);
113 for (ind = 1; ind <= aLen; ind++) {
114 aHCurvePoints->SetValue(ind, CurvePoints.Value(ind));
116 GeomAPI_Interpolate GBC (aHCurvePoints, Standard_False, gp::Resolution());
119 aShape = BRepBuilderAPI_MakeEdge(GBC.Curve()).Edge();
127 if (aShape.IsNull()) return 0;
129 aFunction->SetValue(aShape);
131 log.SetTouched(Label());
137 //=======================================================================
138 //function : GEOMImpl_SplineDriver_Type_
140 //=======================================================================
141 Standard_EXPORT Handle_Standard_Type& GEOMImpl_SplineDriver_Type_()
144 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
145 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
146 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
147 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
148 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
149 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
152 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
153 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_SplineDriver",
154 sizeof(GEOMImpl_SplineDriver),
156 (Standard_Address)_Ancestors,
157 (Standard_Address)NULL);
162 //=======================================================================
163 //function : DownCast
165 //=======================================================================
166 const Handle(GEOMImpl_SplineDriver) Handle(GEOMImpl_SplineDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
168 Handle(GEOMImpl_SplineDriver) _anOtherObject;
170 if (!AnObject.IsNull()) {
171 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_SplineDriver))) {
172 _anOtherObject = Handle(GEOMImpl_SplineDriver)((Handle(GEOMImpl_SplineDriver)&)AnObject);
176 return _anOtherObject ;