Salome HOME
Fix valgrind error: Mismatched free() / delete / delete []
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_Gluer.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 88f1c6d..bb09bce
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  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
@@ -6,7 +6,7 @@
 // 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
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-// File:        GEOMAlgo_Gluer.cxx
-// Created:     Sat Dec 04 12:45:53 2004
-// Author:      Peter KURNEV
-//              <peter@PREFEX>
+// File: GEOMAlgo_Gluer.cxx
+// Created: Sat Dec 04 12:45:53 2004
+// Author: Peter KURNEV
+//  <peter@PREFEX>
 //
 #include <GEOMAlgo_Gluer.hxx>
 
-#include <NMTDS_BoxBndTree.hxx>
 #include <NCollection_UBTreeFiller.hxx>
 
 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
 #include <BRepLib.hxx>
 #include <BRepTools.hxx>
 #include <BRepBndLib.hxx>
-
+//
+#include <IntTools_Tools.hxx>
 #include <IntTools_Context.hxx>
-#include <BOPTools_Tools.hxx>
-#include <BOPTools_Tools3D.hxx>
-#include <BOPTools_Tools2D.hxx>
-#include <BOP_CorrectTolerances.hxx>
+#include <BOPTools_AlgoTools.hxx>
+#include <BOPTools_AlgoTools3D.hxx>
+#include <BOPTools_AlgoTools2D.hxx>
 
+#include <GEOMAlgo_BoxBndTree.hxx>
+#include <GEOMAlgo_AlgoTools.hxx>
 #include <GEOMAlgo_IndexedDataMapOfIntegerShape.hxx>
 #include <GEOMAlgo_IndexedDataMapOfShapeBox.hxx>
 #include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx>
 #include <GEOMAlgo_PassKeyShape.hxx>
-#include <GEOMAlgo_Tools.hxx>
-//
-
-#include <NMTDS_BndSphereTree.hxx>
-#include <NMTDS_BndSphere.hxx>
-#include <NMTDS_IndexedDataMapOfShapeBndSphere.hxx>
+#include <GEOMAlgo_BndSphereTree.hxx>
+#include <GEOMAlgo_BndSphere.hxx>
+#include <GEOMAlgo_IndexedDataMapOfShapeBndSphere.hxx>
 
 //
 static
   void GetSubShapes(const TopoDS_Shape& aS,
-                    TopTools_IndexedMapOfShape& aMSS);
+      TopTools_IndexedMapOfShape& aMSS);
 
 //=======================================================================
 //function : GEOMAlgo_Gluer
@@ -224,14 +222,11 @@ void GEOMAlgo_Gluer::MakeVertices()
   TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
   TopTools_DataMapOfShapeListOfShape aMVV;
   GEOMAlgo_IndexedDataMapOfIntegerShape aMIS;
-  //modified by NIZNHY-PKV Thu Jan 21 10:03:07 2010f
-  //GEOMAlgo_IndexedDataMapOfShapeBox aMSB;
-  NMTDS_IndexedDataMapOfShapeBndSphere aMSB;
-  //modified by NIZNHY-PKV Thu Jan 21 10:03:10 2010t
+  GEOMAlgo_IndexedDataMapOfShapeBndSphere aMSB;
   //
-  NMTDS_BndSphereTreeSelector aSelector;
-  NMTDS_BndSphereTree aBBTree;
-  NCollection_UBTreeFiller <Standard_Integer, NMTDS_BndSphere> aTreeFiller(aBBTree);
+  GEOMAlgo_BndSphereTreeSelector aSelector;
+  GEOMAlgo_BndSphereTree aBBTree;
+  NCollection_UBTreeFiller <Standard_Integer, GEOMAlgo_BndSphere> aTreeFiller(aBBTree);
   //
   TopExp::MapShapes(myShape, TopAbs_VERTEX, aMV);
   aNbV=aMV.Extent();
@@ -241,7 +236,7 @@ void GEOMAlgo_Gluer::MakeVertices()
   }
   //
   for (i=1; i<=aNbV; ++i) {
-    NMTDS_BndSphere aBox;
+    GEOMAlgo_BndSphere aBox;
     //
     const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aMV(i));
     aPV=BRep_Tool::Pnt(aV);
@@ -274,7 +269,7 @@ void GEOMAlgo_Gluer::MakeVertices()
     TColStd_MapIteratorOfMapOfInteger aIt1;
     //
     aMIP.Add(i);
-    while(1) {
+    for(;;) {
       aNbIP=aMIP.Extent();
       aIt1.Initialize(aMIP);
       for(; aIt1.More(); aIt1.Next()) {
@@ -284,10 +279,7 @@ void GEOMAlgo_Gluer::MakeVertices()
         }
         //
         const TopoDS_Shape& aVP=aMIS.FindFromKey(aIP);
-        //modified by NIZNHY-PKV Thu Jan 21 10:04:09 2010f
-        const NMTDS_BndSphere& aBoxVP=aMSB.FindFromKey(aVP);
-        //const Bnd_Box& aBoxVP=aMSB.FindFromKey(aVP);
-        //modified by NIZNHY-PKV Thu Jan 21 10:04:11 2010t
+        const GEOMAlgo_BndSphere& aBoxVP=aMSB.FindFromKey(aVP);
         //
         aSelector.Clear();
         aSelector.SetBox(aBoxVP);
@@ -295,7 +287,7 @@ void GEOMAlgo_Gluer::MakeVertices()
         aNbVSD=aBBTree.Select(aSelector);
         if (!aNbVSD) {
           continue;  // it must not be
       }
+ }
         //
         const TColStd_ListOfInteger& aLI=aSelector.Indices();
         //
@@ -463,14 +455,9 @@ void GEOMAlgo_Gluer::MakeSubShapes (const TopoDS_Shape&  theShape,
           //
           aER.Orientation(TopAbs_FORWARD);
           if (!BRep_Tool::Degenerated(aER)) {
-            // build p-curve
-            //if (bIsUPeriodic) {
-            //  GEOMAlgo_Tools::RefinePCurveForEdgeOnFace(aER, aFFWD, aUMin, aUMax);
-            //}
-            //BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aER, aFFWD);
-            //
             // orient image
-            Standard_Boolean bIsToReverse=BOPTools_Tools3D::IsSplitToReverse1(aER, aE, myContext);
+            Standard_Boolean bIsToReverse=
+              GEOMAlgo_AlgoTools::IsSplitToReverse(aER, aE, myContext);
             if (bIsToReverse) {
               aER.Reverse();
             }
@@ -492,8 +479,7 @@ void GEOMAlgo_Gluer::MakeSubShapes (const TopoDS_Shape&  theShape,
       aBB.Add(theResult, aShapeR);
     }
   }
-  else
-  {
+  else  {
     if (myKeepNonSolids)    {
       // just add image
       const TopoDS_Shape& aShapeR = myOrigins.Find(theShape);
@@ -522,7 +508,7 @@ void GEOMAlgo_Gluer::MakeSolids()
   myResult=aCmp;
   //
   if (aMS.Extent()) {
-    BOP_CorrectTolerances::CorrectCurveOnSurface(myResult);
+    BOPTools_AlgoTools::CorrectCurveOnSurface(myResult, 0.0001);
   }
 }
 //=======================================================================
@@ -637,7 +623,7 @@ void GEOMAlgo_Gluer::MakeShapes(const TopAbs_ShapeEnum aType)
   }
   // check geometric coincidence
   if (myCheckGeometry) {
-    iErr=GEOMAlgo_Tools::RefineSDShapes(aMPKLF, myTol, myContext);
+    iErr=GEOMAlgo_AlgoTools::RefineSDShapes(aMPKLF, myTol, myContext);
     if (iErr) {
       myErrorStatus=200;
       return;
@@ -797,7 +783,7 @@ void GEOMAlgo_Gluer::InnerTolerance()
 //purpose  :
 //=======================================================================
 void GEOMAlgo_Gluer::FacePassKey(const TopoDS_Face& aF,
-                                 GEOMAlgo_PassKeyShape& aPK)
+     GEOMAlgo_PassKeyShape& aPK)
 {
   Standard_Integer i, aNbE;
   TopTools_ListOfShape aLE;
@@ -822,7 +808,7 @@ void GEOMAlgo_Gluer::FacePassKey(const TopoDS_Face& aF,
 //purpose  :
 //=======================================================================
 void GEOMAlgo_Gluer::EdgePassKey(const TopoDS_Edge& aE,
-                                 GEOMAlgo_PassKeyShape& aPK)
+     GEOMAlgo_PassKeyShape& aPK)
 {
   TopoDS_Vertex aV1, aV2;
   //
@@ -841,7 +827,7 @@ void GEOMAlgo_Gluer::EdgePassKey(const TopoDS_Edge& aE,
 //purpose  :
 //=======================================================================
 void GEOMAlgo_Gluer::MakeVertex(const TopTools_ListOfShape& aLV,
-                                TopoDS_Vertex& aNewVertex)
+    TopoDS_Vertex& aNewVertex)
 {
   Standard_Integer aNbV;
   Standard_Real aTolV, aD, aDmax;
@@ -887,7 +873,7 @@ void GEOMAlgo_Gluer::MakeVertex(const TopTools_ListOfShape& aLV,
 //purpose  :
 //=======================================================================
 void GEOMAlgo_Gluer::MakeEdge(const TopoDS_Edge& aE,
-                              TopoDS_Edge& aNewEdge)
+         TopoDS_Edge& aNewEdge)
 {
   myErrorStatus=0;
   //
@@ -933,7 +919,7 @@ void GEOMAlgo_Gluer::MakeEdge(const TopoDS_Edge& aE,
   }
   //
   else {
-    BOPTools_Tools::MakeSplitEdge(aEx, aVR1, aT1, aVR2, aT2, aNewEdge);
+    BOPTools_AlgoTools::MakeSplitEdge(aEx, aVR1, aT1, aVR2, aT2, aNewEdge);
   }
 }
 //=======================================================================
@@ -941,7 +927,7 @@ void GEOMAlgo_Gluer::MakeEdge(const TopoDS_Edge& aE,
 //purpose  :
 //=======================================================================
 void GEOMAlgo_Gluer::MakeFace(const TopoDS_Face& aF,
-                              TopoDS_Face& aNewFace)
+         TopoDS_Face& aNewFace)
 {
   myErrorStatus=0;
   //
@@ -960,7 +946,7 @@ void GEOMAlgo_Gluer::MakeFace(const TopoDS_Face& aF,
   aFFWD.Orientation(TopAbs_FORWARD);
   //
   aS=BRep_Tool::Surface(aFFWD, aLoc);
-  bIsUPeriodic=GEOMAlgo_Tools::IsUPeriodic(aS);
+  bIsUPeriodic=GEOMAlgo_AlgoTools::IsUPeriodic(aS);
   aTol=BRep_Tool::Tolerance(aFFWD);
   BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
   //
@@ -979,12 +965,12 @@ void GEOMAlgo_Gluer::MakeFace(const TopoDS_Face& aF,
       if (!BRep_Tool::Degenerated(aER)) {
         // build p-curve
         if (bIsUPeriodic) {
-          GEOMAlgo_Tools::RefinePCurveForEdgeOnFace(aER, aFFWD, aUMin, aUMax);
-        }
-        BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aER, aFFWD);
-
+          GEOMAlgo_AlgoTools::RefinePCurveForEdgeOnFace(aER, aFFWD, aUMin, aUMax);
+          }
+        BOPTools_AlgoTools2D::BuildPCurveForEdgeOnFace(aER, aFFWD);
+        
         // orient image
-        bIsToReverse=BOPTools_Tools3D::IsSplitToReverse1(aER, aE, myContext);
+        bIsToReverse=GEOMAlgo_AlgoTools::IsSplitToReverse(aER, aE, myContext);
         if (bIsToReverse) {
           aER.Reverse();
         }
@@ -1033,16 +1019,16 @@ Standard_Boolean GEOMAlgo_Gluer::IsToReverse(const TopoDS_Face& aFR,
     const TopoDS_Edge& aER=TopoDS::Edge(myOrigins.Find(aE));
     //
     aC3D=BRep_Tool::Curve(aE, aT1, aT2);
-    aT=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
+    aT=IntTools_Tools::IntermediatePoint(aT1, aT2);
     aC3D->D0(aT, aP);
     myContext->ProjectPointOnEdge(aP, aER, aTR);
     //
-    BOPTools_Tools3D::GetNormalToFaceOnEdge (aE, aF, aT, aDNF);
+    BOPTools_AlgoTools3D::GetNormalToFaceOnEdge (aE, aF, aT, aDNF);
     if (aF.Orientation()==TopAbs_REVERSED) {
       aDNF.Reverse();
     }
     //
-    BOPTools_Tools3D::GetNormalToFaceOnEdge (aER, aFR, aTR, aDNFR);
+    BOPTools_AlgoTools3D::GetNormalToFaceOnEdge (aER, aFR, aTR, aDNFR);
     if (aFR.Orientation()==TopAbs_REVERSED) {
       aDNFR.Reverse();
     }
@@ -1090,7 +1076,7 @@ Standard_Boolean GEOMAlgo_Gluer::HasNewSubShape(const TopoDS_Shape& aS)const
 //purpose  :
 //=======================================================================
 void GetSubShapes(const TopoDS_Shape& aS,
-                  TopTools_IndexedMapOfShape& aMSS)
+    TopTools_IndexedMapOfShape& aMSS)
 {
   Standard_Integer aR;
   TopAbs_ShapeEnum aType;
@@ -1113,7 +1099,8 @@ void GetSubShapes(const TopoDS_Shape& aS,
 //function : Modified
 //purpose  :
 //=======================================================================
-const TopTools_ListOfShape& GEOMAlgo_Gluer::Modified (const TopoDS_Shape& aS)
+const TopTools_ListOfShape& GEOMAlgo_Gluer::Modified
+  (const TopoDS_Shape& aS)
 {
   TopAbs_ShapeEnum aType;
   //