0024624: Lost word in license statement in source files
[occt.git] / src / BRepFeat / BRepFeat_MakePipe.cxx
CommitLineData
b311480e 1// Created on: 1996-09-03
2// Created by: Jacques GOUSSARD
3// Copyright (c) 1996-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <BRepFeat_MakePipe.ixx>
18
19#include <BRepFeat.hxx>
20#include <LocOpe.hxx>
21
22//modified by NIZNHY-PKV Thu Mar 21 17:54:27 2002 f
23//#include <BRepAlgo_Fuse.hxx>
24//#include <BRepAlgo_Cut.hxx>
25#include <BRepAlgoAPI_Fuse.hxx>
26#include <BRepAlgoAPI_Cut.hxx>
27//modified by NIZNHY-PKV Thu Mar 21 17:54:30 2002 t
28
29#include <gp_Vec.hxx>
30#include <gp_Pnt.hxx>
31#include <gp_Pnt2d.hxx>
32#include <TColgp_SequenceOfPnt.hxx>
33#include <Geom_Curve.hxx>
34#include <Geom_Line.hxx>
35
36#include <LocOpe_Pipe.hxx>
37
38#include <BRep_Tool.hxx>
39#include <TopExp_Explorer.hxx>
40#include <TopTools_MapOfShape.hxx>
41#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
42#include <TopTools_ListIteratorOfListOfShape.hxx>
43#include <TopTools_MapIteratorOfMapOfShape.hxx>
44#include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
45
46#include <Bnd_Box.hxx>
47#include <TopoDS_Face.hxx>
48#include <TopoDS_Shape.hxx>
49#include <TopoDS.hxx>
50
51#include <Standard_ConstructionError.hxx>
52
53#include <TopExp.hxx>
54#include <BRepBndLib.hxx>
55
56#ifdef DEB
1d0a9d4d 57extern Standard_Boolean BRepFeat_GettraceFEAT();
7fd59977 58#endif
59
60static void MajMap(const TopoDS_Shape&, // base
61 LocOpe_Pipe&,
62 TopTools_DataMapOfShapeListOfShape&, // myMap
63 TopoDS_Shape&, // myFShape
64 TopoDS_Shape&); // myLShape
65
7fd59977 66//=======================================================================
67//function : Init
68//purpose :
69//=======================================================================
70
71void 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
137void 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
184void 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
7fd59977 204 GluedFacesValid();
205
206 if(myGluedF.IsEmpty()) {
207 if(myFuse == 1) {
208 //modified by NIZNHY-PKV Thu Mar 21 17:53:05 2002 f
209 //BRepAlgo_Fuse f(mySbase, myGShape);
210 //myShape = f.Shape();
211 //UpdateDescendants(f.Builder(), myShape, Standard_False);
212 BRepAlgoAPI_Fuse f(mySbase, myGShape);
213 myShape = f.Shape();
214 UpdateDescendants(f, myShape, Standard_False);
215 //modified by NIZNHY-PKV Thu Mar 21 17:53:10 2002 t
216 Done();
217 }
218 else if(myFuse == 0) {
219 //modified by NIZNHY-PKV Thu Mar 21 17:53:37 2002 f
220 //BRepAlgo_Cut c(mySbase, myGShape);
221 //myShape = c.Shape();
222 //UpdateDescendants(c.Builder(), myShape, Standard_False);
223 BRepAlgoAPI_Cut c(mySbase, myGShape);
224 myShape = c.Shape();
225 UpdateDescendants(c, myShape, Standard_False);
226 //modified by NIZNHY-PKV Thu Mar 21 17:53:50 2002 t
227 Done();
228 }
229 else {
230 myShape = myGShape;
231 Done();
232 }
233 }
234 else {
235 myFShape = thePipe.FirstShape();
236 TColgp_SequenceOfPnt spt;
237 LocOpe::SampleEdges(myFShape,spt);
238 myCurves = thePipe.Curves(spt);
239 myBCurve = thePipe.BarycCurve();
240 GlobalPerform();
241 }
242}
243
244
245//=======================================================================
246//function : Perform
0d969553 247//purpose : till shape Until
7fd59977 248//=======================================================================
249
250void BRepFeat_MakePipe::Perform(const TopoDS_Shape& Until)
251{
252#ifdef DEB
253 Standard_Boolean trc = BRepFeat_GettraceFEAT();
254 if (trc) cout << "BRepFeat_MakePipe::Perform(Until)" << endl;
255#endif
256 if (Until.IsNull()) {
257 Standard_ConstructionError::Raise();
258 }
259 TopExp_Explorer exp(Until, TopAbs_FACE);
260 if (!exp.More()) {
261 Standard_ConstructionError::Raise();
262 }
263 myGluedF.Clear();
264 myPerfSelection = BRepFeat_SelectionU;
265 PerfSelectionValid();
266 mySFrom.Nullify();
267 ShapeFromValid();
268 mySUntil = Until;
269 TransformShapeFU(1);
270 ShapeUntilValid();
271 LocOpe_Pipe thePipe(mySpine,myPbase);
272 TopoDS_Shape VraiTuyau = thePipe.Shape();
273 MajMap(myPbase,thePipe,myMap,myFShape,myLShape);
274 myGShape = VraiTuyau;
275 GeneratedShapeValid();
276
7fd59977 277 GluedFacesValid();
278
279 myFShape = thePipe.FirstShape();
280 TColgp_SequenceOfPnt spt;
281 LocOpe::SampleEdges(myFShape,spt);
282 myCurves = thePipe.Curves(spt);
283 myBCurve = thePipe.BarycCurve();
284 GlobalPerform();
285}
286
287
288//=======================================================================
289//function : Perform
0d969553 290//purpose : between From and Until
7fd59977 291//=======================================================================
292
293void BRepFeat_MakePipe::Perform(const TopoDS_Shape& From,
294 const TopoDS_Shape& Until)
295{
296#ifdef DEB
297 Standard_Boolean trc = BRepFeat_GettraceFEAT();
298 if (trc) cout << "BRepFeat_MakePipe::Perform(From,Until)" << endl;
299#endif
300 if (From.IsNull() || Until.IsNull()) {
301 Standard_ConstructionError::Raise();
302 }
303 if (!mySkface.IsNull()) {
304 if (From.IsSame(mySkface)) {
305 Perform(Until);
306 return;
307 }
308 else if (Until.IsSame(mySkface)) {
309 Perform(From);
310 return;
311 }
312 }
313 myGluedF.Clear();
314 myPerfSelection = BRepFeat_SelectionFU;
315 PerfSelectionValid();
316 TopExp_Explorer exp(From, TopAbs_FACE);
317 if (!exp.More()) {
318 Standard_ConstructionError::Raise();
319 }
320 exp.Init(Until, TopAbs_FACE);
321 if (!exp.More()) {
322 Standard_ConstructionError::Raise();
323 }
324 mySFrom = From;
325 TransformShapeFU(0);
326 ShapeFromValid();
327 mySUntil = Until;
328 TransformShapeFU(1);
329 ShapeUntilValid();
330 LocOpe_Pipe thePipe(mySpine,myPbase);
331 TopoDS_Shape VraiTuyau = thePipe.Shape();
332 MajMap(myPbase,thePipe,myMap,myFShape,myLShape);
333 myGShape = VraiTuyau;
334 GeneratedShapeValid();
335
7fd59977 336 // mySbase, myPbase, mySlface, thePipe, myGluedF);
337 GluedFacesValid();
338
339 myFShape = thePipe.FirstShape();
340 TColgp_SequenceOfPnt spt;
341 LocOpe::SampleEdges(myFShape,spt);
342 myCurves = thePipe.Curves(spt);
343 myBCurve = thePipe.BarycCurve();
344 GlobalPerform();
345}
346
347
348//=======================================================================
349//function : Curves
0d969553 350//purpose : curves parallel to the generating wire of the pipe
7fd59977 351//=======================================================================
352
353void BRepFeat_MakePipe::Curves(TColGeom_SequenceOfCurve& scur)
354{
355 scur = myCurves;
356}
357
358//=======================================================================
359//function : BarycCurve
0d969553 360//purpose : pass through the center of mass
7fd59977 361//=======================================================================
362
363Handle(Geom_Curve) BRepFeat_MakePipe::BarycCurve()
364{
365 return myBCurve;
366}
367
7fd59977 368//=======================================================================
369//function : MajMap
0d969553 370//purpose : management of descendants
7fd59977 371//=======================================================================
372
373static void MajMap(const TopoDS_Shape& theB,
374 LocOpe_Pipe& theP,
375 TopTools_DataMapOfShapeListOfShape& theMap, // myMap
376 TopoDS_Shape& theFShape, // myFShape
377 TopoDS_Shape& theLShape) // myLShape
378{
379 TopExp_Explorer exp(theP.FirstShape(),TopAbs_WIRE);
380 if (exp.More()) {
381 theFShape = exp.Current();
382 TopTools_ListOfShape thelist2;
383 theMap.Bind(theFShape, thelist2);
384 for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) {
385 theMap(theFShape).Append(exp.Current());
386 }
387 }
388
389 exp.Init(theP.LastShape(),TopAbs_WIRE);
390 if (exp.More()) {
391 theLShape = exp.Current();
392 TopTools_ListOfShape thelist3;
393 theMap.Bind(theLShape, thelist3);
394 for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) {
395 theMap(theLShape).Append(exp.Current());
396 }
397 }
398
399 for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) {
400 if (!theMap.IsBound(exp.Current())) {
401 TopTools_ListOfShape thelist4;
402 theMap.Bind(exp.Current(), thelist4);
403 theMap(exp.Current()) = theP.Shapes(exp.Current());
404 }
405 }
406}
407
408
409
410
411
412
413
414
415
416
417
418
419
420