Salome HOME
Update for gcc4.1
[modules/geom.git] / src / GEOMImpl / GEOMImpl_PolylineDriver.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
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.
8 // 
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.
13 //
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
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20
21 #include <Standard_Stream.hxx>
22
23 #include <GEOMImpl_PolylineDriver.hxx>
24 #include <GEOMImpl_IPolyline.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
27
28 #include <BRepBuilderAPI_MakePolygon.hxx>
29 #include <BRep_Tool.hxx>
30 #include <TopoDS.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Vertex.hxx>
33 #include <TopoDS_Wire.hxx>
34 #include <TopAbs.hxx>
35 #include <TopExp.hxx>
36
37 #include <Precision.hxx>
38 #include <gp_Pnt.hxx>
39
40 //=======================================================================
41 //function : GetID
42 //purpose  :
43 //======================================================================= 
44 const Standard_GUID& GEOMImpl_PolylineDriver::GetID()
45 {
46   static Standard_GUID aPolylineDriver("FF1BBB31-5D14-4df2-980B-3A668264EA16");
47   return aPolylineDriver; 
48 }
49
50
51 //=======================================================================
52 //function : GEOMImpl_PolylineDriver
53 //purpose  : 
54 //=======================================================================
55 GEOMImpl_PolylineDriver::GEOMImpl_PolylineDriver() 
56 {
57 }
58
59 //=======================================================================
60 //function : Execute
61 //purpose  :
62 //======================================================================= 
63 Standard_Integer GEOMImpl_PolylineDriver::Execute(TFunction_Logbook& log) const
64 {
65   if (Label().IsNull()) return 0;    
66   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
67
68   GEOMImpl_IPolyline aCI (aFunction);
69   Standard_Integer aType = aFunction->GetType();
70
71   TopoDS_Shape aShape;
72
73   if (aType == POLYLINE_POINTS) {
74     int aLen = aCI.GetLength();
75     int ind = 1;
76     BRepBuilderAPI_MakePolygon aMakePoly;
77     for (; ind <= aLen; ind++)
78     {
79       Handle(GEOM_Function) aRefPoint = aCI.GetPoint(ind);
80       TopoDS_Shape aShapePnt = aRefPoint->GetValue();
81       if (aShapePnt.ShapeType() == TopAbs_VERTEX) {
82         aMakePoly.Add(TopoDS::Vertex(aShapePnt));
83 //        if (!aMakePoly.Added()) return 0;
84       }
85     }
86     if (false) aMakePoly.Close();
87     if (aMakePoly.IsDone()) {
88       aShape = aMakePoly.Wire();
89     }
90   }
91   else {
92   }
93
94   if (aShape.IsNull()) return 0;
95
96   aFunction->SetValue(aShape);
97
98   log.SetTouched(Label()); 
99
100   return 1;    
101 }
102
103
104 //=======================================================================
105 //function :  GEOMImpl_PolylineDriver_Type_
106 //purpose  :
107 //======================================================================= 
108 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PolylineDriver_Type_()
109 {
110
111   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
112   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
113   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
114   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
115   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
116   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
117  
118
119   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
120   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PolylineDriver",
121                                                          sizeof(GEOMImpl_PolylineDriver),
122                                                          1,
123                                                          (Standard_Address)_Ancestors,
124                                                          (Standard_Address)NULL);
125
126   return _aType;
127 }
128
129 //=======================================================================
130 //function : DownCast
131 //purpose  :
132 //======================================================================= 
133 const Handle(GEOMImpl_PolylineDriver) Handle(GEOMImpl_PolylineDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
134 {
135   Handle(GEOMImpl_PolylineDriver) _anOtherObject;
136
137   if (!AnObject.IsNull()) {
138      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PolylineDriver))) {
139        _anOtherObject = Handle(GEOMImpl_PolylineDriver)((Handle(GEOMImpl_PolylineDriver)&)AnObject);
140      }
141   }
142
143   return _anOtherObject ;
144 }