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