DNA_ID.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. /*
  2. * ***** BEGIN GPL LICENSE BLOCK *****
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. *
  18. * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  19. * All rights reserved.
  20. *
  21. * The Original Code is: all of this file.
  22. *
  23. * Contributor(s): none yet.
  24. *
  25. * ***** END GPL LICENSE BLOCK *****
  26. */
  27. /** \file DNA_ID.h
  28. * \ingroup DNA
  29. * \brief ID and Library types, which are fundamental for sdna.
  30. */
  31. #ifndef __DNA_ID_H__
  32. #define __DNA_ID_H__
  33. #include "DNA_listBase.h"
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. struct Library;
  38. struct FileData;
  39. struct ID;
  40. struct PackedFile;
  41. struct GPUTexture;
  42. typedef struct IDPropertyData {
  43. void *pointer;
  44. ListBase group;
  45. int val, val2; /* note, we actually fit a double into these two ints */
  46. } IDPropertyData;
  47. typedef struct IDProperty {
  48. struct IDProperty *next, *prev;
  49. char type, subtype;
  50. short flag;
  51. char name[64]; /* MAX_IDPROP_NAME */
  52. /* saved is used to indicate if this struct has been saved yet.
  53. * seemed like a good idea as a pad var was needed anyway :) */
  54. int saved;
  55. IDPropertyData data; /* note, alignment for 64 bits */
  56. /* array length, also (this is important!) string length + 1.
  57. * the idea is to be able to reuse array realloc functions on strings.*/
  58. int len;
  59. /* Strings and arrays are both buffered, though the buffer isn't saved. */
  60. /* totallen is total length of allocated array/string, including a buffer.
  61. * Note that the buffering is mild; the code comes from python's list implementation. */
  62. int totallen;
  63. } IDProperty;
  64. #define MAX_IDPROP_NAME 64
  65. #define DEFAULT_ALLOC_FOR_NULL_STRINGS 64
  66. /*->type*/
  67. enum {
  68. IDP_STRING = 0,
  69. IDP_INT = 1,
  70. IDP_FLOAT = 2,
  71. IDP_ARRAY = 5,
  72. IDP_GROUP = 6,
  73. IDP_ID = 7,
  74. IDP_DOUBLE = 8,
  75. IDP_IDPARRAY = 9,
  76. IDP_NUMTYPES = 10,
  77. };
  78. /*->subtype */
  79. /* IDP_STRING */
  80. enum {
  81. IDP_STRING_SUB_UTF8 = 0, /* default */
  82. IDP_STRING_SUB_BYTE = 1, /* arbitrary byte array, _not_ null terminated */
  83. };
  84. /*->flag*/
  85. enum {
  86. IDP_FLAG_GHOST = 1 << 7, /* this means the property is set but RNA will return false when checking
  87. * 'RNA_property_is_set', currently this is a runtime flag */
  88. };
  89. /* add any future new id property types here.*/
  90. /* watch it: Sequence has identical beginning. */
  91. /**
  92. * ID is the first thing included in all serializable types. It
  93. * provides a common handle to place all data in double-linked lists.
  94. * */
  95. /* 2 characters for ID code and 64 for actual name */
  96. #define MAX_ID_NAME 66
  97. /* There's a nasty circular dependency here.... 'void *' to the rescue! I
  98. * really wonder why this is needed. */
  99. typedef struct ID {
  100. void *next, *prev;
  101. struct ID *newid;
  102. struct Library *lib;
  103. char name[66]; /* MAX_ID_NAME */
  104. /**
  105. * LIB_... flags report on status of the datablock this ID belongs to (persistent, saved to and read from .blend).
  106. */
  107. short flag;
  108. /**
  109. * LIB_TAG_... tags (runtime only, cleared at read time).
  110. */
  111. short tag;
  112. short pad_s1;
  113. int us;
  114. int icon_id;
  115. IDProperty *properties;
  116. } ID;
  117. /**
  118. * For each library file used, a Library struct is added to Main
  119. * WARNING: readfile.c, expand_doit() reads this struct without DNA check!
  120. */
  121. typedef struct Library {
  122. ID id;
  123. struct FileData *filedata;
  124. char name[1024]; /* path name used for reading, can be relative and edited in the outliner */
  125. /* absolute filepath, this is only for convenience, 'name' is the real path used on file read but in
  126. * some cases its useful to access the absolute one.
  127. * This is set on file read.
  128. * Use BKE_library_filepath_set() rather than setting 'name' directly and it will be kept in sync - campbell */
  129. char filepath[1024];
  130. struct Library *parent; /* set for indirectly linked libs, used in the outliner and while reading */
  131. struct PackedFile *packedfile;
  132. /* Temp data needed by read/write code. */
  133. int temp_index;
  134. short versionfile, subversionfile; /* see BLENDER_VERSION, BLENDER_SUBVERSION, needed for do_versions */
  135. } Library;
  136. enum eIconSizes {
  137. ICON_SIZE_ICON = 0,
  138. ICON_SIZE_PREVIEW = 1,
  139. NUM_ICON_SIZES
  140. };
  141. /* for PreviewImage->flag */
  142. enum ePreviewImage_Flag {
  143. PRV_CHANGED = (1 << 0),
  144. PRV_USER_EDITED = (1 << 1), /* if user-edited, do not auto-update this anymore! */
  145. };
  146. /* for PreviewImage->tag */
  147. enum {
  148. PRV_TAG_DEFFERED = (1 << 0), /* Actual loading of preview is deffered. */
  149. PRV_TAG_DEFFERED_RENDERING = (1 << 1), /* Deffered preview is being loaded. */
  150. PRV_TAG_DEFFERED_DELETE = (1 << 2), /* Deffered preview should be deleted asap. */
  151. };
  152. typedef struct PreviewImage {
  153. /* All values of 2 are really NUM_ICON_SIZES */
  154. unsigned int w[2];
  155. unsigned int h[2];
  156. short flag[2];
  157. short changed_timestamp[2];
  158. unsigned int *rect[2];
  159. /* Runtime-only data. */
  160. struct GPUTexture *gputexture[2];
  161. int icon_id; /* Used by previews outside of ID context. */
  162. short tag; /* Runtime data. */
  163. char pad[2];
  164. } PreviewImage;
  165. #define PRV_DEFERRED_DATA(prv) \
  166. (CHECK_TYPE_INLINE(prv, PreviewImage *), BLI_assert((prv)->tag & PRV_TAG_DEFFERED), (void *)((prv) + 1))
  167. /**
  168. * Defines for working with IDs.
  169. *
  170. * The tags represent types! This is a dirty way of enabling RTTI. The
  171. * sig_byte end endian defines aren't really used much.
  172. *
  173. **/
  174. #ifdef __BIG_ENDIAN__
  175. /* big endian */
  176. # define MAKE_ID2(c, d) ((c) << 8 | (d))
  177. #else
  178. /* little endian */
  179. # define MAKE_ID2(c, d) ((d) << 8 | (c))
  180. #endif
  181. /**
  182. * ID from database.
  183. *
  184. * Written to #BHead.code (for file IO)
  185. * and the first 2 bytes of #ID.name (for runtime checks, see #GS macro).
  186. */
  187. typedef enum ID_Type {
  188. ID_SCE = MAKE_ID2('S', 'C'), /* Scene */
  189. ID_LI = MAKE_ID2('L', 'I'), /* Library */
  190. ID_OB = MAKE_ID2('O', 'B'), /* Object */
  191. ID_ME = MAKE_ID2('M', 'E'), /* Mesh */
  192. ID_CU = MAKE_ID2('C', 'U'), /* Curve */
  193. ID_MB = MAKE_ID2('M', 'B'), /* MetaBall */
  194. ID_MA = MAKE_ID2('M', 'A'), /* Material */
  195. ID_TE = MAKE_ID2('T', 'E'), /* Tex (Texture) */
  196. ID_IM = MAKE_ID2('I', 'M'), /* Image */
  197. ID_LT = MAKE_ID2('L', 'T'), /* Lattice */
  198. ID_LA = MAKE_ID2('L', 'A'), /* Lamp */
  199. ID_CA = MAKE_ID2('C', 'A'), /* Camera */
  200. ID_IP = MAKE_ID2('I', 'P'), /* Ipo (depreciated, replaced by FCurves) */
  201. ID_KE = MAKE_ID2('K', 'E'), /* Key (shape key) */
  202. ID_WO = MAKE_ID2('W', 'O'), /* World */
  203. ID_SCR = MAKE_ID2('S', 'R'), /* Screen */
  204. ID_VF = MAKE_ID2('V', 'F'), /* VFont (Vector Font) */
  205. ID_TXT = MAKE_ID2('T', 'X'), /* Text */
  206. ID_SPK = MAKE_ID2('S', 'K'), /* Speaker */
  207. ID_SO = MAKE_ID2('S', 'O'), /* Sound */
  208. ID_GR = MAKE_ID2('G', 'R'), /* Group */
  209. ID_AR = MAKE_ID2('A', 'R'), /* bArmature */
  210. ID_AC = MAKE_ID2('A', 'C'), /* bAction */
  211. ID_NT = MAKE_ID2('N', 'T'), /* bNodeTree */
  212. ID_BR = MAKE_ID2('B', 'R'), /* Brush */
  213. ID_PA = MAKE_ID2('P', 'A'), /* ParticleSettings */
  214. ID_GD = MAKE_ID2('G', 'D'), /* bGPdata, (Grease Pencil) */
  215. ID_WM = MAKE_ID2('W', 'M'), /* WindowManager */
  216. ID_MC = MAKE_ID2('M', 'C'), /* MovieClip */
  217. ID_MSK = MAKE_ID2('M', 'S'), /* Mask */
  218. ID_LS = MAKE_ID2('L', 'S'), /* FreestyleLineStyle */
  219. ID_PAL = MAKE_ID2('P', 'L'), /* Palette */
  220. ID_PC = MAKE_ID2('P', 'C'), /* PaintCurve */
  221. ID_CF = MAKE_ID2('C', 'F'), /* CacheFile */
  222. } ID_Type;
  223. /* Only used as 'placeholder' in .blend files for directly linked datablocks. */
  224. #define ID_ID MAKE_ID2('I', 'D') /* (internal use only) */
  225. /* Deprecated. */
  226. #define ID_SCRN MAKE_ID2('S', 'N')
  227. /* NOTE! Fake IDs, needed for g.sipo->blocktype or outliner */
  228. #define ID_SEQ MAKE_ID2('S', 'Q')
  229. /* constraint */
  230. #define ID_CO MAKE_ID2('C', 'O')
  231. /* pose (action channel, used to be ID_AC in code, so we keep code for backwards compat) */
  232. #define ID_PO MAKE_ID2('A', 'C')
  233. /* used in outliner... */
  234. #define ID_NLA MAKE_ID2('N', 'L')
  235. /* fluidsim Ipo */
  236. #define ID_FLUIDSIM MAKE_ID2('F', 'S')
  237. #define ID_FAKE_USERS(id) ((((ID *)id)->flag & LIB_FAKEUSER) ? 1 : 0)
  238. #define ID_REAL_USERS(id) (((ID *)id)->us - ID_FAKE_USERS(id))
  239. #define ID_EXTRA_USERS(id) (((ID *)id)->tag & LIB_TAG_EXTRAUSER ? 1 : 0)
  240. #define ID_CHECK_UNDO(id) ((GS((id)->name) != ID_SCR) && (GS((id)->name) != ID_WM))
  241. #define ID_BLEND_PATH(_bmain, _id) ((_id)->lib ? (_id)->lib->filepath : (_bmain)->name)
  242. #define ID_MISSING(_id) (((_id)->tag & LIB_TAG_MISSING) != 0)
  243. #define ID_IS_LINKED_DATABLOCK(_id) (((ID *)(_id))->lib != NULL)
  244. #ifdef GS
  245. # undef GS
  246. #endif
  247. #define GS(a) (CHECK_TYPE_ANY(a, char *, const char *, char [66], const char[66]), (*((const short *)(a))))
  248. #define ID_NEW_SET(_id, _idn) \
  249. (((ID *)(_id))->newid = (ID *)(_idn), ((ID *)(_id))->newid->tag |= LIB_TAG_NEW, (void *)((ID *)(_id))->newid)
  250. #define ID_NEW_REMAP(a) if ((a) && (a)->id.newid) (a) = (void *)(a)->id.newid
  251. /* id->flag (persitent). */
  252. enum {
  253. LIB_FAKEUSER = 1 << 9,
  254. };
  255. /**
  256. * id->tag (runtime-only).
  257. *
  258. * Those flags belong to three different categories, which have different expected handling in code:
  259. *
  260. * - RESET_BEFORE_USE: piece of code that wants to use such flag has to ensure they are properly 'reset' first.
  261. * - RESET_AFTER_USE: piece of code that wants to use such flag has to ensure they are properly 'reset' after usage
  262. * (though 'lifetime' of those flags is a bit fuzzy, e.g. _RECALC ones are reset on depsgraph
  263. * evaluation...).
  264. * - RESET_NEVER: those flags are 'status' one, and never actually need any reset (except on initialization
  265. * during .blend file reading).
  266. */
  267. enum {
  268. /* RESET_NEVER Datablock is from current .blend file. */
  269. LIB_TAG_LOCAL = 0,
  270. /* RESET_NEVER Datablock is from a library, but is used (linked) directly by current .blend file. */
  271. LIB_TAG_EXTERN = 1 << 0,
  272. /* RESET_NEVER Datablock is from a library, and is only used (linked) inderectly through other libraries. */
  273. LIB_TAG_INDIRECT = 1 << 1,
  274. /* RESET_AFTER_USE Three flags used internally in readfile.c, to mark IDs needing to be read (only done once). */
  275. LIB_TAG_NEED_EXPAND = 1 << 3,
  276. LIB_TAG_TESTEXT = (LIB_TAG_NEED_EXPAND | LIB_TAG_EXTERN),
  277. LIB_TAG_TESTIND = (LIB_TAG_NEED_EXPAND | LIB_TAG_INDIRECT),
  278. /* RESET_AFTER_USE Flag used internally in readfile.c, to mark IDs needing to be linked from a library. */
  279. LIB_TAG_READ = 1 << 4,
  280. /* RESET_AFTER_USE */
  281. LIB_TAG_NEED_LINK = 1 << 5,
  282. /* RESET_NEVER tag datablock as a place-holder (because the real one could not be linked from its library e.g.). */
  283. LIB_TAG_MISSING = 1 << 6,
  284. /* tag datablock has having an extra user. */
  285. LIB_TAG_EXTRAUSER = 1 << 2,
  286. /* tag datablock has having actually increased usercount for the extra virtual user. */
  287. LIB_TAG_EXTRAUSER_SET = 1 << 7,
  288. /* RESET_AFTER_USE tag newly duplicated/copied IDs.
  289. * Also used internally in readfile.c to mark datablocks needing do_versions. */
  290. LIB_TAG_NEW = 1 << 8,
  291. /* RESET_BEFORE_USE free test flag.
  292. * TODO make it a RESET_AFTER_USE too. */
  293. LIB_TAG_DOIT = 1 << 10,
  294. /* RESET_AFTER_USE tag existing data before linking so we know what is new. */
  295. LIB_TAG_PRE_EXISTING = 1 << 11,
  296. /* RESET_AFTER_USE, used by update code (depsgraph). */
  297. LIB_TAG_ID_RECALC = 1 << 12,
  298. LIB_TAG_ID_RECALC_DATA = 1 << 13,
  299. LIB_TAG_ANIM_NO_RECALC = 1 << 14,
  300. LIB_TAG_ID_RECALC_ALL = (LIB_TAG_ID_RECALC | LIB_TAG_ID_RECALC_DATA),
  301. };
  302. /* To filter ID types (filter_id) */
  303. /* XXX We cannot put all needed IDs inside an enum...
  304. * We'll have to see whether we can fit all needed ones inside 32 values,
  305. * or if we need to fallback to longlong defines :/
  306. */
  307. enum {
  308. FILTER_ID_AC = (1 << 0),
  309. FILTER_ID_AR = (1 << 1),
  310. FILTER_ID_BR = (1 << 2),
  311. FILTER_ID_CA = (1 << 3),
  312. FILTER_ID_CU = (1 << 4),
  313. FILTER_ID_GD = (1 << 5),
  314. FILTER_ID_GR = (1 << 6),
  315. FILTER_ID_IM = (1 << 7),
  316. FILTER_ID_LA = (1 << 8),
  317. FILTER_ID_LS = (1 << 9),
  318. FILTER_ID_LT = (1 << 10),
  319. FILTER_ID_MA = (1 << 11),
  320. FILTER_ID_MB = (1 << 12),
  321. FILTER_ID_MC = (1 << 13),
  322. FILTER_ID_ME = (1 << 14),
  323. FILTER_ID_MSK = (1 << 15),
  324. FILTER_ID_NT = (1 << 16),
  325. FILTER_ID_OB = (1 << 17),
  326. FILTER_ID_PAL = (1 << 18),
  327. FILTER_ID_PC = (1 << 19),
  328. FILTER_ID_SCE = (1 << 20),
  329. FILTER_ID_SPK = (1 << 21),
  330. FILTER_ID_SO = (1 << 22),
  331. FILTER_ID_TE = (1 << 23),
  332. FILTER_ID_TXT = (1 << 24),
  333. FILTER_ID_VF = (1 << 25),
  334. FILTER_ID_WO = (1 << 26),
  335. FILTER_ID_PA = (1 << 27),
  336. FILTER_ID_CF = (1 << 28),
  337. };
  338. /* IMPORTANT: this enum matches the order currently use in set_lisbasepointers,
  339. * keep them in sync! */
  340. enum {
  341. INDEX_ID_LI = 0,
  342. INDEX_ID_IP,
  343. INDEX_ID_AC,
  344. INDEX_ID_KE,
  345. INDEX_ID_GD,
  346. INDEX_ID_NT,
  347. INDEX_ID_IM,
  348. INDEX_ID_TE,
  349. INDEX_ID_MA,
  350. INDEX_ID_VF,
  351. INDEX_ID_AR,
  352. INDEX_ID_CF,
  353. INDEX_ID_ME,
  354. INDEX_ID_CU,
  355. INDEX_ID_MB,
  356. INDEX_ID_LT,
  357. INDEX_ID_LA,
  358. INDEX_ID_CA,
  359. INDEX_ID_TXT,
  360. INDEX_ID_SO,
  361. INDEX_ID_GR,
  362. INDEX_ID_PAL,
  363. INDEX_ID_PC,
  364. INDEX_ID_BR,
  365. INDEX_ID_PA,
  366. INDEX_ID_SPK,
  367. INDEX_ID_WO,
  368. INDEX_ID_MC,
  369. INDEX_ID_SCR,
  370. INDEX_ID_OB,
  371. INDEX_ID_LS,
  372. INDEX_ID_SCE,
  373. INDEX_ID_WM,
  374. INDEX_ID_MSK,
  375. INDEX_ID_NULL,
  376. };
  377. #ifdef __cplusplus
  378. }
  379. #endif
  380. #endif