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:
authorJeroen Bakker <jbakker>2022-02-11 10:23:52 +0300
committerJeroen Bakker <jeroen@blender.org>2022-02-11 10:24:33 +0300
commitbccdb143db1319a8c7e6df86767513f728c9c86f (patch)
treec2f9c3d199120dbc7b52fa47914e361fc92a6372 /source/blender
parent9118cdfff3fa0a375d7ee25e9fb81e4af371cc02 (diff)
Refactoring of `BKE_library_id_can_use_idtype` to use filter_id.
For an upcoming project we would want to match multiple id types in a single go. To not replicate the implementation using other types we introduce `BKE_library_id_can_use_filter_id` that returns all supported types as a filter. Not all ID types have a filter_id (ID_LI, ID_KE, ID_SCR) These exceptions are not available in the filter_id function. Reviewed By: mont29 Maniphest Tasks: T95279 Differential Revision: https://developer.blender.org/D14061
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/BKE_lib_query.h7
-rw-r--r--source/blender/blenkernel/intern/lib_query.c123
2 files changed, 76 insertions, 54 deletions
diff --git a/source/blender/blenkernel/BKE_lib_query.h b/source/blender/blenkernel/BKE_lib_query.h
index 09d52dd9c62..926be9c7dbe 100644
--- a/source/blender/blenkernel/BKE_lib_query.h
+++ b/source/blender/blenkernel/BKE_lib_query.h
@@ -18,6 +18,8 @@
* - `BKE_lib_query_` should be used for functions in that file.
*/
+#include "BLI_sys_types.h"
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -208,6 +210,11 @@ int BKE_library_ID_use_ID(struct ID *id_user, struct ID *id_used);
bool BKE_library_id_can_use_idtype(struct ID *id_owner, short id_type_used);
/**
+ * Given the id_owner return the type of id_types it can use as a filter_id.
+ */
+uint64_t BKE_library_id_can_use_filter_id(const struct ID *id_owner);
+
+/**
* Check whether given ID is used locally (i.e. by another non-linked ID).
*/
bool BKE_library_ID_is_locally_used(struct Main *bmain, void *idv);
diff --git a/source/blender/blenkernel/intern/lib_query.c b/source/blender/blenkernel/intern/lib_query.c
index d963c0a4046..2a532cb0175 100644
--- a/source/blender/blenkernel/intern/lib_query.c
+++ b/source/blender/blenkernel/intern/lib_query.c
@@ -364,109 +364,96 @@ void BKE_library_update_ID_link_user(ID *id_dst, ID *id_src, const int cb_flag)
}
}
-bool BKE_library_id_can_use_idtype(ID *id_owner, const short id_type_used)
+uint64_t BKE_library_id_can_use_filter_id(const ID *id_owner)
{
/* any type of ID can be used in custom props. */
if (id_owner->properties) {
- return true;
+ return FILTER_ID_ALL;
}
-
const short id_type_owner = GS(id_owner->name);
/* IDProps of armature bones and nodes, and bNode->id can use virtually any type of ID. */
if (ELEM(id_type_owner, ID_NT, ID_AR)) {
- return true;
+ return FILTER_ID_ALL;
}
if (ntreeFromID(id_owner)) {
- return true;
+ return FILTER_ID_ALL;
}
if (BKE_animdata_from_id(id_owner)) {
/* AnimationData can use virtually any kind of data-blocks, through drivers especially. */
- return true;
+ return FILTER_ID_ALL;
}
switch ((ID_Type)id_type_owner) {
case ID_LI:
- return ELEM(id_type_used, ID_LI);
+ /* ID_LI doesn't exist as filter_id. */
+ return 0;
case ID_SCE:
- 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));
+ return FILTER_ID_OB | FILTER_ID_WO | FILTER_ID_SCE | FILTER_ID_MC | FILTER_ID_MA |
+ FILTER_ID_GR | FILTER_ID_TXT | FILTER_ID_LS | FILTER_ID_MSK | FILTER_ID_SO |
+ FILTER_ID_GD | FILTER_ID_BR | FILTER_ID_PAL | FILTER_ID_IM | FILTER_ID_NT;
case ID_OB:
/* Could be more specific, but simpler to just always say 'yes' here. */
- return true;
+ return FILTER_ID_ALL;
case ID_ME:
- return ELEM(id_type_used, ID_ME, ID_KE, ID_MA, ID_IM);
+ return FILTER_ID_ME | FILTER_ID_MA | FILTER_ID_IM;
case ID_CU:
- return ELEM(id_type_used, ID_OB, ID_KE, ID_MA, ID_VF);
+ return FILTER_ID_OB | FILTER_ID_MA | FILTER_ID_VF;
case ID_MB:
- return ELEM(id_type_used, ID_MA);
+ return FILTER_ID_MA;
case ID_MA:
- return (ELEM(id_type_used, ID_TE, ID_GR));
+ return FILTER_ID_TE | FILTER_ID_GR;
case ID_TE:
- return (ELEM(id_type_used, ID_IM, ID_OB));
+ return FILTER_ID_IM | FILTER_ID_OB;
case ID_LT:
- return ELEM(id_type_used, ID_KE);
+ return 0;
case ID_LA:
- return (ELEM(id_type_used, ID_TE));
+ return FILTER_ID_TE;
case ID_CA:
- return ELEM(id_type_used, ID_OB, ID_IM);
+ return FILTER_ID_OB | FILTER_ID_IM;
case ID_KE:
/* Warning! key->from, could be more types in future? */
- return ELEM(id_type_used, ID_ME, ID_CU, ID_LT);
+ return FILTER_ID_ME | FILTER_ID_CU | FILTER_ID_LT;
case ID_SCR:
- return ELEM(id_type_used, ID_SCE);
+ return FILTER_ID_SCE;
case ID_WO:
- return (ELEM(id_type_used, ID_TE));
+ return FILTER_ID_TE;
case ID_SPK:
- return ELEM(id_type_used, ID_SO);
+ return FILTER_ID_SO;
case ID_GR:
- return ELEM(id_type_used, ID_OB, ID_GR);
+ return FILTER_ID_OB | FILTER_ID_GR;
case ID_NT:
/* Could be more specific, but node.id has no type restriction... */
- return true;
+ return FILTER_ID_ALL;
case ID_BR:
- return ELEM(id_type_used, ID_BR, ID_IM, ID_PC, ID_TE, ID_MA);
+ return FILTER_ID_BR | FILTER_ID_IM | FILTER_ID_PC | FILTER_ID_TE | FILTER_ID_MA;
case ID_PA:
- return ELEM(id_type_used, ID_OB, ID_GR, ID_TE);
+ return FILTER_ID_OB | FILTER_ID_GR | FILTER_ID_TE;
case ID_MC:
- return ELEM(id_type_used, ID_GD, ID_IM);
+ return FILTER_ID_GD | FILTER_ID_IM;
case ID_MSK:
/* WARNING! mask->parent.id, not typed. */
- return ELEM(id_type_used, ID_MC);
+ return FILTER_ID_MC;
case ID_LS:
- return (ELEM(id_type_used, ID_TE, ID_OB));
+ return FILTER_ID_TE | FILTER_ID_OB;
case ID_LP:
- return ELEM(id_type_used, ID_IM);
+ return FILTER_ID_IM;
case ID_GD:
- return ELEM(id_type_used, ID_MA);
+ return FILTER_ID_MA;
case ID_WS:
- return ELEM(id_type_used, ID_SCR, ID_SCE);
+ return FILTER_ID_SCE;
case ID_CV:
- return ELEM(id_type_used, ID_MA);
+ return FILTER_ID_MA;
case ID_PT:
- return ELEM(id_type_used, ID_MA);
+ return FILTER_ID_MA;
case ID_VO:
- return ELEM(id_type_used, ID_MA);
+ return FILTER_ID_MA;
case ID_SIM:
- return ELEM(id_type_used, ID_OB, ID_IM);
+ return FILTER_ID_OB | FILTER_ID_IM;
case ID_WM:
- return ELEM(id_type_used, ID_SCE, ID_WS);
+ return FILTER_ID_SCE, FILTER_ID_WS;
case ID_IM:
case ID_VF:
case ID_TXT:
@@ -477,12 +464,40 @@ bool BKE_library_id_can_use_idtype(ID *id_owner, const short id_type_used)
case ID_PC:
case ID_CF:
/* Those types never use/reference other IDs... */
- return false;
+ return 0;
case ID_IP:
/* Deprecated... */
- return false;
+ return 0;
+ }
+ return 0;
+}
+
+bool BKE_library_id_can_use_idtype(ID *id_owner, const short id_type_used)
+{
+ /* any type of ID can be used in custom props. */
+ if (id_owner->properties) {
+ return true;
+ }
+
+ const short id_type_owner = GS(id_owner->name);
+ /* Exception for ID_LI as they don't exist as a filter. */
+ if (id_type_used == ID_LI) {
+ return id_type_owner == ID_LI;
+ }
+
+ /* Exception: ID_KE aren't available as filter_id. */
+ if (id_type_used == ID_KE) {
+ return ELEM(id_type_owner, ID_ME, ID_CU, ID_LT);
}
- return false;
+
+ /* Exception: ID_SCR aren't available as filter_id. */
+ if (id_type_used == ID_SCR) {
+ return ELEM(id_type_owner, ID_WS);
+ }
+
+ const uint64_t filter_id_type_used = BKE_idtype_idcode_to_idfilter(id_type_used);
+ const uint64_t can_be_used = BKE_library_id_can_use_filter_id(id_owner);
+ return (can_be_used & filter_id_type_used) != 0;
}
/* ***** ID users iterator. ***** */