diff --git a/src/Mod/Part/App/TopoShapeSolidPy.xml b/src/Mod/Part/App/TopoShapeSolidPy.xml index 0e3a3705d..c8e4048cf 100644 --- a/src/Mod/Part/App/TopoShapeSolidPy.xml +++ b/src/Mod/Part/App/TopoShapeSolidPy.xml @@ -14,6 +14,12 @@ Create a solid out of the shells of a shape + + + Returns the mass of the current system. + + + Returns the center of mass of the current system. @@ -44,6 +50,28 @@ coordinate system. + + + Returns Ix, Iy, Iz, the static moments of inertia of the + current system; i.e. the moments of inertia about the + three axes of the Cartesian coordinate system. + + + + + + Computes the principal properties of inertia of the current system. + There is always a set of axes for which the products + of inertia of a geometric system are equal to 0; i.e. the + matrix of inertia of the system is diagonal. These axes + are the principal axes of inertia. Their origin is + coincident with the center of mass of the system. The + associated moments are called the principal moments of inertia. + This function computes the eigen values and the + eigen vectors of the matrix of inertia of the system. + + + @@ -52,5 +80,15 @@ shape if the solid has no shells + + + computes the moment of inertia of the material system about the axis A. + + + + + Returns the radius of gyration of the current system about the axis A. + + diff --git a/src/Mod/Part/App/TopoShapeSolidPyImp.cpp b/src/Mod/Part/App/TopoShapeSolidPyImp.cpp index 291dba419..ca1a952c3 100644 --- a/src/Mod/Part/App/TopoShapeSolidPyImp.cpp +++ b/src/Mod/Part/App/TopoShapeSolidPyImp.cpp @@ -26,11 +26,16 @@ #include #include #include +#include #include #include #include #include #include +#include +#include +#include +#include #include #include @@ -91,6 +96,22 @@ int TopoShapeSolidPy::PyInit(PyObject* args, PyObject* /*kwd*/) return 0; } +Py::Object TopoShapeSolidPy::getMass(void) const +{ + GProp_GProps props; + BRepGProp::VolumeProperties(getTopoShapePtr()->_Shape, props); + double c = props.Mass(); + return Py::Float(c); +} + +Py::Object TopoShapeSolidPy::getCenterOfMass(void) const +{ + GProp_GProps props; + BRepGProp::VolumeProperties(getTopoShapePtr()->_Shape, props); + gp_Pnt c = props.CentreOfMass(); + return Py::Vector(Base::Vector3d(c.X(),c.Y(),c.Z())); +} + Py::Object TopoShapeSolidPy::getMatrixOfInertia(void) const { GProp_GProps props; @@ -105,12 +126,50 @@ Py::Object TopoShapeSolidPy::getMatrixOfInertia(void) const return Py::Matrix(mat); } -Py::Object TopoShapeSolidPy::getCenterOfMass(void) const +Py::Object TopoShapeSolidPy::getStaticMoments(void) const { GProp_GProps props; BRepGProp::VolumeProperties(getTopoShapePtr()->_Shape, props); - gp_Pnt c = props.CentreOfMass(); - return Py::Vector(Base::Vector3d(c.X(),c.Y(),c.Z())); + Standard_Real lx,ly,lz; + props.StaticMoments(lx,ly,lz); + Py::Tuple tuple(3); + tuple.setItem(0, Py::Float(lx)); + tuple.setItem(1, Py::Float(ly)); + tuple.setItem(2, Py::Float(lz)); + return tuple; +} + +Py::Dict TopoShapeSolidPy::getPrincipalProperties(void) const +{ + GProp_GProps props; + BRepGProp::VolumeProperties(getTopoShapePtr()->_Shape, props); + GProp_PrincipalProps pprops = props.PrincipalProperties(); + + Py::Dict dict; + dict.setItem("SymmetryAxis", Py::Boolean(pprops.HasSymmetryAxis() ? true : false)); + dict.setItem("SymmetryPoint", Py::Boolean(pprops.HasSymmetryPoint() ? true : false)); + Standard_Real lx,ly,lz; + pprops.Moments(lx,ly,lz); + Py::Tuple tuple(3); + tuple.setItem(0, Py::Float(lx)); + tuple.setItem(1, Py::Float(ly)); + tuple.setItem(2, Py::Float(lz)); + dict.setItem("Moments",tuple); + dict.setItem("FirstAxisOfInertia",Py::Vector(Base::convertTo + (pprops.FirstAxisOfInertia()))); + dict.setItem("SecondAxisOfInertia",Py::Vector(Base::convertTo + (pprops.SecondAxisOfInertia()))); + dict.setItem("ThirdAxisOfInertia",Py::Vector(Base::convertTo + (pprops.ThirdAxisOfInertia()))); + + Standard_Real Rxx,Ryy,Rzz; + pprops.RadiusOfGyration(Rxx,Ryy,Rzz); + Py::Tuple rog(3); + rog.setItem(0, Py::Float(Rxx)); + rog.setItem(1, Py::Float(Ryy)); + rog.setItem(2, Py::Float(Rzz)); + dict.setItem("RadiusOfGyration",rog); + return dict; } Py::Object TopoShapeSolidPy::getOuterShell(void) const @@ -122,6 +181,52 @@ Py::Object TopoShapeSolidPy::getOuterShell(void) const return Py::Object(new TopoShapeShellPy(new TopoShape(shell)),true); } +PyObject* TopoShapeSolidPy::getMomentOfInertia(PyObject *args) +{ + PyObject *p,*d; + if (!PyArg_ParseTuple(args, "O!O!",&Base::VectorPy::Type,&p + ,&Base::VectorPy::Type,&d)) + return 0; + Base::Vector3d pnt = Py::Vector(p,false).toVector(); + Base::Vector3d dir = Py::Vector(d,false).toVector(); + + try { + GProp_GProps props; + BRepGProp::VolumeProperties(getTopoShapePtr()->_Shape, props); + double r = props.MomentOfInertia(gp_Ax1(Base::convertTo(pnt), + Base::convertTo(dir))); + return PyFloat_FromDouble(r); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PyExc_Exception, e->GetMessageString()); + return 0; + } +} + +PyObject* TopoShapeSolidPy::getRadiusOfGyration(PyObject *args) +{ + PyObject *p,*d; + if (!PyArg_ParseTuple(args, "O!O!",&Base::VectorPy::Type,&p + ,&Base::VectorPy::Type,&d)) + return 0; + Base::Vector3d pnt = Py::Vector(p,false).toVector(); + Base::Vector3d dir = Py::Vector(d,false).toVector(); + + try { + GProp_GProps props; + BRepGProp::VolumeProperties(getTopoShapePtr()->_Shape, props); + double r = props.RadiusOfGyration(gp_Ax1(Base::convertTo(pnt), + Base::convertTo(dir))); + return PyFloat_FromDouble(r); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PyExc_Exception, e->GetMessageString()); + return 0; + } +} + PyObject *TopoShapeSolidPy::getCustomAttributes(const char* /*attr*/) const { return 0;