Commit: a8f28329ad43569ff4242682353c504b08201c08
Author: Bastien Montagne
Date:   Fri Feb 8 14:34:13 2019 +0100
Branches: master
https://developer.blender.org/rBa8f28329ad43569ff4242682353c504b08201c08

BKE_idcode: Add utils to convert from 'lbarray' index to ID type.

This can be useful to be able to match some random array data with
ListBase array of IDs generated by `set_listbasepointers()`.

===================================================================

M       source/blender/blenkernel/BKE_idcode.h
M       source/blender/blenkernel/intern/idcode.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_idcode.h 
b/source/blender/blenkernel/BKE_idcode.h
index 3c98656ccb6..ff6e4689f40 100644
--- a/source/blender/blenkernel/BKE_idcode.h
+++ b/source/blender/blenkernel/BKE_idcode.h
@@ -34,6 +34,7 @@ int         BKE_idcode_to_idfilter(const short idcode);
 short       BKE_idcode_from_idfilter(const int idfilter);
 
 int BKE_idcode_to_index(const short idcode);
+short BKE_idcode_from_index(const int index);
 
 /**
  * Return an ID code and steps the index forward 1.
diff --git a/source/blender/blenkernel/intern/idcode.c 
b/source/blender/blenkernel/intern/idcode.c
index 8e6df9f6158..d057eae88a4 100644
--- a/source/blender/blenkernel/intern/idcode.c
+++ b/source/blender/blenkernel/intern/idcode.c
@@ -309,6 +309,58 @@ int BKE_idcode_to_index(const short idcode)
 #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(IM);
+               CASE_IDCODE(KE);
+               CASE_IDCODE(IP);
+               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(LP);
+               CASE_IDCODE(SCE);
+               CASE_IDCODE(SCR);
+               CASE_IDCODE(SPK);
+               CASE_IDCODE(SO);
+               CASE_IDCODE(TE);
+               CASE_IDCODE(TXT);
+               CASE_IDCODE(VF);
+               CASE_IDCODE(WM);
+               CASE_IDCODE(WO);
+               CASE_IDCODE(WS);
+       }
+
+       BLI_assert(0);
+       return -1;
+
+#undef CASE_IDCODE
+}
+
 /**
  * Convert an idcode into a name (plural).
  *

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to