0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / BRepFeat / BRepFeat_MakePipe.cxx
1 // Created on: 1996-09-03
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <Bnd_Box.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BRepAlgoAPI_Cut.hxx>
21 #include <BRepAlgoAPI_Fuse.hxx>
22 #include <BRepBndLib.hxx>
23 #include <BRepFeat.hxx>
24 #include <BRepFeat_MakePipe.hxx>
25 #include <Geom_Curve.hxx>
26 #include <Geom_Line.hxx>
27 #include <gp_Pnt.hxx>
28 #include <gp_Pnt2d.hxx>
29 #include <gp_Vec.hxx>
30 #include <LocOpe.hxx>
31 #include <LocOpe_Pipe.hxx>
32 #include <Standard_ConstructionError.hxx>
33 #include <TColgp_SequenceOfPnt.hxx>
34 #include <TopExp.hxx>
35 #include <TopExp_Explorer.hxx>
36 #include <TopoDS.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <TopoDS_Face.hxx>
39 #include <TopoDS_Shape.hxx>
40 #include <TopoDS_Wire.hxx>
41 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
42 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
43 #include <TopTools_ListIteratorOfListOfShape.hxx>
44 #include <TopTools_MapIteratorOfMapOfShape.hxx>
45 #include <TopTools_MapOfShape.hxx>
46
47 //modified by NIZNHY-PKV Thu Mar 21 17:54:27 2002 f
48 //#include <BRepAlgo_Fuse.hxx>
49 //#include <BRepAlgo_Cut.hxx> 
50 //modified by NIZNHY-PKV Thu Mar 21 17:54:30 2002 t
51 #ifdef OCCT_DEBUG
52 extern Standard_Boolean BRepFeat_GettraceFEAT();
53 #endif
54
55 static void MajMap(const TopoDS_Shape&, // base
56                    LocOpe_Pipe&,
57                    TopTools_DataMapOfShapeListOfShape&, // myMap
58                    TopoDS_Shape&,  // myFShape
59                    TopoDS_Shape&); // myLShape
60
61 //=======================================================================
62 //function : Init
63 //purpose  : 
64 //=======================================================================
65
66 void BRepFeat_MakePipe::Init(const TopoDS_Shape& Sbase,
67                              const TopoDS_Shape& Pbase,
68                              const TopoDS_Face& Skface,
69                              const TopoDS_Wire& Spine,
70                              const Standard_Integer Mode,
71                              const Standard_Boolean Modify)
72 {
73 #ifdef OCCT_DEBUG
74   Standard_Boolean trc = BRepFeat_GettraceFEAT();
75   if (trc) cout << "BRepFeat_MakePipe::Init" << endl;
76 #endif
77   mySbase  = Sbase;
78   BasisShapeValid();
79   mySkface = Skface;
80   SketchFaceValid();
81   myPbase  = Pbase;
82   mySlface.Clear();
83   mySpine   = Spine;
84   if(Mode == 0) {
85     myFuse   = Standard_False;
86     myJustFeat = Standard_False;
87   }
88   else if(Mode == 1) {
89     myFuse   = Standard_True;
90     myJustFeat = Standard_False;
91   }
92   else if(Mode == 2) {
93     myFuse   = Standard_True;
94     myJustFeat = Standard_True;
95   }
96   else {    
97   }
98   myModify = Modify;
99   myJustGluer = Standard_False;
100
101
102   //-------------- ifv
103   //mySkface.Nullify();
104   //-------------- ifv
105
106   myShape.Nullify();
107   myMap.Clear();
108   myFShape.Nullify();
109   myLShape.Nullify();
110   TopExp_Explorer exp;
111   for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
112     TopTools_ListOfShape thelist;
113     myMap.Bind(exp.Current(), thelist);
114     myMap(exp.Current()).Append(exp.Current());
115   }
116 #ifdef OCCT_DEBUG
117   if (trc) {
118     if (myJustFeat)  cout << " Just Feature" << endl;
119     if (myFuse)  cout << " Fuse" << endl;
120     if (!myFuse)  cout << " Cut" << endl;
121     if (!myModify) cout << " Modify = 0" << endl;
122   }
123 #endif 
124 }
125
126
127 //=======================================================================
128 //function : Add
129 //purpose  : add faces of gluing
130 //=======================================================================
131
132 void BRepFeat_MakePipe::Add(const TopoDS_Edge& E,
133                              const TopoDS_Face& F)
134 {
135 #ifdef OCCT_DEBUG
136   Standard_Boolean trc = BRepFeat_GettraceFEAT();
137   if (trc) cout << "BRepFeat_MakePipe::Add(Edge,face)" << endl;
138 #endif
139   TopExp_Explorer exp;
140   for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
141     if (exp.Current().IsSame(F)) {
142       break;
143     }
144   }
145   if (!exp.More()) {
146     Standard_ConstructionError::Raise();
147   }
148
149   for (exp.Init(myPbase,TopAbs_EDGE);exp.More();exp.Next()) {
150     if (exp.Current().IsSame(E)) {
151       break;
152     }
153   }
154   if (!exp.More()) {
155     Standard_ConstructionError::Raise();
156   }
157
158   if (!mySlface.IsBound(F)) {
159     TopTools_ListOfShape thelist1;
160     mySlface.Bind(F,thelist1);
161   }
162   TopTools_ListIteratorOfListOfShape itl(mySlface(F));
163   for (; itl.More();itl.Next()) {
164     if (itl.Value().IsSame(E)) {
165       break;
166     }
167   }
168   if (!itl.More()) {
169     mySlface(F).Append(E);
170   }
171 }
172
173
174 //=======================================================================
175 //function : Perform
176 //purpose  : 
177 //=======================================================================
178
179 void BRepFeat_MakePipe::Perform()
180 {
181 #ifdef OCCT_DEBUG
182   Standard_Boolean trc = BRepFeat_GettraceFEAT();
183   if (trc) cout << "BRepFeat_MakePipe::Perform()" << endl;
184 #endif
185   mySFrom.Nullify();
186   ShapeFromValid();
187   mySUntil.Nullify();
188   ShapeUntilValid();
189   myGluedF.Clear();
190   myPerfSelection = BRepFeat_NoSelection;
191   PerfSelectionValid();
192   TopoDS_Shape theBase = myPbase;
193   LocOpe_Pipe thePipe(mySpine,theBase);
194   TopoDS_Shape VraiPipe = thePipe.Shape();
195   MajMap(myPbase,thePipe,myMap,myFShape,myLShape);
196   myGShape = VraiPipe;
197   GeneratedShapeValid();
198
199   GluedFacesValid();
200
201   if(myGluedF.IsEmpty()) {
202     if(myFuse == 1) {
203       //modified by NIZNHY-PKV Thu Mar 21 17:53:05 2002 f
204       //BRepAlgo_Fuse f(mySbase, myGShape);
205       //myShape = f.Shape();
206       //UpdateDescendants(f.Builder(), myShape, Standard_False);
207       BRepAlgoAPI_Fuse f(mySbase, myGShape);
208       myShape = f.Shape();
209       UpdateDescendants(f, myShape, Standard_False);
210       //modified by NIZNHY-PKV Thu Mar 21 17:53:10 2002 t
211       Done();
212     }
213     else if(myFuse == 0) {
214       //modified by NIZNHY-PKV Thu Mar 21 17:53:37 2002 f
215       //BRepAlgo_Cut c(mySbase, myGShape);
216       //myShape = c.Shape();
217       //UpdateDescendants(c.Builder(), myShape, Standard_False);
218       BRepAlgoAPI_Cut c(mySbase, myGShape);
219       myShape = c.Shape();
220       UpdateDescendants(c, myShape, Standard_False);
221       //modified by NIZNHY-PKV Thu Mar 21 17:53:50 2002 t
222       Done();
223     }
224     else {
225       myShape = myGShape;
226       Done();
227     }
228   }
229   else {
230     myFShape = thePipe.FirstShape();
231     TColgp_SequenceOfPnt spt;
232     LocOpe::SampleEdges(myFShape,spt); 
233     myCurves = thePipe.Curves(spt);
234     myBCurve = thePipe.BarycCurve();
235     GlobalPerform();
236   }
237 }
238
239
240 //=======================================================================
241 //function : Perform
242 //purpose  : till shape Until
243 //=======================================================================
244
245 void BRepFeat_MakePipe::Perform(const TopoDS_Shape& Until)
246 {
247 #ifdef OCCT_DEBUG
248   Standard_Boolean trc = BRepFeat_GettraceFEAT();
249   if (trc) cout << "BRepFeat_MakePipe::Perform(Until)" << endl;
250 #endif
251   if (Until.IsNull()) {
252     Standard_ConstructionError::Raise();
253   }
254   TopExp_Explorer exp(Until, TopAbs_FACE);
255   if (!exp.More()) {
256     Standard_ConstructionError::Raise();
257   }
258   myGluedF.Clear();
259   myPerfSelection = BRepFeat_SelectionU;
260   PerfSelectionValid();
261   mySFrom.Nullify();
262   ShapeFromValid();
263   mySUntil = Until;
264   TransformShapeFU(1);
265   ShapeUntilValid();
266   LocOpe_Pipe thePipe(mySpine,myPbase);
267   TopoDS_Shape VraiTuyau = thePipe.Shape();
268   MajMap(myPbase,thePipe,myMap,myFShape,myLShape);
269   myGShape = VraiTuyau;
270   GeneratedShapeValid();
271
272   GluedFacesValid();
273
274   myFShape = thePipe.FirstShape();
275   TColgp_SequenceOfPnt spt;
276   LocOpe::SampleEdges(myFShape,spt); 
277   myCurves = thePipe.Curves(spt);
278   myBCurve = thePipe.BarycCurve();
279   GlobalPerform();
280 }
281
282
283 //=======================================================================
284 //function : Perform
285 //purpose  : between From and Until
286 //=======================================================================
287
288 void BRepFeat_MakePipe::Perform(const TopoDS_Shape& From,
289                                 const TopoDS_Shape& Until)
290 {
291 #ifdef OCCT_DEBUG
292   Standard_Boolean trc = BRepFeat_GettraceFEAT();
293   if (trc) cout << "BRepFeat_MakePipe::Perform(From,Until)" << endl;
294 #endif
295   if (From.IsNull() || Until.IsNull()) {
296     Standard_ConstructionError::Raise();
297   }
298   if (!mySkface.IsNull()) {
299     if (From.IsSame(mySkface)) {
300       Perform(Until);
301       return;
302     }
303     else if (Until.IsSame(mySkface)) {
304       Perform(From);
305       return;
306     }
307   }
308   myGluedF.Clear();
309   myPerfSelection = BRepFeat_SelectionFU;
310   PerfSelectionValid();
311   TopExp_Explorer exp(From, TopAbs_FACE);
312   if (!exp.More()) {
313     Standard_ConstructionError::Raise();
314   }
315   exp.Init(Until, TopAbs_FACE);
316   if (!exp.More()) {
317     Standard_ConstructionError::Raise();
318   }
319   mySFrom = From;
320   TransformShapeFU(0);
321   ShapeFromValid();
322   mySUntil = Until;
323   TransformShapeFU(1);
324   ShapeUntilValid();  
325   LocOpe_Pipe thePipe(mySpine,myPbase);
326   TopoDS_Shape VraiTuyau = thePipe.Shape();
327   MajMap(myPbase,thePipe,myMap,myFShape,myLShape);
328   myGShape = VraiTuyau;
329   GeneratedShapeValid();
330
331         //      mySbase, myPbase, mySlface, thePipe, myGluedF);
332   GluedFacesValid();
333
334   myFShape = thePipe.FirstShape();
335   TColgp_SequenceOfPnt spt;
336   LocOpe::SampleEdges(myFShape,spt); 
337   myCurves = thePipe.Curves(spt);
338   myBCurve = thePipe.BarycCurve();
339   GlobalPerform();
340 }
341
342
343 //=======================================================================
344 //function : Curves
345 //purpose  : curves parallel to the generating wire of the pipe
346 //=======================================================================
347
348 void BRepFeat_MakePipe::Curves(TColGeom_SequenceOfCurve& scur)
349 {
350   scur = myCurves;
351 }
352
353 //=======================================================================
354 //function : BarycCurve
355 //purpose  : pass through the center of mass
356 //=======================================================================
357
358 Handle(Geom_Curve) BRepFeat_MakePipe::BarycCurve()
359 {
360   return myBCurve;
361 }
362
363 //=======================================================================
364 //function : MajMap
365 //purpose  : management of descendants
366 //=======================================================================
367
368 static void MajMap(const TopoDS_Shape& theB,
369                    LocOpe_Pipe& theP,
370                    TopTools_DataMapOfShapeListOfShape& theMap, // myMap
371                    TopoDS_Shape& theFShape,  // myFShape
372                    TopoDS_Shape& theLShape) // myLShape
373 {
374   TopExp_Explorer exp(theP.FirstShape(),TopAbs_WIRE);
375   if (exp.More()) {
376     theFShape = exp.Current();
377     TopTools_ListOfShape thelist2;
378     theMap.Bind(theFShape, thelist2);
379     for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) {
380       theMap(theFShape).Append(exp.Current());
381     }
382   }
383   
384   exp.Init(theP.LastShape(),TopAbs_WIRE);
385   if (exp.More()) {
386     theLShape = exp.Current();
387     TopTools_ListOfShape thelist3;
388     theMap.Bind(theLShape, thelist3);
389     for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) {
390       theMap(theLShape).Append(exp.Current());
391     }
392   }
393
394   for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) {
395     if (!theMap.IsBound(exp.Current())) {
396       TopTools_ListOfShape thelist4;
397       theMap.Bind(exp.Current(), thelist4);
398       theMap(exp.Current()) = theP.Shapes(exp.Current());
399     }
400   }
401 }
402
403
404
405
406
407
408
409
410
411
412
413
414
415