Salome HOME
Mantis issue 0021453: EDF GEOM: (regression). A fix by PKV.
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IMeasureOperations.cxx
index 26097ccdb195488c1992f7735bc5aa3ce3f2346a..1559dd62b90aa19e65bbd9790fcbaa7f5800e92d 100644 (file)
@@ -18,7 +18,6 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
 
 #include <Standard_Stream.hxx>
 
 #include <GEOM_Function.hxx>
 #include <GEOM_PythonDump.hxx>
 
+#include <NMTTools_CheckerSI.hxx>
+
+#include <NMTDS_Tools.hxx>
+#include <NMTDS_InterfPool.hxx>
+#include <NMTDS_PInterfPool.hxx>
+//#include <NMTDS_PassKeyBoolean.hxx>
+#include <NMTDS_PairBoolean.hxx>
+#include <NMTDS_ShapesDataStructure.hxx>
+//#include <NMTDS_ListIteratorOfListOfPassKeyBoolean.hxx>
+#include <NMTDS_ListIteratorOfListOfPairBoolean.hxx>
+
+#include <Basics_OCCTVersion.hxx>
+
 #include <utilities.h>
 #include <OpUtil.hxx>
 #include <Utils_ExceptHandlers.hxx>
@@ -837,7 +849,7 @@ void GEOMImpl_IMeasureOperations::GetPosition
   }
 
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
 #endif
 
@@ -893,7 +905,7 @@ Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
 
   //Compute the CentreOfMass value
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
 #endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
@@ -947,7 +959,7 @@ Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetVertexByIndex
 
   //Compute
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
 #endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
@@ -1006,7 +1018,7 @@ Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetNormal
 
   //Compute the Normale value
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
 #endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
@@ -1058,7 +1070,7 @@ void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theSha
   //Compute the parameters
   GProp_GProps LProps, SProps;
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
 #endif
     BRepGProp::LinearProperties(aShape, LProps);
@@ -1114,7 +1126,7 @@ void GEOMImpl_IMeasureOperations::GetInertia
   GProp_GProps System;
 
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
 #endif
     if (aShape.ShapeType() == TopAbs_VERTEX ||
@@ -1181,7 +1193,7 @@ void GEOMImpl_IMeasureOperations::GetBoundingBox
   Bnd_Box B;
 
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
 #endif
     BRepBndLib::Add(aShape, B);
@@ -1226,7 +1238,7 @@ void GEOMImpl_IMeasureOperations::GetTolerance
   FaceMax = EdgeMax = VertMax = -RealLast();
 
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
 #endif
     for (TopExp_Explorer ExF (aShape, TopAbs_FACE); ExF.More(); ExF.Next()) {
@@ -1288,7 +1300,7 @@ bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object)      theShape,
   //Compute the parameters
   bool isValid = false;
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
 #endif
     BRepCheck_Analyzer ana (aShape, theIsCheckGeom);
@@ -1309,6 +1321,91 @@ bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object)      theShape,
   return isValid;
 }
 
+//=============================================================================
+/*!
+ *  CheckSelfIntersections
+ */
+//=============================================================================
+bool GEOMImpl_IMeasureOperations::CheckSelfIntersections
+                         (Handle(GEOM_Object)                 theShape,
+                          Handle(TColStd_HSequenceOfInteger)& theIntersections)
+{
+  SetErrorCode(KO);
+  bool isGood = false;
+
+  if (theIntersections.IsNull())
+    theIntersections = new TColStd_HSequenceOfInteger;
+  else
+    theIntersections->Clear();
+
+  if (theShape.IsNull())
+    return isGood;
+
+  Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
+  if (aRefShape.IsNull()) return isGood;
+
+  TopoDS_Shape aShape = aRefShape->GetValue();
+  if (aShape.IsNull()) return isGood;
+
+  // 0. Prepare data
+  BRep_Builder aBB;
+  TopoDS_Compound aCS;
+  TopoDS_Shape aScopy;
+  NMTDS_Tools::CopyShape(aShape, aScopy);
+
+  // Map sub-shapes and their indices
+  TopTools_IndexedMapOfShape anIndices;
+  TopExp::MapShapes(aScopy, anIndices);
+
+  aBB.MakeCompound(aCS);
+  aBB.Add(aCS, aScopy);
+
+  NMTTools_CheckerSI aCSI; // checker of self-interferences
+  aCSI.SetCompositeShape(aCS);
+
+  // 1. Launch the checker
+  aCSI.Perform();
+  Standard_Integer iErr = aCSI.StopStatus();
+  if (iErr) {
+    return false; // Error
+  }
+
+  isGood = true;
+
+  // 2. Take the shapes from DS
+  const NMTDS_ShapesDataStructure& aDS = *(aCSI.DS());
+  Standard_Integer aNbS = aDS.NumberOfShapesOfTheObject();
+
+  // 3. Get the pairs of interfered shapes 
+  NMTDS_PInterfPool pIP = aCSI.IP();
+  //const NMTDS_ListOfPassKeyBoolean& aLPKB = pIP->Get();
+  const NMTDS_ListOfPairBoolean& aLPKB = pIP->Get();
+
+  Standard_Integer n1, n2;
+  //NMTDS_ListIteratorOfListOfPassKeyBoolean aIt;
+  NMTDS_ListIteratorOfListOfPairBoolean aIt;
+
+  aIt.Initialize(aLPKB);
+  for (; aIt.More(); aIt.Next()) {
+    //const NMTDS_PassKeyBoolean& aPKB = aIt.Value();
+    const NMTDS_PairBoolean& aPKB = aIt.Value();
+    aPKB.Ids(n1, n2);
+
+    if (n1 > aNbS || n2 > aNbS)
+      return false; // Error
+
+    const TopoDS_Shape& aS1 = aDS.Shape(n1);
+    const TopoDS_Shape& aS2 = aDS.Shape(n2);
+
+    theIntersections->Append(anIndices.FindIndex(aS1));
+    theIntersections->Append(anIndices.FindIndex(aS2));
+    isGood = false;
+  }
+
+  SetErrorCode(OK);
+  return isGood;
+}
+
 //=============================================================================
 /*!
  *  IsGoodForSolid
@@ -1389,7 +1486,7 @@ TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object)
   Astr = Astr + " Number of sub-shapes : \n";
 
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
 #endif
     int iType, nbTypes [TopAbs_SHAPE];
@@ -1797,7 +1894,7 @@ Standard_Real GEOMImpl_IMeasureOperations::GetMinDistance
 
   //Compute the parameters
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
 #endif
 
@@ -1895,7 +1992,7 @@ void GEOMImpl_IMeasureOperations::PointCoordinates (Handle(GEOM_Object) theShape
   }
 
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
 #endif
     gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
@@ -1920,6 +2017,10 @@ void GEOMImpl_IMeasureOperations::PointCoordinates (Handle(GEOM_Object) theShape
 Standard_Real GEOMImpl_IMeasureOperations::GetAngle (Handle(GEOM_Object) theLine1,
                                                      Handle(GEOM_Object) theLine2)
 {
+  if (theLine1->GetType() == GEOM_VECTOR &&
+      theLine2->GetType() == GEOM_VECTOR)
+    return GetAngleBtwVectors(theLine1, theLine2);
+
   SetErrorCode(KO);
 
   Standard_Real anAngle = -1.0;
@@ -1943,7 +2044,7 @@ Standard_Real GEOMImpl_IMeasureOperations::GetAngle (Handle(GEOM_Object) theLine
   }
 
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
 #endif
     TopoDS_Edge E1 = TopoDS::Edge(aLine1);
@@ -1968,7 +2069,7 @@ Standard_Real GEOMImpl_IMeasureOperations::GetAngle (Handle(GEOM_Object) theLine
     gp_Lin aLin2 = L2->Lin();
 
     anAngle = aLin1.Angle(aLin2);
-    anAngle /= PI180; // convert radians into degrees
+    anAngle *= 180. / M_PI; // convert radians into degrees
 
     if (anAngle > 90.0) {
       anAngle = 180.0 - anAngle;
@@ -2016,7 +2117,7 @@ Standard_Real GEOMImpl_IMeasureOperations::GetAngleBtwVectors (Handle(GEOM_Objec
   }
 
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
 #endif
     TopoDS_Edge aE1 = TopoDS::Edge(aVec1);
@@ -2034,7 +2135,7 @@ Standard_Real GEOMImpl_IMeasureOperations::GetAngleBtwVectors (Handle(GEOM_Objec
     gp_Vec aV2 (BRep_Tool::Pnt(aP21), BRep_Tool::Pnt(aP22)) ;
 
     anAngle = aV1.Angle(aV2);
-    anAngle /= PI180; // convert radians into degrees
+    anAngle *= 180. / M_PI; // convert radians into degrees
 
     SetErrorCode(OK);
   }
@@ -2078,7 +2179,7 @@ Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByParam
 
   //Compute curvature
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
 #endif
     GeomLProp_CLProps Prop = GeomLProp_CLProps
@@ -2132,7 +2233,7 @@ Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByPoint
 
   //Compute curvature
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
 #endif
     GeomAPI_ProjectPointOnCurve PPCurve(aPoint, aCurve, aFP, aLP);
@@ -2175,7 +2276,7 @@ Standard_Real GEOMImpl_IMeasureOperations::getSurfaceCurvatures
   if (aSurf.IsNull()) return aRes;
 
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
 #endif
     GeomLProp_SLProps Prop = GeomLProp_SLProps
@@ -2528,7 +2629,7 @@ void GEOMImpl_IMeasureOperations::StructuralDump (const BRepCheck_Analyzer& theA
   }
   count = NbProblems->Value((Standard_Integer)BRepCheck_SubshapeNotInShape);
   if (count > 0) {
-    theDump += "  Subshape not in Shape .................... ";
+    theDump += "  Sub-shape not in Shape .................... ";
     theDump += TCollection_AsciiString(count) + "\n";
   }
   count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientation);
@@ -2538,7 +2639,7 @@ void GEOMImpl_IMeasureOperations::StructuralDump (const BRepCheck_Analyzer& theA
   }
   count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientationOfSubshape);
   if (count > 0) {
-    theDump += "  Bad Orientation of Subshape .............. ";
+    theDump += "  Bad Orientation of Sub-shape .............. ";
     theDump += TCollection_AsciiString(count) + "\n";
   }
   count = NbProblems->Value((Standard_Integer)BRepCheck_CheckFail);