Salome HOME
Merge remote-tracking branch 'remotes/origin/EDF_2020_Lot2'
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_UnifySameDomain.cpp
index c33177b73d961182d402d189ed6032270f9c3203..7f25eae4e0a208a863693afa8c58702a4e1dd587 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 #include "GeomAlgoAPI_UnifySameDomain.h"
 
 #include <GeomAlgoAPI_CompoundBuilder.h>
+#include <GeomAlgoAPI_DFLoader.h>
 #include <GeomAlgoAPI_ShapeTools.h>
 
-#include <ShapeUpgrade_UnifySameDomain.hxx>
+#include <BRep_Tool.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS_Shape.hxx>
 #include <Precision.hxx>
@@ -30,6 +31,7 @@
 #include <TopoDS_Edge.hxx>
 #include <Bnd_Box.hxx>
 #include <BRepBndLib.hxx>
+#include <ShapeUpgrade_UnifySameDomain.hxx>
 
 //==================================================================================================
 GeomAlgoAPI_UnifySameDomain::GeomAlgoAPI_UnifySameDomain(const ListOfShape& theShapes)
@@ -71,29 +73,18 @@ void GeomAlgoAPI_UnifySameDomain::build(const ListOfShape& theShapes)
 }
 
 // calculates maximum possible tolerance on edges of shape
-// (method from GEOM module BlockFix_UnionFaces.cxx)
 static Standard_Real defineLinearTolerance(const TopoDS_Shape& theShape)
 {
-  Standard_Real aTol = Precision::Confusion();
+  Standard_Real aMaxTol = Precision::Confusion();
 
-  Standard_Real MinSize = RealLast();
   TopExp_Explorer Explo(theShape, TopAbs_EDGE);
   for (; Explo.More(); Explo.Next())
   {
     const TopoDS_Edge& anEdge = TopoDS::Edge(Explo.Current());
-    Bnd_Box aBox;
-    BRepBndLib::Add(anEdge, aBox);
-    Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
-    aBox.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
-    Standard_Real MaxSize = Max(Xmax - Xmin, Max(Ymax - Ymin, Zmax - Zmin));
-    if (MaxSize < MinSize)
-      MinSize = MaxSize;
+    aMaxTol = Max(aMaxTol, BRep_Tool::Tolerance(anEdge));
   }
 
-  if (!Precision::IsInfinite(MinSize))
-    aTol = 0.1 * MinSize;
-
-  return aTol;
+  return aMaxTol;
 }
 
 //==================================================================================================
@@ -113,6 +104,10 @@ void GeomAlgoAPI_UnifySameDomain::build(const GeomShapePtr& theShape,
   if (aResult.IsNull()) {
     return;
   }
+  // take off the compound if it consists of single sub-shape
+  if (aResult.ShapeType() == TopAbs_COMPOUND) {
+    aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
+  }
 
   if (theIsToSimplifyShell && aResult.ShapeType() == TopAbs_SHELL) {
     int aNb = 0;