diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-11-11 19:28:53 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-11-11 19:28:53 +0300 |
commit | bc6190f3e370d21aff0bd9d96fd43d92382c6466 (patch) | |
tree | 94bdbadbeb908085e86fd73b447df1ec1ed05858 /source/blender/makesrna/intern | |
parent | f24392805515416bdba35f531457183e67ef274c (diff) |
python api for collection add()/remove()
Added a group example
C = bpy.context
ob = C.active_object
bpy.data.groups[0].objects.add(ob)
- add_to_group and rem_from_group now take optional scene and base flags and deal with updating the object & base flags
- operators that add objects to groups were setting ob->recalc= OB_RECALC_OB; looks like its not needed.
- previously add() ignored python args, now add and remove are called like any other FunctionRNA from python.
- made the pyrna api use tp_getset's for collestions active/add()/remove()
Diffstat (limited to 'source/blender/makesrna/intern')
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 25 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_group.c | 52 |
2 files changed, 68 insertions, 9 deletions
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 93e83492efa..dea593c78a5 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -1567,7 +1567,7 @@ int RNA_property_collection_length(PointerRNA *ptr, PropertyRNA *prop) void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *r_ptr) { IDProperty *idprop; - CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; +// CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; if((idprop=rna_idproperty_check(&prop, ptr))) { IDPropertyTemplate val = {0}; @@ -1593,6 +1593,9 @@ void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA MEM_freeN(item); } } + + /* py api calls directly */ +#if 0 else if(cprop->add){ if(!(cprop->add->flag & FUNC_USE_CONTEXT)) { /* XXX check for this somewhere else */ ParameterList params; @@ -1603,6 +1606,7 @@ void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA } /*else printf("RNA_property_collection_add %s.%s: not implemented for this property.\n", ptr->type->identifier, prop->identifier);*/ +#endif if(r_ptr) { if(idprop) { @@ -1620,7 +1624,7 @@ void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA int RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key) { IDProperty *idprop; - CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; +// CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; if((idprop=rna_idproperty_check(&prop, ptr))) { IDProperty tmp, *array; @@ -1644,6 +1648,9 @@ int RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key) } else if(prop->flag & PROP_IDPROPERTY) return 1; + + /* py api calls directly */ +#if 0 else if(cprop->remove){ if(!(cprop->remove->flag & FUNC_USE_CONTEXT)) { /* XXX check for this somewhere else */ ParameterList params; @@ -1656,7 +1663,7 @@ int RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key) } /*else printf("RNA_property_collection_remove %s.%s: only supported for id properties.\n", ptr->type->identifier, prop->identifier);*/ - +#endif return 0; } @@ -1767,6 +1774,18 @@ PropertyRNA *RNA_property_collection_active(PropertyRNA *prop) return cprop->active; } +FunctionRNA *RNA_property_collection_add_func(PropertyRNA *prop) +{ + CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; + return cprop->add; +} + +FunctionRNA *RNA_property_collection_remove_func(PropertyRNA *prop) +{ + CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; + return cprop->remove; +} + int RNA_property_collection_raw_array(PointerRNA *ptr, PropertyRNA *prop, PropertyRNA *itemprop, RawArray *array) { CollectionPropertyIterator iter; diff --git a/source/blender/makesrna/intern/rna_group.c b/source/blender/makesrna/intern/rna_group.c index dddc2062f07..8f6a5f1005c 100644 --- a/source/blender/makesrna/intern/rna_group.c +++ b/source/blender/makesrna/intern/rna_group.c @@ -33,6 +33,11 @@ #ifdef RNA_RUNTIME +#include "DNA_scene_types.h" +#include "DNA_object_types.h" + +#include "BKE_group.h" + static PointerRNA rna_Group_objects_get(CollectionPropertyIterator *iter) { ListBaseIterator *internal= iter->internal; @@ -41,6 +46,16 @@ static PointerRNA rna_Group_objects_get(CollectionPropertyIterator *iter) return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ((GroupObject*)internal->link)->ob); } +static int rna_Group_objects_add(Group *group, bContext *C, Object *object) +{ + return add_to_group(group, object, CTX_data_scene(C), NULL); +} + +static int rna_Group_objects_remove(Group *group, bContext *C, Object *object) +{ + return rem_from_group(group, object, CTX_data_scene(C), NULL); +} + #else void RNA_def_group(BlenderRNA *brna) @@ -57,16 +72,41 @@ void RNA_def_group(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Dupli Offset", "Offset from the center to use when instancing as DupliGroup."); RNA_def_property_ui_range(prop, -10000.0, 10000.0, 10, 4); + prop= RNA_def_property(srna, "layer", PROP_BOOLEAN, PROP_LAYER); + RNA_def_property_boolean_sdna(prop, NULL, "layer", 1); + RNA_def_property_array(prop, 20); + RNA_def_property_ui_text(prop, "Dupli Layers", "Layers visible when this groups is instanced as a dupli."); + + + /* add object */ + FunctionRNA *func; + PropertyRNA *parm; + func= RNA_def_function(srna, "add_object", "rna_Group_objects_add"); + RNA_def_function_flag(func, FUNC_USE_CONTEXT); + RNA_def_function_ui_description(func, "Add this object to a group"); + /* return type */ + parm= RNA_def_boolean(func, "success", 0, "Success", "Newly created Group Target."); + RNA_def_function_return(func, parm); + /* object to add */ + parm= RNA_def_pointer(func, "object", "Object", "", "Object to add."); + RNA_def_property_flag(parm, PROP_REQUIRED); + + /* remove object */ + func= RNA_def_function(srna, "remove_object", "rna_Group_objects_remove"); + RNA_def_function_ui_description(func, "Remove this object to a group"); + RNA_def_function_flag(func, FUNC_USE_CONTEXT); + /* return type */ + parm= RNA_def_boolean(func, "success", 0, "Success", "Newly created Group Target."); + RNA_def_function_return(func, parm); + /* object to remove */ + parm= RNA_def_pointer(func, "object", "Object", "", "Object to remove."); + RNA_def_property_flag(parm, PROP_REQUIRED); + prop= RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "gobject", NULL); RNA_def_property_struct_type(prop, "Object"); RNA_def_property_ui_text(prop, "Objects", "A collection of this groups objects."); - RNA_def_property_collection_funcs(prop, 0, 0, 0, "rna_Group_objects_get", 0, 0, 0, 0, 0); - - prop= RNA_def_property(srna, "layer", PROP_BOOLEAN, PROP_LAYER); - RNA_def_property_boolean_sdna(prop, NULL, "layer", 1); - RNA_def_property_array(prop, 20); - RNA_def_property_ui_text(prop, "Dupli Layers", "Layers visible when this groups is instanced as a dupli."); + RNA_def_property_collection_funcs(prop, 0, 0, 0, "rna_Group_objects_get", 0, 0, 0, "add_object", "remove_object"); } #endif |