Make Python API more pythonic

This commit is contained in:
wmayer 2013-10-09 21:16:04 +02:00
parent 564f3d14e3
commit a3b4524cca
3 changed files with 13 additions and 13 deletions

View File

@ -233,7 +233,7 @@ Analyzes the type of transformation.
<Documentation>
<UserDocu>The matrix elements</UserDocu>
</Documentation>
<Parameter Name="A" Type="List" />
<Parameter Name="A" Type="Sequence" />
</Attribute>
<ClassDeclarations>public:
MatrixPy(const Matrix4D &amp; mat, PyTypeObject *T = &amp;Type)

View File

@ -662,24 +662,24 @@ void MatrixPy::setA44(Py::Float arg)
(*this->getMatrixPtr())[3][3] = (double)arg;
}
Py::List MatrixPy::getA(void) const
Py::Sequence MatrixPy::getA(void) const
{
double mat[16];
this->getMatrixPtr()->getMatrix(mat);
Py::List list(16);
Py::Tuple tuple(16);
for (int i=0; i<16; i++) {
list[i] = Py::Float(mat[i]);
tuple[i] = Py::Float(mat[i]);
}
return list;
return tuple;
}
void MatrixPy::setA(Py::List arg)
void MatrixPy::setA(Py::Sequence arg)
{
double mat[16];
this->getMatrixPtr()->getMatrix(mat);
int index=0;
for (Py::List::iterator it = arg.begin(); it != arg.end() && index < 16; ++it) {
for (Py::Sequence::iterator it = arg.begin(); it != arg.end() && index < 16; ++it) {
mat[index++] = (double)Py::Float(*it);
}

View File

@ -135,15 +135,15 @@ PyObject* PointsPy::writeInventor(PyObject * args)
PyObject* PointsPy::addPoints(PyObject * args)
{
PyObject *obj;
if (!PyArg_ParseTuple(args, "O!", &PyList_Type, &obj))
if (!PyArg_ParseTuple(args, "O", &obj))
return 0;
Py::List list(obj);
try {
Py::Sequence list(obj);
union PyType_Object pyType = {&(Base::VectorPy::Type)};
Py::Type vType(pyType.o);
try {
for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
if ((*it).isType(vType)) {
Py::Vector p(*it);
getPointKernelPtr()->push_back(p.toVector());