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