[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11293] branches/pyapi_devel/source/ blender/python/api2_2x: * Added Constants to Mesh

Campbell Barton cbarton at metavr.com
Mon Jul 16 23:20:52 CEST 2007


Revision: 11293
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11293
Author:   campbellbarton
Date:     2007-07-16 23:20:52 +0200 (Mon, 16 Jul 2007)

Log Message:
-----------
* Added Constants to Mesh
* added utility functions for new constants Const_FromPyObject to make getting the const from a PyObject easier.
 (also changed a few things you may want to look ken)
* removed Module Methods that are no longer needed mainly Get/Set/New
* object.type now returns the PyType rather then a string.
* Almost all of the Object/Mesh/Key/Ipo_CreatePyObject functions now return None when the data they recieve is NULL. (most of the time it was checked for and returned None anyway so nicer to do in this function)
* some more tp_new's so types can be called to initialize new instances.
* Made Briggs's Mesh_addPropLayer accept PyTypes float/int/str rather then long constants for layer type.

Modified Paths:
--------------
    branches/pyapi_devel/source/blender/python/api2_2x/Armature.c
    branches/pyapi_devel/source/blender/python/api2_2x/BezTriple.c
    branches/pyapi_devel/source/blender/python/api2_2x/Const.c
    branches/pyapi_devel/source/blender/python/api2_2x/Const.h
    branches/pyapi_devel/source/blender/python/api2_2x/CurNurb.c
    branches/pyapi_devel/source/blender/python/api2_2x/Curve.c
    branches/pyapi_devel/source/blender/python/api2_2x/Effect.c
    branches/pyapi_devel/source/blender/python/api2_2x/Font.c
    branches/pyapi_devel/source/blender/python/api2_2x/Geometry.c
    branches/pyapi_devel/source/blender/python/api2_2x/Group.c
    branches/pyapi_devel/source/blender/python/api2_2x/Image.c
    branches/pyapi_devel/source/blender/python/api2_2x/Ipo.c
    branches/pyapi_devel/source/blender/python/api2_2x/Key.c
    branches/pyapi_devel/source/blender/python/api2_2x/MTex.c
    branches/pyapi_devel/source/blender/python/api2_2x/Material.c
    branches/pyapi_devel/source/blender/python/api2_2x/Mesh.c
    branches/pyapi_devel/source/blender/python/api2_2x/Mesh.h
    branches/pyapi_devel/source/blender/python/api2_2x/NLA.c
    branches/pyapi_devel/source/blender/python/api2_2x/Object.c
    branches/pyapi_devel/source/blender/python/api2_2x/Particle.c
    branches/pyapi_devel/source/blender/python/api2_2x/Pose.c
    branches/pyapi_devel/source/blender/python/api2_2x/Scene.c
    branches/pyapi_devel/source/blender/python/api2_2x/Sound.c
    branches/pyapi_devel/source/blender/python/api2_2x/SurfNurb.c
    branches/pyapi_devel/source/blender/python/api2_2x/Text.c
    branches/pyapi_devel/source/blender/python/api2_2x/Text3d.c
    branches/pyapi_devel/source/blender/python/api2_2x/Texture.c
    branches/pyapi_devel/source/blender/python/api2_2x/Types.c
    branches/pyapi_devel/source/blender/python/api2_2x/bpy_data.c
    branches/pyapi_devel/source/blender/python/api2_2x/bpy_float.c
    branches/pyapi_devel/source/blender/python/api2_2x/bpy_list.c
    branches/pyapi_devel/source/blender/python/api2_2x/bpy_types.c
    branches/pyapi_devel/source/blender/python/api2_2x/gen_library.c
    branches/pyapi_devel/source/blender/python/api2_2x/sceneRadio.c
    branches/pyapi_devel/source/blender/python/api2_2x/sceneRender.c
    branches/pyapi_devel/source/blender/python/api2_2x/sceneSequence.c
    branches/pyapi_devel/source/blender/python/api2_2x/sceneTimeLine.c

Modified: branches/pyapi_devel/source/blender/python/api2_2x/Armature.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Armature.c	2007-07-16 19:04:42 UTC (rev 11292)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Armature.c	2007-07-16 21:20:52 UTC (rev 11293)
@@ -1087,163 +1087,6 @@
 	0								//tp_del
 };
 
-//-------------------MODULE METHODS IMPLEMENTATION------------------------
-//----------------Blender.Armature.Get()
-/* This function will return a Py_Armature when a single string is passed
-* or else it will return a {key:value} dictionary when mutliple strings are passed
-* or it will return a {key:value} dictionary of all armatures when nothing is passed */
-static PyObject *M_Armature_Get(PyObject * self, PyObject * args)
-{
-	PyObject *seq = NULL, *item = NULL, *dict = NULL, *py_armature = NULL;
-	char *name = "", buffer[24];
-	int size = 0, i;
-	void *data;
-
-	//GET ARGUMENTS - () ('s') ('s',..) (['s',..]) are exceptable
-	size = PySequence_Length(args);
-	if (size == 1) {
-		seq = PySequence_GetItem(args, 0); //*new*
-		if (!seq)
-			goto RuntimeError;
-		if(!PyString_Check(seq)){
-			if (PySequence_Check(seq)) {
-				size = PySequence_Length(seq);
-			} else {
-				Py_DECREF(seq);
-				goto AttributeError;
-			}
-		}
-	} else {
-		seq = EXPP_incr_ret(args); //*take ownership*
-	}
-	//'seq' should be a list, empty tuple or string - check list for strings
-	if(!PyString_Check(seq)){
-		for(i = 0; i < size; i++){
-			item = PySequence_GetItem(seq, i); //*new*
-			if (!item) {
-				Py_DECREF(seq);
-				goto RuntimeError;
-			}
-			if(!PyString_Check(item)){
-				EXPP_decr2(item, seq);
-				goto AttributeError;
-			}
-			Py_DECREF(item);
-		}
-	}
-
-	//GET ARMATURES
-	if(size != 1){
-		dict = PyDict_New(); //*new*
-		if(!dict){
-			Py_DECREF(seq);
-			goto RuntimeError;
-		}
-		if(size == 0){	//GET ALL ARMATURES
-			data = G.main->armature.first; //get the first data ID from the armature library
-			while (data){
-				py_armature = Armature_CreatePyObject(data); //*new*
-				sprintf(buffer, "%s", ((bArmature*)data)->id.name +2);
-				if(PyDict_SetItemString(dict, buffer, py_armature) == -1){ //add to dictionary
-					EXPP_decr3(seq, dict, py_armature);
-					goto RuntimeError;
-				}
-				Py_DECREF(py_armature);
-				data = ((ID*)data)->next;
-			}
-			Py_DECREF(seq);
-		}else{	//GET ARMATURE LIST
-			for (i = 0; i < size; i++) {
-				item = PySequence_GetItem(seq, i); //*new*
-				name = PyString_AsString(item);
-				Py_DECREF(item);
-				data = find_id("AR", name); //get data from library
-				if (data != NULL){
-					py_armature = Armature_CreatePyObject(data); //*new*
-					if(PyDict_SetItemString(dict, name, py_armature) == -1){ //add to dictionary
-						EXPP_decr3(seq, dict, py_armature);
-						goto RuntimeError;
-					}
-					Py_DECREF(py_armature);
-				}else{
-					if(PyDict_SetItemString(dict, name, Py_None) == -1){ //add to dictionary
-						EXPP_decr2(seq, dict);
-						goto RuntimeError;
-					}
-					Py_DECREF(Py_None);
-				}
-			}
-			Py_DECREF(seq);
-		}
-		return dict;
-	}else{	//GET SINGLE ARMATURE
-		if(!PyString_Check(seq)){ //This handles the bizarre case where (['s']) is passed
-			item = PySequence_GetItem(seq, 0); //*new*
-			name = PyString_AsString(item);
-			Py_DECREF(item);
-		}else{
-			name = PyString_AsString(seq);
-		}
-		Py_DECREF(seq);
-		data = find_id("AR", name); //get data from library
-		if (data != NULL){
-			return Armature_CreatePyObject(data); //*new*
-		}else{
-			char buffer[128];
-			PyOS_snprintf( buffer, sizeof(buffer),
-						   "Armature \"%s\" not found", name);
-			return EXPP_ReturnPyObjError( PyExc_ValueError,
-										  buffer );
-		}
-	}
-
-RuntimeError:
-	return EXPP_objError(PyExc_RuntimeError, "%s%s%s", 
-		sModuleError, "Get(): ", "Internal Error Ocurred");
-
-AttributeError:
-	return EXPP_objError(PyExc_AttributeError, "%s%s%s", 
-		sModuleBadArgs, "Get(): ", "- Expects (optional) string sequence");
-}
-
-
-//----------------Blender.Armature.New()
-static PyObject *M_Armature_New(PyObject * self, PyObject * args)
-{
-	char *name = "Armature";
-	struct bArmature *armature;
-	BPy_Armature *obj;
-
-	if( !PyArg_ParseTuple( args, "|s", &name ) )
-		return EXPP_ReturnPyObjError( PyExc_TypeError,
-					      "expected nothing or a string as argument" );
-
-	armature= add_armature(name);
-	armature->id.us = 0;
-	obj = (BPy_Armature *)Armature_CreatePyObject(armature); /*new*/
-
-	if( !obj )
-		return EXPP_ReturnPyObjError( PyExc_RuntimeError,
-				       "PyObject_New() failed" );	
-
-	obj->armature = armature;
-	return (PyObject *)obj;
-}
-
-
-//-------------------MODULE METHODS DEFINITION-----------------------------
-
-static char M_Armature_Get_doc[] = "(name) - return the armature with the name 'name', \
-  returns None if not found.\n If 'name' is not specified, it returns a list of all \
-  armatures in the\ncurrent scene.";
-
-static char M_Armature_New_doc[] = "(name) - return a new armature object.";
-
-struct PyMethodDef M_Armature_methods[] = {
-	{"Get", M_Armature_Get, METH_VARARGS, M_Armature_Get_doc},
-	{"New", M_Armature_New, METH_VARARGS, M_Armature_New_doc},
-	{NULL, NULL, 0, NULL}
-};
 //------------------VISIBLE PROTOTYPE IMPLEMENTATION-----------------------
 //------------------------Armature_RebuildEditbones (internal)
 PyObject * Armature_RebuildEditbones(PyObject *pyarmature)
@@ -1317,8 +1160,7 @@
 	}
 
 	//Register the module
-	module = Py_InitModule3("Blender.Armature", M_Armature_methods, 
-		"The Blender Armature module"); 
+	module = Py_InitModule3("Blender.Armature", NULL, "The Blender Armature module"); 
 
 	//Add TYPEOBJECTS to the module
 	PyModule_AddObject(module, "Armature", 

Modified: branches/pyapi_devel/source/blender/python/api2_2x/BezTriple.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/BezTriple.c	2007-07-16 19:04:42 UTC (rev 11292)
+++ branches/pyapi_devel/source/blender/python/api2_2x/BezTriple.c	2007-07-16 21:20:52 UTC (rev 11293)
@@ -37,13 +37,6 @@
 #include "MEM_guardedalloc.h"
 #include "gen_utils.h"
 
-
-/***************************************************************************
-  Python API function prototypes for the BezTriple module.                  
-***************************************************************************/
-static PyObject *M_BezTriple_New( PyObject * self, PyObject * args );
-static PyObject *M_BezTriple_Get( PyObject * self, PyObject * args );
-
 /*************************************
  Doc strings for the BezTriple module
 *************************************/
@@ -62,15 +55,6 @@
  Python method structure definition for Blender.BezTriple module:          
 ****************************************************************************/
 
-struct PyMethodDef M_BezTriple_methods[] = {
-	{"New", ( PyCFunction ) M_BezTriple_New, METH_VARARGS | METH_KEYWORDS,
-	 0},
-/*	{"New", ( PyCFunction ) M_BezTriple_New, METH_O, 0}, */
-	{"Get", M_BezTriple_Get, METH_VARARGS, 0},
-	{"get", M_BezTriple_Get, METH_VARARGS, 0},
-	{NULL, NULL, 0, NULL}
-};
-
 /*****************************************************************************/
 /* Python BPy_BezTriple methods table:                                        */
 /*****************************************************************************/
@@ -85,79 +69,8 @@
 	{NULL, NULL, 0, NULL}
 };
 
-/****************************************************************************
- Function:              M_BezTriple_New                                   
- Python equivalent:     Blender.BezTriple.New                             
-****************************************************************************/
 
-static PyObject *M_BezTriple_New( PyObject* self, PyObject * args )
-{
-	float numbuf[9];
-	PyObject* in_args = NULL;
-	int length;
-
-	/* accept list, tuple, or 3 or 9 args (which better be floats) */
-
-	length = PyTuple_Size( args );
-	if( length == 3 || length == 9 )
-		in_args = args;
-	else if( !PyArg_ParseTuple( args, "|O", &in_args) )
-		goto TypeError;
-
-	if( !in_args ) {
-		numbuf[0] = 0.0f; numbuf[1] = 0.0f; numbuf[2] = 0.0f;
-		numbuf[3] = 0.0f; numbuf[4] = 0.0f; numbuf[5] = 0.0f;
-		numbuf[6] = 0.0f; numbuf[7] = 0.0f; numbuf[8] = 0.0f;
-	} else {
-		int i, length;
-		if( !PySequence_Check( in_args ) )
-			goto TypeError;
-
-		length = PySequence_Length( in_args );
-		if( length != 9 && length != 3 )
-			goto TypeError;
-		
-		for( i = 0; i < length; i++ ) {
-			PyObject *item, *pyfloat;
-			item = PySequence_ITEM( in_args, i);
-			if( !item )
-				goto TypeError;
-			pyfloat = PyNumber_Float( item );
-			Py_DECREF( item );
-			if( !pyfloat )
-				goto TypeError;
-			numbuf[i] = ( float )PyFloat_AS_DOUBLE( pyfloat );
-			Py_DECREF( pyfloat );
-		}
-
-		if( length == 3 ) {
-			numbuf[3] = numbuf[0]; numbuf[6] = numbuf[0];
-			numbuf[4] = numbuf[1]; numbuf[7] = numbuf[1];
-			numbuf[5] = numbuf[2]; numbuf[8] = numbuf[2];
-		}
-	}
-
-	return newBezTriple( numbuf );
-
-TypeError:
-	return EXPP_ReturnPyObjError( PyExc_TypeError,
-			"expected sequence of 3 or 9 floats or nothing" );
-}
-
 /****************************************************************************
- Function:              M_BezTriple_Get                                   
- Python equivalent:     Blender.BezTriple.Get                             
- Description:           Receives a string and returns the ipo data obj  
-                        whose name matches the string.  If no argument is  
-                        passed in, a list of all ipo data names in the  
-                        current scene is returned.                         
-****************************************************************************/
-static PyObject *M_BezTriple_Get( PyObject * self, PyObject * args )
-{
-	return 0;
-}
-
-/****************************************************************************
  Function:    BezTriple_dealloc                                            
  Description: This is a callback function for the BPy_BezTriple type. It is  
               the destructor function.                                     
@@ -499,6 +412,66 @@
 	return PyString_FromString( str );
 }
 
+
+/****************************************************************************
+ Function:              M_BezTriple_New                                   
+ Python equivalent:     Blender.BezTriple.New                             

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list