1 // Copyright (C) 2007-2013 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
23 // File: GEOMAlgo_Gluer.cxx
24 // Created: Sat Dec 04 12:45:53 2004
25 // Author: Peter KURNEV
28 #include <GEOMAlgo_Gluer.hxx>
31 #include <NCollection_UBTreeFiller.hxx>
33 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
34 #include <TColStd_MapOfInteger.hxx>
35 #include <TColStd_ListOfInteger.hxx>
36 #include <TColStd_ListIteratorOfListOfInteger.hxx>
42 #include <Geom_Curve.hxx>
43 #include <Geom_Surface.hxx>
45 #include <Bnd_Box.hxx>
46 #include <Bnd_HArray1OfBox.hxx>
47 #include <Bnd_BoundSortBox.hxx>
49 #include <TopLoc_Location.hxx>
50 #include <TopAbs_ShapeEnum.hxx>
51 #include <TopAbs_Orientation.hxx>
54 #include <TopoDS_Edge.hxx>
55 #include <TopoDS_Vertex.hxx>
56 #include <TopoDS_Shape.hxx>
57 #include <TopoDS_Compound.hxx>
58 #include <TopoDS_Wire.hxx>
59 #include <TopoDS_Shell.hxx>
60 #include <TopoDS_Solid.hxx>
61 #include <TopoDS_Iterator.hxx>
63 #include <TopTools_IndexedMapOfShape.hxx>
64 #include <TopTools_ListOfShape.hxx>
65 #include <TopTools_ListIteratorOfListOfShape.hxx>
66 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
67 #include <TopTools_MapOfShape.hxx>
68 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
71 #include <TopExp_Explorer.hxx>
73 #include <BRep_Tool.hxx>
74 #include <BRep_Builder.hxx>
75 #include <BRepLib.hxx>
76 #include <BRepTools.hxx>
77 #include <BRepBndLib.hxx>
79 #include <IntTools_Tools.hxx>
80 #include <BOPInt_Context.hxx>
81 #include <BOPTools_AlgoTools.hxx>
82 #include <BOPTools_AlgoTools3D.hxx>
83 #include <BOPTools_AlgoTools2D.hxx>
85 #include <GEOMAlgo_BoxBndTree.hxx>
86 #include <GEOMAlgo_AlgoTools.hxx>
87 #include <GEOMAlgo_IndexedDataMapOfIntegerShape.hxx>
88 #include <GEOMAlgo_IndexedDataMapOfShapeBox.hxx>
89 #include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx>
90 #include <GEOMAlgo_PassKeyShape.hxx>
91 #include <GEOMAlgo_BndSphereTree.hxx>
92 #include <GEOMAlgo_BndSphere.hxx>
93 #include <GEOMAlgo_IndexedDataMapOfShapeBndSphere.hxx>
97 void GetSubShapes(const TopoDS_Shape& aS,
98 TopTools_IndexedMapOfShape& aMSS);
100 //=======================================================================
101 //function : GEOMAlgo_Gluer
103 //=======================================================================
104 GEOMAlgo_Gluer::GEOMAlgo_Gluer()
110 myCheckGeometry=Standard_True;
111 myKeepNonSolids=Standard_False;
114 //=======================================================================
115 //function : ~GEOMAlgo_Gluer
117 //=======================================================================
118 GEOMAlgo_Gluer::~GEOMAlgo_Gluer()
121 //=======================================================================
122 //function : SetCheckGeometry
124 //=======================================================================
125 void GEOMAlgo_Gluer::SetCheckGeometry(const Standard_Boolean aFlag)
127 myCheckGeometry=aFlag;
129 //=======================================================================
130 //function : CheckGeometry
132 //=======================================================================
133 Standard_Boolean GEOMAlgo_Gluer::CheckGeometry() const
135 return myCheckGeometry;
137 //=======================================================================
138 //function : SetKeepNonSolids
140 //=======================================================================
141 void GEOMAlgo_Gluer::SetKeepNonSolids(const Standard_Boolean aFlag)
143 myKeepNonSolids=aFlag;
145 //=======================================================================
146 //function : KeepNonSolids
148 //=======================================================================
149 Standard_Boolean GEOMAlgo_Gluer::KeepNonSolids()const
151 return myKeepNonSolids;
153 //=======================================================================
154 //function : AloneShapes
156 //=======================================================================
157 Standard_Integer GEOMAlgo_Gluer::AloneShapes()const
161 //=======================================================================
164 //=======================================================================
165 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer::Images()const
169 //=======================================================================
172 //=======================================================================
173 const TopTools_DataMapOfShapeShape& GEOMAlgo_Gluer::Origins()const
177 //=======================================================================
180 //=======================================================================
181 void GEOMAlgo_Gluer::Perform()
183 const Standard_Integer aNb=8;
189 // Initialize the context
190 GEOMAlgo_ShapeAlgo::Perform();
192 void (GEOMAlgo_Gluer::* pF[aNb])()={
193 &GEOMAlgo_Gluer::CheckData, &GEOMAlgo_Gluer::InnerTolerance,
194 &GEOMAlgo_Gluer::MakeVertices, &GEOMAlgo_Gluer::MakeEdges,
195 &GEOMAlgo_Gluer::MakeFaces, &GEOMAlgo_Gluer::MakeShells,
196 &GEOMAlgo_Gluer::MakeSolids, &GEOMAlgo_Gluer::CheckResult
199 for (i=0; i<aNb; ++i) {
207 //=======================================================================
208 //function : MakeVertices
210 //=======================================================================
211 void GEOMAlgo_Gluer::MakeVertices()
215 Standard_Integer j, i, aNbV, aNbVSD;
218 TColStd_ListIteratorOfListOfInteger aIt;
221 TopTools_IndexedMapOfShape aMV, aMVProcessed;
222 TopTools_ListIteratorOfListOfShape aItS;
223 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
224 TopTools_DataMapOfShapeListOfShape aMVV;
225 GEOMAlgo_IndexedDataMapOfIntegerShape aMIS;
226 //modified by NIZNHY-PKV Thu Jan 21 10:03:07 2010f
227 //GEOMAlgo_IndexedDataMapOfShapeBox aMSB;
228 GEOMAlgo_IndexedDataMapOfShapeBndSphere aMSB;
229 //modified by NIZNHY-PKV Thu Jan 21 10:03:10 2010t
231 GEOMAlgo_BndSphereTreeSelector aSelector;
232 GEOMAlgo_BndSphereTree aBBTree;
233 NCollection_UBTreeFiller <Standard_Integer, GEOMAlgo_BndSphere> aTreeFiller(aBBTree);
235 TopExp::MapShapes(myShape, TopAbs_VERTEX, aMV);
238 myErrorStatus=2; // no vertices in source shape
242 for (i=1; i<=aNbV; ++i) {
243 GEOMAlgo_BndSphere aBox;
245 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aMV(i));
246 aPV=BRep_Tool::Pnt(aV);
247 aTolV=BRep_Tool::Tolerance(aV);
251 aBox.SetRadius(aTolV);
253 aTreeFiller.Add(i, aBox);
261 //------------------------------
263 for (i=1; i<=aNbV; ++i) {
264 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aMV(i));
266 if (aMVProcessed.Contains(aV)) {
270 Standard_Integer aNbIP, aIP, aNbIP1, aIP1;
271 TopTools_ListOfShape aLVSD;
272 TColStd_MapOfInteger aMIP, aMIP1, aMIPC;
273 TColStd_MapIteratorOfMapOfInteger aIt1;
278 aIt1.Initialize(aMIP);
279 for(; aIt1.More(); aIt1.Next()) {
281 if (aMIPC.Contains(aIP)) {
285 const TopoDS_Shape& aVP=aMIS.FindFromKey(aIP);
286 //modified by NIZNHY-PKV Thu Jan 21 10:04:09 2010f
287 const GEOMAlgo_BndSphere& aBoxVP=aMSB.FindFromKey(aVP);
288 //const Bnd_Box& aBoxVP=aMSB.FindFromKey(aVP);
289 //modified by NIZNHY-PKV Thu Jan 21 10:04:11 2010t
292 aSelector.SetBox(aBoxVP);
294 aNbVSD=aBBTree.Select(aSelector);
296 continue; // it must not be
299 const TColStd_ListOfInteger& aLI=aSelector.Indices();
302 for (; aIt.More(); aIt.Next()) {
304 if (aMIP.Contains(aIP1)) {
308 } //for (; aIt.More(); aIt.Next()) {
309 }//for(; aIt1.More(); aIt1.Next()) {
311 aNbIP1=aMIP1.Extent();
316 aIt1.Initialize(aMIP);
317 for(; aIt1.More(); aIt1.Next()) {
323 aIt1.Initialize(aMIP1);
324 for(; aIt1.More(); aIt1.Next()) {
332 aNbIP=aMIPC.Extent();
334 if (!aNbIP) {// no SD vertices founded
337 aMVProcessed.Add(aV);
339 else { // SD vertices founded [ aMIPC ]
340 aIt1.Initialize(aMIPC);
341 for(j=0; aIt1.More(); aIt1.Next(), ++j) {
343 const TopoDS_Shape& aVP=aMIS.FindFromKey(aIP);
348 aMVProcessed.Add(aVP);
351 myImages.Bind(aVF, aLVSD);
352 }// for (i=1; i<=aNbV; ++i) {
353 //------------------------------
357 aItIm.Initialize(myImages);
358 for (; aItIm.More(); aItIm.Next()) {
359 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aItIm.Key());
360 const TopTools_ListOfShape& aLVSD=aItIm.Value();
361 aNbVSD=aLVSD.Extent();
364 MakeVertex(aLVSD, aVnew);
365 aMVV.Bind(aVnew, aLVSD);
369 // UnBind old vertices
371 for (i=1; i<=aNbV; ++i) {
372 const TopoDS_Shape& aV=aMV(i);
377 aItIm.Initialize(aMVV);
378 for (; aItIm.More(); aItIm.Next()) {
379 const TopoDS_Shape& aV=aItIm.Key();
380 const TopTools_ListOfShape& aLVSD=aItIm.Value();
381 myImages.Bind(aV, aLVSD);
385 aItIm.Initialize(myImages);
386 for (; aItIm.More(); aItIm.Next()) {
387 const TopoDS_Shape& aV=aItIm.Key();
388 const TopTools_ListOfShape& aLVSD=aItIm.Value();
389 aItS.Initialize(aLVSD);
390 for (; aItS.More(); aItS.Next()) {
391 const TopoDS_Shape& aVSD=aItS.Value();
392 if (!myOrigins.IsBound(aVSD)) {
393 myOrigins.Bind(aVSD, aV);
398 //=======================================================================
399 //function : MakeSubShapes
401 //=======================================================================
402 void GEOMAlgo_Gluer::MakeSubShapes (const TopoDS_Shape& theShape,
403 TopTools_MapOfShape& theMS,
404 TopoDS_Compound& theResult)
406 if (theMS.Contains(theShape))
413 if (theShape.ShapeType() == TopAbs_COMPOUND ||
414 theShape.ShapeType() == TopAbs_COMPSOLID) {
415 TopoDS_Iterator It (theShape, Standard_True, Standard_True);
416 for (; It.More(); It.Next()) {
417 MakeSubShapes(It.Value(), theMS, theResult);
420 else if (theShape.ShapeType() == TopAbs_SOLID) {
422 TopoDS_Solid aNewSolid;
423 TopExp_Explorer aExpS, aExp;
425 const TopoDS_Solid& aSolid = TopoDS::Solid(theShape);
427 TopAbs_Orientation anOr = aSolid.Orientation();
429 aBB.MakeSolid(aNewSolid);
430 aNewSolid.Orientation(anOr);
432 aExp.Init(aSolid, TopAbs_SHELL);
433 for (; aExp.More(); aExp.Next())
435 const TopoDS_Shape& aShell=aExp.Current();
436 const TopoDS_Shape& aShellR=myOrigins.Find(aShell);
437 aBB.Add(aNewSolid, aShellR);
440 TopTools_ListOfShape aLS;
443 myImages.Bind(aNewSolid, aLS);
444 myOrigins.Bind(aSolid, aNewSolid);
446 aBB.Add(theResult, aNewSolid);
448 else if (theShape.ShapeType() == TopAbs_WIRE) {
449 if (myKeepNonSolids) {
451 if (!myOrigins.IsBound(theShape)) {
453 const TopoDS_Wire& aW=TopoDS::Wire(theShape);
456 aBB.MakeWire(newWire);
458 TopExp_Explorer aExpE (aW, TopAbs_EDGE);
459 for (; aExpE.More(); aExpE.Next()) {
460 const TopoDS_Edge& aE=TopoDS::Edge(aExpE.Current());
461 TopoDS_Edge aER=TopoDS::Edge(myOrigins.Find(aE));
463 aER.Orientation(TopAbs_FORWARD);
464 if (!BRep_Tool::Degenerated(aER)) {
466 Standard_Boolean bIsToReverse=GEOMAlgo_AlgoTools::IsSplitToReverse(aER, aE, myContext);
472 aER.Orientation(aE.Orientation());
475 aBB.Add(newWire, aER);
478 TopTools_ListOfShape aLW;
481 myImages.Bind(newWire, aLW);
482 myOrigins.Bind(aW, newWire);
484 const TopoDS_Shape& aShapeR = myOrigins.Find(theShape);
485 aBB.Add(theResult, aShapeR);
490 if (myKeepNonSolids) {
492 const TopoDS_Shape& aShapeR = myOrigins.Find(theShape);
493 aBB.Add(theResult, aShapeR);
497 //=======================================================================
498 //function : MakeSolids
500 //=======================================================================
501 void GEOMAlgo_Gluer::MakeSolids()
506 TopoDS_Compound aCmp;
507 TopTools_MapOfShape aMS;
509 aBB.MakeCompound(aCmp);
511 // Add images of all initial sub-shapes in the result.
512 // If myKeepNonSolids==false, add only solids images.
513 MakeSubShapes(myShape, aMS, aCmp);
518 BOPTools_AlgoTools::CorrectCurveOnSurface(myResult, 0.0001);
521 //=======================================================================
522 //function : MakeShells
524 //=======================================================================
525 void GEOMAlgo_Gluer::MakeShells()
529 Standard_Boolean bIsToReverse;
530 Standard_Integer i, aNbS;
531 TopAbs_Orientation anOr;
532 TopoDS_Shell aNewShell;
534 TopTools_IndexedMapOfShape aMS;
535 TopExp_Explorer aExp;
538 TopExp::MapShapes(myShape, TopAbs_SHELL, aMS);
541 for (i=1; i<=aNbS; ++i) {
542 const TopoDS_Shell& aShell=TopoDS::Shell(aMS(i));
543 anOr=aShell.Orientation();
545 aBB.MakeShell(aNewShell);
546 aNewShell.Orientation(anOr);
547 aExp.Init(aShell, TopAbs_FACE);
548 for (; aExp.More(); aExp.Next()) {
549 const TopoDS_Face& aF=TopoDS::Face(aExp.Current());
550 aFR=TopoDS::Face(myOrigins.Find(aF));
551 if (aFR.IsSame(aF)) {
552 aBB.Add(aNewShell, aF);
555 bIsToReverse=IsToReverse(aFR, aF);
559 aBB.Add(aNewShell, aFR);
562 TopTools_ListOfShape aLS;
565 myImages.Bind(aNewShell, aLS);
566 myOrigins.Bind(aShell, aNewShell);
569 //=======================================================================
570 //function : MakeFaces
572 //=======================================================================
573 void GEOMAlgo_Gluer::MakeFaces()
575 MakeShapes(TopAbs_FACE);
577 //=======================================================================
578 //function : MakeEdges
580 //=======================================================================
581 void GEOMAlgo_Gluer::MakeEdges()
583 MakeShapes(TopAbs_EDGE);
585 //=======================================================================
586 //function : MakeShapes
588 //=======================================================================
589 void GEOMAlgo_Gluer::MakeShapes(const TopAbs_ShapeEnum aType)
593 Standard_Boolean bHasNewSubShape;
594 Standard_Integer i, aNbF, aNbSDF, iErr;
595 TopoDS_Shape aNewShape;
596 TopTools_IndexedMapOfShape aMF;
597 TopTools_ListIteratorOfListOfShape aItS;
598 GEOMAlgo_PassKeyShape aPKF;
599 GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLF;
601 TopExp::MapShapes(myShape, aType, aMF);
604 for (i=1; i<=aNbF; ++i) {
605 const TopoDS_Shape& aS=aMF(i);
607 if (aType==TopAbs_FACE) {
608 const TopoDS_Face& aF=TopoDS::Face(aS);
609 FacePassKey(aF, aPKF);
611 else if (aType==TopAbs_EDGE) {
612 const TopoDS_Edge& aE=TopoDS::Edge(aS);
613 EdgePassKey(aE, aPKF);
620 if (aMPKLF.Contains(aPKF)) {
621 TopTools_ListOfShape& aLSDF=aMPKLF.ChangeFromKey(aPKF);
625 TopTools_ListOfShape aLSDF;
628 aMPKLF.Add(aPKF, aLSDF);
631 // check geometric coincidence
632 if (myCheckGeometry) {
633 iErr=GEOMAlgo_AlgoTools::RefineSDShapes(aMPKLF, myTol, myContext);
642 aNbF=aMPKLF.Extent();
643 for (i=1; i<=aNbF; ++i) {
644 const TopTools_ListOfShape& aLSDF=aMPKLF(i);
645 aNbSDF=aLSDF.Extent();
647 myErrorStatus=4; // it must not be
650 const TopoDS_Shape& aS1=aLSDF.First();
652 bHasNewSubShape=Standard_True;
653 // prevent creation of a new shape if there are not
654 // new sub-shapes of aSS among the originals
656 bHasNewSubShape=HasNewSubShape(aS1);
657 if (!bHasNewSubShape) {
659 aNewShape.Orientation(TopAbs_FORWARD);
663 if (bHasNewSubShape) {
664 if (aType==TopAbs_FACE) {
665 TopoDS_Face aNewFace;
667 const TopoDS_Face& aF1=TopoDS::Face(aS1);
668 MakeFace(aF1, aNewFace);
671 else if (aType==TopAbs_EDGE) {
672 TopoDS_Edge aNewEdge;
674 const TopoDS_Edge& aE1=TopoDS::Edge(aS1);
675 MakeEdge(aE1, aNewEdge);
680 myImages.Bind(aNewShape, aLSDF);
682 aItS.Initialize(aLSDF);
683 for (; aItS.More(); aItS.Next()) {
684 const TopoDS_Shape& aFSD=aItS.Value();
685 if (!myOrigins.IsBound(aFSD)) {
686 myOrigins.Bind(aFSD, aNewShape);
691 //=======================================================================
692 //function : CheckResult
694 //=======================================================================
695 void GEOMAlgo_Gluer::CheckResult()
699 if (myResult.IsNull()) {
704 Standard_Boolean bFound;
705 Standard_Integer i, j, aNbS, aNbFS, aNbSx;
706 TopTools_IndexedMapOfShape aMS, aMFS;
707 TopTools_IndexedDataMapOfShapeListOfShape aMFR;
709 TopExp::MapShapesAndAncestors(myResult, TopAbs_FACE, TopAbs_SOLID, aMFR);
710 TopExp::MapShapes(myResult, TopAbs_SOLID, aMS);
715 for (i=1; i<=aNbS; ++i) {
716 const TopoDS_Shape& aSolid=aMS(i);
719 TopExp::MapShapes(aSolid, TopAbs_FACE, aMFS);
721 bFound=Standard_False;
723 for (j=1; j<=aNbFS; ++j) {
724 const TopoDS_Shape& aFS=aMFS(j);
725 if (aMFR.Contains(aFS)) {
726 const TopTools_ListOfShape& aLSx=aMFR.FindFromKey(aFS);
742 //=======================================================================
743 //function : CheckData
745 //=======================================================================
746 void GEOMAlgo_Gluer::CheckData()
750 if (myShape.IsNull()) {
755 //=======================================================================
756 //function : InnerTolerance
758 //=======================================================================
759 void GEOMAlgo_Gluer::InnerTolerance()
765 Standard_Real aX[3][2], dH, dHmin, aCoef, aTolTresh;
768 BRepBndLib::Add(myShape, aBox);
769 aBox.Get(aX[0][0], aX[1][0], aX[2][0], aX[0][1], aX[1][1], aX[2][1]);
771 dHmin=aX[0][1]-aX[0][0];
772 for (i=1; i<3; ++i) {
773 dH=aX[i][1]-aX[i][0];
781 aTolTresh=aCoef*dHmin;
782 if (myTol>aTolTresh) {
788 //=======================================================================
789 //function : FacePassKey
791 //=======================================================================
792 void GEOMAlgo_Gluer::FacePassKey(const TopoDS_Face& aF,
793 GEOMAlgo_PassKeyShape& aPK)
795 Standard_Integer i, aNbE;
796 TopTools_ListOfShape aLE;
797 TopTools_IndexedMapOfShape aME;
799 TopExp::MapShapes(aF, TopAbs_EDGE, aME);
802 for (i=1; i<=aNbE; ++i) {
803 const TopoDS_Shape& aE=aME(i);
804 if (!myOrigins.IsBound(aE)) {
808 const TopoDS_Shape& aER=myOrigins.Find(aE);
813 //=======================================================================
814 //function : EdgePassKey
816 //=======================================================================
817 void GEOMAlgo_Gluer::EdgePassKey(const TopoDS_Edge& aE,
818 GEOMAlgo_PassKeyShape& aPK)
820 TopoDS_Vertex aV1, aV2;
822 TopExp::Vertices(aE, aV1, aV2);
824 if (!myOrigins.IsBound(aV1) || !myOrigins.IsBound(aV2) ) {
828 const TopoDS_Shape& aVR1=myOrigins.Find(aV1);
829 const TopoDS_Shape& aVR2=myOrigins.Find(aV2);
830 aPK.SetShapes(aVR1, aVR2);
832 //=======================================================================
833 //function : MakeVertex
835 //=======================================================================
836 void GEOMAlgo_Gluer::MakeVertex(const TopTools_ListOfShape& aLV,
837 TopoDS_Vertex& aNewVertex)
839 Standard_Integer aNbV;
840 Standard_Real aTolV, aD, aDmax;
845 TopTools_ListIteratorOfListOfShape aIt;
853 aGC.SetCoord(0.,0.,0.);
855 for (; aIt.More(); aIt.Next()) {
856 aVx=TopoDS::Vertex(aIt.Value());
857 aP3D=BRep_Tool::Pnt(aVx);
860 aGC/=(Standard_Real)aNbV;
866 for (; aIt.More(); aIt.Next()) {
867 aVx=TopoDS::Vertex(aIt.Value());
868 aP3D=BRep_Tool::Pnt(aVx);
869 aTolV=BRep_Tool::Tolerance(aVx);
870 aD=aPGC.Distance(aP3D)+aTolV;
876 aBB.MakeVertex (aNewVertex, aPGC, aDmax);
878 //=======================================================================
879 //function : MakeEdge
881 //=======================================================================
882 void GEOMAlgo_Gluer::MakeEdge(const TopoDS_Edge& aE,
883 TopoDS_Edge& aNewEdge)
887 Standard_Boolean bIsDE;
888 Standard_Real aT1, aT2;
889 TopoDS_Vertex aV1, aV2, aVR1, aVR2;
892 bIsDE=BRep_Tool::Degenerated(aE);
895 aEx.Orientation(TopAbs_FORWARD);
897 TopExp::Vertices(aEx, aV1, aV2);
899 aT1=BRep_Tool::Parameter(aV1, aEx);
900 aT2=BRep_Tool::Parameter(aV2, aEx);
902 aVR1=TopoDS::Vertex(myOrigins.Find(aV1));
903 aVR1.Orientation(TopAbs_FORWARD);
904 aVR2=TopoDS::Vertex(myOrigins.Find(aV2));
905 aVR2.Orientation(TopAbs_REVERSED);
911 TopAbs_Orientation anOrE;
913 anOrE=aE.Orientation();
914 aTol=BRep_Tool::Tolerance(aE);
921 aBB.Range(E, aT1, aT2);
922 aBB.Degenerated(E, Standard_True);
923 aBB.UpdateEdge(E, aTol);
929 BOPTools_AlgoTools::MakeSplitEdge(aEx, aVR1, aT1, aVR2, aT2, aNewEdge);
932 //=======================================================================
933 //function : MakeFace
935 //=======================================================================
936 void GEOMAlgo_Gluer::MakeFace(const TopoDS_Face& aF,
937 TopoDS_Face& aNewFace)
941 Standard_Boolean bIsToReverse, bIsUPeriodic;
942 Standard_Real aTol, aUMin, aUMax, aVMin, aVMax;
945 TopoDS_Face aFFWD, newFace;
946 TopLoc_Location aLoc;
947 Handle(Geom_Surface) aS;
948 Handle(Geom2d_Curve) aC2D;
949 TopExp_Explorer aExpW, aExpE;
953 aFFWD.Orientation(TopAbs_FORWARD);
955 aS=BRep_Tool::Surface(aFFWD, aLoc);
956 bIsUPeriodic=GEOMAlgo_AlgoTools::IsUPeriodic(aS);
957 aTol=BRep_Tool::Tolerance(aFFWD);
958 BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
960 aBB.MakeFace (newFace, aS, aLoc, aTol);
962 aExpW.Init(aFFWD, TopAbs_WIRE);
963 for (; aExpW.More(); aExpW.Next()) {
964 aBB.MakeWire(newWire);
965 const TopoDS_Wire& aW=TopoDS::Wire(aExpW.Current());
966 aExpE.Init(aW, TopAbs_EDGE);
967 for (; aExpE.More(); aExpE.Next()) {
968 const TopoDS_Edge& aE=TopoDS::Edge(aExpE.Current());
969 aER=TopoDS::Edge(myOrigins.Find(aE));
971 aER.Orientation(TopAbs_FORWARD);
972 if (!BRep_Tool::Degenerated(aER)) {
975 GEOMAlgo_AlgoTools::RefinePCurveForEdgeOnFace(aER, aFFWD, aUMin, aUMax);
977 BOPTools_AlgoTools2D::BuildPCurveForEdgeOnFace(aER, aFFWD);
980 bIsToReverse=GEOMAlgo_AlgoTools::IsSplitToReverse(aER, aE, myContext);
986 aER.Orientation(aE.Orientation());
989 aBB.Add(newWire, aER);
992 TopTools_ListOfShape aLW;
995 myImages.Bind(newWire, aLW);
996 myOrigins.Bind(aW, newWire);
998 aBB.Add(newFace, newWire);
1002 //=======================================================================
1003 //function : IsToReverse
1005 //=======================================================================
1006 Standard_Boolean GEOMAlgo_Gluer::IsToReverse(const TopoDS_Face& aFR,
1007 const TopoDS_Face& aF)
1009 Standard_Boolean bRet;
1010 Standard_Real aT, aT1, aT2, aTR, aScPr;
1011 TopExp_Explorer aExp;
1012 Handle(Geom_Curve)aC3D;
1016 bRet=Standard_False;
1018 aExp.Init(aF, TopAbs_EDGE);
1019 for (; aExp.More(); aExp.Next()) {
1020 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
1022 if (BRep_Tool::Degenerated(aE)) {
1026 const TopoDS_Edge& aER=TopoDS::Edge(myOrigins.Find(aE));
1028 aC3D=BRep_Tool::Curve(aE, aT1, aT2);
1029 aT=IntTools_Tools::IntermediatePoint(aT1, aT2);
1031 myContext->ProjectPointOnEdge(aP, aER, aTR);
1033 BOPTools_AlgoTools3D::GetNormalToFaceOnEdge (aE, aF, aT, aDNF);
1034 if (aF.Orientation()==TopAbs_REVERSED) {
1038 BOPTools_AlgoTools3D::GetNormalToFaceOnEdge (aER, aFR, aTR, aDNFR);
1039 if (aFR.Orientation()==TopAbs_REVERSED) {
1048 //=======================================================================
1049 //function : HasNewSubShape
1051 //=======================================================================
1052 Standard_Boolean GEOMAlgo_Gluer::HasNewSubShape(const TopoDS_Shape& aS)const
1054 Standard_Boolean bRet;
1055 Standard_Integer i, aNbSS;
1056 TopTools_IndexedMapOfShape aMSS;
1058 GetSubShapes(aS, aMSS);
1060 bRet=Standard_False;
1061 aNbSS=aMSS.Extent();
1062 for (i=1; i<=aNbSS; ++i) {
1063 const TopoDS_Shape& aSS=aMSS(i);
1064 if (aSS.ShapeType()==TopAbs_WIRE) {
1068 bRet=!myOrigins.IsBound(aSS);
1073 const TopoDS_Shape& aSSIm=myOrigins.Find(aSS);
1074 bRet=!aSSIm.IsSame(aSS);
1081 //=======================================================================
1082 //function : GetSubShapes
1084 //=======================================================================
1085 void GetSubShapes(const TopoDS_Shape& aS,
1086 TopTools_IndexedMapOfShape& aMSS)
1088 Standard_Integer aR;
1089 TopAbs_ShapeEnum aType;
1090 TopoDS_Iterator aIt;
1092 aType=aS.ShapeType();
1093 aR=(Standard_Integer)aType+1;
1094 if (aR>TopAbs_VERTEX) {
1099 for (; aIt.More(); aIt.Next()) {
1100 const TopoDS_Shape& aSS=aIt.Value();
1102 GetSubShapes(aSS, aMSS);
1105 //=======================================================================
1106 //function : Modified
1108 //=======================================================================
1109 const TopTools_ListOfShape& GEOMAlgo_Gluer::Modified (const TopoDS_Shape& aS)
1111 TopAbs_ShapeEnum aType;
1113 myGenerated.Clear();
1115 aType=aS.ShapeType();
1116 if (aType==TopAbs_VERTEX ||
1117 aType==TopAbs_EDGE ||
1118 aType==TopAbs_WIRE ||
1119 aType==TopAbs_FACE ||
1120 aType==TopAbs_SHELL ||
1121 aType==TopAbs_SOLID) {
1122 if(myOrigins.IsBound(aS)) {
1123 const TopoDS_Shape& aSnew=myOrigins.Find(aS);
1124 if (!aSnew.IsSame(aS)) {
1125 myGenerated.Append(aSnew);
1132 //=======================================================================
1133 //function : Generated
1135 //=======================================================================
1136 const TopTools_ListOfShape& GEOMAlgo_Gluer::Generated(const TopoDS_Shape& )
1138 myGenerated.Clear();
1141 //=======================================================================
1142 //function : IsDeleted
1144 //=======================================================================
1145 Standard_Boolean GEOMAlgo_Gluer::IsDeleted (const TopoDS_Shape& aS)
1147 Standard_Boolean bRet=Standard_False;
1149 const TopTools_ListOfShape& aL=Modified(aS);
1158 // 1 - the object is just initialized
1159 // 2 - no vertices found in source shape
1160 // 3 - nb same domain vertices for the vertex Vi =0
1161 // 4 - nb same domain edges(faces) for the edge Ei(face Fi) =0
1162 // 5 - source shape is Null
1163 // 6 - result shape is Null
1164 // 101 - nb edges > PassKey.NbMax() in FacesPassKey()
1165 // 102 - the edge Ei can not be found in myOrigins Map
1166 // 100 - the vertex Vi can not be found in myOrigins Map
1170 // 1 - some shapes can not be glued by faces