From 3010f2b753f2397256861816504b8e7d697632db Mon Sep 17 00:00:00 2001 From: Maxime Curioni Date: Thu, 31 Jul 2008 08:50:12 +0000 Subject: soc-2008-mxcurioni: the native Python system now supports cross-language polymorphism for the following classes: BinaryPredicate0D (__call__), BinaryPredicate1D (__call__), UnaryPredicate0D (__call__), UnaryPredicate1D (__call__), StrokeShader (shade), ChainingIterator (init, traverse). Other methods could easily be supported in the future. The method now works as planned for the contour style. For style modules with Python shaders, there still is a problem that I will fix right away. --- .../intern/python/BPy_BinaryPredicate0D.cpp | 2 + .../intern/python/BPy_BinaryPredicate1D.cpp | 1 + .../freestyle/intern/python/BPy_Convert.cpp | 9 ++ .../blender/freestyle/intern/python/BPy_Convert.h | 1 + .../freestyle/intern/python/BPy_Operators.cpp | 26 ++-- .../freestyle/intern/python/BPy_StrokeShader.cpp | 1 + .../freestyle/intern/python/BPy_UnaryFunction0D.h | 1 + .../freestyle/intern/python/BPy_UnaryFunction1D.h | 1 + .../intern/python/BPy_UnaryPredicate0D.cpp | 1 + .../intern/python/BPy_UnaryPredicate1D.cpp | 1 + .../blender/freestyle/intern/python/Director.cpp | 82 +++++++++++- source/blender/freestyle/intern/python/Director.h | 67 +++++++--- .../python/Iterator/BPy_ChainingIterator.cpp | 2 + .../freestyle/intern/stroke/ChainingIterators.h | 38 +++++- .../blender/freestyle/intern/stroke/Predicates0D.h | 34 ++++- .../blender/freestyle/intern/stroke/Predicates1D.h | 31 +++-- source/blender/freestyle/intern/stroke/Stroke.h | 1 + .../blender/freestyle/intern/stroke/StrokeShader.h | 15 ++- .../freestyle/intern/view_map/Functions0D.h | 2 +- .../freestyle/intern/view_map/Functions1D.h | 2 +- .../style_modules_blender/freestyle_init.py | 138 ++++++++++----------- 21 files changed, 325 insertions(+), 131 deletions(-) diff --git a/source/blender/freestyle/intern/python/BPy_BinaryPredicate0D.cpp b/source/blender/freestyle/intern/python/BPy_BinaryPredicate0D.cpp index 9c3247b30b8..bcd98a42189 100644 --- a/source/blender/freestyle/intern/python/BPy_BinaryPredicate0D.cpp +++ b/source/blender/freestyle/intern/python/BPy_BinaryPredicate0D.cpp @@ -127,6 +127,8 @@ PyMODINIT_FUNC BinaryPredicate0D_Init( PyObject *module ) int BinaryPredicate0D___init__(BPy_BinaryPredicate0D *self, PyObject *args, PyObject *kwds) { self->bp0D = new BinaryPredicate0D(); + self->bp0D->py_bp0D = (PyObject *) self; + return 0; } diff --git a/source/blender/freestyle/intern/python/BPy_BinaryPredicate1D.cpp b/source/blender/freestyle/intern/python/BPy_BinaryPredicate1D.cpp index 545807fc277..9f7e0359ec8 100644 --- a/source/blender/freestyle/intern/python/BPy_BinaryPredicate1D.cpp +++ b/source/blender/freestyle/intern/python/BPy_BinaryPredicate1D.cpp @@ -159,6 +159,7 @@ PyMODINIT_FUNC BinaryPredicate1D_Init( PyObject *module ) int BinaryPredicate1D___init__(BPy_BinaryPredicate1D *self, PyObject *args, PyObject *kwds) { self->bp1D = new BinaryPredicate1D(); + self->bp1D->py_bp1D = (PyObject *) self; return 0; } diff --git a/source/blender/freestyle/intern/python/BPy_Convert.cpp b/source/blender/freestyle/intern/python/BPy_Convert.cpp index d7b6fa8bd33..0b136b7702f 100644 --- a/source/blender/freestyle/intern/python/BPy_Convert.cpp +++ b/source/blender/freestyle/intern/python/BPy_Convert.cpp @@ -11,6 +11,7 @@ #include "Interface0D/BPy_ViewVertex.h" #include "BPy_Interface1D.h" #include "Interface1D/BPy_FEdge.h" +#include "Interface1D/BPy_Stroke.h" #include "Interface1D/BPy_ViewEdge.h" #include "BPy_Nature.h" #include "BPy_MediumType.h" @@ -115,6 +116,14 @@ PyObject * BPy_Nature_from_Nature( unsigned short n ) { return py_n; } +PyObject * BPy_Stroke_from_Stroke( Stroke& s ) { + PyObject *py_s = Stroke_Type.tp_new( &Stroke_Type, 0, 0 ); + ((BPy_Stroke *) py_s)->s = new Stroke( s ); + ((BPy_Stroke *) py_s)->py_if1D.if1D = ((BPy_Stroke *) py_s)->s; + + return py_s; +} + PyObject * BPy_StrokeAttribute_from_StrokeAttribute( StrokeAttribute& sa ) { PyObject *py_sa = StrokeAttribute_Type.tp_new( &StrokeAttribute_Type, 0, 0 ); ((BPy_StrokeAttribute *) py_sa)->sa = new StrokeAttribute( sa ); diff --git a/source/blender/freestyle/intern/python/BPy_Convert.h b/source/blender/freestyle/intern/python/BPy_Convert.h index 9e743f4b233..4bfaf4c1e17 100644 --- a/source/blender/freestyle/intern/python/BPy_Convert.h +++ b/source/blender/freestyle/intern/python/BPy_Convert.h @@ -80,6 +80,7 @@ PyObject * BPy_FrsMaterial_from_Material( Material& m ); PyObject * BPy_Nature_from_Nature( unsigned short n ); PyObject * BPy_MediumType_from_MediumType( int n ); PyObject * BPy_SShape_from_SShape( SShape& ss ); +PyObject * BPy_Stroke_from_Stroke( Stroke& s ); PyObject * BPy_StrokeAttribute_from_StrokeAttribute( StrokeAttribute& sa ); PyObject * BPy_StrokeVertex_from_StrokeVertex( StrokeVertex& sv ); PyObject * BPy_SVertex_from_SVertex( SVertex& sv ); diff --git a/source/blender/freestyle/intern/python/BPy_Operators.cpp b/source/blender/freestyle/intern/python/BPy_Operators.cpp index 850b4cb5bad..ab64f5bc6eb 100644 --- a/source/blender/freestyle/intern/python/BPy_Operators.cpp +++ b/source/blender/freestyle/intern/python/BPy_Operators.cpp @@ -164,21 +164,19 @@ PyObject * Operators_select(BPy_Operators* self, PyObject *args) Py_RETURN_NONE; } - UnaryPredicate1D *up1D = ((BPy_UnaryPredicate1D *) obj)->up1D; - if( PyObject_HasAttrString( obj, "__call__") ) - up1D->setPythonObject( obj ); - - Operators::select(*up1D); + Operators::select(*( ((BPy_UnaryPredicate1D *) obj)->up1D )); Py_RETURN_NONE; } +// CHANGE: first parameter is a chaining iterator, not just a view + PyObject * Operators_chain(BPy_Operators* self, PyObject *args) { PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0; if(!( PyArg_ParseTuple(args, "OO|O", &obj1, &obj2, &obj3) && - BPy_ViewEdgeIterator_Check(obj1) && ((BPy_ViewEdgeIterator *) obj1)->ve_it && + BPy_ChainingIterator_Check(obj1) && ((BPy_ChainingIterator *) obj1)->c_it && BPy_UnaryPredicate1D_Check(obj2) && ((BPy_UnaryPredicate1D *) obj2)->up1D )) { cout << "ERROR: Operators_chain" << endl; Py_RETURN_NONE; @@ -186,12 +184,13 @@ PyObject * Operators_chain(BPy_Operators* self, PyObject *args) if( !obj3 ) { - Operators::chain( *( ((BPy_ViewEdgeIterator *) obj1)->ve_it ), + Operators::chain( *( ((BPy_ChainingIterator *) obj1)->c_it ), *( ((BPy_UnaryPredicate1D *) obj2)->up1D ) ); } else if( BPy_UnaryFunction1DVoid_Check(obj3) && ((BPy_UnaryFunction1DVoid *) obj3)->uf1D_void ) { - Operators::chain( *( ((BPy_ViewEdgeIterator *) obj1)->ve_it ), + + Operators::chain( *( ((BPy_ChainingIterator *) obj1)->c_it ), *( ((BPy_UnaryPredicate1D *) obj2)->up1D ), *( ((BPy_UnaryFunction1DVoid *) obj3)->uf1D_void ) ); @@ -209,7 +208,7 @@ PyObject * Operators_bidirectionalChain(BPy_Operators* self, PyObject *args) cout << "ERROR: Operators_bidirectionalChain" << endl; Py_RETURN_NONE; } - + if( !obj2 ) { Operators::bidirectionalChain( *( ((BPy_ChainingIterator *) obj1)->c_it ) ); @@ -234,7 +233,7 @@ PyObject * Operators_sequentialSplit(BPy_Operators* self, PyObject *args) cout << "ERROR: Operators_sequentialSplit" << endl; Py_RETURN_NONE; } - + if( obj2 && BPy_UnaryPredicate0D_Check(obj2) ) { Operators::sequentialSplit( *( ((BPy_UnaryPredicate0D *) obj1)->up0D ), @@ -266,7 +265,7 @@ PyObject * Operators_recursiveSplit(BPy_Operators* self, PyObject *args) if( BPy_UnaryPredicate1D_Check(obj2) && ((BPy_UnaryPredicate1D *) obj2)->up1D ) { float f = ( obj3 && PyFloat_Check(obj3) ) ? PyFloat_AsDouble(obj3) : 0.0; - + Operators::recursiveSplit( *( ((BPy_UnaryFunction0DDouble *) obj1)->uf0D_double ), *( ((BPy_UnaryPredicate1D *) obj2)->up1D ), f ); @@ -313,8 +312,9 @@ PyObject * Operators_create(BPy_Operators* self, PyObject *args) vector shaders; for( int i = 0; i < PyList_Size(obj2); i++) { PyObject *py_ss = PyList_GetItem(obj2,i); - if( BPy_StrokeShader_Check(py_ss) ) - shaders.push_back( ((BPy_StrokeShader *) py_ss)->ss ); + + if( BPy_StrokeShader_Check(py_ss) ) + shaders.push_back( ((BPy_StrokeShader *) py_ss)->ss ); } Operators::create( *( ((BPy_UnaryPredicate1D *) obj1)->up1D ), shaders); diff --git a/source/blender/freestyle/intern/python/BPy_StrokeShader.cpp b/source/blender/freestyle/intern/python/BPy_StrokeShader.cpp index a6d2ae1e512..3b756b40d9b 100644 --- a/source/blender/freestyle/intern/python/BPy_StrokeShader.cpp +++ b/source/blender/freestyle/intern/python/BPy_StrokeShader.cpp @@ -254,6 +254,7 @@ PyMODINIT_FUNC StrokeShader_Init( PyObject *module ) int StrokeShader___init__(BPy_StrokeShader *self, PyObject *args, PyObject *kwds) { self->ss = new StrokeShader(); + self->ss->py_ss = (PyObject *) self; return 0; } diff --git a/source/blender/freestyle/intern/python/BPy_UnaryFunction0D.h b/source/blender/freestyle/intern/python/BPy_UnaryFunction0D.h index 0ab0bfbdc2e..d95230ecccd 100644 --- a/source/blender/freestyle/intern/python/BPy_UnaryFunction0D.h +++ b/source/blender/freestyle/intern/python/BPy_UnaryFunction0D.h @@ -18,6 +18,7 @@ extern PyTypeObject UnaryFunction0D_Type; /*---------------------------Python BPy_UnaryFunction0D structure definition----------*/ typedef struct { PyObject_HEAD + PyObject *py_uf0D; } BPy_UnaryFunction0D; /*---------------------------Python BPy_UnaryFunction0D visible prototypes-----------*/ diff --git a/source/blender/freestyle/intern/python/BPy_UnaryFunction1D.h b/source/blender/freestyle/intern/python/BPy_UnaryFunction1D.h index f33fcf48da4..571ef8a5d25 100644 --- a/source/blender/freestyle/intern/python/BPy_UnaryFunction1D.h +++ b/source/blender/freestyle/intern/python/BPy_UnaryFunction1D.h @@ -18,6 +18,7 @@ extern PyTypeObject UnaryFunction1D_Type; /*---------------------------Python BPy_UnaryFunction1D structure definition----------*/ typedef struct { PyObject_HEAD + PyObject *py_uf1D; } BPy_UnaryFunction1D; /*---------------------------Python BPy_UnaryFunction1D visible prototypes-----------*/ diff --git a/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp b/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp index 4fef63eae9b..db708c7830b 100644 --- a/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp +++ b/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp @@ -139,6 +139,7 @@ PyMODINIT_FUNC UnaryPredicate0D_Init( PyObject *module ) int UnaryPredicate0D___init__(BPy_UnaryPredicate0D *self, PyObject *args, PyObject *kwds) { self->up0D = new UnaryPredicate0D(); + self->up0D->py_up0D = (PyObject *) self; return 0; } diff --git a/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp b/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp index 14eb041c480..f2b2c7b9b53 100644 --- a/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp +++ b/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp @@ -181,6 +181,7 @@ PyMODINIT_FUNC UnaryPredicate1D_Init( PyObject *module ) int UnaryPredicate1D___init__(BPy_UnaryPredicate1D *self, PyObject *args, PyObject *kwds) { self->up1D = new UnaryPredicate1D(); + self->up1D->py_up1D = (PyObject *) self; return 0; } diff --git a/source/blender/freestyle/intern/python/Director.cpp b/source/blender/freestyle/intern/python/Director.cpp index 6acdc665a0c..d3aff4a65f2 100644 --- a/source/blender/freestyle/intern/python/Director.cpp +++ b/source/blender/freestyle/intern/python/Director.cpp @@ -2,11 +2,85 @@ #include "BPy_Convert.h" -bool director_BPy_UnaryPredicate1D___call__( PyObject *py_up1D, Interface1D& if1D) { - cout << "Polymorphism works" << endl; +#include "BPy_BinaryPredicate0D.h" +#include "BPy_BinaryPredicate1D.h" +#include "BPy_UnaryFunction0D.h" +#include "BPy_UnaryFunction1D.h" +#include "BPy_UnaryPredicate0D.h" +#include "BPy_UnaryPredicate1D.h" +#include "BPy_StrokeShader.h" +#include "Iterator/BPy_ChainingIterator.h" +#include "Interface1D/BPy_Stroke.h" +#include "Interface1D/BPy_ViewEdge.h" - PyObject *method = PyObject_GetAttrString( py_up1D, "__call__"); - PyObject *result = PyObject_CallFunction(method, "O", BPy_Interface1D_from_Interface1D(if1D) ); +// BinaryPredicate0D: __call__ +bool Director_BPy_BinaryPredicate0D___call__( PyObject *obj, Interface0D& i1, Interface0D& i2) { + PyObject *result = PyObject_CallMethod( obj, "__call__", "OO", BPy_Interface0D_from_Interface0D(i1), BPy_Interface0D_from_Interface0D(i2) ); + + return bool_from_PyBool(result); +} + + +// BinaryPredicate1D: __call__ +bool Director_BPy_BinaryPredicate1D___call__( PyObject *obj, Interface1D& i1, Interface1D& i2) { + PyObject *result = PyObject_CallMethod( obj, "__call__", "OO", BPy_Interface1D_from_Interface1D(i1), BPy_Interface1D_from_Interface1D(i2) ); + + return bool_from_PyBool(result); +} + + +// UnaryPredicate0D: __call__ +bool Director_BPy_UnaryPredicate0D___call__( PyObject *obj, Interface0DIterator& if0D_it) { + PyObject *result = PyObject_CallMethod( obj, "__call__", "O", BPy_Interface0DIterator_from_Interface0DIterator(if0D_it) ); + + return bool_from_PyBool(result); +} + + +// UnaryPredicate1D: __call__ +bool Director_BPy_UnaryPredicate1D___call__( PyObject *obj, Interface1D& if1D) { + PyObject *result = PyObject_CallMethod( obj, "__call__", "O", BPy_Interface1D_from_Interface1D(if1D) ); return bool_from_PyBool(result); } + + +// StrokeShader: shade +void Director_BPy_StrokeShader_shade( PyObject *obj, Stroke& s) { + PyObject_CallMethod( obj, "shade", "O", BPy_Stroke_from_Stroke(s) ); +} + +// ChainingIterator: init, traverse +void Director_BPy_ChainingIterator_init( PyObject *obj ) { + PyObject_CallMethod( obj, "init", "", 0 ); +} + +ViewEdge * Director_BPy_ChainingIterator_traverse( PyObject *obj, AdjacencyIterator& a_it ) { + PyObject *result = PyObject_CallMethod( obj, "traverse", "O", BPy_AdjacencyIterator_from_AdjacencyIterator(a_it) ); + + return ((BPy_ViewEdge *) result)->ve; +} + + +// BPy_UnaryFunction{0D,1D}: __call__ +// BPy_UnaryFunction0DDouble +// BPy_UnaryFunction0DEdgeNature +// BPy_UnaryFunction0DFloat +// BPy_UnaryFunction0DId +// BPy_UnaryFunction0DMaterial +// BPy_UnaryFunction0DUnsigned +// BPy_UnaryFunction0DVec2f +// BPy_UnaryFunction0DVec3f +// BPy_UnaryFunction0DVectorViewShape +// BPy_UnaryFunction0DViewShape + +// BPy_UnaryFunction1DDouble +// BPy_UnaryFunction1DEdgeNature +// BPy_UnaryFunction1DFloat +// BPy_UnaryFunction1DUnsigned +// BPy_UnaryFunction1DVec2f +// BPy_UnaryFunction1DVec3f +// BPy_UnaryFunction1DVectorViewShape +// BPy_UnaryFunction1DVoid + + diff --git a/source/blender/freestyle/intern/python/Director.h b/source/blender/freestyle/intern/python/Director.h index 7114b124ffb..95ab16047a8 100644 --- a/source/blender/freestyle/intern/python/Director.h +++ b/source/blender/freestyle/intern/python/Director.h @@ -1,34 +1,65 @@ #ifndef FREESTYLE_PYTHON_DIRECTOR # define FREESTYLE_PYTHON_DIRECTOR -#include "../view_map/Interface1D.h" +class Interface0D; +class Interface1D; +class Interface0DIterator; +class Stroke; +class AdjacencyIterator; +class ViewEdge; #ifdef __cplusplus extern "C" { #endif -/////////////////////////////////////////////////////////////////////////////////////////// - #include -// SWIG directors -// ---------------------------- -// ViewEdgeInternal::ViewEdgeIterator; -// ChainingIterator; -// ChainSilhouetteIterator; -// ChainPredicateIterator; -// UnaryPredicate0D; -// UnaryPredicate1D; -// BinaryPredicate1D; -// StrokeShader; - -bool director_BPy_UnaryPredicate1D___call__( PyObject *py_up1D, Interface1D& if1D); - -/////////////////////////////////////////////////////////////////////////////////////////// - #ifdef __cplusplus } #endif +// BinaryPredicate0D: __call__ +bool Director_BPy_BinaryPredicate0D___call__( PyObject *obj, Interface0D& i1, Interface0D& i2); + +// BinaryPredicate1D: __call__ +bool Director_BPy_BinaryPredicate1D___call__( PyObject *obj, Interface1D& i1, Interface1D& i2); + +// UnaryPredicate0D: __call__ +bool Director_BPy_UnaryPredicate0D___call__( PyObject *obj, Interface0DIterator& if0D_it); + +// UnaryPredicate1D: __call__ +bool Director_BPy_UnaryPredicate1D___call__( PyObject *obj, Interface1D& if1D); + +// StrokeShader: shade +void Director_BPy_StrokeShader_shade( PyObject *obj, Stroke& s); + +// ChainingIterator: init, traverse +void Director_BPy_ChainingIterator_init( PyObject *obj ); +ViewEdge * Director_BPy_ChainingIterator_traverse( PyObject *obj, AdjacencyIterator& a_it ); + +// BPy_UnaryFunction0DDouble +double Director_BPy_UnaryFunction0DDouble___call__( PyObject *obj, Interface0DIterator& if0D_it); +// BPy_UnaryFunction0DEdgeNature +// BPy_UnaryFunction0DFloat +// BPy_UnaryFunction0DId +// BPy_UnaryFunction0DMaterial +// BPy_UnaryFunction0DUnsigned +// BPy_UnaryFunction0DVec2f +// BPy_UnaryFunction0DVec3f +// BPy_UnaryFunction0DVectorViewShape +// BPy_UnaryFunction0DViewShape + +// BPy_UnaryFunction1DDouble +// BPy_UnaryFunction1DEdgeNature +// BPy_UnaryFunction1DFloat +// BPy_UnaryFunction1DUnsigned +// BPy_UnaryFunction1DVec2f +// BPy_UnaryFunction1DVec3f +// BPy_UnaryFunction1DVectorViewShape +// BPy_UnaryFunction1DVoid +void Director_BPy_UnaryFunction1DVoid___call__( PyObject *obj, Interface1D& if1D); + + + #endif // FREESTYLE_PYTHON_DIRECTOR diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp index 525b0697fa7..f33fe0e17bc 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp @@ -139,6 +139,8 @@ int ChainingIterator___init__(BPy_ChainingIterator *self, PyObject *args ) self->py_ve_it.ve_it = self->c_it; self->py_ve_it.py_it.it = self->c_it; + self->c_it->py_c_it = (PyObject *) self; + return 0; } diff --git a/source/blender/freestyle/intern/stroke/ChainingIterators.h b/source/blender/freestyle/intern/stroke/ChainingIterators.h index b01c895d89a..1f33f99db67 100755 --- a/source/blender/freestyle/intern/stroke/ChainingIterators.h +++ b/source/blender/freestyle/intern/stroke/ChainingIterators.h @@ -36,6 +36,8 @@ #include "../system/Iterator.h" //soc +# include "../python/Director.h" + //using namespace ViewEdgeInternal; // @@ -135,6 +137,9 @@ protected: bool _increment; //true if we're currently incrementing, false when decrementing public: + + PyObject *py_c_it; + /*! Builds a Chaining Iterator from the first ViewEdge used for iteration * and its orientation. * \param iRestrictToSelection @@ -154,6 +159,7 @@ public: _restrictToSelection = iRestrictToSelection; _restrictToUnvisited = iRestrictToUnvisited; _increment = true; + py_c_it = 0; } /*! Copy constructor */ @@ -162,6 +168,7 @@ public: _restrictToSelection = brother._restrictToSelection; _restrictToUnvisited = brother._restrictToUnvisited; _increment = brother._increment; + py_c_it = brother.py_c_it; } /*! Returns the string "ChainingIterator" */ @@ -176,7 +183,16 @@ public: * history information that you * might want to keep. */ - virtual void init(){} + virtual void init() { + string name( py_c_it ? PyString_AsString(PyObject_CallMethod(py_c_it, "getExactTypeName", "")) : getExactTypeName() ); + + if( py_c_it && PyObject_HasAttrString(py_c_it, "init") ) { + Director_BPy_ChainingIterator_init( py_c_it ); + } else { + cerr << "Warning: " << name << " method init() not implemented" << endl; + } + + } /*! This method iterates over the potential next * ViewEdges and returns the one that will be @@ -190,10 +206,16 @@ public: * rules by only iterating over the valid ViewEdges. */ virtual ViewEdge * traverse(const AdjacencyIterator &it){ - cerr << "Warning: the traverse method was not defined" << endl; - return 0; + string name( py_c_it ? PyString_AsString(PyObject_CallMethod(py_c_it, "getExactTypeName", "")) : getExactTypeName() ); + + if( py_c_it && PyObject_HasAttrString(py_c_it, "traverse") ) { + return Director_BPy_ChainingIterator_traverse(py_c_it, const_cast(it) ); + } else { + cerr << "Warning: the " << name << " traverse method was not defined" << endl; + return 0; + } } - + /* accessors */ /*! Returns true if the orientation of the current ViewEdge * corresponds to its natural orientation @@ -274,6 +296,8 @@ public: */ virtual ViewEdge * traverse(const AdjacencyIterator& it); + /*! Inits the iterator context */ + virtual void init() {} }; // @@ -368,7 +392,11 @@ public: * followed next. * When reaching the end of a chain, 0 is returned. */ - virtual ViewEdge * traverse(const AdjacencyIterator &it); + virtual ViewEdge * traverse(const AdjacencyIterator &it); + + /*! Inits the iterator context */ + virtual void init() {} + }; #endif // CHAININGITERATORS_H diff --git a/source/blender/freestyle/intern/stroke/Predicates0D.h b/source/blender/freestyle/intern/stroke/Predicates0D.h index 4c2dfacdf98..0318c1742ec 100755 --- a/source/blender/freestyle/intern/stroke/Predicates0D.h +++ b/source/blender/freestyle/intern/stroke/Predicates0D.h @@ -32,6 +32,8 @@ # include "../view_map/Functions0D.h" +# include "../python/Director.h" + // // UnaryPredicate0D (base class for predicates in 0D) // @@ -48,8 +50,11 @@ class UnaryPredicate0D { public: + + PyObject *py_up0D; + /*! Default constructor. */ - UnaryPredicate0D() {} + UnaryPredicate0D() { py_up0D = 0; } /*! Destructor. */ virtual ~UnaryPredicate0D() {} /*! Returns the string of the name @@ -68,9 +73,16 @@ public: * false otherwise. */ virtual bool operator()(Interface0DIterator& it) { - cerr << "Warning: operator() not implemented" << endl; - return false; + string name( py_up0D ? PyString_AsString(PyObject_CallMethod(py_up0D, "getName", "")) : getName() ); + + if( py_up0D && PyObject_HasAttrString(py_up0D, "__call__") ) { + return Director_BPy_UnaryPredicate0D___call__(py_up0D, it); + } else { + cerr << "Warning: " << name << " operator() not implemented" << endl; + return false; + } } + }; @@ -88,8 +100,11 @@ public: class BinaryPredicate0D { public: + + PyObject *py_bp0D; + /*! Default constructor. */ - BinaryPredicate0D() {} + BinaryPredicate0D() { py_bp0D = 0; } /*! Destructor. */ virtual ~BinaryPredicate0D() {} /*! Returns the string of the name of the @@ -108,9 +123,16 @@ public: * \return true or false. */ virtual bool operator()(Interface0D& inter1, Interface0D& inter2) { - cerr << "Warning: operator() not implemented" << endl; - return false; + string name( py_bp0D ? PyString_AsString(PyObject_CallMethod(py_bp0D, "getName", "")) : getName() ); + + if( py_bp0D && PyObject_HasAttrString(py_bp0D, "__call__") ) { + return Director_BPy_BinaryPredicate0D___call__(py_bp0D, inter1, inter2); + } else { + cerr << "Warning: " << name << " operator() not implemented" << endl; + return false; + } } + }; diff --git a/source/blender/freestyle/intern/stroke/Predicates1D.h b/source/blender/freestyle/intern/stroke/Predicates1D.h index 98148361bb7..8c6f5a9bfa4 100755 --- a/source/blender/freestyle/intern/stroke/Predicates1D.h +++ b/source/blender/freestyle/intern/stroke/Predicates1D.h @@ -58,9 +58,7 @@ public: PyObject *py_up1D; /*! Default constructor. */ - UnaryPredicate1D() { - py_up1D = 0; - } + UnaryPredicate1D() { py_up1D = 0; } /*! Destructor. */ virtual ~UnaryPredicate1D() {} /*! Returns the string of the name @@ -78,17 +76,16 @@ public: * false otherwise. */ virtual bool operator()(Interface1D& inter) { + string name( py_up1D ? PyString_AsString(PyObject_CallMethod(py_up1D, "getName", "")) : getName() ); - if( py_up1D ) { - return director_BPy_UnaryPredicate1D___call__(py_up1D, inter); + if( py_up1D && PyObject_HasAttrString(py_up1D, "__call__")) { + return Director_BPy_UnaryPredicate1D___call__(py_up1D, inter); } else { - cerr << "Warning: operator() not implemented" << endl; - return false; + cerr << "Warning: " << name << " operator() not implemented" << endl; + return false; } } - inline void setPythonObject(PyObject *_py_up1D) { py_up1D = _py_up1D; } - }; @@ -106,8 +103,11 @@ public: class BinaryPredicate1D { public: + + PyObject *py_bp1D; + /*! Default constructor. */ - BinaryPredicate1D() {} + BinaryPredicate1D() { py_bp1D = 0; } /*! Destructor. */ virtual ~BinaryPredicate1D() {} /*! Returns the string of the name of the @@ -125,9 +125,16 @@ public: * \return true or false. */ virtual bool operator()(Interface1D& inter1, Interface1D& inter2) { - cerr << "Warning: operator() not implemented" << endl; - return false; + string name( py_bp1D ? PyString_AsString(PyObject_CallMethod(py_bp1D, "getName", "")) : getName() ); + + if( py_bp1D && py_bp1D && PyObject_HasAttrString(py_bp1D, "__call__") ) { + return Director_BPy_BinaryPredicate1D___call__(py_bp1D, inter1, inter2); + } else { + cerr << "Warning: " << name << " operator() not implemented" << endl; + return false; + } } + }; diff --git a/source/blender/freestyle/intern/stroke/Stroke.h b/source/blender/freestyle/intern/stroke/Stroke.h index 8e4e5e24a2c..3df57341e5f 100755 --- a/source/blender/freestyle/intern/stroke/Stroke.h +++ b/source/blender/freestyle/intern/stroke/Stroke.h @@ -38,6 +38,7 @@ # include "../view_map/Interface1D.h" # include "../system/StringUtils.h" + // // StrokeAttribute // diff --git a/source/blender/freestyle/intern/stroke/StrokeShader.h b/source/blender/freestyle/intern/stroke/StrokeShader.h index fa1289f6e0f..f92895564d8 100755 --- a/source/blender/freestyle/intern/stroke/StrokeShader.h +++ b/source/blender/freestyle/intern/stroke/StrokeShader.h @@ -33,6 +33,8 @@ # include # include +# include "../python/Director.h" + // // StrokeShader base class // @@ -69,8 +71,11 @@ class Stroke; class LIB_STROKE_EXPORT StrokeShader { public: + + PyObject *py_ss; + /*! Default constructor. */ - StrokeShader() {} + StrokeShader() { py_ss = 0; } /*! Destructor. */ virtual ~StrokeShader() {} /*! Returns the string corresponding to the @@ -111,7 +116,13 @@ public: * as Color, Thickness, Geometry...) */ virtual void shade(Stroke& ioStroke) const { - cerr << "Warning: method shade() not implemented" << endl; + string name( py_ss ? PyString_AsString(PyObject_CallMethod(py_ss, "getName", "")) : getName() ); + + if( py_ss && PyObject_HasAttrString(py_ss, "shade") ) { + return Director_BPy_StrokeShader_shade(py_ss, ioStroke); + } else { + cerr << "Warning: " << name << " method shade() not implemented" << endl; + } } }; diff --git a/source/blender/freestyle/intern/view_map/Functions0D.h b/source/blender/freestyle/intern/view_map/Functions0D.h index 3160546da2f..1ad35da8d91 100755 --- a/source/blender/freestyle/intern/view_map/Functions0D.h +++ b/source/blender/freestyle/intern/view_map/Functions0D.h @@ -90,7 +90,7 @@ public: * \return the result of the function of type T. */ virtual T operator()(Interface0DIterator& iter) { - cerr << "Warning: operator() not implemented" << endl; + cerr << "Warning: UnaryFunction0D operator() not implemented" << endl; return T(); } }; diff --git a/source/blender/freestyle/intern/view_map/Functions1D.h b/source/blender/freestyle/intern/view_map/Functions1D.h index c92d12ff330..072733b985d 100755 --- a/source/blender/freestyle/intern/view_map/Functions1D.h +++ b/source/blender/freestyle/intern/view_map/Functions1D.h @@ -92,7 +92,7 @@ public: * \return the result of the function of type T. */ virtual T operator()(Interface1D& inter) { - cerr << "Warning: operator() not implemented" << endl; + cerr << "Warning: UnaryFunction1D operator() not implemented" << endl; return T(0); } /*! Sets the integration method */ diff --git a/source/blender/freestyle/style_modules_blender/freestyle_init.py b/source/blender/freestyle/style_modules_blender/freestyle_init.py index 06b8f933114..e4ad8a9f769 100644 --- a/source/blender/freestyle/style_modules_blender/freestyle_init.py +++ b/source/blender/freestyle/style_modules_blender/freestyle_init.py @@ -49,10 +49,10 @@ class StrokeShader(Blender.Freestyle.StrokeShader): pass class UnaryFunction0D(Blender.Freestyle.UnaryFunction0D): - def __call__(*args): return Blender.Freestyle.UnaryFunction0D.__call__(*args) + pass class UnaryFunction1D(Blender.Freestyle.UnaryFunction1D): - def __call__(*args): return Blender.Freestyle.UnaryFunction1D.__call__(*args) + pass class UnaryPredicate0D(Blender.Freestyle.UnaryPredicate0D): pass @@ -67,19 +67,19 @@ class ViewShape(Blender.Freestyle.ViewShape): pass class FalseBP1D(Blender.Freestyle.FalseBP1D): - def __call__(*args): return Blender.Freestyle.FalseBP1D.__call__(*args) + pass class Length2DBP1D(Blender.Freestyle.Length2DBP1D): - def __call__(*args): return Blender.Freestyle.Length2DBP1D.__call__(*args) + pass class SameShapeIdBP1D(Blender.Freestyle.SameShapeIdBP1D): - def __call__(*args): return Blender.Freestyle.SameShapeIdBP1D.__call__(*args) + pass class TrueBP1D(Blender.Freestyle.TrueBP1D): - def __call__(*args): return Blender.Freestyle.TrueBP1D.__call__(*args) + pass class ViewMapGradientNormBP1D(Blender.Freestyle.ViewMapGradientNormBP1D): - def __call__(*args): return Blender.Freestyle.ViewMapGradientNormBP1D.__call__(*args) + pass class CurvePoint(Blender.Freestyle.CurvePoint): pass @@ -250,37 +250,37 @@ class UnaryFunction1DVoid(Blender.Freestyle.UnaryFunction1DVoid): pass class FalseUP0D(Blender.Freestyle.FalseUP0D): - def __call__(*args): return Blender.Freestyle.FalseUP0D.__call__(*args) + pass class TrueUP0D(Blender.Freestyle.TrueUP0D): - def __call__(*args): return Blender.Freestyle.TrueUP0D.__call__(*args) + pass class ContourUP1D(Blender.Freestyle.ContourUP1D): - def __call__(*args): return Blender.Freestyle.ContourUP1D.__call__(*args) + pass class DensityLowerThanUP1D(Blender.Freestyle.DensityLowerThanUP1D): - def __call__(*args): return Blender.Freestyle.DensityLowerThanUP1D.__call__(*args) + pass class EqualToChainingTimeStampUP1D(Blender.Freestyle.EqualToChainingTimeStampUP1D): - def __call__(*args): return Blender.Freestyle.EqualToChainingTimeStampUP1D.__call__(*args) + pass class EqualToTimeStampUP1D(Blender.Freestyle.EqualToTimeStampUP1D): - def __call__(*args): return Blender.Freestyle.EqualToTimeStampUP1D.__call__(*args) + pass class ExternalContourUP1D(Blender.Freestyle.ExternalContourUP1D): - def __call__(*args): return Blender.Freestyle.ExternalContourUP1D.__call__(*args) + pass class FalseUP1D(Blender.Freestyle.FalseUP1D): - def __call__(*args): return Blender.Freestyle.FalseUP1D.__call__(*args) + pass class QuantitativeInvisibilityUP1D(Blender.Freestyle.QuantitativeInvisibilityUP1D): - def __call__(*args): return Blender.Freestyle.QuantitativeInvisibilityUP1D.__call__(*args) + pass class ShapeUP1D(Blender.Freestyle.ShapeUP1D): - def __call__(*args): return Blender.Freestyle.ShapeUP1D.__call__(*args) + pass class TrueUP1D(Blender.Freestyle.TrueUP1D): - def __call__(*args): return Blender.Freestyle.TrueUP1D.__call__(*args) + pass class StrokeVertex(Blender.Freestyle.StrokeVertex): pass @@ -301,155 +301,155 @@ class FEdgeSmooth(Blender.Freestyle.FEdgeSmooth): pass class Curvature2DAngleF0D(Blender.Freestyle.Curvature2DAngleF0D): - def __call__(*args): return Blender.Freestyle.Curvature2DAngleF0D.__call__(*args) + pass class DensityF0D(Blender.Freestyle.DensityF0D): - def __call__(*args): return Blender.Freestyle.DensityF0D.__call__(*args) + pass class GetProjectedXF0D(Blender.Freestyle.GetProjectedXF0D): - def __call__(*args): return Blender.Freestyle.GetProjectedXF0D.__call__(*args) + pass class GetProjectedYF0D(Blender.Freestyle.GetProjectedYF0D): - def __call__(*args): return Blender.Freestyle.GetProjectedYF0D.__call__(*args) + pass class GetProjectedZF0D(Blender.Freestyle.GetProjectedZF0D): - def __call__(*args): return Blender.Freestyle.GetProjectedZF0D.__call__(*args) + pass class GetXF0D(Blender.Freestyle.GetXF0D): - def __call__(*args): return Blender.Freestyle.GetXF0D.__call__(*args) + pass class GetYF0D(Blender.Freestyle.GetYF0D): - def __call__(*args): return Blender.Freestyle.GetYF0D.__call__(*args) + pass class GetZF0D(Blender.Freestyle.GetZF0D): - def __call__(*args): return Blender.Freestyle.GetZF0D.__call__(*args) + pass class LocalAverageDepthF0D(Blender.Freestyle.LocalAverageDepthF0D): - def __call__(*args): return Blender.Freestyle.LocalAverageDepthF0D.__call__(*args) + pass class ZDiscontinuityF0D(Blender.Freestyle.ZDiscontinuityF0D): - def __call__(*args): return Blender.Freestyle.ZDiscontinuityF0D.__call__(*args) + pass class GetCurvilinearAbscissaF0D(Blender.Freestyle.GetCurvilinearAbscissaF0D): - def __call__(*args): return Blender.Freestyle.GetCurvilinearAbscissaF0D.__call__(*args) + pass class GetParameterF0D(Blender.Freestyle.GetParameterF0D): - def __call__(*args): return Blender.Freestyle.GetParameterF0D.__call__(*args) + pass class GetViewMapGradientNormF0D(Blender.Freestyle.GetViewMapGradientNormF0D): - def __call__(*args): return Blender.Freestyle.GetViewMapGradientNormF0D.__call__(*args) + pass class ReadCompleteViewMapPixelF0D(Blender.Freestyle.ReadCompleteViewMapPixelF0D): - def __call__(*args): return Blender.Freestyle.ReadCompleteViewMapPixelF0D.__call__(*args) + pass class ReadMapPixelF0D(Blender.Freestyle.ReadMapPixelF0D): - def __call__(*args): return Blender.Freestyle.ReadMapPixelF0D.__call__(*args) + pass class ReadSteerableViewMapPixelF0D(Blender.Freestyle.ReadSteerableViewMapPixelF0D): - def __call__(*args): return Blender.Freestyle.ReadSteerableViewMapPixelF0D.__call__(*args) + pass class ShapeIdF0D(Blender.Freestyle.ShapeIdF0D): - def __call__(*args): return Blender.Freestyle.ShapeIdF0D.__call__(*args) + pass class MaterialF0D(Blender.Freestyle.MaterialF0D): - def __call__(*args): return Blender.Freestyle.MaterialF0D.__call__(*args) + pass class CurveNatureF0D(Blender.Freestyle.CurveNatureF0D): - def __call__(*args): return Blender.Freestyle.CurveNatureF0D.__call__(*args) + pass class QuantitativeInvisibilityF0D(Blender.Freestyle.QuantitativeInvisibilityF0D): - def __call__(*args): return Blender.Freestyle.QuantitativeInvisibilityF0D.__call__(*args) + pass class Normal2DF0D(Blender.Freestyle.Normal2DF0D): - def __call__(*args): return Blender.Freestyle.Normal2DF0D.__call__(*args) + pass class VertexOrientation2DF0D(Blender.Freestyle.VertexOrientation2DF0D): - def __call__(*args): return Blender.Freestyle.VertexOrientation2DF0D.__call__(*args) + pass class VertexOrientation3DF0D(Blender.Freestyle.VertexOrientation3DF0D): - def __call__(*args): return Blender.Freestyle.VertexOrientation3DF0D.__call__(*args) + pass class GetOccludersF0D(Blender.Freestyle.GetOccludersF0D): - def __call__(*args): return Blender.Freestyle.GetOccludersF0D.__call__(*args) + pass class GetOccludeeF0D(Blender.Freestyle.GetOccludeeF0D): - def __call__(*args): return Blender.Freestyle.GetOccludeeF0D.__call__(*args) + pass class GetShapeF0D(Blender.Freestyle.GetShapeF0D): - def __call__(*args): return Blender.Freestyle.GetShapeF0D.__call__(*args) + pass class Curvature2DAngleF1D(Blender.Freestyle.Curvature2DAngleF1D): - def __call__(*args): return Blender.Freestyle.Curvature2DAngleF1D.__call__(*args) + pass class DensityF1D(Blender.Freestyle.DensityF1D): - def __call__(*args): return Blender.Freestyle.DensityF1D.__call__(*args) + pass class GetCompleteViewMapDensityF1D(Blender.Freestyle.GetCompleteViewMapDensityF1D): - def __call__(*args): return Blender.Freestyle.GetCompleteViewMapDensityF1D.__call__(*args) + pass class GetDirectionalViewMapDensityF1D(Blender.Freestyle.GetDirectionalViewMapDensityF1D): - def __call__(*args): return Blender.Freestyle.GetDirectionalViewMapDensityF1D.__call__(*args) + pass class GetProjectedXF1D(Blender.Freestyle.GetProjectedXF1D): - def __call__(*args): return Blender.Freestyle.GetProjectedXF1D.__call__(*args) + pass class GetProjectedYF1D(Blender.Freestyle.GetProjectedYF1D): - def __call__(*args): return Blender.Freestyle.GetProjectedYF1D.__call__(*args) + pass class GetProjectedZF1D(Blender.Freestyle.GetProjectedZF1D): - def __call__(*args): return Blender.Freestyle.GetProjectedZF1D.__call__(*args) + pass class GetSteerableViewMapDensityF1D(Blender.Freestyle.GetSteerableViewMapDensityF1D): - def __call__(*args): return Blender.Freestyle.GetSteerableViewMapDensityF1D.__call__(*args) + pass class GetViewMapGradientNormF1D(Blender.Freestyle.GetViewMapGradientNormF1D): - def __call__(*args): return Blender.Freestyle.GetViewMapGradientNormF1D.__call__(*args) + pass class GetXF1D(Blender.Freestyle.GetXF1D): - def __call__(*args): return Blender.Freestyle.GetXF1D.__call__(*args) + pass class GetYF1D(Blender.Freestyle.GetYF1D): - def __call__(*args): return Blender.Freestyle.GetYF1D.__call__(*args) + pass class GetZF1D(Blender.Freestyle.GetZF1D): - def __call__(*args): return Blender.Freestyle.GetZF1D.__call__(*args) + pass class LocalAverageDepthF1D(Blender.Freestyle.LocalAverageDepthF1D): - def __call__(*args): return Blender.Freestyle.LocalAverageDepthF1D.__call__(*args) + pass class ZDiscontinuityF1D(Blender.Freestyle.ZDiscontinuityF1D): - def __call__(*args): return Blender.Freestyle.ZDiscontinuityF1D.__call__(*args) + pass class CurveNatureF1D(Blender.Freestyle.CurveNatureF1D): - def __call__(*args): return Blender.Freestyle.CurveNatureF1D.__call__(*args) + pass class QuantitativeInvisibilityF1D(Blender.Freestyle.QuantitativeInvisibilityF1D): - def __call__(*args): return Blender.Freestyle.QuantitativeInvisibilityF1D.__call__(*args) + pass class Normal2DF1D(Blender.Freestyle.Normal2DF1D): - def __call__(*args): return Blender.Freestyle.Normal2DF1D.__call__(*args) + pass class Orientation2DF1D(Blender.Freestyle.Orientation2DF1D): - def __call__(*args): return Blender.Freestyle.Orientation2DF1D.__call__(*args) + pass class Orientation3DF1D(Blender.Freestyle.Orientation3DF1D): - def __call__(*args): return Blender.Freestyle.Orientation3DF1D.__call__(*args) + pass class GetOccludeeF1D(Blender.Freestyle.GetOccludeeF1D): - def __call__(*args): return Blender.Freestyle.GetOccludeeF1D.__call__(*args) + pass class GetOccludersF1D(Blender.Freestyle.GetOccludersF1D): - def __call__(*args): return Blender.Freestyle.GetOccludersF1D.__call__(*args) + pass class GetShapeF1D(Blender.Freestyle.GetShapeF1D): - def __call__(*args): return Blender.Freestyle.GetShapeF1D.__call__(*args) + pass class ChainingTimeStampF1D(Blender.Freestyle.ChainingTimeStampF1D): - def __call__(*args): return Blender.Freestyle.ChainingTimeStampF1D.__call__(*args) + pass class IncrementChainingTimeStampF1D(Blender.Freestyle.IncrementChainingTimeStampF1D): - def __call__(*args): return Blender.Freestyle.IncrementChainingTimeStampF1D.__call__(*args) + pass class TimeStampF1D(Blender.Freestyle.TimeStampF1D): - def __call__(*args): return Blender.Freestyle.TimeStampF1D.__call__(*args) + pass -- cgit v1.2.3