1 // Created on: 1996-02-13
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <BRepFeat_MakePrism.ixx>
25 #include <BRepFeat.hxx>
27 #include <LocOpe_Prism.hxx>
28 #include <LocOpe_CSIntersector.hxx>
29 #include <LocOpe_PntFace.hxx>
34 #include <gp_Pnt2d.hxx>
35 #include <Geom_Curve.hxx>
36 #include <Geom_Line.hxx>
37 #include <Geom_RectangularTrimmedSurface.hxx>
38 #include <Geom_Surface.hxx>
40 #include <BRepLib_MakeFace.hxx>
42 #include <TColgp_SequenceOfPnt.hxx>
43 #include <TColGeom_SequenceOfCurve.hxx>
44 #include <Bnd_Box.hxx>
46 #include <BRep_Tool.hxx>
48 #include <BRepTools.hxx>
51 #include <TopExp_Explorer.hxx>
52 #include <TopTools_MapOfShape.hxx>
53 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
54 #include <TopTools_ListIteratorOfListOfShape.hxx>
55 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
56 #include <TopTools_ListIteratorOfListOfShape.hxx>
57 #include <TopTools_ListOfShape.hxx>
59 #include <BRepBuilderAPI.hxx>
60 #include <BRepPrimAPI_MakeBox.hxx>
62 //modified by NIZNHY-PKV Thu Mar 21 18:14:23 2002 f
63 //#include <BRepAlgo_Cut.hxx>
64 //#include <BRepAlgo_Fuse.hxx>
65 #include <BRepAlgoAPI_Cut.hxx>
66 #include <BRepAlgoAPI_Fuse.hxx>
67 //modified by NIZNHY-PKV Thu Mar 21 18:14:26 2002 t
69 #include <Standard_ConstructionError.hxx>
73 #include <TopoDS_Face.hxx>
74 #include <TopoDS_Solid.hxx>
75 #include <TopoDS_Compound.hxx>
78 #include <BRepBndLib.hxx>
80 #include <Precision.hxx>
82 #include <Geom_Plane.hxx>
85 extern Standard_Boolean BRepFeat_GettraceFEAT();
88 static void MajMap(const TopoDS_Shape&, // base
90 TopTools_DataMapOfShapeListOfShape&, // myMap
91 TopoDS_Shape&, // myFShape
92 TopoDS_Shape&); // myLShape
94 static Standard_Boolean ToFuse(const TopoDS_Face& ,
97 static Standard_Real HeightMax(const TopoDS_Shape& theSbase,
98 const TopoDS_Face& theSkface,
99 const TopoDS_Shape& theSFrom,
100 const TopoDS_Shape& theSUntil);
102 static Standard_Integer SensOfPrism(const Handle(Geom_Curve) C,
103 const TopoDS_Shape& Until);
105 static Handle(Geom_Curve) TestCurve(const TopoDS_Shape&,
109 //=======================================================================
112 //=======================================================================
114 void BRepFeat_MakePrism::Init(const TopoDS_Shape& Sbase,
115 const TopoDS_Shape& Pbase,
116 const TopoDS_Face& Skface,
118 const Standard_Integer Mode,
119 const Standard_Boolean Modify)
122 Standard_Boolean trc = BRepFeat_GettraceFEAT();
123 if (trc) cout << "BRepFeat_MakePrism::Init" << endl;
133 myFuse = Standard_False;
134 myJustFeat = Standard_False;
137 myFuse = Standard_True;
138 myJustFeat = Standard_False;
141 myFuse = Standard_True;
142 myJustFeat = Standard_True;
147 myJustGluer = Standard_False;
151 //mySkface.Nullify();
162 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
163 TopTools_ListOfShape thelist;
164 myMap.Bind(exp.Current(), thelist);
165 myMap(exp.Current()).Append(exp.Current());
169 if (myJustFeat) cout << " Just Feature" << endl;
170 if (myFuse) cout << " Fuse" << endl;
171 if (!myFuse) cout << " Cut" << endl;
172 if (!myModify) cout << " Modify = 0" << endl;
178 //=======================================================================
180 //purpose : add elements of sliding (edge on face)
181 //=======================================================================
183 void BRepFeat_MakePrism::Add(const TopoDS_Edge& E,
184 const TopoDS_Face& F)
187 Standard_Boolean trc = BRepFeat_GettraceFEAT();
188 if (trc) cout << "BRepFeat_MakePrism::Add(Edge,face)" << endl;
191 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
192 if (exp.Current().IsSame(F)) {
197 Standard_ConstructionError::Raise();
200 for (exp.Init(myPbase,TopAbs_EDGE);exp.More();exp.Next()) {
201 if (exp.Current().IsSame(E)) {
206 Standard_ConstructionError::Raise();
209 if (!mySlface.IsBound(F)) {
210 TopTools_ListOfShape thelist1;
211 mySlface.Bind(F, thelist1);
213 TopTools_ListIteratorOfListOfShape itl(mySlface(F));
214 for (; itl.More();itl.Next()) {
215 if (itl.Value().IsSame(E)) {
220 mySlface(F).Append(E);
225 //=======================================================================
227 //purpose : construction of prism of length Length and
228 // call of reconstruction topo
229 //=======================================================================
231 void BRepFeat_MakePrism::Perform(const Standard_Real Length)
234 Standard_Boolean trc = BRepFeat_GettraceFEAT();
235 if (trc) cout << "BRepFeat_MakePrism::Perform(Length)" << endl;
242 myPerfSelection = BRepFeat_NoSelection;
243 PerfSelectionValid();
244 gp_Vec V(Length*myDir);
246 //construction of prism of height Length
248 LocOpe_Prism thePrism(myPbase,V);
249 TopoDS_Shape VraiPrism = thePrism.Shape();
251 // management of descendants
252 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
255 myGShape = VraiPrism; // the primitive
256 GeneratedShapeValid();
260 Standard_Boolean found = Standard_False;
262 // try to detect the faces of gluing
263 // in case if the top of the prism is tangent to the initial shape
265 if(!mySkface.IsNull() || !mySlface.IsEmpty()) {
266 if(myLShape.ShapeType() == TopAbs_WIRE) {
267 TopExp_Explorer ex1(VraiPrism, TopAbs_FACE);
268 for(; ex1.More(); ex1.Next()) {
269 TopExp_Explorer ex2(ex1.Current(), TopAbs_WIRE);
270 for(; ex2.More(); ex2.Next()) {
271 if(ex2.Current().IsSame(myLShape)) {
272 FFace = TopoDS::Face(ex1.Current());
273 found = Standard_True;
281 TopExp_Explorer exp(mySbase, TopAbs_FACE);
282 for(; exp.More(); exp.Next()) {
283 const TopoDS_Face& ff = TopoDS::Face(exp.Current());
284 if(ToFuse(ff, FFace)) {
285 TopTools_DataMapOfShapeListOfShape sl;
286 if(!FFace.IsSame(myPbase) && BRepFeat::IsInside(ff, FFace))
292 // management of faces of gluing given by the user
296 if(!myGluedF.IsEmpty()) { // case gluing
297 myJustGluer = Standard_True;
298 thePrism.Curves(myCurves);
299 myBCurve = thePrism.BarycCurve();
300 GlobalPerform(); // topological reconstruction
303 // if there is no gluing -> call of ope topo
305 if(myFuse == 1 && !myJustFeat) {
306 //modified by NIZNHY-PKV Thu Mar 21 17:55:30 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:55:34 2002 t
316 else if(myFuse == 0) {
317 //modified by NIZNHY-PKV Thu Mar 21 17:55:59 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:56:02 2002 t
335 //=======================================================================
337 //purpose : construction of prism oriented at the face Until, sufficiently
338 // long; call of topological reconstruction
339 //=======================================================================
341 void BRepFeat_MakePrism::Perform(const TopoDS_Shape& Until)
344 Standard_Boolean trc = BRepFeat_GettraceFEAT();
345 if (trc) cout << "BRepFeat_MakePrism::Perform(Until)" << endl;
347 if (Until.IsNull()) {
348 Standard_ConstructionError::Raise();
350 TopExp_Explorer exp(Until, TopAbs_FACE);
352 Standard_ConstructionError::Raise();
355 myPerfSelection = BRepFeat_SelectionU;
356 PerfSelectionValid();
360 Standard_Boolean Trf = TransformShapeFU(1);
362 Handle(Geom_Curve) C = TestCurve(myPbase,myDir);
363 Standard_Integer sens = SensOfPrism(C, mySUntil);
364 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
365 gp_Vec V(2*sens*Height*myDir);
367 // construction of long prism
368 LocOpe_Prism thePrism(myPbase,V);
369 TopoDS_Shape VraiPrism = thePrism.Shape();
371 // in case of support of face Until
373 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
374 myGShape = VraiPrism;
375 GeneratedShapeValid();
377 thePrism.Curves(myCurves);
378 myBCurve = thePrism.BarycCurve();
381 else { // until support -> passage to topological operations
382 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
383 TColGeom_SequenceOfCurve scur;
387 // direction of the prism depending on Until
389 LocOpe_CSIntersector ASI(mySUntil);
391 TopAbs_Orientation Or;
392 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
394 Or = ASI.Point(1,1).Orientation();
397 Or = ASI.Point(1,ASI.NbPoints(1)).Orientation();
399 if(sens==-1) Or=TopAbs::Reverse(Or);
400 TopoDS_Face FUntil = ASI.Point(1,1).Face();
403 B.MakeCompound(TopoDS::Compound(Comp));
404 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
405 if (!S.IsNull()) B.Add(Comp,S);
406 //modified by NIZNHY-PKV Thu Mar 21 17:56:31 2002 f
407 //BRepAlgo_Cut trP(VraiPrism,Comp);
408 //UpdateDescendants(trP.Builder(),trP.Shape(), Standard_False);
409 BRepAlgoAPI_Cut trP(VraiPrism,Comp);
410 UpdateDescendants(trP, trP.Shape(), Standard_False);
411 //modified by NIZNHY-PKV Thu Mar 21 17:56:38 2002 t
412 TopExp_Explorer ex(trP.Shape(), TopAbs_SOLID);
413 TopoDS_Shape Cutsh = ex.Current();
414 if(myFuse == 1 && !myJustFeat) {
415 //modified by NIZNHY-PKV Thu Mar 21 17:57:49 2002 f
416 //BRepAlgo_Fuse f(mySbase, Cutsh);
417 //myShape = f.Shape();
418 //UpdateDescendants(f.Builder(), myShape, Standard_False);
419 BRepAlgoAPI_Fuse f(mySbase, Cutsh);
421 UpdateDescendants(f, myShape, Standard_False);
422 //modified by NIZNHY-PKV Thu Mar 21 17:57:53 2002 t
425 else if(myFuse == 0) {
426 //modified by NIZNHY-PKV Thu Mar 21 17:59:33 2002 f
427 //BRepAlgo_Cut c(mySbase, Cutsh);
428 //myShape = c.Shape();
429 //UpdateDescendants(c.Builder(), myShape, Standard_False);
430 BRepAlgoAPI_Cut c(mySbase, Cutsh);
432 UpdateDescendants(c, myShape, Standard_False);
433 //modified by NIZNHY-PKV Thu Mar 21 17:59:43 2002 t
442 /* // loop of control of descendance
444 TopExp_Explorer expr(mySbase, TopAbs_FACE);
445 char nom1[20], nom2[20];
446 Standard_Integer ii = 0;
447 for(; expr.More(); expr.Next()) {
449 sprintf(nom1, "faceinitial_%d", ii);
450 DBRep::Set(nom1, expr.Current());
451 Standard_Integer jj = 0;
452 const TopTools_ListOfShape& list = Modified(expr.Current());
453 TopTools_ListIteratorOfListOfShape ite(list);
454 for(; ite.More(); ite.Next()) {
456 sprintf(nom2, "facemodifie_%d_%d", ii, jj);
457 DBRep::Set(nom2, ite.Value());
461 expr.Init(myPbase, TopAbs_EDGE);
463 for(; expr.More(); expr.Next()) {
465 sprintf(nom1, "edgeinitial_%d", ii);
466 DBRep::Set(nom1, expr.Current());
467 Standard_Integer jj = 0;
468 const TopTools_ListOfShape& list = Generated(expr.Current());
469 TopTools_ListIteratorOfListOfShape ite(list);
470 for(; ite.More(); ite.Next()) {
472 sprintf(nom2, "facegeneree_%d_%d", ii, jj);
473 DBRep::Set(nom2, ite.Value());
480 //=======================================================================
482 //purpose : construction of a sufficiently long and properly oriented prism
483 // call of topological reconstruction
484 //=======================================================================
486 void BRepFeat_MakePrism::Perform(const TopoDS_Shape& From,
487 const TopoDS_Shape& Until)
490 Standard_Boolean trc = BRepFeat_GettraceFEAT();
491 if (trc) cout << "BRepFeat_MakePrism::Perform(From,Until)" << endl;
493 if (From.IsNull() || Until.IsNull()) {
494 Standard_ConstructionError::Raise();
497 if (!mySkface.IsNull()) {
498 if (From.IsSame(mySkface)) {
499 myJustGluer = Standard_True;
501 if (myJustGluer) return;
503 else if (Until.IsSame(mySkface)) {
504 myJustGluer = Standard_True;
506 if (myJustGluer) return;
511 myPerfSelection = BRepFeat_SelectionFU;
512 PerfSelectionValid();
514 TopExp_Explorer exp(From, TopAbs_FACE);
516 Standard_ConstructionError::Raise();
518 exp.Init(Until, TopAbs_FACE);
520 Standard_ConstructionError::Raise();
523 Standard_Boolean Trff = TransformShapeFU(0);
526 Standard_Boolean Trfu = TransformShapeFU(1);
530 myStatusError = BRepFeat_IncTypes;
534 // length depending on bounding boxes
536 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
537 Handle(Geom_Curve) C = TestCurve(myPbase,myDir);
538 Standard_Integer sens; // direction of prism
539 Standard_Integer tran; // transfer of prism
540 if(From.IsSame(Until)) {
545 sens = SensOfPrism(C, mySUntil);
546 tran = sens*SensOfPrism(C, mySFrom);
548 LocOpe_Prism thePrism;
550 gp_Vec Vtra(-3*Height*sens/2.*myDir);
551 thePrism.Perform(myPbase,3*sens*Height*myDir,Vtra);
554 thePrism.Perform(myPbase,2*sens*Height*myDir);
556 TopoDS_Shape VraiPrism = thePrism.Shape();
559 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
561 myGShape = VraiPrism;
562 GeneratedShapeValid();
564 thePrism.Curves(myCurves);
565 myBCurve = thePrism.BarycCurve();
568 else { // case until support -> topological operation
569 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
570 TColGeom_SequenceOfCurve scur;
573 LocOpe_CSIntersector ASI1(mySUntil);
574 LocOpe_CSIntersector ASI2(mySFrom);
577 TopAbs_Orientation OrU, OrF;
578 TopoDS_Face FFrom, FUntil;
579 if (ASI1.IsDone() && ASI1.NbPoints(1) >=1) {
581 OrU = ASI1.Point(1,1).Orientation();
584 OrU = ASI1.Point(1,ASI1.NbPoints(1)).Orientation();
586 if(sens==-1) OrU = TopAbs::Reverse(OrU);
587 FUntil = ASI1.Point(1,1).Face();
591 myStatusError = BRepFeat_NoIntersectU;
594 if (ASI2.IsDone() && ASI2.NbPoints(1) >=1) {
595 OrF = ASI2.Point(1,1).Orientation();
596 if(sens==1) OrF = TopAbs::Reverse(OrF);
597 FFrom = ASI2.Point(1,1).Face();
601 myStatusError = BRepFeat_NoIntersectF;
606 B.MakeCompound(TopoDS::Compound(Comp));
607 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, OrU);
613 myStatusError = BRepFeat_NullToolU;
616 TopoDS_Solid SS = BRepFeat::Tool(mySFrom, FFrom, OrF);
622 myStatusError = BRepFeat_NullToolF;
625 //modified by NIZNHY-PKV Thu Mar 21 18:00:10 2002 f
626 //BRepAlgo_Cut trP(VraiPrism,Comp);
627 //UpdateDescendants(trP.Builder(), trP.Shape(), Standard_False);
628 BRepAlgoAPI_Cut trP(VraiPrism,Comp);
629 UpdateDescendants(trP, trP.Shape(), Standard_False);
630 //modified by NIZNHY-PKV Thu Mar 21 18:00:16 2002 t
631 if(myFuse == 1 && !myJustFeat) {
632 //modified by NIZNHY-PKV Thu Mar 21 18:00:35 2002 f
633 //BRepAlgo_Fuse f(mySbase, trP.Shape());
634 //myShape = f.Shape();
635 //UpdateDescendants(f.Builder(), myShape, Standard_False);
636 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
638 UpdateDescendants(f, myShape, Standard_False);
639 //modified by NIZNHY-PKV Thu Mar 21 18:00:40 2002 t
642 else if(myFuse == 0) {
643 //modified by NIZNHY-PKV Thu Mar 21 18:01:01 2002 f
644 //BRepAlgo_Cut c(mySbase, trP.Shape());
645 //myShape = c.Shape();
646 //UpdateDescendants(c.Builder(), myShape, Standard_False);
647 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
649 UpdateDescendants(c, myShape, Standard_False);
650 //modified by NIZNHY-PKV Thu Mar 21 18:01:13 2002 t
654 myShape = trP.Shape();
660 TopExp_Explorer expr(mySbase, TopAbs_FACE);
661 char nom1[20], nom2[20];
662 Standard_Integer ii = 0;
663 for(; expr.More(); expr.Next()) {
665 sprintf(nom1, "faceinitial_%d", ii);
666 DBRep::Set(nom1, expr.Current());
667 Standard_Integer jj = 0;
668 const TopTools_ListOfShape& list = Modified(expr.Current());
669 TopTools_ListIteratorOfListOfShape ite(list);
670 for(; ite.More(); ite.Next()) {
672 sprintf(nom2, "facemodifie_%d_%d", ii, jj);
673 DBRep::Set(nom2, ite.Value());
677 expr.Init(myPbase, TopAbs_EDGE);
679 for(; expr.More(); expr.Next()) {
681 sprintf(nom1, "edgeinitial_%d", ii);
682 DBRep::Set(nom1, expr.Current());
683 Standard_Integer jj = 0;
684 const TopTools_ListOfShape& list = Generated(expr.Current());
685 TopTools_ListIteratorOfListOfShape ite(list);
686 for(; ite.More(); ite.Next()) {
688 sprintf(nom2, "egdegeneree_%d_%d", ii, jj);
689 DBRep::Set(nom2, ite.Value());
697 //=======================================================================
698 //function : PerformUntilEnd
699 //purpose : construction of a prism and reconstruction
700 //=======================================================================
702 void BRepFeat_MakePrism::PerformUntilEnd()
705 Standard_Boolean trc = BRepFeat_GettraceFEAT();
706 if (trc) cout << "BRepFeat_MakePrism::PerformUntilEnd()" << endl;
708 myPerfSelection = BRepFeat_SelectionSh;
709 PerfSelectionValid();
715 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
716 gp_Vec V(2*Height*myDir);
718 LocOpe_Prism thePrism(myPbase,V);
719 TopoDS_Shape VraiPrism = thePrism.Shape();
721 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
723 myGShape = VraiPrism;
724 GeneratedShapeValid();
728 //modified by NIZNHY-PKV Thu Mar 21 18:02:46 2002 f
729 //BRepAlgo_Cut c(mySbase, myGShape);
730 BRepAlgoAPI_Cut c(mySbase, myGShape);
731 //modified by NIZNHY-PKV Thu Mar 21 18:03:15 2002 t
734 //modified by NIZNHY-PKV Thu Mar 21 18:03:38 2002 f
735 //UpdateDescendants(c.Builder(), myShape, Standard_False);
736 UpdateDescendants(c, myShape, Standard_False);
737 //modified by NIZNHY-PKV Thu Mar 21 18:03:42 2002 t
742 thePrism.Curves(myCurves);
743 myBCurve = thePrism.BarycCurve();
748 //=======================================================================
749 //function : PerformFromEnd
751 //=======================================================================
753 void BRepFeat_MakePrism::PerformFromEnd(const TopoDS_Shape& Until)
756 Standard_Boolean trc = BRepFeat_GettraceFEAT();
757 if (trc) cout << "BRepFeat_MakePrism::PerformFromEnd(From,Until)" << endl;
759 if (Until.IsNull()) {
760 Standard_ConstructionError::Raise();
762 if (!mySkface.IsNull() && Until.IsSame(mySkface)) {
768 exp.Init(Until, TopAbs_FACE);
770 Standard_ConstructionError::Raise();
772 myPerfSelection = BRepFeat_SelectionShU;
773 PerfSelectionValid();
777 Standard_Boolean Trf = TransformShapeFU(1);
779 Handle(Geom_Curve) C = TestCurve(myPbase,myDir);
780 Standard_Integer sens = SensOfPrism(C, mySUntil);
781 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
782 gp_Vec Vtra(-3*Height*sens/2.*myDir);
783 gp_Vec Vect(3*sens*Height*myDir);
784 LocOpe_Prism thePrism(myPbase,Vect,Vtra);
785 TopoDS_Shape VraiPrism = thePrism.Shape();
787 if(!Trf) { // case face until
788 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
789 myGShape = VraiPrism;
790 GeneratedShapeValid();
793 thePrism.Curves(myCurves);
794 myBCurve = thePrism.BarycCurve();
797 else { // case support
798 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
799 TColGeom_SequenceOfCurve scur;
802 LocOpe_CSIntersector ASI1(mySUntil);
803 LocOpe_CSIntersector ASI2(mySbase);
806 TopAbs_Orientation OrU = TopAbs_FORWARD, OrF = TopAbs_FORWARD;
807 TopoDS_Face FUntil, FFrom;
808 if (ASI1.IsDone() && ASI1.NbPoints(1) >=1) {
809 OrU = ASI1.Point(1,1).Orientation();
811 OrU = TopAbs::Reverse(OrU);
813 FUntil = ASI1.Point(1,1).Face();
815 if (ASI2.IsDone() && ASI2.NbPoints(1) >=1) {
816 OrF = ASI2.Point(1,1).Orientation();
817 // if(sens==1) OrF = TopAbs::Reverse(OrF);
818 FFrom = ASI2.Point(1 ,1).Face();
819 Handle(Geom_Surface) S = BRep_Tool::Surface(FFrom);
820 if (S->DynamicType() ==
821 STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
822 S = Handle(Geom_RectangularTrimmedSurface)::
823 DownCast(S)->BasisSurface();
825 BRepLib_MakeFace fac(S, Precision::Confusion());
826 mySFrom = fac.Face();
827 Trf = TransformShapeFU(0);
828 FFrom = TopoDS::Face(mySFrom);
836 B.MakeCompound(TopoDS::Compound(Comp));
837 TopoDS_Solid Sol = BRepFeat::Tool(mySUntil, FUntil, OrU);
843 myStatusError = BRepFeat_NullToolU;
847 TopoDS_Solid Sol1 = BRepFeat::Tool(mySFrom, FFrom, OrF);
848 if (!Sol1.IsNull()) {
853 myStatusError = BRepFeat_NullToolF;
856 //modified by NIZNHY-PKV Thu Mar 21 18:03:57 2002 f
857 //BRepAlgo_Cut trP(VraiPrism,Comp);
858 //UpdateDescendants(trP.Builder(), trP.Shape(), Standard_False);
859 BRepAlgoAPI_Cut trP(VraiPrism,Comp);
860 UpdateDescendants(trP, trP.Shape(), Standard_False);
861 //modified by NIZNHY-PKV Thu Mar 21 18:04:08 2002 t
862 if(myFuse == 1 && !myJustFeat) {
863 //modified by NIZNHY-PKV Thu Mar 21 18:04:33 2002 f
864 //BRepAlgo_Fuse f(mySbase, trP.Shape());
865 //myShape = f.Shape();
866 //UpdateDescendants(f.Builder(), myShape, Standard_False);
867 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
869 UpdateDescendants(f, myShape, Standard_False);
870 //modified by NIZNHY-PKV Thu Mar 21 18:04:41 2002 t
873 else if(myFuse == 0) {
874 //modified by NIZNHY-PKV Thu Mar 21 18:04:54 2002 f
875 //BRepAlgo_Cut c(mySbase, trP.Shape());
876 //myShape = c.Shape();
877 //UpdateDescendants(c.Builder(), myShape, Standard_False);
878 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
880 UpdateDescendants(c, myShape, Standard_False);
881 //modified by NIZNHY-PKV Thu Mar 21 18:05:00 2002 t
885 myShape = trP.Shape();
893 //=======================================================================
894 //function : PerformThruAll
896 //=======================================================================
898 void BRepFeat_MakePrism::PerformThruAll()
901 Standard_Boolean trc = BRepFeat_GettraceFEAT();
902 if (trc) cout << "BRepFeat_MakePrism::PerformThruAll()" << endl;
909 myPerfSelection = BRepFeat_NoSelection;
912 myPerfSelection = BRepFeat_SelectionSh;
914 PerfSelectionValid();
918 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
919 gp_Vec V(3*Height*myDir);
920 gp_Vec Vtra(-3*Height/2.*myDir);
921 LocOpe_Prism thePrism(myPbase,V,Vtra);
922 TopoDS_Shape VraiPrism = thePrism.Shape();
923 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
925 myGShape = VraiPrism;
926 GeneratedShapeValid();
929 //modified by NIZNHY-PKV Thu Mar 21 18:05:31 2002 f
930 //BRepAlgo_Cut c(mySbase, myGShape);
931 BRepAlgoAPI_Cut c(mySbase, myGShape);
932 //modified by NIZNHY-PKV Thu Mar 21 18:05:33 2002 t
935 //modified by NIZNHY-PKV Thu Mar 21 18:05:46 2002 f
936 //UpdateDescendants(c.Builder(), myShape, Standard_False);
937 UpdateDescendants(c, myShape, Standard_False);
938 //modified by NIZNHY-PKV Thu Mar 21 18:05:50 2002 t
943 thePrism.Curves(myCurves);
944 myBCurve = thePrism.BarycCurve();
950 //=======================================================================
951 //function : PerformUntilHauteur
953 //=======================================================================
955 void BRepFeat_MakePrism::PerformUntilHeight(const TopoDS_Shape& Until,
956 const Standard_Real Length)
959 Standard_Boolean trc = BRepFeat_GettraceFEAT();
960 if (trc) cout << "BRepFeat_MakePrism::PerformUntilHeight(Until,Length)" << endl;
962 if (Until.IsNull()) {
968 TopExp_Explorer exp(Until, TopAbs_FACE);
970 Standard_ConstructionError::Raise();
973 myPerfSelection = BRepFeat_NoSelection;
974 PerfSelectionValid();
978 Standard_Boolean Trf = TransformShapeFU(1);
980 Handle(Geom_Curve) C = TestCurve(myPbase,myDir);
981 Standard_Integer sens = SensOfPrism(C, mySUntil);
982 gp_Vec V(sens*Length*myDir);
983 LocOpe_Prism thePrism(myPbase,V);
984 TopoDS_Shape VraiPrism = thePrism.Shape();
987 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
989 myGShape = VraiPrism;
990 GeneratedShapeValid();
992 thePrism.Curves(myCurves);
993 myBCurve = thePrism.BarycCurve();
997 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
998 TColGeom_SequenceOfCurve scur;
1001 LocOpe_CSIntersector ASI(mySUntil);
1003 TopAbs_Orientation Or;
1004 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
1006 Or = ASI.Point(1,1).Orientation();
1009 Or = ASI.Point(1,ASI.NbPoints(1)).Orientation();
1011 if(sens==-1) Or=TopAbs::Reverse(Or);
1012 TopoDS_Face FUntil = ASI.Point(1,1).Face();
1015 B.MakeCompound(TopoDS::Compound(Comp));
1016 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
1017 if (!S.IsNull()) B.Add(Comp,S);
1019 //modified by NIZNHY-PKV Thu Mar 21 18:06:09 2002 f
1020 //BRepAlgo_Cut trP(VraiPrism,Comp);
1021 //UpdateDescendants(trP.Builder(), trP.Shape(), Standard_False);
1022 BRepAlgoAPI_Cut trP(VraiPrism,Comp);
1023 UpdateDescendants(trP, trP.Shape(), Standard_False);
1024 //modified by NIZNHY-PKV Thu Mar 21 18:06:15 2002 t
1025 if(myFuse == 1 && !myJustFeat) {
1026 //modified by NIZNHY-PKV Thu Mar 21 18:06:36 2002 f
1027 //BRepAlgo_Fuse f(mySbase, trP.Shape());
1028 //myShape = f.Shape();
1029 //UpdateDescendants(f.Builder(), myShape, Standard_False);
1030 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
1031 myShape = f.Shape();
1032 UpdateDescendants(f, myShape, Standard_False);
1033 //modified by NIZNHY-PKV Thu Mar 21 18:06:41 2002 t
1036 else if(myFuse == 0) {
1037 //modified by NIZNHY-PKV Thu Mar 21 18:07:06 2002 f
1038 //BRepAlgo_Cut c(mySbase, trP.Shape());
1039 //myShape = c.Shape();
1040 //UpdateDescendants(c.Builder(), myShape, Standard_False);
1041 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
1042 myShape = c.Shape();
1043 UpdateDescendants(c, myShape, Standard_False);
1044 //modified by NIZNHY-PKV Thu Mar 21 18:07:12 2002 t
1048 myShape = trP.Shape();
1055 //=======================================================================
1057 //purpose : sequence of curves parallel to the axis of prism
1058 //=======================================================================
1060 void BRepFeat_MakePrism::Curves(TColGeom_SequenceOfCurve& scur)
1065 //=======================================================================
1066 //function : BarycCurve
1067 //purpose : curve parallel to the axis of the prism passing through the center
1069 //=======================================================================
1071 Handle(Geom_Curve) BRepFeat_MakePrism::BarycCurve()
1077 //=======================================================================
1078 //function : HeightMax
1079 //purpose : Calculate the height of the prism following the parameters of
1081 //=======================================================================
1083 static Standard_Real HeightMax(const TopoDS_Shape& theSbase,
1084 const TopoDS_Face& theSkface,
1085 const TopoDS_Shape& theSFrom,
1086 const TopoDS_Shape& theSUntil)
1089 BRepBndLib::Add(theSbase,Box);
1090 BRepBndLib::Add(theSkface,Box);
1091 if(!theSFrom.IsNull()) {
1092 Standard_Boolean FacRevolInfini = Standard_False;
1093 TopExp_Explorer exp;
1094 exp.Init(theSFrom, TopAbs_EDGE);
1095 for(; exp.More(); exp.Next()) {
1096 TopExp_Explorer exp1;
1097 exp1.Init(exp.Current(), TopAbs_VERTEX);
1099 FacRevolInfini = Standard_True;
1104 BRepBndLib::Add(theSFrom,Box);
1106 if(!theSUntil.IsNull())
1108 Standard_Boolean FacRevolInfini = Standard_False;
1109 TopExp_Explorer exp;
1110 exp.Init(theSUntil, TopAbs_EDGE);
1111 for(; exp.More(); exp.Next())
1113 TopExp_Explorer exp1;
1114 exp1.Init(exp.Current(), TopAbs_VERTEX);
1117 FacRevolInfini = Standard_True;
1122 BRepBndLib::Add(theSUntil,Box);
1127 Box.Get(c[0],c[2],c[4],c[1],c[3],c[5]);
1128 Standard_Real parmin=c[0], parmax = c[0];
1129 for(Standard_Integer i = 0 ; i < 6; i++) {
1130 if(c[i] > parmax) parmax = c[i];
1131 if(c[i] < parmin ) parmin = c[i];
1134 Standard_Real Height = fabs(2.*(parmax - parmin));
1136 // Standard_Real Height = abs(2.*(parmax - parmin));
1142 //=======================================================================
1143 //function : SensOfPrism
1144 //purpose : Direction of the prism depending on the shape Until
1145 //=======================================================================
1146 Standard_Integer SensOfPrism(const Handle(Geom_Curve) C,
1147 const TopoDS_Shape& Until)
1149 LocOpe_CSIntersector ASI1(Until);
1150 TColGeom_SequenceOfCurve scur;
1153 Standard_Integer sens = 1;
1154 if(ASI1.IsDone() && ASI1.NbPoints(1) >= 1) {
1155 if(ASI1.Point(1, 1).Parameter() < 0. &&
1156 ASI1.Point(1, ASI1.NbPoints(1)).Parameter() < 0.) {
1160 else if(BRepFeat::ParametricBarycenter(Until,C) < 0) {
1167 //=======================================================================
1169 //purpose : management of descendants
1170 //=======================================================================
1172 static void MajMap(const TopoDS_Shape& theB,
1173 const LocOpe_Prism& theP,
1174 TopTools_DataMapOfShapeListOfShape& theMap, // myMap
1175 TopoDS_Shape& theFShape, // myFShape
1176 TopoDS_Shape& theLShape) // myLShape
1178 TopExp_Explorer exp(theP.FirstShape(),TopAbs_WIRE);
1180 theFShape = exp.Current();
1181 TopTools_ListOfShape thelist2;
1182 theMap.Bind(theFShape, thelist2);
1183 for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) {
1184 theMap(theFShape).Append(exp.Current());
1188 exp.Init(theP.LastShape(),TopAbs_WIRE);
1190 theLShape = exp.Current();
1191 TopTools_ListOfShape thelist3;
1192 theMap.Bind(theLShape, thelist3);
1193 for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) {
1194 theMap(theLShape).Append(exp.Current());
1198 for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) {
1199 if (!theMap.IsBound(exp.Current())) {
1200 TopTools_ListOfShape thelist4;
1201 theMap.Bind(exp.Current(), thelist4);
1202 theMap(exp.Current()) = theP.Shapes(exp.Current());
1208 //=======================================================================
1210 //purpose : management of descendants
1211 //=======================================================================
1213 static Handle(Geom_Curve) TestCurve(const TopoDS_Shape& Base,
1216 gp_Pnt bar(0., 0., 0.);
1217 TColgp_SequenceOfPnt spt;
1218 LocOpe::SampleEdges(Base,spt);
1219 for (Standard_Integer jj=1;jj<=spt.Length(); jj++) {
1220 const gp_Pnt& pvt = spt(jj);
1221 bar.ChangeCoord() += pvt.XYZ();
1223 bar.ChangeCoord().Divide(spt.Length());
1224 gp_Ax1 newAx(bar,V);
1225 Handle(Geom_Line) theLin = new Geom_Line(newAx);
1232 //=======================================================================
1234 //purpose : face SameDomaine or not
1235 //=======================================================================
1237 Standard_Boolean ToFuse(const TopoDS_Face& F1,
1238 const TopoDS_Face& F2)
1240 if (F1.IsNull() || F2.IsNull()) {
1241 return Standard_False;
1244 Handle(Geom_Surface) S1,S2;
1245 TopLoc_Location loc1, loc2;
1246 Handle(Standard_Type) typS1,typS2;
1247 const Standard_Real tollin = Precision::Confusion();
1248 const Standard_Real tolang = Precision::Angular();
1250 S1 = BRep_Tool::Surface(F1,loc1);
1251 S2 = BRep_Tool::Surface(F2,loc2);
1253 typS1 = S1->DynamicType();
1254 typS2 = S2->DynamicType();
1256 if (typS1 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1257 S1 = (*((Handle(Geom_RectangularTrimmedSurface)*)&S1))->BasisSurface();
1258 typS1 = S1->DynamicType();
1261 if (typS2 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1262 S2 = (*((Handle(Geom_RectangularTrimmedSurface)*)&S2))->BasisSurface();
1263 typS2 = S2->DynamicType();
1266 if (typS1 != typS2) {
1267 return Standard_False;
1271 Standard_Boolean ValRet = Standard_False;
1272 if (typS1 == STANDARD_TYPE(Geom_Plane)) {
1273 S1 = BRep_Tool::Surface(F1); // to apply the location.
1274 S2 = BRep_Tool::Surface(F2);
1275 gp_Pln pl1( (*((Handle(Geom_Plane)*)&S1))->Pln());
1276 gp_Pln pl2( (*((Handle(Geom_Plane)*)&S2))->Pln());
1278 if (pl1.Position().IsCoplanar(pl2.Position(),tollin,tolang)) {
1279 ValRet = Standard_True;