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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
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>
28 #include <gp_Pnt2d.hxx>
31 #include <LocOpe_Pipe.hxx>
32 #include <Standard_ConstructionError.hxx>
33 #include <TColgp_SequenceOfPnt.hxx>
35 #include <TopExp_Explorer.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>
48 extern Standard_Boolean BRepFeat_GettraceFEAT();
51 static void MajMap(const TopoDS_Shape&, // base
53 TopTools_DataMapOfShapeListOfShape&, // myMap
54 TopoDS_Shape&, // myFShape
55 TopoDS_Shape&); // myLShape
57 //=======================================================================
60 //=======================================================================
62 void BRepFeat_MakePipe::Init(const TopoDS_Shape& Sbase,
63 const TopoDS_Shape& Pbase,
64 const TopoDS_Face& Skface,
65 const TopoDS_Wire& Spine,
66 const Standard_Integer Mode,
67 const Standard_Boolean Modify)
70 Standard_Boolean trc = BRepFeat_GettraceFEAT();
71 if (trc) cout << "BRepFeat_MakePipe::Init" << endl;
81 myFuse = Standard_False;
82 myJustFeat = Standard_False;
85 myFuse = Standard_True;
86 myJustFeat = Standard_False;
89 myFuse = Standard_True;
90 myJustFeat = Standard_True;
95 myJustGluer = Standard_False;
107 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
108 TopTools_ListOfShape thelist;
109 myMap.Bind(exp.Current(), thelist);
110 myMap(exp.Current()).Append(exp.Current());
114 if (myJustFeat) cout << " Just Feature" << endl;
115 if (myFuse) cout << " Fuse" << endl;
116 if (!myFuse) cout << " Cut" << endl;
117 if (!myModify) cout << " Modify = 0" << endl;
123 //=======================================================================
125 //purpose : add faces of gluing
126 //=======================================================================
128 void BRepFeat_MakePipe::Add(const TopoDS_Edge& E,
129 const TopoDS_Face& F)
132 Standard_Boolean trc = BRepFeat_GettraceFEAT();
133 if (trc) cout << "BRepFeat_MakePipe::Add(Edge,face)" << endl;
136 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
137 if (exp.Current().IsSame(F)) {
142 throw Standard_ConstructionError();
145 for (exp.Init(myPbase,TopAbs_EDGE);exp.More();exp.Next()) {
146 if (exp.Current().IsSame(E)) {
151 throw Standard_ConstructionError();
154 if (!mySlface.IsBound(F)) {
155 TopTools_ListOfShape thelist1;
156 mySlface.Bind(F,thelist1);
158 TopTools_ListIteratorOfListOfShape itl(mySlface(F));
159 for (; itl.More();itl.Next()) {
160 if (itl.Value().IsSame(E)) {
165 mySlface(F).Append(E);
170 //=======================================================================
173 //=======================================================================
175 void BRepFeat_MakePipe::Perform()
178 Standard_Boolean trc = BRepFeat_GettraceFEAT();
179 if (trc) cout << "BRepFeat_MakePipe::Perform()" << endl;
186 myPerfSelection = BRepFeat_NoSelection;
187 PerfSelectionValid();
188 TopoDS_Shape theBase = myPbase;
189 LocOpe_Pipe thePipe(mySpine,theBase);
190 TopoDS_Shape VraiPipe = thePipe.Shape();
191 MajMap(myPbase,thePipe,myMap,myFShape,myLShape);
193 GeneratedShapeValid();
197 if(myGluedF.IsEmpty()) {
199 BRepAlgoAPI_Fuse f(mySbase, myGShape);
201 UpdateDescendants(f, myShape, Standard_False);
204 else if(myFuse == 0) {
205 BRepAlgoAPI_Cut c(mySbase, myGShape);
207 UpdateDescendants(c, myShape, Standard_False);
216 myFShape = thePipe.FirstShape();
217 TColgp_SequenceOfPnt spt;
218 LocOpe::SampleEdges(myFShape,spt);
219 myCurves = thePipe.Curves(spt);
220 myBCurve = thePipe.BarycCurve();
226 //=======================================================================
228 //purpose : till shape Until
229 //=======================================================================
231 void BRepFeat_MakePipe::Perform(const TopoDS_Shape& Until)
234 Standard_Boolean trc = BRepFeat_GettraceFEAT();
235 if (trc) cout << "BRepFeat_MakePipe::Perform(Until)" << endl;
237 if (Until.IsNull()) {
238 throw Standard_ConstructionError();
240 TopExp_Explorer exp(Until, TopAbs_FACE);
242 throw Standard_ConstructionError();
245 myPerfSelection = BRepFeat_SelectionU;
246 PerfSelectionValid();
252 LocOpe_Pipe thePipe(mySpine,myPbase);
253 TopoDS_Shape VraiTuyau = thePipe.Shape();
254 MajMap(myPbase,thePipe,myMap,myFShape,myLShape);
255 myGShape = VraiTuyau;
256 GeneratedShapeValid();
260 myFShape = thePipe.FirstShape();
261 TColgp_SequenceOfPnt spt;
262 LocOpe::SampleEdges(myFShape,spt);
263 myCurves = thePipe.Curves(spt);
264 myBCurve = thePipe.BarycCurve();
269 //=======================================================================
271 //purpose : between From and Until
272 //=======================================================================
274 void BRepFeat_MakePipe::Perform(const TopoDS_Shape& From,
275 const TopoDS_Shape& Until)
278 Standard_Boolean trc = BRepFeat_GettraceFEAT();
279 if (trc) cout << "BRepFeat_MakePipe::Perform(From,Until)" << endl;
281 if (From.IsNull() || Until.IsNull()) {
282 throw Standard_ConstructionError();
284 if (!mySkface.IsNull()) {
285 if (From.IsSame(mySkface)) {
289 else if (Until.IsSame(mySkface)) {
295 myPerfSelection = BRepFeat_SelectionFU;
296 PerfSelectionValid();
297 TopExp_Explorer exp(From, TopAbs_FACE);
299 throw Standard_ConstructionError();
301 exp.Init(Until, TopAbs_FACE);
303 throw Standard_ConstructionError();
311 LocOpe_Pipe thePipe(mySpine,myPbase);
312 TopoDS_Shape VraiTuyau = thePipe.Shape();
313 MajMap(myPbase,thePipe,myMap,myFShape,myLShape);
314 myGShape = VraiTuyau;
315 GeneratedShapeValid();
317 // mySbase, myPbase, mySlface, thePipe, myGluedF);
320 myFShape = thePipe.FirstShape();
321 TColgp_SequenceOfPnt spt;
322 LocOpe::SampleEdges(myFShape,spt);
323 myCurves = thePipe.Curves(spt);
324 myBCurve = thePipe.BarycCurve();
329 //=======================================================================
331 //purpose : curves parallel to the generating wire of the pipe
332 //=======================================================================
334 void BRepFeat_MakePipe::Curves(TColGeom_SequenceOfCurve& scur)
339 //=======================================================================
340 //function : BarycCurve
341 //purpose : pass through the center of mass
342 //=======================================================================
344 Handle(Geom_Curve) BRepFeat_MakePipe::BarycCurve()
349 //=======================================================================
351 //purpose : management of descendants
352 //=======================================================================
354 static void MajMap(const TopoDS_Shape& theB,
356 TopTools_DataMapOfShapeListOfShape& theMap, // myMap
357 TopoDS_Shape& theFShape, // myFShape
358 TopoDS_Shape& theLShape) // myLShape
360 TopExp_Explorer exp(theP.FirstShape(),TopAbs_WIRE);
362 theFShape = exp.Current();
363 TopTools_ListOfShape thelist2;
364 theMap.Bind(theFShape, thelist2);
365 for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) {
366 theMap(theFShape).Append(exp.Current());
370 exp.Init(theP.LastShape(),TopAbs_WIRE);
372 theLShape = exp.Current();
373 TopTools_ListOfShape thelist3;
374 theMap.Bind(theLShape, thelist3);
375 for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) {
376 theMap(theLShape).Append(exp.Current());
380 for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) {
381 if (!theMap.IsBound(exp.Current())) {
382 TopTools_ListOfShape thelist4;
383 theMap.Bind(exp.Current(), thelist4);
384 theMap(exp.Current()) = theP.Shapes(exp.Current());