1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: GEOMAlgo_Gluer.cxx
21 // Created: Sat Dec 04 12:45:53 2004
22 // Author: Peter KURNEV
26 #include <GEOMAlgo_Gluer.ixx>
28 #include <NMTDS_BoxBndTree.hxx>
29 #include <NCollection_UBTreeFiller.hxx>
31 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
32 #include <TColStd_MapOfInteger.hxx>
33 #include <TColStd_ListOfInteger.hxx>
34 #include <TColStd_ListIteratorOfListOfInteger.hxx>
40 #include <Geom_Curve.hxx>
41 #include <Geom_Surface.hxx>
43 #include <Bnd_Box.hxx>
44 #include <Bnd_HArray1OfBox.hxx>
45 #include <Bnd_BoundSortBox.hxx>
47 #include <TopLoc_Location.hxx>
48 #include <TopAbs_ShapeEnum.hxx>
49 #include <TopAbs_Orientation.hxx>
52 #include <TopoDS_Edge.hxx>
53 #include <TopoDS_Vertex.hxx>
54 #include <TopoDS_Shape.hxx>
55 #include <TopoDS_Compound.hxx>
56 #include <TopoDS_Wire.hxx>
57 #include <TopoDS_Shell.hxx>
58 #include <TopoDS_Solid.hxx>
59 #include <TopoDS_Iterator.hxx>
61 #include <TopTools_IndexedMapOfShape.hxx>
62 #include <TopTools_ListOfShape.hxx>
63 #include <TopTools_ListIteratorOfListOfShape.hxx>
64 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
65 #include <TopTools_MapOfShape.hxx>
66 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
69 #include <TopExp_Explorer.hxx>
71 #include <BRep_Tool.hxx>
72 #include <BRep_Builder.hxx>
73 #include <BRepLib.hxx>
74 #include <BRepTools.hxx>
75 #include <BRepBndLib.hxx>
77 #include <IntTools_Context.hxx>
78 #include <BOPTools_Tools.hxx>
79 #include <BOPTools_Tools3D.hxx>
80 #include <BOPTools_Tools2D.hxx>
81 #include <BOP_CorrectTolerances.hxx>
83 #include <GEOMAlgo_IndexedDataMapOfIntegerShape.hxx>
84 #include <GEOMAlgo_IndexedDataMapOfShapeBox.hxx>
85 #include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx>
86 #include <GEOMAlgo_PassKeyShape.hxx>
87 #include <GEOMAlgo_Tools.hxx>
91 void GetSubShapes(const TopoDS_Shape& aS,
92 TopTools_IndexedMapOfShape& aMSS);
94 //=======================================================================
95 //function : GEOMAlgo_Gluer
97 //=======================================================================
98 GEOMAlgo_Gluer::GEOMAlgo_Gluer()
104 myCheckGeometry=Standard_True;
105 myKeepNonSolids=Standard_False;
108 //=======================================================================
109 //function : ~GEOMAlgo_Gluer
111 //=======================================================================
112 GEOMAlgo_Gluer::~GEOMAlgo_Gluer()
115 //=======================================================================
116 //function : SetCheckGeometry
118 //=======================================================================
119 void GEOMAlgo_Gluer::SetCheckGeometry(const Standard_Boolean aFlag)
121 myCheckGeometry=aFlag;
123 //=======================================================================
124 //function : CheckGeometry
126 //=======================================================================
127 Standard_Boolean GEOMAlgo_Gluer::CheckGeometry() const
129 return myCheckGeometry;
131 //=======================================================================
132 //function : SetKeepNonSolids
134 //=======================================================================
135 void GEOMAlgo_Gluer::SetKeepNonSolids(const Standard_Boolean aFlag)
137 myKeepNonSolids=aFlag;
139 //=======================================================================
140 //function : AloneShapes
142 //=======================================================================
143 Standard_Integer GEOMAlgo_Gluer::AloneShapes()const
147 //=======================================================================
150 //=======================================================================
151 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer::Images()const
155 //=======================================================================
158 //=======================================================================
159 const TopTools_DataMapOfShapeShape& GEOMAlgo_Gluer::Origins()const
163 //=======================================================================
166 //=======================================================================
167 void GEOMAlgo_Gluer::Perform()
173 const Standard_Integer aNb=8;
174 void (GEOMAlgo_Gluer::* pF[aNb])()={
175 &GEOMAlgo_Gluer::CheckData, &GEOMAlgo_Gluer::InnerTolerance,
176 &GEOMAlgo_Gluer::MakeVertices, &GEOMAlgo_Gluer::MakeEdges,
177 &GEOMAlgo_Gluer::MakeFaces, &GEOMAlgo_Gluer::MakeShells,
178 &GEOMAlgo_Gluer::MakeSolids, &GEOMAlgo_Gluer::CheckResult
181 for (i=0; i<aNb; ++i) {
188 //=======================================================================
189 //function : MakeVertices
191 //=======================================================================
192 void GEOMAlgo_Gluer::MakeVertices()
196 Standard_Integer j, i, aNbV, aNbVSD;
197 TColStd_ListIteratorOfListOfInteger aIt;
200 TopTools_IndexedMapOfShape aMV, aMVProcessed;
201 TopTools_ListIteratorOfListOfShape aItS;
202 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
203 TopTools_DataMapOfShapeListOfShape aMVV;
204 GEOMAlgo_IndexedDataMapOfIntegerShape aMIS;
205 GEOMAlgo_IndexedDataMapOfShapeBox aMSB;
207 NMTDS_BoxBndTreeSelector aSelector;
208 NMTDS_BoxBndTree aBBTree;
209 NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
212 TopExp::MapShapes(myShape, TopAbs_VERTEX, aMV);
215 myErrorStatus=2; // no vertices in source shape
219 for (i=1; i<=aNbV; ++i) {
220 const TopoDS_Shape& aV=aMV(i);
224 BRepBndLib::Add(aV, aBox);
226 aTreeFiller.Add(i, aBox);
234 //------------------------------
236 for (i=1; i<=aNbV; ++i) {
237 const TopoDS_Shape& aV=aMV(i);
239 if (aMVProcessed.Contains(aV)) {
243 Standard_Integer aNbIP, aIP, aNbIP1, aIP1;
244 TopTools_ListOfShape aLVSD;
245 TColStd_MapOfInteger aMIP, aMIP1, aMIPC;
246 TColStd_MapIteratorOfMapOfInteger aIt1;
251 aIt1.Initialize(aMIP);
252 for(; aIt1.More(); aIt1.Next()) {
254 if (aMIPC.Contains(aIP)) {
258 const TopoDS_Shape& aVP=aMIS.FindFromKey(aIP);
259 const Bnd_Box& aBoxVP=aMSB.FindFromKey(aVP);
262 aSelector.SetBox(aBoxVP);
264 aNbVSD=aBBTree.Select(aSelector);
266 continue; // it must not be
269 const TColStd_ListOfInteger& aLI=aSelector.Indices();
271 for (; aIt.More(); aIt.Next()) {
273 if (aMIP.Contains(aIP1)) {
277 } //for (; aIt.More(); aIt.Next()) {
278 }//for(; aIt1.More(); aIt1.Next()) {
280 aNbIP1=aMIP1.Extent();
285 aIt1.Initialize(aMIP);
286 for(; aIt1.More(); aIt1.Next()) {
292 aIt1.Initialize(aMIP1);
293 for(; aIt1.More(); aIt1.Next()) {
301 aNbIP=aMIPC.Extent();
303 if (!aNbIP) {// no SD vertices founded
306 aMVProcessed.Add(aV);
308 else { // SD vertices founded [ aMIPC ]
309 aIt1.Initialize(aMIPC);
310 for(j=0; aIt1.More(); aIt1.Next(), ++j) {
312 const TopoDS_Shape& aVP=aMIS.FindFromKey(aIP);
317 aMVProcessed.Add(aVP);
320 myImages.Bind(aVF, aLVSD);
321 }// for (i=1; i<=aNbV; ++i) {
322 //------------------------------
326 aItIm.Initialize(myImages);
327 for (; aItIm.More(); aItIm.Next()) {
328 const TopoDS_Shape& aV=aItIm.Key();
329 const TopTools_ListOfShape& aLVSD=aItIm.Value();
330 aNbVSD=aLVSD.Extent();
333 MakeVertex(aLVSD, aVnew);
334 aMVV.Bind(aVnew, aLVSD);
338 // UnBind old vertices
340 for (i=1; i<=aNbV; ++i) {
341 const TopoDS_Shape& aV=aMV(i);
346 aItIm.Initialize(aMVV);
347 for (; aItIm.More(); aItIm.Next()) {
348 const TopoDS_Shape& aV=aItIm.Key();
349 const TopTools_ListOfShape& aLVSD=aItIm.Value();
350 myImages.Bind(aV, aLVSD);
354 aItIm.Initialize(myImages);
355 for (; aItIm.More(); aItIm.Next()) {
356 const TopoDS_Shape& aV=aItIm.Key();
357 const TopTools_ListOfShape& aLVSD=aItIm.Value();
358 aItS.Initialize(aLVSD);
359 for (; aItS.More(); aItS.Next()) {
360 const TopoDS_Shape& aVSD=aItS.Value();
361 if (!myOrigins.IsBound(aVSD)) {
362 myOrigins.Bind(aVSD, aV);
367 //=======================================================================
368 //function : MakeSubShapes
370 //=======================================================================
371 void GEOMAlgo_Gluer::MakeSubShapes (const TopoDS_Shape& theShape,
372 TopTools_MapOfShape& theMS,
373 TopoDS_Compound& theResult)
375 if (theMS.Contains(theShape))
382 if (theShape.ShapeType() == TopAbs_COMPOUND ||
383 theShape.ShapeType() == TopAbs_COMPSOLID)
385 TopoDS_Iterator It (theShape, Standard_True, Standard_True);
386 for (; It.More(); It.Next())
388 MakeSubShapes(It.Value(), theMS, theResult);
391 else if (theShape.ShapeType() == TopAbs_SOLID)
394 TopoDS_Solid aNewSolid;
395 TopExp_Explorer aExpS, aExp;
397 const TopoDS_Solid& aSolid = TopoDS::Solid(theShape);
399 TopAbs_Orientation anOr = aSolid.Orientation();
401 aBB.MakeSolid(aNewSolid);
402 aNewSolid.Orientation(anOr);
404 aExp.Init(aSolid, TopAbs_SHELL);
405 for (; aExp.More(); aExp.Next())
407 const TopoDS_Shape& aShell=aExp.Current();
408 const TopoDS_Shape& aShellR=myOrigins.Find(aShell);
409 aBB.Add(aNewSolid, aShellR);
412 TopTools_ListOfShape aLS;
415 myImages.Bind(aNewSolid, aLS);
416 myOrigins.Bind(aSolid, aNewSolid);
418 aBB.Add(theResult, aNewSolid);
420 else if (theShape.ShapeType() == TopAbs_WIRE)
425 if (!myOrigins.IsBound(theShape))
428 const TopoDS_Wire& aW=TopoDS::Wire(theShape);
431 aBB.MakeWire(newWire);
433 TopExp_Explorer aExpE (aW, TopAbs_EDGE);
434 for (; aExpE.More(); aExpE.Next()) {
435 const TopoDS_Edge& aE=TopoDS::Edge(aExpE.Current());
436 TopoDS_Edge aER=TopoDS::Edge(myOrigins.Find(aE));
438 aER.Orientation(TopAbs_FORWARD);
439 if (!BRep_Tool::Degenerated(aER)) {
441 //if (bIsUPeriodic) {
442 // GEOMAlgo_Tools::RefinePCurveForEdgeOnFace(aER, aFFWD, aUMin, aUMax);
444 //BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aER, aFFWD);
447 Standard_Boolean bIsToReverse=BOPTools_Tools3D::IsSplitToReverse1(aER, aE, myContext);
453 aER.Orientation(aE.Orientation());
456 aBB.Add(newWire, aER);
459 TopTools_ListOfShape aLW;
462 myImages.Bind(newWire, aLW);
463 myOrigins.Bind(aW, newWire);
465 const TopoDS_Shape& aShapeR = myOrigins.Find(theShape);
466 aBB.Add(theResult, aShapeR);
474 const TopoDS_Shape& aShapeR = myOrigins.Find(theShape);
475 aBB.Add(theResult, aShapeR);
479 //=======================================================================
480 //function : MakeSolids
482 //=======================================================================
483 void GEOMAlgo_Gluer::MakeSolids()
488 TopoDS_Compound aCmp;
489 TopTools_MapOfShape aMS;
491 aBB.MakeCompound(aCmp);
493 // Add images of all initial sub-shapes in the result.
494 // If myKeepNonSolids==false, add only solids images.
495 MakeSubShapes(myShape, aMS, aCmp);
500 BOP_CorrectTolerances::CorrectCurveOnSurface(myResult);
503 //=======================================================================
504 //function : MakeShells
506 //=======================================================================
507 void GEOMAlgo_Gluer::MakeShells()
511 Standard_Boolean bIsToReverse;
512 Standard_Integer i, aNbS;
513 TopAbs_Orientation anOr;
514 TopoDS_Shell aNewShell;
516 TopTools_IndexedMapOfShape aMS;
517 TopExp_Explorer aExp;
520 TopExp::MapShapes(myShape, TopAbs_SHELL, aMS);
523 for (i=1; i<=aNbS; ++i) {
524 const TopoDS_Shell& aShell=TopoDS::Shell(aMS(i));
525 anOr=aShell.Orientation();
527 aBB.MakeShell(aNewShell);
528 aNewShell.Orientation(anOr);
529 aExp.Init(aShell, TopAbs_FACE);
530 for (; aExp.More(); aExp.Next()) {
531 const TopoDS_Face& aF=TopoDS::Face(aExp.Current());
532 aFR=TopoDS::Face(myOrigins.Find(aF));
533 if (aFR.IsSame(aF)) {
534 aBB.Add(aNewShell, aF);
537 bIsToReverse=IsToReverse(aFR, aF);
541 aBB.Add(aNewShell, aFR);
544 TopTools_ListOfShape aLS;
547 myImages.Bind(aNewShell, aLS);
548 myOrigins.Bind(aShell, aNewShell);
551 //=======================================================================
552 //function : MakeFaces
554 //=======================================================================
555 void GEOMAlgo_Gluer::MakeFaces()
557 MakeShapes(TopAbs_FACE);
559 //=======================================================================
560 //function : MakeEdges
562 //=======================================================================
563 void GEOMAlgo_Gluer::MakeEdges()
565 MakeShapes(TopAbs_EDGE);
567 //=======================================================================
568 //function : MakeShapes
570 //=======================================================================
571 void GEOMAlgo_Gluer::MakeShapes(const TopAbs_ShapeEnum aType)
575 Standard_Boolean bHasNewSubShape;
576 Standard_Integer i, aNbF, aNbSDF, iErr;
577 TopoDS_Shape aNewShape;
578 TopTools_IndexedMapOfShape aMF;
579 TopTools_ListIteratorOfListOfShape aItS;
580 GEOMAlgo_PassKeyShape aPKF;
581 GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLF;
583 TopExp::MapShapes(myShape, aType, aMF);
586 for (i=1; i<=aNbF; ++i) {
587 const TopoDS_Shape& aS=aMF(i);
589 if (aType==TopAbs_FACE) {
590 const TopoDS_Face& aF=TopoDS::Face(aS);
591 FacePassKey(aF, aPKF);
593 else if (aType==TopAbs_EDGE) {
594 const TopoDS_Edge& aE=TopoDS::Edge(aS);
595 EdgePassKey(aE, aPKF);
602 if (aMPKLF.Contains(aPKF)) {
603 TopTools_ListOfShape& aLSDF=aMPKLF.ChangeFromKey(aPKF);
607 TopTools_ListOfShape aLSDF;
610 aMPKLF.Add(aPKF, aLSDF);
613 // check geometric coincidence
614 if (myCheckGeometry) {
615 iErr=GEOMAlgo_Tools::RefineSDShapes(aMPKLF, myTol, myContext);
624 aNbF=aMPKLF.Extent();
625 for (i=1; i<=aNbF; ++i) {
626 const TopTools_ListOfShape& aLSDF=aMPKLF(i);
627 aNbSDF=aLSDF.Extent();
629 myErrorStatus=4; // it must not be
632 const TopoDS_Shape& aS1=aLSDF.First();
634 bHasNewSubShape=Standard_True;
635 // prevent creation of a new shape if there are not
636 // new subshapes of aSS among the originals
638 bHasNewSubShape=HasNewSubShape(aS1);
639 if (!bHasNewSubShape) {
641 aNewShape.Orientation(TopAbs_FORWARD);
645 if (bHasNewSubShape) {
646 if (aType==TopAbs_FACE) {
647 TopoDS_Face aNewFace;
649 const TopoDS_Face& aF1=TopoDS::Face(aS1);
650 MakeFace(aF1, aNewFace);
653 else if (aType==TopAbs_EDGE) {
654 TopoDS_Edge aNewEdge;
656 const TopoDS_Edge& aE1=TopoDS::Edge(aS1);
657 MakeEdge(aE1, aNewEdge);
662 myImages.Bind(aNewShape, aLSDF);
664 aItS.Initialize(aLSDF);
665 for (; aItS.More(); aItS.Next()) {
666 const TopoDS_Shape& aFSD=aItS.Value();
667 if (!myOrigins.IsBound(aFSD)) {
668 myOrigins.Bind(aFSD, aNewShape);
673 //=======================================================================
674 //function : CheckResult
676 //=======================================================================
677 void GEOMAlgo_Gluer::CheckResult()
681 if (myResult.IsNull()) {
686 Standard_Boolean bFound;
687 Standard_Integer i, j, aNbS, aNbFS, aNbSx;
688 TopTools_IndexedMapOfShape aMS, aMFS;
689 TopTools_IndexedDataMapOfShapeListOfShape aMFR;
691 TopExp::MapShapesAndAncestors(myResult, TopAbs_FACE, TopAbs_SOLID, aMFR);
692 TopExp::MapShapes(myResult, TopAbs_SOLID, aMS);
697 for (i=1; i<=aNbS; ++i) {
698 const TopoDS_Shape& aSolid=aMS(i);
701 TopExp::MapShapes(aSolid, TopAbs_FACE, aMFS);
703 bFound=Standard_False;
705 for (j=1; j<=aNbFS; ++j) {
706 const TopoDS_Shape& aFS=aMFS(j);
707 if (aMFR.Contains(aFS)) {
708 const TopTools_ListOfShape& aLSx=aMFR.FindFromKey(aFS);
724 //=======================================================================
725 //function : CheckData
727 //=======================================================================
728 void GEOMAlgo_Gluer::CheckData()
732 if (myShape.IsNull()) {
737 //=======================================================================
738 //function : InnerTolerance
740 //=======================================================================
741 void GEOMAlgo_Gluer::InnerTolerance()
747 Standard_Real aX[3][2], dH, dHmin, aCoef, aTolTresh;
750 BRepBndLib::Add(myShape, aBox);
751 aBox.Get(aX[0][0], aX[1][0], aX[2][0], aX[0][1], aX[1][1], aX[2][1]);
753 dHmin=aX[0][1]-aX[0][0];
754 for (i=1; i<3; ++i) {
755 dH=aX[i][1]-aX[i][0];
763 aTolTresh=aCoef*dHmin;
764 if (myTol>aTolTresh) {
770 //=======================================================================
771 //function : FacePassKey
773 //=======================================================================
774 void GEOMAlgo_Gluer::FacePassKey(const TopoDS_Face& aF,
775 GEOMAlgo_PassKeyShape& aPK)
777 Standard_Integer i, aNbE;
778 TopTools_ListOfShape aLE;
779 TopTools_IndexedMapOfShape aME;
781 TopExp::MapShapes(aF, TopAbs_EDGE, aME);
784 for (i=1; i<=aNbE; ++i) {
785 const TopoDS_Shape& aE=aME(i);
786 if (!myOrigins.IsBound(aE)) {
790 const TopoDS_Shape& aER=myOrigins.Find(aE);
795 //=======================================================================
796 //function : EdgePassKey
798 //=======================================================================
799 void GEOMAlgo_Gluer::EdgePassKey(const TopoDS_Edge& aE,
800 GEOMAlgo_PassKeyShape& aPK)
802 TopoDS_Vertex aV1, aV2;
804 TopExp::Vertices(aE, aV1, aV2);
806 if (!myOrigins.IsBound(aV1) || !myOrigins.IsBound(aV2) ) {
810 const TopoDS_Shape& aVR1=myOrigins.Find(aV1);
811 const TopoDS_Shape& aVR2=myOrigins.Find(aV2);
812 aPK.SetShapes(aVR1, aVR2);
814 //=======================================================================
815 //function : MakeVertex
817 //=======================================================================
818 void GEOMAlgo_Gluer::MakeVertex(const TopTools_ListOfShape& aLV,
819 TopoDS_Vertex& aNewVertex)
821 Standard_Integer aNbV;
822 Standard_Real aTolV, aD, aDmax;
827 TopTools_ListIteratorOfListOfShape aIt;
835 aGC.SetCoord(0.,0.,0.);
837 for (; aIt.More(); aIt.Next()) {
838 aVx=TopoDS::Vertex(aIt.Value());
839 aP3D=BRep_Tool::Pnt(aVx);
842 aGC/=(Standard_Real)aNbV;
848 for (; aIt.More(); aIt.Next()) {
849 aVx=TopoDS::Vertex(aIt.Value());
850 aP3D=BRep_Tool::Pnt(aVx);
851 aTolV=BRep_Tool::Tolerance(aVx);
852 aD=aPGC.Distance(aP3D)+aTolV;
858 aBB.MakeVertex (aNewVertex, aPGC, aDmax);
860 //=======================================================================
861 //function : MakeEdge
863 //=======================================================================
864 void GEOMAlgo_Gluer::MakeEdge(const TopoDS_Edge& aE,
865 TopoDS_Edge& aNewEdge)
869 Standard_Boolean bIsDE;
870 Standard_Real aT1, aT2;
871 TopoDS_Vertex aV1, aV2, aVR1, aVR2;
874 bIsDE=BRep_Tool::Degenerated(aE);
877 aEx.Orientation(TopAbs_FORWARD);
879 TopExp::Vertices(aEx, aV1, aV2);
881 aT1=BRep_Tool::Parameter(aV1, aEx);
882 aT2=BRep_Tool::Parameter(aV2, aEx);
884 aVR1=TopoDS::Vertex(myOrigins.Find(aV1));
885 aVR1.Orientation(TopAbs_FORWARD);
886 aVR2=TopoDS::Vertex(myOrigins.Find(aV2));
887 aVR2.Orientation(TopAbs_REVERSED);
893 TopAbs_Orientation anOrE;
895 anOrE=aE.Orientation();
896 aTol=BRep_Tool::Tolerance(aE);
903 aBB.Range(E, aT1, aT2);
904 aBB.Degenerated(E, Standard_True);
905 aBB.UpdateEdge(E, aTol);
911 BOPTools_Tools::MakeSplitEdge(aEx, aVR1, aT1, aVR2, aT2, aNewEdge);
914 //=======================================================================
915 //function : MakeFace
917 //=======================================================================
918 void GEOMAlgo_Gluer::MakeFace(const TopoDS_Face& aF,
919 TopoDS_Face& aNewFace)
923 Standard_Boolean bIsToReverse, bIsUPeriodic;
924 Standard_Real aTol, aUMin, aUMax, aVMin, aVMax;
927 TopoDS_Face aFFWD, newFace;
928 TopLoc_Location aLoc;
929 Handle(Geom_Surface) aS;
930 Handle(Geom2d_Curve) aC2D;
931 TopExp_Explorer aExpW, aExpE;
935 aFFWD.Orientation(TopAbs_FORWARD);
937 aS=BRep_Tool::Surface(aFFWD, aLoc);
938 bIsUPeriodic=GEOMAlgo_Tools::IsUPeriodic(aS);
939 aTol=BRep_Tool::Tolerance(aFFWD);
940 BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
942 aBB.MakeFace (newFace, aS, aLoc, aTol);
944 aExpW.Init(aFFWD, TopAbs_WIRE);
945 for (; aExpW.More(); aExpW.Next()) {
946 aBB.MakeWire(newWire);
947 const TopoDS_Wire& aW=TopoDS::Wire(aExpW.Current());
948 aExpE.Init(aW, TopAbs_EDGE);
949 for (; aExpE.More(); aExpE.Next()) {
950 const TopoDS_Edge& aE=TopoDS::Edge(aExpE.Current());
951 aER=TopoDS::Edge(myOrigins.Find(aE));
953 aER.Orientation(TopAbs_FORWARD);
954 if (!BRep_Tool::Degenerated(aER)) {
957 GEOMAlgo_Tools::RefinePCurveForEdgeOnFace(aER, aFFWD, aUMin, aUMax);
959 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aER, aFFWD);
962 bIsToReverse=BOPTools_Tools3D::IsSplitToReverse1(aER, aE, myContext);
968 aER.Orientation(aE.Orientation());
971 aBB.Add(newWire, aER);
974 TopTools_ListOfShape aLW;
977 myImages.Bind(newWire, aLW);
978 myOrigins.Bind(aW, newWire);
980 aBB.Add(newFace, newWire);
984 //=======================================================================
985 //function : IsToReverse
987 //=======================================================================
988 Standard_Boolean GEOMAlgo_Gluer::IsToReverse(const TopoDS_Face& aFR,
989 const TopoDS_Face& aF)
991 Standard_Boolean bRet;
992 Standard_Real aT, aT1, aT2, aTR, aScPr;
993 TopExp_Explorer aExp;
994 Handle(Geom_Curve)aC3D;
1000 aExp.Init(aF, TopAbs_EDGE);
1001 for (; aExp.More(); aExp.Next()) {
1002 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
1004 if (BRep_Tool::Degenerated(aE)) {
1008 const TopoDS_Edge& aER=TopoDS::Edge(myOrigins.Find(aE));
1010 aC3D=BRep_Tool::Curve(aE, aT1, aT2);
1011 aT=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
1013 myContext.ProjectPointOnEdge(aP, aER, aTR);
1015 BOPTools_Tools3D::GetNormalToFaceOnEdge (aE, aF, aT, aDNF);
1016 if (aF.Orientation()==TopAbs_REVERSED) {
1020 BOPTools_Tools3D::GetNormalToFaceOnEdge (aER, aFR, aTR, aDNFR);
1021 if (aFR.Orientation()==TopAbs_REVERSED) {
1030 //=======================================================================
1031 //function : HasNewSubShape
1033 //=======================================================================
1034 Standard_Boolean GEOMAlgo_Gluer::HasNewSubShape(const TopoDS_Shape& aS)const
1036 Standard_Boolean bRet;
1037 Standard_Integer i, aNbSS;
1038 TopTools_IndexedMapOfShape aMSS;
1040 GetSubShapes(aS, aMSS);
1042 bRet=Standard_False;
1043 aNbSS=aMSS.Extent();
1044 for (i=1; i<=aNbSS; ++i) {
1045 const TopoDS_Shape& aSS=aMSS(i);
1046 if (aSS.ShapeType()==TopAbs_WIRE) {
1050 bRet=!myOrigins.IsBound(aSS);
1055 const TopoDS_Shape& aSSIm=myOrigins.Find(aSS);
1056 bRet=!aSSIm.IsSame(aSS);
1063 //=======================================================================
1064 //function : GetSubShapes
1066 //=======================================================================
1067 void GetSubShapes(const TopoDS_Shape& aS,
1068 TopTools_IndexedMapOfShape& aMSS)
1070 Standard_Integer aR;
1071 TopAbs_ShapeEnum aType;
1072 TopoDS_Iterator aIt;
1074 aType=aS.ShapeType();
1075 aR=(Standard_Integer)aType+1;
1076 if (aR>TopAbs_VERTEX) {
1081 for (; aIt.More(); aIt.Next()) {
1082 const TopoDS_Shape& aSS=aIt.Value();
1084 GetSubShapes(aSS, aMSS);
1087 //=======================================================================
1088 //function : Modified
1090 //=======================================================================
1091 const TopTools_ListOfShape& GEOMAlgo_Gluer::Modified (const TopoDS_Shape& aS)
1093 TopAbs_ShapeEnum aType;
1095 myGenerated.Clear();
1097 aType=aS.ShapeType();
1098 if (aType==TopAbs_VERTEX ||
1099 aType==TopAbs_EDGE ||
1100 aType==TopAbs_WIRE ||
1101 aType==TopAbs_FACE ||
1102 aType==TopAbs_SHELL ||
1103 aType==TopAbs_SOLID) {
1104 if(myOrigins.IsBound(aS)) {
1105 const TopoDS_Shape& aSnew=myOrigins.Find(aS);
1106 if (!aSnew.IsSame(aS)) {
1107 myGenerated.Append(aSnew);
1114 //=======================================================================
1115 //function : Generated
1117 //=======================================================================
1118 const TopTools_ListOfShape& GEOMAlgo_Gluer::Generated(const TopoDS_Shape& )
1120 myGenerated.Clear();
1123 //=======================================================================
1124 //function : IsDeleted
1126 //=======================================================================
1127 Standard_Boolean GEOMAlgo_Gluer::IsDeleted (const TopoDS_Shape& aS)
1129 Standard_Boolean bRet=Standard_False;
1131 const TopTools_ListOfShape& aL=Modified(aS);
1139 // 1 - the object is just initialized
1140 // 2 - no vertices found in source shape
1141 // 3 - nb same domain vertices for the vertex Vi =0
1142 // 4 - nb same domain edges(faces) for the edge Ei(face Fi) =0
1143 // 5 - source shape is Null
1144 // 6 - result shape is Null
1145 // 101 - nb edges > PassKey.NbMax() in FacesPassKey()
1146 // 102 - the edge Ei can not be found in myOrigins Map
1147 // 100 - the vertex Vi can not be found in myOrigins Map
1151 // 1 - some shapes can not be glued by faces