[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25866] trunk/blender/source/blender/ makesrna: Change how 'Main' collection type definitons work so that 'self' can be used without overriding the srna type.

Campbell Barton ideasman42 at gmail.com
Sun Jan 10 16:20:22 CET 2010


Revision: 25866
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25866
Author:   campbellbarton
Date:     2010-01-10 16:20:22 +0100 (Sun, 10 Jan 2010)

Log Message:
-----------
Change how 'Main' collection type definitons work so that 'self' can be used without overriding the srna type.

Modified Paths:
--------------
    trunk/blender/source/blender/makesrna/RNA_types.h
    trunk/blender/source/blender/makesrna/intern/rna_main_api.c

Modified: trunk/blender/source/blender/makesrna/RNA_types.h
===================================================================
--- trunk/blender/source/blender/makesrna/RNA_types.h	2010-01-10 14:40:37 UTC (rev 25865)
+++ trunk/blender/source/blender/makesrna/RNA_types.h	2010-01-10 15:20:22 UTC (rev 25866)
@@ -323,6 +323,16 @@
 	void (*free)(void *data);
 } ExtensionRNA;
 
+/* fake struct definitions, needed otherwise collections end up owning the C
+ * structs like 'Object' when defined first */
+#define MainCameras Main
+#define MainScenes Main
+#define MainArmatures Main
+#define MainMaterials Main
+#define MainMeshes Main
+#define MainLamps Main
+#define MainObjects Main
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/blender/source/blender/makesrna/intern/rna_main_api.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_main_api.c	2010-01-10 14:40:37 UTC (rev 25865)
+++ trunk/blender/source/blender/makesrna/intern/rna_main_api.c	2010-01-10 15:20:22 UTC (rev 25866)
@@ -52,25 +52,24 @@
 #include "DNA_mesh_types.h"
 #include "DNA_object_types.h"
 
-static Tex *rna_Main_add_texture(Main *bmain, char *name)
+Tex *rna_Main_add_texture(Main *bmain, char *name)
 {
 	return add_texture(name);
 }
 
 /* TODO: remove texture? */
 
-static Image *rna_Main_add_image(Main *bmain, char *filename)
+Image *rna_Main_add_image(Main *bmain, char *filename)
 {
 	return BKE_add_image_file(filename, 0);
 }
 
-static Camera *rna_Main_cameras_new(bContext *C, char* name)
+Camera *rna_Main_cameras_new(Main *bmain, char* name)
 {
 	return add_camera(name);
 }
-static void rna_Main_cameras_remove(bContext *C, ReportList *reports, struct Camera *camera)
+void rna_Main_cameras_remove(Main *bmain, ReportList *reports, struct Camera *camera)
 {
-	Main *bmain= CTX_data_main(C);
 	if(camera->id.us == 0)
 		free_libblock(&bmain->camera, camera);
 	else
@@ -79,23 +78,22 @@
 	/* XXX python now has invalid pointer? */
 }
 
-static Scene *rna_Main_scenes_new(bContext *C, char* name)
+Scene *rna_Main_scenes_new(Main *bmain, char* name)
 {
 	return add_scene(name);
 }
-static void rna_Main_scenes_remove(bContext *C, ReportList *reports, struct Scene *scene)
+void rna_Main_scenes_remove(Main *bmain, ReportList *reports, struct Scene *scene)
 {
-	Main *bmain= CTX_data_main(C);
 	free_libblock(&bmain->scene, scene);
 }
 
-static Object *rna_Main_objects_new(bContext *C, char* name, int type)
+Object *rna_Main_objects_new(Main *bmain, char* name, int type)
 {
 	Object *ob= add_only_object(type, name);
 	ob->id.us--;
 	return ob;
 }
-static void rna_Main_objects_remove(bContext *C, ReportList *reports, struct Object *object)
+void rna_Main_objects_remove(Main *bmain, ReportList *reports, struct Object *object)
 {
 	/*
 	  NOTE: the following example shows when this function should _not_ be called
@@ -109,20 +107,18 @@
 	  # don't do this since ob is already freed!
 	  bpy.data.remove_object(ob)
 	*/
-	Main *bmain= CTX_data_main(C);
 	if(object->id.us == 0)
 		free_libblock(&bmain->object, object);
 	else
 		BKE_reportf(reports, RPT_ERROR, "Object \"%s\" must have zero users to be removed, found %d.", object->id.name+2, object->id.us);
 }
 
-static Material *rna_Main_materials_new(bContext *C, char* name)
+struct Material *rna_Main_materials_new(Main *bmain, char* name)
 {
 	return add_material(name);
 }
-static void rna_Main_materials_remove(bContext *C, ReportList *reports, struct Material *material)
+void rna_Main_materials_remove(Main *bmain, ReportList *reports, struct Material *material)
 {
-	Main *bmain= CTX_data_main(C);
 	if(material->id.us == 0)
 		free_libblock(&bmain->mat, material);
 	else
@@ -131,15 +127,14 @@
 	/* XXX python now has invalid pointer? */
 }
 
-static Mesh *rna_Main_meshes_new(bContext *C, char* name)
+Mesh *rna_Main_meshes_new(Main *bmain, char* name)
 {
 	Mesh *me= add_mesh(name);
 	me->id.us--;
 	return me;
 }
-static void rna_Main_meshes_remove(bContext *C, ReportList *reports, Mesh *mesh)
+void rna_Main_meshes_remove(Main *bmain, ReportList *reports, Mesh *mesh)
 {
-	Main *bmain= CTX_data_main(C);
 	if(mesh->id.us == 0)
 		free_libblock(&bmain->mesh, mesh);
 	else
@@ -148,15 +143,14 @@
 	/* XXX python now has invalid pointer? */
 }
 
-static Lamp *rna_Main_lamps_new(bContext *C, char* name)
+Lamp *rna_Main_lamps_new(Main *bmain, char* name)
 {
 	Lamp *lamp= add_lamp(name);
 	lamp->id.us--;
 	return lamp;
 }
-static void rna_Main_lamps_remove(bContext *C, ReportList *reports, Lamp *lamp)
+void rna_Main_lamps_remove(Main *bmain, ReportList *reports, Lamp *lamp)
 {
-	Main *bmain= CTX_data_main(C);
 	if(lamp->id.us == 0)
 		free_libblock(&bmain->lamp, lamp);
 	else
@@ -165,15 +159,14 @@
 	/* XXX python now has invalid pointer? */
 }
 
-static bArmature *rna_Main_armatures_new(bContext *C, char* name)
+bArmature *rna_Main_armatures_new(Main *bmain, char* name)
 {
 	bArmature *arm= add_armature(name);
 	arm->id.us--;
 	return arm;
 }
-static void rna_Main_armatures_remove(bContext *C, ReportList *reports, bArmature *arm)
+void rna_Main_armatures_remove(Main *bmain, ReportList *reports, bArmature *arm)
 {
-	Main *bmain= CTX_data_main(C);
 	if(arm->id.us == 0)
 		free_libblock(&bmain->armature, arm);
 	else
@@ -212,11 +205,9 @@
 
 	RNA_def_property_srna(cprop, "MainCameras");
 	srna= RNA_def_struct(brna, "MainCameras", NULL);
-//	RNA_def_struct_sdna(srna, "Camera");
 	RNA_def_struct_ui_text(srna, "Main Cameras", "Collection of cameras.");
 
 	func= RNA_def_function(srna, "new", "rna_Main_cameras_new");
-	RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT);
 	RNA_def_function_ui_description(func, "Add a new camera to the main database");
 	parm= RNA_def_string(func, "name", "Camera", 0, "", "New name for the datablock.");
 	RNA_def_property_flag(parm, PROP_REQUIRED);
@@ -225,7 +216,7 @@
 	RNA_def_function_return(func, parm);
 
 	func= RNA_def_function(srna, "remove", "rna_Main_cameras_remove");
-	RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
+	RNA_def_function_flag(func, FUNC_USE_REPORTS);
 	RNA_def_function_ui_description(func, "Remove a camera from the current blendfile.");
 	parm= RNA_def_pointer(func, "camera", "Camera", "", "Camera to remove.");
 	RNA_def_property_flag(parm, PROP_REQUIRED);
@@ -239,11 +230,9 @@
 
 	RNA_def_property_srna(cprop, "MainScenes");
 	srna= RNA_def_struct(brna, "MainScenes", NULL);
-//	RNA_def_struct_sdna(srna, "Scene");
 	RNA_def_struct_ui_text(srna, "Main Scenes", "Collection of scenes.");
 
 	func= RNA_def_function(srna, "new", "rna_Main_scenes_new");
-	RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT);
 	RNA_def_function_ui_description(func, "Add a new scene to the main database");
 	parm= RNA_def_string(func, "name", "Scene", 0, "", "New name for the datablock.");
 	RNA_def_property_flag(parm, PROP_REQUIRED);
@@ -252,7 +241,7 @@
 	RNA_def_function_return(func, parm);
 
 	func= RNA_def_function(srna, "remove", "rna_Main_scenes_remove");
-	RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
+	RNA_def_function_flag(func, FUNC_USE_REPORTS);
 	parm= RNA_def_pointer(func, "scene", "Scene", "", "Scene to remove.");
 	RNA_def_property_flag(parm, PROP_REQUIRED);
 	RNA_def_function_ui_description(func, "Remove a scene from the current blendfile.");
@@ -271,7 +260,6 @@
 	RNA_def_struct_ui_text(srna, "Main Objects", "Collection of objects.");
 
 	func= RNA_def_function(srna, "new", "rna_Main_objects_new");
-	RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT);
 	RNA_def_function_ui_description(func, "Add a new object to the main database");
 	parm= RNA_def_string(func, "name", "Object", 0, "", "New name for the datablock.");
 	RNA_def_property_flag(parm, PROP_REQUIRED);
@@ -283,7 +271,7 @@
 	RNA_def_function_return(func, parm);
 
 	func= RNA_def_function(srna, "remove", "rna_Main_objects_remove");
-	RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
+	RNA_def_function_flag(func, FUNC_USE_REPORTS);
 	parm= RNA_def_pointer(func, "object", "Object", "", "Object to remove.");
 	RNA_def_property_flag(parm, PROP_REQUIRED);
 	RNA_def_function_ui_description(func, "Remove a object from the current blendfile.");
@@ -301,7 +289,6 @@
 	RNA_def_struct_ui_text(srna, "Main Material", "Collection of materials.");
 
 	func= RNA_def_function(srna, "new", "rna_Main_materials_new");
-	RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT);
 	RNA_def_function_ui_description(func, "Add a new material to the main database");
 	parm= RNA_def_string(func, "name", "Material", 0, "", "New name for the datablock.");
 	RNA_def_property_flag(parm, PROP_REQUIRED);
@@ -310,7 +297,7 @@
 	RNA_def_function_return(func, parm);
 
 	func= RNA_def_function(srna, "remove", "rna_Main_materials_remove");
-	RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
+	RNA_def_function_flag(func, FUNC_USE_REPORTS);
 	RNA_def_function_ui_description(func, "Remove a material from the current blendfile.");
 	parm= RNA_def_pointer(func, "material", "Material", "", "Material to remove.");
 	RNA_def_property_flag(parm, PROP_REQUIRED);
@@ -331,7 +318,6 @@
 	RNA_def_struct_ui_text(srna, "Main Meshes", "Collection of meshes.");
 
 	func= RNA_def_function(srna, "new", "rna_Main_meshes_new");
-	RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT);
 	RNA_def_function_ui_description(func, "Add a new mesh to the main database");
 	parm= RNA_def_string(func, "name", "Mesh", 0, "", "New name for the datablock.");
 	RNA_def_property_flag(parm, PROP_REQUIRED);
@@ -340,7 +326,7 @@
 	RNA_def_function_return(func, parm);
 
 	func= RNA_def_function(srna, "remove", "rna_Main_meshes_remove");
-	RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
+	RNA_def_function_flag(func, FUNC_USE_REPORTS);
 	RNA_def_function_ui_description(func, "Remove a mesh from the current blendfile.");
 	parm= RNA_def_pointer(func, "mesh", "Mesh", "", "Mesh to remove.");
 	RNA_def_property_flag(parm, PROP_REQUIRED);
@@ -357,7 +343,6 @@
 	RNA_def_struct_ui_text(srna, "Main Lamps", "Collection of lamps.");
 
 	func= RNA_def_function(srna, "new", "rna_Main_lamps_new");
-	RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT);
 	RNA_def_function_ui_description(func, "Add a new lamp to the main database");
 	parm= RNA_def_string(func, "name", "Lamp", 0, "", "New name for the datablock.");
 	RNA_def_property_flag(parm, PROP_REQUIRED);
@@ -366,7 +351,7 @@

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list