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. --- .../blender/freestyle/intern/python/Director.cpp | 82 ++++++++++++++++++++-- 1 file changed, 78 insertions(+), 4 deletions(-) (limited to 'source/blender/freestyle/intern/python/Director.cpp') 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 + + -- cgit v1.2.3