Blender  V2.93
BKE_idtype.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
20 #pragma once
21 
28 #include "BLI_sys_types.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 struct BlendDataReader;
35 struct BlendExpander;
36 struct BlendLibReader;
37 struct BlendWriter;
38 struct ID;
40 struct Main;
41 
43 enum {
52 };
53 
54 typedef struct IDCacheKey {
55  /* The session UUID of the ID owning the cached data. */
56  unsigned int id_session_uuid;
57  /* Value uniquely identifying the cache within its ID.
58  * Typically the offset of its member in the data-block struct, but can be anything. */
59  size_t offset_in_ID;
60  /* Actual address of the cached data to save and restore. */
61  void *cache_v;
63 
64 uint BKE_idtype_cache_key_hash(const void *key_v);
65 bool BKE_idtype_cache_key_cmp(const void *key_a_v, const void *key_b_v);
66 
67 /* ********** Prototypes for #IDTypeInfo callbacks. ********** */
68 
69 typedef void (*IDTypeInitDataFunction)(struct ID *id);
70 
72 typedef void (*IDTypeCopyDataFunction)(struct Main *bmain,
73  struct ID *id_dst,
74  const struct ID *id_src,
75  const int flag);
76 
77 typedef void (*IDTypeFreeDataFunction)(struct ID *id);
78 
80 typedef void (*IDTypeMakeLocalFunction)(struct Main *bmain, struct ID *id, const int flags);
81 
82 typedef void (*IDTypeForeachIDFunction)(struct ID *id, struct LibraryForeachIDData *data);
83 
89 typedef void (*IDTypeForeachCacheFunctionCallback)(struct ID *id,
90  const struct IDCacheKey *cache_key,
91  void **cache_p,
92  uint flags,
93  void *user_data);
94 typedef void (*IDTypeForeachCacheFunction)(struct ID *id,
95  IDTypeForeachCacheFunctionCallback function_callback,
96  void *user_data);
97 
98 typedef struct ID *(*IDTypeEmbeddedOwnerGetFunction)(struct Main *bmain, struct ID *id);
99 
100 typedef void (*IDTypeBlendWriteFunction)(struct BlendWriter *writer,
101  struct ID *id,
102  const void *id_address);
103 typedef void (*IDTypeBlendReadDataFunction)(struct BlendDataReader *reader, struct ID *id);
104 typedef void (*IDTypeBlendReadLibFunction)(struct BlendLibReader *reader, struct ID *id);
105 typedef void (*IDTypeBlendReadExpandFunction)(struct BlendExpander *expander, struct ID *id);
106 
107 typedef void (*IDTypeBlendReadUndoPreserve)(struct BlendLibReader *reader,
108  struct ID *id_new,
109  struct ID *id_old);
110 
111 typedef void (*IDTypeLibOverrideApplyPost)(struct ID *id_dst, struct ID *id_src);
112 
113 typedef struct IDTypeInfo {
114  /* ********** General IDType data. ********** */
115 
120  short id_code;
126 
133 
135  size_t struct_size;
136 
138  const char *name;
140  const char *name_plural;
142  const char *translation_context;
143 
146 
147  /* ********** ID management callbacks ********** */
148 
149  /* TODO: Note about callbacks: Ideally we could also handle here `BKE_lib_query`'s behavior, as
150  * well as read/write of files. However, this is a bit more involved than basic ID management
151  * callbacks, so we'll check on this later. */
152 
157 
163 
168 
174 
180 
185 
190 
191  /* ********** Callbacks for reading and writing .blend files. ********** */
192 
197 
202 
207 
212 
219 
227 
228 /* ********** Declaration of each IDTypeInfo. ********** */
229 
230 /* Those are defined in the respective BKE files. */
232 extern IDTypeInfo IDType_ID_LI;
233 extern IDTypeInfo IDType_ID_OB;
234 extern IDTypeInfo IDType_ID_ME;
235 extern IDTypeInfo IDType_ID_CU;
236 extern IDTypeInfo IDType_ID_MB;
237 extern IDTypeInfo IDType_ID_MA;
238 extern IDTypeInfo IDType_ID_TE;
239 extern IDTypeInfo IDType_ID_IM;
240 extern IDTypeInfo IDType_ID_LT;
241 extern IDTypeInfo IDType_ID_LA;
242 extern IDTypeInfo IDType_ID_CA;
243 extern IDTypeInfo IDType_ID_IP;
244 extern IDTypeInfo IDType_ID_KE;
245 extern IDTypeInfo IDType_ID_WO;
247 extern IDTypeInfo IDType_ID_VF;
250 extern IDTypeInfo IDType_ID_SO;
251 extern IDTypeInfo IDType_ID_GR;
252 extern IDTypeInfo IDType_ID_AR;
253 extern IDTypeInfo IDType_ID_AC;
254 extern IDTypeInfo IDType_ID_NT;
255 extern IDTypeInfo IDType_ID_BR;
256 extern IDTypeInfo IDType_ID_PA;
257 extern IDTypeInfo IDType_ID_GD;
258 extern IDTypeInfo IDType_ID_WM;
259 extern IDTypeInfo IDType_ID_MC;
261 extern IDTypeInfo IDType_ID_LS;
263 extern IDTypeInfo IDType_ID_PC;
264 extern IDTypeInfo IDType_ID_CF;
265 extern IDTypeInfo IDType_ID_WS;
266 extern IDTypeInfo IDType_ID_LP;
267 extern IDTypeInfo IDType_ID_HA;
268 extern IDTypeInfo IDType_ID_PT;
269 extern IDTypeInfo IDType_ID_VO;
271 
273 
274 /* ********** Helpers/Utils API. ********** */
275 
276 /* Module initialization. */
277 void BKE_idtype_init(void);
278 
279 /* General helpers. */
280 const struct IDTypeInfo *BKE_idtype_get_info_from_idcode(const short id_code);
281 const struct IDTypeInfo *BKE_idtype_get_info_from_id(const struct ID *id);
282 
283 const char *BKE_idtype_idcode_to_name(const short idcode);
284 const char *BKE_idtype_idcode_to_name_plural(const short idcode);
285 const char *BKE_idtype_idcode_to_translation_context(const short idcode);
286 bool BKE_idtype_idcode_is_linkable(const short idcode);
287 bool BKE_idtype_idcode_is_valid(const short idcode);
288 
289 short BKE_idtype_idcode_from_name(const char *idtype_name);
290 
291 uint64_t BKE_idtype_idcode_to_idfilter(const short idcode);
292 short BKE_idtype_idcode_from_idfilter(const uint64_t idfilter);
293 
294 int BKE_idtype_idcode_to_index(const short idcode);
295 short BKE_idtype_idcode_from_index(const int index);
296 
297 short BKE_idtype_idcode_iter_step(int *index);
298 
299 /* Some helpers/wrappers around callbacks defined in #IDTypeInfo, dealing e.g. with embedded IDs.
300  * XXX Ideally those would rather belong to #BKE_lib_id, but using callback function pointers makes
301  * this hard to do properly if we want to avoid headers includes in headers. */
302 
303 void BKE_idtype_id_foreach_cache(struct ID *id,
304  IDTypeForeachCacheFunctionCallback function_callback,
305  void *user_data);
306 
307 #ifdef __cplusplus
308 }
309 #endif
const char * BKE_idtype_idcode_to_name_plural(const short idcode)
Definition: idtype.c:182
IDTypeInfo IDType_ID_SIM
Definition: simulation.cc:152
@ IDTYPE_FLAGS_NO_MAKELOCAL
Definition: BKE_idtype.h:49
@ IDTYPE_FLAGS_NO_ANIMDATA
Definition: BKE_idtype.h:51
@ IDTYPE_FLAGS_NO_COPY
Definition: BKE_idtype.h:45
@ IDTYPE_FLAGS_NO_LIBLINKING
Definition: BKE_idtype.h:47
IDTypeInfo IDType_ID_SCE
Definition: scene.c:1712
IDTypeInfo IDType_ID_WS
Definition: workspace.c:173
IDTypeInfo IDType_ID_HA
Definition: hair.c:177
IDTypeInfo IDType_ID_NT
Definition: node.cc:942
void(* IDTypeLibOverrideApplyPost)(struct ID *id_dst, struct ID *id_src)
Definition: BKE_idtype.h:111
struct IDTypeInfo IDTypeInfo
void(* IDTypeCopyDataFunction)(struct Main *bmain, struct ID *id_dst, const struct ID *id_src, const int flag)
Definition: BKE_idtype.h:72
IDTypeInfo IDType_ID_AR
Definition: armature.c:311
IDTypeInfo IDType_ID_VO
Definition: volume.cc:632
short BKE_idtype_idcode_from_idfilter(const uint64_t idfilter)
Definition: idtype.c:294
IDTypeInfo IDType_ID_CA
Definition: camera.c:183
void(* IDTypeMakeLocalFunction)(struct Main *bmain, struct ID *id, const int flags)
Definition: BKE_idtype.h:80
IDTypeInfo IDType_ID_LP
Definition: lightprobe.c:87
void(* IDTypeBlendReadDataFunction)(struct BlendDataReader *reader, struct ID *id)
Definition: BKE_idtype.h:103
const char * BKE_idtype_idcode_to_translation_context(const short idcode)
Definition: idtype.c:195
void(* IDTypeForeachIDFunction)(struct ID *id, struct LibraryForeachIDData *data)
Definition: BKE_idtype.h:82
IDTypeInfo IDType_ID_LA
Definition: light.c:189
IDTypeInfo IDType_ID_IP
Definition: ipo.c:179
IDTypeInfo IDType_ID_TE
Definition: texture.c:206
bool BKE_idtype_cache_key_cmp(const void *key_a_v, const void *key_b_v)
Definition: idtype.c:58
void(* IDTypeForeachCacheFunction)(struct ID *id, IDTypeForeachCacheFunctionCallback function_callback, void *user_data)
Definition: BKE_idtype.h:94
short BKE_idtype_idcode_from_index(const int index)
Definition: idtype.c:407
IDTypeInfo IDType_ID_AC
Definition: action.c:290
IDTypeInfo IDType_ID_MA
Definition: material.c:254
bool BKE_idtype_idcode_is_linkable(const short idcode)
Definition: idtype.c:232
const struct IDTypeInfo * BKE_idtype_get_info_from_idcode(const short id_code)
Definition: idtype.c:131
bool BKE_idtype_idcode_is_valid(const short idcode)
Definition: idtype.c:221
IDTypeInfo IDType_ID_WM
Definition: wm.c:261
void(* IDTypeFreeDataFunction)(struct ID *id)
Definition: BKE_idtype.h:77
IDTypeInfo IDType_ID_SPK
Definition: speaker.c:94
IDTypeInfo IDType_ID_WO
Definition: world.c:186
void BKE_idtype_id_foreach_cache(struct ID *id, IDTypeForeachCacheFunctionCallback function_callback, void *user_data)
Definition: idtype.c:480
IDTypeInfo IDType_ID_VF
Definition: font.c:156
IDTypeInfo IDType_ID_PT
Definition: pointcloud.cc:170
struct ID *(* IDTypeEmbeddedOwnerGetFunction)(struct Main *bmain, struct ID *id)
Definition: BKE_idtype.h:98
IDTypeInfo IDType_ID_CU
Definition: curve.c:307
void(* IDTypeBlendReadExpandFunction)(struct BlendExpander *expander, struct ID *id)
Definition: BKE_idtype.h:105
IDTypeInfo IDType_ID_MC
Definition: movieclip.c:342
short BKE_idtype_idcode_iter_step(int *index)
Definition: idtype.c:472
const char * BKE_idtype_idcode_to_name(const short idcode)
Definition: idtype.c:168
IDTypeInfo IDType_ID_LI
Definition: library.c:63
IDTypeInfo IDType_ID_BR
Definition: brush.c:390
IDTypeInfo IDType_ID_PAL
Definition: paint.c:138
void(* IDTypeBlendReadLibFunction)(struct BlendLibReader *reader, struct ID *id)
Definition: BKE_idtype.h:104
IDTypeInfo IDType_ID_IM
Definition: image.c:318
IDTypeInfo IDType_ID_SO
IDTypeInfo IDType_ID_PC
Definition: paint.c:204
IDTypeInfo IDType_ID_OB
Definition: object.c:1135
void(* IDTypeInitDataFunction)(struct ID *id)
Definition: BKE_idtype.h:69
short BKE_idtype_idcode_from_name(const char *idtype_name)
Definition: idtype.c:208
IDTypeInfo IDType_ID_GD
Definition: gpencil.c:309
IDTypeInfo IDType_ID_MB
Definition: mball.c:184
IDTypeInfo IDType_ID_LINK_PLACEHOLDER
Definition: lib_id.c:93
IDTypeInfo IDType_ID_KE
Definition: key.c:203
IDTypeInfo IDType_ID_MSK
Definition: mask.c:250
void(* IDTypeBlendReadUndoPreserve)(struct BlendLibReader *reader, struct ID *id_new, struct ID *id_old)
Definition: BKE_idtype.h:107
int BKE_idtype_idcode_to_index(const short idcode)
Definition: idtype.c:345
IDTypeInfo IDType_ID_SCR
Definition: screen.c:309
IDTypeInfo IDType_ID_PA
Definition: particle.c:491
void(* IDTypeBlendWriteFunction)(struct BlendWriter *writer, struct ID *id, const void *id_address)
Definition: BKE_idtype.h:100
IDTypeInfo IDType_ID_ME
Definition: mesh.c:344
const struct IDTypeInfo * BKE_idtype_get_info_from_id(const struct ID *id)
struct IDCacheKey IDCacheKey
uint BKE_idtype_cache_key_hash(const void *key_v)
Definition: idtype.c:50
IDTypeInfo IDType_ID_LS
Definition: linestyle.c:747
IDTypeInfo IDType_ID_LT
Definition: lattice.c:186
IDTypeInfo IDType_ID_GR
Definition: collection.c:368
IDTypeInfo IDType_ID_TXT
Definition: text.c:239
uint64_t BKE_idtype_idcode_to_idfilter(const short idcode)
Definition: idtype.c:242
IDTypeInfo IDType_ID_CF
Definition: cachefile.c:123
eIDTypeInfoCacheCallbackFlags
Definition: BKE_idtype.h:84
@ IDTYPE_CACHE_CB_FLAGS_PERSISTENT
Definition: BKE_idtype.h:87
void BKE_idtype_init(void)
Definition: idtype.c:125
void(* IDTypeForeachCacheFunctionCallback)(struct ID *id, const struct IDCacheKey *cache_key, void **cache_p, uint flags, void *user_data)
Definition: BKE_idtype.h:89
unsigned int uint
Definition: BLI_sys_types.h:83
void * user_data
unsigned int uint32_t
Definition: stdint.h:83
unsigned __int64 uint64_t
Definition: stdint.h:93
unsigned int id_session_uuid
Definition: BKE_idtype.h:56
size_t offset_in_ID
Definition: BKE_idtype.h:59
void * cache_v
Definition: BKE_idtype.h:61
IDTypeBlendReadUndoPreserve blend_read_undo_preserve
Definition: BKE_idtype.h:218
IDTypeBlendReadExpandFunction blend_read_expand
Definition: BKE_idtype.h:211
int main_listbase_index
Definition: BKE_idtype.h:132
IDTypeEmbeddedOwnerGetFunction owner_get
Definition: BKE_idtype.h:189
short id_code
Definition: BKE_idtype.h:120
const char * name
Definition: BKE_idtype.h:138
IDTypeForeachIDFunction foreach_id
Definition: BKE_idtype.h:179
const char * name_plural
Definition: BKE_idtype.h:140
IDTypeCopyDataFunction copy_data
Definition: BKE_idtype.h:162
IDTypeInitDataFunction init_data
Definition: BKE_idtype.h:156
IDTypeForeachCacheFunction foreach_cache
Definition: BKE_idtype.h:184
uint64_t id_filter
Definition: BKE_idtype.h:125
IDTypeBlendWriteFunction blend_write
Definition: BKE_idtype.h:196
IDTypeBlendReadDataFunction blend_read_data
Definition: BKE_idtype.h:201
IDTypeFreeDataFunction free_data
Definition: BKE_idtype.h:167
uint32_t flags
Definition: BKE_idtype.h:145
size_t struct_size
Definition: BKE_idtype.h:135
IDTypeMakeLocalFunction make_local
Definition: BKE_idtype.h:173
IDTypeLibOverrideApplyPost lib_override_apply_post
Definition: BKE_idtype.h:225
const char * translation_context
Definition: BKE_idtype.h:142
IDTypeBlendReadLibFunction blend_read_lib
Definition: BKE_idtype.h:206
Definition: DNA_ID.h:273
short flag
Definition: DNA_ID.h:288
Definition: BKE_main.h:116