1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <Standard_Stream.hxx>
23 #include <GEOMImpl_SplineDriver.hxx>
24 #include <GEOMImpl_ISpline.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
28 #include <BRepBuilderAPI_MakeEdge.hxx>
29 #include <BRep_Tool.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Edge.hxx>
36 #include <TopoDS_Vertex.hxx>
38 #include <Geom_BezierCurve.hxx>
39 //#include <GeomAPI_PointsToBSpline.hxx>
40 #include <GeomAPI_Interpolate.hxx>
44 #include <gp_Circ.hxx>
45 #include <Precision.hxx>
46 #include <TColgp_Array1OfPnt.hxx>
47 #include <TColgp_HArray1OfPnt.hxx>
49 //=======================================================================
52 //=======================================================================
53 const Standard_GUID& GEOMImpl_SplineDriver::GetID()
55 static Standard_GUID aSplineDriver("FF1BBB33-5D14-4df2-980B-3A668264EA16");
60 //=======================================================================
61 //function : GEOMImpl_SplineDriver
63 //=======================================================================
64 GEOMImpl_SplineDriver::GEOMImpl_SplineDriver()
68 //=======================================================================
71 //=======================================================================
72 Standard_Integer GEOMImpl_SplineDriver::Execute(TFunction_Logbook& log) const
74 if (Label().IsNull()) return 0;
75 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
77 GEOMImpl_ISpline aCI (aFunction);
78 Standard_Integer aType = aFunction->GetType();
82 if (aType == SPLINE_BEZIER || aType == SPLINE_INTERPOLATION) {
83 int ind, aLen = aCI.GetLength();
84 if (aLen < 2) return 0;
85 Standard_Boolean isSeveral = Standard_False;
87 TColgp_Array1OfPnt CurvePoints (1, aLen);
88 for (ind = 1; ind <= aLen; ind++) {
89 Handle(GEOM_Function) aRefPoint = aCI.GetPoint(ind);
90 TopoDS_Shape aShapePnt = aRefPoint->GetValue();
91 if (aShapePnt.ShapeType() == TopAbs_VERTEX) {
92 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
93 if (!isSeveral && ind > 1) {
94 if (aP.Distance(aPrevP) > Precision::Confusion()) {
95 isSeveral = Standard_True;
98 CurvePoints.SetValue(ind, aP);
102 if (aType == SPLINE_BEZIER) {
104 Standard_ConstructionError::Raise("Points for Bezier Curve are too close");
106 Handle(Geom_BezierCurve) GBC = new Geom_BezierCurve(CurvePoints);
107 aShape = BRepBuilderAPI_MakeEdge(GBC).Edge();
109 // GeomAPI_PointsToBSpline GBC (CurvePoints);
110 // aShape = BRepBuilderAPI_MakeEdge(GBC).Edge();
111 Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt(1, aLen);
112 for (ind = 1; ind <= aLen; ind++) {
113 aHCurvePoints->SetValue(ind, CurvePoints.Value(ind));
115 GeomAPI_Interpolate GBC (aHCurvePoints, Standard_False, gp::Resolution());
118 aShape = BRepBuilderAPI_MakeEdge(GBC.Curve()).Edge();
126 if (aShape.IsNull()) return 0;
128 aFunction->SetValue(aShape);
130 log.SetTouched(Label());
136 //=======================================================================
137 //function : GEOMImpl_SplineDriver_Type_
139 //=======================================================================
140 Standard_EXPORT Handle_Standard_Type& GEOMImpl_SplineDriver_Type_()
143 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
144 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
145 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
146 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
147 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
148 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
151 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
152 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_SplineDriver",
153 sizeof(GEOMImpl_SplineDriver),
155 (Standard_Address)_Ancestors,
156 (Standard_Address)NULL);
161 //=======================================================================
162 //function : DownCast
164 //=======================================================================
165 const Handle(GEOMImpl_SplineDriver) Handle(GEOMImpl_SplineDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
167 Handle(GEOMImpl_SplineDriver) _anOtherObject;
169 if (!AnObject.IsNull()) {
170 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_SplineDriver))) {
171 _anOtherObject = Handle(GEOMImpl_SplineDriver)((Handle(GEOMImpl_SplineDriver)&)AnObject);
175 return _anOtherObject ;