From 96e52b09da9c808a6d10526f2115178e8499ebec Mon Sep 17 00:00:00 2001 From: Maxime Curioni Date: Tue, 15 Jul 2008 01:07:19 +0000 Subject: soc-2008-mxcurioni: Reimplemented the Freestyle Python API's files to be correctly used as classes and not submodules. Added and integrated object lifecycle functions (__new__, __alloc__, __repr__) for the previous classes: BinaryPredicate0D, BinaryPredicate1D, Id, Interface0D, Interface1D. All of these classes were tested within Blender's Python interpreter with simple test cases and their getter/setters were corrected. Interface0DIterator was modified to allow BPy_Interface1D to be instantiated: verticesBegin(), verticesEnd(), pointsBegin(float) and pointsEnd(float) are not pure virtual functions anymore. If they are called directly from BPy_Interface1D (instead of its subclasses), an error message is displayed. --- .../freestyle/intern/python/BinaryPredicate0D.cpp | 109 +++++++++----- .../freestyle/intern/python/BinaryPredicate0D.h | 2 +- .../freestyle/intern/python/BinaryPredicate1D.cpp | 110 +++++++++----- .../freestyle/intern/python/BinaryPredicate1D.h | 3 +- source/blender/freestyle/intern/python/Convert.cpp | 12 +- source/blender/freestyle/intern/python/Convert.h | 4 + .../blender/freestyle/intern/python/Freestyle.cpp | 22 +-- source/blender/freestyle/intern/python/Id.cpp | 165 ++++++++++++++------- source/blender/freestyle/intern/python/Id.h | 3 +- .../freestyle/intern/python/Interface0D.cpp | 117 ++++++++++----- .../blender/freestyle/intern/python/Interface0D.h | 3 +- .../freestyle/intern/python/Interface1D.cpp | 123 +++++++++------ .../blender/freestyle/intern/python/Interface1D.h | 2 +- .../freestyle/intern/view_map/Interface1D.h | 23 ++- 14 files changed, 459 insertions(+), 239 deletions(-) (limited to 'source/blender/freestyle') diff --git a/source/blender/freestyle/intern/python/BinaryPredicate0D.cpp b/source/blender/freestyle/intern/python/BinaryPredicate0D.cpp index 2c16adb7a82..107216a6b50 100644 --- a/source/blender/freestyle/intern/python/BinaryPredicate0D.cpp +++ b/source/blender/freestyle/intern/python/BinaryPredicate0D.cpp @@ -9,18 +9,22 @@ extern "C" { /////////////////////////////////////////////////////////////////////////////////////////// - -/*-----------------------Python API function prototypes for the BinaryPredicate0D module--*/ -//static PyObject *Freestyle_testOutput( BPy_Freestyle * self ); -/*-----------------------BinaryPredicate0D module doc strings-----------------------------*/ -static char M_BinaryPredicate0D_doc[] = "The Blender.Freestyle.BinaryPredicate0D submodule"; -/*----------------------BinaryPredicate0D module method def----------------------------*/ -struct PyMethodDef M_BinaryPredicate0D_methods[] = { -// {"testOutput", ( PyCFunction ) Freestyle_testOutput, METH_NOARGS, "() - Return Curve Data name"}, +/*--------------- Python API function prototypes for BinaryPredicate0D instance -----------*/ +static PyObject * BinaryPredicate0D___new__(PyTypeObject *type, PyObject *args, PyObject *kwds); +static void BinaryPredicate0D___dealloc__(BPy_BinaryPredicate0D *self); +static PyObject * BinaryPredicate0D___repr__(BPy_BinaryPredicate0D *self); + +static PyObject * BinaryPredicate0D_getName( BPy_BinaryPredicate0D *self, PyObject *args); +static PyObject * BinaryPredicate0D___call__( BPy_BinaryPredicate0D *self, PyObject *args); + +/*----------------------BinaryPredicate0D instance definitions ----------------------------*/ +static PyMethodDef BPy_BinaryPredicate0D_methods[] = { + {"getName", ( PyCFunction ) BinaryPredicate0D_getName, METH_NOARGS, "( )Returns the string of the name of the binary predicate."}, + {"__call__", ( PyCFunction ) BinaryPredicate0D___call__, METH_VARARGS, "BinaryPredicate0D(Interface0D, Interface0D ). Must be overloaded by inherited classes. It evaluates a relation between two Interface0D." }, {NULL, NULL, 0, NULL} }; -/*-----------------------BPy_Freestyle method def------------------------------*/ +/*-----------------------BPy_BinaryPredicate0D type definition ------------------------------*/ PyTypeObject BinaryPredicate0D_Type = { PyObject_HEAD_INIT( NULL ) @@ -30,12 +34,12 @@ PyTypeObject BinaryPredicate0D_Type = { 0, /* tp_itemsize */ /* methods */ - NULL, /* tp_dealloc */ - NULL, /* printfunc tp_print; */ - NULL, /* getattrfunc tp_getattr; */ - NULL, /* setattrfunc tp_setattr; */ - NULL, /* tp_compare */ - NULL, /* tp_repr */ + (destructor)BinaryPredicate0D___dealloc__, /* tp_dealloc */ + NULL, /* printfunc tp_print; */ + NULL, /* getattrfunc tp_getattr; */ + NULL, /* setattrfunc tp_setattr; */ + NULL, /* tp_compare */ + (reprfunc)BinaryPredicate0D___repr__, /* tp_repr */ /* Method suites for standard classes */ @@ -78,17 +82,17 @@ PyTypeObject BinaryPredicate0D_Type = { NULL, /* iternextfunc tp_iternext; */ /*** Attribute descriptor and subclassing stuff ***/ - NULL, /* struct PyMethodDef *tp_methods; */ - NULL, /* struct PyMemberDef *tp_members; */ - NULL, /* struct PyGetSetDef *tp_getset; */ - NULL, /* struct _typeobject *tp_base; */ - NULL, /* PyObject *tp_dict; */ - NULL, /* descrgetfunc tp_descr_get; */ - NULL, /* descrsetfunc tp_descr_set; */ - 0, /* long tp_dictoffset; */ - NULL, /* initproc tp_init; */ - NULL, /* allocfunc tp_alloc; */ - NULL, /* newfunc tp_new; */ + BPy_BinaryPredicate0D_methods, /* struct PyMethodDef *tp_methods; */ + NULL, /* struct PyMemberDef *tp_members; */ + NULL, /* struct PyGetSetDef *tp_getset; */ + NULL, /* struct _typeobject *tp_base; */ + NULL, /* PyObject *tp_dict; */ + NULL, /* descrgetfunc tp_descr_get; */ + NULL, /* descrsetfunc tp_descr_set; */ + 0, /* long tp_dictoffset; */ + NULL, /* initproc tp_init; */ + NULL, /* allocfunc tp_alloc; */ + (newfunc)BinaryPredicate0D___new__, /* newfunc tp_new; */ /* Low-level free-memory routine */ NULL, /* freefunc tp_free; */ @@ -106,35 +110,60 @@ PyTypeObject BinaryPredicate0D_Type = { }; //-------------------MODULE INITIALIZATION-------------------------------- -PyObject *BinaryPredicate0D_Init( void ) +PyMODINIT_FUNC BinaryPredicate0D_Init( PyObject *module ) { - PyObject *submodule; - + if( module == NULL ) + return; + if( PyType_Ready( &BinaryPredicate0D_Type ) < 0 ) - return NULL; - - submodule = Py_InitModule3( "Blender.Freestyle.BinaryPredicate0D", M_BinaryPredicate0D_methods, M_BinaryPredicate0D_doc ); - - return submodule; + return; + + Py_INCREF( &BinaryPredicate0D_Type ); + PyModule_AddObject(module, "BinaryPredicate0D", (PyObject *)&BinaryPredicate0D_Type); } //------------------------INSTANCE METHODS ---------------------------------- -PyObject *BinaryPredicate0D_getName( BPy_BinaryPredicate0D *self, PyObject *args) +PyObject * BinaryPredicate0D___new__(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + BPy_BinaryPredicate0D *self; + + self = (BPy_BinaryPredicate0D *)type->tp_alloc(type, 0); + if (self != NULL) { + self->bp0D = new BinaryPredicate0D(); + } + + return (PyObject *)self; +} + +void BinaryPredicate0D___dealloc__(BPy_BinaryPredicate0D* self) +{ + delete self->bp0D; + self->ob_type->tp_free((PyObject*)self); +} + +PyObject * BinaryPredicate0D___repr__(BPy_BinaryPredicate0D* self) +{ + return PyString_FromFormat("type: %s - address: %p", self->bp0D->getName().c_str(), self->bp0D ); +} + + +PyObject * BinaryPredicate0D_getName( BPy_BinaryPredicate0D *self, PyObject *args) { return PyString_FromString( self->bp0D->getName().c_str() ); } -PyObject *BinaryPredicate0D___call__( BPy_BinaryPredicate0D *self, PyObject *args) +PyObject * BinaryPredicate0D___call__( BPy_BinaryPredicate0D *self, PyObject *args) { - BPy_BinaryPredicate0D *obj1; - BPy_Interface0D *obj2, *obj3; + BPy_Interface0D *obj1, *obj2; bool b; - if (!PyArg_ParseTuple(args,(char *)"OOO:BinaryPredicate0D___call__", &obj1, obj2, &obj3)) + if( !PyArg_ParseTuple(args,(char *)"OO:BinaryPredicate0D___call__", &obj1, obj2) ) { cout << "ERROR: BinaryPredicate0D___call__ " << endl; + return NULL; + } - b = self->bp0D->operator()( *(obj2->if0D) , *(obj3->if0D) ); + b = self->bp0D->operator()( *(obj1->if0D) , *(obj2->if0D) ); return PyBool_from_bool( b ); } diff --git a/source/blender/freestyle/intern/python/BinaryPredicate0D.h b/source/blender/freestyle/intern/python/BinaryPredicate0D.h index 30467d2e565..6ad25ab2816 100644 --- a/source/blender/freestyle/intern/python/BinaryPredicate0D.h +++ b/source/blender/freestyle/intern/python/BinaryPredicate0D.h @@ -24,7 +24,7 @@ typedef struct { /*---------------------------Python BPy_BinaryPredicate0D visible prototypes-----------*/ -PyObject *BinaryPredicate0D_Init( void ); +PyMODINIT_FUNC BinaryPredicate0D_Init( PyObject *module ); /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BinaryPredicate1D.cpp b/source/blender/freestyle/intern/python/BinaryPredicate1D.cpp index d6a99d689bb..afdab7c08ed 100644 --- a/source/blender/freestyle/intern/python/BinaryPredicate1D.cpp +++ b/source/blender/freestyle/intern/python/BinaryPredicate1D.cpp @@ -9,33 +9,36 @@ extern "C" { /////////////////////////////////////////////////////////////////////////////////////////// - -/*-----------------------Python API function prototypes for the BinaryPredicate1D module--*/ -//static PyObject *Freestyle_testOutput( BPy_Freestyle * self ); -/*-----------------------BinaryPredicate1D module doc strings-----------------------------*/ -static char M_BinaryPredicate1D_doc[] = "The Blender.Freestyle.BinaryPredicate1D submodule"; -/*----------------------BinaryPredicate1D module method def----------------------------*/ -struct PyMethodDef M_BinaryPredicate1D_methods[] = { -// {"testOutput", ( PyCFunction ) Freestyle_testOutput, METH_NOARGS, "() - Return Curve Data name"}, +/*--------------- Python API function prototypes for BinaryPredicate1D instance -----------*/ +static PyObject * BinaryPredicate1D___new__(PyTypeObject *type, PyObject *args, PyObject *kwds); +static void BinaryPredicate1D___dealloc__(BPy_BinaryPredicate1D *self); +static PyObject * BinaryPredicate1D___repr__(BPy_BinaryPredicate1D *self); + +static PyObject * BinaryPredicate1D_getName( BPy_BinaryPredicate1D *self, PyObject *args); +static PyObject * BinaryPredicate1D___call__( BPy_BinaryPredicate1D *self, PyObject *args); + +/*----------------------BinaryPredicate1D instance definitions ----------------------------*/ +static PyMethodDef BPy_BinaryPredicate1D_methods[] = { + {"getName", ( PyCFunction ) BinaryPredicate1D_getName, METH_NOARGS, "( )Returns the string of the name of the binary predicate."}, + {"__call__", ( PyCFunction ) BinaryPredicate1D___call__, METH_VARARGS, "BinaryPredicate1D(Interface1D, Interface1D ). Must be overloaded by inherited classes. It evaluates a relation between two Interface1D." }, {NULL, NULL, 0, NULL} }; -/*-----------------------BPy_Freestyle method def------------------------------*/ - +/*-----------------------BPy_BinaryPredicate1D type definition ------------------------------*/ PyTypeObject BinaryPredicate1D_Type = { PyObject_HEAD_INIT( NULL ) - 0, /* ob_size */ + 0, /* ob_size */ "BinaryPredicate1D", /* tp_name */ sizeof( BPy_BinaryPredicate1D ), /* tp_basicsize */ - 0, /* tp_itemsize */ + 0, /* tp_itemsize */ /* methods */ - NULL, /* tp_dealloc */ - NULL, /* printfunc tp_print; */ - NULL, /* getattrfunc tp_getattr; */ - NULL, /* setattrfunc tp_setattr; */ - NULL, /* tp_compare */ - NULL, /* tp_repr */ + (destructor)BinaryPredicate1D___dealloc__, /* tp_dealloc */ + NULL, /* printfunc tp_print; */ + NULL, /* getattrfunc tp_getattr; */ + NULL, /* setattrfunc tp_setattr; */ + NULL, /* tp_compare */ + (reprfunc)BinaryPredicate1D___repr__, /* tp_repr */ /* Method suites for standard classes */ @@ -78,17 +81,17 @@ PyTypeObject BinaryPredicate1D_Type = { NULL, /* iternextfunc tp_iternext; */ /*** Attribute descriptor and subclassing stuff ***/ - NULL, /* struct PyMethodDef *tp_methods; */ - NULL, /* struct PyMemberDef *tp_members; */ - NULL, /* struct PyGetSetDef *tp_getset; */ - NULL, /* struct _typeobject *tp_base; */ - NULL, /* PyObject *tp_dict; */ - NULL, /* descrgetfunc tp_descr_get; */ - NULL, /* descrsetfunc tp_descr_set; */ - 0, /* long tp_dictoffset; */ - NULL, /* initproc tp_init; */ - NULL, /* allocfunc tp_alloc; */ - NULL, /* newfunc tp_new; */ + BPy_BinaryPredicate1D_methods, /* struct PyMethodDef *tp_methods; */ + NULL, /* struct PyMemberDef *tp_members; */ + NULL, /* struct PyGetSetDef *tp_getset; */ + NULL, /* struct _typeobject *tp_base; */ + NULL, /* PyObject *tp_dict; */ + NULL, /* descrgetfunc tp_descr_get; */ + NULL, /* descrsetfunc tp_descr_set; */ + 0, /* long tp_dictoffset; */ + NULL, /* initproc tp_init; */ + NULL, /* allocfunc tp_alloc; */ + BinaryPredicate1D___new__, /* newfunc tp_new; */ /* Low-level free-memory routine */ NULL, /* freefunc tp_free; */ @@ -106,20 +109,44 @@ PyTypeObject BinaryPredicate1D_Type = { }; //-------------------MODULE INITIALIZATION-------------------------------- -PyObject *BinaryPredicate1D_Init( void ) +PyMODINIT_FUNC BinaryPredicate1D_Init( PyObject *module ) { - PyObject *submodule; - + if( module == NULL ) + return; + if( PyType_Ready( &BinaryPredicate1D_Type ) < 0 ) - return NULL; - - submodule = Py_InitModule3( "Blender.Freestyle.BinaryPredicate1D", M_BinaryPredicate1D_methods, M_BinaryPredicate1D_doc ); - - return submodule; + return; + + Py_INCREF( &BinaryPredicate1D_Type ); + PyModule_AddObject(module, "BinaryPredicate1D", (PyObject *)&BinaryPredicate1D_Type); } + //------------------------INSTANCE METHODS ---------------------------------- +PyObject * BinaryPredicate1D___new__(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + BPy_BinaryPredicate1D *self; + + self = (BPy_BinaryPredicate1D *)type->tp_alloc(type, 0); + if (self != NULL) { + self->bp1D = new BinaryPredicate1D(); + } + + return (PyObject *)self; +} + +void BinaryPredicate1D___dealloc__(BPy_BinaryPredicate1D* self) +{ + delete self->bp1D; + self->ob_type->tp_free((PyObject*)self); +} + +PyObject * BinaryPredicate1D___repr__(BPy_BinaryPredicate1D* self) +{ + return PyString_FromFormat("type: %s - address: %p", self->bp1D->getName().c_str(), self->bp1D ); +} + PyObject *BinaryPredicate1D_getName( BPy_BinaryPredicate1D *self, PyObject *args) { return PyString_FromString( self->bp1D->getName().c_str() ); @@ -127,14 +154,15 @@ PyObject *BinaryPredicate1D_getName( BPy_BinaryPredicate1D *self, PyObject *args PyObject *BinaryPredicate1D___call__( BPy_BinaryPredicate1D *self, PyObject *args) { - BPy_BinaryPredicate1D *obj1; - BPy_Interface1D *obj2, *obj3; + BPy_Interface1D *obj1, *obj2; bool b; - if (!PyArg_ParseTuple(args,(char *)"OOO:BinaryPredicate1D___call__", &obj1, &obj2, &obj3)) + if( !PyArg_ParseTuple(args,(char *)"OO:BinaryPredicate1D___call__", &obj1, &obj2) ) { cout << "ERROR: BinaryPredicate1D___call__ " << endl; + return NULL; + } - b = self->bp1D->operator()( *(obj2->if1D) , *(obj3->if1D) ); + b = self->bp1D->operator()( *(obj1->if1D) , *(obj2->if1D) ); return PyBool_from_bool( b ); } diff --git a/source/blender/freestyle/intern/python/BinaryPredicate1D.h b/source/blender/freestyle/intern/python/BinaryPredicate1D.h index d401c585197..2745ca6fc3f 100644 --- a/source/blender/freestyle/intern/python/BinaryPredicate1D.h +++ b/source/blender/freestyle/intern/python/BinaryPredicate1D.h @@ -24,8 +24,7 @@ typedef struct { /*---------------------------Python BPy_BinaryPredicate1D visible prototypes-----------*/ -PyObject *BinaryPredicate1D_Init( void ); - +PyMODINIT_FUNC BinaryPredicate1D_Init( PyObject *module ); /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Convert.cpp b/source/blender/freestyle/intern/python/Convert.cpp index c8ceddaf98b..d87848cde8e 100644 --- a/source/blender/freestyle/intern/python/Convert.cpp +++ b/source/blender/freestyle/intern/python/Convert.cpp @@ -32,7 +32,7 @@ PyObject *PyBool_from_bool( bool b ){ PyObject *Vector_from_Vec2f( Vec2f vec ) { float vec_data[2]; // because vec->_coord is protected vec_data[0] = vec.x(); vec_data[1] = vec.y(); - return newVectorObject( vec_data, 3, Py_NEW); + return newVectorObject( vec_data, 2, Py_NEW); } PyObject *Vector_from_Vec3f( Vec3f vec ) { @@ -47,6 +47,16 @@ PyObject *Vector_from_Vec3r( Vec3r vec ) { return newVectorObject( vec_data, 3, Py_NEW); } +PyObject *BPy_Id_from_Id( Id id ) { + BPy_Id *py_id; + + py_id = (BPy_Id *) Id_Type.tp_new( &Id_Type, 0, 0 ); + py_id->id->setFirst( id.getFirst() ); + py_id->id->setSecond( id.getSecond() ); + + return (PyObject *)py_id; +} + /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/Convert.h b/source/blender/freestyle/intern/python/Convert.h index d1bac93734a..a2e7eeafd94 100644 --- a/source/blender/freestyle/intern/python/Convert.h +++ b/source/blender/freestyle/intern/python/Convert.h @@ -4,6 +4,8 @@ #include "../geometry/Geom.h" using namespace Geometry; +#include "Id.h" + #ifdef __cplusplus extern "C" { #endif @@ -22,6 +24,8 @@ PyObject *Vector_from_Vec2f( Vec2f v ); PyObject *Vector_from_Vec3f( Vec3f v ); PyObject *Vector_from_Vec3r( Vec3r v ); +PyObject *BPy_Id_from_Id( Id id ); + /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/Freestyle.cpp b/source/blender/freestyle/intern/python/Freestyle.cpp index e3a5cf91117..93d01b29040 100644 --- a/source/blender/freestyle/intern/python/Freestyle.cpp +++ b/source/blender/freestyle/intern/python/Freestyle.cpp @@ -111,22 +111,22 @@ PyTypeObject Freestyle_Type = { //-------------------MODULE INITIALIZATION-------------------------------- PyObject *Freestyle_Init( void ) { - PyObject *submodule; - PyObject *dict; + PyObject *module; if( PyType_Ready( &Freestyle_Type ) < 0 ) return NULL; - submodule = Py_InitModule3( "Blender.Freestyle", M_Freestyle_methods, M_Freestyle_doc ); - - dict = PyModule_GetDict( submodule ); - PyDict_SetItemString( dict, "BinaryPredicate0D", BinaryPredicate0D_Init() ); - PyDict_SetItemString( dict, "BinaryPredicate1D", BinaryPredicate1D_Init() ); - PyDict_SetItemString( dict, "Interface0D", Interface0D_Init() ); - PyDict_SetItemString( dict, "Interface1D", Interface1D_Init() ); - PyDict_SetItemString( dict, "Id", Id_Init() ); + // initialize modules + module = Py_InitModule3( "Blender.Freestyle", M_Freestyle_methods, M_Freestyle_doc ); - return submodule; + // attach its classes (adding the object types to the module) + BinaryPredicate0D_Init( module ); + BinaryPredicate1D_Init( module ); + Id_Init( module ); + Interface0D_Init( module ); + Interface1D_Init( module ); + + return module; } /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Id.cpp b/source/blender/freestyle/intern/python/Id.cpp index a835efa78f7..1f862df0204 100644 --- a/source/blender/freestyle/intern/python/Id.cpp +++ b/source/blender/freestyle/intern/python/Id.cpp @@ -8,33 +8,48 @@ extern "C" { /////////////////////////////////////////////////////////////////////////////////////////// - -/*-----------------------Python API function prototypes for the Id module--*/ -//static PyObject *Freestyle_testOutput( BPy_Freestyle * self ); -/*-----------------------Id module doc strings-----------------------------*/ -static char M_Id_doc[] = "The Blender.Freestyle.Id submodule"; -/*----------------------Id module method def----------------------------*/ -struct PyMethodDef M_Id_methods[] = { -// {"testOutput", ( PyCFunction ) Freestyle_testOutput, METH_NOARGS, "() - Return Curve Data name"}, +/*--------------- Python API function prototypes for Id instance -----------*/ +static PyObject * Id___new__(PyTypeObject *type, PyObject *args, PyObject *kwds); +static void Id___dealloc__(BPy_Id *self); +static int Id___init__(BPy_Id *self, PyObject *args, PyObject *kwds); +static PyObject * Id___repr__(BPy_Id* self); + +static PyObject * Id_getFirst( BPy_Id *self ); +static PyObject * Id_getSecond( BPy_Id *self); +static PyObject * Id_setFirst( BPy_Id *self , PyObject *args); +static PyObject * Id_setSecond( BPy_Id *self , PyObject *args); +static PyObject * Id___eq__( BPy_Id *self , PyObject *args); +static PyObject * Id___ne__( BPy_Id *self , PyObject *args); +static PyObject * Id___lt__( BPy_Id *self , PyObject *args); + +/*----------------------Id instance definitions ----------------------------*/ +static PyMethodDef BPy_Id_methods[] = { + {"getFirst", ( PyCFunction ) Id_getFirst, METH_NOARGS, "Returns the first Id number"}, + {"getSecond", ( PyCFunction ) Id_getSecond, METH_NOARGS, "Returns the second Id number" }, + {"setFirst", ( PyCFunction ) Id_setFirst, METH_VARARGS, "Sets the first number constituing the Id" }, + {"setSecond", ( PyCFunction ) Id_setSecond, METH_VARARGS, "Sets the second number constituing the Id" }, + {"__eq__", ( PyCFunction ) Id___eq__, METH_VARARGS, "Operator ==" }, + {"__ne__", ( PyCFunction ) Id___ne__, METH_VARARGS, "Operator !=" }, + {"__lt__", ( PyCFunction ) Id___lt__, METH_VARARGS, "Operator <" }, {NULL, NULL, 0, NULL} }; -/*-----------------------BPy_Freestyle method def------------------------------*/ +/*-----------------------BPy_Id type definition ------------------------------*/ PyTypeObject Id_Type = { PyObject_HEAD_INIT( NULL ) 0, /* ob_size */ - "Id", /* tp_name */ - sizeof( BPy_Id ), /* tp_basicsize */ + "Id", /* tp_name */ + sizeof( BPy_Id ), /* tp_basicsize */ 0, /* tp_itemsize */ /* methods */ - NULL, /* tp_dealloc */ + (destructor)Id___dealloc__, /* tp_dealloc */ NULL, /* printfunc tp_print; */ NULL, /* getattrfunc tp_getattr; */ NULL, /* setattrfunc tp_setattr; */ NULL, /* tp_compare */ - NULL, /* tp_repr */ + (reprfunc)Id___repr__, /* tp_repr */ /* Method suites for standard classes */ @@ -77,17 +92,17 @@ PyTypeObject Id_Type = { NULL, /* iternextfunc tp_iternext; */ /*** Attribute descriptor and subclassing stuff ***/ - NULL, /* struct PyMethodDef *tp_methods; */ - NULL, /* struct PyMemberDef *tp_members; */ - NULL, /* struct PyGetSetDef *tp_getset; */ - NULL, /* struct _typeobject *tp_base; */ - NULL, /* PyObject *tp_dict; */ - NULL, /* descrgetfunc tp_descr_get; */ - NULL, /* descrsetfunc tp_descr_set; */ - 0, /* long tp_dictoffset; */ - NULL, /* initproc tp_init; */ - NULL, /* allocfunc tp_alloc; */ - NULL, /* newfunc tp_new; */ + BPy_Id_methods, /* struct PyMethodDef *tp_methods; */ + NULL, /* struct PyMemberDef *tp_members; */ + NULL, /* struct PyGetSetDef *tp_getset; */ + NULL, /* struct _typeobject *tp_base; */ + NULL, /* PyObject *tp_dict; */ + NULL, /* descrgetfunc tp_descr_get; */ + NULL, /* descrsetfunc tp_descr_set; */ + 0, /* long tp_dictoffset; */ + (initproc)Id___init__, /* initproc tp_init; */ + NULL, /* allocfunc tp_alloc; */ + Id___new__, /* newfunc tp_new; */ /* Low-level free-memory routine */ NULL, /* freefunc tp_free; */ @@ -105,20 +120,57 @@ PyTypeObject Id_Type = { }; //-------------------MODULE INITIALIZATION-------------------------------- -PyObject *Id_Init( void ) +PyMODINIT_FUNC Id_Init( PyObject *module ) { - PyObject *submodule; - + if( module == NULL ) + return; + if( PyType_Ready( &Id_Type ) < 0 ) - return NULL; - - submodule = Py_InitModule3( "Blender.Freestyle.Id", M_Id_methods, M_Id_doc ); - - return submodule; + return; + + Py_INCREF( &Id_Type ); + PyModule_AddObject(module, "Id", (PyObject *)&Id_Type); } //------------------------INSTANCE METHODS ---------------------------------- +PyObject * Id___new__(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + BPy_Id *self; + + self = (BPy_Id *)type->tp_alloc(type, 0); + if (self != NULL) { + self->id = new Id(); + } + + return (PyObject *)self; +} + +void Id___dealloc__(BPy_Id* self) +{ + delete self->id; + self->ob_type->tp_free((PyObject*)self); +} + +int Id___init__(BPy_Id *self, PyObject *args, PyObject *kwds) +{ + int first = 0, second = 0; + static char *kwlist[] = {"first", "second", NULL}; + + if (! PyArg_ParseTupleAndKeywords(args, kwds, "|ii", kwlist, &first, &second) ) + return -1; + + self->id->setFirst( first ); + self->id->setSecond( second ); + + return 0; +} + +PyObject * Id___repr__(BPy_Id* self) +{ + return PyString_FromFormat("[ first: %i, second: %i ](BPy_Id)", self->id->getFirst(), self->id->getSecond() ); +} + PyObject *Id_getFirst( BPy_Id *self ) { return PyInt_FromLong( self->id->getFirst() ); } @@ -130,14 +182,13 @@ PyObject *Id_getSecond( BPy_Id *self) { PyObject *Id_setFirst( BPy_Id *self , PyObject *args) { - PyObject * obj1 = 0 ; - PyObject * obj2 = 0 ; unsigned int i; - if( !PyArg_ParseTuple(args, (char *)"OO:Id_setFirst", &obj1, &obj2) ) + if( !PyArg_ParseTuple(args, (char *)"i:Id_setFirst", i) ) { cout << "ERROR: Id_setFirst" << endl; + Py_RETURN_NONE; + } - i = static_cast( PyInt_AsLong(obj2) ); self->id->setFirst( i ); Py_RETURN_NONE; @@ -145,48 +196,50 @@ PyObject *Id_setFirst( BPy_Id *self , PyObject *args) { PyObject *Id_setSecond( BPy_Id *self , PyObject *args) { - PyObject * obj1 = 0 ; - PyObject * obj2 = 0 ; unsigned int i; - if( !PyArg_ParseTuple(args, (char *)"OO:Id_setSecond", &obj1, &obj2) ) + if( !PyArg_ParseTuple(args, (char *)"i:Id_setSecond", i) ) { cout << "ERROR: Id_setSecond" << endl; + Py_RETURN_NONE; + } - i = static_cast( PyInt_AsLong(obj2) ); self->id->setSecond( i ); Py_RETURN_NONE; } PyObject *Id___eq__( BPy_Id *self , PyObject *args) { - BPy_Id * obj1 = 0 ; - BPy_Id * obj2 = 0 ; + BPy_Id * other = 0 ; - if( !PyArg_ParseTuple(args, (char *)"OO:Id___eq__", &obj1, &obj2) ) + if( !PyArg_ParseTuple(args, (char *)"O:Id___eq__", &other) ) { cout << "ERROR: Id___eq__" << endl; + Py_RETURN_NONE; + } - return PyBool_from_bool( obj1->id == obj2->id ); + return PyBool_from_bool( self->id == other->id ); } -PyObject *Id___ne__(PyObject *self , PyObject *args) { - BPy_Id * obj1 = 0 ; - BPy_Id * obj2 = 0 ; +PyObject *Id___ne__(BPy_Id *self , PyObject *args) { + BPy_Id * other = 0 ; - if( !PyArg_ParseTuple(args, (char *)"OO:Id___ne__", &obj1, &obj2) ) + if( !PyArg_ParseTuple(args, (char *)"O:Id___ne__", &other) ) { cout << "ERROR: Id___ne__" << endl; - - return PyBool_from_bool( obj1->id != obj2->id ); + Py_RETURN_NONE; + } + + return PyBool_from_bool( self->id != other->id ); } -PyObject *Id___lt__(PyObject *self , PyObject *args) { - BPy_Id * obj1 = 0 ; - BPy_Id * obj2 = 0 ; +PyObject *Id___lt__(BPy_Id *self , PyObject *args) { + BPy_Id * other = 0 ; - if( !PyArg_ParseTuple(args, (char *)"OO:Id___lt__", &obj1, &obj2) ) + if( !PyArg_ParseTuple(args, (char *)"O:Id___lt__", &other) ) { cout << "ERROR: Id___lt__" << endl; - - return PyBool_from_bool( obj1->id < obj2->id ); + Py_RETURN_NONE; + } + + return PyBool_from_bool( self->id <= other->id ); } diff --git a/source/blender/freestyle/intern/python/Id.h b/source/blender/freestyle/intern/python/Id.h index 032f35f7094..608ff3eef99 100644 --- a/source/blender/freestyle/intern/python/Id.h +++ b/source/blender/freestyle/intern/python/Id.h @@ -27,8 +27,7 @@ typedef struct { /*---------------------------Python BPy_Id visible prototypes-----------*/ -PyObject *Id_Init( void ); - +PyMODINIT_FUNC Id_Init( PyObject *module ); /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface0D.cpp b/source/blender/freestyle/intern/python/Interface0D.cpp index e09e0447aa7..47b9b28839f 100644 --- a/source/blender/freestyle/intern/python/Interface0D.cpp +++ b/source/blender/freestyle/intern/python/Interface0D.cpp @@ -8,18 +8,42 @@ extern "C" { /////////////////////////////////////////////////////////////////////////////////////////// - -/*-----------------------Python API function prototypes for the Interface0D module--*/ -//static PyObject *Freestyle_testOutput( BPy_Freestyle * self ); -/*-----------------------Interface0D module doc strings-----------------------------*/ -static char M_Interface0D_doc[] = "The Blender.Freestyle.Interface0D submodule"; -/*----------------------Interface0D module method def----------------------------*/ -struct PyMethodDef M_Interface0D_methods[] = { -// {"testOutput", ( PyCFunction ) Freestyle_testOutput, METH_NOARGS, "() - Return Curve Data name"}, +/*--------------- Python API function prototypes for Interface0D instance -----------*/ +static PyObject * Interface0D___new__(PyTypeObject *type, PyObject *args, PyObject *kwds); +static void Interface0D___dealloc__(BPy_Interface0D *self); +static PyObject * Interface0D___repr__(BPy_Interface0D *self); + +static PyObject *Interface0D_getExactTypeName( BPy_Interface0D *self ); +static PyObject *Interface0D_getX( BPy_Interface0D *self ); +static PyObject *Interface0D_getY( BPy_Interface0D *self ); +static PyObject *Interface0D_getZ( BPy_Interface0D *self ); +static PyObject *Interface0D_getPoint3D( BPy_Interface0D *self ); +static PyObject *Interface0D_getProjectedX( BPy_Interface0D *self ); +static PyObject *Interface0D_getProjectedY( BPy_Interface0D *self ); +static PyObject *Interface0D_getProjectedZ( BPy_Interface0D *self ); +static PyObject *Interface0D_getPoint2D( BPy_Interface0D *self ); +static PyObject *Interface0D_getFEdge( BPy_Interface0D *self ); +static PyObject *Interface0D_getId( BPy_Interface0D *self ); +static PyObject *Interface0D_getNature( BPy_Interface0D *self ); + +/*----------------------Interface0D instance definitions ----------------------------*/ +static PyMethodDef BPy_Interface0D_methods[] = { + {"getExactTypeName", ( PyCFunction ) Interface0D_getExactTypeName, METH_NOARGS, "( )Returns the string of the name of the interface."}, + {"getX", ( PyCFunction ) Interface0D_getX, METH_NOARGS, "( )Returns the 3D x coordinate of the point. "}, + {"getY", ( PyCFunction ) Interface0D_getY, METH_NOARGS, "( )Returns the 3D y coordinate of the point. "}, + {"getZ", ( PyCFunction ) Interface0D_getZ, METH_NOARGS, "( )Returns the 3D z coordinate of the point. "}, + {"getPoint3D", ( PyCFunction ) Interface0D_getPoint3D, METH_NOARGS, "() Returns the 3D point."}, + {"getProjectedX", ( PyCFunction ) Interface0D_getProjectedX, METH_NOARGS, "() Returns the 2D x coordinate of the point."}, + {"getProjectedY", ( PyCFunction ) Interface0D_getProjectedY, METH_NOARGS, "() Returns the 2D y coordinate of the point."}, + {"getProjectedZ", ( PyCFunction ) Interface0D_getProjectedZ, METH_NOARGS, "() Returns the 2D z coordinate of the point."}, + {"getPoint2D", ( PyCFunction ) Interface0D_getPoint2D, METH_NOARGS, "() Returns the 2D point."}, + {"getFEdge", ( PyCFunction ) Interface0D_getFEdge, METH_NOARGS, "() Returns the FEdge that lies between this Interface0D and the Interface0D given as argument."}, + {"getId", ( PyCFunction ) Interface0D_getId, METH_NOARGS, "() Returns the Id of the point."}, + {"getNature", ( PyCFunction ) Interface0D_getNature, METH_NOARGS, "() Returns the nature of the point."}, {NULL, NULL, 0, NULL} }; -/*-----------------------BPy_Freestyle method def------------------------------*/ +/*-----------------------BPy_Interface0D type definition ------------------------------*/ PyTypeObject Interface0D_Type = { PyObject_HEAD_INIT( NULL ) @@ -29,12 +53,12 @@ PyTypeObject Interface0D_Type = { 0, /* tp_itemsize */ /* methods */ - NULL, /* tp_dealloc */ - NULL, /* printfunc tp_print; */ - NULL, /* getattrfunc tp_getattr; */ - NULL, /* setattrfunc tp_setattr; */ - NULL, /* tp_compare */ - NULL, /* tp_repr */ + (destructor)Interface0D___dealloc__, /* tp_dealloc */ + NULL, /* printfunc tp_print; */ + NULL, /* getattrfunc tp_getattr; */ + NULL, /* setattrfunc tp_setattr; */ + NULL, /* tp_compare */ + (reprfunc)Interface0D___repr__, /* tp_repr */ /* Method suites for standard classes */ @@ -77,17 +101,17 @@ PyTypeObject Interface0D_Type = { NULL, /* iternextfunc tp_iternext; */ /*** Attribute descriptor and subclassing stuff ***/ - NULL, /* struct PyMethodDef *tp_methods; */ - NULL, /* struct PyMemberDef *tp_members; */ - NULL, /* struct PyGetSetDef *tp_getset; */ - NULL, /* struct _typeobject *tp_base; */ - NULL, /* PyObject *tp_dict; */ - NULL, /* descrgetfunc tp_descr_get; */ - NULL, /* descrsetfunc tp_descr_set; */ - 0, /* long tp_dictoffset; */ - NULL, /* initproc tp_init; */ - NULL, /* allocfunc tp_alloc; */ - NULL, /* newfunc tp_new; */ + BPy_Interface0D_methods, /* struct PyMethodDef *tp_methods; */ + NULL, /* struct PyMemberDef *tp_members; */ + NULL, /* struct PyGetSetDef *tp_getset; */ + NULL, /* struct _typeobject *tp_base; */ + NULL, /* PyObject *tp_dict; */ + NULL, /* descrgetfunc tp_descr_get; */ + NULL, /* descrsetfunc tp_descr_set; */ + 0, /* long tp_dictoffset; */ + NULL, /* initproc tp_init; */ + NULL, /* allocfunc tp_alloc; */ + (newfunc)Interface0D___new__, /* newfunc tp_new; */ /* Low-level free-memory routine */ NULL, /* freefunc tp_free; */ @@ -105,20 +129,43 @@ PyTypeObject Interface0D_Type = { }; //-------------------MODULE INITIALIZATION-------------------------------- -PyObject *Interface0D_Init( void ) +PyMODINIT_FUNC Interface0D_Init( PyObject *module ) { - PyObject *submodule; - + if( module == NULL ) + return; + if( PyType_Ready( &Interface0D_Type ) < 0 ) - return NULL; - - submodule = Py_InitModule3( "Blender.Freestyle.Interface0D", M_Interface0D_methods, M_Interface0D_doc ); - - return submodule; + return; + + Py_INCREF( &Interface0D_Type ); + PyModule_AddObject(module, "Interface0D", (PyObject *)&Interface0D_Type); } //------------------------INSTANCE METHODS ---------------------------------- +PyObject * Interface0D___new__(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + BPy_Interface0D *self; + + self = (BPy_Interface0D *)type->tp_alloc(type, 0); + if (self != NULL) { + self->if0D = new Interface0D(); + } + + return (PyObject *)self; +} + +void Interface0D___dealloc__(BPy_Interface0D* self) +{ + delete self->if0D; + self->ob_type->tp_free((PyObject*)self); +} + +PyObject * Interface0D___repr__(BPy_Interface0D* self) +{ + return PyString_FromFormat("type: %s - address: %p", self->if0D->getExactTypeName().c_str(), self->if0D ); +} + PyObject *Interface0D_getExactTypeName( BPy_Interface0D *self ) { return PyString_FromString( self->if0D->getExactTypeName().c_str() ); } @@ -170,7 +217,7 @@ PyObject *Interface0D_getFEdge( BPy_Interface0D *self ) { PyObject *Interface0D_getId( BPy_Interface0D *self ) { - // Id + return BPy_Id_from_Id( self->if0D->getId() ); } diff --git a/source/blender/freestyle/intern/python/Interface0D.h b/source/blender/freestyle/intern/python/Interface0D.h index e3e97cbaecd..10df1463da8 100644 --- a/source/blender/freestyle/intern/python/Interface0D.h +++ b/source/blender/freestyle/intern/python/Interface0D.h @@ -24,8 +24,7 @@ typedef struct { /*---------------------------Python BPy_Interface0D visible prototypes-----------*/ -PyObject *Interface0D_Init( void ); - +PyMODINIT_FUNC Interface0D_Init( PyObject *module ); /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface1D.cpp b/source/blender/freestyle/intern/python/Interface1D.cpp index 65641c6c8ff..7511401198b 100644 --- a/source/blender/freestyle/intern/python/Interface1D.cpp +++ b/source/blender/freestyle/intern/python/Interface1D.cpp @@ -8,18 +8,34 @@ extern "C" { /////////////////////////////////////////////////////////////////////////////////////////// - -/*-----------------------Python API function prototypes for the Interface1D module--*/ -//static PyObject *Freestyle_testOutput( BPy_Freestyle * self ); -/*-----------------------Interface1D module doc strings-----------------------------*/ -static char M_Interface1D_doc[] = "The Blender.Freestyle.Interface1D submodule"; -/*----------------------Interface1D module method def----------------------------*/ -struct PyMethodDef M_Interface1D_methods[] = { -// {"testOutput", ( PyCFunction ) Freestyle_testOutput, METH_NOARGS, "() - Return Curve Data name"}, +/*--------------- Python API function prototypes for Interface1D instance -----------*/ +static PyObject * Interface1D___new__(PyTypeObject *type, PyObject *args, PyObject *kwds); +static void Interface1D___dealloc__(BPy_Interface1D *self); +static PyObject * Interface1D___repr__(BPy_Interface1D *self); + +static PyObject *Interface1D_getExactTypeName( BPy_Interface1D *self ); +static PyObject *Interface1D_getVertices( BPy_Interface1D *self ); +static PyObject *Interface1D_getPoints( BPy_Interface1D *self ); +static PyObject *Interface1D_getLength2D( BPy_Interface1D *self ); +static PyObject *Interface1D_getId( BPy_Interface1D *self ); +static PyObject *Interface1D_getNature( BPy_Interface1D *self ); +static PyObject *Interface1D_getTimeStamp( BPy_Interface1D *self ); +static PyObject *Interface1D_setTimeStamp( BPy_Interface1D *self, PyObject *args); + +/*----------------------Interface1D instance definitions ----------------------------*/ +static PyMethodDef BPy_Interface1D_methods[] = { + {"getExactTypeName", ( PyCFunction ) Interface1D_getExactTypeName, METH_NOARGS, "( )Returns the string of the name of the interface."}, + {"getVertices", ( PyCFunction ) Interface1D_getVertices, METH_NOARGS, "Returns the vertices"}, + {"getPoints", ( PyCFunction ) Interface1D_getPoints, METH_NOARGS, "Returns the points. The difference with getVertices() is that here we can iterate over points of the 1D element at any given sampling. At each call, a virtual point is created."}, + {"getLength2D", ( PyCFunction ) Interface1D_getLength2D, METH_NOARGS, "Returns the 2D length of the 1D element"}, + {"getId", ( PyCFunction ) Interface1D_getId, METH_NOARGS, "Returns the Id of the 1D element"}, + {"getNature", ( PyCFunction ) Interface1D_getNature, METH_NOARGS, "Returns the nature of the 1D element"}, + {"getTimeStamp", ( PyCFunction ) Interface1D_getTimeStamp, METH_NOARGS, "Returns the time stamp of the 1D element. Mainly used for selection"}, + {"setTimeStamp", ( PyCFunction ) Interface1D_setTimeStamp, METH_VARARGS, "Sets the time stamp for the 1D element"}, {NULL, NULL, 0, NULL} }; -/*-----------------------BPy_Freestyle method def------------------------------*/ +/*-----------------------BPy_Interface1D type definition ------------------------------*/ PyTypeObject Interface1D_Type = { PyObject_HEAD_INIT( NULL ) @@ -29,12 +45,12 @@ PyTypeObject Interface1D_Type = { 0, /* tp_itemsize */ /* methods */ - NULL, /* tp_dealloc */ - NULL, /* printfunc tp_print; */ - NULL, /* getattrfunc tp_getattr; */ - NULL, /* setattrfunc tp_setattr; */ - NULL, /* tp_compare */ - NULL, /* tp_repr */ + (destructor)Interface1D___dealloc__, /* tp_dealloc */ + NULL, /* printfunc tp_print; */ + NULL, /* getattrfunc tp_getattr; */ + NULL, /* setattrfunc tp_setattr; */ + NULL, /* tp_compare */ + (reprfunc)Interface1D___repr__, /* tp_repr */ /* Method suites for standard classes */ @@ -77,17 +93,17 @@ PyTypeObject Interface1D_Type = { NULL, /* iternextfunc tp_iternext; */ /*** Attribute descriptor and subclassing stuff ***/ - NULL, /* struct PyMethodDef *tp_methods; */ - NULL, /* struct PyMemberDef *tp_members; */ - NULL, /* struct PyGetSetDef *tp_getset; */ - NULL, /* struct _typeobject *tp_base; */ - NULL, /* PyObject *tp_dict; */ - NULL, /* descrgetfunc tp_descr_get; */ - NULL, /* descrsetfunc tp_descr_set; */ - 0, /* long tp_dictoffset; */ - NULL, /* initproc tp_init; */ - NULL, /* allocfunc tp_alloc; */ - NULL, /* newfunc tp_new; */ + BPy_Interface1D_methods, /* struct PyMethodDef *tp_methods; */ + NULL, /* struct PyMemberDef *tp_members; */ + NULL, /* struct PyGetSetDef *tp_getset; */ + NULL, /* struct _typeobject *tp_base; */ + NULL, /* PyObject *tp_dict; */ + NULL, /* descrgetfunc tp_descr_get; */ + NULL, /* descrsetfunc tp_descr_set; */ + 0, /* long tp_dictoffset; */ + NULL, /* initproc tp_init; */ + NULL, /* allocfunc tp_alloc; */ + (newfunc)Interface1D___new__, /* newfunc tp_new; */ /* Low-level free-memory routine */ NULL, /* freefunc tp_free; */ @@ -105,31 +121,53 @@ PyTypeObject Interface1D_Type = { }; //-------------------MODULE INITIALIZATION-------------------------------- -PyObject *Interface1D_Init( void ) +PyMODINIT_FUNC Interface1D_Init( PyObject *module ) { - PyObject *submodule; - + if( module == NULL ) + return; + if( PyType_Ready( &Interface1D_Type ) < 0 ) - return NULL; - - submodule = Py_InitModule3( "Blender.Freestyle.Interface1D", M_Interface1D_methods, M_Interface1D_doc ); - - return submodule; + return; + + Py_INCREF( &Interface1D_Type ); + PyModule_AddObject(module, "Interface1D", (PyObject *)&Interface1D_Type); } //------------------------INSTANCE METHODS ---------------------------------- +PyObject * Interface1D___new__(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + BPy_Interface1D *self; + + self = (BPy_Interface1D *)type->tp_alloc(type, 0); + if (self != NULL) { + self->if1D = new Interface1D(); + } + + return (PyObject *)self; +} + +void Interface1D___dealloc__(BPy_Interface1D* self) +{ + delete self->if1D; + self->ob_type->tp_free((PyObject*)self); +} + +PyObject * Interface1D___repr__(BPy_Interface1D* self) +{ + return PyString_FromFormat("type: %s - address: %p", self->if1D->getExactTypeName().c_str(), self->if1D ); +} PyObject *Interface1D_getExactTypeName( BPy_Interface1D *self ) { return PyString_FromString( self->if1D->getExactTypeName().c_str() ); } PyObject *Interface1D_getVertices( BPy_Interface1D *self ) { - // Vector + return PyList_New(0); } PyObject *Interface1D_getPoints( BPy_Interface1D *self ) { - // Vector + return PyList_New(0); } PyObject *Interface1D_getLength2D( BPy_Interface1D *self ) { @@ -137,7 +175,7 @@ PyObject *Interface1D_getLength2D( BPy_Interface1D *self ) { } PyObject *Interface1D_getId( BPy_Interface1D *self ) { - // Id + return BPy_Id_from_Id( self->if1D->getId() ); } PyObject *Interface1D_getNature( BPy_Interface1D *self ) { @@ -149,14 +187,13 @@ PyObject *Interface1D_getTimeStamp( BPy_Interface1D *self ) { } PyObject *Interface1D_setTimeStamp( BPy_Interface1D *self, PyObject *args) { - PyObject * obj1 = 0 ; - PyObject * obj2 = 0 ; - unsigned int timestamp; - - if( !PyArg_ParseTuple(args, (char *)"OO:Interface1D_setTimeStamp", &obj1, &obj2) ) + int timestamp = 0 ; + + if( !PyArg_ParseTuple(args, (char *)"i:Interface1D_setTimeStamp", ×tamp) ) { cout << "ERROR: Interface1D_setTimeStamp" << endl; + Py_RETURN_NONE; + } - timestamp = static_cast( PyInt_AsLong(obj2) ); self->if1D->setTimeStamp( timestamp ); Py_RETURN_NONE; diff --git a/source/blender/freestyle/intern/python/Interface1D.h b/source/blender/freestyle/intern/python/Interface1D.h index 7477d368372..f39203744e4 100644 --- a/source/blender/freestyle/intern/python/Interface1D.h +++ b/source/blender/freestyle/intern/python/Interface1D.h @@ -24,7 +24,7 @@ typedef struct { /*---------------------------Python BPy_Interface1D visible prototypes-----------*/ -PyObject *Interface1D_Init( void ); +PyMODINIT_FUNC Interface1D_Init( PyObject *module ); /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/view_map/Interface1D.h b/source/blender/freestyle/intern/view_map/Interface1D.h index 96dd94c36f9..8c75afc73df 100755 --- a/source/blender/freestyle/intern/view_map/Interface1D.h +++ b/source/blender/freestyle/intern/view_map/Interface1D.h @@ -139,11 +139,19 @@ public: /*! Returns an iterator over the Interface1D vertices, * pointing to the first vertex. */ - virtual Interface0DIterator verticesBegin() = 0; + virtual Interface0DIterator verticesBegin() { + cerr << "Warning: method verticesBegin() not implemented" << endl; + return Interface0DIterator(); + } + /*! Returns an iterator over the Interface1D vertices, * pointing after the last vertex. */ - virtual Interface0DIterator verticesEnd() = 0; + virtual Interface0DIterator verticesEnd(){ + cerr << "Warning: method verticesEnd() not implemented" << endl; + return Interface0DIterator(); + } + /*! Returns an iterator over the Interface1D points, * pointing to the first point. The difference with * verticesBegin() is that here we can iterate over @@ -153,7 +161,11 @@ public: * The sampling with which we want to iterate over points of * this 1D element. */ - virtual Interface0DIterator pointsBegin(float t=0.f) = 0; + virtual Interface0DIterator pointsBegin(float t=0.f) { + cerr << "Warning: method pointsBegin() not implemented" << endl; + return Interface0DIterator(); + } + /*! Returns an iterator over the Interface1D points, * pointing after the last point. The difference with * verticesEnd() is that here we can iterate over @@ -163,7 +175,10 @@ public: * The sampling with which we want to iterate over points of * this 1D element. */ - virtual Interface0DIterator pointsEnd(float t=0.f) = 0; + virtual Interface0DIterator pointsEnd(float t=0.f) { + cerr << "Warning: method pointsEnd() not implemented" << endl; + return Interface0DIterator(); + } // Data access methods -- cgit v1.2.3