1 // Created on: 1996-02-13
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Bnd_Box.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BRepAlgoAPI_Cut.hxx>
21 #include <BRepAlgoAPI_Fuse.hxx>
22 #include <BRepBndLib.hxx>
23 #include <BRepBuilderAPI.hxx>
24 #include <BRepFeat.hxx>
25 #include <BRepFeat_MakePrism.hxx>
26 #include <BRepLib_MakeFace.hxx>
27 #include <BRepPrimAPI_MakeBox.hxx>
28 #include <BRepTools.hxx>
29 #include <Geom_Curve.hxx>
30 #include <Geom_Line.hxx>
31 #include <Geom_Plane.hxx>
32 #include <Geom_RectangularTrimmedSurface.hxx>
33 #include <Geom_Surface.hxx>
38 #include <gp_Pnt2d.hxx>
41 #include <LocOpe_CSIntersector.hxx>
42 #include <LocOpe_PntFace.hxx>
43 #include <LocOpe_Prism.hxx>
44 #include <Precision.hxx>
45 #include <Standard_ConstructionError.hxx>
46 #include <TColGeom_SequenceOfCurve.hxx>
47 #include <TColgp_SequenceOfPnt.hxx>
49 #include <TopExp_Explorer.hxx>
51 #include <TopoDS_Compound.hxx>
52 #include <TopoDS_Edge.hxx>
53 #include <TopoDS_Face.hxx>
54 #include <TopoDS_Shape.hxx>
55 #include <TopoDS_Solid.hxx>
56 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
57 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
58 #include <TopTools_ListIteratorOfListOfShape.hxx>
59 #include <TopTools_ListOfShape.hxx>
60 #include <TopTools_MapOfShape.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 //modified by NIZNHY-PKV Thu Mar 21 18:14:26 2002 t
67 extern Standard_Boolean BRepFeat_GettraceFEAT();
70 static void MajMap(const TopoDS_Shape&, // base
72 TopTools_DataMapOfShapeListOfShape&, // myMap
73 TopoDS_Shape&, // myFShape
74 TopoDS_Shape&); // myLShape
76 static Standard_Boolean ToFuse(const TopoDS_Face& ,
79 static Standard_Real HeightMax(const TopoDS_Shape& theSbase,
80 const TopoDS_Face& theSkface,
81 const TopoDS_Shape& theSFrom,
82 const TopoDS_Shape& theSUntil);
84 static Standard_Integer SensOfPrism(const Handle(Geom_Curve) C,
85 const TopoDS_Shape& Until);
87 static Handle(Geom_Curve) TestCurve(const TopoDS_Shape&,
91 //=======================================================================
94 //=======================================================================
96 void BRepFeat_MakePrism::Init(const TopoDS_Shape& Sbase,
97 const TopoDS_Shape& Pbase,
98 const TopoDS_Face& Skface,
100 const Standard_Integer Mode,
101 const Standard_Boolean Modify)
104 Standard_Boolean trc = BRepFeat_GettraceFEAT();
105 if (trc) cout << "BRepFeat_MakePrism::Init" << endl;
115 myFuse = Standard_False;
116 myJustFeat = Standard_False;
119 myFuse = Standard_True;
120 myJustFeat = Standard_False;
123 myFuse = Standard_True;
124 myJustFeat = Standard_True;
129 myJustGluer = Standard_False;
133 //mySkface.Nullify();
144 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
145 TopTools_ListOfShape thelist;
146 myMap.Bind(exp.Current(), thelist);
147 myMap(exp.Current()).Append(exp.Current());
151 if (myJustFeat) cout << " Just Feature" << endl;
152 if (myFuse) cout << " Fuse" << endl;
153 if (!myFuse) cout << " Cut" << endl;
154 if (!myModify) cout << " Modify = 0" << endl;
160 //=======================================================================
162 //purpose : add elements of sliding (edge on face)
163 //=======================================================================
165 void BRepFeat_MakePrism::Add(const TopoDS_Edge& E,
166 const TopoDS_Face& F)
169 Standard_Boolean trc = BRepFeat_GettraceFEAT();
170 if (trc) cout << "BRepFeat_MakePrism::Add(Edge,face)" << endl;
173 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
174 if (exp.Current().IsSame(F)) {
179 Standard_ConstructionError::Raise();
182 for (exp.Init(myPbase,TopAbs_EDGE);exp.More();exp.Next()) {
183 if (exp.Current().IsSame(E)) {
188 Standard_ConstructionError::Raise();
191 if (!mySlface.IsBound(F)) {
192 TopTools_ListOfShape thelist1;
193 mySlface.Bind(F, thelist1);
195 TopTools_ListIteratorOfListOfShape itl(mySlface(F));
196 for (; itl.More();itl.Next()) {
197 if (itl.Value().IsSame(E)) {
202 mySlface(F).Append(E);
207 //=======================================================================
209 //purpose : construction of prism of length Length and
210 // call of reconstruction topo
211 //=======================================================================
213 void BRepFeat_MakePrism::Perform(const Standard_Real Length)
216 Standard_Boolean trc = BRepFeat_GettraceFEAT();
217 if (trc) cout << "BRepFeat_MakePrism::Perform(Length)" << endl;
224 myPerfSelection = BRepFeat_NoSelection;
225 PerfSelectionValid();
226 gp_Vec V(Length*myDir);
228 //construction of prism of height Length
230 LocOpe_Prism thePrism(myPbase,V);
231 TopoDS_Shape VraiPrism = thePrism.Shape();
233 // management of descendants
234 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
237 myGShape = VraiPrism; // the primitive
238 GeneratedShapeValid();
242 Standard_Boolean found = Standard_False;
244 // try to detect the faces of gluing
245 // in case if the top of the prism is tangent to the initial shape
247 if(!mySkface.IsNull() || !mySlface.IsEmpty()) {
248 if(myLShape.ShapeType() == TopAbs_WIRE) {
249 TopExp_Explorer ex1(VraiPrism, TopAbs_FACE);
250 for(; ex1.More(); ex1.Next()) {
251 TopExp_Explorer ex2(ex1.Current(), TopAbs_WIRE);
252 for(; ex2.More(); ex2.Next()) {
253 if(ex2.Current().IsSame(myLShape)) {
254 FFace = TopoDS::Face(ex1.Current());
255 found = Standard_True;
263 TopExp_Explorer exp(mySbase, TopAbs_FACE);
264 for(; exp.More(); exp.Next()) {
265 const TopoDS_Face& ff = TopoDS::Face(exp.Current());
266 if(ToFuse(ff, FFace)) {
267 TopTools_DataMapOfShapeListOfShape sl;
268 if(!FFace.IsSame(myPbase) && BRepFeat::IsInside(ff, FFace))
274 // management of faces of gluing given by the user
278 if(!myGluedF.IsEmpty()) { // case gluing
279 myJustGluer = Standard_True;
280 thePrism.Curves(myCurves);
281 myBCurve = thePrism.BarycCurve();
282 GlobalPerform(); // topological reconstruction
285 // if there is no gluing -> call of ope topo
287 if(myFuse == 1 && !myJustFeat) {
288 //modified by NIZNHY-PKV Thu Mar 21 17:55:30 2002 f
289 //BRepAlgo_Fuse f(mySbase, myGShape);
290 //myShape = f.Shape();
291 //UpdateDescendants(f.Builder(), myShape, Standard_False);
292 BRepAlgoAPI_Fuse f(mySbase, myGShape);
294 UpdateDescendants(f, myShape, Standard_False);
295 //modified by NIZNHY-PKV Thu Mar 21 17:55:34 2002 t
298 else if(myFuse == 0) {
299 //modified by NIZNHY-PKV Thu Mar 21 17:55:59 2002 f
300 //BRepAlgo_Cut c(mySbase, myGShape);
301 //myShape = c.Shape();
302 //UpdateDescendants(c.Builder(), myShape, Standard_False);
303 BRepAlgoAPI_Cut c(mySbase, myGShape);
305 UpdateDescendants(c, myShape, Standard_False);
306 //modified by NIZNHY-PKV Thu Mar 21 17:56:02 2002 t
317 //=======================================================================
319 //purpose : construction of prism oriented at the face Until, sufficiently
320 // long; call of topological reconstruction
321 //=======================================================================
323 void BRepFeat_MakePrism::Perform(const TopoDS_Shape& Until)
326 Standard_Boolean trc = BRepFeat_GettraceFEAT();
327 if (trc) cout << "BRepFeat_MakePrism::Perform(Until)" << endl;
329 if (Until.IsNull()) {
330 Standard_ConstructionError::Raise();
332 TopExp_Explorer exp(Until, TopAbs_FACE);
334 Standard_ConstructionError::Raise();
337 myPerfSelection = BRepFeat_SelectionU;
338 PerfSelectionValid();
342 Standard_Boolean Trf = TransformShapeFU(1);
344 Handle(Geom_Curve) C = TestCurve(myPbase,myDir);
345 Standard_Integer sens = SensOfPrism(C, mySUntil);
346 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
347 gp_Vec V(2*sens*Height*myDir);
349 // construction of long prism
350 LocOpe_Prism thePrism(myPbase,V);
351 TopoDS_Shape VraiPrism = thePrism.Shape();
353 // in case of support of face Until
355 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
356 myGShape = VraiPrism;
357 GeneratedShapeValid();
359 thePrism.Curves(myCurves);
360 myBCurve = thePrism.BarycCurve();
363 else { // until support -> passage to topological operations
364 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
365 TColGeom_SequenceOfCurve scur;
369 // direction of the prism depending on Until
371 LocOpe_CSIntersector ASI(mySUntil);
373 TopAbs_Orientation Or;
374 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
376 Or = ASI.Point(1,1).Orientation();
379 Or = ASI.Point(1,ASI.NbPoints(1)).Orientation();
381 if(sens==-1) Or=TopAbs::Reverse(Or);
382 TopoDS_Face FUntil = ASI.Point(1,1).Face();
385 B.MakeCompound(TopoDS::Compound(Comp));
386 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
387 if (!S.IsNull()) B.Add(Comp,S);
388 //modified by NIZNHY-PKV Thu Mar 21 17:56:31 2002 f
389 //BRepAlgo_Cut trP(VraiPrism,Comp);
390 //UpdateDescendants(trP.Builder(),trP.Shape(), Standard_False);
391 BRepAlgoAPI_Cut trP(VraiPrism,Comp);
392 UpdateDescendants(trP, trP.Shape(), Standard_False);
393 //modified by NIZNHY-PKV Thu Mar 21 17:56:38 2002 t
394 TopExp_Explorer ex(trP.Shape(), TopAbs_SOLID);
395 TopoDS_Shape Cutsh = ex.Current();
396 if(myFuse == 1 && !myJustFeat) {
397 //modified by NIZNHY-PKV Thu Mar 21 17:57:49 2002 f
398 //BRepAlgo_Fuse f(mySbase, Cutsh);
399 //myShape = f.Shape();
400 //UpdateDescendants(f.Builder(), myShape, Standard_False);
401 BRepAlgoAPI_Fuse f(mySbase, Cutsh);
403 UpdateDescendants(f, myShape, Standard_False);
404 //modified by NIZNHY-PKV Thu Mar 21 17:57:53 2002 t
407 else if(myFuse == 0) {
408 //modified by NIZNHY-PKV Thu Mar 21 17:59:33 2002 f
409 //BRepAlgo_Cut c(mySbase, Cutsh);
410 //myShape = c.Shape();
411 //UpdateDescendants(c.Builder(), myShape, Standard_False);
412 BRepAlgoAPI_Cut c(mySbase, Cutsh);
414 UpdateDescendants(c, myShape, Standard_False);
415 //modified by NIZNHY-PKV Thu Mar 21 17:59:43 2002 t
424 /* // loop of control of descendance
426 TopExp_Explorer expr(mySbase, TopAbs_FACE);
427 char nom1[20], nom2[20];
428 Standard_Integer ii = 0;
429 for(; expr.More(); expr.Next()) {
431 sprintf(nom1, "faceinitial_%d", ii);
432 DBRep::Set(nom1, expr.Current());
433 Standard_Integer jj = 0;
434 const TopTools_ListOfShape& list = Modified(expr.Current());
435 TopTools_ListIteratorOfListOfShape ite(list);
436 for(; ite.More(); ite.Next()) {
438 sprintf(nom2, "facemodifie_%d_%d", ii, jj);
439 DBRep::Set(nom2, ite.Value());
443 expr.Init(myPbase, TopAbs_EDGE);
445 for(; expr.More(); expr.Next()) {
447 sprintf(nom1, "edgeinitial_%d", ii);
448 DBRep::Set(nom1, expr.Current());
449 Standard_Integer jj = 0;
450 const TopTools_ListOfShape& list = Generated(expr.Current());
451 TopTools_ListIteratorOfListOfShape ite(list);
452 for(; ite.More(); ite.Next()) {
454 sprintf(nom2, "facegeneree_%d_%d", ii, jj);
455 DBRep::Set(nom2, ite.Value());
462 //=======================================================================
464 //purpose : construction of a sufficiently long and properly oriented prism
465 // call of topological reconstruction
466 //=======================================================================
468 void BRepFeat_MakePrism::Perform(const TopoDS_Shape& From,
469 const TopoDS_Shape& Until)
472 Standard_Boolean trc = BRepFeat_GettraceFEAT();
473 if (trc) cout << "BRepFeat_MakePrism::Perform(From,Until)" << endl;
475 if (From.IsNull() || Until.IsNull()) {
476 Standard_ConstructionError::Raise();
479 if (!mySkface.IsNull()) {
480 if (From.IsSame(mySkface)) {
481 myJustGluer = Standard_True;
483 if (myJustGluer) return;
485 else if (Until.IsSame(mySkface)) {
486 myJustGluer = Standard_True;
488 if (myJustGluer) return;
493 myPerfSelection = BRepFeat_SelectionFU;
494 PerfSelectionValid();
496 TopExp_Explorer exp(From, TopAbs_FACE);
498 Standard_ConstructionError::Raise();
500 exp.Init(Until, TopAbs_FACE);
502 Standard_ConstructionError::Raise();
505 Standard_Boolean Trff = TransformShapeFU(0);
508 Standard_Boolean Trfu = TransformShapeFU(1);
512 myStatusError = BRepFeat_IncTypes;
516 // length depending on bounding boxes
518 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
519 Handle(Geom_Curve) C = TestCurve(myPbase,myDir);
520 Standard_Integer sens; // direction of prism
521 Standard_Integer tran; // transfer of prism
522 if(From.IsSame(Until)) {
527 sens = SensOfPrism(C, mySUntil);
528 tran = sens*SensOfPrism(C, mySFrom);
530 LocOpe_Prism thePrism;
532 gp_Vec Vtra(-3*Height*sens/2.*myDir);
533 thePrism.Perform(myPbase,3*sens*Height*myDir,Vtra);
536 thePrism.Perform(myPbase,2*sens*Height*myDir);
538 TopoDS_Shape VraiPrism = thePrism.Shape();
541 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
543 myGShape = VraiPrism;
544 GeneratedShapeValid();
546 thePrism.Curves(myCurves);
547 myBCurve = thePrism.BarycCurve();
550 else { // case until support -> topological operation
551 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
552 TColGeom_SequenceOfCurve scur;
555 LocOpe_CSIntersector ASI1(mySUntil);
556 LocOpe_CSIntersector ASI2(mySFrom);
559 TopAbs_Orientation OrU, OrF;
560 TopoDS_Face FFrom, FUntil;
561 Standard_Real ParF, ParU;
562 if (ASI1.IsDone() && ASI1.NbPoints(1) >=1) {
564 OrU = ASI1.Point(1,1).Orientation();
567 OrU = ASI1.Point(1,ASI1.NbPoints(1)).Orientation();
569 if(sens==-1) OrU = TopAbs::Reverse(OrU);
570 FUntil = ASI1.Point(1,1).Face();
571 ParU = ASI1.Point(1,1).Parameter();
575 myStatusError = BRepFeat_NoIntersectU;
578 if (ASI2.IsDone() && ASI2.NbPoints(1) >=1) {
579 OrF = ASI2.Point(1,1).Orientation();
580 if(sens==1) OrF = TopAbs::Reverse(OrF);
581 FFrom = ASI2.Point(1,1).Face();
582 ParF = ASI2.Point(1,1).Parameter();
586 myStatusError = BRepFeat_NoIntersectF;
589 if(tran > 0 && (Abs(ParU) < Abs(ParF)))
591 TopAbs_Orientation Or;
598 B.MakeCompound(TopoDS::Compound(Comp));
599 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, OrU);
605 myStatusError = BRepFeat_NullToolU;
608 TopoDS_Solid SS = BRepFeat::Tool(mySFrom, FFrom, OrF);
614 myStatusError = BRepFeat_NullToolF;
617 //modified by NIZNHY-PKV Thu Mar 21 18:00:10 2002 f
618 //BRepAlgo_Cut trP(VraiPrism,Comp);
619 //UpdateDescendants(trP.Builder(), trP.Shape(), Standard_False);
620 BRepAlgoAPI_Cut trP(VraiPrism,Comp);
621 UpdateDescendants(trP, trP.Shape(), Standard_False);
622 //modified by NIZNHY-PKV Thu Mar 21 18:00:16 2002 t
623 if(myFuse == 1 && !myJustFeat) {
624 //modified by NIZNHY-PKV Thu Mar 21 18:00:35 2002 f
625 //BRepAlgo_Fuse f(mySbase, trP.Shape());
626 //myShape = f.Shape();
627 //UpdateDescendants(f.Builder(), myShape, Standard_False);
628 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
630 UpdateDescendants(f, myShape, Standard_False);
631 //modified by NIZNHY-PKV Thu Mar 21 18:00:40 2002 t
634 else if(myFuse == 0) {
635 //modified by NIZNHY-PKV Thu Mar 21 18:01:01 2002 f
636 //BRepAlgo_Cut c(mySbase, trP.Shape());
637 //myShape = c.Shape();
638 //UpdateDescendants(c.Builder(), myShape, Standard_False);
639 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
641 UpdateDescendants(c, myShape, Standard_False);
642 //modified by NIZNHY-PKV Thu Mar 21 18:01:13 2002 t
646 myShape = trP.Shape();
652 TopExp_Explorer expr(mySbase, TopAbs_FACE);
653 char nom1[20], nom2[20];
654 Standard_Integer ii = 0;
655 for(; expr.More(); expr.Next()) {
657 sprintf(nom1, "faceinitial_%d", ii);
658 DBRep::Set(nom1, expr.Current());
659 Standard_Integer jj = 0;
660 const TopTools_ListOfShape& list = Modified(expr.Current());
661 TopTools_ListIteratorOfListOfShape ite(list);
662 for(; ite.More(); ite.Next()) {
664 sprintf(nom2, "facemodifie_%d_%d", ii, jj);
665 DBRep::Set(nom2, ite.Value());
669 expr.Init(myPbase, TopAbs_EDGE);
671 for(; expr.More(); expr.Next()) {
673 sprintf(nom1, "edgeinitial_%d", ii);
674 DBRep::Set(nom1, expr.Current());
675 Standard_Integer jj = 0;
676 const TopTools_ListOfShape& list = Generated(expr.Current());
677 TopTools_ListIteratorOfListOfShape ite(list);
678 for(; ite.More(); ite.Next()) {
680 sprintf(nom2, "egdegeneree_%d_%d", ii, jj);
681 DBRep::Set(nom2, ite.Value());
689 //=======================================================================
690 //function : PerformUntilEnd
691 //purpose : construction of a prism and reconstruction
692 //=======================================================================
694 void BRepFeat_MakePrism::PerformUntilEnd()
697 Standard_Boolean trc = BRepFeat_GettraceFEAT();
698 if (trc) cout << "BRepFeat_MakePrism::PerformUntilEnd()" << endl;
700 myPerfSelection = BRepFeat_SelectionSh;
701 PerfSelectionValid();
707 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
708 gp_Vec V(2*Height*myDir);
710 LocOpe_Prism thePrism(myPbase,V);
711 TopoDS_Shape VraiPrism = thePrism.Shape();
713 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
715 myGShape = VraiPrism;
716 GeneratedShapeValid();
720 //modified by NIZNHY-PKV Thu Mar 21 18:02:46 2002 f
721 //BRepAlgo_Cut c(mySbase, myGShape);
722 BRepAlgoAPI_Cut c(mySbase, myGShape);
723 //modified by NIZNHY-PKV Thu Mar 21 18:03:15 2002 t
726 //modified by NIZNHY-PKV Thu Mar 21 18:03:38 2002 f
727 //UpdateDescendants(c.Builder(), myShape, Standard_False);
728 UpdateDescendants(c, myShape, Standard_False);
729 //modified by NIZNHY-PKV Thu Mar 21 18:03:42 2002 t
734 thePrism.Curves(myCurves);
735 myBCurve = thePrism.BarycCurve();
740 //=======================================================================
741 //function : PerformFromEnd
743 //=======================================================================
745 void BRepFeat_MakePrism::PerformFromEnd(const TopoDS_Shape& Until)
748 Standard_Boolean trc = BRepFeat_GettraceFEAT();
749 if (trc) cout << "BRepFeat_MakePrism::PerformFromEnd(From,Until)" << endl;
751 if (Until.IsNull()) {
752 Standard_ConstructionError::Raise();
754 if (!mySkface.IsNull() && Until.IsSame(mySkface)) {
760 exp.Init(Until, TopAbs_FACE);
762 Standard_ConstructionError::Raise();
764 myPerfSelection = BRepFeat_SelectionShU;
765 PerfSelectionValid();
769 Standard_Boolean Trf = TransformShapeFU(1);
771 Handle(Geom_Curve) C = TestCurve(myPbase,myDir);
772 Standard_Integer sens = SensOfPrism(C, mySUntil);
773 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
774 gp_Vec Vtra(-3*Height*sens/2.*myDir);
775 gp_Vec Vect(3*sens*Height*myDir);
776 LocOpe_Prism thePrism(myPbase,Vect,Vtra);
777 TopoDS_Shape VraiPrism = thePrism.Shape();
779 if(!Trf) { // case face until
780 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
781 myGShape = VraiPrism;
782 GeneratedShapeValid();
785 thePrism.Curves(myCurves);
786 myBCurve = thePrism.BarycCurve();
789 else { // case support
790 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
791 TColGeom_SequenceOfCurve scur;
794 LocOpe_CSIntersector ASI1(mySUntil);
795 LocOpe_CSIntersector ASI2(mySbase);
798 TopAbs_Orientation OrU = TopAbs_FORWARD, OrF = TopAbs_FORWARD;
799 TopoDS_Face FUntil, FFrom;
800 if (ASI1.IsDone() && ASI1.NbPoints(1) >=1) {
801 OrU = ASI1.Point(1,1).Orientation();
803 OrU = TopAbs::Reverse(OrU);
805 FUntil = ASI1.Point(1,1).Face();
807 if (ASI2.IsDone() && ASI2.NbPoints(1) >=1) {
808 OrF = ASI2.Point(1,1).Orientation();
809 // if(sens==1) OrF = TopAbs::Reverse(OrF);
810 FFrom = ASI2.Point(1 ,1).Face();
811 Handle(Geom_Surface) S = BRep_Tool::Surface(FFrom);
812 if (S->DynamicType() ==
813 STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
814 S = Handle(Geom_RectangularTrimmedSurface)::
815 DownCast(S)->BasisSurface();
817 BRepLib_MakeFace fac(S, Precision::Confusion());
818 mySFrom = fac.Face();
819 Trf = TransformShapeFU(0);
820 FFrom = TopoDS::Face(mySFrom);
828 B.MakeCompound(TopoDS::Compound(Comp));
829 TopoDS_Solid Sol = BRepFeat::Tool(mySUntil, FUntil, OrU);
835 myStatusError = BRepFeat_NullToolU;
839 TopoDS_Solid Sol1 = BRepFeat::Tool(mySFrom, FFrom, OrF);
840 if (!Sol1.IsNull()) {
845 myStatusError = BRepFeat_NullToolF;
848 //modified by NIZNHY-PKV Thu Mar 21 18:03:57 2002 f
849 //BRepAlgo_Cut trP(VraiPrism,Comp);
850 //UpdateDescendants(trP.Builder(), trP.Shape(), Standard_False);
851 BRepAlgoAPI_Cut trP(VraiPrism,Comp);
852 UpdateDescendants(trP, trP.Shape(), Standard_False);
853 //modified by NIZNHY-PKV Thu Mar 21 18:04:08 2002 t
854 if(myFuse == 1 && !myJustFeat) {
855 //modified by NIZNHY-PKV Thu Mar 21 18:04:33 2002 f
856 //BRepAlgo_Fuse f(mySbase, trP.Shape());
857 //myShape = f.Shape();
858 //UpdateDescendants(f.Builder(), myShape, Standard_False);
859 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
861 UpdateDescendants(f, myShape, Standard_False);
862 //modified by NIZNHY-PKV Thu Mar 21 18:04:41 2002 t
865 else if(myFuse == 0) {
866 //modified by NIZNHY-PKV Thu Mar 21 18:04:54 2002 f
867 //BRepAlgo_Cut c(mySbase, trP.Shape());
868 //myShape = c.Shape();
869 //UpdateDescendants(c.Builder(), myShape, Standard_False);
870 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
872 UpdateDescendants(c, myShape, Standard_False);
873 //modified by NIZNHY-PKV Thu Mar 21 18:05:00 2002 t
877 myShape = trP.Shape();
885 //=======================================================================
886 //function : PerformThruAll
888 //=======================================================================
890 void BRepFeat_MakePrism::PerformThruAll()
893 Standard_Boolean trc = BRepFeat_GettraceFEAT();
894 if (trc) cout << "BRepFeat_MakePrism::PerformThruAll()" << endl;
901 myPerfSelection = BRepFeat_NoSelection;
904 myPerfSelection = BRepFeat_SelectionSh;
906 PerfSelectionValid();
910 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
911 gp_Vec V(3*Height*myDir);
912 gp_Vec Vtra(-3*Height/2.*myDir);
913 LocOpe_Prism thePrism(myPbase,V,Vtra);
914 TopoDS_Shape VraiPrism = thePrism.Shape();
915 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
917 myGShape = VraiPrism;
918 GeneratedShapeValid();
921 //modified by NIZNHY-PKV Thu Mar 21 18:05:31 2002 f
922 //BRepAlgo_Cut c(mySbase, myGShape);
923 BRepAlgoAPI_Cut c(mySbase, myGShape);
924 //modified by NIZNHY-PKV Thu Mar 21 18:05:33 2002 t
927 //modified by NIZNHY-PKV Thu Mar 21 18:05:46 2002 f
928 //UpdateDescendants(c.Builder(), myShape, Standard_False);
929 UpdateDescendants(c, myShape, Standard_False);
930 //modified by NIZNHY-PKV Thu Mar 21 18:05:50 2002 t
935 thePrism.Curves(myCurves);
936 myBCurve = thePrism.BarycCurve();
942 //=======================================================================
943 //function : PerformUntilHauteur
945 //=======================================================================
947 void BRepFeat_MakePrism::PerformUntilHeight(const TopoDS_Shape& Until,
948 const Standard_Real Length)
951 Standard_Boolean trc = BRepFeat_GettraceFEAT();
952 if (trc) cout << "BRepFeat_MakePrism::PerformUntilHeight(Until,Length)" << endl;
954 if (Until.IsNull()) {
960 TopExp_Explorer exp(Until, TopAbs_FACE);
962 Standard_ConstructionError::Raise();
965 myPerfSelection = BRepFeat_NoSelection;
966 PerfSelectionValid();
970 Standard_Boolean Trf = TransformShapeFU(1);
972 Handle(Geom_Curve) C = TestCurve(myPbase,myDir);
973 Standard_Integer sens = SensOfPrism(C, mySUntil);
974 gp_Vec V(sens*Length*myDir);
975 LocOpe_Prism thePrism(myPbase,V);
976 TopoDS_Shape VraiPrism = thePrism.Shape();
979 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
981 myGShape = VraiPrism;
982 GeneratedShapeValid();
984 thePrism.Curves(myCurves);
985 myBCurve = thePrism.BarycCurve();
989 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
990 TColGeom_SequenceOfCurve scur;
993 LocOpe_CSIntersector ASI(mySUntil);
995 TopAbs_Orientation Or;
996 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
998 Or = ASI.Point(1,1).Orientation();
1001 Or = ASI.Point(1,ASI.NbPoints(1)).Orientation();
1003 if(sens==-1) Or=TopAbs::Reverse(Or);
1004 TopoDS_Face FUntil = ASI.Point(1,1).Face();
1007 B.MakeCompound(TopoDS::Compound(Comp));
1008 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
1009 if (!S.IsNull()) B.Add(Comp,S);
1011 //modified by NIZNHY-PKV Thu Mar 21 18:06:09 2002 f
1012 //BRepAlgo_Cut trP(VraiPrism,Comp);
1013 //UpdateDescendants(trP.Builder(), trP.Shape(), Standard_False);
1014 BRepAlgoAPI_Cut trP(VraiPrism,Comp);
1015 UpdateDescendants(trP, trP.Shape(), Standard_False);
1016 //modified by NIZNHY-PKV Thu Mar 21 18:06:15 2002 t
1017 if(myFuse == 1 && !myJustFeat) {
1018 //modified by NIZNHY-PKV Thu Mar 21 18:06:36 2002 f
1019 //BRepAlgo_Fuse f(mySbase, trP.Shape());
1020 //myShape = f.Shape();
1021 //UpdateDescendants(f.Builder(), myShape, Standard_False);
1022 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
1023 myShape = f.Shape();
1024 UpdateDescendants(f, myShape, Standard_False);
1025 //modified by NIZNHY-PKV Thu Mar 21 18:06:41 2002 t
1028 else if(myFuse == 0) {
1029 //modified by NIZNHY-PKV Thu Mar 21 18:07:06 2002 f
1030 //BRepAlgo_Cut c(mySbase, trP.Shape());
1031 //myShape = c.Shape();
1032 //UpdateDescendants(c.Builder(), myShape, Standard_False);
1033 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
1034 myShape = c.Shape();
1035 UpdateDescendants(c, myShape, Standard_False);
1036 //modified by NIZNHY-PKV Thu Mar 21 18:07:12 2002 t
1040 myShape = trP.Shape();
1047 //=======================================================================
1049 //purpose : sequence of curves parallel to the axis of prism
1050 //=======================================================================
1052 void BRepFeat_MakePrism::Curves(TColGeom_SequenceOfCurve& scur)
1057 //=======================================================================
1058 //function : BarycCurve
1059 //purpose : curve parallel to the axis of the prism passing through the center
1061 //=======================================================================
1063 Handle(Geom_Curve) BRepFeat_MakePrism::BarycCurve()
1069 //=======================================================================
1070 //function : HeightMax
1071 //purpose : Calculate the height of the prism following the parameters of
1073 //=======================================================================
1075 static Standard_Real HeightMax(const TopoDS_Shape& theSbase,
1076 const TopoDS_Face& theSkface,
1077 const TopoDS_Shape& theSFrom,
1078 const TopoDS_Shape& theSUntil)
1081 BRepBndLib::Add(theSbase,Box);
1082 BRepBndLib::Add(theSkface,Box);
1083 if(!theSFrom.IsNull()) {
1084 Standard_Boolean FacRevolInfini = Standard_False;
1085 TopExp_Explorer exp;
1086 exp.Init(theSFrom, TopAbs_EDGE);
1087 for(; exp.More(); exp.Next()) {
1088 TopExp_Explorer exp1;
1089 exp1.Init(exp.Current(), TopAbs_VERTEX);
1091 FacRevolInfini = Standard_True;
1096 BRepBndLib::Add(theSFrom,Box);
1098 if(!theSUntil.IsNull())
1100 Standard_Boolean FacRevolInfini = Standard_False;
1101 TopExp_Explorer exp;
1102 exp.Init(theSUntil, TopAbs_EDGE);
1103 for(; exp.More(); exp.Next())
1105 TopExp_Explorer exp1;
1106 exp1.Init(exp.Current(), TopAbs_VERTEX);
1109 FacRevolInfini = Standard_True;
1114 BRepBndLib::Add(theSUntil,Box);
1119 Box.Get(c[0],c[2],c[4],c[1],c[3],c[5]);
1120 Standard_Real parmin=c[0], parmax = c[0];
1121 for(Standard_Integer i = 0 ; i < 6; i++) {
1122 if(c[i] > parmax) parmax = c[i];
1123 if(c[i] < parmin ) parmin = c[i];
1125 //#ifndef OCCT_DEBUG
1126 Standard_Real Height = fabs(2.*(parmax - parmin));
1128 // Standard_Real Height = abs(2.*(parmax - parmin));
1134 //=======================================================================
1135 //function : SensOfPrism
1136 //purpose : Direction of the prism depending on the shape Until
1137 //=======================================================================
1138 Standard_Integer SensOfPrism(const Handle(Geom_Curve) C,
1139 const TopoDS_Shape& Until)
1141 LocOpe_CSIntersector ASI1(Until);
1142 TColGeom_SequenceOfCurve scur;
1145 Standard_Integer sens = 1;
1146 if(ASI1.IsDone() && ASI1.NbPoints(1) >= 1) {
1147 if(ASI1.Point(1, 1).Parameter() < 0. &&
1148 ASI1.Point(1, ASI1.NbPoints(1)).Parameter() < 0.) {
1152 else if(BRepFeat::ParametricBarycenter(Until,C) < 0) {
1159 //=======================================================================
1161 //purpose : management of descendants
1162 //=======================================================================
1164 static void MajMap(const TopoDS_Shape& theB,
1165 const LocOpe_Prism& theP,
1166 TopTools_DataMapOfShapeListOfShape& theMap, // myMap
1167 TopoDS_Shape& theFShape, // myFShape
1168 TopoDS_Shape& theLShape) // myLShape
1170 TopExp_Explorer exp(theP.FirstShape(),TopAbs_WIRE);
1172 theFShape = exp.Current();
1173 TopTools_ListOfShape thelist2;
1174 theMap.Bind(theFShape, thelist2);
1175 for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) {
1176 theMap(theFShape).Append(exp.Current());
1180 exp.Init(theP.LastShape(),TopAbs_WIRE);
1182 theLShape = exp.Current();
1183 TopTools_ListOfShape thelist3;
1184 theMap.Bind(theLShape, thelist3);
1185 for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) {
1186 theMap(theLShape).Append(exp.Current());
1190 for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) {
1191 if (!theMap.IsBound(exp.Current())) {
1192 TopTools_ListOfShape thelist4;
1193 theMap.Bind(exp.Current(), thelist4);
1194 theMap(exp.Current()) = theP.Shapes(exp.Current());
1200 //=======================================================================
1202 //purpose : management of descendants
1203 //=======================================================================
1205 static Handle(Geom_Curve) TestCurve(const TopoDS_Shape& Base,
1208 gp_Pnt bar(0., 0., 0.);
1209 TColgp_SequenceOfPnt spt;
1210 LocOpe::SampleEdges(Base,spt);
1211 for (Standard_Integer jj=1;jj<=spt.Length(); jj++) {
1212 const gp_Pnt& pvt = spt(jj);
1213 bar.ChangeCoord() += pvt.XYZ();
1215 bar.ChangeCoord().Divide(spt.Length());
1216 gp_Ax1 newAx(bar,V);
1217 Handle(Geom_Line) theLin = new Geom_Line(newAx);
1224 //=======================================================================
1226 //purpose : face SameDomaine or not
1227 //=======================================================================
1229 static Standard_Boolean ToFuse (const TopoDS_Face& F1, const TopoDS_Face& F2)
1231 if (F1.IsNull() || F2.IsNull()) {
1232 return Standard_False;
1235 Handle(Geom_Surface) S1,S2;
1236 TopLoc_Location loc1, loc2;
1237 Handle(Standard_Type) typS1,typS2;
1238 const Standard_Real tollin = Precision::Confusion();
1239 const Standard_Real tolang = Precision::Angular();
1241 S1 = BRep_Tool::Surface(F1,loc1);
1242 S2 = BRep_Tool::Surface(F2,loc2);
1244 typS1 = S1->DynamicType();
1245 typS2 = S2->DynamicType();
1247 if (typS1 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1248 S1 = Handle(Geom_RectangularTrimmedSurface)::DownCast (S1)->BasisSurface();
1249 typS1 = S1->DynamicType();
1252 if (typS2 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1253 S2 = Handle(Geom_RectangularTrimmedSurface)::DownCast (S2)->BasisSurface();
1254 typS2 = S2->DynamicType();
1257 if (typS1 != typS2) {
1258 return Standard_False;
1262 Standard_Boolean ValRet = Standard_False;
1263 if (typS1 == STANDARD_TYPE(Geom_Plane)) {
1264 gp_Pln pl1( Handle(Geom_Plane)::DownCast (S1)->Pln());
1265 gp_Pln pl2( Handle(Geom_Plane)::DownCast (S2)->Pln());
1268 if (! loc1.IsIdentity())
1269 pl1.Transform (loc1.Transformation());
1270 if (! loc2.IsIdentity())
1271 pl2.Transform (loc2.Transformation());
1273 if (pl1.Position().IsCoplanar(pl2.Position(),tollin,tolang)) {
1274 ValRet = Standard_True;