1 // Created on: 1996-02-13
2 // Created by: Olga KOULECHOVA
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.
17 #include <BRepFeat_Form.ixx>
20 #include <LocOpe_Gluer.hxx>
21 #include <LocOpe_FindEdges.hxx>
22 #include <LocOpe_CSIntersector.hxx>
23 #include <LocOpe_SequenceOfCirc.hxx>
24 #include <LocOpe_PntFace.hxx>
25 #include <LocOpe_BuildShape.hxx>
27 #include <TopExp_Explorer.hxx>
28 #include <TopOpeBRepBuild_HBuilder.hxx>
29 #include <TopTools_MapOfShape.hxx>
30 #include <TopTools_ListIteratorOfListOfShape.hxx>
31 #include <TopTools_MapIteratorOfMapOfShape.hxx>
32 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
33 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
34 #include <TColgp_SequenceOfPnt.hxx>
35 #include <Standard_NoSuchObject.hxx>
36 #include <Precision.hxx>
38 #include <BRep_Tool.hxx>
39 #include <Geom_RectangularTrimmedSurface.hxx>
40 #include <Geom_Plane.hxx>
41 #include <Geom_CylindricalSurface.hxx>
42 #include <Geom_ConicalSurface.hxx>
44 #include <TopoDS_Solid.hxx>
45 #include <TopoDS_Compound.hxx>
46 #include <BRepTools_Modifier.hxx>
47 #include <BRepTools_TrsfModification.hxx>
48 #include <BRepFeat.hxx>
49 #include <BRepCheck_Analyzer.hxx>
52 #include <Bnd_Box.hxx>
53 #include <BRepBndLib.hxx>
54 #include <BRepLib.hxx>
58 #include <BRepAlgo.hxx>
59 //modified by NIZNHY-PKV Thu Mar 21 17:30:25 2002 f
60 //#include <BRepAlgo_Cut.hxx>
61 //#include <BRepAlgo_Fuse.hxx>
63 #include <BRepAlgoAPI_Cut.hxx>
64 #include <BRepAlgoAPI_Fuse.hxx>
65 #include <BRepFeat_Builder.hxx>
66 //modified by NIZNHY-PKV Thu Mar 21 17:30:29 2002 t
69 extern Standard_Boolean BRepFeat_GettraceFEAT();
72 static void Descendants(const TopoDS_Shape&,
74 TopTools_MapOfShape&);
76 //=======================================================================
78 //purpose : topological reconstruction of the result
79 //=======================================================================
80 void BRepFeat_Form::GlobalPerform ()
84 Standard_Boolean trc = BRepFeat_GettraceFEAT();
85 if (trc) cout << "BRepFeat_Form::GlobalPerform ()" << endl;
88 if (!mySbOK || !myGSOK || !mySFOK || !mySUOK || !myGFOK ||
91 if (trc) cout << " Fields not initialized in BRepFeat_Form" << endl;
93 myStatusError = BRepFeat_NotInitialized;
99 TopExp_Explorer exp,exp2;
100 Standard_Integer theOpe = 2;
101 TopTools_DataMapIteratorOfDataMapOfShapeShape itm;
103 if(myJustFeat && !myFuse) {
105 if (trc) cout << " Invalid option : myJustFeat + Cut" << endl;
107 myStatusError = BRepFeat_InvOption;
111 else if(myJustFeat) {
114 else if (!myGluedF.IsEmpty()) {
118 Standard_Boolean ChangeOpe = Standard_False;
120 Standard_Boolean FromInShape = Standard_False;
121 Standard_Boolean UntilInShape = Standard_False;
123 if (!mySFrom.IsNull()) {
124 FromInShape = Standard_True;
125 for (exp2.Init(mySFrom,TopAbs_FACE); exp2.More(); exp2.Next()) {
126 const TopoDS_Shape& ffrom = exp2.Current();
127 for (exp.Init(mySbase,TopAbs_FACE); exp.More(); exp.Next()) {
128 if (exp.Current().IsSame(ffrom)) {
133 FromInShape = Standard_False;
135 if (trc) cout << " From not in Shape" << endl;
142 if (!mySUntil.IsNull()) {
143 UntilInShape = Standard_True;
144 for (exp2.Init(mySUntil,TopAbs_FACE); exp2.More(); exp2.Next()) {
145 const TopoDS_Shape& funtil = exp2.Current();
146 for (exp.Init(mySbase,TopAbs_FACE); exp.More(); exp.Next()) {
147 if (exp.Current().IsSame(funtil)) {
152 UntilInShape = Standard_False;
154 if (trc) cout << " Until not in Shape" << endl;
161 TopTools_ListIteratorOfListOfShape it,it2;
162 Standard_Integer sens = 0;
164 TColGeom_SequenceOfCurve scur;
167 Standard_Real locmin;
168 Standard_Real locmax;
169 Standard_Real mf, Mf, mu, Mu;
171 TopAbs_Orientation Orifuntil = TopAbs_INTERNAL;
172 TopAbs_Orientation Oriffrom = TopAbs_INTERNAL;
173 TopoDS_Face FFrom,FUntil;
175 LocOpe_CSIntersector ASI1;
176 LocOpe_CSIntersector ASI2;
178 TopTools_ListOfShape IntList;
181 //--- 1) by intersection
183 // Intersection Tool Shape From
184 if (!mySFrom.IsNull()) {
189 // Intersection Tool Shape Until
190 if (!mySUntil.IsNull()) {
196 // Find sens, locmin, locmax, FFrom, FUntil
197 locmin = RealFirst();
199 for (Standard_Integer jj=1; jj<=scur.Length(); jj++) {
200 if (ASI1.IsDone() && ASI2.IsDone()) {
201 if (ASI1.NbPoints(jj) <= 0) {
204 mf = ASI1.Point(jj,1).Parameter();
205 Mf = ASI1.Point(jj,ASI1.NbPoints(jj)).Parameter();
206 if (ASI2.NbPoints(jj) <= 0) {
209 mu = ASI2.Point(jj,1).Parameter();
210 Mu = ASI2.Point(jj,ASI2.NbPoints(jj)).Parameter();
211 if (scur(jj)->IsPeriodic()) {
212 Standard_Real period = scur(jj)->Period();
214 locmax = ElCLib::InPeriod(Mu,locmin,locmin+period);
217 Standard_Integer ku, kf;
218 if (! (mu > Mf || mf > Mu)) { //overlapping intervals
221 ku = ASI2.NbPoints(jj);
223 locmax = Max(Mf, Mu);
227 myStatusError = BRepFeat_IntervalOverlap;
233 ku = ASI2.NbPoints(jj);
239 myStatusError = BRepFeat_IntervalOverlap;
244 kf = ASI1.NbPoints(jj);
249 if (Oriffrom == TopAbs_INTERNAL) {
250 TopAbs_Orientation Oript = ASI1.Point(jj,kf).Orientation();
251 if (Oript == TopAbs_FORWARD || Oript == TopAbs_REVERSED) {
253 Oript = TopAbs::Reverse(Oript);
255 Oriffrom = TopAbs::Reverse(Oript);
256 FFrom = ASI1.Point(jj,kf).Face();
259 if (Orifuntil == TopAbs_INTERNAL) {
260 TopAbs_Orientation Oript = ASI2.Point(jj,ku).Orientation();
261 if (Oript == TopAbs_FORWARD || Oript == TopAbs_REVERSED) {
263 Oript = TopAbs::Reverse(Oript);
266 FUntil = ASI2.Point(jj,ku).Face();
271 else if (ASI2.IsDone()) {
272 if (ASI2.NbPoints(jj) <= 0)
275 // for base case prism on mySUntil -> ambivalent direction
276 // -> preferrable direction = 1
278 if (ASI2.Point(jj,1).Parameter()*
279 ASI2.Point(jj,ASI2.NbPoints(jj)).Parameter()<=0)
281 else if (ASI2.Point(jj,1).Parameter()<0.)
290 locmax = -ASI2.Point(jj,ku).Parameter();
294 ku = ASI2.NbPoints(jj);
296 locmax = ASI2.Point(jj,ku).Parameter();
298 if (Orifuntil == TopAbs_INTERNAL && sens != 0) {
299 TopAbs_Orientation Oript = ASI2.Point(jj,ku).Orientation();
300 if (Oript == TopAbs_FORWARD || Oript == TopAbs_REVERSED) {
302 Oript = TopAbs::Reverse(Oript);
305 FUntil = ASI2.Point(jj,ku).Face();
318 LocOpe_Gluer theGlue;
324 if (trc) cout << " Gluer" << endl;
326 Standard_Boolean Collage = Standard_True;
327 // cut by FFrom && FUntil
330 B.MakeCompound(TopoDS::Compound(Comp));
331 if (!mySFrom.IsNull()) {
332 TopoDS_Solid S = BRepFeat::Tool(mySFrom,FFrom,Oriffrom);
337 if (!mySUntil.IsNull()) {
338 TopoDS_Solid S = BRepFeat::Tool(mySUntil,FUntil,Orifuntil);
344 LocOpe_FindEdges theFE;
345 TopTools_DataMapOfShapeListOfShape locmap;
346 TopExp_Explorer expp(Comp, TopAbs_SOLID);
347 if(expp.More() && !Comp.IsNull() && !myGShape.IsNull()) {
348 //modified by NIZNHY-PKV Thu Mar 21 17:15:36 2002 f
349 //BRepAlgo_Cut trP(myGShape,Comp);
350 BRepAlgoAPI_Cut trP(myGShape, Comp);
351 //modified by NIZNHY-PKV Thu Mar 21 17:15:58 2002 t
352 exp.Init(trP.Shape(), TopAbs_SOLID);
353 if (exp.Current().IsNull()) {
355 ChangeOpe = Standard_True;
356 Collage = Standard_False;
359 // Only solids are preserved
360 TopoDS_Shape theGShape;
362 B.MakeCompound(TopoDS::Compound(theGShape));
363 for (; exp.More(); exp.Next()) {
364 B.Add(theGShape,exp.Current());
366 if (!BRepAlgo::IsValid(theGShape)) {
368 ChangeOpe = Standard_True;
369 Collage = Standard_False;
372 if(!mySFrom.IsNull()) {
374 ex.Init(mySFrom, TopAbs_FACE);
375 for(; ex.More(); ex.Next()) {
376 const TopoDS_Face& fac = TopoDS::Face(ex.Current());
378 TopTools_ListOfShape thelist;
379 myMap.Bind(fac, thelist);
382 TopTools_ListOfShape thelist1;
383 locmap.Bind(fac, thelist1);
385 if (trP.IsDeleted(fac)) {
387 else if (!FromInShape) {
388 myMap(fac) = trP.Modified(fac);
389 if (myMap(fac).IsEmpty()) myMap(fac).Append(fac);
392 locmap(fac) =trP.Modified(fac) ;
393 if (locmap(fac).IsEmpty()) locmap(fac).Append(fac);
396 }// if(!mySFrom.IsNull())
398 if(!mySUntil.IsNull()) {
400 ex.Init(mySUntil, TopAbs_FACE);
401 for(; ex.More(); ex.Next()) {
402 const TopoDS_Face& fac = TopoDS::Face(ex.Current());
404 TopTools_ListOfShape thelist2;
405 myMap.Bind(fac,thelist2);
408 TopTools_ListOfShape thelist3;
409 locmap.Bind(fac,thelist3);
411 if (trP.IsDeleted(fac)) {
413 else if (!UntilInShape) {
414 myMap(fac) = trP.Modified(fac);
415 if (myMap(fac).IsEmpty()) myMap(fac).Append(fac);
418 locmap(fac) = trP.Modified(fac);
419 if (locmap(fac).IsEmpty()) locmap(fac).Append(fac);
422 }// if(!mySUntil.IsNull())
424 //modified by NIZNHY-PKV Thu Mar 21 17:21:49 2002 f
425 //UpdateDescendants(trP.Builder(),theGShape,Standard_True); // skip faces
426 UpdateDescendants(trP,theGShape,Standard_True); // skip faces
427 //modified by NIZNHY-PKV Thu Mar 21 17:22:32 2002 t
429 theGlue.Init(mySbase,theGShape);
430 for (itm.Initialize(myGluedF);itm.More();itm.Next()) {
431 const TopoDS_Face& gl = TopoDS::Face(itm.Key());
432 TopTools_ListOfShape ldsc;
433 if (trP.IsDeleted(gl)) {
436 ldsc = trP.Modified(gl);
437 if (ldsc.IsEmpty()) ldsc.Append(gl);
439 const TopoDS_Face& glface = TopoDS::Face(itm.Value());
440 for (it.Initialize(ldsc);it.More();it.Next()) {
441 const TopoDS_Face& fac = TopoDS::Face(it.Value());
442 Collage = BRepFeat::IsInside(fac, glface);
445 ChangeOpe = Standard_True;
449 theGlue.Bind(fac,glface);
450 theFE.Set(fac,glface);
451 for (theFE.InitIterator(); theFE.More();theFE.Next()) {
452 theGlue.Bind(theFE.EdgeFrom(),theFE.EdgeTo());
459 }// if(expp.More() && !Comp.IsNull() && !myGShape.IsNull())
461 theGlue.Init(mySbase,myGShape);
462 for (itm.Initialize(myGluedF); itm.More();itm.Next()) {
463 const TopoDS_Face& glface = TopoDS::Face(itm.Key());
464 const TopoDS_Face& fac = TopoDS::Face(myGluedF(glface));
465 for (exp.Init(myGShape,TopAbs_FACE); exp.More(); exp.Next()) {
466 if (exp.Current().IsSame(glface)) {
471 Collage = BRepFeat::IsInside(glface, fac);
474 ChangeOpe = Standard_True;
478 theGlue.Bind(glface, fac);
479 theFE.Set(glface, fac);
480 for (theFE.InitIterator(); theFE.More();theFE.Next()) {
481 theGlue.Bind(theFE.EdgeFrom(),theFE.EdgeTo());
488 // Add gluing on start and end face if necessary !!!
489 if (FromInShape && Collage) {
490 TopExp_Explorer ex(mySFrom,TopAbs_FACE);
491 for(; ex.More(); ex.Next()) {
492 const TopoDS_Face& fac2 = TopoDS::Face(ex.Current());
493 // for (it.Initialize(myMap(fac2)); it.More(); it.Next()) {
494 for (it.Initialize(locmap(fac2)); it.More(); it.Next()) {
495 const TopoDS_Face& fac1 = TopoDS::Face(it.Value());
496 theFE.Set(fac1, fac2);
497 theGlue.Bind(fac1, fac2);
498 for (theFE.InitIterator(); theFE.More();theFE.Next()) {
499 theGlue.Bind(theFE.EdgeFrom(),theFE.EdgeTo());
502 // myMap.UnBind(fac2);
506 if (UntilInShape && Collage) {
507 TopExp_Explorer ex(mySUntil, TopAbs_FACE);
508 for(; ex.More(); ex.Next()) {
509 const TopoDS_Face& fac2 = TopoDS::Face(ex.Current());
510 // for (it.Initialize(myMap(fac2)); it.More(); it.Next()) {
511 for (it.Initialize(locmap(fac2)); it.More(); it.Next()) {
512 const TopoDS_Face& fac1 = TopoDS::Face(it.Value());
513 theGlue.Bind(fac1, fac2);
514 theFE.Set(fac1, fac2);
515 for (theFE.InitIterator(); theFE.More();theFE.Next()) {
516 theGlue.Bind(theFE.EdgeFrom(),theFE.EdgeTo());
519 //myMap.UnBind(fac2); // to avoid fac2 in Map when
520 // UpdateDescendants(theGlue) is called
524 LocOpe_Operation ope = theGlue.OpeType();
525 if (ope == LocOpe_INVALID ||
526 (myFuse && ope != LocOpe_FUSE) ||
527 (!myFuse && ope != LocOpe_CUT) ||
530 ChangeOpe = Standard_True;
534 //--- if the gluing is always applicable
538 if (trc) cout << " still Gluer" << endl;
541 if (theGlue.IsDone()) {
542 TopoDS_Shape shshs = theGlue.ResultingShape();
543 // if (BRepOffsetAPI::IsTopologicallyValid(shshs)) {
544 if (BRepAlgo::IsValid(shshs)) {
545 UpdateDescendants(theGlue);
546 myNewEdges = theGlue.Edges();
547 myTgtEdges = theGlue.TgtEdges();
549 if (trc) cout << " Gluer result" << endl;
552 myShape = theGlue.ResultingShape();
556 ChangeOpe = Standard_True;
561 ChangeOpe = Standard_True;
566 //--- case without gluing + Tool with proper dimensions
568 if (theOpe == 2 && ChangeOpe && myJustGluer) {
570 if (trc) cout << " Gluer failure" << endl;
572 myJustGluer = Standard_False;
578 //--- case without gluing
582 if (trc) cout << " No Gluer" << endl;
584 TopoDS_Shape theGShape = myGShape;
587 if (trc) cout << " Passage to topological operations" << endl;
593 B.MakeCompound(TopoDS::Compound(Comp));
594 if (!mySFrom.IsNull() || !mySUntil.IsNull()) {
595 if (!mySFrom.IsNull() && !FromInShape) {
596 TopoDS_Solid S = BRepFeat::Tool(mySFrom,FFrom,Oriffrom);
601 if (!mySUntil.IsNull() && !UntilInShape) {
602 if (!mySFrom.IsNull()) {
603 if (!mySFrom.IsSame(mySUntil)) {
604 TopoDS_Solid S = BRepFeat::Tool(mySUntil,FUntil,Orifuntil);
611 TopoDS_Solid S = BRepFeat::Tool(mySUntil,FUntil,Orifuntil);
619 // update type of selection
620 if(myPerfSelection == BRepFeat_SelectionU && !UntilInShape) {
621 myPerfSelection = BRepFeat_NoSelection;
623 else if(myPerfSelection == BRepFeat_SelectionFU &&
624 !FromInShape && !UntilInShape) {
625 myPerfSelection = BRepFeat_NoSelection;
627 else if(myPerfSelection == BRepFeat_SelectionShU && !UntilInShape) {
628 myPerfSelection = BRepFeat_NoSelection;
632 TopExp_Explorer expp(Comp, TopAbs_SOLID);
633 if(expp.More() && !Comp.IsNull() && !myGShape.IsNull()) {
634 //modified by NIZNHY-PKV Thu Mar 21 17:24:52 2002 f
635 //BRepAlgo_Cut trP(myGShape,Comp);
636 BRepAlgoAPI_Cut trP(myGShape, Comp);
637 //modified by NIZNHY-PKV Thu Mar 21 17:24:56 2002 t
638 // the result is necessarily a compound.
639 exp.Init(trP.Shape(),TopAbs_SOLID);
641 myStatusError = BRepFeat_EmptyCutResult;
645 // Only solids are preserved
648 B.MakeCompound(TopoDS::Compound(theGShape));
649 for (; exp.More(); exp.Next()) {
650 B.Add(theGShape,exp.Current());
652 if (!BRepAlgo::IsValid(theGShape)) {
653 myStatusError = BRepFeat_InvShape;
657 if(!mySFrom.IsNull()) {
659 TopExp_Explorer ex(mySFrom, TopAbs_FACE);
660 for(; ex.More(); ex.Next()) {
661 const TopoDS_Face& fac = TopoDS::Face(ex.Current());
662 TopTools_ListOfShape thelist4;
663 myMap.Bind(fac,thelist4);
664 if (trP.IsDeleted(fac)) {
667 myMap(fac) = trP.Modified(fac);
668 if (myMap(fac).IsEmpty()) myMap(fac).Append(fac);
673 if(!mySUntil.IsNull()) {
675 TopExp_Explorer ex(mySUntil, TopAbs_FACE);
676 for(; ex.More(); ex.Next()) {
677 const TopoDS_Face& fac = TopoDS::Face(ex.Current());
678 TopTools_ListOfShape thelist5;
679 myMap.Bind(fac,thelist5);
680 if (trP.IsDeleted(fac)) {
683 myMap(fac) = trP.Modified(fac);
684 if (myMap.IsEmpty()) myMap(fac).Append(fac);
689 //modified by NIZNHY-PKV Thu Mar 21 17:27:23 2002 f
690 //UpdateDescendants(trP.Builder(),theGShape,Standard_True);
691 UpdateDescendants(trP,theGShape,Standard_True);
692 //modified by NIZNHY-PKV Thu Mar 21 17:27:31 2002 t
693 }//if(expp.More() && !Comp.IsNull() && !myGShape.IsNull()) {
696 //--- generation of "just feature" for assembly = Parts of tool
697 Standard_Boolean bFlag = (myPerfSelection == BRepFeat_NoSelection) ? 0 : 1;
698 BRepFeat_Builder theBuilder;
699 theBuilder.Init(mySbase, theGShape);
700 theBuilder.SetOperation(myFuse, bFlag);
701 theBuilder.Perform();
703 TopTools_ListOfShape lshape;
704 theBuilder.PartsOfTool(lshape);
706 Standard_Real pbmin = RealLast(), pbmax = RealFirst();
707 Standard_Real prmin = RealLast() - 2*Precision::Confusion();
708 Standard_Real prmax = RealFirst() + 2*Precision::Confusion();
709 Standard_Boolean flag1 = Standard_False;
710 Handle(Geom_Curve) C;
712 //--- Selection of pieces of tool to be preserved
713 if(!lshape.IsEmpty() && myPerfSelection != BRepFeat_NoSelection) {
714 // Find ParametricMinMax depending on the constraints of Shape From and Until
715 // -> prmin, prmax, pbmin and pbmax
718 myStatusError = BRepFeat_EmptyBaryCurve;
723 if(myPerfSelection == BRepFeat_SelectionSh) {
724 BRepFeat::ParametricMinMax(mySbase,C,
725 prmin, prmax, pbmin, pbmax, flag1);
727 else if(myPerfSelection == BRepFeat_SelectionFU) {
728 Standard_Real prmin1, prmax1, prmin2, prmax2;
729 Standard_Real prbmin1, prbmax1, prbmin2, prbmax2;
731 BRepFeat::ParametricMinMax(mySFrom,C,
732 prmin1, prmax1, prbmin1, prbmax1, flag1);
733 BRepFeat::ParametricMinMax(mySUntil,C,
734 prmin2, prmax2, prbmin2, prbmax2, flag1);
736 // case of revolutions
737 if (C->IsPeriodic()) {
738 Standard_Real period = C->Period();
741 prmin = ElCLib::InPeriod(prmin1,prmax-period,prmax);
744 prmin = Min(prmin1, prmin2);
747 pbmin = ElCLib::InPeriod(prbmin1,pbmax-period,pbmax);
750 prmin = Min(prmin1, prmin2);
751 prmax = Max(prmax1, prmax2);
752 pbmin = Min(prbmin1, prbmin2);
753 pbmax = Max(prbmax1, prbmax2);
756 else if(myPerfSelection == BRepFeat_SelectionShU) {
757 Standard_Real prmin1, prmax1, prmin2, prmax2;
758 Standard_Real prbmin1, prbmax1, prbmin2, prbmax2;
760 if(!myJustFeat && sens == 0) sens =1;
762 myStatusError = BRepFeat_IncDirection;
767 BRepFeat::ParametricMinMax(mySUntil,C,
768 prmin1, prmax1, prbmin1, prbmax1, flag1);
770 BRepFeat::ParametricMinMax(mySbase,C,
771 prmin2, prmax2, prbmin2, prbmax2, flag1);
778 else if (sens == -1) {
785 else if (myPerfSelection == BRepFeat_SelectionU) {
786 Standard_Real prmin1, prmax1, prbmin1, prbmax1;
788 myStatusError = BRepFeat_IncDirection;
793 // Find parts of the tool containing descendants of Shape Until
794 BRepFeat::ParametricMinMax(mySUntil,C,
795 prmin1, prmax1, prbmin1, prbmax1, flag1);
802 else if(sens == -1) {
811 // Finer choice of ParametricMinMax in case when the tool
812 // intersects Shapes From and Until
813 // case of several intersections (keep PartsOfTool according to the selection)
814 // position of the face of intersection in PartsOfTool (before or after)
815 Standard_Real delta = Precision::Confusion();
817 if (myPerfSelection != BRepFeat_NoSelection) {
818 // modif of the test for cts21181 : (prbmax2 and prnmin2) -> (prbmin1 and prbmax1)
819 // correction take into account flag2 for pro15323 and flag3 for pro16060
820 if (!mySUntil.IsNull()) {
821 TopTools_MapOfShape mapFuntil;
822 Descendants(mySUntil,theBuilder,mapFuntil);
823 if (!mapFuntil.IsEmpty()) {
824 for (it.Initialize(lshape); it.More(); it.Next()) {
825 TopExp_Explorer expf;
826 for (expf.Init(it.Value(),TopAbs_FACE);
827 expf.More(); expf.Next()) {
828 if (mapFuntil.Contains(expf.Current())) {
829 Standard_Boolean flag2,flag3;
830 Standard_Real prmin1, prmax1, prbmin1, prbmax1;
831 Standard_Real prmin2, prmax2, prbmin2, prbmax2;
832 BRepFeat::ParametricMinMax(expf.Current(),C, prmin1, prmax1,
833 prbmin1, prbmax1,flag3);
834 BRepFeat::ParametricMinMax(it.Value(),C, prmin2, prmax2,
835 prbmin2, prbmax2,flag2);
837 Standard_Boolean testOK = !flag2;
840 if (flag1 && prmax2 > prmin + delta) {
842 if (flag3 && prmax1 == prmax2) {
843 testOK = Standard_True;
847 if (prbmin1 < pbmax && testOK) {
855 else if (sens == -1){
856 Standard_Boolean testOK = !flag2;
859 if (flag1 && prmin2 < prmax - delta) {
861 if (flag3 && prmin1 == prmin2) {
862 testOK = Standard_True;
866 if (prbmax1 > pbmin && testOK) {
878 it.Initialize(lshape);
881 if (!mySFrom.IsNull()) {
882 TopTools_MapOfShape mapFfrom;
883 Descendants(mySFrom, theBuilder, mapFfrom);
884 if (!mapFfrom.IsEmpty()) {
885 for (it.Initialize(lshape); it.More(); it.Next()) {
886 TopExp_Explorer expf;
887 for (expf.Init(it.Value(),TopAbs_FACE);
888 expf.More(); expf.Next()) {
889 if (mapFfrom.Contains(expf.Current())) {
890 Standard_Boolean flag2,flag3;
891 Standard_Real prmin1, prmax1, prbmin1, prbmax1;
892 Standard_Real prmin2, prmax2, prbmin2, prbmax2;
893 BRepFeat::ParametricMinMax(expf.Current(),C, prmin1, prmax1,
894 prbmin1, prbmax1,flag3);
895 BRepFeat::ParametricMinMax(it.Value(),C, prmin2, prmax2,
896 prbmin2, prbmax2,flag2);
898 Standard_Boolean testOK = !flag2;
901 if (flag1 && prmin2 < prmax - delta) {
903 if (flag3 && prmin1 == prmin2) {
904 testOK = Standard_True;
908 if (prbmax1 > pbmin && testOK) {
916 else if (sens == -1){
917 Standard_Boolean testOK = !flag2;
920 if (flag1 && prmax2 > prmin + delta) {
922 if (flag3 && prmax1 == prmax2) {
923 testOK = Standard_True;
927 if (prbmin1 < pbmax && testOK) {
939 it.Initialize(lshape);
945 // Parse PartsOfTool to preserve or not depending on ParametricMinMax
947 Standard_Boolean KeepParts = Standard_False;
948 Standard_Real prmin1, prmax1, prbmin1, prbmax1;
949 Standard_Real min, max, pmin, pmax;
950 Standard_Boolean flag2;
951 for (it.Initialize(lshape); it.More(); it.Next()) {
952 if (C->IsPeriodic()) {
953 Standard_Real period = C->Period();
954 Standard_Real pr, prb;
955 BRepFeat::ParametricMinMax(it.Value(),C, pr, prmax1,
956 prb, prbmax1,flag2,Standard_True);
958 prmin1 = ElCLib::InPeriod(pr,prmax1-period,prmax1);
963 prbmin1 = ElCLib::InPeriod(prb,prbmax1-period,prbmax1);
966 BRepFeat::ParametricMinMax(it.Value(),C,
967 prmin1, prmax1, prbmin1, prbmax1,flag2);
969 if(flag2 == Standard_False || flag1 == Standard_False) {
981 if (!((min > pmax - delta) ||
982 (max < pmin + delta))) {
983 KeepParts = Standard_True;
984 const TopoDS_Shape& S = it.Value();
985 theBuilder.KeepPart(S);
989 // Case when no part of the tool is preserved
992 if (trc) cout << " No parts of tool kept" << endl;
994 myStatusError = BRepFeat_NoParts;
1000 // case JustFeature -> all PartsOfTool are preserved
1001 Standard_Real prmin1, prmax1, prbmin1, prbmax1;
1002 Standard_Real min, max, pmin, pmax;
1003 Standard_Boolean flag2;
1006 B.MakeCompound(TopoDS::Compound(Compo));
1007 for (it.Initialize(lshape); it.More(); it.Next()) {
1008 BRepFeat::ParametricMinMax(it.Value(),C,
1009 prmin1, prmax1, prbmin1, prbmax1,flag2);
1010 if(flag2 == Standard_False || flag1 == Standard_False) {
1022 if ((min < pmax - delta) &&
1023 (max > pmin + delta)){
1024 if (!it.Value().IsNull()) {
1025 B.Add(Compo,it.Value());
1033 //--- Generation of result myShape
1036 // removal of edges of section that have no common vertices
1037 // with PartsOfTool preserved
1038 //modified by NIZHNY-EMV Thu May 10 15:56:24 2012
1040 theBuilder.PerformResult();
1041 myShape = theBuilder.Shape();
1043 myShape = theBuilder.Shape();
1045 //modified by NIZHNY-EMV Thu May 10 15:56:26 2012
1049 // all is already done
1054 myStatusError = BRepFeat_OK;
1057 //=======================================================================
1058 //function : IsDeleted
1060 //=======================================================================
1062 Standard_Boolean BRepFeat_Form::IsDeleted(const TopoDS_Shape& F)
1064 return (myMap(F).IsEmpty());
1067 //=======================================================================
1068 //function : Modified
1070 //=======================================================================
1072 const TopTools_ListOfShape& BRepFeat_Form::Modified
1073 (const TopoDS_Shape& F)
1075 if (myMap.IsBound(F)) {
1076 static TopTools_ListOfShape list;
1077 list.Clear(); // For the second passage DPF
1078 TopTools_ListIteratorOfListOfShape ite(myMap(F));
1079 for(; ite.More(); ite.Next()) {
1080 const TopoDS_Shape& sh = ite.Value();
1086 return myGenerated; // empty list
1089 //=======================================================================
1090 //function : Generated
1092 //=======================================================================
1094 const TopTools_ListOfShape& BRepFeat_Form::Generated
1095 (const TopoDS_Shape& S)
1097 if (myMap.IsBound(S) &&
1098 S.ShapeType() != TopAbs_FACE) { // check if filter on face or not
1099 static TopTools_ListOfShape list;
1100 list.Clear(); // For the second passage DPF
1101 TopTools_ListIteratorOfListOfShape ite(myMap(S));
1102 for(; ite.More(); ite.Next()) {
1103 const TopoDS_Shape& sh = ite.Value();
1109 else return myGenerated;
1114 //=======================================================================
1115 //function : UpdateDescendants
1117 //=======================================================================
1119 void BRepFeat_Form::UpdateDescendants(const LocOpe_Gluer& G)
1121 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itdm;
1122 TopTools_ListIteratorOfListOfShape it,it2;
1123 TopTools_MapIteratorOfMapOfShape itm;
1125 for (itdm.Initialize(myMap);itdm.More();itdm.Next()) {
1126 const TopoDS_Shape& orig = itdm.Key();
1127 TopTools_MapOfShape newdsc;
1128 for (it.Initialize(itdm.Value());it.More();it.Next()) {
1129 const TopoDS_Face& fdsc = TopoDS::Face(it.Value());
1130 for (it2.Initialize(G.DescendantFaces(fdsc));
1131 it2.More();it2.Next()) {
1132 newdsc.Add(it2.Value());
1135 myMap.ChangeFind(orig).Clear();
1136 for (itm.Initialize(newdsc);itm.More();itm.Next()) {
1137 myMap.ChangeFind(orig).Append(itm.Key());
1146 //=======================================================================
1147 //function : FirstShape
1149 //=======================================================================
1151 const TopTools_ListOfShape& BRepFeat_Form::FirstShape() const
1153 if (!myFShape.IsNull()) {
1154 return myMap(myFShape);
1156 return myGenerated; // empty list
1160 //=======================================================================
1161 //function : LastShape
1163 //=======================================================================
1165 const TopTools_ListOfShape& BRepFeat_Form::LastShape() const
1167 if (!myLShape.IsNull()) {
1168 return myMap(myLShape);
1170 return myGenerated; // empty list
1174 //=======================================================================
1175 //function : NewEdges
1177 //=======================================================================
1179 const TopTools_ListOfShape& BRepFeat_Form::NewEdges() const
1185 //=======================================================================
1186 //function : NewEdges
1188 //=======================================================================
1190 const TopTools_ListOfShape& BRepFeat_Form::TgtEdges() const
1196 //=======================================================================
1197 //function : TransformSUntil
1198 //purpose : Limitation of the shape until the case of infinite faces
1199 //=======================================================================
1201 Standard_Boolean BRepFeat_Form::TransformShapeFU(const Standard_Integer flag)
1204 Standard_Boolean trc = BRepFeat_GettraceFEAT();
1206 Standard_Boolean Trf = Standard_False;
1208 TopoDS_Shape shapefu;
1216 TopExp_Explorer exp(shapefu, TopAbs_FACE);
1217 if (!exp.More()) { // no faces... It is necessary to return an error
1219 if (trc) cout << " BRepFeat_Form::TransformShapeFU : invalid Shape" << endl;
1225 if (!exp.More()) { // the only face. Is it infinite?
1227 TopoDS_Face fac = TopoDS::Face(exp.Current());
1229 Handle(Geom_Surface) S = BRep_Tool::Surface(fac);
1230 Handle(Standard_Type) styp = S->DynamicType();
1231 if (styp == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1232 S = Handle(Geom_RectangularTrimmedSurface)::DownCast(S)->BasisSurface();
1233 styp = S->DynamicType();
1236 if (styp == STANDARD_TYPE(Geom_Plane) ||
1237 styp == STANDARD_TYPE(Geom_CylindricalSurface) ||
1238 styp == STANDARD_TYPE(Geom_ConicalSurface)) {
1239 TopExp_Explorer exp1(fac, TopAbs_WIRE);
1241 Trf = Standard_True;
1244 Trf = BRep_Tool::NaturalRestriction(fac);
1249 BRepFeat::FaceUntil(mySbase, fac);
1253 TopTools_ListOfShape thelist6;
1254 myMap.Bind(mySFrom,thelist6);
1255 myMap(mySFrom).Append(fac);
1258 else if(flag == 1) {
1259 TopTools_ListOfShape thelist7;
1260 myMap.Bind(mySUntil,thelist7);
1261 myMap(mySUntil).Append(fac);
1268 for (exp.ReInit(); exp.More(); exp.Next()) {
1269 const TopoDS_Shape& fac = exp.Current();
1270 TopTools_ListOfShape thelist8;
1271 myMap.Bind(fac,thelist8);
1272 myMap(fac).Append(fac);
1277 if (Trf && (flag == 0)) cout << " TransformShapeFU From" << endl;
1278 if (Trf && (flag == 1)) cout << " TransformShapeFU Until" << endl;
1285 //=======================================================================
1286 //function : CurrentStatusError
1288 //=======================================================================
1290 BRepFeat_StatusError BRepFeat_Form::CurrentStatusError() const
1292 return myStatusError;
1295 //=======================================================================
1296 //function : Descendants
1298 //=======================================================================
1300 static void Descendants(const TopoDS_Shape& S,
1301 BRepFeat_Builder& theFB,
1302 TopTools_MapOfShape& mapF)
1305 TopTools_ListIteratorOfListOfShape it;
1306 TopExp_Explorer exp;
1307 for (exp.Init(S,TopAbs_FACE); exp.More(); exp.Next()) {
1309 const TopoDS_Face& fdsc = TopoDS::Face(exp.Current());
1310 const TopTools_ListOfShape& aLM=theFB.Modified(fdsc);
1312 for (; it.More(); it.Next()) {
1313 mapF.Add(it.Value());
1319 //=======================================================================
1320 //function : UpdateDescendants
1322 //=======================================================================
1323 void BRepFeat_Form::UpdateDescendants(const Handle(TopOpeBRepBuild_HBuilder)& B,
1324 const TopoDS_Shape& S,
1325 const Standard_Boolean SkipFace)
1327 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itdm;
1328 TopTools_ListIteratorOfListOfShape it,it2;
1329 TopTools_MapIteratorOfMapOfShape itm;
1330 TopExp_Explorer exp;
1332 for (itdm.Initialize(myMap);itdm.More();itdm.Next()) {
1333 const TopoDS_Shape& orig = itdm.Key();
1334 if (SkipFace && orig.ShapeType() == TopAbs_FACE) {
1337 TopTools_MapOfShape newdsc;
1339 if (itdm.Value().IsEmpty()) {myMap.ChangeFind(orig).Append(orig);}
1341 for (it.Initialize(itdm.Value());it.More();it.Next()) {
1342 const TopoDS_Shape& sh = it.Value();
1343 if(sh.ShapeType() != TopAbs_FACE) continue;
1344 const TopoDS_Face& fdsc = TopoDS::Face(it.Value());
1345 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
1346 if (exp.Current().IsSame(fdsc)) { // preserved
1352 if (B->IsSplit(fdsc, TopAbs_OUT)) {
1353 for (it2.Initialize(B->Splits(fdsc,TopAbs_OUT));
1354 it2.More();it2.Next()) {
1355 newdsc.Add(it2.Value());
1358 if (B->IsSplit(fdsc, TopAbs_IN)) {
1359 for (it2.Initialize(B->Splits(fdsc,TopAbs_IN));
1360 it2.More();it2.Next()) {
1361 newdsc.Add(it2.Value());
1364 if (B->IsSplit(fdsc, TopAbs_ON)) {
1365 for (it2.Initialize(B->Splits(fdsc,TopAbs_ON));
1366 it2.More();it2.Next()) {
1367 newdsc.Add(it2.Value());
1370 if (B->IsMerged(fdsc, TopAbs_OUT)) {
1371 for (it2.Initialize(B->Merged(fdsc,TopAbs_OUT));
1372 it2.More();it2.Next()) {
1373 newdsc.Add(it2.Value());
1376 if (B->IsMerged(fdsc, TopAbs_IN)) {
1377 for (it2.Initialize(B->Merged(fdsc,TopAbs_IN));
1378 it2.More();it2.Next()) {
1379 newdsc.Add(it2.Value());
1382 if (B->IsMerged(fdsc, TopAbs_ON)) {
1383 for (it2.Initialize(B->Merged(fdsc,TopAbs_ON));
1384 it2.More();it2.Next()) {
1385 newdsc.Add(it2.Value());
1390 myMap.ChangeFind(orig).Clear();
1391 for (itm.Initialize(newdsc); itm.More(); itm.Next()) {
1392 // check the appartenance to the shape...
1393 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
1394 if (exp.Current().IsSame(itm.Key())) {
1395 // const TopoDS_Shape& sh = itm.Key();
1396 myMap.ChangeFind(orig).Append(itm.Key());
1403 //modified by NIZNHY-PKV Thu Mar 21 18:43:18 2002 f
1404 //=======================================================================
1405 //function : UpdateDescendants
1407 //=======================================================================
1408 void BRepFeat_Form::UpdateDescendants(const BRepAlgoAPI_BooleanOperation& aBOP,
1409 const TopoDS_Shape& S,
1410 const Standard_Boolean SkipFace)
1412 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itdm;
1413 TopTools_ListIteratorOfListOfShape it,it2;
1414 TopTools_MapIteratorOfMapOfShape itm;
1415 TopExp_Explorer exp;
1417 for (itdm.Initialize(myMap);itdm.More();itdm.Next()) {
1418 const TopoDS_Shape& orig = itdm.Key();
1419 if (SkipFace && orig.ShapeType() == TopAbs_FACE) {
1422 TopTools_MapOfShape newdsc;
1424 if (itdm.Value().IsEmpty()) {myMap.ChangeFind(orig).Append(orig);}
1426 for (it.Initialize(itdm.Value());it.More();it.Next()) {
1427 const TopoDS_Shape& sh = it.Value();
1428 if(sh.ShapeType() != TopAbs_FACE) continue;
1429 const TopoDS_Face& fdsc = TopoDS::Face(it.Value());
1430 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
1431 if (exp.Current().IsSame(fdsc)) { // preserved
1437 BRepAlgoAPI_BooleanOperation* pBOP=(BRepAlgoAPI_BooleanOperation*)&aBOP;
1438 const TopTools_ListOfShape& aLM=pBOP->Modified(fdsc);
1439 it2.Initialize(aLM);
1440 for (; it2.More(); it2.Next()) {
1441 const TopoDS_Shape& aS=it2.Value();
1447 myMap.ChangeFind(orig).Clear();
1448 for (itm.Initialize(newdsc); itm.More(); itm.Next()) {
1449 // check the appartenance to the shape...
1450 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
1451 if (exp.Current().IsSame(itm.Key())) {
1452 // const TopoDS_Shape& sh = itm.Key();
1453 myMap.ChangeFind(orig).Append(itm.Key());
1460 //modified by NIZNHY-PKV Thu Mar 21 18:43:36 2002 t