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>
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
52 extern Standard_Boolean BRepFeat_GettraceFEAT();
55 static void MajMap(const TopoDS_Shape&, // base
57 TopTools_DataMapOfShapeListOfShape&, // myMap
58 TopoDS_Shape&, // myFShape
59 TopoDS_Shape&); // myLShape
61 //=======================================================================
64 //=======================================================================
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)
74 Standard_Boolean trc = BRepFeat_GettraceFEAT();
75 if (trc) cout << "BRepFeat_MakePipe::Init" << endl;
85 myFuse = Standard_False;
86 myJustFeat = Standard_False;
89 myFuse = Standard_True;
90 myJustFeat = Standard_False;
93 myFuse = Standard_True;
94 myJustFeat = Standard_True;
99 myJustGluer = Standard_False;
103 //mySkface.Nullify();
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());
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;
127 //=======================================================================
129 //purpose : add faces of gluing
130 //=======================================================================
132 void BRepFeat_MakePipe::Add(const TopoDS_Edge& E,
133 const TopoDS_Face& F)
136 Standard_Boolean trc = BRepFeat_GettraceFEAT();
137 if (trc) cout << "BRepFeat_MakePipe::Add(Edge,face)" << endl;
140 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
141 if (exp.Current().IsSame(F)) {
146 Standard_ConstructionError::Raise();
149 for (exp.Init(myPbase,TopAbs_EDGE);exp.More();exp.Next()) {
150 if (exp.Current().IsSame(E)) {
155 Standard_ConstructionError::Raise();
158 if (!mySlface.IsBound(F)) {
159 TopTools_ListOfShape thelist1;
160 mySlface.Bind(F,thelist1);
162 TopTools_ListIteratorOfListOfShape itl(mySlface(F));
163 for (; itl.More();itl.Next()) {
164 if (itl.Value().IsSame(E)) {
169 mySlface(F).Append(E);
174 //=======================================================================
177 //=======================================================================
179 void BRepFeat_MakePipe::Perform()
182 Standard_Boolean trc = BRepFeat_GettraceFEAT();
183 if (trc) cout << "BRepFeat_MakePipe::Perform()" << endl;
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);
197 GeneratedShapeValid();
201 if(myGluedF.IsEmpty()) {
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);
209 UpdateDescendants(f, myShape, Standard_False);
210 //modified by NIZNHY-PKV Thu Mar 21 17:53:10 2002 t
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);
220 UpdateDescendants(c, myShape, Standard_False);
221 //modified by NIZNHY-PKV Thu Mar 21 17:53:50 2002 t
230 myFShape = thePipe.FirstShape();
231 TColgp_SequenceOfPnt spt;
232 LocOpe::SampleEdges(myFShape,spt);
233 myCurves = thePipe.Curves(spt);
234 myBCurve = thePipe.BarycCurve();
240 //=======================================================================
242 //purpose : till shape Until
243 //=======================================================================
245 void BRepFeat_MakePipe::Perform(const TopoDS_Shape& Until)
248 Standard_Boolean trc = BRepFeat_GettraceFEAT();
249 if (trc) cout << "BRepFeat_MakePipe::Perform(Until)" << endl;
251 if (Until.IsNull()) {
252 Standard_ConstructionError::Raise();
254 TopExp_Explorer exp(Until, TopAbs_FACE);
256 Standard_ConstructionError::Raise();
259 myPerfSelection = BRepFeat_SelectionU;
260 PerfSelectionValid();
266 LocOpe_Pipe thePipe(mySpine,myPbase);
267 TopoDS_Shape VraiTuyau = thePipe.Shape();
268 MajMap(myPbase,thePipe,myMap,myFShape,myLShape);
269 myGShape = VraiTuyau;
270 GeneratedShapeValid();
274 myFShape = thePipe.FirstShape();
275 TColgp_SequenceOfPnt spt;
276 LocOpe::SampleEdges(myFShape,spt);
277 myCurves = thePipe.Curves(spt);
278 myBCurve = thePipe.BarycCurve();
283 //=======================================================================
285 //purpose : between From and Until
286 //=======================================================================
288 void BRepFeat_MakePipe::Perform(const TopoDS_Shape& From,
289 const TopoDS_Shape& Until)
292 Standard_Boolean trc = BRepFeat_GettraceFEAT();
293 if (trc) cout << "BRepFeat_MakePipe::Perform(From,Until)" << endl;
295 if (From.IsNull() || Until.IsNull()) {
296 Standard_ConstructionError::Raise();
298 if (!mySkface.IsNull()) {
299 if (From.IsSame(mySkface)) {
303 else if (Until.IsSame(mySkface)) {
309 myPerfSelection = BRepFeat_SelectionFU;
310 PerfSelectionValid();
311 TopExp_Explorer exp(From, TopAbs_FACE);
313 Standard_ConstructionError::Raise();
315 exp.Init(Until, TopAbs_FACE);
317 Standard_ConstructionError::Raise();
325 LocOpe_Pipe thePipe(mySpine,myPbase);
326 TopoDS_Shape VraiTuyau = thePipe.Shape();
327 MajMap(myPbase,thePipe,myMap,myFShape,myLShape);
328 myGShape = VraiTuyau;
329 GeneratedShapeValid();
331 // mySbase, myPbase, mySlface, thePipe, myGluedF);
334 myFShape = thePipe.FirstShape();
335 TColgp_SequenceOfPnt spt;
336 LocOpe::SampleEdges(myFShape,spt);
337 myCurves = thePipe.Curves(spt);
338 myBCurve = thePipe.BarycCurve();
343 //=======================================================================
345 //purpose : curves parallel to the generating wire of the pipe
346 //=======================================================================
348 void BRepFeat_MakePipe::Curves(TColGeom_SequenceOfCurve& scur)
353 //=======================================================================
354 //function : BarycCurve
355 //purpose : pass through the center of mass
356 //=======================================================================
358 Handle(Geom_Curve) BRepFeat_MakePipe::BarycCurve()
363 //=======================================================================
365 //purpose : management of descendants
366 //=======================================================================
368 static void MajMap(const TopoDS_Shape& theB,
370 TopTools_DataMapOfShapeListOfShape& theMap, // myMap
371 TopoDS_Shape& theFShape, // myFShape
372 TopoDS_Shape& theLShape) // myLShape
374 TopExp_Explorer exp(theP.FirstShape(),TopAbs_WIRE);
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());
384 exp.Init(theP.LastShape(),TopAbs_WIRE);
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());
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());