diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2017-11-08 17:16:49 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2017-11-08 23:39:01 +0300 |
commit | 206c94fea98d44ed9667607638c455c7c0e63822 (patch) | |
tree | ddc1f6f30c18d10674daaeeaee6b465550447709 /source/blender/makesrna/intern/rna_scene.c | |
parent | 670e6cab4319b94c96c6a61cb76199f1054b935a (diff) |
Farewell Scene->base
While getting rid of Scene->base we got the following fixes:
* Fix "Convert To" operator
* Fix "NLA allowing to selected objects that are not selectable
* Fix scene.objects (readonly, no option to link/unlink)
Note: Collada needs to use the context SceneLayer for adding objects
however I added a placeholder, so Collada maintainers can fix this
properly.
Diffstat (limited to 'source/blender/makesrna/intern/rna_scene.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_scene.c | 169 |
1 files changed, 26 insertions, 143 deletions
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index a5645f362b9..26f1ac845d4 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -618,87 +618,39 @@ static void rna_SpaceImageEditor_uv_sculpt_update(Main *bmain, Scene *scene, Poi ED_space_image_uv_sculpt_update(bmain->wm.first, scene); } -static int rna_Scene_object_bases_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr) + +/* Read-only Iterator of all the scene objects. */ + +static void rna_Scene_objects_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) { Scene *scene = (Scene *)ptr->data; - BaseLegacy *base; - - for (base = scene->base.first; base; base = base->next) { - if (STREQLEN(base->object->id.name + 2, key, sizeof(base->object->id.name) - 2)) { - *r_ptr = rna_pointer_inherit_refine(ptr, &RNA_ObjectBaseLegacy, base); - return true; - } - } + iter->internal.custom = MEM_callocN(sizeof(BLI_Iterator), __func__); - return false; + ((BLI_Iterator *)iter->internal.custom)->valid = true; + BKE_scene_objects_iterator_begin(iter->internal.custom, (void *)scene); + iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid; } -static PointerRNA rna_Scene_objects_get(CollectionPropertyIterator *iter) +static void rna_Scene_objects_next(CollectionPropertyIterator *iter) { - ListBaseIterator *internal = &iter->internal.listbase; - - /* we are actually iterating a Base list, so override get */ - return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ((BaseLegacy *)internal->link)->object); + BKE_scene_objects_iterator_next(iter->internal.custom); + iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid; } -static BaseLegacy *rna_Scene_object_link(Scene *scene, bContext *C, ReportList *reports, Object *ob) +static void rna_Scene_objects_end(CollectionPropertyIterator *iter) { - Scene *scene_act = CTX_data_scene(C); - BaseLegacy *base; - - if (BKE_scene_base_find(scene, ob)) { - BKE_reportf(reports, RPT_ERROR, "Object '%s' is already in scene '%s'", ob->id.name + 2, scene->id.name + 2); - return NULL; - } - - base = BKE_scene_base_add(scene, ob); - id_us_plus(&ob->id); - - /* this is similar to what object_add_type and BKE_object_add do */ - base->lay = scene->lay; - - /* when linking to an inactive scene don't touch the layer */ - if (scene == scene_act) - ob->lay = base->lay; - - /* TODO(sergey): Only update relations for the current scene. */ - DEG_relations_tag_update(CTX_data_main(C)); - DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); - - /* slows down importers too much, run scene.update() */ - /* DEG_srelations_tag_update(G.main); */ - - WM_main_add_notifier(NC_SCENE | ND_OB_ACTIVE, scene); - - return base; + BKE_scene_objects_iterator_end(iter->internal.custom); + MEM_freeN(iter->internal.custom); } -static void rna_Scene_object_unlink(Scene *scene, ReportList *reports, Object *ob) +static PointerRNA rna_Scene_objects_get(CollectionPropertyIterator *iter) { - BaseLegacy *base = BKE_scene_base_find(scene, ob); - if (!base) { - BKE_reportf(reports, RPT_ERROR, "Object '%s' is not in this scene '%s'", ob->id.name + 2, scene->id.name + 2); - return; - } - if (base == scene->basact && ob->mode != OB_MODE_OBJECT) { - BKE_reportf(reports, RPT_ERROR, "Object '%s' must be in object mode to unlink", ob->id.name + 2); - return; - } - if (scene->basact == base) { - scene->basact = NULL; - } - - BKE_scene_base_unlink(scene, base); - MEM_freeN(base); - - id_us_min(&ob->id); - - /* needed otherwise the depgraph will contain freed objects which can crash, see [#20958] */ - DEG_relations_tag_update(G.main); - - WM_main_add_notifier(NC_SCENE | ND_OB_ACTIVE, scene); + Object *ob = ((BLI_Iterator *)iter->internal.custom)->current; + return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ob); } +/* End of read-only Iterator of all the scene objects. */ + static void rna_Scene_skgen_etch_template_set(PointerRNA *ptr, PointerRNA value) { ToolSettings *ts = (ToolSettings *)ptr->data; @@ -708,21 +660,6 @@ static void rna_Scene_skgen_etch_template_set(PointerRNA *ptr, PointerRNA value) ts->skgen_template = NULL; } -static PointerRNA rna_Scene_active_object_get(PointerRNA *ptr) -{ - Scene *scene = (Scene *)ptr->data; - return rna_pointer_inherit_refine(ptr, &RNA_Object, scene->basact ? scene->basact->object : NULL); -} - -static void rna_Scene_active_object_set(PointerRNA *ptr, PointerRNA value) -{ - Scene *scene = (Scene *)ptr->data; - if (value.data) - scene->basact = BKE_scene_base_find(scene, (Object *)value.data); - else - scene->basact = NULL; -} - static void rna_Scene_set_set(PointerRNA *ptr, PointerRNA value) { Scene *scene = (Scene *)ptr->data; @@ -6658,60 +6595,11 @@ static void rna_def_scene_render_data(BlenderRNA *brna) static void rna_def_scene_objects(BlenderRNA *brna, PropertyRNA *cprop) { StructRNA *srna; - PropertyRNA *prop; - FunctionRNA *func; - PropertyRNA *parm; - RNA_def_property_srna(cprop, "SceneObjects"); srna = RNA_def_struct(brna, "SceneObjects", NULL); RNA_def_struct_sdna(srna, "Scene"); - RNA_def_struct_ui_text(srna, "Scene Objects", "Collection of scene objects"); - - func = RNA_def_function(srna, "link", "rna_Scene_object_link"); - RNA_def_function_ui_description(func, "Link object to scene, run scene.update() after"); - RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS); - parm = RNA_def_pointer(func, "object", "Object", "", "Object to add to scene"); - RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED); - parm = RNA_def_pointer(func, "base", "ObjectBaseLegacy", "", "The newly created base"); - RNA_def_function_return(func, parm); - - func = RNA_def_function(srna, "unlink", "rna_Scene_object_unlink"); - RNA_def_function_ui_description(func, "Unlink object from scene"); - RNA_def_function_flag(func, FUNC_USE_REPORTS); - parm = RNA_def_pointer(func, "object", "Object", "", "Object to remove from scene"); - RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED); - - prop = RNA_def_property(srna, "active", 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, NULL); - RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_UNLINK); - RNA_def_property_ui_text(prop, "Active Object", "Active object for this scene"); - /* 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); -} - -/* scene.bases.* */ -static void rna_def_scene_bases(BlenderRNA *brna, PropertyRNA *cprop) -{ - StructRNA *srna; - PropertyRNA *prop; - -/* FunctionRNA *func; */ -/* PropertyRNA *parm; */ - - RNA_def_property_srna(cprop, "SceneBases"); - srna = RNA_def_struct(brna, "SceneBases", NULL); - RNA_def_struct_sdna(srna, "Scene"); - RNA_def_struct_ui_text(srna, "Scene Bases", "Collection of scene bases"); - - prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE); - RNA_def_property_struct_type(prop, "ObjectBaseLegacy"); - RNA_def_property_pointer_sdna(prop, NULL, "basact"); - RNA_def_property_flag(prop, PROP_EDITABLE); - RNA_def_property_ui_text(prop, "Active Base", "Active object base in the scene"); - RNA_def_property_update(prop, NC_SCENE | ND_OB_ACTIVE, NULL); + RNA_def_struct_ui_text(srna, "Scene Objects", "All the of scene objects"); } /* scene.timeline_markers */ @@ -6946,21 +6834,16 @@ void RNA_def_scene(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Cursor Location", "3D cursor location"); RNA_def_property_ui_range(prop, -10000.0, 10000.0, 10, 4); RNA_def_property_update(prop, NC_WINDOW, NULL); - - /* Bases/Objects */ - prop = RNA_def_property(srna, "object_bases", PROP_COLLECTION, PROP_NONE); - RNA_def_property_collection_sdna(prop, NULL, "base", NULL); - RNA_def_property_struct_type(prop, "ObjectBaseLegacy"); - RNA_def_property_ui_text(prop, "Bases", ""); - RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, NULL, NULL, NULL, - "rna_Scene_object_bases_lookup_string", NULL); - rna_def_scene_bases(brna, prop); 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, NULL, NULL, NULL, "rna_Scene_objects_get", NULL, NULL, NULL, NULL); + RNA_def_property_collection_funcs(prop, + "rna_Scene_objects_begin", + "rna_Scene_objects_next", + "rna_Scene_objects_end", + "rna_Scene_objects_get", + NULL, NULL, NULL, NULL); rna_def_scene_objects(brna, prop); /* Layers */ |