2 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
18 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): none yet.
25 * ***** END GPL LICENSE BLOCK *****
30 * \brief ID and Library types, which are fundamental for sdna.
36 #include "DNA_listBase.h"
48 typedef struct IDPropertyData {
51 int val, val2; /* note, we actually fit a double into these two ints */
54 typedef struct IDProperty {
55 struct IDProperty *next, *prev;
58 char name[64]; /* MAX_IDPROP_NAME */
60 /* saved is used to indicate if this struct has been saved yet.
61 * seemed like a good idea as a pad var was needed anyway :) */
63 IDPropertyData data; /* note, alignment for 64 bits */
65 /* array length, also (this is important!) string length + 1.
66 * the idea is to be able to reuse array realloc functions on strings.*/
69 /* Strings and arrays are both buffered, though the buffer isn't saved. */
70 /* totallen is total length of allocated array/string, including a buffer.
71 * Note that the buffering is mild; the code comes from python's list implementation. */
75 #define MAX_IDPROP_NAME 64
76 #define DEFAULT_ALLOC_FOR_NULL_STRINGS 64
85 /* the ID link property type hasn't been implemented yet, this will require
86 * some cleanup of blenkernel, most likely. */
97 IDP_STRING_SUB_UTF8 = 0, /* default */
98 IDP_STRING_SUB_BYTE = 1, /* arbitrary byte array, _not_ null terminated */
103 IDP_FLAG_GHOST = 1 << 7, /* this means the property is set but RNA will return false when checking
104 * 'RNA_property_is_set', currently this is a runtime flag */
107 /* add any future new id property types here.*/
109 /* watch it: Sequence has identical beginning. */
111 * ID is the first thing included in all serializable types. It
112 * provides a common handle to place all data in double-linked lists.
115 /* 2 characters for ID code and 64 for actual name */
116 #define MAX_ID_NAME 66
118 /* There's a nasty circular dependency here.... 'void *' to the rescue! I
119 * really wonder why this is needed. */
124 char name[66]; /* MAX_ID_NAME */
126 * LIB_... flags report on status of the datablock this ID belongs to (persistent, saved to and read from .blend).
130 * LIB_TAG_... tags (runtime only, cleared at read time).
136 IDProperty *properties;
140 * For each library file used, a Library struct is added to Main
141 * WARNING: readfile.c, expand_doit() reads this struct without DNA check!
143 typedef struct Library {
145 struct FileData *filedata;
146 char name[1024]; /* path name used for reading, can be relative and edited in the outliner */
148 /* absolute filepath, this is only for convenience, 'name' is the real path used on file read but in
149 * some cases its useful to access the absolute one.
150 * This is set on file read.
151 * Use BKE_library_filepath_set() rather than setting 'name' directly and it will be kept in sync - campbell */
154 struct Library *parent; /* set for indirectly linked libs, used in the outliner and while reading */
156 struct PackedFile *packedfile;
164 ICON_SIZE_PREVIEW = 1,
169 /* for PreviewImage->flag */
170 enum ePreviewImage_Flag {
171 PRV_CHANGED = (1 << 0),
172 PRV_USER_EDITED = (1 << 1), /* if user-edited, do not auto-update this anymore! */
175 typedef struct PreviewImage {
176 /* All values of 2 are really NUM_ICON_SIZES */
180 short changed_timestamp[2];
181 unsigned int *rect[2];
183 /* Runtime-only data. */
184 struct GPUTexture *gputexture[2];
185 int icon_id; /* Used by previews outside of ID context. */
188 char use_deferred; /* for now a mere bool, if we add more deferred loading methods we can switch to bitflag. */
191 #define PRV_DEFERRED_DATA(prv) \
192 (CHECK_TYPE_INLINE(prv, PreviewImage *), BLI_assert((prv)->use_deferred), (void *)((prv) + 1))
195 * Defines for working with IDs.
197 * The tags represent types! This is a dirty way of enabling RTTI. The
198 * sig_byte end endian defines aren't really used much.
202 #ifdef __BIG_ENDIAN__
204 # define MAKE_ID2(c, d) ((c) << 8 | (d))
207 # define MAKE_ID2(c, d) ((d) << 8 | (c))
213 * Written to #BHead.code (for file IO)
214 * and the first 2 bytes of #ID.name (for runtime checks, see #GS macro).
216 #define ID_SCE MAKE_ID2('S', 'C') /* Scene */
217 #define ID_LI MAKE_ID2('L', 'I') /* Library */
218 #define ID_OB MAKE_ID2('O', 'B') /* Object */
219 #define ID_ME MAKE_ID2('M', 'E') /* Mesh */
220 #define ID_CU MAKE_ID2('C', 'U') /* Curve */
221 #define ID_MB MAKE_ID2('M', 'B') /* MetaBall */
222 #define ID_MA MAKE_ID2('M', 'A') /* Material */
223 #define ID_TE MAKE_ID2('T', 'E') /* Tex (Texture) */
224 #define ID_IM MAKE_ID2('I', 'M') /* Image */
225 #define ID_LT MAKE_ID2('L', 'T') /* Lattice */
226 #define ID_LA MAKE_ID2('L', 'A') /* Lamp */
227 #define ID_CA MAKE_ID2('C', 'A') /* Camera */
228 #define ID_IP MAKE_ID2('I', 'P') /* Ipo (depreciated, replaced by FCurves) */
229 #define ID_KE MAKE_ID2('K', 'E') /* Key (shape key) */
230 #define ID_WO MAKE_ID2('W', 'O') /* World */
231 #define ID_SCR MAKE_ID2('S', 'R') /* Screen */
232 #define ID_SCRN MAKE_ID2('S', 'N') /* (depreciated?) */
233 #define ID_VF MAKE_ID2('V', 'F') /* VFont (Vector Font) */
234 #define ID_TXT MAKE_ID2('T', 'X') /* Text */
235 #define ID_SPK MAKE_ID2('S', 'K') /* Speaker */
236 #define ID_SO MAKE_ID2('S', 'O') /* Sound */
237 #define ID_GR MAKE_ID2('G', 'R') /* Group */
238 #define ID_ID MAKE_ID2('I', 'D') /* (internal use only) */
239 #define ID_AR MAKE_ID2('A', 'R') /* bArmature */
240 #define ID_AC MAKE_ID2('A', 'C') /* bAction */
241 #define ID_NT MAKE_ID2('N', 'T') /* bNodeTree */
242 #define ID_BR MAKE_ID2('B', 'R') /* Brush */
243 #define ID_GD MAKE_ID2('G', 'D') /* bGPdata, (Grease Pencil) */
244 #define ID_WM MAKE_ID2('W', 'M') /* WindowManager */
245 #define ID_MC MAKE_ID2('M', 'C') /* MovieClip */
246 #define ID_MSK MAKE_ID2('M', 'S') /* Mask */
247 #define ID_LS MAKE_ID2('L', 'S') /* FreestyleLineStyle */
248 #define ID_PAL MAKE_ID2('P', 'L') /* Palette */
249 #define ID_PC MAKE_ID2('P', 'C') /* PaintCurve */
251 /* NOTE! Fake IDs, needed for g.sipo->blocktype or outliner */
252 #define ID_SEQ MAKE_ID2('S', 'Q')
254 #define ID_CO MAKE_ID2('C', 'O')
255 /* pose (action channel, used to be ID_AC in code, so we keep code for backwards compat) */
256 #define ID_PO MAKE_ID2('A', 'C')
257 /* used in outliner... */
258 #define ID_NLA MAKE_ID2('N', 'L')
260 #define ID_FLUIDSIM MAKE_ID2('F', 'S')
262 #define ID_FAKE_USERS(id) ((((ID *)id)->flag & LIB_FAKEUSER) ? 1 : 0)
263 #define ID_REAL_USERS(id) (((ID *)id)->us - ID_FAKE_USERS(id))
265 #define ID_CHECK_UNDO(id) ((GS((id)->name) != ID_SCR) && (GS((id)->name) != ID_WM))
267 #define ID_BLEND_PATH(_bmain, _id) ((_id)->lib ? (_id)->lib->filepath : (_bmain)->name)
269 #define ID_MISSING(_id) (((_id)->tag & LIB_TAG_MISSING) != 0)
274 #define GS(a) (CHECK_TYPE_ANY(a, char *, const char *, char [66], const char[66]), (*((const short *)(a))))
276 #define ID_NEW(a) if ( (a) && (a)->id.newid ) (a) = (void *)(a)->id.newid
277 #define ID_NEW_US(a) if ( (a)->id.newid) { (a) = (void *)(a)->id.newid; (a)->id.us++; }
278 #define ID_NEW_US2(a) if (((ID *)a)->newid) { (a) = ((ID *)a)->newid; ((ID *)a)->us++; }
280 /* id->flag (persitent). */
282 LIB_FAKEUSER = 1 << 9,
286 * id->tag (runtime-only).
288 * Those flags belong to three different categories, which have different expected handling in code:
290 * - RESET_BEFORE_USE: piece of code that wants to use such flag has to ensure they are properly 'reset' first.
291 * - RESET_AFTER_USE: piece of code that wants to use such flag has to ensure they are properly 'reset' after usage
292 * (though 'lifetime' of those flags is a bit fuzzy, e.g. _RECALC ones are reset on depsgraph
294 * - RESET_NEVER: those flags are 'status' one, and never actually need any reset (except on initialization
295 * during .blend file reading).
298 /* RESET_NEVER Datablock is from current .blend file. */
300 /* RESET_NEVER Datablock is from a library, but is used (linked) directly by current .blend file. */
301 LIB_TAG_EXTERN = 1 << 0,
302 /* RESET_NEVER Datablock is from a library, and is only used (linked) inderectly through other libraries. */
303 LIB_TAG_INDIRECT = 1 << 1,
305 /* RESET_AFTER_USE Three flags used internally in readfile.c, to mark IDs needing to be read (only done once). */
306 LIB_TAG_NEED_EXPAND = 1 << 3,
307 LIB_TAG_TESTEXT = (LIB_TAG_NEED_EXPAND | LIB_TAG_EXTERN),
308 LIB_TAG_TESTIND = (LIB_TAG_NEED_EXPAND | LIB_TAG_INDIRECT),
309 /* RESET_AFTER_USE Flag used internally in readfile.c, to mark IDs needing to be linked from a library. */
310 LIB_TAG_READ = 1 << 4,
311 /* RESET_AFTER_USE */
312 LIB_TAG_NEED_LINK = 1 << 5,
314 /* RESET_NEVER tag datablock as a place-holder (because the real one could not be linked from its library e.g.). */
315 LIB_TAG_MISSING = 1 << 6,
317 /* tag datablock has having an extra user. */
318 LIB_TAG_EXTRAUSER = 1 << 2,
319 /* tag datablock has having actually increased usercount for the extra virtual user. */
320 LIB_TAG_EXTRAUSER_SET = 1 << 7,
322 /* RESET_AFTER_USE tag newly duplicated/copied IDs. */
323 LIB_TAG_NEW = 1 << 8,
324 /* RESET_BEFORE_USE free test flag.
325 * TODO make it a RESET_AFTER_USE too. */
326 LIB_TAG_DOIT = 1 << 10,
327 /* RESET_AFTER_USE tag existing data before linking so we know what is new. */
328 LIB_TAG_PRE_EXISTING = 1 << 11,
330 /* RESET_AFTER_USE, used by update code (depsgraph). */
331 LIB_TAG_ID_RECALC = 1 << 12,
332 LIB_TAG_ID_RECALC_DATA = 1 << 13,
333 LIB_TAG_ANIM_NO_RECALC = 1 << 14,
334 LIB_TAG_ID_RECALC_ALL = (LIB_TAG_ID_RECALC | LIB_TAG_ID_RECALC_DATA),
337 /* To filter ID types (filter_id) */
338 /* XXX We cannot put all needed IDs inside an enum...
339 * We'll have to see whether we can fit all needed ones inside 32 values,
340 * or if we need to fallback to longlong defines :/
343 FILTER_ID_AC = (1 << 0),
344 FILTER_ID_AR = (1 << 1),
345 FILTER_ID_BR = (1 << 2),
346 FILTER_ID_CA = (1 << 3),
347 FILTER_ID_CU = (1 << 4),
348 FILTER_ID_GD = (1 << 5),
349 FILTER_ID_GR = (1 << 6),
350 FILTER_ID_IM = (1 << 7),
351 FILTER_ID_LA = (1 << 8),
352 FILTER_ID_LS = (1 << 9),
353 FILTER_ID_LT = (1 << 10),
354 FILTER_ID_MA = (1 << 11),
355 FILTER_ID_MB = (1 << 12),
356 FILTER_ID_MC = (1 << 13),
357 FILTER_ID_ME = (1 << 14),
358 FILTER_ID_MSK = (1 << 15),
359 FILTER_ID_NT = (1 << 16),
360 FILTER_ID_OB = (1 << 17),
361 FILTER_ID_PAL = (1 << 18),
362 FILTER_ID_PC = (1 << 19),
363 FILTER_ID_SCE = (1 << 20),
364 FILTER_ID_SPK = (1 << 21),
365 FILTER_ID_SO = (1 << 22),
366 FILTER_ID_TE = (1 << 23),
367 FILTER_ID_TXT = (1 << 24),
368 FILTER_ID_VF = (1 << 25),
369 FILTER_ID_WO = (1 << 26),