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>
7 #include <BRepFeat_MakePipe.ixx>
9 #include <BRepFeat.hxx>
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
21 #include <gp_Pnt2d.hxx>
22 #include <TColgp_SequenceOfPnt.hxx>
23 #include <Geom_Curve.hxx>
24 #include <Geom_Line.hxx>
26 #include <LocOpe_Pipe.hxx>
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>
36 #include <Bnd_Box.hxx>
37 #include <TopoDS_Face.hxx>
38 #include <TopoDS_Shape.hxx>
41 #include <Standard_ConstructionError.hxx>
44 #include <BRepBndLib.hxx>
47 Standard_IMPORT Standard_Boolean BRepFeat_GettraceFEAT();
50 static void MajMap(const TopoDS_Shape&, // base
52 TopTools_DataMapOfShapeListOfShape&, // myMap
53 TopoDS_Shape&, // myFShape
54 TopoDS_Shape&); // myLShape
57 static void SetGluedFaces(const TopoDS_Face& theSkface,
58 const TopoDS_Shape& theSbase,
59 const TopoDS_Shape& thePbase,
60 const TopTools_DataMapOfShapeListOfShape&
63 TopTools_DataMapOfShapeShape&);
66 //=======================================================================
69 //=======================================================================
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)
79 Standard_Boolean trc = BRepFeat_GettraceFEAT();
80 if (trc) cout << "BRepFeat_MakePipe::Init" << endl;
90 myFuse = Standard_False;
91 myJustFeat = Standard_False;
94 myFuse = Standard_True;
95 myJustFeat = Standard_False;
98 myFuse = Standard_True;
99 myJustFeat = Standard_True;
104 myJustGluer = Standard_False;
108 //mySkface.Nullify();
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());
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;
132 //=======================================================================
134 //purpose : add faces of gluing
135 //=======================================================================
137 void BRepFeat_MakePipe::Add(const TopoDS_Edge& E,
138 const TopoDS_Face& F)
141 Standard_Boolean trc = BRepFeat_GettraceFEAT();
142 if (trc) cout << "BRepFeat_MakePipe::Add(Edge,face)" << endl;
145 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
146 if (exp.Current().IsSame(F)) {
151 Standard_ConstructionError::Raise();
154 for (exp.Init(myPbase,TopAbs_EDGE);exp.More();exp.Next()) {
155 if (exp.Current().IsSame(E)) {
160 Standard_ConstructionError::Raise();
163 if (!mySlface.IsBound(F)) {
164 TopTools_ListOfShape thelist1;
165 mySlface.Bind(F,thelist1);
167 TopTools_ListIteratorOfListOfShape itl(mySlface(F));
168 for (; itl.More();itl.Next()) {
169 if (itl.Value().IsSame(E)) {
174 mySlface(F).Append(E);
179 //=======================================================================
182 //=======================================================================
184 void BRepFeat_MakePipe::Perform()
187 Standard_Boolean trc = BRepFeat_GettraceFEAT();
188 if (trc) cout << "BRepFeat_MakePipe::Perform()" << endl;
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);
202 GeneratedShapeValid();
204 //SetGluedFaces(mySkface, mySbase, myPbase, mySlface, thePipe, myGluedF);
207 if(myGluedF.IsEmpty()) {
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);
215 UpdateDescendants(f, myShape, Standard_False);
216 //modified by NIZNHY-PKV Thu Mar 21 17:53:10 2002 t
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);
226 UpdateDescendants(c, myShape, Standard_False);
227 //modified by NIZNHY-PKV Thu Mar 21 17:53:50 2002 t
236 myFShape = thePipe.FirstShape();
237 TColgp_SequenceOfPnt spt;
238 LocOpe::SampleEdges(myFShape,spt);
239 myCurves = thePipe.Curves(spt);
240 myBCurve = thePipe.BarycCurve();
246 //=======================================================================
248 //purpose : till shape Until
249 //=======================================================================
251 void BRepFeat_MakePipe::Perform(const TopoDS_Shape& Until)
254 Standard_Boolean trc = BRepFeat_GettraceFEAT();
255 if (trc) cout << "BRepFeat_MakePipe::Perform(Until)" << endl;
257 if (Until.IsNull()) {
258 Standard_ConstructionError::Raise();
260 TopExp_Explorer exp(Until, TopAbs_FACE);
262 Standard_ConstructionError::Raise();
265 myPerfSelection = BRepFeat_SelectionU;
266 PerfSelectionValid();
272 LocOpe_Pipe thePipe(mySpine,myPbase);
273 TopoDS_Shape VraiTuyau = thePipe.Shape();
274 MajMap(myPbase,thePipe,myMap,myFShape,myLShape);
275 myGShape = VraiTuyau;
276 GeneratedShapeValid();
278 //SetGluedFaces(mySkface, mySbase, myPbase, mySlface, thePipe, myGluedF);
281 myFShape = thePipe.FirstShape();
282 TColgp_SequenceOfPnt spt;
283 LocOpe::SampleEdges(myFShape,spt);
284 myCurves = thePipe.Curves(spt);
285 myBCurve = thePipe.BarycCurve();
290 //=======================================================================
292 //purpose : between From and Until
293 //=======================================================================
295 void BRepFeat_MakePipe::Perform(const TopoDS_Shape& From,
296 const TopoDS_Shape& Until)
299 Standard_Boolean trc = BRepFeat_GettraceFEAT();
300 if (trc) cout << "BRepFeat_MakePipe::Perform(From,Until)" << endl;
302 if (From.IsNull() || Until.IsNull()) {
303 Standard_ConstructionError::Raise();
305 if (!mySkface.IsNull()) {
306 if (From.IsSame(mySkface)) {
310 else if (Until.IsSame(mySkface)) {
316 myPerfSelection = BRepFeat_SelectionFU;
317 PerfSelectionValid();
318 TopExp_Explorer exp(From, TopAbs_FACE);
320 Standard_ConstructionError::Raise();
322 exp.Init(Until, TopAbs_FACE);
324 Standard_ConstructionError::Raise();
332 LocOpe_Pipe thePipe(mySpine,myPbase);
333 TopoDS_Shape VraiTuyau = thePipe.Shape();
334 MajMap(myPbase,thePipe,myMap,myFShape,myLShape);
335 myGShape = VraiTuyau;
336 GeneratedShapeValid();
338 //SetGluedFaces(TopoDS_Face(), // on ne veut pas binder mySkface
339 // mySbase, myPbase, mySlface, thePipe, myGluedF);
342 myFShape = thePipe.FirstShape();
343 TColgp_SequenceOfPnt spt;
344 LocOpe::SampleEdges(myFShape,spt);
345 myCurves = thePipe.Curves(spt);
346 myBCurve = thePipe.BarycCurve();
351 //=======================================================================
353 //purpose : curves parallel to the generating wire of the pipe
354 //=======================================================================
356 void BRepFeat_MakePipe::Curves(TColGeom_SequenceOfCurve& scur)
361 //=======================================================================
362 //function : BarycCurve
363 //purpose : pass through the center of mass
364 //=======================================================================
366 Handle(Geom_Curve) BRepFeat_MakePipe::BarycCurve()
372 //=======================================================================
373 //function : SetGluedFaces
374 //purpose : management of faces of gluing and sliding
375 //=======================================================================
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)
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);
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);
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) {
417 Standard_Boolean trc = BRepFeat_GettraceFEAT();
418 if (trc) cout << " BRepFeat_MakeDPipe : Pb SetGluedFace" << endl;
421 theMap.Bind(gfac.First(),fac);
428 //=======================================================================
430 //purpose : management of descendants
431 //=======================================================================
433 static void MajMap(const TopoDS_Shape& theB,
435 TopTools_DataMapOfShapeListOfShape& theMap, // myMap
436 TopoDS_Shape& theFShape, // myFShape
437 TopoDS_Shape& theLShape) // myLShape
439 TopExp_Explorer exp(theP.FirstShape(),TopAbs_WIRE);
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());
449 exp.Init(theP.LastShape(),TopAbs_WIRE);
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());
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());