Salome HOME
0023588: [CEA 2272] : GEOM test failed after transition to OCC 7.3
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IMeasureOperations.cxx
index b9598338e087c15db06f3018daaa6ffa701d2688..a06332644285efcee503ab9dcc6dbfac9d83bc89 100644 (file)
@@ -83,8 +83,8 @@
  *  Constructor
  */
 //=============================================================================
-GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations (GEOM_Engine* theEngine, int theDocID)
-: GEOM_IOperations(theEngine, theDocID)
+GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations (GEOM_Engine* theEngine)
+: GEOM_IOperations(theEngine)
 {
   MESSAGE("GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations");
 }
@@ -179,7 +179,7 @@ GEOMImpl_IMeasureOperations::ShapeKind GEOMImpl_IMeasureOperations::KindOfShape
     return SK_LCS;
   }
 
-  // Interprete results
+  // Interpret results
   TopAbs_ShapeEnum aType = anInfo.Type();
   switch (aType)
   {
@@ -736,6 +736,7 @@ GEOMImpl_IMeasureOperations::ShapeKind GEOMImpl_IMeasureOperations::KindOfShape
       theDoubles->Append(aP.Z());
     }
     break;
+  default:;
   }
 
   SetErrorCode(OK);
@@ -805,7 +806,7 @@ Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
   if (theShape.IsNull()) return NULL;
 
   //Add a new CentreOfMass object
-  Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GetDocID(), GEOM_CDG);
+  Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GEOM_CDG);
 
   //Add a new CentreOfMass function
   Handle(GEOM_Function) aFunction =
@@ -859,7 +860,7 @@ Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetVertexByIndex
   if (aRefShape.IsNull()) return NULL;
 
   //Add a new Vertex object
-  Handle(GEOM_Object) aVertex = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
+  Handle(GEOM_Object) aVertex = GetEngine()->AddObject(GEOM_POINT);
 
   //Add a function
   Handle(GEOM_Function) aFunction =
@@ -907,7 +908,7 @@ Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetNormal
   if (theFace.IsNull()) return NULL;
 
   //Add a new Normale object
-  Handle(GEOM_Object) aNorm = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
+  Handle(GEOM_Object) aNorm = GetEngine()->AddObject(GEOM_VECTOR);
 
   //Add a new Normale function
   Handle(GEOM_Function) aFunction =
@@ -1145,7 +1146,7 @@ Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetBoundingBox
   if (theShape.IsNull()) return NULL;
 
   //Add a new BoundingBox object
-  Handle(GEOM_Object) aBnd = GetEngine()->AddObject(GetDocID(), GEOM_BOX);
+  Handle(GEOM_Object) aBnd = GetEngine()->AddObject(GEOM_BOX);
 
   //Add a new BoundingBox function
   const int aType = (precise ? BND_BOX_MEASURE_PRECISE : BND_BOX_MEASURE);
@@ -1600,7 +1601,7 @@ bool GEOMImpl_IMeasureOperations::CheckSelfIntersections
 //=============================================================================
 bool GEOMImpl_IMeasureOperations::CheckSelfIntersectionsFast
                          (Handle(GEOM_Object) theShape,
-                         float theDeflection, double theTolerance,
+                          float theDeflection, double theTolerance,
                           Handle(TColStd_HSequenceOfInteger)& theIntersections)
 {
   SetErrorCode(KO);
@@ -1881,7 +1882,7 @@ TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object)
           aListOfShape.Append(s);
           nbTypes[s.ShapeType()]++;
           if ((sp.ShapeType() == TopAbs_COMPOUND) || (sp.ShapeType() == TopAbs_COMPSOLID)) {
-           nbFlatType[s.ShapeType()]++;
+            nbFlatType[s.ShapeType()]++;
           }
         }
       }
@@ -1900,17 +1901,17 @@ TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object)
     if ((aShape.ShapeType() == TopAbs_COMPOUND) || (aShape.ShapeType() == TopAbs_COMPSOLID)){
       Astr = Astr + " --------------------- \n Flat content : \n";
       if (nbFlatType[TopAbs_VERTEX] > 0)
-       Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbFlatType[TopAbs_VERTEX]) + "\n";
+        Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbFlatType[TopAbs_VERTEX]) + "\n";
       if (nbFlatType[TopAbs_EDGE] > 0)
-       Astr = Astr + " EDGE : " + TCollection_AsciiString(nbFlatType[TopAbs_EDGE]) + "\n";
+        Astr = Astr + " EDGE : " + TCollection_AsciiString(nbFlatType[TopAbs_EDGE]) + "\n";
       if (nbFlatType[TopAbs_WIRE] > 0)
-       Astr = Astr + " WIRE : " + TCollection_AsciiString(nbFlatType[TopAbs_WIRE]) + "\n";
+        Astr = Astr + " WIRE : " + TCollection_AsciiString(nbFlatType[TopAbs_WIRE]) + "\n";
       if (nbFlatType[TopAbs_FACE] > 0)
-       Astr = Astr + " FACE : " + TCollection_AsciiString(nbFlatType[TopAbs_FACE]) + "\n";
+        Astr = Astr + " FACE : " + TCollection_AsciiString(nbFlatType[TopAbs_FACE]) + "\n";
       if (nbFlatType[TopAbs_SHELL] > 0)
-       Astr = Astr + " SHELL : " + TCollection_AsciiString(nbFlatType[TopAbs_SHELL]) + "\n";
+        Astr = Astr + " SHELL : " + TCollection_AsciiString(nbFlatType[TopAbs_SHELL]) + "\n";
       if (nbFlatType[TopAbs_SOLID] > 0)
-       Astr = Astr + " SOLID : " + TCollection_AsciiString(nbFlatType[TopAbs_SOLID]) + "\n";
+        Astr = Astr + " SOLID : " + TCollection_AsciiString(nbFlatType[TopAbs_SOLID]) + "\n";
     }
   }
   catch (Standard_Failure& aFail) {
@@ -2125,21 +2126,9 @@ Standard_Integer GEOMImpl_IMeasureOperations::ClosestPoints (Handle(GEOM_Object)
 
     // skl 30.06.2008
     // additional workaround for bugs 19899, 19908 and 19910 from Mantis
-    gp_Pnt P1, P2;
-    double dist = GEOMUtils::GetMinDistanceSingular(aShape1, aShape2, P1, P2);
-    if (dist > -1.0) {
-      nbSolutions = 1;
-
-      theDoubles->Append(P1.X());
-      theDoubles->Append(P1.Y());
-      theDoubles->Append(P1.Z());
-      theDoubles->Append(P2.X());
-      theDoubles->Append(P2.Y());
-      theDoubles->Append(P2.Z());
-
-      SetErrorCode(OK);
-      return nbSolutions;
-    }
+    gp_Pnt P1s, P2s;
+    double dist = GEOMUtils::GetMinDistanceSingular(aShape1, aShape2, P1s, P2s);
+    bool singularBetter = dist >= 0;
 
     BRepExtrema_DistShapeShape dst (aShape1, aShape2);
     if (dst.IsDone()) {
@@ -2150,15 +2139,32 @@ Standard_Integer GEOMImpl_IMeasureOperations::ClosestPoints (Handle(GEOM_Object)
       for (int i = 1; i <= nbSolutions; i++) {
         P1 = dst.PointOnShape1(i);
         P2 = dst.PointOnShape2(i);
-
+       
         theDoubles->Append(P1.X());
         theDoubles->Append(P1.Y());
         theDoubles->Append(P1.Z());
         theDoubles->Append(P2.X());
         theDoubles->Append(P2.Y());
         theDoubles->Append(P2.Z());
+       
+       Standard_Real Dist = P1.Distance(P2);
+       singularBetter = singularBetter && dist < Dist;
       }
     }
+
+    if (singularBetter) {
+      if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
+      else theDoubles->Clear();
+
+      nbSolutions = 1;
+    
+      theDoubles->Append(P1s.X());
+      theDoubles->Append(P1s.Y());
+      theDoubles->Append(P1s.Z());
+      theDoubles->Append(P2s.X());
+      theDoubles->Append(P2s.Y());
+      theDoubles->Append(P2s.Z());
+    }
   }
   catch (Standard_Failure& aFail) {
     SetErrorCode(aFail.GetMessageString());