1 // Created on: 1996-09-03
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_MakeDPrism.ixx>
19 #include <BRepFeat.hxx>
21 #include <LocOpe_CSIntersector.hxx>
22 #include <TColGeom_SequenceOfCurve.hxx>
23 #include <LocOpe_DPrism.hxx>
24 #include <LocOpe_SequenceOfLin.hxx>
25 #include <LocOpe_PntFace.hxx>
29 #include <gp_Pnt2d.hxx>
32 #include <Precision.hxx>
34 #include <Geom_Surface.hxx>
35 #include <Geom_Curve.hxx>
36 #include <Geom_Line.hxx>
37 #include <Geom2d_Curve.hxx>
38 #include <Geom_Plane.hxx>
39 #include <Geom_RectangularTrimmedSurface.hxx>
40 #include <TColgp_SequenceOfPnt.hxx>
41 #include <TColGeom_SequenceOfCurve.hxx>
42 #include <Bnd_Box.hxx>
44 #include <BRepBndLib.hxx>
45 #include <BRep_Builder.hxx>
46 #include <BRep_Tool.hxx>
47 #include <BRepTools.hxx>
48 #include <BRepPrimAPI_MakeBox.hxx>
49 #include <BRepLib.hxx>
51 #include <BRepAlgo.hxx>
52 //modified by NIZNHY-PKV Thu Mar 21 17:49:46 2002 f
53 //#include <BRepAlgo_Cut.hxx>
54 //#include <BRepAlgo_Fuse.hxx>
55 #include <BRepAlgoAPI_Cut.hxx>
56 #include <BRepAlgoAPI_Fuse.hxx>
57 //modified by NIZNHY-PKV Thu Mar 21 17:50:04 2002 t
59 #include <BRepLib_MakeFace.hxx>
61 #include <TopExp_Explorer.hxx>
62 #include <TopTools_MapOfShape.hxx>
63 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
64 #include <TopTools_ListIteratorOfListOfShape.hxx>
65 #include <TopTools_MapIteratorOfMapOfShape.hxx>
66 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
67 #include <TopoDS_Solid.hxx>
68 #include <TopoDS_Compound.hxx>
69 #include <TopoDS_Shell.hxx>
70 #include <TopoDS_Shape.hxx>
71 #include <TopoDS_Face.hxx>
74 #include <Standard_ConstructionError.hxx>
78 #include <BRepFeat.hxx>
82 extern Standard_Boolean BRepFeat_GettraceFEAT();
85 static void MajMap(const TopoDS_Shape&,
87 TopTools_DataMapOfShapeListOfShape&, // myMap
88 TopoDS_Shape&, // myFShape
89 TopoDS_Shape&); // myLShape
91 static Standard_Real HeightMax(const TopoDS_Shape& theSbase,
92 const TopoDS_Face& theSkface,
93 const TopoDS_Shape& theSFrom,
94 const TopoDS_Shape& theSUntil);
96 static Standard_Integer SensOfPrism(const Handle(Geom_Curve) C,
97 const TopoDS_Shape& Until);
99 static Handle(Geom_Curve) TestCurve(const TopoDS_Face&);
101 static Standard_Boolean ToFuse(const TopoDS_Face& ,
106 //=======================================================================
109 //=======================================================================
111 void BRepFeat_MakeDPrism::Init(const TopoDS_Shape& Sbase,
112 const TopoDS_Face& Pbase,
113 const TopoDS_Face& Skface,
114 const Standard_Real Angle,
115 const Standard_Integer Mode,
116 const Standard_Boolean Modify)
120 Standard_Boolean trc = BRepFeat_GettraceFEAT();
121 if (trc) cout << "BRepFeat_MakeDPrism::Init" << endl;
130 myFuse = Standard_False;
131 myJustFeat = Standard_False;
134 myFuse = Standard_True;
135 myJustFeat = Standard_False;
138 myFuse = Standard_True;
139 myJustFeat = Standard_True;
144 myJustGluer = Standard_False;
148 //mySkface.Nullify();
158 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
159 TopTools_ListOfShape thelist;
160 myMap.Bind(exp.Current(), thelist);
161 myMap(exp.Current()).Append(exp.Current());
166 if (myJustFeat) cout << " Just Feature" << endl;
167 if (myFuse) cout << " Fuse" << endl;
168 if (!myFuse) cout << " Cut" << endl;
169 if (!myModify) cout << " Modify = 0" << endl;
170 // cout <<" Angle = " << myAngle << endl;
176 //=======================================================================
178 //purpose : add sliding faces and edges
179 //=======================================================================
181 void BRepFeat_MakeDPrism::Add(const TopoDS_Edge& E,
182 const TopoDS_Face& F)
185 Standard_Boolean trc = BRepFeat_GettraceFEAT();
186 if (trc) cout << "BRepFeat_MakeDPrism::Add(Edge,face)" << endl;
189 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
190 if (exp.Current().IsSame(F)) {
195 Standard_ConstructionError::Raise();
198 for (exp.Init(myPbase,TopAbs_EDGE);exp.More();exp.Next()) {
199 if (exp.Current().IsSame(E)) {
204 Standard_ConstructionError::Raise();
207 if (!mySlface.IsBound(F)) {
208 TopTools_ListOfShape thelist;
209 mySlface.Bind(F, thelist);
211 TopTools_ListIteratorOfListOfShape itl(mySlface(F));
212 for (; itl.More();itl.Next()) {
213 if (itl.Value().IsSame(E)) {
218 mySlface(F).Append(E);
223 //=======================================================================
225 //purpose : feature of Height
226 //=======================================================================
228 void BRepFeat_MakeDPrism::Perform(const Standard_Real Height)
231 Standard_Boolean trc = BRepFeat_GettraceFEAT();
232 if (trc) cout << "BRepFeat_MakeDPrism::Perform(Height)" << endl;
239 myPerfSelection = BRepFeat_NoSelection;
240 PerfSelectionValid();
242 Standard_Real theheight = Height/cos(myAngle);
243 // myPbase.Orientation(TopAbs_FORWARD);
245 LocOpe_DPrism theDPrism(myPbase,theheight,myAngle);
246 TopoDS_Shape VraiDPrism = theDPrism.Shape();
248 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
250 myGShape = VraiDPrism;
251 GeneratedShapeValid();
252 TopoDS_Shape Base = theDPrism.FirstShape();
253 TopExp_Explorer exp(Base, TopAbs_FACE);
254 TopoDS_Face theBase = TopoDS::Face(exp.Current());
258 myStatusError = BRepFeat_InvFirstShape;
264 Standard_Boolean found = Standard_False;
266 if(!mySkface.IsNull() || !mySlface.IsEmpty()) {
267 if(myLShape.ShapeType() == TopAbs_WIRE) {
268 TopExp_Explorer ex1(VraiDPrism, TopAbs_FACE);
269 for(; ex1.More(); ex1.Next()) {
270 TopExp_Explorer ex2(ex1.Current(), TopAbs_WIRE);
271 for(; ex2.More(); ex2.Next()) {
272 if(ex2.Current().IsSame(myLShape)) {
273 FFace = TopoDS::Face(ex1.Current());
274 found = Standard_True;
282 TopExp_Explorer exp(mySbase, TopAbs_FACE);
283 for(; exp.More(); exp.Next()) {
284 const TopoDS_Face& ff = TopoDS::Face(exp.Current());
285 if(ToFuse(ff, FFace)) {
286 TopTools_DataMapOfShapeListOfShape sl;
292 // management of gluing faces
296 if(!myGluedF.IsEmpty()) { // case gluing
297 myJustGluer = Standard_True;
298 theDPrism.Curves(myCurves);
299 myBCurve = theDPrism.BarycCurve();
303 // if there is no gluing -> call topological operations
306 //modified by NIZNHY-PKV Thu Mar 21 17:32:17 2002 f
307 //BRepAlgo_Fuse f(mySbase, myGShape);
308 //myShape = f.Shape();
309 //UpdateDescendants(f.Builder(), myShape, Standard_False);
310 BRepAlgoAPI_Fuse f(mySbase, myGShape);
312 UpdateDescendants(f, myShape, Standard_False);
313 //modified by NIZNHY-PKV Thu Mar 21 17:32:23 2002 t
316 else if(myFuse == 0) {
317 //modified by NIZNHY-PKV Thu Mar 21 17:32:57 2002 f
318 //BRepAlgo_Cut c(mySbase, myGShape);
319 //myShape = c.Shape();
320 //UpdateDescendants(c.Builder(), myShape, Standard_False);
321 BRepAlgoAPI_Cut c(mySbase, myGShape);
323 UpdateDescendants(c, myShape, Standard_False);
324 //modified by NIZNHY-PKV Thu Mar 21 17:33:00 2002 t
334 //=======================================================================
336 //purpose : feature limited by the shape Until
337 //=======================================================================
339 void BRepFeat_MakeDPrism::Perform(const TopoDS_Shape& Until)
342 Standard_Boolean trc = BRepFeat_GettraceFEAT();
343 if (trc) cout << "BRepFeat_MakeDPrism::Perform(Until)" << endl;
345 if (Until.IsNull()) {
346 Standard_ConstructionError::Raise();
348 TopExp_Explorer exp(Until, TopAbs_FACE);
350 Standard_ConstructionError::Raise();
352 // myPbase.Orientation(TopAbs_FORWARD);
355 myPerfSelection = BRepFeat_SelectionU;
356 PerfSelectionValid();
360 Standard_Boolean Trf = TransformShapeFU(1);
362 Handle(Geom_Curve) C = TestCurve(myPbase);
363 Standard_Integer sens = SensOfPrism(C, mySUntil);
366 Standard_Real Height =
367 sens*HeightMax(mySbase, mySkface, mySFrom, mySUntil);
368 LocOpe_DPrism theDPrism(myPbase,Height,myAngle);
369 TopoDS_Shape VraiDPrism = theDPrism.Shape();
371 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
372 myGShape = VraiDPrism;
373 GeneratedShapeValid();
374 TopoDS_Shape Base = theDPrism.FirstShape();
375 exp.Init(Base, TopAbs_FACE);
376 TopoDS_Face theBase = TopoDS::Face(exp.Current());
380 myStatusError = BRepFeat_InvFirstShape;
385 theDPrism.Curves(myCurves);
386 myBCurve = theDPrism.BarycCurve();
390 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
391 Handle(Geom_Curve) C1;
399 TColGeom_SequenceOfCurve scur;
402 LocOpe_CSIntersector ASI(mySUntil);
404 TopAbs_Orientation Or;
405 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
407 Or = ASI.Point(1,1).Orientation();
410 Or = ASI.Point(1,ASI.NbPoints(1)).Orientation();
412 // Standard_Real prm = ASI.Point(1,1).Parameter();
413 // if(prm < 0) Or = TopAbs::Reverse(Or);
414 TopoDS_Face FUntil = ASI.Point(1,1).Face();
416 bB.MakeCompound(TopoDS::Compound(Comp));
417 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
418 if (!S.IsNull()) bB.Add(Comp,S);
420 //modified by NIZNHY-PKV Thu Mar 21 17:33:27 2002
421 //BRepAlgo_Cut trP(VraiDPrism,Comp);
422 //UpdateDescendants(trP.Builder(),trP.Shape(), Standard_False);
423 BRepAlgoAPI_Cut trP(VraiDPrism,Comp);
424 UpdateDescendants(trP, trP.Shape(), Standard_False);
425 //modified by NIZNHY-PKV Thu Mar 21 17:33:32 2002 t
427 TopExp_Explorer ex(trP.Shape(), TopAbs_SOLID);
428 TopoDS_Shape Cutsh = ex.Current();
430 //modified by NIZNHY-PKV Thu Mar 21 17:34:09 2002 f
431 //BRepAlgo_Fuse f(mySbase, Cutsh);
432 //myShape = f.Shape();
433 //UpdateDescendants(f.Builder(), myShape, Standard_False);
434 BRepAlgoAPI_Fuse f(mySbase, Cutsh);
436 UpdateDescendants(f, myShape, Standard_False);
437 //modified by NIZNHY-PKV Thu Mar 21 17:34:13 2002 t
440 else if(myFuse == 0) {
441 //modified by NIZNHY-PKV Thu Mar 21 17:34:56 2002 f
442 //BRepAlgo_Cut c(mySbase, Cutsh);
443 //myShape = c.Shape();
444 //UpdateDescendants(c.Builder(), myShape, Standard_False);
445 BRepAlgoAPI_Cut c(mySbase, Cutsh);
447 UpdateDescendants(c, myShape, Standard_False);
448 //modified by NIZNHY-PKV Thu Mar 21 17:34:59 2002 t
457 TopTools_ListIteratorOfListOfShape ited(myNewEdges);
458 for (; ited.More();ited.Next()) {
459 const TopoDS_Edge& ledg=TopoDS::Edge(ited.Value());
460 if (!BRepAlgo::IsValid(ledg)) {
461 bB.SameRange(ledg, Standard_False);
462 bB.SameParameter(ledg, Standard_False);
463 BRepLib::SameParameter(ledg, BRep_Tool::Tolerance(ledg));
469 //=======================================================================
471 //purpose : feature limited by two shapes
472 //=======================================================================
474 void BRepFeat_MakeDPrism::Perform(const TopoDS_Shape& From,
475 const TopoDS_Shape& Until)
478 Standard_Boolean trc = BRepFeat_GettraceFEAT();
479 if (trc) cout << "BRepFeat_MakeDPrism::Perform(From,Until)" << endl;
481 if (From.IsNull() || Until.IsNull()) {
482 Standard_ConstructionError::Raise();
485 if (!mySkface.IsNull()) {
486 if (From.IsSame(mySkface)) {
487 myJustGluer = Standard_True;
489 if (myJustGluer) return;
491 else if (Until.IsSame(mySkface)) {
492 myJustGluer = Standard_True;
494 if (myJustGluer) return;
497 // myPbase.Orientation(TopAbs_FORWARD);
500 myPerfSelection = BRepFeat_SelectionFU;
501 PerfSelectionValid();
503 TopExp_Explorer exp(From, TopAbs_FACE);
505 Standard_ConstructionError::Raise();
507 exp.Init(Until, TopAbs_FACE);
509 Standard_ConstructionError::Raise();
512 Standard_Boolean Trff = TransformShapeFU(0);
515 Standard_Boolean Trfu = TransformShapeFU(1);
519 myStatusError = BRepFeat_IncTypes;
522 Handle(Geom_Curve) C = TestCurve(myPbase);
523 Standard_Integer sens;
524 if(From.IsSame(Until)) {
528 sens = SensOfPrism(C, mySUntil);
531 Standard_Real Height =
532 sens*HeightMax(mySbase, myPbase, mySFrom, mySUntil);
533 LocOpe_DPrism theDPrism(myPbase, Height, Height, myAngle);
534 TopoDS_Shape VraiDPrism = theDPrism.Shape();
538 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
540 // Make systematically dprism
541 myGShape = VraiDPrism;
542 GeneratedShapeValid();
544 // management of gluing faces
545 // mySbase, myPbase, mySlface, theDPrism, myGluedF);
547 theDPrism.Curves(myCurves);
548 myBCurve = theDPrism.BarycCurve();
550 // topologic reconstruction
554 // management of descendants
555 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
556 Handle(Geom_Curve) C1;
563 TColGeom_SequenceOfCurve scur;
566 LocOpe_CSIntersector ASI1(mySUntil);
567 LocOpe_CSIntersector ASI2(mySFrom);
570 TopAbs_Orientation OrU, OrF;
571 TopoDS_Face FFrom, FUntil;
572 //direction of dprism
573 if (ASI1.IsDone() && ASI1.NbPoints(1) >=1) {
575 OrU = ASI1.Point(1,1).Orientation();
578 OrU = ASI1.Point(1,ASI1.NbPoints(1)).Orientation();
580 // Standard_Real prm = ASI1.Point(1,1).Parameter();
581 // if(prm < 0) OrU = TopAbs::Reverse(OrU);
582 FUntil = ASI1.Point(1,1).Face();
586 myStatusError = BRepFeat_NoIntersectU;
589 if (ASI2.IsDone() && ASI2.NbPoints(1) >=1) {
590 OrF = ASI2.Point(1,1).Orientation();
591 // Standard_Real prm = ASI2.Point(1,1).Parameter();
592 OrF = TopAbs::Reverse(OrF);
593 FFrom = ASI2.Point(1,1).Face();
597 myStatusError = BRepFeat_NoIntersectF;
602 B.MakeCompound(TopoDS::Compound(Comp));
603 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, OrU);
604 if (!S.IsNull()) B.Add(Comp,S);
607 myStatusError = BRepFeat_NullToolU;
610 TopoDS_Solid SS = BRepFeat::Tool(mySFrom, FFrom, OrF);
611 if (!SS.IsNull()) B.Add(Comp,SS);
614 myStatusError = BRepFeat_NullToolF;
618 //modified by NIZNHY-PKV Thu Mar 21 17:35:48 2002 f
619 //BRepAlgo_Cut trP(VraiDPrism,Comp);
620 BRepAlgoAPI_Cut trP(VraiDPrism,Comp);
621 //modified by NIZNHY-PKV Thu Mar 21 17:35:59 2002 t
624 //modified by NIZNHY-PKV Thu Mar 21 17:36:06 2002 f
625 //BRepAlgo_Fuse f(mySbase, trP.Shape());
626 //myShape = f.Shape();
627 //UpdateDescendants(f.Builder(), myShape, Standard_False);
628 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
630 UpdateDescendants(f, myShape, Standard_False);
631 //modified by NIZNHY-PKV Thu Mar 21 17:36:33 2002 t
635 else if(myFuse == 0) {
636 //modified by NIZNHY-PKV Thu Mar 21 17:37:16 2002 f
637 //BRepAlgo_Cut c(mySbase, trP.Shape());
638 //myShape = c.Shape();
639 //UpdateDescendants(c.Builder(), myShape, Standard_False);
640 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
642 UpdateDescendants(c, myShape, Standard_False);
643 //modified by NIZNHY-PKV Thu Mar 21 17:37:49 2002 t
647 myShape = trP.Shape();
654 //=======================================================================
656 //purpose : feature semi-infinie
657 //=======================================================================
659 void BRepFeat_MakeDPrism::PerformUntilEnd()
662 Standard_Boolean trc = BRepFeat_GettraceFEAT();
663 if (trc) cout << "BRepFeat_MakeDPrism::PerformUntilEnd()" << endl;
665 myPerfSelection = BRepFeat_SelectionSh;
666 PerfSelectionValid();
672 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
673 // myPbase.Orientation(TopAbs_FORWARD);
675 LocOpe_DPrism theDPrism(myPbase, Height, myAngle);
676 TopoDS_Shape VraiDPrism = theDPrism.Shape();
678 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
680 myGShape = VraiDPrism;
681 GeneratedShapeValid();
683 theDPrism.Curves(myCurves);
684 myBCurve = theDPrism.BarycCurve();
688 //=======================================================================
689 //function : PerformFromEnd
690 //purpose : feature semiinfinite limited by the shape Until from the other side
691 //=======================================================================
693 void BRepFeat_MakeDPrism::PerformFromEnd(const TopoDS_Shape& Until)
696 Standard_Boolean trc = BRepFeat_GettraceFEAT();
697 if (trc) cout << "BRepFeat_MakeDPrism::PerformFromEnd(From,Until)" << endl;
699 if (Until.IsNull()) {
700 Standard_ConstructionError::Raise();
702 if (!mySkface.IsNull() && Until.IsSame(mySkface)) {
707 exp.Init(Until, TopAbs_FACE);
709 Standard_ConstructionError::Raise();
711 // myPbase.Orientation(TopAbs_FORWARD);
712 myPerfSelection = BRepFeat_SelectionShU;
713 PerfSelectionValid();
717 Standard_Boolean Trf = TransformShapeFU(1);
719 Handle(Geom_Curve) C = TestCurve(myPbase);
720 Standard_Integer sens = SensOfPrism(C, mySUntil);
721 Standard_Real Height =
722 sens*HeightMax(mySbase, mySkface, mySFrom, mySUntil);
724 LocOpe_DPrism theDPrism(myPbase, Height, Height, myAngle);
725 TopoDS_Shape VraiDPrism = theDPrism.Shape();
726 if(VraiDPrism.IsNull()) {
728 myStatusError = BRepFeat_NullRealTool;
732 if(!Trf) { // case finite face
733 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
734 myGShape = VraiDPrism;
735 GeneratedShapeValid();
738 theDPrism.Curves(myCurves);
739 myBCurve = theDPrism.BarycCurve();
742 else { // case support
743 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
744 Handle(Geom_Curve) C2;
751 TColGeom_SequenceOfCurve scur;
754 LocOpe_CSIntersector ASI1(mySUntil);
755 LocOpe_CSIntersector ASI2(mySbase);
758 TopAbs_Orientation OrU = TopAbs_FORWARD, OrF = TopAbs_FORWARD;
759 TopoDS_Face FUntil, FFrom;
760 if (ASI1.IsDone() && ASI1.NbPoints(1) >=1) {
761 OrU = ASI1.Point(1,1).Orientation();
762 Standard_Real prm = ASI1.Point(1,1).Parameter();
763 if(prm < 0) OrU = TopAbs::Reverse(OrU);
764 FUntil = ASI1.Point(1,1).Face();
767 if (ASI2.IsDone() && ASI2.NbPoints(1) >=1) {
768 Standard_Integer jj = ASI2.NbPoints(1);
769 Standard_Real prm = ASI2.Point(1,1).Parameter();
770 FFrom = ASI2.Point(1, 1).Face();
771 OrF = ASI2.Point(1,1).Orientation();
772 OrF = TopAbs::Reverse(OrF);
773 for(Standard_Integer iii = 1; iii <= jj; iii++) {
774 if(ASI2.Point(1,iii).Parameter() < prm) {
775 prm = ASI2.Point(1,iii).Parameter();
776 FFrom = ASI2.Point(1, iii).Face();
777 OrF = ASI2.Point(1,iii).Orientation();
778 OrF = TopAbs::Reverse(OrF);
781 Handle(Geom_Surface) S = BRep_Tool::Surface(FFrom);
782 if (S->DynamicType() ==
783 STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
784 S = Handle(Geom_RectangularTrimmedSurface)::
785 DownCast(S)->BasisSurface();
787 BRepLib_MakeFace fac(S, Precision::Confusion());
788 mySFrom = fac.Face();
789 Trf = TransformShapeFU(0);
790 // FFrom = TopoDS::Face(mySFrom);
795 B.MakeCompound(TopoDS::Compound(Comp));
796 TopoDS_Solid Sol = BRepFeat::Tool(mySUntil, FUntil, OrU);
797 if (!Sol.IsNull()) B.Add(Comp,Sol);
800 myStatusError = BRepFeat_NullToolU;
804 TopoDS_Solid Sol1 = BRepFeat::Tool(mySFrom, FFrom, OrF);
805 if (!Sol1.IsNull()) B.Add(Comp,Sol1);
808 myStatusError = BRepFeat_NullToolF;
812 //modified by NIZNHY-PKV Thu Mar 21 17:38:33 2002 f
813 //BRepAlgo_Cut trP(VraiDPrism,Comp);
814 BRepAlgoAPI_Cut trP(VraiDPrism,Comp);
815 //modified by NIZNHY-PKV Thu Mar 21 17:38:37 2002 t
817 //modified by NIZNHY-PKV Thu Mar 21 17:40:03 2002 f
818 //BRepAlgo_Fuse f(mySbase, trP.Shape());
819 //myShape = f.Shape();
820 //UpdateDescendants(f.Builder(), myShape, Standard_False);
821 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
823 UpdateDescendants(f, myShape, Standard_False);
824 //modified by NIZNHY-PKV Thu Mar 21 17:40:07 2002 t
827 else if(myFuse == 0) {
828 //modified by NIZNHY-PKV Thu Mar 21 17:40:33 2002 t
829 //BRepAlgo_Cut c(mySbase, trP.Shape());
830 //myShape = c.Shape();
831 //UpdateDescendants(c.Builder(), myShape, Standard_False);
832 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
834 UpdateDescendants(c, myShape, Standard_False);
835 //modified by NIZNHY-PKV Thu Mar 21 17:40:44 2002 t
839 myShape = trP.Shape();
847 //=======================================================================
848 //function : PerformThruAll
849 //purpose : feature throughout the entire initial shape
850 //=======================================================================
852 void BRepFeat_MakeDPrism::PerformThruAll()
855 Standard_Boolean trc = BRepFeat_GettraceFEAT();
856 if (trc) cout << "BRepFeat_MakeDPrism::PerformThruAll()" << endl;
863 myPerfSelection = BRepFeat_NoSelection;
866 myPerfSelection = BRepFeat_SelectionSh;
869 PerfSelectionValid();
870 // myPbase.Orientation(TopAbs_FORWARD);
874 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
875 LocOpe_DPrism theDPrism(myPbase, Height, Height, myAngle);
876 TopoDS_Shape VraiDPrism = theDPrism.Shape();
877 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
879 myGShape = VraiDPrism;
880 GeneratedShapeValid();
883 //modified by NIZNHY-PKV Thu Mar 21 17:46:16 2002 f
884 //BRepAlgo_Cut c(mySbase, myGShape);
885 BRepAlgoAPI_Cut c(mySbase, myGShape);
886 //modified by NIZNHY-PKV Thu Mar 21 17:46:26 2002 t
889 //modified by NIZNHY-PKV Thu Mar 21 17:46:39 2002 f
890 //UpdateDescendants(c.Builder(), myShape, Standard_False);
891 UpdateDescendants(c, myShape, Standard_False);
892 //modified by NIZNHY-PKV Thu Mar 21 17:46:43 2002 t
897 theDPrism.Curves(myCurves);
898 myBCurve = theDPrism.BarycCurve();
904 //=======================================================================
905 //function : PerformUntilHeight
906 //purpose : feature until the shape is of the given height
907 //=======================================================================
909 void BRepFeat_MakeDPrism::PerformUntilHeight(const TopoDS_Shape& Until,
910 const Standard_Real Height)
913 Standard_Boolean trc = BRepFeat_GettraceFEAT();
914 if (trc) cout << "BRepFeat_MakeDPrism::PerformUntilHeight(Until,Height)" << endl;
916 if (Until.IsNull()) {
922 TopExp_Explorer exp(Until, TopAbs_FACE);
924 Standard_ConstructionError::Raise();
926 // myPbase.Orientation(TopAbs_FORWARD);
928 myPerfSelection = BRepFeat_NoSelection;
929 PerfSelectionValid();
933 Standard_Boolean Trf = TransformShapeFU(1);
935 Handle(Geom_Curve) C = TestCurve(myPbase);
936 Standard_Integer sens = SensOfPrism(C, mySUntil);
938 LocOpe_DPrism theDPrism(myPbase,sens*Height,myAngle);
939 TopoDS_Shape VraiDPrism = theDPrism.Shape();
941 if(!Trf) { // case face finished
942 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
943 myGShape = VraiDPrism;
944 GeneratedShapeValid();
945 TopoDS_Shape Base = theDPrism.FirstShape();
946 exp.Init(Base, TopAbs_FACE);
947 TopoDS_Face theBase = TopoDS::Face(exp.Current());
951 myStatusError = BRepFeat_InvFirstShape;
956 theDPrism.Curves(myCurves);
957 myBCurve = theDPrism.BarycCurve();
960 else { // case support
961 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
962 Handle(Geom_Curve) C1;
969 TColGeom_SequenceOfCurve scur;
972 LocOpe_CSIntersector ASI(mySUntil);
974 TopAbs_Orientation Or;
975 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
977 Or = ASI.Point(1,1).Orientation();
980 Or = ASI.Point(1,ASI.NbPoints(1)).Orientation();
982 // Standard_Real prm = ASI.Point(1,1).Parameter();
983 // if(prm < 0) Or = TopAbs::Reverse(Or);
984 TopoDS_Face FUntil = ASI.Point(1,1).Face();
987 B.MakeCompound(TopoDS::Compound(Comp));
988 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
989 if (!S.IsNull()) B.Add(Comp,S);
990 //modified by NIZNHY-PKV Thu Mar 21 17:47:14 2002 f
991 //BRepAlgo_Cut trP(VraiDPrism,Comp);
992 BRepAlgoAPI_Cut trP(VraiDPrism,Comp);
993 //modified by NIZNHY-PKV Thu Mar 21 17:47:21 2002 t
995 //modified by NIZNHY-PKV Thu Mar 21 17:47:42 2002 f
996 //BRepAlgo_Fuse f(mySbase, trP.Shape());
997 //myShape = f.Shape();
998 //UpdateDescendants(f.Builder(), myShape, Standard_False);
999 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
1000 myShape = f.Shape();
1001 UpdateDescendants(f, myShape, Standard_False);
1002 //modified by NIZNHY-PKV Thu Mar 21 17:47:49 2002 t
1005 else if(myFuse == 0) {
1006 //modified by NIZNHY-PKV Thu Mar 21 17:48:18 2002 f
1007 //BRepAlgo_Cut c(mySbase, trP.Shape());
1008 //myShape = c.Shape();
1009 //UpdateDescendants(c.Builder(), myShape, Standard_False);
1010 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
1011 myShape = c.Shape();
1012 UpdateDescendants(c, myShape, Standard_False);
1013 //modified by NIZNHY-PKV Thu Mar 21 17:48:26 2002 t
1017 myShape = trP.Shape();
1025 //=======================================================================
1027 //purpose : curves parallel to the axis of the prism
1028 //=======================================================================
1030 void BRepFeat_MakeDPrism::Curves(TColGeom_SequenceOfCurve& scur)
1035 //============================================================================
1036 // function : BRepFeat_BossEgdes
1037 // purpose: Determination of TopEdges and LatEdges.
1038 // sig = 1 -> TopEdges = FirstShape of the DPrism
1039 // sig = 2 -> TOpEdges = LastShape of the DPrism
1040 //============================================================================
1041 void BRepFeat_MakeDPrism::BossEdges (const Standard_Integer signature)
1044 Standard_Boolean trc = BRepFeat_GettraceFEAT();
1045 if (trc) cout << "BRepFeat_MakeDPrism::BossEdges (integer)" << endl;
1047 TopTools_ListOfShape theLastShape;
1048 theLastShape.Clear();
1049 if (signature == 1 || signature == -1) {
1050 theLastShape = FirstShape();
1052 else if (signature == 2 || signature == -2) {
1053 theLastShape = LastShape();
1060 TopTools_ListIteratorOfListOfShape itLS;
1061 TopExp_Explorer ExpE;
1062 for (itLS.Initialize(theLastShape);itLS.More();itLS.Next()) {
1063 const TopoDS_Face& FF = TopoDS::Face(itLS.Value());
1064 for (ExpE.Init(FF,TopAbs_EDGE);ExpE.More();ExpE.Next()) {
1065 const TopoDS_Edge& EE = TopoDS::Edge(ExpE.Current());
1066 myTopEdges.Append(EE);
1071 if (signature < 0) {
1072 // Attention check if TgtEdges is important
1073 myLatEdges = NewEdges();
1075 else if (signature > 0) {
1076 if ( !myShape.IsNull() ) {
1077 TopTools_MapOfShape MapE;
1078 Standard_Boolean Found;
1080 TopExp_Explorer ExpF;
1081 for (ExpF.Init(myShape,TopAbs_FACE);ExpF.More();ExpF.Next()) {
1082 Found = Standard_False;
1083 const TopoDS_Face& FF = TopoDS::Face(ExpF.Current());
1084 for (itLS.Initialize(theLastShape);itLS.More();itLS.Next()) {
1085 const TopoDS_Face& TopFace = TopoDS::Face(itLS.Value());
1086 if (!FF.IsSame(TopFace)) {
1087 TopExp_Explorer ExpE;
1088 for (ExpE.Init(FF,TopAbs_EDGE);ExpE.More() && !Found ;ExpE.Next()) {
1089 const TopoDS_Edge& E1 = TopoDS::Edge(ExpE.Current());
1090 TopoDS_Vertex V1,V2;
1091 TopExp::Vertices (E1,V1,V2);
1092 TopTools_ListIteratorOfListOfShape it(myTopEdges);
1093 for (;it.More() && !Found ; it.Next()) {
1094 TopoDS_Edge E2 = TopoDS::Edge(it.Value());
1095 TopoDS_Vertex VT1,VT2;
1096 TopExp::Vertices (E2,VT1,VT2);
1098 if (V1.IsSame(VT1) || V1.IsSame(VT2) || V2.IsSame(VT1) || V2.IsSame(VT2)) {
1099 Found = Standard_True;
1100 TopExp_Explorer ExpE2;
1101 for (ExpE2.Init(FF,TopAbs_EDGE);ExpE2.More();ExpE2.Next()) {
1102 const TopoDS_Edge& E3 = TopoDS::Edge(ExpE2.Current());
1103 if (MapE.Contains(E3)) {
1115 TopTools_ListIteratorOfListOfShape it(myTopEdges);
1116 for (;it.More() ; it.Next()) {
1117 if (MapE.Contains(it.Value())) {MapE.Remove(it.Value()); }
1120 TopTools_MapIteratorOfMapOfShape itMap;
1121 for (itMap.Initialize(MapE);itMap.More();itMap.Next()) {
1122 if (!BRep_Tool::Degenerated(TopoDS::Edge(itMap.Key())))
1123 myLatEdges.Append(itMap.Key());
1131 //============================================================================
1132 // function : BRepFeat_TopEgdes
1133 // Purpose: Returns the list of TopoDS Edges of the top of the boss
1134 //============================================================================
1135 const TopTools_ListOfShape& BRepFeat_MakeDPrism::TopEdges ()
1140 //============================================================================
1141 // function : BRepFeat_LatEgdes
1142 // Purpose: Returns the list of TopoDS Edges of the top of the boss
1143 //============================================================================
1144 const TopTools_ListOfShape& BRepFeat_MakeDPrism::LatEdges ()
1149 //=======================================================================
1150 //function : BarycCurve
1151 //purpose : passe par le centre de masses de la primitive
1152 //=======================================================================
1154 Handle(Geom_Curve) BRepFeat_MakeDPrism::BarycCurve()
1160 //=======================================================================
1161 //function : HeightMax
1162 //purpose : Calculate the height of the prism following the parameters of the bounding box
1163 //=======================================================================
1165 static Standard_Real HeightMax(const TopoDS_Shape& theSbase, // shape initial
1166 const TopoDS_Face& theSkface, // face de sketch
1167 const TopoDS_Shape& theSFrom, // shape from
1168 const TopoDS_Shape& theSUntil) // shape until
1171 BRepBndLib::Add(theSbase,Box);
1172 BRepBndLib::Add(theSkface,Box);
1173 if(!theSFrom.IsNull()) {
1174 BRepBndLib::Add(theSFrom,Box);
1176 if(!theSUntil.IsNull()) {
1177 BRepBndLib::Add(theSUntil,Box);
1181 Box.Get(c[0],c[2],c[4],c[1],c[3],c[5]);
1182 // Standard_Real parmin=c[0], parmax = c[0];
1183 // for(Standard_Integer i = 0 ; i < 6; i++) {
1184 // if(c[i] > parmax) parmax = c[i];
1185 // if(c[i] < parmin ) parmin = c[i];
1187 // Standard_Real Height = abs(2.*(parmax - parmin));
1188 // return(2.*Height);
1190 Standard_Real par = Max( Max( fabs(c[1] - c[0]), fabs(c[3] - c[2]) ), fabs(c[5] - c[4]) );
1192 // Standard_Real par = Max( Max( abs(c[1] - c[0]), abs(c[3] - c[2]) ), abs(c[5] - c[4]) );
1195 cout << "Height = > " << par << endl;
1204 //=======================================================================
1205 //function : SensOfPrism
1206 //purpose : determine the direction of prism generation
1207 //=======================================================================
1208 Standard_Integer SensOfPrism(const Handle(Geom_Curve) C,
1209 const TopoDS_Shape& Until)
1211 LocOpe_CSIntersector ASI1(Until);
1212 TColGeom_SequenceOfCurve scur;
1215 Standard_Integer sens = 1;
1216 if(ASI1.IsDone() && ASI1.NbPoints(1) >= 1) {
1217 Standard_Integer nb = ASI1.NbPoints(1);
1218 Standard_Real prm1 = ASI1.Point(1, 1).Parameter();
1219 Standard_Real prm2 = ASI1.Point(1, nb).Parameter();
1220 if(prm1 < 0. && prm2 < 0.) {
1224 else if(BRepFeat::ParametricBarycenter(Until,C) < 0) {
1231 //=======================================================================
1234 //=======================================================================
1236 static void MajMap(const TopoDS_Shape& theB,
1237 const LocOpe_DPrism& theP,
1238 TopTools_DataMapOfShapeListOfShape& theMap, // myMap
1239 TopoDS_Shape& theFShape, // myFShape
1240 TopoDS_Shape& theLShape) // myLShape
1242 TopExp_Explorer exp;
1243 if(!theP.FirstShape().IsNull()) {
1244 exp.Init(theP.FirstShape(),TopAbs_WIRE);
1246 theFShape = exp.Current();
1247 TopTools_ListOfShape thelist;
1248 theMap.Bind(theFShape, thelist);
1249 for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) {
1250 theMap(theFShape).Append(exp.Current());
1255 if(!theP.LastShape().IsNull()) {
1256 exp.Init(theP.LastShape(),TopAbs_WIRE);
1258 theLShape = exp.Current();
1259 TopTools_ListOfShape thelist1;
1260 theMap.Bind(theLShape, thelist1);
1261 for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) {
1262 theMap(theLShape).Append(exp.Current());
1267 for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) {
1268 if (!theMap.IsBound(exp.Current())) {
1269 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
1270 TopTools_ListOfShape thelist2;
1271 theMap.Bind(edg, thelist2);
1272 theMap(edg) = theP.Shapes(edg);
1278 //=======================================================================
1281 //=======================================================================
1283 static Handle(Geom_Curve) TestCurve(const TopoDS_Face& Base)
1285 gp_Pnt bar(0., 0., 0.);
1286 TColgp_SequenceOfPnt spt;
1287 LocOpe::SampleEdges(Base,spt);
1288 for (Standard_Integer jj=1;jj<=spt.Length(); jj++) {
1289 const gp_Pnt& pvt = spt(jj);
1290 bar.ChangeCoord() += pvt.XYZ();
1292 bar.ChangeCoord().Divide(spt.Length());
1293 Handle(Geom_Surface) s = BRep_Tool::Surface(Base);
1294 if (s->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1295 s = Handle(Geom_RectangularTrimmedSurface)::
1296 DownCast(s)->BasisSurface();
1298 Handle (Geom_Plane) P = Handle(Geom_Plane)::DownCast(s);
1300 Handle(Geom_Curve) toto;
1303 gp_Pln pp = P->Pln();
1304 gp_Dir Normale(pp.Position().XDirection()^pp.Position().YDirection());
1305 gp_Ax1 theAx(bar, Normale);
1306 Handle(Geom_Line) theLin = new Geom_Line(theAx);
1314 //=======================================================================
1317 //=======================================================================
1319 Standard_Boolean ToFuse(const TopoDS_Face& F1,
1320 const TopoDS_Face& F2)
1322 if (F1.IsNull() || F2.IsNull()) {
1323 return Standard_False;
1326 Handle(Geom_Surface) S1,S2;
1327 TopLoc_Location loc1, loc2;
1328 Handle(Standard_Type) typS1,typS2;
1329 const Standard_Real tollin = Precision::Confusion();
1330 const Standard_Real tolang = Precision::Angular();
1332 S1 = BRep_Tool::Surface(F1,loc1);
1333 S2 = BRep_Tool::Surface(F2,loc2);
1335 typS1 = S1->DynamicType();
1336 typS2 = S2->DynamicType();
1338 if (typS1 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1339 S1 = (*((Handle(Geom_RectangularTrimmedSurface)*)&S1))->BasisSurface();
1340 typS1 = S1->DynamicType();
1343 if (typS2 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1344 S2 = (*((Handle(Geom_RectangularTrimmedSurface)*)&S2))->BasisSurface();
1345 typS2 = S2->DynamicType();
1348 if (typS1 != typS2) {
1349 return Standard_False;
1353 Standard_Boolean ValRet = Standard_False;
1354 if (typS1 == STANDARD_TYPE(Geom_Plane)) {
1355 S1 = BRep_Tool::Surface(F1); // to apply the location.
1356 S2 = BRep_Tool::Surface(F2);
1357 gp_Pln pl1( (*((Handle(Geom_Plane)*)&S1))->Pln());
1358 gp_Pln pl2( (*((Handle(Geom_Plane)*)&S2))->Pln());
1360 if (pl1.Position().IsCoplanar(pl2.Position(),tollin,tolang)) {
1361 ValRet = Standard_True;