1 // Created on: 1996-09-03
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <BRepFeat_MakePipe.ixx>
25 #include <BRepFeat.hxx>
28 //modified by NIZNHY-PKV Thu Mar 21 17:54:27 2002 f
29 //#include <BRepAlgo_Fuse.hxx>
30 //#include <BRepAlgo_Cut.hxx>
31 #include <BRepAlgoAPI_Fuse.hxx>
32 #include <BRepAlgoAPI_Cut.hxx>
33 //modified by NIZNHY-PKV Thu Mar 21 17:54:30 2002 t
37 #include <gp_Pnt2d.hxx>
38 #include <TColgp_SequenceOfPnt.hxx>
39 #include <Geom_Curve.hxx>
40 #include <Geom_Line.hxx>
42 #include <LocOpe_Pipe.hxx>
44 #include <BRep_Tool.hxx>
45 #include <TopExp_Explorer.hxx>
46 #include <TopTools_MapOfShape.hxx>
47 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
48 #include <TopTools_ListIteratorOfListOfShape.hxx>
49 #include <TopTools_MapIteratorOfMapOfShape.hxx>
50 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
52 #include <Bnd_Box.hxx>
53 #include <TopoDS_Face.hxx>
54 #include <TopoDS_Shape.hxx>
57 #include <Standard_ConstructionError.hxx>
60 #include <BRepBndLib.hxx>
63 Standard_IMPORT Standard_Boolean BRepFeat_GettraceFEAT();
66 static void MajMap(const TopoDS_Shape&, // base
68 TopTools_DataMapOfShapeListOfShape&, // myMap
69 TopoDS_Shape&, // myFShape
70 TopoDS_Shape&); // myLShape
73 static void SetGluedFaces(const TopoDS_Face& theSkface,
74 const TopoDS_Shape& theSbase,
75 const TopoDS_Shape& thePbase,
76 const TopTools_DataMapOfShapeListOfShape&
79 TopTools_DataMapOfShapeShape&);
82 //=======================================================================
85 //=======================================================================
87 void BRepFeat_MakePipe::Init(const TopoDS_Shape& Sbase,
88 const TopoDS_Shape& Pbase,
89 const TopoDS_Face& Skface,
90 const TopoDS_Wire& Spine,
91 const Standard_Integer Mode,
92 const Standard_Boolean Modify)
95 Standard_Boolean trc = BRepFeat_GettraceFEAT();
96 if (trc) cout << "BRepFeat_MakePipe::Init" << endl;
106 myFuse = Standard_False;
107 myJustFeat = Standard_False;
110 myFuse = Standard_True;
111 myJustFeat = Standard_False;
114 myFuse = Standard_True;
115 myJustFeat = Standard_True;
120 myJustGluer = Standard_False;
124 //mySkface.Nullify();
132 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
133 TopTools_ListOfShape thelist;
134 myMap.Bind(exp.Current(), thelist);
135 myMap(exp.Current()).Append(exp.Current());
139 if (myJustFeat) cout << " Just Feature" << endl;
140 if (myFuse) cout << " Fuse" << endl;
141 if (!myFuse) cout << " Cut" << endl;
142 if (!myModify) cout << " Modify = 0" << endl;
148 //=======================================================================
150 //purpose : add faces of gluing
151 //=======================================================================
153 void BRepFeat_MakePipe::Add(const TopoDS_Edge& E,
154 const TopoDS_Face& F)
157 Standard_Boolean trc = BRepFeat_GettraceFEAT();
158 if (trc) cout << "BRepFeat_MakePipe::Add(Edge,face)" << endl;
161 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
162 if (exp.Current().IsSame(F)) {
167 Standard_ConstructionError::Raise();
170 for (exp.Init(myPbase,TopAbs_EDGE);exp.More();exp.Next()) {
171 if (exp.Current().IsSame(E)) {
176 Standard_ConstructionError::Raise();
179 if (!mySlface.IsBound(F)) {
180 TopTools_ListOfShape thelist1;
181 mySlface.Bind(F,thelist1);
183 TopTools_ListIteratorOfListOfShape itl(mySlface(F));
184 for (; itl.More();itl.Next()) {
185 if (itl.Value().IsSame(E)) {
190 mySlface(F).Append(E);
195 //=======================================================================
198 //=======================================================================
200 void BRepFeat_MakePipe::Perform()
203 Standard_Boolean trc = BRepFeat_GettraceFEAT();
204 if (trc) cout << "BRepFeat_MakePipe::Perform()" << endl;
211 myPerfSelection = BRepFeat_NoSelection;
212 PerfSelectionValid();
213 TopoDS_Shape theBase = myPbase;
214 LocOpe_Pipe thePipe(mySpine,theBase);
215 TopoDS_Shape VraiPipe = thePipe.Shape();
216 MajMap(myPbase,thePipe,myMap,myFShape,myLShape);
218 GeneratedShapeValid();
220 //SetGluedFaces(mySkface, mySbase, myPbase, mySlface, thePipe, myGluedF);
223 if(myGluedF.IsEmpty()) {
225 //modified by NIZNHY-PKV Thu Mar 21 17:53:05 2002 f
226 //BRepAlgo_Fuse f(mySbase, myGShape);
227 //myShape = f.Shape();
228 //UpdateDescendants(f.Builder(), myShape, Standard_False);
229 BRepAlgoAPI_Fuse f(mySbase, myGShape);
231 UpdateDescendants(f, myShape, Standard_False);
232 //modified by NIZNHY-PKV Thu Mar 21 17:53:10 2002 t
235 else if(myFuse == 0) {
236 //modified by NIZNHY-PKV Thu Mar 21 17:53:37 2002 f
237 //BRepAlgo_Cut c(mySbase, myGShape);
238 //myShape = c.Shape();
239 //UpdateDescendants(c.Builder(), myShape, Standard_False);
240 BRepAlgoAPI_Cut c(mySbase, myGShape);
242 UpdateDescendants(c, myShape, Standard_False);
243 //modified by NIZNHY-PKV Thu Mar 21 17:53:50 2002 t
252 myFShape = thePipe.FirstShape();
253 TColgp_SequenceOfPnt spt;
254 LocOpe::SampleEdges(myFShape,spt);
255 myCurves = thePipe.Curves(spt);
256 myBCurve = thePipe.BarycCurve();
262 //=======================================================================
264 //purpose : till shape Until
265 //=======================================================================
267 void BRepFeat_MakePipe::Perform(const TopoDS_Shape& Until)
270 Standard_Boolean trc = BRepFeat_GettraceFEAT();
271 if (trc) cout << "BRepFeat_MakePipe::Perform(Until)" << endl;
273 if (Until.IsNull()) {
274 Standard_ConstructionError::Raise();
276 TopExp_Explorer exp(Until, TopAbs_FACE);
278 Standard_ConstructionError::Raise();
281 myPerfSelection = BRepFeat_SelectionU;
282 PerfSelectionValid();
288 LocOpe_Pipe thePipe(mySpine,myPbase);
289 TopoDS_Shape VraiTuyau = thePipe.Shape();
290 MajMap(myPbase,thePipe,myMap,myFShape,myLShape);
291 myGShape = VraiTuyau;
292 GeneratedShapeValid();
294 //SetGluedFaces(mySkface, mySbase, myPbase, mySlface, thePipe, myGluedF);
297 myFShape = thePipe.FirstShape();
298 TColgp_SequenceOfPnt spt;
299 LocOpe::SampleEdges(myFShape,spt);
300 myCurves = thePipe.Curves(spt);
301 myBCurve = thePipe.BarycCurve();
306 //=======================================================================
308 //purpose : between From and Until
309 //=======================================================================
311 void BRepFeat_MakePipe::Perform(const TopoDS_Shape& From,
312 const TopoDS_Shape& Until)
315 Standard_Boolean trc = BRepFeat_GettraceFEAT();
316 if (trc) cout << "BRepFeat_MakePipe::Perform(From,Until)" << endl;
318 if (From.IsNull() || Until.IsNull()) {
319 Standard_ConstructionError::Raise();
321 if (!mySkface.IsNull()) {
322 if (From.IsSame(mySkface)) {
326 else if (Until.IsSame(mySkface)) {
332 myPerfSelection = BRepFeat_SelectionFU;
333 PerfSelectionValid();
334 TopExp_Explorer exp(From, TopAbs_FACE);
336 Standard_ConstructionError::Raise();
338 exp.Init(Until, TopAbs_FACE);
340 Standard_ConstructionError::Raise();
348 LocOpe_Pipe thePipe(mySpine,myPbase);
349 TopoDS_Shape VraiTuyau = thePipe.Shape();
350 MajMap(myPbase,thePipe,myMap,myFShape,myLShape);
351 myGShape = VraiTuyau;
352 GeneratedShapeValid();
354 //SetGluedFaces(TopoDS_Face(), // on ne veut pas binder mySkface
355 // mySbase, myPbase, mySlface, thePipe, myGluedF);
358 myFShape = thePipe.FirstShape();
359 TColgp_SequenceOfPnt spt;
360 LocOpe::SampleEdges(myFShape,spt);
361 myCurves = thePipe.Curves(spt);
362 myBCurve = thePipe.BarycCurve();
367 //=======================================================================
369 //purpose : curves parallel to the generating wire of the pipe
370 //=======================================================================
372 void BRepFeat_MakePipe::Curves(TColGeom_SequenceOfCurve& scur)
377 //=======================================================================
378 //function : BarycCurve
379 //purpose : pass through the center of mass
380 //=======================================================================
382 Handle(Geom_Curve) BRepFeat_MakePipe::BarycCurve()
388 //=======================================================================
389 //function : SetGluedFaces
390 //purpose : management of faces of gluing and sliding
391 //=======================================================================
393 static void SetGluedFaces(const TopoDS_Face& theSkface,
394 const TopoDS_Shape& theSbase,
395 const TopoDS_Shape& thePbase,
396 const TopTools_DataMapOfShapeListOfShape& theSlmap,
397 LocOpe_Pipe& thePipe,
398 TopTools_DataMapOfShapeShape& theMap)
401 if (!theSkface.IsNull() && thePbase.ShapeType() == TopAbs_FACE) {
402 for (exp.Init(theSbase,TopAbs_FACE); exp.More(); exp.Next()) {
403 if (exp.Current().IsSame(theSkface)) {
404 theMap.Bind(thePbase,theSkface);
410 TopExp_Explorer exp2;
411 for (exp.Init(thePbase,TopAbs_FACE);exp.More();exp.Next()) {
412 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
413 for (exp2.Init(theSbase,TopAbs_FACE);exp2.More();exp2.Next()) {
414 if (exp2.Current().IsSame(fac)) {
415 theMap.Bind(fac,fac);
423 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm(theSlmap);
424 if(!theSlmap.IsEmpty()) {
425 for (; itm.More(); itm.Next()) {
426 const TopoDS_Face& fac = TopoDS::Face(itm.Key());
427 const TopTools_ListOfShape& ledg = itm.Value();
428 TopTools_ListIteratorOfListOfShape it;
429 for (it.Initialize(ledg); it.More(); it.Next()) {
430 const TopTools_ListOfShape& gfac = thePipe.Shapes(it.Value());
431 if (gfac.Extent() != 1) {
433 Standard_Boolean trc = BRepFeat_GettraceFEAT();
434 if (trc) cout << " BRepFeat_MakeDPipe : Pb SetGluedFace" << endl;
437 theMap.Bind(gfac.First(),fac);
444 //=======================================================================
446 //purpose : management of descendants
447 //=======================================================================
449 static void MajMap(const TopoDS_Shape& theB,
451 TopTools_DataMapOfShapeListOfShape& theMap, // myMap
452 TopoDS_Shape& theFShape, // myFShape
453 TopoDS_Shape& theLShape) // myLShape
455 TopExp_Explorer exp(theP.FirstShape(),TopAbs_WIRE);
457 theFShape = exp.Current();
458 TopTools_ListOfShape thelist2;
459 theMap.Bind(theFShape, thelist2);
460 for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) {
461 theMap(theFShape).Append(exp.Current());
465 exp.Init(theP.LastShape(),TopAbs_WIRE);
467 theLShape = exp.Current();
468 TopTools_ListOfShape thelist3;
469 theMap.Bind(theLShape, thelist3);
470 for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) {
471 theMap(theLShape).Append(exp.Current());
475 for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) {
476 if (!theMap.IsBound(exp.Current())) {
477 TopTools_ListOfShape thelist4;
478 theMap.Bind(exp.Current(), thelist4);
479 theMap(exp.Current()) = theP.Shapes(exp.Current());