Expose findCentroid to Python

This commit is contained in:
wandererfan
2018-08-07 08:19:16 -04:00
committed by wmayer
parent 20247dd88f
commit 2dd9e67887
3 changed files with 46 additions and 1 deletions

View File

@@ -110,6 +110,9 @@ public:
add_varargs_method("writeDXFPage",&Module::writeDXFPage,
"writeDXFPage(page,filename): Exports a DrawPage to a DXF file."
);
add_varargs_method("findCentroid",&Module::findCentroid,
"vector = findCentroid(shape,direction): finds geometric centroid of shape looking in direction."
);
initialize("This is a module for making drawings"); // register with Python
}
virtual ~Module() {}
@@ -693,8 +696,38 @@ private:
}
return Py::None();
}
}
Py::Object findCentroid(const Py::Tuple& args)
{
PyObject *pcObjShape;
PyObject *pcObjDir;
if (!PyArg_ParseTuple(args.ptr(), "OO", &pcObjShape,
&pcObjDir)) {
throw Py::TypeError("expected (shape,direction");
}
if (!PyObject_TypeCheck(pcObjShape, &(TopoShapePy::Type))) {
throw Py::TypeError("expected arg1 to be 'Shape'");
}
if (!PyObject_TypeCheck(pcObjDir, &(Base::VectorPy::Type))) {
throw Py::TypeError("expected arg2 to be 'Vector'");
}
TopoShapePy* pShape = static_cast<TopoShapePy*>(pcObjShape);
if (!pShape) {
Base::Console().Error("TechDraw::findCentroid - input shape is null\n");
return Py::None();
}
const TopoDS_Shape& shape = pShape->getTopoShapePtr()->getShape();
Base::Vector3d dir = static_cast<Base::VectorPy*>(pcObjDir)->value();
Base::Vector3d c = TechDrawGeometry::findCentroidVec(shape,dir);
PyObject* result = nullptr;
result = new Base::VectorPy(new Base::Vector3d(c));
return Py::asObject(result);
}
};