Merge branch 'master' into blender2.8
[blender.git] / source / blender / blenkernel / intern / library_query.c
index 3292f0d6640a4af7cdefecc444245d732e3227e2..902cabad85746b4d5810a7b4d0b7854688dd2e58 100644 (file)
 
 #include "MEM_guardedalloc.h"
 
-#include "DNA_actuator_types.h"
 #include "DNA_anim_types.h"
 #include "DNA_armature_types.h"
 #include "DNA_brush_types.h"
 #include "DNA_camera_types.h"
+#include "DNA_collection_types.h"
 #include "DNA_constraint_types.h"
-#include "DNA_controller_types.h"
-#include "DNA_group_types.h"
 #include "DNA_gpencil_types.h"
 #include "DNA_key_types.h"
 #include "DNA_lamp_types.h"
 #include "DNA_mask_types.h"
 #include "DNA_node_types.h"
 #include "DNA_object_force_types.h"
+#include "DNA_lightprobe_types.h"
 #include "DNA_rigidbody_types.h"
 #include "DNA_scene_types.h"
-#include "DNA_sensor_types.h"
 #include "DNA_sequence_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_speaker_types.h"
 #include "DNA_sound_types.h"
 #include "DNA_text_types.h"
 #include "DNA_vfont_types.h"
+#include "DNA_windowmanager_types.h"
+#include "DNA_workspace_types.h"
 #include "DNA_world_types.h"
 
 #include "BLI_utildefines.h"
 #include "BLI_linklist_stack.h"
 
 #include "BKE_animsys.h"
+#include "BKE_collection.h"
 #include "BKE_constraint.h"
 #include "BKE_fcurve.h"
+#include "BKE_gpencil_modifier.h"
 #include "BKE_idprop.h"
 #include "BKE_library.h"
 #include "BKE_library_query.h"
@@ -79,9 +81,9 @@
 #include "BKE_node.h"
 #include "BKE_particle.h"
 #include "BKE_rigidbody.h"
-#include "BKE_sca.h"
 #include "BKE_sequencer.h"
 #include "BKE_tracking.h"
+#include "BKE_workspace.h"
 
 
 #define FOREACH_FINALIZE _finalize
@@ -194,27 +196,8 @@ static void library_foreach_modifiersForeachIDLink(
        FOREACH_FINALIZE_VOID;
 }
 
-static void library_foreach_constraintObjectLooper(bConstraint *UNUSED(con), ID **id_pointer,
-                                                   bool is_reference, void *user_data)
-{
-       LibraryForeachIDData *data = (LibraryForeachIDData *) user_data;
-       const int cb_flag = is_reference ? IDWALK_CB_USER : IDWALK_CB_NOP;
-       FOREACH_CALLBACK_INVOKE_ID_PP(data, id_pointer, cb_flag);
-
-       FOREACH_FINALIZE_VOID;
-}
-
-static void library_foreach_particlesystemsObjectLooper(
-        ParticleSystem *UNUSED(psys), ID **id_pointer, void *user_data, int cb_flag)
-{
-       LibraryForeachIDData *data = (LibraryForeachIDData *) user_data;
-       FOREACH_CALLBACK_INVOKE_ID_PP(data, id_pointer, cb_flag);
-
-       FOREACH_FINALIZE_VOID;
-}
-
-static void library_foreach_sensorsObjectLooper(
-        bSensor *UNUSED(sensor), ID **id_pointer, void *user_data, int cb_flag)
+static void library_foreach_gpencil_modifiersForeachIDLink(
+        void *user_data, Object *UNUSED(object), ID **id_pointer, int cb_flag)
 {
        LibraryForeachIDData *data = (LibraryForeachIDData *) user_data;
        FOREACH_CALLBACK_INVOKE_ID_PP(data, id_pointer, cb_flag);
@@ -222,17 +205,18 @@ static void library_foreach_sensorsObjectLooper(
        FOREACH_FINALIZE_VOID;
 }
 
-static void library_foreach_controllersObjectLooper(
-        bController *UNUSED(controller), ID **id_pointer, void *user_data, int cb_flag)
+static void library_foreach_constraintObjectLooper(bConstraint *UNUSED(con), ID **id_pointer,
+                                                   bool is_reference, void *user_data)
 {
        LibraryForeachIDData *data = (LibraryForeachIDData *) user_data;
+       const int cb_flag = is_reference ? IDWALK_CB_USER : IDWALK_CB_NOP;
        FOREACH_CALLBACK_INVOKE_ID_PP(data, id_pointer, cb_flag);
 
        FOREACH_FINALIZE_VOID;
 }
 
-static void library_foreach_actuatorsObjectLooper(
-        bActuator *UNUSED(actuator), ID **id_pointer, void *user_data, int cb_flag)
+static void library_foreach_particlesystemsObjectLooper(
+        ParticleSystem *UNUSED(psys), ID **id_pointer, void *user_data, int cb_flag)
 {
        LibraryForeachIDData *data = (LibraryForeachIDData *) user_data;
        FOREACH_CALLBACK_INVOKE_ID_PP(data, id_pointer, cb_flag);
@@ -296,6 +280,9 @@ static void library_foreach_mtex(LibraryForeachIDData *data, MTex *mtex)
 static void library_foreach_paint(LibraryForeachIDData *data, Paint *paint)
 {
        FOREACH_CALLBACK_INVOKE(data, paint->brush, IDWALK_CB_USER);
+       for (int i = 0; i < paint->tool_slots_len; i++) {
+               FOREACH_CALLBACK_INVOKE(data, paint->tool_slots[i].brush, IDWALK_CB_USER);
+       }
        FOREACH_CALLBACK_INVOKE(data, paint->palette, IDWALK_CB_USER);
 
        FOREACH_FINALIZE_VOID;
@@ -312,6 +299,16 @@ static void library_foreach_bone(LibraryForeachIDData *data, Bone *bone)
        FOREACH_FINALIZE_VOID;
 }
 
+static void library_foreach_layer_collection(LibraryForeachIDData *data, ListBase *lb)
+{
+       for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
+               FOREACH_CALLBACK_INVOKE(data, lc->collection, IDWALK_CB_NOP);
+               library_foreach_layer_collection(data, &lc->layer_collections);
+       }
+
+       FOREACH_FINALIZE_VOID;
+}
+
 static void library_foreach_ID_as_subdata_link(
         ID **id_pp, LibraryIDLinkCallback callback, void *user_data, int flag, LibraryForeachIDData *data)
 {
@@ -384,6 +381,11 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
                        continue;
                }
 
+               if (id->override_static != NULL) {
+                       CALLBACK_INVOKE_ID(id->override_static->reference, IDWALK_CB_USER | IDWALK_CB_STATIC_OVERRIDE_REFERENCE);
+                       CALLBACK_INVOKE_ID(id->override_static->storage, IDWALK_CB_USER | IDWALK_CB_STATIC_OVERRIDE_REFERENCE);
+               }
+
                library_foreach_idproperty_ID_link(&data, id->properties, IDWALK_CB_USER);
 
                AnimData *adt = BKE_animdata_from_id(id);
@@ -402,8 +404,6 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
                        {
                                Scene *scene = (Scene *) id;
                                ToolSettings *toolsett = scene->toolsettings;
-                               SceneRenderLayer *srl;
-                               Base *base;
 
                                CALLBACK_INVOKE(scene->camera, IDWALK_CB_NOP);
                                CALLBACK_INVOKE(scene->world, IDWALK_CB_USER);
@@ -413,35 +413,6 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
                                        /* nodetree **are owned by IDs**, treat them as mere sub-data and not real ID! */
                                        library_foreach_ID_as_subdata_link((ID **)&scene->nodetree, callback, user_data, flag, &data);
                                }
-                               /* DO NOT handle scene->basact here, it's doubling with the loop over whole scene->base later,
-                                * since basact is just a pointer to one of those items. */
-                               CALLBACK_INVOKE(scene->obedit, IDWALK_CB_NOP);
-
-                               for (srl = scene->r.layers.first; srl; srl = srl->next) {
-                                       FreestyleModuleConfig *fmc;
-                                       FreestyleLineSet *fls;
-
-                                       if (srl->mat_override) {
-                                               CALLBACK_INVOKE(srl->mat_override, IDWALK_CB_USER);
-                                       }
-                                       if (srl->light_override) {
-                                               CALLBACK_INVOKE(srl->light_override, IDWALK_CB_USER);
-                                       }
-                                       for (fmc = srl->freestyleConfig.modules.first; fmc; fmc = fmc->next) {
-                                               if (fmc->script) {
-                                                       CALLBACK_INVOKE(fmc->script, IDWALK_CB_NOP);
-                                               }
-                                       }
-                                       for (fls = srl->freestyleConfig.linesets.first; fls; fls = fls->next) {
-                                               if (fls->group) {
-                                                       CALLBACK_INVOKE(fls->group, IDWALK_CB_USER);
-                                               }
-                                               if (fls->linestyle) {
-                                                       CALLBACK_INVOKE(fls->linestyle, IDWALK_CB_USER);
-                                               }
-                                       }
-                               }
-
                                if (scene->ed) {
                                        Sequence *seq;
                                        SEQP_BEGIN(scene->ed, seq)
@@ -459,10 +430,37 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
                                        SEQ_END
                                }
 
-                               CALLBACK_INVOKE(scene->gpd, IDWALK_CB_USER);
 
-                               for (base = scene->base.first; base; base = base->next) {
-                                       CALLBACK_INVOKE(base->object, IDWALK_CB_USER);
+                               for (CollectionObject *cob = scene->master_collection->gobject.first; cob; cob = cob->next) {
+                                       CALLBACK_INVOKE(cob->ob, IDWALK_CB_USER);
+                               }
+                               for (CollectionChild *child = scene->master_collection->children.first; child; child = child->next) {
+                                       CALLBACK_INVOKE(child->collection, IDWALK_CB_USER);
+                               }
+
+                               ViewLayer *view_layer;
+                               for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+                                       for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+                                               CALLBACK_INVOKE(base->object, IDWALK_CB_NOP);
+                                       }
+
+                                       library_foreach_layer_collection(&data, &view_layer->layer_collections);
+
+                                       for (FreestyleModuleConfig  *fmc = view_layer->freestyle_config.modules.first; fmc; fmc = fmc->next) {
+                                               if (fmc->script) {
+                                                       CALLBACK_INVOKE(fmc->script, IDWALK_CB_NOP);
+                                               }
+                                       }
+
+                                       for (FreestyleLineSet *fls = view_layer->freestyle_config.linesets.first; fls; fls = fls->next) {
+                                               if (fls->group) {
+                                                       CALLBACK_INVOKE(fls->group, IDWALK_CB_USER);
+                                               }
+
+                                               if (fls->linestyle) {
+                                                       CALLBACK_INVOKE(fls->linestyle, IDWALK_CB_USER);
+                                               }
+                                       }
                                }
 
                                for (TimeMarker *marker = scene->markers.first; marker; marker = marker->next) {
@@ -470,8 +468,6 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
                                }
 
                                if (toolsett) {
-                                       CALLBACK_INVOKE(toolsett->skgen_template, IDWALK_CB_NOP);
-
                                        CALLBACK_INVOKE(toolsett->particle.scene, IDWALK_CB_NOP);
                                        CALLBACK_INVOKE(toolsett->particle.object, IDWALK_CB_NOP);
                                        CALLBACK_INVOKE(toolsett->particle.shape_object, IDWALK_CB_NOP);
@@ -494,14 +490,15 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
                                        if (toolsett->uvsculpt) {
                                                library_foreach_paint(&data, &toolsett->uvsculpt->paint);
                                        }
+                                       if (toolsett->gp_paint) {
+                                               library_foreach_paint(&data, &toolsett->gp_paint->paint);
+                                       }
                                }
 
                                if (scene->rigidbody_world) {
                                        BKE_rigidbody_world_id_loop(scene->rigidbody_world, library_foreach_rigidbodyworldSceneLooper, &data);
                                }
 
-                               CALLBACK_INVOKE(scene->gm.dome.warptext, IDWALK_CB_NOP);
-
                                break;
                        }
 
@@ -586,6 +583,7 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
                                }
 
                                modifiers_foreachIDLink(object, library_foreach_modifiersForeachIDLink, &data);
+                               BKE_gpencil_modifiers_foreachIDLink(object, library_foreach_gpencil_modifiersForeachIDLink, &data);
                                BKE_constraints_id_loop(&object->constraints, library_foreach_constraintObjectLooper, &data);
 
                                for (psys = object->particlesystem.first; psys; psys = psys->next) {
@@ -599,10 +597,6 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
                                                CALLBACK_INVOKE(object->soft->effector_weights->group, IDWALK_CB_NOP);
                                        }
                                }
-
-                               BKE_sca_sensors_id_loop(&object->sensors, library_foreach_sensorsObjectLooper, &data);
-                               BKE_sca_controllers_id_loop(&object->controllers, library_foreach_controllersObjectLooper, &data);
-                               BKE_sca_actuators_id_loop(&object->actuators, library_foreach_actuatorsObjectLooper, &data);
                                break;
                        }
 
@@ -624,31 +618,6 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
                                for (i = 0; i < mesh->totcol; i++) {
                                        CALLBACK_INVOKE(mesh->mat[i], IDWALK_CB_USER);
                                }
-
-                               /* XXX Really not happy with this - probably texface should rather use some kind of
-                                * 'texture slots' and just set indices in each poly/face item - would also save some memory.
-                                * Maybe a nice TODO for blender2.8? */
-                               if (mesh->mtface || mesh->mtpoly) {
-                                       for (i = 0; i < mesh->pdata.totlayer; i++) {
-                                               if (mesh->pdata.layers[i].type == CD_MTEXPOLY) {
-                                                       MTexPoly *txface = (MTexPoly *)mesh->pdata.layers[i].data;
-
-                                                       for (int j = 0; j < mesh->totpoly; j++, txface++) {
-                                                               CALLBACK_INVOKE(txface->tpage, IDWALK_CB_USER_ONE);
-                                                       }
-                                               }
-                                       }
-
-                                       for (i = 0; i < mesh->fdata.totlayer; i++) {
-                                               if (mesh->fdata.layers[i].type == CD_MTFACE) {
-                                                       MTFace *tface = (MTFace *)mesh->fdata.layers[i].data;
-
-                                                       for (int j = 0; j < mesh->totface; j++, tface++) {
-                                                               CALLBACK_INVOKE(tface->tpage, IDWALK_CB_USER_ONE);
-                                                       }
-                                               }
-                                       }
-                               }
                                break;
                        }
 
@@ -681,19 +650,17 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
                        case ID_MA:
                        {
                                Material *material = (Material *) id;
-                               for (i = 0; i < MAX_MTEX; i++) {
-                                       if (material->mtex[i]) {
-                                               library_foreach_mtex(&data, material->mtex[i]);
-                                       }
-                               }
                                if (material->nodetree) {
                                        /* nodetree **are owned by IDs**, treat them as mere sub-data and not real ID! */
                                        library_foreach_ID_as_subdata_link((ID **)&material->nodetree, callback, user_data, flag, &data);
                                }
-                               CALLBACK_INVOKE(material->group, IDWALK_CB_USER);
                                if (material->texpaintslot != NULL) {
                                        CALLBACK_INVOKE(material->texpaintslot->ima, IDWALK_CB_NOP);
                                }
+                               if (material->gp_style != NULL) {
+                                       CALLBACK_INVOKE(material->gp_style->sima, IDWALK_CB_USER);
+                                       CALLBACK_INVOKE(material->gp_style->ima, IDWALK_CB_USER);
+                               }
                                break;
                        }
 
@@ -705,16 +672,6 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
                                        library_foreach_ID_as_subdata_link((ID **)&texture->nodetree, callback, user_data, flag, &data);
                                }
                                CALLBACK_INVOKE(texture->ima, IDWALK_CB_USER);
-                               if (texture->env) {
-                                       CALLBACK_INVOKE(texture->env->object, IDWALK_CB_NOP);
-                                       CALLBACK_INVOKE(texture->env->ima, IDWALK_CB_USER);
-                               }
-                               if (texture->pd)
-                                       CALLBACK_INVOKE(texture->pd->object, IDWALK_CB_NOP);
-                               if (texture->vd)
-                                       CALLBACK_INVOKE(texture->vd->object, IDWALK_CB_NOP);
-                               if (texture->ot)
-                                       CALLBACK_INVOKE(texture->ot->object, IDWALK_CB_NOP);
                                break;
                        }
 
@@ -728,11 +685,6 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
                        case ID_LA:
                        {
                                Lamp *lamp = (Lamp *) id;
-                               for (i = 0; i < MAX_MTEX; i++) {
-                                       if (lamp->mtex[i]) {
-                                               library_foreach_mtex(&data, lamp->mtex[i]);
-                                       }
-                               }
                                if (lamp->nodetree) {
                                        /* nodetree **are owned by IDs**, treat them as mere sub-data and not real ID! */
                                        library_foreach_ID_as_subdata_link((ID **)&lamp->nodetree, callback, user_data, flag, &data);
@@ -744,6 +696,15 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
                        {
                                Camera *camera = (Camera *) id;
                                CALLBACK_INVOKE(camera->dof_ob, IDWALK_CB_NOP);
+                               for (CameraBGImage *bgpic = camera->bg_images.first; bgpic; bgpic = bgpic->next) {
+                                       if (bgpic->source == CAM_BGIMG_SOURCE_IMAGE) {
+                                               CALLBACK_INVOKE(bgpic->ima, IDWALK_CB_USER);
+                                       }
+                                       else if (bgpic->source == CAM_BGIMG_SOURCE_MOVIE) {
+                                               CALLBACK_INVOKE(bgpic->clip, IDWALK_CB_USER);
+                                       }
+                               }
+
                                break;
                        }
 
@@ -754,21 +715,9 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
                                break;
                        }
 
-                       case ID_SCR:
-                       {
-                               bScreen *screen = (bScreen *) id;
-                               CALLBACK_INVOKE(screen->scene, IDWALK_CB_USER_ONE);
-                               break;
-                       }
-
                        case ID_WO:
                        {
                                World *world = (World *) id;
-                               for (i = 0; i < MAX_MTEX; i++) {
-                                       if (world->mtex[i]) {
-                                               library_foreach_mtex(&data, world->mtex[i]);
-                                       }
-                               }
                                if (world->nodetree) {
                                        /* nodetree **are owned by IDs**, treat them as mere sub-data and not real ID! */
                                        library_foreach_ID_as_subdata_link((ID **)&world->nodetree, callback, user_data, flag, &data);
@@ -783,12 +732,22 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
                                break;
                        }
 
+                       case ID_LP:
+                       {
+                               LightProbe *probe = (LightProbe *) id;
+                               CALLBACK_INVOKE(probe->image, IDWALK_CB_USER);
+                               CALLBACK_INVOKE(probe->visibility_grp, IDWALK_CB_NOP);
+                               break;
+                       }
+
                        case ID_GR:
                        {
-                               Group *group = (Group *) id;
-                               GroupObject *gob;
-                               for (gob = group->gobject.first; gob; gob = gob->next) {
-                                       CALLBACK_INVOKE(gob->ob, IDWALK_CB_USER_ONE);
+                               Collection *collection = (Collection *) id;
+                               for (CollectionObject *cob = collection->gobject.first; cob; cob = cob->next) {
+                                       CALLBACK_INVOKE(cob->ob, IDWALK_CB_USER);
+                               }
+                               for (CollectionChild *child = collection->children.first; child; child = child->next) {
+                                       CALLBACK_INVOKE(child->collection, IDWALK_CB_USER);
                                }
                                break;
                        }
@@ -828,6 +787,9 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
                                CALLBACK_INVOKE(brush->toggle_brush, IDWALK_CB_NOP);
                                CALLBACK_INVOKE(brush->clone.image, IDWALK_CB_NOP);
                                CALLBACK_INVOKE(brush->paint_curve, IDWALK_CB_USER);
+                               if (brush->gpencil_settings) {
+                                       CALLBACK_INVOKE(brush->gpencil_settings->material, IDWALK_CB_USER);
+                               }
                                library_foreach_mtex(&data, &brush->mtex);
                                library_foreach_mtex(&data, &brush->mask_mtex);
                                break;
@@ -877,6 +839,10 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
                                                }
                                        }
                                }
+
+                               for (ParticleDupliWeight *dw = psett->dupliweights.first; dw; dw = dw->next) {
+                                       CALLBACK_INVOKE(dw->ob, IDWALK_CB_NOP);
+                               }
                                break;
                        }
 
@@ -971,22 +937,60 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
                                }
                                break;
                        }
+
+                       case ID_WM:
+                       {
+                               wmWindowManager *wm = (wmWindowManager *)id;
+
+                               for (wmWindow *win = wm->windows.first; win; win = win->next) {
+                                       ID *workspace = (ID *)BKE_workspace_active_get(win->workspace_hook);
+
+                                       CALLBACK_INVOKE(win->scene, IDWALK_CB_USER_ONE);
+
+                                       CALLBACK_INVOKE_ID(workspace, IDWALK_CB_NOP);
+                                       /* allow callback to set a different workspace */
+                                       BKE_workspace_active_set(win->workspace_hook, (WorkSpace *)workspace);
+                               }
+                               break;
+                       }
+
+                       case ID_WS:
+                       {
+                               WorkSpace *workspace = (WorkSpace *)id;
+                               ListBase *layouts = BKE_workspace_layouts_get(workspace);
+
+                               for (WorkSpaceLayout *layout = layouts->first; layout; layout = layout->next) {
+                                       bScreen *screen = BKE_workspace_layout_screen_get(layout);
+
+                                       /* CALLBACK_INVOKE expects an actual pointer, not a variable holding the pointer.
+                                        * However we can't access layout->screen here since we are outside the workspace project. */
+                                       CALLBACK_INVOKE(screen, IDWALK_CB_USER);
+                                       /* allow callback to set a different screen */
+                                       BKE_workspace_layout_screen_set(layout, screen);
+                               }
+                               break;
+                       }
                        case ID_GD:
                        {
                                bGPdata *gpencil = (bGPdata *) id;
+                               /* materials */
+                               for (i = 0; i < gpencil->totcol; i++) {
+                                       CALLBACK_INVOKE(gpencil->mat[i], IDWALK_CB_USER);
+                               }
 
-                               for (bGPDlayer *gp_layer = gpencil->layers.first; gp_layer; gp_layer = gp_layer->next) {
-                                       CALLBACK_INVOKE(gp_layer->parent, IDWALK_CB_NOP);
+                               for (bGPDlayer *gplayer = gpencil->layers.first; gplayer != NULL; gplayer = gplayer->next) {
+                                       CALLBACK_INVOKE(gplayer->parent, IDWALK_CB_NOP);
                                }
+
                                break;
                        }
 
                        /* Nothing needed for those... */
+                       case ID_SCR:
                        case ID_IM:
                        case ID_VF:
                        case ID_TXT:
                        case ID_SO:
-                       case ID_WM:
                        case ID_PAL:
                        case ID_PC:
                        case ID_CF:
@@ -1063,14 +1067,8 @@ bool BKE_library_id_can_use_idtype(ID *id_owner, const short id_type_used)
                        return (ELEM(id_type_used, ID_OB, ID_WO, ID_SCE, ID_MC, ID_MA, ID_GR, ID_TXT,
                                                   ID_LS, ID_MSK, ID_SO, ID_GD, ID_BR, ID_PAL, ID_IM, ID_NT));
                case ID_OB:
-                       /* Could be the following, but simpler to just always say 'yes' here. */
-#if 0
-                       return ELEM(id_type_used, ID_ME, ID_CU, ID_MB, ID_LT, ID_SPK, ID_AR, ID_LA, ID_CA,  /* obdata */
-                                                 ID_OB, ID_MA, ID_GD, ID_GR, ID_TE, ID_PA, ID_TXT, ID_SO, ID_MC, ID_IM, ID_AC
-                                                 /* + constraints, modifiers and game logic ID types... */);
-#else
+                       /* Could be more specific, but simpler to just always say 'yes' here. */
                        return true;
-#endif
                case ID_ME:
                        return ELEM(id_type_used, ID_ME, ID_KE, ID_MA, ID_IM);
                case ID_CU:
@@ -1096,16 +1094,12 @@ bool BKE_library_id_can_use_idtype(ID *id_owner, const short id_type_used)
                case ID_SPK:
                        return ELEM(id_type_used, ID_SO);
                case ID_GR:
-                       return ELEM(id_type_used, ID_OB);
+                       return ELEM(id_type_used, ID_OB, ID_GR);
                case ID_NT:
-                       /* Could be the following, but node.id has no type restriction... */
-#if 0
-                       return ELEM(id_type_used, ID_GD /* + node.id types... */);
-#else
+                       /* Could be more specific, but node.id has no type restriction... */
                        return true;
-#endif
                case ID_BR:
-                       return ELEM(id_type_used, ID_BR, ID_IM, ID_PC, ID_TE);
+                       return ELEM(id_type_used, ID_BR, ID_IM, ID_PC, ID_TE, ID_MA);
                case ID_PA:
                        return ELEM(id_type_used, ID_OB, ID_GR, ID_TE);
                case ID_MC:
@@ -1114,13 +1108,18 @@ bool BKE_library_id_can_use_idtype(ID *id_owner, const short id_type_used)
                        return ELEM(id_type_used, ID_MC);  /* WARNING! mask->parent.id, not typed. */
                case ID_LS:
                        return (ELEM(id_type_used, ID_TE, ID_OB));
+               case ID_LP:
+                       return ELEM(id_type_used, ID_IM);
+               case ID_GD:
+                       return ELEM(id_type_used, ID_MA);
+               case ID_WS:
+                       return ELEM(id_type_used, ID_SCR, ID_SCE);
                case ID_IM:
                case ID_VF:
                case ID_TXT:
                case ID_SO:
                case ID_AR:
                case ID_AC:
-               case ID_GD:
                case ID_WM:
                case ID_PAL:
                case ID_PC: