1 // Copyright (C) 2007-2021 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 #include <IntTools_Context.hxx>
82 #include <BOPTools_AlgoTools.hxx>
83 #include <BOPTools_AlgoTools3D.hxx>
84 #include <BOPTools_AlgoTools2D.hxx>
86 #include <GEOMAlgo_BoxBndTree.hxx>
87 #include <GEOMAlgo_AlgoTools.hxx>
88 #include <GEOMAlgo_IndexedDataMapOfIntegerShape.hxx>
89 #include <GEOMAlgo_IndexedDataMapOfShapeBox.hxx>
90 #include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx>
91 #include <GEOMAlgo_PassKeyShape.hxx>
92 #include <GEOMAlgo_BndSphereTree.hxx>
93 #include <GEOMAlgo_BndSphere.hxx>
94 #include <GEOMAlgo_IndexedDataMapOfShapeBndSphere.hxx>
98 void GetSubShapes(const TopoDS_Shape& aS,
99 TopTools_IndexedMapOfShape& aMSS);
101 //=======================================================================
102 //function : GEOMAlgo_Gluer
104 //=======================================================================
105 GEOMAlgo_Gluer::GEOMAlgo_Gluer()
111 myCheckGeometry=Standard_True;
112 myKeepNonSolids=Standard_False;
115 //=======================================================================
116 //function : ~GEOMAlgo_Gluer
118 //=======================================================================
119 GEOMAlgo_Gluer::~GEOMAlgo_Gluer()
122 //=======================================================================
123 //function : SetCheckGeometry
125 //=======================================================================
126 void GEOMAlgo_Gluer::SetCheckGeometry(const Standard_Boolean aFlag)
128 myCheckGeometry=aFlag;
130 //=======================================================================
131 //function : CheckGeometry
133 //=======================================================================
134 Standard_Boolean GEOMAlgo_Gluer::CheckGeometry() const
136 return myCheckGeometry;
138 //=======================================================================
139 //function : SetKeepNonSolids
141 //=======================================================================
142 void GEOMAlgo_Gluer::SetKeepNonSolids(const Standard_Boolean aFlag)
144 myKeepNonSolids=aFlag;
146 //=======================================================================
147 //function : KeepNonSolids
149 //=======================================================================
150 Standard_Boolean GEOMAlgo_Gluer::KeepNonSolids()const
152 return myKeepNonSolids;
154 //=======================================================================
155 //function : AloneShapes
157 //=======================================================================
158 Standard_Integer GEOMAlgo_Gluer::AloneShapes()const
162 //=======================================================================
165 //=======================================================================
166 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer::Images()const
170 //=======================================================================
173 //=======================================================================
174 const TopTools_DataMapOfShapeShape& GEOMAlgo_Gluer::Origins()const
178 //=======================================================================
181 //=======================================================================
182 void GEOMAlgo_Gluer::Perform()
184 const Standard_Integer aNb=8;
190 // Initialize the context
191 GEOMAlgo_ShapeAlgo::Perform();
193 void (GEOMAlgo_Gluer::* pF[aNb])()={
194 &GEOMAlgo_Gluer::CheckData, &GEOMAlgo_Gluer::InnerTolerance,
195 &GEOMAlgo_Gluer::MakeVertices, &GEOMAlgo_Gluer::MakeEdges,
196 &GEOMAlgo_Gluer::MakeFaces, &GEOMAlgo_Gluer::MakeShells,
197 &GEOMAlgo_Gluer::MakeSolids, &GEOMAlgo_Gluer::CheckResult
200 for (i=0; i<aNb; ++i) {
208 //=======================================================================
209 //function : MakeVertices
211 //=======================================================================
212 void GEOMAlgo_Gluer::MakeVertices()
216 Standard_Integer j, i, aNbV, aNbVSD;
219 TColStd_ListIteratorOfListOfInteger aIt;
222 TopTools_IndexedMapOfShape aMV, aMVProcessed;
223 TopTools_ListIteratorOfListOfShape aItS;
224 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
225 TopTools_DataMapOfShapeListOfShape aMVV;
226 GEOMAlgo_IndexedDataMapOfIntegerShape aMIS;
227 GEOMAlgo_IndexedDataMapOfShapeBndSphere aMSB;
229 GEOMAlgo_BndSphereTreeSelector aSelector;
230 GEOMAlgo_BndSphereTree aBBTree;
231 NCollection_UBTreeFiller <Standard_Integer, GEOMAlgo_BndSphere> aTreeFiller(aBBTree);
233 TopExp::MapShapes(myShape, TopAbs_VERTEX, aMV);
236 myErrorStatus=2; // no vertices in source shape
240 for (i=1; i<=aNbV; ++i) {
241 GEOMAlgo_BndSphere aBox;
243 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aMV(i));
244 aPV=BRep_Tool::Pnt(aV);
245 aTolV=BRep_Tool::Tolerance(aV);
249 aBox.SetRadius(aTolV);
251 aTreeFiller.Add(i, aBox);
259 //------------------------------
261 for (i=1; i<=aNbV; ++i) {
262 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aMV(i));
264 if (aMVProcessed.Contains(aV)) {
268 Standard_Integer aNbIP, aIP, aNbIP1, aIP1;
269 TopTools_ListOfShape aLVSD;
270 TColStd_MapOfInteger aMIP, aMIP1, aMIPC;
271 TColStd_MapIteratorOfMapOfInteger aIt1;
276 aIt1.Initialize(aMIP);
277 for(; aIt1.More(); aIt1.Next()) {
279 if (aMIPC.Contains(aIP)) {
283 const TopoDS_Shape& aVP=aMIS.FindFromKey(aIP);
284 const GEOMAlgo_BndSphere& aBoxVP=aMSB.FindFromKey(aVP);
287 aSelector.SetBox(aBoxVP);
289 aNbVSD=aBBTree.Select(aSelector);
291 continue; // it must not be
294 const TColStd_ListOfInteger& aLI=aSelector.Indices();
297 for (; aIt.More(); aIt.Next()) {
299 if (aMIP.Contains(aIP1)) {
303 } //for (; aIt.More(); aIt.Next()) {
304 }//for(; aIt1.More(); aIt1.Next()) {
306 aNbIP1=aMIP1.Extent();
311 aIt1.Initialize(aMIP);
312 for(; aIt1.More(); aIt1.Next()) {
318 aIt1.Initialize(aMIP1);
319 for(; aIt1.More(); aIt1.Next()) {
327 aNbIP=aMIPC.Extent();
329 if (!aNbIP) {// no SD vertices founded
332 aMVProcessed.Add(aV);
334 else { // SD vertices founded [ aMIPC ]
335 aIt1.Initialize(aMIPC);
336 for(j=0; aIt1.More(); aIt1.Next(), ++j) {
338 const TopoDS_Shape& aVP=aMIS.FindFromKey(aIP);
343 aMVProcessed.Add(aVP);
346 myImages.Bind(aVF, aLVSD);
347 }// for (i=1; i<=aNbV; ++i) {
348 //------------------------------
352 aItIm.Initialize(myImages);
353 for (; aItIm.More(); aItIm.Next()) {
354 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aItIm.Key());
355 const TopTools_ListOfShape& aLVSD=aItIm.Value();
356 aNbVSD=aLVSD.Extent();
359 MakeVertex(aLVSD, aVnew);
360 aMVV.Bind(aVnew, aLVSD);
364 // UnBind old vertices
366 for (i=1; i<=aNbV; ++i) {
367 const TopoDS_Shape& aV=aMV(i);
372 aItIm.Initialize(aMVV);
373 for (; aItIm.More(); aItIm.Next()) {
374 const TopoDS_Shape& aV=aItIm.Key();
375 const TopTools_ListOfShape& aLVSD=aItIm.Value();
376 myImages.Bind(aV, aLVSD);
380 aItIm.Initialize(myImages);
381 for (; aItIm.More(); aItIm.Next()) {
382 const TopoDS_Shape& aV=aItIm.Key();
383 const TopTools_ListOfShape& aLVSD=aItIm.Value();
384 aItS.Initialize(aLVSD);
385 for (; aItS.More(); aItS.Next()) {
386 const TopoDS_Shape& aVSD=aItS.Value();
387 if (!myOrigins.IsBound(aVSD)) {
388 myOrigins.Bind(aVSD, aV);
393 //=======================================================================
394 //function : MakeSubShapes
396 //=======================================================================
397 void GEOMAlgo_Gluer::MakeSubShapes (const TopoDS_Shape& theShape,
398 TopTools_MapOfShape& theMS,
399 TopoDS_Compound& theResult)
401 if (theMS.Contains(theShape))
408 if (theShape.ShapeType() == TopAbs_COMPOUND ||
409 theShape.ShapeType() == TopAbs_COMPSOLID) {
410 TopoDS_Iterator It (theShape, Standard_True, Standard_True);
411 for (; It.More(); It.Next()) {
412 MakeSubShapes(It.Value(), theMS, theResult);
415 else if (theShape.ShapeType() == TopAbs_SOLID) {
417 TopoDS_Solid aNewSolid;
418 TopExp_Explorer aExpS, aExp;
420 const TopoDS_Solid& aSolid = TopoDS::Solid(theShape);
422 TopAbs_Orientation anOr = aSolid.Orientation();
424 aBB.MakeSolid(aNewSolid);
425 aNewSolid.Orientation(anOr);
427 aExp.Init(aSolid, TopAbs_SHELL);
428 for (; aExp.More(); aExp.Next())
430 const TopoDS_Shape& aShell=aExp.Current();
431 const TopoDS_Shape& aShellR=myOrigins.Find(aShell);
432 aBB.Add(aNewSolid, aShellR);
435 TopTools_ListOfShape aLS;
438 myImages.Bind(aNewSolid, aLS);
439 myOrigins.Bind(aSolid, aNewSolid);
441 aBB.Add(theResult, aNewSolid);
443 else if (theShape.ShapeType() == TopAbs_WIRE) {
444 if (myKeepNonSolids) {
446 if (!myOrigins.IsBound(theShape)) {
448 const TopoDS_Wire& aW=TopoDS::Wire(theShape);
451 aBB.MakeWire(newWire);
453 TopExp_Explorer aExpE (aW, TopAbs_EDGE);
454 for (; aExpE.More(); aExpE.Next()) {
455 const TopoDS_Edge& aE=TopoDS::Edge(aExpE.Current());
456 TopoDS_Edge aER=TopoDS::Edge(myOrigins.Find(aE));
458 aER.Orientation(TopAbs_FORWARD);
459 if (!BRep_Tool::Degenerated(aER)) {
461 Standard_Boolean bIsToReverse=
462 GEOMAlgo_AlgoTools::IsSplitToReverse(aER, aE, myContext);
468 aER.Orientation(aE.Orientation());
471 aBB.Add(newWire, aER);
474 TopTools_ListOfShape aLW;
477 myImages.Bind(newWire, aLW);
478 myOrigins.Bind(aW, newWire);
480 const TopoDS_Shape& aShapeR = myOrigins.Find(theShape);
481 aBB.Add(theResult, aShapeR);
485 if (myKeepNonSolids) {
487 const TopoDS_Shape& aShapeR = myOrigins.Find(theShape);
488 aBB.Add(theResult, aShapeR);
492 //=======================================================================
493 //function : MakeSolids
495 //=======================================================================
496 void GEOMAlgo_Gluer::MakeSolids()
501 TopoDS_Compound aCmp;
502 TopTools_MapOfShape aMS;
504 aBB.MakeCompound(aCmp);
506 // Add images of all initial sub-shapes in the result.
507 // If myKeepNonSolids==false, add only solids images.
508 MakeSubShapes(myShape, aMS, aCmp);
513 TopTools_IndexedMapOfShape aMapToAvoid;
514 BOPTools_AlgoTools::CorrectCurveOnSurface(myResult, aMapToAvoid, 0.0001);
517 //=======================================================================
518 //function : MakeShells
520 //=======================================================================
521 void GEOMAlgo_Gluer::MakeShells()
525 Standard_Boolean bIsToReverse;
526 Standard_Integer i, aNbS;
527 TopAbs_Orientation anOr;
528 TopoDS_Shell aNewShell;
530 TopTools_IndexedMapOfShape aMS;
531 TopExp_Explorer aExp;
534 TopExp::MapShapes(myShape, TopAbs_SHELL, aMS);
537 for (i=1; i<=aNbS; ++i) {
538 const TopoDS_Shell& aShell=TopoDS::Shell(aMS(i));
539 anOr=aShell.Orientation();
541 aBB.MakeShell(aNewShell);
542 aNewShell.Orientation(anOr);
543 aExp.Init(aShell, TopAbs_FACE);
544 for (; aExp.More(); aExp.Next()) {
545 const TopoDS_Face& aF=TopoDS::Face(aExp.Current());
546 aFR=TopoDS::Face(myOrigins.Find(aF));
547 if (aFR.IsSame(aF)) {
548 aBB.Add(aNewShell, aF);
551 bIsToReverse=IsToReverse(aFR, aF);
555 aBB.Add(aNewShell, aFR);
558 TopTools_ListOfShape aLS;
561 myImages.Bind(aNewShell, aLS);
562 myOrigins.Bind(aShell, aNewShell);
565 //=======================================================================
566 //function : MakeFaces
568 //=======================================================================
569 void GEOMAlgo_Gluer::MakeFaces()
571 MakeShapes(TopAbs_FACE);
573 //=======================================================================
574 //function : MakeEdges
576 //=======================================================================
577 void GEOMAlgo_Gluer::MakeEdges()
579 MakeShapes(TopAbs_EDGE);
581 //=======================================================================
582 //function : MakeShapes
584 //=======================================================================
585 void GEOMAlgo_Gluer::MakeShapes(const TopAbs_ShapeEnum aType)
589 Standard_Boolean bHasNewSubShape;
590 Standard_Integer i, aNbF, aNbSDF, iErr;
591 TopoDS_Shape aNewShape;
592 TopTools_IndexedMapOfShape aMF;
593 TopTools_ListIteratorOfListOfShape aItS;
594 GEOMAlgo_PassKeyShape aPKF;
595 GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLF;
597 TopExp::MapShapes(myShape, aType, aMF);
600 for (i=1; i<=aNbF; ++i) {
601 const TopoDS_Shape& aS=aMF(i);
603 if (aType==TopAbs_FACE) {
604 const TopoDS_Face& aF=TopoDS::Face(aS);
605 FacePassKey(aF, aPKF);
607 else if (aType==TopAbs_EDGE) {
608 const TopoDS_Edge& aE=TopoDS::Edge(aS);
609 EdgePassKey(aE, aPKF);
616 if (aMPKLF.Contains(aPKF)) {
617 TopTools_ListOfShape& aLSDF=aMPKLF.ChangeFromKey(aPKF);
621 TopTools_ListOfShape aLSDF;
624 aMPKLF.Add(aPKF, aLSDF);
627 // check geometric coincidence
628 if (myCheckGeometry) {
629 iErr=GEOMAlgo_AlgoTools::RefineSDShapes(aMPKLF, myTol, myContext);
638 aNbF=aMPKLF.Extent();
639 for (i=1; i<=aNbF; ++i) {
640 const TopTools_ListOfShape& aLSDF=aMPKLF(i);
641 aNbSDF=aLSDF.Extent();
643 myErrorStatus=4; // it must not be
646 const TopoDS_Shape& aS1=aLSDF.First();
648 bHasNewSubShape=Standard_True;
649 // prevent creation of a new shape if there are not
650 // new sub-shapes of aSS among the originals
652 bHasNewSubShape=HasNewSubShape(aS1);
653 if (!bHasNewSubShape) {
655 aNewShape.Orientation(TopAbs_FORWARD);
659 if (bHasNewSubShape) {
660 if (aType==TopAbs_FACE) {
661 TopoDS_Face aNewFace;
663 const TopoDS_Face& aF1=TopoDS::Face(aS1);
664 MakeFace(aF1, aNewFace);
667 else if (aType==TopAbs_EDGE) {
668 TopoDS_Edge aNewEdge;
670 const TopoDS_Edge& aE1=TopoDS::Edge(aS1);
671 MakeEdge(aE1, aNewEdge);
676 myImages.Bind(aNewShape, aLSDF);
678 aItS.Initialize(aLSDF);
679 for (; aItS.More(); aItS.Next()) {
680 const TopoDS_Shape& aFSD=aItS.Value();
681 if (!myOrigins.IsBound(aFSD)) {
682 myOrigins.Bind(aFSD, aNewShape);
687 //=======================================================================
688 //function : CheckResult
690 //=======================================================================
691 void GEOMAlgo_Gluer::CheckResult()
695 if (myResult.IsNull()) {
700 Standard_Boolean bFound;
701 Standard_Integer i, j, aNbS, aNbFS, aNbSx;
702 TopTools_IndexedMapOfShape aMS, aMFS;
703 TopTools_IndexedDataMapOfShapeListOfShape aMFR;
705 TopExp::MapShapesAndAncestors(myResult, TopAbs_FACE, TopAbs_SOLID, aMFR);
706 TopExp::MapShapes(myResult, TopAbs_SOLID, aMS);
711 for (i=1; i<=aNbS; ++i) {
712 const TopoDS_Shape& aSolid=aMS(i);
715 TopExp::MapShapes(aSolid, TopAbs_FACE, aMFS);
717 bFound=Standard_False;
719 for (j=1; j<=aNbFS; ++j) {
720 const TopoDS_Shape& aFS=aMFS(j);
721 if (aMFR.Contains(aFS)) {
722 const TopTools_ListOfShape& aLSx=aMFR.FindFromKey(aFS);
738 //=======================================================================
739 //function : CheckData
741 //=======================================================================
742 void GEOMAlgo_Gluer::CheckData()
746 if (myShape.IsNull()) {
751 //=======================================================================
752 //function : InnerTolerance
754 //=======================================================================
755 void GEOMAlgo_Gluer::InnerTolerance()
761 Standard_Real aX[3][2], dH, dHmin, aCoef, aTolTresh;
764 BRepBndLib::Add(myShape, aBox);
765 aBox.Get(aX[0][0], aX[1][0], aX[2][0], aX[0][1], aX[1][1], aX[2][1]);
767 dHmin=aX[0][1]-aX[0][0];
768 for (i=1; i<3; ++i) {
769 dH=aX[i][1]-aX[i][0];
777 aTolTresh=aCoef*dHmin;
778 if (myTol>aTolTresh) {
784 //=======================================================================
785 //function : FacePassKey
787 //=======================================================================
788 void GEOMAlgo_Gluer::FacePassKey(const TopoDS_Face& aF,
789 GEOMAlgo_PassKeyShape& aPK)
791 Standard_Integer i, aNbE;
792 TopTools_ListOfShape aLE;
793 TopTools_IndexedMapOfShape aME;
795 TopExp::MapShapes(aF, TopAbs_EDGE, aME);
798 for (i=1; i<=aNbE; ++i) {
799 const TopoDS_Shape& aE=aME(i);
800 if (!myOrigins.IsBound(aE)) {
804 const TopoDS_Shape& aER=myOrigins.Find(aE);
809 //=======================================================================
810 //function : EdgePassKey
812 //=======================================================================
813 void GEOMAlgo_Gluer::EdgePassKey(const TopoDS_Edge& aE,
814 GEOMAlgo_PassKeyShape& aPK)
816 TopoDS_Vertex aV1, aV2;
818 TopExp::Vertices(aE, aV1, aV2);
820 if (!myOrigins.IsBound(aV1) || !myOrigins.IsBound(aV2) ) {
824 const TopoDS_Shape& aVR1=myOrigins.Find(aV1);
825 const TopoDS_Shape& aVR2=myOrigins.Find(aV2);
826 aPK.SetShapes(aVR1, aVR2);
828 //=======================================================================
829 //function : MakeVertex
831 //=======================================================================
832 void GEOMAlgo_Gluer::MakeVertex(const TopTools_ListOfShape& aLV,
833 TopoDS_Vertex& aNewVertex)
835 Standard_Integer aNbV;
836 Standard_Real aTolV, aD, aDmax;
841 TopTools_ListIteratorOfListOfShape aIt;
849 aGC.SetCoord(0.,0.,0.);
851 for (; aIt.More(); aIt.Next()) {
852 aVx=TopoDS::Vertex(aIt.Value());
853 aP3D=BRep_Tool::Pnt(aVx);
856 aGC/=(Standard_Real)aNbV;
862 for (; aIt.More(); aIt.Next()) {
863 aVx=TopoDS::Vertex(aIt.Value());
864 aP3D=BRep_Tool::Pnt(aVx);
865 aTolV=BRep_Tool::Tolerance(aVx);
866 aD=aPGC.Distance(aP3D)+aTolV;
872 aBB.MakeVertex (aNewVertex, aPGC, aDmax);
874 //=======================================================================
875 //function : MakeEdge
877 //=======================================================================
878 void GEOMAlgo_Gluer::MakeEdge(const TopoDS_Edge& aE,
879 TopoDS_Edge& aNewEdge)
883 Standard_Boolean bIsDE;
884 Standard_Real aT1, aT2;
885 TopoDS_Vertex aV1, aV2, aVR1, aVR2;
888 bIsDE=BRep_Tool::Degenerated(aE);
891 aEx.Orientation(TopAbs_FORWARD);
893 TopExp::Vertices(aEx, aV1, aV2);
895 aT1=BRep_Tool::Parameter(aV1, aEx);
896 aT2=BRep_Tool::Parameter(aV2, aEx);
898 aVR1=TopoDS::Vertex(myOrigins.Find(aV1));
899 aVR1.Orientation(TopAbs_FORWARD);
900 aVR2=TopoDS::Vertex(myOrigins.Find(aV2));
901 aVR2.Orientation(TopAbs_REVERSED);
907 //TopAbs_Orientation anOrE;
909 //anOrE=aE.Orientation();
910 aTol=BRep_Tool::Tolerance(aE);
917 aBB.Range(E, aT1, aT2);
918 aBB.Degenerated(E, Standard_True);
919 aBB.UpdateEdge(E, aTol);
925 BOPTools_AlgoTools::MakeSplitEdge(aEx, aVR1, aT1, aVR2, aT2, aNewEdge);
928 //=======================================================================
929 //function : MakeFace
931 //=======================================================================
932 void GEOMAlgo_Gluer::MakeFace(const TopoDS_Face& aF,
933 TopoDS_Face& aNewFace)
937 Standard_Boolean bIsToReverse, bIsUPeriodic;
938 Standard_Real aTol, aUMin, aUMax, aVMin, aVMax;
941 TopoDS_Face aFFWD, newFace;
942 TopLoc_Location aLoc;
943 Handle(Geom_Surface) aS;
944 Handle(Geom2d_Curve) aC2D;
945 TopExp_Explorer aExpW, aExpE;
949 aFFWD.Orientation(TopAbs_FORWARD);
951 aS=BRep_Tool::Surface(aFFWD, aLoc);
952 bIsUPeriodic=GEOMAlgo_AlgoTools::IsUPeriodic(aS);
953 aTol=BRep_Tool::Tolerance(aFFWD);
954 BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
956 aBB.MakeFace (newFace, aS, aLoc, aTol);
958 aExpW.Init(aFFWD, TopAbs_WIRE);
959 for (; aExpW.More(); aExpW.Next()) {
960 aBB.MakeWire(newWire);
961 const TopoDS_Wire& aW=TopoDS::Wire(aExpW.Current());
962 aExpE.Init(aW, TopAbs_EDGE);
963 for (; aExpE.More(); aExpE.Next()) {
964 const TopoDS_Edge& aE=TopoDS::Edge(aExpE.Current());
965 aER=TopoDS::Edge(myOrigins.Find(aE));
967 aER.Orientation(TopAbs_FORWARD);
968 if (!BRep_Tool::Degenerated(aER)) {
971 GEOMAlgo_AlgoTools::RefinePCurveForEdgeOnFace(aER, aFFWD, aUMin, aUMax);
973 BOPTools_AlgoTools2D::BuildPCurveForEdgeOnFace(aER, aFFWD);
976 bIsToReverse=GEOMAlgo_AlgoTools::IsSplitToReverse(aER, aE, myContext);
982 aER.Orientation(aE.Orientation());
985 aBB.Add(newWire, aER);
988 TopTools_ListOfShape aLW;
991 myImages.Bind(newWire, aLW);
992 myOrigins.Bind(aW, newWire);
994 aBB.Add(newFace, newWire);
998 //=======================================================================
999 //function : IsToReverse
1001 //=======================================================================
1002 Standard_Boolean GEOMAlgo_Gluer::IsToReverse(const TopoDS_Face& aFR,
1003 const TopoDS_Face& aF)
1005 Standard_Boolean bRet;
1006 Standard_Real aT, aT1, aT2, aTR, aScPr;
1007 TopExp_Explorer aExp;
1008 Handle(Geom_Curve)aC3D;
1012 bRet=Standard_False;
1014 aExp.Init(aF, TopAbs_EDGE);
1015 for (; aExp.More(); aExp.Next()) {
1016 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
1018 if (BRep_Tool::Degenerated(aE)) {
1022 const TopoDS_Edge& aER=TopoDS::Edge(myOrigins.Find(aE));
1024 aC3D=BRep_Tool::Curve(aE, aT1, aT2);
1025 aT=IntTools_Tools::IntermediatePoint(aT1, aT2);
1027 myContext->ProjectPointOnEdge(aP, aER, aTR);
1029 BOPTools_AlgoTools3D::GetNormalToFaceOnEdge (aE, aF, aT, aDNF);
1030 if (aF.Orientation()==TopAbs_REVERSED) {
1034 BOPTools_AlgoTools3D::GetNormalToFaceOnEdge (aER, aFR, aTR, aDNFR);
1035 if (aFR.Orientation()==TopAbs_REVERSED) {
1044 //=======================================================================
1045 //function : HasNewSubShape
1047 //=======================================================================
1048 Standard_Boolean GEOMAlgo_Gluer::HasNewSubShape(const TopoDS_Shape& aS)const
1050 Standard_Boolean bRet;
1051 Standard_Integer i, aNbSS;
1052 TopTools_IndexedMapOfShape aMSS;
1054 GetSubShapes(aS, aMSS);
1056 bRet=Standard_False;
1057 aNbSS=aMSS.Extent();
1058 for (i=1; i<=aNbSS; ++i) {
1059 const TopoDS_Shape& aSS=aMSS(i);
1060 if (aSS.ShapeType()==TopAbs_WIRE) {
1064 bRet=!myOrigins.IsBound(aSS);
1069 const TopoDS_Shape& aSSIm=myOrigins.Find(aSS);
1070 bRet=!aSSIm.IsSame(aSS);
1077 //=======================================================================
1078 //function : GetSubShapes
1080 //=======================================================================
1081 void GetSubShapes(const TopoDS_Shape& aS,
1082 TopTools_IndexedMapOfShape& aMSS)
1084 Standard_Integer aR;
1085 TopAbs_ShapeEnum aType;
1086 TopoDS_Iterator aIt;
1088 aType=aS.ShapeType();
1089 aR=(Standard_Integer)aType+1;
1090 if (aR>TopAbs_VERTEX) {
1095 for (; aIt.More(); aIt.Next()) {
1096 const TopoDS_Shape& aSS=aIt.Value();
1098 GetSubShapes(aSS, aMSS);
1101 //=======================================================================
1102 //function : Modified
1104 //=======================================================================
1105 const TopTools_ListOfShape& GEOMAlgo_Gluer::Modified
1106 (const TopoDS_Shape& aS)
1108 TopAbs_ShapeEnum aType;
1110 myGenerated.Clear();
1112 aType=aS.ShapeType();
1113 if (aType==TopAbs_VERTEX ||
1114 aType==TopAbs_EDGE ||
1115 aType==TopAbs_WIRE ||
1116 aType==TopAbs_FACE ||
1117 aType==TopAbs_SHELL ||
1118 aType==TopAbs_SOLID) {
1119 if(myOrigins.IsBound(aS)) {
1120 const TopoDS_Shape& aSnew=myOrigins.Find(aS);
1121 if (!aSnew.IsSame(aS)) {
1122 myGenerated.Append(aSnew);
1129 //=======================================================================
1130 //function : Generated
1132 //=======================================================================
1133 const TopTools_ListOfShape& GEOMAlgo_Gluer::Generated(const TopoDS_Shape& )
1135 myGenerated.Clear();
1138 //=======================================================================
1139 //function : IsDeleted
1141 //=======================================================================
1142 Standard_Boolean GEOMAlgo_Gluer::IsDeleted (const TopoDS_Shape& aS)
1144 Standard_Boolean bRet=Standard_False;
1146 const TopTools_ListOfShape& aL=Modified(aS);
1155 // 1 - the object is just initialized
1156 // 2 - no vertices found in source shape
1157 // 3 - nb same domain vertices for the vertex Vi =0
1158 // 4 - nb same domain edges(faces) for the edge Ei(face Fi) =0
1159 // 5 - source shape is Null
1160 // 6 - result shape is Null
1161 // 101 - nb edges > PassKey.NbMax() in FacesPassKey()
1162 // 102 - the edge Ei can not be found in myOrigins Map
1163 // 100 - the vertex Vi can not be found in myOrigins Map
1167 // 1 - some shapes can not be glued by faces