]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_PolylineDriver.cxx
Salome HOME
Update copyright notes (for 2010)
[modules/geom.git] / src / GEOMImpl / GEOMImpl_PolylineDriver.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include <Standard_Stream.hxx>
24
25 #include <GEOMImpl_PolylineDriver.hxx>
26 #include <GEOMImpl_IPolyline.hxx>
27 #include <GEOMImpl_Types.hxx>
28 #include <GEOM_Function.hxx>
29
30 #include <BRepBuilderAPI_MakePolygon.hxx>
31 #include <BRep_Tool.hxx>
32 #include <TopoDS.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopoDS_Vertex.hxx>
35 #include <TopoDS_Wire.hxx>
36 #include <TopAbs.hxx>
37 #include <TopExp.hxx>
38
39 #include <Precision.hxx>
40 #include <gp_Pnt.hxx>
41
42 //=======================================================================
43 //function : GetID
44 //purpose  :
45 //======================================================================= 
46 const Standard_GUID& GEOMImpl_PolylineDriver::GetID()
47 {
48   static Standard_GUID aPolylineDriver("FF1BBB31-5D14-4df2-980B-3A668264EA16");
49   return aPolylineDriver; 
50 }
51
52
53 //=======================================================================
54 //function : GEOMImpl_PolylineDriver
55 //purpose  : 
56 //=======================================================================
57 GEOMImpl_PolylineDriver::GEOMImpl_PolylineDriver() 
58 {
59 }
60
61 //=======================================================================
62 //function : Execute
63 //purpose  :
64 //======================================================================= 
65 Standard_Integer GEOMImpl_PolylineDriver::Execute(TFunction_Logbook& log) const
66 {
67   if (Label().IsNull()) return 0;    
68   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
69
70   GEOMImpl_IPolyline aCI (aFunction);
71   Standard_Integer aType = aFunction->GetType();
72
73   TopoDS_Shape aShape;
74
75   if (aType == POLYLINE_POINTS) {
76     int aLen = aCI.GetLength();
77     int ind = 1;
78     BRepBuilderAPI_MakePolygon aMakePoly;
79     for (; ind <= aLen; ind++)
80     {
81       Handle(GEOM_Function) aRefPoint = aCI.GetPoint(ind);
82       TopoDS_Shape aShapePnt = aRefPoint->GetValue();
83       if (aShapePnt.ShapeType() == TopAbs_VERTEX) {
84         aMakePoly.Add(TopoDS::Vertex(aShapePnt));
85 //        if (!aMakePoly.Added()) return 0;
86       }
87     }
88     // Compare first and last point coordinates and close polyline if it's the same.
89     if ( aLen > 2 ) {
90       Handle(GEOM_Function) aFPoint = aCI.GetPoint(1);
91       TopoDS_Shape aFirstPnt = aFPoint->GetValue();
92       TopoDS_Vertex aV1 = TopoDS::Vertex(aFirstPnt);
93
94       Handle(GEOM_Function) aLPoint = aCI.GetPoint(aLen);
95       TopoDS_Shape aLastPnt = aLPoint->GetValue();
96       TopoDS_Vertex aV2 = TopoDS::Vertex(aLastPnt);
97
98       if ( !aV1.IsNull() && !aV2.IsNull() && aV1.IsSame(aV2) )
99         aMakePoly.Close();
100     }
101
102     if (aMakePoly.IsDone()) {
103       aShape = aMakePoly.Wire();
104     }
105   }
106   else {
107   }
108
109   if (aShape.IsNull()) return 0;
110
111   aFunction->SetValue(aShape);
112
113   log.SetTouched(Label()); 
114
115   return 1;    
116 }
117
118
119 //=======================================================================
120 //function :  GEOMImpl_PolylineDriver_Type_
121 //purpose  :
122 //======================================================================= 
123 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PolylineDriver_Type_()
124 {
125
126   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
127   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
128   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
129   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
130   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
131   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
132  
133
134   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
135   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PolylineDriver",
136                                                          sizeof(GEOMImpl_PolylineDriver),
137                                                          1,
138                                                          (Standard_Address)_Ancestors,
139                                                          (Standard_Address)NULL);
140
141   return _aType;
142 }
143
144 //=======================================================================
145 //function : DownCast
146 //purpose  :
147 //======================================================================= 
148 const Handle(GEOMImpl_PolylineDriver) Handle(GEOMImpl_PolylineDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
149 {
150   Handle(GEOMImpl_PolylineDriver) _anOtherObject;
151
152   if (!AnObject.IsNull()) {
153      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PolylineDriver))) {
154        _anOtherObject = Handle(GEOMImpl_PolylineDriver)((Handle(GEOMImpl_PolylineDriver)&)AnObject);
155      }
156   }
157
158   return _anOtherObject ;
159 }