[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24277] trunk/blender: active property for collections for things like scene.objects.active

Campbell Barton ideasman42 at gmail.com
Tue Nov 3 17:07:31 CET 2009


Revision: 24277
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24277
Author:   campbellbarton
Date:     2009-11-03 17:07:29 +0100 (Tue, 03 Nov 2009)

Log Message:
-----------
active property for collections for things like scene.objects.active
will add more properties later

Modified Paths:
--------------
    trunk/blender/release/scripts/io/add_mesh_torus.py
    trunk/blender/source/blender/makesrna/RNA_access.h
    trunk/blender/source/blender/makesrna/RNA_define.h
    trunk/blender/source/blender/makesrna/intern/makesrna.c
    trunk/blender/source/blender/makesrna/intern/rna_access.c
    trunk/blender/source/blender/makesrna/intern/rna_define.c
    trunk/blender/source/blender/makesrna/intern/rna_internal_types.h
    trunk/blender/source/blender/makesrna/intern/rna_scene.c
    trunk/blender/source/blender/python/intern/bpy_rna.c

Modified: trunk/blender/release/scripts/io/add_mesh_torus.py
===================================================================
--- trunk/blender/release/scripts/io/add_mesh_torus.py	2009-11-03 14:10:34 UTC (rev 24276)
+++ trunk/blender/release/scripts/io/add_mesh_torus.py	2009-11-03 16:07:29 UTC (rev 24277)
@@ -117,7 +117,7 @@
         ob_new = bpy.data.add_object('MESH', "Torus")
         ob_new.data = mesh
         scene.add_object(ob_new)
-        scene.active_object = ob_new
+        scene.objects.active = ob_new
         ob_new.selected = True
 
         ob_new.location = tuple(context.scene.cursor_location)

Modified: trunk/blender/source/blender/makesrna/RNA_access.h
===================================================================
--- trunk/blender/source/blender/makesrna/RNA_access.h	2009-11-03 14:10:34 UTC (rev 24276)
+++ trunk/blender/source/blender/makesrna/RNA_access.h	2009-11-03 16:07:29 UTC (rev 24277)
@@ -678,6 +678,7 @@
 int RNA_property_collection_lookup_index(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *t_ptr);
 int RNA_property_collection_lookup_int(PointerRNA *ptr, PropertyRNA *prop, int key, PointerRNA *r_ptr);
 int RNA_property_collection_lookup_string(PointerRNA *ptr, PropertyRNA *prop, const char *key, PointerRNA *r_ptr);
+PropertyRNA *RNA_property_collection_active(PropertyRNA *prop);
 
 /* efficient functions to set properties for arrays */
 int RNA_property_collection_raw_array(PointerRNA *ptr, PropertyRNA *prop, PropertyRNA *itemprop, RawArray *array);

Modified: trunk/blender/source/blender/makesrna/RNA_define.h
===================================================================
--- trunk/blender/source/blender/makesrna/RNA_define.h	2009-11-03 14:10:34 UTC (rev 24276)
+++ trunk/blender/source/blender/makesrna/RNA_define.h	2009-11-03 16:07:29 UTC (rev 24277)
@@ -164,6 +164,7 @@
 void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set);
 void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *typef);
 void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, const char *next, const char *end, const char *get, const char *length, const char *lookupint, const char *lookupstring, const char *add, const char *remove);
+void RNA_def_property_collection_active(PropertyRNA *prop, PropertyRNA *prop_act);
 
 /* Function */
 

Modified: trunk/blender/source/blender/makesrna/intern/makesrna.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/makesrna.c	2009-11-03 14:10:34 UTC (rev 24276)
+++ trunk/blender/source/blender/makesrna/intern/makesrna.c	2009-11-03 16:07:29 UTC (rev 24277)
@@ -1834,6 +1834,9 @@
 				else fprintf(f, "NULL, ");
 				if(cprop->remove) fprintf(f, "&rna_%s_%s_func, ", srna->identifier, (char*)cprop->remove);
 				else fprintf(f, "NULL, ");
+
+				if(cprop->active) fprintf(f, "(PropertyRNA*)&rna_%s%s_%s, ", srna->identifier, strnest, cprop->active->identifier);
+
 				if(cprop->type) fprintf(f, "&RNA_%s\n", (char*)cprop->type);
 				else fprintf(f, "NULL\n");
 				break;

Modified: trunk/blender/source/blender/makesrna/intern/rna_access.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_access.c	2009-11-03 14:10:34 UTC (rev 24276)
+++ trunk/blender/source/blender/makesrna/intern/rna_access.c	2009-11-03 16:07:29 UTC (rev 24277)
@@ -1756,6 +1756,12 @@
 	}
 }
 
+PropertyRNA *RNA_property_collection_active(PropertyRNA *prop)
+{
+	CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
+	return cprop->active;
+}
+
 int RNA_property_collection_raw_array(PointerRNA *ptr, PropertyRNA *prop, PropertyRNA *itemprop, RawArray *array)
 {
 	CollectionPropertyIterator iter;

Modified: trunk/blender/source/blender/makesrna/intern/rna_define.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_define.c	2009-11-03 14:10:34 UTC (rev 24276)
+++ trunk/blender/source/blender/makesrna/intern/rna_define.c	2009-11-03 16:07:29 UTC (rev 24277)
@@ -1957,6 +1957,26 @@
 	}
 }
 
+void RNA_def_property_collection_active(PropertyRNA *prop, PropertyRNA *prop_act)
+{
+	if(!DefRNA.preprocess) {
+		fprintf(stderr, "RNA_def_property_collection_active: only during preprocessing.\n");
+		return;
+	}
+
+	switch(prop->type) {
+		case PROP_COLLECTION: {
+			CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
+			cprop->active= prop_act;
+			break;
+		}
+		default:
+			fprintf(stderr, "RNA_def_property_collection_active: %s.%s, type is not collection.\n", prop->identifier, prop_act->identifier);
+			DefRNA.error= 1;
+			break;
+	}
+}
+
 /* Compact definitions */
 
 PropertyRNA *RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, int default_value, const char *ui_name, const char *ui_description)

Modified: trunk/blender/source/blender/makesrna/intern/rna_internal_types.h
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_internal_types.h	2009-11-03 14:10:34 UTC (rev 24276)
+++ trunk/blender/source/blender/makesrna/intern/rna_internal_types.h	2009-11-03 16:07:29 UTC (rev 24277)
@@ -257,6 +257,8 @@
 	PropCollectionLookupStringFunc lookupstring;	/* optional */
 	FunctionRNA *add, *remove;
 
+	PropertyRNA *active;
+
 	struct StructRNA *type;
 } CollectionPropertyRNA;
 

Modified: trunk/blender/source/blender/makesrna/intern/rna_scene.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_scene.c	2009-11-03 14:10:34 UTC (rev 24276)
+++ trunk/blender/source/blender/makesrna/intern/rna_scene.c	2009-11-03 16:07:29 UTC (rev 24277)
@@ -2175,6 +2175,7 @@
 {
 	StructRNA *srna;
 	PropertyRNA *prop;
+	PropertyRNA *prop_act;
 	FunctionRNA *func;
 	
 	static EnumPropertyItem audio_distance_model_items[] = {
@@ -2206,15 +2207,6 @@
 	RNA_def_property_pointer_funcs(prop, NULL, "rna_Scene_set_set", NULL);
 	RNA_def_property_ui_text(prop, "Set Scene", "Background set scene.");
 
-	prop= RNA_def_property(srna, "active_object", PROP_POINTER, PROP_NONE);
-	RNA_def_property_struct_type(prop, "Object");
-	RNA_def_property_pointer_funcs(prop, "rna_Scene_active_object_get", "rna_Scene_active_object_set", NULL);
-	RNA_def_property_flag(prop, PROP_EDITABLE);
-	RNA_def_property_ui_text(prop, "Object", "Object to use as projector transform.");
-	/* Could call: ED_base_object_activate(C, scene->basact);
-	 * but would be a bad level call and it seems the notifier is enough */
-	RNA_def_property_update(prop, NC_SCENE|ND_OB_ACTIVE, NULL);
-
 	prop= RNA_def_property(srna, "world", PROP_POINTER, PROP_NONE);
 	RNA_def_property_flag(prop, PROP_EDITABLE);
 	RNA_def_property_ui_text(prop, "World", "World used for rendering the scene.");
@@ -2232,12 +2224,35 @@
 	RNA_def_property_struct_type(prop, "Base");
 	RNA_def_property_ui_text(prop, "Bases", "");
 
+	{ /* Collection active property */
+		prop_act= RNA_def_property(srna, "base_active", PROP_POINTER, PROP_NONE);
+		RNA_def_property_struct_type(prop_act, "Base");
+		RNA_def_property_pointer_sdna(prop_act, NULL, "basact");
+		RNA_def_property_flag(prop_act, PROP_EDITABLE);
+		RNA_def_property_ui_text(prop_act, "Active Base", "Active object in the scene.");
+		RNA_def_property_update(prop_act, NC_SCENE|ND_OB_ACTIVE, NULL);
+		RNA_def_property_collection_active(prop, prop_act);
+	}
+
 	prop= RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
 	RNA_def_property_collection_sdna(prop, NULL, "base", NULL);
 	RNA_def_property_struct_type(prop, "Object");
 	RNA_def_property_ui_text(prop, "Objects", "");
 	RNA_def_property_collection_funcs(prop, 0, 0, 0, "rna_Scene_objects_get", 0, 0, 0, 0, 0);
 
+	{ /* Collection active property */
+		prop_act= RNA_def_property(srna, "objects_active", PROP_POINTER, PROP_NONE);
+		RNA_def_property_struct_type(prop_act, "Object");
+		RNA_def_property_pointer_funcs(prop_act, "rna_Scene_active_object_get", "rna_Scene_active_object_set", NULL);
+		RNA_def_property_flag(prop_act, PROP_EDITABLE);
+		RNA_def_property_ui_text(prop_act, "Object", "Object to use as projector transform.");
+		/* Could call: ED_base_object_activate(C, scene->basact);
+		 * but would be a bad level call and it seems the notifier is enough */
+		RNA_def_property_update(prop_act, NC_SCENE|ND_OB_ACTIVE, NULL);
+
+		RNA_def_property_collection_active(prop, prop_act);
+	}
+
 	/* Layers */
 	prop= RNA_def_property(srna, "visible_layers", PROP_BOOLEAN, PROP_LAYER_MEMBER);
 	RNA_def_property_boolean_sdna(prop, NULL, "lay", 1);

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c	2009-11-03 14:10:34 UTC (rev 24276)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c	2009-11-03 16:07:29 UTC (rev 24277)
@@ -1412,6 +1412,54 @@
 	return pyrna_py_to_prop(&self->ptr, prop, NULL, value, "StructRNA - Attribute (setattr):");
 }
 
+static PyObject *pyrna_prop_getattro( BPy_PropertyRNA * self, PyObject *pyname )
+{
+	char *name = _PyUnicode_AsString(pyname);
+
+	if(strcmp(name, "active")==0) {
+		PropertyRNA *prop_act;
+
+		if (RNA_property_type(self->prop) != PROP_COLLECTION) {
+			PyErr_SetString( PyExc_TypeError, "this BPy_PropertyRNA object is not a collection");
+			return NULL;
+		}
+
+		prop_act= RNA_property_collection_active(self->prop);
+		if (prop_act==NULL) {
+			PyErr_SetString( PyExc_TypeError, "collection has no active");
+			return NULL;
+		}
+
+		return pyrna_prop_to_py(&self->ptr, prop_act);
+	}
+
+	return PyObject_GenericGetAttr((PyObject *)self, pyname);
+}
+
+//--------------- setattr-------------------------------------------
+static int pyrna_prop_setattro( BPy_PropertyRNA * self, PyObject *pyname, PyObject * value )
+{
+	char *name = _PyUnicode_AsString(pyname);
+	if(strcmp(name, "active")==0) {
+		PropertyRNA *prop_act;
+
+		if (RNA_property_type(self->prop) != PROP_COLLECTION) {
+			PyErr_SetString( PyExc_TypeError, "this BPy_PropertyRNA object is not a collection");
+			return -1;
+		}
+
+		prop_act= RNA_property_collection_active(self->prop);
+		if (prop_act==NULL) {
+			PyErr_SetString( PyExc_TypeError, "collection has no active");
+			return -1;
+		}
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list