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