3 #include "GEOMImpl_SplineDriver.hxx"
4 #include "GEOMImpl_ISpline.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
8 #include <BRepBuilderAPI_MakeEdge.hxx>
9 #include <BRep_Tool.hxx>
14 #include <TopoDS_Shape.hxx>
15 #include <TopoDS_Edge.hxx>
16 #include <TopoDS_Vertex.hxx>
18 #include <Geom_BezierCurve.hxx>
19 //#include <GeomAPI_PointsToBSpline.hxx>
20 #include <GeomAPI_Interpolate.hxx>
24 #include <gp_Circ.hxx>
25 #include <Precision.hxx>
26 #include <TColgp_Array1OfPnt.hxx>
27 #include <TColgp_HArray1OfPnt.hxx>
29 //=======================================================================
32 //=======================================================================
33 const Standard_GUID& GEOMImpl_SplineDriver::GetID()
35 static Standard_GUID aSplineDriver("FF1BBB33-5D14-4df2-980B-3A668264EA16");
40 //=======================================================================
41 //function : GEOMImpl_SplineDriver
43 //=======================================================================
44 GEOMImpl_SplineDriver::GEOMImpl_SplineDriver()
48 //=======================================================================
51 //=======================================================================
52 Standard_Integer GEOMImpl_SplineDriver::Execute(TFunction_Logbook& log) const
54 if (Label().IsNull()) return 0;
55 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
57 GEOMImpl_ISpline aCI (aFunction);
58 Standard_Integer aType = aFunction->GetType();
62 if (aType == SPLINE_BEZIER || aType == SPLINE_INTERPOLATION) {
63 int ind, aLen = aCI.GetLength();
64 if (aLen < 2) return 0;
65 Standard_Boolean isSeveral = Standard_False;
67 TColgp_Array1OfPnt CurvePoints (1, aLen);
68 for (ind = 1; ind <= aLen; ind++) {
69 Handle(GEOM_Function) aRefPoint = aCI.GetPoint(ind);
70 TopoDS_Shape aShapePnt = aRefPoint->GetValue();
71 if (aShapePnt.ShapeType() == TopAbs_VERTEX) {
72 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
73 if (!isSeveral && ind > 1) {
74 if (aP.Distance(aPrevP) > Precision::Confusion()) {
75 isSeveral = Standard_True;
78 CurvePoints.SetValue(ind, aP);
82 if (aType == SPLINE_BEZIER) {
84 Standard_ConstructionError::Raise("Points for Bezier Curve are too close");
86 Handle(Geom_BezierCurve) GBC = new Geom_BezierCurve(CurvePoints);
87 aShape = BRepBuilderAPI_MakeEdge(GBC).Edge();
89 // GeomAPI_PointsToBSpline GBC (CurvePoints);
90 // aShape = BRepBuilderAPI_MakeEdge(GBC).Edge();
91 Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt(1, aLen);
92 for (ind = 1; ind <= aLen; ind++) {
93 aHCurvePoints->SetValue(ind, CurvePoints.Value(ind));
95 GeomAPI_Interpolate GBC (aHCurvePoints, Standard_False, gp::Resolution());
98 aShape = BRepBuilderAPI_MakeEdge(GBC).Edge();
106 if (aShape.IsNull()) return 0;
108 aFunction->SetValue(aShape);
110 log.SetTouched(Label());
116 //=======================================================================
117 //function : GEOMImpl_SplineDriver_Type_
119 //=======================================================================
120 Standard_EXPORT Handle_Standard_Type& GEOMImpl_SplineDriver_Type_()
123 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
124 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
125 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
126 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
127 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
128 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
131 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
132 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_SplineDriver",
133 sizeof(GEOMImpl_SplineDriver),
135 (Standard_Address)_Ancestors,
136 (Standard_Address)NULL);
141 //=======================================================================
142 //function : DownCast
144 //=======================================================================
145 const Handle(GEOMImpl_SplineDriver) Handle(GEOMImpl_SplineDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
147 Handle(GEOMImpl_SplineDriver) _anOtherObject;
149 if (!AnObject.IsNull()) {
150 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_SplineDriver))) {
151 _anOtherObject = Handle(GEOMImpl_SplineDriver)((Handle(GEOMImpl_SplineDriver)&)AnObject);
155 return _anOtherObject ;