Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-11-03 19:07:29 +0300
committerCampbell Barton <ideasman42@gmail.com>2009-11-03 19:07:29 +0300
commitb8b89d5ae4a1c94630847d12112597f4b8256986 (patch)
tree222d63d48a131c05b98a3160ac0fadf74e8eebe9
parentb3c8935b066cd1a9f17cb7199d87ede3f644a35c (diff)
active property for collections for things like scene.objects.active
will add more properties later
-rw-r--r--release/scripts/io/add_mesh_torus.py2
-rw-r--r--source/blender/makesrna/RNA_access.h1
-rw-r--r--source/blender/makesrna/RNA_define.h1
-rw-r--r--source/blender/makesrna/intern/makesrna.c3
-rw-r--r--source/blender/makesrna/intern/rna_access.c6
-rw-r--r--source/blender/makesrna/intern/rna_define.c20
-rw-r--r--source/blender/makesrna/intern/rna_internal_types.h2
-rw-r--r--source/blender/makesrna/intern/rna_scene.c33
-rw-r--r--source/blender/python/intern/bpy_rna.c59
9 files changed, 110 insertions, 17 deletions
diff --git a/release/scripts/io/add_mesh_torus.py b/release/scripts/io/add_mesh_torus.py
index 8a6a3a58ed6..27ef587ce5a 100644
--- a/release/scripts/io/add_mesh_torus.py
+++ b/release/scripts/io/add_mesh_torus.py
@@ -117,7 +117,7 @@ class AddTorusPrimitive(bpy.types.Operator):
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)
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 44b36e65aa3..dc730ee46f9 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -678,6 +678,7 @@ int RNA_property_collection_length(PointerRNA *ptr, PropertyRNA *prop);
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);
diff --git a/source/blender/makesrna/RNA_define.h b/source/blender/makesrna/RNA_define.h
index 37b175fbf12..ed4a371b9c3 100644
--- a/source/blender/makesrna/RNA_define.h
+++ b/source/blender/makesrna/RNA_define.h
@@ -164,6 +164,7 @@ void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char
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 */
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index b16a0f00fd2..6689cda3f2b 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -1834,6 +1834,9 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
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;
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index fac18ba7942..f0aaceec4aa 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -1756,6 +1756,12 @@ int RNA_property_collection_lookup_string(PointerRNA *ptr, PropertyRNA *prop, co
}
}
+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;
diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c
index 48de7ace222..46c4a8af73a 100644
--- a/source/blender/makesrna/intern/rna_define.c
+++ b/source/blender/makesrna/intern/rna_define.c
@@ -1957,6 +1957,26 @@ void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, con
}
}
+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)
diff --git a/source/blender/makesrna/intern/rna_internal_types.h b/source/blender/makesrna/intern/rna_internal_types.h
index 645bc50ed89..434e4ee6fe9 100644
--- a/source/blender/makesrna/intern/rna_internal_types.h
+++ b/source/blender/makesrna/intern/rna_internal_types.h
@@ -257,6 +257,8 @@ typedef struct CollectionPropertyRNA {
PropCollectionLookupStringFunc lookupstring; /* optional */
FunctionRNA *add, *remove;
+ PropertyRNA *active;
+
struct StructRNA *type;
} CollectionPropertyRNA;
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index e7aeac96aef..667f88a3a33 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -2175,6 +2175,7 @@ void RNA_def_scene(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
+ PropertyRNA *prop_act;
FunctionRNA *func;
static EnumPropertyItem audio_distance_model_items[] = {
@@ -2206,15 +2207,6 @@ void RNA_def_scene(BlenderRNA *brna)
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 @@ void RNA_def_scene(BlenderRNA *brna)
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);
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index cd1f7dbc102..eee863e5d1b 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -1412,6 +1412,54 @@ static int pyrna_struct_setattro( BPy_StructRNA * self, PyObject *pyname, PyObje
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;
+ }
+
+ return pyrna_py_to_prop(&self->ptr, prop_act, NULL, value, "StructRNA - Attribute (setattr):");
+ }
+
+ return PyObject_GenericSetAttr((PyObject *)self, pyname, value);
+}
+
static PyObject *pyrna_prop_keys(BPy_PropertyRNA *self)
{
PyObject *ret;
@@ -1850,7 +1898,6 @@ static struct PyMethodDef pyrna_prop_methods[] = {
/* array accessor function */
{"foreach_get", (PyCFunction)pyrna_prop_foreach_get, METH_VARARGS, NULL},
{"foreach_set", (PyCFunction)pyrna_prop_foreach_set, METH_VARARGS, NULL},
-
{NULL, NULL, 0, NULL}
};
@@ -2321,8 +2368,10 @@ PyTypeObject pyrna_prop_Type = {
NULL, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
- NULL, /*PyObject_GenericGetAttr - MINGW Complains, assign later */ /* getattrofunc tp_getattro; */ /* will only use these if this is a subtype of a py class */
- NULL, /*PyObject_GenericSetAttr - MINGW Complains, assign later */ /* setattrofunc tp_setattro; */
+
+ /* will only use these if this is a subtype of a py class */
+ ( getattrofunc ) pyrna_prop_getattro, /* getattrofunc tp_getattro; */
+ ( setattrofunc ) pyrna_prop_setattro, /* setattrofunc tp_setattro; */
/* Functions to access object as input/output buffer */
NULL, /* PyBufferProcs *tp_as_buffer; */
@@ -2589,10 +2638,6 @@ PyObject *BPY_rna_module( void )
mathutils_rna_matrix_cb_index= Mathutils_RegisterCallback(&mathutils_rna_matrix_cb);
#endif
- /* This can't be set in the pytype struct because some compilers complain */
- pyrna_prop_Type.tp_getattro = PyObject_GenericGetAttr;
- pyrna_prop_Type.tp_setattro = PyObject_GenericSetAttr;
-
if( PyType_Ready( &pyrna_struct_Type ) < 0 )
return NULL;