0024933: Inconsistent results of self-interferences checker in SALOME and DRAW Applic...
[occt.git] / src / BOPAlgo / BOPAlgo_ArgumentAnalyzer.cxx
index c715e05..113d41c 100644 (file)
@@ -3,8 +3,8 @@
 //
 // This file is part of Open CASCADE Technology software library.
 //
-// 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
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License 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.
 
 #include <Standard_ErrorHandler.hxx>
 #include <Standard_Failure.hxx>
-#include <TopExp.hxx>
-#include <TopExp_Explorer.hxx>
-#include <BRep_Builder.hxx>
-#include <BRep_Tool.hxx>
-#include <BRepExtrema_DistShapeShape.hxx>
+
+#include <TColStd_Array2OfBoolean.hxx>
+
 #include <gp_Pnt.hxx>
+
+#include <Geom_Surface.hxx>
+
 #include <TopoDS_Iterator.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Vertex.hxx>
 #include <TopoDS_Wire.hxx>
 #include <TopoDS_Shell.hxx>
 #include <TopoDS_Solid.hxx>
+
+#include <BRep_Builder.hxx>
+#include <BRep_Tool.hxx>
+
+#include <TopExp.hxx>
+#include <TopExp_Explorer.hxx>
+
+#include <BRepExtrema_DistShapeShape.hxx>
+//
 #include <BOPCol_ListOfShape.hxx>
 #include <BOPCol_SequenceOfShape.hxx>
 #include <BOPCol_MapOfShape.hxx>
 
-#include <TColStd_Array2OfBoolean.hxx>
-
 #include <IntTools_Range.hxx>
 #include <IntTools_EdgeEdge.hxx>
 #include <IntTools_CommonPrt.hxx>
 
-#include <BOPAlgo_Operation.hxx>
-#include <BOPAlgo_CheckerSI.hxx>
-#include <BOPAlgo_BuilderFace.hxx>
-
-#include <BOPDS_DS.hxx>
-#include <BOPDS_VectorOfInterfVV.hxx>
-#include <BOPDS_VectorOfInterfVE.hxx>
-#include <BOPDS_VectorOfInterfEE.hxx>
-#include <BOPDS_VectorOfInterfVF.hxx>
-#include <BOPDS_VectorOfInterfEF.hxx>
-#include <BOPDS_VectorOfInterfFF.hxx>
-
 #include <BOPInt_Context.hxx>
 
 #include <BOPTools_AlgoTools3D.hxx>
 #include <BOPTools_AlgoTools.hxx>
-#include <BOPCol_ListOfShape.hxx>
-#include <Geom_Surface.hxx>
+
+#include <BOPDS_DS.hxx>
+#include <BOPDS_MapOfPassKey.hxx>
+
+#include <BOPAlgo_Operation.hxx>
+#include <BOPAlgo_CheckerSI.hxx>
+#include <BOPAlgo_BuilderFace.hxx>
 
 // ================================================================================
 // function: Constructor
@@ -296,108 +297,65 @@ void BOPAlgo_ArgumentAnalyzer::TestTypes()
     }
   }
 }
-
-// ================================================================================
-// function: TestSelfInterferences
-// purpose:
-// ================================================================================
+//=======================================================================
+//function : TestSelfInterferences
+//purpose  : 
+//=======================================================================
 void BOPAlgo_ArgumentAnalyzer::TestSelfInterferences()
 {
-  Standard_Integer ii = 0, j;
-  Standard_Boolean bSelfInt;
-
+  Standard_Integer ii;
+  //
   for(ii = 0; ii < 2; ii++) {
     const TopoDS_Shape& aS = (ii == 0) ? myShape1 : myShape2;
-
-    if(aS.IsNull())
+    if(aS.IsNull()) {
       continue;
-
+    }
+    //
     Standard_Boolean bIsEmpty = (ii == 0) ? myEmpty1 : myEmpty2;
     if (bIsEmpty) {
       continue;
     }
-
-    BOPAlgo_CheckerSI aChecker;
+    //
+    Standard_Integer iErr, n1, n2;
+    BOPDS_MapIteratorMapOfPassKey aItMPK;
     BOPCol_ListOfShape anArgs;
+    BOPAlgo_CheckerSI aChecker;
+    //
     anArgs.Append(aS);
     aChecker.SetArguments(anArgs);
     //
     aChecker.Perform();
-    Standard_Integer iErr = aChecker.ErrorStatus();
-    //
-    const BOPDS_PDS& theDS = aChecker.PDS();
-    BOPDS_VectorOfInterfVV& aVVs=theDS->InterfVV();
-    BOPDS_VectorOfInterfVE& aVEs=theDS->InterfVE();
-    BOPDS_VectorOfInterfEE& aEEs=theDS->InterfEE();
-    BOPDS_VectorOfInterfVF& aVFs=theDS->InterfVF();
-    BOPDS_VectorOfInterfEF& aEFs=theDS->InterfEF();
-    BOPDS_VectorOfInterfFF& aFFs=theDS->InterfFF();
+    iErr=aChecker.ErrorStatus();
     //
-    Standard_Integer aNb[6] = {aVVs.Extent(), aVEs.Extent(), aEEs.Extent(), 
-                               aVFs.Extent(), aEFs.Extent(), aFFs.Extent()};
+    const BOPDS_DS& aDS=*(aChecker.PDS());
+    const BOPDS_MapOfPassKey& aMPK=aDS.Interferences();
     //
-    for (Standard_Integer aTypeInt = 0; aTypeInt < 6; ++aTypeInt) {
-      for (Standard_Integer i = 0; i < aNb[aTypeInt]; ++i) {
-        BOPDS_Interf* aInt = (aTypeInt==0) ? (BOPDS_Interf*)(&aVVs(i)) : 
-          ((aTypeInt==1) ? (BOPDS_Interf*)(&aVEs(i)) :
-           ((aTypeInt==2) ? (BOPDS_Interf*)(&aEEs(i)) : 
-            ((aTypeInt==3) ? (BOPDS_Interf*)(&aVFs(i)) :
-             ((aTypeInt==4) ? (BOPDS_Interf*)(&aEFs(i)) : (BOPDS_Interf*)(&aFFs(i))))));
-        //
-        Standard_Integer nI1 = aInt->Index1();
-        Standard_Integer nI2 = aInt->Index2();
-        if (nI1 == nI2) {
-          continue;
-        }
-        //
-        if (aTypeInt == 4) {
-          BOPDS_InterfEF& aEF=aEFs(i);
-          if (aEF.CommonPart().Type()==TopAbs_SHAPE) {
-            continue;
-          }
-        }
-        //
-        const TopoDS_Shape& aS1 = theDS->Shape(nI1);
-        const TopoDS_Shape& aS2 = theDS->Shape(nI2);
-        //
-        if (aTypeInt == 5) {
-          bSelfInt = Standard_False;
-          BOPDS_InterfFF& aFF = aFFs(i);
-          BOPDS_VectorOfPoint& aVP=aFF.ChangePoints();
-          Standard_Integer aNbP=aVP.Extent();
-          BOPDS_VectorOfCurve& aVC=aFF.ChangeCurves();
-          Standard_Integer aNbC=aVC.Extent();
-          if (!aNbP && !aNbC) {
-            continue;
-          }
-          for (j=0; j<aNbC; ++j) {
-            BOPDS_Curve& aNC=aVC(j);
-            BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks();
-            if (aLPBC.Extent()) {
-              bSelfInt = Standard_True;
-              break;
-            }
-          }
-          if (!bSelfInt) {
-            continue;
-          }
-        }
-        //
-        BOPAlgo_CheckResult aResult;
-        if(ii == 0) {
-          aResult.SetShape1(myShape1);
-          aResult.AddFaultyShape1(aS1);
-          aResult.AddFaultyShape1(aS2);
-        }
-        else {
-          aResult.SetShape2(myShape2);
-          aResult.AddFaultyShape2(aS1);
-          aResult.AddFaultyShape2(aS2);
-        }
-        aResult.SetCheckStatus(BOPAlgo_SelfIntersect);
-        myResult.Append(aResult);
+    aItMPK.Initialize(aMPK);
+    for (; aItMPK.More(); aItMPK.Next()) {
+      const BOPDS_PassKey& aPK=aItMPK.Value();
+      aPK.Ids(n1, n2);
+      if(aDS.IsNewShape(n1) || aDS.IsNewShape(n2)) {
+        continue;
+      }
+      //
+      const TopoDS_Shape& aS1=aDS.Shape(n1);
+      const TopoDS_Shape& aS2=aDS.Shape(n2);
+      //
+      BOPAlgo_CheckResult aResult;
+      if(ii == 0) {
+        aResult.SetShape1(myShape1);
+        aResult.AddFaultyShape1(aS1);
+        aResult.AddFaultyShape1(aS2);
+      }
+      else {
+        aResult.SetShape2(myShape2);
+        aResult.AddFaultyShape2(aS1);
+        aResult.AddFaultyShape2(aS2);
       }
+      aResult.SetCheckStatus(BOPAlgo_SelfIntersect);
+      myResult.Append(aResult);
     }
+    //
     if (iErr) {
       BOPAlgo_CheckResult aResult;
       if(ii == 0) {
@@ -411,10 +369,8 @@ void BOPAlgo_ArgumentAnalyzer::TestSelfInterferences()
       aResult.SetCheckStatus(BOPAlgo_OperationAborted);
       myResult.Append(aResult);
     }
-  }
-  
+  }// for(ii = 0; ii < 2; ii++) {
 }
-
 // ================================================================================
 // function: TestSmallEdge
 // purpose:
@@ -520,7 +476,6 @@ void BOPAlgo_ArgumentAnalyzer::TestSmallEdge()
     }
   }
 }
-
 // ================================================================================
 // function: TestRebuildFace
 // purpose:
@@ -699,28 +654,12 @@ void BOPAlgo_ArgumentAnalyzer::TestTangent()
         }
       }
       else if(theType == TopAbs_EDGE) {
-        Standard_Integer aDiscretize = 30;
-        Standard_Real    aDeflection = 0.01;
         const TopoDS_Edge& aE1 = *(TopoDS_Edge*)&(aS1);
         const TopoDS_Edge& aE2 = *(TopoDS_Edge*)&(aS2);
-        
-        IntTools_EdgeEdge aEE;
-        aEE.SetEdge1 (aE1);
-        aEE.SetEdge2 (aE2);
-        aEE.SetTolerance1 (BRep_Tool::Tolerance(aE1));
-        aEE.SetTolerance2 (BRep_Tool::Tolerance(aE2));
-        aEE.SetDiscretize (aDiscretize);
-        aEE.SetDeflection (aDeflection);
-        
-        Standard_Real f = 0., l = 0.;
-        BRep_Tool::Range(aE1, f, l);
-        aEE.SetRange1(f, l);
-        
-        BRep_Tool::Range(aE2, f, l);
-        aEE.SetRange2(f, l);
-        
+        //
+        IntTools_EdgeEdge aEE(aE1, aE2);
+        //
         aEE.Perform();
-        
         if (aEE.IsDone()) {
           const IntTools_SequenceOfCommonPrts& aCPrts = aEE.CommonParts();
           Standard_Integer ii = 0;