From 5ff38ba7d5710cb64298c4f3d385d2c3f9588dbc Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 22 Mar 2015 18:39:49 +0100 Subject: [PATCH] + add methods to get GProps from curves and surfaces --- src/Mod/Part/App/TopoShapeEdgePy.xml | 67 +++++++++++++++++--- src/Mod/Part/App/TopoShapeEdgePyImp.cpp | 70 +++++++++++++++++++++ src/Mod/Part/App/TopoShapeFacePy.xml | 69 ++++++++++++++++---- src/Mod/Part/App/TopoShapeFacePyImp.cpp | 70 +++++++++++++++++++++ src/Mod/Part/App/TopoShapeShellPy.xml | 58 +++++++++++++++++ src/Mod/Part/App/TopoShapeShellPyImp.cpp | 80 ++++++++++++++++++++++++ src/Mod/Part/App/TopoShapeWirePy.xml | 51 ++++++++++++++- src/Mod/Part/App/TopoShapeWirePyImp.cpp | 70 +++++++++++++++++++++ 8 files changed, 514 insertions(+), 21 deletions(-) diff --git a/src/Mod/Part/App/TopoShapeEdgePy.xml b/src/Mod/Part/App/TopoShapeEdgePy.xml index a2e527e01..59a4a1eb4 100644 --- a/src/Mod/Part/App/TopoShapeEdgePy.xml +++ b/src/Mod/Part/App/TopoShapeEdgePy.xml @@ -145,15 +145,6 @@ Part.show(s) - - - Returns the center of mass of the current system. -If the gravitational field is uniform, it is the center of gravity. -The coordinates returned for the center of mass are expressed in the -absolute Cartesian coordinate system. - - - Returns true of the edge is closed @@ -166,6 +157,64 @@ absolute Cartesian coordinate system. + + + Returns the mass of the current system. + + + + + + Returns the center of mass of the current system. +If the gravitational field is uniform, it is the center of gravity. +The coordinates returned for the center of mass are expressed in the +absolute Cartesian coordinate system. + + + + + + Returns the matrix of inertia. It is a symmetrical matrix. +The coefficients of the matrix are the quadratic moments of +inertia. + + | Ixx Ixy Ixz 0 | + | Ixy Iyy Iyz 0 | + | Ixz Iyz Izz 0 | + | 0 0 0 1 | + +The moments of inertia are denoted by Ixx, Iyy, Izz. +The products of inertia are denoted by Ixy, Ixz, Iyz. +The matrix of inertia is returned in the central coordinate +system (G, Gx, Gy, Gz) where G is the centre of mass of the +system and Gx, Gy, Gz the directions parallel to the X(1,0,0) +Y(0,1,0) Z(0,0,1) directions of the absolute cartesian +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. + + + diff --git a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp index d0174c6bb..820b39bd5 100644 --- a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp +++ b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp @@ -33,6 +33,7 @@ # include # include # include +# include # include # include # include @@ -67,6 +68,7 @@ #include #include +#include "Tools.h" #include "OCCError.h" #include "TopoShape.h" #include "TopoShapeFacePy.h" @@ -756,6 +758,14 @@ Py::Float TopoShapeEdgePy::getLastParameter(void) const return Py::Float(t); } +Py::Object TopoShapeEdgePy::getMass(void) const +{ + GProp_GProps props; + BRepGProp::LinearProperties(getTopoShapePtr()->_Shape, props); + double c = props.Mass(); + return Py::Float(c); +} + Py::Object TopoShapeEdgePy::getCenterOfMass(void) const { GProp_GProps props; @@ -764,6 +774,66 @@ Py::Object TopoShapeEdgePy::getCenterOfMass(void) const return Py::Vector(Base::Vector3d(c.X(),c.Y(),c.Z())); } +Py::Object TopoShapeEdgePy::getMatrixOfInertia(void) const +{ + GProp_GProps props; + BRepGProp::LinearProperties(getTopoShapePtr()->_Shape, props); + gp_Mat m = props.MatrixOfInertia(); + Base::Matrix4D mat; + for (int i=0; i<3; i++) { + for (int j=0; j<3; j++) { + mat[i][j] = m(i+1,j+1); + } + } + return Py::Matrix(mat); +} + +Py::Object TopoShapeEdgePy::getStaticMoments(void) const +{ + GProp_GProps props; + BRepGProp::LinearProperties(getTopoShapePtr()->_Shape, props); + 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 TopoShapeEdgePy::getPrincipalProperties(void) const +{ + GProp_GProps props; + BRepGProp::LinearProperties(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::Boolean TopoShapeEdgePy::getClosed(void) const { if (getTopoShapePtr()->_Shape.IsNull()) diff --git a/src/Mod/Part/App/TopoShapeFacePy.xml b/src/Mod/Part/App/TopoShapeFacePy.xml index 9da4136fc..2916c3648 100644 --- a/src/Mod/Part/App/TopoShapeFacePy.xml +++ b/src/Mod/Part/App/TopoShapeFacePy.xml @@ -100,16 +100,63 @@ deprecated -- please use OuterWire - - - - Returns the center of mass of the current system. - If the gravitational field is uniform, it is the center of gravity. - The coordinates returned for the center of mass are expressed in the - absolute Cartesian coordinate system. - - - - + + + Returns the mass of the current system. + + + + + + Returns the center of mass of the current system. +If the gravitational field is uniform, it is the center of gravity. +The coordinates returned for the center of mass are expressed in the +absolute Cartesian coordinate system. + + + + + + Returns the matrix of inertia. It is a symmetrical matrix. +The coefficients of the matrix are the quadratic moments of +inertia. + + | Ixx Ixy Ixz 0 | + | Ixy Iyy Iyz 0 | + | Ixz Iyz Izz 0 | + | 0 0 0 1 | + +The moments of inertia are denoted by Ixx, Iyy, Izz. +The products of inertia are denoted by Ixy, Ixz, Iyz. +The matrix of inertia is returned in the central coordinate +system (G, Gx, Gy, Gz) where G is the centre of mass of the +system and Gx, Gy, Gz the directions parallel to the X(1,0,0) +Y(0,1,0) Z(0,0,1) directions of the absolute cartesian +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. + + + diff --git a/src/Mod/Part/App/TopoShapeFacePyImp.cpp b/src/Mod/Part/App/TopoShapeFacePyImp.cpp index d543f89ff..5cb68418e 100644 --- a/src/Mod/Part/App/TopoShapeFacePyImp.cpp +++ b/src/Mod/Part/App/TopoShapeFacePyImp.cpp @@ -61,6 +61,7 @@ #include #include #include +#include #include #include #include @@ -85,6 +86,7 @@ #include "SurfaceOfExtrusionPy.h" #include "ToroidPy.h" #include "OCCError.h" +#include "Tools.h" using namespace Part; @@ -688,6 +690,14 @@ Py::Object TopoShapeFacePy::getOuterWire(void) const return Py::Object(); } +Py::Object TopoShapeFacePy::getMass(void) const +{ + GProp_GProps props; + BRepGProp::SurfaceProperties(getTopoShapePtr()->_Shape, props); + double c = props.Mass(); + return Py::Float(c); +} + Py::Object TopoShapeFacePy::getCenterOfMass(void) const { GProp_GProps props; @@ -696,6 +706,66 @@ Py::Object TopoShapeFacePy::getCenterOfMass(void) const return Py::Vector(Base::Vector3d(c.X(),c.Y(),c.Z())); } +Py::Object TopoShapeFacePy::getMatrixOfInertia(void) const +{ + GProp_GProps props; + BRepGProp::SurfaceProperties(getTopoShapePtr()->_Shape, props); + gp_Mat m = props.MatrixOfInertia(); + Base::Matrix4D mat; + for (int i=0; i<3; i++) { + for (int j=0; j<3; j++) { + mat[i][j] = m(i+1,j+1); + } + } + return Py::Matrix(mat); +} + +Py::Object TopoShapeFacePy::getStaticMoments(void) const +{ + GProp_GProps props; + BRepGProp::SurfaceProperties(getTopoShapePtr()->_Shape, props); + 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 TopoShapeFacePy::getPrincipalProperties(void) const +{ + GProp_GProps props; + BRepGProp::SurfaceProperties(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; +} + PyObject *TopoShapeFacePy::getCustomAttributes(const char* attr) const { return 0; diff --git a/src/Mod/Part/App/TopoShapeShellPy.xml b/src/Mod/Part/App/TopoShapeShellPy.xml index e769368e5..0d889482b 100644 --- a/src/Mod/Part/App/TopoShapeShellPy.xml +++ b/src/Mod/Part/App/TopoShapeShellPy.xml @@ -34,5 +34,63 @@ Make a half-space solid by this shell and a reference point. + + + Returns the mass of the current system. + + + + + + Returns the center of mass of the current system. +If the gravitational field is uniform, it is the center of gravity. +The coordinates returned for the center of mass are expressed in the +absolute Cartesian coordinate system. + + + + + + Returns the matrix of inertia. It is a symmetrical matrix. +The coefficients of the matrix are the quadratic moments of +inertia. + + | Ixx Ixy Ixz 0 | + | Ixy Iyy Iyz 0 | + | Ixz Iyz Izz 0 | + | 0 0 0 1 | + +The moments of inertia are denoted by Ixx, Iyy, Izz. +The products of inertia are denoted by Ixy, Ixz, Iyz. +The matrix of inertia is returned in the central coordinate +system (G, Gx, Gy, Gz) where G is the centre of mass of the +system and Gx, Gy, Gz the directions parallel to the X(1,0,0) +Y(0,1,0) Z(0,0,1) directions of the absolute cartesian +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. + + + diff --git a/src/Mod/Part/App/TopoShapeShellPyImp.cpp b/src/Mod/Part/App/TopoShapeShellPyImp.cpp index 0c38c7506..a6d027a2b 100644 --- a/src/Mod/Part/App/TopoShapeShellPyImp.cpp +++ b/src/Mod/Part/App/TopoShapeShellPyImp.cpp @@ -26,6 +26,9 @@ # include # include # include +# include +# include +# include # include # include # include @@ -38,6 +41,7 @@ #include #include "OCCError.h" +#include "Tools.h" #include "TopoShape.h" #include "TopoShapeCompoundPy.h" #include "TopoShapeCompSolidPy.h" @@ -198,6 +202,82 @@ PyObject* TopoShapeShellPy::makeHalfSpace(PyObject *args) } } +Py::Object TopoShapeShellPy::getMass(void) const +{ + GProp_GProps props; + BRepGProp::SurfaceProperties(getTopoShapePtr()->_Shape, props); + double c = props.Mass(); + return Py::Float(c); +} + +Py::Object TopoShapeShellPy::getCenterOfMass(void) const +{ + GProp_GProps props; + BRepGProp::SurfaceProperties(getTopoShapePtr()->_Shape, props); + gp_Pnt c = props.CentreOfMass(); + return Py::Vector(Base::Vector3d(c.X(),c.Y(),c.Z())); +} + +Py::Object TopoShapeShellPy::getMatrixOfInertia(void) const +{ + GProp_GProps props; + BRepGProp::SurfaceProperties(getTopoShapePtr()->_Shape, props); + gp_Mat m = props.MatrixOfInertia(); + Base::Matrix4D mat; + for (int i=0; i<3; i++) { + for (int j=0; j<3; j++) { + mat[i][j] = m(i+1,j+1); + } + } + return Py::Matrix(mat); +} + +Py::Object TopoShapeShellPy::getStaticMoments(void) const +{ + GProp_GProps props; + BRepGProp::SurfaceProperties(getTopoShapePtr()->_Shape, props); + 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 TopoShapeShellPy::getPrincipalProperties(void) const +{ + GProp_GProps props; + BRepGProp::SurfaceProperties(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; +} + PyObject *TopoShapeShellPy::getCustomAttributes(const char* /*attr*/) const { return 0; diff --git a/src/Mod/Part/App/TopoShapeWirePy.xml b/src/Mod/Part/App/TopoShapeWirePy.xml index adbfcfa00..2b881158d 100644 --- a/src/Mod/Part/App/TopoShapeWirePy.xml +++ b/src/Mod/Part/App/TopoShapeWirePy.xml @@ -91,14 +91,63 @@ Part.show(s) + + + Returns the mass of the current system. + + + - Returns the center of mass of the current system. + Returns the center of mass of the current system. If the gravitational field is uniform, it is the center of gravity. The coordinates returned for the center of mass are expressed in the absolute Cartesian coordinate system. + + + Returns the matrix of inertia. It is a symmetrical matrix. +The coefficients of the matrix are the quadratic moments of +inertia. + + | Ixx Ixy Ixz 0 | + | Ixy Iyy Iyz 0 | + | Ixz Iyz Izz 0 | + | 0 0 0 1 | + +The moments of inertia are denoted by Ixx, Iyy, Izz. +The products of inertia are denoted by Ixy, Ixz, Iyz. +The matrix of inertia is returned in the central coordinate +system (G, Gx, Gy, Gz) where G is the centre of mass of the +system and Gx, Gy, Gz the directions parallel to the X(1,0,0) +Y(0,1,0) Z(0,0,1) directions of the absolute cartesian +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. + + + diff --git a/src/Mod/Part/App/TopoShapeWirePyImp.cpp b/src/Mod/Part/App/TopoShapeWirePyImp.cpp index 2fd4c2cd1..0f173e684 100644 --- a/src/Mod/Part/App/TopoShapeWirePyImp.cpp +++ b/src/Mod/Part/App/TopoShapeWirePyImp.cpp @@ -37,6 +37,7 @@ #include #include +#include #include #include #include @@ -54,6 +55,7 @@ #include "TopoShapeWirePy.h" #include "TopoShapeWirePy.cpp" #include "OCCError.h" +#include "Tools.h" using namespace Part; @@ -499,6 +501,14 @@ PyObject* TopoShapeWirePy::discretize(PyObject *args, PyObject *kwds) return 0; } +Py::Object TopoShapeWirePy::getMass(void) const +{ + GProp_GProps props; + BRepGProp::LinearProperties(getTopoShapePtr()->_Shape, props); + double c = props.Mass(); + return Py::Float(c); +} + Py::Object TopoShapeWirePy::getCenterOfMass(void) const { GProp_GProps props; @@ -507,6 +517,66 @@ Py::Object TopoShapeWirePy::getCenterOfMass(void) const return Py::Vector(Base::Vector3d(c.X(),c.Y(),c.Z())); } +Py::Object TopoShapeWirePy::getMatrixOfInertia(void) const +{ + GProp_GProps props; + BRepGProp::LinearProperties(getTopoShapePtr()->_Shape, props); + gp_Mat m = props.MatrixOfInertia(); + Base::Matrix4D mat; + for (int i=0; i<3; i++) { + for (int j=0; j<3; j++) { + mat[i][j] = m(i+1,j+1); + } + } + return Py::Matrix(mat); +} + +Py::Object TopoShapeWirePy::getStaticMoments(void) const +{ + GProp_GProps props; + BRepGProp::LinearProperties(getTopoShapePtr()->_Shape, props); + 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 TopoShapeWirePy::getPrincipalProperties(void) const +{ + GProp_GProps props; + BRepGProp::LinearProperties(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; +} + PyObject *TopoShapeWirePy::getCustomAttributes(const char* /*attr*/) const { return 0;