Salome HOME
Mantis issue 0021191: GlueEdges and GlueFaces problem with tolerance 1. A fix by...
[modules/geom.git] / src / NMTTools / NMTTools_Tools.cxx
index 3f986765ec772cb1ea1533603942cb23684802fb..cdbcc5f06bd6f1890716ec5f46cd7d10b1eedc19 100644 (file)
@@ -1,96 +1,95 @@
-// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-// 
+//
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either 
+// License as published by the Free Software Foundation; either
 // version 2.1 of the License.
-// 
-// This library is distributed in the hope that it will be useful 
-// but WITHOUT ANY WARRANTY; without even the implied warranty of 
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 // Lesser General Public License for more details.
 //
-// You should have received a copy of the GNU Lesser General Public  
-// License along with this library; if not, write to the Free Software 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// File:       NMTTools_Tools.cxx
-// Created:    Mon Dec  8 10:35:15 2003
-// Author:     Peter KURNEV
-//             <pkv@irinox>
 
+// File:        NMTTools_Tools.cxx
+// Created:     Mon Dec  8 10:35:15 2003
+// Author:      Peter KURNEV
 
 #include <NMTTools_Tools.ixx>
 
-#include <TColStd_IndexedMapOfInteger.hxx>
-
-#include <gp_Pnt.hxx>
-#include <gp_XYZ.hxx>
-#include <gp_Pnt2d.hxx>
+#include <Basics_OCCTVersion.hxx>
 
-#include <Geom_Surface.hxx>
-#include <GeomAPI_ProjectPointOnSurf.hxx>
+#include <NMTTools_ListIteratorOfListOfCoupleOfShape.hxx>
+#include <NMTTools_IndexedDataMapOfShapeIndexedMapOfShape.hxx>
+#include <NMTTools_CoupleOfShape.hxx>
 
 #include <TopoDS.hxx>
 #include <TopoDS_Vertex.hxx>
 #include <TopoDS_Shape.hxx>
 #include <TopoDS_Edge.hxx>
+#include <TopoDS_Iterator.hxx>
 
 #include <TopExp.hxx>
+#include <TopExp_Explorer.hxx>
 
-#include <TopTools_ListIteratorOfListOfShape.hxx>
+#include <TopTools_MapOfShape.hxx>
+#include <TopTools_MapIteratorOfMapOfShape.hxx>
 #include <TopTools_IndexedMapOfShape.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
 
 #include <BRep_Tool.hxx>
 #include <BRep_Builder.hxx>
 #include <BRepTools.hxx>
+#include <BRepLib.hxx>
 
 #include <BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger.hxx>
 #include <BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger.hxx>
 
 #include <BOPTools_VVInterference.hxx>
 #include <BOPTools_SSInterference.hxx>
-
 #include <BOPTools_Tools2D.hxx>
+#include <BOPTools_Tools3D.hxx>
 #include <BOPTools_Tools.hxx>
-#include <NMTTools_ListIteratorOfListOfCoupleOfShape.hxx>
-#include <NMTTools_IndexedDataMapOfShapeIndexedMapOfShape.hxx>
-#include <NMTTools_CoupleOfShape.hxx>
-#include <TopTools_IndexedMapOfShape.hxx>
-#include <Geom2d_Curve.hxx>
+
 #include <Geom_Curve.hxx>
 #include <Geom_TrimmedCurve.hxx>
-#include <BOPTools_Tools2D.hxx>
-#include <BRepLib.hxx>
-#include <BOPTools_Tools3D.hxx>
-#include <TopExp_Explorer.hxx>
-//
-#include <TopTools_MapOfShape.hxx>
-#include <TopTools_MapIteratorOfMapOfShape.hxx>
-#include <TopoDS_Iterator.hxx>
+#include <Geom_Surface.hxx>
+#include <GeomAPI_ProjectPointOnSurf.hxx>
+#include <Geom2d_Curve.hxx>
+
+#include <TColStd_IndexedMapOfInteger.hxx>
 
-static 
+#include <gp_Pnt.hxx>
+#include <gp_XYZ.hxx>
+#include <gp_Pnt2d.hxx>
+
+static
   void ProcessBlock(const Standard_Integer iV,
-                   const BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMCV,
-                   TColStd_IndexedMapOfInteger& aProcessed,
-                   TColStd_IndexedMapOfInteger& aChain);
+                    const BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMCV,
+                    TColStd_IndexedMapOfInteger& aProcessed,
+                    TColStd_IndexedMapOfInteger& aChain);
 static
   void ProcessBlock(const TopoDS_Shape& aF,
-                   const NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMCV,
-                   TopTools_IndexedMapOfShape& aProcessed,
-                   TopTools_IndexedMapOfShape& aChain);
+                    const NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMCV,
+                    TopTools_IndexedMapOfShape& aProcessed,
+                    TopTools_IndexedMapOfShape& aChain);
 
 //modified by NIZNHY-PKV Thu Nov 16 10:46:53 2006f SKL/PartC5
 //=======================================================================
 // function: UpdateEdge
-// purpose: 
+// purpose:
 //=======================================================================
   void  NMTTools_Tools::UpdateEdge(const TopoDS_Edge& aE,
-                                  const Standard_Real aTolR)
-{ 
+                                   const Standard_Real aTolR)
+{
   Standard_Real aTolE, aTolES, aTolV;
   TopoDS_Iterator aIt;
   BRep_Builder aBB;
@@ -110,12 +109,11 @@ static
 }
 //=======================================================================
 // function: MakePCurve
-// purpose: 
+// purpose:
 //=======================================================================
   void  NMTTools_Tools::MakePCurve(const TopoDS_Edge& aE,
-                                   const TopoDS_Face& aF,
-                                   const Handle(Geom2d_Curve)& aC2Dx1)
-                                   
+                                    const TopoDS_Face& aF,
+                                    const Handle(Geom2d_Curve)& aC2Dx1)
 {
   Standard_Real aTolE, aT1, aT2, aOutFirst, aOutLast, aOutTol;
   Handle(Geom2d_Curve) aC2D, aC2DA;
@@ -137,10 +135,10 @@ static
   }
   //
   if (aC3DE->IsPeriodic()) {
-    BOPTools_Tools2D::AdjustPCurveOnFace(aFFWD, aT1, aT2,  aC2D, aC2DA); 
+    BOPTools_Tools2D::AdjustPCurveOnFace(aFFWD, aT1, aT2,  aC2D, aC2DA);
   }
   else {
-    BOPTools_Tools2D::AdjustPCurveOnFace(aFFWD, aC3DETrim, aC2D, aC2DA); 
+    BOPTools_Tools2D::AdjustPCurveOnFace(aFFWD, aC3DETrim, aC2D, aC2DA);
   }
   //
   aBB.UpdateEdge(aE, aC2DA, aFFWD, aTolE);
@@ -149,14 +147,14 @@ static
 /*
 //=======================================================================
 // function: MakePCurve
-// purpose: 
+// purpose:
 //=======================================================================
   void  NMTTools_Tools::MakePCurve(const TopoDS_Edge& aE,
-                                  const TopoDS_Face& aF,
-                                  const Handle(Geom2d_Curve)& aC2Dx,
-                                  const Standard_Real aTolR2D)
+                                   const TopoDS_Face& aF,
+                                   const Handle(Geom2d_Curve)& aC2Dx,
+                                   const Standard_Real aTolR2D)
 {
-  Standard_Integer k, aNbV;   
+  Standard_Integer k, aNbV;
   Standard_Real aTolEdge, aTolFact, aTolV, aTolVmax;
   Standard_Real aTFirst, aTLast, aOutFirst, aOutLast, aOutTol;
   TopoDS_Face aFFWD;
@@ -196,24 +194,28 @@ static
     BOPTools_Tools2D::CurveOnSurface(aE, aFFWD, aC2D, aOutFirst, aOutLast, aOutTol, Standard_True);
   }
   if (aC3DE->IsPeriodic()) {
-    BOPTools_Tools2D::AdjustPCurveOnFace(aFFWD, aTFirst, aTLast,  aC2D, aC2DA); 
+    BOPTools_Tools2D::AdjustPCurveOnFace(aFFWD, aTFirst, aTLast,  aC2D, aC2DA);
   }
   else {
-    BOPTools_Tools2D::AdjustPCurveOnFace(aFFWD, aC3DETrim, aC2D, aC2DA); 
+    BOPTools_Tools2D::AdjustPCurveOnFace(aFFWD, aC3DETrim, aC2D, aC2DA);
   }
   //
   aBB.UpdateEdge(aE, aC2DA, aFFWD, aTolFact);
   BRepLib::SameParameter(aE);
 }
 */
-//modified by NIZNHY-PKV Thu Nov 16 10:46:55 2006t 
+//modified by NIZNHY-PKV Thu Nov 16 10:46:55 2006t
 //=======================================================================
 // function: IsSplitInOnFace
-// purpose: 
+// purpose:
 //=======================================================================
   Standard_Boolean NMTTools_Tools::IsSplitInOnFace(const TopoDS_Edge& aE,
-                                                  const TopoDS_Face& aF,
-                                                  IntTools_Context& aContext)
+                                                   const TopoDS_Face& aF,
+#if OCC_VERSION_LARGE > 0x06050200
+                                                   const Handle(IntTools_Context)& aContext)
+#else
+                                                   IntTools_Context& aContext)
+#endif
 {
   Standard_Boolean bFlag;
   Standard_Real aT, aTolE, aTolF, aTol, aDist, aU, aV;
@@ -224,7 +226,11 @@ static
   aTolF=BRep_Tool::Tolerance(aF);
   aTol=aTolE+aTolF;
   //
+#if OCC_VERSION_LARGE > 0x06050200
+  GeomAPI_ProjectPointOnSurf& aProjector=aContext->ProjPS(aF);
+#else
   GeomAPI_ProjectPointOnSurf& aProjector=aContext.ProjPS(aF);
+#endif
   //
   aT=BOPTools_Tools2D::IntermediatePoint(aE);
   BOPTools_Tools::PointOnEdge(aE, aT, aP);
@@ -243,15 +249,19 @@ static
   //
   aProjector.LowerDistanceParameters(aU, aV);
   aP2D.SetCoord(aU, aV);
+#if OCC_VERSION_LARGE > 0x06050200
+  bFlag=aContext->IsPointInOnFace (aF, aP2D);
+#else
   bFlag=aContext.IsPointInOnFace (aF, aP2D);
+#endif
   return bFlag;
 }
 //=======================================================================
 // function: NMTTools_Tools::MakeNewVertex
-// purpose : 
+// purpose :
 //=======================================================================
   void NMTTools_Tools::MakeNewVertex(const TopTools_ListOfShape& aLVs,
-                                    TopoDS_Vertex& aNewVertex)
+                                     TopoDS_Vertex& aNewVertex)
 {
   Standard_Integer aNb;
   Standard_Real aTi, aDi, aDmax=-1.e5;
@@ -291,10 +301,10 @@ static
 }
 //=======================================================================
 // function: FindChains
-// purpose : 
+// purpose :
 //=======================================================================
   void NMTTools_Tools::FindChains(const BOPTools_CArray1OfSSInterference& FFs,
-                                 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapChains)
+                                  BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapChains)
 {
   Standard_Boolean bIsTangentFaces;
   Standard_Integer j, aNb, anIndex1, anIndex2;
@@ -339,10 +349,10 @@ static
 }
 //=======================================================================
 // function: FindChains
-// purpose : 
+// purpose :
 //=======================================================================
   void NMTTools_Tools::FindChains(const BOPTools_CArray1OfVVInterference& VVs,
-                                 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapChains)
+                                  BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapChains)
 {
   Standard_Integer j, aNb, anIndex1, anIndex2;
   BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger aMCV;
@@ -381,10 +391,10 @@ static
 
 //=======================================================================
 // function: FindChains
-// purpose : 
+// purpose :
 //=======================================================================
   void NMTTools_Tools::FindChains(const BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMCV,
-                                 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapChains)
+                                  BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapChains)
 {
   Standard_Integer  i, j, aNbCV, aNbV, iV, iVx;
   TColStd_IndexedMapOfInteger aProcessed, aChain;
@@ -411,12 +421,12 @@ static
 }
 //=======================================================================
 // function: ProcessBlock
-// purpose: 
+// purpose:
 //=======================================================================
 void ProcessBlock(const Standard_Integer iV,
-                 const BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMCV,
-                 TColStd_IndexedMapOfInteger& aProcessed,
-                 TColStd_IndexedMapOfInteger& aChain)
+                  const BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMCV,
+                  TColStd_IndexedMapOfInteger& aProcessed,
+                  TColStd_IndexedMapOfInteger& aChain)
 {
   Standard_Integer j, aNbV, iVx;
   //
@@ -435,14 +445,18 @@ void ProcessBlock(const Standard_Integer iV,
 }
 //=======================================================================
 // function: AreFacesSameDomain
-// purpose : 
+// purpose :
 //=======================================================================
   Standard_Boolean NMTTools_Tools::AreFacesSameDomain(const TopoDS_Face& aF1x,
-                                                     const TopoDS_Face& aF2y,
-                                                     IntTools_Context& aCtx)
+                                                      const TopoDS_Face& aF2y,
+#if OCC_VERSION_LARGE > 0x06050200
+                                                      const Handle(IntTools_Context)& aCtx)
+#else
+                                                      IntTools_Context& aCtx)
+#endif
 {
   Standard_Boolean bFlag;
-  // Modified  Thu Sep 14 14:35:18 2006 
+  // Modified  Thu Sep 14 14:35:18 2006
   // Contribution of Samtech www.samcef.com BEGIN
   Standard_Integer aNbE1, aNbE2;
   Standard_Real aTolF1, aTolF2, aTol;
@@ -461,7 +475,7 @@ void ProcessBlock(const Standard_Integer iV,
   aF2=aF2y;
   aF2.Orientation(TopAbs_FORWARD);
   //
-  // Modified  Thu Sep 14 14:35:18 2006 
+  // Modified  Thu Sep 14 14:35:18 2006
   // Contribution of Samtech www.samcef.com BEGIN
   //
   // 1
@@ -478,7 +492,7 @@ void ProcessBlock(const Standard_Integer iV,
     const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
     if (!BRep_Tool::Degenerated(aE)) {
       if (!aME1.Contains(aE)) {
-       return bFlag;
+        return bFlag;
       }
       aME2.Add(aE);
     }
@@ -506,7 +520,11 @@ void ProcessBlock(const Standard_Integer iV,
   for (; aIt.More(); aIt.Next()) {
     const TopoDS_Edge& aE=TopoDS::Edge(aIt.Key());
     BOPTools_Tools3D::PointNearEdge(aE, aF1, aP2D, aP);
+#if OCC_VERSION_LARGE > 0x06050200
+    bFlag=aCtx->IsValidPointForFace(aP, aF2, aTol);
+#else
     bFlag=aCtx.IsValidPointForFace(aP, aF2, aTol);
+#endif
     break;
   }
   //
@@ -514,12 +532,12 @@ void ProcessBlock(const Standard_Integer iV,
 }
 //=======================================================================
 // function: FindChains
-// purpose : 
+// purpose :
 //=======================================================================
   void NMTTools_Tools::FindChains(const NMTTools_ListOfCoupleOfShape& aLCS,
-                                 NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMapChains)
+                                  NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMapChains)
 {
-  NMTTools_ListIteratorOfListOfCoupleOfShape aItCS; 
+  NMTTools_ListIteratorOfListOfCoupleOfShape aItCS;
   NMTTools_IndexedDataMapOfShapeIndexedMapOfShape aMCV;
   //
   aItCS.Initialize(aLCS);
@@ -558,10 +576,10 @@ void ProcessBlock(const Standard_Integer iV,
 }
 //=======================================================================
 // function: FindChains
-// purpose : 
+// purpose :
 //=======================================================================
   void NMTTools_Tools::FindChains(const NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMCV,
-                                 NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMapChains)
+                                  NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMapChains)
 {
   Standard_Integer  i, j, aNbCV, aNbV;
   TopTools_IndexedMapOfShape aProcessed, aChain;
@@ -588,12 +606,12 @@ void ProcessBlock(const Standard_Integer iV,
 }
 //=======================================================================
 // function: ProcessBlock
-// purpose: 
+// purpose:
 //=======================================================================
 void ProcessBlock(const TopoDS_Shape& aF,
-                 const NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMCV,
-                 TopTools_IndexedMapOfShape& aProcessed,
-                 TopTools_IndexedMapOfShape& aChain)
+                  const NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMCV,
+                  TopTools_IndexedMapOfShape& aProcessed,
+                  TopTools_IndexedMapOfShape& aChain)
 {
   Standard_Integer j, aNbV;
   //