+ Make Python API more pythonic

This commit is contained in:
wmayer
2013-10-11 13:57:05 +02:00
parent 890d454eca
commit 4686118f2a
20 changed files with 255 additions and 256 deletions

View File

@@ -240,15 +240,15 @@ PyObject* MeshPy::crossSections(PyObject *args)
PyObject *obj;
PyObject *poly=Py_False;
float min_eps = 1.0e-2f;
if (!PyArg_ParseTuple(args, "O!|fO!", &PyList_Type, &obj, &min_eps, &PyBool_Type, &poly))
if (!PyArg_ParseTuple(args, "O|fO!", &obj, &min_eps, &PyBool_Type, &poly))
return 0;
Py::List list(obj);
Py::Sequence list(obj);
union PyType_Object pyType = {&(Base::VectorPy::Type)};
Py::Type vType(pyType.o);
std::vector<MeshObject::TPlane> csPlanes;
for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
Py::Tuple pair(*it);
Py::Object p1 = pair.getItem(0);
Py::Object p2 = pair.getItem(1);
@@ -578,12 +578,12 @@ PyObject* MeshPy::addFacets(PyObject *args)
PyObject* MeshPy::removeFacets(PyObject *args)
{
PyObject* list;
if (!PyArg_ParseTuple(args, "O!", &PyList_Type, &list))
if (!PyArg_ParseTuple(args, "O", &list))
return 0;
std::vector<unsigned long> indices;
Py::List ary(list);
for (Py::List::iterator it = ary.begin(); it != ary.end(); ++it) {
Py::Sequence ary(list);
for (Py::Sequence::iterator it = ary.begin(); it != ary.end(); ++it) {
Py::Int f(*it);
indices.push_back((long)f);
}
@@ -726,12 +726,12 @@ PyObject* MeshPy::getPointSelection(PyObject *args)
PyObject* MeshPy::meshFromSegment(PyObject *args)
{
PyObject* list;
if (!PyArg_ParseTuple(args, "O!", &PyList_Type, &list))
if (!PyArg_ParseTuple(args, "O", &list))
return 0;
std::vector<unsigned long> segment;
Py::List ary(list);
for (Py::List::iterator it = ary.begin(); it != ary.end(); ++it) {
Py::Sequence ary(list);
for (Py::Sequence::iterator it = ary.begin(); it != ary.end(); ++it) {
Py::Int f(*it);
segment.push_back((long)f);
}
@@ -1284,13 +1284,13 @@ PyObject* MeshPy::cut(PyObject *args)
{
PyObject* poly;
int mode;
if (!PyArg_ParseTuple(args, "O!i", &PyList_Type, &poly, &mode))
if (!PyArg_ParseTuple(args, "Oi", &poly, &mode))
return NULL;
Py::List list(poly);
Py::Sequence list(poly);
std::vector<Base::Vector3f> polygon;
polygon.reserve(list.size());
for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
Base::Vector3d pnt = Py::Vector(*it).toVector();
polygon.push_back(Base::convertTo<Base::Vector3f>(pnt));
}
@@ -1318,13 +1318,13 @@ PyObject* MeshPy::trim(PyObject *args)
{
PyObject* poly;
int mode;
if (!PyArg_ParseTuple(args, "O!i", &PyList_Type, &poly, &mode))
if (!PyArg_ParseTuple(args, "Oi", &poly, &mode))
return NULL;
Py::List list(poly);
Py::Sequence list(poly);
std::vector<Base::Vector3f> polygon;
polygon.reserve(list.size());
for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
Base::Vector3d pnt = Py::Vector(*it).toVector();
polygon.push_back(Base::convertTo<Base::Vector3f>(pnt));
}
@@ -1453,7 +1453,7 @@ PyObject* MeshPy::getPlanarSegments(PyObject *args)
PyObject* MeshPy::getSegmentsByCurvature(PyObject *args)
{
PyObject* l;
if (!PyArg_ParseTuple(args, "O!",&PyList_Type,&l))
if (!PyArg_ParseTuple(args, "O",&l))
return NULL;
const MeshCore::MeshKernel& kernel = getMeshObjectPtr()->getKernel();
@@ -1461,9 +1461,9 @@ PyObject* MeshPy::getSegmentsByCurvature(PyObject *args)
MeshCore::MeshCurvature meshCurv(kernel);
meshCurv.ComputePerVertex();
Py::List func(l);
Py::Sequence func(l);
std::vector<MeshCore::MeshSurfaceSegment*> segm;
for (Py::List::iterator it = func.begin(); it != func.end(); ++it) {
for (Py::Sequence::iterator it = func.begin(); it != func.end(); ++it) {
Py::Tuple t(*it);
float c1 = (float)Py::Float(t[0]);
float c2 = (float)Py::Float(t[1]);