1 // Copyright (C) 2007-2016 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 <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_Tools.hxx>
79 #include <IntTools_Context.hxx>
80 #include <BOPTools_AlgoTools.hxx>
81 #include <BOPTools_AlgoTools3D.hxx>
82 #include <BOPTools_AlgoTools2D.hxx>
84 #include <GEOMAlgo_BoxBndTree.hxx>
85 #include <GEOMAlgo_AlgoTools.hxx>
86 #include <GEOMAlgo_IndexedDataMapOfIntegerShape.hxx>
87 #include <GEOMAlgo_IndexedDataMapOfShapeBox.hxx>
88 #include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx>
89 #include <GEOMAlgo_PassKeyShape.hxx>
90 #include <GEOMAlgo_BndSphereTree.hxx>
91 #include <GEOMAlgo_BndSphere.hxx>
92 #include <GEOMAlgo_IndexedDataMapOfShapeBndSphere.hxx>
96 void GetSubShapes(const TopoDS_Shape& aS,
97 TopTools_IndexedMapOfShape& aMSS);
99 //=======================================================================
100 //function : GEOMAlgo_Gluer
102 //=======================================================================
103 GEOMAlgo_Gluer::GEOMAlgo_Gluer()
109 myCheckGeometry=Standard_True;
110 myKeepNonSolids=Standard_False;
113 //=======================================================================
114 //function : ~GEOMAlgo_Gluer
116 //=======================================================================
117 GEOMAlgo_Gluer::~GEOMAlgo_Gluer()
120 //=======================================================================
121 //function : SetCheckGeometry
123 //=======================================================================
124 void GEOMAlgo_Gluer::SetCheckGeometry(const Standard_Boolean aFlag)
126 myCheckGeometry=aFlag;
128 //=======================================================================
129 //function : CheckGeometry
131 //=======================================================================
132 Standard_Boolean GEOMAlgo_Gluer::CheckGeometry() const
134 return myCheckGeometry;
136 //=======================================================================
137 //function : SetKeepNonSolids
139 //=======================================================================
140 void GEOMAlgo_Gluer::SetKeepNonSolids(const Standard_Boolean aFlag)
142 myKeepNonSolids=aFlag;
144 //=======================================================================
145 //function : KeepNonSolids
147 //=======================================================================
148 Standard_Boolean GEOMAlgo_Gluer::KeepNonSolids()const
150 return myKeepNonSolids;
152 //=======================================================================
153 //function : AloneShapes
155 //=======================================================================
156 Standard_Integer GEOMAlgo_Gluer::AloneShapes()const
160 //=======================================================================
163 //=======================================================================
164 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer::Images()const
168 //=======================================================================
171 //=======================================================================
172 const TopTools_DataMapOfShapeShape& GEOMAlgo_Gluer::Origins()const
176 //=======================================================================
179 //=======================================================================
180 void GEOMAlgo_Gluer::Perform()
182 const Standard_Integer aNb=8;
188 // Initialize the context
189 GEOMAlgo_ShapeAlgo::Perform();
191 void (GEOMAlgo_Gluer::* pF[aNb])()={
192 &GEOMAlgo_Gluer::CheckData, &GEOMAlgo_Gluer::InnerTolerance,
193 &GEOMAlgo_Gluer::MakeVertices, &GEOMAlgo_Gluer::MakeEdges,
194 &GEOMAlgo_Gluer::MakeFaces, &GEOMAlgo_Gluer::MakeShells,
195 &GEOMAlgo_Gluer::MakeSolids, &GEOMAlgo_Gluer::CheckResult
198 for (i=0; i<aNb; ++i) {
206 //=======================================================================
207 //function : MakeVertices
209 //=======================================================================
210 void GEOMAlgo_Gluer::MakeVertices()
214 Standard_Integer j, i, aNbV, aNbVSD;
217 TColStd_ListIteratorOfListOfInteger aIt;
220 TopTools_IndexedMapOfShape aMV, aMVProcessed;
221 TopTools_ListIteratorOfListOfShape aItS;
222 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
223 TopTools_DataMapOfShapeListOfShape aMVV;
224 GEOMAlgo_IndexedDataMapOfIntegerShape aMIS;
225 GEOMAlgo_IndexedDataMapOfShapeBndSphere aMSB;
227 GEOMAlgo_BndSphereTreeSelector aSelector;
228 GEOMAlgo_BndSphereTree aBBTree;
229 NCollection_UBTreeFiller <Standard_Integer, GEOMAlgo_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 GEOMAlgo_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 const GEOMAlgo_BndSphere& aBoxVP=aMSB.FindFromKey(aVP);
285 aSelector.SetBox(aBoxVP);
287 aNbVSD=aBBTree.Select(aSelector);
289 continue; // it must not be
292 const TColStd_ListOfInteger& aLI=aSelector.Indices();
295 for (; aIt.More(); aIt.Next()) {
297 if (aMIP.Contains(aIP1)) {
301 } //for (; aIt.More(); aIt.Next()) {
302 }//for(; aIt1.More(); aIt1.Next()) {
304 aNbIP1=aMIP1.Extent();
309 aIt1.Initialize(aMIP);
310 for(; aIt1.More(); aIt1.Next()) {
316 aIt1.Initialize(aMIP1);
317 for(; aIt1.More(); aIt1.Next()) {
325 aNbIP=aMIPC.Extent();
327 if (!aNbIP) {// no SD vertices founded
330 aMVProcessed.Add(aV);
332 else { // SD vertices founded [ aMIPC ]
333 aIt1.Initialize(aMIPC);
334 for(j=0; aIt1.More(); aIt1.Next(), ++j) {
336 const TopoDS_Shape& aVP=aMIS.FindFromKey(aIP);
341 aMVProcessed.Add(aVP);
344 myImages.Bind(aVF, aLVSD);
345 }// for (i=1; i<=aNbV; ++i) {
346 //------------------------------
350 aItIm.Initialize(myImages);
351 for (; aItIm.More(); aItIm.Next()) {
352 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aItIm.Key());
353 const TopTools_ListOfShape& aLVSD=aItIm.Value();
354 aNbVSD=aLVSD.Extent();
357 MakeVertex(aLVSD, aVnew);
358 aMVV.Bind(aVnew, aLVSD);
362 // UnBind old vertices
364 for (i=1; i<=aNbV; ++i) {
365 const TopoDS_Shape& aV=aMV(i);
370 aItIm.Initialize(aMVV);
371 for (; aItIm.More(); aItIm.Next()) {
372 const TopoDS_Shape& aV=aItIm.Key();
373 const TopTools_ListOfShape& aLVSD=aItIm.Value();
374 myImages.Bind(aV, aLVSD);
378 aItIm.Initialize(myImages);
379 for (; aItIm.More(); aItIm.Next()) {
380 const TopoDS_Shape& aV=aItIm.Key();
381 const TopTools_ListOfShape& aLVSD=aItIm.Value();
382 aItS.Initialize(aLVSD);
383 for (; aItS.More(); aItS.Next()) {
384 const TopoDS_Shape& aVSD=aItS.Value();
385 if (!myOrigins.IsBound(aVSD)) {
386 myOrigins.Bind(aVSD, aV);
391 //=======================================================================
392 //function : MakeSubShapes
394 //=======================================================================
395 void GEOMAlgo_Gluer::MakeSubShapes (const TopoDS_Shape& theShape,
396 TopTools_MapOfShape& theMS,
397 TopoDS_Compound& theResult)
399 if (theMS.Contains(theShape))
406 if (theShape.ShapeType() == TopAbs_COMPOUND ||
407 theShape.ShapeType() == TopAbs_COMPSOLID) {
408 TopoDS_Iterator It (theShape, Standard_True, Standard_True);
409 for (; It.More(); It.Next()) {
410 MakeSubShapes(It.Value(), theMS, theResult);
413 else if (theShape.ShapeType() == TopAbs_SOLID) {
415 TopoDS_Solid aNewSolid;
416 TopExp_Explorer aExpS, aExp;
418 const TopoDS_Solid& aSolid = TopoDS::Solid(theShape);
420 TopAbs_Orientation anOr = aSolid.Orientation();
422 aBB.MakeSolid(aNewSolid);
423 aNewSolid.Orientation(anOr);
425 aExp.Init(aSolid, TopAbs_SHELL);
426 for (; aExp.More(); aExp.Next())
428 const TopoDS_Shape& aShell=aExp.Current();
429 const TopoDS_Shape& aShellR=myOrigins.Find(aShell);
430 aBB.Add(aNewSolid, aShellR);
433 TopTools_ListOfShape aLS;
436 myImages.Bind(aNewSolid, aLS);
437 myOrigins.Bind(aSolid, aNewSolid);
439 aBB.Add(theResult, aNewSolid);
441 else if (theShape.ShapeType() == TopAbs_WIRE) {
442 if (myKeepNonSolids) {
444 if (!myOrigins.IsBound(theShape)) {
446 const TopoDS_Wire& aW=TopoDS::Wire(theShape);
449 aBB.MakeWire(newWire);
451 TopExp_Explorer aExpE (aW, TopAbs_EDGE);
452 for (; aExpE.More(); aExpE.Next()) {
453 const TopoDS_Edge& aE=TopoDS::Edge(aExpE.Current());
454 TopoDS_Edge aER=TopoDS::Edge(myOrigins.Find(aE));
456 aER.Orientation(TopAbs_FORWARD);
457 if (!BRep_Tool::Degenerated(aER)) {
459 Standard_Boolean bIsToReverse=
460 GEOMAlgo_AlgoTools::IsSplitToReverse(aER, aE, myContext);
466 aER.Orientation(aE.Orientation());
469 aBB.Add(newWire, aER);
472 TopTools_ListOfShape aLW;
475 myImages.Bind(newWire, aLW);
476 myOrigins.Bind(aW, newWire);
478 const TopoDS_Shape& aShapeR = myOrigins.Find(theShape);
479 aBB.Add(theResult, aShapeR);
483 if (myKeepNonSolids) {
485 const TopoDS_Shape& aShapeR = myOrigins.Find(theShape);
486 aBB.Add(theResult, aShapeR);
490 //=======================================================================
491 //function : MakeSolids
493 //=======================================================================
494 void GEOMAlgo_Gluer::MakeSolids()
499 TopoDS_Compound aCmp;
500 TopTools_MapOfShape aMS;
502 aBB.MakeCompound(aCmp);
504 // Add images of all initial sub-shapes in the result.
505 // If myKeepNonSolids==false, add only solids images.
506 MakeSubShapes(myShape, aMS, aCmp);
511 BOPTools_AlgoTools::CorrectCurveOnSurface(myResult, 0.0001);
514 //=======================================================================
515 //function : MakeShells
517 //=======================================================================
518 void GEOMAlgo_Gluer::MakeShells()
522 Standard_Boolean bIsToReverse;
523 Standard_Integer i, aNbS;
524 TopAbs_Orientation anOr;
525 TopoDS_Shell aNewShell;
527 TopTools_IndexedMapOfShape aMS;
528 TopExp_Explorer aExp;
531 TopExp::MapShapes(myShape, TopAbs_SHELL, aMS);
534 for (i=1; i<=aNbS; ++i) {
535 const TopoDS_Shell& aShell=TopoDS::Shell(aMS(i));
536 anOr=aShell.Orientation();
538 aBB.MakeShell(aNewShell);
539 aNewShell.Orientation(anOr);
540 aExp.Init(aShell, TopAbs_FACE);
541 for (; aExp.More(); aExp.Next()) {
542 const TopoDS_Face& aF=TopoDS::Face(aExp.Current());
543 aFR=TopoDS::Face(myOrigins.Find(aF));
544 if (aFR.IsSame(aF)) {
545 aBB.Add(aNewShell, aF);
548 bIsToReverse=IsToReverse(aFR, aF);
552 aBB.Add(aNewShell, aFR);
555 TopTools_ListOfShape aLS;
558 myImages.Bind(aNewShell, aLS);
559 myOrigins.Bind(aShell, aNewShell);
562 //=======================================================================
563 //function : MakeFaces
565 //=======================================================================
566 void GEOMAlgo_Gluer::MakeFaces()
568 MakeShapes(TopAbs_FACE);
570 //=======================================================================
571 //function : MakeEdges
573 //=======================================================================
574 void GEOMAlgo_Gluer::MakeEdges()
576 MakeShapes(TopAbs_EDGE);
578 //=======================================================================
579 //function : MakeShapes
581 //=======================================================================
582 void GEOMAlgo_Gluer::MakeShapes(const TopAbs_ShapeEnum aType)
586 Standard_Boolean bHasNewSubShape;
587 Standard_Integer i, aNbF, aNbSDF, iErr;
588 TopoDS_Shape aNewShape;
589 TopTools_IndexedMapOfShape aMF;
590 TopTools_ListIteratorOfListOfShape aItS;
591 GEOMAlgo_PassKeyShape aPKF;
592 GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLF;
594 TopExp::MapShapes(myShape, aType, aMF);
597 for (i=1; i<=aNbF; ++i) {
598 const TopoDS_Shape& aS=aMF(i);
600 if (aType==TopAbs_FACE) {
601 const TopoDS_Face& aF=TopoDS::Face(aS);
602 FacePassKey(aF, aPKF);
604 else if (aType==TopAbs_EDGE) {
605 const TopoDS_Edge& aE=TopoDS::Edge(aS);
606 EdgePassKey(aE, aPKF);
613 if (aMPKLF.Contains(aPKF)) {
614 TopTools_ListOfShape& aLSDF=aMPKLF.ChangeFromKey(aPKF);
618 TopTools_ListOfShape aLSDF;
621 aMPKLF.Add(aPKF, aLSDF);
624 // check geometric coincidence
625 if (myCheckGeometry) {
626 iErr=GEOMAlgo_AlgoTools::RefineSDShapes(aMPKLF, myTol, myContext);
635 aNbF=aMPKLF.Extent();
636 for (i=1; i<=aNbF; ++i) {
637 const TopTools_ListOfShape& aLSDF=aMPKLF(i);
638 aNbSDF=aLSDF.Extent();
640 myErrorStatus=4; // it must not be
643 const TopoDS_Shape& aS1=aLSDF.First();
645 bHasNewSubShape=Standard_True;
646 // prevent creation of a new shape if there are not
647 // new sub-shapes of aSS among the originals
649 bHasNewSubShape=HasNewSubShape(aS1);
650 if (!bHasNewSubShape) {
652 aNewShape.Orientation(TopAbs_FORWARD);
656 if (bHasNewSubShape) {
657 if (aType==TopAbs_FACE) {
658 TopoDS_Face aNewFace;
660 const TopoDS_Face& aF1=TopoDS::Face(aS1);
661 MakeFace(aF1, aNewFace);
664 else if (aType==TopAbs_EDGE) {
665 TopoDS_Edge aNewEdge;
667 const TopoDS_Edge& aE1=TopoDS::Edge(aS1);
668 MakeEdge(aE1, aNewEdge);
673 myImages.Bind(aNewShape, aLSDF);
675 aItS.Initialize(aLSDF);
676 for (; aItS.More(); aItS.Next()) {
677 const TopoDS_Shape& aFSD=aItS.Value();
678 if (!myOrigins.IsBound(aFSD)) {
679 myOrigins.Bind(aFSD, aNewShape);
684 //=======================================================================
685 //function : CheckResult
687 //=======================================================================
688 void GEOMAlgo_Gluer::CheckResult()
692 if (myResult.IsNull()) {
697 Standard_Boolean bFound;
698 Standard_Integer i, j, aNbS, aNbFS, aNbSx;
699 TopTools_IndexedMapOfShape aMS, aMFS;
700 TopTools_IndexedDataMapOfShapeListOfShape aMFR;
702 TopExp::MapShapesAndAncestors(myResult, TopAbs_FACE, TopAbs_SOLID, aMFR);
703 TopExp::MapShapes(myResult, TopAbs_SOLID, aMS);
708 for (i=1; i<=aNbS; ++i) {
709 const TopoDS_Shape& aSolid=aMS(i);
712 TopExp::MapShapes(aSolid, TopAbs_FACE, aMFS);
714 bFound=Standard_False;
716 for (j=1; j<=aNbFS; ++j) {
717 const TopoDS_Shape& aFS=aMFS(j);
718 if (aMFR.Contains(aFS)) {
719 const TopTools_ListOfShape& aLSx=aMFR.FindFromKey(aFS);
735 //=======================================================================
736 //function : CheckData
738 //=======================================================================
739 void GEOMAlgo_Gluer::CheckData()
743 if (myShape.IsNull()) {
748 //=======================================================================
749 //function : InnerTolerance
751 //=======================================================================
752 void GEOMAlgo_Gluer::InnerTolerance()
758 Standard_Real aX[3][2], dH, dHmin, aCoef, aTolTresh;
761 BRepBndLib::Add(myShape, aBox);
762 aBox.Get(aX[0][0], aX[1][0], aX[2][0], aX[0][1], aX[1][1], aX[2][1]);
764 dHmin=aX[0][1]-aX[0][0];
765 for (i=1; i<3; ++i) {
766 dH=aX[i][1]-aX[i][0];
774 aTolTresh=aCoef*dHmin;
775 if (myTol>aTolTresh) {
781 //=======================================================================
782 //function : FacePassKey
784 //=======================================================================
785 void GEOMAlgo_Gluer::FacePassKey(const TopoDS_Face& aF,
786 GEOMAlgo_PassKeyShape& aPK)
788 Standard_Integer i, aNbE;
789 TopTools_ListOfShape aLE;
790 TopTools_IndexedMapOfShape aME;
792 TopExp::MapShapes(aF, TopAbs_EDGE, aME);
795 for (i=1; i<=aNbE; ++i) {
796 const TopoDS_Shape& aE=aME(i);
797 if (!myOrigins.IsBound(aE)) {
801 const TopoDS_Shape& aER=myOrigins.Find(aE);
806 //=======================================================================
807 //function : EdgePassKey
809 //=======================================================================
810 void GEOMAlgo_Gluer::EdgePassKey(const TopoDS_Edge& aE,
811 GEOMAlgo_PassKeyShape& aPK)
813 TopoDS_Vertex aV1, aV2;
815 TopExp::Vertices(aE, aV1, aV2);
817 if (!myOrigins.IsBound(aV1) || !myOrigins.IsBound(aV2) ) {
821 const TopoDS_Shape& aVR1=myOrigins.Find(aV1);
822 const TopoDS_Shape& aVR2=myOrigins.Find(aV2);
823 aPK.SetShapes(aVR1, aVR2);
825 //=======================================================================
826 //function : MakeVertex
828 //=======================================================================
829 void GEOMAlgo_Gluer::MakeVertex(const TopTools_ListOfShape& aLV,
830 TopoDS_Vertex& aNewVertex)
832 Standard_Integer aNbV;
833 Standard_Real aTolV, aD, aDmax;
838 TopTools_ListIteratorOfListOfShape aIt;
846 aGC.SetCoord(0.,0.,0.);
848 for (; aIt.More(); aIt.Next()) {
849 aVx=TopoDS::Vertex(aIt.Value());
850 aP3D=BRep_Tool::Pnt(aVx);
853 aGC/=(Standard_Real)aNbV;
859 for (; aIt.More(); aIt.Next()) {
860 aVx=TopoDS::Vertex(aIt.Value());
861 aP3D=BRep_Tool::Pnt(aVx);
862 aTolV=BRep_Tool::Tolerance(aVx);
863 aD=aPGC.Distance(aP3D)+aTolV;
869 aBB.MakeVertex (aNewVertex, aPGC, aDmax);
871 //=======================================================================
872 //function : MakeEdge
874 //=======================================================================
875 void GEOMAlgo_Gluer::MakeEdge(const TopoDS_Edge& aE,
876 TopoDS_Edge& aNewEdge)
880 Standard_Boolean bIsDE;
881 Standard_Real aT1, aT2;
882 TopoDS_Vertex aV1, aV2, aVR1, aVR2;
885 bIsDE=BRep_Tool::Degenerated(aE);
888 aEx.Orientation(TopAbs_FORWARD);
890 TopExp::Vertices(aEx, aV1, aV2);
892 aT1=BRep_Tool::Parameter(aV1, aEx);
893 aT2=BRep_Tool::Parameter(aV2, aEx);
895 aVR1=TopoDS::Vertex(myOrigins.Find(aV1));
896 aVR1.Orientation(TopAbs_FORWARD);
897 aVR2=TopoDS::Vertex(myOrigins.Find(aV2));
898 aVR2.Orientation(TopAbs_REVERSED);
904 TopAbs_Orientation anOrE;
906 anOrE=aE.Orientation();
907 aTol=BRep_Tool::Tolerance(aE);
914 aBB.Range(E, aT1, aT2);
915 aBB.Degenerated(E, Standard_True);
916 aBB.UpdateEdge(E, aTol);
922 BOPTools_AlgoTools::MakeSplitEdge(aEx, aVR1, aT1, aVR2, aT2, aNewEdge);
925 //=======================================================================
926 //function : MakeFace
928 //=======================================================================
929 void GEOMAlgo_Gluer::MakeFace(const TopoDS_Face& aF,
930 TopoDS_Face& aNewFace)
934 Standard_Boolean bIsToReverse, bIsUPeriodic;
935 Standard_Real aTol, aUMin, aUMax, aVMin, aVMax;
938 TopoDS_Face aFFWD, newFace;
939 TopLoc_Location aLoc;
940 Handle(Geom_Surface) aS;
941 Handle(Geom2d_Curve) aC2D;
942 TopExp_Explorer aExpW, aExpE;
946 aFFWD.Orientation(TopAbs_FORWARD);
948 aS=BRep_Tool::Surface(aFFWD, aLoc);
949 bIsUPeriodic=GEOMAlgo_AlgoTools::IsUPeriodic(aS);
950 aTol=BRep_Tool::Tolerance(aFFWD);
951 BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
953 aBB.MakeFace (newFace, aS, aLoc, aTol);
955 aExpW.Init(aFFWD, TopAbs_WIRE);
956 for (; aExpW.More(); aExpW.Next()) {
957 aBB.MakeWire(newWire);
958 const TopoDS_Wire& aW=TopoDS::Wire(aExpW.Current());
959 aExpE.Init(aW, TopAbs_EDGE);
960 for (; aExpE.More(); aExpE.Next()) {
961 const TopoDS_Edge& aE=TopoDS::Edge(aExpE.Current());
962 aER=TopoDS::Edge(myOrigins.Find(aE));
964 aER.Orientation(TopAbs_FORWARD);
965 if (!BRep_Tool::Degenerated(aER)) {
968 GEOMAlgo_AlgoTools::RefinePCurveForEdgeOnFace(aER, aFFWD, aUMin, aUMax);
970 BOPTools_AlgoTools2D::BuildPCurveForEdgeOnFace(aER, aFFWD);
973 bIsToReverse=GEOMAlgo_AlgoTools::IsSplitToReverse(aER, aE, myContext);
979 aER.Orientation(aE.Orientation());
982 aBB.Add(newWire, aER);
985 TopTools_ListOfShape aLW;
988 myImages.Bind(newWire, aLW);
989 myOrigins.Bind(aW, newWire);
991 aBB.Add(newFace, newWire);
995 //=======================================================================
996 //function : IsToReverse
998 //=======================================================================
999 Standard_Boolean GEOMAlgo_Gluer::IsToReverse(const TopoDS_Face& aFR,
1000 const TopoDS_Face& aF)
1002 Standard_Boolean bRet;
1003 Standard_Real aT, aT1, aT2, aTR, aScPr;
1004 TopExp_Explorer aExp;
1005 Handle(Geom_Curve)aC3D;
1009 bRet=Standard_False;
1011 aExp.Init(aF, TopAbs_EDGE);
1012 for (; aExp.More(); aExp.Next()) {
1013 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
1015 if (BRep_Tool::Degenerated(aE)) {
1019 const TopoDS_Edge& aER=TopoDS::Edge(myOrigins.Find(aE));
1021 aC3D=BRep_Tool::Curve(aE, aT1, aT2);
1022 aT=IntTools_Tools::IntermediatePoint(aT1, aT2);
1024 myContext->ProjectPointOnEdge(aP, aER, aTR);
1026 BOPTools_AlgoTools3D::GetNormalToFaceOnEdge (aE, aF, aT, aDNF);
1027 if (aF.Orientation()==TopAbs_REVERSED) {
1031 BOPTools_AlgoTools3D::GetNormalToFaceOnEdge (aER, aFR, aTR, aDNFR);
1032 if (aFR.Orientation()==TopAbs_REVERSED) {
1041 //=======================================================================
1042 //function : HasNewSubShape
1044 //=======================================================================
1045 Standard_Boolean GEOMAlgo_Gluer::HasNewSubShape(const TopoDS_Shape& aS)const
1047 Standard_Boolean bRet;
1048 Standard_Integer i, aNbSS;
1049 TopTools_IndexedMapOfShape aMSS;
1051 GetSubShapes(aS, aMSS);
1053 bRet=Standard_False;
1054 aNbSS=aMSS.Extent();
1055 for (i=1; i<=aNbSS; ++i) {
1056 const TopoDS_Shape& aSS=aMSS(i);
1057 if (aSS.ShapeType()==TopAbs_WIRE) {
1061 bRet=!myOrigins.IsBound(aSS);
1066 const TopoDS_Shape& aSSIm=myOrigins.Find(aSS);
1067 bRet=!aSSIm.IsSame(aSS);
1074 //=======================================================================
1075 //function : GetSubShapes
1077 //=======================================================================
1078 void GetSubShapes(const TopoDS_Shape& aS,
1079 TopTools_IndexedMapOfShape& aMSS)
1081 Standard_Integer aR;
1082 TopAbs_ShapeEnum aType;
1083 TopoDS_Iterator aIt;
1085 aType=aS.ShapeType();
1086 aR=(Standard_Integer)aType+1;
1087 if (aR>TopAbs_VERTEX) {
1092 for (; aIt.More(); aIt.Next()) {
1093 const TopoDS_Shape& aSS=aIt.Value();
1095 GetSubShapes(aSS, aMSS);
1098 //=======================================================================
1099 //function : Modified
1101 //=======================================================================
1102 const TopTools_ListOfShape& GEOMAlgo_Gluer::Modified
1103 (const TopoDS_Shape& aS)
1105 TopAbs_ShapeEnum aType;
1107 myGenerated.Clear();
1109 aType=aS.ShapeType();
1110 if (aType==TopAbs_VERTEX ||
1111 aType==TopAbs_EDGE ||
1112 aType==TopAbs_WIRE ||
1113 aType==TopAbs_FACE ||
1114 aType==TopAbs_SHELL ||
1115 aType==TopAbs_SOLID) {
1116 if(myOrigins.IsBound(aS)) {
1117 const TopoDS_Shape& aSnew=myOrigins.Find(aS);
1118 if (!aSnew.IsSame(aS)) {
1119 myGenerated.Append(aSnew);
1126 //=======================================================================
1127 //function : Generated
1129 //=======================================================================
1130 const TopTools_ListOfShape& GEOMAlgo_Gluer::Generated(const TopoDS_Shape& )
1132 myGenerated.Clear();
1135 //=======================================================================
1136 //function : IsDeleted
1138 //=======================================================================
1139 Standard_Boolean GEOMAlgo_Gluer::IsDeleted (const TopoDS_Shape& aS)
1141 Standard_Boolean bRet=Standard_False;
1143 const TopTools_ListOfShape& aL=Modified(aS);
1152 // 1 - the object is just initialized
1153 // 2 - no vertices found in source shape
1154 // 3 - nb same domain vertices for the vertex Vi =0
1155 // 4 - nb same domain edges(faces) for the edge Ei(face Fi) =0
1156 // 5 - source shape is Null
1157 // 6 - result shape is Null
1158 // 101 - nb edges > PassKey.NbMax() in FacesPassKey()
1159 // 102 - the edge Ei can not be found in myOrigins Map
1160 // 100 - the vertex Vi can not be found in myOrigins Map
1164 // 1 - some shapes can not be glued by faces