diff options
author | Maxime Curioni <maxime.curioni@gmail.com> | 2008-07-30 05:51:40 +0400 |
---|---|---|
committer | Maxime Curioni <maxime.curioni@gmail.com> | 2008-07-30 05:51:40 +0400 |
commit | a482f644242456ad6ddf0306e1b37d8855342103 (patch) | |
tree | 4d89fe22969b7970ce09f195d82261ac47544157 /source/blender/freestyle/intern/python | |
parent | 7d5eaa674b70b13af3c67b2209fdfe32b6168e45 (diff) |
soc-2008-mxcurioni: Tested SWIG-less environment more and understood why the former predicate methods were not working. As Stéphane had mentioned a few months ago, Freestyle uses SWIG directors to provide cross-language polymorphism. The API and the system I had provided did not support that feature and only implementations in C++ were supported. To correct the problem, after researching how directors are implemented in SWIG, I provided the same functionality. So far, I only provided the code for the UnaryPredicate1D class and it works. The implementation is in intern/python/Director.cpp and Operators.cpp. I will port the remaining directors tonight and continue to test it.
To prevent strokes from piling up after each render, I clear the canvas at each render now (as it should have been all along)
Diffstat (limited to 'source/blender/freestyle/intern/python')
7 files changed, 66 insertions, 3 deletions
diff --git a/source/blender/freestyle/intern/python/BPy_Convert.cpp b/source/blender/freestyle/intern/python/BPy_Convert.cpp index b541babd752..d7b6fa8bd33 100644 --- a/source/blender/freestyle/intern/python/BPy_Convert.cpp +++ b/source/blender/freestyle/intern/python/BPy_Convert.cpp @@ -9,6 +9,7 @@ #include "Interface0D/CurvePoint/BPy_StrokeVertex.h" #include "Interface0D/BPy_SVertex.h" #include "Interface0D/BPy_ViewVertex.h" +#include "BPy_Interface1D.h" #include "Interface1D/BPy_FEdge.h" #include "Interface1D/BPy_ViewEdge.h" #include "BPy_Nature.h" @@ -79,6 +80,14 @@ PyObject * BPy_Interface0D_from_Interface0D( Interface0D& if0D ) { return py_if0D; } +PyObject * BPy_Interface1D_from_Interface1D( Interface1D& if1D ) { + PyObject *py_if1D = Interface1D_Type.tp_new( &Interface1D_Type, 0, 0 ); + ((BPy_Interface1D *) py_if1D)->if1D = &if1D; + + return py_if1D; +} + + PyObject * BPy_SVertex_from_SVertex( SVertex& sv ) { PyObject *py_sv = SVertex_Type.tp_new( &SVertex_Type, 0, 0 ); ((BPy_SVertex *) py_sv)->sv = new SVertex( sv ); diff --git a/source/blender/freestyle/intern/python/BPy_Convert.h b/source/blender/freestyle/intern/python/BPy_Convert.h index 5b613b3c4c3..9e743f4b233 100644 --- a/source/blender/freestyle/intern/python/BPy_Convert.h +++ b/source/blender/freestyle/intern/python/BPy_Convert.h @@ -17,6 +17,9 @@ using namespace Geometry; // Interface0D, Interface0DIteratorNested, Interface0DIterator #include "../view_map/Interface0D.h" +// Interface1D +#include "../view_map/Interface1D.h" + // Material #include "../scene_graph/Material.h" @@ -71,6 +74,7 @@ PyObject * BPy_directedViewEdge_from_directedViewEdge( ViewVertex::directedViewE PyObject * BPy_FEdge_from_FEdge( FEdge& fe ); PyObject * BPy_Id_from_Id( Id& id ); PyObject * BPy_Interface0D_from_Interface0D( Interface0D& if0D ); +PyObject * BPy_Interface1D_from_Interface1D( Interface1D& if1D ); PyObject * BPy_IntegrationType_from_IntegrationType( int i ); PyObject * BPy_FrsMaterial_from_Material( Material& m ); PyObject * BPy_Nature_from_Nature( unsigned short n ); diff --git a/source/blender/freestyle/intern/python/BPy_Operators.cpp b/source/blender/freestyle/intern/python/BPy_Operators.cpp index b0a8e7e3bd2..850b4cb5bad 100644 --- a/source/blender/freestyle/intern/python/BPy_Operators.cpp +++ b/source/blender/freestyle/intern/python/BPy_Operators.cpp @@ -164,7 +164,11 @@ PyObject * Operators_select(BPy_Operators* self, PyObject *args) Py_RETURN_NONE; } - Operators::select(*( ((BPy_UnaryPredicate1D *) obj)->up1D )); + UnaryPredicate1D *up1D = ((BPy_UnaryPredicate1D *) obj)->up1D; + if( PyObject_HasAttrString( obj, "__call__") ) + up1D->setPythonObject( obj ); + + Operators::select(*up1D); Py_RETURN_NONE; } diff --git a/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp b/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp index a13de77bbe9..14eb041c480 100644 --- a/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp +++ b/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp @@ -215,7 +215,7 @@ PyObject * UnaryPredicate1D___call__( BPy_UnaryPredicate1D *self, PyObject *args if( if1D ) return PyBool_from_bool( self->up1D->operator()(*if1D) ); - + Py_RETURN_NONE; } diff --git a/source/blender/freestyle/intern/python/Director.cpp b/source/blender/freestyle/intern/python/Director.cpp new file mode 100644 index 00000000000..6acdc665a0c --- /dev/null +++ b/source/blender/freestyle/intern/python/Director.cpp @@ -0,0 +1,12 @@ +#include "Director.h" + +#include "BPy_Convert.h" + +bool director_BPy_UnaryPredicate1D___call__( PyObject *py_up1D, Interface1D& if1D) { + cout << "Polymorphism works" << endl; + + PyObject *method = PyObject_GetAttrString( py_up1D, "__call__"); + PyObject *result = PyObject_CallFunction(method, "O", BPy_Interface1D_from_Interface1D(if1D) ); + + return bool_from_PyBool(result); +} diff --git a/source/blender/freestyle/intern/python/Director.h b/source/blender/freestyle/intern/python/Director.h new file mode 100644 index 00000000000..7114b124ffb --- /dev/null +++ b/source/blender/freestyle/intern/python/Director.h @@ -0,0 +1,34 @@ +#ifndef FREESTYLE_PYTHON_DIRECTOR +# define FREESTYLE_PYTHON_DIRECTOR + +#include "../view_map/Interface1D.h" + +#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 + + +#endif // FREESTYLE_PYTHON_DIRECTOR diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp index 75526507493..4bfaab92a8e 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp @@ -111,7 +111,7 @@ int ChainSilhouetteIterator___init__(BPy_ChainSilhouetteIterator *self, PyObject { PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0; - if (!( PyArg_ParseTuple(args, "O|OO", &obj1, &obj2, &obj3) )) + if (!( PyArg_ParseTuple(args, "|OOO", &obj1, &obj2, &obj3) )) return -1; if( obj1 && BPy_ChainSilhouetteIterator_Check(obj1) ) { |