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.
18 #include <Bnd_Box.hxx>
19 #include <BRep_Builder.hxx>
20 #include <BRep_Tool.hxx>
21 #include <BRepAlgo.hxx>
22 #include <BRepAlgoAPI_Cut.hxx>
23 #include <BRepAlgoAPI_Fuse.hxx>
24 #include <BRepBndLib.hxx>
25 #include <BRepFeat.hxx>
26 #include <BRepFeat_MakeDPrism.hxx>
27 #include <BRepLib.hxx>
28 #include <BRepLib_MakeFace.hxx>
29 #include <BRepPrimAPI_MakeBox.hxx>
30 #include <BRepTools.hxx>
31 #include <Geom2d_Curve.hxx>
32 #include <Geom_Curve.hxx>
33 #include <Geom_Line.hxx>
34 #include <Geom_Plane.hxx>
35 #include <Geom_RectangularTrimmedSurface.hxx>
36 #include <Geom_Surface.hxx>
39 #include <gp_Pnt2d.hxx>
42 #include <LocOpe_CSIntersector.hxx>
43 #include <LocOpe_DPrism.hxx>
44 #include <LocOpe_PntFace.hxx>
45 #include <LocOpe_SequenceOfLin.hxx>
46 #include <Precision.hxx>
47 #include <Standard_ConstructionError.hxx>
48 #include <TColGeom_SequenceOfCurve.hxx>
49 #include <TColgp_SequenceOfPnt.hxx>
52 #include <TopExp_Explorer.hxx>
54 #include <TopoDS_Compound.hxx>
55 #include <TopoDS_Edge.hxx>
56 #include <TopoDS_Face.hxx>
57 #include <TopoDS_Shape.hxx>
58 #include <TopoDS_Shell.hxx>
59 #include <TopoDS_Solid.hxx>
60 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
61 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
62 #include <TopTools_ListIteratorOfListOfShape.hxx>
63 #include <TopTools_MapIteratorOfMapOfShape.hxx>
64 #include <TopTools_MapOfShape.hxx>
66 //modified by NIZNHY-PKV Thu Mar 21 17:49:46 2002 f
67 //#include <BRepAlgo_Cut.hxx>
68 //#include <BRepAlgo_Fuse.hxx>
69 //modified by NIZNHY-PKV Thu Mar 21 17:50:04 2002 t
71 extern Standard_Boolean BRepFeat_GettraceFEAT();
74 static void MajMap(const TopoDS_Shape&,
76 TopTools_DataMapOfShapeListOfShape&, // myMap
77 TopoDS_Shape&, // myFShape
78 TopoDS_Shape&); // myLShape
80 static Standard_Real HeightMax(const TopoDS_Shape& theSbase,
81 const TopoDS_Face& theSkface,
82 const TopoDS_Shape& theSFrom,
83 const TopoDS_Shape& theSUntil);
85 static Standard_Integer SensOfPrism(const Handle(Geom_Curve) C,
86 const TopoDS_Shape& Until);
88 static Handle(Geom_Curve) TestCurve(const TopoDS_Face&);
90 static Standard_Boolean ToFuse(const TopoDS_Face& ,
95 //=======================================================================
98 //=======================================================================
100 void BRepFeat_MakeDPrism::Init(const TopoDS_Shape& Sbase,
101 const TopoDS_Face& Pbase,
102 const TopoDS_Face& Skface,
103 const Standard_Real Angle,
104 const Standard_Integer Mode,
105 const Standard_Boolean Modify)
109 Standard_Boolean trc = BRepFeat_GettraceFEAT();
110 if (trc) cout << "BRepFeat_MakeDPrism::Init" << endl;
119 myFuse = Standard_False;
120 myJustFeat = Standard_False;
123 myFuse = Standard_True;
124 myJustFeat = Standard_False;
127 myFuse = Standard_True;
128 myJustFeat = Standard_True;
133 myJustGluer = Standard_False;
137 //mySkface.Nullify();
147 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
148 TopTools_ListOfShape thelist;
149 myMap.Bind(exp.Current(), thelist);
150 myMap(exp.Current()).Append(exp.Current());
155 if (myJustFeat) cout << " Just Feature" << endl;
156 if (myFuse) cout << " Fuse" << endl;
157 if (!myFuse) cout << " Cut" << endl;
158 if (!myModify) cout << " Modify = 0" << endl;
159 // cout <<" Angle = " << myAngle << endl;
165 //=======================================================================
167 //purpose : add sliding faces and edges
168 //=======================================================================
170 void BRepFeat_MakeDPrism::Add(const TopoDS_Edge& E,
171 const TopoDS_Face& F)
174 Standard_Boolean trc = BRepFeat_GettraceFEAT();
175 if (trc) cout << "BRepFeat_MakeDPrism::Add(Edge,face)" << endl;
178 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
179 if (exp.Current().IsSame(F)) {
184 Standard_ConstructionError::Raise();
187 for (exp.Init(myPbase,TopAbs_EDGE);exp.More();exp.Next()) {
188 if (exp.Current().IsSame(E)) {
193 Standard_ConstructionError::Raise();
196 if (!mySlface.IsBound(F)) {
197 TopTools_ListOfShape thelist;
198 mySlface.Bind(F, thelist);
200 TopTools_ListIteratorOfListOfShape itl(mySlface(F));
201 for (; itl.More();itl.Next()) {
202 if (itl.Value().IsSame(E)) {
207 mySlface(F).Append(E);
212 //=======================================================================
214 //purpose : feature of Height
215 //=======================================================================
217 void BRepFeat_MakeDPrism::Perform(const Standard_Real Height)
220 Standard_Boolean trc = BRepFeat_GettraceFEAT();
221 if (trc) cout << "BRepFeat_MakeDPrism::Perform(Height)" << endl;
228 myPerfSelection = BRepFeat_NoSelection;
229 PerfSelectionValid();
231 Standard_Real theheight = Height/cos(myAngle);
232 // myPbase.Orientation(TopAbs_FORWARD);
234 LocOpe_DPrism theDPrism(myPbase,theheight,myAngle);
235 TopoDS_Shape VraiDPrism = theDPrism.Shape();
237 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
239 myGShape = VraiDPrism;
240 GeneratedShapeValid();
241 TopoDS_Shape Base = theDPrism.FirstShape();
242 TopExp_Explorer exp(Base, TopAbs_FACE);
243 TopoDS_Face theBase = TopoDS::Face(exp.Current());
247 myStatusError = BRepFeat_InvFirstShape;
253 Standard_Boolean found = Standard_False;
255 if(!mySkface.IsNull() || !mySlface.IsEmpty()) {
256 if(myLShape.ShapeType() == TopAbs_WIRE) {
257 TopExp_Explorer ex1(VraiDPrism, TopAbs_FACE);
258 for(; ex1.More(); ex1.Next()) {
259 TopExp_Explorer ex2(ex1.Current(), TopAbs_WIRE);
260 for(; ex2.More(); ex2.Next()) {
261 if(ex2.Current().IsSame(myLShape)) {
262 FFace = TopoDS::Face(ex1.Current());
263 found = Standard_True;
271 TopExp_Explorer anExp(mySbase, TopAbs_FACE);
272 for(; anExp.More(); anExp.Next()) {
273 const TopoDS_Face& ff = TopoDS::Face(anExp.Current());
274 if(ToFuse(ff, FFace)) {
275 TopTools_DataMapOfShapeListOfShape sl;
281 // management of gluing faces
285 if(!myGluedF.IsEmpty()) { // case gluing
286 myJustGluer = Standard_True;
287 theDPrism.Curves(myCurves);
288 myBCurve = theDPrism.BarycCurve();
292 // if there is no gluing -> call topological operations
295 //modified by NIZNHY-PKV Thu Mar 21 17:32:17 2002 f
296 //BRepAlgo_Fuse f(mySbase, myGShape);
297 //myShape = f.Shape();
298 //UpdateDescendants(f.Builder(), myShape, Standard_False);
299 BRepAlgoAPI_Fuse f(mySbase, myGShape);
301 UpdateDescendants(f, myShape, Standard_False);
302 //modified by NIZNHY-PKV Thu Mar 21 17:32:23 2002 t
305 else if(myFuse == 0) {
306 //modified by NIZNHY-PKV Thu Mar 21 17:32:57 2002 f
307 //BRepAlgo_Cut c(mySbase, myGShape);
308 //myShape = c.Shape();
309 //UpdateDescendants(c.Builder(), myShape, Standard_False);
310 BRepAlgoAPI_Cut c(mySbase, myGShape);
312 UpdateDescendants(c, myShape, Standard_False);
313 //modified by NIZNHY-PKV Thu Mar 21 17:33:00 2002 t
323 //=======================================================================
325 //purpose : feature limited by the shape Until
326 //=======================================================================
328 void BRepFeat_MakeDPrism::Perform(const TopoDS_Shape& Until)
331 Standard_Boolean trc = BRepFeat_GettraceFEAT();
332 if (trc) cout << "BRepFeat_MakeDPrism::Perform(Until)" << endl;
334 if (Until.IsNull()) {
335 Standard_ConstructionError::Raise();
337 TopExp_Explorer exp(Until, TopAbs_FACE);
339 Standard_ConstructionError::Raise();
341 // myPbase.Orientation(TopAbs_FORWARD);
344 myPerfSelection = BRepFeat_SelectionU;
345 PerfSelectionValid();
349 Standard_Boolean Trf = TransformShapeFU(1);
351 Handle(Geom_Curve) C = TestCurve(myPbase);
352 Standard_Integer sens = SensOfPrism(C, mySUntil);
355 Standard_Real Height =
356 sens*HeightMax(mySbase, mySkface, mySFrom, mySUntil);
357 LocOpe_DPrism theDPrism(myPbase,Height,myAngle);
358 TopoDS_Shape VraiDPrism = theDPrism.Shape();
360 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
361 myGShape = VraiDPrism;
362 GeneratedShapeValid();
363 TopoDS_Shape Base = theDPrism.FirstShape();
364 exp.Init(Base, TopAbs_FACE);
365 TopoDS_Face theBase = TopoDS::Face(exp.Current());
369 myStatusError = BRepFeat_InvFirstShape;
374 theDPrism.Curves(myCurves);
375 myBCurve = theDPrism.BarycCurve();
379 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
380 Handle(Geom_Curve) C1;
388 TColGeom_SequenceOfCurve scur;
391 LocOpe_CSIntersector ASI(mySUntil);
393 TopAbs_Orientation Or;
394 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
396 Or = ASI.Point(1,1).Orientation();
399 Or = ASI.Point(1,ASI.NbPoints(1)).Orientation();
401 // Standard_Real prm = ASI.Point(1,1).Parameter();
402 // if(prm < 0) Or = TopAbs::Reverse(Or);
403 TopoDS_Face FUntil = ASI.Point(1,1).Face();
405 bB.MakeCompound(TopoDS::Compound(Comp));
406 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
407 if (!S.IsNull()) bB.Add(Comp,S);
409 //modified by NIZNHY-PKV Thu Mar 21 17:33:27 2002
410 //BRepAlgo_Cut trP(VraiDPrism,Comp);
411 //UpdateDescendants(trP.Builder(),trP.Shape(), Standard_False);
412 BRepAlgoAPI_Cut trP(VraiDPrism,Comp);
413 UpdateDescendants(trP, trP.Shape(), Standard_False);
414 //modified by NIZNHY-PKV Thu Mar 21 17:33:32 2002 t
416 TopExp_Explorer ex(trP.Shape(), TopAbs_SOLID);
417 TopoDS_Shape Cutsh = ex.Current();
419 //modified by NIZNHY-PKV Thu Mar 21 17:34:09 2002 f
420 //BRepAlgo_Fuse f(mySbase, Cutsh);
421 //myShape = f.Shape();
422 //UpdateDescendants(f.Builder(), myShape, Standard_False);
423 BRepAlgoAPI_Fuse f(mySbase, Cutsh);
425 UpdateDescendants(f, myShape, Standard_False);
426 //modified by NIZNHY-PKV Thu Mar 21 17:34:13 2002 t
429 else if(myFuse == 0) {
430 //modified by NIZNHY-PKV Thu Mar 21 17:34:56 2002 f
431 //BRepAlgo_Cut c(mySbase, Cutsh);
432 //myShape = c.Shape();
433 //UpdateDescendants(c.Builder(), myShape, Standard_False);
434 BRepAlgoAPI_Cut c(mySbase, Cutsh);
436 UpdateDescendants(c, myShape, Standard_False);
437 //modified by NIZNHY-PKV Thu Mar 21 17:34:59 2002 t
446 TopTools_ListIteratorOfListOfShape ited(myNewEdges);
447 for (; ited.More();ited.Next()) {
448 const TopoDS_Edge& ledg=TopoDS::Edge(ited.Value());
449 if (!BRepAlgo::IsValid(ledg)) {
450 bB.SameRange(ledg, Standard_False);
451 bB.SameParameter(ledg, Standard_False);
452 BRepLib::SameParameter(ledg, BRep_Tool::Tolerance(ledg));
458 //=======================================================================
460 //purpose : feature limited by two shapes
461 //=======================================================================
463 void BRepFeat_MakeDPrism::Perform(const TopoDS_Shape& From,
464 const TopoDS_Shape& Until)
467 Standard_Boolean trc = BRepFeat_GettraceFEAT();
468 if (trc) cout << "BRepFeat_MakeDPrism::Perform(From,Until)" << endl;
470 if (From.IsNull() || Until.IsNull()) {
471 Standard_ConstructionError::Raise();
474 if (!mySkface.IsNull()) {
475 if (From.IsSame(mySkface)) {
476 myJustGluer = Standard_True;
478 if (myJustGluer) return;
480 else if (Until.IsSame(mySkface)) {
481 myJustGluer = Standard_True;
483 if (myJustGluer) return;
486 // myPbase.Orientation(TopAbs_FORWARD);
489 myPerfSelection = BRepFeat_SelectionFU;
490 PerfSelectionValid();
492 TopExp_Explorer exp(From, TopAbs_FACE);
494 Standard_ConstructionError::Raise();
496 exp.Init(Until, TopAbs_FACE);
498 Standard_ConstructionError::Raise();
501 Standard_Boolean Trff = TransformShapeFU(0);
504 Standard_Boolean Trfu = TransformShapeFU(1);
508 myStatusError = BRepFeat_IncTypes;
511 Handle(Geom_Curve) C = TestCurve(myPbase);
512 Standard_Integer sens;
513 if(From.IsSame(Until)) {
517 sens = SensOfPrism(C, mySUntil);
520 Standard_Real Height =
521 sens*HeightMax(mySbase, myPbase, mySFrom, mySUntil);
522 LocOpe_DPrism theDPrism(myPbase, Height, Height, myAngle);
523 TopoDS_Shape VraiDPrism = theDPrism.Shape();
527 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
529 // Make systematically dprism
530 myGShape = VraiDPrism;
531 GeneratedShapeValid();
533 // management of gluing faces
534 // mySbase, myPbase, mySlface, theDPrism, myGluedF);
536 theDPrism.Curves(myCurves);
537 myBCurve = theDPrism.BarycCurve();
539 // topologic reconstruction
543 // management of descendants
544 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
545 Handle(Geom_Curve) C1;
552 TColGeom_SequenceOfCurve scur;
555 LocOpe_CSIntersector ASI1(mySUntil);
556 LocOpe_CSIntersector ASI2(mySFrom);
559 TopAbs_Orientation OrU, OrF;
560 TopoDS_Face FFrom, FUntil;
561 //direction of dprism
562 if (ASI1.IsDone() && ASI1.NbPoints(1) >=1) {
564 OrU = ASI1.Point(1,1).Orientation();
567 OrU = ASI1.Point(1,ASI1.NbPoints(1)).Orientation();
569 // Standard_Real prm = ASI1.Point(1,1).Parameter();
570 // if(prm < 0) OrU = TopAbs::Reverse(OrU);
571 FUntil = ASI1.Point(1,1).Face();
575 myStatusError = BRepFeat_NoIntersectU;
578 if (ASI2.IsDone() && ASI2.NbPoints(1) >=1) {
579 OrF = ASI2.Point(1,1).Orientation();
580 // Standard_Real prm = ASI2.Point(1,1).Parameter();
581 OrF = TopAbs::Reverse(OrF);
582 FFrom = ASI2.Point(1,1).Face();
586 myStatusError = BRepFeat_NoIntersectF;
591 B.MakeCompound(TopoDS::Compound(Comp));
592 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, OrU);
593 if (!S.IsNull()) B.Add(Comp,S);
596 myStatusError = BRepFeat_NullToolU;
599 TopoDS_Solid SS = BRepFeat::Tool(mySFrom, FFrom, OrF);
600 if (!SS.IsNull()) B.Add(Comp,SS);
603 myStatusError = BRepFeat_NullToolF;
607 //modified by NIZNHY-PKV Thu Mar 21 17:35:48 2002 f
608 //BRepAlgo_Cut trP(VraiDPrism,Comp);
609 BRepAlgoAPI_Cut trP(VraiDPrism,Comp);
610 //modified by NIZNHY-PKV Thu Mar 21 17:35:59 2002 t
613 //modified by NIZNHY-PKV Thu Mar 21 17:36:06 2002 f
614 //BRepAlgo_Fuse f(mySbase, trP.Shape());
615 //myShape = f.Shape();
616 //UpdateDescendants(f.Builder(), myShape, Standard_False);
617 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
619 UpdateDescendants(f, myShape, Standard_False);
620 //modified by NIZNHY-PKV Thu Mar 21 17:36:33 2002 t
624 else if(myFuse == 0) {
625 //modified by NIZNHY-PKV Thu Mar 21 17:37:16 2002 f
626 //BRepAlgo_Cut c(mySbase, trP.Shape());
627 //myShape = c.Shape();
628 //UpdateDescendants(c.Builder(), myShape, Standard_False);
629 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
631 UpdateDescendants(c, myShape, Standard_False);
632 //modified by NIZNHY-PKV Thu Mar 21 17:37:49 2002 t
636 myShape = trP.Shape();
643 //=======================================================================
645 //purpose : feature semi-infinie
646 //=======================================================================
648 void BRepFeat_MakeDPrism::PerformUntilEnd()
651 Standard_Boolean trc = BRepFeat_GettraceFEAT();
652 if (trc) cout << "BRepFeat_MakeDPrism::PerformUntilEnd()" << endl;
654 myPerfSelection = BRepFeat_SelectionSh;
655 PerfSelectionValid();
661 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
662 // myPbase.Orientation(TopAbs_FORWARD);
664 LocOpe_DPrism theDPrism(myPbase, Height, myAngle);
665 TopoDS_Shape VraiDPrism = theDPrism.Shape();
667 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
669 myGShape = VraiDPrism;
670 GeneratedShapeValid();
672 theDPrism.Curves(myCurves);
673 myBCurve = theDPrism.BarycCurve();
677 //=======================================================================
678 //function : PerformFromEnd
679 //purpose : feature semiinfinite limited by the shape Until from the other side
680 //=======================================================================
682 void BRepFeat_MakeDPrism::PerformFromEnd(const TopoDS_Shape& Until)
685 Standard_Boolean trc = BRepFeat_GettraceFEAT();
686 if (trc) cout << "BRepFeat_MakeDPrism::PerformFromEnd(From,Until)" << endl;
688 if (Until.IsNull()) {
689 Standard_ConstructionError::Raise();
691 if (!mySkface.IsNull() && Until.IsSame(mySkface)) {
696 exp.Init(Until, TopAbs_FACE);
698 Standard_ConstructionError::Raise();
700 // myPbase.Orientation(TopAbs_FORWARD);
701 myPerfSelection = BRepFeat_SelectionShU;
702 PerfSelectionValid();
706 Standard_Boolean Trf = TransformShapeFU(1);
708 Handle(Geom_Curve) C = TestCurve(myPbase);
709 Standard_Integer sens = SensOfPrism(C, mySUntil);
710 Standard_Real Height =
711 sens*HeightMax(mySbase, mySkface, mySFrom, mySUntil);
713 LocOpe_DPrism theDPrism(myPbase, Height, Height, myAngle);
714 TopoDS_Shape VraiDPrism = theDPrism.Shape();
715 if(VraiDPrism.IsNull()) {
717 myStatusError = BRepFeat_NullRealTool;
721 if(!Trf) { // case finite face
722 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
723 myGShape = VraiDPrism;
724 GeneratedShapeValid();
727 theDPrism.Curves(myCurves);
728 myBCurve = theDPrism.BarycCurve();
731 else { // case support
732 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
733 Handle(Geom_Curve) C2;
740 TColGeom_SequenceOfCurve scur;
743 LocOpe_CSIntersector ASI1(mySUntil);
744 LocOpe_CSIntersector ASI2(mySbase);
747 TopAbs_Orientation OrU = TopAbs_FORWARD, OrF = TopAbs_FORWARD;
748 TopoDS_Face FUntil, FFrom;
749 if (ASI1.IsDone() && ASI1.NbPoints(1) >=1) {
750 OrU = ASI1.Point(1,1).Orientation();
751 Standard_Real prm = ASI1.Point(1,1).Parameter();
752 if(prm < 0) OrU = TopAbs::Reverse(OrU);
753 FUntil = ASI1.Point(1,1).Face();
756 if (ASI2.IsDone() && ASI2.NbPoints(1) >=1) {
757 Standard_Integer jj = ASI2.NbPoints(1);
758 Standard_Real prm = ASI2.Point(1,1).Parameter();
759 FFrom = ASI2.Point(1, 1).Face();
760 OrF = ASI2.Point(1,1).Orientation();
761 OrF = TopAbs::Reverse(OrF);
762 for(Standard_Integer iii = 1; iii <= jj; iii++) {
763 if(ASI2.Point(1,iii).Parameter() < prm) {
764 prm = ASI2.Point(1,iii).Parameter();
765 FFrom = ASI2.Point(1, iii).Face();
766 OrF = ASI2.Point(1,iii).Orientation();
767 OrF = TopAbs::Reverse(OrF);
770 Handle(Geom_Surface) S = BRep_Tool::Surface(FFrom);
771 if (S->DynamicType() ==
772 STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
773 S = Handle(Geom_RectangularTrimmedSurface)::
774 DownCast(S)->BasisSurface();
776 BRepLib_MakeFace fac(S, Precision::Confusion());
777 mySFrom = fac.Face();
778 Trf = TransformShapeFU(0);
779 // FFrom = TopoDS::Face(mySFrom);
784 B.MakeCompound(TopoDS::Compound(Comp));
785 TopoDS_Solid Sol = BRepFeat::Tool(mySUntil, FUntil, OrU);
786 if (!Sol.IsNull()) B.Add(Comp,Sol);
789 myStatusError = BRepFeat_NullToolU;
793 TopoDS_Solid Sol1 = BRepFeat::Tool(mySFrom, FFrom, OrF);
794 if (!Sol1.IsNull()) B.Add(Comp,Sol1);
797 myStatusError = BRepFeat_NullToolF;
801 //modified by NIZNHY-PKV Thu Mar 21 17:38:33 2002 f
802 //BRepAlgo_Cut trP(VraiDPrism,Comp);
803 BRepAlgoAPI_Cut trP(VraiDPrism,Comp);
804 //modified by NIZNHY-PKV Thu Mar 21 17:38:37 2002 t
806 //modified by NIZNHY-PKV Thu Mar 21 17:40:03 2002 f
807 //BRepAlgo_Fuse f(mySbase, trP.Shape());
808 //myShape = f.Shape();
809 //UpdateDescendants(f.Builder(), myShape, Standard_False);
810 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
812 UpdateDescendants(f, myShape, Standard_False);
813 //modified by NIZNHY-PKV Thu Mar 21 17:40:07 2002 t
816 else if(myFuse == 0) {
817 //modified by NIZNHY-PKV Thu Mar 21 17:40:33 2002 t
818 //BRepAlgo_Cut c(mySbase, trP.Shape());
819 //myShape = c.Shape();
820 //UpdateDescendants(c.Builder(), myShape, Standard_False);
821 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
823 UpdateDescendants(c, myShape, Standard_False);
824 //modified by NIZNHY-PKV Thu Mar 21 17:40:44 2002 t
828 myShape = trP.Shape();
836 //=======================================================================
837 //function : PerformThruAll
838 //purpose : feature throughout the entire initial shape
839 //=======================================================================
841 void BRepFeat_MakeDPrism::PerformThruAll()
844 Standard_Boolean trc = BRepFeat_GettraceFEAT();
845 if (trc) cout << "BRepFeat_MakeDPrism::PerformThruAll()" << endl;
852 myPerfSelection = BRepFeat_NoSelection;
855 myPerfSelection = BRepFeat_SelectionSh;
858 PerfSelectionValid();
859 // myPbase.Orientation(TopAbs_FORWARD);
863 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
864 LocOpe_DPrism theDPrism(myPbase, Height, Height, myAngle);
865 TopoDS_Shape VraiDPrism = theDPrism.Shape();
866 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
868 myGShape = VraiDPrism;
869 GeneratedShapeValid();
872 //modified by NIZNHY-PKV Thu Mar 21 17:46:16 2002 f
873 //BRepAlgo_Cut c(mySbase, myGShape);
874 BRepAlgoAPI_Cut c(mySbase, myGShape);
875 //modified by NIZNHY-PKV Thu Mar 21 17:46:26 2002 t
878 //modified by NIZNHY-PKV Thu Mar 21 17:46:39 2002 f
879 //UpdateDescendants(c.Builder(), myShape, Standard_False);
880 UpdateDescendants(c, myShape, Standard_False);
881 //modified by NIZNHY-PKV Thu Mar 21 17:46:43 2002 t
886 theDPrism.Curves(myCurves);
887 myBCurve = theDPrism.BarycCurve();
893 //=======================================================================
894 //function : PerformUntilHeight
895 //purpose : feature until the shape is of the given height
896 //=======================================================================
898 void BRepFeat_MakeDPrism::PerformUntilHeight(const TopoDS_Shape& Until,
899 const Standard_Real Height)
902 Standard_Boolean trc = BRepFeat_GettraceFEAT();
903 if (trc) cout << "BRepFeat_MakeDPrism::PerformUntilHeight(Until,Height)" << endl;
905 if (Until.IsNull()) {
911 TopExp_Explorer exp(Until, TopAbs_FACE);
913 Standard_ConstructionError::Raise();
915 // myPbase.Orientation(TopAbs_FORWARD);
917 myPerfSelection = BRepFeat_NoSelection;
918 PerfSelectionValid();
922 Standard_Boolean Trf = TransformShapeFU(1);
924 Handle(Geom_Curve) C = TestCurve(myPbase);
925 Standard_Integer sens = SensOfPrism(C, mySUntil);
927 LocOpe_DPrism theDPrism(myPbase,sens*Height,myAngle);
928 TopoDS_Shape VraiDPrism = theDPrism.Shape();
930 if(!Trf) { // case face finished
931 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
932 myGShape = VraiDPrism;
933 GeneratedShapeValid();
934 TopoDS_Shape Base = theDPrism.FirstShape();
935 exp.Init(Base, TopAbs_FACE);
936 TopoDS_Face theBase = TopoDS::Face(exp.Current());
940 myStatusError = BRepFeat_InvFirstShape;
945 theDPrism.Curves(myCurves);
946 myBCurve = theDPrism.BarycCurve();
949 else { // case support
950 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
951 Handle(Geom_Curve) C1;
958 TColGeom_SequenceOfCurve scur;
961 LocOpe_CSIntersector ASI(mySUntil);
963 TopAbs_Orientation Or;
964 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
966 Or = ASI.Point(1,1).Orientation();
969 Or = ASI.Point(1,ASI.NbPoints(1)).Orientation();
971 // Standard_Real prm = ASI.Point(1,1).Parameter();
972 // if(prm < 0) Or = TopAbs::Reverse(Or);
973 TopoDS_Face FUntil = ASI.Point(1,1).Face();
976 B.MakeCompound(TopoDS::Compound(Comp));
977 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
978 if (!S.IsNull()) B.Add(Comp,S);
979 //modified by NIZNHY-PKV Thu Mar 21 17:47:14 2002 f
980 //BRepAlgo_Cut trP(VraiDPrism,Comp);
981 BRepAlgoAPI_Cut trP(VraiDPrism,Comp);
982 //modified by NIZNHY-PKV Thu Mar 21 17:47:21 2002 t
984 //modified by NIZNHY-PKV Thu Mar 21 17:47:42 2002 f
985 //BRepAlgo_Fuse f(mySbase, trP.Shape());
986 //myShape = f.Shape();
987 //UpdateDescendants(f.Builder(), myShape, Standard_False);
988 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
990 UpdateDescendants(f, myShape, Standard_False);
991 //modified by NIZNHY-PKV Thu Mar 21 17:47:49 2002 t
994 else if(myFuse == 0) {
995 //modified by NIZNHY-PKV Thu Mar 21 17:48:18 2002 f
996 //BRepAlgo_Cut c(mySbase, trP.Shape());
997 //myShape = c.Shape();
998 //UpdateDescendants(c.Builder(), myShape, Standard_False);
999 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
1000 myShape = c.Shape();
1001 UpdateDescendants(c, myShape, Standard_False);
1002 //modified by NIZNHY-PKV Thu Mar 21 17:48:26 2002 t
1006 myShape = trP.Shape();
1014 //=======================================================================
1016 //purpose : curves parallel to the axis of the prism
1017 //=======================================================================
1019 void BRepFeat_MakeDPrism::Curves(TColGeom_SequenceOfCurve& scur)
1024 //============================================================================
1025 // function : BRepFeat_BossEgdes
1026 // purpose: Determination of TopEdges and LatEdges.
1027 // sig = 1 -> TopEdges = FirstShape of the DPrism
1028 // sig = 2 -> TOpEdges = LastShape of the DPrism
1029 //============================================================================
1030 void BRepFeat_MakeDPrism::BossEdges (const Standard_Integer signature)
1033 Standard_Boolean trc = BRepFeat_GettraceFEAT();
1034 if (trc) cout << "BRepFeat_MakeDPrism::BossEdges (integer)" << endl;
1036 TopTools_ListOfShape theLastShape;
1037 theLastShape.Clear();
1038 if (signature == 1 || signature == -1) {
1039 theLastShape = FirstShape();
1041 else if (signature == 2 || signature == -2) {
1042 theLastShape = LastShape();
1049 TopTools_ListIteratorOfListOfShape itLS;
1050 TopExp_Explorer ExpE;
1051 for (itLS.Initialize(theLastShape);itLS.More();itLS.Next()) {
1052 const TopoDS_Face& FF = TopoDS::Face(itLS.Value());
1053 for (ExpE.Init(FF,TopAbs_EDGE);ExpE.More();ExpE.Next()) {
1054 const TopoDS_Edge& EE = TopoDS::Edge(ExpE.Current());
1055 myTopEdges.Append(EE);
1060 if (signature < 0) {
1061 // Attention check if TgtEdges is important
1062 myLatEdges = NewEdges();
1064 else if (signature > 0) {
1065 if ( !myShape.IsNull() ) {
1066 TopTools_MapOfShape MapE;
1067 Standard_Boolean Found;
1069 TopExp_Explorer ExpF;
1070 for (ExpF.Init(myShape,TopAbs_FACE);ExpF.More();ExpF.Next()) {
1071 Found = Standard_False;
1072 const TopoDS_Face& FF = TopoDS::Face(ExpF.Current());
1073 for (itLS.Initialize(theLastShape);itLS.More();itLS.Next()) {
1074 const TopoDS_Face& TopFace = TopoDS::Face(itLS.Value());
1075 if (!FF.IsSame(TopFace)) {
1076 for (ExpE.Init(FF,TopAbs_EDGE);ExpE.More() && !Found ;ExpE.Next()) {
1077 const TopoDS_Edge& E1 = TopoDS::Edge(ExpE.Current());
1078 TopoDS_Vertex V1,V2;
1079 TopExp::Vertices (E1,V1,V2);
1080 TopTools_ListIteratorOfListOfShape it(myTopEdges);
1081 for (;it.More() && !Found ; it.Next()) {
1082 TopoDS_Edge E2 = TopoDS::Edge(it.Value());
1083 TopoDS_Vertex VT1,VT2;
1084 TopExp::Vertices (E2,VT1,VT2);
1086 if (V1.IsSame(VT1) || V1.IsSame(VT2) || V2.IsSame(VT1) || V2.IsSame(VT2)) {
1087 Found = Standard_True;
1088 TopExp_Explorer ExpE2;
1089 for (ExpE2.Init(FF,TopAbs_EDGE);ExpE2.More();ExpE2.Next()) {
1090 const TopoDS_Edge& E3 = TopoDS::Edge(ExpE2.Current());
1091 if (MapE.Contains(E3)) {
1103 TopTools_ListIteratorOfListOfShape it(myTopEdges);
1104 for (;it.More() ; it.Next()) {
1105 if (MapE.Contains(it.Value())) {MapE.Remove(it.Value()); }
1108 TopTools_MapIteratorOfMapOfShape itMap;
1109 for (itMap.Initialize(MapE);itMap.More();itMap.Next()) {
1110 if (!BRep_Tool::Degenerated(TopoDS::Edge(itMap.Key())))
1111 myLatEdges.Append(itMap.Key());
1119 //============================================================================
1120 // function : BRepFeat_TopEgdes
1121 // Purpose: Returns the list of TopoDS Edges of the top of the boss
1122 //============================================================================
1123 const TopTools_ListOfShape& BRepFeat_MakeDPrism::TopEdges ()
1128 //============================================================================
1129 // function : BRepFeat_LatEgdes
1130 // Purpose: Returns the list of TopoDS Edges of the top of the boss
1131 //============================================================================
1132 const TopTools_ListOfShape& BRepFeat_MakeDPrism::LatEdges ()
1137 //=======================================================================
1138 //function : BarycCurve
1139 //purpose : passe par le centre de masses de la primitive
1140 //=======================================================================
1142 Handle(Geom_Curve) BRepFeat_MakeDPrism::BarycCurve()
1148 //=======================================================================
1149 //function : HeightMax
1150 //purpose : Calculate the height of the prism following the parameters of the bounding box
1151 //=======================================================================
1153 static Standard_Real HeightMax(const TopoDS_Shape& theSbase, // shape initial
1154 const TopoDS_Face& theSkface, // face de sketch
1155 const TopoDS_Shape& theSFrom, // shape from
1156 const TopoDS_Shape& theSUntil) // shape until
1159 BRepBndLib::Add(theSbase,Box);
1160 BRepBndLib::Add(theSkface,Box);
1161 if(!theSFrom.IsNull()) {
1162 BRepBndLib::Add(theSFrom,Box);
1164 if(!theSUntil.IsNull()) {
1165 BRepBndLib::Add(theSUntil,Box);
1169 Box.Get(c[0],c[2],c[4],c[1],c[3],c[5]);
1170 // Standard_Real parmin=c[0], parmax = c[0];
1171 // for(Standard_Integer i = 0 ; i < 6; i++) {
1172 // if(c[i] > parmax) parmax = c[i];
1173 // if(c[i] < parmin ) parmin = c[i];
1175 // Standard_Real Height = abs(2.*(parmax - parmin));
1176 // return(2.*Height);
1177 //#ifndef OCCT_DEBUG
1178 Standard_Real par = Max( Max( fabs(c[1] - c[0]), fabs(c[3] - c[2]) ), fabs(c[5] - c[4]) );
1180 // Standard_Real par = Max( Max( abs(c[1] - c[0]), abs(c[3] - c[2]) ), abs(c[5] - c[4]) );
1183 cout << "Height = > " << par << endl;
1192 //=======================================================================
1193 //function : SensOfPrism
1194 //purpose : determine the direction of prism generation
1195 //=======================================================================
1196 Standard_Integer SensOfPrism(const Handle(Geom_Curve) C,
1197 const TopoDS_Shape& Until)
1199 LocOpe_CSIntersector ASI1(Until);
1200 TColGeom_SequenceOfCurve scur;
1203 Standard_Integer sens = 1;
1204 if(ASI1.IsDone() && ASI1.NbPoints(1) >= 1) {
1205 Standard_Integer nb = ASI1.NbPoints(1);
1206 Standard_Real prm1 = ASI1.Point(1, 1).Parameter();
1207 Standard_Real prm2 = ASI1.Point(1, nb).Parameter();
1208 if(prm1 < 0. && prm2 < 0.) {
1212 else if(BRepFeat::ParametricBarycenter(Until,C) < 0) {
1219 //=======================================================================
1222 //=======================================================================
1224 static void MajMap(const TopoDS_Shape& theB,
1225 const LocOpe_DPrism& theP,
1226 TopTools_DataMapOfShapeListOfShape& theMap, // myMap
1227 TopoDS_Shape& theFShape, // myFShape
1228 TopoDS_Shape& theLShape) // myLShape
1230 TopExp_Explorer exp;
1231 if(!theP.FirstShape().IsNull()) {
1232 exp.Init(theP.FirstShape(),TopAbs_WIRE);
1234 theFShape = exp.Current();
1235 TopTools_ListOfShape thelist;
1236 theMap.Bind(theFShape, thelist);
1237 for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) {
1238 theMap(theFShape).Append(exp.Current());
1243 if(!theP.LastShape().IsNull()) {
1244 exp.Init(theP.LastShape(),TopAbs_WIRE);
1246 theLShape = exp.Current();
1247 TopTools_ListOfShape thelist1;
1248 theMap.Bind(theLShape, thelist1);
1249 for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) {
1250 theMap(theLShape).Append(exp.Current());
1255 for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) {
1256 if (!theMap.IsBound(exp.Current())) {
1257 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
1258 TopTools_ListOfShape thelist2;
1259 theMap.Bind(edg, thelist2);
1260 theMap(edg) = theP.Shapes(edg);
1266 //=======================================================================
1269 //=======================================================================
1271 static Handle(Geom_Curve) TestCurve(const TopoDS_Face& Base)
1273 gp_Pnt bar(0., 0., 0.);
1274 TColgp_SequenceOfPnt spt;
1275 LocOpe::SampleEdges(Base,spt);
1276 for (Standard_Integer jj=1;jj<=spt.Length(); jj++) {
1277 const gp_Pnt& pvt = spt(jj);
1278 bar.ChangeCoord() += pvt.XYZ();
1280 bar.ChangeCoord().Divide(spt.Length());
1281 Handle(Geom_Surface) s = BRep_Tool::Surface(Base);
1282 if (s->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1283 s = Handle(Geom_RectangularTrimmedSurface)::
1284 DownCast(s)->BasisSurface();
1286 Handle (Geom_Plane) P = Handle(Geom_Plane)::DownCast(s);
1288 Handle(Geom_Curve) toto;
1291 gp_Pln pp = P->Pln();
1292 gp_Dir Normale(pp.Position().XDirection()^pp.Position().YDirection());
1293 gp_Ax1 theAx(bar, Normale);
1294 Handle(Geom_Line) theLin = new Geom_Line(theAx);
1302 //=======================================================================
1305 //=======================================================================
1307 Standard_Boolean ToFuse(const TopoDS_Face& F1,
1308 const TopoDS_Face& F2)
1310 if (F1.IsNull() || F2.IsNull()) {
1311 return Standard_False;
1314 Handle(Geom_Surface) S1,S2;
1315 TopLoc_Location loc1, loc2;
1316 Handle(Standard_Type) typS1,typS2;
1317 const Standard_Real tollin = Precision::Confusion();
1318 const Standard_Real tolang = Precision::Angular();
1320 S1 = BRep_Tool::Surface(F1,loc1);
1321 S2 = BRep_Tool::Surface(F2,loc2);
1323 typS1 = S1->DynamicType();
1324 typS2 = S2->DynamicType();
1326 if (typS1 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1327 S1 = Handle(Geom_RectangularTrimmedSurface)::DownCast (S1)->BasisSurface();
1328 typS1 = S1->DynamicType();
1331 if (typS2 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1332 S2 = Handle(Geom_RectangularTrimmedSurface)::DownCast (S2)->BasisSurface();
1333 typS2 = S2->DynamicType();
1336 if (typS1 != typS2) {
1337 return Standard_False;
1341 Standard_Boolean ValRet = Standard_False;
1342 if (typS1 == STANDARD_TYPE(Geom_Plane)) {
1343 S1 = BRep_Tool::Surface(F1); // to apply the location.
1344 S2 = BRep_Tool::Surface(F2);
1345 gp_Pln pl1( Handle(Geom_Plane)::DownCast (S1)->Pln());
1346 gp_Pln pl2( Handle(Geom_Plane)::DownCast (S2)->Pln());
1348 if (pl1.Position().IsCoplanar(pl2.Position(),tollin,tolang)) {
1349 ValRet = Standard_True;