]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/GeomAlgoAPI/GeomAlgoAPI_ShapeProps.cpp
Salome HOME
Feature #524: 4.01. Revolution feature (not complete!)
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_ShapeProps.cpp
index 00ef55c0ea3710b858304f33ab83ad7d1447420e..f11155bede13d709e4c0e4925fe079f14acf8c09 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 NULL;
+  }
+  const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
+  if(aShape.IsNull()) {
+    return NULL;
+  }
+  BRepGProp::SurfaceProperties(aShape, aGProps);
+  gp_Pnt aCentre = aGProps.CentreOfMass();
+  return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aCentre.X(), aCentre.Y(), aCentre.Z()));
+}