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:
authorBastien Montagne <b.mont29@gmail.com>2020-03-19 21:37:00 +0300
committerBastien Montagne <b.mont29@gmail.com>2020-03-19 21:39:23 +0300
commit12b621059a6f1337e8ae8fdd9533e7808225e71e (patch)
treed04a2fddc28152235191e2d93884f4d143410d85 /source/blender/blenkernel/intern
parent0b7854323d41f3a1a55a40ddf76a90e2017a0784 (diff)
Cleanup/refactor: remove BKE_idcode, in favour of BKE_idtype.
Mpving utils from idcode to idtype proved to be somewhat painful for some reasons, but now all looks good. Had to add a fake/empty shell for the special snowflake too, `ID_LINK_PLACEHOLDER/INDEX_ID_NULL`...
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r--source/blender/blenkernel/intern/idcode.c432
-rw-r--r--source/blender/blenkernel/intern/idprop_utils.c4
-rw-r--r--source/blender/blenkernel/intern/idtype.c340
-rw-r--r--source/blender/blenkernel/intern/lib_id.c33
-rw-r--r--source/blender/blenkernel/intern/main_idmap.c4
-rw-r--r--source/blender/blenkernel/intern/mesh.c4
-rw-r--r--source/blender/blenkernel/intern/modifier.c2
7 files changed, 368 insertions, 451 deletions
diff --git a/source/blender/blenkernel/intern/idcode.c b/source/blender/blenkernel/intern/idcode.c
deleted file mode 100644
index 454be246ad9..00000000000
--- a/source/blender/blenkernel/intern/idcode.c
+++ /dev/null
@@ -1,432 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- * return info about ID types
- */
-
-/** \file
- * \ingroup bke
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "DNA_ID.h"
-
-#include "BLI_utildefines.h"
-
-#include "BLT_translation.h"
-
-#include "BKE_idcode.h"
-#include "BKE_main.h"
-
-typedef struct {
- unsigned short code;
- const char *name, *plural;
-
- const char *i18n_context;
-
- int flags;
-#define IDTYPE_FLAGS_ISLINKABLE (1 << 0)
-} IDType;
-
-/* Keep alignment for readability. */
-/* clang-format off */
-/**
- * When editing ensure that:
- * - Plural needs to match rna_main.c's #MainCollectionDef.
- * - Keep it in sync with i18n contexts in BLT_translation.h
- */
-static IDType idtypes[] = {
- /** ID's directly below must all be in #Main, and be kept in sync with #MAX_LIBARRAY (membership, not order) */
- {ID_AC, "Action", "actions", BLT_I18NCONTEXT_ID_ACTION, IDTYPE_FLAGS_ISLINKABLE},
- {ID_AR, "Armature", "armatures", BLT_I18NCONTEXT_ID_ARMATURE, IDTYPE_FLAGS_ISLINKABLE},
- {ID_BR, "Brush", "brushes", BLT_I18NCONTEXT_ID_BRUSH, IDTYPE_FLAGS_ISLINKABLE},
- {ID_CA, "Camera", "cameras", BLT_I18NCONTEXT_ID_CAMERA, IDTYPE_FLAGS_ISLINKABLE},
- {ID_CF, "CacheFile", "cache_files", BLT_I18NCONTEXT_ID_CACHEFILE, IDTYPE_FLAGS_ISLINKABLE},
- {ID_GR, "Collection", "collections", BLT_I18NCONTEXT_ID_COLLECTION, IDTYPE_FLAGS_ISLINKABLE},
- {ID_CU, "Curve", "curves", BLT_I18NCONTEXT_ID_CURVE, IDTYPE_FLAGS_ISLINKABLE},
- {ID_GD, "GPencil", "grease_pencils", BLT_I18NCONTEXT_ID_GPENCIL, IDTYPE_FLAGS_ISLINKABLE}, /* rename gpencil */
- {ID_HA, "Hair", "hair", BLT_I18NCONTEXT_ID_HAIR, IDTYPE_FLAGS_ISLINKABLE},
- {ID_IM, "Image", "images", BLT_I18NCONTEXT_ID_IMAGE, IDTYPE_FLAGS_ISLINKABLE},
- {ID_IP, "Ipo", "ipos", "", IDTYPE_FLAGS_ISLINKABLE}, /* deprecated */
- {ID_KE, "Key", "shape_keys", BLT_I18NCONTEXT_ID_SHAPEKEY, 0 },
- {ID_LA, "Light", "lights", BLT_I18NCONTEXT_ID_LIGHT, IDTYPE_FLAGS_ISLINKABLE},
- {ID_LI, "Library", "libraries", BLT_I18NCONTEXT_ID_LIBRARY, 0 },
- {ID_LS, "FreestyleLineStyle", "linestyles", BLT_I18NCONTEXT_ID_FREESTYLELINESTYLE, IDTYPE_FLAGS_ISLINKABLE},
- {ID_LT, "Lattice", "lattices", BLT_I18NCONTEXT_ID_LATTICE, IDTYPE_FLAGS_ISLINKABLE},
- {ID_MA, "Material", "materials", BLT_I18NCONTEXT_ID_MATERIAL, IDTYPE_FLAGS_ISLINKABLE},
- {ID_MB, "Metaball", "metaballs", BLT_I18NCONTEXT_ID_METABALL, IDTYPE_FLAGS_ISLINKABLE},
- {ID_MC, "MovieClip", "movieclips", BLT_I18NCONTEXT_ID_MOVIECLIP, IDTYPE_FLAGS_ISLINKABLE},
- {ID_ME, "Mesh", "meshes", BLT_I18NCONTEXT_ID_MESH, IDTYPE_FLAGS_ISLINKABLE},
- {ID_MSK, "Mask", "masks", BLT_I18NCONTEXT_ID_MASK, IDTYPE_FLAGS_ISLINKABLE},
- {ID_NT, "NodeTree", "node_groups", BLT_I18NCONTEXT_ID_NODETREE, IDTYPE_FLAGS_ISLINKABLE},
- {ID_OB, "Object", "objects", BLT_I18NCONTEXT_ID_OBJECT, IDTYPE_FLAGS_ISLINKABLE},
- {ID_PA, "ParticleSettings", "particles", BLT_I18NCONTEXT_ID_PARTICLESETTINGS, IDTYPE_FLAGS_ISLINKABLE},
- {ID_PAL, "Palettes", "palettes", BLT_I18NCONTEXT_ID_PALETTE, IDTYPE_FLAGS_ISLINKABLE},
- {ID_PC, "PaintCurve", "paint_curves", BLT_I18NCONTEXT_ID_PAINTCURVE, IDTYPE_FLAGS_ISLINKABLE},
- {ID_LP, "LightProbe", "lightprobes", BLT_I18NCONTEXT_ID_LIGHTPROBE, IDTYPE_FLAGS_ISLINKABLE},
- {ID_PT, "PointCloud", "pointclouds", BLT_I18NCONTEXT_ID_POINTCLOUD, IDTYPE_FLAGS_ISLINKABLE},
- {ID_SCE, "Scene", "scenes", BLT_I18NCONTEXT_ID_SCENE, IDTYPE_FLAGS_ISLINKABLE},
- {ID_SCR, "Screen", "screens", BLT_I18NCONTEXT_ID_SCREEN, IDTYPE_FLAGS_ISLINKABLE},
- {ID_SEQ, "Sequence", "sequences", BLT_I18NCONTEXT_ID_SEQUENCE, 0 }, /* not actually ID data */
- {ID_SPK, "Speaker", "speakers", BLT_I18NCONTEXT_ID_SPEAKER, IDTYPE_FLAGS_ISLINKABLE},
- {ID_SO, "Sound", "sounds", BLT_I18NCONTEXT_ID_SOUND, IDTYPE_FLAGS_ISLINKABLE},
- {ID_TE, "Texture", "textures", BLT_I18NCONTEXT_ID_TEXTURE, IDTYPE_FLAGS_ISLINKABLE},
- {ID_TXT, "Text", "texts", BLT_I18NCONTEXT_ID_TEXT, IDTYPE_FLAGS_ISLINKABLE},
- {ID_VF, "VFont", "fonts", BLT_I18NCONTEXT_ID_VFONT, IDTYPE_FLAGS_ISLINKABLE},
- {ID_VO, "Volume", "volumes", BLT_I18NCONTEXT_ID_VOLUME, IDTYPE_FLAGS_ISLINKABLE},
- {ID_WO, "World", "worlds", BLT_I18NCONTEXT_ID_WORLD, IDTYPE_FLAGS_ISLINKABLE},
- {ID_WM, "WindowManager", "window_managers", BLT_I18NCONTEXT_ID_WINDOWMANAGER, 0 },
- {ID_WS, "WorkSpace", "workspaces", BLT_I18NCONTEXT_ID_WORKSPACE, IDTYPE_FLAGS_ISLINKABLE},
-
- /** Keep last, not an ID exactly, only include for completeness */
- {ID_LINK_PLACEHOLDER, "Link Placeholder", "link_placeholders", BLT_I18NCONTEXT_ID_ID, 0}, /* plural is fake */
-};
-/* clang-format on */
-
-/* -1 for ID_LINK_PLACEHOLDER */
-BLI_STATIC_ASSERT((ARRAY_SIZE(idtypes) - 1 == MAX_LIBARRAY), "Missing IDType");
-
-static IDType *idtype_from_name(const char *str)
-{
- int i = ARRAY_SIZE(idtypes);
-
- while (i--) {
- if (STREQ(str, idtypes[i].name)) {
- return &idtypes[i];
- }
- }
-
- return NULL;
-}
-static IDType *idtype_from_code(short idcode)
-{
- int i = ARRAY_SIZE(idtypes);
-
- while (i--) {
- if (idcode == idtypes[i].code) {
- return &idtypes[i];
- }
- }
-
- return NULL;
-}
-
-/**
- * Return if the ID code is a valid ID code.
- *
- * \param idcode: The code to check.
- * \return Boolean, 0 when invalid.
- */
-bool BKE_idcode_is_valid(short idcode)
-{
- return idtype_from_code(idcode) ? true : false;
-}
-
-/**
- * Return non-zero when an ID type is linkable.
- *
- * \param idcode: The code to check.
- * \return Boolean, 0 when non linkable.
- */
-bool BKE_idcode_is_linkable(short idcode)
-{
- IDType *idt = idtype_from_code(idcode);
- BLI_assert(idt);
- return idt ? ((idt->flags & IDTYPE_FLAGS_ISLINKABLE) != 0) : false;
-}
-
-/**
- * Convert an idcode into a name.
- *
- * \param idcode: The code to convert.
- * \return A static string representing the name of
- * the code.
- */
-const char *BKE_idcode_to_name(short idcode)
-{
- IDType *idt = idtype_from_code(idcode);
- BLI_assert(idt);
- return idt ? idt->name : NULL;
-}
-
-/**
- * Convert a name into an idcode (ie. ID_SCE)
- *
- * \param name: The name to convert.
- * \return The code for the name, or 0 if invalid.
- */
-short BKE_idcode_from_name(const char *name)
-{
- IDType *idt = idtype_from_name(name);
- BLI_assert(idt);
- return idt ? idt->code : 0;
-}
-
-/**
- * Convert an idcode into an idfilter (e.g. ID_OB -> FILTER_ID_OB).
- */
-uint64_t BKE_idcode_to_idfilter(const short idcode)
-{
-#define CASE_IDFILTER(_id) \
- case ID_##_id: \
- return FILTER_ID_##_id
-
- switch (idcode) {
- CASE_IDFILTER(AC);
- CASE_IDFILTER(AR);
- CASE_IDFILTER(BR);
- CASE_IDFILTER(CA);
- CASE_IDFILTER(CF);
- CASE_IDFILTER(CU);
- CASE_IDFILTER(GD);
- CASE_IDFILTER(GR);
- CASE_IDFILTER(IM);
- CASE_IDFILTER(LA);
- CASE_IDFILTER(LS);
- CASE_IDFILTER(LT);
- CASE_IDFILTER(MA);
- CASE_IDFILTER(MB);
- CASE_IDFILTER(MC);
- CASE_IDFILTER(ME);
- CASE_IDFILTER(MSK);
- CASE_IDFILTER(NT);
- CASE_IDFILTER(OB);
- CASE_IDFILTER(PA);
- CASE_IDFILTER(PAL);
- CASE_IDFILTER(PC);
- CASE_IDFILTER(LP);
- CASE_IDFILTER(SCE);
- CASE_IDFILTER(SPK);
- CASE_IDFILTER(SO);
- CASE_IDFILTER(TE);
- CASE_IDFILTER(TXT);
- CASE_IDFILTER(VF);
- CASE_IDFILTER(HA);
- CASE_IDFILTER(PT);
- CASE_IDFILTER(VO);
- CASE_IDFILTER(WO);
- CASE_IDFILTER(WS);
- default:
- return 0;
- }
-
-#undef CASE_IDFILTER
-}
-
-/**
- * Convert an idfilter into an idcode (e.g. FILTER_ID_OB -> ID_OB).
- */
-short BKE_idcode_from_idfilter(const uint64_t idfilter)
-{
-#define CASE_IDFILTER(_id) \
- case FILTER_ID_##_id: \
- return ID_##_id
-
- switch (idfilter) {
- CASE_IDFILTER(AC);
- CASE_IDFILTER(AR);
- CASE_IDFILTER(BR);
- CASE_IDFILTER(CA);
- CASE_IDFILTER(CF);
- CASE_IDFILTER(CU);
- CASE_IDFILTER(GD);
- CASE_IDFILTER(GR);
- CASE_IDFILTER(HA);
- CASE_IDFILTER(IM);
- CASE_IDFILTER(LA);
- CASE_IDFILTER(LP);
- CASE_IDFILTER(LS);
- CASE_IDFILTER(LT);
- CASE_IDFILTER(MA);
- CASE_IDFILTER(MB);
- CASE_IDFILTER(MC);
- CASE_IDFILTER(ME);
- CASE_IDFILTER(MSK);
- CASE_IDFILTER(NT);
- CASE_IDFILTER(OB);
- CASE_IDFILTER(PA);
- CASE_IDFILTER(PAL);
- CASE_IDFILTER(PC);
- CASE_IDFILTER(PT);
- CASE_IDFILTER(SCE);
- CASE_IDFILTER(SPK);
- CASE_IDFILTER(SO);
- CASE_IDFILTER(TE);
- CASE_IDFILTER(TXT);
- CASE_IDFILTER(VF);
- CASE_IDFILTER(VO);
- CASE_IDFILTER(WO);
- default:
- return 0;
- }
-
-#undef CASE_IDFILTER
-}
-
-/**
- * Convert an idcode into an index (e.g. ID_OB -> INDEX_ID_OB).
- */
-int BKE_idcode_to_index(const short idcode)
-{
-#define CASE_IDINDEX(_id) \
- case ID_##_id: \
- return INDEX_ID_##_id
-
- switch ((ID_Type)idcode) {
- CASE_IDINDEX(AC);
- CASE_IDINDEX(AR);
- CASE_IDINDEX(BR);
- CASE_IDINDEX(CA);
- CASE_IDINDEX(CF);
- CASE_IDINDEX(CU);
- CASE_IDINDEX(GD);
- CASE_IDINDEX(GR);
- CASE_IDINDEX(HA);
- CASE_IDINDEX(IM);
- CASE_IDINDEX(KE);
- CASE_IDINDEX(IP);
- CASE_IDINDEX(LA);
- CASE_IDINDEX(LI);
- CASE_IDINDEX(LP);
- CASE_IDINDEX(LS);
- CASE_IDINDEX(LT);
- CASE_IDINDEX(MA);
- CASE_IDINDEX(MB);
- CASE_IDINDEX(MC);
- CASE_IDINDEX(ME);
- CASE_IDINDEX(MSK);
- CASE_IDINDEX(NT);
- CASE_IDINDEX(OB);
- CASE_IDINDEX(PA);
- CASE_IDINDEX(PAL);
- CASE_IDINDEX(PC);
- CASE_IDINDEX(PT);
- CASE_IDINDEX(SCE);
- CASE_IDINDEX(SCR);
- CASE_IDINDEX(SPK);
- CASE_IDINDEX(SO);
- CASE_IDINDEX(TE);
- CASE_IDINDEX(TXT);
- CASE_IDINDEX(VF);
- CASE_IDINDEX(VO);
- CASE_IDINDEX(WM);
- CASE_IDINDEX(WO);
- CASE_IDINDEX(WS);
- }
-
- BLI_assert(0);
- return -1;
-
-#undef CASE_IDINDEX
-}
-
-/**
- * Get an idcode from an index (e.g. INDEX_ID_OB -> ID_OB).
- */
-short BKE_idcode_from_index(const int index)
-{
-#define CASE_IDCODE(_id) \
- case INDEX_ID_##_id: \
- return ID_##_id
-
- switch (index) {
- CASE_IDCODE(AC);
- CASE_IDCODE(AR);
- CASE_IDCODE(BR);
- CASE_IDCODE(CA);
- CASE_IDCODE(CF);
- CASE_IDCODE(CU);
- CASE_IDCODE(GD);
- CASE_IDCODE(GR);
- CASE_IDCODE(HA);
- CASE_IDCODE(IM);
- CASE_IDCODE(KE);
- CASE_IDCODE(IP);
- CASE_IDCODE(LA);
- CASE_IDCODE(LI);
- CASE_IDCODE(LP);
- CASE_IDCODE(LS);
- CASE_IDCODE(LT);
- CASE_IDCODE(MA);
- CASE_IDCODE(MB);
- CASE_IDCODE(MC);
- CASE_IDCODE(ME);
- CASE_IDCODE(MSK);
- CASE_IDCODE(NT);
- CASE_IDCODE(OB);
- CASE_IDCODE(PA);
- CASE_IDCODE(PAL);
- CASE_IDCODE(PC);
- CASE_IDCODE(PT);
- CASE_IDCODE(SCE);
- CASE_IDCODE(SCR);
- CASE_IDCODE(SPK);
- CASE_IDCODE(SO);
- CASE_IDCODE(TE);
- CASE_IDCODE(TXT);
- CASE_IDCODE(VF);
- CASE_IDCODE(VO);
- CASE_IDCODE(WM);
- CASE_IDCODE(WO);
- CASE_IDCODE(WS);
- }
-
- BLI_assert(0);
- return -1;
-
-#undef CASE_IDCODE
-}
-
-/**
- * Convert an idcode into a name (plural).
- *
- * \param idcode: The code to convert.
- * \return A static string representing the name of
- * the code.
- */
-const char *BKE_idcode_to_name_plural(short idcode)
-{
- IDType *idt = idtype_from_code(idcode);
- BLI_assert(idt);
- return idt ? idt->plural : NULL;
-}
-
-/**
- * Convert an idcode into its translations' context.
- *
- * \param idcode: The code to convert.
- * \return A static string representing the i18n context of the code.
- */
-const char *BKE_idcode_to_translation_context(short idcode)
-{
- IDType *idt = idtype_from_code(idcode);
- BLI_assert(idt);
- return idt ? idt->i18n_context : BLT_I18NCONTEXT_DEFAULT;
-}
-
-/**
- * Return an ID code and steps the index forward 1.
- *
- * \param index: start as 0.
- * \return the code, 0 when all codes have been returned.
- */
-short BKE_idcode_iter_step(int *index)
-{
- return (*index < ARRAY_SIZE(idtypes)) ? idtypes[(*index)++].code : 0;
-}
diff --git a/source/blender/blenkernel/intern/idprop_utils.c b/source/blender/blenkernel/intern/idprop_utils.c
index c966838171d..a7dd6afd10d 100644
--- a/source/blender/blenkernel/intern/idprop_utils.c
+++ b/source/blender/blenkernel/intern/idprop_utils.c
@@ -25,8 +25,8 @@
#include "BLI_string.h"
#include "BLI_utildefines.h"
-#include "BKE_idcode.h"
#include "BKE_idprop.h"
+#include "BKE_idtype.h"
#include "MEM_guardedalloc.h"
@@ -181,7 +181,7 @@ static void idp_repr_fn_recursive(struct ReprState *state, const IDProperty *pro
const ID *id = prop->data.pointer;
if (id != NULL) {
STR_APPEND_STR("bpy.data.");
- STR_APPEND_STR(BKE_idcode_to_name_plural(GS(id->name)));
+ STR_APPEND_STR(BKE_idtype_idcode_to_name_plural(GS(id->name)));
STR_APPEND_STR("[");
STR_APPEND_STR_QUOTE(id->name + 2);
STR_APPEND_STR("]");
diff --git a/source/blender/blenkernel/intern/idtype.c b/source/blender/blenkernel/intern/idtype.c
index ce2835717a0..5ec5dc4b4cd 100644
--- a/source/blender/blenkernel/intern/idtype.c
+++ b/source/blender/blenkernel/intern/idtype.c
@@ -24,6 +24,8 @@
* \ingroup bke
*/
+#include <string.h>
+
#include "MEM_guardedalloc.h"
#include "BLI_utildefines.h"
@@ -34,13 +36,13 @@
#include "DNA_ID.h"
-#include "BKE_idcode.h"
+#include "BKE_main.h"
#include "BKE_idtype.h"
// static CLG_LogRef LOG = {"bke.idtype"};
-static IDTypeInfo *id_types[INDEX_ID_MAX] = {NULL};
+static IDTypeInfo *id_types[MAX_LIBARRAY] = {NULL};
static void id_type_init(void)
{
@@ -91,6 +93,10 @@ static void id_type_init(void)
INIT_TYPE(ID_PT);
INIT_TYPE(ID_VO);
+ /* Special naughty boy... */
+ BLI_assert(IDType_ID_LINK_PLACEHOLDER.main_listbase_index == INDEX_ID_NULL);
+ id_types[INDEX_ID_NULL] = &IDType_ID_LINK_PLACEHOLDER;
+
#undef INIT_TYPE
}
@@ -102,9 +108,9 @@ void BKE_idtype_init(void)
const IDTypeInfo *BKE_idtype_get_info_from_idcode(const short id_code)
{
- int id_index = BKE_idcode_to_index(id_code);
+ int id_index = BKE_idtype_idcode_to_index(id_code);
- if (id_index >= 0 && id_index < INDEX_ID_MAX && id_types[id_index] != NULL &&
+ if (id_index >= 0 && id_index < ARRAY_SIZE(id_types) && id_types[id_index] != NULL &&
id_types[id_index]->name[0] != '\0') {
return id_types[id_index];
}
@@ -117,3 +123,329 @@ const IDTypeInfo *BKE_idtype_get_info_from_id(const ID *id)
{
return BKE_idtype_get_info_from_idcode(GS(id->name));
}
+
+static const IDTypeInfo *idtype_get_info_from_name(const char *str)
+{
+ for (int i = ARRAY_SIZE(id_types); i--;) {
+ if (id_types[i] != NULL && STREQ(str, id_types[i]->name)) {
+ return id_types[i];
+ }
+ }
+
+ return NULL;
+}
+
+/* Various helpers/wrappers around IDTypeInfo structure. */
+
+/**
+ * Convert an idcode into a name.
+ *
+ * \param idcode: The code to convert.
+ * \return A static string representing the name of
+ * the code.
+ */
+const char *BKE_idtype_idcode_to_name(const short idcode)
+{
+ const IDTypeInfo *id_type = BKE_idtype_get_info_from_idcode(idcode);
+ BLI_assert(id_type != NULL);
+ return id_type != NULL ? id_type->name : NULL;
+}
+
+/**
+ * Convert an idcode into a name (plural).
+ *
+ * \param idcode: The code to convert.
+ * \return A static string representing the name of
+ * the code.
+ */
+const char *BKE_idtype_idcode_to_name_plural(const short idcode)
+{
+ const IDTypeInfo *id_type = BKE_idtype_get_info_from_idcode(idcode);
+ BLI_assert(id_type != NULL);
+ return id_type != NULL ? id_type->name_plural : NULL;
+}
+
+/**
+ * Convert an idcode into its translations' context.
+ *
+ * \param idcode: The code to convert.
+ * \return A static string representing the i18n context of the code.
+ */
+const char *BKE_idtype_idcode_to_translation_context(const short idcode)
+{
+ const IDTypeInfo *id_type = BKE_idtype_get_info_from_idcode(idcode);
+ BLI_assert(id_type != NULL);
+ return id_type != NULL ? id_type->translation_context : BLT_I18NCONTEXT_DEFAULT;
+}
+
+/**
+ * Convert a name into an idcode (ie. ID_SCE)
+ *
+ * \param name: The name to convert.
+ * \return The code for the name, or 0 if invalid.
+ */
+short BKE_idtype_idcode_from_name(const char *name)
+{
+ const IDTypeInfo *id_type = idtype_get_info_from_name(name);
+ BLI_assert(id_type);
+ return id_type != NULL ? id_type->id_code : 0;
+}
+
+/**
+ * Return if the ID code is a valid ID code.
+ *
+ * \param idcode: The code to check.
+ * \return Boolean, 0 when invalid.
+ */
+bool BKE_idtype_idcode_is_valid(const short idcode)
+{
+ return BKE_idtype_get_info_from_idcode(idcode) != NULL ? true : false;
+}
+
+/**
+ * Return non-zero when an ID type is linkable.
+ *
+ * \param idcode: The code to check.
+ * \return Boolean, 0 when non linkable.
+ */
+bool BKE_idtype_idcode_is_linkable(const short idcode)
+{
+ const IDTypeInfo *id_type = BKE_idtype_get_info_from_idcode(idcode);
+ BLI_assert(id_type != NULL);
+ return id_type != NULL ? (id_type->flags & IDTYPE_FLAGS_NO_LIBLINKING) == 0 : false;
+}
+
+/**
+ * Convert an idcode into an idfilter (e.g. ID_OB -> FILTER_ID_OB).
+ */
+uint64_t BKE_idtype_idcode_to_idfilter(const short idcode)
+{
+#define CASE_IDFILTER(_id) \
+ case ID_##_id: \
+ return FILTER_ID_##_id
+
+ switch (idcode) {
+ CASE_IDFILTER(AC);
+ CASE_IDFILTER(AR);
+ CASE_IDFILTER(BR);
+ CASE_IDFILTER(CA);
+ CASE_IDFILTER(CF);
+ CASE_IDFILTER(CU);
+ CASE_IDFILTER(GD);
+ CASE_IDFILTER(GR);
+ CASE_IDFILTER(HA);
+ CASE_IDFILTER(IM);
+ CASE_IDFILTER(LA);
+ CASE_IDFILTER(LS);
+ CASE_IDFILTER(LT);
+ CASE_IDFILTER(MA);
+ CASE_IDFILTER(MB);
+ CASE_IDFILTER(MC);
+ CASE_IDFILTER(ME);
+ CASE_IDFILTER(MSK);
+ CASE_IDFILTER(NT);
+ CASE_IDFILTER(OB);
+ CASE_IDFILTER(PA);
+ CASE_IDFILTER(PAL);
+ CASE_IDFILTER(PC);
+ CASE_IDFILTER(PT);
+ CASE_IDFILTER(LP);
+ CASE_IDFILTER(SCE);
+ CASE_IDFILTER(SPK);
+ CASE_IDFILTER(SO);
+ CASE_IDFILTER(TE);
+ CASE_IDFILTER(TXT);
+ CASE_IDFILTER(VF);
+ CASE_IDFILTER(VO);
+ CASE_IDFILTER(WO);
+ CASE_IDFILTER(WS);
+ default:
+ return 0;
+ }
+
+#undef CASE_IDFILTER
+}
+
+/**
+ * Convert an idfilter into an idcode (e.g. FILTER_ID_OB -> ID_OB).
+ */
+short BKE_idtype_idcode_from_idfilter(const uint64_t idfilter)
+{
+#define CASE_IDFILTER(_id) \
+ case FILTER_ID_##_id: \
+ return ID_##_id
+
+ switch (idfilter) {
+ CASE_IDFILTER(AC);
+ CASE_IDFILTER(AR);
+ CASE_IDFILTER(BR);
+ CASE_IDFILTER(CA);
+ CASE_IDFILTER(CF);
+ CASE_IDFILTER(CU);
+ CASE_IDFILTER(GD);
+ CASE_IDFILTER(GR);
+ CASE_IDFILTER(HA);
+ CASE_IDFILTER(IM);
+ CASE_IDFILTER(LA);
+ CASE_IDFILTER(LS);
+ CASE_IDFILTER(LT);
+ CASE_IDFILTER(MA);
+ CASE_IDFILTER(MB);
+ CASE_IDFILTER(MC);
+ CASE_IDFILTER(ME);
+ CASE_IDFILTER(MSK);
+ CASE_IDFILTER(NT);
+ CASE_IDFILTER(OB);
+ CASE_IDFILTER(PA);
+ CASE_IDFILTER(PAL);
+ CASE_IDFILTER(PC);
+ CASE_IDFILTER(PT);
+ CASE_IDFILTER(LP);
+ CASE_IDFILTER(SCE);
+ CASE_IDFILTER(SPK);
+ CASE_IDFILTER(SO);
+ CASE_IDFILTER(TE);
+ CASE_IDFILTER(TXT);
+ CASE_IDFILTER(VF);
+ CASE_IDFILTER(VO);
+ CASE_IDFILTER(WO);
+ default:
+ return 0;
+ }
+
+#undef CASE_IDFILTER
+}
+
+/**
+ * Convert an idcode into an index (e.g. ID_OB -> INDEX_ID_OB).
+ */
+int BKE_idtype_idcode_to_index(const short idcode)
+{
+#define CASE_IDINDEX(_id) \
+ case ID_##_id: \
+ return INDEX_ID_##_id
+
+ switch ((ID_Type)idcode) {
+ CASE_IDINDEX(AC);
+ CASE_IDINDEX(AR);
+ CASE_IDINDEX(BR);
+ CASE_IDINDEX(CA);
+ CASE_IDINDEX(CF);
+ CASE_IDINDEX(CU);
+ CASE_IDINDEX(GD);
+ CASE_IDINDEX(GR);
+ CASE_IDINDEX(HA);
+ CASE_IDINDEX(IM);
+ CASE_IDINDEX(IP);
+ CASE_IDINDEX(KE);
+ CASE_IDINDEX(LA);
+ CASE_IDINDEX(LI);
+ CASE_IDINDEX(LS);
+ CASE_IDINDEX(LT);
+ CASE_IDINDEX(MA);
+ CASE_IDINDEX(MB);
+ CASE_IDINDEX(MC);
+ CASE_IDINDEX(ME);
+ CASE_IDINDEX(MSK);
+ CASE_IDINDEX(NT);
+ CASE_IDINDEX(OB);
+ CASE_IDINDEX(PA);
+ CASE_IDINDEX(PAL);
+ CASE_IDINDEX(PC);
+ CASE_IDINDEX(PT);
+ CASE_IDINDEX(LP);
+ CASE_IDINDEX(SCE);
+ CASE_IDINDEX(SCR);
+ CASE_IDINDEX(SPK);
+ CASE_IDINDEX(SO);
+ CASE_IDINDEX(TE);
+ CASE_IDINDEX(TXT);
+ CASE_IDINDEX(VF);
+ CASE_IDINDEX(VO);
+ CASE_IDINDEX(WM);
+ CASE_IDINDEX(WO);
+ CASE_IDINDEX(WS);
+ }
+
+ /* Special naughty boy... */
+ if (idcode == ID_LINK_PLACEHOLDER) {
+ return INDEX_ID_NULL;
+ }
+
+ return -1;
+
+#undef CASE_IDINDEX
+}
+
+/**
+ * Get an idcode from an index (e.g. INDEX_ID_OB -> ID_OB).
+ */
+short BKE_idtype_idcode_from_index(const int index)
+{
+#define CASE_IDCODE(_id) \
+ case INDEX_ID_##_id: \
+ return ID_##_id
+
+ switch (index) {
+ CASE_IDCODE(AC);
+ CASE_IDCODE(AR);
+ CASE_IDCODE(BR);
+ CASE_IDCODE(CA);
+ CASE_IDCODE(CF);
+ CASE_IDCODE(CU);
+ CASE_IDCODE(GD);
+ CASE_IDCODE(GR);
+ CASE_IDCODE(HA);
+ CASE_IDCODE(IM);
+ CASE_IDCODE(IP);
+ CASE_IDCODE(KE);
+ CASE_IDCODE(LA);
+ CASE_IDCODE(LI);
+ CASE_IDCODE(LS);
+ CASE_IDCODE(LT);
+ CASE_IDCODE(MA);
+ CASE_IDCODE(MB);
+ CASE_IDCODE(MC);
+ CASE_IDCODE(ME);
+ CASE_IDCODE(MSK);
+ CASE_IDCODE(NT);
+ CASE_IDCODE(OB);
+ CASE_IDCODE(PA);
+ CASE_IDCODE(PAL);
+ CASE_IDCODE(PC);
+ CASE_IDCODE(PT);
+ CASE_IDCODE(LP);
+ CASE_IDCODE(SCE);
+ CASE_IDCODE(SCR);
+ CASE_IDCODE(SPK);
+ CASE_IDCODE(SO);
+ CASE_IDCODE(TE);
+ CASE_IDCODE(TXT);
+ CASE_IDCODE(VF);
+ CASE_IDCODE(VO);
+ CASE_IDCODE(WM);
+ CASE_IDCODE(WO);
+ CASE_IDCODE(WS);
+ }
+
+ /* Special naughty boy... */
+ if (index == INDEX_ID_NULL) {
+ return ID_LINK_PLACEHOLDER;
+ }
+
+ return -1;
+
+#undef CASE_IDCODE
+}
+
+/**
+ * Return an ID code and steps the index forward 1.
+ *
+ * \param index: start as 0.
+ * \return the code, 0 when all codes have been returned.
+ */
+short BKE_idtype_idcode_iter_step(int *index)
+{
+ printf("%d: %d\n", *index, BKE_idtype_idcode_from_index((*index)));
+ return (*index < ARRAY_SIZE(id_types)) ? BKE_idtype_idcode_from_index((*index)++) : 0;
+}
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index 3e779c92a4a..a9a2ad31ee0 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -93,7 +93,6 @@
#include "BKE_global.h"
#include "BKE_gpencil.h"
#include "BKE_hair.h"
-#include "BKE_idcode.h"
#include "BKE_idprop.h"
#include "BKE_idtype.h"
#include "BKE_image.h"
@@ -139,6 +138,23 @@
static CLG_LogRef LOG = {.identifier = "bke.lib_id"};
+/* Empty shell mostly, but needed for read code. */
+IDTypeInfo IDType_ID_LINK_PLACEHOLDER = {
+ .id_code = ID_LINK_PLACEHOLDER,
+ .id_filter = 0,
+ .main_listbase_index = INDEX_ID_NULL,
+ .struct_size = sizeof(ID),
+ .name = "LinkPlaceholder",
+ .name_plural = "link_placeholders",
+ .translation_context = BLT_I18NCONTEXT_ID_ID,
+ .flags = IDTYPE_FLAGS_NO_COPY | IDTYPE_FLAGS_NO_LIBLINKING | IDTYPE_FLAGS_NO_MAKELOCAL,
+
+ .init_data = NULL,
+ .copy_data = NULL,
+ .free_data = NULL,
+ .make_local = NULL,
+};
+
/* GS reads the memory pointed at in a specific ordering.
* only use this definition, makes little and big endian systems
* work fine, in conjunction with MAKE_ID */
@@ -204,7 +220,7 @@ void BKE_lib_id_clear_library_data(Main *bmain, ID *id)
void id_lib_extern(ID *id)
{
if (id && ID_IS_LINKED(id)) {
- BLI_assert(BKE_idcode_is_linkable(GS(id->name)));
+ BLI_assert(BKE_idtype_idcode_is_linkable(GS(id->name)));
if (id->tag & LIB_TAG_INDIRECT) {
id->tag &= ~LIB_TAG_INDIRECT;
id->flag &= ~LIB_INDIRECT_WEAK_LINK;
@@ -217,7 +233,7 @@ void id_lib_extern(ID *id)
void id_lib_indirect_weak_link(ID *id)
{
if (id && ID_IS_LINKED(id)) {
- BLI_assert(BKE_idcode_is_linkable(GS(id->name)));
+ BLI_assert(BKE_idtype_idcode_is_linkable(GS(id->name)));
if (id->tag & LIB_TAG_INDIRECT) {
id->flag |= LIB_INDIRECT_WEAK_LINK;
}
@@ -355,7 +371,8 @@ static int lib_id_expand_local_cb(LibraryIDLinkCallbackData *cb_data)
* (through drivers)...
* Just skip it, shape key can only be either indirectly linked, or fully local, period.
* And let's curse one more time that stupid useless shapekey ID type! */
- if (*id_pointer && *id_pointer != id_self && BKE_idcode_is_linkable(GS((*id_pointer)->name))) {
+ if (*id_pointer && *id_pointer != id_self &&
+ BKE_idtype_idcode_is_linkable(GS((*id_pointer)->name))) {
id_lib_extern(*id_pointer);
}
@@ -1154,7 +1171,7 @@ void *BKE_id_new(Main *bmain, const short type, const char *name)
BLI_assert(bmain != NULL);
if (name == NULL) {
- name = DATA_(BKE_idcode_to_name(type));
+ name = DATA_(BKE_idtype_idcode_to_name(type));
}
ID *id = BKE_libblock_alloc(bmain, type, name, 0);
@@ -1171,7 +1188,7 @@ void *BKE_id_new(Main *bmain, const short type, const char *name)
void *BKE_id_new_nomain(const short type, const char *name)
{
if (name == NULL) {
- name = DATA_(BKE_idcode_to_name(type));
+ name = DATA_(BKE_idtype_idcode_to_name(type));
}
ID *id = BKE_libblock_alloc(NULL,
@@ -1670,7 +1687,7 @@ bool BKE_id_new_name_validate(ListBase *lb, ID *id, const char *tname)
if (name[0] == '\0') {
/* Disallow empty names. */
- BLI_strncpy(name, DATA_(BKE_idcode_to_name(GS(id->name))), sizeof(name));
+ BLI_strncpy(name, DATA_(BKE_idtype_idcode_to_name(GS(id->name))), sizeof(name));
}
else {
/* disallow non utf8 chars,
@@ -1875,7 +1892,7 @@ void BKE_library_make_local(Main *bmain,
/* Do not explicitly make local non-linkable IDs (shapekeys, in fact),
* they are assumed to be handled by real data-blocks responsible of them. */
- const bool do_skip = (id && !BKE_idcode_is_linkable(GS(id->name)));
+ const bool do_skip = (id && !BKE_idtype_idcode_is_linkable(GS(id->name)));
for (; id; id = id->next) {
ID *ntree = (ID *)ntreeFromID(id);
diff --git a/source/blender/blenkernel/intern/main_idmap.c b/source/blender/blenkernel/intern/main_idmap.c
index 0936e1f399f..d5499374e06 100644
--- a/source/blender/blenkernel/intern/main_idmap.c
+++ b/source/blender/blenkernel/intern/main_idmap.c
@@ -25,7 +25,7 @@
#include "DNA_ID.h"
-#include "BKE_idcode.h"
+#include "BKE_idtype.h"
#include "BKE_lib_id.h"
#include "BKE_main.h"
#include "BKE_main_idmap.h" /* own include */
@@ -110,7 +110,7 @@ struct IDNameLib_Map *BKE_main_idmap_create(struct Main *bmain,
while (index < MAX_LIBARRAY) {
struct IDNameLib_TypeMap *type_map = &id_map->type_maps[index];
type_map->map = NULL;
- type_map->id_type = BKE_idcode_iter_step(&index);
+ type_map->id_type = BKE_idtype_idcode_iter_step(&index);
BLI_assert(type_map->id_type != 0);
}
BLI_assert(index == MAX_LIBARRAY);
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 600f6b8a3ec..a59337bc4a2 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -44,7 +44,6 @@
#include "BKE_animsys.h"
#include "BKE_editmesh.h"
#include "BKE_global.h"
-#include "BKE_idcode.h"
#include "BKE_idtype.h"
#include "BKE_key.h"
#include "BKE_lib_id.h"
@@ -672,7 +671,8 @@ static void mesh_ensure_cdlayers_primary(Mesh *mesh, bool do_tessface)
Mesh *BKE_mesh_new_nomain(
int verts_len, int edges_len, int tessface_len, int loops_len, int polys_len)
{
- Mesh *mesh = BKE_libblock_alloc(NULL, ID_ME, BKE_idcode_to_name(ID_ME), LIB_ID_COPY_LOCALIZE);
+ Mesh *mesh = BKE_libblock_alloc(
+ NULL, ID_ME, BKE_idtype_idcode_to_name(ID_ME), LIB_ID_COPY_LOCALIZE);
BKE_libblock_init_empty(&mesh->id);
/* don't use CustomData_reset(...); because we dont want to touch customdata */
diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c
index 92cfc90ec3d..43e246bb342 100644
--- a/source/blender/blenkernel/intern/modifier.c
+++ b/source/blender/blenkernel/intern/modifier.c
@@ -51,7 +51,7 @@
#include "BKE_appdir.h"
#include "BKE_editmesh.h"
#include "BKE_global.h"
-#include "BKE_idcode.h"
+#include "BKE_idtype.h"
#include "BKE_key.h"
#include "BKE_lib_id.h"
#include "BKE_lib_query.h"