Salome HOME
Fix for the issue #593: do not remove naming attribute, but use TNaming_Builder for...
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_ShapeProps.cpp
index 00ef55c0ea3710b858304f33ab83ad7d1447420e..fcec982022d1855f029f7ee67d410c7c39144ba7 100644 (file)
 #include <GProp_GProps.hxx>
 #include <TopoDS_Shape.hxx>
 
-
+//=================================================================================================
 double GeomAlgoAPI_ShapeProps::volume(std::shared_ptr<GeomAPI_Shape> theShape)
 {
   GProp_GProps aGProps;
-  TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+  if(!theShape) {
+    return 0.0;
+  }
+  const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
+  if(aShape.IsNull()) {
+    return 0.0;
+  }
   BRepGProp::VolumeProperties(aShape, aGProps);
   return aGProps.Mass();
-}
\ No newline at end of file
+}
+
+//=================================================================================================
+std::shared_ptr<GeomAPI_Pnt> GeomAlgoAPI_ShapeProps::centreOfMass(std::shared_ptr<GeomAPI_Shape> theShape)
+{
+  GProp_GProps aGProps;
+  if(!theShape) {
+    return std::shared_ptr<GeomAPI_Pnt>();
+  }
+  const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
+  if(aShape.IsNull()) {
+    return std::shared_ptr<GeomAPI_Pnt>();
+  }
+  BRepGProp::SurfaceProperties(aShape, aGProps);
+  gp_Pnt aCentre = aGProps.CentreOfMass();
+  return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aCentre.X(), aCentre.Y(), aCentre.Z()));
+}