Salome HOME
[bos #41409][FORUM] (2024) kindOfShape() bug for CONE2D
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_Gluer.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 53f7a69..bf7a382
@@ -1,11 +1,38 @@
-// File:       GEOMAlgo_Gluer.cxx
-// Created:    Sat Dec 04 12:45:53 2004
-// Author:     Peter KURNEV
-//             <peter@PREFEX>
+// Copyright (C) 2007-2024  CEA, EDF, 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
+// 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
+// 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
+// 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: GEOMAlgo_Gluer.cxx
+// Created: Sat Dec 04 12:45:53 2004
+// Author: Peter KURNEV
+//  <peter@PREFEX>
+//
+#include <GEOMAlgo_Gluer.hxx>
+
+#include <Basics_OCCTVersion.hxx>
 
-#include <GEOMAlgo_Gluer.ixx>
+#include <NCollection_UBTreeFiller.hxx>
 
+#include <TColStd_MapIteratorOfMapOfInteger.hxx>
+#include <TColStd_MapOfInteger.hxx>
 #include <TColStd_ListOfInteger.hxx>
 #include <TColStd_ListIteratorOfListOfInteger.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_IndexedDataMapOfPassKeyListOfShape.hxx>
-#include <GEOMAlgo_PassKey.hxx>
-#include <GEOMAlgo_Tools.hxx>
-//
+#include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx>
+#include <GEOMAlgo_PassKeyShape.hxx>
+#include <GEOMAlgo_BndSphereTree.hxx>
+#include <GEOMAlgo_BndSphere.hxx>
+#include <GEOMAlgo_IndexedDataMapOfShapeBndSphere.hxx>
 
-static 
+//
+static
   void GetSubShapes(const TopoDS_Shape& aS,
-                   TopTools_IndexedMapOfShape& aMSS);
+      TopTools_IndexedMapOfShape& aMSS);
 
 //=======================================================================
 //function : GEOMAlgo_Gluer
-//purpose  : 
+//purpose  :
 //=======================================================================
 GEOMAlgo_Gluer::GEOMAlgo_Gluer()
 :
@@ -78,18 +109,19 @@ GEOMAlgo_Gluer::GEOMAlgo_Gluer()
   myTolerance=0.0001;
   myTol=myTolerance;
   myCheckGeometry=Standard_True;
+  myKeepNonSolids=Standard_False;
   myNbAlone=0;
 }
 //=======================================================================
 //function : ~GEOMAlgo_Gluer
-//purpose  : 
+//purpose  :
 //=======================================================================
 GEOMAlgo_Gluer::~GEOMAlgo_Gluer()
 {
 }
 //=======================================================================
 //function : SetCheckGeometry
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_Gluer::SetCheckGeometry(const Standard_Boolean aFlag)
 {
@@ -97,15 +129,31 @@ void GEOMAlgo_Gluer::SetCheckGeometry(const Standard_Boolean aFlag)
 }
 //=======================================================================
 //function : CheckGeometry
-//purpose  : 
+//purpose  :
 //=======================================================================
 Standard_Boolean GEOMAlgo_Gluer::CheckGeometry() const
 {
   return myCheckGeometry;
 }
 //=======================================================================
+//function : SetKeepNonSolids
+//purpose  :
+//=======================================================================
+void GEOMAlgo_Gluer::SetKeepNonSolids(const Standard_Boolean aFlag)
+{
+  myKeepNonSolids=aFlag;
+}
+//=======================================================================
+//function : KeepNonSolids
+//purpose  :
+//=======================================================================
+Standard_Boolean GEOMAlgo_Gluer::KeepNonSolids()const
+{
+  return myKeepNonSolids;
+}
+//=======================================================================
 //function : AloneShapes
-//purpose  : 
+//purpose  :
 //=======================================================================
 Standard_Integer GEOMAlgo_Gluer::AloneShapes()const
 {
@@ -113,7 +161,7 @@ Standard_Integer GEOMAlgo_Gluer::AloneShapes()const
 }
 //=======================================================================
 //function : Images
-//purpose  : 
+//purpose  :
 //=======================================================================
 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer::Images()const
 {
@@ -121,7 +169,7 @@ const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer::Images()const
 }
 //=======================================================================
 //function : Origins
-//purpose  : 
+//purpose  :
 //=======================================================================
 const TopTools_DataMapOfShapeShape& GEOMAlgo_Gluer::Origins()const
 {
@@ -129,15 +177,19 @@ const TopTools_DataMapOfShapeShape& GEOMAlgo_Gluer::Origins()const
 }
 //=======================================================================
 //function : Perform
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_Gluer::Perform()
 {
+  const Standard_Integer aNb=8;
+  Standard_Integer i;
+  //
   myErrorStatus=0;
   myWarningStatus=0;
   //
-  Standard_Integer i;
-  const Standard_Integer aNb=8;
+  // Initialize the context
+  GEOMAlgo_ShapeAlgo::Perform();
+  //
   void (GEOMAlgo_Gluer::* pF[aNb])()={
     &GEOMAlgo_Gluer::CheckData,       &GEOMAlgo_Gluer::InnerTolerance,
     &GEOMAlgo_Gluer::MakeVertices,    &GEOMAlgo_Gluer::MakeEdges,
@@ -152,26 +204,31 @@ void GEOMAlgo_Gluer::Perform()
     }
   }
 }
+
 //=======================================================================
 //function : MakeVertices
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_Gluer::MakeVertices()
 {
   myErrorStatus=0;
   //
-  Standard_Integer j, i, aNbV, aIndex, aNbVSD;
+  Standard_Integer j, i, aNbV, aNbVSD;
+  Standard_Real aTolV;
+  gp_Pnt aPV;
   TColStd_ListIteratorOfListOfInteger aIt;
-  Handle(Bnd_HArray1OfBox) aHAB;
-  Bnd_BoundSortBox aBSB;
-  TopoDS_Shape aSTmp, aVF;
+  TopoDS_Shape aVF;
   TopoDS_Vertex aVnew;
   TopTools_IndexedMapOfShape aMV, aMVProcessed;
   TopTools_ListIteratorOfListOfShape aItS;
   TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
   TopTools_DataMapOfShapeListOfShape aMVV;
   GEOMAlgo_IndexedDataMapOfIntegerShape aMIS;
-  GEOMAlgo_IndexedDataMapOfShapeBox aMSB;
+  GEOMAlgo_IndexedDataMapOfShapeBndSphere aMSB;
+  //
+  GEOMAlgo_BndSphereTreeSelector aSelector;
+  GEOMAlgo_BndSphereTree aBBTree;
+  NCollection_UBTreeFiller <Standard_Integer, GEOMAlgo_BndSphere> aTreeFiller(aBBTree);
   //
   TopExp::MapShapes(myShape, TopAbs_VERTEX, aMV);
   aNbV=aMV.Extent();
@@ -180,59 +237,121 @@ void GEOMAlgo_Gluer::MakeVertices()
     return;
   }
   //
-  aHAB=new Bnd_HArray1OfBox(1, aNbV);
-  //
   for (i=1; i<=aNbV; ++i) {
-    const TopoDS_Shape& aV=aMV(i);
-    Bnd_Box aBox;
+    GEOMAlgo_BndSphere aBox;
+    //
+    const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aMV(i));
+    aPV=BRep_Tool::Pnt(aV);
+    aTolV=BRep_Tool::Tolerance(aV);
+    //
+    aBox.SetGap(myTol);
+    aBox.SetCenter(aPV);
+    aBox.SetRadius(aTolV);
+    //
+    aTreeFiller.Add(i, aBox);
     //
-    aBox.SetGap(myTol); 
-    BRepBndLib::Add(aV, aBox);
-    aHAB->SetValue(i, aBox);
     aMIS.Add(i, aV);
-    aMSB.Add(aV, aBox); 
+    aMSB.Add(aV, aBox);
   }
   //
-  aBSB.Initialize(aHAB);
+  aTreeFiller.Fill();
   //
+  //------------------------------
+  // Chains
   for (i=1; i<=aNbV; ++i) {
-    const TopoDS_Shape& aV=aMV(i);
+    const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aMV(i));
     //
     if (aMVProcessed.Contains(aV)) {
       continue;
     }
     //
-    const Bnd_Box& aBoxV=aMSB.FindFromKey(aV);
-    const TColStd_ListOfInteger& aLI=aBSB.Compare(aBoxV);
-    aNbVSD=aLI.Extent();
-    if (!aNbVSD) {
-      myErrorStatus=3; // it must not be 
-      return;
-    }
+    Standard_Integer aNbIP, aIP, aNbIP1, aIP1;
+    TopTools_ListOfShape aLVSD;
+    TColStd_MapOfInteger aMIP, aMIP1, aMIPC;
+    TColStd_MapIteratorOfMapOfInteger aIt1;
     //
-    // Images
+    aMIP.Add(i);
+    for(;;) {
+      aNbIP=aMIP.Extent();
+      aIt1.Initialize(aMIP);
+      for(; aIt1.More(); aIt1.Next()) {
+        aIP=aIt1.Key();
+        if (aMIPC.Contains(aIP)) {
+          continue;
+        }
+        //
+        const TopoDS_Shape& aVP=aMIS.FindFromKey(aIP);
+        const GEOMAlgo_BndSphere& aBoxVP=aMSB.FindFromKey(aVP);
+        //
+        aSelector.Clear();
+        aSelector.SetBox(aBoxVP);
+        //
+        aNbVSD=aBBTree.Select(aSelector);
+        if (!aNbVSD) {
+          continue;  // it must not be
+ }
+        //
+        const TColStd_ListOfInteger& aLI=aSelector.Indices();
+        //
+        aIt.Initialize(aLI);
+        for (; aIt.More(); aIt.Next()) {
+          aIP1=aIt.Value();
+          if (aMIP.Contains(aIP1)) {
+            continue;
+          }
+          aMIP1.Add(aIP1);
+        } //for (; aIt.More(); aIt.Next()) {
+      }//for(; aIt1.More(); aIt1.Next()) {
+      //
+      aNbIP1=aMIP1.Extent();
+      if (!aNbIP1) {
+        break;
+      }
+      //
+      aIt1.Initialize(aMIP);
+      for(; aIt1.More(); aIt1.Next()) {
+        aIP=aIt1.Key();
+        aMIPC.Add(aIP);
+      }
+      //
+      aMIP.Clear();
+      aIt1.Initialize(aMIP1);
+      for(; aIt1.More(); aIt1.Next()) {
+        aIP=aIt1.Key();
+        aMIP.Add(aIP);
+      }
+      aMIP1.Clear();
+    }// while(1)
     //
-    TopTools_ListOfShape aLVSD;
+    // Fill myImages
+    aNbIP=aMIPC.Extent();
     //
-    aIt.Initialize(aLI);
-    for (j=0; aIt.More(); aIt.Next(), ++j) {
-      aIndex=aIt.Value();
-      const TopoDS_Shape& aVx=aMIS.FindFromKey(aIndex);
-      if(!j) {
-       aVF=aVx;
+    if (!aNbIP) {// no SD vertices founded
+      aVF=aV;
+      aLVSD.Append(aV);
+      aMVProcessed.Add(aV);
+    }
+    else { // SD vertices founded [ aMIPC ]
+      aIt1.Initialize(aMIPC);
+      for(j=0; aIt1.More(); aIt1.Next(), ++j) {
+        aIP=aIt1.Key();
+        const TopoDS_Shape& aVP=aMIS.FindFromKey(aIP);
+        if (!j) {
+          aVF=aVP;
+        }
+        aLVSD.Append(aVP);
+        aMVProcessed.Add(aVP);
       }
-      aLVSD.Append(aVx);
-      aMVProcessed.Add(aVx);
     }
-    //
     myImages.Bind(aVF, aLVSD);
-  }
+  }// for (i=1; i<=aNbV; ++i) {
+  //------------------------------
   //
   // Make new vertices
   aMV.Clear();
   aItIm.Initialize(myImages);
   for (; aItIm.More(); aItIm.Next()) {
-    const TopoDS_Shape& aV=aItIm.Key();
+    const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aItIm.Key());
     const TopTools_ListOfShape& aLVSD=aItIm.Value();
     aNbVSD=aLVSD.Extent();
     if (aNbVSD>1) {
@@ -262,50 +381,52 @@ void GEOMAlgo_Gluer::MakeVertices()
   for (; aItIm.More(); aItIm.Next()) {
     const TopoDS_Shape& aV=aItIm.Key();
     const TopTools_ListOfShape& aLVSD=aItIm.Value();
-    //
     aItS.Initialize(aLVSD);
     for (; aItS.More(); aItS.Next()) {
       const TopoDS_Shape& aVSD=aItS.Value();
       if (!myOrigins.IsBound(aVSD)) {
-       myOrigins.Bind(aVSD, aV);
+        myOrigins.Bind(aVSD, aV);
       }
     }
   }
 }
 //=======================================================================
-//function : MakeSolids
-//purpose  : 
+//function : MakeSubShapes
+//purpose  :
 //=======================================================================
-void GEOMAlgo_Gluer::MakeSolids()
+void GEOMAlgo_Gluer::MakeSubShapes (const TopoDS_Shape&  theShape,
+                                    TopTools_MapOfShape& theMS,
+                                    TopoDS_Compound&     theResult)
 {
-  myErrorStatus=0;
+  if (theMS.Contains(theShape))
+    return;
   //
-  Standard_Integer aNbS;
-  TopAbs_Orientation anOr;
-  TopoDS_Compound aCmp;
-  TopoDS_Solid aNewSolid;
-  TopTools_IndexedMapOfShape aMS;
-  TopExp_Explorer aExpS, aExp;
   BRep_Builder aBB;
   //
-  aBB.MakeCompound(aCmp);
+  theMS.Add(theShape);
   //
-  aNbS=aMS.Extent();
-  aExpS.Init(myShape, TopAbs_SOLID);
-  for (; aExpS.More(); aExpS.Next()) {
-    const TopoDS_Solid& aSolid=TopoDS::Solid(aExpS.Current());
-    if (aMS.Contains(aSolid)) {
-      continue;
+  if (theShape.ShapeType() == TopAbs_COMPOUND ||
+      theShape.ShapeType() == TopAbs_COMPSOLID)  {
+    TopoDS_Iterator It (theShape, Standard_True, Standard_True);
+    for (; It.More(); It.Next())    {
+      MakeSubShapes(It.Value(), theMS, theResult);
     }
-    aMS.Add(aSolid);
+  }
+  else if (theShape.ShapeType() == TopAbs_SOLID)  {
+    // build a solid
+    TopoDS_Solid aNewSolid;
+    TopExp_Explorer aExpS, aExp;
+    //
+    const TopoDS_Solid& aSolid = TopoDS::Solid(theShape);
     //
-    anOr=aSolid.Orientation();
+    TopAbs_Orientation anOr = aSolid.Orientation();
     //
     aBB.MakeSolid(aNewSolid);
     aNewSolid.Orientation(anOr);
     //
     aExp.Init(aSolid, TopAbs_SHELL);
-    for (; aExp.More(); aExp.Next()) {
+    for (; aExp.More(); aExp.Next())
+    {
       const TopoDS_Shape& aShell=aExp.Current();
       const TopoDS_Shape& aShellR=myOrigins.Find(aShell);
       aBB.Add(aNewSolid, aShellR);
@@ -317,20 +438,85 @@ void GEOMAlgo_Gluer::MakeSolids()
     myImages.Bind(aNewSolid, aLS);
     myOrigins.Bind(aSolid, aNewSolid);
     //
-    aBB.Add(aCmp, aNewSolid);
+    aBB.Add(theResult, aNewSolid);
+  }
+  else if (theShape.ShapeType() == TopAbs_WIRE)  {
+    if (myKeepNonSolids)    {
+      // just add image
+      if (!myOrigins.IsBound(theShape))   {
+        // build wire
+        const TopoDS_Wire& aW=TopoDS::Wire(theShape);
+        //
+        TopoDS_Wire newWire;
+        aBB.MakeWire(newWire);
+        //
+        TopExp_Explorer aExpE (aW, TopAbs_EDGE);
+        for (; aExpE.More(); aExpE.Next()) {
+          const TopoDS_Edge& aE=TopoDS::Edge(aExpE.Current());
+          TopoDS_Edge aER=TopoDS::Edge(myOrigins.Find(aE));
+          //
+          aER.Orientation(TopAbs_FORWARD);
+          if (!BRep_Tool::Degenerated(aER)) {
+            // orient image
+            Standard_Boolean bIsToReverse=
+              GEOMAlgo_AlgoTools::IsSplitToReverse(aER, aE, myContext);
+            if (bIsToReverse) {
+              aER.Reverse();
+            }
+          }
+          else {
+            aER.Orientation(aE.Orientation());
+          }
+          //
+          aBB.Add(newWire, aER);
+        }
+        // xf
+        TopTools_ListOfShape aLW;
+        //
+        aLW.Append(aW);
+        myImages.Bind(newWire, aLW);
+        myOrigins.Bind(aW, newWire);
+      }
+      const TopoDS_Shape& aShapeR = myOrigins.Find(theShape);
+      aBB.Add(theResult, aShapeR);
+    }
   }
+  else  {
+    if (myKeepNonSolids)    {
+      // just add image
+      const TopoDS_Shape& aShapeR = myOrigins.Find(theShape);
+      aBB.Add(theResult, aShapeR);
+    }
+  }
+}
+//=======================================================================
+//function : MakeSolids
+//purpose  :
+//=======================================================================
+void GEOMAlgo_Gluer::MakeSolids()
+{
+  myErrorStatus=0;
+  //
+  BRep_Builder aBB;
+  TopoDS_Compound aCmp;
+  TopTools_MapOfShape aMS;
+  //
+  aBB.MakeCompound(aCmp);
+  //
+  // Add images of all initial sub-shapes in the result.
+  // If myKeepNonSolids==false, add only solids images.
+  MakeSubShapes(myShape, aMS, aCmp);
   //
   myResult=aCmp;
   //
-  aNbS=aMS.Extent();
-  if (aNbS) {
-    //Standard_Real aTol=1.e-7;
-    BOP_CorrectTolerances::CorrectCurveOnSurface(myResult);
+  if (aMS.Extent()) {
+    TopTools_IndexedMapOfShape aMapToAvoid;
+    BOPTools_AlgoTools::CorrectCurveOnSurface(myResult, aMapToAvoid, 0.0001);
   }
 }
 //=======================================================================
 //function : MakeShells
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_Gluer::MakeShells()
 {
@@ -359,12 +545,12 @@ void GEOMAlgo_Gluer::MakeShells()
       const TopoDS_Face& aF=TopoDS::Face(aExp.Current());
       aFR=TopoDS::Face(myOrigins.Find(aF));
       if (aFR.IsSame(aF)) {
-       aBB.Add(aNewShell, aF);
-       continue;
+        aBB.Add(aNewShell, aF);
+        continue;
       }
       bIsToReverse=IsToReverse(aFR, aF);
       if (bIsToReverse) {
-       aFR.Reverse();
+        aFR.Reverse();
       }
       aBB.Add(aNewShell, aFR);
     }
@@ -378,7 +564,7 @@ void GEOMAlgo_Gluer::MakeShells()
 }
 //=======================================================================
 //function : MakeFaces
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_Gluer::MakeFaces()
 {
@@ -386,7 +572,7 @@ void GEOMAlgo_Gluer::MakeFaces()
 }
 //=======================================================================
 //function : MakeEdges
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_Gluer::MakeEdges()
 {
@@ -394,7 +580,7 @@ void GEOMAlgo_Gluer::MakeEdges()
 }
 //=======================================================================
 //function : MakeShapes
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_Gluer::MakeShapes(const TopAbs_ShapeEnum aType)
 {
@@ -405,16 +591,15 @@ void GEOMAlgo_Gluer::MakeShapes(const TopAbs_ShapeEnum aType)
   TopoDS_Shape aNewShape;
   TopTools_IndexedMapOfShape aMF;
   TopTools_ListIteratorOfListOfShape aItS;
-  GEOMAlgo_PassKey aPKF;
-  GEOMAlgo_IndexedDataMapOfPassKeyListOfShape aMPKLF;
+  GEOMAlgo_PassKeyShape aPKF;
+  GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLF;
   //
   TopExp::MapShapes(myShape, aType, aMF);
   //
   aNbF=aMF.Extent();
   for (i=1; i<=aNbF; ++i) {
     const TopoDS_Shape& aS=aMF(i);
-    // 
-    aPKF.Clear();
+    //
     if (aType==TopAbs_FACE) {
       const TopoDS_Face& aF=TopoDS::Face(aS);
       FacePassKey(aF, aPKF);
@@ -441,7 +626,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;
@@ -460,34 +645,31 @@ void GEOMAlgo_Gluer::MakeShapes(const TopAbs_ShapeEnum aType)
     //
     const TopoDS_Shape& aS1=aLSDF.First();
     //
-    //modified by NIZNHY-PKV Fri Jan 21 15:34:00 2005 f
-    //
     bHasNewSubShape=Standard_True;
     // prevent creation of a new shape if there are not
-    // new subshapes of aSS among the originals
+    // new sub-shapes of aSS among the originals
     if (aNbSDF==1) {
       bHasNewSubShape=HasNewSubShape(aS1);
       if (!bHasNewSubShape) {
-       aNewShape=aS1;
-       aNewShape.Orientation(TopAbs_FORWARD);
+        aNewShape=aS1;
+        aNewShape.Orientation(TopAbs_FORWARD);
       }
     }
-    //modified by NIZNHY-PKV Fri Jan 21 15:34:05 2005 t
     //
-    if (bHasNewSubShape) {//modified by NIZNHY-PKV Fri Jan 21 15:34:10 2005ft 
+    if (bHasNewSubShape) {
       if (aType==TopAbs_FACE) {
-       TopoDS_Face aNewFace;
-       //
-       const TopoDS_Face& aF1=TopoDS::Face(aS1);
-       MakeFace(aF1, aNewFace);
-       aNewShape=aNewFace;
+        TopoDS_Face aNewFace;
+        //
+        const TopoDS_Face& aF1=TopoDS::Face(aS1);
+        MakeFace(aF1, aNewFace);
+        aNewShape=aNewFace;
       }
       else if (aType==TopAbs_EDGE) {
-       TopoDS_Edge aNewEdge;
-       //
-       const TopoDS_Edge& aE1=TopoDS::Edge(aS1);
-       MakeEdge(aE1, aNewEdge);
-       aNewShape=aNewEdge;
+        TopoDS_Edge aNewEdge;
+        //
+        const TopoDS_Edge& aE1=TopoDS::Edge(aS1);
+        MakeEdge(aE1, aNewEdge);
+        aNewShape=aNewEdge;
       }
     }
     //
@@ -497,14 +679,14 @@ void GEOMAlgo_Gluer::MakeShapes(const TopAbs_ShapeEnum aType)
     for (; aItS.More(); aItS.Next()) {
       const TopoDS_Shape& aFSD=aItS.Value();
       if (!myOrigins.IsBound(aFSD)) {
-       myOrigins.Bind(aFSD, aNewShape);
+        myOrigins.Bind(aFSD, aNewShape);
       }
     }
   }
 }
 //=======================================================================
 //function : CheckResult
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_Gluer::CheckResult()
 {
@@ -512,9 +694,9 @@ void GEOMAlgo_Gluer::CheckResult()
   //
   if (myResult.IsNull()) {
     myErrorStatus=6;
-    return; 
+    return;
   }
-  // 
+  //
   Standard_Boolean bFound;
   Standard_Integer i, j, aNbS, aNbFS, aNbSx;
   TopTools_IndexedMapOfShape aMS, aMFS;
@@ -523,7 +705,7 @@ void GEOMAlgo_Gluer::CheckResult()
   TopExp::MapShapesAndAncestors(myResult, TopAbs_FACE, TopAbs_SOLID, aMFR);
   TopExp::MapShapes(myResult, TopAbs_SOLID, aMS);
   //
-  
+
   myNbAlone=0;
   aNbS=aMS.Extent();
   for (i=1; i<=aNbS; ++i) {
@@ -537,12 +719,12 @@ void GEOMAlgo_Gluer::CheckResult()
     for (j=1; j<=aNbFS; ++j) {
       const TopoDS_Shape& aFS=aMFS(j);
       if (aMFR.Contains(aFS)) {
-       const TopTools_ListOfShape& aLSx=aMFR.FindFromKey(aFS);
-       aNbSx=aLSx.Extent();
-       if (aNbSx==2) {
-         bFound=!bFound;
-         break;
-       }
+        const TopTools_ListOfShape& aLSx=aMFR.FindFromKey(aFS);
+        aNbSx=aLSx.Extent();
+        if (aNbSx==2) {
+          bFound=!bFound;
+          break;
+        }
       }
     }
     //
@@ -555,7 +737,7 @@ void GEOMAlgo_Gluer::CheckResult()
 }
 //=======================================================================
 //function : CheckData
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_Gluer::CheckData()
 {
@@ -563,12 +745,12 @@ void GEOMAlgo_Gluer::CheckData()
   //
   if (myShape.IsNull()) {
     myErrorStatus=5;
-    return; 
+    return;
   }
 }
 //=======================================================================
 //function : InnerTolerance
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_Gluer::InnerTolerance()
 {
@@ -601,22 +783,17 @@ void GEOMAlgo_Gluer::InnerTolerance()
 }
 //=======================================================================
 //function : FacePassKey
-//purpose  : 
+//purpose  :
 //=======================================================================
-void GEOMAlgo_Gluer::FacePassKey(const TopoDS_Face& aF, 
-                                GEOMAlgo_PassKey& aPK)
+void GEOMAlgo_Gluer::FacePassKey(const TopoDS_Face& aF,
+     GEOMAlgo_PassKeyShape& aPK)
 {
-  Standard_Integer i, aNbE, aNbMax;
+  Standard_Integer i, aNbE;
   TopTools_ListOfShape aLE;
   TopTools_IndexedMapOfShape aME;
   //
   TopExp::MapShapes(aF, TopAbs_EDGE, aME);
   aNbE=aME.Extent();
-  aNbMax=aPK.NbMax();
-  if (!aNbE || aNbE>aNbMax) {
-     myErrorStatus=101; // temprorary
-     return;
-  }
   //
   for (i=1; i<=aNbE; ++i) {
     const TopoDS_Shape& aE=aME(i);
@@ -627,14 +804,14 @@ void GEOMAlgo_Gluer::FacePassKey(const TopoDS_Face& aF,
     const TopoDS_Shape& aER=myOrigins.Find(aE);
     aLE.Append(aER);
   }
-  aPK.SetIds(aLE);
+  aPK.SetShapes(aLE);
 }
 //=======================================================================
 //function : EdgePassKey
-//purpose  : 
+//purpose  :
 //=======================================================================
-void GEOMAlgo_Gluer::EdgePassKey(const TopoDS_Edge& aE, 
-                                GEOMAlgo_PassKey& aPK)
+void GEOMAlgo_Gluer::EdgePassKey(const TopoDS_Edge& aE,
+     GEOMAlgo_PassKeyShape& aPK)
 {
   TopoDS_Vertex aV1, aV2;
   //
@@ -646,14 +823,14 @@ void GEOMAlgo_Gluer::EdgePassKey(const TopoDS_Edge& aE,
   }
   const TopoDS_Shape& aVR1=myOrigins.Find(aV1);
   const TopoDS_Shape& aVR2=myOrigins.Find(aV2);
-  aPK.SetIds(aVR1, aVR2);
+  aPK.SetShapes(aVR1, aVR2);
 }
 //=======================================================================
 //function : MakeVertex
-//purpose  : 
+//purpose  :
 //=======================================================================
-void GEOMAlgo_Gluer::MakeVertex(const TopTools_ListOfShape& aLV, 
-                               TopoDS_Vertex& aNewVertex)
+void GEOMAlgo_Gluer::MakeVertex(const TopTools_ListOfShape& aLV,
+    TopoDS_Vertex& aNewVertex)
 {
   Standard_Integer aNbV;
   Standard_Real aTolV, aD, aDmax;
@@ -696,10 +873,10 @@ void GEOMAlgo_Gluer::MakeVertex(const TopTools_ListOfShape& aLV,
 }
 //=======================================================================
 //function : MakeEdge
-//purpose  : 
+//purpose  :
 //=======================================================================
-void GEOMAlgo_Gluer::MakeEdge(const TopoDS_Edge& aE, 
-                             TopoDS_Edge& aNewEdge)
+void GEOMAlgo_Gluer::MakeEdge(const TopoDS_Edge& aE,
+         TopoDS_Edge& aNewEdge)
 {
   myErrorStatus=0;
   //
@@ -727,9 +904,9 @@ void GEOMAlgo_Gluer::MakeEdge(const TopoDS_Edge& aE,
     Standard_Real aTol;
     BRep_Builder aBB;
     TopoDS_Edge E;
-    TopAbs_Orientation anOrE;
+    //TopAbs_Orientation anOrE;
     //
-    anOrE=aE.Orientation();
+    //anOrE=aE.Orientation();
     aTol=BRep_Tool::Tolerance(aE);
     //
     E=aEx;
@@ -745,16 +922,15 @@ 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);
   }
 }
-//
 //=======================================================================
 //function : MakeFace
-//purpose  : 
+//purpose  :
 //=======================================================================
-void GEOMAlgo_Gluer::MakeFace(const TopoDS_Face& aF, 
-                             TopoDS_Face& aNewFace)
+void GEOMAlgo_Gluer::MakeFace(const TopoDS_Face& aF,
+         TopoDS_Face& aNewFace)
 {
   myErrorStatus=0;
   //
@@ -773,7 +949,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);
   //
@@ -790,43 +966,41 @@ void GEOMAlgo_Gluer::MakeFace(const TopoDS_Face& aF,
       //
       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 
-       bIsToReverse=BOPTools_Tools3D::IsSplitToReverse1(aER, aE, myContext);
-       if (bIsToReverse) {
-         aER.Reverse();
-       }
+        // build p-curve
+        if (bIsUPeriodic) {
+          GEOMAlgo_AlgoTools::RefinePCurveForEdgeOnFace(aER, aFFWD, aUMin, aUMax);
+          }
+        BOPTools_AlgoTools2D::BuildPCurveForEdgeOnFace(aER, aFFWD);
+        
+        // orient image
+        bIsToReverse=GEOMAlgo_AlgoTools::IsSplitToReverse(aER, aE, myContext);
+        if (bIsToReverse) {
+          aER.Reverse();
+        }
       }
       else {
-       aER.Orientation(aE.Orientation());
+        aER.Orientation(aE.Orientation());
       }
       //
       aBB.Add(newWire, aER);
     }
-    //modified by NIZNHY-PKV Mon Jan 31 17:26:36 2005f
-    //
+    // xf
     TopTools_ListOfShape aLW;
     //
     aLW.Append(aW);
     myImages.Bind(newWire, aLW);
     myOrigins.Bind(aW, newWire);
-    //
-    //modified by NIZNHY-PKV Mon Jan 31 17:26:41 2005 t
+    // xt
     aBB.Add(newFace, newWire);
   }
   aNewFace=newFace;
 }
 //=======================================================================
 //function : IsToReverse
-//purpose  : 
+//purpose  :
 //=======================================================================
 Standard_Boolean GEOMAlgo_Gluer::IsToReverse(const TopoDS_Face& aFR,
-                                            const TopoDS_Face& aF)
+                                             const TopoDS_Face& aF)
 {
   Standard_Boolean bRet;
   Standard_Real aT, aT1, aT2, aTR, aScPr;
@@ -848,16 +1022,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);
+    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();
     }
@@ -867,11 +1041,9 @@ Standard_Boolean GEOMAlgo_Gluer::IsToReverse(const TopoDS_Face& aFR,
   }
   return bRet;
 }
-//
-//modified by NIZNHY-PKV Fri Jan 21 10:55:42 2005 f
 //=======================================================================
 //function : HasNewSubShape
-//purpose  : 
+//purpose  :
 //=======================================================================
 Standard_Boolean GEOMAlgo_Gluer::HasNewSubShape(const TopoDS_Shape& aS)const
 {
@@ -904,10 +1076,10 @@ Standard_Boolean GEOMAlgo_Gluer::HasNewSubShape(const TopoDS_Shape& aS)const
 }
 //=======================================================================
 //function : GetSubShapes
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GetSubShapes(const TopoDS_Shape& aS,
-                 TopTools_IndexedMapOfShape& aMSS)
+    TopTools_IndexedMapOfShape& aMSS)
 {
   Standard_Integer aR;
   TopAbs_ShapeEnum aType;
@@ -928,9 +1100,10 @@ void GetSubShapes(const TopoDS_Shape& aS,
 }
 //=======================================================================
 //function : Modified
-//purpose  : 
+//purpose  :
 //=======================================================================
-const TopTools_ListOfShape& GEOMAlgo_Gluer::Modified (const TopoDS_Shape& aS) 
+const TopTools_ListOfShape& GEOMAlgo_Gluer::Modified
+  (const TopoDS_Shape& aS)
 {
   TopAbs_ShapeEnum aType;
   //
@@ -938,15 +1111,15 @@ const TopTools_ListOfShape& GEOMAlgo_Gluer::Modified (const TopoDS_Shape& aS)
   //
   aType=aS.ShapeType();
   if (aType==TopAbs_VERTEX ||
-      aType==TopAbs_EDGE   || 
-      aType==TopAbs_WIRE   || //modified by NIZNHY-PKV Mon Jan 31 17:18:36 2005ft
-      aType==TopAbs_FACE   || 
-      aType==TopAbs_SHELL  || //modified by NIZNHY-PKV Mon Jan 31 17:18:36 2005ft
-      aType==TopAbs_SOLID) {  //modified by NIZNHY-PKV Mon Jan 31 17:18:36 2005ft
+      aType==TopAbs_EDGE   ||
+      aType==TopAbs_WIRE   ||
+      aType==TopAbs_FACE   ||
+      aType==TopAbs_SHELL  ||
+      aType==TopAbs_SOLID) {
     if(myOrigins.IsBound(aS)) {
       const TopoDS_Shape& aSnew=myOrigins.Find(aS);
       if (!aSnew.IsSame(aS)) {
-       myGenerated.Append(aSnew);
+        myGenerated.Append(aSnew);
       }
     }
   }
@@ -955,7 +1128,7 @@ const TopTools_ListOfShape& GEOMAlgo_Gluer::Modified (const TopoDS_Shape& aS)
 }
 //=======================================================================
 //function : Generated
-//purpose  : 
+//purpose  :
 //=======================================================================
 const TopTools_ListOfShape& GEOMAlgo_Gluer::Generated(const TopoDS_Shape& )
 {
@@ -964,7 +1137,7 @@ const TopTools_ListOfShape& GEOMAlgo_Gluer::Generated(const TopoDS_Shape& )
 }
 //=======================================================================
 //function : IsDeleted
-//purpose  : 
+//purpose  :
 //=======================================================================
 Standard_Boolean GEOMAlgo_Gluer::IsDeleted (const TopoDS_Shape& aS)
 {
@@ -975,11 +1148,11 @@ Standard_Boolean GEOMAlgo_Gluer::IsDeleted (const TopoDS_Shape& aS)
   //
   return bRet;
 }
-//modified by NIZNHY-PKV Fri Jan 21 10:59:21 2005 t
+
 //
 // ErrorStatus
 //
-// 1   - the object is just initialized 
+// 1   - the object is just initialized
 // 2   - no vertices found in source shape
 // 3   - nb same domain vertices for the vertex Vi =0
 // 4   - nb same domain edges(faces) for the edge Ei(face Fi)  =0