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>
90 //modified by NIZNHY-PKV Thu Jan 21 10:02:52 2010f
91 #include <NMTDS_BndSphereTree.hxx>
92 #include <NMTDS_BndSphere.hxx>
93 #include <NMTDS_IndexedDataMapOfShapeBndSphere.hxx>
94 //modified by NIZNHY-PKV Thu Jan 21 10:02:56 2010t
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()
187 const Standard_Integer aNb=8;
188 void (GEOMAlgo_Gluer::* pF[aNb])()={
189 &GEOMAlgo_Gluer::CheckData, &GEOMAlgo_Gluer::InnerTolerance,
190 &GEOMAlgo_Gluer::MakeVertices, &GEOMAlgo_Gluer::MakeEdges,
191 &GEOMAlgo_Gluer::MakeFaces, &GEOMAlgo_Gluer::MakeShells,
192 &GEOMAlgo_Gluer::MakeSolids, &GEOMAlgo_Gluer::CheckResult
195 for (i=0; i<aNb; ++i) {
203 //=======================================================================
204 //function : MakeVertices
206 //=======================================================================
207 void GEOMAlgo_Gluer::MakeVertices()
211 Standard_Integer j, i, aNbV, aNbVSD;
214 TColStd_ListIteratorOfListOfInteger aIt;
217 TopTools_IndexedMapOfShape aMV, aMVProcessed;
218 TopTools_ListIteratorOfListOfShape aItS;
219 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
220 TopTools_DataMapOfShapeListOfShape aMVV;
221 GEOMAlgo_IndexedDataMapOfIntegerShape aMIS;
222 //modified by NIZNHY-PKV Thu Jan 21 10:03:07 2010f
223 //GEOMAlgo_IndexedDataMapOfShapeBox aMSB;
224 NMTDS_IndexedDataMapOfShapeBndSphere aMSB;
225 //modified by NIZNHY-PKV Thu Jan 21 10:03:10 2010t
227 NMTDS_BndSphereTreeSelector aSelector;
228 NMTDS_BndSphereTree aBBTree;
229 NCollection_UBTreeFiller <Standard_Integer, NMTDS_BndSphere> aTreeFiller(aBBTree);
231 TopExp::MapShapes(myShape, TopAbs_VERTEX, aMV);
234 myErrorStatus=2; // no vertices in source shape
238 for (i=1; i<=aNbV; ++i) {
239 NMTDS_BndSphere aBox;
241 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aMV(i));
242 aPV=BRep_Tool::Pnt(aV);
243 aTolV=BRep_Tool::Tolerance(aV);
247 aBox.SetRadius(aTolV);
249 aTreeFiller.Add(i, aBox);
257 //------------------------------
259 for (i=1; i<=aNbV; ++i) {
260 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aMV(i));
262 if (aMVProcessed.Contains(aV)) {
266 Standard_Integer aNbIP, aIP, aNbIP1, aIP1;
267 TopTools_ListOfShape aLVSD;
268 TColStd_MapOfInteger aMIP, aMIP1, aMIPC;
269 TColStd_MapIteratorOfMapOfInteger aIt1;
274 aIt1.Initialize(aMIP);
275 for(; aIt1.More(); aIt1.Next()) {
277 if (aMIPC.Contains(aIP)) {
281 const TopoDS_Shape& aVP=aMIS.FindFromKey(aIP);
282 //modified by NIZNHY-PKV Thu Jan 21 10:04:09 2010f
283 const NMTDS_BndSphere& aBoxVP=aMSB.FindFromKey(aVP);
284 //const Bnd_Box& aBoxVP=aMSB.FindFromKey(aVP);
285 //modified by NIZNHY-PKV Thu Jan 21 10:04:11 2010t
288 aSelector.SetBox(aBoxVP);
290 aNbVSD=aBBTree.Select(aSelector);
292 continue; // it must not be
295 const TColStd_ListOfInteger& aLI=aSelector.Indices();
298 for (; aIt.More(); aIt.Next()) {
300 if (aMIP.Contains(aIP1)) {
304 } //for (; aIt.More(); aIt.Next()) {
305 }//for(; aIt1.More(); aIt1.Next()) {
307 aNbIP1=aMIP1.Extent();
312 aIt1.Initialize(aMIP);
313 for(; aIt1.More(); aIt1.Next()) {
319 aIt1.Initialize(aMIP1);
320 for(; aIt1.More(); aIt1.Next()) {
328 aNbIP=aMIPC.Extent();
330 if (!aNbIP) {// no SD vertices founded
333 aMVProcessed.Add(aV);
335 else { // SD vertices founded [ aMIPC ]
336 aIt1.Initialize(aMIPC);
337 for(j=0; aIt1.More(); aIt1.Next(), ++j) {
339 const TopoDS_Shape& aVP=aMIS.FindFromKey(aIP);
344 aMVProcessed.Add(aVP);
347 myImages.Bind(aVF, aLVSD);
348 }// for (i=1; i<=aNbV; ++i) {
349 //------------------------------
353 aItIm.Initialize(myImages);
354 for (; aItIm.More(); aItIm.Next()) {
355 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aItIm.Key());
356 const TopTools_ListOfShape& aLVSD=aItIm.Value();
357 aNbVSD=aLVSD.Extent();
360 MakeVertex(aLVSD, aVnew);
361 aMVV.Bind(aVnew, aLVSD);
365 // UnBind old vertices
367 for (i=1; i<=aNbV; ++i) {
368 const TopoDS_Shape& aV=aMV(i);
373 aItIm.Initialize(aMVV);
374 for (; aItIm.More(); aItIm.Next()) {
375 const TopoDS_Shape& aV=aItIm.Key();
376 const TopTools_ListOfShape& aLVSD=aItIm.Value();
377 myImages.Bind(aV, aLVSD);
381 aItIm.Initialize(myImages);
382 for (; aItIm.More(); aItIm.Next()) {
383 const TopoDS_Shape& aV=aItIm.Key();
384 const TopTools_ListOfShape& aLVSD=aItIm.Value();
385 aItS.Initialize(aLVSD);
386 for (; aItS.More(); aItS.Next()) {
387 const TopoDS_Shape& aVSD=aItS.Value();
388 if (!myOrigins.IsBound(aVSD)) {
389 myOrigins.Bind(aVSD, aV);
394 //=======================================================================
395 //function : MakeSubShapes
397 //=======================================================================
398 void GEOMAlgo_Gluer::MakeSubShapes (const TopoDS_Shape& theShape,
399 TopTools_MapOfShape& theMS,
400 TopoDS_Compound& theResult)
402 if (theMS.Contains(theShape))
409 if (theShape.ShapeType() == TopAbs_COMPOUND ||
410 theShape.ShapeType() == TopAbs_COMPSOLID) {
411 TopoDS_Iterator It (theShape, Standard_True, Standard_True);
412 for (; It.More(); It.Next()) {
413 MakeSubShapes(It.Value(), theMS, theResult);
416 else if (theShape.ShapeType() == TopAbs_SOLID) {
418 TopoDS_Solid aNewSolid;
419 TopExp_Explorer aExpS, aExp;
421 const TopoDS_Solid& aSolid = TopoDS::Solid(theShape);
423 TopAbs_Orientation anOr = aSolid.Orientation();
425 aBB.MakeSolid(aNewSolid);
426 aNewSolid.Orientation(anOr);
428 aExp.Init(aSolid, TopAbs_SHELL);
429 for (; aExp.More(); aExp.Next())
431 const TopoDS_Shape& aShell=aExp.Current();
432 const TopoDS_Shape& aShellR=myOrigins.Find(aShell);
433 aBB.Add(aNewSolid, aShellR);
436 TopTools_ListOfShape aLS;
439 myImages.Bind(aNewSolid, aLS);
440 myOrigins.Bind(aSolid, aNewSolid);
442 aBB.Add(theResult, aNewSolid);
444 else if (theShape.ShapeType() == TopAbs_WIRE) {
445 if (myKeepNonSolids) {
447 if (!myOrigins.IsBound(theShape)) {
449 const TopoDS_Wire& aW=TopoDS::Wire(theShape);
452 aBB.MakeWire(newWire);
454 TopExp_Explorer aExpE (aW, TopAbs_EDGE);
455 for (; aExpE.More(); aExpE.Next()) {
456 const TopoDS_Edge& aE=TopoDS::Edge(aExpE.Current());
457 TopoDS_Edge aER=TopoDS::Edge(myOrigins.Find(aE));
459 aER.Orientation(TopAbs_FORWARD);
460 if (!BRep_Tool::Degenerated(aER)) {
462 //if (bIsUPeriodic) {
463 // GEOMAlgo_Tools::RefinePCurveForEdgeOnFace(aER, aFFWD, aUMin, aUMax);
465 //BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aER, aFFWD);
468 Standard_Boolean bIsToReverse=BOPTools_Tools3D::IsSplitToReverse1(aER, aE, myContext);
474 aER.Orientation(aE.Orientation());
477 aBB.Add(newWire, aER);
480 TopTools_ListOfShape aLW;
483 myImages.Bind(newWire, aLW);
484 myOrigins.Bind(aW, newWire);
486 const TopoDS_Shape& aShapeR = myOrigins.Find(theShape);
487 aBB.Add(theResult, aShapeR);
492 if (myKeepNonSolids) {
494 const TopoDS_Shape& aShapeR = myOrigins.Find(theShape);
495 aBB.Add(theResult, aShapeR);
499 //=======================================================================
500 //function : MakeSolids
502 //=======================================================================
503 void GEOMAlgo_Gluer::MakeSolids()
508 TopoDS_Compound aCmp;
509 TopTools_MapOfShape aMS;
511 aBB.MakeCompound(aCmp);
513 // Add images of all initial sub-shapes in the result.
514 // If myKeepNonSolids==false, add only solids images.
515 MakeSubShapes(myShape, aMS, aCmp);
520 BOP_CorrectTolerances::CorrectCurveOnSurface(myResult);
523 //=======================================================================
524 //function : MakeShells
526 //=======================================================================
527 void GEOMAlgo_Gluer::MakeShells()
531 Standard_Boolean bIsToReverse;
532 Standard_Integer i, aNbS;
533 TopAbs_Orientation anOr;
534 TopoDS_Shell aNewShell;
536 TopTools_IndexedMapOfShape aMS;
537 TopExp_Explorer aExp;
540 TopExp::MapShapes(myShape, TopAbs_SHELL, aMS);
543 for (i=1; i<=aNbS; ++i) {
544 const TopoDS_Shell& aShell=TopoDS::Shell(aMS(i));
545 anOr=aShell.Orientation();
547 aBB.MakeShell(aNewShell);
548 aNewShell.Orientation(anOr);
549 aExp.Init(aShell, TopAbs_FACE);
550 for (; aExp.More(); aExp.Next()) {
551 const TopoDS_Face& aF=TopoDS::Face(aExp.Current());
552 aFR=TopoDS::Face(myOrigins.Find(aF));
553 if (aFR.IsSame(aF)) {
554 aBB.Add(aNewShell, aF);
557 bIsToReverse=IsToReverse(aFR, aF);
561 aBB.Add(aNewShell, aFR);
564 TopTools_ListOfShape aLS;
567 myImages.Bind(aNewShell, aLS);
568 myOrigins.Bind(aShell, aNewShell);
571 //=======================================================================
572 //function : MakeFaces
574 //=======================================================================
575 void GEOMAlgo_Gluer::MakeFaces()
577 MakeShapes(TopAbs_FACE);
579 //=======================================================================
580 //function : MakeEdges
582 //=======================================================================
583 void GEOMAlgo_Gluer::MakeEdges()
585 MakeShapes(TopAbs_EDGE);
587 //=======================================================================
588 //function : MakeShapes
590 //=======================================================================
591 void GEOMAlgo_Gluer::MakeShapes(const TopAbs_ShapeEnum aType)
595 Standard_Boolean bHasNewSubShape;
596 Standard_Integer i, aNbF, aNbSDF, iErr;
597 TopoDS_Shape aNewShape;
598 TopTools_IndexedMapOfShape aMF;
599 TopTools_ListIteratorOfListOfShape aItS;
600 GEOMAlgo_PassKeyShape aPKF;
601 GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLF;
603 TopExp::MapShapes(myShape, aType, aMF);
606 for (i=1; i<=aNbF; ++i) {
607 const TopoDS_Shape& aS=aMF(i);
609 if (aType==TopAbs_FACE) {
610 const TopoDS_Face& aF=TopoDS::Face(aS);
611 FacePassKey(aF, aPKF);
613 else if (aType==TopAbs_EDGE) {
614 const TopoDS_Edge& aE=TopoDS::Edge(aS);
615 EdgePassKey(aE, aPKF);
622 if (aMPKLF.Contains(aPKF)) {
623 TopTools_ListOfShape& aLSDF=aMPKLF.ChangeFromKey(aPKF);
627 TopTools_ListOfShape aLSDF;
630 aMPKLF.Add(aPKF, aLSDF);
633 // check geometric coincidence
634 if (myCheckGeometry) {
635 iErr=GEOMAlgo_Tools::RefineSDShapes(aMPKLF, myTol, myContext);
644 aNbF=aMPKLF.Extent();
645 for (i=1; i<=aNbF; ++i) {
646 const TopTools_ListOfShape& aLSDF=aMPKLF(i);
647 aNbSDF=aLSDF.Extent();
649 myErrorStatus=4; // it must not be
652 const TopoDS_Shape& aS1=aLSDF.First();
654 bHasNewSubShape=Standard_True;
655 // prevent creation of a new shape if there are not
656 // new subshapes of aSS among the originals
658 bHasNewSubShape=HasNewSubShape(aS1);
659 if (!bHasNewSubShape) {
661 aNewShape.Orientation(TopAbs_FORWARD);
665 if (bHasNewSubShape) {
666 if (aType==TopAbs_FACE) {
667 TopoDS_Face aNewFace;
669 const TopoDS_Face& aF1=TopoDS::Face(aS1);
670 MakeFace(aF1, aNewFace);
673 else if (aType==TopAbs_EDGE) {
674 TopoDS_Edge aNewEdge;
676 const TopoDS_Edge& aE1=TopoDS::Edge(aS1);
677 MakeEdge(aE1, aNewEdge);
682 myImages.Bind(aNewShape, aLSDF);
684 aItS.Initialize(aLSDF);
685 for (; aItS.More(); aItS.Next()) {
686 const TopoDS_Shape& aFSD=aItS.Value();
687 if (!myOrigins.IsBound(aFSD)) {
688 myOrigins.Bind(aFSD, aNewShape);
693 //=======================================================================
694 //function : CheckResult
696 //=======================================================================
697 void GEOMAlgo_Gluer::CheckResult()
701 if (myResult.IsNull()) {
706 Standard_Boolean bFound;
707 Standard_Integer i, j, aNbS, aNbFS, aNbSx;
708 TopTools_IndexedMapOfShape aMS, aMFS;
709 TopTools_IndexedDataMapOfShapeListOfShape aMFR;
711 TopExp::MapShapesAndAncestors(myResult, TopAbs_FACE, TopAbs_SOLID, aMFR);
712 TopExp::MapShapes(myResult, TopAbs_SOLID, aMS);
717 for (i=1; i<=aNbS; ++i) {
718 const TopoDS_Shape& aSolid=aMS(i);
721 TopExp::MapShapes(aSolid, TopAbs_FACE, aMFS);
723 bFound=Standard_False;
725 for (j=1; j<=aNbFS; ++j) {
726 const TopoDS_Shape& aFS=aMFS(j);
727 if (aMFR.Contains(aFS)) {
728 const TopTools_ListOfShape& aLSx=aMFR.FindFromKey(aFS);
744 //=======================================================================
745 //function : CheckData
747 //=======================================================================
748 void GEOMAlgo_Gluer::CheckData()
752 if (myShape.IsNull()) {
757 //=======================================================================
758 //function : InnerTolerance
760 //=======================================================================
761 void GEOMAlgo_Gluer::InnerTolerance()
767 Standard_Real aX[3][2], dH, dHmin, aCoef, aTolTresh;
770 BRepBndLib::Add(myShape, aBox);
771 aBox.Get(aX[0][0], aX[1][0], aX[2][0], aX[0][1], aX[1][1], aX[2][1]);
773 dHmin=aX[0][1]-aX[0][0];
774 for (i=1; i<3; ++i) {
775 dH=aX[i][1]-aX[i][0];
783 aTolTresh=aCoef*dHmin;
784 if (myTol>aTolTresh) {
790 //=======================================================================
791 //function : FacePassKey
793 //=======================================================================
794 void GEOMAlgo_Gluer::FacePassKey(const TopoDS_Face& aF,
795 GEOMAlgo_PassKeyShape& aPK)
797 Standard_Integer i, aNbE;
798 TopTools_ListOfShape aLE;
799 TopTools_IndexedMapOfShape aME;
801 TopExp::MapShapes(aF, TopAbs_EDGE, aME);
804 for (i=1; i<=aNbE; ++i) {
805 const TopoDS_Shape& aE=aME(i);
806 if (!myOrigins.IsBound(aE)) {
810 const TopoDS_Shape& aER=myOrigins.Find(aE);
815 //=======================================================================
816 //function : EdgePassKey
818 //=======================================================================
819 void GEOMAlgo_Gluer::EdgePassKey(const TopoDS_Edge& aE,
820 GEOMAlgo_PassKeyShape& aPK)
822 TopoDS_Vertex aV1, aV2;
824 TopExp::Vertices(aE, aV1, aV2);
826 if (!myOrigins.IsBound(aV1) || !myOrigins.IsBound(aV2) ) {
830 const TopoDS_Shape& aVR1=myOrigins.Find(aV1);
831 const TopoDS_Shape& aVR2=myOrigins.Find(aV2);
832 aPK.SetShapes(aVR1, aVR2);
834 //=======================================================================
835 //function : MakeVertex
837 //=======================================================================
838 void GEOMAlgo_Gluer::MakeVertex(const TopTools_ListOfShape& aLV,
839 TopoDS_Vertex& aNewVertex)
841 Standard_Integer aNbV;
842 Standard_Real aTolV, aD, aDmax;
847 TopTools_ListIteratorOfListOfShape aIt;
855 aGC.SetCoord(0.,0.,0.);
857 for (; aIt.More(); aIt.Next()) {
858 aVx=TopoDS::Vertex(aIt.Value());
859 aP3D=BRep_Tool::Pnt(aVx);
862 aGC/=(Standard_Real)aNbV;
868 for (; aIt.More(); aIt.Next()) {
869 aVx=TopoDS::Vertex(aIt.Value());
870 aP3D=BRep_Tool::Pnt(aVx);
871 aTolV=BRep_Tool::Tolerance(aVx);
872 aD=aPGC.Distance(aP3D)+aTolV;
878 aBB.MakeVertex (aNewVertex, aPGC, aDmax);
880 //=======================================================================
881 //function : MakeEdge
883 //=======================================================================
884 void GEOMAlgo_Gluer::MakeEdge(const TopoDS_Edge& aE,
885 TopoDS_Edge& aNewEdge)
889 Standard_Boolean bIsDE;
890 Standard_Real aT1, aT2;
891 TopoDS_Vertex aV1, aV2, aVR1, aVR2;
894 bIsDE=BRep_Tool::Degenerated(aE);
897 aEx.Orientation(TopAbs_FORWARD);
899 TopExp::Vertices(aEx, aV1, aV2);
901 aT1=BRep_Tool::Parameter(aV1, aEx);
902 aT2=BRep_Tool::Parameter(aV2, aEx);
904 aVR1=TopoDS::Vertex(myOrigins.Find(aV1));
905 aVR1.Orientation(TopAbs_FORWARD);
906 aVR2=TopoDS::Vertex(myOrigins.Find(aV2));
907 aVR2.Orientation(TopAbs_REVERSED);
913 TopAbs_Orientation anOrE;
915 anOrE=aE.Orientation();
916 aTol=BRep_Tool::Tolerance(aE);
923 aBB.Range(E, aT1, aT2);
924 aBB.Degenerated(E, Standard_True);
925 aBB.UpdateEdge(E, aTol);
931 BOPTools_Tools::MakeSplitEdge(aEx, aVR1, aT1, aVR2, aT2, aNewEdge);
934 //=======================================================================
935 //function : MakeFace
937 //=======================================================================
938 void GEOMAlgo_Gluer::MakeFace(const TopoDS_Face& aF,
939 TopoDS_Face& aNewFace)
943 Standard_Boolean bIsToReverse, bIsUPeriodic;
944 Standard_Real aTol, aUMin, aUMax, aVMin, aVMax;
947 TopoDS_Face aFFWD, newFace;
948 TopLoc_Location aLoc;
949 Handle(Geom_Surface) aS;
950 Handle(Geom2d_Curve) aC2D;
951 TopExp_Explorer aExpW, aExpE;
955 aFFWD.Orientation(TopAbs_FORWARD);
957 aS=BRep_Tool::Surface(aFFWD, aLoc);
958 bIsUPeriodic=GEOMAlgo_Tools::IsUPeriodic(aS);
959 aTol=BRep_Tool::Tolerance(aFFWD);
960 BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
962 aBB.MakeFace (newFace, aS, aLoc, aTol);
964 aExpW.Init(aFFWD, TopAbs_WIRE);
965 for (; aExpW.More(); aExpW.Next()) {
966 aBB.MakeWire(newWire);
967 const TopoDS_Wire& aW=TopoDS::Wire(aExpW.Current());
968 aExpE.Init(aW, TopAbs_EDGE);
969 for (; aExpE.More(); aExpE.Next()) {
970 const TopoDS_Edge& aE=TopoDS::Edge(aExpE.Current());
971 aER=TopoDS::Edge(myOrigins.Find(aE));
973 aER.Orientation(TopAbs_FORWARD);
974 if (!BRep_Tool::Degenerated(aER)) {
977 GEOMAlgo_Tools::RefinePCurveForEdgeOnFace(aER, aFFWD, aUMin, aUMax);
979 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aER, aFFWD);
982 bIsToReverse=BOPTools_Tools3D::IsSplitToReverse1(aER, aE, myContext);
988 aER.Orientation(aE.Orientation());
991 aBB.Add(newWire, aER);
994 TopTools_ListOfShape aLW;
997 myImages.Bind(newWire, aLW);
998 myOrigins.Bind(aW, newWire);
1000 aBB.Add(newFace, newWire);
1004 //=======================================================================
1005 //function : IsToReverse
1007 //=======================================================================
1008 Standard_Boolean GEOMAlgo_Gluer::IsToReverse(const TopoDS_Face& aFR,
1009 const TopoDS_Face& aF)
1011 Standard_Boolean bRet;
1012 Standard_Real aT, aT1, aT2, aTR, aScPr;
1013 TopExp_Explorer aExp;
1014 Handle(Geom_Curve)aC3D;
1018 bRet=Standard_False;
1020 aExp.Init(aF, TopAbs_EDGE);
1021 for (; aExp.More(); aExp.Next()) {
1022 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
1024 if (BRep_Tool::Degenerated(aE)) {
1028 const TopoDS_Edge& aER=TopoDS::Edge(myOrigins.Find(aE));
1030 aC3D=BRep_Tool::Curve(aE, aT1, aT2);
1031 aT=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
1033 myContext.ProjectPointOnEdge(aP, aER, aTR);
1035 BOPTools_Tools3D::GetNormalToFaceOnEdge (aE, aF, aT, aDNF);
1036 if (aF.Orientation()==TopAbs_REVERSED) {
1040 BOPTools_Tools3D::GetNormalToFaceOnEdge (aER, aFR, aTR, aDNFR);
1041 if (aFR.Orientation()==TopAbs_REVERSED) {
1050 //=======================================================================
1051 //function : HasNewSubShape
1053 //=======================================================================
1054 Standard_Boolean GEOMAlgo_Gluer::HasNewSubShape(const TopoDS_Shape& aS)const
1056 Standard_Boolean bRet;
1057 Standard_Integer i, aNbSS;
1058 TopTools_IndexedMapOfShape aMSS;
1060 GetSubShapes(aS, aMSS);
1062 bRet=Standard_False;
1063 aNbSS=aMSS.Extent();
1064 for (i=1; i<=aNbSS; ++i) {
1065 const TopoDS_Shape& aSS=aMSS(i);
1066 if (aSS.ShapeType()==TopAbs_WIRE) {
1070 bRet=!myOrigins.IsBound(aSS);
1075 const TopoDS_Shape& aSSIm=myOrigins.Find(aSS);
1076 bRet=!aSSIm.IsSame(aSS);
1083 //=======================================================================
1084 //function : GetSubShapes
1086 //=======================================================================
1087 void GetSubShapes(const TopoDS_Shape& aS,
1088 TopTools_IndexedMapOfShape& aMSS)
1090 Standard_Integer aR;
1091 TopAbs_ShapeEnum aType;
1092 TopoDS_Iterator aIt;
1094 aType=aS.ShapeType();
1095 aR=(Standard_Integer)aType+1;
1096 if (aR>TopAbs_VERTEX) {
1101 for (; aIt.More(); aIt.Next()) {
1102 const TopoDS_Shape& aSS=aIt.Value();
1104 GetSubShapes(aSS, aMSS);
1107 //=======================================================================
1108 //function : Modified
1110 //=======================================================================
1111 const TopTools_ListOfShape& GEOMAlgo_Gluer::Modified (const TopoDS_Shape& aS)
1113 TopAbs_ShapeEnum aType;
1115 myGenerated.Clear();
1117 aType=aS.ShapeType();
1118 if (aType==TopAbs_VERTEX ||
1119 aType==TopAbs_EDGE ||
1120 aType==TopAbs_WIRE ||
1121 aType==TopAbs_FACE ||
1122 aType==TopAbs_SHELL ||
1123 aType==TopAbs_SOLID) {
1124 if(myOrigins.IsBound(aS)) {
1125 const TopoDS_Shape& aSnew=myOrigins.Find(aS);
1126 if (!aSnew.IsSame(aS)) {
1127 myGenerated.Append(aSnew);
1134 //=======================================================================
1135 //function : Generated
1137 //=======================================================================
1138 const TopTools_ListOfShape& GEOMAlgo_Gluer::Generated(const TopoDS_Shape& )
1140 myGenerated.Clear();
1143 //=======================================================================
1144 //function : IsDeleted
1146 //=======================================================================
1147 Standard_Boolean GEOMAlgo_Gluer::IsDeleted (const TopoDS_Shape& aS)
1149 Standard_Boolean bRet=Standard_False;
1151 const TopTools_ListOfShape& aL=Modified(aS);
1160 // 1 - the object is just initialized
1161 // 2 - no vertices found in source shape
1162 // 3 - nb same domain vertices for the vertex Vi =0
1163 // 4 - nb same domain edges(faces) for the edge Ei(face Fi) =0
1164 // 5 - source shape is Null
1165 // 6 - result shape is Null
1166 // 101 - nb edges > PassKey.NbMax() in FacesPassKey()
1167 // 102 - the edge Ei can not be found in myOrigins Map
1168 // 100 - the vertex Vi can not be found in myOrigins Map
1172 // 1 - some shapes can not be glued by faces