0021762: Integration of new Boolean Operation algorithm to OCCT.
[occt.git] / src / BRepFeat / BRepFeat_MakeRevol.cxx
CommitLineData
b311480e 1// Created on: 1996-02-13
2// Created by: Jacques GOUSSARD
3// Copyright (c) 1996-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
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.
10//
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.
13//
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.
20
7fd59977 21
22
23#include <BRepFeat_MakeRevol.ixx>
24
25#include <BRepFeat.hxx>
26#include <LocOpe.hxx>
27#include <LocOpe_Revol.hxx>
7fd59977 28#include <LocOpe_Gluer.hxx>
29#include <LocOpe_FindEdges.hxx>
30#include <LocOpe_SequenceOfCirc.hxx>
31#include <LocOpe_BuildShape.hxx>
32#include <LocOpe_CSIntersector.hxx>
33#include <LocOpe_PntFace.hxx>
34
35#include <gp_Vec.hxx>
36#include <gp_Pnt.hxx>
37#include <gp_Ax1.hxx>
38#include <gp_Pnt2d.hxx>
39#include <TColgp_SequenceOfPnt.hxx>
40#include <Geom_Surface.hxx>
41#include <Geom_Curve.hxx>
42#include <Geom_Circle.hxx>
43#include <Geom2d_Curve.hxx>
44#include <Geom_RectangularTrimmedSurface.hxx>
45#include <Bnd_Box.hxx>
46
47#include <BRepSweep_Revol.hxx>
48#include <BRep_Builder.hxx>
49#include <BRep_Tool.hxx>
50#include <TopExp_Explorer.hxx>
51#include <TopTools_MapOfShape.hxx>
52#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
53#include <TopTools_ListIteratorOfListOfShape.hxx>
54#include <TopTools_MapIteratorOfMapOfShape.hxx>
55#include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
56
57#include <BRepAlgoAPI_Cut.hxx>
58#include <BRepAlgoAPI_Fuse.hxx>
59
60#include <BRepLib_MakeFace.hxx>
61#include <BRepTools_Modifier.hxx>
62#include <BRepTools_TrsfModification.hxx>
63
64#include <Standard_ConstructionError.hxx>
65
66#include <TopoDS_Solid.hxx>
67#include <TopoDS_Compound.hxx>
68#include <TopoDS_Shell.hxx>
69
70#include <gp_Pln.hxx>
71#include <Geom_Plane.hxx>
72
73
74#include <TopExp.hxx>
75#include <Precision.hxx>
76#include <BRepBndLib.hxx>
77#include <BRepBuilderAPI.hxx>
78#include <BRepFeat.hxx>
79
80#include <ElCLib.hxx>
81
82#ifdef DEB
1d0a9d4d 83extern Standard_Boolean BRepFeat_GettraceFEAT();
7fd59977 84#endif
85
86static void MajMap(const TopoDS_Shape&, // base
87 const LocOpe_Revol&,
88 TopTools_DataMapOfShapeListOfShape&, // myMap
89 TopoDS_Shape&, // myFShape
90 TopoDS_Shape&); // myLShape
91
92
93static void SetGluedFaces(const TopoDS_Face& theSkface,
94 const TopoDS_Shape& theSbase,
95 const TopoDS_Shape& thePbase,
96 const TopTools_DataMapOfShapeListOfShape& theSlmap,
97 LocOpe_Revol&,
98 TopTools_DataMapOfShapeShape&);
99
100
101static void VerifGluedFaces(const TopoDS_Face& theSkface,
102 const TopoDS_Shape& thePbase,
103 Handle(Geom_Curve)& theBCurve,
104 TColGeom_SequenceOfCurve& theCurves,
105 LocOpe_Revol& theRevol,
106 TopTools_DataMapOfShapeShape& theMap);
107
108
109static Standard_Boolean ToFuse(const TopoDS_Face& ,
110 const TopoDS_Face&);
111
112
113
114
115//=======================================================================
116//function : Init
117//purpose :
118//=======================================================================
119
120void BRepFeat_MakeRevol::Init(const TopoDS_Shape& Sbase,
121 const TopoDS_Shape& Pbase,
122 const TopoDS_Face& Skface,
123 const gp_Ax1& Axis,
124 const Standard_Integer Mode,
125 const Standard_Boolean Modify)
126{
127#ifdef DEB
128 Standard_Boolean trc = BRepFeat_GettraceFEAT();
129 if (trc) cout << "BRepFeat_MakeRevol::Init" << endl;
130#endif
131 myAxis = Axis;
132 myPbase = Pbase;
133 mySbase = Sbase;
134 BasisShapeValid();
135 mySkface = Skface;
136 SketchFaceValid();
137 myPbase = Pbase;
138 mySlface.Clear();
139 if(Mode == 0) {
140 myFuse = Standard_False;
141 myJustFeat = Standard_False;
142 }
143 else if(Mode == 1) {
144 myFuse = Standard_True;
145 myJustFeat = Standard_False;
146 }
147 else if(Mode == 2) {
148 myFuse = Standard_True;
149 myJustFeat = Standard_True;
150 }
151 else {
152 }
153 myModify = Modify;
154 myJustGluer = Standard_False;
155
156 //-------------- ifv
157// mySkface.Nullify();
158 //-------------- ifv
159
160
161 myShape.Nullify();
162 myMap.Clear();
163 myFShape.Nullify();
164 myLShape.Nullify();
165 TopExp_Explorer exp;
166 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
167 TopTools_ListOfShape thelist;
168 myMap.Bind(exp.Current(), thelist);
169 myMap(exp.Current()).Append(exp.Current());
170 }
171#ifdef DEB
172 if (trc) {
173 if (myJustFeat) cout << " Just Feature" << endl;
174 if (myFuse) cout << " Fuse" << endl;
175 if (!myFuse) cout << " Cut" << endl;
176 if (!myModify) cout << " Modify = 0" << endl;
177 }
178#endif
179}
180
181
182//=======================================================================
183//function : Add
0d969553 184//purpose : add faces add edges of sliding
7fd59977 185//=======================================================================
186
187void BRepFeat_MakeRevol::Add(const TopoDS_Edge& E,
188 const TopoDS_Face& F)
189{
190#ifdef DEB
191 Standard_Boolean trc = BRepFeat_GettraceFEAT();
192 if (trc) cout << "BRepFeat_MakeRevol::Add(Edge,face)" << endl;
193#endif
194 TopExp_Explorer exp;
195 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
196 if (exp.Current().IsSame(F)) {
197 break;
198 }
199 }
200 if (!exp.More()) {
201 Standard_ConstructionError::Raise();
202 }
203
204 for (exp.Init(myPbase,TopAbs_EDGE);exp.More();exp.Next()) {
205 if (exp.Current().IsSame(E)) {
206 break;
207 }
208 }
209 if (!exp.More()) {
210 Standard_ConstructionError::Raise();
211 }
212
213 if (!mySlface.IsBound(F)) {
214 TopTools_ListOfShape thelist;
215 mySlface.Bind(F, thelist);
216 }
217 TopTools_ListIteratorOfListOfShape itl(mySlface(F));
218 for (; itl.More();itl.Next()) {
219 if (itl.Value().IsSame(E)) {
220 break;
221 }
222 }
223 if (!itl.More()) {
224 mySlface(F).Append(E);
225 }
226}
227
228
229//=======================================================================
230//function : Perform
231//purpose :
232//=======================================================================
233
234void BRepFeat_MakeRevol::Perform(const Standard_Real Angle)
235{
236#ifdef DEB
237 Standard_Boolean trc = BRepFeat_GettraceFEAT();
238 if (trc) cout << "BRepFeat_MakeRevol::Perform(Angle)" << endl;
239#endif
240 mySFrom.Nullify();
241 ShapeFromValid();
242 mySUntil.Nullify();
243 ShapeUntilValid();
244 myGluedF.Clear();
245 myPerfSelection = BRepFeat_NoSelection;
246 PerfSelectionValid();
c6541a0c 247 Standard_Boolean RevolComp = (2*M_PI-Abs(Angle) <= Precision::Angular());
7fd59977 248 LocOpe_Revol theRevol;
249 Standard_Real angledec = 0.;
250 TopExp_Explorer exp;
251 if(RevolComp) {
252 /*
253 if (!mySkface.IsNull() || !mySlface.IsEmpty()) {
254 for (exp.Init(mySbase,TopAbs_FACE); exp.More(); exp.Next()) {
255 if (exp.Current().IsSame(mySkface)) {
c6541a0c 256 angledec = M_PI/5; // pourquoi pas
7fd59977 257 if (myFuse) angledec = -angledec;
258 break;
259 }
260 }
261 }
262 */
263 mySkface.Nullify();
264 }
265 if(angledec == 0.) theRevol.Perform(myPbase, myAxis, Angle);
266 else theRevol.Perform(myPbase, myAxis, Angle, angledec);
267
268 TopoDS_Shape VraiRevol = theRevol.Shape();
269
270 MajMap(myPbase,theRevol,myMap,myFShape,myLShape);
271
272 myGShape = VraiRevol;
273 GeneratedShapeValid();
274 TopoDS_Shape Base = theRevol.FirstShape();
275 exp.Init(Base, TopAbs_FACE);
276 TopoDS_Face theBase = TopoDS::Face(exp.Current());
277 exp.Next();
278 if(exp.More()) {
279 NotDone();
280 myStatusError = BRepFeat_InvFirstShape;
281 return;
282 }
283
284 TopoDS_Face FFace;
285
286 Standard_Boolean found = Standard_False;
287
288 if(!mySkface.IsNull() || !mySlface.IsEmpty()) {
289 if(myLShape.ShapeType() == TopAbs_WIRE) {
290 TopExp_Explorer ex1(VraiRevol, TopAbs_FACE);
291 for(; ex1.More(); ex1.Next()) {
292 TopExp_Explorer ex2(ex1.Current(), TopAbs_WIRE);
293 for(; ex2.More(); ex2.Next()) {
294 if(ex2.Current().IsSame(myLShape)) {
295 FFace = TopoDS::Face(ex1.Current());
296 found = Standard_True;
297 break;
298 }
299 }
300 if(found) break;
301 }
302 }
303
304 TopExp_Explorer exp(mySbase, TopAbs_FACE);
305 for(; exp.More(); exp.Next()) {
306 const TopoDS_Face& ff = TopoDS::Face(exp.Current());
307 if(ToFuse(ff, FFace)) {
308 TopTools_DataMapOfShapeListOfShape sl;
309 if(!FFace.IsSame(myPbase) && BRepFeat::IsInside(ff, FFace))
310 //SetGluedFaces(ff, mySbase, FFace, sl, theRevol, myGluedF);
311 break;
312 }
313 }
314 }
315
316 //SetGluedFaces(mySkface, mySbase, theBase, mySlface, theRevol, myGluedF);
317 GluedFacesValid();
318 if (!mySkface.IsNull()) {
319 VerifGluedFaces(mySkface, theBase, myBCurve, myCurves, theRevol, myGluedF);
320 }
321
322 if(myGluedF.IsEmpty()) {
323 if(myFuse == 1) {
324 //modified by NIZNHY-PKV Thu Mar 21 18:15:06 2002 f
325 //BRepAlgo_Fuse f(mySbase, myGShape);
326 //myShape = f.Shape();
327 //UpdateDescendants(f.Builder(), myShape, Standard_False);
328 BRepAlgoAPI_Fuse f(mySbase, myGShape);
329 myShape = f.Shape();
330 UpdateDescendants(f, myShape, Standard_False);
331 //modified by NIZNHY-PKV Thu Mar 21 18:15:11 2002 t
332 Done();
333 }
334 else if(myFuse == 0) {
335 //modified by NIZNHY-PKV Thu Mar 21 18:15:37 2002 f
336 //BRepAlgo_Cut c(mySbase, myGShape);
337 //myShape = c.Shape();
338 //UpdateDescendants(c.Builder(), myShape, Standard_False);
339 BRepAlgoAPI_Cut c(mySbase, myGShape);
340 myShape = c.Shape();
341 UpdateDescendants(c, myShape, Standard_False);
342 //modified by NIZNHY-PKV Thu Mar 21 18:15:47 2002 t
343 Done();
344 }
345 else {
346 myShape = myGShape;
347 Done();
348 }
349 }
350 else {
351 theRevol.Curves(myCurves);
352 myBCurve = theRevol.BarycCurve();
353 GlobalPerform();
354 }
355}
356
357
358//=======================================================================
359//function : Perform
0d969553 360//purpose : feature till shape Until
7fd59977 361//=======================================================================
362
363void BRepFeat_MakeRevol::Perform(const TopoDS_Shape& Until)
364{
365#ifdef DEB
366 Standard_Boolean trc = BRepFeat_GettraceFEAT();
367 if (trc) cout << "BRepFeat_MakeRevol::Perform(Until)" << endl;
368#endif
369 Standard_Real Angle = 0.;
370 Standard_Boolean TourComplet = Standard_False;
371
372 if (Until.IsNull()) {
373 Standard_ConstructionError::Raise();
374 }
375 TopExp_Explorer exp(Until, TopAbs_FACE);
376 if (!exp.More()) {
377 Standard_ConstructionError::Raise();
378 }
379 if (!mySkface.IsNull() && Until.IsSame(mySkface)) {
c6541a0c 380 Angle = 2*M_PI;
7fd59977 381 TourComplet = Standard_True;
382 }
383 myGluedF.Clear();
384 myPerfSelection = BRepFeat_SelectionU;
385 PerfSelectionValid();
386 mySFrom.Nullify();
387 ShapeFromValid();
388 mySUntil = Until;
389 Standard_Boolean Trf = TransformShapeFU(1);
390 ShapeUntilValid();
391
0d969553 392// Do systematically almost complete revolution
c6541a0c 393// BRepSweep_Revol theRevol(myPbase,myAxis,2.*M_PI-10.*Precision::Angular());
7fd59977 394 LocOpe_Revol theRevol;
395 if(!TourComplet) {
c6541a0c 396 Angle = 2.*M_PI- 3*M_PI/180.;
7fd59977 397#ifdef DEB
0d969553 398 if (trc) cout << " No complete Revolution" << endl;
7fd59977 399#endif
400 }
401 theRevol.Perform(myPbase, myAxis, Angle);
402 TopoDS_Shape VraiRevol = theRevol.Shape();
403 MajMap(myPbase,theRevol,myMap,myFShape,myLShape);
404
405
406 if(!Trf) {
407
408 myGShape = VraiRevol;
409 GeneratedShapeValid();
410
411 TopoDS_Shape Base = theRevol.FirstShape();
412 exp.Init(Base, TopAbs_FACE);
413 TopoDS_Face theBase = TopoDS::Face(exp.Current());
414 exp.Next();
415 if(exp.More()) {
416 NotDone();
417 myStatusError = BRepFeat_InvFirstShape;
418 return;
419 }
420
421 //SetGluedFaces(mySkface, mySbase, theBase, mySlface, theRevol, myGluedF);
422 GluedFacesValid();
423 //VerifGluedFaces(mySkface, theBase, myBCurve, myCurves, theRevol, myGluedF);
424
425 theRevol.Curves(myCurves);
426 myBCurve = theRevol.BarycCurve();
427 GlobalPerform();
428 }
429 else {
430 TColGeom_SequenceOfCurve scur;
431 theRevol.Curves(myCurves);
432 myBCurve = theRevol.BarycCurve();
433 scur.Clear();
434 scur.Append(myBCurve);
435 LocOpe_CSIntersector ASI(mySUntil);
436 ASI.Perform(scur);
437 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
438 TopAbs_Orientation Or = ASI.Point(1,1).Orientation();
439 TopoDS_Face FUntil = ASI.Point(1,1).Face();
440 TopoDS_Shape Comp;
441 BRep_Builder B;
442 B.MakeCompound(TopoDS::Compound(Comp));
443 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
444 if (!S.IsNull()) B.Add(Comp,S);
445 //modified by NIZNHY-PKV Thu Mar 21 18:17:31 2002 f
446 //BRepAlgo_Cut trP(VraiRevol,Comp);
447 BRepAlgoAPI_Cut trP(VraiRevol,Comp);
448 //modified by NIZNHY-PKV Thu Mar 21 18:17:37 2002 t
449 TopoDS_Shape Cutsh = trP.Shape();
450 TopExp_Explorer ex(Cutsh, TopAbs_SOLID);
451 for(; ex.More(); ex.Next()) {
452 TopExp_Explorer ex1(ex.Current(), TopAbs_FACE);
453 for(; ex1.More(); ex1.Next()) {
454 const TopoDS_Face& fac = TopoDS::Face(ex1.Current());
455 if(fac.IsSame(myPbase)) {
456 VraiRevol = ex.Current();
457 break;
458 }
459 }
460 }
461 if(myFuse == 1) {
462 //modified by NIZNHY-PKV Thu Mar 21 18:17:53 2002 f
463 //BRepAlgo_Fuse f(mySbase, VraiRevol);
464 //myShape = f.Shape();
465 //UpdateDescendants(f.Builder(), myShape, Standard_False);
466 BRepAlgoAPI_Fuse f(mySbase, VraiRevol);
467 myShape = f.Shape();
468 UpdateDescendants(f, myShape, Standard_False);
469 //modified by NIZNHY-PKV Thu Mar 21 18:17:57 2002 t
470 Done();
471 }
472 else if(myFuse == 0) {
473 //modified by NIZNHY-PKV Thu Mar 21 18:18:23 2002 f
474 //BRepAlgo_Cut c(mySbase, VraiRevol);
475 //myShape = c.Shape();
476 //UpdateDescendants(c.Builder(), myShape, Standard_False);
477 BRepAlgoAPI_Cut c(mySbase, VraiRevol);
478 myShape = c.Shape();
479 UpdateDescendants(c, myShape, Standard_False);
480 //modified by NIZNHY-PKV Thu Mar 21 18:18:28 2002 t
481 Done();
482 }
483 else {
484 myShape = VraiRevol;
485 Done();
486 }
487 }
488 }
0d969553 489 // Loop of control of descendance
7fd59977 490/*
491 TopExp_Explorer expr(mySbase, TopAbs_FACE);
492 char nom1[20], nom2[20];
493 Standard_Integer ii = 0;
494 for(; expr.More(); expr.Next()) {
495 ii++;
496 sprintf(nom1, "faceinitial_%d", ii);
497 DBRep::Set(nom1, expr.Current());
498 Standard_Integer jj = 0;
499 const TopTools_ListOfShape& list = Modified(expr.Current());
500 TopTools_ListIteratorOfListOfShape ite(list);
501 for(; ite.More(); ite.Next()) {
502 jj++;
503 sprintf(nom2, "facemodifie_%d_%d", ii, jj);
504 DBRep::Set(nom2, ite.Value());
505 }
506 }
507
508 expr.Init(myPbase, TopAbs_EDGE);
509 ii=0;
510 for(; expr.More(); expr.Next()) {
511 ii++;
512 sprintf(nom1, "edgeinitial_%d", ii);
513 DBRep::Set(nom1, expr.Current());
514 Standard_Integer jj = 0;
515 const TopTools_ListOfShape& list = Generated(expr.Current());
516 TopTools_ListIteratorOfListOfShape ite(list);
517 for(; ite.More(); ite.Next()) {
518 jj++;
519 sprintf(nom2, "facegeneree_%d_%d", ii, jj);
520 DBRep::Set(nom2, ite.Value());
521 }
522 }
523*/
524 }
525
526
527//=======================================================================
528//function : Perform
0d969553 529//purpose : feature limited by two shapes
7fd59977 530//=======================================================================
531
532void BRepFeat_MakeRevol::Perform(const TopoDS_Shape& From,
533 const TopoDS_Shape& Until)
534{
535#ifdef DEB
536 Standard_Boolean trc = BRepFeat_GettraceFEAT();
537 if (trc) cout << "BRepFeat_MakeRevol::Perform(From,Until)" << endl;
538#endif
539 if (From.IsNull() || Until.IsNull()) {
540 Standard_ConstructionError::Raise();
541 }
542 if (!mySkface.IsNull()) {
543 if (From.IsSame(mySkface)) {
544 myJustGluer = Standard_True;
545 Perform(Until);
546 if (myJustGluer) return;
547 }
548 else if (Until.IsSame(mySkface)) {
549 myJustGluer = Standard_True;
550 myAxis.Reverse();
551 Perform(From);
552 if (myJustGluer) return;
553 }
554 }
555
556 myGluedF.Clear();
557 myPerfSelection = BRepFeat_SelectionFU;
558 PerfSelectionValid();
559
560 TopExp_Explorer exp(From, TopAbs_FACE);
561 if (!exp.More()) {
562 Standard_ConstructionError::Raise();
563 }
564 exp.Init(Until, TopAbs_FACE);
565 if (!exp.More()) {
566 Standard_ConstructionError::Raise();
567 }
568
569 mySFrom = From;
570 Standard_Boolean Trff = TransformShapeFU(0);
571 ShapeFromValid();
572 mySUntil = Until;
573 Standard_Boolean Trfu = TransformShapeFU(1);
574 ShapeUntilValid();
575
576 if(Trfu != Trff) {
577 NotDone();
578 myStatusError = BRepFeat_IncTypes;
579 return;
580 }
581
582 LocOpe_Revol theRevol;
c6541a0c 583 theRevol.Perform(myPbase, myAxis, 2*M_PI);
7fd59977 584 TopoDS_Shape VraiRevol = theRevol.Shape();
585
586 MajMap(myPbase,theRevol,myMap,myFShape,myLShape);
587
588 if(!Trff) {
589 myGShape = VraiRevol;
590 GeneratedShapeValid();
591
592 //SetGluedFaces(TopoDS_Face(), mySbase, myPbase, mySlface, theRevol, myGluedF);
593 GluedFacesValid();
594// VerifGluedFaces(mySkface, theBase, myBCurve, myCurves, theRevol, myGluedF);
595
596 theRevol.Curves(myCurves);
597 myBCurve = theRevol.BarycCurve();
598 GlobalPerform();
599 }
600 else {
601 theRevol.Curves(myCurves);
602 myBCurve = theRevol.BarycCurve();
603 TColGeom_SequenceOfCurve scur;
604 scur.Clear();
605 scur.Append(myBCurve);
606 LocOpe_CSIntersector ASI1(mySUntil);
607 LocOpe_CSIntersector ASI2(mySFrom);
608 ASI1.Perform(scur);
609 ASI2.Perform(scur);
610 TopAbs_Orientation OrU, OrF;
611 TopoDS_Face FFrom, FUntil;
612 Standard_Real PrF, PrU;
613 if (ASI1.IsDone() && ASI1.NbPoints(1) >=1) {
614 OrU = ASI1.Point(1,1).Orientation();
615 FUntil = ASI1.Point(1,1).Face();
616 PrU = ASI1.Point(1,1).Parameter();
617 }
618 else {
619 NotDone();
620 myStatusError = BRepFeat_NoIntersectU;
621 return;
622 }
623 if (ASI2.IsDone() && ASI2.NbPoints(1) >=1) {
624 Standard_Real pr1 = ASI2.Point(1,1).Parameter();
c6541a0c 625 pr1 = ElCLib::InPeriod(pr1,PrU-2*M_PI,PrU);
7fd59977 626 Standard_Real pr2 = ASI2.Point(1,ASI2.NbPoints(1)).Parameter();
c6541a0c 627 pr2 = ElCLib::InPeriod(pr2,PrU-2*M_PI,PrU);
7fd59977 628 OrF = OrU;
629 FFrom = ASI2.Point(1,1).Face();
630 PrF = Max(pr1, pr2);
631 }
632 else {
633 NotDone();
634 myStatusError = BRepFeat_NoIntersectF;
635 return;
636 }
637 if(!(PrU > PrF)) {
638 NotDone();
639 myStatusError = BRepFeat_IncParameter;
640 return;
641 }
642 TopoDS_Shape Comp;
643 BRep_Builder B;
644 B.MakeCompound(TopoDS::Compound(Comp));
645 TopoDS_Solid SF = BRepFeat::Tool(mySFrom, FFrom, OrF);
646 if (!SF.IsNull()) B.Add(Comp,SF);
647 TopoDS_Solid SU = BRepFeat::Tool(mySUntil, FUntil, OrU);
648 if (!SU.IsNull()) B.Add(Comp,SU);
649 //modified by NIZNHY-PKV Thu Mar 21 18:18:54 2002 f
650 //BRepAlgo_Cut trP(VraiRevol,Comp);
651 BRepAlgoAPI_Cut trP(VraiRevol,Comp);
652 //modified by NIZNHY-PKV Thu Mar 21 18:18:57 2002 t
653 TopoDS_Shape Cutsh = trP.Shape();
654 TopExp_Explorer ex(Cutsh, TopAbs_SOLID);
655// Standard_Real PrF = BRepFeat::ParametricBarycenter(mySFrom, myBCurve);
656// Standard_Real PrU = BRepFeat::ParametricBarycenter(mySUntil, myBCurve);
657 VraiRevol = ex.Current();
658 for(; ex.More(); ex.Next()) {
659 Standard_Real PrCur = BRepFeat::
660 ParametricBarycenter(ex.Current(), myBCurve);
661 if(PrF <= PrCur && PrU >= PrCur) {
662 VraiRevol = ex.Current();
663 break;
664 }
665 }
666 if(myFuse == 1) {
667 //modified by NIZNHY-PKV Thu Mar 21 18:19:14 2002 f
668 //BRepAlgo_Fuse f(mySbase, VraiRevol);
669 //myShape = f.Shape();
670 //UpdateDescendants(f.Builder(), myShape, Standard_False);
671 BRepAlgoAPI_Fuse f(mySbase, VraiRevol);
672 myShape = f.Shape();
673 UpdateDescendants(f, myShape, Standard_False);
674 //modified by NIZNHY-PKV Thu Mar 21 18:19:18 2002 t
675 Done();
676 }
677 else if(myFuse == 0) {
678 //modified by NIZNHY-PKV Thu Mar 21 18:19:46 2002 f
679 //BRepAlgo_Cut c(mySbase, VraiRevol);
680 //myShape = c.Shape();
681 //UpdateDescendants(c.Builder(), myShape, Standard_False);
682 BRepAlgoAPI_Cut c(mySbase, VraiRevol);
683 myShape = c.Shape();
684 UpdateDescendants(c, myShape, Standard_False);
685 //modified by NIZNHY-PKV Thu Mar 21 18:19:50 2002 t
686 Done();
687 }
688 else {
689 myShape = VraiRevol;
690 Done();
691 }
692 }
693}
694
695
696//=======================================================================
697//function : PerformThruAll
0d969553 698//purpose : feature throughout the initial shape
7fd59977 699//=======================================================================
700
701void BRepFeat_MakeRevol::PerformThruAll()
702{
703#ifdef DEB
704 Standard_Boolean trc = BRepFeat_GettraceFEAT();
705 if (trc) cout << "BRepFeat_MakeRevol::PerformThruAll()" << endl;
706#endif
c6541a0c 707 Perform(2.*M_PI);
7fd59977 708}
709
710//=======================================================================
711//function : PerformUntilAngle
0d969553 712//purpose : feature till shape Until defined with the angle
7fd59977 713//=======================================================================
714
715void BRepFeat_MakeRevol::PerformUntilAngle(const TopoDS_Shape& Until,
716 const Standard_Real Angle)
717{
718#ifdef DEB
719 Standard_Boolean trc = BRepFeat_GettraceFEAT();
720 if (trc) cout << "BRepFeat_MakeRevol::PerformUntilAngle(Until,Angle)" << endl;
721#endif
722 if (Until.IsNull()) {
723 Perform(Angle);
724 }
725 if(Angle == 0) {
726 Perform(Until);
727 }
728 TopExp_Explorer exp(Until, TopAbs_FACE);
729 if (!exp.More()) {
730 Standard_ConstructionError::Raise();
731 }
732 if (!mySkface.IsNull() && Until.IsSame(mySkface)) {
733 Perform(Angle);
734 return;
735 }
736 myGluedF.Clear();
737 myPerfSelection = BRepFeat_NoSelection;
738 PerfSelectionValid();
739 mySFrom.Nullify();
740 ShapeFromValid();
741 mySUntil = Until;
742 Standard_Boolean Trf = TransformShapeFU(1);
743 ShapeUntilValid();
744
0d969553 745// Produce systematicallt an almost complete revolution
c6541a0c 746// BRepSweep_Revol theRevol(myPbase,myAxis,2.*M_PI-10.*Precision::Angular());
7fd59977 747 LocOpe_Revol theRevol;
748 theRevol.Perform(myPbase, myAxis, Angle);
749 TopoDS_Shape VraiRevol = theRevol.Shape();
750
751 MajMap(myPbase,theRevol,myMap,myFShape,myLShape);
752
753 if(Trf) {
754 myGShape = VraiRevol;
755 GeneratedShapeValid();
756
757 TopoDS_Shape Base = theRevol.FirstShape();
758 exp.Init(Base, TopAbs_FACE);
759 TopoDS_Face theBase = TopoDS::Face(exp.Current());
760 exp.Next();
761 if(exp.More()) {
762 NotDone();
763 myStatusError = BRepFeat_InvFirstShape;
764 return;
765 }
766
767 //SetGluedFaces(mySkface, mySbase, theBase, mySlface, theRevol, myGluedF);
768 GluedFacesValid();
769 //VerifGluedFaces(mySkface, theBase, myBCurve, myCurves, theRevol, myGluedF);
770
771
772 theRevol.Curves(myCurves);
773 myBCurve = theRevol.BarycCurve();
774 GlobalPerform();
775 }
776 else {
777 TColGeom_SequenceOfCurve scur;
778 theRevol.Curves(myCurves);
779 myBCurve = theRevol.BarycCurve();
780 scur.Clear();
781 scur.Append(myBCurve);
782 LocOpe_CSIntersector ASI(mySUntil);
783 ASI.Perform(scur);
784 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
785 TopAbs_Orientation Or = ASI.Point(1,1).Orientation();
786 TopoDS_Face FUntil = ASI.Point(1,1).Face();
787 TopoDS_Shape Comp;
788 BRep_Builder B;
789 B.MakeCompound(TopoDS::Compound(Comp));
790 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
791 if (!S.IsNull()) B.Add(Comp,S);
792 //modified by NIZNHY-PKV Thu Mar 21 18:20:14 2002 f
793 //BRepAlgo_Cut trP(VraiRevol,Comp);
794 BRepAlgoAPI_Cut trP(VraiRevol,Comp);
795 //modified by NIZNHY-PKV Thu Mar 21 18:20:19 2002 t
796 TopoDS_Shape Cutsh = trP.Shape();
797 TopExp_Explorer ex(Cutsh, TopAbs_SOLID);
798 for(; ex.More(); ex.Next()) {
799 TopExp_Explorer ex1(ex.Current(), TopAbs_FACE);
800 for(; ex1.More(); ex1.Next()) {
801 const TopoDS_Face& fac = TopoDS::Face(ex1.Current());
802 if(fac.IsSame(myPbase)) {
803 VraiRevol = ex.Current();
804 break;
805 }
806 }
807 }
808 if(myFuse == 1) {
809 //modified by NIZNHY-PKV Thu Mar 21 18:20:36 2002 f
810 //BRepAlgo_Fuse f(mySbase, VraiRevol);
811 //myShape = f.Shape();
812 //UpdateDescendants(f.Builder(), myShape, Standard_False);
813 BRepAlgoAPI_Fuse f(mySbase, VraiRevol);
814 myShape = f.Shape();
815 UpdateDescendants(f, myShape, Standard_False);
816 //modified by NIZNHY-PKV Thu Mar 21 18:20:40 2002 t
817 Done();
818 }
819 else if(myFuse == 0) {
820 //modified by NIZNHY-PKV Thu Mar 21 18:21:07 2002 f
821 //BRepAlgo_Cut c(mySbase, VraiRevol);
822 //myShape = c.Shape();
823 //UpdateDescendants(c.Builder(), myShape, Standard_False);
824 BRepAlgoAPI_Cut c(mySbase, VraiRevol);
825 myShape = c.Shape();
826 UpdateDescendants(c, myShape, Standard_False);
827 //modified by NIZNHY-PKV Thu Mar 21 18:21:26 2002 t
828 Done();
829 }
830 else {
831 myShape = VraiRevol;
832 Done();
833 }
834 }
835 }
836}
837//=======================================================================
838//function : Curves
0d969553 839//purpose : circles parallel to the generating edge of revolution
7fd59977 840//=======================================================================
841
842void BRepFeat_MakeRevol::Curves(TColGeom_SequenceOfCurve& scur)
843{
844 scur = myCurves;
845}
846
847//=======================================================================
848//function : BarycCurve
0d969553 849//purpose : pass through the center of mass of the primitive
7fd59977 850//=======================================================================
851
852Handle(Geom_Curve) BRepFeat_MakeRevol::BarycCurve()
853{
854 return myBCurve;
855}
856
857
858//=======================================================================
859//function : SetGluedFaces
0d969553 860//purpose : management of gluing faces
7fd59977 861//=======================================================================
862
863static void SetGluedFaces(const TopoDS_Face& theSkface,
864 const TopoDS_Shape& theSbase,
865 const TopoDS_Shape& thePbase,
866 const TopTools_DataMapOfShapeListOfShape& theSlmap,
867 LocOpe_Revol& theRevol,
868 TopTools_DataMapOfShapeShape& theMap)
869{
870 TopExp_Explorer exp;
871 if (!theSkface.IsNull() && thePbase.ShapeType() == TopAbs_FACE) {
872 for (exp.Init(theSbase,TopAbs_FACE); exp.More(); exp.Next()) {
873 if (exp.Current().IsSame(theSkface)) {
874 theMap.Bind(thePbase,theSkface);
875 break;
876 }
877 }
878 }
879 else {
880 TopExp_Explorer exp2;
881 for (exp.Init(thePbase,TopAbs_FACE);exp.More();exp.Next()) {
882 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
883 for (exp2.Init(theSbase,TopAbs_FACE);exp2.More();exp2.Next()) {
884 if (exp2.Current().IsSame(fac)) {
885 theMap.Bind(fac,fac);
886 break;
887 }
888 }
889 }
890 }
891
0d969553 892 // Sliding
7fd59977 893 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm(theSlmap);
894 if(!theSlmap.IsEmpty()) {
895 for (; itm.More(); itm.Next()) {
896 const TopoDS_Face& fac = TopoDS::Face(itm.Key());
897 const TopTools_ListOfShape& ledg = itm.Value();
898 TopTools_ListIteratorOfListOfShape it;
899 for (it.Initialize(ledg); it.More(); it.Next()) {
900 const TopTools_ListOfShape& gfac = theRevol.Shapes(it.Value());
901 if (gfac.Extent() != 1) {
902#ifdef DEB
903 Standard_Boolean trc = BRepFeat_GettraceFEAT();
904 if (trc) cout << " BRepFeat_MakeRevol : Pb SetGluedFace" << endl;
905#endif
906 }
907 theMap.Bind(gfac.First(),fac);
908 }
909 }
910 }
911}
912
913//=======================================================================
914//function : VerifGluedFaces
0d969553
Y
915//purpose : Check intersection Tool/theSkface = thePbase
916// if yes -> OK otherwise -> case without gluing
7fd59977 917//=======================================================================
918
919static void VerifGluedFaces(const TopoDS_Face& theSkface,
920 const TopoDS_Shape& thePbase,
921 Handle(Geom_Curve)& theBCurve,
922 TColGeom_SequenceOfCurve& theCurves,
923 LocOpe_Revol& theRevol,
924 TopTools_DataMapOfShapeShape& theMap)
925{
926 Standard_Boolean GluedFaces = Standard_True;
927 TopoDS_Shape VraiRevol = theRevol.Shape();
928
929 TColGeom_SequenceOfCurve scur;
930 theRevol.Curves(theCurves);
931 theBCurve = theRevol.BarycCurve();
932 scur.Clear();
933 scur.Append(theBCurve);
934 LocOpe_CSIntersector ASI(theSkface);
935 ASI.Perform(scur);
936 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
937 TopAbs_Orientation Or = ASI.Point(1,1).Orientation();
938 TopoDS_Face FSk = ASI.Point(1,1).Face();
939 TopoDS_Shape Comp;
940 BRep_Builder B;
941 B.MakeCompound(TopoDS::Compound(Comp));
942 TopoDS_Solid S = BRepFeat::Tool(theSkface, FSk, Or);
943 if (!S.IsNull()) B.Add(Comp,S);
944 //modified by NIZNHY-PKV Thu Mar 21 18:21:54 2002 f
945 //BRepAlgo_Cut trP(VraiRevol,Comp);
946 BRepAlgoAPI_Cut trP(VraiRevol,Comp);
947 //modified by NIZNHY-PKV Thu Mar 21 18:21:58 2002 t
948 TopoDS_Shape Cutsh = trP.Shape();
949 TopExp_Explorer ex(Cutsh, TopAbs_SOLID);
950 for(; ex.More(); ex.Next()) {
951 TopExp_Explorer ex1(ex.Current(), TopAbs_FACE);
952 for(; ex1.More(); ex1.Next()) {
953 const TopoDS_Face& fac1 = TopoDS::Face(ex1.Current());
954 TopExp_Explorer ex2(thePbase, TopAbs_FACE);
955 for(; ex2.More(); ex2.Next()) {
956 const TopoDS_Face& fac2 = TopoDS::Face(ex2.Current());
957 if(fac1.IsSame(fac2)) break;
958 }
959 if (ex2.More()) break;
960 }
961 if (ex1.More()) continue;
962 GluedFaces = Standard_False;
963 break;
964 }
965 if (!GluedFaces) {
966#ifdef DEB
967 Standard_Boolean trc = BRepFeat_GettraceFEAT();
0d969553 968 if (trc) cout << " Intersection Revol/skface : no gluing" << endl;
7fd59977 969#endif
970 theMap.Clear();
971 }
972 }
973}
974
975//=======================================================================
976//function : MajMap
0d969553 977//purpose : management of descendants
7fd59977 978//=======================================================================
979
980static void MajMap(const TopoDS_Shape& theB,
981 const LocOpe_Revol& theP,
982 TopTools_DataMapOfShapeListOfShape& theMap, // myMap
983 TopoDS_Shape& theFShape, // myFShape
984 TopoDS_Shape& theLShape) // myLShape
985{
986 TopExp_Explorer exp(theP.FirstShape(),TopAbs_WIRE);
987 if (exp.More()) {
988 theFShape = exp.Current();
989 TopTools_ListOfShape thelist;
990 theMap.Bind(theFShape, thelist);
991 for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) {
992 theMap(theFShape).Append(exp.Current());
993 }
994 }
995
996 exp.Init(theP.LastShape(),TopAbs_WIRE);
997 if (exp.More()) {
998 theLShape = exp.Current();
999 TopTools_ListOfShape thelist1;
1000 theMap.Bind(theLShape, thelist1);
1001 for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) {
1002 theMap(theLShape).Append(exp.Current());
1003 }
1004 }
1005
1006 for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) {
1007 if (!theMap.IsBound(exp.Current())) {
1008 TopTools_ListOfShape thelist2;
1009 theMap.Bind(exp.Current(), thelist2);
1010 theMap(exp.Current()) = theP.Shapes(exp.Current());
1011 }
1012 }
1013}
1014
1015
1016
1017//=======================================================================
1018//function : ToFuse
0d969553 1019//purpose : two faces samedomaine or not
7fd59977 1020//=======================================================================
1021
1022Standard_Boolean ToFuse(const TopoDS_Face& F1,
1023 const TopoDS_Face& F2)
1024{
1025 if (F1.IsNull() || F2.IsNull()) {
1026 return Standard_False;
1027 }
1028
1029 Handle(Geom_Surface) S1,S2;
1030 TopLoc_Location loc1, loc2;
1031 Handle(Standard_Type) typS1,typS2;
1032 const Standard_Real tollin = Precision::Confusion();
1033 const Standard_Real tolang = Precision::Angular();
1034
1035 S1 = BRep_Tool::Surface(F1,loc1);
1036 S2 = BRep_Tool::Surface(F2,loc2);
1037
1038 typS1 = S1->DynamicType();
1039 typS2 = S2->DynamicType();
1040
1041 if (typS1 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1042 S1 = (*((Handle(Geom_RectangularTrimmedSurface)*)&S1))->BasisSurface();
1043 typS1 = S1->DynamicType();
1044 }
1045
1046 if (typS2 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1047 S2 = (*((Handle(Geom_RectangularTrimmedSurface)*)&S2))->BasisSurface();
1048 typS2 = S2->DynamicType();
1049 }
1050
1051 if (typS1 != typS2) {
1052 return Standard_False;
1053 }
1054
1055
1056 Standard_Boolean ValRet = Standard_False;
1057 if (typS1 == STANDARD_TYPE(Geom_Plane)) {
0d969553 1058 S1 = BRep_Tool::Surface(F1); // to apply the location.
7fd59977 1059 S2 = BRep_Tool::Surface(F2);
1060 gp_Pln pl1( (*((Handle(Geom_Plane)*)&S1))->Pln());
1061 gp_Pln pl2( (*((Handle(Geom_Plane)*)&S2))->Pln());
1062
1063 if (pl1.Position().IsCoplanar(pl2.Position(),tollin,tolang)) {
1064 ValRet = Standard_True;
1065 }
1066 }
1067
1068 return ValRet;
1069}
1070
1071
1072
1073
1074
1075
1076
1077
1078