diff options
Diffstat (limited to 'source/blender/freestyle/intern')
35 files changed, 876 insertions, 871 deletions
diff --git a/source/blender/freestyle/intern/python/BPy_BBox.cpp b/source/blender/freestyle/intern/python/BPy_BBox.cpp index 3f2218110aa..fb17ef2ecd9 100644 --- a/source/blender/freestyle/intern/python/BPy_BBox.cpp +++ b/source/blender/freestyle/intern/python/BPy_BBox.cpp @@ -7,14 +7,14 @@ extern "C" { /////////////////////////////////////////////////////////////////////////////////////////// //-------------------MODULE INITIALIZATION-------------------------------- -int BBox_Init( PyObject *module ) +int BBox_Init(PyObject *module) { if (module == NULL) return -1; - if (PyType_Ready( &BBox_Type ) < 0) + if (PyType_Ready(&BBox_Type) < 0) return -1; - Py_INCREF( &BBox_Type ); + Py_INCREF(&BBox_Type); PyModule_AddObject(module, "BBox", (PyObject *)&BBox_Type); return 0; @@ -23,11 +23,17 @@ int BBox_Init( PyObject *module ) //------------------------INSTANCE METHODS ---------------------------------- PyDoc_STRVAR(BBox_doc, -"Class for representing a bounding box.\n"); +"Class for representing a bounding box.\n" +"\n" +".. method:: __init__()\n" +"\n" +" Default constructor."); static int BBox_init(BPy_BBox *self, PyObject *args, PyObject *kwds) { - if (!PyArg_ParseTuple(args, "")) + static const char *kwlist[] = {NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) return -1; self->bb = new BBox< Vec3r>(); return 0; @@ -44,7 +50,6 @@ static PyObject * BBox_repr(BPy_BBox* self) return PyUnicode_FromFormat("BBox - address: %p", self->bb); } -/*----------------------BBox instance definitions ----------------------------*/ static PyMethodDef BPy_BBox_methods[] = { {NULL, NULL, 0, NULL} }; diff --git a/source/blender/freestyle/intern/python/BPy_Convert.cpp b/source/blender/freestyle/intern/python/BPy_Convert.cpp index 88576ff5954..72056d0d6d5 100644 --- a/source/blender/freestyle/intern/python/BPy_Convert.cpp +++ b/source/blender/freestyle/intern/python/BPy_Convert.cpp @@ -318,6 +318,7 @@ PyObject * BPy_ViewShape_from_ViewShape( ViewShape& vs ) { PyObject *py_vs = ViewShape_Type.tp_new( &ViewShape_Type, 0, 0 ); ((BPy_ViewShape *) py_vs)->vs = &vs; ((BPy_ViewShape *) py_vs)->borrowed = 1; + ((BPy_ViewShape *) py_vs)->py_ss = NULL; return py_vs; } diff --git a/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp b/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp index 8d651c702b0..9664fa56b8d 100644 --- a/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp +++ b/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp @@ -6,19 +6,17 @@ extern "C" { #endif -#include "BLI_math.h" - /////////////////////////////////////////////////////////////////////////////////////////// //-------------------MODULE INITIALIZATION-------------------------------- -int FrsMaterial_Init( PyObject *module ) +int FrsMaterial_Init(PyObject *module) { if (module == NULL) return -1; - if (PyType_Ready( &FrsMaterial_Type ) < 0) + if (PyType_Ready(&FrsMaterial_Type) < 0) return -1; - Py_INCREF( &FrsMaterial_Type ); + Py_INCREF(&FrsMaterial_Type); PyModule_AddObject(module, "Material", (PyObject *)&FrsMaterial_Type); FrsMaterial_mathutils_register_callback(); @@ -35,59 +33,67 @@ PyDoc_STRVAR(FrsMaterial_doc, "\n" " Default constructor.\n" "\n" -".. method:: __init__(m)\n" +".. method:: __init__(brother)\n" "\n" " Copy constructor.\n" "\n" -" :arg m: A Material object.\n" -" :type m: :class:`Material`\n" +" :arg brother: A Material object.\n" +" :type brother: :class:`Material`\n" "\n" -".. method:: __init__(iDiffuse, iAmbiant, iSpecular, iEmission, iShininess)\n" +".. method:: __init__(diffuse, ambient, specular, emission, shininess)\n" "\n" -" Builds a Material from its diffuse, ambiant, specular, emissive\n" +" Builds a Material from its diffuse, ambient, specular, emissive\n" " colors and a shininess coefficient.\n" "\n" -" :arg iDiffuse: The diffuse color.\n" -" :type iDiffuse: :class:`mathutils.Vector`, list or tuple of 4 float values\n" -" :arg iAmbiant: The ambiant color.\n" -" :type iAmbiant: :class:`mathutils.Vector`, list or tuple of 4 float values\n" -" :arg iSpecular: The specular color.\n" -" :type iSpecular: :class:`mathutils.Vector`, list or tuple of 4 float values\n" -" :arg iEmission: The emissive color.\n" -" :type iEmission: :class:`mathutils.Vector`, list or tuple of 4 float values\n" -" :arg iShininess: The shininess coefficient.\n" -" :type iShininess: :class:float"); +" :arg diffuse: The diffuse color.\n" +" :type diffuse: :class:`mathutils.Vector`, list or tuple of 4 float values\n" +" :arg ambient: The ambient color.\n" +" :type ambient: :class:`mathutils.Vector`, list or tuple of 4 float values\n" +" :arg specular: The specular color.\n" +" :type specular: :class:`mathutils.Vector`, list or tuple of 4 float values\n" +" :arg emission: The emissive color.\n" +" :type emission: :class:`mathutils.Vector`, list or tuple of 4 float values\n" +" :arg shininess: The shininess coefficient.\n" +" :type shininess: :class:float"); + +static int convert_v4(PyObject *obj, void *v) +{ + return float_array_from_PyObject(obj, (float *)v, 4); +} static int FrsMaterial_init(BPy_FrsMaterial *self, PyObject *args, PyObject *kwds) { - PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0; - float f1[4], f2[4], f3[4], f4[4], f5 = 0.; - - if (!PyArg_ParseTuple(args, "|OOOOf", &obj1, &obj2, &obj3, &obj4, &f5)) - return -1; - - if (!obj1) { - self->m = new FrsMaterial(); - - } else if (BPy_FrsMaterial_Check(obj1) && !obj2) { - FrsMaterial *m = ((BPy_FrsMaterial *) obj1)->m; - if (!m) { - PyErr_SetString(PyExc_RuntimeError, "invalid FrsMaterial object"); - return -1; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"diffuse", "ambient", "specular", "emission", "shininess", NULL}; + PyObject *brother = 0; + float diffuse[4], ambient[4], specular[4], emission[4], shininess; + + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FrsMaterial_Type, &brother)) { + if (!brother) { + self->m = new FrsMaterial(); + } else { + FrsMaterial *m = ((BPy_FrsMaterial *)brother)->m; + if (!m) { + PyErr_SetString(PyExc_RuntimeError, "invalid Material object"); + return -1; + } + self->m = new FrsMaterial(*m); } - self->m = new FrsMaterial(*m); - - } else if (float_array_from_PyObject(obj1, f1, 4) && obj2 && - float_array_from_PyObject(obj2, f2, 4) && obj3 && - float_array_from_PyObject(obj3, f3, 4) && obj4 && - float_array_from_PyObject(obj4, f4, 4)) { - self->m = new FrsMaterial(f1, f2, f3, f4, f5); - - } else { + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O&O&O&O&f", (char **)kwlist_2, + convert_v4, diffuse, + convert_v4, ambient, + convert_v4, specular, + convert_v4, emission, + &shininess)) + { + self->m = new FrsMaterial(diffuse, ambient, specular, emission, shininess); + } + else { PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; } - return 0; } @@ -97,7 +103,6 @@ static void FrsMaterial_dealloc(BPy_FrsMaterial* self) Py_TYPE(self)->tp_free((PyObject*)self); } - static PyObject * FrsMaterial_repr(BPy_FrsMaterial* self) { return PyUnicode_FromFormat("Material - address: %p", self->m); diff --git a/source/blender/freestyle/intern/python/BPy_Id.cpp b/source/blender/freestyle/intern/python/BPy_Id.cpp index da9c2b9ca15..5d56903d854 100644 --- a/source/blender/freestyle/intern/python/BPy_Id.cpp +++ b/source/blender/freestyle/intern/python/BPy_Id.cpp @@ -25,43 +25,43 @@ int Id_Init(PyObject *module) //------------------------INSTANCE METHODS ---------------------------------- PyDoc_STRVAR(Id_doc, -".. method:: __init__()\n" +"Class for representing an object Id.\n" "\n" -" Default constructor.\n" +".. method:: __init__(first=0, second=0)\n" "\n" -".. method:: __init__(iBrother)\n" +" Build the Id from two numbers.\n" "\n" -" Copy constructor.\n" -"\n" -" :arg iBrother: An Id object.\n" -" :type iBrother: :class:`Id`\n" -"\n" -".. method:: __init__(iFirst)\n" +" :arg first: The first number.\n" +" :type first: int\n" +" :arg iSecond: The second number.\n" +" :type iSecond: int\n" "\n" -" Builds an Id from an integer. The second number is set to 0.\n" +".. method:: __init__(brother)\n" "\n" -" :arg iFirst: The first Id number.\n" -" :type iFirst: int\n" -"\n" -".. method:: __init__(iFirst, iSecond)\n" -"\n" -" Builds the Id from the two numbers.\n" +" Copy constructor.\n" "\n" -" :arg iFirst: The first Id number.\n" -" :type iFirst: int\n" -" :arg iSecond: The second Id number.\n" -" :type iSecond: int\n"); +" :arg brother: An Id object.\n" +" :type brother: :class:`Id`"); static int Id_init(BPy_Id *self, PyObject *args, PyObject *kwds) { + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"first", "second", NULL}; + PyObject *brother; int first = 0, second = 0; - static const char *kwlist[] = {"first", "second", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ii", (char**)kwlist, &first, &second)) + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_1, &Id_Type, &brother)) { + self->id = new Id(*(((BPy_Id *)brother)->id)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "|ii", (char**)kwlist_2, &first, &second)) + { + self->id = new Id(first, second); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; - - self->id = new Id(first, second); - + } return 0; } diff --git a/source/blender/freestyle/intern/python/BPy_Interface0D.cpp b/source/blender/freestyle/intern/python/BPy_Interface0D.cpp index c7c46d0404e..b455ba20cf9 100644 --- a/source/blender/freestyle/intern/python/BPy_Interface0D.cpp +++ b/source/blender/freestyle/intern/python/BPy_Interface0D.cpp @@ -74,7 +74,9 @@ PyDoc_STRVAR(Interface0D_doc, static int Interface0D_init(BPy_Interface0D *self, PyObject *args, PyObject *kwds) { - if (!PyArg_ParseTuple(args, "")) + static const char *kwlist[] = {NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) return -1; self->if0D = new Interface0D(); self->borrowed = 0; diff --git a/source/blender/freestyle/intern/python/BPy_Interface1D.cpp b/source/blender/freestyle/intern/python/BPy_Interface1D.cpp index f6046b4cad3..c0c5943018b 100644 --- a/source/blender/freestyle/intern/python/BPy_Interface1D.cpp +++ b/source/blender/freestyle/intern/python/BPy_Interface1D.cpp @@ -84,7 +84,9 @@ PyDoc_STRVAR(Interface1D_doc, static int Interface1D_init(BPy_Interface1D *self, PyObject *args, PyObject *kwds) { - if (!PyArg_ParseTuple(args, "")) + static const char *kwlist[] = {NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) return -1; self->if1D = new Interface1D(); self->borrowed = 0; diff --git a/source/blender/freestyle/intern/python/BPy_Iterator.cpp b/source/blender/freestyle/intern/python/BPy_Iterator.cpp index 0e2f4b3fd43..a8729f61760 100644 --- a/source/blender/freestyle/intern/python/BPy_Iterator.cpp +++ b/source/blender/freestyle/intern/python/BPy_Iterator.cpp @@ -85,7 +85,21 @@ int Iterator_Init(PyObject *module) //------------------------INSTANCE METHODS ---------------------------------- PyDoc_STRVAR(Iterator_doc, -"Base class to define iterators."); +"Base class to define iterators.\n" +"\n" +".. method:: __init__()\n" +"\n" +" Default constructor."); + +static int Iterator_init(BPy_Iterator *self, PyObject *args, PyObject *kwds) +{ + static const char *kwlist[] = {NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->it = new Iterator(); + return 0; +} static void Iterator_dealloc(BPy_Iterator* self) { @@ -212,7 +226,7 @@ PyTypeObject Iterator_Type = { 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - 0, /* tp_init */ + (initproc)Iterator_init, /* tp_init */ 0, /* tp_alloc */ PyType_GenericNew, /* tp_new */ }; diff --git a/source/blender/freestyle/intern/python/BPy_SShape.cpp b/source/blender/freestyle/intern/python/BPy_SShape.cpp index 763e88e2ce1..759c1fd2234 100644 --- a/source/blender/freestyle/intern/python/BPy_SShape.cpp +++ b/source/blender/freestyle/intern/python/BPy_SShape.cpp @@ -20,7 +20,7 @@ int SShape_Init(PyObject *module) if (PyType_Ready(&SShape_Type) < 0) return -1; - Py_INCREF( &SShape_Type ); + Py_INCREF(&SShape_Type); PyModule_AddObject(module, "SShape", (PyObject *)&SShape_Type); return 0; @@ -36,27 +36,25 @@ PyDoc_STRVAR(SShape_doc, "\n" " Default constructor.\n" "\n" -".. method:: __init__(iBrother)\n" +".. method:: __init__(brother)\n" "\n" " Copy constructor.\n" "\n" -" :arg iBrother: An SShape object.\n" -" :type iBrother: :class:`SShape`"); +" :arg brother: An SShape object.\n" +" :type brother: :class:`SShape`"); static int SShape_init(BPy_SShape *self, PyObject *args, PyObject *kwds) { - PyObject *obj = NULL; + static const char *kwlist[] = {"brother", NULL}; + PyObject *brother = 0; - if (!PyArg_ParseTuple(args, "|O!", &SShape_Type, &obj)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &SShape_Type, &brother)) return -1; - - if (!obj) { + if (!brother) self->ss = new SShape(); - } else { - self->ss = new SShape(*(((BPy_SShape *)obj)->ss)); - } + else + self->ss = new SShape(*(((BPy_SShape *)brother)->ss)); self->borrowed = 0; - return 0; } diff --git a/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp b/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp index cdc381ee328..6262eb4f5d7 100644 --- a/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp +++ b/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp @@ -9,14 +9,14 @@ extern "C" { /////////////////////////////////////////////////////////////////////////////////////////// //-------------------MODULE INITIALIZATION-------------------------------- -int StrokeAttribute_Init( PyObject *module ) +int StrokeAttribute_Init(PyObject *module) { - if( module == NULL ) + if (module == NULL) return -1; - if( PyType_Ready( &StrokeAttribute_Type ) < 0 ) + if (PyType_Ready(&StrokeAttribute_Type) < 0) return -1; - Py_INCREF( &StrokeAttribute_Type ); + Py_INCREF(&StrokeAttribute_Type); PyModule_AddObject(module, "StrokeAttribute", (PyObject *)&StrokeAttribute_Type); StrokeAttribute_mathutils_register_callback(); @@ -34,94 +34,84 @@ PyDoc_STRVAR(StrokeAttribute_doc, "\n" " Default constructor.\n" "\n" -".. method:: __init__(iBrother)\n" +".. method:: __init__(brother)\n" "\n" " Copy constructor.\n" "\n" -" :arg iBrother: A StrokeAttribute object.\n" -" :type iBrother: :class:`StrokeAttribute`\n" +" :arg brother: A StrokeAttribute object.\n" +" :type brother: :class:`StrokeAttribute`\n" "\n" -".. method:: __init__(iRColor, iGColor, iBColor, iAlpha, iRThickness, iLThickness)\n" +".. method:: __init__(red, green, blue, alpha, thickness_right, thickness_left)\n" "\n" -" Builds a stroke vertex attribute from a set of parameters.\n" +" Build a stroke vertex attribute from a set of parameters.\n" "\n" -" :arg iRColor: Red component of a stroke color.\n" -" :type iRColor: float\n" -" :arg iGColor: Green component of a stroke color.\n" -" :type iGColor: float\n" -" :arg iBColor: Blue component of a stroke color.\n" -" :type iBColor: float\n" -" :arg iAlpha: Alpha component of a stroke color.\n" -" :type iAlpha: float\n" -" :arg iRThickness: Stroke thickness on the right.\n" -" :type iRThickness: float\n" -" :arg iLThickness: Stroke thickness on the left.\n" -" :type iLThickness: float\n" +" :arg red: Red component of a stroke color.\n" +" :type red: float\n" +" :arg green: Green component of a stroke color.\n" +" :type green: float\n" +" :arg blue: Blue component of a stroke color.\n" +" :type blue: float\n" +" :arg alpha: Alpha component of a stroke color.\n" +" :type alpha: float\n" +" :arg thickness_right: Stroke thickness on the right.\n" +" :type thickness_right: float\n" +" :arg thickness_left: Stroke thickness on the left.\n" +" :type thickness_left: float\n" "\n" -".. method:: __init__(a1, a2, t)\n" +".. method:: __init__(attribute1, attribute2, t)\n" "\n" -" Interpolation constructor. Builds a StrokeAttribute from two\n" +" Interpolation constructor. Build a StrokeAttribute from two\n" " StrokeAttribute objects and an interpolation parameter.\n" "\n" -" :arg a1: The first StrokeAttribute object.\n" -" :type a1: :class:`StrokeAttribute`\n" -" :arg a2: The second StrokeAttribute object.\n" -" :type a2: :class:`StrokeAttribute`\n" -" :arg t: The interpolation parameter.\n" +" :arg attribute1: The first StrokeAttribute object.\n" +" :type attribute1: :class:`StrokeAttribute`\n" +" :arg attribute2: The second StrokeAttribute object.\n" +" :type attribute2: :class:`StrokeAttribute`\n" +" :arg t: The interpolation parameter (0 <= t <= 1).\n" " :type t: float\n"); -static int StrokeAttribute___init__(BPy_StrokeAttribute *self, PyObject *args, PyObject *kwds) +static int StrokeAttribute_init(BPy_StrokeAttribute *self, PyObject *args, PyObject *kwds) { - - PyObject *obj1 = 0, *obj2 = 0 , *obj3 = 0, *obj4 = 0, *obj5 = 0 , *obj6 = 0; - - if (! PyArg_ParseTuple(args, "|OOOOOO", &obj1, &obj2, &obj3, &obj4, &obj5, &obj6) ) - return -1; - - if ( !obj1 ) { - - self->sa = new StrokeAttribute(); - - } else if ( BPy_StrokeAttribute_Check(obj1) && !obj2 ) { - - self->sa = new StrokeAttribute( *( ((BPy_StrokeAttribute *) obj1)->sa ) ); - - } else if ( BPy_StrokeAttribute_Check(obj1) && - BPy_StrokeAttribute_Check(obj2) && - PyFloat_Check(obj3) && !obj4 ) { - - self->sa = new StrokeAttribute( *( ((BPy_StrokeAttribute *) obj1)->sa ), - *( ((BPy_StrokeAttribute *) obj2)->sa ), - PyFloat_AsDouble( obj3 ) ); - - } else if ( obj6 ) { - - self->sa = new StrokeAttribute( PyFloat_AsDouble( obj1 ), - PyFloat_AsDouble( obj2 ), - PyFloat_AsDouble( obj3 ), - PyFloat_AsDouble( obj4 ), - PyFloat_AsDouble( obj5 ), - PyFloat_AsDouble( obj6 ) ); - - } else { - PyErr_SetString(PyExc_TypeError, "invalid arguments"); + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"attribute1", "attribute2", "t", NULL}; + static const char *kwlist_3[] = {"red", "green", "blue", "alpha", "thickness_right", "thickness_left", NULL}; + PyObject *obj1 = 0, *obj2 = 0; + float red, green, blue, alpha, thickness_right, thickness_left, t; + + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &StrokeAttribute_Type, &obj1)) { + if (!obj1) + self->sa = new StrokeAttribute(); + else + self->sa = new StrokeAttribute(*(((BPy_StrokeAttribute *)obj1)->sa)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O!O!f", (char **)kwlist_2, + &StrokeAttribute_Type, &obj1, &StrokeAttribute_Type, &obj2, &t)) + { + self->sa = new StrokeAttribute(*(((BPy_StrokeAttribute *)obj1)->sa), *(((BPy_StrokeAttribute *)obj2)->sa), t); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "ffffff", (char **)kwlist_3, + &red, &green, &blue, &alpha, &thickness_right, &thickness_left)) + { + self->sa = new StrokeAttribute(red, green, blue, alpha, thickness_right, thickness_left); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; } - self->borrowed = 0; - return 0; - } -static void StrokeAttribute___dealloc__(BPy_StrokeAttribute* self) +static void StrokeAttribute_dealloc(BPy_StrokeAttribute* self) { - if( self->sa && !self->borrowed ) + if (self->sa && !self->borrowed) delete self->sa; - Py_TYPE(self)->tp_free((PyObject*)self); + Py_TYPE(self)->tp_free((PyObject*)self); } -static PyObject * StrokeAttribute___repr__(BPy_StrokeAttribute* self) +static PyObject * StrokeAttribute_repr(BPy_StrokeAttribute* self) { stringstream repr("StrokeAttribute:"); repr << " r: " << self->sa->getColorR() @@ -131,7 +121,7 @@ static PyObject * StrokeAttribute___repr__(BPy_StrokeAttribute* self) << " - R: " << self->sa->getThicknessR() << " L: " << self->sa->getThicknessL(); - return PyUnicode_FromString( repr.str().c_str() ); + return PyUnicode_FromString(repr.str().c_str()); } PyDoc_STRVAR(StrokeAttribute_get_attribute_real_doc, @@ -144,14 +134,15 @@ PyDoc_STRVAR(StrokeAttribute_get_attribute_real_doc, " :return: The attribute value.\n" " :rtype: float\n"); -static PyObject *StrokeAttribute_get_attribute_real( BPy_StrokeAttribute *self, PyObject *args ) { +static PyObject *StrokeAttribute_get_attribute_real(BPy_StrokeAttribute *self, PyObject *args) +{ char *attr; - if(!( PyArg_ParseTuple(args, "s", &attr) )) + if(!(PyArg_ParseTuple(args, "s", &attr))) return NULL; - double a = self->sa->getAttributeReal( attr ); - return PyFloat_FromDouble( a ); + double a = self->sa->getAttributeReal(attr); + return PyFloat_FromDouble(a); } PyDoc_STRVAR(StrokeAttribute_get_attribute_vec2_doc, @@ -164,14 +155,15 @@ PyDoc_STRVAR(StrokeAttribute_get_attribute_vec2_doc, " :return: The attribute value.\n" " :rtype: :class:`mathutils.Vector`\n"); -static PyObject *StrokeAttribute_get_attribute_vec2( BPy_StrokeAttribute *self, PyObject *args ) { +static PyObject *StrokeAttribute_get_attribute_vec2(BPy_StrokeAttribute *self, PyObject *args) +{ char *attr; - if(!( PyArg_ParseTuple(args, "s", &attr) )) + if(!(PyArg_ParseTuple(args, "s", &attr))) return NULL; - Vec2f a = self->sa->getAttributeVec2f( attr ); - return Vector_from_Vec2f( a ); + Vec2f a = self->sa->getAttributeVec2f(attr); + return Vector_from_Vec2f(a); } PyDoc_STRVAR(StrokeAttribute_get_attribute_vec3_doc, @@ -184,14 +176,15 @@ PyDoc_STRVAR(StrokeAttribute_get_attribute_vec3_doc, " :return: The attribute value.\n" " :rtype: :class:`mathutils.Vector`\n"); -static PyObject *StrokeAttribute_get_attribute_vec3( BPy_StrokeAttribute *self, PyObject *args ) { +static PyObject *StrokeAttribute_get_attribute_vec3(BPy_StrokeAttribute *self, PyObject *args) +{ char *attr; - if(!( PyArg_ParseTuple(args, "s", &attr) )) + if(!(PyArg_ParseTuple(args, "s", &attr))) return NULL; - Vec3f a = self->sa->getAttributeVec3f( attr ); - return Vector_from_Vec3f( a ); + Vec3f a = self->sa->getAttributeVec3f(attr); + return Vector_from_Vec3f(a); } PyDoc_STRVAR(StrokeAttribute_has_attribute_real_doc, @@ -204,13 +197,14 @@ PyDoc_STRVAR(StrokeAttribute_has_attribute_real_doc, " :return: True if the attribute is availbale.\n" " :rtype: bool\n"); -static PyObject *StrokeAttribute_has_attribute_real( BPy_StrokeAttribute *self, PyObject *args ) { +static PyObject *StrokeAttribute_has_attribute_real(BPy_StrokeAttribute *self, PyObject *args) +{ char *attr; - if(!( PyArg_ParseTuple(args, "s", &attr) )) + if(!(PyArg_ParseTuple(args, "s", &attr))) return NULL; - return PyBool_from_bool( self->sa->isAttributeAvailableReal( attr ) ); + return PyBool_from_bool(self->sa->isAttributeAvailableReal(attr)); } PyDoc_STRVAR(StrokeAttribute_has_attribute_vec2_doc, @@ -224,13 +218,14 @@ PyDoc_STRVAR(StrokeAttribute_has_attribute_vec2_doc, " :return: True if the attribute is availbale.\n" " :rtype: bool\n"); -static PyObject *StrokeAttribute_has_attribute_vec2( BPy_StrokeAttribute *self, PyObject *args ) { +static PyObject *StrokeAttribute_has_attribute_vec2(BPy_StrokeAttribute *self, PyObject *args) +{ char *attr; - if(!( PyArg_ParseTuple(args, "s", &attr) )) + if(!(PyArg_ParseTuple(args, "s", &attr))) return NULL; - return PyBool_from_bool( self->sa->isAttributeAvailableVec2f( attr ) ); + return PyBool_from_bool(self->sa->isAttributeAvailableVec2f(attr)); } PyDoc_STRVAR(StrokeAttribute_has_attribute_vec3_doc, @@ -244,13 +239,14 @@ PyDoc_STRVAR(StrokeAttribute_has_attribute_vec3_doc, " :return: True if the attribute is availbale.\n" " :rtype: bool\n"); -static PyObject *StrokeAttribute_has_attribute_vec3( BPy_StrokeAttribute *self, PyObject *args ) { +static PyObject *StrokeAttribute_has_attribute_vec3(BPy_StrokeAttribute *self, PyObject *args) +{ char *attr; - if(!( PyArg_ParseTuple(args, "s", &attr) )) + if(!(PyArg_ParseTuple(args, "s", &attr))) return NULL; - return PyBool_from_bool( self->sa->isAttributeAvailableVec3f( attr ) ); + return PyBool_from_bool(self->sa->isAttributeAvailableVec3f(attr)); } PyDoc_STRVAR(StrokeAttribute_set_attribute_real_doc, @@ -265,14 +261,15 @@ PyDoc_STRVAR(StrokeAttribute_set_attribute_real_doc, " :arg att: The attribute value.\n" " :type att: float\n"); -static PyObject * StrokeAttribute_set_attribute_real( BPy_StrokeAttribute *self, PyObject *args ) { +static PyObject * StrokeAttribute_set_attribute_real(BPy_StrokeAttribute *self, PyObject *args) +{ char *s = 0; double d = 0; - if(!( PyArg_ParseTuple(args, "sd", &s, &d) )) + if(!(PyArg_ParseTuple(args, "sd", &s, &d))) return NULL; - self->sa->setAttributeReal( s, d ); + self->sa->setAttributeReal(s, d); Py_RETURN_NONE; } @@ -288,18 +285,19 @@ PyDoc_STRVAR(StrokeAttribute_set_attribute_vec2_doc, " :arg att: The attribute value.\n" " :type att: :class:`mathutils.Vector`, list or tuple of 2 real numbers\n"); -static PyObject * StrokeAttribute_set_attribute_vec2( BPy_StrokeAttribute *self, PyObject *args ) { +static PyObject * StrokeAttribute_set_attribute_vec2(BPy_StrokeAttribute *self, PyObject *args) +{ char *s; PyObject *obj = 0; - if(!( PyArg_ParseTuple(args, "sO", &s, &obj) )) + if(!(PyArg_ParseTuple(args, "sO", &s, &obj))) return NULL; Vec2f *v = Vec2f_ptr_from_PyObject(obj); - if( !v ) { + if (!v) { PyErr_SetString(PyExc_TypeError, "argument 2 must be a 2D vector (either a list of 2 elements or Vector)"); return NULL; } - self->sa->setAttributeVec2f( s, *v ); + self->sa->setAttributeVec2f(s, *v); delete v; Py_RETURN_NONE; @@ -317,18 +315,19 @@ PyDoc_STRVAR(StrokeAttribute_set_attribute_vec3_doc, " :arg att: The attribute value.\n" " :type att: :class:`mathutils.Vector`, list or tuple of 3 real numbers\n"); -static PyObject * StrokeAttribute_set_attribute_vec3( BPy_StrokeAttribute *self, PyObject *args ) { +static PyObject * StrokeAttribute_set_attribute_vec3(BPy_StrokeAttribute *self, PyObject *args) +{ char *s; PyObject *obj = 0; - if(!( PyArg_ParseTuple(args, "sO", &s, &obj) )) + if(!(PyArg_ParseTuple(args, "sO", &s, &obj))) return NULL; Vec3f *v = Vec3f_ptr_from_PyObject(obj); - if( !v ) { + if (!v) { PyErr_SetString(PyExc_TypeError, "argument 2 must be a 3D vector (either a list of 3 elements or Vector)"); return NULL; } - self->sa->setAttributeVec3f( s, *v ); + self->sa->setAttributeVec3f(s, *v); delete v; Py_RETURN_NONE; @@ -336,15 +335,15 @@ static PyObject * StrokeAttribute_set_attribute_vec3( BPy_StrokeAttribute *self, /*----------------------StrokeAttribute instance definitions ----------------------------*/ static PyMethodDef BPy_StrokeAttribute_methods[] = { - {"get_attribute_real", ( PyCFunction ) StrokeAttribute_get_attribute_real, METH_VARARGS, StrokeAttribute_get_attribute_real_doc}, - {"get_attribute_vec2", ( PyCFunction ) StrokeAttribute_get_attribute_vec2, METH_VARARGS, StrokeAttribute_get_attribute_vec2_doc}, - {"get_attribute_vec3", ( PyCFunction ) StrokeAttribute_get_attribute_vec3, METH_VARARGS, StrokeAttribute_get_attribute_vec3_doc}, - {"has_attribute_real", ( PyCFunction ) StrokeAttribute_has_attribute_real, METH_VARARGS, StrokeAttribute_has_attribute_real_doc}, - {"has_attribute_vec2", ( PyCFunction ) StrokeAttribute_has_attribute_vec2, METH_VARARGS, StrokeAttribute_has_attribute_vec2_doc}, - {"has_attribute_vec3", ( PyCFunction ) StrokeAttribute_has_attribute_vec3, METH_VARARGS, StrokeAttribute_has_attribute_vec3_doc}, - {"set_attribute_real", ( PyCFunction ) StrokeAttribute_set_attribute_real, METH_VARARGS, StrokeAttribute_set_attribute_real_doc}, - {"set_attribute_vec2", ( PyCFunction ) StrokeAttribute_set_attribute_vec2, METH_VARARGS, StrokeAttribute_set_attribute_vec2_doc}, - {"set_attribute_vec3", ( PyCFunction ) StrokeAttribute_set_attribute_vec3, METH_VARARGS, StrokeAttribute_set_attribute_vec3_doc}, + {"get_attribute_real", (PyCFunction) StrokeAttribute_get_attribute_real, METH_VARARGS, StrokeAttribute_get_attribute_real_doc}, + {"get_attribute_vec2", (PyCFunction) StrokeAttribute_get_attribute_vec2, METH_VARARGS, StrokeAttribute_get_attribute_vec2_doc}, + {"get_attribute_vec3", (PyCFunction) StrokeAttribute_get_attribute_vec3, METH_VARARGS, StrokeAttribute_get_attribute_vec3_doc}, + {"has_attribute_real", (PyCFunction) StrokeAttribute_has_attribute_real, METH_VARARGS, StrokeAttribute_has_attribute_real_doc}, + {"has_attribute_vec2", (PyCFunction) StrokeAttribute_has_attribute_vec2, METH_VARARGS, StrokeAttribute_has_attribute_vec2_doc}, + {"has_attribute_vec3", (PyCFunction) StrokeAttribute_has_attribute_vec3, METH_VARARGS, StrokeAttribute_has_attribute_vec3_doc}, + {"set_attribute_real", (PyCFunction) StrokeAttribute_set_attribute_real, METH_VARARGS, StrokeAttribute_set_attribute_real_doc}, + {"set_attribute_vec2", (PyCFunction) StrokeAttribute_set_attribute_vec2, METH_VARARGS, StrokeAttribute_set_attribute_vec2_doc}, + {"set_attribute_vec3", (PyCFunction) StrokeAttribute_set_attribute_vec3, METH_VARARGS, StrokeAttribute_set_attribute_vec3_doc}, {NULL, NULL, 0, NULL} }; @@ -565,12 +564,12 @@ PyTypeObject StrokeAttribute_Type = { "StrokeAttribute", /* tp_name */ sizeof(BPy_StrokeAttribute), /* tp_basicsize */ 0, /* tp_itemsize */ - (destructor)StrokeAttribute___dealloc__, /* tp_dealloc */ + (destructor)StrokeAttribute_dealloc, /* tp_dealloc */ 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_reserved */ - (reprfunc)StrokeAttribute___repr__, /* tp_repr */ + (reprfunc)StrokeAttribute_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ @@ -596,7 +595,7 @@ PyTypeObject StrokeAttribute_Type = { 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc)StrokeAttribute___init__, /* tp_init */ + (initproc)StrokeAttribute_init, /* tp_init */ 0, /* tp_alloc */ PyType_GenericNew, /* tp_new */ }; @@ -606,4 +605,3 @@ PyTypeObject StrokeAttribute_Type = { #ifdef __cplusplus } #endif - diff --git a/source/blender/freestyle/intern/python/BPy_ViewMap.cpp b/source/blender/freestyle/intern/python/BPy_ViewMap.cpp index 985e6408e1b..a8ba9ce8084 100644 --- a/source/blender/freestyle/intern/python/BPy_ViewMap.cpp +++ b/source/blender/freestyle/intern/python/BPy_ViewMap.cpp @@ -36,6 +36,10 @@ PyDoc_STRVAR(ViewMap_doc, static int ViewMap_init(BPy_ViewMap *self, PyObject *args, PyObject *kwds) { + static const char *kwlist[] = {NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; self->vm = new ViewMap(); return 0; } diff --git a/source/blender/freestyle/intern/python/BPy_ViewShape.cpp b/source/blender/freestyle/intern/python/BPy_ViewShape.cpp index 95e17251194..e33e6c2db38 100644 --- a/source/blender/freestyle/intern/python/BPy_ViewShape.cpp +++ b/source/blender/freestyle/intern/python/BPy_ViewShape.cpp @@ -36,47 +36,57 @@ PyDoc_STRVAR(ViewShape_doc, "\n" " Default constructor.\n" "\n" -".. method:: __init__(iBrother)\n" +".. method:: __init__(brother)\n" "\n" " Copy constructor.\n" "\n" -" :arg iBrother: A ViewShape object.\n" -" :type iBrother: :class:`ViewShape`\n" +" :arg brother: A ViewShape object.\n" +" :type brother: :class:`ViewShape`\n" "\n" -".. method:: __init__(iSShape)\n" +".. method:: __init__(sshape)\n" "\n" " Builds a ViewShape from an SShape.\n" "\n" -" :arg iSShape: An SShape object.\n" -" :type iSShape: :class:`SShape`"); +" :arg sshape: An SShape object.\n" +" :type sshape: :class:`SShape`"); static int ViewShape_init(BPy_ViewShape *self, PyObject *args, PyObject *kwds) { - PyObject *obj; - - if (!PyArg_ParseTuple(args, "|O", &obj)) - return -1; - - if (!obj) { - self->vs = new ViewShape(); - - } else if (BPy_SShape_Check(obj)) { - self->vs = new ViewShape(((BPy_SShape *)obj)->ss); - - } else if (BPy_ViewShape_Check(obj)) { - self->vs = new ViewShape(*(((BPy_ViewShape *)obj)->vs)); - - } else { - PyErr_SetString(PyExc_TypeError, "invalid argument"); + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"sshape", NULL}; + PyObject *obj = 0; + + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &ViewShape_Type, &obj)) { + if (!obj) { + self->vs = new ViewShape(); + self->py_ss = NULL; + } else { + self->vs = new ViewShape(*(((BPy_ViewShape *)obj)->vs)); + self->py_ss = ((BPy_ViewShape *)obj)->py_ss; + } + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_2, &SShape_Type, &obj)) + { + BPy_SShape *py_ss = (BPy_SShape *)obj; + self->vs = new ViewShape(py_ss->ss); + self->py_ss = (!py_ss->borrowed) ? py_ss : NULL; + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; } self->borrowed = 0; - + Py_XINCREF(self->py_ss); return 0; } static void ViewShape_dealloc(BPy_ViewShape *self) { + if (self->py_ss) { + self->vs->setSShape((SShape *)0); + Py_DECREF(self->py_ss); + } if (self->vs && !self->borrowed) delete self->vs; Py_TYPE(self)->tp_free((PyObject*)self); @@ -140,7 +150,10 @@ PyDoc_STRVAR(ViewShape_sshape_doc, static PyObject *ViewShape_sshape_get(BPy_ViewShape *self, void *UNUSED(closure)) { - return BPy_SShape_from_SShape(*(self->vs->sshape())); + SShape *ss = self->vs->sshape(); + if (!ss) + Py_RETURN_NONE; + return BPy_SShape_from_SShape(*ss); } static int ViewShape_sshape_set(BPy_ViewShape *self, PyObject *value, void *UNUSED(closure)) @@ -149,7 +162,14 @@ static int ViewShape_sshape_set(BPy_ViewShape *self, PyObject *value, void *UNUS PyErr_SetString(PyExc_TypeError, "value must be an SShape"); return -1; } - self->vs->setSShape(((BPy_SShape *)value)->ss); + BPy_SShape *py_ss = (BPy_SShape *)value; + self->vs->setSShape(py_ss->ss); + if (self->py_ss) + Py_DECREF(self->py_ss); + if (!py_ss->borrowed) { + self->py_ss = py_ss; + Py_INCREF(self->py_ss); + } return 0; } diff --git a/source/blender/freestyle/intern/python/BPy_ViewShape.h b/source/blender/freestyle/intern/python/BPy_ViewShape.h index 1850ec8f13a..092ba677dc1 100644 --- a/source/blender/freestyle/intern/python/BPy_ViewShape.h +++ b/source/blender/freestyle/intern/python/BPy_ViewShape.h @@ -5,6 +5,8 @@ #include "../view_map/ViewMap.h" +#include "BPy_SShape.h" + #ifdef __cplusplus extern "C" { #endif @@ -20,6 +22,7 @@ typedef struct { PyObject_HEAD ViewShape *vs; int borrowed; /* non-zero if *vs a borrowed object */ + BPy_SShape *py_ss; } BPy_ViewShape; /*---------------------------Python BPy_ViewShape visible prototypes-----------*/ diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp index 3e2cc495785..e63d1c583d8 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp @@ -27,78 +27,80 @@ PyDoc_STRVAR(CurvePoint_doc, "\n" " Defult constructor.\n" "\n" -".. method:: __init__(iBrother)\n" +".. method:: __init__(brother)\n" "\n" " Copy constructor.\n" "\n" -" :arg iBrother: A CurvePoint object.\n" -" :type iBrother: :class:`CurvePoint`\n" +" :arg brother: A CurvePoint object.\n" +" :type brother: :class:`CurvePoint`\n" "\n" -".. method:: __init__(iA, iB, t2d)\n" +".. method:: __init__(first_vertex, second_vertex, t2d)\n" "\n" -" Builds a CurvePoint from two SVertex and an interpolation parameter.\n" +" Builds a CurvePoint from two SVertex objects and an interpolation parameter.\n" "\n" -" :arg iA: The first SVertex.\n" -" :type iA: :class:`SVertex`\n" -" :arg iB: The second SVertex.\n" -" :type iB: :class:`SVertex`\n" +" :arg first_vertex: The first SVertex.\n" +" :type first_vertex: :class:`SVertex`\n" +" :arg second_vertex: The second SVertex.\n" +" :type second_vertex: :class:`SVertex`\n" " :arg t2d: A 2D interpolation parameter used to linearly interpolate\n" -" iA and iB.\n" +" first_vertex and second_vertex.\n" " :type t2d: float\n" "\n" -".. method:: __init__(iA, iB, t2d)\n" +".. method:: __init__(first_point, second_point, t2d)\n" "\n" -" Builds a CurvePoint from two CurvePoint and an interpolation\n" +" Builds a CurvePoint from two CurvePoint objects and an interpolation\n" " parameter.\n" "\n" -" :arg iA: The first CurvePoint.\n" -" :type iA: :class:`CurvePoint`\n" -" :arg iB: The second CurvePoint.\n" -" :type iB: :class:`CurvePoint`\n" -" :arg t2d: The 2D interpolation parameter used to linearly\n" -" interpolate iA and iB.\n" +" :arg first_point: The first CurvePoint.\n" +" :type first_point: :class:`CurvePoint`\n" +" :arg second_point: The second CurvePoint.\n" +" :type second_point: :class:`CurvePoint`\n" +" :arg t2d: The 2D interpolation parameter used to linearly interpolate\n" +" first_point and second_point.\n" " :type t2d: float"); static int CurvePoint_init(BPy_CurvePoint *self, PyObject *args, PyObject *kwds) { - - PyObject *obj1 = 0, *obj2 = 0 , *obj3 = 0; - - if (! PyArg_ParseTuple(args, "|OOO!", &obj1, &obj2, &PyFloat_Type, &obj3) ) - return -1; - - if( !obj1 ){ - self->cp = new CurvePoint(); - - } else if( !obj2 && BPy_CurvePoint_Check(obj1) ) { - self->cp = new CurvePoint( *(((BPy_CurvePoint *) obj1)->cp) ); - - } else if( obj3 && BPy_SVertex_Check(obj1) && BPy_SVertex_Check(obj2) ) { - self->cp = new CurvePoint( ((BPy_SVertex *) obj1)->sv, - ((BPy_SVertex *) obj2)->sv, - PyFloat_AsDouble( obj3 ) ); - - } else if( obj3 && BPy_CurvePoint_Check(obj1) && BPy_CurvePoint_Check(obj2) ) { - CurvePoint *cp1 = ((BPy_CurvePoint *) obj1)->cp; - CurvePoint *cp2 = ((BPy_CurvePoint *) obj2)->cp; - if( !cp1 || cp1->A() == 0 || cp1->B() == 0 ) { + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"first_vertex", "second_vertex", "t2d", NULL}; + static const char *kwlist_3[] = {"first_point", "second_point", "t2d", NULL}; + PyObject *obj1 = 0, *obj2 = 0; + float t2d; + + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &CurvePoint_Type, &obj1)) { + if (!obj1) + self->cp = new CurvePoint(); + else + self->cp = new CurvePoint(*(((BPy_CurvePoint *)obj1)->cp)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O!O!f", (char **)kwlist_2, + &SVertex_Type, &obj1, &SVertex_Type, &obj2, &t2d)) + { + self->cp = new CurvePoint(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv, t2d); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O!O!f", (char **)kwlist_3, + &CurvePoint_Type, &obj1, &CurvePoint_Type, &obj2, &t2d)) + { + CurvePoint *cp1 = ((BPy_CurvePoint *)obj1)->cp; + CurvePoint *cp2 = ((BPy_CurvePoint *)obj2)->cp; + if (!cp1 || cp1->A() == 0 || cp1->B() == 0) { PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid CurvePoint object"); return -1; } - if( !cp2 || cp2->A() == 0 || cp2->B() == 0 ) { + if (!cp2 || cp2->A() == 0 || cp2->B() == 0) { PyErr_SetString(PyExc_TypeError, "argument 2 is an invalid CurvePoint object"); return -1; } - self->cp = new CurvePoint( cp1, cp2, PyFloat_AsDouble( obj3 ) ); - - } else { + self->cp = new CurvePoint(cp1, cp2, t2d); + } + else { PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; } - self->py_if0D.if0D = self->cp; self->py_if0D.borrowed = 0; - return 0; } diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp index 0d0a772b4e5..f1ac241c66f 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp @@ -21,53 +21,52 @@ PyDoc_STRVAR(SVertex_doc, "\n" " Default constructor.\n" "\n" -".. method:: __init__(iBrother)\n" +".. method:: __init__(brother)\n" "\n" " Copy constructor.\n" "\n" -" :arg iBrother: A SVertex object.\n" -" :type iBrother: :class:`SVertex`\n" +" :arg brother: A SVertex object.\n" +" :type brother: :class:`SVertex`\n" "\n" -".. method:: __init__(iPoint3D, id)\n" +".. method:: __init__(point_3d, id)\n" "\n" " Builds a SVertex from 3D coordinates and an Id.\n" "\n" -" :arg iPoint3D: A three-dimensional vector.\n" -" :type iPoint3D: :class:`mathutils.Vector`\n" +" :arg point_3d: A three-dimensional vector.\n" +" :type point_3d: :class:`mathutils.Vector`\n" " :arg id: An Id object.\n" " :type id: :class:`Id`"); -static int SVertex_init(BPy_SVertex *self, PyObject *args, PyObject *kwds) +static int convert_v3(PyObject *obj, void *v) { - PyObject *py_point = 0; - BPy_Id *py_id = 0; - - if (!PyArg_ParseTuple(args, "|OO!", &py_point, &Id_Type, &py_id)) - return -1; - - if (!py_point) { - self->sv = new SVertex(); - - } else if (!py_id && BPy_SVertex_Check(py_point)) { - self->sv = new SVertex( *(((BPy_SVertex *)py_point)->sv) ); + return float_array_from_PyObject(obj, (float *)v, 3); +} - } else if (py_point && py_id) { - Vec3r *v = Vec3r_ptr_from_PyObject(py_point); - if (!v) { - PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); - return -1; - } - self->sv = new SVertex(*v, *(py_id->id)); - delete v; +static int SVertex_init(BPy_SVertex *self, PyObject *args, PyObject *kwds) +{ + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"point_3d", "id", NULL}; + PyObject *obj = 0; + float v[3]; - } else { + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &SVertex_Type, &obj)) { + if (!obj) + self->sv = new SVertex(); + else + self->sv = new SVertex(*(((BPy_SVertex *)obj)->sv)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O&O!", (char **)kwlist_2, convert_v3, v, &Id_Type, &obj)) + { + Vec3r point_3d(v[0], v[1], v[2]); + self->sv = new SVertex(point_3d, *(((BPy_Id *)obj)->id)); + } + else { PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; } - self->py_if0D.if0D = self->sv; self->py_if0D.borrowed = 0; - return 0; } @@ -115,7 +114,7 @@ static PyObject *SVertex_add_fedge( BPy_SVertex *self , PyObject *args) { Py_RETURN_NONE; } -// virtual bool operator== (const SVertex &iBrother) +// virtual bool operator== (const SVertex &brother) static PyMethodDef BPy_SVertex_methods[] = { {"add_normal", (PyCFunction)SVertex_add_normal, METH_VARARGS, SVertex_add_normal_doc}, diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp index 4fabfc508db..7954cf7fed8 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp @@ -23,27 +23,12 @@ PyDoc_STRVAR(ViewVertex_doc, ":class:`NonTVertex` when it corresponds to a vertex of the initial\n" "input mesh (it is the case for vertices such as corners for example).\n" "Thus, this class can be specialized into two classes, the\n" -":class:`TVertex` class and the :class:`NonTVertex` class.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(iBrother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg iBrother: A ViewVertex object.\n" -" :type iBrother: :class:`ViewVertex`"); +":class:`TVertex` class and the :class:`NonTVertex` class."); static int ViewVertex_init(BPy_ViewVertex *self, PyObject *args, PyObject *kwds) { - if (!PyArg_ParseTuple(args, "")) - return -1; - self->vv = 0; // ViewVertex is abstract - self->py_if0D.if0D = self->vv; - self->py_if0D.borrowed = 0; - return 0; + PyErr_SetString(PyExc_TypeError, "cannot instantiate abstract class"); + return -1; } PyDoc_STRVAR(ViewVertex_edges_begin_doc, diff --git a/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp index ad83a6933c3..09ebbfd1b3a 100644 --- a/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp @@ -9,8 +9,6 @@ extern "C" { #endif -#include "../../../python/mathutils/mathutils.h" /* for Vector callbacks */ - /////////////////////////////////////////////////////////////////////////////////////////// //------------------------INSTANCE METHODS ---------------------------------- @@ -24,71 +22,74 @@ PyDoc_STRVAR(StrokeVertex_doc, "\n" " Default constructor.\n" "\n" -".. method:: __init__(iBrother)\n" +".. method:: __init__(brother)\n" "\n" " Copy constructor.\n" "\n" -" :arg iBrother: A StrokeVertex object.\n" -" :type iBrother: :class:`StrokeVertex`\n" +" :arg brother: A StrokeVertex object.\n" +" :type brother: :class:`StrokeVertex`\n" "\n" -".. method:: __init__(iA, iB, t3)\n" +".. method:: __init__(first_vertex, second_vertex, t3d)\n" "\n" -" Builds a stroke vertex from 2 stroke vertices and an interpolation\n" +" Build a stroke vertex from 2 stroke vertices and an interpolation\n" " parameter.\n" "\n" -" :arg iA: The first StrokeVertex.\n" -" :type iA: :class:`StrokeVertex`\n" -" :arg iB: The second StrokeVertex.\n" -" :type iB: :class:`StrokeVertex`\n" -" :arg t3: An interpolation parameter.\n" -" :type t3: float\n" +" :arg first_vertex: The first StrokeVertex.\n" +" :type first_vertex: :class:`StrokeVertex`\n" +" :arg second_vertex: The second StrokeVertex.\n" +" :type second_vertex: :class:`StrokeVertex`\n" +" :arg t3d: An interpolation parameter.\n" +" :type t3d: float\n" "\n" -".. method:: __init__(iPoint)\n" +".. method:: __init__(point)\n" "\n" -" Builds a stroke vertex from a CurvePoint\n" +" Build a stroke vertex from a CurvePoint\n" "\n" -" :arg iPoint: A CurvePoint object.\n" -" :type iPoint: :class:`CurvePoint`\n" +" :arg point: A CurvePoint object.\n" +" :type point: :class:`CurvePoint`\n" "\n" -".. method:: __init__(iSVertex)\n" +".. method:: __init__(svertex)\n" "\n" -" Builds a stroke vertex from a SVertex\n" +" Build a stroke vertex from a SVertex\n" "\n" -" :arg iSVertex: An SVertex object.\n" -" :type iSVertex: :class:`SVertex`\n" +" :arg svertex: An SVertex object.\n" +" :type svertex: :class:`SVertex`\n" "\n" -".. method:: __init__(iSVertex, iAttribute)\n" +".. method:: __init__(svertex, attribute)\n" "\n" -" Builds a stroke vertex from an SVertex and a StrokeAttribute object.\n" +" Build a stroke vertex from an SVertex and a StrokeAttribute object.\n" "\n" -" :arg iSVertex: An SVertex object.\n" -" :type iSVertex: :class:`SVertex`\n" -" :arg iAttribute: A StrokeAttribute object.\n" -" :type iAttribute: :class:`StrokeAttribute`"); +" :arg svertex: An SVertex object.\n" +" :type svertex: :class:`SVertex`\n" +" :arg attribute: A StrokeAttribute object.\n" +" :type attribute: :class:`StrokeAttribute`"); static int StrokeVertex_init(BPy_StrokeVertex *self, PyObject *args, PyObject *kwds) { - - PyObject *obj1 = 0, *obj2 = 0 , *obj3 = 0; - - if (!PyArg_ParseTuple(args, "|OOO!", &obj1, &obj2, &PyFloat_Type, &obj3)) - return -1; - - if (!obj1){ - self->sv = new StrokeVertex(); - - } else if (!obj2 && BPy_StrokeVertex_Check(obj1) && ((BPy_StrokeVertex *) obj1)->sv) { - self->sv = new StrokeVertex( *(((BPy_StrokeVertex *) obj1)->sv) ); - - } else if (!obj2 && BPy_CurvePoint_Check(obj1) && ((BPy_CurvePoint *) obj1)->cp) { - self->sv = new StrokeVertex( ((BPy_CurvePoint *) obj1)->cp ); - - } else if (!obj2 && BPy_SVertex_Check(obj1) && ((BPy_SVertex *) obj1)->sv) { - self->sv = new StrokeVertex( ((BPy_SVertex *) obj1)->sv ); - - } else if (obj3 && BPy_StrokeVertex_Check(obj1) && BPy_StrokeVertex_Check(obj2)) { - StrokeVertex *sv1 = ((BPy_StrokeVertex *) obj1)->sv; - StrokeVertex *sv2 = ((BPy_StrokeVertex *) obj2)->sv; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"first_vertex", "second_vertex", "t3d", NULL}; + static const char *kwlist_3[] = {"point", NULL}; + static const char *kwlist_4[] = {"svertex", "attribute", NULL}; + PyObject *obj1 = 0, *obj2 = 0; + float t3d; + + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &StrokeVertex_Type, &obj1)) { + if (!obj1) { + self->sv = new StrokeVertex(); + } else { + if (!((BPy_StrokeVertex *)obj1)->sv) { + PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid StrokeVertex object"); + return -1; + } + self->sv = new StrokeVertex(*(((BPy_StrokeVertex *)obj1)->sv)); + } + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O!O!f", (char **)kwlist_2, + &StrokeVertex_Type, &obj1, &StrokeVertex_Type, &obj2, &t3d)) + { + StrokeVertex *sv1 = ((BPy_StrokeVertex *)obj1)->sv; + StrokeVertex *sv2 = ((BPy_StrokeVertex *)obj2)->sv; if (!sv1 || (sv1->A() == 0 && sv1->B() == 0)) { PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid StrokeVertex object"); return -1; @@ -97,17 +98,34 @@ static int StrokeVertex_init(BPy_StrokeVertex *self, PyObject *args, PyObject *k PyErr_SetString(PyExc_TypeError, "argument 2 is an invalid StrokeVertex object"); return -1; } - self->sv = new StrokeVertex(sv1, sv2, PyFloat_AsDouble(obj3)); - - } else { + self->sv = new StrokeVertex(sv1, sv2, t3d); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_3, &CurvePoint_Type, &obj1)) + { + CurvePoint *cp = ((BPy_CurvePoint *)obj1)->cp; + if (!cp || cp->A() == 0 || cp->B() == 0) { + PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid CurvePoint object"); + return -1; + } + self->sv = new StrokeVertex(cp); + } + else if (PyErr_Clear(), (obj2 = 0), + PyArg_ParseTupleAndKeywords(args, kwds, "O!|O!", (char **)kwlist_4, + &SVertex_Type, &obj1, &StrokeAttribute_Type, &obj2)) + { + if (!obj2) + self->sv = new StrokeVertex(((BPy_SVertex *)obj1)->sv); + else + self->sv = new StrokeVertex(((BPy_SVertex *)obj1)->sv, *(((BPy_StrokeAttribute *)obj2)->sa)); + } + else { PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; } - self->py_cp.cp = self->sv; self->py_cp.py_if0D.if0D = self->sv; self->py_cp.py_if0D.borrowed = 0; - return 0; } diff --git a/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp index a0e0717ef37..b2b2f8bda28 100644 --- a/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp @@ -21,42 +21,29 @@ PyDoc_STRVAR(NonTVertex_doc, "\n" " Default constructor.\n" "\n" -".. method:: __init__(iBrother)\n" +".. method:: __init__(svertex)\n" "\n" -" Copy constructor.\n" +" Build a NonTVertex from a SVertex.\n" "\n" -" :arg iBrother: A NonTVertex object.\n" -" :type iBrother: :class:`NonTVertex`\n" -"\n" -".. method:: __init__(iSVertex)\n" -"\n" -" Builds a NonTVertex from a SVertex.\n" -"\n" -" :arg iSVertex: An SVertex object.\n" -" :type iSVertex: :class:`SVertex`"); +" :arg svertex: An SVertex object.\n" +" :type svertex: :class:`SVertex`"); + +/* Note: No copy constructor in Python because the C++ copy constructor is 'protected'. */ static int NonTVertex_init(BPy_NonTVertex *self, PyObject *args, PyObject *kwds) { + static const char *kwlist[] = {"svertex", NULL}; PyObject *obj = 0; - if (!PyArg_ParseTuple(args, "|O!", &SVertex_Type, &obj)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &SVertex_Type, &obj)) return -1; - - if (!obj) { + if (!obj) self->ntv = new NonTVertex(); - - } else if(((BPy_SVertex *)obj)->sv) { + else self->ntv = new NonTVertex(((BPy_SVertex *)obj)->sv); - - } else { - PyErr_SetString(PyExc_TypeError, "invalid argument"); - return -1; - } - self->py_vv.vv = self->ntv; self->py_vv.py_if0D.if0D = self->ntv; self->py_vv.py_if0D.borrowed = 0; - return 0; } diff --git a/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp index 55c8b64d13c..e501bb7f713 100644 --- a/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp @@ -25,18 +25,15 @@ PyDoc_STRVAR(TVertex_doc, "\n" ".. method:: __init__()\n" "\n" -" Default constructor.\n" -"\n" -".. method:: __init__(iBrother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg iBrother: A TVertex object.\n" -" :type iBrother: :class:`TVertex`"); +" Default constructor."); + +/* Note: No copy constructor in Python because the C++ copy constructor is 'protected'. */ static int TVertex_init(BPy_TVertex *self, PyObject *args, PyObject *kwds) { - if (!PyArg_ParseTuple(args, "")) + static const char *kwlist[] = {NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) return -1; self->tv = new TVertex(); self->py_vv.vv = self->tv; diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp index be3d97f5f78..2090a4523f0 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp @@ -31,46 +31,46 @@ PyDoc_STRVAR(FEdge_doc, "\n" " Default constructor.\n" "\n" -".. method:: FEdge(iBrother)\n" +".. method:: FEdge(brother)\n" "\n" " Copy constructor.\n" "\n" -" :arg iBrother: An FEdge object.\n" -" :type iBrother: :class:`FEdge`\n" +" :arg brother: An FEdge object.\n" +" :type brother: :class:`FEdge`\n" "\n" -".. method:: FEdge(vA, vB)\n" +".. method:: FEdge(first_vertex, second_vertex)\n" "\n" -" Builds an FEdge going from vA to vB.\n" +" Builds an FEdge going from the first vertex to the second.\n" "\n" -" :arg vA: The first SVertex.\n" -" :type vA: :class:`SVertex`\n" -" :arg vB: The second SVertex.\n" -" :type vB: :class:`SVertex`"); +" :arg first_vertex: The first SVertex.\n" +" :type first_vertex: :class:`SVertex`\n" +" :arg second_vertex: The second SVertex.\n" +" :type second_vertex: :class:`SVertex`"); static int FEdge_init(BPy_FEdge *self, PyObject *args, PyObject *kwds) { + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"first_vertex", "second_vertex", NULL}; PyObject *obj1 = 0, *obj2 = 0; - if (!PyArg_ParseTuple(args, "|OO", &obj1, &obj2)) - return -1; - - if (!obj1) { - self->fe = new FEdge(); - - } else if(!obj2 && BPy_FEdge_Check(obj1)) { - self->fe = new FEdge(*(((BPy_FEdge *)obj1)->fe)); - - } else if(obj2 && BPy_SVertex_Check(obj1) && BPy_SVertex_Check(obj2)) { + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FEdge_Type, &obj1)) { + if (!obj1) + self->fe = new FEdge(); + else + self->fe = new FEdge(*(((BPy_FEdge *)obj1)->fe)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", (char **)kwlist_2, + &SVertex_Type, &obj1, &SVertex_Type, &obj2)) + { self->fe = new FEdge(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv); - - } else { + } + else { PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; } - self->py_if1D.if1D = self->fe; self->py_if1D.borrowed = 0; - return 0; } diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp index e5b984e41bd..43e960007a0 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp @@ -24,45 +24,43 @@ PyDoc_STRVAR(FrsCurve_doc, "\n" " Default Constructor.\n" "\n" -".. method:: __init__(iBrother)\n" +".. method:: __init__(brother)\n" "\n" " Copy Constructor.\n" "\n" -" :arg iBrother: A Curve object.\n" -" :type iBrother: :class:`Curve`\n" +" :arg brother: A Curve object.\n" +" :type brother: :class:`Curve`\n" "\n" -".. method:: __init__(iId)\n" +".. method:: __init__(id)\n" "\n" " Builds a Curve from its Id.\n" "\n" -" :arg iId: An Id object.\n" -" :type iId: :class:`Id`"); +" :arg id: An Id object.\n" +" :type id: :class:`Id`"); static int FrsCurve_init(BPy_FrsCurve *self, PyObject *args, PyObject *kwds) { - + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"id", NULL}; PyObject *obj = 0; - if (!PyArg_ParseTuple(args, "|O", &obj)) - return -1; - - if (!obj) { - self->c = new Curve(); - - } else if (BPy_FrsCurve_Check(obj)) { - self->c = new Curve(*( ((BPy_FrsCurve *) obj)->c )); - - } else if (BPy_Id_Check(obj)) { - self->c = new Curve(*( ((BPy_Id *) obj)->id )); - - } else { - PyErr_SetString(PyExc_TypeError, "invalid argument"); + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FrsCurve_Type, &obj)) { + if (!obj) + self->c = new Curve(); + else + self->c = new Curve(*(((BPy_FrsCurve *)obj)->c)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_2, &Id_Type, &obj)) + { + self->c = new Curve(*(((BPy_Id *)obj)->id)); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; } - self->py_if1D.if1D = self->c; self->py_if1D.borrowed = 0; - return 0; } diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp index f0cc91b9a79..7896471fb0a 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp @@ -16,7 +16,7 @@ extern "C" { /*----------------------Stroke methods ----------------------------*/ // Stroke () -// template<class InputVertexIterator> Stroke (InputVertexIterator iBegin, InputVertexIterator iEnd) +// template<class InputVertexIterator> Stroke (InputVertexIterator begin, InputVertexIterator end) // // pb: - need to be able to switch representation: InputVertexIterator <=> position // - is it even used ? not even in SWIG version @@ -33,50 +33,23 @@ PyDoc_STRVAR(Stroke_doc, "\n" " Default constructor\n" "\n" -".. method:: Stroke(iBrother)\n" +".. method:: Stroke(brother)\n" "\n" -" Copy constructor\n" -"\n" -" :arg iBrother: \n" -" :type iBrother: :class:`Stroke`\n" -"\n" -".. method:: Stroke(iBegin, iEnd)\n" -"\n" -" Builds a stroke from a set of StrokeVertex. This constructor is\n" -" templated by an iterator type. This iterator type must allow the\n" -" vertices parsing using the ++ operator.\n" -"\n" -" :arg iBegin: The iterator pointing to the first vertex.\n" -" :type iBegin: InputVertexIterator\n" -" :arg iEnd: The iterator pointing to the end of the vertex list.\n" -" :type iEnd: InputVertexIterator"); +" Copy constructor"); static int Stroke_init(BPy_Stroke *self, PyObject *args, PyObject *kwds) { - PyObject *obj1 = NULL, *obj2 = NULL; + static const char *kwlist[] = {"brother", NULL}; + PyObject *brother = 0; - if (!PyArg_ParseTuple(args, "|OO", &obj1, &obj2)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &Stroke_Type, &brother)) return -1; - - if (!obj1) { + if (!brother) self->s = new Stroke(); - - } else if (!obj2 && BPy_Stroke_Check(obj1)) { - self->s = new Stroke(*(((BPy_Stroke *)obj1)->s)); - - } else if (obj2) { - PyErr_SetString(PyExc_TypeError, - "Stroke(InputVertexIterator iBegin, InputVertexIterator iEnd) not implemented"); - return -1; - - } else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - + else + self->s = new Stroke(*(((BPy_Stroke *)brother)->s)); self->py_if1D.if1D = self->s; self->py_if1D.borrowed = 0; - return 0; } diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.cpp index 8e1cb42f37c..cdba2746812 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.cpp @@ -27,18 +27,24 @@ PyDoc_STRVAR(ViewEdge_doc, "\n" " Default constructor.\n" "\n" -".. method:: __init__(iBrother)\n" +".. method:: __init__(brother)\n" "\n" " Copy constructor.\n" "\n" -" :arg iBrother: A ViewEdge object.\n" -" :type iBrother: :class:`ViewEdge`"); +" :arg brother: A ViewEdge object.\n" +" :type brother: :class:`ViewEdge`"); static int ViewEdge_init(BPy_ViewEdge *self, PyObject *args, PyObject *kwds) { - if (!PyArg_ParseTuple(args, "")) + static const char *kwlist[] = {"brother", NULL}; + PyObject *brother = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &ViewEdge_Type, &brother)) return -1; - self->ve = new ViewEdge(); + if (!brother) + self->ve = new ViewEdge(); + else + self->ve = new ViewEdge(*(((BPy_ViewEdge *)brother)->ve)); self->py_if1D.if1D = self->ve; self->py_if1D.borrowed = 0; return 0; diff --git a/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp b/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp index 793fc206389..16769e2cf74 100644 --- a/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp @@ -23,12 +23,12 @@ PyDoc_STRVAR(Chain_doc, "\n" " Defult constructor.\n" "\n" -".. method:: __init__(iBrother)\n" +".. method:: __init__(brother)\n" "\n" " Copy constructor.\n" "\n" -" :arg iBrother: A Chain object.\n" -" :type iBrother: :class:`Chain`\n" +" :arg brother: A Chain object.\n" +" :type brother: :class:`Chain`\n" "\n" ".. method:: __init__(id)\n" "\n" @@ -39,30 +39,28 @@ PyDoc_STRVAR(Chain_doc, static int Chain_init(BPy_Chain *self, PyObject *args, PyObject *kwds) { - + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"id", NULL}; PyObject *obj = 0; - if (!PyArg_ParseTuple(args, "|O", &obj)) - return -1; - - if (!obj) { - self->c = new Chain(); - - } else if (BPy_Chain_Check(obj)) { - self->c = new Chain(*(((BPy_Chain *)obj)->c)); - - } else if (BPy_Id_Check(obj)) { + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &Chain_Type, &obj)) { + if (!obj) + self->c = new Chain(); + else + self->c = new Chain(*(((BPy_Chain *)obj)->c)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_2, &Id_Type, &obj)) + { self->c = new Chain(*(((BPy_Id *)obj)->id)); - - } else { - PyErr_SetString(PyExc_TypeError, "invalid argument"); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; } - self->py_c.c = self->c; self->py_c.py_if1D.if1D = self->c; self->py_c.py_if1D.borrowed = 0; - return 0; } diff --git a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp index 49da570a9fc..a4b32cf72df 100644 --- a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp @@ -25,39 +25,41 @@ PyDoc_STRVAR(FEdgeSharp_doc, "\n" " Default constructor.\n" "\n" -".. method:: __init__(iBrother)\n" +".. method:: __init__(brother)\n" "\n" " Copy constructor.\n" "\n" -" :arg iBrother: An FEdgeSharp object.\n" -" :type iBrother: :class:`FEdgeSharp`\n" +" :arg brother: An FEdgeSharp object.\n" +" :type brother: :class:`FEdgeSharp`\n" "\n" -".. method:: __init__(vA, vB)\n" +".. method:: __init__(first_vertex, second_vertex)\n" "\n" -" Builds an FEdgeSharp going from vA to vB.\n" +" Builds an FEdgeSharp going from the first vertex to the second.\n" "\n" -" :arg vA: The first SVertex object.\n" -" :type vA: :class:`SVertex`\n" -" :arg vB: The second SVertex object.\n" -" :type vB: :class:`SVertex`"); +" :arg first_vertex: The first SVertex object.\n" +" :type first_vertex: :class:`SVertex`\n" +" :arg second_vertex: The second SVertex object.\n" +" :type second_vertex: :class:`SVertex`"); static int FEdgeSharp_init(BPy_FEdgeSharp *self, PyObject *args, PyObject *kwds) { + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"first_vertex", "second_vertex", NULL}; PyObject *obj1 = 0, *obj2 = 0; - if (!PyArg_ParseTuple(args, "|OO", &obj1, &obj2)) - return -1; - - if (!obj1) { - self->fes = new FEdgeSharp(); - - } else if (!obj2 && BPy_FEdgeSharp_Check(obj1)) { - self->fes = new FEdgeSharp(*(((BPy_FEdgeSharp *)obj1)->fes)); - - } else if (obj2 && BPy_SVertex_Check(obj1) && BPy_SVertex_Check(obj2)) { + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FEdgeSharp_Type, &obj1)) { + if (!obj1) + self->fes = new FEdgeSharp(); + else + self->fes = new FEdgeSharp(*(((BPy_FEdgeSharp *)obj1)->fes)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", (char **)kwlist_2, + &SVertex_Type, &obj1, &SVertex_Type, &obj2)) + { self->fes = new FEdgeSharp(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv); - - } else { + } + else { PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; } diff --git a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp index 847794c74c0..9b51dab4edb 100644 --- a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp @@ -22,47 +22,47 @@ PyDoc_STRVAR(FEdgeSmooth_doc, "\n" " Default constructor.\n" "\n" -".. method:: __init__(iBrother)\n" +".. method:: __init__(brother)\n" "\n" " Copy constructor.\n" "\n" -" :arg iBrother: An FEdgeSmooth object.\n" -" :type iBrother: :class:`FEdgeSmooth`\n" +" :arg brother: An FEdgeSmooth object.\n" +" :type brother: :class:`FEdgeSmooth`\n" "\n" -".. method:: __init__(vA, vB)\n" +".. method:: __init__(first_vertex, second_vertex)\n" "\n" -" Builds an FEdgeSmooth going from vA to vB.\n" +" Builds an FEdgeSmooth going from the first to the second.\n" "\n" -" :arg vA: The first SVertex object.\n" -" :type vA: :class:`SVertex`\n" -" :arg vB: The second SVertex object.\n" -" :type vB: :class:`SVertex`"); +" :arg first_vertex: The first SVertex object.\n" +" :type first_vertex: :class:`SVertex`\n" +" :arg second_vertex: The second SVertex object.\n" +" :type second_vertex: :class:`SVertex`"); static int FEdgeSmooth_init(BPy_FEdgeSmooth *self, PyObject *args, PyObject *kwds) { + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"first_vertex", "second_vertex", NULL}; PyObject *obj1 = 0, *obj2 = 0; - if (!PyArg_ParseTuple(args, "|OO", &obj1, &obj2)) - return -1; - - if (!obj1) { - self->fes = new FEdgeSmooth(); - - } else if (!obj2 && BPy_FEdgeSmooth_Check(obj1)) { - self->fes = new FEdgeSmooth(*(((BPy_FEdgeSmooth *)obj1)->fes)); - - } else if (obj2 && BPy_SVertex_Check(obj1) && BPy_SVertex_Check(obj2)) { + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FEdgeSmooth_Type, &obj1)) { + if (!obj1) + self->fes = new FEdgeSmooth(); + else + self->fes = new FEdgeSmooth(*(((BPy_FEdgeSmooth *)obj1)->fes)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", (char **)kwlist_2, + &SVertex_Type, &obj1, &SVertex_Type, &obj2)) + { self->fes = new FEdgeSmooth(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv); - - } else { + } + else { PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; } - self->py_fe.fe = self->fes; self->py_fe.py_if1D.if1D = self->fes; self->py_fe.py_if1D.borrowed = 0; - return 0; } diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp index 8d7e5638d19..358bf78221f 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp @@ -19,52 +19,55 @@ PyDoc_STRVAR(AdjacencyIterator_doc, "decrement() methods of a :class:`ChainingIterator` and passed to the\n" "traverse() method of the ChainingIterator.\n" "\n" -".. method:: __init__(iVertex, iRestrictToSelection=True, iRestrictToUnvisited=True)\n" +".. method:: __init__()\n" "\n" -" Builds a AdjacencyIterator object.\n" +" Default constructor.\n" "\n" -" :arg iVertex: The vertex which is the next crossing.\n" -" :type iVertex: :class:`ViewVertex`\n" -" :arg iRestrictToSelection: Indicates whether to force the chaining\n" -" to stay within the set of selected ViewEdges or not.\n" -" :type iRestrictToSelection: bool\n" -" :arg iRestrictToUnvisited: Indicates whether a ViewEdge that has\n" -" already been chained must be ignored ot not.\n" -" :type iRestrictToUnvisited: bool\n" -"\n" -".. method:: __init__(it)\n" +".. method:: __init__(brother)\n" "\n" " Copy constructor.\n" "\n" -" :arg it: An AdjacencyIterator object.\n" -" :type it: :class:`AdjacencyIterator`"); +" :arg brother: An AdjacencyIterator object.\n" +" :type brother: :class:`AdjacencyIterator`\n" +"\n" +".. method:: __init__(vertex, restrict_to_selection=True, restrict_to_unvisited=True)\n" +"\n" +" Builds a AdjacencyIterator object.\n" +"\n" +" :arg vertex: The vertex which is the next crossing.\n" +" :type vertex: :class:`ViewVertex`\n" +" :arg restrict_to_selection: Indicates whether to force the chaining\n" +" to stay within the set of selected ViewEdges or not.\n" +" :type restrict_to_selection: bool\n" +" :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n" +" already been chained must be ignored ot not.\n" +" :type restrict_to_unvisited: bool"); -static int AdjacencyIterator_init(BPy_AdjacencyIterator *self, PyObject *args) +static int AdjacencyIterator_init(BPy_AdjacencyIterator *self, PyObject *args, PyObject *kwds) { - PyObject *obj1 = 0, *obj2 = 0 , *obj3 = 0; - - if (!PyArg_ParseTuple(args, "|OOO", &obj1, &obj2, &obj3)) - return -1; - - 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; - + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"vertex", "restrict_to_selection", "restrict_to_unvisited", NULL}; + PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0; + + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &AdjacencyIterator_Type, &obj1)) { + if (!obj1) + self->a_it = new AdjacencyIterator(); + else + self->a_it = new AdjacencyIterator(*(((BPy_AdjacencyIterator *)obj1)->a_it)); + } + else if (PyErr_Clear(), (obj2 = obj3 = 0), + PyArg_ParseTupleAndKeywords(args, kwds, "O!|O!O!", (char **)kwlist_2, + &ViewVertex_Type, &obj1, &PyBool_Type, &obj2, &PyBool_Type, &obj3)) + { + bool restrictToSelection = (!obj2) ? true : bool_from_PyBool(obj2); + bool restrictToUnvisited = (!obj3) ? true : bool_from_PyBool(obj3); self->a_it = new AdjacencyIterator(((BPy_ViewVertex *)obj1)->vv, restrictToSelection, restrictToUnvisited); - - } else { + } + else { PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; } - self->py_it.it = self->a_it; - return 0; } diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp index 13495a4fd04..f449bf11a9e 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp @@ -26,17 +26,17 @@ PyDoc_STRVAR(ChainPredicateIterator_doc, "predicate is kept as the next one. If none of the potential next\n" "ViewEdge respects these two predicates, None is returned.\n" "\n" -".. method:: __init__(iRestrictToSelection=True, iRestrictToUnvisited=True, begin=None, orientation=True)\n" +".. method:: __init__(restrict_to_selection=True, restrict_to_unvisited=True, begin=None, orientation=True)\n" "\n" " Builds a ChainPredicateIterator from a starting ViewEdge and its\n" " orientation.\n" "\n" -" :arg iRestrictToSelection: Indicates whether to force the chaining\n" +" :arg restrict_to_selection: Indicates whether to force the chaining\n" " to stay within the set of selected ViewEdges or not.\n" -" :type iRestrictToSelection: bool\n" -" :arg iRestrictToUnvisited: Indicates whether a ViewEdge that has\n" +" :type restrict_to_selection: bool\n" +" :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n" " already been chained must be ignored ot not.\n" -" :type iRestrictToUnvisited: bool\n" +" :type restrict_to_unvisited: bool\n" " :arg begin: The ViewEdge from where to start the iteration.\n" " :type begin: :class:`ViewEdge` or None\n" " :arg orientation: If true, we'll look for the next ViewEdge among\n" @@ -45,7 +45,7 @@ PyDoc_STRVAR(ChainPredicateIterator_doc, " ViewVertex of begin. \n" " :type orientation: bool\n" "\n" -".. method:: __init__(upred, bpred, iRestrictToSelection=True, iRestrictToUnvisited=True, begin=None, orientation=True)\n" +".. method:: __init__(upred, bpred, restrict_to_selection=True, restrict_to_unvisited=True, begin=None, orientation=True)\n" "\n" " Builds a ChainPredicateIterator from a unary predicate, a binary\n" " predicate, a starting ViewEdge and its orientation.\n" @@ -55,12 +55,12 @@ PyDoc_STRVAR(ChainPredicateIterator_doc, " :arg bpred: The binary predicate that the next ViewEdge must\n" " satisfy together with the actual pointed ViewEdge.\n" " :type bpred: :class:`BinaryPredicate1D`\n" -" :arg iRestrictToSelection: Indicates whether to force the chaining\n" +" :arg restrict_to_selection: Indicates whether to force the chaining\n" " to stay within the set of selected ViewEdges or not.\n" -" :type iRestrictToSelection: bool\n" -" :arg iRestrictToUnvisited: Indicates whether a ViewEdge that has\n" +" :type restrict_to_selection: bool\n" +" :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n" " already been chained must be ignored ot not.\n" -" :type iRestrictToUnvisited: bool\n" +" :type restrict_to_unvisited: bool\n" " :arg begin: The ViewEdge from where to start the iteration.\n" " :type begin: :class:`ViewEdge` or None\n" " :arg orientation: If true, we'll look for the next ViewEdge among\n" @@ -76,73 +76,61 @@ PyDoc_STRVAR(ChainPredicateIterator_doc, " :arg brother: A ChainPredicateIterator object.\n" " :type brother: :class:`ChainPredicateIterator`"); -static int ChainPredicateIterator_init(BPy_ChainPredicateIterator *self, PyObject *args) +static int check_begin(PyObject *obj, void *v) { - PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0, *obj5 = 0, *obj6 = 0; + if (obj != 0 && obj != Py_None && !BPy_ViewEdge_Check(obj)) + return 0; + *((PyObject **)v) = obj; + return 1; +} - if (!(PyArg_ParseTuple(args, "|OOOOOO", &obj1, &obj2, &obj3, &obj4, &obj5, &obj6))) - return -1; +static int ChainPredicateIterator_init(BPy_ChainPredicateIterator *self, PyObject *args, PyObject *kwds) +{ + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"upred", "bpred", "restrict_to_selection", "restrict_to_unvisited", "begin", "orientation", NULL}; + static const char *kwlist_3[] = {"restrict_to_selection", "restrict_to_unvisited", "begin", "orientation", NULL}; + PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0, *obj5 = 0, *obj6 = 0; - if (obj1 && BPy_ChainPredicateIterator_Check(obj1)) { + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_1, &ChainingIterator_Type, &obj1)) { self->cp_it = new ChainPredicateIterator(*(((BPy_ChainPredicateIterator *)obj1)->cp_it)); - self->upred = NULL; - self->bpred = NULL; - - } else if ( obj1 && BPy_UnaryPredicate1D_Check(obj1) && - obj2 && BPy_BinaryPredicate1D_Check(obj2)) { - - if (!((BPy_UnaryPredicate1D *)obj1)->up1D) { - PyErr_SetString(PyExc_TypeError, "1st argument: invalid UnaryPredicate1D object"); - return -1; - } - if (!((BPy_BinaryPredicate1D *)obj2)->bp1D) { - PyErr_SetString(PyExc_TypeError, "2nd argument: invalid BinaryPredicate1D object"); - return -1; - } + } + else if (PyErr_Clear(), (obj3 = obj4 = obj5 = obj6 = 0), + PyArg_ParseTupleAndKeywords(args, kwds, "O!O!|O!O!O&O!", (char **)kwlist_2, + &UnaryPredicate1D_Type, &obj1, &BinaryPredicate1D_Type, &obj2, + &PyBool_Type, &obj3, &PyBool_Type, &obj4, check_begin, &obj5, + &PyBool_Type, &obj6)) + { UnaryPredicate1D *up1D = ((BPy_UnaryPredicate1D *)obj1)->up1D; BinaryPredicate1D *bp1D = ((BPy_BinaryPredicate1D *)obj2)->bp1D; - bool restrictToSelection = (obj3) ? bool_from_PyBool(obj3) : true; - bool restrictToUnvisited = (obj4) ? bool_from_PyBool(obj4) : true; - ViewEdge *begin; - if (!obj5 || obj5 == Py_None) - begin = NULL; - else if (BPy_ViewEdge_Check(obj5)) - begin = ((BPy_ViewEdge *)obj5)->ve; - else { - PyErr_SetString(PyExc_TypeError, "5th argument must be either a ViewEdge object or None"); - return -1; - } - bool orientation = (obj6) ? bool_from_PyBool(obj6) : true; - - self->cp_it = new ChainPredicateIterator(*up1D, *bp1D, restrictToSelection, restrictToUnvisited, begin, orientation); + bool restrict_to_selection = (!obj3) ? true : bool_from_PyBool(obj3); + bool restrict_to_unvisited = (!obj4) ? true : bool_from_PyBool(obj4); + ViewEdge *begin = (!obj5 || obj5 == Py_None) ? NULL : ((BPy_ViewEdge *)obj5)->ve; + bool orientation = (!obj6) ? true : bool_from_PyBool(obj6); + self->cp_it = new ChainPredicateIterator(*up1D, *bp1D, restrict_to_selection, restrict_to_unvisited, begin, orientation); self->upred = obj1; self->bpred = obj2; Py_INCREF(self->upred); Py_INCREF(self->bpred); - - } else { - bool restrictToSelection = (obj1) ? bool_from_PyBool(obj1) : true; - bool restrictToUnvisited = (obj2) ? bool_from_PyBool(obj2) : true; - ViewEdge *begin; - if (!obj3 || obj3 == Py_None) - begin = NULL; - 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->cp_it = new ChainPredicateIterator(restrictToSelection, restrictToUnvisited, begin, orientation); + } + else if (PyErr_Clear(), (obj1 = obj2 = obj3 = obj4 = 0), + PyArg_ParseTupleAndKeywords(args, kwds, "|O!O!O&O!", (char **)kwlist_3, + &PyBool_Type, &obj1, &PyBool_Type, &obj2, check_begin, &obj3, + &PyBool_Type, &obj4)) + { + bool restrict_to_selection = (!obj1) ? true : bool_from_PyBool(obj1); + bool restrict_to_unvisited = (!obj2) ? true : bool_from_PyBool(obj2); + ViewEdge *begin = (!obj3 || obj3 == Py_None) ? NULL : ((BPy_ViewEdge *)obj3)->ve; + bool orientation = (!obj4) ? true : bool_from_PyBool(obj4); + self->cp_it = new ChainPredicateIterator(restrict_to_selection, restrict_to_unvisited, begin, orientation); self->upred = NULL; self->bpred = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; } - self->py_c_it.c_it = self->cp_it; self->py_c_it.py_ve_it.ve_it = self->cp_it; self->py_c_it.py_ve_it.py_it.it = self->cp_it; - return 0; } diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp index efc64913932..cfa0a6dcb8d 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp @@ -11,7 +11,7 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- -// ChainSilhouetteIterator (bool iRestrictToSelection=true, ViewEdge *begin=NULL, bool orientation=true) +// ChainSilhouetteIterator (bool restrict_to_selection=true, ViewEdge *begin=NULL, bool orientation=true) // ChainSilhouetteIterator (const ChainSilhouetteIterator &brother) PyDoc_STRVAR(ChainSilhouetteIterator_doc, @@ -24,14 +24,14 @@ PyDoc_STRVAR(ChainSilhouetteIterator_doc, "ViewEdge that are both Silhouette and Crease, there will be a\n" "precedence of the silhouette over the crease criterion.\n" "\n" -".. method:: __init__(iRestrictToSelection=True, begin=None, orientation=True)\n" +".. method:: __init__(restrict_to_selection=True, begin=None, orientation=True)\n" "\n" " Builds a ChainSilhouetteIterator from the first ViewEdge used for\n" " iteration and its orientation.\n" "\n" -" :arg iRestrictToSelection: Indicates whether to force the chaining\n" +" :arg restrict_to_selection: Indicates whether to force the chaining\n" " to stay within the set of selected ViewEdges or not.\n" -" :type iRestrictToSelection: bool\n" +" :type restrict_to_selection: bool\n" " :arg begin: The ViewEdge from where to start the iteration.\n" " :type begin: :class:`ViewEdge` or None\n" " :arg orientation: If true, we'll look for the next ViewEdge among\n" @@ -47,36 +47,39 @@ PyDoc_STRVAR(ChainSilhouetteIterator_doc, " :arg brother: A ChainSilhouetteIterator object.\n" " :type brother: :class:`ChainSilhouetteIterator`"); -static int ChainSilhouetteIterator_init(BPy_ChainSilhouetteIterator *self, PyObject *args) +static int check_begin(PyObject *obj, void *v) { - PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0; + if (obj != 0 && obj != Py_None && !BPy_ViewEdge_Check(obj)) + return 0; + *((PyObject **)v) = obj; + return 1; +} - if (!(PyArg_ParseTuple(args, "|OOO", &obj1, &obj2, &obj3))) - return -1; +static int ChainSilhouetteIterator_init(BPy_ChainSilhouetteIterator *self, PyObject *args, PyObject *kwds) +{ + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"restrict_to_selection", "begin", "orientation", NULL}; + PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0; - if (obj1 && BPy_ChainSilhouetteIterator_Check(obj1)) { + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_1, &ChainSilhouetteIterator_Type, &obj1)) { self->cs_it = new ChainSilhouetteIterator(*(((BPy_ChainSilhouetteIterator *)obj1)->cs_it)); - - } else { - bool restrictToSelection = (obj1) ? bool_from_PyBool(obj1) : true; - ViewEdge *begin; - if (!obj2 || obj2 == Py_None) - begin = NULL; - else if (BPy_ViewEdge_Check(obj2)) - begin = ((BPy_ViewEdge *)obj2)->ve; - else { - PyErr_SetString(PyExc_TypeError, "2nd argument must be either a ViewEdge object or None"); - return -1; - } - bool orientation = (obj3) ? bool_from_PyBool(obj3) : true; - - self->cs_it = new ChainSilhouetteIterator(restrictToSelection, begin, orientation); } - + else if (PyErr_Clear(), (obj1 = obj2 = obj3 = 0), + PyArg_ParseTupleAndKeywords(args, kwds, "|O!O&O!", (char **)kwlist_2, + &PyBool_Type, &obj1, check_begin, &obj2, &PyBool_Type, &obj3)) + { + bool restrict_to_selection = (!obj1) ? true : bool_from_PyBool(obj1); + ViewEdge *begin = (!obj2 || obj2 == Py_None) ? NULL : ((BPy_ViewEdge *)obj2)->ve; + bool orientation = (!obj3) ? true : bool_from_PyBool(obj3); + self->cs_it = new ChainSilhouetteIterator(restrict_to_selection, begin, orientation); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } self->py_c_it.c_it = self->cs_it; self->py_c_it.py_ve_it.ve_it = self->cs_it; self->py_c_it.py_ve_it.py_it.it = self->cs_it; - return 0; } diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp index 5323fe1c146..1c727582b7b 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp @@ -25,17 +25,17 @@ PyDoc_STRVAR(ChainingIterator_doc, "they will be included in the adjacency iterator (i.e, the adjacent\n" "iterator will only stop on \"valid\" edges).\n" "\n" -".. method:: __init__(iRestrictToSelection=True, iRestrictToUnvisited=True, begin=None, orientation=True)\n" +".. method:: __init__(restrict_to_selection=True, restrict_to_unvisited=True, begin=None, orientation=True)\n" "\n" " Builds a Chaining Iterator from the first ViewEdge used for\n" " iteration and its orientation.\n" "\n" -" :arg iRestrictToSelection: Indicates whether to force the chaining\n" +" :arg restrict_to_selection: Indicates whether to force the chaining\n" " to stay within the set of selected ViewEdges or not.\n" -" :type iRestrictToSelection: bool\n" -" :arg iRestrictToUnvisited: Indicates whether a ViewEdge that has\n" +" :type restrict_to_selection: bool\n" +" :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n" " already been chained must be ignored ot not.\n" -" :type iRestrictToUnvisited: bool\n" +" :type restrict_to_unvisited: bool\n" " :arg begin: The ViewEdge from which to start the chain.\n" " :type begin: :class:`ViewEdge` or None\n" " :arg orientation: The direction to follow to explore the graph. If\n" @@ -49,33 +49,38 @@ PyDoc_STRVAR(ChainingIterator_doc, " :arg brother: \n" " :type brother: ChainingIterator"); -static int ChainingIterator___init__(BPy_ChainingIterator *self, PyObject *args) +static int check_begin(PyObject *obj, void *v) { - PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0; + if (obj != 0 && obj != Py_None && !BPy_ViewEdge_Check(obj)) + return 0; + *((PyObject **)v) = obj; + return 1; +} - if (!PyArg_ParseTuple(args, "|OOOO", &obj1, &obj2, &obj3, &obj4)) - return -1; +static int ChainingIterator___init__(BPy_ChainingIterator *self, PyObject *args, PyObject *kwds) +{ + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"restrict_to_selection", "restrict_to_unvisited", "begin", "orientation", NULL}; + PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0; - if (obj1 && BPy_ChainingIterator_Check(obj1)) { + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_1, &ChainingIterator_Type, &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; - ViewEdge *begin; - if (!obj3 || obj3 == Py_None) - begin = NULL; - 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); } - + else if (PyErr_Clear(), (obj1 = obj2 = obj3 = obj4 = 0), + PyArg_ParseTupleAndKeywords(args, kwds, "|O!O!O&O!", (char **)kwlist_2, + &PyBool_Type, &obj1, &PyBool_Type, &obj2, check_begin, &obj3, + &PyBool_Type, &obj4)) + { + bool restrict_to_selection = (!obj1) ? true : bool_from_PyBool(obj1); + bool restrict_to_unvisited = (!obj2) ? true : bool_from_PyBool(obj2); + ViewEdge *begin = (!obj3 || obj3 == Py_None) ? NULL : ((BPy_ViewEdge *)obj3)->ve; + bool orientation = (!obj4) ? true : bool_from_PyBool(obj4); + self->c_it = new ChainingIterator(restrict_to_selection, restrict_to_unvisited, begin, orientation); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } self->py_ve_it.ve_it = self->c_it; self->py_ve_it.py_it.it = self->c_it; diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp index 8761bc540bb..a4de82be090 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp @@ -16,7 +16,18 @@ PyDoc_STRVAR(CurvePointIterator_doc, "\n" "Class representing an iterator on a curve. Allows an iterating\n" "outside initial vertices. A CurvePoint is instanciated and returned\n" -"by getObject().\n" +"through the .object attribute.\n" +"\n" +".. method:: __init__()\n" +"\n" +" Default constructor.\n" +"\n" +".. method:: __init__(brother)\n" +"\n" +" Copy constructor.\n" +"\n" +" :arg brother: A CurvePointIterator object.\n" +" :type brother: :class:`CurvePointIterator`\n" "\n" ".. method:: __init__(step=0.0)\n" "\n" @@ -26,59 +37,35 @@ PyDoc_STRVAR(CurvePointIterator_doc, " If zero, no resampling is done (i.e., the iterator iterates over\n" " initial vertices).\n" " :type step: float\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: A CurvePointIterator object.\n" -" :type brother: :class:`CurvePointIterator`"); +); -static int CurvePointIterator_init(BPy_CurvePointIterator *self, PyObject *args) +static int CurvePointIterator_init(BPy_CurvePointIterator *self, PyObject *args, PyObject *kwds) { - PyObject *obj = 0; - - if (!PyArg_ParseTuple(args, "|O", &obj)) - return -1; - - 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 { - PyErr_SetString(PyExc_TypeError, "invalid argument"); + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"step", NULL}; + PyObject *brother = 0; + float step; + + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &CurvePointIterator_Type, &brother)) { + if (!brother) + self->cp_it = new CurveInternal::CurvePointIterator(); + else + self->cp_it = new CurveInternal::CurvePointIterator(*(((BPy_CurvePointIterator *)brother)->cp_it)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "f", (char **)kwlist_2, &step)) + { + self->cp_it = new CurveInternal::CurvePointIterator(step); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; } - self->py_it.it = self->cp_it; - return 0; } -PyDoc_STRVAR(CurvePointIterator_cast_to_interface0diterator_doc, -".. method:: cast_to_interface0diterator()\n" -"\n" -" Returns an Interface0DIterator converted from this\n" -" CurvePointIterator. Useful for any call to a function of the\n" -" UnaryFunction0D type.\n" -"\n" -" :return: An Interface0DIterator object converted from the\n" -" iterator.\n" -" :rtype: :class:`Interface0DIterator`"); - -static PyObject * CurvePointIterator_cast_to_interface0diterator(BPy_CurvePointIterator *self) -{ - Interface0DIterator it(self->cp_it->castToInterface0DIterator()); - return BPy_Interface0DIterator_from_Interface0DIterator(it, 0); -} - static PyMethodDef BPy_CurvePointIterator_methods[] = { - {"cast_to_interface0diterator", (PyCFunction) CurvePointIterator_cast_to_interface0diterator, METH_NOARGS, CurvePointIterator_cast_to_interface0diterator_doc}, {NULL, NULL, 0, NULL} }; diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp index fb9ec03648a..9c15eab1aad 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp @@ -16,24 +16,54 @@ PyDoc_STRVAR(Interface0DIterator_doc, "Class defining an iterator over Interface0D elements. An instance of\n" "this iterator is always obtained from a 1D element.\n" "\n" -".. method:: __init__(it)\n" +".. method:: __init__(brother)\n" "\n" " Copy constructor.\n" "\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`Interface0DIterator`"); +" :arg brother: An Interface0DIterator object.\n" +" :type brother: :class:`Interface0DIterator`\n" +"\n" +".. method:: __init__(it)\n" +"\n" +" Construct a nested Interface0DIterator that can be the argument of\n" +" a Function0D.\n" +"\n" +" :arg it: An iterator object to be nested.\n" +" :type it: :class:`SVertexIterator`, :class:`CurvePointIterator`, or\n" +" :class:`StrokeVertexIterator`"); -static int Interface0DIterator_init(BPy_Interface0DIterator *self, PyObject *args) +static int convert_nested_it(PyObject *obj, void *v) { - PyObject *obj = 0; + if (!obj || !BPy_Iterator_Check(obj)) + return 0; + Interface0DIteratorNested *nested_it = dynamic_cast<Interface0DIteratorNested *>(((BPy_Iterator *)obj)->it); + if (!nested_it) + return 0; + *((Interface0DIteratorNested **)v) = nested_it; + return 1; +} - if (!PyArg_ParseTuple(args, "O!", &Interface0DIterator_Type, &obj)) - return -1; +static int Interface0DIterator_init(BPy_Interface0DIterator *self, PyObject *args, PyObject *kwds) +{ + static const char *kwlist_1[] = {"it", NULL}; + static const char *kwlist_2[] = {"brother", NULL}; + Interface0DIteratorNested *nested_it; + PyObject *brother; - self->if0D_it = new Interface0DIterator(*(((BPy_Interface0DIterator *)obj)->if0D_it)); + if (PyArg_ParseTupleAndKeywords(args, kwds, "O&", (char **)kwlist_1, convert_nested_it, &nested_it)) { + self->if0D_it = new Interface0DIterator(nested_it->copy()); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_2, &Interface0DIterator_Type, &brother)) + { + self->if0D_it = new Interface0DIterator(*(((BPy_Interface0DIterator *)brother)->if0D_it)); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } self->py_it.it = self->if0D_it; self->reversed = 0; - return 0; } diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp index 6243e487646..8946ef92eec 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp @@ -23,62 +23,62 @@ PyDoc_STRVAR(SVertexIterator_doc, "\n" " Default constructor.\n" "\n" -".. method:: __init__(it)\n" +".. method:: __init__(brother)\n" "\n" " Copy constructor.\n" "\n" -" :arg it: An SVertexIterator object.\n" -" :type it: :class:`SVertexIterator`\n" +" :arg brother: An SVertexIterator object.\n" +" :type brother: :class:`SVertexIterator`\n" "\n" -".. method:: __init__(v, begin, prev, next, t)\n" +".. method:: __init__(vertex, begin, previous_edge, next_edge, t)\n" "\n" -" Builds an SVertexIterator that starts iteration from an SVertex\n" +" Build an SVertexIterator that starts iteration from an SVertex\n" " object v.\n" "\n" -" :arg v: The SVertex from which the iterator starts iteration.\n" -" :type v: :class:`SVertex`\n" -" :arg begin: The first vertex of a view edge.\n" +" :arg vertex: The SVertex from which the iterator starts iteration.\n" +" :type vertex: :class:`SVertex`\n" +" :arg begin: The first SVertex of a ViewEdge.\n" " :type begin: :class:`SVertex`\n" -" :arg prev: The previous FEdge coming to v.\n" -" :type prev: :class:`FEdge`\n" -" :arg next: The next FEdge going out from v.\n" -" :type next: :class:`FEdge`\n" -" :arg t: The curvilinear abscissa at v.\n" +" :arg previous_edge: The previous FEdge coming to vertex.\n" +" :type previous_edge: :class:`FEdge`\n" +" :arg next_edge: The next FEdge going out from vertex.\n" +" :type next_edge: :class:`FEdge`\n" +" :arg t: The curvilinear abscissa at vertex.\n" " :type t: float"); -static int SVertexIterator_init(BPy_SVertexIterator *self, PyObject *args) +static int SVertexIterator_init(BPy_SVertexIterator *self, PyObject *args, PyObject *kwds) { + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"vertex", "begin", "previous_edge", "next_edge", "t", NULL}; 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 (!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)) { + float t; + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &SVertexIterator_Type, &obj1)) { + if (!obj1) + self->sv_it = new ViewEdgeInternal::SVertexIterator(); + else + self->sv_it = new ViewEdgeInternal::SVertexIterator(*(((BPy_SVertexIterator *)obj1)->sv_it)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!O!f", (char **)kwlist_2, + &SVertex_Type, &obj1, + &SVertex_Type, &obj2, + &FEdge_Type, &obj3, + &FEdge_Type, &obj4, + &t)) + { self->sv_it = new ViewEdgeInternal::SVertexIterator( - ((BPy_SVertex *)obj1)->sv, - ((BPy_SVertex *)obj2)->sv, - ((BPy_FEdge *)obj3)->fe, - ((BPy_FEdge *)obj4)->fe, - f); - - } else { + ((BPy_SVertex *)obj1)->sv, + ((BPy_SVertex *)obj2)->sv, + ((BPy_FEdge *)obj3)->fe, + ((BPy_FEdge *)obj4)->fe, + t); + } + else { PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; } - self->py_it.it = self->sv_it; - return 0; } diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp index 57a9f867d53..4c92e1276ff 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp @@ -30,34 +30,26 @@ PyDoc_STRVAR(StrokeVertexIterator_doc, "\n" " Default constructor.\n" "\n" -".. method:: __init__(it)\n" +".. method:: __init__(brother)\n" "\n" " Copy constructor.\n" "\n" -" :arg it: A StrokeVertexIterator object.\n" -" :type it: :class:`StrokeVertexIterator`"); +" :arg brother: A StrokeVertexIterator object.\n" +" :type brother: :class:`StrokeVertexIterator`"); -static int StrokeVertexIterator_init(BPy_StrokeVertexIterator *self, PyObject *args) +static int StrokeVertexIterator_init(BPy_StrokeVertexIterator *self, PyObject *args, PyObject *kwds) { - PyObject *obj = 0; + static const char *kwlist[] = {"brother", NULL}; + PyObject *brother = 0; - if (!PyArg_ParseTuple(args, "|O", &obj)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &StrokeVertexIterator_Type, &brother)) return -1; - - if (!obj) { + if (!brother) self->sv_it = new StrokeInternal::StrokeVertexIterator(); - - } 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; - } - + else + self->sv_it = new StrokeInternal::StrokeVertexIterator(*(((BPy_StrokeVertexIterator *)brother)->sv_it)); self->py_it.it = self->sv_it; self->reversed = 0; - return 0; } @@ -83,24 +75,7 @@ static PyObject * StrokeVertexIterator_iternext(BPy_StrokeVertexIterator *self) return BPy_StrokeVertex_from_StrokeVertex(*sv); } -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`"); - -static PyObject * StrokeVertexIterator_cast_to_interface0diterator(BPy_StrokeVertexIterator *self) -{ - Interface0DIterator it(self->sv_it->castToInterface0DIterator()); - return BPy_Interface0DIterator_from_Interface0DIterator(it, 0); -} - static PyMethodDef BPy_StrokeVertexIterator_methods[] = { - {"cast_to_interface0diterator", (PyCFunction) StrokeVertexIterator_cast_to_interface0diterator, METH_NOARGS, StrokeVertexIterator_cast_to_interface0diterator_doc}, {NULL, NULL, 0, NULL} }; diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp index 066d223f6e9..e8678fde48c 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp @@ -33,40 +33,43 @@ PyDoc_STRVAR(ViewEdgeIterator_doc, " ViewVertex of begin.\n" " :type orientation: bool\n" "\n" -".. method:: __init__(it)\n" +".. method:: __init__(brother)\n" "\n" " Copy constructor.\n" "\n" -" :arg it: A ViewEdgeIterator object.\n" -" :type it: :class:`ViewEdgeIterator`"); +" :arg brother: A ViewEdgeIterator object.\n" +" :type brother: :class:`ViewEdgeIterator`"); -static int ViewEdgeIterator_init(BPy_ViewEdgeIterator *self, PyObject *args) +static int check_begin(PyObject *obj, void *v) { - PyObject *obj1 = 0, *obj2 = 0; + if (obj != 0 && obj != Py_None && !BPy_ViewEdge_Check(obj)) + return 0; + *((PyObject **)v) = obj; + return 1; +} - if (!PyArg_ParseTuple(args, "O|O", &obj1, &obj2)) - return -1; +static int ViewEdgeIterator_init(BPy_ViewEdgeIterator *self, PyObject *args, PyObject *kwds) +{ + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"begin", "orientation", NULL}; + PyObject *obj1 = 0, *obj2 = 0; - if (BPy_ViewEdgeIterator_Check(obj1)) { + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_1, &ViewEdgeIterator_Type, &obj1)) { self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(*(((BPy_ViewEdgeIterator *)obj1)->ve_it)); - - } else { - ViewEdge *begin; - if (obj1 == Py_None) - begin = NULL; - 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; - + } + else if (PyErr_Clear(), (obj1 = obj2 = 0), + PyArg_ParseTupleAndKeywords(args, kwds, "|O&O!", (char **)kwlist_2, + check_begin, &obj1, &PyBool_Type, &obj2)) + { + ViewEdge *begin = (!obj1 || obj1 == Py_None) ? NULL : ((BPy_ViewEdge *)obj1)->ve; + bool orientation = (!obj2) ? true : bool_from_PyBool(obj2); self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(begin, orientation); } - + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } self->py_it.it = self->ve_it; - return 0; } diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp index e3dbb089d49..086109e56d1 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp @@ -29,25 +29,19 @@ PyDoc_STRVAR(orientedViewEdgeIterator_doc, " :arg iBrother: An orientedViewEdgeIterator object.\n" " :type iBrother: :class:`orientedViewEdgeIterator`"); -static int orientedViewEdgeIterator_init(BPy_orientedViewEdgeIterator *self, PyObject *args) +static int orientedViewEdgeIterator_init(BPy_orientedViewEdgeIterator *self, PyObject *args, PyObject *kwds) { - PyObject *obj = 0; + static const char *kwlist[] = {"brother", NULL}; + PyObject *brother = 0; - if (!PyArg_ParseTuple(args, "|O", &obj)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &orientedViewEdgeIterator_Type, &brother)) return -1; - - if (!obj) + if (!brother) self->ove_it = new ViewVertexInternal::orientedViewEdgeIterator(); - 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; - } - + else + self->ove_it = new ViewVertexInternal::orientedViewEdgeIterator(*(((BPy_orientedViewEdgeIterator *)brother)->ove_it)); self->py_it.it = self->ove_it; self->reversed = 0; - return 0; } |