diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2013-02-16 18:21:40 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2013-02-16 18:21:40 +0400 |
commit | b35a893249bed1a70f40b86615531d7d75fe12f3 (patch) | |
tree | b3e8bbbad81873f6270f4dd00d35bc3a0526f3af /source/blender/freestyle/intern/python | |
parent | aa9c01f384d38a8e75bfd25bbdadba3fe2246e5b (diff) |
Freestyle Python API improvements - part 4.
Major API updates were made as in part 3 to address code review comments.
This revision focuses on Python wrappers of C++ iterators.
* Most getter/setter methods were reimplemented as attributes using PyGetSetDef.
* The naming of methods and attributes was fixed to follow the naming conventions
of the Blender Python API (i.e., lower case + underscores for methods and attributes,
and CamelCase for classes). The only irregular naming change is the following, to
better indicate the functionality:
- ChainingIterator: getVertex --> next_vertex
* In addition, some code clean-up was done in both C++ and Python. Also duplicated
definitions of predicate classes were removed.
Diffstat (limited to 'source/blender/freestyle/intern/python')
9 files changed, 562 insertions, 591 deletions
diff --git a/source/blender/freestyle/intern/python/BPy_Iterator.cpp b/source/blender/freestyle/intern/python/BPy_Iterator.cpp index dd7d3783d81..0e2f4b3fd43 100644 --- a/source/blender/freestyle/intern/python/BPy_Iterator.cpp +++ b/source/blender/freestyle/intern/python/BPy_Iterator.cpp @@ -12,8 +12,6 @@ #include "Iterator/BPy_ChainPredicateIterator.h" #include "Iterator/BPy_ChainSilhouetteIterator.h" - - #ifdef __cplusplus extern "C" { #endif @@ -21,64 +19,64 @@ extern "C" { /////////////////////////////////////////////////////////////////////////////////////////// //-------------------MODULE INITIALIZATION-------------------------------- -int Iterator_Init( PyObject *module ) -{ - if( module == NULL ) +int Iterator_Init(PyObject *module) +{ + if (module == NULL) return -1; - if( PyType_Ready( &Iterator_Type ) < 0 ) + if (PyType_Ready(&Iterator_Type) < 0) return -1; - Py_INCREF( &Iterator_Type ); + Py_INCREF(&Iterator_Type); PyModule_AddObject(module, "Iterator", (PyObject *)&Iterator_Type); - if( PyType_Ready( &AdjacencyIterator_Type ) < 0 ) + if (PyType_Ready(&AdjacencyIterator_Type) < 0) return -1; - Py_INCREF( &AdjacencyIterator_Type ); + Py_INCREF(&AdjacencyIterator_Type); PyModule_AddObject(module, "AdjacencyIterator", (PyObject *)&AdjacencyIterator_Type); - if( PyType_Ready( &Interface0DIterator_Type ) < 0 ) + if (PyType_Ready(&Interface0DIterator_Type) < 0) return -1; - Py_INCREF( &Interface0DIterator_Type ); + Py_INCREF(&Interface0DIterator_Type); PyModule_AddObject(module, "Interface0DIterator", (PyObject *)&Interface0DIterator_Type); - if( PyType_Ready( &CurvePointIterator_Type ) < 0 ) + if (PyType_Ready(&CurvePointIterator_Type) < 0) return -1; - Py_INCREF( &CurvePointIterator_Type ); + Py_INCREF(&CurvePointIterator_Type); PyModule_AddObject(module, "CurvePointIterator", (PyObject *)&CurvePointIterator_Type); - if( PyType_Ready( &StrokeVertexIterator_Type ) < 0 ) + if (PyType_Ready(&StrokeVertexIterator_Type) < 0) return -1; - Py_INCREF( &StrokeVertexIterator_Type ); + Py_INCREF(&StrokeVertexIterator_Type); PyModule_AddObject(module, "StrokeVertexIterator", (PyObject *)&StrokeVertexIterator_Type); - if( PyType_Ready( &SVertexIterator_Type ) < 0 ) + if (PyType_Ready(&SVertexIterator_Type) < 0) return -1; - Py_INCREF( &SVertexIterator_Type ); + Py_INCREF(&SVertexIterator_Type); PyModule_AddObject(module, "SVertexIterator", (PyObject *)&SVertexIterator_Type); - if( PyType_Ready( &orientedViewEdgeIterator_Type ) < 0 ) + if (PyType_Ready(&orientedViewEdgeIterator_Type) < 0) return -1; - Py_INCREF( &orientedViewEdgeIterator_Type ); + Py_INCREF(&orientedViewEdgeIterator_Type); PyModule_AddObject(module, "orientedViewEdgeIterator", (PyObject *)&orientedViewEdgeIterator_Type); - if( PyType_Ready( &ViewEdgeIterator_Type ) < 0 ) + if (PyType_Ready(&ViewEdgeIterator_Type) < 0) return -1; - Py_INCREF( &ViewEdgeIterator_Type ); + Py_INCREF(&ViewEdgeIterator_Type); PyModule_AddObject(module, "ViewEdgeIterator", (PyObject *)&ViewEdgeIterator_Type); - if( PyType_Ready( &ChainingIterator_Type ) < 0 ) + if (PyType_Ready(&ChainingIterator_Type) < 0) return -1; - Py_INCREF( &ChainingIterator_Type ); + Py_INCREF(&ChainingIterator_Type); PyModule_AddObject(module, "ChainingIterator", (PyObject *)&ChainingIterator_Type); - if( PyType_Ready( &ChainPredicateIterator_Type ) < 0 ) + if (PyType_Ready(&ChainPredicateIterator_Type) < 0) return -1; - Py_INCREF( &ChainPredicateIterator_Type ); + Py_INCREF(&ChainPredicateIterator_Type); PyModule_AddObject(module, "ChainPredicateIterator", (PyObject *)&ChainPredicateIterator_Type); - if( PyType_Ready( &ChainSilhouetteIterator_Type ) < 0 ) + if (PyType_Ready(&ChainSilhouetteIterator_Type) < 0) return -1; - Py_INCREF( &ChainSilhouetteIterator_Type ); + Py_INCREF(&ChainSilhouetteIterator_Type); PyModule_AddObject(module, "ChainSilhouetteIterator", (PyObject *)&ChainSilhouetteIterator_Type); return 0; @@ -86,95 +84,94 @@ int Iterator_Init( PyObject *module ) //------------------------INSTANCE METHODS ---------------------------------- -static char Iterator___doc__[] = -"Base class to define iterators.\n"; +PyDoc_STRVAR(Iterator_doc, +"Base class to define iterators."); -static void Iterator___dealloc__(BPy_Iterator* self) +static void Iterator_dealloc(BPy_Iterator* self) { if (self->it) delete self->it; - Py_TYPE(self)->tp_free((PyObject*)self); + Py_TYPE(self)->tp_free((PyObject*)self); } -static PyObject * Iterator___repr__(BPy_Iterator* self) +static PyObject * Iterator_repr(BPy_Iterator* self) { - return PyUnicode_FromFormat("type: %s - address: %p", self->it->getExactTypeName().c_str(), self->it ); + return PyUnicode_FromFormat("type: %s - address: %p", self->it->getExactTypeName().c_str(), self->it); } -static char Iterator_getExactTypeName___doc__[] = -".. method:: getExactTypeName()\n" -"\n" -" Returns the name of the iterator.\n" -"\n" -" :return: The name of the iterator.\n" -" :rtype: str\n"; - -static PyObject * Iterator_getExactTypeName(BPy_Iterator* self) { - return PyUnicode_FromString( self->it->getExactTypeName().c_str() ); -} - -static char Iterator_increment___doc__[] = +PyDoc_STRVAR(Iterator_increment_doc, ".. method:: increment()\n" "\n" -" Makes the iterator point the next element.\n"; +" Makes the iterator point the next element."); -static PyObject * Iterator_increment(BPy_Iterator* self) { +static PyObject * Iterator_increment(BPy_Iterator* self) +{ if (self->it->isEnd()) { PyErr_SetString(PyExc_RuntimeError , "cannot increment any more"); return NULL; } self->it->increment(); - Py_RETURN_NONE; } -static char Iterator_decrement___doc__[] = +PyDoc_STRVAR(Iterator_decrement_doc, ".. method:: decrement()\n" "\n" -" Makes the iterator point the previous element.\n"; +" Makes the iterator point the previous element."); -static PyObject * Iterator_decrement(BPy_Iterator* self) { +static PyObject * Iterator_decrement(BPy_Iterator* self) +{ if (self->it->isBegin()) { PyErr_SetString(PyExc_RuntimeError , "cannot decrement any more"); return NULL; } self->it->decrement(); - Py_RETURN_NONE; } -static char Iterator_isBegin___doc__[] = -".. method:: isBegin()\n" -"\n" -" Returns true if the interator points the first element.\n" +static PyMethodDef BPy_Iterator_methods[] = { + {"increment", (PyCFunction) Iterator_increment, METH_NOARGS, Iterator_increment_doc}, + {"decrement", (PyCFunction) Iterator_decrement, METH_NOARGS, Iterator_decrement_doc}, + {NULL, NULL, 0, NULL} +}; + +/*----------------------Iterator get/setters ----------------------------*/ + +PyDoc_STRVAR(Iterator_exact_type_name_doc, +"The string of the name of this iterator.\n" "\n" -" :return: True if the interator points the first element.\n" -" :rtype: bool\n"; +":type: str"); -static PyObject * Iterator_isBegin(BPy_Iterator* self) { - return PyBool_from_bool( self->it->isBegin() ); +static PyObject *Iterator_exact_type_name_get(BPy_Iterator *self, void *UNUSED(closure)) +{ + return PyUnicode_FromString(self->it->getExactTypeName().c_str()); } -static char Iterator_isEnd___doc__[] = -".. method:: isEnd()\n" +PyDoc_STRVAR(Iterator_is_begin_doc, +"True if the interator points the first element.\n" "\n" -" Returns true if the interator points the last element.\n" +":type: bool"); + +static PyObject *Iterator_is_begin_get(BPy_Iterator *self, void *UNUSED(closure)) +{ + return PyBool_from_bool(self->it->isBegin()); +} + +PyDoc_STRVAR(Iterator_is_end_doc, +"True if the interator points the last element.\n" "\n" -" :return: True if the interator points the last element.\n" -" :rtype: bool\n"; +":type: bool"); -static PyObject * Iterator_isEnd(BPy_Iterator* self) { - return PyBool_from_bool( self->it->isEnd() ); +static PyObject *Iterator_is_end_get(BPy_Iterator *self, void *UNUSED(closure)) +{ + return PyBool_from_bool(self->it->isEnd()); } -/*----------------------Iterator instance definitions ----------------------------*/ -static PyMethodDef BPy_Iterator_methods[] = { - {"getExactTypeName", ( PyCFunction ) Iterator_getExactTypeName, METH_NOARGS, Iterator_getExactTypeName___doc__}, - {"increment", ( PyCFunction ) Iterator_increment, METH_NOARGS, Iterator_increment___doc__}, - {"decrement", ( PyCFunction ) Iterator_decrement, METH_NOARGS, Iterator_decrement___doc__}, - {"isBegin", ( PyCFunction ) Iterator_isBegin, METH_NOARGS, Iterator_isBegin___doc__}, - {"isEnd", ( PyCFunction ) Iterator_isEnd, METH_NOARGS, Iterator_isEnd___doc__}, - {NULL, NULL, 0, NULL} +static PyGetSetDef BPy_Iterator_getseters[] = { + {(char *)"exact_type_name", (getter)Iterator_exact_type_name_get, (setter)NULL, (char *)Iterator_exact_type_name_doc, NULL}, + {(char *)"is_begin", (getter)Iterator_is_begin_get, (setter)NULL, (char *)Iterator_is_begin_doc, NULL}, + {(char *)"is_end", (getter)Iterator_is_end_get, (setter)NULL, (char *)Iterator_is_end_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_Iterator type definition ------------------------------*/ @@ -184,12 +181,12 @@ PyTypeObject Iterator_Type = { "Iterator", /* tp_name */ sizeof(BPy_Iterator), /* tp_basicsize */ 0, /* tp_itemsize */ - (destructor)Iterator___dealloc__, /* tp_dealloc */ + (destructor)Iterator_dealloc, /* tp_dealloc */ 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_reserved */ - (reprfunc)Iterator___repr__, /* tp_repr */ + (reprfunc)Iterator_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ @@ -200,7 +197,7 @@ PyTypeObject Iterator_Type = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - Iterator___doc__, /* tp_doc */ + Iterator_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -209,7 +206,7 @@ PyTypeObject Iterator_Type = { 0, /* tp_iternext */ BPy_Iterator_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + BPy_Iterator_getseters, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ @@ -225,5 +222,3 @@ PyTypeObject Iterator_Type = { #ifdef __cplusplus } #endif - - diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp index 1f4b041cce8..8d7e5638d19 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp @@ -11,7 +11,7 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- -static char AdjacencyIterator___doc__[] = +PyDoc_STRVAR(AdjacencyIterator_doc, "Class hierarchy: :class:`Iterator` > :class:`AdjacencyIterator`\n" "\n" "Class for representing adjacency iterators used in the chaining\n" @@ -37,27 +37,27 @@ static char AdjacencyIterator___doc__[] = " Copy constructor.\n" "\n" " :arg it: An AdjacencyIterator object.\n" -" :type it: :class:`AdjacencyIterator`\n"; +" :type it: :class:`AdjacencyIterator`"); -static int AdjacencyIterator___init__(BPy_AdjacencyIterator *self, PyObject *args ) -{ +static int AdjacencyIterator_init(BPy_AdjacencyIterator *self, PyObject *args) +{ PyObject *obj1 = 0, *obj2 = 0 , *obj3 = 0; - if (! PyArg_ParseTuple(args, "|OOO", &obj1, &obj2, &obj3) ) - return -1; + if (!PyArg_ParseTuple(args, "|OOO", &obj1, &obj2, &obj3)) + return -1; - if( !obj1 && !obj2 && !obj3 ){ + if (!obj1) { self->a_it = new AdjacencyIterator(); + + } else if (BPy_AdjacencyIterator_Check(obj1) && !obj2) { + self->a_it = new AdjacencyIterator(*(((BPy_AdjacencyIterator *)obj1)->a_it)); + + } else if (BPy_ViewVertex_Check(obj1) && (!obj2 || PyBool_Check(obj2)) && (!obj3 || PyBool_Check(obj3))) { + bool restrictToSelection = (obj2) ? bool_from_PyBool(obj2) : true; + bool restrictToUnvisited = (obj3) ? bool_from_PyBool(obj3) : true; - } else if( BPy_AdjacencyIterator_Check(obj1) ) { - self->a_it = new AdjacencyIterator(*( ((BPy_AdjacencyIterator *) obj1)->a_it )); - - } else if( BPy_ViewVertex_Check(obj1) ) { - bool restrictToSelection = ( obj2 ) ? bool_from_PyBool(obj2) : true; - bool restrictToUnvisited = ( obj3 ) ? bool_from_PyBool(obj3) : true; - - self->a_it = new AdjacencyIterator( ((BPy_ViewVertex *) obj1)->vv, restrictToSelection, restrictToUnvisited ); - + self->a_it = new AdjacencyIterator(((BPy_ViewVertex *)obj1)->vv, restrictToSelection, restrictToUnvisited); + } else { PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; @@ -66,55 +66,54 @@ static int AdjacencyIterator___init__(BPy_AdjacencyIterator *self, PyObject *arg self->py_it.it = self->a_it; return 0; - } -static PyObject * AdjacencyIterator_iternext(BPy_AdjacencyIterator *self) { +static PyObject * AdjacencyIterator_iternext(BPy_AdjacencyIterator *self) +{ if (self->a_it->isEnd()) { PyErr_SetNone(PyExc_StopIteration); return NULL; } ViewEdge *ve = self->a_it->operator*(); self->a_it->increment(); - return BPy_ViewEdge_from_ViewEdge( *ve ); + return BPy_ViewEdge_from_ViewEdge(*ve); } -static char AdjacencyIterator_isIncoming___doc__[] = -".. method:: isIncoming()\n" -"\n" -" Returns true if the current ViewEdge is coming towards the\n" -" iteration vertex. False otherwise.\n" -"\n" -" :return: True if the current ViewEdge is coming towards the\n" -" iteration vertex\n" -" :rtype: bool\n"; +static PyMethodDef BPy_AdjacencyIterator_methods[] = { + {NULL, NULL, 0, NULL} +}; -static PyObject * AdjacencyIterator_isIncoming(BPy_AdjacencyIterator *self) { - return PyBool_from_bool(self->a_it->isIncoming()); -} +/*----------------------AdjacencyIterator get/setters ----------------------------*/ -static char AdjacencyIterator_getObject___doc__[] = -".. method:: getObject()\n" -"\n" -" Returns the pointed ViewEdge.\n" +PyDoc_STRVAR(AdjacencyIterator_object_doc, +"The ViewEdge object currently pointed by this iterator.\n" "\n" -" :return: The pointed ViewEdge.\n" -" :rtype: :class:`ViewEdge`\n"; +":type: :class:`ViewEdge`"); -static PyObject * AdjacencyIterator_getObject(BPy_AdjacencyIterator *self) { - +static PyObject *AdjacencyIterator_object_get(BPy_AdjacencyIterator *self, void *UNUSED(closure)) +{ ViewEdge *ve = self->a_it->operator*(); - if( ve ) - return BPy_ViewEdge_from_ViewEdge( *ve ); + if (ve) + return BPy_ViewEdge_from_ViewEdge(*ve); Py_RETURN_NONE; } -/*----------------------AdjacencyIterator instance definitions ----------------------------*/ -static PyMethodDef BPy_AdjacencyIterator_methods[] = { - {"isIncoming", ( PyCFunction ) AdjacencyIterator_isIncoming, METH_NOARGS, AdjacencyIterator_isIncoming___doc__}, - {"getObject", ( PyCFunction ) AdjacencyIterator_getObject, METH_NOARGS, AdjacencyIterator_getObject___doc__}, - {NULL, NULL, 0, NULL} +PyDoc_STRVAR(AdjacencyIterator_is_incoming_doc, +"True if the current ViewEdge is coming towards the iteration vertex, and\n" +"False otherwise.\n" +"\n" +":type: bool"); + +static PyObject *AdjacencyIterator_is_incoming_get(BPy_AdjacencyIterator *self, void *UNUSED(closure)) +{ + return PyBool_from_bool(self->a_it->isIncoming()); +} + +static PyGetSetDef BPy_AdjacencyIterator_getseters[] = { + {(char *)"is_incoming", (getter)AdjacencyIterator_is_incoming_get, (setter)NULL, (char *)AdjacencyIterator_is_incoming_doc, NULL}, + {(char *)"object", (getter)AdjacencyIterator_object_get, (setter)NULL, (char *)AdjacencyIterator_object_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_AdjacencyIterator type definition ------------------------------*/ @@ -140,7 +139,7 @@ PyTypeObject AdjacencyIterator_Type = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - AdjacencyIterator___doc__, /* tp_doc */ + AdjacencyIterator_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -149,13 +148,13 @@ PyTypeObject AdjacencyIterator_Type = { (iternextfunc)AdjacencyIterator_iternext, /* tp_iternext */ BPy_AdjacencyIterator_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + BPy_AdjacencyIterator_getseters, /* tp_getset */ &Iterator_Type, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc)AdjacencyIterator___init__, /* tp_init */ + (initproc)AdjacencyIterator_init, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ }; diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp index ddb957c900e..5323fe1c146 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp @@ -13,7 +13,7 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- -static char ChainingIterator___doc__[] = +PyDoc_STRVAR(ChainingIterator_doc, "Class hierarchy: :class:`Iterator` > :class:`ViewEdgeIterator` > :class:`ChainingIterator`\n" "\n" "Base class for chaining iterators. This class is designed to be\n" @@ -47,52 +47,53 @@ static char ChainingIterator___doc__[] = " Copy constructor.\n" "\n" " :arg brother: \n" -" :type brother: ChainingIterator\n"; +" :type brother: ChainingIterator"); -static int ChainingIterator___init__(BPy_ChainingIterator *self, PyObject *args ) -{ +static int ChainingIterator___init__(BPy_ChainingIterator *self, PyObject *args) +{ PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0; - if (!( PyArg_ParseTuple(args, "|OOOO", &obj1, &obj2, &obj3, &obj4) )) - return -1; + if (!PyArg_ParseTuple(args, "|OOOO", &obj1, &obj2, &obj3, &obj4)) + return -1; + + if (obj1 && BPy_ChainingIterator_Check(obj1)) { + self->c_it = new ChainingIterator(*(((BPy_ChainingIterator *)obj1)->c_it)); - if( obj1 && BPy_ChainingIterator_Check(obj1) ) { - self->c_it = new ChainingIterator(*( ((BPy_ChainingIterator *) obj1)->c_it )); - } else { - bool restrictToSelection = ( obj1 ) ? bool_from_PyBool(obj1) : true; - bool restrictToUnvisited = ( obj2 ) ? bool_from_PyBool(obj2) : true; + bool restrictToSelection = (obj1) ? bool_from_PyBool(obj1) : true; + bool restrictToUnvisited = (obj2) ? bool_from_PyBool(obj2) : true; ViewEdge *begin; - if ( !obj3 || obj3 == Py_None ) + if (!obj3 || obj3 == Py_None) begin = NULL; - else if ( BPy_ViewEdge_Check(obj3) ) - begin = ((BPy_ViewEdge *) obj3)->ve; + else if (BPy_ViewEdge_Check(obj3)) + begin = ((BPy_ViewEdge *)obj3)->ve; else { PyErr_SetString(PyExc_TypeError, "3rd argument must be either a ViewEdge object or None"); return -1; } - bool orientation = ( obj4 ) ? bool_from_PyBool(obj4) : true; - - self->c_it = new ChainingIterator( restrictToSelection, restrictToUnvisited, begin, orientation); + bool orientation = (obj4) ? bool_from_PyBool(obj4) : true; + + self->c_it = new ChainingIterator(restrictToSelection, restrictToUnvisited, begin, orientation); } - + self->py_ve_it.ve_it = self->c_it; self->py_ve_it.py_it.it = self->c_it; - - self->c_it->py_c_it = (PyObject *) self; - + + self->c_it->py_c_it = (PyObject *)self; + return 0; } -static char ChainingIterator_init___doc__[] = +PyDoc_STRVAR(ChainingIterator_init_doc, ".. method:: init()\n" "\n" " Initializes the iterator context. This method is called each\n" " time a new chain is started. It can be used to reset some\n" -" history information that you might want to keep.\n"; +" history information that you might want to keep."); -static PyObject *ChainingIterator_init( BPy_ChainingIterator *self ) { - if( typeid(*(self->c_it)) == typeid(ChainingIterator) ) { +static PyObject *ChainingIterator_init(BPy_ChainingIterator *self) +{ + if (typeid(*(self->c_it)) == typeid(ChainingIterator)) { PyErr_SetString(PyExc_TypeError, "init() method not properly overridden"); return NULL; } @@ -101,7 +102,7 @@ static PyObject *ChainingIterator_init( BPy_ChainingIterator *self ) { Py_RETURN_NONE; } -static char ChainingIterator_traverse___doc__[] = +PyDoc_STRVAR(ChainingIterator_traverse_doc, ".. method:: traverse(it)\n" "\n" " This method iterates over the potential next ViewEdges and returns\n" @@ -113,77 +114,77 @@ static char ChainingIterator_traverse___doc__[] = " restriction rules by only iterating over the valid ViewEdges.\n" " :type it: :class:`AdjacencyIterator`\n" " :return: Returns the next ViewEdge to follow, or None if chaining ends.\n" -" :rtype: :class:`ViewEdge` or None\n"; +" :rtype: :class:`ViewEdge` or None"); -static PyObject *ChainingIterator_traverse( BPy_ChainingIterator *self, PyObject *args ) { +static PyObject *ChainingIterator_traverse(BPy_ChainingIterator *self, PyObject *args) +{ PyObject *py_a_it; - if(!( PyArg_ParseTuple(args, "O!", &AdjacencyIterator_Type, &py_a_it) )) + if(!(PyArg_ParseTuple(args, "O!", &AdjacencyIterator_Type, &py_a_it))) return NULL; - - if( typeid(*(self->c_it)) == typeid(ChainingIterator) ) { + + if (typeid(*(self->c_it)) == typeid(ChainingIterator)) { PyErr_SetString(PyExc_TypeError, "traverse() method not properly overridden"); return NULL; } - if( ((BPy_AdjacencyIterator *) py_a_it)->a_it ) - self->c_it->traverse(*( ((BPy_AdjacencyIterator *) py_a_it)->a_it )); - + if (((BPy_AdjacencyIterator *)py_a_it)->a_it) + self->c_it->traverse(*(((BPy_AdjacencyIterator *)py_a_it)->a_it)); + Py_RETURN_NONE; } -static char ChainingIterator_getVertex___doc__[] = -".. method:: getVertex()\n" -"\n" -" Returns the vertex which is the next crossing.\n" + +static PyMethodDef BPy_ChainingIterator_methods[] = { + {"init", (PyCFunction) ChainingIterator_init, METH_NOARGS, ChainingIterator_init_doc}, + {"traverse", (PyCFunction) ChainingIterator_traverse, METH_VARARGS, ChainingIterator_traverse_doc}, + {NULL, NULL, 0, NULL} +}; + +/*----------------------ChainingIterator get/setters ----------------------------*/ + +PyDoc_STRVAR(ChainingIterator_object_doc, +"The ViewEdge object currently pointed by this iterator.\n" "\n" -" :return: The vertex which is the next crossing.\n" -" :rtype: :class:`ViewVertex`\n"; +":type: :class:`ViewEdge`"); + +static PyObject *ChainingIterator_object_get(BPy_ChainingIterator *self, void *UNUSED(closure)) +{ + ViewEdge *ve = self->c_it->operator*(); + if (ve) + return BPy_ViewEdge_from_ViewEdge(*ve); -static PyObject *ChainingIterator_getVertex( BPy_ChainingIterator *self ) { - ViewVertex *v = self->c_it->getVertex(); - if( v ) - return Any_BPy_ViewVertex_from_ViewVertex( *v ); - Py_RETURN_NONE; } -static char ChainingIterator_isIncrementing___doc__[] = -".. method:: isIncrementing()\n" -"\n" -" Returns true if the current iteration is an incrementation.\n" +PyDoc_STRVAR(ChainingIterator_next_vertex_doc, +"The ViewVertex that is the next crossing.\n" "\n" -" :return: True if the current iteration is an incrementation.\n" -" :rtype: bool\n"; +":type: :class:`ViewVertex`"); + +static PyObject *ChainingIterator_next_vertex_get(BPy_ChainingIterator *self, void *UNUSED(closure)) +{ + ViewVertex *v = self->c_it->getVertex(); + if (v) + return Any_BPy_ViewVertex_from_ViewVertex(*v); -static PyObject *ChainingIterator_isIncrementing( BPy_ChainingIterator *self ) { - return PyBool_from_bool( self->c_it->isIncrementing() ); + Py_RETURN_NONE; } -static char ChainingIterator_getObject___doc__[] = -".. method:: getObject()\n" -"\n" -" Returns the pointed ViewEdge.\n" +PyDoc_STRVAR(ChainingIterator_is_incrementing_doc, +"True if the current iteration is an incrementation.\n" "\n" -" :return: The pointed ViewEdge.\n" -" :rtype: :class:`ViewEdge`\n"; - -static PyObject * ChainingIterator_getObject( BPy_ChainingIterator *self) { - - ViewEdge *ve = self->c_it->operator*(); - if( ve ) - return BPy_ViewEdge_from_ViewEdge( *ve ); +":type: bool"); - Py_RETURN_NONE; +static PyObject *ChainingIterator_is_incrementing_get(BPy_ChainingIterator *self, void *UNUSED(closure)) +{ + return PyBool_from_bool(self->c_it->isIncrementing()); } -/*----------------------ChainingIterator instance definitions ----------------------------*/ -static PyMethodDef BPy_ChainingIterator_methods[] = { - {"init", ( PyCFunction ) ChainingIterator_init, METH_NOARGS, ChainingIterator_init___doc__}, - {"traverse", ( PyCFunction ) ChainingIterator_traverse, METH_VARARGS, ChainingIterator_traverse___doc__}, - {"getVertex", ( PyCFunction ) ChainingIterator_getVertex, METH_NOARGS, ChainingIterator_getVertex___doc__}, - {"isIncrementing", ( PyCFunction ) ChainingIterator_isIncrementing, METH_NOARGS, ChainingIterator_isIncrementing___doc__}, - {"getObject", ( PyCFunction ) ChainingIterator_getObject, METH_NOARGS, ChainingIterator_getObject___doc__}, - {NULL, NULL, 0, NULL} +static PyGetSetDef BPy_ChainingIterator_getseters[] = { + {(char *)"object", (getter)ChainingIterator_object_get, (setter)NULL, (char *)ChainingIterator_object_doc, NULL}, + {(char *)"next_vertex", (getter)ChainingIterator_next_vertex_get, (setter)NULL, (char *)ChainingIterator_next_vertex_doc, NULL}, + {(char *)"is_incrementing", (getter)ChainingIterator_is_incrementing_get, (setter)NULL, (char *)ChainingIterator_is_incrementing_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_ChainingIterator type definition ------------------------------*/ @@ -209,7 +210,7 @@ PyTypeObject ChainingIterator_Type = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ChainingIterator___doc__, /* tp_doc */ + ChainingIterator_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -218,7 +219,7 @@ PyTypeObject ChainingIterator_Type = { 0, /* tp_iternext */ BPy_ChainingIterator_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + BPy_ChainingIterator_getseters, /* tp_getset */ &ViewEdgeIterator_Type, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp index f66d95b3a39..8761bc540bb 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp @@ -11,7 +11,7 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- -static char CurvePointIterator___doc__[] = +PyDoc_STRVAR(CurvePointIterator_doc, "Class hierarchy: :class:`Iterator` > :class:`CurvePointIterator`\n" "\n" "Class representing an iterator on a curve. Allows an iterating\n" @@ -32,24 +32,24 @@ static char CurvePointIterator___doc__[] = " Copy constructor.\n" "\n" " :arg brother: A CurvePointIterator object.\n" -" :type brother: :class:`CurvePointIterator`\n"; +" :type brother: :class:`CurvePointIterator`"); -static int CurvePointIterator___init__(BPy_CurvePointIterator *self, PyObject *args ) -{ +static int CurvePointIterator_init(BPy_CurvePointIterator *self, PyObject *args) +{ PyObject *obj = 0; - if (! PyArg_ParseTuple(args, "|O", &obj) ) - return -1; + if (!PyArg_ParseTuple(args, "|O", &obj)) + return -1; - if( !obj ){ + if (!obj) { self->cp_it = new CurveInternal::CurvePointIterator(); - - } else if( BPy_CurvePointIterator_Check(obj) ) { - self->cp_it = new CurveInternal::CurvePointIterator(*( ((BPy_CurvePointIterator *) obj)->cp_it )); - - } else if( PyFloat_Check(obj) ) { - self->cp_it = new CurveInternal::CurvePointIterator( PyFloat_AsDouble(obj) ); - + + } else if (BPy_CurvePointIterator_Check(obj)) { + self->cp_it = new CurveInternal::CurvePointIterator(*(((BPy_CurvePointIterator *)obj)->cp_it)); + + } else if (PyFloat_Check(obj)) { + self->cp_it = new CurveInternal::CurvePointIterator(PyFloat_AsDouble(obj)); + } else { PyErr_SetString(PyExc_TypeError, "invalid argument"); return -1; @@ -60,65 +60,65 @@ static int CurvePointIterator___init__(BPy_CurvePointIterator *self, PyObject *a return 0; } -static char CurvePointIterator_t___doc__[] = -".. method:: t()\n" +PyDoc_STRVAR(CurvePointIterator_cast_to_interface0diterator_doc, +".. method:: cast_to_interface0diterator()\n" "\n" -" Returns the curvilinear abscissa.\n" +" Returns an Interface0DIterator converted from this\n" +" CurvePointIterator. Useful for any call to a function of the\n" +" UnaryFunction0D type.\n" "\n" -" :return: The curvilinear abscissa.\n" -" :rtype: float\n"; +" :return: An Interface0DIterator object converted from the\n" +" iterator.\n" +" :rtype: :class:`Interface0DIterator`"); -static PyObject * CurvePointIterator_t( BPy_CurvePointIterator *self ) { - return PyFloat_FromDouble( self->cp_it->t() ); +static PyObject * CurvePointIterator_cast_to_interface0diterator(BPy_CurvePointIterator *self) +{ + Interface0DIterator it(self->cp_it->castToInterface0DIterator()); + return BPy_Interface0DIterator_from_Interface0DIterator(it, 0); } -static char CurvePointIterator_u___doc__[] = -".. method:: u()\n" -"\n" -" Returns the point parameter in the curve (0<=u<=1).\n" +static PyMethodDef BPy_CurvePointIterator_methods[] = { + {"cast_to_interface0diterator", (PyCFunction) CurvePointIterator_cast_to_interface0diterator, METH_NOARGS, CurvePointIterator_cast_to_interface0diterator_doc}, + {NULL, NULL, 0, NULL} +}; + +/*----------------------CurvePointIterator get/setters ----------------------------*/ + +PyDoc_STRVAR(CurvePointIterator_object_doc, +"The CurvePoint object currently pointed by this iterator.\n" "\n" -" :return: The point parameter.\n" -" :rtype: float\n"; +":type: :class:`CurvePoint`"); -static PyObject * CurvePointIterator_u( BPy_CurvePointIterator *self ) { - return PyFloat_FromDouble( self->cp_it->u() ); +static PyObject *CurvePointIterator_object_get(BPy_CurvePointIterator *self, void *UNUSED(closure)) +{ + return BPy_CurvePoint_from_CurvePoint(self->cp_it->operator*()); } -static char CurvePointIterator_castToInterface0DIterator___doc__[] = -".. method:: castToInterface0DIterator()\n" -"\n" -" Returns an Interface0DIterator converted from this\n" -" CurvePointIterator. Useful for any call to a function of the\n" -" UnaryFunction0D type.\n" +PyDoc_STRVAR(CurvePointIterator_t_doc, +"The curvilinear abscissa of the current point.\n" "\n" -" :return: An Interface0DIterator object converted from the\n" -" iterator.\n" -" :rtype: :class:`Interface0DIterator`\n"; +":type: float"); -static PyObject * CurvePointIterator_castToInterface0DIterator( BPy_CurvePointIterator *self ) { - Interface0DIterator it( self->cp_it->castToInterface0DIterator() ); - return BPy_Interface0DIterator_from_Interface0DIterator( it, 0 ); +static PyObject *CurvePointIterator_t_get(BPy_CurvePointIterator *self, void *UNUSED(closure)) +{ + return PyFloat_FromDouble(self->cp_it->t()); } -static char CurvePointIterator_getObject___doc__[] = -".. method:: getObject()\n" +PyDoc_STRVAR(CurvePointIterator_u_doc, +"The point parameter at the current point in the stroke (0 <= u <= 1).\n" "\n" -" Returns a CurvePoint pointed by the iterator.\n" -"\n" -" :return: \n" -" :rtype: :class:`CurvePoint`\n"; +":type: float"); -static PyObject * CurvePointIterator_getObject(BPy_CurvePointIterator *self) { - return BPy_CurvePoint_from_CurvePoint( self->cp_it->operator*() ); +static PyObject *CurvePointIterator_u_get(BPy_CurvePointIterator *self, void *UNUSED(closure)) +{ + return PyFloat_FromDouble(self->cp_it->u()); } -/*----------------------CurvePointIterator instance definitions ----------------------------*/ -static PyMethodDef BPy_CurvePointIterator_methods[] = { - {"t", ( PyCFunction ) CurvePointIterator_t, METH_NOARGS, CurvePointIterator_t___doc__}, - {"u", ( PyCFunction ) CurvePointIterator_u, METH_NOARGS, CurvePointIterator_u___doc__}, - {"castToInterface0DIterator", ( PyCFunction ) CurvePointIterator_castToInterface0DIterator, METH_NOARGS, CurvePointIterator_castToInterface0DIterator___doc__}, - {"getObject", ( PyCFunction ) CurvePointIterator_getObject, METH_NOARGS, CurvePointIterator_getObject___doc__}, - {NULL, NULL, 0, NULL} +static PyGetSetDef BPy_CurvePointIterator_getseters[] = { + {(char *)"object", (getter)CurvePointIterator_object_get, (setter)NULL, (char *)CurvePointIterator_object_doc, NULL}, + {(char *)"t", (getter)CurvePointIterator_t_get, (setter)NULL, (char *)CurvePointIterator_t_doc, NULL}, + {(char *)"u", (getter)CurvePointIterator_u_get, (setter)NULL, (char *)CurvePointIterator_u_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_CurvePointIterator type definition ------------------------------*/ @@ -144,7 +144,7 @@ PyTypeObject CurvePointIterator_Type = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - CurvePointIterator___doc__, /* tp_doc */ + CurvePointIterator_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -153,13 +153,13 @@ PyTypeObject CurvePointIterator_Type = { 0, /* tp_iternext */ BPy_CurvePointIterator_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + BPy_CurvePointIterator_getseters, /* tp_getset */ &Iterator_Type, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc)CurvePointIterator___init__, /* tp_init */ + (initproc)CurvePointIterator_init, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ }; diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp index 6643913c32a..fb9ec03648a 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp @@ -10,7 +10,7 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- -static char Interface0DIterator___doc__[] = +PyDoc_STRVAR(Interface0DIterator_doc, "Class hierarchy: :class:`Iterator` > :class:`Interface0DIterator`\n" "\n" "Class defining an iterator over Interface0D elements. An instance of\n" @@ -21,24 +21,26 @@ static char Interface0DIterator___doc__[] = " Copy constructor.\n" "\n" " :arg it: An Interface0DIterator object.\n" -" :type it: :class:`Interface0DIterator`\n"; +" :type it: :class:`Interface0DIterator`"); -static int Interface0DIterator___init__(BPy_Interface0DIterator *self, PyObject *args ) -{ +static int Interface0DIterator_init(BPy_Interface0DIterator *self, PyObject *args) +{ PyObject *obj = 0; - if (!( PyArg_ParseTuple(args, "O!", &Interface0DIterator_Type, &obj) )) - return -1; + if (!PyArg_ParseTuple(args, "O!", &Interface0DIterator_Type, &obj)) + return -1; - self->if0D_it = new Interface0DIterator(*( ((BPy_Interface0DIterator *) obj)->if0D_it )); + self->if0D_it = new Interface0DIterator(*(((BPy_Interface0DIterator *)obj)->if0D_it)); self->py_it.it = self->if0D_it; self->reversed = 0; - + return 0; } -static PyObject * Interface0DIterator_iternext( BPy_Interface0DIterator *self ) { +static PyObject * Interface0DIterator_iternext(BPy_Interface0DIterator *self) +{ Interface0D *if0D; + if (self->reversed) { if (self->if0D_it->isBegin()) { PyErr_SetNone(PyExc_StopIteration); @@ -54,51 +56,50 @@ static PyObject * Interface0DIterator_iternext( BPy_Interface0DIterator *self ) if0D = self->if0D_it->operator->(); self->if0D_it->increment(); } - return Any_BPy_Interface0D_from_Interface0D( *if0D ); + return Any_BPy_Interface0D_from_Interface0D(*if0D); } -static char Interface0DIterator_t___doc__[] = -".. method:: t()\n" -"\n" -" Returns the curvilinear abscissa.\n" +static PyMethodDef BPy_Interface0DIterator_methods[] = { + {NULL, NULL, 0, NULL} +}; + +/*----------------------Interface0DIterator get/setters ----------------------------*/ + +PyDoc_STRVAR(Interface0DIterator_object_doc, +"The Interface0D object currently pointed by this iterator.\n" "\n" -" :return: The curvilinear abscissa.\n" -" :rtype: float\n"; +":type: :class:`Interface0D`"); -static PyObject * Interface0DIterator_t( BPy_Interface0DIterator *self ) { - return PyFloat_FromDouble( self->if0D_it->t() ); +static PyObject *Interface0DIterator_object_get(BPy_Interface0DIterator *self, void *UNUSED(closure)) +{ + return Any_BPy_Interface0D_from_Interface0D(self->if0D_it->operator*()); } -static char Interface0DIterator_u___doc__[] = -".. method:: u()\n" -"\n" -" Returns the point parameter in the curve 0<=u<=1.\n" +PyDoc_STRVAR(Interface0DIterator_t_doc, +"The curvilinear abscissa of the current point.\n" "\n" -" :return: The point parameter.\n" -" :rtype: float\n"; +":type: float"); -static PyObject * Interface0DIterator_u( BPy_Interface0DIterator *self ) { - return PyFloat_FromDouble( self->if0D_it->u() ); +static PyObject *Interface0DIterator_t_get(BPy_Interface0DIterator *self, void *UNUSED(closure)) +{ + return PyFloat_FromDouble(self->if0D_it->t()); } -static char Interface0DIterator_getObject___doc__[] = -".. method:: getObject()\n" +PyDoc_STRVAR(Interface0DIterator_u_doc, +"The point parameter at the current point in the 1D element (0 <= u <= 1).\n" "\n" -" Returns the pointed Interface0D.\n" -"\n" -" :return: The pointed Interface0D.\n" -" :rtype: :class:`Interface0D`\n"; +":type: float"); -static PyObject * Interface0DIterator_getObject(BPy_Interface0DIterator *self) { - return Any_BPy_Interface0D_from_Interface0D( self->if0D_it->operator*() ); +static PyObject *Interface0DIterator_u_get(BPy_Interface0DIterator *self, void *UNUSED(closure)) +{ + return PyFloat_FromDouble(self->if0D_it->u()); } -/*----------------------Interface0DIterator instance definitions ----------------------------*/ -static PyMethodDef BPy_Interface0DIterator_methods[] = { - {"t", ( PyCFunction ) Interface0DIterator_t, METH_NOARGS, Interface0DIterator_t___doc__}, - {"u", ( PyCFunction ) Interface0DIterator_u, METH_NOARGS, Interface0DIterator_u___doc__}, - {"getObject", ( PyCFunction ) Interface0DIterator_getObject, METH_NOARGS, Interface0DIterator_getObject___doc__}, - {NULL, NULL, 0, NULL} +static PyGetSetDef BPy_Interface0DIterator_getseters[] = { + {(char *)"object", (getter)Interface0DIterator_object_get, (setter)NULL, (char *)Interface0DIterator_object_doc, NULL}, + {(char *)"t", (getter)Interface0DIterator_t_get, (setter)NULL, (char *)Interface0DIterator_t_doc, NULL}, + {(char *)"u", (getter)Interface0DIterator_u_get, (setter)NULL, (char *)Interface0DIterator_u_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_Interface0DIterator type definition ------------------------------*/ @@ -124,7 +125,7 @@ PyTypeObject Interface0DIterator_Type = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - Interface0DIterator___doc__, /* tp_doc */ + Interface0DIterator_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -133,13 +134,13 @@ PyTypeObject Interface0DIterator_Type = { (iternextfunc)Interface0DIterator_iternext, /* tp_iternext */ BPy_Interface0DIterator_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + BPy_Interface0DIterator_getseters, /* tp_getset */ &Iterator_Type, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc)Interface0DIterator___init__, /* tp_init */ + (initproc)Interface0DIterator_init, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ }; diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp index ef40d994e27..6243e487646 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp @@ -12,7 +12,7 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- -static char SVertexIterator___doc__[] = +PyDoc_STRVAR(SVertexIterator_doc, "Class hierarchy: :class:`Iterator` > :class:`SVertexIterator`\n" "\n" "Class representing an iterator over :class:`SVertex` of a\n" @@ -44,34 +44,34 @@ static char SVertexIterator___doc__[] = " :arg next: The next FEdge going out from v.\n" " :type next: :class:`FEdge`\n" " :arg t: The curvilinear abscissa at v.\n" -" :type t: float\n"; +" :type t: float"); -static int SVertexIterator___init__(BPy_SVertexIterator *self, PyObject *args ) -{ +static int SVertexIterator_init(BPy_SVertexIterator *self, PyObject *args) +{ PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0; float f = 0; - if (! PyArg_ParseTuple(args, "|OOOOf", &obj1, &obj2, &obj3, &obj4, f) ) - return -1; + if (!PyArg_ParseTuple(args, "|OOOOf", &obj1, &obj2, &obj3, &obj4, f)) + return -1; - if( !obj1 ){ + if (!obj1) { self->sv_it = new ViewEdgeInternal::SVertexIterator(); - - } else if( BPy_SVertexIterator_Check(obj1) ) { - self->sv_it = new ViewEdgeInternal::SVertexIterator(*( ((BPy_SVertexIterator *) obj1)->sv_it )); - - } else if( obj1 && BPy_SVertex_Check(obj1) && - obj2 && BPy_SVertex_Check(obj2) && - obj3 && BPy_FEdge_Check(obj3) && - obj4 && BPy_FEdge_Check(obj4) ) { + + } else if (BPy_SVertexIterator_Check(obj1)) { + self->sv_it = new ViewEdgeInternal::SVertexIterator(*(((BPy_SVertexIterator *)obj1)->sv_it)); + + } else if (obj1 && BPy_SVertex_Check(obj1) && + obj2 && BPy_SVertex_Check(obj2) && + obj3 && BPy_FEdge_Check(obj3) && + obj4 && BPy_FEdge_Check(obj4)) { self->sv_it = new ViewEdgeInternal::SVertexIterator( - ((BPy_SVertex *) obj1)->sv, - ((BPy_SVertex *) obj2)->sv, - ((BPy_FEdge *) obj3)->fe, - ((BPy_FEdge *) obj4)->fe, - f ); - + ((BPy_SVertex *)obj1)->sv, + ((BPy_SVertex *)obj2)->sv, + ((BPy_FEdge *)obj3)->fe, + ((BPy_FEdge *)obj4)->fe, + f); + } else { PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; @@ -82,53 +82,52 @@ static int SVertexIterator___init__(BPy_SVertexIterator *self, PyObject *args ) return 0; } -static char SVertexIterator_t___doc__[] = -".. method:: t()\n" -"\n" -" Returns the curvilinear abscissa.\n" +static PyMethodDef BPy_SVertexIterator_methods[] = { + {NULL, NULL, 0, NULL} +}; + +/*----------------------SVertexIterator get/setters ----------------------------*/ + +PyDoc_STRVAR(SVertexIterator_object_doc, +"The SVertex object currently pointed by this iterator.\n" "\n" -" :return: The curvilinear abscissa.\n" -" :rtype: float\n"; +":type: :class:`SVertex`"); + +static PyObject *SVertexIterator_object_get(BPy_SVertexIterator *self, void *UNUSED(closure)) +{ + SVertex *sv = self->sv_it->operator->(); -static PyObject * SVertexIterator_t( BPy_SVertexIterator *self ) { - return PyFloat_FromDouble( self->sv_it->t() ); + if (sv) + return BPy_SVertex_from_SVertex(*sv); + + Py_RETURN_NONE; } -static char SVertexIterator_u___doc__[] = -".. method:: u()\n" -"\n" -" Returns the point parameter (0<=u<=1).\n" +PyDoc_STRVAR(SVertexIterator_t_doc, +"The curvilinear abscissa of the current point.\n" "\n" -" :return: The point parameter.\n" -" :rtype: float\n"; +":type: float"); -static PyObject * SVertexIterator_u( BPy_SVertexIterator *self ) { - return PyFloat_FromDouble( self->sv_it->u() ); +static PyObject *SVertexIterator_t_get(BPy_SVertexIterator *self, void *UNUSED(closure)) +{ + return PyFloat_FromDouble(self->sv_it->t()); } -static char SVertexIterator_getObject___doc__[] = -".. method:: getObject()\n" +PyDoc_STRVAR(SVertexIterator_u_doc, +"The point parameter at the current point in the 1D element (0 <= u <= 1).\n" "\n" -" Returns the pointed SVertex.\n" -"\n" -" :return: the pointed SVertex.\n" -" :rtype: :class:`SVertex`\n"; +":type: float"); -static PyObject * SVertexIterator_getObject( BPy_SVertexIterator *self) { - SVertex *sv = self->sv_it->operator->(); - - if( sv ) - return BPy_SVertex_from_SVertex( *sv ); - - Py_RETURN_NONE; +static PyObject *SVertexIterator_u_get(BPy_SVertexIterator *self, void *UNUSED(closure)) +{ + return PyFloat_FromDouble(self->sv_it->u()); } -/*----------------------SVertexIterator instance definitions ----------------------------*/ -static PyMethodDef BPy_SVertexIterator_methods[] = { - {"t", ( PyCFunction ) SVertexIterator_t, METH_NOARGS, SVertexIterator_t___doc__}, - {"u", ( PyCFunction ) SVertexIterator_u, METH_NOARGS, SVertexIterator_u___doc__}, - {"getObject", ( PyCFunction ) SVertexIterator_getObject, METH_NOARGS, SVertexIterator_getObject___doc__}, - {NULL, NULL, 0, NULL} +static PyGetSetDef BPy_SVertexIterator_getseters[] = { + {(char *)"object", (getter)SVertexIterator_object_get, (setter)NULL, (char *)SVertexIterator_object_doc, NULL}, + {(char *)"t", (getter)SVertexIterator_t_get, (setter)NULL, (char *)SVertexIterator_t_doc, NULL}, + {(char *)"u", (getter)SVertexIterator_u_get, (setter)NULL, (char *)SVertexIterator_u_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_SVertexIterator type definition ------------------------------*/ @@ -154,7 +153,7 @@ PyTypeObject SVertexIterator_Type = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - SVertexIterator___doc__, /* tp_doc */ + SVertexIterator_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -163,13 +162,13 @@ PyTypeObject SVertexIterator_Type = { 0, /* tp_iternext */ BPy_SVertexIterator_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + BPy_SVertexIterator_getseters, /* tp_getset */ &Iterator_Type, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc)SVertexIterator___init__, /* tp_init */ + (initproc)SVertexIterator_init, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ }; diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp index a9b2c4d774a..57a9f867d53 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp @@ -11,7 +11,7 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- -static char StrokeVertexIterator___doc__[] = +PyDoc_STRVAR(StrokeVertexIterator_doc, "Class hierarchy: :class:`Iterator` > :class:`StrokeVertexIterator`\n" "\n" "Class defining an iterator designed to iterate over the\n" @@ -35,21 +35,21 @@ static char StrokeVertexIterator___doc__[] = " Copy constructor.\n" "\n" " :arg it: A StrokeVertexIterator object.\n" -" :type it: :class:`StrokeVertexIterator`\n"; +" :type it: :class:`StrokeVertexIterator`"); -static int StrokeVertexIterator___init__(BPy_StrokeVertexIterator *self, PyObject *args ) -{ +static int StrokeVertexIterator_init(BPy_StrokeVertexIterator *self, PyObject *args) +{ PyObject *obj = 0; - if (! PyArg_ParseTuple(args, "|O", &obj) ) - return -1; + if (!PyArg_ParseTuple(args, "|O", &obj)) + return -1; - if( !obj ){ + if (!obj) { self->sv_it = new StrokeInternal::StrokeVertexIterator(); - - } else if( BPy_StrokeVertexIterator_Check(obj) ) { - self->sv_it = new StrokeInternal::StrokeVertexIterator(*( ((BPy_StrokeVertexIterator *) obj)->sv_it )); - + + } else if (BPy_StrokeVertexIterator_Check(obj)) { + self->sv_it = new StrokeInternal::StrokeVertexIterator(*(((BPy_StrokeVertexIterator *)obj)->sv_it)); + } else { PyErr_SetString(PyExc_TypeError, "invalid argument"); return -1; @@ -61,8 +61,10 @@ static int StrokeVertexIterator___init__(BPy_StrokeVertexIterator *self, PyObjec return 0; } -static PyObject * StrokeVertexIterator_iternext( BPy_StrokeVertexIterator *self ) { +static PyObject * StrokeVertexIterator_iternext(BPy_StrokeVertexIterator *self) +{ StrokeVertex *sv; + if (self->reversed) { if (self->sv_it->isBegin()) { PyErr_SetNone(PyExc_StopIteration); @@ -78,73 +80,74 @@ static PyObject * StrokeVertexIterator_iternext( BPy_StrokeVertexIterator *self sv = self->sv_it->operator->(); self->sv_it->increment(); } - return BPy_StrokeVertex_from_StrokeVertex( *sv ); -} - -static char StrokeVertexIterator_t___doc__[] = -".. method:: t()\n" -"\n" -" Returns the curvilinear abscissa of the current point.\n" -"\n" -" :return: The curvilinear abscissa of the current point.\n" -" :rtype: float\n"; - -static PyObject * StrokeVertexIterator_t( BPy_StrokeVertexIterator *self ) { - return PyFloat_FromDouble( self->sv_it->t() ); -} - -static char StrokeVertexIterator_u___doc__[] = -".. method:: u()\n" -"\n" -" Returns the point parameter in the stroke (0<=u<=1).\n" -"\n" -" :return: The point parameter in the stroke\n" -" :rtype: float\n"; - -static PyObject * StrokeVertexIterator_u( BPy_StrokeVertexIterator *self ) { - return PyFloat_FromDouble( self->sv_it->u() ); + return BPy_StrokeVertex_from_StrokeVertex(*sv); } -static char StrokeVertexIterator_castToInterface0DIterator___doc__[] = -".. method:: castToInterface0DIterator()\n" +PyDoc_STRVAR(StrokeVertexIterator_cast_to_interface0diterator_doc, +".. method:: cast_to_interface0diterator()\n" "\n" " Returns an Interface0DIterator converted from this\n" " StrokeVertexIterator. Useful for any call to a function of the\n" " UnaryFunction0D type.\n" "\n" " :return: An Interface0DIterator converted from the StrokeVertexIterator.\n" -" :rtype: :class:`Interface0DIterator`\n"; +" :rtype: :class:`Interface0DIterator`"); -static PyObject * StrokeVertexIterator_castToInterface0DIterator( BPy_StrokeVertexIterator *self ) { - Interface0DIterator it( self->sv_it->castToInterface0DIterator() ); - return BPy_Interface0DIterator_from_Interface0DIterator( it, 0 ); +static PyObject * StrokeVertexIterator_cast_to_interface0diterator(BPy_StrokeVertexIterator *self) +{ + Interface0DIterator it(self->sv_it->castToInterface0DIterator()); + return BPy_Interface0DIterator_from_Interface0DIterator(it, 0); } -static char StrokeVertexIterator_getObject___doc__[] = -".. method:: getObject()\n" -"\n" -" Returns the pointed StrokeVertex.\n" +static PyMethodDef BPy_StrokeVertexIterator_methods[] = { + {"cast_to_interface0diterator", (PyCFunction) StrokeVertexIterator_cast_to_interface0diterator, METH_NOARGS, StrokeVertexIterator_cast_to_interface0diterator_doc}, + {NULL, NULL, 0, NULL} +}; + +/*----------------------StrokeVertexIterator get/setters ----------------------------*/ + +PyDoc_STRVAR(StrokeVertexIterator_object_doc, +"The StrokeVertex object currently pointed by this iterator.\n" "\n" -" :return: The pointed StrokeVertex.\n" -" :rtype: :class:`StrokeVertex`\n"; +":type: :class:`StrokeVertex`"); -static PyObject * StrokeVertexIterator_getObject( BPy_StrokeVertexIterator *self) { +static PyObject *StrokeVertexIterator_object_get(BPy_StrokeVertexIterator *self, void *UNUSED(closure)) +{ if (!self->reversed && self->sv_it->isEnd()) Py_RETURN_NONE; + StrokeVertex *sv = self->sv_it->operator->(); - if( sv ) - return BPy_StrokeVertex_from_StrokeVertex( *sv ); + if (sv) + return BPy_StrokeVertex_from_StrokeVertex(*sv); Py_RETURN_NONE; } -/*----------------------StrokeVertexIterator instance definitions ----------------------------*/ -static PyMethodDef BPy_StrokeVertexIterator_methods[] = { - {"t", ( PyCFunction ) StrokeVertexIterator_t, METH_NOARGS, StrokeVertexIterator_t___doc__}, - {"u", ( PyCFunction ) StrokeVertexIterator_u, METH_NOARGS, StrokeVertexIterator_u___doc__}, - {"castToInterface0DIterator", ( PyCFunction ) StrokeVertexIterator_castToInterface0DIterator, METH_NOARGS, StrokeVertexIterator_castToInterface0DIterator___doc__}, - {"getObject", ( PyCFunction ) StrokeVertexIterator_getObject, METH_NOARGS, StrokeVertexIterator_getObject___doc__}, - {NULL, NULL, 0, NULL} +PyDoc_STRVAR(StrokeVertexIterator_t_doc, +"The curvilinear abscissa of the current point.\n" +"\n" +":type: float"); + +static PyObject *StrokeVertexIterator_t_get(BPy_StrokeVertexIterator *self, void *UNUSED(closure)) +{ + return PyFloat_FromDouble(self->sv_it->t()); +} + +PyDoc_STRVAR(StrokeVertexIterator_u_doc, +"The point parameter at the current point in the stroke (0 <= u <= 1).\n" +"\n" +":type: float"); + +static PyObject *StrokeVertexIterator_u_get(BPy_StrokeVertexIterator *self, void *UNUSED(closure)) +{ + return PyFloat_FromDouble(self->sv_it->u()); +} + +static PyGetSetDef BPy_StrokeVertexIterator_getseters[] = { + {(char *)"object", (getter)StrokeVertexIterator_object_get, (setter)NULL, (char *)StrokeVertexIterator_object_doc, NULL}, + {(char *)"t", (getter)StrokeVertexIterator_t_get, (setter)NULL, (char *)StrokeVertexIterator_t_doc, NULL}, + {(char *)"u", (getter)StrokeVertexIterator_u_get, (setter)NULL, (char *)StrokeVertexIterator_u_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_StrokeVertexIterator type definition ------------------------------*/ @@ -170,7 +173,7 @@ PyTypeObject StrokeVertexIterator_Type = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - StrokeVertexIterator___doc__, /* tp_doc */ + StrokeVertexIterator_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -179,13 +182,13 @@ PyTypeObject StrokeVertexIterator_Type = { (iternextfunc)StrokeVertexIterator_iternext, /* tp_iternext */ BPy_StrokeVertexIterator_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + BPy_StrokeVertexIterator_getseters, /* tp_getset */ &Iterator_Type, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc)StrokeVertexIterator___init__, /* tp_init */ + (initproc)StrokeVertexIterator_init, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ }; diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp index 660e00b7089..066d223f6e9 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp @@ -12,7 +12,7 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- -static char ViewEdgeIterator___doc__[] = +PyDoc_STRVAR(ViewEdgeIterator_doc, "Class hierarchy: :class:`Iterator` > :class:`ViewEdgeIterator`\n" "\n" "Base class for iterators over ViewEdges of the :class:`ViewMap` Graph.\n" @@ -38,182 +38,148 @@ static char ViewEdgeIterator___doc__[] = " Copy constructor.\n" "\n" " :arg it: A ViewEdgeIterator object.\n" -" :type it: :class:`ViewEdgeIterator`\n"; +" :type it: :class:`ViewEdgeIterator`"); -static int ViewEdgeIterator___init__(BPy_ViewEdgeIterator *self, PyObject *args ) -{ +static int ViewEdgeIterator_init(BPy_ViewEdgeIterator *self, PyObject *args) +{ PyObject *obj1 = 0, *obj2 = 0; - if (!( PyArg_ParseTuple(args, "O|O", &obj1, &obj2) )) - return -1; + if (!PyArg_ParseTuple(args, "O|O", &obj1, &obj2)) + return -1; + + if (BPy_ViewEdgeIterator_Check(obj1)) { + self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(*(((BPy_ViewEdgeIterator *)obj1)->ve_it)); - if( obj1 && BPy_ViewEdgeIterator_Check(obj1) ) { - self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(*( ((BPy_ViewEdgeIterator *) obj1)->ve_it )); - } else { ViewEdge *begin; - if ( !obj1 || obj1 == Py_None ) + if (obj1 == Py_None) begin = NULL; - else if ( BPy_ViewEdge_Check(obj1) ) - begin = ((BPy_ViewEdge *) obj1)->ve; + else if (BPy_ViewEdge_Check(obj1)) + begin = ((BPy_ViewEdge *)obj1)->ve; else { PyErr_SetString(PyExc_TypeError, "1st argument must be either a ViewEdge object or None"); return -1; } - bool orientation = ( obj2 ) ? bool_from_PyBool(obj2) : true; - - self->ve_it = new ViewEdgeInternal::ViewEdgeIterator( begin, orientation); - + bool orientation = (obj2) ? bool_from_PyBool(obj2) : true; + + self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(begin, orientation); } - + self->py_it.it = self->ve_it; return 0; } -static char ViewEdgeIterator_getCurrentEdge___doc__[] = -".. method:: getCurrentEdge()\n" +PyDoc_STRVAR(ViewEdgeIterator_change_orientation_doc, +".. method:: change_orientation()\n" "\n" -" Returns the current pointed ViewEdge.\n" -"\n" -" :return: The current pointed ViewEdge.\n" -" :rtype: :class:`ViewEdge`\n"; +" Changes the current orientation."); -static PyObject *ViewEdgeIterator_getCurrentEdge( BPy_ViewEdgeIterator *self ) { - ViewEdge *ve = self->ve_it->getCurrentEdge(); - if( ve ) - return BPy_ViewEdge_from_ViewEdge( *ve ); - +static PyObject *ViewEdgeIterator_change_orientation(BPy_ViewEdgeIterator *self) +{ + self->ve_it->changeOrientation(); + Py_RETURN_NONE; } -static char ViewEdgeIterator_setCurrentEdge___doc__[] = -".. method:: setCurrentEdge(edge)\n" -"\n" -" Sets the current pointed ViewEdge.\n" -"\n" -" :arg edge: The current pointed ViewEdge.\n" -" :type edge: :class:`ViewEdge`\n"; - -static PyObject *ViewEdgeIterator_setCurrentEdge( BPy_ViewEdgeIterator *self, PyObject *args ) { - PyObject *py_ve; - - if(!( PyArg_ParseTuple(args, "O!", &ViewEdge_Type, &py_ve) )) - return NULL; +static PyMethodDef BPy_ViewEdgeIterator_methods[] = { + {"change_orientation", (PyCFunction) ViewEdgeIterator_change_orientation, METH_NOARGS, ViewEdgeIterator_change_orientation_doc}, + {NULL, NULL, 0, NULL} +}; - self->ve_it->setCurrentEdge( ((BPy_ViewEdge *) py_ve)->ve ); - - Py_RETURN_NONE; -} +/*----------------------ViewEdgeIterator get/setters ----------------------------*/ -static char ViewEdgeIterator_getBegin___doc__[] = -".. method:: getBegin()\n" -"\n" -" Returns the first ViewEdge used for the iteration.\n" +PyDoc_STRVAR(ViewEdgeIterator_object_doc, +"The ViewEdge object currently pointed by this iterator.\n" "\n" -" :return: The first ViewEdge used for the iteration.\n" -" :rtype: :class:`ViewEdge`\n"; +":type: :class:`ViewEdge`"); + +static PyObject *ViewEdgeIterator_object_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure)) +{ + ViewEdge *ve = self->ve_it->operator*(); + if (ve) + return BPy_ViewEdge_from_ViewEdge(*ve); -static PyObject *ViewEdgeIterator_getBegin( BPy_ViewEdgeIterator *self ) { - ViewEdge *ve = self->ve_it->getBegin(); - if( ve ) - return BPy_ViewEdge_from_ViewEdge( *ve ); - Py_RETURN_NONE; } -static char ViewEdgeIterator_setBegin___doc__[] = -".. method:: setBegin(begin)\n" +PyDoc_STRVAR(ViewEdgeIterator_current_edge_doc, +"The ViewEdge object currently pointed by this iterator.\n" "\n" -" Sets the first ViewEdge used for the iteration.\n" -"\n" -" :arg begin: The first ViewEdge used for the iteration.\n" -" :type begin: :class:`ViewEdge`\n"; +":type: :class:`ViewEdge`"); -static PyObject *ViewEdgeIterator_setBegin( BPy_ViewEdgeIterator *self, PyObject *args ) { - PyObject *py_ve; +static PyObject *ViewEdgeIterator_current_edge_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure)) +{ + ViewEdge *ve = self->ve_it->getCurrentEdge(); + if (ve) + return BPy_ViewEdge_from_ViewEdge(*ve); - if(!( PyArg_ParseTuple(args, "O!", &ViewEdge_Type, &py_ve) )) - return NULL; + Py_RETURN_NONE;} - self->ve_it->setBegin( ((BPy_ViewEdge *) py_ve)->ve ); - - Py_RETURN_NONE; +static int ViewEdgeIterator_current_edge_set(BPy_ViewEdgeIterator *self, PyObject *value, void *UNUSED(closure)) +{ + if (!BPy_ViewEdge_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be a ViewEdge"); + return -1; + } + self->ve_it->setCurrentEdge(((BPy_ViewEdge *)value)->ve); + return 0; } -static char ViewEdgeIterator_getOrientation___doc__[] = -".. method:: getOrientation()\n" -"\n" -" Returns the orientation of the pointed ViewEdge in the iteration.\n" +PyDoc_STRVAR(ViewEdgeIterator_orientation_doc, +"The orientation of the pointed ViewEdge in the iteration.\n" +"If true, the iterator looks for the next ViewEdge among those ViewEdges\n" +"that surround the ending ViewVertex of the \"begin\" ViewEdge. If false,\n" +"the iterator searches over the ViewEdges surrounding the ending ViewVertex\n" +"of the \"begin\" ViewEdge.\n" "\n" -" :return: The orientation of the pointed ViewEdge in the iteration.\n" -" :rtype: bool\n"; +":type: bool"); -static PyObject *ViewEdgeIterator_getOrientation( BPy_ViewEdgeIterator *self ) { - return PyBool_from_bool( self->ve_it->getOrientation() ); +static PyObject *ViewEdgeIterator_orientation_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure)) +{ + return PyBool_from_bool(self->ve_it->getOrientation()); } -static char ViewEdgeIterator_setOrientation___doc__[] = -".. method:: setOrientation(orientation)\n" -"\n" -" Sets the orientation of the pointed ViewEdge in the iteration.\n" -"\n" -" :arg orientation: If true, we'll look for the next ViewEdge among\n" -" the ViewEdges that surround the ending ViewVertex of begin. If\n" -" false, we'll search over the ViewEdges surrounding the ending\n" -" ViewVertex of begin.\n" -" :type orientation: bool\n"; - -static PyObject *ViewEdgeIterator_setOrientation( BPy_ViewEdgeIterator *self, PyObject *args ) { - PyObject *py_b; - - if(!( PyArg_ParseTuple(args, "O", &py_b) )) - return NULL; - - self->ve_it->setOrientation( bool_from_PyBool(py_b) ); - - Py_RETURN_NONE; +static int ViewEdgeIterator_orientation_set(BPy_ViewEdgeIterator *self, PyObject *value, void *UNUSED(closure)) +{ + if (!PyBool_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be a boolean"); + return -1; + } + self->ve_it->setOrientation(bool_from_PyBool(value)); + return 0; } -static char ViewEdgeIterator_changeOrientation___doc__[] = -".. method:: changeOrientation()\n" +PyDoc_STRVAR(ViewEdgeIterator_begin_doc, +"The first ViewEdge used for the iteration.\n" "\n" -" Changes the current orientation.\n"; +":type: :class:`ViewEdge`"); + +static PyObject *ViewEdgeIterator_begin_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure)) +{ + ViewEdge *ve = self->ve_it->getBegin(); + if (ve) + return BPy_ViewEdge_from_ViewEdge(*ve); -static PyObject *ViewEdgeIterator_changeOrientation( BPy_ViewEdgeIterator *self ) { - self->ve_it->changeOrientation(); - Py_RETURN_NONE; } -static char ViewEdgeIterator_getObject___doc__[] = -".. method:: getObject()\n" -"\n" -" Returns the pointed ViewEdge.\n" -"\n" -" :return: The pointed ViewEdge.\n" -" :rtype: :class:`ViewEdge`\n"; - -static PyObject * ViewEdgeIterator_getObject( BPy_ViewEdgeIterator *self) { - - ViewEdge *ve = self->ve_it->operator*(); - if( ve ) - return BPy_ViewEdge_from_ViewEdge( *ve ); - - Py_RETURN_NONE; +static int ViewEdgeIterator_begin_set(BPy_ViewEdgeIterator *self, PyObject *value, void *UNUSED(closure)) +{ + if(!BPy_ViewEdge_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be a ViewEdge"); + return -1; + } + self->ve_it->setBegin(((BPy_ViewEdge *)value)->ve); + return 0; } -/*----------------------ViewEdgeIterator instance definitions ----------------------------*/ -static PyMethodDef BPy_ViewEdgeIterator_methods[] = { - {"getCurrentEdge", ( PyCFunction ) ViewEdgeIterator_getCurrentEdge, METH_NOARGS, ViewEdgeIterator_getCurrentEdge___doc__}, - {"setCurrentEdge", ( PyCFunction ) ViewEdgeIterator_setCurrentEdge, METH_VARARGS, ViewEdgeIterator_setCurrentEdge___doc__}, - {"getBegin", ( PyCFunction ) ViewEdgeIterator_getBegin, METH_NOARGS, ViewEdgeIterator_getBegin___doc__}, - {"setBegin", ( PyCFunction ) ViewEdgeIterator_setBegin, METH_VARARGS, ViewEdgeIterator_setBegin___doc__}, - {"getOrientation", ( PyCFunction ) ViewEdgeIterator_getOrientation, METH_NOARGS, ViewEdgeIterator_getOrientation___doc__}, - {"setOrientation", ( PyCFunction ) ViewEdgeIterator_setOrientation, METH_VARARGS, ViewEdgeIterator_setOrientation___doc__}, - {"changeOrientation", ( PyCFunction ) ViewEdgeIterator_changeOrientation, METH_NOARGS, ViewEdgeIterator_changeOrientation___doc__}, - {"getObject", ( PyCFunction ) ViewEdgeIterator_getObject, METH_NOARGS, ViewEdgeIterator_getObject___doc__}, - {NULL, NULL, 0, NULL} +static PyGetSetDef BPy_ViewEdgeIterator_getseters[] = { + {(char *)"object", (getter)ViewEdgeIterator_object_get, (setter)NULL, (char *)ViewEdgeIterator_object_doc, NULL}, + {(char *)"current_edge", (getter)ViewEdgeIterator_current_edge_get, (setter)ViewEdgeIterator_current_edge_set, (char *)ViewEdgeIterator_current_edge_doc, NULL}, + {(char *)"orientation", (getter)ViewEdgeIterator_orientation_get, (setter)ViewEdgeIterator_orientation_set, (char *)ViewEdgeIterator_orientation_doc, NULL}, + {(char *)"begin", (getter)ViewEdgeIterator_begin_get, (setter)ViewEdgeIterator_begin_set, (char *)ViewEdgeIterator_begin_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_ViewEdgeIterator type definition ------------------------------*/ @@ -239,7 +205,7 @@ PyTypeObject ViewEdgeIterator_Type = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ViewEdgeIterator___doc__, /* tp_doc */ + ViewEdgeIterator_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -248,13 +214,13 @@ PyTypeObject ViewEdgeIterator_Type = { 0, /* tp_iternext */ BPy_ViewEdgeIterator_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + BPy_ViewEdgeIterator_getseters, /* tp_getset */ &Iterator_Type, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc)ViewEdgeIterator___init__, /* tp_init */ + (initproc)ViewEdgeIterator_init, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ }; diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp index 46eb7055217..e3dbb089d49 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp @@ -10,7 +10,7 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- -static char orientedViewEdgeIterator___doc__[] = +PyDoc_STRVAR(orientedViewEdgeIterator_doc, "Class hierarchy: :class:`Iterator` > :class:`orientedViewEdgeIterator`\n" "\n" "Class representing an iterator over oriented ViewEdges around a\n" @@ -27,32 +27,34 @@ static char orientedViewEdgeIterator___doc__[] = " Copy constructor.\n" "\n" " :arg iBrother: An orientedViewEdgeIterator object.\n" -" :type iBrother: :class:`orientedViewEdgeIterator`\n"; +" :type iBrother: :class:`orientedViewEdgeIterator`"); -static int orientedViewEdgeIterator___init__(BPy_orientedViewEdgeIterator *self, PyObject *args ) -{ +static int orientedViewEdgeIterator_init(BPy_orientedViewEdgeIterator *self, PyObject *args) +{ PyObject *obj = 0; - if (!( PyArg_ParseTuple(args, "|O", &obj) )) - return -1; + if (!PyArg_ParseTuple(args, "|O", &obj)) + return -1; - if( !obj ) + if (!obj) self->ove_it = new ViewVertexInternal::orientedViewEdgeIterator(); - else if( BPy_orientedViewEdgeIterator_Check(obj) ) - self->ove_it = new ViewVertexInternal::orientedViewEdgeIterator(*( ((BPy_orientedViewEdgeIterator *) obj)->ove_it )); + else if (BPy_orientedViewEdgeIterator_Check(obj)) + self->ove_it = new ViewVertexInternal::orientedViewEdgeIterator(*(((BPy_orientedViewEdgeIterator *)obj)->ove_it)); else { PyErr_SetString(PyExc_TypeError, "invalid argument"); return -1; } - + self->py_it.it = self->ove_it; self->reversed = 0; - + return 0; } -static PyObject * orientedViewEdgeIterator_iternext( BPy_orientedViewEdgeIterator *self ) { +static PyObject * orientedViewEdgeIterator_iternext(BPy_orientedViewEdgeIterator *self) +{ ViewVertex::directedViewEdge *dve; + if (self->reversed) { if (self->ove_it->isBegin()) { PyErr_SetNone(PyExc_StopIteration); @@ -68,26 +70,31 @@ static PyObject * orientedViewEdgeIterator_iternext( BPy_orientedViewEdgeIterato dve = self->ove_it->operator->(); self->ove_it->increment(); } - return BPy_directedViewEdge_from_directedViewEdge( *dve ); + return BPy_directedViewEdge_from_directedViewEdge(*dve); } -static char orientedViewEdgeIterator_getObject___doc__[] = -".. method:: getObject()\n" -"\n" -" Returns the pointed oriented ViewEdge.\n" +static PyMethodDef BPy_orientedViewEdgeIterator_methods[] = { + {NULL, NULL, 0, NULL} +}; + +/*----------------------orientedViewEdgeIterator get/setters ----------------------------*/ + +PyDoc_STRVAR(orientedViewEdgeIterator_object_doc, +"The oriented ViewEdge (i.e., a tuple of the pointed ViewEdge and a boolean\n" +"value) currently pointed by this iterator. If the boolean value is true,\n" +"the ViewEdge is incoming.\n" "\n" -" :return: A tuple of the pointed ViewEdge and a boolean value. If\n" -" the boolean value is true, the ViewEdge is incoming.\n" -" :rtype: (:class:`directedViewEdge`, bool)\n"; +":type: (:class:`directedViewEdge`, bool)"); + +static PyObject *orientedViewEdgeIterator_object_get(BPy_orientedViewEdgeIterator *self, void *UNUSED(closure)) +{ + return BPy_directedViewEdge_from_directedViewEdge(self->ove_it->operator*()); -static PyObject * orientedViewEdgeIterator_getObject( BPy_orientedViewEdgeIterator *self) { - return BPy_directedViewEdge_from_directedViewEdge( self->ove_it->operator*() ); } -/*----------------------orientedViewEdgeIterator instance definitions ----------------------------*/ -static PyMethodDef BPy_orientedViewEdgeIterator_methods[] = { - {"getObject", ( PyCFunction ) orientedViewEdgeIterator_getObject, METH_NOARGS, orientedViewEdgeIterator_getObject___doc__}, - {NULL, NULL, 0, NULL} +static PyGetSetDef BPy_orientedViewEdgeIterator_getseters[] = { + {(char *)"object", (getter)orientedViewEdgeIterator_object_get, (setter)NULL, (char *)orientedViewEdgeIterator_object_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_orientedViewEdgeIterator type definition ------------------------------*/ @@ -113,7 +120,7 @@ PyTypeObject orientedViewEdgeIterator_Type = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - orientedViewEdgeIterator___doc__, /* tp_doc */ + orientedViewEdgeIterator_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -122,13 +129,13 @@ PyTypeObject orientedViewEdgeIterator_Type = { (iternextfunc)orientedViewEdgeIterator_iternext, /* tp_iternext */ BPy_orientedViewEdgeIterator_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + BPy_orientedViewEdgeIterator_getseters, /* tp_getset */ &Iterator_Type, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc)orientedViewEdgeIterator___init__, /* tp_init */ + (initproc)orientedViewEdgeIterator_init, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ }; |