+ add methods to get GProps from curves and surfaces

This commit is contained in:
wmayer 2015-03-22 18:39:49 +01:00
parent 0a4b08fcb6
commit 5ff38ba7d5
8 changed files with 514 additions and 21 deletions

View File

@ -145,15 +145,6 @@ Part.show(s)
</Documentation>
<Parameter Name="Curve" Type="Object"/>
</Attribute>
<Attribute Name="CenterOfMass" ReadOnly="true">
<Documentation>
<UserDocu>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.</UserDocu>
</Documentation>
<Parameter Name="CenterOfMass" Type="Object"/>
</Attribute>
<Attribute Name="Closed" ReadOnly="true">
<Documentation>
<UserDocu>Returns true of the edge is closed</UserDocu>
@ -166,6 +157,64 @@ absolute Cartesian coordinate system.</UserDocu>
</Documentation>
<Parameter Name="Degenerated" Type="Boolean"/>
</Attribute>
<Attribute Name="Mass" ReadOnly="true">
<Documentation>
<UserDocu>Returns the mass of the current system.</UserDocu>
</Documentation>
<Parameter Name="Mass" Type="Object"/>
</Attribute>
<Attribute Name="CenterOfMass" ReadOnly="true">
<Documentation>
<UserDocu>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.</UserDocu>
</Documentation>
<Parameter Name="CenterOfMass" Type="Object"/>
</Attribute>
<Attribute Name="MatrixOfInertia" ReadOnly="true">
<Documentation>
<UserDocu>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.</UserDocu>
</Documentation>
<Parameter Name="MatrixOfInertia" Type="Object"/>
</Attribute>
<Attribute Name="StaticMoments" ReadOnly="true">
<Documentation>
<UserDocu>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.</UserDocu>
</Documentation>
<Parameter Name="StaticMoments" Type="Object"/>
</Attribute>
<Attribute Name="PrincipalProperties" ReadOnly="true">
<Documentation>
<UserDocu>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.</UserDocu>
</Documentation>
<Parameter Name="PrincipalProperties" Type="Dict"/>
</Attribute>
<ClassDeclarations>
</ClassDeclarations>
</PythonExport>

View File

@ -33,6 +33,7 @@
# include <BRepLProp_CLProps.hxx>
# include <BRepLProp_CurveTool.hxx>
# include <GProp_GProps.hxx>
# include <GProp_PrincipalProps.hxx>
# include <Geom_Circle.hxx>
# include <Geom_Curve.hxx>
# include <Geom_Ellipse.hxx>
@ -67,6 +68,7 @@
#include <Base/VectorPy.h>
#include <Base/GeometryPyCXX.h>
#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
<Base::Vector3d>(pprops.FirstAxisOfInertia())));
dict.setItem("SecondAxisOfInertia",Py::Vector(Base::convertTo
<Base::Vector3d>(pprops.SecondAxisOfInertia())));
dict.setItem("ThirdAxisOfInertia",Py::Vector(Base::convertTo
<Base::Vector3d>(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())

View File

@ -100,16 +100,63 @@ deprecated -- please use OuterWire</UserDocu>
</Documentation>
<Parameter Name="OuterWire" Type="Object"/>
</Attribute>
<Attribute Name="CenterOfMass" ReadOnly="true">
<Documentation>
<UserDocu>
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.
</UserDocu>
</Documentation>
<Parameter Name="CenterOfMass" Type="Object"/>
</Attribute>
<Attribute Name="Mass" ReadOnly="true">
<Documentation>
<UserDocu>Returns the mass of the current system.</UserDocu>
</Documentation>
<Parameter Name="Mass" Type="Object"/>
</Attribute>
<Attribute Name="CenterOfMass" ReadOnly="true">
<Documentation>
<UserDocu>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.</UserDocu>
</Documentation>
<Parameter Name="CenterOfMass" Type="Object"/>
</Attribute>
<Attribute Name="MatrixOfInertia" ReadOnly="true">
<Documentation>
<UserDocu>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.</UserDocu>
</Documentation>
<Parameter Name="MatrixOfInertia" Type="Object"/>
</Attribute>
<Attribute Name="StaticMoments" ReadOnly="true">
<Documentation>
<UserDocu>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.</UserDocu>
</Documentation>
<Parameter Name="StaticMoments" Type="Object"/>
</Attribute>
<Attribute Name="PrincipalProperties" ReadOnly="true">
<Documentation>
<UserDocu>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.</UserDocu>
</Documentation>
<Parameter Name="PrincipalProperties" Type="Dict"/>
</Attribute>
</PythonExport>
</GenerateModel>

View File

@ -61,6 +61,7 @@
#include <BRepPrimAPI_MakeHalfSpace.hxx>
#include <BRepGProp.hxx>
#include <GProp_GProps.hxx>
#include <GProp_PrincipalProps.hxx>
#include <BRepLProp_SurfaceTool.hxx>
#include <BRepGProp_Face.hxx>
#include <GeomLProp_SLProps.hxx>
@ -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
<Base::Vector3d>(pprops.FirstAxisOfInertia())));
dict.setItem("SecondAxisOfInertia",Py::Vector(Base::convertTo
<Base::Vector3d>(pprops.SecondAxisOfInertia())));
dict.setItem("ThirdAxisOfInertia",Py::Vector(Base::convertTo
<Base::Vector3d>(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;

View File

@ -34,5 +34,63 @@
<UserDocu>Make a half-space solid by this shell and a reference point.</UserDocu>
</Documentation>
</Methode>
<Attribute Name="Mass" ReadOnly="true">
<Documentation>
<UserDocu>Returns the mass of the current system.</UserDocu>
</Documentation>
<Parameter Name="Mass" Type="Object"/>
</Attribute>
<Attribute Name="CenterOfMass" ReadOnly="true">
<Documentation>
<UserDocu>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.</UserDocu>
</Documentation>
<Parameter Name="CenterOfMass" Type="Object"/>
</Attribute>
<Attribute Name="MatrixOfInertia" ReadOnly="true">
<Documentation>
<UserDocu>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.</UserDocu>
</Documentation>
<Parameter Name="MatrixOfInertia" Type="Object"/>
</Attribute>
<Attribute Name="StaticMoments" ReadOnly="true">
<Documentation>
<UserDocu>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.</UserDocu>
</Documentation>
<Parameter Name="StaticMoments" Type="Object"/>
</Attribute>
<Attribute Name="PrincipalProperties" ReadOnly="true">
<Documentation>
<UserDocu>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.</UserDocu>
</Documentation>
<Parameter Name="PrincipalProperties" Type="Dict"/>
</Attribute>
</PythonExport>
</GenerateModel>

View File

@ -26,6 +26,9 @@
# include <gp_Ax1.hxx>
# include <BRep_Builder.hxx>
# include <BRepCheck_Analyzer.hxx>
# include <BRepGProp.hxx>
# include <GProp_GProps.hxx>
# include <GProp_PrincipalProps.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Shell.hxx>
# include <ShapeUpgrade_ShellSewing.hxx>
@ -38,6 +41,7 @@
#include <Base/GeometryPyCXX.h>
#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
<Base::Vector3d>(pprops.FirstAxisOfInertia())));
dict.setItem("SecondAxisOfInertia",Py::Vector(Base::convertTo
<Base::Vector3d>(pprops.SecondAxisOfInertia())));
dict.setItem("ThirdAxisOfInertia",Py::Vector(Base::convertTo
<Base::Vector3d>(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;

View File

@ -91,14 +91,63 @@ Part.show(s)
</UserDocu>
</Documentation>
</Methode>
<Attribute Name="Mass" ReadOnly="true">
<Documentation>
<UserDocu>Returns the mass of the current system.</UserDocu>
</Documentation>
<Parameter Name="Mass" Type="Object"/>
</Attribute>
<Attribute Name="CenterOfMass" ReadOnly="true">
<Documentation>
<UserDocu>Returns the center of mass of the current system.
<UserDocu>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.</UserDocu>
</Documentation>
<Parameter Name="CenterOfMass" Type="Object"/>
</Attribute>
<Attribute Name="MatrixOfInertia" ReadOnly="true">
<Documentation>
<UserDocu>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.</UserDocu>
</Documentation>
<Parameter Name="MatrixOfInertia" Type="Object"/>
</Attribute>
<Attribute Name="StaticMoments" ReadOnly="true">
<Documentation>
<UserDocu>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.</UserDocu>
</Documentation>
<Parameter Name="StaticMoments" Type="Object"/>
</Attribute>
<Attribute Name="PrincipalProperties" ReadOnly="true">
<Documentation>
<UserDocu>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.</UserDocu>
</Documentation>
<Parameter Name="PrincipalProperties" Type="Dict"/>
</Attribute>
</PythonExport>
</GenerateModel>

View File

@ -37,6 +37,7 @@
#include <BRepGProp.hxx>
#include <GProp_GProps.hxx>
#include <GProp_PrincipalProps.hxx>
#include <GCPnts_UniformAbscissa.hxx>
#include <GCPnts_UniformDeflection.hxx>
#include <GCPnts_TangentialDeflection.hxx>
@ -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
<Base::Vector3d>(pprops.FirstAxisOfInertia())));
dict.setItem("SecondAxisOfInertia",Py::Vector(Base::convertTo
<Base::Vector3d>(pprops.SecondAxisOfInertia())));
dict.setItem("ThirdAxisOfInertia",Py::Vector(Base::convertTo
<Base::Vector3d>(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;