1 // File: BRepFeat_MakePrism.cxx
2 // Created: Tue Feb 13 14:42:59 1996
3 // Author: Jacques GOUSSARD
7 #include <BRepFeat_MakePrism.ixx>
9 #include <BRepFeat.hxx>
11 #include <LocOpe_Prism.hxx>
12 #include <LocOpe_CSIntersector.hxx>
13 #include <LocOpe_PntFace.hxx>
18 #include <gp_Pnt2d.hxx>
19 #include <Geom_Curve.hxx>
20 #include <Geom_Line.hxx>
21 #include <Geom_RectangularTrimmedSurface.hxx>
22 #include <Geom_Surface.hxx>
24 #include <BRepLib_MakeFace.hxx>
26 #include <TColgp_SequenceOfPnt.hxx>
27 #include <TColGeom_SequenceOfCurve.hxx>
28 #include <Bnd_Box.hxx>
30 #include <BRep_Tool.hxx>
32 #include <BRepTools.hxx>
35 #include <TopExp_Explorer.hxx>
36 #include <TopTools_MapOfShape.hxx>
37 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
38 #include <TopTools_ListIteratorOfListOfShape.hxx>
39 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
40 #include <TopTools_ListIteratorOfListOfShape.hxx>
41 #include <TopTools_ListOfShape.hxx>
43 #include <BRepBuilderAPI.hxx>
44 #include <BRepPrimAPI_MakeBox.hxx>
46 //modified by NIZNHY-PKV Thu Mar 21 18:14:23 2002 f
47 //#include <BRepAlgo_Cut.hxx>
48 //#include <BRepAlgo_Fuse.hxx>
49 #include <BRepAlgoAPI_Cut.hxx>
50 #include <BRepAlgoAPI_Fuse.hxx>
51 //modified by NIZNHY-PKV Thu Mar 21 18:14:26 2002 t
53 #include <Standard_ConstructionError.hxx>
57 #include <TopoDS_Face.hxx>
58 #include <TopoDS_Solid.hxx>
59 #include <TopoDS_Compound.hxx>
62 #include <BRepBndLib.hxx>
64 #include <Precision.hxx>
66 #include <Geom_Plane.hxx>
69 Standard_IMPORT Standard_Boolean BRepFeat_GettraceFEAT();
72 static void MajMap(const TopoDS_Shape&, // base
74 TopTools_DataMapOfShapeListOfShape&, // myMap
75 TopoDS_Shape&, // myFShape
76 TopoDS_Shape&); // myLShape
78 static Standard_Boolean ToFuse(const TopoDS_Face& ,
82 static void SetGluedFaces(const TopoDS_Face& theSkface,
83 const TopoDS_Shape& theSbase,
84 const TopoDS_Shape& thePbase,
85 const TopTools_DataMapOfShapeListOfShape& theSlmap,
87 TopTools_DataMapOfShapeShape&);
90 static void VerifGluedFaces(const TopoDS_Face& theSkface,
91 const TopoDS_Shape& thePbase,
92 Handle(Geom_Curve)& theBCurve,
93 TColGeom_SequenceOfCurve& theCurves,
94 LocOpe_Prism& thePrism,
95 TopTools_DataMapOfShapeShape& theMap);
98 static Standard_Real HeightMax(const TopoDS_Shape& theSbase,
99 const TopoDS_Face& theSkface,
100 const TopoDS_Shape& theSFrom,
101 const TopoDS_Shape& theSUntil);
103 static Standard_Integer SensOfPrism(const Handle(Geom_Curve) C,
104 const TopoDS_Shape& Until);
106 static Handle(Geom_Curve) TestCurve(const TopoDS_Shape&,
110 //=======================================================================
113 //=======================================================================
115 void BRepFeat_MakePrism::Init(const TopoDS_Shape& Sbase,
116 const TopoDS_Shape& Pbase,
117 const TopoDS_Face& Skface,
119 const Standard_Integer Mode,
120 const Standard_Boolean Modify)
123 Standard_Boolean trc = BRepFeat_GettraceFEAT();
124 if (trc) cout << "BRepFeat_MakePrism::Init" << endl;
134 myFuse = Standard_False;
135 myJustFeat = Standard_False;
138 myFuse = Standard_True;
139 myJustFeat = Standard_False;
142 myFuse = Standard_True;
143 myJustFeat = Standard_True;
148 myJustGluer = Standard_False;
152 //mySkface.Nullify();
163 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
164 TopTools_ListOfShape thelist;
165 myMap.Bind(exp.Current(), thelist);
166 myMap(exp.Current()).Append(exp.Current());
170 if (myJustFeat) cout << " Just Feature" << endl;
171 if (myFuse) cout << " Fuse" << endl;
172 if (!myFuse) cout << " Cut" << endl;
173 if (!myModify) cout << " Modify = 0" << endl;
179 //=======================================================================
181 //purpose : add elements de glissemant (edge sur face)
182 //=======================================================================
184 void BRepFeat_MakePrism::Add(const TopoDS_Edge& E,
185 const TopoDS_Face& F)
188 Standard_Boolean trc = BRepFeat_GettraceFEAT();
189 if (trc) cout << "BRepFeat_MakePrism::Add(Edge,face)" << endl;
192 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
193 if (exp.Current().IsSame(F)) {
198 Standard_ConstructionError::Raise();
201 for (exp.Init(myPbase,TopAbs_EDGE);exp.More();exp.Next()) {
202 if (exp.Current().IsSame(E)) {
207 Standard_ConstructionError::Raise();
210 if (!mySlface.IsBound(F)) {
211 TopTools_ListOfShape thelist1;
212 mySlface.Bind(F, thelist1);
214 TopTools_ListIteratorOfListOfShape itl(mySlface(F));
215 for (; itl.More();itl.Next()) {
216 if (itl.Value().IsSame(E)) {
221 mySlface(F).Append(E);
226 //=======================================================================
228 //purpose : construction du prism de longueur Length et
229 // appel de reconstruction topo
230 //=======================================================================
232 void BRepFeat_MakePrism::Perform(const Standard_Real Length)
235 Standard_Boolean trc = BRepFeat_GettraceFEAT();
236 if (trc) cout << "BRepFeat_MakePrism::Perform(Length)" << endl;
243 myPerfSelection = BRepFeat_NoSelection;
244 PerfSelectionValid();
245 gp_Vec V(Length*myDir);
247 //construction de prism de hauteur Length
249 LocOpe_Prism thePrism(myPbase,V);
250 TopoDS_Shape VraiPrism = thePrism.Shape();
252 // gestion des descendants
253 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
256 myGShape = VraiPrism; // la primitive
257 GeneratedShapeValid();
261 Standard_Boolean found = Standard_False;
263 // essai de detecter des faces de collage
264 //cas le top du prism est tgt au shape initial
266 if(!mySkface.IsNull() || !mySlface.IsEmpty()) {
267 if(myLShape.ShapeType() == TopAbs_WIRE) {
268 TopExp_Explorer ex1(VraiPrism, TopAbs_FACE);
269 for(; ex1.More(); ex1.Next()) {
270 TopExp_Explorer ex2(ex1.Current(), TopAbs_WIRE);
271 for(; ex2.More(); ex2.Next()) {
272 if(ex2.Current().IsSame(myLShape)) {
273 FFace = TopoDS::Face(ex1.Current());
274 found = Standard_True;
282 TopExp_Explorer exp(mySbase, TopAbs_FACE);
283 for(; exp.More(); exp.Next()) {
284 const TopoDS_Face& ff = TopoDS::Face(exp.Current());
285 if(ToFuse(ff, FFace)) {
286 TopTools_DataMapOfShapeListOfShape sl;
287 if(!FFace.IsSame(myPbase) && BRepFeat::IsInside(ff, FFace))
288 // SetGluedFaces(ff, mySbase, FFace, sl, thePrism, myGluedF);
294 // gestion des faces de collage donnees par l'utilisateur
296 // SetGluedFaces(mySkface, mySbase, myPbase, mySlface, thePrism, myGluedF);
298 // VerifGluedFaces(mySkface, myPbase, myBCurve, myCurves, thePrism, myGluedF);
300 if(!myGluedF.IsEmpty()) { // cas collage
301 myJustGluer = Standard_True;
302 thePrism.Curves(myCurves);
303 myBCurve = thePrism.BarycCurve();
304 GlobalPerform(); // reconstruction topologique
307 // si il n'y a pas de collage -> appel des ope topo
309 if(myFuse == 1 && !myJustFeat) {
310 //modified by NIZNHY-PKV Thu Mar 21 17:55:30 2002 f
311 //BRepAlgo_Fuse f(mySbase, myGShape);
312 //myShape = f.Shape();
313 //UpdateDescendants(f.Builder(), myShape, Standard_False);
314 BRepAlgoAPI_Fuse f(mySbase, myGShape);
316 UpdateDescendants(f, myShape, Standard_False);
317 //modified by NIZNHY-PKV Thu Mar 21 17:55:34 2002 t
320 else if(myFuse == 0) {
321 //modified by NIZNHY-PKV Thu Mar 21 17:55:59 2002 f
322 //BRepAlgo_Cut c(mySbase, myGShape);
323 //myShape = c.Shape();
324 //UpdateDescendants(c.Builder(), myShape, Standard_False);
325 BRepAlgoAPI_Cut c(mySbase, myGShape);
327 UpdateDescendants(c, myShape, Standard_False);
328 //modified by NIZNHY-PKV Thu Mar 21 17:56:02 2002 t
339 //=======================================================================
341 //purpose : construction de prism oriente vers la face Until, suffisemment
342 // long; appel de reconstruction topo
343 //=======================================================================
345 void BRepFeat_MakePrism::Perform(const TopoDS_Shape& Until)
348 Standard_Boolean trc = BRepFeat_GettraceFEAT();
349 if (trc) cout << "BRepFeat_MakePrism::Perform(Until)" << endl;
351 if (Until.IsNull()) {
352 Standard_ConstructionError::Raise();
354 TopExp_Explorer exp(Until, TopAbs_FACE);
356 Standard_ConstructionError::Raise();
359 myPerfSelection = BRepFeat_SelectionU;
360 PerfSelectionValid();
364 Standard_Boolean Trf = TransformShapeFU(1);
366 Handle(Geom_Curve) C = TestCurve(myPbase,myDir);
367 Standard_Integer sens = SensOfPrism(C, mySUntil);
368 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
369 gp_Vec V(2*sens*Height*myDir);
371 // construction du prism long
372 LocOpe_Prism thePrism(myPbase,V);
373 TopoDS_Shape VraiPrism = thePrism.Shape();
375 // dans le cas de support de face Until
377 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
378 myGShape = VraiPrism;
379 GeneratedShapeValid();
381 //SetGluedFaces(mySkface, mySbase, myPbase, mySlface, thePrism, myGluedF);
383 // VerifGluedFaces(mySkface, myPbase, myBCurve, myCurves, thePrism, myGluedF);
385 thePrism.Curves(myCurves);
386 myBCurve = thePrism.BarycCurve();
389 else { // until support -> passage en ope topo
390 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
391 TColGeom_SequenceOfCurve scur;
395 // sens du prism en fonction de Until
397 LocOpe_CSIntersector ASI(mySUntil);
399 TopAbs_Orientation Or;
400 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
402 Or = ASI.Point(1,1).Orientation();
405 Or = ASI.Point(1,ASI.NbPoints(1)).Orientation();
407 if(sens==-1) Or=TopAbs::Reverse(Or);
408 TopoDS_Face FUntil = ASI.Point(1,1).Face();
411 B.MakeCompound(TopoDS::Compound(Comp));
412 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
413 if (!S.IsNull()) B.Add(Comp,S);
414 //modified by NIZNHY-PKV Thu Mar 21 17:56:31 2002 f
415 //BRepAlgo_Cut trP(VraiPrism,Comp);
416 //UpdateDescendants(trP.Builder(),trP.Shape(), Standard_False);
417 BRepAlgoAPI_Cut trP(VraiPrism,Comp);
418 UpdateDescendants(trP, trP.Shape(), Standard_False);
419 //modified by NIZNHY-PKV Thu Mar 21 17:56:38 2002 t
420 TopExp_Explorer ex(trP.Shape(), TopAbs_SOLID);
421 TopoDS_Shape Cutsh = ex.Current();
422 if(myFuse == 1 && !myJustFeat) {
423 //modified by NIZNHY-PKV Thu Mar 21 17:57:49 2002 f
424 //BRepAlgo_Fuse f(mySbase, Cutsh);
425 //myShape = f.Shape();
426 //UpdateDescendants(f.Builder(), myShape, Standard_False);
427 BRepAlgoAPI_Fuse f(mySbase, Cutsh);
429 UpdateDescendants(f, myShape, Standard_False);
430 //modified by NIZNHY-PKV Thu Mar 21 17:57:53 2002 t
433 else if(myFuse == 0) {
434 //modified by NIZNHY-PKV Thu Mar 21 17:59:33 2002 f
435 //BRepAlgo_Cut c(mySbase, Cutsh);
436 //myShape = c.Shape();
437 //UpdateDescendants(c.Builder(), myShape, Standard_False);
438 BRepAlgoAPI_Cut c(mySbase, Cutsh);
440 UpdateDescendants(c, myShape, Standard_False);
441 //modified by NIZNHY-PKV Thu Mar 21 17:59:43 2002 t
450 /* // boucle de controle de descendance
452 TopExp_Explorer expr(mySbase, TopAbs_FACE);
453 char nom1[20], nom2[20];
454 Standard_Integer ii = 0;
455 for(; expr.More(); expr.Next()) {
457 sprintf(nom1, "faceinitial_%d", ii);
458 DBRep::Set(nom1, expr.Current());
459 Standard_Integer jj = 0;
460 const TopTools_ListOfShape& list = Modified(expr.Current());
461 TopTools_ListIteratorOfListOfShape ite(list);
462 for(; ite.More(); ite.Next()) {
464 sprintf(nom2, "facemodifie_%d_%d", ii, jj);
465 DBRep::Set(nom2, ite.Value());
469 expr.Init(myPbase, TopAbs_EDGE);
471 for(; expr.More(); expr.Next()) {
473 sprintf(nom1, "edgeinitial_%d", ii);
474 DBRep::Set(nom1, expr.Current());
475 Standard_Integer jj = 0;
476 const TopTools_ListOfShape& list = Generated(expr.Current());
477 TopTools_ListIteratorOfListOfShape ite(list);
478 for(; ite.More(); ite.Next()) {
480 sprintf(nom2, "facegeneree_%d_%d", ii, jj);
481 DBRep::Set(nom2, ite.Value());
488 //=======================================================================
490 //purpose : construction d'un prisme suffisemment long et bien oriente
491 // appel de reconstruction topo
492 //=======================================================================
494 void BRepFeat_MakePrism::Perform(const TopoDS_Shape& From,
495 const TopoDS_Shape& Until)
498 Standard_Boolean trc = BRepFeat_GettraceFEAT();
499 if (trc) cout << "BRepFeat_MakePrism::Perform(From,Until)" << endl;
501 if (From.IsNull() || Until.IsNull()) {
502 Standard_ConstructionError::Raise();
505 if (!mySkface.IsNull()) {
506 if (From.IsSame(mySkface)) {
507 myJustGluer = Standard_True;
509 if (myJustGluer) return;
511 else if (Until.IsSame(mySkface)) {
512 myJustGluer = Standard_True;
514 if (myJustGluer) return;
519 myPerfSelection = BRepFeat_SelectionFU;
520 PerfSelectionValid();
522 TopExp_Explorer exp(From, TopAbs_FACE);
524 Standard_ConstructionError::Raise();
526 exp.Init(Until, TopAbs_FACE);
528 Standard_ConstructionError::Raise();
531 Standard_Boolean Trff = TransformShapeFU(0);
534 Standard_Boolean Trfu = TransformShapeFU(1);
538 myStatusError = BRepFeat_IncTypes;
542 // longueur en fonction des boites englobantes
544 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
545 Handle(Geom_Curve) C = TestCurve(myPbase,myDir);
546 Standard_Integer sens; // sens de prism
547 Standard_Integer tran; // transfert de prism
548 if(From.IsSame(Until)) {
553 sens = SensOfPrism(C, mySUntil);
554 tran = sens*SensOfPrism(C, mySFrom);
556 LocOpe_Prism thePrism;
558 gp_Vec Vtra(-3*Height*sens/2.*myDir);
559 thePrism.Perform(myPbase,3*sens*Height*myDir,Vtra);
562 thePrism.Perform(myPbase,2*sens*Height*myDir);
564 TopoDS_Shape VraiPrism = thePrism.Shape();
567 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
569 myGShape = VraiPrism;
570 GeneratedShapeValid();
572 //SetGluedFaces(TopoDS_Face(), // on ne veut pas binder mySkface
573 // mySbase, myPbase, mySlface, thePrism, myGluedF);
575 //// VerifGluedFaces(mySkface, myPbase, myBCurve, myCurves, thePrism, myGluedF);
577 thePrism.Curves(myCurves);
578 myBCurve = thePrism.BarycCurve();
581 else { // cas until support -> ope topo
582 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
583 TColGeom_SequenceOfCurve scur;
586 LocOpe_CSIntersector ASI1(mySUntil);
587 LocOpe_CSIntersector ASI2(mySFrom);
590 TopAbs_Orientation OrU, OrF;
591 TopoDS_Face FFrom, FUntil;
592 if (ASI1.IsDone() && ASI1.NbPoints(1) >=1) {
594 OrU = ASI1.Point(1,1).Orientation();
597 OrU = ASI1.Point(1,ASI1.NbPoints(1)).Orientation();
599 if(sens==-1) OrU = TopAbs::Reverse(OrU);
600 FUntil = ASI1.Point(1,1).Face();
604 myStatusError = BRepFeat_NoIntersectU;
607 if (ASI2.IsDone() && ASI2.NbPoints(1) >=1) {
608 OrF = ASI2.Point(1,1).Orientation();
609 if(sens==1) OrF = TopAbs::Reverse(OrF);
610 FFrom = ASI2.Point(1,1).Face();
614 myStatusError = BRepFeat_NoIntersectF;
619 B.MakeCompound(TopoDS::Compound(Comp));
620 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, OrU);
626 myStatusError = BRepFeat_NullToolU;
629 TopoDS_Solid SS = BRepFeat::Tool(mySFrom, FFrom, OrF);
635 myStatusError = BRepFeat_NullToolF;
638 //modified by NIZNHY-PKV Thu Mar 21 18:00:10 2002 f
639 //BRepAlgo_Cut trP(VraiPrism,Comp);
640 //UpdateDescendants(trP.Builder(), trP.Shape(), Standard_False);
641 BRepAlgoAPI_Cut trP(VraiPrism,Comp);
642 UpdateDescendants(trP, trP.Shape(), Standard_False);
643 //modified by NIZNHY-PKV Thu Mar 21 18:00:16 2002 t
644 if(myFuse == 1 && !myJustFeat) {
645 //modified by NIZNHY-PKV Thu Mar 21 18:00:35 2002 f
646 //BRepAlgo_Fuse f(mySbase, trP.Shape());
647 //myShape = f.Shape();
648 //UpdateDescendants(f.Builder(), myShape, Standard_False);
649 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
651 UpdateDescendants(f, myShape, Standard_False);
652 //modified by NIZNHY-PKV Thu Mar 21 18:00:40 2002 t
655 else if(myFuse == 0) {
656 //modified by NIZNHY-PKV Thu Mar 21 18:01:01 2002 f
657 //BRepAlgo_Cut c(mySbase, trP.Shape());
658 //myShape = c.Shape();
659 //UpdateDescendants(c.Builder(), myShape, Standard_False);
660 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
662 UpdateDescendants(c, myShape, Standard_False);
663 //modified by NIZNHY-PKV Thu Mar 21 18:01:13 2002 t
667 myShape = trP.Shape();
671 // controle historique
673 TopExp_Explorer expr(mySbase, TopAbs_FACE);
674 char nom1[20], nom2[20];
675 Standard_Integer ii = 0;
676 for(; expr.More(); expr.Next()) {
678 sprintf(nom1, "faceinitial_%d", ii);
679 DBRep::Set(nom1, expr.Current());
680 Standard_Integer jj = 0;
681 const TopTools_ListOfShape& list = Modified(expr.Current());
682 TopTools_ListIteratorOfListOfShape ite(list);
683 for(; ite.More(); ite.Next()) {
685 sprintf(nom2, "facemodifie_%d_%d", ii, jj);
686 DBRep::Set(nom2, ite.Value());
690 expr.Init(myPbase, TopAbs_EDGE);
692 for(; expr.More(); expr.Next()) {
694 sprintf(nom1, "edgeinitial_%d", ii);
695 DBRep::Set(nom1, expr.Current());
696 Standard_Integer jj = 0;
697 const TopTools_ListOfShape& list = Generated(expr.Current());
698 TopTools_ListIteratorOfListOfShape ite(list);
699 for(; ite.More(); ite.Next()) {
701 sprintf(nom2, "egdegeneree_%d_%d", ii, jj);
702 DBRep::Set(nom2, ite.Value());
710 //=======================================================================
711 //function : PerformUntilEnd
712 //purpose : construction d'un prism et reconstruction
713 //=======================================================================
715 void BRepFeat_MakePrism::PerformUntilEnd()
718 Standard_Boolean trc = BRepFeat_GettraceFEAT();
719 if (trc) cout << "BRepFeat_MakePrism::PerformUntilEnd()" << endl;
721 myPerfSelection = BRepFeat_SelectionSh;
722 PerfSelectionValid();
728 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
729 gp_Vec V(2*Height*myDir);
731 LocOpe_Prism thePrism(myPbase,V);
732 TopoDS_Shape VraiPrism = thePrism.Shape();
734 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
736 myGShape = VraiPrism;
737 GeneratedShapeValid();
741 //modified by NIZNHY-PKV Thu Mar 21 18:02:46 2002 f
742 //BRepAlgo_Cut c(mySbase, myGShape);
743 BRepAlgoAPI_Cut c(mySbase, myGShape);
744 //modified by NIZNHY-PKV Thu Mar 21 18:03:15 2002 t
747 //modified by NIZNHY-PKV Thu Mar 21 18:03:38 2002 f
748 //UpdateDescendants(c.Builder(), myShape, Standard_False);
749 UpdateDescendants(c, myShape, Standard_False);
750 //modified by NIZNHY-PKV Thu Mar 21 18:03:42 2002 t
755 thePrism.Curves(myCurves);
756 myBCurve = thePrism.BarycCurve();
761 //=======================================================================
762 //function : PerformFromEnd
764 //=======================================================================
766 void BRepFeat_MakePrism::PerformFromEnd(const TopoDS_Shape& Until)
769 Standard_Boolean trc = BRepFeat_GettraceFEAT();
770 if (trc) cout << "BRepFeat_MakePrism::PerformFromEnd(From,Until)" << endl;
772 if (Until.IsNull()) {
773 Standard_ConstructionError::Raise();
775 if (!mySkface.IsNull() && Until.IsSame(mySkface)) {
781 exp.Init(Until, TopAbs_FACE);
783 Standard_ConstructionError::Raise();
785 myPerfSelection = BRepFeat_SelectionShU;
786 PerfSelectionValid();
790 Standard_Boolean Trf = TransformShapeFU(1);
792 Handle(Geom_Curve) C = TestCurve(myPbase,myDir);
793 Standard_Integer sens = SensOfPrism(C, mySUntil);
794 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
795 gp_Vec Vtra(-3*Height*sens/2.*myDir);
796 gp_Vec Vect(3*sens*Height*myDir);
797 LocOpe_Prism thePrism(myPbase,Vect,Vtra);
798 TopoDS_Shape VraiPrism = thePrism.Shape();
800 if(!Trf) { // cas face until
801 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
802 myGShape = VraiPrism;
803 GeneratedShapeValid();
806 thePrism.Curves(myCurves);
807 myBCurve = thePrism.BarycCurve();
810 else { // cas support
811 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
812 TColGeom_SequenceOfCurve scur;
815 LocOpe_CSIntersector ASI1(mySUntil);
816 LocOpe_CSIntersector ASI2(mySbase);
820 TopAbs_Orientation OrU = TopAbs_FORWARD, OrF = TopAbs_FORWARD;
822 TopAbs_Orientation OrU, OrF;
824 TopoDS_Face FUntil, FFrom;
825 if (ASI1.IsDone() && ASI1.NbPoints(1) >=1) {
826 OrU = ASI1.Point(1,1).Orientation();
828 OrU = TopAbs::Reverse(OrU);
830 FUntil = ASI1.Point(1,1).Face();
832 if (ASI2.IsDone() && ASI2.NbPoints(1) >=1) {
833 OrF = ASI2.Point(1,1).Orientation();
834 // if(sens==1) OrF = TopAbs::Reverse(OrF);
835 FFrom = ASI2.Point(1 ,1).Face();
836 Handle(Geom_Surface) S = BRep_Tool::Surface(FFrom);
837 if (S->DynamicType() ==
838 STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
839 S = Handle(Geom_RectangularTrimmedSurface)::
840 DownCast(S)->BasisSurface();
842 BRepLib_MakeFace fac(S);
843 mySFrom = fac.Face();
844 Trf = TransformShapeFU(0);
845 FFrom = TopoDS::Face(mySFrom);
853 B.MakeCompound(TopoDS::Compound(Comp));
854 TopoDS_Solid Sol = BRepFeat::Tool(mySUntil, FUntil, OrU);
860 myStatusError = BRepFeat_NullToolU;
864 TopoDS_Solid Sol1 = BRepFeat::Tool(mySFrom, FFrom, OrF);
865 if (!Sol1.IsNull()) {
870 myStatusError = BRepFeat_NullToolF;
873 //modified by NIZNHY-PKV Thu Mar 21 18:03:57 2002 f
874 //BRepAlgo_Cut trP(VraiPrism,Comp);
875 //UpdateDescendants(trP.Builder(), trP.Shape(), Standard_False);
876 BRepAlgoAPI_Cut trP(VraiPrism,Comp);
877 UpdateDescendants(trP, trP.Shape(), Standard_False);
878 //modified by NIZNHY-PKV Thu Mar 21 18:04:08 2002 t
879 if(myFuse == 1 && !myJustFeat) {
880 //modified by NIZNHY-PKV Thu Mar 21 18:04:33 2002 f
881 //BRepAlgo_Fuse f(mySbase, trP.Shape());
882 //myShape = f.Shape();
883 //UpdateDescendants(f.Builder(), myShape, Standard_False);
884 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
886 UpdateDescendants(f, myShape, Standard_False);
887 //modified by NIZNHY-PKV Thu Mar 21 18:04:41 2002 t
890 else if(myFuse == 0) {
891 //modified by NIZNHY-PKV Thu Mar 21 18:04:54 2002 f
892 //BRepAlgo_Cut c(mySbase, trP.Shape());
893 //myShape = c.Shape();
894 //UpdateDescendants(c.Builder(), myShape, Standard_False);
895 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
897 UpdateDescendants(c, myShape, Standard_False);
898 //modified by NIZNHY-PKV Thu Mar 21 18:05:00 2002 t
902 myShape = trP.Shape();
910 //=======================================================================
911 //function : PerformThruAll
913 //=======================================================================
915 void BRepFeat_MakePrism::PerformThruAll()
918 Standard_Boolean trc = BRepFeat_GettraceFEAT();
919 if (trc) cout << "BRepFeat_MakePrism::PerformThruAll()" << endl;
926 myPerfSelection = BRepFeat_NoSelection;
929 myPerfSelection = BRepFeat_SelectionSh;
931 PerfSelectionValid();
935 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
936 gp_Vec V(3*Height*myDir);
937 gp_Vec Vtra(-3*Height/2.*myDir);
938 LocOpe_Prism thePrism(myPbase,V,Vtra);
939 TopoDS_Shape VraiPrism = thePrism.Shape();
940 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
942 myGShape = VraiPrism;
943 GeneratedShapeValid();
946 //modified by NIZNHY-PKV Thu Mar 21 18:05:31 2002 f
947 //BRepAlgo_Cut c(mySbase, myGShape);
948 BRepAlgoAPI_Cut c(mySbase, myGShape);
949 //modified by NIZNHY-PKV Thu Mar 21 18:05:33 2002 t
952 //modified by NIZNHY-PKV Thu Mar 21 18:05:46 2002 f
953 //UpdateDescendants(c.Builder(), myShape, Standard_False);
954 UpdateDescendants(c, myShape, Standard_False);
955 //modified by NIZNHY-PKV Thu Mar 21 18:05:50 2002 t
960 thePrism.Curves(myCurves);
961 myBCurve = thePrism.BarycCurve();
967 //=======================================================================
968 //function : PerformUntilHauteur
970 //=======================================================================
972 void BRepFeat_MakePrism::PerformUntilHeight(const TopoDS_Shape& Until,
973 const Standard_Real Length)
976 Standard_Boolean trc = BRepFeat_GettraceFEAT();
977 if (trc) cout << "BRepFeat_MakePrism::PerformUntilHeight(Until,Length)" << endl;
979 if (Until.IsNull()) {
985 TopExp_Explorer exp(Until, TopAbs_FACE);
987 Standard_ConstructionError::Raise();
990 myPerfSelection = BRepFeat_NoSelection;
991 PerfSelectionValid();
995 Standard_Boolean Trf = TransformShapeFU(1);
997 Handle(Geom_Curve) C = TestCurve(myPbase,myDir);
998 Standard_Integer sens = SensOfPrism(C, mySUntil);
999 gp_Vec V(sens*Length*myDir);
1000 LocOpe_Prism thePrism(myPbase,V);
1001 TopoDS_Shape VraiPrism = thePrism.Shape();
1004 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
1006 myGShape = VraiPrism;
1007 GeneratedShapeValid();
1009 //SetGluedFaces(mySkface, mySbase, myPbase, mySlface, thePrism, myGluedF);
1011 // VerifGluedFaces(mySkface, myPbase, myBCurve, myCurves, thePrism, myGluedF);
1013 thePrism.Curves(myCurves);
1014 myBCurve = thePrism.BarycCurve();
1018 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
1019 TColGeom_SequenceOfCurve scur;
1022 LocOpe_CSIntersector ASI(mySUntil);
1024 TopAbs_Orientation Or;
1025 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
1027 Or = ASI.Point(1,1).Orientation();
1030 Or = ASI.Point(1,ASI.NbPoints(1)).Orientation();
1032 if(sens==-1) Or=TopAbs::Reverse(Or);
1033 TopoDS_Face FUntil = ASI.Point(1,1).Face();
1036 B.MakeCompound(TopoDS::Compound(Comp));
1037 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
1038 if (!S.IsNull()) B.Add(Comp,S);
1040 //modified by NIZNHY-PKV Thu Mar 21 18:06:09 2002 f
1041 //BRepAlgo_Cut trP(VraiPrism,Comp);
1042 //UpdateDescendants(trP.Builder(), trP.Shape(), Standard_False);
1043 BRepAlgoAPI_Cut trP(VraiPrism,Comp);
1044 UpdateDescendants(trP, trP.Shape(), Standard_False);
1045 //modified by NIZNHY-PKV Thu Mar 21 18:06:15 2002 t
1046 if(myFuse == 1 && !myJustFeat) {
1047 //modified by NIZNHY-PKV Thu Mar 21 18:06:36 2002 f
1048 //BRepAlgo_Fuse f(mySbase, trP.Shape());
1049 //myShape = f.Shape();
1050 //UpdateDescendants(f.Builder(), myShape, Standard_False);
1051 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
1052 myShape = f.Shape();
1053 UpdateDescendants(f, myShape, Standard_False);
1054 //modified by NIZNHY-PKV Thu Mar 21 18:06:41 2002 t
1057 else if(myFuse == 0) {
1058 //modified by NIZNHY-PKV Thu Mar 21 18:07:06 2002 f
1059 //BRepAlgo_Cut c(mySbase, trP.Shape());
1060 //myShape = c.Shape();
1061 //UpdateDescendants(c.Builder(), myShape, Standard_False);
1062 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
1063 myShape = c.Shape();
1064 UpdateDescendants(c, myShape, Standard_False);
1065 //modified by NIZNHY-PKV Thu Mar 21 18:07:12 2002 t
1069 myShape = trP.Shape();
1076 //=======================================================================
1078 //purpose : sequence de courbes paralleles a l'axe de prism
1079 //=======================================================================
1081 void BRepFeat_MakePrism::Curves(TColGeom_SequenceOfCurve& scur)
1086 //=======================================================================
1087 //function : BarycCurve
1088 //purpose : courbe parallele a l'axe du prisme passant par le centre des
1090 //=======================================================================
1092 Handle(Geom_Curve) BRepFeat_MakePrism::BarycCurve()
1098 //=======================================================================
1099 //function : HeightMax
1100 //purpose : Calcul de la hauteur du prisme selon les parametres de
1102 //=======================================================================
1104 static Standard_Real HeightMax(const TopoDS_Shape& theSbase,
1105 const TopoDS_Face& theSkface,
1106 const TopoDS_Shape& theSFrom,
1107 const TopoDS_Shape& theSUntil)
1110 BRepBndLib::Add(theSbase,Box);
1111 BRepBndLib::Add(theSkface,Box);
1112 if(!theSFrom.IsNull()) {
1114 Standard_Boolean FacRevolInfini = Standard_False;
1116 Standard_Boolean FacRevolInfini;
1118 TopExp_Explorer exp;
1119 exp.Init(theSFrom, TopAbs_EDGE);
1120 for(; exp.More(); exp.Next()) {
1121 TopExp_Explorer exp1;
1122 exp1.Init(exp.Current(), TopAbs_VERTEX);
1124 FacRevolInfini = Standard_True;
1129 BRepBndLib::Add(theSFrom,Box);
1131 if(!theSUntil.IsNull()) {
1133 Standard_Boolean FacRevolInfini = Standard_False;
1135 Standard_Boolean FacRevolInfini;
1137 TopExp_Explorer exp;
1138 exp.Init(theSUntil, TopAbs_EDGE);
1139 for(; exp.More(); exp.Next()) {
1140 TopExp_Explorer exp1;
1141 exp1.Init(exp.Current(), TopAbs_VERTEX);
1143 FacRevolInfini = Standard_True;
1148 BRepBndLib::Add(theSUntil,Box);
1153 Box.Get(c[0],c[2],c[4],c[1],c[3],c[5]);
1154 Standard_Real parmin=c[0], parmax = c[0];
1155 for(Standard_Integer i = 0 ; i < 6; i++) {
1156 if(c[i] > parmax) parmax = c[i];
1157 if(c[i] < parmin ) parmin = c[i];
1160 Standard_Real Height = fabs(2.*(parmax - parmin));
1162 // Standard_Real Height = abs(2.*(parmax - parmin));
1168 //=======================================================================
1169 //function : SensOfPrism
1170 //purpose : sens de prism en fonction du shape Until
1171 //=======================================================================
1172 Standard_Integer SensOfPrism(const Handle(Geom_Curve) C,
1173 const TopoDS_Shape& Until)
1175 LocOpe_CSIntersector ASI1(Until);
1176 TColGeom_SequenceOfCurve scur;
1179 Standard_Integer sens = 1;
1180 if(ASI1.IsDone() && ASI1.NbPoints(1) >= 1) {
1181 if(ASI1.Point(1, 1).Parameter() < 0. &&
1182 ASI1.Point(1, ASI1.NbPoints(1)).Parameter() < 0.) {
1186 else if(BRepFeat::ParametricBarycenter(Until,C) < 0) {
1194 //=======================================================================
1195 //function : SetGluedFaces
1196 //purpose : gestion de faces de collage
1197 //=======================================================================
1199 static void SetGluedFaces(const TopoDS_Face& theSkface,
1200 const TopoDS_Shape& theSbase,
1201 const TopoDS_Shape& thePbase,
1202 const TopTools_DataMapOfShapeListOfShape& theSlmap,
1203 LocOpe_Prism& thePrism,
1204 TopTools_DataMapOfShapeShape& theMap)
1206 TopExp_Explorer exp;
1207 if (!theSkface.IsNull() && thePbase.ShapeType() == TopAbs_FACE) {
1208 for (exp.Init(theSbase,TopAbs_FACE); exp.More(); exp.Next()) {
1209 if (exp.Current().IsSame(theSkface)) {
1210 theMap.Bind(thePbase,theSkface);
1216 for (exp.Init(theSbase,TopAbs_FACE); exp.More(); exp.Next()) {
1217 if (exp.Current().IsSame(theSkface)) {
1218 TopExp_Explorer exp2;
1219 for (exp2.Init(thePbase,TopAbs_FACE);exp2.More();exp2.Next()) {
1220 theMap.Bind(exp2.Current(),theSkface);
1228 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm(theSlmap);
1229 if(!theSlmap.IsEmpty()) {
1230 for (; itm.More(); itm.Next()) {
1231 const TopoDS_Face& fac = TopoDS::Face(itm.Key());
1232 const TopTools_ListOfShape& ledg = itm.Value();
1233 TopTools_ListIteratorOfListOfShape it;
1234 for (it.Initialize(ledg); it.More(); it.Next()) {
1235 const TopTools_ListOfShape& gfac = thePrism.Shapes(it.Value());
1236 if (gfac.Extent() != 1) {
1238 Standard_Boolean trc = BRepFeat_GettraceFEAT();
1239 if (trc) cout << " BRepFeat_MakePrism : Pb SetGluedFace" << endl;
1242 theMap.Bind(gfac.First(),fac);
1249 //=======================================================================
1250 //function : VerifGluedFaces
1251 //purpose : Verification intersection Outil/theSkface = thePbase
1252 // Si oui -> OK si non -> cas sans collage
1253 //=======================================================================
1255 static void VerifGluedFaces(const TopoDS_Face& theSkface,
1256 const TopoDS_Shape& thePbase,
1257 Handle(Geom_Curve)& theBCurve,
1258 TColGeom_SequenceOfCurve& theCurves,
1259 LocOpe_Prism& thePrism,
1260 TopTools_DataMapOfShapeShape& theMap)
1262 Standard_Boolean GluedFaces = Standard_True;
1263 TopoDS_Shape VraiPrism = thePrism.Shape();
1265 TColGeom_SequenceOfCurve scur;
1266 thePrism.Curves(theCurves);
1267 theBCurve = thePrism.BarycCurve();
1269 scur.Append(theBCurve);
1270 LocOpe_CSIntersector ASI(theSkface);
1272 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
1273 TopAbs_Orientation Or = ASI.Point(1,1).Orientation();
1274 TopoDS_Face FSk = ASI.Point(1,1).Face();
1277 B.MakeCompound(TopoDS::Compound(Comp));
1278 TopoDS_Solid S = BRepFeat::Tool(theSkface, FSk, Or);
1279 if (!S.IsNull()) B.Add(Comp,S);
1280 //modified by NIZNHY-PKV Thu Mar 21 18:07:35 2002 f
1281 //BRepAlgo_Cut trP(VraiPrism,Comp);
1282 BRepAlgoAPI_Cut trP(VraiPrism,Comp);
1283 //modified by NIZNHY-PKV Thu Mar 21 18:07:39 2002 t
1284 TopoDS_Shape Cutsh = trP.Shape();
1285 TopExp_Explorer ex(Cutsh, TopAbs_SOLID);
1286 for(; ex.More(); ex.Next()) {
1287 TopExp_Explorer ex1(ex.Current(), TopAbs_FACE);
1288 for(; ex1.More(); ex1.Next()) {
1289 const TopoDS_Face& fac1 = TopoDS::Face(ex1.Current());
1290 TopExp_Explorer ex2(thePbase, TopAbs_FACE);
1291 for(; ex2.More(); ex2.Next()) {
1292 const TopoDS_Face& fac2 = TopoDS::Face(ex2.Current());
1293 if(fac1.IsSame(fac2)) break;
1295 if (ex2.More()) break;
1297 if (ex1.More()) continue;
1298 GluedFaces = Standard_False;
1303 Standard_Boolean trc = BRepFeat_GettraceFEAT();
1304 if (trc) cout << " Intersection Prism/skface : pas de collage" << endl;
1312 //=======================================================================
1314 //purpose : gestion des descendants
1315 //=======================================================================
1317 static void MajMap(const TopoDS_Shape& theB,
1318 const LocOpe_Prism& theP,
1319 TopTools_DataMapOfShapeListOfShape& theMap, // myMap
1320 TopoDS_Shape& theFShape, // myFShape
1321 TopoDS_Shape& theLShape) // myLShape
1323 TopExp_Explorer exp(theP.FirstShape(),TopAbs_WIRE);
1325 theFShape = exp.Current();
1326 TopTools_ListOfShape thelist2;
1327 theMap.Bind(theFShape, thelist2);
1328 for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) {
1329 theMap(theFShape).Append(exp.Current());
1333 exp.Init(theP.LastShape(),TopAbs_WIRE);
1335 theLShape = exp.Current();
1336 TopTools_ListOfShape thelist3;
1337 theMap.Bind(theLShape, thelist3);
1338 for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) {
1339 theMap(theLShape).Append(exp.Current());
1343 for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) {
1344 if (!theMap.IsBound(exp.Current())) {
1345 TopTools_ListOfShape thelist4;
1346 theMap.Bind(exp.Current(), thelist4);
1347 theMap(exp.Current()) = theP.Shapes(exp.Current());
1353 //=======================================================================
1355 //purpose : gestion des descendants
1356 //=======================================================================
1358 static Handle(Geom_Curve) TestCurve(const TopoDS_Shape& Base,
1361 gp_Pnt bar(0., 0., 0.);
1362 TColgp_SequenceOfPnt spt;
1363 LocOpe::SampleEdges(Base,spt);
1364 for (Standard_Integer jj=1;jj<=spt.Length(); jj++) {
1365 const gp_Pnt& pvt = spt(jj);
1366 bar.ChangeCoord() += pvt.XYZ();
1368 bar.ChangeCoord().Divide(spt.Length());
1369 gp_Ax1 newAx(bar,V);
1370 Handle(Geom_Line) theLin = new Geom_Line(newAx);
1377 //=======================================================================
1379 //purpose : face SameDomaine ou pas
1380 //=======================================================================
1382 Standard_Boolean ToFuse(const TopoDS_Face& F1,
1383 const TopoDS_Face& F2)
1385 if (F1.IsNull() || F2.IsNull()) {
1386 return Standard_False;
1389 Handle(Geom_Surface) S1,S2;
1390 TopLoc_Location loc1, loc2;
1391 Handle(Standard_Type) typS1,typS2;
1392 const Standard_Real tollin = Precision::Confusion();
1393 const Standard_Real tolang = Precision::Angular();
1395 S1 = BRep_Tool::Surface(F1,loc1);
1396 S2 = BRep_Tool::Surface(F2,loc2);
1398 typS1 = S1->DynamicType();
1399 typS2 = S2->DynamicType();
1401 if (typS1 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1402 S1 = (*((Handle(Geom_RectangularTrimmedSurface)*)&S1))->BasisSurface();
1403 typS1 = S1->DynamicType();
1406 if (typS2 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1407 S2 = (*((Handle(Geom_RectangularTrimmedSurface)*)&S2))->BasisSurface();
1408 typS2 = S2->DynamicType();
1411 if (typS1 != typS2) {
1412 return Standard_False;
1416 Standard_Boolean ValRet = Standard_False;
1417 if (typS1 == STANDARD_TYPE(Geom_Plane)) {
1418 S1 = BRep_Tool::Surface(F1); // pour appliquer la location.
1419 S2 = BRep_Tool::Surface(F2);
1420 gp_Pln pl1( (*((Handle(Geom_Plane)*)&S1))->Pln());
1421 gp_Pln pl2( (*((Handle(Geom_Plane)*)&S2))->Pln());
1423 if (pl1.Position().IsCoplanar(pl2.Position(),tollin,tolang)) {
1424 ValRet = Standard_True;