Salome HOME
Fix for the bug IPAL22851: Sub-shapes spelling
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_Builder_2.cxx
index fe064bbbe3f22634ed166e23a32bd2f5a444734c..9818ad60e6e17a43db8fc481608300c19a550c8e 100755 (executable)
@@ -1,25 +1,24 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// 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
+// 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.
+// 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.
 //
-//  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.
+// 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
+// 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
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-
 // File:        GEOMAlgo_Builder_2.cxx
 // Author:      Peter KURNEV
 
 #include <TopTools_DataMapOfIntegerShape.hxx>
 #include <TColStd_ListOfInteger.hxx>
 #include <TColStd_ListIteratorOfListOfInteger.hxx>
+#include <TopTools_DataMapOfShapeInteger.hxx>
 
 static
   void UpdateCandidates(const Standard_Integer ,
                         const Standard_Integer ,
                         NMTTools_IndexedDataMapOfIndexedMapOfInteger& );
 
+
 //=======================================================================
 //function : FillImagesFaces
 //purpose  :
 //=======================================================================
-  void GEOMAlgo_Builder::FillImagesFaces()
+void GEOMAlgo_Builder::FillImagesFaces()
 {
   myErrorStatus=0;
   //
@@ -120,7 +121,7 @@ static
 // function: FillIn2DParts
 // purpose:
 //=======================================================================
-  void GEOMAlgo_Builder::FillIn2DParts()
+void GEOMAlgo_Builder::FillIn2DParts()
 {
   const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
   NMTTools_PaveFiller* pPF=myPaveFiller;
@@ -153,20 +154,16 @@ static
     aLSpIn.Clear();
     //
     // 1. In Parts
-    for (j=1; j<=aNbCBP; ++j) {
-      NMTTools_ListOfCommonBlock& aLCB=aCBP(j);
-      aItCB.Initialize(aLCB);
-      for (; aItCB.More(); aItCB.Next()) {
-        NMTTools_CommonBlock& aCB=aItCB.Value();
-        if (aCB.IsPaveBlockOnFace(nF)) {
-          const BOPTools_PaveBlock& aPB1=aCB.PaveBlock1();
-          nSpIn=aPB1.Edge();
-          const TopoDS_Shape& aSpIn=aDS.Shape(nSpIn);
-          if (aMFence.Add(aSpIn)){
-            aLSpIn.Append(aSpIn);
-          }
-        }
-      }
+    BOPTools_ListOfPaveBlock aLPBIn;
+    //
+    pPF->RealSplitsInFace(nF, aLPBIn);
+    //
+    aItPB.Initialize(aLPBIn);
+    for (; aItPB.More(); aItPB.Next()) {
+      const BOPTools_PaveBlock& aPB1=aItPB.Value();
+      nSpIn=aPB1.Edge();
+      const TopoDS_Shape& aSpIn=aDS.Shape(nSpIn);
+      aLSpIn.Append(aSpIn);
     }
     //
     // 2. Section Parts
@@ -205,7 +202,7 @@ static
 // function: BuildSplitFaces
 // purpose:
 //=======================================================================
-  void GEOMAlgo_Builder::BuildSplitFaces()
+void GEOMAlgo_Builder::BuildSplitFaces()
 {
   const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
   NMTTools_PaveFiller* pPF=myPaveFiller;
@@ -409,13 +406,13 @@ static
 // function: FillSameDomainFaces
 // purpose:
 //=======================================================================
-  void GEOMAlgo_Builder::FillSameDomainFaces()
+void GEOMAlgo_Builder::FillSameDomainFaces()
 {
-  Standard_Boolean bIsSDF, bHasImage1, bHasImage2;
+  Standard_Boolean bIsSDF, bHasImage1, bHasImage2, bForward;
   Standard_Integer i, j, aNbFF, nF1, nF2, aNbPBInOn, aNbC, aNbSE;
   Standard_Integer aNbF1, aNbF2, i2s, aNbSD;
   TopTools_MapOfShape aMFence;
-  TopTools_ListOfShape aLSempty;
+  TopTools_ListOfShape aLX1, aLX2;
   TopTools_ListIteratorOfListOfShape aItF1, aItF2;
   NMTTools_ListOfCoupleOfShape aLCS;
   //
@@ -463,12 +460,22 @@ static
     // Try to find SDF among images of nF1, nF2
     aMFence.Clear();
     //
-    //XXXXXXXXXXXXXf
+    //--------------------------------------------------------
     bHasImage1=mySplitFaces.HasImage(aF1);
     bHasImage2=mySplitFaces.HasImage(aF2);
     //
-    const TopTools_ListOfShape& aLF1r=(bHasImage1)? mySplitFaces.Image(aF1) : aLSempty;
-    const TopTools_ListOfShape& aLF2r=(bHasImage2)? mySplitFaces.Image(aF2) : aLSempty;
+    aLX1.Clear();
+    if (!bHasImage1) {
+      aLX1.Append(aF1);
+    }
+    //
+    aLX2.Clear();
+    if (!bHasImage2) {
+      aLX2.Append(aF2);
+    }
+    //
+    const TopTools_ListOfShape& aLF1r=(bHasImage1)? mySplitFaces.Image(aF1) : aLX1;
+    const TopTools_ListOfShape& aLF2r=(bHasImage2)? mySplitFaces.Image(aF2) : aLX2;
     //
     TopTools_DataMapOfIntegerShape aMIS;
     TColStd_ListIteratorOfListOfInteger aItLI;
@@ -478,8 +485,10 @@ static
     //
     aNbF1=aLF1r.Extent();
     aNbF2=aLF2r.Extent();
-    const TopTools_ListOfShape& aLF1=(aNbF1<aNbF2)? aLF1r : aLF2r;
-    const TopTools_ListOfShape& aLF2=(aNbF1<aNbF2)? aLF2r : aLF1r;
+    bForward=(aNbF1<aNbF2);
+    //
+    const TopTools_ListOfShape& aLF1=bForward ? aLF1r : aLF2r;
+    const TopTools_ListOfShape& aLF2=bForward ? aLF2r : aLF1r;
     //
     // 1. aTreeFiller
     aItF2.Initialize(aLF2);
@@ -518,10 +527,10 @@ static
       for (; aItLI.More(); aItLI.Next()) {
         i2s=aItLI.Value();
         const TopoDS_Face& aF2y=*((TopoDS_Face*)(&aMIS.Find(i2s)));
+        //
         bIsSDF=NMTTools_Tools::AreFacesSameDomain(aF1x, aF2y, aCtx);
         if (bIsSDF) {
-          if (aMFence.Contains(aF1x) ||
-              aMFence.Contains(aF2y)) {
+          if (aMFence.Contains(aF1x) || aMFence.Contains(aF2y)) {
             continue;
           }
           aMFence.Add(aF1x);
@@ -533,22 +542,37 @@ static
           aCS.SetShape2(aF2y);
           aLCS.Append(aCS);
           //
-          if (aF1x==aF1) {
-            if (!mySplitFaces.HasImage(aF1)) {
-              mySplitFaces.Bind(aF1, aF1);
+          if (bForward) {
+            if (aF1x==aF1) {
+              if (!mySplitFaces.HasImage(aF1)) {
+                mySplitFaces.Bind(aF1, aF1);
+              }
+            }
+            if (aF2y==aF2) {
+              if (!mySplitFaces.HasImage(aF2)) {
+                mySplitFaces.Bind(aF2, aF2);
+              }
             }
           }
-          if (aF2y==aF2) {
-            if (!mySplitFaces.HasImage(aF2)) {
-              mySplitFaces.Bind(aF2, aF2);
+          else {
+            if (aF1x==aF2) {
+              if (!mySplitFaces.HasImage(aF2)) {
+                mySplitFaces.Bind(aF2, aF2);
+              }
+            }
+            if (aF2y==aF1) {
+              if (!mySplitFaces.HasImage(aF1)) {
+                mySplitFaces.Bind(aF1, aF1);
+              }
             }
           }
+          //
           break;
         }//if (bIsSDF) {
       }//for (; aItLI.More(); aItLI.Next()) {
     }//for (; aItF1.More(); aItF1.Next()) {
   }//for (i=1; i<=aNbFF; ++i)
-  //XXXXXXXXXXXXXt
+  //-------------------------------------------------------------
   aNbC=aLCS.Extent();
   if (!aNbC) {
     return;
@@ -557,18 +581,60 @@ static
   // 2. Find Chains
   NMTTools_IndexedDataMapOfShapeIndexedMapOfShape aMC;
   //
-  NMTTools_Tools::FindChains(aLCS, aMC);
+  NMTTools_Tools::FindChains(aLCS, aMC); 
+  //
+  Standard_Boolean bIsImage;
+  Standard_Integer aIx, aIxMin, aNbMSDF, k, aNbMFj;
+  TopoDS_Shape aFOld, aFSDmin;
+  TopTools_IndexedMapOfShape aMFj;
+  TopTools_DataMapOfShapeInteger aDMSI;
+  //
+  aItF1.Initialize(myShapes);
+  for (j=1; aItF1.More(); aItF1.Next(), ++j) {
+    const TopoDS_Shape& aSj=aItF1.Value();
+    aMFj.Clear();
+    TopExp::MapShapes(aSj, TopAbs_FACE, aMFj);
+    aNbMFj=aMFj.Extent();
+    for (k=1; k<=aNbMFj; ++k) {
+      const TopoDS_Shape& aFk=aMFj(k);
+      if (!aDMSI.IsBound(aFk)) {
+       aDMSI.Bind(aFk, j);
+      }
+    }
+  }
   //
   // 3. Fill the map of SDF mySameDomainFaces
   aNbC=aMC.Extent();
   for (i=1; i<=aNbC; ++i) {
-    const TopoDS_Shape& aF=aMC.FindKey(i);
+   // const TopoDS_Shape& aF=aMC.FindKey(i);
     const TopTools_IndexedMapOfShape& aMSDF=aMC(i);
     //
-    aNbFF=aMSDF.Extent();
-    for (j=1; j<=aNbFF; ++j) {
+    aNbMSDF=aMSDF.Extent();
+    for (j=1; j<=aNbMSDF; ++j) {
       const TopoDS_Shape& aFSD=aMSDF(j);
-      mySameDomainShapes.Add(aFSD, aF);
+      bIsImage=mySplitFaces.IsImage(aFSD);
+      aFOld=aFSD;
+      if (bIsImage) {
+       aFOld=mySplitFaces.ImageFrom(aFSD);
+      }
+      //
+      aIx=aDMSI.Find(aFOld);
+      if (j==1) {
+       aIxMin=aIx;
+       aFSDmin=aFSD;
+       continue;
+      }
+      else {
+       if (aIx<aIxMin) {
+         aIxMin=aIx;
+         aFSDmin=aFSD;
+       }
+      }
+    }
+    //
+    for (j=1; j<=aNbMSDF; ++j) {
+      const TopoDS_Shape& aFSD=aMSDF(j);
+      mySameDomainShapes.Add(aFSD, aFSDmin);
     }
   }
   //
@@ -578,7 +644,7 @@ static
 // function: FillImagesFaces1
 // purpose:
 //=======================================================================
-  void GEOMAlgo_Builder::FillImagesFaces1()
+void GEOMAlgo_Builder::FillImagesFaces1()
 {
   Standard_Integer i, aNb, iSense, aNbLFx;
   TopoDS_Face aF, aFSp, aFSD;
@@ -598,19 +664,19 @@ static
       continue;
     }
     //
-    aF=TopoDS::Face(aS);
+    aF=*((TopoDS_Face*)&aS);
     //
     aLFx.Clear();
     const TopTools_ListOfShape& aLF=mySplitFaces.Image(aF);
     aIt.Initialize(aLF);
     for (; aIt.More(); aIt.Next()) {
-      aFSp=TopoDS::Face(aIt.Value());
+      aFSp=*((TopoDS_Face*)(&aIt.Value()));
       if (!mySameDomainShapes.Contains(aFSp)) {
         aLFx.Append(aFSp);
       }
       else {
         const TopoDS_Shape& aSx=mySameDomainShapes.FindFromKey(aFSp);
-        aFSD=TopoDS::Face(aSx);
+        aFSD=*((TopoDS_Face*)(&aSx));
         iSense=GEOMAlgo_Tools3D::Sense(aFSp, aFSD);
         if (iSense<0) {
           aFSD.Reverse();
@@ -618,6 +684,7 @@ static
         aLFx.Append(aFSD);
       }
     }
+    //
     if (!myImages.HasImage(aF)) {
       aNbLFx=aLFx.Extent();
       if (aNbLFx==1) {
@@ -635,14 +702,13 @@ static
 // function: FillInternalVertices
 // purpose:
 //=======================================================================
-  void GEOMAlgo_Builder::FillInternalVertices()
+void GEOMAlgo_Builder::FillInternalVertices()
 {
   const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
   NMTTools_PaveFiller* pPF=myPaveFiller;
   NMTDS_InterfPool* pIP=pPF->IP();
   IntTools_Context& aCtx= pPF->ChangeContext();
   //
-  /*BOPTools_CArray1OfSSInterference& aFFs=*/pIP->SSInterferences();
   BOPTools_CArray1OfVSInterference& aVFs=pIP->VSInterferences();
   BOPTools_CArray1OfESInterference& aEFs=pIP->ESInterferences();
   const NMTTools_IndexedDataMapOfIndexedMapOfInteger& aMAV=pPF->AloneVertices();