1 // Created on: 1996-09-03
2 // Created by: Olga KOULECHOVA
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
23 #include <BRepFeat_MakeDPrism.ixx>
25 #include <BRepFeat.hxx>
27 #include <LocOpe_CSIntersector.hxx>
28 #include <TColGeom_SequenceOfCurve.hxx>
29 #include <LocOpe_DPrism.hxx>
30 #include <LocOpe_SequenceOfLin.hxx>
31 #include <LocOpe_PntFace.hxx>
35 #include <gp_Pnt2d.hxx>
38 #include <Precision.hxx>
40 #include <Geom_Surface.hxx>
41 #include <Geom_Curve.hxx>
42 #include <Geom_Line.hxx>
43 #include <Geom2d_Curve.hxx>
44 #include <Geom_Plane.hxx>
45 #include <Geom_RectangularTrimmedSurface.hxx>
46 #include <TColgp_SequenceOfPnt.hxx>
47 #include <TColGeom_SequenceOfCurve.hxx>
48 #include <Bnd_Box.hxx>
50 #include <BRepBndLib.hxx>
51 #include <BRep_Builder.hxx>
52 #include <BRep_Tool.hxx>
53 #include <BRepTools.hxx>
54 #include <BRepPrimAPI_MakeBox.hxx>
55 #include <BRepLib.hxx>
57 #include <BRepAlgo.hxx>
58 //modified by NIZNHY-PKV Thu Mar 21 17:49:46 2002 f
59 //#include <BRepAlgo_Cut.hxx>
60 //#include <BRepAlgo_Fuse.hxx>
61 #include <BRepAlgoAPI_Cut.hxx>
62 #include <BRepAlgoAPI_Fuse.hxx>
63 //modified by NIZNHY-PKV Thu Mar 21 17:50:04 2002 t
65 #include <BRepLib_MakeFace.hxx>
67 #include <TopExp_Explorer.hxx>
68 #include <TopTools_MapOfShape.hxx>
69 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
70 #include <TopTools_ListIteratorOfListOfShape.hxx>
71 #include <TopTools_MapIteratorOfMapOfShape.hxx>
72 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
73 #include <TopoDS_Solid.hxx>
74 #include <TopoDS_Compound.hxx>
75 #include <TopoDS_Shell.hxx>
76 #include <TopoDS_Shape.hxx>
77 #include <TopoDS_Face.hxx>
80 #include <Standard_ConstructionError.hxx>
84 #include <BRepFeat.hxx>
88 extern Standard_Boolean BRepFeat_GettraceFEAT();
91 static void MajMap(const TopoDS_Shape&,
93 TopTools_DataMapOfShapeListOfShape&, // myMap
94 TopoDS_Shape&, // myFShape
95 TopoDS_Shape&); // myLShape
97 static Standard_Real HeightMax(const TopoDS_Shape& theSbase,
98 const TopoDS_Face& theSkface,
99 const TopoDS_Shape& theSFrom,
100 const TopoDS_Shape& theSUntil);
102 static Standard_Integer SensOfPrism(const Handle(Geom_Curve) C,
103 const TopoDS_Shape& Until);
105 static Handle(Geom_Curve) TestCurve(const TopoDS_Face&);
107 static Standard_Boolean ToFuse(const TopoDS_Face& ,
112 //=======================================================================
115 //=======================================================================
117 void BRepFeat_MakeDPrism::Init(const TopoDS_Shape& Sbase,
118 const TopoDS_Face& Pbase,
119 const TopoDS_Face& Skface,
120 const Standard_Real Angle,
121 const Standard_Integer Mode,
122 const Standard_Boolean Modify)
126 Standard_Boolean trc = BRepFeat_GettraceFEAT();
127 if (trc) cout << "BRepFeat_MakeDPrism::Init" << endl;
136 myFuse = Standard_False;
137 myJustFeat = Standard_False;
140 myFuse = Standard_True;
141 myJustFeat = Standard_False;
144 myFuse = Standard_True;
145 myJustFeat = Standard_True;
150 myJustGluer = Standard_False;
154 //mySkface.Nullify();
164 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
165 TopTools_ListOfShape thelist;
166 myMap.Bind(exp.Current(), thelist);
167 myMap(exp.Current()).Append(exp.Current());
172 if (myJustFeat) cout << " Just Feature" << endl;
173 if (myFuse) cout << " Fuse" << endl;
174 if (!myFuse) cout << " Cut" << endl;
175 if (!myModify) cout << " Modify = 0" << endl;
176 // cout <<" Angle = " << myAngle << endl;
182 //=======================================================================
184 //purpose : add sliding faces and edges
185 //=======================================================================
187 void BRepFeat_MakeDPrism::Add(const TopoDS_Edge& E,
188 const TopoDS_Face& F)
191 Standard_Boolean trc = BRepFeat_GettraceFEAT();
192 if (trc) cout << "BRepFeat_MakeDPrism::Add(Edge,face)" << endl;
195 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
196 if (exp.Current().IsSame(F)) {
201 Standard_ConstructionError::Raise();
204 for (exp.Init(myPbase,TopAbs_EDGE);exp.More();exp.Next()) {
205 if (exp.Current().IsSame(E)) {
210 Standard_ConstructionError::Raise();
213 if (!mySlface.IsBound(F)) {
214 TopTools_ListOfShape thelist;
215 mySlface.Bind(F, thelist);
217 TopTools_ListIteratorOfListOfShape itl(mySlface(F));
218 for (; itl.More();itl.Next()) {
219 if (itl.Value().IsSame(E)) {
224 mySlface(F).Append(E);
229 //=======================================================================
231 //purpose : feature of Height
232 //=======================================================================
234 void BRepFeat_MakeDPrism::Perform(const Standard_Real Height)
237 Standard_Boolean trc = BRepFeat_GettraceFEAT();
238 if (trc) cout << "BRepFeat_MakeDPrism::Perform(Height)" << endl;
245 myPerfSelection = BRepFeat_NoSelection;
246 PerfSelectionValid();
248 Standard_Real theheight = Height/cos(myAngle);
249 // myPbase.Orientation(TopAbs_FORWARD);
251 LocOpe_DPrism theDPrism(myPbase,theheight,myAngle);
252 TopoDS_Shape VraiDPrism = theDPrism.Shape();
254 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
256 myGShape = VraiDPrism;
257 GeneratedShapeValid();
258 TopoDS_Shape Base = theDPrism.FirstShape();
259 TopExp_Explorer exp(Base, TopAbs_FACE);
260 TopoDS_Face theBase = TopoDS::Face(exp.Current());
264 myStatusError = BRepFeat_InvFirstShape;
270 Standard_Boolean found = Standard_False;
272 if(!mySkface.IsNull() || !mySlface.IsEmpty()) {
273 if(myLShape.ShapeType() == TopAbs_WIRE) {
274 TopExp_Explorer ex1(VraiDPrism, TopAbs_FACE);
275 for(; ex1.More(); ex1.Next()) {
276 TopExp_Explorer ex2(ex1.Current(), TopAbs_WIRE);
277 for(; ex2.More(); ex2.Next()) {
278 if(ex2.Current().IsSame(myLShape)) {
279 FFace = TopoDS::Face(ex1.Current());
280 found = Standard_True;
288 TopExp_Explorer exp(mySbase, TopAbs_FACE);
289 for(; exp.More(); exp.Next()) {
290 const TopoDS_Face& ff = TopoDS::Face(exp.Current());
291 if(ToFuse(ff, FFace)) {
292 TopTools_DataMapOfShapeListOfShape sl;
298 // management of gluing faces
302 if(!myGluedF.IsEmpty()) { // case gluing
303 myJustGluer = Standard_True;
304 theDPrism.Curves(myCurves);
305 myBCurve = theDPrism.BarycCurve();
309 // if there is no gluing -> call topological operations
312 //modified by NIZNHY-PKV Thu Mar 21 17:32:17 2002 f
313 //BRepAlgo_Fuse f(mySbase, myGShape);
314 //myShape = f.Shape();
315 //UpdateDescendants(f.Builder(), myShape, Standard_False);
316 BRepAlgoAPI_Fuse f(mySbase, myGShape);
318 UpdateDescendants(f, myShape, Standard_False);
319 //modified by NIZNHY-PKV Thu Mar 21 17:32:23 2002 t
322 else if(myFuse == 0) {
323 //modified by NIZNHY-PKV Thu Mar 21 17:32:57 2002 f
324 //BRepAlgo_Cut c(mySbase, myGShape);
325 //myShape = c.Shape();
326 //UpdateDescendants(c.Builder(), myShape, Standard_False);
327 BRepAlgoAPI_Cut c(mySbase, myGShape);
329 UpdateDescendants(c, myShape, Standard_False);
330 //modified by NIZNHY-PKV Thu Mar 21 17:33:00 2002 t
340 //=======================================================================
342 //purpose : feature limited by the shape Until
343 //=======================================================================
345 void BRepFeat_MakeDPrism::Perform(const TopoDS_Shape& Until)
348 Standard_Boolean trc = BRepFeat_GettraceFEAT();
349 if (trc) cout << "BRepFeat_MakeDPrism::Perform(Until)" << endl;
351 if (Until.IsNull()) {
352 Standard_ConstructionError::Raise();
354 TopExp_Explorer exp(Until, TopAbs_FACE);
356 Standard_ConstructionError::Raise();
358 // myPbase.Orientation(TopAbs_FORWARD);
361 myPerfSelection = BRepFeat_SelectionU;
362 PerfSelectionValid();
366 Standard_Boolean Trf = TransformShapeFU(1);
368 Handle(Geom_Curve) C = TestCurve(myPbase);
369 Standard_Integer sens = SensOfPrism(C, mySUntil);
372 Standard_Real Height =
373 sens*HeightMax(mySbase, mySkface, mySFrom, mySUntil);
374 LocOpe_DPrism theDPrism(myPbase,Height,myAngle);
375 TopoDS_Shape VraiDPrism = theDPrism.Shape();
377 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
378 myGShape = VraiDPrism;
379 GeneratedShapeValid();
380 TopoDS_Shape Base = theDPrism.FirstShape();
381 exp.Init(Base, TopAbs_FACE);
382 TopoDS_Face theBase = TopoDS::Face(exp.Current());
386 myStatusError = BRepFeat_InvFirstShape;
391 theDPrism.Curves(myCurves);
392 myBCurve = theDPrism.BarycCurve();
396 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
397 Handle(Geom_Curve) C1;
405 TColGeom_SequenceOfCurve scur;
408 LocOpe_CSIntersector ASI(mySUntil);
410 TopAbs_Orientation Or;
411 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
413 Or = ASI.Point(1,1).Orientation();
416 Or = ASI.Point(1,ASI.NbPoints(1)).Orientation();
418 // Standard_Real prm = ASI.Point(1,1).Parameter();
419 // if(prm < 0) Or = TopAbs::Reverse(Or);
420 TopoDS_Face FUntil = ASI.Point(1,1).Face();
422 bB.MakeCompound(TopoDS::Compound(Comp));
423 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
424 if (!S.IsNull()) bB.Add(Comp,S);
426 //modified by NIZNHY-PKV Thu Mar 21 17:33:27 2002
427 //BRepAlgo_Cut trP(VraiDPrism,Comp);
428 //UpdateDescendants(trP.Builder(),trP.Shape(), Standard_False);
429 BRepAlgoAPI_Cut trP(VraiDPrism,Comp);
430 UpdateDescendants(trP, trP.Shape(), Standard_False);
431 //modified by NIZNHY-PKV Thu Mar 21 17:33:32 2002 t
433 TopExp_Explorer ex(trP.Shape(), TopAbs_SOLID);
434 TopoDS_Shape Cutsh = ex.Current();
436 //modified by NIZNHY-PKV Thu Mar 21 17:34:09 2002 f
437 //BRepAlgo_Fuse f(mySbase, Cutsh);
438 //myShape = f.Shape();
439 //UpdateDescendants(f.Builder(), myShape, Standard_False);
440 BRepAlgoAPI_Fuse f(mySbase, Cutsh);
442 UpdateDescendants(f, myShape, Standard_False);
443 //modified by NIZNHY-PKV Thu Mar 21 17:34:13 2002 t
446 else if(myFuse == 0) {
447 //modified by NIZNHY-PKV Thu Mar 21 17:34:56 2002 f
448 //BRepAlgo_Cut c(mySbase, Cutsh);
449 //myShape = c.Shape();
450 //UpdateDescendants(c.Builder(), myShape, Standard_False);
451 BRepAlgoAPI_Cut c(mySbase, Cutsh);
453 UpdateDescendants(c, myShape, Standard_False);
454 //modified by NIZNHY-PKV Thu Mar 21 17:34:59 2002 t
463 TopTools_ListIteratorOfListOfShape ited(myNewEdges);
464 for (; ited.More();ited.Next()) {
465 const TopoDS_Edge& ledg=TopoDS::Edge(ited.Value());
466 if (!BRepAlgo::IsValid(ledg)) {
467 bB.SameRange(ledg, Standard_False);
468 bB.SameParameter(ledg, Standard_False);
469 BRepLib::SameParameter(ledg, BRep_Tool::Tolerance(ledg));
475 //=======================================================================
477 //purpose : feature limited by two shapes
478 //=======================================================================
480 void BRepFeat_MakeDPrism::Perform(const TopoDS_Shape& From,
481 const TopoDS_Shape& Until)
484 Standard_Boolean trc = BRepFeat_GettraceFEAT();
485 if (trc) cout << "BRepFeat_MakeDPrism::Perform(From,Until)" << endl;
487 if (From.IsNull() || Until.IsNull()) {
488 Standard_ConstructionError::Raise();
491 if (!mySkface.IsNull()) {
492 if (From.IsSame(mySkface)) {
493 myJustGluer = Standard_True;
495 if (myJustGluer) return;
497 else if (Until.IsSame(mySkface)) {
498 myJustGluer = Standard_True;
500 if (myJustGluer) return;
503 // myPbase.Orientation(TopAbs_FORWARD);
506 myPerfSelection = BRepFeat_SelectionFU;
507 PerfSelectionValid();
509 TopExp_Explorer exp(From, TopAbs_FACE);
511 Standard_ConstructionError::Raise();
513 exp.Init(Until, TopAbs_FACE);
515 Standard_ConstructionError::Raise();
518 Standard_Boolean Trff = TransformShapeFU(0);
521 Standard_Boolean Trfu = TransformShapeFU(1);
525 myStatusError = BRepFeat_IncTypes;
528 Handle(Geom_Curve) C = TestCurve(myPbase);
529 Standard_Integer sens;
530 if(From.IsSame(Until)) {
534 sens = SensOfPrism(C, mySUntil);
537 Standard_Real Height =
538 sens*HeightMax(mySbase, myPbase, mySFrom, mySUntil);
539 LocOpe_DPrism theDPrism(myPbase, Height, Height, myAngle);
540 TopoDS_Shape VraiDPrism = theDPrism.Shape();
544 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
546 // Make systematically dprism
547 myGShape = VraiDPrism;
548 GeneratedShapeValid();
550 // management of gluing faces
551 // mySbase, myPbase, mySlface, theDPrism, myGluedF);
553 theDPrism.Curves(myCurves);
554 myBCurve = theDPrism.BarycCurve();
556 // topologic reconstruction
560 // management of descendants
561 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
562 Handle(Geom_Curve) C1;
569 TColGeom_SequenceOfCurve scur;
572 LocOpe_CSIntersector ASI1(mySUntil);
573 LocOpe_CSIntersector ASI2(mySFrom);
576 TopAbs_Orientation OrU, OrF;
577 TopoDS_Face FFrom, FUntil;
578 //direction of dprism
579 if (ASI1.IsDone() && ASI1.NbPoints(1) >=1) {
581 OrU = ASI1.Point(1,1).Orientation();
584 OrU = ASI1.Point(1,ASI1.NbPoints(1)).Orientation();
586 // Standard_Real prm = ASI1.Point(1,1).Parameter();
587 // if(prm < 0) OrU = TopAbs::Reverse(OrU);
588 FUntil = ASI1.Point(1,1).Face();
592 myStatusError = BRepFeat_NoIntersectU;
595 if (ASI2.IsDone() && ASI2.NbPoints(1) >=1) {
596 OrF = ASI2.Point(1,1).Orientation();
597 // Standard_Real prm = ASI2.Point(1,1).Parameter();
598 OrF = TopAbs::Reverse(OrF);
599 FFrom = ASI2.Point(1,1).Face();
603 myStatusError = BRepFeat_NoIntersectF;
608 B.MakeCompound(TopoDS::Compound(Comp));
609 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, OrU);
610 if (!S.IsNull()) B.Add(Comp,S);
613 myStatusError = BRepFeat_NullToolU;
616 TopoDS_Solid SS = BRepFeat::Tool(mySFrom, FFrom, OrF);
617 if (!SS.IsNull()) B.Add(Comp,SS);
620 myStatusError = BRepFeat_NullToolF;
624 //modified by NIZNHY-PKV Thu Mar 21 17:35:48 2002 f
625 //BRepAlgo_Cut trP(VraiDPrism,Comp);
626 BRepAlgoAPI_Cut trP(VraiDPrism,Comp);
627 //modified by NIZNHY-PKV Thu Mar 21 17:35:59 2002 t
630 //modified by NIZNHY-PKV Thu Mar 21 17:36:06 2002 f
631 //BRepAlgo_Fuse f(mySbase, trP.Shape());
632 //myShape = f.Shape();
633 //UpdateDescendants(f.Builder(), myShape, Standard_False);
634 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
636 UpdateDescendants(f, myShape, Standard_False);
637 //modified by NIZNHY-PKV Thu Mar 21 17:36:33 2002 t
641 else if(myFuse == 0) {
642 //modified by NIZNHY-PKV Thu Mar 21 17:37:16 2002 f
643 //BRepAlgo_Cut c(mySbase, trP.Shape());
644 //myShape = c.Shape();
645 //UpdateDescendants(c.Builder(), myShape, Standard_False);
646 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
648 UpdateDescendants(c, myShape, Standard_False);
649 //modified by NIZNHY-PKV Thu Mar 21 17:37:49 2002 t
653 myShape = trP.Shape();
660 //=======================================================================
662 //purpose : feature semi-infinie
663 //=======================================================================
665 void BRepFeat_MakeDPrism::PerformUntilEnd()
668 Standard_Boolean trc = BRepFeat_GettraceFEAT();
669 if (trc) cout << "BRepFeat_MakeDPrism::PerformUntilEnd()" << endl;
671 myPerfSelection = BRepFeat_SelectionSh;
672 PerfSelectionValid();
678 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
679 // myPbase.Orientation(TopAbs_FORWARD);
681 LocOpe_DPrism theDPrism(myPbase, Height, myAngle);
682 TopoDS_Shape VraiDPrism = theDPrism.Shape();
684 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
686 myGShape = VraiDPrism;
687 GeneratedShapeValid();
689 theDPrism.Curves(myCurves);
690 myBCurve = theDPrism.BarycCurve();
694 //=======================================================================
695 //function : PerformFromEnd
696 //purpose : feature semiinfinite limited by the shape Until from the other side
697 //=======================================================================
699 void BRepFeat_MakeDPrism::PerformFromEnd(const TopoDS_Shape& Until)
702 Standard_Boolean trc = BRepFeat_GettraceFEAT();
703 if (trc) cout << "BRepFeat_MakeDPrism::PerformFromEnd(From,Until)" << endl;
705 if (Until.IsNull()) {
706 Standard_ConstructionError::Raise();
708 if (!mySkface.IsNull() && Until.IsSame(mySkface)) {
713 exp.Init(Until, TopAbs_FACE);
715 Standard_ConstructionError::Raise();
717 // myPbase.Orientation(TopAbs_FORWARD);
718 myPerfSelection = BRepFeat_SelectionShU;
719 PerfSelectionValid();
723 Standard_Boolean Trf = TransformShapeFU(1);
725 Handle(Geom_Curve) C = TestCurve(myPbase);
726 Standard_Integer sens = SensOfPrism(C, mySUntil);
727 Standard_Real Height =
728 sens*HeightMax(mySbase, mySkface, mySFrom, mySUntil);
730 LocOpe_DPrism theDPrism(myPbase, Height, Height, myAngle);
731 TopoDS_Shape VraiDPrism = theDPrism.Shape();
732 if(VraiDPrism.IsNull()) {
734 myStatusError = BRepFeat_NullRealTool;
738 if(!Trf) { // case finite face
739 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
740 myGShape = VraiDPrism;
741 GeneratedShapeValid();
744 theDPrism.Curves(myCurves);
745 myBCurve = theDPrism.BarycCurve();
748 else { // case support
749 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
750 Handle(Geom_Curve) C2;
757 TColGeom_SequenceOfCurve scur;
760 LocOpe_CSIntersector ASI1(mySUntil);
761 LocOpe_CSIntersector ASI2(mySbase);
764 TopAbs_Orientation OrU = TopAbs_FORWARD, OrF = TopAbs_FORWARD;
765 TopoDS_Face FUntil, FFrom;
766 if (ASI1.IsDone() && ASI1.NbPoints(1) >=1) {
767 OrU = ASI1.Point(1,1).Orientation();
768 Standard_Real prm = ASI1.Point(1,1).Parameter();
769 if(prm < 0) OrU = TopAbs::Reverse(OrU);
770 FUntil = ASI1.Point(1,1).Face();
773 if (ASI2.IsDone() && ASI2.NbPoints(1) >=1) {
774 Standard_Integer jj = ASI2.NbPoints(1);
775 Standard_Real prm = ASI2.Point(1,1).Parameter();
776 FFrom = ASI2.Point(1, 1).Face();
777 OrF = ASI2.Point(1,1).Orientation();
778 OrF = TopAbs::Reverse(OrF);
779 for(Standard_Integer iii = 1; iii <= jj; iii++) {
780 if(ASI2.Point(1,iii).Parameter() < prm) {
781 prm = ASI2.Point(1,iii).Parameter();
782 FFrom = ASI2.Point(1, iii).Face();
783 OrF = ASI2.Point(1,iii).Orientation();
784 OrF = TopAbs::Reverse(OrF);
787 Handle(Geom_Surface) S = BRep_Tool::Surface(FFrom);
788 if (S->DynamicType() ==
789 STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
790 S = Handle(Geom_RectangularTrimmedSurface)::
791 DownCast(S)->BasisSurface();
793 BRepLib_MakeFace fac(S, Precision::Confusion());
794 mySFrom = fac.Face();
795 Trf = TransformShapeFU(0);
796 // FFrom = TopoDS::Face(mySFrom);
801 B.MakeCompound(TopoDS::Compound(Comp));
802 TopoDS_Solid Sol = BRepFeat::Tool(mySUntil, FUntil, OrU);
803 if (!Sol.IsNull()) B.Add(Comp,Sol);
806 myStatusError = BRepFeat_NullToolU;
810 TopoDS_Solid Sol1 = BRepFeat::Tool(mySFrom, FFrom, OrF);
811 if (!Sol1.IsNull()) B.Add(Comp,Sol1);
814 myStatusError = BRepFeat_NullToolF;
818 //modified by NIZNHY-PKV Thu Mar 21 17:38:33 2002 f
819 //BRepAlgo_Cut trP(VraiDPrism,Comp);
820 BRepAlgoAPI_Cut trP(VraiDPrism,Comp);
821 //modified by NIZNHY-PKV Thu Mar 21 17:38:37 2002 t
823 //modified by NIZNHY-PKV Thu Mar 21 17:40:03 2002 f
824 //BRepAlgo_Fuse f(mySbase, trP.Shape());
825 //myShape = f.Shape();
826 //UpdateDescendants(f.Builder(), myShape, Standard_False);
827 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
829 UpdateDescendants(f, myShape, Standard_False);
830 //modified by NIZNHY-PKV Thu Mar 21 17:40:07 2002 t
833 else if(myFuse == 0) {
834 //modified by NIZNHY-PKV Thu Mar 21 17:40:33 2002 t
835 //BRepAlgo_Cut c(mySbase, trP.Shape());
836 //myShape = c.Shape();
837 //UpdateDescendants(c.Builder(), myShape, Standard_False);
838 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
840 UpdateDescendants(c, myShape, Standard_False);
841 //modified by NIZNHY-PKV Thu Mar 21 17:40:44 2002 t
845 myShape = trP.Shape();
853 //=======================================================================
854 //function : PerformThruAll
855 //purpose : feature throughout the entire initial shape
856 //=======================================================================
858 void BRepFeat_MakeDPrism::PerformThruAll()
861 Standard_Boolean trc = BRepFeat_GettraceFEAT();
862 if (trc) cout << "BRepFeat_MakeDPrism::PerformThruAll()" << endl;
869 myPerfSelection = BRepFeat_NoSelection;
872 myPerfSelection = BRepFeat_SelectionSh;
875 PerfSelectionValid();
876 // myPbase.Orientation(TopAbs_FORWARD);
880 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
881 LocOpe_DPrism theDPrism(myPbase, Height, Height, myAngle);
882 TopoDS_Shape VraiDPrism = theDPrism.Shape();
883 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
885 myGShape = VraiDPrism;
886 GeneratedShapeValid();
889 //modified by NIZNHY-PKV Thu Mar 21 17:46:16 2002 f
890 //BRepAlgo_Cut c(mySbase, myGShape);
891 BRepAlgoAPI_Cut c(mySbase, myGShape);
892 //modified by NIZNHY-PKV Thu Mar 21 17:46:26 2002 t
895 //modified by NIZNHY-PKV Thu Mar 21 17:46:39 2002 f
896 //UpdateDescendants(c.Builder(), myShape, Standard_False);
897 UpdateDescendants(c, myShape, Standard_False);
898 //modified by NIZNHY-PKV Thu Mar 21 17:46:43 2002 t
903 theDPrism.Curves(myCurves);
904 myBCurve = theDPrism.BarycCurve();
910 //=======================================================================
911 //function : PerformUntilHeight
912 //purpose : feature until the shape is of the given height
913 //=======================================================================
915 void BRepFeat_MakeDPrism::PerformUntilHeight(const TopoDS_Shape& Until,
916 const Standard_Real Height)
919 Standard_Boolean trc = BRepFeat_GettraceFEAT();
920 if (trc) cout << "BRepFeat_MakeDPrism::PerformUntilHeight(Until,Height)" << endl;
922 if (Until.IsNull()) {
928 TopExp_Explorer exp(Until, TopAbs_FACE);
930 Standard_ConstructionError::Raise();
932 // myPbase.Orientation(TopAbs_FORWARD);
934 myPerfSelection = BRepFeat_NoSelection;
935 PerfSelectionValid();
939 Standard_Boolean Trf = TransformShapeFU(1);
941 Handle(Geom_Curve) C = TestCurve(myPbase);
942 Standard_Integer sens = SensOfPrism(C, mySUntil);
944 LocOpe_DPrism theDPrism(myPbase,sens*Height,myAngle);
945 TopoDS_Shape VraiDPrism = theDPrism.Shape();
947 if(!Trf) { // case face finished
948 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
949 myGShape = VraiDPrism;
950 GeneratedShapeValid();
951 TopoDS_Shape Base = theDPrism.FirstShape();
952 exp.Init(Base, TopAbs_FACE);
953 TopoDS_Face theBase = TopoDS::Face(exp.Current());
957 myStatusError = BRepFeat_InvFirstShape;
962 theDPrism.Curves(myCurves);
963 myBCurve = theDPrism.BarycCurve();
966 else { // case support
967 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
968 Handle(Geom_Curve) C1;
975 TColGeom_SequenceOfCurve scur;
978 LocOpe_CSIntersector ASI(mySUntil);
980 TopAbs_Orientation Or;
981 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
983 Or = ASI.Point(1,1).Orientation();
986 Or = ASI.Point(1,ASI.NbPoints(1)).Orientation();
988 // Standard_Real prm = ASI.Point(1,1).Parameter();
989 // if(prm < 0) Or = TopAbs::Reverse(Or);
990 TopoDS_Face FUntil = ASI.Point(1,1).Face();
993 B.MakeCompound(TopoDS::Compound(Comp));
994 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
995 if (!S.IsNull()) B.Add(Comp,S);
996 //modified by NIZNHY-PKV Thu Mar 21 17:47:14 2002 f
997 //BRepAlgo_Cut trP(VraiDPrism,Comp);
998 BRepAlgoAPI_Cut trP(VraiDPrism,Comp);
999 //modified by NIZNHY-PKV Thu Mar 21 17:47:21 2002 t
1001 //modified by NIZNHY-PKV Thu Mar 21 17:47:42 2002 f
1002 //BRepAlgo_Fuse f(mySbase, trP.Shape());
1003 //myShape = f.Shape();
1004 //UpdateDescendants(f.Builder(), myShape, Standard_False);
1005 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
1006 myShape = f.Shape();
1007 UpdateDescendants(f, myShape, Standard_False);
1008 //modified by NIZNHY-PKV Thu Mar 21 17:47:49 2002 t
1011 else if(myFuse == 0) {
1012 //modified by NIZNHY-PKV Thu Mar 21 17:48:18 2002 f
1013 //BRepAlgo_Cut c(mySbase, trP.Shape());
1014 //myShape = c.Shape();
1015 //UpdateDescendants(c.Builder(), myShape, Standard_False);
1016 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
1017 myShape = c.Shape();
1018 UpdateDescendants(c, myShape, Standard_False);
1019 //modified by NIZNHY-PKV Thu Mar 21 17:48:26 2002 t
1023 myShape = trP.Shape();
1031 //=======================================================================
1033 //purpose : curves parallel to the axis of the prism
1034 //=======================================================================
1036 void BRepFeat_MakeDPrism::Curves(TColGeom_SequenceOfCurve& scur)
1041 //============================================================================
1042 // function : BRepFeat_BossEgdes
1043 // purpose: Determination of TopEdges and LatEdges.
1044 // sig = 1 -> TopEdges = FirstShape of the DPrism
1045 // sig = 2 -> TOpEdges = LastShape of the DPrism
1046 //============================================================================
1047 void BRepFeat_MakeDPrism::BossEdges (const Standard_Integer signature)
1050 Standard_Boolean trc = BRepFeat_GettraceFEAT();
1051 if (trc) cout << "BRepFeat_MakeDPrism::BossEdges (integer)" << endl;
1053 TopTools_ListOfShape theLastShape;
1054 theLastShape.Clear();
1055 if (signature == 1 || signature == -1) {
1056 theLastShape = FirstShape();
1058 else if (signature == 2 || signature == -2) {
1059 theLastShape = LastShape();
1066 TopTools_ListIteratorOfListOfShape itLS;
1067 TopExp_Explorer ExpE;
1068 for (itLS.Initialize(theLastShape);itLS.More();itLS.Next()) {
1069 const TopoDS_Face& FF = TopoDS::Face(itLS.Value());
1070 for (ExpE.Init(FF,TopAbs_EDGE);ExpE.More();ExpE.Next()) {
1071 const TopoDS_Edge& EE = TopoDS::Edge(ExpE.Current());
1072 myTopEdges.Append(EE);
1077 if (signature < 0) {
1078 // Attention check if TgtEdges is important
1079 myLatEdges = NewEdges();
1081 else if (signature > 0) {
1082 if ( !myShape.IsNull() ) {
1083 TopTools_MapOfShape MapE;
1084 Standard_Boolean Found;
1086 TopExp_Explorer ExpF;
1087 for (ExpF.Init(myShape,TopAbs_FACE);ExpF.More();ExpF.Next()) {
1088 Found = Standard_False;
1089 const TopoDS_Face& FF = TopoDS::Face(ExpF.Current());
1090 for (itLS.Initialize(theLastShape);itLS.More();itLS.Next()) {
1091 const TopoDS_Face& TopFace = TopoDS::Face(itLS.Value());
1092 if (!FF.IsSame(TopFace)) {
1093 TopExp_Explorer ExpE;
1094 for (ExpE.Init(FF,TopAbs_EDGE);ExpE.More() && !Found ;ExpE.Next()) {
1095 const TopoDS_Edge& E1 = TopoDS::Edge(ExpE.Current());
1096 TopoDS_Vertex V1,V2;
1097 TopExp::Vertices (E1,V1,V2);
1098 TopTools_ListIteratorOfListOfShape it(myTopEdges);
1099 for (;it.More() && !Found ; it.Next()) {
1100 TopoDS_Edge E2 = TopoDS::Edge(it.Value());
1101 TopoDS_Vertex VT1,VT2;
1102 TopExp::Vertices (E2,VT1,VT2);
1104 if (V1.IsSame(VT1) || V1.IsSame(VT2) || V2.IsSame(VT1) || V2.IsSame(VT2)) {
1105 Found = Standard_True;
1106 TopExp_Explorer ExpE2;
1107 for (ExpE2.Init(FF,TopAbs_EDGE);ExpE2.More();ExpE2.Next()) {
1108 const TopoDS_Edge& E3 = TopoDS::Edge(ExpE2.Current());
1109 if (MapE.Contains(E3)) {
1121 TopTools_ListIteratorOfListOfShape it(myTopEdges);
1122 for (;it.More() ; it.Next()) {
1123 if (MapE.Contains(it.Value())) {MapE.Remove(it.Value()); }
1126 TopTools_MapIteratorOfMapOfShape itMap;
1127 for (itMap.Initialize(MapE);itMap.More();itMap.Next()) {
1128 if (!BRep_Tool::Degenerated(TopoDS::Edge(itMap.Key())))
1129 myLatEdges.Append(itMap.Key());
1137 //============================================================================
1138 // function : BRepFeat_TopEgdes
1139 // Purpose: Returns the list of TopoDS Edges of the top of the boss
1140 //============================================================================
1141 const TopTools_ListOfShape& BRepFeat_MakeDPrism::TopEdges ()
1146 //============================================================================
1147 // function : BRepFeat_LatEgdes
1148 // Purpose: Returns the list of TopoDS Edges of the top of the boss
1149 //============================================================================
1150 const TopTools_ListOfShape& BRepFeat_MakeDPrism::LatEdges ()
1155 //=======================================================================
1156 //function : BarycCurve
1157 //purpose : passe par le centre de masses de la primitive
1158 //=======================================================================
1160 Handle(Geom_Curve) BRepFeat_MakeDPrism::BarycCurve()
1166 //=======================================================================
1167 //function : HeightMax
1168 //purpose : Calculate the height of the prism following the parameters of the bounding box
1169 //=======================================================================
1171 static Standard_Real HeightMax(const TopoDS_Shape& theSbase, // shape initial
1172 const TopoDS_Face& theSkface, // face de sketch
1173 const TopoDS_Shape& theSFrom, // shape from
1174 const TopoDS_Shape& theSUntil) // shape until
1177 BRepBndLib::Add(theSbase,Box);
1178 BRepBndLib::Add(theSkface,Box);
1179 if(!theSFrom.IsNull()) {
1180 BRepBndLib::Add(theSFrom,Box);
1182 if(!theSUntil.IsNull()) {
1183 BRepBndLib::Add(theSUntil,Box);
1187 Box.Get(c[0],c[2],c[4],c[1],c[3],c[5]);
1188 // Standard_Real parmin=c[0], parmax = c[0];
1189 // for(Standard_Integer i = 0 ; i < 6; i++) {
1190 // if(c[i] > parmax) parmax = c[i];
1191 // if(c[i] < parmin ) parmin = c[i];
1193 // Standard_Real Height = abs(2.*(parmax - parmin));
1194 // return(2.*Height);
1196 Standard_Real par = Max( Max( fabs(c[1] - c[0]), fabs(c[3] - c[2]) ), fabs(c[5] - c[4]) );
1198 // Standard_Real par = Max( Max( abs(c[1] - c[0]), abs(c[3] - c[2]) ), abs(c[5] - c[4]) );
1201 cout << "Height = > " << par << endl;
1210 //=======================================================================
1211 //function : SensOfPrism
1212 //purpose : determine the direction of prism generation
1213 //=======================================================================
1214 Standard_Integer SensOfPrism(const Handle(Geom_Curve) C,
1215 const TopoDS_Shape& Until)
1217 LocOpe_CSIntersector ASI1(Until);
1218 TColGeom_SequenceOfCurve scur;
1221 Standard_Integer sens = 1;
1222 if(ASI1.IsDone() && ASI1.NbPoints(1) >= 1) {
1223 Standard_Integer nb = ASI1.NbPoints(1);
1224 Standard_Real prm1 = ASI1.Point(1, 1).Parameter();
1225 Standard_Real prm2 = ASI1.Point(1, nb).Parameter();
1226 if(prm1 < 0. && prm2 < 0.) {
1230 else if(BRepFeat::ParametricBarycenter(Until,C) < 0) {
1237 //=======================================================================
1240 //=======================================================================
1242 static void MajMap(const TopoDS_Shape& theB,
1243 const LocOpe_DPrism& theP,
1244 TopTools_DataMapOfShapeListOfShape& theMap, // myMap
1245 TopoDS_Shape& theFShape, // myFShape
1246 TopoDS_Shape& theLShape) // myLShape
1248 TopExp_Explorer exp;
1249 if(!theP.FirstShape().IsNull()) {
1250 exp.Init(theP.FirstShape(),TopAbs_WIRE);
1252 theFShape = exp.Current();
1253 TopTools_ListOfShape thelist;
1254 theMap.Bind(theFShape, thelist);
1255 for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) {
1256 theMap(theFShape).Append(exp.Current());
1261 if(!theP.LastShape().IsNull()) {
1262 exp.Init(theP.LastShape(),TopAbs_WIRE);
1264 theLShape = exp.Current();
1265 TopTools_ListOfShape thelist1;
1266 theMap.Bind(theLShape, thelist1);
1267 for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) {
1268 theMap(theLShape).Append(exp.Current());
1273 for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) {
1274 if (!theMap.IsBound(exp.Current())) {
1275 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
1276 TopTools_ListOfShape thelist2;
1277 theMap.Bind(edg, thelist2);
1278 theMap(edg) = theP.Shapes(edg);
1284 //=======================================================================
1287 //=======================================================================
1289 static Handle(Geom_Curve) TestCurve(const TopoDS_Face& Base)
1291 gp_Pnt bar(0., 0., 0.);
1292 TColgp_SequenceOfPnt spt;
1293 LocOpe::SampleEdges(Base,spt);
1294 for (Standard_Integer jj=1;jj<=spt.Length(); jj++) {
1295 const gp_Pnt& pvt = spt(jj);
1296 bar.ChangeCoord() += pvt.XYZ();
1298 bar.ChangeCoord().Divide(spt.Length());
1299 Handle(Geom_Surface) s = BRep_Tool::Surface(Base);
1300 if (s->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1301 s = Handle(Geom_RectangularTrimmedSurface)::
1302 DownCast(s)->BasisSurface();
1304 Handle (Geom_Plane) P = Handle(Geom_Plane)::DownCast(s);
1306 Handle(Geom_Curve) toto;
1309 gp_Pln pp = P->Pln();
1310 gp_Dir Normale(pp.Position().XDirection()^pp.Position().YDirection());
1311 gp_Ax1 theAx(bar, Normale);
1312 Handle(Geom_Line) theLin = new Geom_Line(theAx);
1320 //=======================================================================
1323 //=======================================================================
1325 Standard_Boolean ToFuse(const TopoDS_Face& F1,
1326 const TopoDS_Face& F2)
1328 if (F1.IsNull() || F2.IsNull()) {
1329 return Standard_False;
1332 Handle(Geom_Surface) S1,S2;
1333 TopLoc_Location loc1, loc2;
1334 Handle(Standard_Type) typS1,typS2;
1335 const Standard_Real tollin = Precision::Confusion();
1336 const Standard_Real tolang = Precision::Angular();
1338 S1 = BRep_Tool::Surface(F1,loc1);
1339 S2 = BRep_Tool::Surface(F2,loc2);
1341 typS1 = S1->DynamicType();
1342 typS2 = S2->DynamicType();
1344 if (typS1 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1345 S1 = (*((Handle(Geom_RectangularTrimmedSurface)*)&S1))->BasisSurface();
1346 typS1 = S1->DynamicType();
1349 if (typS2 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1350 S2 = (*((Handle(Geom_RectangularTrimmedSurface)*)&S2))->BasisSurface();
1351 typS2 = S2->DynamicType();
1354 if (typS1 != typS2) {
1355 return Standard_False;
1359 Standard_Boolean ValRet = Standard_False;
1360 if (typS1 == STANDARD_TYPE(Geom_Plane)) {
1361 S1 = BRep_Tool::Surface(F1); // to apply the location.
1362 S2 = BRep_Tool::Surface(F2);
1363 gp_Pln pl1( (*((Handle(Geom_Plane)*)&S1))->Pln());
1364 gp_Pln pl2( (*((Handle(Geom_Plane)*)&S2))->Pln());
1366 if (pl1.Position().IsCoplanar(pl2.Position(),tollin,tolang)) {
1367 ValRet = Standard_True;