[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11310] branches/pyapi_devel/source/ blender/python: work in progress - moving to kens new constants

Campbell Barton cbarton at metavr.com
Wed Jul 18 21:00:03 CEST 2007


Revision: 11310
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11310
Author:   campbellbarton
Date:     2007-07-18 21:00:03 +0200 (Wed, 18 Jul 2007)

Log Message:
-----------
work in progress - moving to kens new constants
also redid most of the effect module
lots of other misc changes too

Modified Paths:
--------------
    branches/pyapi_devel/source/blender/python/BPY_interface.c
    branches/pyapi_devel/source/blender/python/api2_2x/Armature.c
    branches/pyapi_devel/source/blender/python/api2_2x/Armature.h
    branches/pyapi_devel/source/blender/python/api2_2x/BezTriple.c
    branches/pyapi_devel/source/blender/python/api2_2x/BezTriple.h
    branches/pyapi_devel/source/blender/python/api2_2x/Blender.c
    branches/pyapi_devel/source/blender/python/api2_2x/Bone.c
    branches/pyapi_devel/source/blender/python/api2_2x/Camera.c
    branches/pyapi_devel/source/blender/python/api2_2x/Const.h
    branches/pyapi_devel/source/blender/python/api2_2x/Constraint.c
    branches/pyapi_devel/source/blender/python/api2_2x/Constraint.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/Draw.c
    branches/pyapi_devel/source/blender/python/api2_2x/Effect.c
    branches/pyapi_devel/source/blender/python/api2_2x/Effect.h
    branches/pyapi_devel/source/blender/python/api2_2x/Font.c
    branches/pyapi_devel/source/blender/python/api2_2x/Font.h
    branches/pyapi_devel/source/blender/python/api2_2x/Image.c
    branches/pyapi_devel/source/blender/python/api2_2x/Image.h
    branches/pyapi_devel/source/blender/python/api2_2x/Ipo.c
    branches/pyapi_devel/source/blender/python/api2_2x/Ipo.h
    branches/pyapi_devel/source/blender/python/api2_2x/Ipocurve.c
    branches/pyapi_devel/source/blender/python/api2_2x/Ipocurve.h
    branches/pyapi_devel/source/blender/python/api2_2x/Key.c
    branches/pyapi_devel/source/blender/python/api2_2x/Key.h
    branches/pyapi_devel/source/blender/python/api2_2x/Lamp.c
    branches/pyapi_devel/source/blender/python/api2_2x/Material.c
    branches/pyapi_devel/source/blender/python/api2_2x/Material.h
    branches/pyapi_devel/source/blender/python/api2_2x/Mesh.c
    branches/pyapi_devel/source/blender/python/api2_2x/Metaball.c
    branches/pyapi_devel/source/blender/python/api2_2x/Metaball.h
    branches/pyapi_devel/source/blender/python/api2_2x/Modifier.c
    branches/pyapi_devel/source/blender/python/api2_2x/Modifier.h
    branches/pyapi_devel/source/blender/python/api2_2x/NLA.c
    branches/pyapi_devel/source/blender/python/api2_2x/Noise.c
    branches/pyapi_devel/source/blender/python/api2_2x/Object.c
    branches/pyapi_devel/source/blender/python/api2_2x/Pose.c
    branches/pyapi_devel/source/blender/python/api2_2x/Text3d.c
    branches/pyapi_devel/source/blender/python/api2_2x/Text3d.h
    branches/pyapi_devel/source/blender/python/api2_2x/Texture.c
    branches/pyapi_devel/source/blender/python/api2_2x/Window.c
    branches/pyapi_devel/source/blender/python/api2_2x/bpy.c
    branches/pyapi_devel/source/blender/python/api2_2x/bpy_data.c
    branches/pyapi_devel/source/blender/python/api2_2x/bpy_types.c
    branches/pyapi_devel/source/blender/python/api2_2x/gen_utils.c
    branches/pyapi_devel/source/blender/python/api2_2x/gen_utils.h
    branches/pyapi_devel/source/blender/python/api2_2x/logic.c
    branches/pyapi_devel/source/blender/python/api2_2x/object_softbody.c
    branches/pyapi_devel/source/blender/python/api2_2x/sceneRadio.c
    branches/pyapi_devel/source/blender/python/api2_2x/sceneRender.c

Modified: branches/pyapi_devel/source/blender/python/BPY_interface.c
===================================================================
--- branches/pyapi_devel/source/blender/python/BPY_interface.c	2007-07-18 17:11:54 UTC (rev 11309)
+++ branches/pyapi_devel/source/blender/python/BPY_interface.c	2007-07-18 19:00:03 UTC (rev 11310)
@@ -60,7 +60,6 @@
 #include "BKE_global.h"
 #include "BKE_main.h"
 #include "api2_2x/EXPP_interface.h"
-#include "api2_2x/constant.h"
 #include "api2_2x/gen_utils.h"
 #include "api2_2x/gen_library.h" /* GetPyObjectFromID */
 #include "api2_2x/BGL.h" 
@@ -641,7 +640,7 @@
 int BPY_txt_do_python_Text( struct Text *text )
 {
 	PyObject *py_dict, *py_result;
-	BPy_constant *info;
+	PyObject *info;
 	char textname[24];
 	Script *script = G.main->script.first;
 
@@ -693,14 +692,14 @@
 
 	script->py_globaldict = py_dict;
 
-	info = ( BPy_constant * ) PyConstant_New(  );
+	info = PyDict_New();
 	if( info ) {
-		PyConstant_Insert( info, "name",
-				 PyString_FromString( script->id.name + 2 ) );
-		Py_INCREF( Py_None );
-		PyConstant_Insert( info, "arg", Py_None );
-		EXPP_dict_set_item_str( py_dict, "__script__",
-				      ( PyObject * ) info );
+		PyObject *tmpstr = PyString_FromString( script->id.name + 2 );
+		PyDict_SetItemString(info, "name",	tmpstr );
+		Py_DECREF(tmpstr);
+		PyDict_SetItemString(info, "arg",	Py_None);
+		PyDict_SetItemString( py_dict, "__script__", info );
+		Py_DECREF(info);
 	}
 
 	py_result = RunPython( text, py_dict );	/* Run the script */
@@ -721,6 +720,7 @@
 			ReleaseGlobalDictionary( py_dict );
 			script->py_globaldict = NULL;
 			free_libblock( &G.main->script, script );
+		
 		}
 	}
 
@@ -795,7 +795,7 @@
 int BPY_menu_do_python( short menutype, int event )
 {
 	PyObject *py_dict, *py_res, *pyarg = NULL;
-	BPy_constant *info;
+	PyObject *info;
 	BPyMenu *pym;
 	BPySubMenu *pysm;
 	FILE *fp = NULL;
@@ -937,14 +937,15 @@
 	py_dict = CreateGlobalDictionary(  );
 
 	script->py_globaldict = py_dict;
-
-	info = ( BPy_constant * ) PyConstant_New(  );
+	
+	info = PyDict_New();
 	if( info ) {
-		PyConstant_Insert( info, "name",
-				 PyString_FromString( script->id.name + 2 ) );
-		PyConstant_Insert( info, "arg", pyarg );
-		EXPP_dict_set_item_str( py_dict, "__script__",
-				      ( PyObject * ) info );
+		PyObject *tmpstr = PyString_FromString( script->id.name + 2 );
+		PyDict_SetItemString(info, "name",	tmpstr );
+		Py_DECREF(tmpstr);
+		PyDict_SetItemString(info, "arg",	pyarg);
+		PyDict_SetItemString( py_dict, "__script__", info );
+		Py_DECREF(info);
 	}
 
 	/* Previously we used PyRun_File to run directly the code on a FILE 
@@ -1900,7 +1901,7 @@
 		disable_where_scriptlink( (short)during_slink );
 
 		/* set globals in Blender module to identify scriptlink */
-		EXPP_dict_set_item_str( g_blenderdict, "bylink", EXPP_incr_ret_True() );
+		EXPP_dict_set_item_str( g_blenderdict, "bylink", Py_True ); Py_INCREF(Py_True);
 		EXPP_dict_set_item_str( g_blenderdict, "link",
 				      GetPyObjectFromID( id ) );
 		EXPP_dict_set_item_str( g_blenderdict, "event",
@@ -1942,7 +1943,7 @@
 		/* cleanup bylink flag and clear link so PyObject
 		 * can be released 
 		 */
-		EXPP_dict_set_item_str( g_blenderdict, "bylink", EXPP_incr_ret_False() );
+		PyDict_SetItemString(g_blenderdict, "bylink", Py_False);
 		PyDict_SetItemString( g_blenderdict, "link", Py_None );
 		EXPP_dict_set_item_str( g_blenderdict, "event",
 				      PyString_FromString( "" ) );
@@ -2121,7 +2122,7 @@
 		}
 
 		/* set globals in Blender module to identify space handler scriptlink */
-		EXPP_dict_set_item_str(g_blenderdict, "bylink", EXPP_incr_ret_True());
+		EXPP_dict_set_item_str(g_blenderdict, "bylink", Py_True); Py_INCREF(Py_True);
 		/* unlike normal scriptlinks, here Blender.link is int (space event type) */
 		EXPP_dict_set_item_str(g_blenderdict, "link", PyInt_FromLong(space_event));
 		/* note: DRAW space_events set event to 0 */
@@ -2181,7 +2182,7 @@
 
 		}
 
-		EXPP_dict_set_item_str(g_blenderdict, "bylink", EXPP_incr_ret_False());
+		PyDict_SetItemString(g_blenderdict, "bylink", Py_False);
 		PyDict_SetItemString(g_blenderdict, "link", Py_None );
 		EXPP_dict_set_item_str(g_blenderdict, "event", PyString_FromString(""));
 	}

Modified: branches/pyapi_devel/source/blender/python/api2_2x/Armature.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Armature.c	2007-07-18 17:11:54 UTC (rev 11309)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Armature.c	2007-07-18 19:00:03 UTC (rev 11310)
@@ -43,6 +43,7 @@
 #include "NLA.h"
 #include "gen_utils.h"
 #include "gen_library.h"
+#include "Const.h"
 
 #include "DNA_object_types.h" //This must come before BIF_editarmature.h...
 #include "BIF_editarmature.h"
@@ -641,55 +642,53 @@
 	return EXPP_intError(PyExc_AttributeError, "%s%s", 
 		sArmatureBadArgs, "Expects True or False");
 }
+
+/*****************************************************************************/
+/* PythonTypeObject constant declarations                                    */
+/*****************************************************************************/
+
+/* 
+ * structure of "tuples" of constant's string name and int value
+ *
+ * For example, these two structures will define the constant category
+ * "bpy.class.Object.DrawTypes" the constant 
+ * "bpy.class.Object.DrawTypes.BOUNDBOX" and others.
+ */
+
+static constIdents drawTypesIdents[] = {
+	{"BOUNDBOX",	{(int)ARM_OCTA}},
+	{"STICK",		{(int)ARM_LINE}},
+	{"BBONE",		{(int)ARM_B_BONE}},
+	{"ENVELOPE",	{(int)ARM_ENVELOPE}},
+};
+
+/* 
+ * structure with constant internal type (int), constant category name,
+ * and number of constant values in the category.
+ */
+
+static constDefinition drawTypes = {
+	EXPP_CONST_INT, "DrawTypes",
+		sizeof(drawTypesIdents)/sizeof(constIdents), drawTypesIdents
+};
+
 //------------------------Armature.drawType (getter)
-static PyObject *Armature_getDrawType(BPy_Armature *self, void *closure)
+static PyObject *Armature_getDrawType(BPy_Armature *self)
 {
-	if (self->armature->drawtype == ARM_OCTA){
-		return EXPP_GetModuleConstant("Blender.Armature", "OCTAHEDRON") ;
-	}else if (self->armature->drawtype == ARM_LINE){
-		return EXPP_GetModuleConstant("Blender.Armature", "STICK") ;
-	}else if (self->armature->drawtype == ARM_B_BONE){
-		return EXPP_GetModuleConstant("Blender.Armature", "BBONE") ;
-	}else if (self->armature->drawtype == ARM_ENVELOPE){
-		return EXPP_GetModuleConstant("Blender.Armature", "ENVELOPE") ;
-	}else{
-		goto RuntimeError;
-	}
-
-RuntimeError:
-	return EXPP_objError(PyExc_RuntimeError, "%s%s%s", 
-		sArmatureError, "drawType: ", "Internal failure!");
+	return PyConst_NewInt( &drawTypes, self->armature->drawtype );
 }
 //------------------------Armature.drawType (setter)
-static int Armature_setDrawType(BPy_Armature *self, PyObject *value, void *closure)
+static int Armature_setDrawType(BPy_Armature *self, PyObject *value)
 {
-	PyObject *val = NULL, *name = NULL;
-	long numeric_value;
-
-	if(value){
-		if(BPy_Constant_Check(value)){
-			name = PyDict_GetItemString(((BPy_constant*)value)->dict, "name");
-			if (!STREQ2(PyString_AsString(name), "OCTAHEDRON", "STICK") &&
-				!STREQ2(PyString_AsString(name), "BBONE", "ENVELOPE"))
-				goto ValueError;
-			val = PyDict_GetItemString(((BPy_constant*)value)->dict, "value");
-			if (PyInt_Check(val)){
-				numeric_value = PyInt_AS_LONG(val);
-				self->armature->drawtype = (int)numeric_value;
-				return 0;
-			}
-		}
-	}
-	goto AttributeError;
-
-AttributeError:
-	return EXPP_intError(PyExc_AttributeError, "%s%s", 
-		sArmatureBadArgs, "Expects module constant");
-
-ValueError:
-	return EXPP_intError(PyExc_AttributeError, "%s%s", 
-		sArmatureBadArgs, "Argument must be the constant OCTAHEDRON, STICK, BBONE, or ENVELOPE");
+	constValue *c = Const_FromPyObject( &drawTypes, value);
+	if( !c )
+		return EXPP_ReturnIntError( PyExc_TypeError,
+				"expected DrawType constant or string" );
+	
+	self->armature->drawtype = c->i;
+	return 0;
 }
+
 //------------------------Armature.ghostStep (getter)
 static PyObject *Armature_getStep(BPy_Armature *self, void *closure)
 {
@@ -1148,58 +1147,42 @@
 		sModuleError, "Armature_CreatePyObject: ", "Internal Error Ocurred");
 }
 
-//-------------------MODULE INITIALIZATION--------------------------------
-PyObject *Armature_Init(void)
+/*****************************************************************************/
+/* ObjectType_Init(): add constants to the type at run-rime and initialize   */
+/*****************************************************************************/
+PyObject *ArmatureType_Init( void )
 {
-	PyObject *module, *dict;
+	/* only allocate new dictionary once */
+	if( Armature_Type.tp_dict == NULL ) {
+		Armature_Type.tp_dict = PyDict_New();
+		PyConstCategory_AddObjectToDict( Armature_Type.tp_dict, &drawTypes );
+		PyType_Ready( &Armature_Type ) ;
+	}
+	return (PyObject *) &Armature_Type ;
+}
 
+//-------------------MODULE INITIALIZATION--------------------------------
+void Armature_Init(void)
+{
 	//Initializes TypeObject.ob_type
-	if (PyType_Ready(&Armature_Type) < 0 ||	PyType_Ready(&BonesDict_Type) < 0 || 
-		PyType_Ready(&EditBone_Type) < 0 ||	PyType_Ready(&Bone_Type) < 0) {
-		return EXPP_incr_ret(Py_None);
-	}
+	PyType_Ready(&BonesDict_Type);
+	PyType_Ready(&EditBone_Type);
+	PyType_Ready(&Bone_Type);
 
 	//Register the module
-	module = Py_InitModule3("Blender.Armature", NULL, "The Blender Armature module"); 
+	//module = Py_InitModule3("Blender.Armature", NULL, "The Blender Armature module"); 
 
 	//Add TYPEOBJECTS to the module
-	PyModule_AddObject(module, "Armature", 
-		EXPP_incr_ret((PyObject *)&Armature_Type)); //*steals*
+	/*
 	PyModule_AddObject(module, "Bone", 
 		EXPP_incr_ret((PyObject *)&Bone_Type)); //*steals*
 	PyModule_AddObject(module, "Editbone", 
 		EXPP_incr_ret((PyObject *)&EditBone_Type)); //*steals*
-
-	//Add CONSTANTS to the module
-	PyModule_AddObject(module, "CONNECTED", 
-		PyConstant_NewInt("CONNECTED", BONE_CONNECTED));
-	PyModule_AddObject(module, "HINGE", 
-		PyConstant_NewInt("HINGE", BONE_HINGE));
-	PyModule_AddObject(module, "NO_DEFORM", 
-		PyConstant_NewInt("NO_DEFORM", BONE_NO_DEFORM));
-	PyModule_AddObject(module, "MULTIPLY", 
-		PyConstant_NewInt("MULTIPLY", BONE_MULT_VG_ENV));
-	PyModule_AddObject(module, "HIDDEN_EDIT", 
-		PyConstant_NewInt("HIDDEN_EDIT", BONE_HIDDEN_A));
-	PyModule_AddObject(module, "ROOT_SELECTED", 
-		PyConstant_NewInt("ROOT_SELECTED", BONE_ROOTSEL));

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list