Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/layer.c
| Show First 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | bool BKE_scene_layer_remove(Main *bmain, Scene *scene, SceneLayer *sl) | ||||
| } | } | ||||
| BLI_remlink(&scene->render_layers, sl); | BLI_remlink(&scene->render_layers, sl); | ||||
| BKE_scene_layer_free(sl); | BKE_scene_layer_free(sl); | ||||
| MEM_freeN(sl); | MEM_freeN(sl); | ||||
| /* TODO WORKSPACE: set active_layer to 0 */ | /* TODO WORKSPACE: set active_layer to 0 */ | ||||
| for (Scene *sce = bmain->scene.first; sce; sce = sce->id.next) { | for (Scene *sce = bmain->scene.first; sce; sce = sce->id.next) { | ||||
sergey: Shouldn't this be using ID remap thingie from @mont29? | |||||
Not Done Inline ActionsThis part is a copy+paste from BKE_scene_remove_render_layer. dfelinto: This part is a copy+paste from `BKE_scene_remove_render_layer`. | |||||
Done Inline ActionsEeeek! Hell no, this has nothing to do in ID remapping, this is not concerning IDs at all actually. But this has nothing to do here either imho, old code was a nice example of bad mixing it seems… This code should be a BKE_ utility defined in BKE_nodes, and called from here (e.g. BKE_nodetree_remove_layer_n(bNodeTree *ntree, const int layer_index) or something like that). mont29: Eeeek! Hell no, this has nothing to do in ID remapping, this is not concerning IDs at all… | |||||
| if (sce->nodetree) { | if (sce->nodetree) { | ||||
| BKE_nodetree_remove_layer_n(sce->nodetree, scene, act); | BKE_nodetree_remove_layer_n(sce->nodetree, scene, act); | ||||
| } | } | ||||
Done Inline ActionsCan define bNode *node directly in for loop mont29: Can define `bNode *node` directly in for loop | |||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| /** | /** | ||||
| * Free (or release) any data used by this SceneLayer (does not free the SceneLayer itself). | * Free (or release) any data used by this SceneLayer (does not free the SceneLayer itself). | ||||
| */ | */ | ||||
| Show All 16 Lines | void BKE_scene_layer_engine_set(SceneLayer *sl, const char *engine) | ||||
| BLI_strncpy_utf8(sl->engine, engine, sizeof(sl->engine)); | BLI_strncpy_utf8(sl->engine, engine, sizeof(sl->engine)); | ||||
| } | } | ||||
| /** | /** | ||||
| * Tag all the selected objects of a renderlayer | * Tag all the selected objects of a renderlayer | ||||
| */ | */ | ||||
| void BKE_scene_layer_selected_objects_tag(SceneLayer *sl, const int tag) | void BKE_scene_layer_selected_objects_tag(SceneLayer *sl, const int tag) | ||||
| { | { | ||||
| for (ObjectBase *ob_base = sl->object_bases.first; ob_base; ob_base = ob_base->next) { | for (ObjectBase *base = sl->object_bases.first; base; base = base->next) { | ||||
| if ((ob_base->flag & BASE_SELECTED) != 0) { | if ((base->flag & BASE_SELECTED) != 0) { | ||||
| ob_base->object->flag |= tag; | base->object->flag |= tag; | ||||
| } | } | ||||
| else { | else { | ||||
| ob_base->object->flag &= ~tag; | base->object->flag &= ~tag; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* ObjectBase */ | /* ObjectBase */ | ||||
| ObjectBase *BKE_scene_layer_base_find(SceneLayer *sl, Object *ob) | ObjectBase *BKE_scene_layer_base_find(SceneLayer *sl, Object *ob) | ||||
| { | { | ||||
| return BLI_findptr(&sl->object_bases, ob, offsetof(ObjectBase, object)); | return BLI_findptr(&sl->object_bases, ob, offsetof(ObjectBase, object)); | ||||
| } | } | ||||
| void BKE_scene_layer_base_deselect_all(SceneLayer *sl) | |||||
| { | |||||
| ObjectBase *base; | |||||
| for (base = sl->object_bases.first; base; base = base->next) { | |||||
| base->flag &= ~BASE_SELECTED; | |||||
| } | |||||
| } | |||||
| void BKE_scene_layer_base_select(struct SceneLayer *sl, ObjectBase *selbase) | |||||
| { | |||||
| selbase->flag |= BASE_SELECTED; | |||||
| sl->basact = selbase; | |||||
| } | |||||
| static void scene_layer_object_base_unref(SceneLayer* sl, ObjectBase *base) | static void scene_layer_object_base_unref(SceneLayer* sl, ObjectBase *base) | ||||
| { | { | ||||
| base->refcount--; | base->refcount--; | ||||
| /* It only exists in the RenderLayer */ | /* It only exists in the RenderLayer */ | ||||
| if (base->refcount == 0) { | if (base->refcount == 0) { | ||||
| if (sl->basact == base) { | if (sl->basact == base) { | ||||
| sl->basact = NULL; | sl->basact = NULL; | ||||
| } | } | ||||
| BLI_remlink(&sl->object_bases, base); | BLI_remlink(&sl->object_bases, base); | ||||
| MEM_freeN(base); | MEM_freeN(base); | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Return the base if existent, or create it if necessary | * Return the base if existent, or create it if necessary | ||||
| * Always bump the refcount | * Always bump the refcount | ||||
| */ | */ | ||||
| static ObjectBase *object_base_add(SceneLayer *sl, Object *ob) | static ObjectBase *object_base_add(SceneLayer *sl, Object *ob) | ||||
| { | { | ||||
| ObjectBase *ob_base; | ObjectBase *base; | ||||
| ob_base = BKE_scene_layer_base_find(sl, ob); | base = BKE_scene_layer_base_find(sl, ob); | ||||
| if (ob_base == NULL) { | if (base == NULL) { | ||||
| ob_base = MEM_callocN(sizeof(ObjectBase), "Object Base"); | base = MEM_callocN(sizeof(ObjectBase), "Object Base"); | ||||
| /* do not bump user count, leave it for SceneCollections */ | /* do not bump user count, leave it for SceneCollections */ | ||||
| ob_base->object = ob; | base->object = ob; | ||||
| BLI_addtail(&sl->object_bases, ob_base); | BLI_addtail(&sl->object_bases, base); | ||||
| } | } | ||||
| ob_base->refcount++; | base->refcount++; | ||||
| return ob_base; | return base; | ||||
| } | } | ||||
| /* LayerCollection */ | /* LayerCollection */ | ||||
| /** | /** | ||||
| * When freeing the entire SceneLayer at once we don't bother with unref | * When freeing the entire SceneLayer at once we don't bother with unref | ||||
| * otherwise SceneLayer is passed to keep the syncing of the LayerCollection tree | * otherwise SceneLayer is passed to keep the syncing of the LayerCollection tree | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | void BKE_collection_unlink(SceneLayer *sl, LayerCollection *lc) | ||||
| BLI_remlink(&sl->layer_collections, lc); | BLI_remlink(&sl->layer_collections, lc); | ||||
| MEM_freeN(lc); | MEM_freeN(lc); | ||||
| sl->active_collection = 0; | sl->active_collection = 0; | ||||
| } | } | ||||
| static void layer_collection_object_add(SceneLayer *sl, LayerCollection *lc, Object *ob) | static void layer_collection_object_add(SceneLayer *sl, LayerCollection *lc, Object *ob) | ||||
| { | { | ||||
| ObjectBase *ob_base = object_base_add(sl, ob); | ObjectBase *base = object_base_add(sl, ob); | ||||
| /* only add an object once - prevent SceneCollection->objects and | /* only add an object once - prevent SceneCollection->objects and | ||||
| * SceneCollection->filter_objects to add the same object */ | * SceneCollection->filter_objects to add the same object */ | ||||
| if (BLI_findptr(&lc->object_bases, ob_base, offsetof(LinkData, data))) { | if (BLI_findptr(&lc->object_bases, base, offsetof(LinkData, data))) { | ||||
| return; | return; | ||||
| } | } | ||||
| BLI_addtail(&lc->object_bases, BLI_genericNodeN(ob_base)); | BLI_addtail(&lc->object_bases, BLI_genericNodeN(base)); | ||||
| } | } | ||||
| static void layer_collection_object_remove(SceneLayer *sl, LayerCollection *lc, Object *ob) | static void layer_collection_object_remove(SceneLayer *sl, LayerCollection *lc, Object *ob) | ||||
| { | { | ||||
| ObjectBase *ob_base; | ObjectBase *base; | ||||
| ob_base = BKE_scene_layer_base_find(sl, ob); | base = BKE_scene_layer_base_find(sl, ob); | ||||
| LinkData *link = BLI_findptr(&lc->object_bases, ob_base, offsetof(LinkData, data)); | LinkData *link = BLI_findptr(&lc->object_bases, base, offsetof(LinkData, data)); | ||||
| BLI_remlink(&lc->object_bases, link); | BLI_remlink(&lc->object_bases, link); | ||||
| MEM_freeN(link); | MEM_freeN(link); | ||||
| scene_layer_object_base_unref(sl, ob_base); | scene_layer_object_base_unref(sl, base); | ||||
| } | } | ||||
| static void layer_collection_objects_populate(SceneLayer *sl, LayerCollection *lc, ListBase *objects) | static void layer_collection_objects_populate(SceneLayer *sl, LayerCollection *lc, ListBase *objects) | ||||
| { | { | ||||
| for (LinkData *link = objects->first; link; link = link->next) { | for (LinkData *link = objects->first; link; link = link->next) { | ||||
| layer_collection_object_add(sl, lc, link->data); | layer_collection_object_add(sl, lc, link->data); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | void BKE_collection_override_datablock_add(LayerCollection *UNUSED(lc), const char *UNUSED(data_path), ID *UNUSED(id)) | ||||
| TODO_LAYER_OVERRIDE; | TODO_LAYER_OVERRIDE; | ||||
| } | } | ||||
| /* Iterators */ | /* Iterators */ | ||||
| void BKE_selected_objects_Iterator_begin(Iterator *iter, void *data_in) | void BKE_selected_objects_Iterator_begin(Iterator *iter, void *data_in) | ||||
| { | { | ||||
| SceneLayer *sl = data_in; | SceneLayer *sl = data_in; | ||||
| ObjectBase *ob_base = sl->object_bases.first; | ObjectBase *base = sl->object_bases.first; | ||||
| /* when there are no objects */ | |||||
| if (base == NULL) { | |||||
| iter->valid = false; | |||||
| return; | |||||
| } | |||||
| iter->valid = true; | iter->valid = true; | ||||
| iter->data = base; | |||||
| if ((ob_base->flag & BASE_SELECTED) == 0) { | if ((base->flag & BASE_SELECTED) == 0) { | ||||
| BKE_selected_objects_Iterator_next(iter); | BKE_selected_objects_Iterator_next(iter); | ||||
| } | } | ||||
| else { | else { | ||||
| iter->current = ob_base->object; | iter->current = base->object; | ||||
| iter->data = ob_base; | |||||
| } | } | ||||
| } | } | ||||
| void BKE_selected_objects_Iterator_next(Iterator *iter) | void BKE_selected_objects_Iterator_next(Iterator *iter) | ||||
| { | { | ||||
| ObjectBase *ob_base = ((ObjectBase *)iter->data)->next; | ObjectBase *base = ((ObjectBase *)iter->data)->next; | ||||
| while (ob_base) { | while (base) { | ||||
| if ((ob_base->flag & BASE_SELECTED) != 0) { | if ((base->flag & BASE_SELECTED) != 0) { | ||||
| iter->current = ob_base->object; | iter->current = base->object; | ||||
| iter->data = ob_base; | iter->data = base; | ||||
| return; | return; | ||||
| } | } | ||||
| ob_base = ob_base->next; | base = base->next; | ||||
| }; | }; | ||||
| iter->current = NULL; | iter->current = NULL; | ||||
| iter->valid = false; | iter->valid = false; | ||||
| } | } | ||||
| void BKE_selected_objects_Iterator_end(Iterator *UNUSED(iter)) | void BKE_selected_objects_Iterator_end(Iterator *UNUSED(iter)) | ||||
| { | { | ||||
| /* do nothing */ | /* do nothing */ | ||||
| } | } | ||||
Shouldn't this be using ID remap thingie from @Bastien Montagne (mont29)?