2 #include <Standard_Stream.hxx>
4 #include <GEOMImpl_SplineDriver.hxx>
5 #include <GEOMImpl_ISpline.hxx>
6 #include <GEOMImpl_Types.hxx>
7 #include <GEOM_Function.hxx>
9 #include <BRepBuilderAPI_MakeEdge.hxx>
10 #include <BRep_Tool.hxx>
15 #include <TopoDS_Shape.hxx>
16 #include <TopoDS_Edge.hxx>
17 #include <TopoDS_Vertex.hxx>
19 #include <Geom_BezierCurve.hxx>
20 //#include <GeomAPI_PointsToBSpline.hxx>
21 #include <GeomAPI_Interpolate.hxx>
25 #include <gp_Circ.hxx>
26 #include <Precision.hxx>
27 #include <TColgp_Array1OfPnt.hxx>
28 #include <TColgp_HArray1OfPnt.hxx>
30 //=======================================================================
33 //=======================================================================
34 const Standard_GUID& GEOMImpl_SplineDriver::GetID()
36 static Standard_GUID aSplineDriver("FF1BBB33-5D14-4df2-980B-3A668264EA16");
41 //=======================================================================
42 //function : GEOMImpl_SplineDriver
44 //=======================================================================
45 GEOMImpl_SplineDriver::GEOMImpl_SplineDriver()
49 //=======================================================================
52 //=======================================================================
53 Standard_Integer GEOMImpl_SplineDriver::Execute(TFunction_Logbook& log) const
55 if (Label().IsNull()) return 0;
56 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
58 GEOMImpl_ISpline aCI (aFunction);
59 Standard_Integer aType = aFunction->GetType();
63 if (aType == SPLINE_BEZIER || aType == SPLINE_INTERPOLATION) {
64 int ind, aLen = aCI.GetLength();
65 if (aLen < 2) return 0;
66 Standard_Boolean isSeveral = Standard_False;
68 TColgp_Array1OfPnt CurvePoints (1, aLen);
69 for (ind = 1; ind <= aLen; ind++) {
70 Handle(GEOM_Function) aRefPoint = aCI.GetPoint(ind);
71 TopoDS_Shape aShapePnt = aRefPoint->GetValue();
72 if (aShapePnt.ShapeType() == TopAbs_VERTEX) {
73 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
74 if (!isSeveral && ind > 1) {
75 if (aP.Distance(aPrevP) > Precision::Confusion()) {
76 isSeveral = Standard_True;
79 CurvePoints.SetValue(ind, aP);
83 if (aType == SPLINE_BEZIER) {
85 Standard_ConstructionError::Raise("Points for Bezier Curve are too close");
87 Handle(Geom_BezierCurve) GBC = new Geom_BezierCurve(CurvePoints);
88 aShape = BRepBuilderAPI_MakeEdge(GBC).Edge();
90 // GeomAPI_PointsToBSpline GBC (CurvePoints);
91 // aShape = BRepBuilderAPI_MakeEdge(GBC).Edge();
92 Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt(1, aLen);
93 for (ind = 1; ind <= aLen; ind++) {
94 aHCurvePoints->SetValue(ind, CurvePoints.Value(ind));
96 GeomAPI_Interpolate GBC (aHCurvePoints, Standard_False, gp::Resolution());
99 aShape = BRepBuilderAPI_MakeEdge(GBC.Curve()).Edge();
107 if (aShape.IsNull()) return 0;
109 aFunction->SetValue(aShape);
111 log.SetTouched(Label());
117 //=======================================================================
118 //function : GEOMImpl_SplineDriver_Type_
120 //=======================================================================
121 Standard_EXPORT Handle_Standard_Type& GEOMImpl_SplineDriver_Type_()
124 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
125 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
126 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
127 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
128 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
129 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
132 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
133 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_SplineDriver",
134 sizeof(GEOMImpl_SplineDriver),
136 (Standard_Address)_Ancestors,
137 (Standard_Address)NULL);
142 //=======================================================================
143 //function : DownCast
145 //=======================================================================
146 const Handle(GEOMImpl_SplineDriver) Handle(GEOMImpl_SplineDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
148 Handle(GEOMImpl_SplineDriver) _anOtherObject;
150 if (!AnObject.IsNull()) {
151 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_SplineDriver))) {
152 _anOtherObject = Handle(GEOMImpl_SplineDriver)((Handle(GEOMImpl_SplineDriver)&)AnObject);
156 return _anOtherObject ;