Salome HOME
Fix error in test case for issue #1779
[modules/shaper.git] / src / GeomAPI / GeomAPI_Shape.cpp
index fc736ac749e379a753d92ebd081d988d59d5430b..c4f30b6d321fb8aceee45910f7ce2f4cb0da47ee 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "GeomAPI_Shape.h"
 
+#include <GeomAPI_Pnt.h>
 #include <GeomAPI_Vertex.h>
 #include <GeomAPI_Edge.h>
 #include <GeomAPI_Wire.h>
@@ -50,6 +51,9 @@
 #include <TopoDS_Shape.hxx>
 #include <NCollection_List.hxx>
 
+#include <BOPAlgo_CheckerSI.hxx>
+#include <BOPDS_DS.hxx>
+
 #include <sstream>
 #include <algorithm> // for std::transform
 
@@ -563,11 +567,48 @@ bool GeomAPI_Shape::computeSize(double& theXmin, double& theYmin, double& theZmi
   if (aShape.IsNull())
     return false;
   Bnd_Box aBndBox;
-  BRepBndLib::Add(aShape, aBndBox);
+  BRepBndLib::Add(aShape, aBndBox, false);
+  if (aBndBox.IsVoid())
+    return false;
   aBndBox.Get(theXmin, theYmin, theZmin, theXmax, theYmax, theZmax);
   return true;
 }
 
+GeomPointPtr GeomAPI_Shape::middlePoint() const
+{
+  GeomPointPtr aMiddlePoint;
+
+  switch (shapeType()) {
+  case VERTEX:
+    aMiddlePoint = vertex()->point();
+    break;
+  case EDGE:
+    aMiddlePoint = edge()->middlePoint();
+    break;
+  case WIRE:
+    aMiddlePoint = wire()->middlePoint();
+    break;
+  case FACE:
+    aMiddlePoint = face()->middlePoint();
+    break;
+  case SHELL:
+    aMiddlePoint = shell()->middlePoint();
+    break;
+  case SOLID:
+    aMiddlePoint = solid()->middlePoint();
+    break;
+  default: {
+      // get middle point as center of the bounding box
+      double aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ;
+      computeSize(aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ);
+      aMiddlePoint = GeomPointPtr(new GeomAPI_Pnt(
+          (aMinX + aMaxX) * 0.5, (aMinY + aMaxY) * 0.5, (aMinZ + aMaxZ) * 0.5));
+    }
+  }
+
+  return aMiddlePoint;
+}
+
 std::string GeomAPI_Shape::getShapeStream() const
 {
   std::ostringstream aStream;
@@ -628,3 +669,19 @@ void GeomAPI_Shape::translate(const std::shared_ptr<GeomAPI_Dir> theDir, const d
   TopoDS_Shape aResult = MY_SHAPE->Moved(aTranslation);
   setImpl(new TopoDS_Shape(aResult));
 }
+
+bool GeomAPI_Shape::isSelfIntersected(const int theLevelOfCheck) const
+{
+  BOPAlgo_CheckerSI aCSI;  // checker of self-interferences
+  aCSI.SetLevelOfCheck(theLevelOfCheck);
+  TopTools_ListOfShape aList;
+  const TopoDS_Shape& aThisShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
+  aList.Append(aThisShape);
+  aCSI.SetArguments(aList);
+  aCSI.Perform();
+  if (aCSI.HasErrors() || aCSI.DS().Interferences().Extent() > 0) {
+    return true;
+  }
+
+  return false;
+}