Salome HOME
Issue #634 API must be wrapped by SWIG
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_ShapeProps.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAlgoAPI_ShapeProps.cpp
4 // Created:     8 May 2015
5 // Author:      Dmitry Bobylev
6
7 #include <GeomAlgoAPI_ShapeProps.h>
8
9 #include <BRepGProp.hxx>
10 #include <GProp_GProps.hxx>
11 #include <TopoDS_Shape.hxx>
12
13 //=================================================================================================
14 double GeomAlgoAPI_ShapeProps::volume(std::shared_ptr<GeomAPI_Shape> theShape)
15 {
16   GProp_GProps aGProps;
17   if(!theShape) {
18     return 0.0;
19   }
20   const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
21   if(aShape.IsNull()) {
22     return 0.0;
23   }
24   BRepGProp::VolumeProperties(aShape, aGProps);
25   return aGProps.Mass();
26 }
27
28 //=================================================================================================
29 std::shared_ptr<GeomAPI_Pnt> GeomAlgoAPI_ShapeProps::centreOfMass(std::shared_ptr<GeomAPI_Shape> theShape)
30 {
31   GProp_GProps aGProps;
32   if(!theShape) {
33     return std::shared_ptr<GeomAPI_Pnt>();
34   }
35   const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
36   if(aShape.IsNull()) {
37     return std::shared_ptr<GeomAPI_Pnt>();
38   }
39   BRepGProp::SurfaceProperties(aShape, aGProps);
40   gp_Pnt aCentre = aGProps.CentreOfMass();
41   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aCentre.X(), aCentre.Y(), aCentre.Z()));
42 }