Salome HOME
[bos #36177] [FORUM] - Remove extra-edge on hemisphere
[modules/geom.git] / src / BlockFix / BlockFix_BlockFixAPI.cxx
index ea30cc5321501575be699e12c6ac63dd22d852b6..103124a4fbf35fa05f9b6927391e495cbde85a9b 100644 (file)
 
 #include <Precision.hxx>
 
+#include <BRepTools.hxx>
+#include <BRepBuilderAPI_Copy.hxx>
+#include <BRepCheck_Analyzer.hxx>
+
 #include <Basics_OCCTVersion.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(BlockFix_BlockFixAPI, Standard_Transient)
@@ -64,7 +68,22 @@ void BlockFix_BlockFixAPI::Perform()
 {
   // processing spheres with degenerativities
   TopoDS_Shape aShape = Shape();
-  myShape = BlockFix::RotateSphereSpace(aShape,myTolerance);
+  // Copy the shape to avoid modification of initial shape
+  // while trying the approach with small rotation
+  BRepBuilderAPI_Copy aMC (aShape);
+  if (!aMC.IsDone()) return;
+  TopoDS_Shape aSCopy = aMC.Shape();
+  TopoDS_Shape aNewShape = BlockFix::RotateSphereSpace(aSCopy, myTolerance, Standard_True);
+  BRepCheck_Analyzer ana (aNewShape, false);
+  if (ana.IsValid()) {
+    if (aNewShape == aSCopy)
+      myShape = aShape;
+    else
+      myShape = aNewShape;
+  }
+  else {
+    myShape = BlockFix::RotateSphereSpace(aShape, myTolerance, Standard_False);
+  }
 
   // try to approximate non-canonic surfaces
   // with singularities on boundaries by filling