diff options
Diffstat (limited to 'source/blender/freestyle/intern/python')
13 files changed, 160 insertions, 35 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<StrokeShader *> 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 <Python.h> -// 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; } |