Salome HOME
High level objects history implementation for LinearCopy and AngularCopy features.
[modules/shaper.git] / src / GeomAPI / GeomAPI_Shape.cpp
index 4cde5e7361172393638f9787bf1a8a9012eda14e..d7840b16832d8cb297b4b9a024d0098ef953a5c7 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>
@@ -151,6 +152,7 @@ bool GeomAPI_Shape::isCompoundOfSolids() const
   return isAtLeastOne;
 }
 
+// LCOV_EXCL_START
 GeomAPI_Shape::ShapeType GeomAPI_Shape::typeOfCompoundShapes() const
 {
   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
@@ -167,6 +169,7 @@ GeomAPI_Shape::ShapeType GeomAPI_Shape::typeOfCompoundShapes() const
   }
   return (GeomAPI_Shape::ShapeType) aType;
 }
+// LCOV_EXCL_STOP
 
 // adds the nopt-compound elements recursively to the list
 static void addSimpleToList(const TopoDS_Shape& theShape, NCollection_List<TopoDS_Shape>& theList)
@@ -566,11 +569,49 @@ 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;
+}
+
+// LCOV_EXCL_START
 std::string GeomAPI_Shape::getShapeStream() const
 {
   std::ostringstream aStream;
@@ -578,6 +619,7 @@ std::string GeomAPI_Shape::getShapeStream() const
   BRepTools::Write(aShape, aStream);
   return aStream.str();
 }
+// LCOV_EXCL_STOP
 
 GeomShapePtr GeomAPI_Shape::intersect(const GeomShapePtr theShape) const
 {