Salome HOME
Workaround for bugs 0019899, 0019908 and 0019910 from Mantis.
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IShapesOperations.cxx
index e3647c3a01aea35cbcafa3046a79216bec46c1ed..ad976665b5e957564fcd80242995ec8b674eeb96 100644 (file)
@@ -799,8 +799,6 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::MakeExplode
   TopExp::MapShapes(aShape, anIndices);
   Handle(TColStd_HArray1OfInteger) anArray;
 
-  Standard_Integer nbAllSubShape = anIndices.Extent();
-
   TopTools_ListIteratorOfListOfShape itSub (listShape);
   TCollection_AsciiString anAsciiList, anEntry;
   for (int index = 1; itSub.More(); itSub.Next(), ++index)
@@ -2877,7 +2875,9 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetInPlace (Handle(GEOM_Object)
   Standard_Real    tab_aWhat[4],    tab_aWhere[4];
   Standard_Real    dl_l = 1e-3;
   Standard_Real    min_l, Tol_1D, Tol_2D, Tol_3D, Tol_Mass;
-  gp_Pnt           aPnt, aPnt_aWhat;
+  Standard_Real    aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
+  Bnd_Box          BoundingBox;
+  gp_Pnt           aPnt, aPnt_aWhat, tab_Pnt[2];
   GProp_GProps     aProps;
 
   // Find the iType of the aWhat shape
@@ -2893,9 +2893,8 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetInPlace (Handle(GEOM_Object)
     else if ( compType == TopAbs_SOLID || compType == TopAbs_COMPSOLID) iType = TopAbs_SOLID;
   }
   else {
-    cout << endl;
-    cout << "WARNING : shape to be extracted is of unknown type !" << endl;
-    cout << endl;
+    SetErrorCode("Error: An attempt to extract a shape of not supported type.");
+    return NULL;
   }
 
   TopExp_Explorer Exp_aWhat( aWhat,   TopAbs_ShapeEnum( iType ) );
@@ -2903,10 +2902,22 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetInPlace (Handle(GEOM_Object)
   TopExp_Explorer Exp_Edge( aWhere,   TopAbs_EDGE );
 
   // Find the shortest edge in theShapeWhere shape
+  BRepBndLib::Add(aWhere, BoundingBox);
+  BoundingBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
+  min_l = fabs(aXmax - aXmin);
+  if( min_l < fabs(aYmax - aYmin) ) min_l = fabs(aYmax - aYmin);
+  if( min_l < fabs(aZmax - aZmin) ) min_l = fabs(aZmax - aZmin);
+  min_l /= dl_l;
   for ( Standard_Integer nbEdge = 0; Exp_Edge.More(); Exp_Edge.Next(), nbEdge++ ) {
-    BRepGProp::LinearProperties(Exp_Edge.Current(), aProps);
-    if ( ! nbEdge ) min_l = aProps.Mass();
-    if ( aProps.Mass() < min_l ) min_l = aProps.Mass();
+    TopExp_Explorer Exp_Vertex( Exp_Edge.Current(), TopAbs_VERTEX);
+    for ( Standard_Integer nbVertex = 0; Exp_Vertex.More(); Exp_Vertex.Next(), nbVertex++ ) {
+      aPnt = BRep_Tool::Pnt( TopoDS::Vertex( Exp_Vertex.Current() ) );
+      tab_Pnt[nbVertex] = aPnt;
+    }
+    if ( not tab_Pnt[0].IsEqual(tab_Pnt[1], dl_l) ) {
+      BRepGProp::LinearProperties(Exp_Edge.Current(), aProps);
+      if ( aProps.Mass() < min_l ) min_l = aProps.Mass();
+    }
   }
 
   // Compute tolerances
@@ -3267,6 +3278,12 @@ static bool isSameEdge(const TopoDS_Edge& theEdge1, const TopoDS_Edge& theEdge2)
 
   if(!coincide) return false;
 
+  if (BRep_Tool::Degenerated(theEdge1))
+    if (BRep_Tool::Degenerated(theEdge2)) return true;
+    else return false;
+  else
+    if (BRep_Tool::Degenerated(theEdge2)) return false;
+
   double U11, U12, U21, U22;
   Handle(Geom_Curve) C1 = BRep_Tool::Curve(theEdge1, U11, U12);
   Handle(Geom_Curve) C2 = BRep_Tool::Curve(theEdge2, U21, U22);