[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15889] branches/soc-2008-mxcurioni/source /blender/freestyle: 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).

Maxime Curioni maxime.curioni at gmail.com
Thu Jul 31 10:51:17 CEST 2008


Revision: 15889
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15889
Author:   mxcurioni
Date:     2008-07-31 10:50:12 +0200 (Thu, 31 Jul 2008)

Log Message:
-----------
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.

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_BinaryPredicate0D.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_BinaryPredicate1D.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Operators.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_StrokeShader.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryFunction0D.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryFunction1D.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Director.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Director.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/ChainingIterators.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Predicates0D.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Predicates1D.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Stroke.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/StrokeShader.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/Functions0D.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/Functions1D.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/style_modules_blender/freestyle_init.py

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_BinaryPredicate0D.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_BinaryPredicate0D.cpp	2008-07-30 21:52:02 UTC (rev 15888)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_BinaryPredicate0D.cpp	2008-07-31 08:50:12 UTC (rev 15889)
@@ -127,6 +127,8 @@
 int BinaryPredicate0D___init__(BPy_BinaryPredicate0D *self, PyObject *args, PyObject *kwds)
 {
 	self->bp0D = new BinaryPredicate0D();
+	self->bp0D->py_bp0D = (PyObject *) self;
+	
 	return 0;
 }
 

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_BinaryPredicate1D.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_BinaryPredicate1D.cpp	2008-07-30 21:52:02 UTC (rev 15888)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_BinaryPredicate1D.cpp	2008-07-31 08:50:12 UTC (rev 15889)
@@ -159,6 +159,7 @@
 int BinaryPredicate1D___init__(BPy_BinaryPredicate1D *self, PyObject *args, PyObject *kwds)
 {
 	self->bp1D = new BinaryPredicate1D();
+	self->bp1D->py_bp1D = (PyObject *) self;	
 	return 0;
 }
 

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.cpp	2008-07-30 21:52:02 UTC (rev 15888)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.cpp	2008-07-31 08:50:12 UTC (rev 15889)
@@ -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 @@
 	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 );

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.h	2008-07-30 21:52:02 UTC (rev 15888)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.h	2008-07-31 08:50:12 UTC (rev 15889)
@@ -80,6 +80,7 @@
 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 );

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Operators.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Operators.cpp	2008-07-30 21:52:02 UTC (rev 15888)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Operators.cpp	2008-07-31 08:50:12 UTC (rev 15889)
@@ -164,21 +164,19 @@
 		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 @@
 
 	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 @@
 		cout << "ERROR: Operators_bidirectionalChain" << endl;
 		Py_RETURN_NONE;
 	}
-
+	
 	if( !obj2 ) {
 
 		Operators::bidirectionalChain( 	*( ((BPy_ChainingIterator *) obj1)->c_it ) );
@@ -234,7 +233,7 @@
 		cout << "ERROR: Operators_sequentialSplit" << endl;
 		Py_RETURN_NONE;
 	}
-
+	
 	if( obj2 && BPy_UnaryPredicate0D_Check(obj2) ) {
 		
 		Operators::sequentialSplit( 	*( ((BPy_UnaryPredicate0D *) obj1)->up0D ),
@@ -266,7 +265,7 @@
 	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 @@
 	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);

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_StrokeShader.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_StrokeShader.cpp	2008-07-30 21:52:02 UTC (rev 15888)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_StrokeShader.cpp	2008-07-31 08:50:12 UTC (rev 15889)
@@ -254,6 +254,7 @@
 int StrokeShader___init__(BPy_StrokeShader *self, PyObject *args, PyObject *kwds)
 {
 	self->ss = new StrokeShader();
+	self->ss->py_ss = (PyObject *) self;
 	return 0;
 }
 

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryFunction0D.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryFunction0D.h	2008-07-30 21:52:02 UTC (rev 15888)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryFunction0D.h	2008-07-31 08:50:12 UTC (rev 15889)
@@ -18,6 +18,7 @@
 /*---------------------------Python BPy_UnaryFunction0D structure definition----------*/
 typedef struct {
 	PyObject_HEAD
+	PyObject *py_uf0D;
 } BPy_UnaryFunction0D;
 
 /*---------------------------Python BPy_UnaryFunction0D visible prototypes-----------*/

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryFunction1D.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryFunction1D.h	2008-07-30 21:52:02 UTC (rev 15888)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryFunction1D.h	2008-07-31 08:50:12 UTC (rev 15889)
@@ -18,6 +18,7 @@
 /*---------------------------Python BPy_UnaryFunction1D structure definition----------*/
 typedef struct {
 	PyObject_HEAD
+	PyObject *py_uf1D;
 } BPy_UnaryFunction1D;
 
 /*---------------------------Python BPy_UnaryFunction1D visible prototypes-----------*/

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp	2008-07-30 21:52:02 UTC (rev 15888)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp	2008-07-31 08:50:12 UTC (rev 15889)
@@ -139,6 +139,7 @@
 int UnaryPredicate0D___init__(BPy_UnaryPredicate0D *self, PyObject *args, PyObject *kwds)
 {
 	self->up0D = new UnaryPredicate0D();
+	self->up0D->py_up0D = (PyObject *) self;
 	return 0;
 }
 

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp	2008-07-30 21:52:02 UTC (rev 15888)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp	2008-07-31 08:50:12 UTC (rev 15889)
@@ -181,6 +181,7 @@
 int UnaryPredicate1D___init__(BPy_UnaryPredicate1D *self, PyObject *args, PyObject *kwds)
 {
 	self->up1D = new UnaryPredicate1D();
+	self->up1D->py_up1D = (PyObject *) self;
 	return 0;
 }
 

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Director.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Director.cpp	2008-07-30 21:52:02 UTC (rev 15888)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Director.cpp	2008-07-31 08:50:12 UTC (rev 15889)
@@ -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"

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list