Salome HOME
PAL7508. Correct behaviour of GetShapesOnPlane().
[modules/geom.git] / src / GEOMImpl / GEOMImpl_SplineDriver.cxx
1
2 using namespace std;
3 #include "GEOMImpl_SplineDriver.hxx"
4 #include "GEOMImpl_ISpline.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
7
8 #include <BRepBuilderAPI_MakeEdge.hxx>
9 #include <BRep_Tool.hxx>
10
11 #include <TopAbs.hxx>
12 #include <TopExp.hxx>
13 #include <TopoDS.hxx>
14 #include <TopoDS_Shape.hxx>
15 #include <TopoDS_Edge.hxx>
16 #include <TopoDS_Vertex.hxx>
17
18 #include <Geom_BezierCurve.hxx>
19 //#include <GeomAPI_PointsToBSpline.hxx>
20 #include <GeomAPI_Interpolate.hxx>
21
22 #include <gp.hxx>
23 #include <gp_Pnt.hxx>
24 #include <gp_Circ.hxx>
25 #include <Precision.hxx>
26 #include <TColgp_Array1OfPnt.hxx>
27 #include <TColgp_HArray1OfPnt.hxx>
28
29 //=======================================================================
30 //function : GetID
31 //purpose  :
32 //=======================================================================
33 const Standard_GUID& GEOMImpl_SplineDriver::GetID()
34 {
35   static Standard_GUID aSplineDriver("FF1BBB33-5D14-4df2-980B-3A668264EA16");
36   return aSplineDriver;
37 }
38
39
40 //=======================================================================
41 //function : GEOMImpl_SplineDriver
42 //purpose  :
43 //=======================================================================
44 GEOMImpl_SplineDriver::GEOMImpl_SplineDriver()
45 {
46 }
47
48 //=======================================================================
49 //function : Execute
50 //purpose  :
51 //=======================================================================
52 Standard_Integer GEOMImpl_SplineDriver::Execute(TFunction_Logbook& log) const
53 {
54   if (Label().IsNull()) return 0;
55   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
56
57   GEOMImpl_ISpline aCI (aFunction);
58   Standard_Integer aType = aFunction->GetType();
59
60   TopoDS_Shape aShape;
61
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;
66     gp_Pnt aPrevP;
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;
76           }
77         }
78         CurvePoints.SetValue(ind, aP);
79         aPrevP = aP;
80       }
81     }
82     if (aType == SPLINE_BEZIER) {
83       if (!isSeveral) {
84         Standard_ConstructionError::Raise("Points for Bezier Curve are too close");
85       }
86       Handle(Geom_BezierCurve) GBC = new Geom_BezierCurve(CurvePoints);
87       aShape = BRepBuilderAPI_MakeEdge(GBC).Edge();
88     } else {
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));
94       }
95       GeomAPI_Interpolate GBC (aHCurvePoints, Standard_False, gp::Resolution());
96       GBC.Perform();
97       if (GBC.IsDone())
98         aShape = BRepBuilderAPI_MakeEdge(GBC).Edge();
99       else
100         return 0;
101     }
102   }
103   else {
104   }
105
106   if (aShape.IsNull()) return 0;
107
108   aFunction->SetValue(aShape);
109
110   log.SetTouched(Label());
111
112   return 1;
113 }
114
115
116 //=======================================================================
117 //function :  GEOMImpl_SplineDriver_Type_
118 //purpose  :
119 //=======================================================================
120 Standard_EXPORT Handle_Standard_Type& GEOMImpl_SplineDriver_Type_()
121 {
122
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);
129
130
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),
134                                                          1,
135                                                          (Standard_Address)_Ancestors,
136                                                          (Standard_Address)NULL);
137
138   return _aType;
139 }
140
141 //=======================================================================
142 //function : DownCast
143 //purpose  :
144 //=======================================================================
145 const Handle(GEOMImpl_SplineDriver) Handle(GEOMImpl_SplineDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
146 {
147   Handle(GEOMImpl_SplineDriver) _anOtherObject;
148
149   if (!AnObject.IsNull()) {
150      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_SplineDriver))) {
151        _anOtherObject = Handle(GEOMImpl_SplineDriver)((Handle(GEOMImpl_SplineDriver)&)AnObject);
152      }
153   }
154
155   return _anOtherObject ;
156 }