0024597: Missing internal vertex in the result of General Fuse Operation
[occt.git] / src / BOPDS / BOPDS_DS.cxx
index 57c1564..0023f46 100644 (file)
@@ -1,21 +1,16 @@
 // Created by: Peter KURNEV
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
 //
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
 //
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// This library is free software; you can redistribute it and / or modify it
+// under the terms of the GNU Lesser General Public version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
 //
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
 #include <BOPDS_DS.ixx>
 //
@@ -73,7 +68,7 @@ static
 //function : 
 //purpose  : 
 //=======================================================================
-  BOPDS_DS::BOPDS_DS()
+BOPDS_DS::BOPDS_DS()
 :
   myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
   myArguments(myAllocator),
@@ -81,16 +76,20 @@ static
   myLines(myAllocator),
   myMapShapeIndex(100, myAllocator),
   myPaveBlocksPool(myAllocator),
+  myMapPBCB(100, myAllocator),
   myFaceInfoPool(myAllocator),
   myShapesSD(100, myAllocator),
-  myMapPBCB(100, myAllocator),
   myInterfTB(100, myAllocator),
   myInterfVV(myAllocator),
   myInterfVE(myAllocator),
   myInterfVF(myAllocator),
   myInterfEE(myAllocator),
   myInterfEF(myAllocator),
-  myInterfFF(myAllocator)
+  myInterfFF(myAllocator),
+  myInterfVZ(myAllocator),
+  myInterfEZ(myAllocator),
+  myInterfFZ(myAllocator),
+  myInterfZZ(myAllocator)
 {
   myNbShapes=0;
   myNbSourceShapes=0;
@@ -99,7 +98,7 @@ static
 //function : 
 //purpose  : 
 //=======================================================================
-  BOPDS_DS::BOPDS_DS(const Handle(NCollection_BaseAllocator)& theAllocator)
+BOPDS_DS::BOPDS_DS(const Handle(NCollection_BaseAllocator)& theAllocator)
 :
   myAllocator(theAllocator),
   myArguments(myAllocator),
@@ -107,16 +106,20 @@ static
   myLines(myAllocator),
   myMapShapeIndex(100, myAllocator),
   myPaveBlocksPool(myAllocator),
+  myMapPBCB(100, myAllocator),
   myFaceInfoPool(myAllocator),
   myShapesSD(100, myAllocator),
-  myMapPBCB(100, myAllocator),
   myInterfTB(100, myAllocator),
   myInterfVV(myAllocator),
   myInterfVE(myAllocator),
   myInterfVF(myAllocator),
   myInterfEE(myAllocator),
   myInterfEF(myAllocator),
-  myInterfFF(myAllocator)
+  myInterfFF(myAllocator),
+  myInterfVZ(myAllocator),
+  myInterfEZ(myAllocator),
+  myInterfFZ(myAllocator),
+  myInterfZZ(myAllocator)
 {
   myNbShapes=0;
   myNbSourceShapes=0;
@@ -125,7 +128,7 @@ static
 //function : ~
 //purpose  : 
 //=======================================================================
-  BOPDS_DS::~BOPDS_DS()
+BOPDS_DS::~BOPDS_DS()
 {
   Clear();
 }
@@ -133,7 +136,7 @@ static
 //function : Clear
 //purpose  : 
 //=======================================================================
-  void BOPDS_DS::Clear()
+void BOPDS_DS::Clear()
 {
   myNbShapes=0;
   myNbSourceShapes=0;
@@ -153,12 +156,16 @@ static
   myInterfEE.Clear();
   myInterfEF.Clear();
   myInterfFF.Clear();
+  myInterfVZ.Clear();
+  myInterfEZ.Clear();
+  myInterfFZ.Clear();
+  myInterfZZ.Clear();
 }
 //=======================================================================
 //function : SetArguments
 //purpose  : 
 //=======================================================================
-  void BOPDS_DS::SetArguments(const BOPCol_ListOfShape& theLS)
+void BOPDS_DS::SetArguments(const BOPCol_ListOfShape& theLS)
 {
   myArguments=theLS;
 }
@@ -166,7 +173,7 @@ static
 //function : Arguments
 //purpose  : 
 //=======================================================================
-  const BOPCol_ListOfShape& BOPDS_DS::Arguments()const
+const BOPCol_ListOfShape& BOPDS_DS::Arguments()const
 {
   return myArguments;
 }
@@ -174,7 +181,7 @@ static
 //function : Allocator
 //purpose  : 
 //=======================================================================
-  const Handle(NCollection_BaseAllocator)& BOPDS_DS::Allocator()const
+const Handle(NCollection_BaseAllocator)& BOPDS_DS::Allocator()const
 {
   return myAllocator;
 }
@@ -183,7 +190,7 @@ static
 //function : NbShapes
 //purpose  : 
 //=======================================================================
-  Standard_Integer BOPDS_DS::NbShapes()const
+Standard_Integer BOPDS_DS::NbShapes()const
 {
   return myLines.Size();
 }
@@ -191,7 +198,7 @@ static
 //function : NbSourceShapes
 //purpose  : 
 //=======================================================================
-  Standard_Integer BOPDS_DS::NbSourceShapes()const
+Standard_Integer BOPDS_DS::NbSourceShapes()const
 {
   return myNbSourceShapes;
 }
@@ -199,7 +206,7 @@ static
 //function : NbRanges
 //purpose  : 
 //=======================================================================
-  Standard_Integer BOPDS_DS::NbRanges()const
+Standard_Integer BOPDS_DS::NbRanges()const
 {
   return myRanges.Size();
 }
@@ -207,7 +214,7 @@ static
 //function : Range
 //purpose  : 
 //=======================================================================
-  const BOPDS_IndexRange& BOPDS_DS::Range(const Standard_Integer theI)const
+const BOPDS_IndexRange& BOPDS_DS::Range(const Standard_Integer theI)const
 {
   return myRanges(theI);
 }
@@ -215,7 +222,7 @@ static
 //function : Rank
 //purpose  : 
 //=======================================================================
-  Standard_Integer BOPDS_DS::Rank(const Standard_Integer theI)const
+Standard_Integer BOPDS_DS::Rank(const Standard_Integer theI)const
 {
   Standard_Integer i, aNb, iErr;
   //
@@ -233,7 +240,7 @@ static
 //function : IsNewShape
 //purpose  : 
 //=======================================================================
-  Standard_Boolean BOPDS_DS::IsNewShape(const Standard_Integer theI)const
+Standard_Boolean BOPDS_DS::IsNewShape(const Standard_Integer theI)const
 {
   return theI>=NbSourceShapes();
 }
@@ -241,7 +248,7 @@ static
 //function : Append
 //purpose  : 
 //=======================================================================
-  Standard_Integer BOPDS_DS::Append(const BOPDS_ShapeInfo& theSI)
+Standard_Integer BOPDS_DS::Append(const BOPDS_ShapeInfo& theSI)
 {
   Standard_Integer iX;
   //
@@ -253,7 +260,7 @@ static
 //function : Append
 //purpose  : 
 //=======================================================================
-  Standard_Integer BOPDS_DS::Append(const TopoDS_Shape& theS)
+Standard_Integer BOPDS_DS::Append(const TopoDS_Shape& theS)
 {
   Standard_Integer iX;
   //
@@ -265,7 +272,7 @@ static
 //function : ShapeInfo
 //purpose  : 
 //=======================================================================
-  const BOPDS_ShapeInfo& BOPDS_DS::ShapeInfo(const Standard_Integer theI)const
+const BOPDS_ShapeInfo& BOPDS_DS::ShapeInfo(const Standard_Integer theI)const
 {
   return myLines(theI);
 }
@@ -273,7 +280,7 @@ static
 //function : ChangeShapeInfo
 //purpose  : 
 //=======================================================================
-  BOPDS_ShapeInfo& BOPDS_DS::ChangeShapeInfo(const Standard_Integer theI)
+BOPDS_ShapeInfo& BOPDS_DS::ChangeShapeInfo(const Standard_Integer theI)
 {
   BOPDS_ShapeInfo *pSI;
   //
@@ -285,7 +292,7 @@ static
 //function : Shape
 //purpose  : 
 //=======================================================================
-  const TopoDS_Shape& BOPDS_DS::Shape(const Standard_Integer theI)const
+const TopoDS_Shape& BOPDS_DS::Shape(const Standard_Integer theI)const
 {
   const TopoDS_Shape& aS=ShapeInfo(theI).Shape();
   return aS;
@@ -294,7 +301,7 @@ static
 //function : Index
 //purpose  : 
 //=======================================================================
-  Standard_Integer BOPDS_DS::Index(const TopoDS_Shape& theS)const
+Standard_Integer BOPDS_DS::Index(const TopoDS_Shape& theS)const
 {
   Standard_Integer iRet;
   //
@@ -309,11 +316,13 @@ static
 //function : Init
 //purpose  : 
 //=======================================================================
-  void BOPDS_DS::Init()
+void BOPDS_DS::Init()
 {
   Standard_Integer i1, i2, j, aI, aNb, aNbS, aNbE, aNbSx, nV, nW, nE, aNbF;
+  Standard_Integer n1, n2, n3;
   Standard_Real aTol;
   TopAbs_ShapeEnum aTS;
+  TopoDS_Iterator aItS;
   BOPCol_ListIteratorOfListOfInteger aIt1, aIt2, aIt3;
   BOPCol_ListIteratorOfListOfShape aIt;
   BOPDS_IndexRange aR;
@@ -358,6 +367,9 @@ static
   aIt.Initialize(myArguments);
   for (; aIt.More(); aIt.Next()) {
     const TopoDS_Shape& aS=aIt.Value();
+    if (aMSI.IsBound(aS)) {
+      continue;
+    }
     aI=Append(aS);
     aMSI.Bind(aS, aI);
     //
@@ -369,8 +381,6 @@ static
     i1=i2+1;
   }
   //
-  //aMSI.Clear();
-  //
   myNbSourceShapes=NbShapes();
   //
   // 2 Bounding Boxes
@@ -513,6 +523,16 @@ static
         }
       }//for (; aIt1.More(); aIt1.Next()) {
       //
+      // pure internal vertices on the face
+      aItS.Initialize(aS);
+      for (; aItS.More(); aItS.Next()) {
+       const TopoDS_Shape& aSx=aItS.Value();
+       if (aSx.ShapeType()==TopAbs_VERTEX){
+         nV=Index(aSx);
+         aMI.Add(nV);
+       }
+      }
+      //
       //
       // For a Face: change wires for BRep sub-shapes
       aLW.Clear();
@@ -526,6 +546,59 @@ static
     }//if (aTS==TopAbs_FACE) {
   }//for (j=0; j<myNbSourceShapes; ++j) {
   //
+  // 2.4 Solids
+  for (j=0; j<myNbSourceShapes; ++j) {
+    BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
+    //
+    aTS=aSI.ShapeType();
+    if (aTS!=TopAbs_SOLID) {
+      continue;
+    }
+    Bnd_Box& aBox=aSI.ChangeBox();
+    BuildBndBoxSolid(j, aBox); 
+    //
+    //
+    // update sub-shapes by BRep comprising ones
+    aMI.Clear();
+    BOPCol_ListOfInteger& aLI1=aSI.ChangeSubShapes();
+    //
+    aIt1.Initialize(aLI1);
+    for (; aIt1.More(); aIt1.Next()) {
+      n1=aIt1.Value();
+      BOPDS_ShapeInfo& aSI1=ChangeShapeInfo(n1);
+      if (aSI1.ShapeType()!=TopAbs_SHELL) {
+       continue;
+      }
+      //
+      const BOPCol_ListOfInteger& aLI2=aSI1.SubShapes(); 
+      aIt2.Initialize(aLI2);
+      for (; aIt2.More(); aIt2.Next()) {
+       n2=aIt2.Value();
+       BOPDS_ShapeInfo& aSI2=ChangeShapeInfo(n2);
+       if (aSI2.ShapeType()!=TopAbs_FACE) {
+         continue;
+       }
+       //
+       aMI.Add(n2);
+       //
+       const BOPCol_ListOfInteger& aLI3=aSI2.SubShapes(); 
+       aIt3.Initialize(aLI3);
+       for (; aIt3.More(); aIt3.Next()) {
+         n3=aIt3.Value();
+         aMI.Add(n3);
+       }
+      }
+    }
+    //
+    aLI1.Clear();
+    aItMI.Initialize(aMI);
+    for (; aItMI.More(); aItMI.Next()) {
+      n1=aItMI.Value();
+      aLI1.Append(n1);
+    }
+    aMI.Clear();
+  }//for (j=0; j<myNbSourceShapes; ++j) {
+  //
   aMI.Clear();
   aAllocator.Nullify();
   //-----------------------------------------------------scope_1 t
@@ -545,10 +618,10 @@ static
 //function : InitShape
 //purpose  : 
 //=======================================================================
-  void BOPDS_DS::InitShape(const Standard_Integer aI,
-                           const TopoDS_Shape& aS,
-                           Handle(NCollection_BaseAllocator)& theAllocator,
-                           BOPCol_DataMapOfShapeInteger& aMSI)
+void BOPDS_DS::InitShape(const Standard_Integer aI,
+                        const TopoDS_Shape& aS,
+                        Handle(NCollection_BaseAllocator)& theAllocator,
+                        BOPCol_DataMapOfShapeInteger& aMSI)
 {
   Standard_Integer aIx;
   TopoDS_Iterator aIt;
@@ -588,7 +661,7 @@ static
 //function : HasInterf
 //purpose  : 
 //=======================================================================
-  Standard_Boolean BOPDS_DS::HasInterf(const Standard_Integer theI) const
+Standard_Boolean BOPDS_DS::HasInterf(const Standard_Integer theI) const
 {
   Standard_Integer n1, n2;
   Standard_Boolean bRet;
@@ -608,13 +681,14 @@ static
   //
   return bRet;
 }
-
 //=======================================================================
 //function : HasInterfShapeSubShapes
 //purpose  : 
 //=======================================================================
-  Standard_Boolean BOPDS_DS::HasInterfShapeSubShapes(const Standard_Integer theI1,
-                                                     const Standard_Integer theI2)const
+Standard_Boolean BOPDS_DS::HasInterfShapeSubShapes
+  (const Standard_Integer theI1,
+   const Standard_Integer theI2,
+   const Standard_Boolean theFlag)const
 {
   Standard_Boolean bRet;
   Standard_Integer n2;
@@ -627,19 +701,25 @@ static
   for (; aIt.More(); aIt.Next()) {
     n2=aIt.Value();
     bRet=HasInterf(theI1, n2);
-    if(bRet) {
-      break;
+    if (theFlag) {
+      if(bRet) {
+       break;
+      }
+    }
+    else {
+      if(!bRet) {
+       break;
+      }
     }
   }
   return bRet;
 }
-
 //=======================================================================
 //function : HasInterfSubShapes
 //purpose  : 
 //=======================================================================
-  Standard_Boolean BOPDS_DS::HasInterfSubShapes(const Standard_Integer theI1,
-                                                const Standard_Integer theI2)const
+Standard_Boolean BOPDS_DS::HasInterfSubShapes(const Standard_Integer theI1,
+                                             const Standard_Integer theI2)const
 {
   Standard_Boolean bRet;
   Standard_Integer n1;
@@ -664,7 +744,7 @@ static
 //function : PaveBlocksPool
 //purpose  : 
 //=======================================================================
-  const BOPDS_VectorOfListOfPaveBlock& BOPDS_DS::PaveBlocksPool()const
+const BOPDS_VectorOfListOfPaveBlock& BOPDS_DS::PaveBlocksPool()const
 {
   return myPaveBlocksPool;
 }
@@ -672,7 +752,7 @@ static
 //function : ChangePaveBlocksPool
 //purpose  : 
 //=======================================================================
-  BOPDS_VectorOfListOfPaveBlock& BOPDS_DS::ChangePaveBlocksPool()
+BOPDS_VectorOfListOfPaveBlock& BOPDS_DS::ChangePaveBlocksPool()
 {
   return myPaveBlocksPool;
 }
@@ -680,7 +760,7 @@ static
 //function : HasPaveBlocks
 //purpose  : 
 //=======================================================================
-  Standard_Boolean BOPDS_DS::HasPaveBlocks(const Standard_Integer theI)const
+Standard_Boolean BOPDS_DS::HasPaveBlocks(const Standard_Integer theI)const
 {
   return ShapeInfo(theI).HasReference();
 }
@@ -688,7 +768,7 @@ static
 //function : PaveBlocks
 //purpose  : 
 //=======================================================================
-  const BOPDS_ListOfPaveBlock& BOPDS_DS::PaveBlocks(const Standard_Integer theI)const
+const BOPDS_ListOfPaveBlock& BOPDS_DS::PaveBlocks(const Standard_Integer theI)const
 {
   static BOPDS_ListOfPaveBlock sLPB;
   Standard_Integer aRef;
@@ -704,7 +784,7 @@ static
 //function : ChangePaveBlocks
 //purpose  : 
 //=======================================================================
-  BOPDS_ListOfPaveBlock& BOPDS_DS::ChangePaveBlocks(const Standard_Integer theI)
+BOPDS_ListOfPaveBlock& BOPDS_DS::ChangePaveBlocks(const Standard_Integer theI)
 {
   Standard_Boolean bHasReference;
   Standard_Integer aRef;
@@ -722,9 +802,9 @@ static
 //function : InitPaveBlocks
 //purpose  : 
 //=======================================================================
-  void BOPDS_DS::InitPaveBlocks(const Standard_Integer theI)
+void BOPDS_DS::InitPaveBlocks(const Standard_Integer theI)
 {
-  Standard_Integer nV, iRef, aNbV, nVSD, i;
+  Standard_Integer nV = 0, iRef, aNbV, nVSD, i;
   Standard_Real aT;
   TopoDS_Vertex aV;
   BOPCol_ListIteratorOfListOfInteger aIt;
@@ -782,7 +862,7 @@ static
 //function : UpdatePaveBlocks
 //purpose  : 
 //=======================================================================
-  void BOPDS_DS::UpdatePaveBlocks()
+void BOPDS_DS::UpdatePaveBlocks()
 {
   Standard_Boolean bIsToUpdate;
   Standard_Integer i, aNbPBP;
@@ -818,7 +898,7 @@ static
 //function : UpdatePaveBlock
 //purpose  : 
 //=======================================================================
-  void BOPDS_DS::UpdatePaveBlock(const Handle(BOPDS_PaveBlock)& thePB)
+void BOPDS_DS::UpdatePaveBlock(const Handle(BOPDS_PaveBlock)& thePB)
 {
   if (!thePB->IsToUpdate()){
     return;
@@ -856,7 +936,7 @@ static
 //function : UpdateCommonBlock
 //purpose  : 
 //=======================================================================
-  void BOPDS_DS::UpdateCommonBlock(const Handle(BOPDS_CommonBlock)& theCB)
+void BOPDS_DS::UpdateCommonBlock(const Handle(BOPDS_CommonBlock)& theCB)
 {
   Standard_Integer nE, iRef, n1, n2;
   BOPDS_ListIteratorOfListOfPaveBlock aItPB, aItPBCB, aItPBN;
@@ -976,7 +1056,7 @@ static
 // function: RealPaveBlock
 // purpose: 
 //=======================================================================
-  Handle(BOPDS_PaveBlock) BOPDS_DS::RealPaveBlock
+Handle(BOPDS_PaveBlock) BOPDS_DS::RealPaveBlock
     (const Handle(BOPDS_PaveBlock)& thePB) const
 {
   if (IsCommonBlock(thePB)) {
@@ -991,7 +1071,7 @@ static
 // function: IsCommonBlockOnEdge
 // purpose: 
 //=======================================================================
-  Standard_Boolean BOPDS_DS::IsCommonBlockOnEdge
+Standard_Boolean BOPDS_DS::IsCommonBlockOnEdge
     (const Handle(BOPDS_PaveBlock)& thePB) const
 {
   if (IsCommonBlock(thePB)) {
@@ -1005,7 +1085,7 @@ static
 //function : IsCommonBlock
 //purpose  : 
 //=======================================================================
-  Standard_Boolean BOPDS_DS::IsCommonBlock
+Standard_Boolean BOPDS_DS::IsCommonBlock
     (const Handle(BOPDS_PaveBlock)& thePB) const
 {
   return myMapPBCB.IsBound(thePB);
@@ -1015,7 +1095,7 @@ static
 //function : CommonBlock
 //purpose  : 
 //=======================================================================
-  const Handle(BOPDS_CommonBlock)& BOPDS_DS::CommonBlock
+const Handle(BOPDS_CommonBlock)& BOPDS_DS::CommonBlock
     (const Handle(BOPDS_PaveBlock)& thePB) const
 {
   Handle(BOPDS_CommonBlock) aNullCB;
@@ -1030,8 +1110,8 @@ static
 //function : SetCommonBlock
 //purpose  : 
 //=======================================================================
-  void BOPDS_DS::SetCommonBlock(const Handle(BOPDS_PaveBlock)& thePB,
-                                const Handle(BOPDS_CommonBlock)& theCB)
+void BOPDS_DS::SetCommonBlock(const Handle(BOPDS_PaveBlock)& thePB,
+                             const Handle(BOPDS_CommonBlock)& theCB)
 {
   if (IsCommonBlock(thePB)) {
     Handle(BOPDS_CommonBlock)& aCB = myMapPBCB.ChangeFind(thePB);
@@ -1050,7 +1130,7 @@ static
 //function : FaceInfoPool
 //purpose  : 
 //=======================================================================
-  const BOPDS_VectorOfFaceInfo& BOPDS_DS::FaceInfoPool()const
+const BOPDS_VectorOfFaceInfo& BOPDS_DS::FaceInfoPool()const
 {
   return myFaceInfoPool;
 }
@@ -1058,7 +1138,7 @@ static
 //function : HasFaceInfo
 //purpose  : 
 //=======================================================================
-  Standard_Boolean BOPDS_DS::HasFaceInfo(const Standard_Integer theI)const
+Standard_Boolean BOPDS_DS::HasFaceInfo(const Standard_Integer theI)const
 {
   return ShapeInfo(theI).HasReference();
 }
@@ -1066,7 +1146,7 @@ static
 //function : FaceInfo
 //purpose  : 
 //=======================================================================
-  const BOPDS_FaceInfo& BOPDS_DS::FaceInfo(const Standard_Integer theI)const
+const BOPDS_FaceInfo& BOPDS_DS::FaceInfo(const Standard_Integer theI)const
 {
   static BOPDS_FaceInfo sFI;
   Standard_Integer aRef;
@@ -1082,7 +1162,7 @@ static
 //function : ChangeFaceInfo
 //purpose  : 
 //=======================================================================
-  BOPDS_FaceInfo& BOPDS_DS::ChangeFaceInfo(const Standard_Integer theI)
+BOPDS_FaceInfo& BOPDS_DS::ChangeFaceInfo(const Standard_Integer theI)
 {
   Standard_Boolean bHasReference;
   Standard_Integer aRef;
@@ -1103,7 +1183,7 @@ static
 //function : InitFaceInfo
 //purpose  : 
 //=======================================================================
-  void BOPDS_DS::InitFaceInfo(const Standard_Integer theI)
+void BOPDS_DS::InitFaceInfo(const Standard_Integer theI)
 {
   Standard_Integer iRef;
   //
@@ -1120,7 +1200,7 @@ static
 //function : UpdateFaceInfoIn
 //purpose  : 
 //=======================================================================
-  void BOPDS_DS::UpdateFaceInfoIn(const Standard_Integer theI)
+void BOPDS_DS::UpdateFaceInfoIn(const Standard_Integer theI)
 {
   Standard_Integer iRef;
   //
@@ -1140,7 +1220,7 @@ static
 //function : UpdateFaceInfoOn
 //purpose  : 
 //=======================================================================
-  void BOPDS_DS::UpdateFaceInfoOn(const Standard_Integer theI)
+void BOPDS_DS::UpdateFaceInfoOn(const Standard_Integer theI)
 {
   Standard_Integer iRef;
   //
@@ -1160,9 +1240,9 @@ static
 //function : FaceInfoOn
 //purpose  : 
 //=======================================================================
-  void BOPDS_DS::FaceInfoOn(const Standard_Integer theF,
-                            BOPDS_IndexedMapOfPaveBlock& theMPB,
-                            BOPCol_MapOfInteger& theMI)
+void BOPDS_DS::FaceInfoOn(const Standard_Integer theF,
+                         BOPDS_IndexedMapOfPaveBlock& theMPB,
+                         BOPCol_MapOfInteger& theMI)
 {
   Standard_Integer nS, nSD, nV1, nV2;
   BOPCol_ListIteratorOfListOfInteger aIt;
@@ -1199,13 +1279,29 @@ static
 //function : FaceInfoIn
 //purpose  : 
 //=======================================================================
-  void BOPDS_DS::FaceInfoIn(const Standard_Integer theF,
-                            BOPDS_IndexedMapOfPaveBlock& theMPB,
-                            BOPCol_MapOfInteger& theMI)
+void BOPDS_DS::FaceInfoIn(const Standard_Integer theF,
+                         BOPDS_IndexedMapOfPaveBlock& theMPB,
+                         BOPCol_MapOfInteger& theMI)
 {
-  Standard_Integer i, aNbVF, aNbEF, nV, nE;
+  Standard_Integer i, aNbVF, aNbEF, nV, nE, nVSD;
+  TopoDS_Iterator aItS;
   BOPDS_ListIteratorOfListOfPaveBlock aItPB;
   //
+  // 1. Pure internal vertices on the face
+  const TopoDS_Shape& aF=Shape(theF);
+  aItS.Initialize(aF);
+  for (; aItS.More(); aItS.Next()) {
+    const TopoDS_Shape& aSx=aItS.Value();
+    if (aSx.ShapeType()==TopAbs_VERTEX){
+      nV=Index(aSx);
+      if (HasShapeSD(nV, nVSD)) {
+       nV=nVSD;
+      }
+      theMI.Add(nV);
+    }
+  }
+  //
+  // 2. aVFs
   BOPDS_VectorOfInterfVF& aVFs=InterfVF();
   aNbVF=aVFs.Extent();
   for (i=0; i<aNbVF; ++i) {
@@ -1216,6 +1312,7 @@ static
     }
   }
   //
+  // 3. aEFs
   BOPDS_VectorOfInterfEF& aEFs=InterfEF();
   aNbEF=aEFs.Extent();
   for (i=0; i<aNbEF; ++i) {
@@ -1247,7 +1344,7 @@ static
 //function : RefineFaceInfoOn
 //purpose  : 
 //=======================================================================
-  void BOPDS_DS::RefineFaceInfoOn()
+void BOPDS_DS::RefineFaceInfoOn()
 {
   Standard_Integer i, aNb, nF, aNbPB, j;
   BOPDS_IndexedMapOfPaveBlock aMPB;
@@ -1276,8 +1373,8 @@ static
 //function : AloneVertices
 //purpose  : 
 //=======================================================================
-  void BOPDS_DS::AloneVertices(const Standard_Integer theI,
-                               BOPCol_ListOfInteger& theLI)const
+void BOPDS_DS::AloneVertices(const Standard_Integer theI,
+                            BOPCol_ListOfInteger& theLI)const
 {
   if (HasFaceInfo(theI)) {
     //
@@ -1314,99 +1411,63 @@ static
     }
   }
 }
-
 //=======================================================================
 //function : VerticesOnIn
 //purpose  : 
 //=======================================================================
-  void BOPDS_DS::VerticesOnIn(const Standard_Integer nF1,
-                              const Standard_Integer nF2,
-                              BOPCol_MapOfInteger& aMI,
-                              BOPDS_MapOfPaveBlock& aMPB)const
+void BOPDS_DS::VerticesOnIn(const Standard_Integer nF1,
+                           const Standard_Integer nF2,
+                           BOPCol_MapOfInteger& aMI,
+                           BOPDS_MapOfPaveBlock& aMPB)const
 {
-  Standard_Integer nV, nV1, nV2;
+  Standard_Integer i, nV, nV1, nV2;
   BOPCol_MapIteratorOfMapOfInteger aIt;
+  BOPDS_IndexedMapOfPaveBlock* pMPB[4];
   BOPDS_MapIteratorOfMapOfPaveBlock aItMPB;
   //
   const BOPDS_FaceInfo& aFI1=FaceInfo(nF1);
   const BOPDS_FaceInfo& aFI2=FaceInfo(nF2);
   //
-  const BOPDS_IndexedMapOfPaveBlock& aMPBOn1=aFI1.PaveBlocksOn();
-  aItMPB.Initialize(aMPBOn1);
-  for (; aItMPB.More(); aItMPB.Next()) {
-    const Handle(BOPDS_PaveBlock)& aPB=aItMPB.Value();
-    aMPB.Add(aPB);
-    aPB->Indices(nV1, nV2);
-    aMI.Add(nV1);
-    aMI.Add(nV2);
-  }
-  //
-  const BOPDS_IndexedMapOfPaveBlock& aMPBIn1=aFI1.PaveBlocksIn();
-  aItMPB.Initialize(aMPBIn1);
-  for (; aItMPB.More(); aItMPB.Next()) {
-    const Handle(BOPDS_PaveBlock)& aPB=aItMPB.Value();
-    aMPB.Add(aPB);
-    aPB->Indices(nV1, nV2);
-    aMI.Add(nV1);
-    aMI.Add(nV2);
-  }
-  //
-  const BOPDS_IndexedMapOfPaveBlock& aMPBOn2=aFI2.PaveBlocksOn();
-  aItMPB.Initialize(aMPBOn2);
-  for (; aItMPB.More(); aItMPB.Next()) {
-    const Handle(BOPDS_PaveBlock)& aPB=aItMPB.Value();
-    aMPB.Add(aPB);
-    aPB->Indices(nV1, nV2);
-    aMI.Add(nV1);
-    aMI.Add(nV2);
-  }
-  //
-  const BOPDS_IndexedMapOfPaveBlock& aMPBIn2=aFI2.PaveBlocksIn();
-  aItMPB.Initialize(aMPBIn2);
-  for (; aItMPB.More(); aItMPB.Next()) {
-    const Handle(BOPDS_PaveBlock)& aPB=aItMPB.Value();
-    aMPB.Add(aPB);
-    aPB->Indices(nV1, nV2);
-    aMI.Add(nV1);
-    aMI.Add(nV2);
+  pMPB[0]=(BOPDS_IndexedMapOfPaveBlock*)&aFI1.PaveBlocksOn();
+  pMPB[1]=(BOPDS_IndexedMapOfPaveBlock*)&aFI1.PaveBlocksIn();
+  pMPB[2]=(BOPDS_IndexedMapOfPaveBlock*)&aFI2.PaveBlocksOn();
+  pMPB[3]=(BOPDS_IndexedMapOfPaveBlock*)&aFI2.PaveBlocksIn();
+  //
+  for (i=0; i<4; ++i) {
+    aItMPB.Initialize(*pMPB[i]);
+    for (; aItMPB.More(); aItMPB.Next()) {
+      const Handle(BOPDS_PaveBlock)& aPB=aItMPB.Value();
+      aMPB.Add(aPB);
+      aPB->Indices(nV1, nV2);
+      aMI.Add(nV1);
+      aMI.Add(nV2);
+    }
   }
   //
   const BOPCol_MapOfInteger& aMVOn1=aFI1.VerticesOn();
-  aIt.Initialize(aMVOn1);
-  for (; aIt.More(); aIt.Next()) {
-    nV=aIt.Value();
-    aMI.Add(nV);
-  }
-  //
   const BOPCol_MapOfInteger& aMVIn1=aFI1.VerticesIn();
-  aIt.Initialize(aMVOn1);
-  for (; aIt.More(); aIt.Next()) {
-    nV=aIt.Value();
-    aMI.Add(nV);
-  }
-  //
   const BOPCol_MapOfInteger& aMVOn2=aFI2.VerticesOn();
-  aIt.Initialize(aMVOn2);
-  for (; aIt.More(); aIt.Next()) {
-    nV=aIt.Value();
-    aMI.Add(nV);
-  }
-  //
   const BOPCol_MapOfInteger& aMVIn2=aFI2.VerticesIn();
-  aIt.Initialize(aMVOn1);
-  for (; aIt.More(); aIt.Next()) {
-    nV=aIt.Value();
-    aMI.Add(nV);
+  //
+  for (i=0; i<2; ++i) {
+    const BOPCol_MapOfInteger& aMV1=(!i) ? aMVOn1 : aMVIn1;
+    aIt.Initialize(aMV1);
+    for (; aIt.More(); aIt.Next()) {
+      nV=aIt.Value();
+      if (aMVOn2.Contains(nV) || aMVIn2.Contains(nV)) {
+       aMI.Add(nV);
+      }
+    }
   }
 } 
 //=======================================================================
 //function : SharedEdges
 //purpose  : 
 //=======================================================================
-  void BOPDS_DS::SharedEdges(const Standard_Integer nF1,
-                             const Standard_Integer nF2,
-                             BOPCol_ListOfInteger& theLI,
-                             const Handle(NCollection_BaseAllocator)& aAllocator)
+void BOPDS_DS::SharedEdges(const Standard_Integer nF1,
+                          const Standard_Integer nF2,
+                          BOPCol_ListOfInteger& theLI,
+                          const Handle(NCollection_BaseAllocator)& aAllocator)
 {
   Standard_Integer nE, nSp;
   BOPCol_ListIteratorOfListOfInteger aItLI;
@@ -1470,7 +1531,7 @@ static
 //function : ShapesSD
 //purpose  : 
 //=======================================================================
-  BOPCol_DataMapOfIntegerInteger& BOPDS_DS::ShapesSD()
+BOPCol_DataMapOfIntegerInteger& BOPDS_DS::ShapesSD()
 {
   return myShapesSD;
 }
@@ -1478,7 +1539,7 @@ static
 //function : AddShapeSD
 //purpose  : 
 //=======================================================================
-  void BOPDS_DS::AddShapeSD(const Standard_Integer theIndex,
+void BOPDS_DS::AddShapeSD(const Standard_Integer theIndex,
                             const Standard_Integer theIndexSD)
 {
   myShapesSD.Bind(theIndex, theIndexSD);
@@ -1487,8 +1548,8 @@ static
 //function : HasShapeSD
 //purpose  : 
 //=======================================================================
-  Standard_Boolean BOPDS_DS::HasShapeSD(const Standard_Integer theIndex,
-                                        Standard_Integer& theIndexSD)const
+Standard_Boolean BOPDS_DS::HasShapeSD(const Standard_Integer theIndex,
+                                     Standard_Integer& theIndexSD)const
 {
   Standard_Boolean bRet;
   //
@@ -1502,7 +1563,7 @@ static
 //function : Dump
 //purpose  : 
 //=======================================================================
-  void BOPDS_DS::Dump()const
+void BOPDS_DS::Dump()const
 {
   Standard_Integer i, aNb, aNbSS;
   //
@@ -1534,8 +1595,8 @@ static
 // function: CheckCoincidence
 // purpose:
 //=======================================================================
-  Standard_Boolean BOPDS_DS::CheckCoincidence(const Handle(BOPDS_PaveBlock)& aPB1,
-                                              const Handle(BOPDS_PaveBlock)& aPB2)
+Standard_Boolean BOPDS_DS::CheckCoincidence(const Handle(BOPDS_PaveBlock)& aPB1,
+                                           const Handle(BOPDS_PaveBlock)& aPB2)
 {
   Standard_Boolean bRet;
   Standard_Integer nE1, nE2, aNbPoints;
@@ -1579,7 +1640,7 @@ static
 // function: SortPaveBlocks
 // purpose:
 //=======================================================================
-  void BOPDS_DS::SortPaveBlocks(const Handle(BOPDS_CommonBlock)& aCB)
+void BOPDS_DS::SortPaveBlocks(const Handle(BOPDS_CommonBlock)& aCB)
 {
   Standard_Integer theI;
   Standard_Boolean bToSort;
@@ -1614,8 +1675,8 @@ static
 // function: IsToSort
 // purpose:
 //=======================================================================
-  Standard_Boolean BOPDS_DS::IsToSort(const Handle(BOPDS_CommonBlock)& aCB,
-                                      Standard_Integer& theI)
+Standard_Boolean BOPDS_DS::IsToSort(const Handle(BOPDS_CommonBlock)& aCB,
+                                   Standard_Integer& theI)
 {
   Standard_Boolean bRet;
   bRet = Standard_False;
@@ -1656,8 +1717,8 @@ static
 // function: IsSubShape
 // purpose:
 //=======================================================================
-  Standard_Boolean BOPDS_DS::IsSubShape(const Standard_Integer theI1,
-                                        const Standard_Integer theI2)
+Standard_Boolean BOPDS_DS::IsSubShape(const Standard_Integer theI1,
+                                     const Standard_Integer theI2)
 {
   Standard_Boolean bRet;
   Standard_Integer nS;
@@ -1683,8 +1744,8 @@ static
 // function: Paves
 // purpose:
 //=======================================================================
-  void BOPDS_DS::Paves(const Standard_Integer theEdge,
-                       BOPDS_ListOfPave& theLP)
+void BOPDS_DS::Paves(const Standard_Integer theEdge,
+                    BOPDS_ListOfPave& theLP)
 {
   Standard_Integer aNb, i;
   BOPDS_Pave *pPaves;
@@ -1724,8 +1785,8 @@ static
 // function: UpdateTolerance
 // purpose:
 //=======================================================================
-  void BOPDS_DS::UpdateEdgeTolerance(const Standard_Integer nE,
-                                     const Standard_Real aTol)
+void BOPDS_DS::UpdateEdgeTolerance(const Standard_Integer nE,
+                                  const Standard_Real aTol)
 {
   Standard_Integer nV;
   Standard_Real aTolV;
@@ -1872,3 +1933,79 @@ void SortShell(const int n, BOPDS_Pave *a)
     }//for (i=0; i<nd; ++i) 
   }//while (1)
 }
+//=======================================================================
+//function : BuildBndBoxSolid
+//purpose  : 
+//=======================================================================
+void BOPDS_DS::BuildBndBoxSolid(const Standard_Integer theIndex,
+                               Bnd_Box& aBoxS)
+{
+  Standard_Boolean bIsOpenBox, bIsInverted;
+  Standard_Integer nSh, nFc;
+  Standard_Real aTolS, aTolFc;
+  BOPCol_ListIteratorOfListOfInteger aItLI, aItLI1;
+  //
+  const BOPDS_ShapeInfo& aSI=ShapeInfo(theIndex);
+  const TopoDS_Shape& aS=aSI.Shape();
+  const TopoDS_Solid& aSolid=(*(TopoDS_Solid*)(&aS));
+  //
+  bIsOpenBox=Standard_False;
+  //
+  aTolS=0.;
+  const BOPCol_ListOfInteger& aLISh=aSI.SubShapes();
+  aItLI.Initialize(aLISh);
+  for (; aItLI.More(); aItLI.Next()) {
+    nSh=aItLI.Value();
+    const BOPDS_ShapeInfo& aSISh=ShapeInfo(nSh);
+    if (aSISh.ShapeType()!=TopAbs_SHELL) {
+      continue;
+    }
+    //
+    const BOPCol_ListOfInteger& aLIFc=aSISh.SubShapes();
+    aItLI1.Initialize(aLIFc);
+    for (; aItLI1.More(); aItLI1.Next()) {
+      nFc=aItLI1.Value();
+      const BOPDS_ShapeInfo& aSIFc=ShapeInfo(nFc);
+      if (aSIFc.ShapeType()!=TopAbs_FACE) {
+       continue;
+      }
+      //
+      const Bnd_Box& aBFc=aSIFc.Box();
+      aBoxS.Add(aBFc);
+      //
+      if (!bIsOpenBox) {
+       bIsOpenBox=(aBFc.IsOpenXmin() || aBFc.IsOpenXmax() ||
+                   aBFc.IsOpenYmin() || aBFc.IsOpenYmax() ||
+                   aBFc.IsOpenZmin() || aBFc.IsOpenZmax()); 
+       if (bIsOpenBox) {
+         break;
+       }
+      }
+      //
+      const TopoDS_Face& aFc=*((TopoDS_Face*)&aSIFc.Shape());
+      aTolFc=BRep_Tool::Tolerance(aFc);
+      if (aTolFc>aTolS) {
+       aTolS=aTolFc;
+      }
+    }//for (; aItLI1.More(); aItLI1.Next()) {
+    if (bIsOpenBox) {
+      break;
+    }
+    //
+    const TopoDS_Shell& aSh=*((TopoDS_Shell*)&aSISh.Shape());
+    bIsOpenBox=BOPTools_AlgoTools::IsOpenShell(aSh);
+    if (bIsOpenBox) {
+      break;
+    }
+  }//for (; aItLI.More(); aItLI.Next()) {
+  //
+  if (bIsOpenBox) {
+    aBoxS.SetWhole();
+  }
+  else {
+    bIsInverted=BOPTools_AlgoTools::IsInvertedSolid(aSolid);
+    if (bIsInverted) {
+      aBoxS.SetWhole(); 
+    }
+  }
+}