7fd59977 |
1 | // File: BRepFeat_MakePipe.cxx |
2 | // Created: Tue Sep 3 11:18:26 1996 |
3 | // Author: Jacques GOUSSARD |
4 | // <jag@mobilox.lyon.matra-dtv.fr> |
5 | |
6 | |
7 | #include <BRepFeat_MakePipe.ixx> |
8 | |
9 | #include <BRepFeat.hxx> |
10 | #include <LocOpe.hxx> |
11 | |
12 | //modified by NIZNHY-PKV Thu Mar 21 17:54:27 2002 f |
13 | //#include <BRepAlgo_Fuse.hxx> |
14 | //#include <BRepAlgo_Cut.hxx> |
15 | #include <BRepAlgoAPI_Fuse.hxx> |
16 | #include <BRepAlgoAPI_Cut.hxx> |
17 | //modified by NIZNHY-PKV Thu Mar 21 17:54:30 2002 t |
18 | |
19 | #include <gp_Vec.hxx> |
20 | #include <gp_Pnt.hxx> |
21 | #include <gp_Pnt2d.hxx> |
22 | #include <TColgp_SequenceOfPnt.hxx> |
23 | #include <Geom_Curve.hxx> |
24 | #include <Geom_Line.hxx> |
25 | |
26 | #include <LocOpe_Pipe.hxx> |
27 | |
28 | #include <BRep_Tool.hxx> |
29 | #include <TopExp_Explorer.hxx> |
30 | #include <TopTools_MapOfShape.hxx> |
31 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
32 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
33 | #include <TopTools_MapIteratorOfMapOfShape.hxx> |
34 | #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx> |
35 | |
36 | #include <Bnd_Box.hxx> |
37 | #include <TopoDS_Face.hxx> |
38 | #include <TopoDS_Shape.hxx> |
39 | #include <TopoDS.hxx> |
40 | |
41 | #include <Standard_ConstructionError.hxx> |
42 | |
43 | #include <TopExp.hxx> |
44 | #include <BRepBndLib.hxx> |
45 | |
46 | #ifdef DEB |
47 | Standard_IMPORT Standard_Boolean BRepFeat_GettraceFEAT(); |
48 | #endif |
49 | |
50 | static void MajMap(const TopoDS_Shape&, // base |
51 | LocOpe_Pipe&, |
52 | TopTools_DataMapOfShapeListOfShape&, // myMap |
53 | TopoDS_Shape&, // myFShape |
54 | TopoDS_Shape&); // myLShape |
55 | |
56 | |
57 | static void SetGluedFaces(const TopoDS_Face& theSkface, |
58 | const TopoDS_Shape& theSbase, |
59 | const TopoDS_Shape& thePbase, |
60 | const TopTools_DataMapOfShapeListOfShape& |
61 | theSlmap, |
62 | LocOpe_Pipe&, |
63 | TopTools_DataMapOfShapeShape&); |
64 | |
65 | |
66 | //======================================================================= |
67 | //function : Init |
68 | //purpose : |
69 | //======================================================================= |
70 | |
71 | void BRepFeat_MakePipe::Init(const TopoDS_Shape& Sbase, |
72 | const TopoDS_Shape& Pbase, |
73 | const TopoDS_Face& Skface, |
74 | const TopoDS_Wire& Spine, |
75 | const Standard_Integer Mode, |
76 | const Standard_Boolean Modify) |
77 | { |
78 | #ifdef DEB |
79 | Standard_Boolean trc = BRepFeat_GettraceFEAT(); |
80 | if (trc) cout << "BRepFeat_MakePipe::Init" << endl; |
81 | #endif |
82 | mySbase = Sbase; |
83 | BasisShapeValid(); |
84 | mySkface = Skface; |
85 | SketchFaceValid(); |
86 | myPbase = Pbase; |
87 | mySlface.Clear(); |
88 | mySpine = Spine; |
89 | if(Mode == 0) { |
90 | myFuse = Standard_False; |
91 | myJustFeat = Standard_False; |
92 | } |
93 | else if(Mode == 1) { |
94 | myFuse = Standard_True; |
95 | myJustFeat = Standard_False; |
96 | } |
97 | else if(Mode == 2) { |
98 | myFuse = Standard_True; |
99 | myJustFeat = Standard_True; |
100 | } |
101 | else { |
102 | } |
103 | myModify = Modify; |
104 | myJustGluer = Standard_False; |
105 | |
106 | |
107 | //-------------- ifv |
108 | //mySkface.Nullify(); |
109 | //-------------- ifv |
110 | |
111 | myShape.Nullify(); |
112 | myMap.Clear(); |
113 | myFShape.Nullify(); |
114 | myLShape.Nullify(); |
115 | TopExp_Explorer exp; |
116 | for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) { |
117 | TopTools_ListOfShape thelist; |
118 | myMap.Bind(exp.Current(), thelist); |
119 | myMap(exp.Current()).Append(exp.Current()); |
120 | } |
121 | #ifdef DEB |
122 | if (trc) { |
123 | if (myJustFeat) cout << " Just Feature" << endl; |
124 | if (myFuse) cout << " Fuse" << endl; |
125 | if (!myFuse) cout << " Cut" << endl; |
126 | if (!myModify) cout << " Modify = 0" << endl; |
127 | } |
128 | #endif |
129 | } |
130 | |
131 | |
132 | //======================================================================= |
133 | //function : Add |
0d969553 |
134 | //purpose : add faces of gluing |
7fd59977 |
135 | //======================================================================= |
136 | |
137 | void BRepFeat_MakePipe::Add(const TopoDS_Edge& E, |
138 | const TopoDS_Face& F) |
139 | { |
140 | #ifdef DEB |
141 | Standard_Boolean trc = BRepFeat_GettraceFEAT(); |
142 | if (trc) cout << "BRepFeat_MakePipe::Add(Edge,face)" << endl; |
143 | #endif |
144 | TopExp_Explorer exp; |
145 | for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) { |
146 | if (exp.Current().IsSame(F)) { |
147 | break; |
148 | } |
149 | } |
150 | if (!exp.More()) { |
151 | Standard_ConstructionError::Raise(); |
152 | } |
153 | |
154 | for (exp.Init(myPbase,TopAbs_EDGE);exp.More();exp.Next()) { |
155 | if (exp.Current().IsSame(E)) { |
156 | break; |
157 | } |
158 | } |
159 | if (!exp.More()) { |
160 | Standard_ConstructionError::Raise(); |
161 | } |
162 | |
163 | if (!mySlface.IsBound(F)) { |
164 | TopTools_ListOfShape thelist1; |
165 | mySlface.Bind(F,thelist1); |
166 | } |
167 | TopTools_ListIteratorOfListOfShape itl(mySlface(F)); |
168 | for (; itl.More();itl.Next()) { |
169 | if (itl.Value().IsSame(E)) { |
170 | break; |
171 | } |
172 | } |
173 | if (!itl.More()) { |
174 | mySlface(F).Append(E); |
175 | } |
176 | } |
177 | |
178 | |
179 | //======================================================================= |
180 | //function : Perform |
181 | //purpose : |
182 | //======================================================================= |
183 | |
184 | void BRepFeat_MakePipe::Perform() |
185 | { |
186 | #ifdef DEB |
187 | Standard_Boolean trc = BRepFeat_GettraceFEAT(); |
188 | if (trc) cout << "BRepFeat_MakePipe::Perform()" << endl; |
189 | #endif |
190 | mySFrom.Nullify(); |
191 | ShapeFromValid(); |
192 | mySUntil.Nullify(); |
193 | ShapeUntilValid(); |
194 | myGluedF.Clear(); |
195 | myPerfSelection = BRepFeat_NoSelection; |
196 | PerfSelectionValid(); |
197 | TopoDS_Shape theBase = myPbase; |
198 | LocOpe_Pipe thePipe(mySpine,theBase); |
199 | TopoDS_Shape VraiPipe = thePipe.Shape(); |
200 | MajMap(myPbase,thePipe,myMap,myFShape,myLShape); |
201 | myGShape = VraiPipe; |
202 | GeneratedShapeValid(); |
203 | |
204 | //SetGluedFaces(mySkface, mySbase, myPbase, mySlface, thePipe, myGluedF); |
205 | GluedFacesValid(); |
206 | |
207 | if(myGluedF.IsEmpty()) { |
208 | if(myFuse == 1) { |
209 | //modified by NIZNHY-PKV Thu Mar 21 17:53:05 2002 f |
210 | //BRepAlgo_Fuse f(mySbase, myGShape); |
211 | //myShape = f.Shape(); |
212 | //UpdateDescendants(f.Builder(), myShape, Standard_False); |
213 | BRepAlgoAPI_Fuse f(mySbase, myGShape); |
214 | myShape = f.Shape(); |
215 | UpdateDescendants(f, myShape, Standard_False); |
216 | //modified by NIZNHY-PKV Thu Mar 21 17:53:10 2002 t |
217 | Done(); |
218 | } |
219 | else if(myFuse == 0) { |
220 | //modified by NIZNHY-PKV Thu Mar 21 17:53:37 2002 f |
221 | //BRepAlgo_Cut c(mySbase, myGShape); |
222 | //myShape = c.Shape(); |
223 | //UpdateDescendants(c.Builder(), myShape, Standard_False); |
224 | BRepAlgoAPI_Cut c(mySbase, myGShape); |
225 | myShape = c.Shape(); |
226 | UpdateDescendants(c, myShape, Standard_False); |
227 | //modified by NIZNHY-PKV Thu Mar 21 17:53:50 2002 t |
228 | Done(); |
229 | } |
230 | else { |
231 | myShape = myGShape; |
232 | Done(); |
233 | } |
234 | } |
235 | else { |
236 | myFShape = thePipe.FirstShape(); |
237 | TColgp_SequenceOfPnt spt; |
238 | LocOpe::SampleEdges(myFShape,spt); |
239 | myCurves = thePipe.Curves(spt); |
240 | myBCurve = thePipe.BarycCurve(); |
241 | GlobalPerform(); |
242 | } |
243 | } |
244 | |
245 | |
246 | //======================================================================= |
247 | //function : Perform |
0d969553 |
248 | //purpose : till shape Until |
7fd59977 |
249 | //======================================================================= |
250 | |
251 | void BRepFeat_MakePipe::Perform(const TopoDS_Shape& Until) |
252 | { |
253 | #ifdef DEB |
254 | Standard_Boolean trc = BRepFeat_GettraceFEAT(); |
255 | if (trc) cout << "BRepFeat_MakePipe::Perform(Until)" << endl; |
256 | #endif |
257 | if (Until.IsNull()) { |
258 | Standard_ConstructionError::Raise(); |
259 | } |
260 | TopExp_Explorer exp(Until, TopAbs_FACE); |
261 | if (!exp.More()) { |
262 | Standard_ConstructionError::Raise(); |
263 | } |
264 | myGluedF.Clear(); |
265 | myPerfSelection = BRepFeat_SelectionU; |
266 | PerfSelectionValid(); |
267 | mySFrom.Nullify(); |
268 | ShapeFromValid(); |
269 | mySUntil = Until; |
270 | TransformShapeFU(1); |
271 | ShapeUntilValid(); |
272 | LocOpe_Pipe thePipe(mySpine,myPbase); |
273 | TopoDS_Shape VraiTuyau = thePipe.Shape(); |
274 | MajMap(myPbase,thePipe,myMap,myFShape,myLShape); |
275 | myGShape = VraiTuyau; |
276 | GeneratedShapeValid(); |
277 | |
278 | //SetGluedFaces(mySkface, mySbase, myPbase, mySlface, thePipe, myGluedF); |
279 | GluedFacesValid(); |
280 | |
281 | myFShape = thePipe.FirstShape(); |
282 | TColgp_SequenceOfPnt spt; |
283 | LocOpe::SampleEdges(myFShape,spt); |
284 | myCurves = thePipe.Curves(spt); |
285 | myBCurve = thePipe.BarycCurve(); |
286 | GlobalPerform(); |
287 | } |
288 | |
289 | |
290 | //======================================================================= |
291 | //function : Perform |
0d969553 |
292 | //purpose : between From and Until |
7fd59977 |
293 | //======================================================================= |
294 | |
295 | void BRepFeat_MakePipe::Perform(const TopoDS_Shape& From, |
296 | const TopoDS_Shape& Until) |
297 | { |
298 | #ifdef DEB |
299 | Standard_Boolean trc = BRepFeat_GettraceFEAT(); |
300 | if (trc) cout << "BRepFeat_MakePipe::Perform(From,Until)" << endl; |
301 | #endif |
302 | if (From.IsNull() || Until.IsNull()) { |
303 | Standard_ConstructionError::Raise(); |
304 | } |
305 | if (!mySkface.IsNull()) { |
306 | if (From.IsSame(mySkface)) { |
307 | Perform(Until); |
308 | return; |
309 | } |
310 | else if (Until.IsSame(mySkface)) { |
311 | Perform(From); |
312 | return; |
313 | } |
314 | } |
315 | myGluedF.Clear(); |
316 | myPerfSelection = BRepFeat_SelectionFU; |
317 | PerfSelectionValid(); |
318 | TopExp_Explorer exp(From, TopAbs_FACE); |
319 | if (!exp.More()) { |
320 | Standard_ConstructionError::Raise(); |
321 | } |
322 | exp.Init(Until, TopAbs_FACE); |
323 | if (!exp.More()) { |
324 | Standard_ConstructionError::Raise(); |
325 | } |
326 | mySFrom = From; |
327 | TransformShapeFU(0); |
328 | ShapeFromValid(); |
329 | mySUntil = Until; |
330 | TransformShapeFU(1); |
331 | ShapeUntilValid(); |
332 | LocOpe_Pipe thePipe(mySpine,myPbase); |
333 | TopoDS_Shape VraiTuyau = thePipe.Shape(); |
334 | MajMap(myPbase,thePipe,myMap,myFShape,myLShape); |
335 | myGShape = VraiTuyau; |
336 | GeneratedShapeValid(); |
337 | |
338 | //SetGluedFaces(TopoDS_Face(), // on ne veut pas binder mySkface |
339 | // mySbase, myPbase, mySlface, thePipe, myGluedF); |
340 | GluedFacesValid(); |
341 | |
342 | myFShape = thePipe.FirstShape(); |
343 | TColgp_SequenceOfPnt spt; |
344 | LocOpe::SampleEdges(myFShape,spt); |
345 | myCurves = thePipe.Curves(spt); |
346 | myBCurve = thePipe.BarycCurve(); |
347 | GlobalPerform(); |
348 | } |
349 | |
350 | |
351 | //======================================================================= |
352 | //function : Curves |
0d969553 |
353 | //purpose : curves parallel to the generating wire of the pipe |
7fd59977 |
354 | //======================================================================= |
355 | |
356 | void BRepFeat_MakePipe::Curves(TColGeom_SequenceOfCurve& scur) |
357 | { |
358 | scur = myCurves; |
359 | } |
360 | |
361 | //======================================================================= |
362 | //function : BarycCurve |
0d969553 |
363 | //purpose : pass through the center of mass |
7fd59977 |
364 | //======================================================================= |
365 | |
366 | Handle(Geom_Curve) BRepFeat_MakePipe::BarycCurve() |
367 | { |
368 | return myBCurve; |
369 | } |
370 | |
371 | |
372 | //======================================================================= |
373 | //function : SetGluedFaces |
0d969553 |
374 | //purpose : management of faces of gluing and sliding |
7fd59977 |
375 | //======================================================================= |
376 | |
377 | static void SetGluedFaces(const TopoDS_Face& theSkface, |
378 | const TopoDS_Shape& theSbase, |
379 | const TopoDS_Shape& thePbase, |
380 | const TopTools_DataMapOfShapeListOfShape& theSlmap, |
381 | LocOpe_Pipe& thePipe, |
382 | TopTools_DataMapOfShapeShape& theMap) |
383 | { |
384 | TopExp_Explorer exp; |
385 | if (!theSkface.IsNull() && thePbase.ShapeType() == TopAbs_FACE) { |
386 | for (exp.Init(theSbase,TopAbs_FACE); exp.More(); exp.Next()) { |
387 | if (exp.Current().IsSame(theSkface)) { |
388 | theMap.Bind(thePbase,theSkface); |
389 | break; |
390 | } |
391 | } |
392 | } |
393 | else { |
394 | TopExp_Explorer exp2; |
395 | for (exp.Init(thePbase,TopAbs_FACE);exp.More();exp.Next()) { |
396 | const TopoDS_Face& fac = TopoDS::Face(exp.Current()); |
397 | for (exp2.Init(theSbase,TopAbs_FACE);exp2.More();exp2.Next()) { |
398 | if (exp2.Current().IsSame(fac)) { |
399 | theMap.Bind(fac,fac); |
400 | break; |
401 | } |
402 | } |
403 | } |
404 | } |
405 | |
0d969553 |
406 | // Sliding |
7fd59977 |
407 | TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm(theSlmap); |
408 | if(!theSlmap.IsEmpty()) { |
409 | for (; itm.More(); itm.Next()) { |
410 | const TopoDS_Face& fac = TopoDS::Face(itm.Key()); |
411 | const TopTools_ListOfShape& ledg = itm.Value(); |
412 | TopTools_ListIteratorOfListOfShape it; |
413 | for (it.Initialize(ledg); it.More(); it.Next()) { |
414 | const TopTools_ListOfShape& gfac = thePipe.Shapes(it.Value()); |
415 | if (gfac.Extent() != 1) { |
416 | #ifdef DEB |
417 | Standard_Boolean trc = BRepFeat_GettraceFEAT(); |
418 | if (trc) cout << " BRepFeat_MakeDPipe : Pb SetGluedFace" << endl; |
419 | #endif |
420 | } |
421 | theMap.Bind(gfac.First(),fac); |
422 | } |
423 | } |
424 | } |
425 | } |
426 | |
427 | |
428 | //======================================================================= |
429 | //function : MajMap |
0d969553 |
430 | //purpose : management of descendants |
7fd59977 |
431 | //======================================================================= |
432 | |
433 | static void MajMap(const TopoDS_Shape& theB, |
434 | LocOpe_Pipe& theP, |
435 | TopTools_DataMapOfShapeListOfShape& theMap, // myMap |
436 | TopoDS_Shape& theFShape, // myFShape |
437 | TopoDS_Shape& theLShape) // myLShape |
438 | { |
439 | TopExp_Explorer exp(theP.FirstShape(),TopAbs_WIRE); |
440 | if (exp.More()) { |
441 | theFShape = exp.Current(); |
442 | TopTools_ListOfShape thelist2; |
443 | theMap.Bind(theFShape, thelist2); |
444 | for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) { |
445 | theMap(theFShape).Append(exp.Current()); |
446 | } |
447 | } |
448 | |
449 | exp.Init(theP.LastShape(),TopAbs_WIRE); |
450 | if (exp.More()) { |
451 | theLShape = exp.Current(); |
452 | TopTools_ListOfShape thelist3; |
453 | theMap.Bind(theLShape, thelist3); |
454 | for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) { |
455 | theMap(theLShape).Append(exp.Current()); |
456 | } |
457 | } |
458 | |
459 | for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) { |
460 | if (!theMap.IsBound(exp.Current())) { |
461 | TopTools_ListOfShape thelist4; |
462 | theMap.Bind(exp.Current(), thelist4); |
463 | theMap(exp.Current()) = theP.Shapes(exp.Current()); |
464 | } |
465 | } |
466 | } |
467 | |
468 | |
469 | |
470 | |
471 | |
472 | |
473 | |
474 | |
475 | |
476 | |
477 | |
478 | |
479 | |
480 | |