[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15609] branches/soc-2008-mxcurioni/source /blender/freestyle: soc-2008-mxcurioni: SWIG removal - completed SVertex and CurvePoint classes migration.

Maxime Curioni maxime.curioni at gmail.com
Thu Jul 17 08:35:31 CEST 2008


Revision: 15609
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15609
Author:   mxcurioni
Date:     2008-07-17 08:35:30 +0200 (Thu, 17 Jul 2008)

Log Message:
-----------
soc-2008-mxcurioni: SWIG removal - completed SVertex and CurvePoint classes migration. Stabilized a lot of the code for C++ -> Python conversion. Added the correct rich comparison operator and tested it. Corrected 'dupplicate' typo and changde to __copy__ for Python API.

>From now on, when a set should be output (PySet_Type), it is given as a list (PyList_Type). The reason is that it doesn't really matter what we bring back to the Python interpreter. The set is guaranteed in memory on the C++ side.

For the CurvePoint class, the userdata variable is not yet ported (and will probably available as a list or a dictionary). The CurvePoint implementation works except for the initialization from other CurvePoints: somehow, the inner variables don't seem to be correctly handled. I do not know if it is a bug in Freestyle or if the CurvePoint object's state is correct for my test case. CurvePoint needs more testing.

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/source/blender/freestyle/SConscript
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BinaryPredicate0D.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BinaryPredicate1D.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Convert.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Convert.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Id.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/CurvePoint.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/CurvePoint.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/SVertex.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface1D/FEdge/FEdgeSharp.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface1D.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/swig/ModuleWrapper.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/Silhouette.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/ViewMap.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/winged_edge/WEdge.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/winged_edge/WEdge.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/winged_edge/WXEdge.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/python/Freestyle.py

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/SConscript
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/SConscript	2008-07-16 23:02:23 UTC (rev 15608)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/SConscript	2008-07-17 06:35:30 UTC (rev 15609)
@@ -67,6 +67,7 @@
 					prefix + '/Id.cpp',
 					prefix + '/Interface0D.cpp',
 					prefix + '/Interface0D/CurvePoint.cpp',
+					prefix + '/Interface0D/SVertex.cpp',
 					prefix + '/Interface1D.cpp'
 				]
 

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BinaryPredicate0D.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BinaryPredicate0D.cpp	2008-07-16 23:02:23 UTC (rev 15608)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BinaryPredicate0D.cpp	2008-07-17 06:35:30 UTC (rev 15609)
@@ -153,7 +153,7 @@
 	BPy_Interface0D *obj1, *obj2;
 	bool b;
 
-	if( !PyArg_ParseTuple(args,(char *)"OO:BinaryPredicate0D___call__", &obj1, obj2) ) {
+	if( !PyArg_ParseTuple(args,(char *)"OO", &obj1, &obj2) ) {
 		cout << "ERROR: BinaryPredicate0D___call__ " << endl;		
 		return NULL;
 	}

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BinaryPredicate1D.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BinaryPredicate1D.cpp	2008-07-16 23:02:23 UTC (rev 15608)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BinaryPredicate1D.cpp	2008-07-17 06:35:30 UTC (rev 15609)
@@ -151,7 +151,7 @@
 	BPy_Interface1D *obj1, *obj2;
 	bool b;
 	
-	if( !PyArg_ParseTuple(args,(char *)"OO:BinaryPredicate1D___call__", &obj1, &obj2) ) {
+	if( !PyArg_ParseTuple(args,(char *)"OO", &obj1, &obj2) ) {
 		cout << "ERROR: BinaryPredicate1D___call__ " << endl;		
 		return NULL;
 	}

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Convert.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Convert.cpp	2008-07-16 23:02:23 UTC (rev 15608)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Convert.cpp	2008-07-17 06:35:30 UTC (rev 15609)
@@ -7,22 +7,7 @@
 
 ///////////////////////////////////////////////////////////////////////////////////////////
 
-static char M_Convert_doc[] = "The Blender.Freestyle.Convert utility submodule";
-/*----------------------Freestyle module method def----------------------------*/
-struct PyMethodDef M_Convert_methods[] = {
-//	{"testOutput", ( PyCFunction ) Freestyle_testOutput, METH_NOARGS, "() - Return Curve Data name"},
-	{NULL, NULL, 0, NULL}
-};
 
-
-//-------------------MODULE INITIALIZATION--------------------------------
-PyObject *Convert_Init( void )
-{
-	return Py_InitModule3( "Blender.Freestyle.Convert", M_Convert_methods, M_Convert_doc );
-}
-
-//-------------------------------------------------------------------------
-
 PyObject *PyBool_from_bool( bool b ){
 	// SWIG_From_bool
 	return PyBool_FromLong( b ? 1 : 0);
@@ -31,32 +16,64 @@
 
 PyObject *Vector_from_Vec2f( Vec2f vec ) {
 	float vec_data[2]; // because vec->_coord is protected
-	vec_data[0] = vec.x();		vec_data[1] = vec.y();
-	return newVectorObject( vec_data, 2, Py_NEW);
+
+	if( &vec != 0 ){
+		vec_data[0] = vec.x();		vec_data[1] = vec.y();
+		return newVectorObject( vec_data, 2, Py_NEW);
+	} 
+
+	Py_RETURN_NONE;
 }
 
 PyObject *Vector_from_Vec3f( Vec3f vec ) {
 	float vec_data[3]; // because vec->_coord is protected
-	vec_data[0] = vec.x();		vec_data[1] = vec.y(); 		vec_data[2] = vec.z(); 
-	return newVectorObject( vec_data, 3, Py_NEW);
+	
+	if( &vec != 0 ){
+		vec_data[0] = vec.x();		vec_data[1] = vec.y(); 		vec_data[2] = vec.z(); 
+		return newVectorObject( vec_data, 3, Py_NEW);
+	} 
+
+	Py_RETURN_NONE;
 }
 
 PyObject *Vector_from_Vec3r( Vec3r vec ) {
 	float vec_data[3]; // because vec->_coord is protected
-	vec_data[0] = vec.x();		vec_data[1] = vec.y(); 		vec_data[2] = vec.z(); 
-	return newVectorObject( vec_data, 3, Py_NEW);
+	
+	if( &vec != 0 ){
+		vec_data[0] = vec.x();		vec_data[1] = vec.y(); 		vec_data[2] = vec.z(); 
+		return newVectorObject( vec_data, 3, Py_NEW);
+	} 
+
+	Py_RETURN_NONE;
 }
 
 PyObject *BPy_Id_from_Id( Id id ) {
 	BPy_Id *py_id;
 	
-	py_id = (BPy_Id *) Id_Type.tp_new( &Id_Type, 0, 0 );
-	py_id->id->setFirst( id.getFirst() );
-	py_id->id->setSecond( id.getSecond() );
+	if( &id != 0 ) {
+		py_id = (BPy_Id *) Id_Type.tp_new( &Id_Type, 0, 0 );
+		py_id->id = new Id( id.getFirst(), id.getSecond() );
+
+		return (PyObject *)py_id;
+	}
 	
-	return (PyObject *)py_id;
+	Py_RETURN_NONE;
 }
 
+PyObject *BPy_SVertex_from_SVertex( SVertex sv ) {
+	BPy_SVertex *py_sv;
+
+	if( &sv != 0 ) {
+		py_sv = (BPy_SVertex *) SVertex_Type.tp_new( &SVertex_Type, 0, 0 );
+		py_sv->sv = new SVertex( sv );
+		py_sv->py_if0D.if0D = py_sv->sv;
+
+		return (PyObject *)py_sv;
+	}
+
+	Py_RETURN_NONE;
+}
+	
 ///////////////////////////////////////////////////////////////////////////////////////////
 
 #ifdef __cplusplus

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Convert.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Convert.h	2008-07-16 23:02:23 UTC (rev 15608)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Convert.h	2008-07-17 06:35:30 UTC (rev 15609)
@@ -5,6 +5,7 @@
 using namespace Geometry;
 
 #include "Id.h"
+#include "Interface0D/SVertex.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -16,8 +17,6 @@
 #include "api2_2x/vector.h"
 #include "api2_2x/gen_utils.h"
 
-PyObject *Convert_Init( void );
-
 PyObject *PyBool_from_bool( bool b );
 
 PyObject *Vector_from_Vec2f( Vec2f v );
@@ -25,6 +24,7 @@
 PyObject *Vector_from_Vec3r( Vec3r v );
 
 PyObject *BPy_Id_from_Id( Id id );
+PyObject *BPy_SVertex_from_SVertex( SVertex sv );
 
 ///////////////////////////////////////////////////////////////////////////////////////////
 

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Id.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Id.cpp	2008-07-16 23:02:23 UTC (rev 15608)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Id.cpp	2008-07-17 06:35:30 UTC (rev 15609)
@@ -12,14 +12,12 @@
 static int Id___init__(BPy_Id *self, PyObject *args, PyObject *kwds);
 static void Id___dealloc__(BPy_Id *self);
 static PyObject * Id___repr__(BPy_Id* self);
+static PyObject * Id_RichCompare(BPy_Id *o1, BPy_Id *o2, int opid);
 
 static PyObject * Id_getFirst( BPy_Id *self );
 static PyObject * Id_getSecond( BPy_Id *self);
 static PyObject * Id_setFirst( BPy_Id *self , PyObject *args);
 static PyObject * Id_setSecond( BPy_Id *self , PyObject *args);
-static PyObject * Id___eq__( BPy_Id *self , PyObject *args);
-static PyObject * Id___ne__( BPy_Id *self , PyObject *args);
-static PyObject * Id___lt__( BPy_Id *self , PyObject *args);
 
 /*----------------------Id instance definitions ----------------------------*/
 static PyMethodDef BPy_Id_methods[] = {
@@ -27,9 +25,6 @@
 	{"getSecond", ( PyCFunction ) Id_getSecond, METH_NOARGS, "Returns the second Id number" },
 	{"setFirst", ( PyCFunction ) Id_setFirst, METH_VARARGS, "Sets the first number constituing the Id" },
 	{"setSecond", ( PyCFunction ) Id_setSecond, METH_VARARGS, "Sets the second number constituing the Id" },
-	{"__eq__", ( PyCFunction ) Id___eq__, METH_VARARGS, "Operator ==" },
-	{"__ne__", ( PyCFunction ) Id___ne__, METH_VARARGS, "Operator !=" },
-	{"__lt__", ( PyCFunction ) Id___lt__, METH_VARARGS, "Operator <" },
 	{NULL, NULL, 0, NULL}
 };
 
@@ -80,7 +75,7 @@
 
   /***  Assigned meaning in release 2.1 ***/
   /*** rich comparisons ***/
-	NULL,                       /* richcmpfunc tp_richcompare; */
+	(richcmpfunc)Id_RichCompare,                   /* richcmpfunc tp_richcompare; */
 
   /***  weak reference enabler ***/
 	0,                          /* long tp_weaklistoffset; */
@@ -170,7 +165,7 @@
 PyObject *Id_setFirst( BPy_Id *self , PyObject *args) {
 	unsigned int i;
 
-	if( !PyArg_ParseTuple(args, (char *)"i:Id_setFirst", i) ) {
+	if( !PyArg_ParseTuple(args, (char *)"i", &i) ) {
 		cout << "ERROR: Id_setFirst" << endl;
 		Py_RETURN_NONE;
 	}
@@ -184,7 +179,7 @@
 PyObject *Id_setSecond( BPy_Id *self , PyObject *args) {
 	unsigned int i;
 
-	if( !PyArg_ParseTuple(args, (char *)"i:Id_setSecond", i) ) {
+	if( !PyArg_ParseTuple(args, (char *)"i", &i) ) {
 		cout << "ERROR: Id_setSecond" << endl;
 		Py_RETURN_NONE;
 	}
@@ -194,41 +189,32 @@
 	Py_RETURN_NONE;
 }
 
-PyObject *Id___eq__( BPy_Id *self , PyObject *args) {
-	BPy_Id * other = 0 ;
-
-	if( !PyArg_ParseTuple(args, (char *)"O:Id___eq__", &other) ) {
-		cout << "ERROR: Id___eq__" << endl;
-		Py_RETURN_NONE;
+PyObject * Id_RichCompare(BPy_Id *o1, BPy_Id *o2, int opid) {
+	switch(opid){
+		case Py_LT:
+			return PyBool_from_bool( o1->id->operator<(*(o2->id)) );
+			break;
+		case Py_LE:
+			return PyBool_from_bool( o1->id->operator<(*(o2->id)) || o1->id->operator<(*(o2->id)) );
+			break;
+		case Py_EQ:
+			return PyBool_from_bool( o1->id->operator==(*(o2->id)) );
+			break;
+		case Py_NE:
+			return PyBool_from_bool( o1->id->operator!=(*(o2->id)) );
+			break;
+		case Py_GT:
+			return PyBool_from_bool(!( o1->id->operator<(*(o2->id)) || o1->id->operator<(*(o2->id)) ));
+			break;
+		case Py_GE:
+			return PyBool_from_bool(!( o1->id->operator<(*(o2->id)) ));
+			break;
 	}
 	
-	return PyBool_from_bool( self->id == other->id );
+	Py_RETURN_NONE;
 }
 
 
-PyObject *Id___ne__(BPy_Id *self , PyObject *args) {
-	BPy_Id * other = 0 ;
-
-	if( !PyArg_ParseTuple(args, (char *)"O:Id___ne__", &other) ) {
-		cout << "ERROR: Id___ne__" << endl;
-		Py_RETURN_NONE;
-	}
-	
-	return PyBool_from_bool( self->id != other->id );
-}
-
-PyObject *Id___lt__(BPy_Id *self , PyObject *args) {
-	BPy_Id * other = 0 ;
-
-	if( !PyArg_ParseTuple(args, (char *)"O:Id___lt__", &other) ) {
-		cout << "ERROR: Id___lt__" << endl;
-		Py_RETURN_NONE;
-	}
-	
-	return PyBool_from_bool( self->id <= other->id );
-}
-
-
 ///////////////////////////////////////////////////////////////////////////////////////////
 
 #ifdef __cplusplus


@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list