]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_PipeDriver.cxx
Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/geom.git] / src / GEOMImpl / GEOMImpl_PipeDriver.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/
19 //
20
21 #include <Standard_Stream.hxx>
22
23 #include <GEOMImpl_PipeDriver.hxx>
24 #include <GEOMImpl_IPipe.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
27
28 #include <BRep_Tool.hxx>
29 #include <BRepCheck_Analyzer.hxx>
30 #include <BRepOffsetAPI_MakePipe.hxx>
31 #include <BRepBuilderAPI_MakeWire.hxx>
32
33 #include <TopAbs.hxx>
34 #include <TopoDS.hxx>
35 #include <TopoDS_Wire.hxx>
36 #include <TopoDS_Edge.hxx>
37 #include <TopoDS_Shape.hxx>
38
39 #include <Standard_NullObject.hxx>
40 #include <Standard_TypeMismatch.hxx>
41 #include <Standard_ConstructionError.hxx>
42
43 //=======================================================================
44 //function : GetID
45 //purpose  :
46 //=======================================================================
47 const Standard_GUID& GEOMImpl_PipeDriver::GetID()
48 {
49   static Standard_GUID aPipeDriver("FF1BBB19-5D14-4df2-980B-3A668264EA16");
50   return aPipeDriver;
51 }
52
53
54 //=======================================================================
55 //function : GEOMImpl_PipeDriver
56 //purpose  :
57 //=======================================================================
58 GEOMImpl_PipeDriver::GEOMImpl_PipeDriver()
59 {
60 }
61
62 //=======================================================================
63 //function : Execute
64 //purpose  :
65 //=======================================================================
66 Standard_Integer GEOMImpl_PipeDriver::Execute(TFunction_Logbook& log) const
67 {
68   if (Label().IsNull()) return 0;
69   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
70
71   GEOMImpl_IPipe aCI (aFunction);
72   Standard_Integer aType = aFunction->GetType();
73
74   TopoDS_Shape aShape;
75
76   if (aType == PIPE_BASE_PATH) {
77     Handle(GEOM_Function) aRefBase = aCI.GetBase();
78     Handle(GEOM_Function) aRefPath = aCI.GetPath();
79     TopoDS_Shape aShapeBase = aRefBase->GetValue();
80     TopoDS_Shape aShapePath = aRefPath->GetValue();
81     if (aShapeBase.IsNull() || aShapePath.IsNull()) {
82       Standard_NullObject::Raise("MakePipe aborted : null shape argument");
83     }
84
85     // Get path contour
86     TopoDS_Wire aWire;
87     if (aShapePath.ShapeType() == TopAbs_WIRE) {
88       aWire = TopoDS::Wire(aShapePath);
89     } else {
90       if (aShapePath.ShapeType() == TopAbs_EDGE) {
91         TopoDS_Edge anEdge = TopoDS::Edge(aShapePath);
92         aWire = BRepBuilderAPI_MakeWire(anEdge);
93       } else {
94         Standard_TypeMismatch::Raise("MakePipe aborted : path shape is neither a wire nor an edge");
95       }
96     }
97
98     // Make pipe
99     aShape = BRepOffsetAPI_MakePipe(aWire, aShapeBase);
100   }
101   else {
102   }
103
104   if (aShape.IsNull()) return 0;
105
106   BRepCheck_Analyzer ana (aShape, Standard_False);
107   if (!ana.IsValid()) {
108     Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
109   }
110
111   aFunction->SetValue(aShape);
112
113   log.SetTouched(Label());
114
115   return 1;
116 }
117
118
119 //=======================================================================
120 //function :  GEOMImpl_PipeDriver_Type_
121 //purpose  :
122 //=======================================================================
123 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PipeDriver_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_PipeDriver",
136                                                          sizeof(GEOMImpl_PipeDriver),
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_PipeDriver) Handle(GEOMImpl_PipeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
149 {
150   Handle(GEOMImpl_PipeDriver) _anOtherObject;
151
152   if (!AnObject.IsNull()) {
153      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PipeDriver))) {
154        _anOtherObject = Handle(GEOMImpl_PipeDriver)((Handle(GEOMImpl_PipeDriver)&)AnObject);
155      }
156   }
157
158   return _anOtherObject ;
159 }