Salome HOME
Update copyrights 2014.
[modules/geom.git] / src / GEOMImpl / GEOMImpl_PipePathDriver.cxx
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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 <Basics_OCCTVersion.hxx>
26
27 #include <GEOMImpl_PipePathDriver.hxx>
28
29 #include <GEOMImpl_IShapesOperations.hxx>
30 #include <GEOMImpl_ShapeDriver.hxx>
31 #include <GEOMImpl_IPipePath.hxx>
32 #include <GEOMImpl_Types.hxx>
33 #include <GEOM_Function.hxx>
34
35 #include <ShapeAnalysis_FreeBounds.hxx>
36 #include <ShapeAnalysis_Edge.hxx>
37 #include <ShapeFix_Face.hxx>
38 #include <ShapeFix_Shell.hxx>
39 #include <ShapeFix_Shape.hxx>
40 #include <ShapeFix_ShapeTolerance.hxx>
41
42 #include <BRep_Tool.hxx>
43 #include <BRep_Builder.hxx>
44 #include <BRepBuilderAPI_Copy.hxx>
45 #include <BRepBuilderAPI_MakeFace.hxx>
46 #include <BRepBuilderAPI_MakeWire.hxx>
47 #include <BRepBuilderAPI_Sewing.hxx>
48 #include <BRepCheck_Analyzer.hxx>
49 #include <BRepGProp.hxx>
50 #include <BRepOffsetAPI_MakePipe.hxx>
51 #include <BRepOffsetAPI_MakePipeShell.hxx>
52
53 #if OCC_VERSION_LARGE > 0x06050300
54 #include <BRepOffsetAPI_MiddlePath.hxx>
55 #endif
56
57 #include <TopAbs.hxx>
58 #include <TopExp.hxx>
59 #include <TopExp_Explorer.hxx>
60 #include <TopoDS.hxx>
61 #include <TopoDS_Wire.hxx>
62 #include <TopoDS_Edge.hxx>
63 #include <TopoDS_Shape.hxx>
64 #include <TopoDS_Solid.hxx>
65 #include <TopoDS_Shell.hxx>
66 #include <TopoDS_Face.hxx>
67 #include <TopoDS_Compound.hxx>
68 #include <TopTools_SequenceOfShape.hxx>
69 #include <TopTools_HSequenceOfShape.hxx>
70 #include <TopTools_IndexedDataMapOfShapeShape.hxx>
71 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
72 #include <TopTools_ListIteratorOfListOfShape.hxx>
73
74 #include <GProp_GProps.hxx>
75
76 #include <GeomAPI_ProjectPointOnCurve.hxx>
77 #include <GeomAPI_Interpolate.hxx>
78 #include <Geom_TrimmedCurve.hxx>
79 #include <Geom_Plane.hxx>
80 #include <Geom_RectangularTrimmedSurface.hxx>
81 #include <Geom_BezierSurface.hxx>
82 #include <Geom_Line.hxx>
83 #include <Geom_Conic.hxx>
84 #include <Geom_BSplineCurve.hxx>
85 #include <Geom_BSplineSurface.hxx>
86 #include <GeomFill_BSplineCurves.hxx>
87 #include <GeomConvert_ApproxCurve.hxx>
88 #include <GeomConvert.hxx>
89
90 #include <TColgp_SequenceOfPnt.hxx>
91 #include <TColgp_HArray1OfPnt.hxx>
92 #include <TColgp_Array2OfPnt.hxx>
93 #include <TColStd_HSequenceOfTransient.hxx>
94
95 #include <Precision.hxx>
96
97 #include <Standard_NullObject.hxx>
98 #include <Standard_TypeMismatch.hxx>
99 #include <Standard_ConstructionError.hxx>
100
101 #include "utilities.h"
102
103 //=======================================================================
104 //function : GetID
105 //purpose  :
106 //=======================================================================
107 const Standard_GUID& GEOMImpl_PipePathDriver::GetID()
108 {
109   static Standard_GUID aPipePathDriver ("FF1BBB19-5D14-4df2-980B-3A668264EA17");
110   return aPipePathDriver;
111 }
112
113 //=======================================================================
114 //function : GEOMImpl_PipePathDriver
115 //purpose  :
116 //=======================================================================
117 GEOMImpl_PipePathDriver::GEOMImpl_PipePathDriver()
118 {
119 }
120
121 //=======================================================================
122 //function : Execute
123 //purpose  :
124 //=======================================================================
125 Standard_Integer GEOMImpl_PipePathDriver::Execute (TFunction_Logbook& log) const
126 {
127   if (Label().IsNull()) return 0;
128   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
129   Standard_Integer aType = aFunction->GetType();
130
131   TopoDS_Shape aRes;
132
133   // RestorePath
134   if (aType == PIPE_PATH_TWO_BASES) {
135     GEOMImpl_IPipePath aPI (aFunction);
136
137     Handle(GEOM_Function) aRefShape = aPI.GetShape();
138     Handle(GEOM_Function) aRefBase1 = aPI.GetBase1();
139     Handle(GEOM_Function) aRefBase2 = aPI.GetBase2();
140
141     TopoDS_Shape aShape = aRefShape->GetValue();
142     TopoDS_Shape aBase1 = aRefBase1->GetValue();
143     TopoDS_Shape aBase2 = aRefBase2->GetValue();
144
145     if (aShape.IsNull() || aBase1.IsNull() || aBase2.IsNull())
146       Standard_NullObject::Raise("RestorePath aborted : null argument");
147
148 #if OCC_VERSION_LARGE > 0x06050300
149     BRepOffsetAPI_MiddlePath aMPB (aShape, aBase1, aBase2);
150     aMPB.Build();
151     if (aMPB.IsDone()) {
152       aRes = aMPB.Shape();
153     }
154 #else
155     Standard_NullObject::Raise("RestorePath is not implemented in used OCCT version");
156 #endif
157   }
158   else if (aType == PIPE_PATH_TWO_SEQS) {
159     GEOMImpl_IPipePath aPI (aFunction);
160
161     Handle(GEOM_Function) aRefShape = aPI.GetShape();
162     TopoDS_Shape aShape = aRefShape->GetValue();
163
164     Handle(TColStd_HSequenceOfTransient) aBaseSeq1 = aPI.GetBaseSeq1();
165     Handle(TColStd_HSequenceOfTransient) aBaseSeq2 = aPI.GetBaseSeq2();
166
167     TopoDS_Shape aBase1;
168     TopoDS_Shape aBase2;
169
170     if (aBaseSeq1->Length() == 1 && aBaseSeq2->Length() == 1) {
171       Handle(GEOM_Function) aRefShape1 = Handle(GEOM_Function)::DownCast(aBaseSeq1->Value(1));
172       Handle(GEOM_Function) aRefShape2 = Handle(GEOM_Function)::DownCast(aBaseSeq2->Value(1));
173       aBase1 = aRefShape1->GetValue();
174       aBase2 = aRefShape2->GetValue();
175     }
176     else {
177       aBase1 = GEOMImpl_ShapeDriver::MakeWireFromEdges(aBaseSeq1, Precision::Confusion());
178       aBase2 = GEOMImpl_ShapeDriver::MakeWireFromEdges(aBaseSeq2, Precision::Confusion());
179     }
180
181     if (aShape.IsNull() || aBase1.IsNull() || aBase2.IsNull())
182       Standard_NullObject::Raise("RestorePath aborted : null argument");
183
184 #if OCC_VERSION_LARGE > 0x06050300
185     BRepOffsetAPI_MiddlePath aMPB (aShape, aBase1, aBase2);
186     aMPB.Build();
187     if (aMPB.IsDone()) {
188       aRes = aMPB.Shape();
189     }
190 #else
191     Standard_NullObject::Raise("RestorePath is not implemented in used OCCT version");
192 #endif
193   }
194   else {
195   }
196
197   if (aRes.IsNull()) return 0;
198
199   aFunction->SetValue(aRes);
200   log.SetTouched(Label());
201
202   return 1;
203 }
204
205 //================================================================================
206 /*!
207  * \brief Returns a name of creation operation and names and values of creation parameters
208  */
209 //================================================================================
210
211 bool GEOMImpl_PipePathDriver::
212 GetCreationInformation(std::string&             theOperationName,
213                        std::vector<GEOM_Param>& theParams)
214 {
215   if (Label().IsNull()) return 0;
216   Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
217
218   GEOMImpl_IPipePath aCI( function );
219   Standard_Integer aType = function->GetType();
220
221   theOperationName = "PIPE_PATH";
222
223   switch ( aType ) {
224   case PIPE_PATH_TWO_BASES:
225     AddParam( theParams, "Pipe-like object", aCI.GetShape() );
226     AddParam( theParams, "First base", aCI.GetBase1() );
227     AddParam( theParams, "Second base", aCI.GetBase2() );
228     break;
229   case PIPE_PATH_TWO_SEQS:
230     AddParam( theParams, "Pipe-like object", aCI.GetShape() );
231     AddParam( theParams, "First bases", aCI.GetBaseSeq1() );
232     AddParam( theParams, "Second bases", aCI.GetBaseSeq2() );
233     break;
234   default:
235     return false;
236   }
237   
238   return true;
239 }
240
241 IMPLEMENT_STANDARD_HANDLE (GEOMImpl_PipePathDriver,GEOM_BaseDriver);
242 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_PipePathDriver,GEOM_BaseDriver);