1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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>
30 #include <Basics_OCCTVersion.hxx>
32 #include <NCollection_UBTreeFiller.hxx>
34 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
35 #include <TColStd_MapOfInteger.hxx>
36 #include <TColStd_ListOfInteger.hxx>
37 #include <TColStd_ListIteratorOfListOfInteger.hxx>
43 #include <Geom_Curve.hxx>
44 #include <Geom_Surface.hxx>
46 #include <Bnd_Box.hxx>
47 #include <Bnd_HArray1OfBox.hxx>
48 #include <Bnd_BoundSortBox.hxx>
50 #include <TopLoc_Location.hxx>
51 #include <TopAbs_ShapeEnum.hxx>
52 #include <TopAbs_Orientation.hxx>
55 #include <TopoDS_Edge.hxx>
56 #include <TopoDS_Vertex.hxx>
57 #include <TopoDS_Shape.hxx>
58 #include <TopoDS_Compound.hxx>
59 #include <TopoDS_Wire.hxx>
60 #include <TopoDS_Shell.hxx>
61 #include <TopoDS_Solid.hxx>
62 #include <TopoDS_Iterator.hxx>
64 #include <TopTools_IndexedMapOfShape.hxx>
65 #include <TopTools_ListOfShape.hxx>
66 #include <TopTools_ListIteratorOfListOfShape.hxx>
67 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
68 #include <TopTools_MapOfShape.hxx>
69 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
72 #include <TopExp_Explorer.hxx>
74 #include <BRep_Tool.hxx>
75 #include <BRep_Builder.hxx>
76 #include <BRepLib.hxx>
77 #include <BRepTools.hxx>
78 #include <BRepBndLib.hxx>
80 #include <IntTools_Tools.hxx>
81 #if OCC_VERSION_LARGE > 0x06070100
82 #include <IntTools_Context.hxx>
84 #include <BOPInt_Context.hxx>
86 #include <BOPTools_AlgoTools.hxx>
87 #include <BOPTools_AlgoTools3D.hxx>
88 #include <BOPTools_AlgoTools2D.hxx>
90 #include <GEOMAlgo_BoxBndTree.hxx>
91 #include <GEOMAlgo_AlgoTools.hxx>
92 #include <GEOMAlgo_IndexedDataMapOfIntegerShape.hxx>
93 #include <GEOMAlgo_IndexedDataMapOfShapeBox.hxx>
94 #include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx>
95 #include <GEOMAlgo_PassKeyShape.hxx>
96 #include <GEOMAlgo_BndSphereTree.hxx>
97 #include <GEOMAlgo_BndSphere.hxx>
98 #include <GEOMAlgo_IndexedDataMapOfShapeBndSphere.hxx>
102 void GetSubShapes(const TopoDS_Shape& aS,
103 TopTools_IndexedMapOfShape& aMSS);
105 //=======================================================================
106 //function : GEOMAlgo_Gluer
108 //=======================================================================
109 GEOMAlgo_Gluer::GEOMAlgo_Gluer()
115 myCheckGeometry=Standard_True;
116 myKeepNonSolids=Standard_False;
119 //=======================================================================
120 //function : ~GEOMAlgo_Gluer
122 //=======================================================================
123 GEOMAlgo_Gluer::~GEOMAlgo_Gluer()
126 //=======================================================================
127 //function : SetCheckGeometry
129 //=======================================================================
130 void GEOMAlgo_Gluer::SetCheckGeometry(const Standard_Boolean aFlag)
132 myCheckGeometry=aFlag;
134 //=======================================================================
135 //function : CheckGeometry
137 //=======================================================================
138 Standard_Boolean GEOMAlgo_Gluer::CheckGeometry() const
140 return myCheckGeometry;
142 //=======================================================================
143 //function : SetKeepNonSolids
145 //=======================================================================
146 void GEOMAlgo_Gluer::SetKeepNonSolids(const Standard_Boolean aFlag)
148 myKeepNonSolids=aFlag;
150 //=======================================================================
151 //function : KeepNonSolids
153 //=======================================================================
154 Standard_Boolean GEOMAlgo_Gluer::KeepNonSolids()const
156 return myKeepNonSolids;
158 //=======================================================================
159 //function : AloneShapes
161 //=======================================================================
162 Standard_Integer GEOMAlgo_Gluer::AloneShapes()const
166 //=======================================================================
169 //=======================================================================
170 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer::Images()const
174 //=======================================================================
177 //=======================================================================
178 const TopTools_DataMapOfShapeShape& GEOMAlgo_Gluer::Origins()const
182 //=======================================================================
185 //=======================================================================
186 void GEOMAlgo_Gluer::Perform()
188 const Standard_Integer aNb=8;
194 // Initialize the context
195 GEOMAlgo_ShapeAlgo::Perform();
197 void (GEOMAlgo_Gluer::* pF[aNb])()={
198 &GEOMAlgo_Gluer::CheckData, &GEOMAlgo_Gluer::InnerTolerance,
199 &GEOMAlgo_Gluer::MakeVertices, &GEOMAlgo_Gluer::MakeEdges,
200 &GEOMAlgo_Gluer::MakeFaces, &GEOMAlgo_Gluer::MakeShells,
201 &GEOMAlgo_Gluer::MakeSolids, &GEOMAlgo_Gluer::CheckResult
204 for (i=0; i<aNb; ++i) {
212 //=======================================================================
213 //function : MakeVertices
215 //=======================================================================
216 void GEOMAlgo_Gluer::MakeVertices()
220 Standard_Integer j, i, aNbV, aNbVSD;
223 TColStd_ListIteratorOfListOfInteger aIt;
226 TopTools_IndexedMapOfShape aMV, aMVProcessed;
227 TopTools_ListIteratorOfListOfShape aItS;
228 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
229 TopTools_DataMapOfShapeListOfShape aMVV;
230 GEOMAlgo_IndexedDataMapOfIntegerShape aMIS;
231 //modified by NIZNHY-PKV Thu Jan 21 10:03:07 2010f
232 //GEOMAlgo_IndexedDataMapOfShapeBox aMSB;
233 GEOMAlgo_IndexedDataMapOfShapeBndSphere aMSB;
234 //modified by NIZNHY-PKV Thu Jan 21 10:03:10 2010t
236 GEOMAlgo_BndSphereTreeSelector aSelector;
237 GEOMAlgo_BndSphereTree aBBTree;
238 NCollection_UBTreeFiller <Standard_Integer, GEOMAlgo_BndSphere> aTreeFiller(aBBTree);
240 TopExp::MapShapes(myShape, TopAbs_VERTEX, aMV);
243 myErrorStatus=2; // no vertices in source shape
247 for (i=1; i<=aNbV; ++i) {
248 GEOMAlgo_BndSphere aBox;
250 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aMV(i));
251 aPV=BRep_Tool::Pnt(aV);
252 aTolV=BRep_Tool::Tolerance(aV);
256 aBox.SetRadius(aTolV);
258 aTreeFiller.Add(i, aBox);
266 //------------------------------
268 for (i=1; i<=aNbV; ++i) {
269 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aMV(i));
271 if (aMVProcessed.Contains(aV)) {
275 Standard_Integer aNbIP, aIP, aNbIP1, aIP1;
276 TopTools_ListOfShape aLVSD;
277 TColStd_MapOfInteger aMIP, aMIP1, aMIPC;
278 TColStd_MapIteratorOfMapOfInteger aIt1;
283 aIt1.Initialize(aMIP);
284 for(; aIt1.More(); aIt1.Next()) {
286 if (aMIPC.Contains(aIP)) {
290 const TopoDS_Shape& aVP=aMIS.FindFromKey(aIP);
291 //modified by NIZNHY-PKV Thu Jan 21 10:04:09 2010f
292 const GEOMAlgo_BndSphere& aBoxVP=aMSB.FindFromKey(aVP);
293 //const Bnd_Box& aBoxVP=aMSB.FindFromKey(aVP);
294 //modified by NIZNHY-PKV Thu Jan 21 10:04:11 2010t
297 aSelector.SetBox(aBoxVP);
299 aNbVSD=aBBTree.Select(aSelector);
301 continue; // it must not be
304 const TColStd_ListOfInteger& aLI=aSelector.Indices();
307 for (; aIt.More(); aIt.Next()) {
309 if (aMIP.Contains(aIP1)) {
313 } //for (; aIt.More(); aIt.Next()) {
314 }//for(; aIt1.More(); aIt1.Next()) {
316 aNbIP1=aMIP1.Extent();
321 aIt1.Initialize(aMIP);
322 for(; aIt1.More(); aIt1.Next()) {
328 aIt1.Initialize(aMIP1);
329 for(; aIt1.More(); aIt1.Next()) {
337 aNbIP=aMIPC.Extent();
339 if (!aNbIP) {// no SD vertices founded
342 aMVProcessed.Add(aV);
344 else { // SD vertices founded [ aMIPC ]
345 aIt1.Initialize(aMIPC);
346 for(j=0; aIt1.More(); aIt1.Next(), ++j) {
348 const TopoDS_Shape& aVP=aMIS.FindFromKey(aIP);
353 aMVProcessed.Add(aVP);
356 myImages.Bind(aVF, aLVSD);
357 }// for (i=1; i<=aNbV; ++i) {
358 //------------------------------
362 aItIm.Initialize(myImages);
363 for (; aItIm.More(); aItIm.Next()) {
364 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aItIm.Key());
365 const TopTools_ListOfShape& aLVSD=aItIm.Value();
366 aNbVSD=aLVSD.Extent();
369 MakeVertex(aLVSD, aVnew);
370 aMVV.Bind(aVnew, aLVSD);
374 // UnBind old vertices
376 for (i=1; i<=aNbV; ++i) {
377 const TopoDS_Shape& aV=aMV(i);
382 aItIm.Initialize(aMVV);
383 for (; aItIm.More(); aItIm.Next()) {
384 const TopoDS_Shape& aV=aItIm.Key();
385 const TopTools_ListOfShape& aLVSD=aItIm.Value();
386 myImages.Bind(aV, aLVSD);
390 aItIm.Initialize(myImages);
391 for (; aItIm.More(); aItIm.Next()) {
392 const TopoDS_Shape& aV=aItIm.Key();
393 const TopTools_ListOfShape& aLVSD=aItIm.Value();
394 aItS.Initialize(aLVSD);
395 for (; aItS.More(); aItS.Next()) {
396 const TopoDS_Shape& aVSD=aItS.Value();
397 if (!myOrigins.IsBound(aVSD)) {
398 myOrigins.Bind(aVSD, aV);
403 //=======================================================================
404 //function : MakeSubShapes
406 //=======================================================================
407 void GEOMAlgo_Gluer::MakeSubShapes (const TopoDS_Shape& theShape,
408 TopTools_MapOfShape& theMS,
409 TopoDS_Compound& theResult)
411 if (theMS.Contains(theShape))
418 if (theShape.ShapeType() == TopAbs_COMPOUND ||
419 theShape.ShapeType() == TopAbs_COMPSOLID) {
420 TopoDS_Iterator It (theShape, Standard_True, Standard_True);
421 for (; It.More(); It.Next()) {
422 MakeSubShapes(It.Value(), theMS, theResult);
425 else if (theShape.ShapeType() == TopAbs_SOLID) {
427 TopoDS_Solid aNewSolid;
428 TopExp_Explorer aExpS, aExp;
430 const TopoDS_Solid& aSolid = TopoDS::Solid(theShape);
432 TopAbs_Orientation anOr = aSolid.Orientation();
434 aBB.MakeSolid(aNewSolid);
435 aNewSolid.Orientation(anOr);
437 aExp.Init(aSolid, TopAbs_SHELL);
438 for (; aExp.More(); aExp.Next())
440 const TopoDS_Shape& aShell=aExp.Current();
441 const TopoDS_Shape& aShellR=myOrigins.Find(aShell);
442 aBB.Add(aNewSolid, aShellR);
445 TopTools_ListOfShape aLS;
448 myImages.Bind(aNewSolid, aLS);
449 myOrigins.Bind(aSolid, aNewSolid);
451 aBB.Add(theResult, aNewSolid);
453 else if (theShape.ShapeType() == TopAbs_WIRE) {
454 if (myKeepNonSolids) {
456 if (!myOrigins.IsBound(theShape)) {
458 const TopoDS_Wire& aW=TopoDS::Wire(theShape);
461 aBB.MakeWire(newWire);
463 TopExp_Explorer aExpE (aW, TopAbs_EDGE);
464 for (; aExpE.More(); aExpE.Next()) {
465 const TopoDS_Edge& aE=TopoDS::Edge(aExpE.Current());
466 TopoDS_Edge aER=TopoDS::Edge(myOrigins.Find(aE));
468 aER.Orientation(TopAbs_FORWARD);
469 if (!BRep_Tool::Degenerated(aER)) {
471 Standard_Boolean bIsToReverse=GEOMAlgo_AlgoTools::IsSplitToReverse(aER, aE, myContext);
477 aER.Orientation(aE.Orientation());
480 aBB.Add(newWire, aER);
483 TopTools_ListOfShape aLW;
486 myImages.Bind(newWire, aLW);
487 myOrigins.Bind(aW, newWire);
489 const TopoDS_Shape& aShapeR = myOrigins.Find(theShape);
490 aBB.Add(theResult, aShapeR);
495 if (myKeepNonSolids) {
497 const TopoDS_Shape& aShapeR = myOrigins.Find(theShape);
498 aBB.Add(theResult, aShapeR);
502 //=======================================================================
503 //function : MakeSolids
505 //=======================================================================
506 void GEOMAlgo_Gluer::MakeSolids()
511 TopoDS_Compound aCmp;
512 TopTools_MapOfShape aMS;
514 aBB.MakeCompound(aCmp);
516 // Add images of all initial sub-shapes in the result.
517 // If myKeepNonSolids==false, add only solids images.
518 MakeSubShapes(myShape, aMS, aCmp);
523 BOPTools_AlgoTools::CorrectCurveOnSurface(myResult, 0.0001);
526 //=======================================================================
527 //function : MakeShells
529 //=======================================================================
530 void GEOMAlgo_Gluer::MakeShells()
534 Standard_Boolean bIsToReverse;
535 Standard_Integer i, aNbS;
536 TopAbs_Orientation anOr;
537 TopoDS_Shell aNewShell;
539 TopTools_IndexedMapOfShape aMS;
540 TopExp_Explorer aExp;
543 TopExp::MapShapes(myShape, TopAbs_SHELL, aMS);
546 for (i=1; i<=aNbS; ++i) {
547 const TopoDS_Shell& aShell=TopoDS::Shell(aMS(i));
548 anOr=aShell.Orientation();
550 aBB.MakeShell(aNewShell);
551 aNewShell.Orientation(anOr);
552 aExp.Init(aShell, TopAbs_FACE);
553 for (; aExp.More(); aExp.Next()) {
554 const TopoDS_Face& aF=TopoDS::Face(aExp.Current());
555 aFR=TopoDS::Face(myOrigins.Find(aF));
556 if (aFR.IsSame(aF)) {
557 aBB.Add(aNewShell, aF);
560 bIsToReverse=IsToReverse(aFR, aF);
564 aBB.Add(aNewShell, aFR);
567 TopTools_ListOfShape aLS;
570 myImages.Bind(aNewShell, aLS);
571 myOrigins.Bind(aShell, aNewShell);
574 //=======================================================================
575 //function : MakeFaces
577 //=======================================================================
578 void GEOMAlgo_Gluer::MakeFaces()
580 MakeShapes(TopAbs_FACE);
582 //=======================================================================
583 //function : MakeEdges
585 //=======================================================================
586 void GEOMAlgo_Gluer::MakeEdges()
588 MakeShapes(TopAbs_EDGE);
590 //=======================================================================
591 //function : MakeShapes
593 //=======================================================================
594 void GEOMAlgo_Gluer::MakeShapes(const TopAbs_ShapeEnum aType)
598 Standard_Boolean bHasNewSubShape;
599 Standard_Integer i, aNbF, aNbSDF, iErr;
600 TopoDS_Shape aNewShape;
601 TopTools_IndexedMapOfShape aMF;
602 TopTools_ListIteratorOfListOfShape aItS;
603 GEOMAlgo_PassKeyShape aPKF;
604 GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLF;
606 TopExp::MapShapes(myShape, aType, aMF);
609 for (i=1; i<=aNbF; ++i) {
610 const TopoDS_Shape& aS=aMF(i);
612 if (aType==TopAbs_FACE) {
613 const TopoDS_Face& aF=TopoDS::Face(aS);
614 FacePassKey(aF, aPKF);
616 else if (aType==TopAbs_EDGE) {
617 const TopoDS_Edge& aE=TopoDS::Edge(aS);
618 EdgePassKey(aE, aPKF);
625 if (aMPKLF.Contains(aPKF)) {
626 TopTools_ListOfShape& aLSDF=aMPKLF.ChangeFromKey(aPKF);
630 TopTools_ListOfShape aLSDF;
633 aMPKLF.Add(aPKF, aLSDF);
636 // check geometric coincidence
637 if (myCheckGeometry) {
638 iErr=GEOMAlgo_AlgoTools::RefineSDShapes(aMPKLF, myTol, myContext);
647 aNbF=aMPKLF.Extent();
648 for (i=1; i<=aNbF; ++i) {
649 const TopTools_ListOfShape& aLSDF=aMPKLF(i);
650 aNbSDF=aLSDF.Extent();
652 myErrorStatus=4; // it must not be
655 const TopoDS_Shape& aS1=aLSDF.First();
657 bHasNewSubShape=Standard_True;
658 // prevent creation of a new shape if there are not
659 // new sub-shapes of aSS among the originals
661 bHasNewSubShape=HasNewSubShape(aS1);
662 if (!bHasNewSubShape) {
664 aNewShape.Orientation(TopAbs_FORWARD);
668 if (bHasNewSubShape) {
669 if (aType==TopAbs_FACE) {
670 TopoDS_Face aNewFace;
672 const TopoDS_Face& aF1=TopoDS::Face(aS1);
673 MakeFace(aF1, aNewFace);
676 else if (aType==TopAbs_EDGE) {
677 TopoDS_Edge aNewEdge;
679 const TopoDS_Edge& aE1=TopoDS::Edge(aS1);
680 MakeEdge(aE1, aNewEdge);
685 myImages.Bind(aNewShape, aLSDF);
687 aItS.Initialize(aLSDF);
688 for (; aItS.More(); aItS.Next()) {
689 const TopoDS_Shape& aFSD=aItS.Value();
690 if (!myOrigins.IsBound(aFSD)) {
691 myOrigins.Bind(aFSD, aNewShape);
696 //=======================================================================
697 //function : CheckResult
699 //=======================================================================
700 void GEOMAlgo_Gluer::CheckResult()
704 if (myResult.IsNull()) {
709 Standard_Boolean bFound;
710 Standard_Integer i, j, aNbS, aNbFS, aNbSx;
711 TopTools_IndexedMapOfShape aMS, aMFS;
712 TopTools_IndexedDataMapOfShapeListOfShape aMFR;
714 TopExp::MapShapesAndAncestors(myResult, TopAbs_FACE, TopAbs_SOLID, aMFR);
715 TopExp::MapShapes(myResult, TopAbs_SOLID, aMS);
720 for (i=1; i<=aNbS; ++i) {
721 const TopoDS_Shape& aSolid=aMS(i);
724 TopExp::MapShapes(aSolid, TopAbs_FACE, aMFS);
726 bFound=Standard_False;
728 for (j=1; j<=aNbFS; ++j) {
729 const TopoDS_Shape& aFS=aMFS(j);
730 if (aMFR.Contains(aFS)) {
731 const TopTools_ListOfShape& aLSx=aMFR.FindFromKey(aFS);
747 //=======================================================================
748 //function : CheckData
750 //=======================================================================
751 void GEOMAlgo_Gluer::CheckData()
755 if (myShape.IsNull()) {
760 //=======================================================================
761 //function : InnerTolerance
763 //=======================================================================
764 void GEOMAlgo_Gluer::InnerTolerance()
770 Standard_Real aX[3][2], dH, dHmin, aCoef, aTolTresh;
773 BRepBndLib::Add(myShape, aBox);
774 aBox.Get(aX[0][0], aX[1][0], aX[2][0], aX[0][1], aX[1][1], aX[2][1]);
776 dHmin=aX[0][1]-aX[0][0];
777 for (i=1; i<3; ++i) {
778 dH=aX[i][1]-aX[i][0];
786 aTolTresh=aCoef*dHmin;
787 if (myTol>aTolTresh) {
793 //=======================================================================
794 //function : FacePassKey
796 //=======================================================================
797 void GEOMAlgo_Gluer::FacePassKey(const TopoDS_Face& aF,
798 GEOMAlgo_PassKeyShape& aPK)
800 Standard_Integer i, aNbE;
801 TopTools_ListOfShape aLE;
802 TopTools_IndexedMapOfShape aME;
804 TopExp::MapShapes(aF, TopAbs_EDGE, aME);
807 for (i=1; i<=aNbE; ++i) {
808 const TopoDS_Shape& aE=aME(i);
809 if (!myOrigins.IsBound(aE)) {
813 const TopoDS_Shape& aER=myOrigins.Find(aE);
818 //=======================================================================
819 //function : EdgePassKey
821 //=======================================================================
822 void GEOMAlgo_Gluer::EdgePassKey(const TopoDS_Edge& aE,
823 GEOMAlgo_PassKeyShape& aPK)
825 TopoDS_Vertex aV1, aV2;
827 TopExp::Vertices(aE, aV1, aV2);
829 if (!myOrigins.IsBound(aV1) || !myOrigins.IsBound(aV2) ) {
833 const TopoDS_Shape& aVR1=myOrigins.Find(aV1);
834 const TopoDS_Shape& aVR2=myOrigins.Find(aV2);
835 aPK.SetShapes(aVR1, aVR2);
837 //=======================================================================
838 //function : MakeVertex
840 //=======================================================================
841 void GEOMAlgo_Gluer::MakeVertex(const TopTools_ListOfShape& aLV,
842 TopoDS_Vertex& aNewVertex)
844 Standard_Integer aNbV;
845 Standard_Real aTolV, aD, aDmax;
850 TopTools_ListIteratorOfListOfShape aIt;
858 aGC.SetCoord(0.,0.,0.);
860 for (; aIt.More(); aIt.Next()) {
861 aVx=TopoDS::Vertex(aIt.Value());
862 aP3D=BRep_Tool::Pnt(aVx);
865 aGC/=(Standard_Real)aNbV;
871 for (; aIt.More(); aIt.Next()) {
872 aVx=TopoDS::Vertex(aIt.Value());
873 aP3D=BRep_Tool::Pnt(aVx);
874 aTolV=BRep_Tool::Tolerance(aVx);
875 aD=aPGC.Distance(aP3D)+aTolV;
881 aBB.MakeVertex (aNewVertex, aPGC, aDmax);
883 //=======================================================================
884 //function : MakeEdge
886 //=======================================================================
887 void GEOMAlgo_Gluer::MakeEdge(const TopoDS_Edge& aE,
888 TopoDS_Edge& aNewEdge)
892 Standard_Boolean bIsDE;
893 Standard_Real aT1, aT2;
894 TopoDS_Vertex aV1, aV2, aVR1, aVR2;
897 bIsDE=BRep_Tool::Degenerated(aE);
900 aEx.Orientation(TopAbs_FORWARD);
902 TopExp::Vertices(aEx, aV1, aV2);
904 aT1=BRep_Tool::Parameter(aV1, aEx);
905 aT2=BRep_Tool::Parameter(aV2, aEx);
907 aVR1=TopoDS::Vertex(myOrigins.Find(aV1));
908 aVR1.Orientation(TopAbs_FORWARD);
909 aVR2=TopoDS::Vertex(myOrigins.Find(aV2));
910 aVR2.Orientation(TopAbs_REVERSED);
916 TopAbs_Orientation anOrE;
918 anOrE=aE.Orientation();
919 aTol=BRep_Tool::Tolerance(aE);
926 aBB.Range(E, aT1, aT2);
927 aBB.Degenerated(E, Standard_True);
928 aBB.UpdateEdge(E, aTol);
934 BOPTools_AlgoTools::MakeSplitEdge(aEx, aVR1, aT1, aVR2, aT2, aNewEdge);
937 //=======================================================================
938 //function : MakeFace
940 //=======================================================================
941 void GEOMAlgo_Gluer::MakeFace(const TopoDS_Face& aF,
942 TopoDS_Face& aNewFace)
946 Standard_Boolean bIsToReverse, bIsUPeriodic;
947 Standard_Real aTol, aUMin, aUMax, aVMin, aVMax;
950 TopoDS_Face aFFWD, newFace;
951 TopLoc_Location aLoc;
952 Handle(Geom_Surface) aS;
953 Handle(Geom2d_Curve) aC2D;
954 TopExp_Explorer aExpW, aExpE;
958 aFFWD.Orientation(TopAbs_FORWARD);
960 aS=BRep_Tool::Surface(aFFWD, aLoc);
961 bIsUPeriodic=GEOMAlgo_AlgoTools::IsUPeriodic(aS);
962 aTol=BRep_Tool::Tolerance(aFFWD);
963 BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
965 aBB.MakeFace (newFace, aS, aLoc, aTol);
967 aExpW.Init(aFFWD, TopAbs_WIRE);
968 for (; aExpW.More(); aExpW.Next()) {
969 aBB.MakeWire(newWire);
970 const TopoDS_Wire& aW=TopoDS::Wire(aExpW.Current());
971 aExpE.Init(aW, TopAbs_EDGE);
972 for (; aExpE.More(); aExpE.Next()) {
973 const TopoDS_Edge& aE=TopoDS::Edge(aExpE.Current());
974 aER=TopoDS::Edge(myOrigins.Find(aE));
976 aER.Orientation(TopAbs_FORWARD);
977 if (!BRep_Tool::Degenerated(aER)) {
980 GEOMAlgo_AlgoTools::RefinePCurveForEdgeOnFace(aER, aFFWD, aUMin, aUMax);
982 BOPTools_AlgoTools2D::BuildPCurveForEdgeOnFace(aER, aFFWD);
985 bIsToReverse=GEOMAlgo_AlgoTools::IsSplitToReverse(aER, aE, myContext);
991 aER.Orientation(aE.Orientation());
994 aBB.Add(newWire, aER);
997 TopTools_ListOfShape aLW;
1000 myImages.Bind(newWire, aLW);
1001 myOrigins.Bind(aW, newWire);
1003 aBB.Add(newFace, newWire);
1007 //=======================================================================
1008 //function : IsToReverse
1010 //=======================================================================
1011 Standard_Boolean GEOMAlgo_Gluer::IsToReverse(const TopoDS_Face& aFR,
1012 const TopoDS_Face& aF)
1014 Standard_Boolean bRet;
1015 Standard_Real aT, aT1, aT2, aTR, aScPr;
1016 TopExp_Explorer aExp;
1017 Handle(Geom_Curve)aC3D;
1021 bRet=Standard_False;
1023 aExp.Init(aF, TopAbs_EDGE);
1024 for (; aExp.More(); aExp.Next()) {
1025 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
1027 if (BRep_Tool::Degenerated(aE)) {
1031 const TopoDS_Edge& aER=TopoDS::Edge(myOrigins.Find(aE));
1033 aC3D=BRep_Tool::Curve(aE, aT1, aT2);
1034 aT=IntTools_Tools::IntermediatePoint(aT1, aT2);
1036 myContext->ProjectPointOnEdge(aP, aER, aTR);
1038 BOPTools_AlgoTools3D::GetNormalToFaceOnEdge (aE, aF, aT, aDNF);
1039 if (aF.Orientation()==TopAbs_REVERSED) {
1043 BOPTools_AlgoTools3D::GetNormalToFaceOnEdge (aER, aFR, aTR, aDNFR);
1044 if (aFR.Orientation()==TopAbs_REVERSED) {
1053 //=======================================================================
1054 //function : HasNewSubShape
1056 //=======================================================================
1057 Standard_Boolean GEOMAlgo_Gluer::HasNewSubShape(const TopoDS_Shape& aS)const
1059 Standard_Boolean bRet;
1060 Standard_Integer i, aNbSS;
1061 TopTools_IndexedMapOfShape aMSS;
1063 GetSubShapes(aS, aMSS);
1065 bRet=Standard_False;
1066 aNbSS=aMSS.Extent();
1067 for (i=1; i<=aNbSS; ++i) {
1068 const TopoDS_Shape& aSS=aMSS(i);
1069 if (aSS.ShapeType()==TopAbs_WIRE) {
1073 bRet=!myOrigins.IsBound(aSS);
1078 const TopoDS_Shape& aSSIm=myOrigins.Find(aSS);
1079 bRet=!aSSIm.IsSame(aSS);
1086 //=======================================================================
1087 //function : GetSubShapes
1089 //=======================================================================
1090 void GetSubShapes(const TopoDS_Shape& aS,
1091 TopTools_IndexedMapOfShape& aMSS)
1093 Standard_Integer aR;
1094 TopAbs_ShapeEnum aType;
1095 TopoDS_Iterator aIt;
1097 aType=aS.ShapeType();
1098 aR=(Standard_Integer)aType+1;
1099 if (aR>TopAbs_VERTEX) {
1104 for (; aIt.More(); aIt.Next()) {
1105 const TopoDS_Shape& aSS=aIt.Value();
1107 GetSubShapes(aSS, aMSS);
1110 //=======================================================================
1111 //function : Modified
1113 //=======================================================================
1114 const TopTools_ListOfShape& GEOMAlgo_Gluer::Modified (const TopoDS_Shape& aS)
1116 TopAbs_ShapeEnum aType;
1118 myGenerated.Clear();
1120 aType=aS.ShapeType();
1121 if (aType==TopAbs_VERTEX ||
1122 aType==TopAbs_EDGE ||
1123 aType==TopAbs_WIRE ||
1124 aType==TopAbs_FACE ||
1125 aType==TopAbs_SHELL ||
1126 aType==TopAbs_SOLID) {
1127 if(myOrigins.IsBound(aS)) {
1128 const TopoDS_Shape& aSnew=myOrigins.Find(aS);
1129 if (!aSnew.IsSame(aS)) {
1130 myGenerated.Append(aSnew);
1137 //=======================================================================
1138 //function : Generated
1140 //=======================================================================
1141 const TopTools_ListOfShape& GEOMAlgo_Gluer::Generated(const TopoDS_Shape& )
1143 myGenerated.Clear();
1146 //=======================================================================
1147 //function : IsDeleted
1149 //=======================================================================
1150 Standard_Boolean GEOMAlgo_Gluer::IsDeleted (const TopoDS_Shape& aS)
1152 Standard_Boolean bRet=Standard_False;
1154 const TopTools_ListOfShape& aL=Modified(aS);
1163 // 1 - the object is just initialized
1164 // 2 - no vertices found in source shape
1165 // 3 - nb same domain vertices for the vertex Vi =0
1166 // 4 - nb same domain edges(faces) for the edge Ei(face Fi) =0
1167 // 5 - source shape is Null
1168 // 6 - result shape is Null
1169 // 101 - nb edges > PassKey.NbMax() in FacesPassKey()
1170 // 102 - the edge Ei can not be found in myOrigins Map
1171 // 100 - the vertex Vi can not be found in myOrigins Map
1175 // 1 - some shapes can not be glued by faces