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&);
91 //=======================================================================
94 //=======================================================================
96 void BRepFeat_MakeDPrism::Init(const TopoDS_Shape& Sbase,
97 const TopoDS_Face& Pbase,
98 const TopoDS_Face& Skface,
99 const Standard_Real Angle,
100 const Standard_Integer Mode,
101 const Standard_Boolean Modify)
105 Standard_Boolean trc = BRepFeat_GettraceFEAT();
106 if (trc) cout << "BRepFeat_MakeDPrism::Init" << endl;
115 myFuse = Standard_False;
116 myJustFeat = Standard_False;
119 myFuse = Standard_True;
120 myJustFeat = Standard_False;
123 myFuse = Standard_True;
124 myJustFeat = Standard_True;
129 myJustGluer = Standard_False;
133 //mySkface.Nullify();
143 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
144 TopTools_ListOfShape thelist;
145 myMap.Bind(exp.Current(), thelist);
146 myMap(exp.Current()).Append(exp.Current());
151 if (myJustFeat) cout << " Just Feature" << endl;
152 if (myFuse) cout << " Fuse" << endl;
153 if (!myFuse) cout << " Cut" << endl;
154 if (!myModify) cout << " Modify = 0" << endl;
155 // cout <<" Angle = " << myAngle << endl;
161 //=======================================================================
163 //purpose : add sliding faces and edges
164 //=======================================================================
166 void BRepFeat_MakeDPrism::Add(const TopoDS_Edge& E,
167 const TopoDS_Face& F)
170 Standard_Boolean trc = BRepFeat_GettraceFEAT();
171 if (trc) cout << "BRepFeat_MakeDPrism::Add(Edge,face)" << endl;
174 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
175 if (exp.Current().IsSame(F)) {
180 Standard_ConstructionError::Raise();
183 for (exp.Init(myPbase,TopAbs_EDGE);exp.More();exp.Next()) {
184 if (exp.Current().IsSame(E)) {
189 Standard_ConstructionError::Raise();
192 if (!mySlface.IsBound(F)) {
193 TopTools_ListOfShape thelist;
194 mySlface.Bind(F, thelist);
196 TopTools_ListIteratorOfListOfShape itl(mySlface(F));
197 for (; itl.More();itl.Next()) {
198 if (itl.Value().IsSame(E)) {
203 mySlface(F).Append(E);
208 //=======================================================================
210 //purpose : feature of Height
211 //=======================================================================
213 void BRepFeat_MakeDPrism::Perform(const Standard_Real Height)
216 Standard_Boolean trc = BRepFeat_GettraceFEAT();
217 if (trc) cout << "BRepFeat_MakeDPrism::Perform(Height)" << endl;
224 myPerfSelection = BRepFeat_NoSelection;
225 PerfSelectionValid();
227 Standard_Real theheight = Height/cos(myAngle);
228 // myPbase.Orientation(TopAbs_FORWARD);
230 LocOpe_DPrism theDPrism(myPbase,theheight,myAngle);
231 TopoDS_Shape VraiDPrism = theDPrism.Shape();
233 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
235 myGShape = VraiDPrism;
236 GeneratedShapeValid();
237 TopoDS_Shape Base = theDPrism.FirstShape();
238 TopExp_Explorer exp(Base, TopAbs_FACE);
239 TopoDS_Face theBase = TopoDS::Face(exp.Current());
243 myStatusError = BRepFeat_InvFirstShape;
247 // management of gluing faces
251 if(!myGluedF.IsEmpty()) { // case gluing
252 myJustGluer = Standard_True;
253 theDPrism.Curves(myCurves);
254 myBCurve = theDPrism.BarycCurve();
258 // if there is no gluing -> call topological operations
261 //modified by NIZNHY-PKV Thu Mar 21 17:32:17 2002 f
262 //BRepAlgo_Fuse f(mySbase, myGShape);
263 //myShape = f.Shape();
264 //UpdateDescendants(f.Builder(), myShape, Standard_False);
265 BRepAlgoAPI_Fuse f(mySbase, myGShape);
267 UpdateDescendants(f, myShape, Standard_False);
268 //modified by NIZNHY-PKV Thu Mar 21 17:32:23 2002 t
271 else if(myFuse == 0) {
272 //modified by NIZNHY-PKV Thu Mar 21 17:32:57 2002 f
273 //BRepAlgo_Cut c(mySbase, myGShape);
274 //myShape = c.Shape();
275 //UpdateDescendants(c.Builder(), myShape, Standard_False);
276 BRepAlgoAPI_Cut c(mySbase, myGShape);
278 UpdateDescendants(c, myShape, Standard_False);
279 //modified by NIZNHY-PKV Thu Mar 21 17:33:00 2002 t
289 //=======================================================================
291 //purpose : feature limited by the shape Until
292 //=======================================================================
294 void BRepFeat_MakeDPrism::Perform(const TopoDS_Shape& Until)
297 Standard_Boolean trc = BRepFeat_GettraceFEAT();
298 if (trc) cout << "BRepFeat_MakeDPrism::Perform(Until)" << endl;
300 if (Until.IsNull()) {
301 Standard_ConstructionError::Raise();
303 TopExp_Explorer exp(Until, TopAbs_FACE);
305 Standard_ConstructionError::Raise();
307 // myPbase.Orientation(TopAbs_FORWARD);
310 myPerfSelection = BRepFeat_SelectionU;
311 PerfSelectionValid();
315 Standard_Boolean Trf = TransformShapeFU(1);
317 Handle(Geom_Curve) C = TestCurve(myPbase);
318 Standard_Integer sens = SensOfPrism(C, mySUntil);
321 Standard_Real Height =
322 sens*HeightMax(mySbase, mySkface, mySFrom, mySUntil);
323 LocOpe_DPrism theDPrism(myPbase,Height,myAngle);
324 TopoDS_Shape VraiDPrism = theDPrism.Shape();
326 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
327 myGShape = VraiDPrism;
328 GeneratedShapeValid();
329 TopoDS_Shape Base = theDPrism.FirstShape();
330 exp.Init(Base, TopAbs_FACE);
331 TopoDS_Face theBase = TopoDS::Face(exp.Current());
335 myStatusError = BRepFeat_InvFirstShape;
340 theDPrism.Curves(myCurves);
341 myBCurve = theDPrism.BarycCurve();
345 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
346 Handle(Geom_Curve) C1;
354 TColGeom_SequenceOfCurve scur;
357 LocOpe_CSIntersector ASI(mySUntil);
359 TopAbs_Orientation Or;
360 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
362 Or = ASI.Point(1,1).Orientation();
365 Or = ASI.Point(1,ASI.NbPoints(1)).Orientation();
367 // Standard_Real prm = ASI.Point(1,1).Parameter();
368 // if(prm < 0) Or = TopAbs::Reverse(Or);
369 TopoDS_Face FUntil = ASI.Point(1,1).Face();
371 bB.MakeCompound(TopoDS::Compound(Comp));
372 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
373 if (!S.IsNull()) bB.Add(Comp,S);
375 //modified by NIZNHY-PKV Thu Mar 21 17:33:27 2002
376 //BRepAlgo_Cut trP(VraiDPrism,Comp);
377 //UpdateDescendants(trP.Builder(),trP.Shape(), Standard_False);
378 BRepAlgoAPI_Cut trP(VraiDPrism,Comp);
379 UpdateDescendants(trP, trP.Shape(), Standard_False);
380 //modified by NIZNHY-PKV Thu Mar 21 17:33:32 2002 t
382 TopExp_Explorer ex(trP.Shape(), TopAbs_SOLID);
383 TopoDS_Shape Cutsh = ex.Current();
385 //modified by NIZNHY-PKV Thu Mar 21 17:34:09 2002 f
386 //BRepAlgo_Fuse f(mySbase, Cutsh);
387 //myShape = f.Shape();
388 //UpdateDescendants(f.Builder(), myShape, Standard_False);
389 BRepAlgoAPI_Fuse f(mySbase, Cutsh);
391 UpdateDescendants(f, myShape, Standard_False);
392 //modified by NIZNHY-PKV Thu Mar 21 17:34:13 2002 t
395 else if(myFuse == 0) {
396 //modified by NIZNHY-PKV Thu Mar 21 17:34:56 2002 f
397 //BRepAlgo_Cut c(mySbase, Cutsh);
398 //myShape = c.Shape();
399 //UpdateDescendants(c.Builder(), myShape, Standard_False);
400 BRepAlgoAPI_Cut c(mySbase, Cutsh);
402 UpdateDescendants(c, myShape, Standard_False);
403 //modified by NIZNHY-PKV Thu Mar 21 17:34:59 2002 t
412 TopTools_ListIteratorOfListOfShape ited(myNewEdges);
413 for (; ited.More();ited.Next()) {
414 const TopoDS_Edge& ledg=TopoDS::Edge(ited.Value());
415 if (!BRepAlgo::IsValid(ledg)) {
416 bB.SameRange(ledg, Standard_False);
417 bB.SameParameter(ledg, Standard_False);
418 BRepLib::SameParameter(ledg, BRep_Tool::Tolerance(ledg));
424 //=======================================================================
426 //purpose : feature limited by two shapes
427 //=======================================================================
429 void BRepFeat_MakeDPrism::Perform(const TopoDS_Shape& From,
430 const TopoDS_Shape& Until)
433 Standard_Boolean trc = BRepFeat_GettraceFEAT();
434 if (trc) cout << "BRepFeat_MakeDPrism::Perform(From,Until)" << endl;
436 if (From.IsNull() || Until.IsNull()) {
437 Standard_ConstructionError::Raise();
440 if (!mySkface.IsNull()) {
441 if (From.IsSame(mySkface)) {
442 myJustGluer = Standard_True;
444 if (myJustGluer) return;
446 else if (Until.IsSame(mySkface)) {
447 myJustGluer = Standard_True;
449 if (myJustGluer) return;
452 // myPbase.Orientation(TopAbs_FORWARD);
455 myPerfSelection = BRepFeat_SelectionFU;
456 PerfSelectionValid();
458 TopExp_Explorer exp(From, TopAbs_FACE);
460 Standard_ConstructionError::Raise();
462 exp.Init(Until, TopAbs_FACE);
464 Standard_ConstructionError::Raise();
467 Standard_Boolean Trff = TransformShapeFU(0);
470 Standard_Boolean Trfu = TransformShapeFU(1);
474 myStatusError = BRepFeat_IncTypes;
477 Handle(Geom_Curve) C = TestCurve(myPbase);
478 Standard_Integer sens;
479 if(From.IsSame(Until)) {
483 sens = SensOfPrism(C, mySUntil);
486 Standard_Real Height =
487 sens*HeightMax(mySbase, myPbase, mySFrom, mySUntil);
488 LocOpe_DPrism theDPrism(myPbase, Height, Height, myAngle);
489 TopoDS_Shape VraiDPrism = theDPrism.Shape();
493 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
495 // Make systematically dprism
496 myGShape = VraiDPrism;
497 GeneratedShapeValid();
499 // management of gluing faces
500 // mySbase, myPbase, mySlface, theDPrism, myGluedF);
502 theDPrism.Curves(myCurves);
503 myBCurve = theDPrism.BarycCurve();
505 // topologic reconstruction
509 // management of descendants
510 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
511 Handle(Geom_Curve) C1;
518 TColGeom_SequenceOfCurve scur;
521 LocOpe_CSIntersector ASI1(mySUntil);
522 LocOpe_CSIntersector ASI2(mySFrom);
525 TopAbs_Orientation OrU, OrF;
526 TopoDS_Face FFrom, FUntil;
527 //direction of dprism
528 if (ASI1.IsDone() && ASI1.NbPoints(1) >=1) {
530 OrU = ASI1.Point(1,1).Orientation();
533 OrU = ASI1.Point(1,ASI1.NbPoints(1)).Orientation();
535 // Standard_Real prm = ASI1.Point(1,1).Parameter();
536 // if(prm < 0) OrU = TopAbs::Reverse(OrU);
537 FUntil = ASI1.Point(1,1).Face();
541 myStatusError = BRepFeat_NoIntersectU;
544 if (ASI2.IsDone() && ASI2.NbPoints(1) >=1) {
545 OrF = ASI2.Point(1,1).Orientation();
546 // Standard_Real prm = ASI2.Point(1,1).Parameter();
547 OrF = TopAbs::Reverse(OrF);
548 FFrom = ASI2.Point(1,1).Face();
552 myStatusError = BRepFeat_NoIntersectF;
557 B.MakeCompound(TopoDS::Compound(Comp));
558 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, OrU);
559 if (!S.IsNull()) B.Add(Comp,S);
562 myStatusError = BRepFeat_NullToolU;
565 TopoDS_Solid SS = BRepFeat::Tool(mySFrom, FFrom, OrF);
566 if (!SS.IsNull()) B.Add(Comp,SS);
569 myStatusError = BRepFeat_NullToolF;
573 //modified by NIZNHY-PKV Thu Mar 21 17:35:48 2002 f
574 //BRepAlgo_Cut trP(VraiDPrism,Comp);
575 BRepAlgoAPI_Cut trP(VraiDPrism,Comp);
576 //modified by NIZNHY-PKV Thu Mar 21 17:35:59 2002 t
579 //modified by NIZNHY-PKV Thu Mar 21 17:36:06 2002 f
580 //BRepAlgo_Fuse f(mySbase, trP.Shape());
581 //myShape = f.Shape();
582 //UpdateDescendants(f.Builder(), myShape, Standard_False);
583 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
585 UpdateDescendants(f, myShape, Standard_False);
586 //modified by NIZNHY-PKV Thu Mar 21 17:36:33 2002 t
590 else if(myFuse == 0) {
591 //modified by NIZNHY-PKV Thu Mar 21 17:37:16 2002 f
592 //BRepAlgo_Cut c(mySbase, trP.Shape());
593 //myShape = c.Shape();
594 //UpdateDescendants(c.Builder(), myShape, Standard_False);
595 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
597 UpdateDescendants(c, myShape, Standard_False);
598 //modified by NIZNHY-PKV Thu Mar 21 17:37:49 2002 t
602 myShape = trP.Shape();
609 //=======================================================================
611 //purpose : feature semi-infinie
612 //=======================================================================
614 void BRepFeat_MakeDPrism::PerformUntilEnd()
617 Standard_Boolean trc = BRepFeat_GettraceFEAT();
618 if (trc) cout << "BRepFeat_MakeDPrism::PerformUntilEnd()" << endl;
620 myPerfSelection = BRepFeat_SelectionSh;
621 PerfSelectionValid();
627 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
628 // myPbase.Orientation(TopAbs_FORWARD);
630 LocOpe_DPrism theDPrism(myPbase, Height, myAngle);
631 TopoDS_Shape VraiDPrism = theDPrism.Shape();
633 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
635 myGShape = VraiDPrism;
636 GeneratedShapeValid();
638 theDPrism.Curves(myCurves);
639 myBCurve = theDPrism.BarycCurve();
643 //=======================================================================
644 //function : PerformFromEnd
645 //purpose : feature semiinfinite limited by the shape Until from the other side
646 //=======================================================================
648 void BRepFeat_MakeDPrism::PerformFromEnd(const TopoDS_Shape& Until)
651 Standard_Boolean trc = BRepFeat_GettraceFEAT();
652 if (trc) cout << "BRepFeat_MakeDPrism::PerformFromEnd(From,Until)" << endl;
654 if (Until.IsNull()) {
655 Standard_ConstructionError::Raise();
657 if (!mySkface.IsNull() && Until.IsSame(mySkface)) {
662 exp.Init(Until, TopAbs_FACE);
664 Standard_ConstructionError::Raise();
666 // myPbase.Orientation(TopAbs_FORWARD);
667 myPerfSelection = BRepFeat_SelectionShU;
668 PerfSelectionValid();
672 Standard_Boolean Trf = TransformShapeFU(1);
674 Handle(Geom_Curve) C = TestCurve(myPbase);
675 Standard_Integer sens = SensOfPrism(C, mySUntil);
676 Standard_Real Height =
677 sens*HeightMax(mySbase, mySkface, mySFrom, mySUntil);
679 LocOpe_DPrism theDPrism(myPbase, Height, Height, myAngle);
680 TopoDS_Shape VraiDPrism = theDPrism.Shape();
681 if(VraiDPrism.IsNull()) {
683 myStatusError = BRepFeat_NullRealTool;
687 if(!Trf) { // case finite face
688 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
689 myGShape = VraiDPrism;
690 GeneratedShapeValid();
693 theDPrism.Curves(myCurves);
694 myBCurve = theDPrism.BarycCurve();
697 else { // case support
698 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
699 Handle(Geom_Curve) C2;
706 TColGeom_SequenceOfCurve scur;
709 LocOpe_CSIntersector ASI1(mySUntil);
710 LocOpe_CSIntersector ASI2(mySbase);
713 TopAbs_Orientation OrU = TopAbs_FORWARD, OrF = TopAbs_FORWARD;
714 TopoDS_Face FUntil, FFrom;
715 if (ASI1.IsDone() && ASI1.NbPoints(1) >=1) {
716 OrU = ASI1.Point(1,1).Orientation();
717 Standard_Real prm = ASI1.Point(1,1).Parameter();
718 if(prm < 0) OrU = TopAbs::Reverse(OrU);
719 FUntil = ASI1.Point(1,1).Face();
722 if (ASI2.IsDone() && ASI2.NbPoints(1) >=1) {
723 Standard_Integer jj = ASI2.NbPoints(1);
724 Standard_Real prm = ASI2.Point(1,1).Parameter();
725 FFrom = ASI2.Point(1, 1).Face();
726 OrF = ASI2.Point(1,1).Orientation();
727 OrF = TopAbs::Reverse(OrF);
728 for(Standard_Integer iii = 1; iii <= jj; iii++) {
729 if(ASI2.Point(1,iii).Parameter() < prm) {
730 prm = ASI2.Point(1,iii).Parameter();
731 FFrom = ASI2.Point(1, iii).Face();
732 OrF = ASI2.Point(1,iii).Orientation();
733 OrF = TopAbs::Reverse(OrF);
736 Handle(Geom_Surface) S = BRep_Tool::Surface(FFrom);
737 if (S->DynamicType() ==
738 STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
739 S = Handle(Geom_RectangularTrimmedSurface)::
740 DownCast(S)->BasisSurface();
742 BRepLib_MakeFace fac(S, Precision::Confusion());
743 mySFrom = fac.Face();
744 Trf = TransformShapeFU(0);
745 // FFrom = TopoDS::Face(mySFrom);
750 B.MakeCompound(TopoDS::Compound(Comp));
751 TopoDS_Solid Sol = BRepFeat::Tool(mySUntil, FUntil, OrU);
752 if (!Sol.IsNull()) B.Add(Comp,Sol);
755 myStatusError = BRepFeat_NullToolU;
759 TopoDS_Solid Sol1 = BRepFeat::Tool(mySFrom, FFrom, OrF);
760 if (!Sol1.IsNull()) B.Add(Comp,Sol1);
763 myStatusError = BRepFeat_NullToolF;
767 //modified by NIZNHY-PKV Thu Mar 21 17:38:33 2002 f
768 //BRepAlgo_Cut trP(VraiDPrism,Comp);
769 BRepAlgoAPI_Cut trP(VraiDPrism,Comp);
770 //modified by NIZNHY-PKV Thu Mar 21 17:38:37 2002 t
772 //modified by NIZNHY-PKV Thu Mar 21 17:40:03 2002 f
773 //BRepAlgo_Fuse f(mySbase, trP.Shape());
774 //myShape = f.Shape();
775 //UpdateDescendants(f.Builder(), myShape, Standard_False);
776 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
778 UpdateDescendants(f, myShape, Standard_False);
779 //modified by NIZNHY-PKV Thu Mar 21 17:40:07 2002 t
782 else if(myFuse == 0) {
783 //modified by NIZNHY-PKV Thu Mar 21 17:40:33 2002 t
784 //BRepAlgo_Cut c(mySbase, trP.Shape());
785 //myShape = c.Shape();
786 //UpdateDescendants(c.Builder(), myShape, Standard_False);
787 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
789 UpdateDescendants(c, myShape, Standard_False);
790 //modified by NIZNHY-PKV Thu Mar 21 17:40:44 2002 t
794 myShape = trP.Shape();
802 //=======================================================================
803 //function : PerformThruAll
804 //purpose : feature throughout the entire initial shape
805 //=======================================================================
807 void BRepFeat_MakeDPrism::PerformThruAll()
810 Standard_Boolean trc = BRepFeat_GettraceFEAT();
811 if (trc) cout << "BRepFeat_MakeDPrism::PerformThruAll()" << endl;
818 myPerfSelection = BRepFeat_NoSelection;
821 myPerfSelection = BRepFeat_SelectionSh;
824 PerfSelectionValid();
825 // myPbase.Orientation(TopAbs_FORWARD);
829 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
830 LocOpe_DPrism theDPrism(myPbase, Height, Height, myAngle);
831 TopoDS_Shape VraiDPrism = theDPrism.Shape();
832 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
834 myGShape = VraiDPrism;
835 GeneratedShapeValid();
838 //modified by NIZNHY-PKV Thu Mar 21 17:46:16 2002 f
839 //BRepAlgo_Cut c(mySbase, myGShape);
840 BRepAlgoAPI_Cut c(mySbase, myGShape);
841 //modified by NIZNHY-PKV Thu Mar 21 17:46:26 2002 t
844 //modified by NIZNHY-PKV Thu Mar 21 17:46:39 2002 f
845 //UpdateDescendants(c.Builder(), myShape, Standard_False);
846 UpdateDescendants(c, myShape, Standard_False);
847 //modified by NIZNHY-PKV Thu Mar 21 17:46:43 2002 t
852 theDPrism.Curves(myCurves);
853 myBCurve = theDPrism.BarycCurve();
859 //=======================================================================
860 //function : PerformUntilHeight
861 //purpose : feature until the shape is of the given height
862 //=======================================================================
864 void BRepFeat_MakeDPrism::PerformUntilHeight(const TopoDS_Shape& Until,
865 const Standard_Real Height)
868 Standard_Boolean trc = BRepFeat_GettraceFEAT();
869 if (trc) cout << "BRepFeat_MakeDPrism::PerformUntilHeight(Until,Height)" << endl;
871 if (Until.IsNull()) {
877 TopExp_Explorer exp(Until, TopAbs_FACE);
879 Standard_ConstructionError::Raise();
881 // myPbase.Orientation(TopAbs_FORWARD);
883 myPerfSelection = BRepFeat_NoSelection;
884 PerfSelectionValid();
888 Standard_Boolean Trf = TransformShapeFU(1);
890 Handle(Geom_Curve) C = TestCurve(myPbase);
891 Standard_Integer sens = SensOfPrism(C, mySUntil);
893 LocOpe_DPrism theDPrism(myPbase,sens*Height,myAngle);
894 TopoDS_Shape VraiDPrism = theDPrism.Shape();
896 if(!Trf) { // case face finished
897 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
898 myGShape = VraiDPrism;
899 GeneratedShapeValid();
900 TopoDS_Shape Base = theDPrism.FirstShape();
901 exp.Init(Base, TopAbs_FACE);
902 TopoDS_Face theBase = TopoDS::Face(exp.Current());
906 myStatusError = BRepFeat_InvFirstShape;
911 theDPrism.Curves(myCurves);
912 myBCurve = theDPrism.BarycCurve();
915 else { // case support
916 MajMap(myPbase,theDPrism,myMap,myFShape,myLShape);
917 Handle(Geom_Curve) C1;
924 TColGeom_SequenceOfCurve scur;
927 LocOpe_CSIntersector ASI(mySUntil);
929 TopAbs_Orientation Or;
930 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
932 Or = ASI.Point(1,1).Orientation();
935 Or = ASI.Point(1,ASI.NbPoints(1)).Orientation();
937 // Standard_Real prm = ASI.Point(1,1).Parameter();
938 // if(prm < 0) Or = TopAbs::Reverse(Or);
939 TopoDS_Face FUntil = ASI.Point(1,1).Face();
942 B.MakeCompound(TopoDS::Compound(Comp));
943 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
944 if (!S.IsNull()) B.Add(Comp,S);
945 //modified by NIZNHY-PKV Thu Mar 21 17:47:14 2002 f
946 //BRepAlgo_Cut trP(VraiDPrism,Comp);
947 BRepAlgoAPI_Cut trP(VraiDPrism,Comp);
948 //modified by NIZNHY-PKV Thu Mar 21 17:47:21 2002 t
950 //modified by NIZNHY-PKV Thu Mar 21 17:47:42 2002 f
951 //BRepAlgo_Fuse f(mySbase, trP.Shape());
952 //myShape = f.Shape();
953 //UpdateDescendants(f.Builder(), myShape, Standard_False);
954 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
956 UpdateDescendants(f, myShape, Standard_False);
957 //modified by NIZNHY-PKV Thu Mar 21 17:47:49 2002 t
960 else if(myFuse == 0) {
961 //modified by NIZNHY-PKV Thu Mar 21 17:48:18 2002 f
962 //BRepAlgo_Cut c(mySbase, trP.Shape());
963 //myShape = c.Shape();
964 //UpdateDescendants(c.Builder(), myShape, Standard_False);
965 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
967 UpdateDescendants(c, myShape, Standard_False);
968 //modified by NIZNHY-PKV Thu Mar 21 17:48:26 2002 t
972 myShape = trP.Shape();
980 //=======================================================================
982 //purpose : curves parallel to the axis of the prism
983 //=======================================================================
985 void BRepFeat_MakeDPrism::Curves(TColGeom_SequenceOfCurve& scur)
990 //============================================================================
991 // function : BRepFeat_BossEgdes
992 // purpose: Determination of TopEdges and LatEdges.
993 // sig = 1 -> TopEdges = FirstShape of the DPrism
994 // sig = 2 -> TOpEdges = LastShape of the DPrism
995 //============================================================================
996 void BRepFeat_MakeDPrism::BossEdges (const Standard_Integer signature)
999 Standard_Boolean trc = BRepFeat_GettraceFEAT();
1000 if (trc) cout << "BRepFeat_MakeDPrism::BossEdges (integer)" << endl;
1002 TopTools_ListOfShape theLastShape;
1003 theLastShape.Clear();
1004 if (signature == 1 || signature == -1) {
1005 theLastShape = FirstShape();
1007 else if (signature == 2 || signature == -2) {
1008 theLastShape = LastShape();
1015 TopTools_ListIteratorOfListOfShape itLS;
1016 TopExp_Explorer ExpE;
1017 for (itLS.Initialize(theLastShape);itLS.More();itLS.Next()) {
1018 const TopoDS_Face& FF = TopoDS::Face(itLS.Value());
1019 for (ExpE.Init(FF,TopAbs_EDGE);ExpE.More();ExpE.Next()) {
1020 const TopoDS_Edge& EE = TopoDS::Edge(ExpE.Current());
1021 myTopEdges.Append(EE);
1026 if (signature < 0) {
1027 // Attention check if TgtEdges is important
1028 myLatEdges = NewEdges();
1030 else if (signature > 0) {
1031 if ( !myShape.IsNull() ) {
1032 TopTools_MapOfShape MapE;
1033 Standard_Boolean Found;
1035 TopExp_Explorer ExpF;
1036 for (ExpF.Init(myShape,TopAbs_FACE);ExpF.More();ExpF.Next()) {
1037 Found = Standard_False;
1038 const TopoDS_Face& FF = TopoDS::Face(ExpF.Current());
1039 for (itLS.Initialize(theLastShape);itLS.More();itLS.Next()) {
1040 const TopoDS_Face& TopFace = TopoDS::Face(itLS.Value());
1041 if (!FF.IsSame(TopFace)) {
1042 for (ExpE.Init(FF,TopAbs_EDGE);ExpE.More() && !Found ;ExpE.Next()) {
1043 const TopoDS_Edge& E1 = TopoDS::Edge(ExpE.Current());
1044 TopoDS_Vertex V1,V2;
1045 TopExp::Vertices (E1,V1,V2);
1046 TopTools_ListIteratorOfListOfShape it(myTopEdges);
1047 for (;it.More() && !Found ; it.Next()) {
1048 TopoDS_Edge E2 = TopoDS::Edge(it.Value());
1049 TopoDS_Vertex VT1,VT2;
1050 TopExp::Vertices (E2,VT1,VT2);
1052 if (V1.IsSame(VT1) || V1.IsSame(VT2) || V2.IsSame(VT1) || V2.IsSame(VT2)) {
1053 Found = Standard_True;
1054 TopExp_Explorer ExpE2;
1055 for (ExpE2.Init(FF,TopAbs_EDGE);ExpE2.More();ExpE2.Next()) {
1056 const TopoDS_Edge& E3 = TopoDS::Edge(ExpE2.Current());
1057 if (MapE.Contains(E3)) {
1069 TopTools_ListIteratorOfListOfShape it(myTopEdges);
1070 for (;it.More() ; it.Next()) {
1071 if (MapE.Contains(it.Value())) {MapE.Remove(it.Value()); }
1074 TopTools_MapIteratorOfMapOfShape itMap;
1075 for (itMap.Initialize(MapE);itMap.More();itMap.Next()) {
1076 if (!BRep_Tool::Degenerated(TopoDS::Edge(itMap.Key())))
1077 myLatEdges.Append(itMap.Key());
1085 //============================================================================
1086 // function : BRepFeat_TopEgdes
1087 // Purpose: Returns the list of TopoDS Edges of the top of the boss
1088 //============================================================================
1089 const TopTools_ListOfShape& BRepFeat_MakeDPrism::TopEdges ()
1094 //============================================================================
1095 // function : BRepFeat_LatEgdes
1096 // Purpose: Returns the list of TopoDS Edges of the top of the boss
1097 //============================================================================
1098 const TopTools_ListOfShape& BRepFeat_MakeDPrism::LatEdges ()
1103 //=======================================================================
1104 //function : BarycCurve
1105 //purpose : passe par le centre de masses de la primitive
1106 //=======================================================================
1108 Handle(Geom_Curve) BRepFeat_MakeDPrism::BarycCurve()
1114 //=======================================================================
1115 //function : HeightMax
1116 //purpose : Calculate the height of the prism following the parameters of the bounding box
1117 //=======================================================================
1119 static Standard_Real HeightMax(const TopoDS_Shape& theSbase, // shape initial
1120 const TopoDS_Face& theSkface, // face de sketch
1121 const TopoDS_Shape& theSFrom, // shape from
1122 const TopoDS_Shape& theSUntil) // shape until
1125 BRepBndLib::Add(theSbase,Box);
1126 BRepBndLib::Add(theSkface,Box);
1127 if(!theSFrom.IsNull()) {
1128 BRepBndLib::Add(theSFrom,Box);
1130 if(!theSUntil.IsNull()) {
1131 BRepBndLib::Add(theSUntil,Box);
1135 Box.Get(c[0],c[2],c[4],c[1],c[3],c[5]);
1136 // Standard_Real parmin=c[0], parmax = c[0];
1137 // for(Standard_Integer i = 0 ; i < 6; i++) {
1138 // if(c[i] > parmax) parmax = c[i];
1139 // if(c[i] < parmin ) parmin = c[i];
1141 // Standard_Real Height = abs(2.*(parmax - parmin));
1142 // return(2.*Height);
1143 //#ifndef OCCT_DEBUG
1144 Standard_Real par = Max( Max( fabs(c[1] - c[0]), fabs(c[3] - c[2]) ), fabs(c[5] - c[4]) );
1146 // Standard_Real par = Max( Max( abs(c[1] - c[0]), abs(c[3] - c[2]) ), abs(c[5] - c[4]) );
1149 cout << "Height = > " << par << endl;
1158 //=======================================================================
1159 //function : SensOfPrism
1160 //purpose : determine the direction of prism generation
1161 //=======================================================================
1162 Standard_Integer SensOfPrism(const Handle(Geom_Curve) C,
1163 const TopoDS_Shape& Until)
1165 LocOpe_CSIntersector ASI1(Until);
1166 TColGeom_SequenceOfCurve scur;
1169 Standard_Integer sens = 1;
1170 if(ASI1.IsDone() && ASI1.NbPoints(1) >= 1) {
1171 Standard_Integer nb = ASI1.NbPoints(1);
1172 Standard_Real prm1 = ASI1.Point(1, 1).Parameter();
1173 Standard_Real prm2 = ASI1.Point(1, nb).Parameter();
1174 if(prm1 < 0. && prm2 < 0.) {
1178 else if(BRepFeat::ParametricBarycenter(Until,C) < 0) {
1185 //=======================================================================
1188 //=======================================================================
1190 static void MajMap(const TopoDS_Shape& theB,
1191 const LocOpe_DPrism& theP,
1192 TopTools_DataMapOfShapeListOfShape& theMap, // myMap
1193 TopoDS_Shape& theFShape, // myFShape
1194 TopoDS_Shape& theLShape) // myLShape
1196 TopExp_Explorer exp;
1197 if(!theP.FirstShape().IsNull()) {
1198 exp.Init(theP.FirstShape(),TopAbs_WIRE);
1200 theFShape = exp.Current();
1201 TopTools_ListOfShape thelist;
1202 theMap.Bind(theFShape, thelist);
1203 for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) {
1204 theMap(theFShape).Append(exp.Current());
1209 if(!theP.LastShape().IsNull()) {
1210 exp.Init(theP.LastShape(),TopAbs_WIRE);
1212 theLShape = exp.Current();
1213 TopTools_ListOfShape thelist1;
1214 theMap.Bind(theLShape, thelist1);
1215 for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) {
1216 theMap(theLShape).Append(exp.Current());
1221 for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) {
1222 if (!theMap.IsBound(exp.Current())) {
1223 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
1224 TopTools_ListOfShape thelist2;
1225 theMap.Bind(edg, thelist2);
1226 theMap(edg) = theP.Shapes(edg);
1232 //=======================================================================
1235 //=======================================================================
1237 static Handle(Geom_Curve) TestCurve(const TopoDS_Face& Base)
1239 gp_Pnt bar(0., 0., 0.);
1240 TColgp_SequenceOfPnt spt;
1241 LocOpe::SampleEdges(Base,spt);
1242 for (Standard_Integer jj=1;jj<=spt.Length(); jj++) {
1243 const gp_Pnt& pvt = spt(jj);
1244 bar.ChangeCoord() += pvt.XYZ();
1246 bar.ChangeCoord().Divide(spt.Length());
1247 Handle(Geom_Surface) s = BRep_Tool::Surface(Base);
1248 if (s->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1249 s = Handle(Geom_RectangularTrimmedSurface)::
1250 DownCast(s)->BasisSurface();
1252 Handle (Geom_Plane) P = Handle(Geom_Plane)::DownCast(s);
1254 Handle(Geom_Curve) toto;
1257 gp_Pln pp = P->Pln();
1258 gp_Dir Normale(pp.Position().XDirection()^pp.Position().YDirection());
1259 gp_Ax1 theAx(bar, Normale);
1260 Handle(Geom_Line) theLin = new Geom_Line(theAx);