[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22158] branches/soc-2008-mxcurioni/source /blender/freestyle/intern/python: Fixed the handling of constructor arguments in the following Python

Tamito Kajiyama rd6t-kjym at asahi-net.or.jp
Mon Aug 3 00:39:21 CEST 2009


Revision: 22158
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22158
Author:   kjym3
Date:     2009-08-03 00:39:21 +0200 (Mon, 03 Aug 2009)

Log Message:
-----------
Fixed the handling of constructor arguments in the following Python
types: Interface0D, SVertex, ViewVertex, StrokeVertex, NonTVertex,
and TVertex.

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Interface0D.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Interface0D.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Interface0D.cpp	2009-08-02 21:46:35 UTC (rev 22157)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Interface0D.cpp	2009-08-02 22:39:21 UTC (rev 22158)
@@ -182,6 +182,8 @@
 
 int Interface0D___init__(BPy_Interface0D *self, PyObject *args, PyObject *kwds)
 {
+    if ( !PyArg_ParseTuple(args, "") )
+        return -1;
 	self->if0D = new Interface0D();
 	self->borrowed = 0;
 	return 0;

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp	2009-08-02 21:46:35 UTC (rev 22157)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp	2009-08-02 22:39:21 UTC (rev 22158)
@@ -135,7 +135,13 @@
 	if (! PyArg_ParseTuple(args, "|OO!", &py_point, &Id_Type, &py_id) )
         return -1;
 	
-	if( py_point && py_id ) {
+	if( !py_point ) {
+		self->sv = new SVertex();
+
+	} else if( !py_id && BPy_SVertex_Check(py_point) ) {
+		self->sv = new SVertex( *(((BPy_SVertex *)py_point)->sv) );
+
+	} else if( py_point && py_id ) {
 		Vec3r *v = Vec3r_ptr_from_PyObject(py_point);
 		if( !v ) {
 			PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)");
@@ -143,8 +149,7 @@
 		}
 		self->sv = new SVertex( *v, *(py_id->id) );
 		delete v;
-	} else if( !py_point && !py_id ) {
-		self->sv = new SVertex();
+
 	} else {
 		PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
 		return -1;

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp	2009-08-02 21:46:35 UTC (rev 22157)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp	2009-08-02 22:39:21 UTC (rev 22158)
@@ -11,7 +11,7 @@
 ///////////////////////////////////////////////////////////////////////////////////////////
 
 /*---------------  Python API function prototypes for ViewVertex instance  -----------*/
-static int ViewVertex___init__(BPy_ViewVertex *self);
+static int ViewVertex___init__( BPy_ViewVertex *self, PyObject *args, PyObject *kwds );
 static PyObject * ViewVertex_setNature( BPy_ViewVertex *self, PyObject *args );
 static PyObject * ViewVertex_edgesBegin( BPy_ViewVertex *self );
 static PyObject * ViewVertex_edgesEnd( BPy_ViewVertex *self );
@@ -116,10 +116,12 @@
 
 //------------------------INSTANCE METHODS ----------------------------------
 
-int ViewVertex___init__(BPy_ViewVertex *self )
+int ViewVertex___init__( BPy_ViewVertex *self, PyObject *args, PyObject *kwds )
 {	
+    if( !PyArg_ParseTuple(args, "") )
+        return -1;
 	self->vv = 0; // ViewVertex is abstract
-	self->py_if0D.if0D = new Interface0D();
+	self->py_if0D.if0D = self->vv;
 	self->py_if0D.borrowed = 0;
 	return 0;
 }

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp	2009-08-02 21:46:35 UTC (rev 22157)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp	2009-08-02 22:39:21 UTC (rev 22158)
@@ -141,24 +141,34 @@
 
 	PyObject *obj1 = 0, *obj2 = 0 , *obj3 = 0;
 
-    if (! PyArg_ParseTuple(args, "|OOO", &obj1, &obj2, &obj3) )
+    if (! PyArg_ParseTuple(args, "|OOO!", &obj1, &obj2, &PyFloat_Type, &obj3) )
         return -1;
 
-	if( !obj1 && !obj2 && !obj3 ){
+	if( !obj1 ){
 		self->sv = new StrokeVertex();
 		
-	} else if( BPy_CurvePoint_Check(obj1) && ((BPy_CurvePoint *) obj1)->cp ) {
+	} else if( !obj2 && BPy_StrokeVertex_Check(obj1) && ((BPy_StrokeVertex *) obj1)->sv ) {
+		self->sv = new StrokeVertex( *(((BPy_StrokeVertex *) obj1)->sv) );
+
+	} else if( !obj2 && BPy_CurvePoint_Check(obj1) && ((BPy_CurvePoint *) obj1)->cp ) {
 		self->sv = new StrokeVertex( ((BPy_CurvePoint *) obj1)->cp );
 	
-	} else if( BPy_SVertex_Check(obj1) && ((BPy_SVertex *) obj1)->sv ) {
+	} else if( !obj2 && BPy_SVertex_Check(obj1) && ((BPy_SVertex *) obj1)->sv ) {
 		self->sv = new StrokeVertex( ((BPy_SVertex *) obj1)->sv );
 	
-	} else if( BPy_StrokeVertex_Check(obj1) && BPy_StrokeVertex_Check(obj2) 
-				&& ((BPy_StrokeVertex *) obj1)->sv && ((BPy_StrokeVertex *) obj2)->sv) {
-	
-		self->sv = new StrokeVertex(	((BPy_StrokeVertex *) obj1)->sv,
-										((BPy_StrokeVertex *) obj2)->sv,
-										PyFloat_AsDouble( obj3 ) );
+	} else if( obj3 && BPy_StrokeVertex_Check(obj1) && BPy_StrokeVertex_Check(obj2) ) {
+		StrokeVertex *sv1 = ((BPy_StrokeVertex *) obj1)->sv;
+		StrokeVertex *sv2 = ((BPy_StrokeVertex *) obj2)->sv;
+		if( !sv1 || ( sv1->A() == 0 && sv1->B() == 0 ) ) {
+			PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid StrokeVertex object");
+			return -1;
+		}
+		if( !sv2 || ( sv2->A() == 0 && sv2->B() == 0 ) ) {
+			PyErr_SetString(PyExc_TypeError, "argument 2 is an invalid StrokeVertex object");
+			return -1;
+		}
+		self->sv = new StrokeVertex( sv1, sv2, PyFloat_AsDouble( obj3 ) );
+
 	} else {
 		PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
 		return -1;

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp	2009-08-02 21:46:35 UTC (rev 22157)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp	2009-08-02 22:39:21 UTC (rev 22158)
@@ -117,13 +117,13 @@
 
 	PyObject *obj = 0;
 
-    if (! PyArg_ParseTuple(args, "|O", &obj) )
+    if (! PyArg_ParseTuple(args, "|O!", &SVertex_Type, &obj) )
         return -1;
 
 	if( !obj ){
 		self->ntv = new NonTVertex();
 
-	} else if( BPy_SVertex_Check(obj) && ((BPy_SVertex *) obj)->sv ) {
+	} else if( ((BPy_SVertex *) obj)->sv ) {
 		self->ntv = new NonTVertex( ((BPy_SVertex *) obj)->sv );
 
 	} else {

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp	2009-08-02 21:46:35 UTC (rev 22157)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp	2009-08-02 22:39:21 UTC (rev 22158)
@@ -127,6 +127,8 @@
 
 int TVertex___init__(BPy_TVertex *self, PyObject *args, PyObject *kwds)
 {
+    if( !PyArg_ParseTuple(args, "") )
+        return -1;
 	self->tv = new TVertex();
 	self->py_vv.vv = self->tv;
 	self->py_vv.py_if0D.if0D = self->tv;





More information about the Bf-blender-cvs mailing list