1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File: GEOMAlgo_Gluer.cxx
23 // Created: Sat Dec 04 12:45:53 2004
24 // Author: Peter KURNEV
27 #include <GEOMAlgo_Gluer.ixx>
29 #include <NMTDS_BoxBndTree.hxx>
30 #include <NCollection_UBTreeFiller.hxx>
32 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
33 #include <TColStd_MapOfInteger.hxx>
34 #include <TColStd_ListOfInteger.hxx>
35 #include <TColStd_ListIteratorOfListOfInteger.hxx>
41 #include <Geom_Curve.hxx>
42 #include <Geom_Surface.hxx>
44 #include <Bnd_Box.hxx>
45 #include <Bnd_HArray1OfBox.hxx>
46 #include <Bnd_BoundSortBox.hxx>
48 #include <TopLoc_Location.hxx>
49 #include <TopAbs_ShapeEnum.hxx>
50 #include <TopAbs_Orientation.hxx>
53 #include <TopoDS_Edge.hxx>
54 #include <TopoDS_Vertex.hxx>
55 #include <TopoDS_Shape.hxx>
56 #include <TopoDS_Compound.hxx>
57 #include <TopoDS_Wire.hxx>
58 #include <TopoDS_Shell.hxx>
59 #include <TopoDS_Solid.hxx>
60 #include <TopoDS_Iterator.hxx>
62 #include <TopTools_IndexedMapOfShape.hxx>
63 #include <TopTools_ListOfShape.hxx>
64 #include <TopTools_ListIteratorOfListOfShape.hxx>
65 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
66 #include <TopTools_MapOfShape.hxx>
67 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
70 #include <TopExp_Explorer.hxx>
72 #include <BRep_Tool.hxx>
73 #include <BRep_Builder.hxx>
74 #include <BRepLib.hxx>
75 #include <BRepTools.hxx>
76 #include <BRepBndLib.hxx>
78 #include <IntTools_Context.hxx>
79 #include <BOPTools_Tools.hxx>
80 #include <BOPTools_Tools3D.hxx>
81 #include <BOPTools_Tools2D.hxx>
82 #include <BOP_CorrectTolerances.hxx>
84 #include <GEOMAlgo_IndexedDataMapOfIntegerShape.hxx>
85 #include <GEOMAlgo_IndexedDataMapOfShapeBox.hxx>
86 #include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx>
87 #include <GEOMAlgo_PassKeyShape.hxx>
88 #include <GEOMAlgo_Tools.hxx>
92 void GetSubShapes(const TopoDS_Shape& aS,
93 TopTools_IndexedMapOfShape& aMSS);
95 //=======================================================================
96 //function : GEOMAlgo_Gluer
98 //=======================================================================
99 GEOMAlgo_Gluer::GEOMAlgo_Gluer()
105 myCheckGeometry=Standard_True;
106 myKeepNonSolids=Standard_False;
109 //=======================================================================
110 //function : ~GEOMAlgo_Gluer
112 //=======================================================================
113 GEOMAlgo_Gluer::~GEOMAlgo_Gluer()
116 //=======================================================================
117 //function : SetCheckGeometry
119 //=======================================================================
120 void GEOMAlgo_Gluer::SetCheckGeometry(const Standard_Boolean aFlag)
122 myCheckGeometry=aFlag;
124 //=======================================================================
125 //function : CheckGeometry
127 //=======================================================================
128 Standard_Boolean GEOMAlgo_Gluer::CheckGeometry() const
130 return myCheckGeometry;
132 //=======================================================================
133 //function : SetKeepNonSolids
135 //=======================================================================
136 void GEOMAlgo_Gluer::SetKeepNonSolids(const Standard_Boolean aFlag)
138 myKeepNonSolids=aFlag;
140 //=======================================================================
141 //function : AloneShapes
143 //=======================================================================
144 Standard_Integer GEOMAlgo_Gluer::AloneShapes()const
148 //=======================================================================
151 //=======================================================================
152 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer::Images()const
156 //=======================================================================
159 //=======================================================================
160 const TopTools_DataMapOfShapeShape& GEOMAlgo_Gluer::Origins()const
164 //=======================================================================
167 //=======================================================================
168 void GEOMAlgo_Gluer::Perform()
174 const Standard_Integer aNb=8;
175 void (GEOMAlgo_Gluer::* pF[aNb])()={
176 &GEOMAlgo_Gluer::CheckData, &GEOMAlgo_Gluer::InnerTolerance,
177 &GEOMAlgo_Gluer::MakeVertices, &GEOMAlgo_Gluer::MakeEdges,
178 &GEOMAlgo_Gluer::MakeFaces, &GEOMAlgo_Gluer::MakeShells,
179 &GEOMAlgo_Gluer::MakeSolids, &GEOMAlgo_Gluer::CheckResult
182 for (i=0; i<aNb; ++i) {
189 //=======================================================================
190 //function : MakeVertices
192 //=======================================================================
193 void GEOMAlgo_Gluer::MakeVertices()
197 Standard_Integer j, i, aNbV, aNbVSD;
198 TColStd_ListIteratorOfListOfInteger aIt;
201 TopTools_IndexedMapOfShape aMV, aMVProcessed;
202 TopTools_ListIteratorOfListOfShape aItS;
203 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
204 TopTools_DataMapOfShapeListOfShape aMVV;
205 GEOMAlgo_IndexedDataMapOfIntegerShape aMIS;
206 GEOMAlgo_IndexedDataMapOfShapeBox aMSB;
208 NMTDS_BoxBndTreeSelector aSelector;
209 NMTDS_BoxBndTree aBBTree;
210 NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
213 TopExp::MapShapes(myShape, TopAbs_VERTEX, aMV);
216 myErrorStatus=2; // no vertices in source shape
220 for (i=1; i<=aNbV; ++i) {
221 const TopoDS_Shape& aV=aMV(i);
225 BRepBndLib::Add(aV, aBox);
227 aTreeFiller.Add(i, aBox);
235 //------------------------------
237 for (i=1; i<=aNbV; ++i) {
238 const TopoDS_Shape& aV=aMV(i);
240 if (aMVProcessed.Contains(aV)) {
244 Standard_Integer aNbIP, aIP, aNbIP1, aIP1;
245 TopTools_ListOfShape aLVSD;
246 TColStd_MapOfInteger aMIP, aMIP1, aMIPC;
247 TColStd_MapIteratorOfMapOfInteger aIt1;
252 aIt1.Initialize(aMIP);
253 for(; aIt1.More(); aIt1.Next()) {
255 if (aMIPC.Contains(aIP)) {
259 const TopoDS_Shape& aVP=aMIS.FindFromKey(aIP);
260 const Bnd_Box& aBoxVP=aMSB.FindFromKey(aVP);
263 aSelector.SetBox(aBoxVP);
265 aNbVSD=aBBTree.Select(aSelector);
267 continue; // it must not be
270 const TColStd_ListOfInteger& aLI=aSelector.Indices();
272 for (; aIt.More(); aIt.Next()) {
274 if (aMIP.Contains(aIP1)) {
278 } //for (; aIt.More(); aIt.Next()) {
279 }//for(; aIt1.More(); aIt1.Next()) {
281 aNbIP1=aMIP1.Extent();
286 aIt1.Initialize(aMIP);
287 for(; aIt1.More(); aIt1.Next()) {
293 aIt1.Initialize(aMIP1);
294 for(; aIt1.More(); aIt1.Next()) {
302 aNbIP=aMIPC.Extent();
304 if (!aNbIP) {// no SD vertices founded
307 aMVProcessed.Add(aV);
309 else { // SD vertices founded [ aMIPC ]
310 aIt1.Initialize(aMIPC);
311 for(j=0; aIt1.More(); aIt1.Next(), ++j) {
313 const TopoDS_Shape& aVP=aMIS.FindFromKey(aIP);
318 aMVProcessed.Add(aVP);
321 myImages.Bind(aVF, aLVSD);
322 }// for (i=1; i<=aNbV; ++i) {
323 //------------------------------
327 aItIm.Initialize(myImages);
328 for (; aItIm.More(); aItIm.Next()) {
329 const TopoDS_Shape& aV=aItIm.Key();
330 const TopTools_ListOfShape& aLVSD=aItIm.Value();
331 aNbVSD=aLVSD.Extent();
334 MakeVertex(aLVSD, aVnew);
335 aMVV.Bind(aVnew, aLVSD);
339 // UnBind old vertices
341 for (i=1; i<=aNbV; ++i) {
342 const TopoDS_Shape& aV=aMV(i);
347 aItIm.Initialize(aMVV);
348 for (; aItIm.More(); aItIm.Next()) {
349 const TopoDS_Shape& aV=aItIm.Key();
350 const TopTools_ListOfShape& aLVSD=aItIm.Value();
351 myImages.Bind(aV, aLVSD);
355 aItIm.Initialize(myImages);
356 for (; aItIm.More(); aItIm.Next()) {
357 const TopoDS_Shape& aV=aItIm.Key();
358 const TopTools_ListOfShape& aLVSD=aItIm.Value();
359 aItS.Initialize(aLVSD);
360 for (; aItS.More(); aItS.Next()) {
361 const TopoDS_Shape& aVSD=aItS.Value();
362 if (!myOrigins.IsBound(aVSD)) {
363 myOrigins.Bind(aVSD, aV);
368 //=======================================================================
369 //function : MakeSubShapes
371 //=======================================================================
372 void GEOMAlgo_Gluer::MakeSubShapes (const TopoDS_Shape& theShape,
373 TopTools_MapOfShape& theMS,
374 TopoDS_Compound& theResult)
376 if (theMS.Contains(theShape))
383 if (theShape.ShapeType() == TopAbs_COMPOUND ||
384 theShape.ShapeType() == TopAbs_COMPSOLID)
386 TopoDS_Iterator It (theShape, Standard_True, Standard_True);
387 for (; It.More(); It.Next())
389 MakeSubShapes(It.Value(), theMS, theResult);
392 else if (theShape.ShapeType() == TopAbs_SOLID)
395 TopoDS_Solid aNewSolid;
396 TopExp_Explorer aExpS, aExp;
398 const TopoDS_Solid& aSolid = TopoDS::Solid(theShape);
400 TopAbs_Orientation anOr = aSolid.Orientation();
402 aBB.MakeSolid(aNewSolid);
403 aNewSolid.Orientation(anOr);
405 aExp.Init(aSolid, TopAbs_SHELL);
406 for (; aExp.More(); aExp.Next())
408 const TopoDS_Shape& aShell=aExp.Current();
409 const TopoDS_Shape& aShellR=myOrigins.Find(aShell);
410 aBB.Add(aNewSolid, aShellR);
413 TopTools_ListOfShape aLS;
416 myImages.Bind(aNewSolid, aLS);
417 myOrigins.Bind(aSolid, aNewSolid);
419 aBB.Add(theResult, aNewSolid);
421 else if (theShape.ShapeType() == TopAbs_WIRE)
426 if (!myOrigins.IsBound(theShape))
429 const TopoDS_Wire& aW=TopoDS::Wire(theShape);
432 aBB.MakeWire(newWire);
434 TopExp_Explorer aExpE (aW, TopAbs_EDGE);
435 for (; aExpE.More(); aExpE.Next()) {
436 const TopoDS_Edge& aE=TopoDS::Edge(aExpE.Current());
437 TopoDS_Edge aER=TopoDS::Edge(myOrigins.Find(aE));
439 aER.Orientation(TopAbs_FORWARD);
440 if (!BRep_Tool::Degenerated(aER)) {
442 //if (bIsUPeriodic) {
443 // GEOMAlgo_Tools::RefinePCurveForEdgeOnFace(aER, aFFWD, aUMin, aUMax);
445 //BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aER, aFFWD);
448 Standard_Boolean bIsToReverse=BOPTools_Tools3D::IsSplitToReverse1(aER, aE, myContext);
454 aER.Orientation(aE.Orientation());
457 aBB.Add(newWire, aER);
460 TopTools_ListOfShape aLW;
463 myImages.Bind(newWire, aLW);
464 myOrigins.Bind(aW, newWire);
466 const TopoDS_Shape& aShapeR = myOrigins.Find(theShape);
467 aBB.Add(theResult, aShapeR);
475 const TopoDS_Shape& aShapeR = myOrigins.Find(theShape);
476 aBB.Add(theResult, aShapeR);
480 //=======================================================================
481 //function : MakeSolids
483 //=======================================================================
484 void GEOMAlgo_Gluer::MakeSolids()
489 TopoDS_Compound aCmp;
490 TopTools_MapOfShape aMS;
492 aBB.MakeCompound(aCmp);
494 // Add images of all initial sub-shapes in the result.
495 // If myKeepNonSolids==false, add only solids images.
496 MakeSubShapes(myShape, aMS, aCmp);
501 BOP_CorrectTolerances::CorrectCurveOnSurface(myResult);
504 //=======================================================================
505 //function : MakeShells
507 //=======================================================================
508 void GEOMAlgo_Gluer::MakeShells()
512 Standard_Boolean bIsToReverse;
513 Standard_Integer i, aNbS;
514 TopAbs_Orientation anOr;
515 TopoDS_Shell aNewShell;
517 TopTools_IndexedMapOfShape aMS;
518 TopExp_Explorer aExp;
521 TopExp::MapShapes(myShape, TopAbs_SHELL, aMS);
524 for (i=1; i<=aNbS; ++i) {
525 const TopoDS_Shell& aShell=TopoDS::Shell(aMS(i));
526 anOr=aShell.Orientation();
528 aBB.MakeShell(aNewShell);
529 aNewShell.Orientation(anOr);
530 aExp.Init(aShell, TopAbs_FACE);
531 for (; aExp.More(); aExp.Next()) {
532 const TopoDS_Face& aF=TopoDS::Face(aExp.Current());
533 aFR=TopoDS::Face(myOrigins.Find(aF));
534 if (aFR.IsSame(aF)) {
535 aBB.Add(aNewShell, aF);
538 bIsToReverse=IsToReverse(aFR, aF);
542 aBB.Add(aNewShell, aFR);
545 TopTools_ListOfShape aLS;
548 myImages.Bind(aNewShell, aLS);
549 myOrigins.Bind(aShell, aNewShell);
552 //=======================================================================
553 //function : MakeFaces
555 //=======================================================================
556 void GEOMAlgo_Gluer::MakeFaces()
558 MakeShapes(TopAbs_FACE);
560 //=======================================================================
561 //function : MakeEdges
563 //=======================================================================
564 void GEOMAlgo_Gluer::MakeEdges()
566 MakeShapes(TopAbs_EDGE);
568 //=======================================================================
569 //function : MakeShapes
571 //=======================================================================
572 void GEOMAlgo_Gluer::MakeShapes(const TopAbs_ShapeEnum aType)
576 Standard_Boolean bHasNewSubShape;
577 Standard_Integer i, aNbF, aNbSDF, iErr;
578 TopoDS_Shape aNewShape;
579 TopTools_IndexedMapOfShape aMF;
580 TopTools_ListIteratorOfListOfShape aItS;
581 GEOMAlgo_PassKeyShape aPKF;
582 GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLF;
584 TopExp::MapShapes(myShape, aType, aMF);
587 for (i=1; i<=aNbF; ++i) {
588 const TopoDS_Shape& aS=aMF(i);
590 if (aType==TopAbs_FACE) {
591 const TopoDS_Face& aF=TopoDS::Face(aS);
592 FacePassKey(aF, aPKF);
594 else if (aType==TopAbs_EDGE) {
595 const TopoDS_Edge& aE=TopoDS::Edge(aS);
596 EdgePassKey(aE, aPKF);
603 if (aMPKLF.Contains(aPKF)) {
604 TopTools_ListOfShape& aLSDF=aMPKLF.ChangeFromKey(aPKF);
608 TopTools_ListOfShape aLSDF;
611 aMPKLF.Add(aPKF, aLSDF);
614 // check geometric coincidence
615 if (myCheckGeometry) {
616 iErr=GEOMAlgo_Tools::RefineSDShapes(aMPKLF, myTol, myContext);
625 aNbF=aMPKLF.Extent();
626 for (i=1; i<=aNbF; ++i) {
627 const TopTools_ListOfShape& aLSDF=aMPKLF(i);
628 aNbSDF=aLSDF.Extent();
630 myErrorStatus=4; // it must not be
633 const TopoDS_Shape& aS1=aLSDF.First();
635 bHasNewSubShape=Standard_True;
636 // prevent creation of a new shape if there are not
637 // new subshapes of aSS among the originals
639 bHasNewSubShape=HasNewSubShape(aS1);
640 if (!bHasNewSubShape) {
642 aNewShape.Orientation(TopAbs_FORWARD);
646 if (bHasNewSubShape) {
647 if (aType==TopAbs_FACE) {
648 TopoDS_Face aNewFace;
650 const TopoDS_Face& aF1=TopoDS::Face(aS1);
651 MakeFace(aF1, aNewFace);
654 else if (aType==TopAbs_EDGE) {
655 TopoDS_Edge aNewEdge;
657 const TopoDS_Edge& aE1=TopoDS::Edge(aS1);
658 MakeEdge(aE1, aNewEdge);
663 myImages.Bind(aNewShape, aLSDF);
665 aItS.Initialize(aLSDF);
666 for (; aItS.More(); aItS.Next()) {
667 const TopoDS_Shape& aFSD=aItS.Value();
668 if (!myOrigins.IsBound(aFSD)) {
669 myOrigins.Bind(aFSD, aNewShape);
674 //=======================================================================
675 //function : CheckResult
677 //=======================================================================
678 void GEOMAlgo_Gluer::CheckResult()
682 if (myResult.IsNull()) {
687 Standard_Boolean bFound;
688 Standard_Integer i, j, aNbS, aNbFS, aNbSx;
689 TopTools_IndexedMapOfShape aMS, aMFS;
690 TopTools_IndexedDataMapOfShapeListOfShape aMFR;
692 TopExp::MapShapesAndAncestors(myResult, TopAbs_FACE, TopAbs_SOLID, aMFR);
693 TopExp::MapShapes(myResult, TopAbs_SOLID, aMS);
698 for (i=1; i<=aNbS; ++i) {
699 const TopoDS_Shape& aSolid=aMS(i);
702 TopExp::MapShapes(aSolid, TopAbs_FACE, aMFS);
704 bFound=Standard_False;
706 for (j=1; j<=aNbFS; ++j) {
707 const TopoDS_Shape& aFS=aMFS(j);
708 if (aMFR.Contains(aFS)) {
709 const TopTools_ListOfShape& aLSx=aMFR.FindFromKey(aFS);
725 //=======================================================================
726 //function : CheckData
728 //=======================================================================
729 void GEOMAlgo_Gluer::CheckData()
733 if (myShape.IsNull()) {
738 //=======================================================================
739 //function : InnerTolerance
741 //=======================================================================
742 void GEOMAlgo_Gluer::InnerTolerance()
748 Standard_Real aX[3][2], dH, dHmin, aCoef, aTolTresh;
751 BRepBndLib::Add(myShape, aBox);
752 aBox.Get(aX[0][0], aX[1][0], aX[2][0], aX[0][1], aX[1][1], aX[2][1]);
754 dHmin=aX[0][1]-aX[0][0];
755 for (i=1; i<3; ++i) {
756 dH=aX[i][1]-aX[i][0];
764 aTolTresh=aCoef*dHmin;
765 if (myTol>aTolTresh) {
771 //=======================================================================
772 //function : FacePassKey
774 //=======================================================================
775 void GEOMAlgo_Gluer::FacePassKey(const TopoDS_Face& aF,
776 GEOMAlgo_PassKeyShape& aPK)
778 Standard_Integer i, aNbE;
779 TopTools_ListOfShape aLE;
780 TopTools_IndexedMapOfShape aME;
782 TopExp::MapShapes(aF, TopAbs_EDGE, aME);
785 for (i=1; i<=aNbE; ++i) {
786 const TopoDS_Shape& aE=aME(i);
787 if (!myOrigins.IsBound(aE)) {
791 const TopoDS_Shape& aER=myOrigins.Find(aE);
796 //=======================================================================
797 //function : EdgePassKey
799 //=======================================================================
800 void GEOMAlgo_Gluer::EdgePassKey(const TopoDS_Edge& aE,
801 GEOMAlgo_PassKeyShape& aPK)
803 TopoDS_Vertex aV1, aV2;
805 TopExp::Vertices(aE, aV1, aV2);
807 if (!myOrigins.IsBound(aV1) || !myOrigins.IsBound(aV2) ) {
811 const TopoDS_Shape& aVR1=myOrigins.Find(aV1);
812 const TopoDS_Shape& aVR2=myOrigins.Find(aV2);
813 aPK.SetShapes(aVR1, aVR2);
815 //=======================================================================
816 //function : MakeVertex
818 //=======================================================================
819 void GEOMAlgo_Gluer::MakeVertex(const TopTools_ListOfShape& aLV,
820 TopoDS_Vertex& aNewVertex)
822 Standard_Integer aNbV;
823 Standard_Real aTolV, aD, aDmax;
828 TopTools_ListIteratorOfListOfShape aIt;
836 aGC.SetCoord(0.,0.,0.);
838 for (; aIt.More(); aIt.Next()) {
839 aVx=TopoDS::Vertex(aIt.Value());
840 aP3D=BRep_Tool::Pnt(aVx);
843 aGC/=(Standard_Real)aNbV;
849 for (; aIt.More(); aIt.Next()) {
850 aVx=TopoDS::Vertex(aIt.Value());
851 aP3D=BRep_Tool::Pnt(aVx);
852 aTolV=BRep_Tool::Tolerance(aVx);
853 aD=aPGC.Distance(aP3D)+aTolV;
859 aBB.MakeVertex (aNewVertex, aPGC, aDmax);
861 //=======================================================================
862 //function : MakeEdge
864 //=======================================================================
865 void GEOMAlgo_Gluer::MakeEdge(const TopoDS_Edge& aE,
866 TopoDS_Edge& aNewEdge)
870 Standard_Boolean bIsDE;
871 Standard_Real aT1, aT2;
872 TopoDS_Vertex aV1, aV2, aVR1, aVR2;
875 bIsDE=BRep_Tool::Degenerated(aE);
878 aEx.Orientation(TopAbs_FORWARD);
880 TopExp::Vertices(aEx, aV1, aV2);
882 aT1=BRep_Tool::Parameter(aV1, aEx);
883 aT2=BRep_Tool::Parameter(aV2, aEx);
885 aVR1=TopoDS::Vertex(myOrigins.Find(aV1));
886 aVR1.Orientation(TopAbs_FORWARD);
887 aVR2=TopoDS::Vertex(myOrigins.Find(aV2));
888 aVR2.Orientation(TopAbs_REVERSED);
894 TopAbs_Orientation anOrE;
896 anOrE=aE.Orientation();
897 aTol=BRep_Tool::Tolerance(aE);
904 aBB.Range(E, aT1, aT2);
905 aBB.Degenerated(E, Standard_True);
906 aBB.UpdateEdge(E, aTol);
912 BOPTools_Tools::MakeSplitEdge(aEx, aVR1, aT1, aVR2, aT2, aNewEdge);
915 //=======================================================================
916 //function : MakeFace
918 //=======================================================================
919 void GEOMAlgo_Gluer::MakeFace(const TopoDS_Face& aF,
920 TopoDS_Face& aNewFace)
924 Standard_Boolean bIsToReverse, bIsUPeriodic;
925 Standard_Real aTol, aUMin, aUMax, aVMin, aVMax;
928 TopoDS_Face aFFWD, newFace;
929 TopLoc_Location aLoc;
930 Handle(Geom_Surface) aS;
931 Handle(Geom2d_Curve) aC2D;
932 TopExp_Explorer aExpW, aExpE;
936 aFFWD.Orientation(TopAbs_FORWARD);
938 aS=BRep_Tool::Surface(aFFWD, aLoc);
939 bIsUPeriodic=GEOMAlgo_Tools::IsUPeriodic(aS);
940 aTol=BRep_Tool::Tolerance(aFFWD);
941 BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
943 aBB.MakeFace (newFace, aS, aLoc, aTol);
945 aExpW.Init(aFFWD, TopAbs_WIRE);
946 for (; aExpW.More(); aExpW.Next()) {
947 aBB.MakeWire(newWire);
948 const TopoDS_Wire& aW=TopoDS::Wire(aExpW.Current());
949 aExpE.Init(aW, TopAbs_EDGE);
950 for (; aExpE.More(); aExpE.Next()) {
951 const TopoDS_Edge& aE=TopoDS::Edge(aExpE.Current());
952 aER=TopoDS::Edge(myOrigins.Find(aE));
954 aER.Orientation(TopAbs_FORWARD);
955 if (!BRep_Tool::Degenerated(aER)) {
958 GEOMAlgo_Tools::RefinePCurveForEdgeOnFace(aER, aFFWD, aUMin, aUMax);
960 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aER, aFFWD);
963 bIsToReverse=BOPTools_Tools3D::IsSplitToReverse1(aER, aE, myContext);
969 aER.Orientation(aE.Orientation());
972 aBB.Add(newWire, aER);
975 TopTools_ListOfShape aLW;
978 myImages.Bind(newWire, aLW);
979 myOrigins.Bind(aW, newWire);
981 aBB.Add(newFace, newWire);
985 //=======================================================================
986 //function : IsToReverse
988 //=======================================================================
989 Standard_Boolean GEOMAlgo_Gluer::IsToReverse(const TopoDS_Face& aFR,
990 const TopoDS_Face& aF)
992 Standard_Boolean bRet;
993 Standard_Real aT, aT1, aT2, aTR, aScPr;
994 TopExp_Explorer aExp;
995 Handle(Geom_Curve)aC3D;
1001 aExp.Init(aF, TopAbs_EDGE);
1002 for (; aExp.More(); aExp.Next()) {
1003 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
1005 if (BRep_Tool::Degenerated(aE)) {
1009 const TopoDS_Edge& aER=TopoDS::Edge(myOrigins.Find(aE));
1011 aC3D=BRep_Tool::Curve(aE, aT1, aT2);
1012 aT=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
1014 myContext.ProjectPointOnEdge(aP, aER, aTR);
1016 BOPTools_Tools3D::GetNormalToFaceOnEdge (aE, aF, aT, aDNF);
1017 if (aF.Orientation()==TopAbs_REVERSED) {
1021 BOPTools_Tools3D::GetNormalToFaceOnEdge (aER, aFR, aTR, aDNFR);
1022 if (aFR.Orientation()==TopAbs_REVERSED) {
1031 //=======================================================================
1032 //function : HasNewSubShape
1034 //=======================================================================
1035 Standard_Boolean GEOMAlgo_Gluer::HasNewSubShape(const TopoDS_Shape& aS)const
1037 Standard_Boolean bRet;
1038 Standard_Integer i, aNbSS;
1039 TopTools_IndexedMapOfShape aMSS;
1041 GetSubShapes(aS, aMSS);
1043 bRet=Standard_False;
1044 aNbSS=aMSS.Extent();
1045 for (i=1; i<=aNbSS; ++i) {
1046 const TopoDS_Shape& aSS=aMSS(i);
1047 if (aSS.ShapeType()==TopAbs_WIRE) {
1051 bRet=!myOrigins.IsBound(aSS);
1056 const TopoDS_Shape& aSSIm=myOrigins.Find(aSS);
1057 bRet=!aSSIm.IsSame(aSS);
1064 //=======================================================================
1065 //function : GetSubShapes
1067 //=======================================================================
1068 void GetSubShapes(const TopoDS_Shape& aS,
1069 TopTools_IndexedMapOfShape& aMSS)
1071 Standard_Integer aR;
1072 TopAbs_ShapeEnum aType;
1073 TopoDS_Iterator aIt;
1075 aType=aS.ShapeType();
1076 aR=(Standard_Integer)aType+1;
1077 if (aR>TopAbs_VERTEX) {
1082 for (; aIt.More(); aIt.Next()) {
1083 const TopoDS_Shape& aSS=aIt.Value();
1085 GetSubShapes(aSS, aMSS);
1088 //=======================================================================
1089 //function : Modified
1091 //=======================================================================
1092 const TopTools_ListOfShape& GEOMAlgo_Gluer::Modified (const TopoDS_Shape& aS)
1094 TopAbs_ShapeEnum aType;
1096 myGenerated.Clear();
1098 aType=aS.ShapeType();
1099 if (aType==TopAbs_VERTEX ||
1100 aType==TopAbs_EDGE ||
1101 aType==TopAbs_WIRE ||
1102 aType==TopAbs_FACE ||
1103 aType==TopAbs_SHELL ||
1104 aType==TopAbs_SOLID) {
1105 if(myOrigins.IsBound(aS)) {
1106 const TopoDS_Shape& aSnew=myOrigins.Find(aS);
1107 if (!aSnew.IsSame(aS)) {
1108 myGenerated.Append(aSnew);
1115 //=======================================================================
1116 //function : Generated
1118 //=======================================================================
1119 const TopTools_ListOfShape& GEOMAlgo_Gluer::Generated(const TopoDS_Shape& )
1121 myGenerated.Clear();
1124 //=======================================================================
1125 //function : IsDeleted
1127 //=======================================================================
1128 Standard_Boolean GEOMAlgo_Gluer::IsDeleted (const TopoDS_Shape& aS)
1130 Standard_Boolean bRet=Standard_False;
1132 const TopTools_ListOfShape& aL=Modified(aS);
1140 // 1 - the object is just initialized
1141 // 2 - no vertices found in source shape
1142 // 3 - nb same domain vertices for the vertex Vi =0
1143 // 4 - nb same domain edges(faces) for the edge Ei(face Fi) =0
1144 // 5 - source shape is Null
1145 // 6 - result shape is Null
1146 // 101 - nb edges > PassKey.NbMax() in FacesPassKey()
1147 // 102 - the edge Ei can not be found in myOrigins Map
1148 // 100 - the vertex Vi can not be found in myOrigins Map
1152 // 1 - some shapes can not be glued by faces