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& ,
98 static void SetGluedFaces(const TopoDS_Face& theSkface,
99 const TopoDS_Shape& theSbase,
100 const TopoDS_Shape& thePbase,
101 const TopTools_DataMapOfShapeListOfShape& theSlmap,
103 TopTools_DataMapOfShapeShape&);
106 static void VerifGluedFaces(const TopoDS_Face& theSkface,
107 const TopoDS_Shape& thePbase,
108 Handle(Geom_Curve)& theBCurve,
109 TColGeom_SequenceOfCurve& theCurves,
110 LocOpe_Prism& thePrism,
111 TopTools_DataMapOfShapeShape& theMap);
114 static Standard_Real HeightMax(const TopoDS_Shape& theSbase,
115 const TopoDS_Face& theSkface,
116 const TopoDS_Shape& theSFrom,
117 const TopoDS_Shape& theSUntil);
119 static Standard_Integer SensOfPrism(const Handle(Geom_Curve) C,
120 const TopoDS_Shape& Until);
122 static Handle(Geom_Curve) TestCurve(const TopoDS_Shape&,
126 //=======================================================================
129 //=======================================================================
131 void BRepFeat_MakePrism::Init(const TopoDS_Shape& Sbase,
132 const TopoDS_Shape& Pbase,
133 const TopoDS_Face& Skface,
135 const Standard_Integer Mode,
136 const Standard_Boolean Modify)
139 Standard_Boolean trc = BRepFeat_GettraceFEAT();
140 if (trc) cout << "BRepFeat_MakePrism::Init" << endl;
150 myFuse = Standard_False;
151 myJustFeat = Standard_False;
154 myFuse = Standard_True;
155 myJustFeat = Standard_False;
158 myFuse = Standard_True;
159 myJustFeat = Standard_True;
164 myJustGluer = Standard_False;
168 //mySkface.Nullify();
179 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
180 TopTools_ListOfShape thelist;
181 myMap.Bind(exp.Current(), thelist);
182 myMap(exp.Current()).Append(exp.Current());
186 if (myJustFeat) cout << " Just Feature" << endl;
187 if (myFuse) cout << " Fuse" << endl;
188 if (!myFuse) cout << " Cut" << endl;
189 if (!myModify) cout << " Modify = 0" << endl;
195 //=======================================================================
197 //purpose : add elements of sliding (edge on face)
198 //=======================================================================
200 void BRepFeat_MakePrism::Add(const TopoDS_Edge& E,
201 const TopoDS_Face& F)
204 Standard_Boolean trc = BRepFeat_GettraceFEAT();
205 if (trc) cout << "BRepFeat_MakePrism::Add(Edge,face)" << endl;
208 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
209 if (exp.Current().IsSame(F)) {
214 Standard_ConstructionError::Raise();
217 for (exp.Init(myPbase,TopAbs_EDGE);exp.More();exp.Next()) {
218 if (exp.Current().IsSame(E)) {
223 Standard_ConstructionError::Raise();
226 if (!mySlface.IsBound(F)) {
227 TopTools_ListOfShape thelist1;
228 mySlface.Bind(F, thelist1);
230 TopTools_ListIteratorOfListOfShape itl(mySlface(F));
231 for (; itl.More();itl.Next()) {
232 if (itl.Value().IsSame(E)) {
237 mySlface(F).Append(E);
242 //=======================================================================
244 //purpose : construction of prism of length Length and
245 // call of reconstruction topo
246 //=======================================================================
248 void BRepFeat_MakePrism::Perform(const Standard_Real Length)
251 Standard_Boolean trc = BRepFeat_GettraceFEAT();
252 if (trc) cout << "BRepFeat_MakePrism::Perform(Length)" << endl;
259 myPerfSelection = BRepFeat_NoSelection;
260 PerfSelectionValid();
261 gp_Vec V(Length*myDir);
263 //construction of prism of height Length
265 LocOpe_Prism thePrism(myPbase,V);
266 TopoDS_Shape VraiPrism = thePrism.Shape();
268 // management of descendants
269 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
272 myGShape = VraiPrism; // the primitive
273 GeneratedShapeValid();
277 Standard_Boolean found = Standard_False;
279 // try to detect the faces of gluing
280 // in case if the top of the prism is tangent to the initial shape
282 if(!mySkface.IsNull() || !mySlface.IsEmpty()) {
283 if(myLShape.ShapeType() == TopAbs_WIRE) {
284 TopExp_Explorer ex1(VraiPrism, TopAbs_FACE);
285 for(; ex1.More(); ex1.Next()) {
286 TopExp_Explorer ex2(ex1.Current(), TopAbs_WIRE);
287 for(; ex2.More(); ex2.Next()) {
288 if(ex2.Current().IsSame(myLShape)) {
289 FFace = TopoDS::Face(ex1.Current());
290 found = Standard_True;
298 TopExp_Explorer exp(mySbase, TopAbs_FACE);
299 for(; exp.More(); exp.Next()) {
300 const TopoDS_Face& ff = TopoDS::Face(exp.Current());
301 if(ToFuse(ff, FFace)) {
302 TopTools_DataMapOfShapeListOfShape sl;
303 if(!FFace.IsSame(myPbase) && BRepFeat::IsInside(ff, FFace))
304 // SetGluedFaces(ff, mySbase, FFace, sl, thePrism, myGluedF);
310 // management of faces of gluing given by the user
312 // SetGluedFaces(mySkface, mySbase, myPbase, mySlface, thePrism, myGluedF);
314 // VerifGluedFaces(mySkface, myPbase, myBCurve, myCurves, thePrism, myGluedF);
316 if(!myGluedF.IsEmpty()) { // case gluing
317 myJustGluer = Standard_True;
318 thePrism.Curves(myCurves);
319 myBCurve = thePrism.BarycCurve();
320 GlobalPerform(); // topological reconstruction
323 // if there is no gluing -> call of ope topo
325 if(myFuse == 1 && !myJustFeat) {
326 //modified by NIZNHY-PKV Thu Mar 21 17:55:30 2002 f
327 //BRepAlgo_Fuse f(mySbase, myGShape);
328 //myShape = f.Shape();
329 //UpdateDescendants(f.Builder(), myShape, Standard_False);
330 BRepAlgoAPI_Fuse f(mySbase, myGShape);
332 UpdateDescendants(f, myShape, Standard_False);
333 //modified by NIZNHY-PKV Thu Mar 21 17:55:34 2002 t
336 else if(myFuse == 0) {
337 //modified by NIZNHY-PKV Thu Mar 21 17:55:59 2002 f
338 //BRepAlgo_Cut c(mySbase, myGShape);
339 //myShape = c.Shape();
340 //UpdateDescendants(c.Builder(), myShape, Standard_False);
341 BRepAlgoAPI_Cut c(mySbase, myGShape);
343 UpdateDescendants(c, myShape, Standard_False);
344 //modified by NIZNHY-PKV Thu Mar 21 17:56:02 2002 t
355 //=======================================================================
357 //purpose : construction of prism oriented at the face Until, sufficiently
358 // long; call of topological reconstruction
359 //=======================================================================
361 void BRepFeat_MakePrism::Perform(const TopoDS_Shape& Until)
364 Standard_Boolean trc = BRepFeat_GettraceFEAT();
365 if (trc) cout << "BRepFeat_MakePrism::Perform(Until)" << endl;
367 if (Until.IsNull()) {
368 Standard_ConstructionError::Raise();
370 TopExp_Explorer exp(Until, TopAbs_FACE);
372 Standard_ConstructionError::Raise();
375 myPerfSelection = BRepFeat_SelectionU;
376 PerfSelectionValid();
380 Standard_Boolean Trf = TransformShapeFU(1);
382 Handle(Geom_Curve) C = TestCurve(myPbase,myDir);
383 Standard_Integer sens = SensOfPrism(C, mySUntil);
384 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
385 gp_Vec V(2*sens*Height*myDir);
387 // construction of long prism
388 LocOpe_Prism thePrism(myPbase,V);
389 TopoDS_Shape VraiPrism = thePrism.Shape();
391 // in case of support of face Until
393 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
394 myGShape = VraiPrism;
395 GeneratedShapeValid();
397 //SetGluedFaces(mySkface, mySbase, myPbase, mySlface, thePrism, myGluedF);
399 // VerifGluedFaces(mySkface, myPbase, myBCurve, myCurves, thePrism, myGluedF);
401 thePrism.Curves(myCurves);
402 myBCurve = thePrism.BarycCurve();
405 else { // until support -> passage to topological operations
406 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
407 TColGeom_SequenceOfCurve scur;
411 // direction of the prism depending on Until
413 LocOpe_CSIntersector ASI(mySUntil);
415 TopAbs_Orientation Or;
416 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
418 Or = ASI.Point(1,1).Orientation();
421 Or = ASI.Point(1,ASI.NbPoints(1)).Orientation();
423 if(sens==-1) Or=TopAbs::Reverse(Or);
424 TopoDS_Face FUntil = ASI.Point(1,1).Face();
427 B.MakeCompound(TopoDS::Compound(Comp));
428 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
429 if (!S.IsNull()) B.Add(Comp,S);
430 //modified by NIZNHY-PKV Thu Mar 21 17:56:31 2002 f
431 //BRepAlgo_Cut trP(VraiPrism,Comp);
432 //UpdateDescendants(trP.Builder(),trP.Shape(), Standard_False);
433 BRepAlgoAPI_Cut trP(VraiPrism,Comp);
434 UpdateDescendants(trP, trP.Shape(), Standard_False);
435 //modified by NIZNHY-PKV Thu Mar 21 17:56:38 2002 t
436 TopExp_Explorer ex(trP.Shape(), TopAbs_SOLID);
437 TopoDS_Shape Cutsh = ex.Current();
438 if(myFuse == 1 && !myJustFeat) {
439 //modified by NIZNHY-PKV Thu Mar 21 17:57:49 2002 f
440 //BRepAlgo_Fuse f(mySbase, Cutsh);
441 //myShape = f.Shape();
442 //UpdateDescendants(f.Builder(), myShape, Standard_False);
443 BRepAlgoAPI_Fuse f(mySbase, Cutsh);
445 UpdateDescendants(f, myShape, Standard_False);
446 //modified by NIZNHY-PKV Thu Mar 21 17:57:53 2002 t
449 else if(myFuse == 0) {
450 //modified by NIZNHY-PKV Thu Mar 21 17:59:33 2002 f
451 //BRepAlgo_Cut c(mySbase, Cutsh);
452 //myShape = c.Shape();
453 //UpdateDescendants(c.Builder(), myShape, Standard_False);
454 BRepAlgoAPI_Cut c(mySbase, Cutsh);
456 UpdateDescendants(c, myShape, Standard_False);
457 //modified by NIZNHY-PKV Thu Mar 21 17:59:43 2002 t
466 /* // loop of control of descendance
468 TopExp_Explorer expr(mySbase, TopAbs_FACE);
469 char nom1[20], nom2[20];
470 Standard_Integer ii = 0;
471 for(; expr.More(); expr.Next()) {
473 sprintf(nom1, "faceinitial_%d", ii);
474 DBRep::Set(nom1, expr.Current());
475 Standard_Integer jj = 0;
476 const TopTools_ListOfShape& list = Modified(expr.Current());
477 TopTools_ListIteratorOfListOfShape ite(list);
478 for(; ite.More(); ite.Next()) {
480 sprintf(nom2, "facemodifie_%d_%d", ii, jj);
481 DBRep::Set(nom2, ite.Value());
485 expr.Init(myPbase, TopAbs_EDGE);
487 for(; expr.More(); expr.Next()) {
489 sprintf(nom1, "edgeinitial_%d", ii);
490 DBRep::Set(nom1, expr.Current());
491 Standard_Integer jj = 0;
492 const TopTools_ListOfShape& list = Generated(expr.Current());
493 TopTools_ListIteratorOfListOfShape ite(list);
494 for(; ite.More(); ite.Next()) {
496 sprintf(nom2, "facegeneree_%d_%d", ii, jj);
497 DBRep::Set(nom2, ite.Value());
504 //=======================================================================
506 //purpose : construction of a sufficiently long and properly oriented prism
507 // call of topological reconstruction
508 //=======================================================================
510 void BRepFeat_MakePrism::Perform(const TopoDS_Shape& From,
511 const TopoDS_Shape& Until)
514 Standard_Boolean trc = BRepFeat_GettraceFEAT();
515 if (trc) cout << "BRepFeat_MakePrism::Perform(From,Until)" << endl;
517 if (From.IsNull() || Until.IsNull()) {
518 Standard_ConstructionError::Raise();
521 if (!mySkface.IsNull()) {
522 if (From.IsSame(mySkface)) {
523 myJustGluer = Standard_True;
525 if (myJustGluer) return;
527 else if (Until.IsSame(mySkface)) {
528 myJustGluer = Standard_True;
530 if (myJustGluer) return;
535 myPerfSelection = BRepFeat_SelectionFU;
536 PerfSelectionValid();
538 TopExp_Explorer exp(From, TopAbs_FACE);
540 Standard_ConstructionError::Raise();
542 exp.Init(Until, TopAbs_FACE);
544 Standard_ConstructionError::Raise();
547 Standard_Boolean Trff = TransformShapeFU(0);
550 Standard_Boolean Trfu = TransformShapeFU(1);
554 myStatusError = BRepFeat_IncTypes;
558 // length depending on bounding boxes
560 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
561 Handle(Geom_Curve) C = TestCurve(myPbase,myDir);
562 Standard_Integer sens; // direction of prism
563 Standard_Integer tran; // transfer of prism
564 if(From.IsSame(Until)) {
569 sens = SensOfPrism(C, mySUntil);
570 tran = sens*SensOfPrism(C, mySFrom);
572 LocOpe_Prism thePrism;
574 gp_Vec Vtra(-3*Height*sens/2.*myDir);
575 thePrism.Perform(myPbase,3*sens*Height*myDir,Vtra);
578 thePrism.Perform(myPbase,2*sens*Height*myDir);
580 TopoDS_Shape VraiPrism = thePrism.Shape();
583 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
585 myGShape = VraiPrism;
586 GeneratedShapeValid();
588 //SetGluedFaces(TopoDS_Face(), // on ne veut pas binder mySkface
589 // mySbase, myPbase, mySlface, thePrism, myGluedF);
591 //// VerifGluedFaces(mySkface, myPbase, myBCurve, myCurves, thePrism, myGluedF);
593 thePrism.Curves(myCurves);
594 myBCurve = thePrism.BarycCurve();
597 else { // case until support -> topological operation
598 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
599 TColGeom_SequenceOfCurve scur;
602 LocOpe_CSIntersector ASI1(mySUntil);
603 LocOpe_CSIntersector ASI2(mySFrom);
606 TopAbs_Orientation OrU, OrF;
607 TopoDS_Face FFrom, FUntil;
608 if (ASI1.IsDone() && ASI1.NbPoints(1) >=1) {
610 OrU = ASI1.Point(1,1).Orientation();
613 OrU = ASI1.Point(1,ASI1.NbPoints(1)).Orientation();
615 if(sens==-1) OrU = TopAbs::Reverse(OrU);
616 FUntil = ASI1.Point(1,1).Face();
620 myStatusError = BRepFeat_NoIntersectU;
623 if (ASI2.IsDone() && ASI2.NbPoints(1) >=1) {
624 OrF = ASI2.Point(1,1).Orientation();
625 if(sens==1) OrF = TopAbs::Reverse(OrF);
626 FFrom = ASI2.Point(1,1).Face();
630 myStatusError = BRepFeat_NoIntersectF;
635 B.MakeCompound(TopoDS::Compound(Comp));
636 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, OrU);
642 myStatusError = BRepFeat_NullToolU;
645 TopoDS_Solid SS = BRepFeat::Tool(mySFrom, FFrom, OrF);
651 myStatusError = BRepFeat_NullToolF;
654 //modified by NIZNHY-PKV Thu Mar 21 18:00:10 2002 f
655 //BRepAlgo_Cut trP(VraiPrism,Comp);
656 //UpdateDescendants(trP.Builder(), trP.Shape(), Standard_False);
657 BRepAlgoAPI_Cut trP(VraiPrism,Comp);
658 UpdateDescendants(trP, trP.Shape(), Standard_False);
659 //modified by NIZNHY-PKV Thu Mar 21 18:00:16 2002 t
660 if(myFuse == 1 && !myJustFeat) {
661 //modified by NIZNHY-PKV Thu Mar 21 18:00:35 2002 f
662 //BRepAlgo_Fuse f(mySbase, trP.Shape());
663 //myShape = f.Shape();
664 //UpdateDescendants(f.Builder(), myShape, Standard_False);
665 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
667 UpdateDescendants(f, myShape, Standard_False);
668 //modified by NIZNHY-PKV Thu Mar 21 18:00:40 2002 t
671 else if(myFuse == 0) {
672 //modified by NIZNHY-PKV Thu Mar 21 18:01:01 2002 f
673 //BRepAlgo_Cut c(mySbase, trP.Shape());
674 //myShape = c.Shape();
675 //UpdateDescendants(c.Builder(), myShape, Standard_False);
676 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
678 UpdateDescendants(c, myShape, Standard_False);
679 //modified by NIZNHY-PKV Thu Mar 21 18:01:13 2002 t
683 myShape = trP.Shape();
689 TopExp_Explorer expr(mySbase, TopAbs_FACE);
690 char nom1[20], nom2[20];
691 Standard_Integer ii = 0;
692 for(; expr.More(); expr.Next()) {
694 sprintf(nom1, "faceinitial_%d", ii);
695 DBRep::Set(nom1, expr.Current());
696 Standard_Integer jj = 0;
697 const TopTools_ListOfShape& list = Modified(expr.Current());
698 TopTools_ListIteratorOfListOfShape ite(list);
699 for(; ite.More(); ite.Next()) {
701 sprintf(nom2, "facemodifie_%d_%d", ii, jj);
702 DBRep::Set(nom2, ite.Value());
706 expr.Init(myPbase, TopAbs_EDGE);
708 for(; expr.More(); expr.Next()) {
710 sprintf(nom1, "edgeinitial_%d", ii);
711 DBRep::Set(nom1, expr.Current());
712 Standard_Integer jj = 0;
713 const TopTools_ListOfShape& list = Generated(expr.Current());
714 TopTools_ListIteratorOfListOfShape ite(list);
715 for(; ite.More(); ite.Next()) {
717 sprintf(nom2, "egdegeneree_%d_%d", ii, jj);
718 DBRep::Set(nom2, ite.Value());
726 //=======================================================================
727 //function : PerformUntilEnd
728 //purpose : construction of a prism and reconstruction
729 //=======================================================================
731 void BRepFeat_MakePrism::PerformUntilEnd()
734 Standard_Boolean trc = BRepFeat_GettraceFEAT();
735 if (trc) cout << "BRepFeat_MakePrism::PerformUntilEnd()" << endl;
737 myPerfSelection = BRepFeat_SelectionSh;
738 PerfSelectionValid();
744 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
745 gp_Vec V(2*Height*myDir);
747 LocOpe_Prism thePrism(myPbase,V);
748 TopoDS_Shape VraiPrism = thePrism.Shape();
750 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
752 myGShape = VraiPrism;
753 GeneratedShapeValid();
757 //modified by NIZNHY-PKV Thu Mar 21 18:02:46 2002 f
758 //BRepAlgo_Cut c(mySbase, myGShape);
759 BRepAlgoAPI_Cut c(mySbase, myGShape);
760 //modified by NIZNHY-PKV Thu Mar 21 18:03:15 2002 t
763 //modified by NIZNHY-PKV Thu Mar 21 18:03:38 2002 f
764 //UpdateDescendants(c.Builder(), myShape, Standard_False);
765 UpdateDescendants(c, myShape, Standard_False);
766 //modified by NIZNHY-PKV Thu Mar 21 18:03:42 2002 t
771 thePrism.Curves(myCurves);
772 myBCurve = thePrism.BarycCurve();
777 //=======================================================================
778 //function : PerformFromEnd
780 //=======================================================================
782 void BRepFeat_MakePrism::PerformFromEnd(const TopoDS_Shape& Until)
785 Standard_Boolean trc = BRepFeat_GettraceFEAT();
786 if (trc) cout << "BRepFeat_MakePrism::PerformFromEnd(From,Until)" << endl;
788 if (Until.IsNull()) {
789 Standard_ConstructionError::Raise();
791 if (!mySkface.IsNull() && Until.IsSame(mySkface)) {
797 exp.Init(Until, TopAbs_FACE);
799 Standard_ConstructionError::Raise();
801 myPerfSelection = BRepFeat_SelectionShU;
802 PerfSelectionValid();
806 Standard_Boolean Trf = TransformShapeFU(1);
808 Handle(Geom_Curve) C = TestCurve(myPbase,myDir);
809 Standard_Integer sens = SensOfPrism(C, mySUntil);
810 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
811 gp_Vec Vtra(-3*Height*sens/2.*myDir);
812 gp_Vec Vect(3*sens*Height*myDir);
813 LocOpe_Prism thePrism(myPbase,Vect,Vtra);
814 TopoDS_Shape VraiPrism = thePrism.Shape();
816 if(!Trf) { // case face until
817 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
818 myGShape = VraiPrism;
819 GeneratedShapeValid();
822 thePrism.Curves(myCurves);
823 myBCurve = thePrism.BarycCurve();
826 else { // case support
827 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
828 TColGeom_SequenceOfCurve scur;
831 LocOpe_CSIntersector ASI1(mySUntil);
832 LocOpe_CSIntersector ASI2(mySbase);
835 TopAbs_Orientation OrU = TopAbs_FORWARD, OrF = TopAbs_FORWARD;
836 TopoDS_Face FUntil, FFrom;
837 if (ASI1.IsDone() && ASI1.NbPoints(1) >=1) {
838 OrU = ASI1.Point(1,1).Orientation();
840 OrU = TopAbs::Reverse(OrU);
842 FUntil = ASI1.Point(1,1).Face();
844 if (ASI2.IsDone() && ASI2.NbPoints(1) >=1) {
845 OrF = ASI2.Point(1,1).Orientation();
846 // if(sens==1) OrF = TopAbs::Reverse(OrF);
847 FFrom = ASI2.Point(1 ,1).Face();
848 Handle(Geom_Surface) S = BRep_Tool::Surface(FFrom);
849 if (S->DynamicType() ==
850 STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
851 S = Handle(Geom_RectangularTrimmedSurface)::
852 DownCast(S)->BasisSurface();
854 BRepLib_MakeFace fac(S, Precision::Confusion());
855 mySFrom = fac.Face();
856 Trf = TransformShapeFU(0);
857 FFrom = TopoDS::Face(mySFrom);
865 B.MakeCompound(TopoDS::Compound(Comp));
866 TopoDS_Solid Sol = BRepFeat::Tool(mySUntil, FUntil, OrU);
872 myStatusError = BRepFeat_NullToolU;
876 TopoDS_Solid Sol1 = BRepFeat::Tool(mySFrom, FFrom, OrF);
877 if (!Sol1.IsNull()) {
882 myStatusError = BRepFeat_NullToolF;
885 //modified by NIZNHY-PKV Thu Mar 21 18:03:57 2002 f
886 //BRepAlgo_Cut trP(VraiPrism,Comp);
887 //UpdateDescendants(trP.Builder(), trP.Shape(), Standard_False);
888 BRepAlgoAPI_Cut trP(VraiPrism,Comp);
889 UpdateDescendants(trP, trP.Shape(), Standard_False);
890 //modified by NIZNHY-PKV Thu Mar 21 18:04:08 2002 t
891 if(myFuse == 1 && !myJustFeat) {
892 //modified by NIZNHY-PKV Thu Mar 21 18:04:33 2002 f
893 //BRepAlgo_Fuse f(mySbase, trP.Shape());
894 //myShape = f.Shape();
895 //UpdateDescendants(f.Builder(), myShape, Standard_False);
896 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
898 UpdateDescendants(f, myShape, Standard_False);
899 //modified by NIZNHY-PKV Thu Mar 21 18:04:41 2002 t
902 else if(myFuse == 0) {
903 //modified by NIZNHY-PKV Thu Mar 21 18:04:54 2002 f
904 //BRepAlgo_Cut c(mySbase, trP.Shape());
905 //myShape = c.Shape();
906 //UpdateDescendants(c.Builder(), myShape, Standard_False);
907 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
909 UpdateDescendants(c, myShape, Standard_False);
910 //modified by NIZNHY-PKV Thu Mar 21 18:05:00 2002 t
914 myShape = trP.Shape();
922 //=======================================================================
923 //function : PerformThruAll
925 //=======================================================================
927 void BRepFeat_MakePrism::PerformThruAll()
930 Standard_Boolean trc = BRepFeat_GettraceFEAT();
931 if (trc) cout << "BRepFeat_MakePrism::PerformThruAll()" << endl;
938 myPerfSelection = BRepFeat_NoSelection;
941 myPerfSelection = BRepFeat_SelectionSh;
943 PerfSelectionValid();
947 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
948 gp_Vec V(3*Height*myDir);
949 gp_Vec Vtra(-3*Height/2.*myDir);
950 LocOpe_Prism thePrism(myPbase,V,Vtra);
951 TopoDS_Shape VraiPrism = thePrism.Shape();
952 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
954 myGShape = VraiPrism;
955 GeneratedShapeValid();
958 //modified by NIZNHY-PKV Thu Mar 21 18:05:31 2002 f
959 //BRepAlgo_Cut c(mySbase, myGShape);
960 BRepAlgoAPI_Cut c(mySbase, myGShape);
961 //modified by NIZNHY-PKV Thu Mar 21 18:05:33 2002 t
964 //modified by NIZNHY-PKV Thu Mar 21 18:05:46 2002 f
965 //UpdateDescendants(c.Builder(), myShape, Standard_False);
966 UpdateDescendants(c, myShape, Standard_False);
967 //modified by NIZNHY-PKV Thu Mar 21 18:05:50 2002 t
972 thePrism.Curves(myCurves);
973 myBCurve = thePrism.BarycCurve();
979 //=======================================================================
980 //function : PerformUntilHauteur
982 //=======================================================================
984 void BRepFeat_MakePrism::PerformUntilHeight(const TopoDS_Shape& Until,
985 const Standard_Real Length)
988 Standard_Boolean trc = BRepFeat_GettraceFEAT();
989 if (trc) cout << "BRepFeat_MakePrism::PerformUntilHeight(Until,Length)" << endl;
991 if (Until.IsNull()) {
997 TopExp_Explorer exp(Until, TopAbs_FACE);
999 Standard_ConstructionError::Raise();
1002 myPerfSelection = BRepFeat_NoSelection;
1003 PerfSelectionValid();
1007 Standard_Boolean Trf = TransformShapeFU(1);
1009 Handle(Geom_Curve) C = TestCurve(myPbase,myDir);
1010 Standard_Integer sens = SensOfPrism(C, mySUntil);
1011 gp_Vec V(sens*Length*myDir);
1012 LocOpe_Prism thePrism(myPbase,V);
1013 TopoDS_Shape VraiPrism = thePrism.Shape();
1016 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
1018 myGShape = VraiPrism;
1019 GeneratedShapeValid();
1021 //SetGluedFaces(mySkface, mySbase, myPbase, mySlface, thePrism, myGluedF);
1023 // VerifGluedFaces(mySkface, myPbase, myBCurve, myCurves, thePrism, myGluedF);
1025 thePrism.Curves(myCurves);
1026 myBCurve = thePrism.BarycCurve();
1030 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
1031 TColGeom_SequenceOfCurve scur;
1034 LocOpe_CSIntersector ASI(mySUntil);
1036 TopAbs_Orientation Or;
1037 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
1039 Or = ASI.Point(1,1).Orientation();
1042 Or = ASI.Point(1,ASI.NbPoints(1)).Orientation();
1044 if(sens==-1) Or=TopAbs::Reverse(Or);
1045 TopoDS_Face FUntil = ASI.Point(1,1).Face();
1048 B.MakeCompound(TopoDS::Compound(Comp));
1049 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
1050 if (!S.IsNull()) B.Add(Comp,S);
1052 //modified by NIZNHY-PKV Thu Mar 21 18:06:09 2002 f
1053 //BRepAlgo_Cut trP(VraiPrism,Comp);
1054 //UpdateDescendants(trP.Builder(), trP.Shape(), Standard_False);
1055 BRepAlgoAPI_Cut trP(VraiPrism,Comp);
1056 UpdateDescendants(trP, trP.Shape(), Standard_False);
1057 //modified by NIZNHY-PKV Thu Mar 21 18:06:15 2002 t
1058 if(myFuse == 1 && !myJustFeat) {
1059 //modified by NIZNHY-PKV Thu Mar 21 18:06:36 2002 f
1060 //BRepAlgo_Fuse f(mySbase, trP.Shape());
1061 //myShape = f.Shape();
1062 //UpdateDescendants(f.Builder(), myShape, Standard_False);
1063 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
1064 myShape = f.Shape();
1065 UpdateDescendants(f, myShape, Standard_False);
1066 //modified by NIZNHY-PKV Thu Mar 21 18:06:41 2002 t
1069 else if(myFuse == 0) {
1070 //modified by NIZNHY-PKV Thu Mar 21 18:07:06 2002 f
1071 //BRepAlgo_Cut c(mySbase, trP.Shape());
1072 //myShape = c.Shape();
1073 //UpdateDescendants(c.Builder(), myShape, Standard_False);
1074 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
1075 myShape = c.Shape();
1076 UpdateDescendants(c, myShape, Standard_False);
1077 //modified by NIZNHY-PKV Thu Mar 21 18:07:12 2002 t
1081 myShape = trP.Shape();
1088 //=======================================================================
1090 //purpose : sequence of curves parallel to the axis of prism
1091 //=======================================================================
1093 void BRepFeat_MakePrism::Curves(TColGeom_SequenceOfCurve& scur)
1098 //=======================================================================
1099 //function : BarycCurve
1100 //purpose : curve parallel to the axis of the prism passing through the center
1102 //=======================================================================
1104 Handle(Geom_Curve) BRepFeat_MakePrism::BarycCurve()
1110 //=======================================================================
1111 //function : HeightMax
1112 //purpose : Calculate the height of the prism following the parameters of
1114 //=======================================================================
1116 static Standard_Real HeightMax(const TopoDS_Shape& theSbase,
1117 const TopoDS_Face& theSkface,
1118 const TopoDS_Shape& theSFrom,
1119 const TopoDS_Shape& theSUntil)
1122 BRepBndLib::Add(theSbase,Box);
1123 BRepBndLib::Add(theSkface,Box);
1124 if(!theSFrom.IsNull()) {
1125 Standard_Boolean FacRevolInfini = Standard_False;
1126 TopExp_Explorer exp;
1127 exp.Init(theSFrom, TopAbs_EDGE);
1128 for(; exp.More(); exp.Next()) {
1129 TopExp_Explorer exp1;
1130 exp1.Init(exp.Current(), TopAbs_VERTEX);
1132 FacRevolInfini = Standard_True;
1137 BRepBndLib::Add(theSFrom,Box);
1139 if(!theSUntil.IsNull()) {
1140 Standard_Boolean FacRevolInfini;
1141 TopExp_Explorer exp;
1142 exp.Init(theSUntil, TopAbs_EDGE);
1143 for(; exp.More(); exp.Next()) {
1144 TopExp_Explorer exp1;
1145 exp1.Init(exp.Current(), TopAbs_VERTEX);
1147 FacRevolInfini = Standard_True;
1152 BRepBndLib::Add(theSUntil,Box);
1157 Box.Get(c[0],c[2],c[4],c[1],c[3],c[5]);
1158 Standard_Real parmin=c[0], parmax = c[0];
1159 for(Standard_Integer i = 0 ; i < 6; i++) {
1160 if(c[i] > parmax) parmax = c[i];
1161 if(c[i] < parmin ) parmin = c[i];
1164 Standard_Real Height = fabs(2.*(parmax - parmin));
1166 // Standard_Real Height = abs(2.*(parmax - parmin));
1172 //=======================================================================
1173 //function : SensOfPrism
1174 //purpose : Direction of the prism depending on the shape Until
1175 //=======================================================================
1176 Standard_Integer SensOfPrism(const Handle(Geom_Curve) C,
1177 const TopoDS_Shape& Until)
1179 LocOpe_CSIntersector ASI1(Until);
1180 TColGeom_SequenceOfCurve scur;
1183 Standard_Integer sens = 1;
1184 if(ASI1.IsDone() && ASI1.NbPoints(1) >= 1) {
1185 if(ASI1.Point(1, 1).Parameter() < 0. &&
1186 ASI1.Point(1, ASI1.NbPoints(1)).Parameter() < 0.) {
1190 else if(BRepFeat::ParametricBarycenter(Until,C) < 0) {
1198 //=======================================================================
1199 //function : SetGluedFaces
1200 //purpose : management of gluing faces
1201 //=======================================================================
1203 static void SetGluedFaces(const TopoDS_Face& theSkface,
1204 const TopoDS_Shape& theSbase,
1205 const TopoDS_Shape& thePbase,
1206 const TopTools_DataMapOfShapeListOfShape& theSlmap,
1207 LocOpe_Prism& thePrism,
1208 TopTools_DataMapOfShapeShape& theMap)
1210 TopExp_Explorer exp;
1211 if (!theSkface.IsNull() && thePbase.ShapeType() == TopAbs_FACE) {
1212 for (exp.Init(theSbase,TopAbs_FACE); exp.More(); exp.Next()) {
1213 if (exp.Current().IsSame(theSkface)) {
1214 theMap.Bind(thePbase,theSkface);
1220 for (exp.Init(theSbase,TopAbs_FACE); exp.More(); exp.Next()) {
1221 if (exp.Current().IsSame(theSkface)) {
1222 TopExp_Explorer exp2;
1223 for (exp2.Init(thePbase,TopAbs_FACE);exp2.More();exp2.Next()) {
1224 theMap.Bind(exp2.Current(),theSkface);
1232 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm(theSlmap);
1233 if(!theSlmap.IsEmpty()) {
1234 for (; itm.More(); itm.Next()) {
1235 const TopoDS_Face& fac = TopoDS::Face(itm.Key());
1236 const TopTools_ListOfShape& ledg = itm.Value();
1237 TopTools_ListIteratorOfListOfShape it;
1238 for (it.Initialize(ledg); it.More(); it.Next()) {
1239 const TopTools_ListOfShape& gfac = thePrism.Shapes(it.Value());
1240 if (gfac.Extent() != 1) {
1242 Standard_Boolean trc = BRepFeat_GettraceFEAT();
1243 if (trc) cout << " BRepFeat_MakePrism : Pb SetGluedFace" << endl;
1246 theMap.Bind(gfac.First(),fac);
1253 //=======================================================================
1254 //function : VerifGluedFaces
1255 //purpose : Verification intersection Tool/theSkface = thePbase
1256 // If yes -> OK otherwise -> case without gluing
1257 //=======================================================================
1259 static void VerifGluedFaces(const TopoDS_Face& theSkface,
1260 const TopoDS_Shape& thePbase,
1261 Handle(Geom_Curve)& theBCurve,
1262 TColGeom_SequenceOfCurve& theCurves,
1263 LocOpe_Prism& thePrism,
1264 TopTools_DataMapOfShapeShape& theMap)
1266 Standard_Boolean GluedFaces = Standard_True;
1267 TopoDS_Shape VraiPrism = thePrism.Shape();
1269 TColGeom_SequenceOfCurve scur;
1270 thePrism.Curves(theCurves);
1271 theBCurve = thePrism.BarycCurve();
1273 scur.Append(theBCurve);
1274 LocOpe_CSIntersector ASI(theSkface);
1276 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
1277 TopAbs_Orientation Or = ASI.Point(1,1).Orientation();
1278 TopoDS_Face FSk = ASI.Point(1,1).Face();
1281 B.MakeCompound(TopoDS::Compound(Comp));
1282 TopoDS_Solid S = BRepFeat::Tool(theSkface, FSk, Or);
1283 if (!S.IsNull()) B.Add(Comp,S);
1284 //modified by NIZNHY-PKV Thu Mar 21 18:07:35 2002 f
1285 //BRepAlgo_Cut trP(VraiPrism,Comp);
1286 BRepAlgoAPI_Cut trP(VraiPrism,Comp);
1287 //modified by NIZNHY-PKV Thu Mar 21 18:07:39 2002 t
1288 TopoDS_Shape Cutsh = trP.Shape();
1289 TopExp_Explorer ex(Cutsh, TopAbs_SOLID);
1290 for(; ex.More(); ex.Next()) {
1291 TopExp_Explorer ex1(ex.Current(), TopAbs_FACE);
1292 for(; ex1.More(); ex1.Next()) {
1293 const TopoDS_Face& fac1 = TopoDS::Face(ex1.Current());
1294 TopExp_Explorer ex2(thePbase, TopAbs_FACE);
1295 for(; ex2.More(); ex2.Next()) {
1296 const TopoDS_Face& fac2 = TopoDS::Face(ex2.Current());
1297 if(fac1.IsSame(fac2)) break;
1299 if (ex2.More()) break;
1301 if (ex1.More()) continue;
1302 GluedFaces = Standard_False;
1307 Standard_Boolean trc = BRepFeat_GettraceFEAT();
1308 if (trc) cout << " Intersection Prism/skface : no gluing" << endl;
1316 //=======================================================================
1318 //purpose : management of descendants
1319 //=======================================================================
1321 static void MajMap(const TopoDS_Shape& theB,
1322 const LocOpe_Prism& theP,
1323 TopTools_DataMapOfShapeListOfShape& theMap, // myMap
1324 TopoDS_Shape& theFShape, // myFShape
1325 TopoDS_Shape& theLShape) // myLShape
1327 TopExp_Explorer exp(theP.FirstShape(),TopAbs_WIRE);
1329 theFShape = exp.Current();
1330 TopTools_ListOfShape thelist2;
1331 theMap.Bind(theFShape, thelist2);
1332 for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) {
1333 theMap(theFShape).Append(exp.Current());
1337 exp.Init(theP.LastShape(),TopAbs_WIRE);
1339 theLShape = exp.Current();
1340 TopTools_ListOfShape thelist3;
1341 theMap.Bind(theLShape, thelist3);
1342 for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) {
1343 theMap(theLShape).Append(exp.Current());
1347 for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) {
1348 if (!theMap.IsBound(exp.Current())) {
1349 TopTools_ListOfShape thelist4;
1350 theMap.Bind(exp.Current(), thelist4);
1351 theMap(exp.Current()) = theP.Shapes(exp.Current());
1357 //=======================================================================
1359 //purpose : management of descendants
1360 //=======================================================================
1362 static Handle(Geom_Curve) TestCurve(const TopoDS_Shape& Base,
1365 gp_Pnt bar(0., 0., 0.);
1366 TColgp_SequenceOfPnt spt;
1367 LocOpe::SampleEdges(Base,spt);
1368 for (Standard_Integer jj=1;jj<=spt.Length(); jj++) {
1369 const gp_Pnt& pvt = spt(jj);
1370 bar.ChangeCoord() += pvt.XYZ();
1372 bar.ChangeCoord().Divide(spt.Length());
1373 gp_Ax1 newAx(bar,V);
1374 Handle(Geom_Line) theLin = new Geom_Line(newAx);
1381 //=======================================================================
1383 //purpose : face SameDomaine or not
1384 //=======================================================================
1386 Standard_Boolean ToFuse(const TopoDS_Face& F1,
1387 const TopoDS_Face& F2)
1389 if (F1.IsNull() || F2.IsNull()) {
1390 return Standard_False;
1393 Handle(Geom_Surface) S1,S2;
1394 TopLoc_Location loc1, loc2;
1395 Handle(Standard_Type) typS1,typS2;
1396 const Standard_Real tollin = Precision::Confusion();
1397 const Standard_Real tolang = Precision::Angular();
1399 S1 = BRep_Tool::Surface(F1,loc1);
1400 S2 = BRep_Tool::Surface(F2,loc2);
1402 typS1 = S1->DynamicType();
1403 typS2 = S2->DynamicType();
1405 if (typS1 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1406 S1 = (*((Handle(Geom_RectangularTrimmedSurface)*)&S1))->BasisSurface();
1407 typS1 = S1->DynamicType();
1410 if (typS2 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1411 S2 = (*((Handle(Geom_RectangularTrimmedSurface)*)&S2))->BasisSurface();
1412 typS2 = S2->DynamicType();
1415 if (typS1 != typS2) {
1416 return Standard_False;
1420 Standard_Boolean ValRet = Standard_False;
1421 if (typS1 == STANDARD_TYPE(Geom_Plane)) {
1422 S1 = BRep_Tool::Surface(F1); // to apply the location.
1423 S2 = BRep_Tool::Surface(F2);
1424 gp_Pln pl1( (*((Handle(Geom_Plane)*)&S1))->Pln());
1425 gp_Pln pl2( (*((Handle(Geom_Plane)*)&S2))->Pln());
1427 if (pl1.Position().IsCoplanar(pl2.Position(),tollin,tolang)) {
1428 ValRet = Standard_True;