Blender V4.5
rna_main.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdlib>
10#include <cstring>
11
12#include "BLI_path_utils.hh"
13
14#include "RNA_define.hh"
15
16#include "rna_internal.hh"
17
18#ifdef RNA_RUNTIME
19
20# include "BKE_global.hh"
21# include "BKE_main.hh"
22# include "BKE_mesh.hh"
23
24/* all the list begin functions are added manually here, Main is not in SDNA */
25
26static bool rna_Main_use_autopack_get(PointerRNA * /*ptr*/)
27{
28 if (G.fileflags & G_FILE_AUTOPACK) {
29 return 1;
30 }
31
32 return 0;
33}
34
35static void rna_Main_use_autopack_set(PointerRNA * /*ptr*/, bool value)
36{
37 if (value) {
38 G.fileflags |= G_FILE_AUTOPACK;
39 }
40 else {
41 G.fileflags &= ~G_FILE_AUTOPACK;
42 }
43}
44
45static bool rna_Main_is_saved_get(PointerRNA *ptr)
46{
47 const Main *bmain = (Main *)ptr->data;
48 return (bmain->filepath[0] != '\0');
49}
50
51static bool rna_Main_is_dirty_get(PointerRNA *ptr)
52{
53 /* XXX, not totally nice to do it this way, should store in main ? */
54 Main *bmain = (Main *)ptr->data;
56 if ((wm = static_cast<wmWindowManager *>(bmain->wm.first))) {
57 return !wm->file_saved;
58 }
59
60 return true;
61}
62
63static void rna_Main_filepath_get(PointerRNA *ptr, char *value)
64{
65 Main *bmain = (Main *)ptr->data;
66 strcpy(value, bmain->filepath);
67}
68
69static int rna_Main_filepath_length(PointerRNA *ptr)
70{
71 Main *bmain = (Main *)ptr->data;
72 return strlen(bmain->filepath);
73}
74
75# if 0
76static void rna_Main_filepath_set(PointerRNA *ptr, const char *value)
77{
78 Main *bmain = (Main *)ptr->data;
79 STRNCPY(bmain->filepath, value);
80}
81# endif
82
83# define RNA_MAIN_LISTBASE_FUNCS_DEF(_listbase_name) \
84 static void rna_Main_##_listbase_name##_begin(CollectionPropertyIterator *iter, \
85 PointerRNA *ptr) \
86 { \
87 rna_iterator_listbase_begin(iter, ptr, &((Main *)ptr->data)->_listbase_name, nullptr); \
88 }
89
90RNA_MAIN_LISTBASE_FUNCS_DEF(actions)
91RNA_MAIN_LISTBASE_FUNCS_DEF(armatures)
92RNA_MAIN_LISTBASE_FUNCS_DEF(brushes)
93RNA_MAIN_LISTBASE_FUNCS_DEF(cachefiles)
94RNA_MAIN_LISTBASE_FUNCS_DEF(cameras)
95RNA_MAIN_LISTBASE_FUNCS_DEF(collections)
96RNA_MAIN_LISTBASE_FUNCS_DEF(curves)
97RNA_MAIN_LISTBASE_FUNCS_DEF(fonts)
98RNA_MAIN_LISTBASE_FUNCS_DEF(gpencils)
99RNA_MAIN_LISTBASE_FUNCS_DEF(grease_pencils)
100RNA_MAIN_LISTBASE_FUNCS_DEF(hair_curves)
101RNA_MAIN_LISTBASE_FUNCS_DEF(images)
102RNA_MAIN_LISTBASE_FUNCS_DEF(lattices)
103RNA_MAIN_LISTBASE_FUNCS_DEF(libraries)
104RNA_MAIN_LISTBASE_FUNCS_DEF(lightprobes)
105RNA_MAIN_LISTBASE_FUNCS_DEF(lights)
106RNA_MAIN_LISTBASE_FUNCS_DEF(linestyles)
107RNA_MAIN_LISTBASE_FUNCS_DEF(masks)
108RNA_MAIN_LISTBASE_FUNCS_DEF(materials)
109RNA_MAIN_LISTBASE_FUNCS_DEF(meshes)
110RNA_MAIN_LISTBASE_FUNCS_DEF(metaballs)
111RNA_MAIN_LISTBASE_FUNCS_DEF(movieclips)
112RNA_MAIN_LISTBASE_FUNCS_DEF(nodetrees)
113RNA_MAIN_LISTBASE_FUNCS_DEF(objects)
114RNA_MAIN_LISTBASE_FUNCS_DEF(paintcurves)
115RNA_MAIN_LISTBASE_FUNCS_DEF(palettes)
116RNA_MAIN_LISTBASE_FUNCS_DEF(particles)
117RNA_MAIN_LISTBASE_FUNCS_DEF(pointclouds)
118RNA_MAIN_LISTBASE_FUNCS_DEF(scenes)
119RNA_MAIN_LISTBASE_FUNCS_DEF(screens)
120RNA_MAIN_LISTBASE_FUNCS_DEF(shapekeys)
121RNA_MAIN_LISTBASE_FUNCS_DEF(sounds)
122RNA_MAIN_LISTBASE_FUNCS_DEF(speakers)
123RNA_MAIN_LISTBASE_FUNCS_DEF(texts)
124RNA_MAIN_LISTBASE_FUNCS_DEF(textures)
125RNA_MAIN_LISTBASE_FUNCS_DEF(volumes)
126RNA_MAIN_LISTBASE_FUNCS_DEF(wm)
127RNA_MAIN_LISTBASE_FUNCS_DEF(workspaces)
128RNA_MAIN_LISTBASE_FUNCS_DEF(worlds)
129
130# undef RNA_MAIN_LISTBASE_FUNCS_DEF
131
132static void rna_Main_version_get(PointerRNA *ptr, int *value)
133{
134 Main *bmain = (Main *)ptr->data;
135 value[0] = bmain->versionfile / 100;
136 value[1] = bmain->versionfile % 100;
137 value[2] = bmain->subversionfile;
138}
139
140# ifdef UNIT_TEST
141
142static PointerRNA rna_Test_test_get(PointerRNA *ptr)
143{
144 PointerRNA ret = *ptr;
145 ret.type = &RNA_Test;
146
147 return ret;
148}
149
150# endif
151
152#else
153
154/* local convenience types */
155using CollectionDefFunc = void(BlenderRNA *brna, PropertyRNA *cprop);
156
158 const char *identifier;
159 const char *type;
160 const char *iter_begin;
161 const char *name;
162 const char *description;
164};
165
167{
168 StructRNA *srna;
169 PropertyRNA *prop;
170
171 /* Plural must match ID-types in `readblenentry.cc`. */
172 MainCollectionDef lists[] = {
173 {"cameras",
174 "Camera",
175 "rna_Main_cameras_begin",
176 "Cameras",
177 "Camera data-blocks",
179 {"scenes",
180 "Scene",
181 "rna_Main_scenes_begin",
182 "Scenes",
183 "Scene data-blocks",
185 {"objects",
186 "Object",
187 "rna_Main_objects_begin",
188 "Objects",
189 "Object data-blocks",
191 {"materials",
192 "Material",
193 "rna_Main_materials_begin",
194 "Materials",
195 "Material data-blocks",
197 {"node_groups",
198 "NodeTree",
199 "rna_Main_nodetrees_begin",
200 "Node Groups",
201 "Node group data-blocks",
203 {"meshes",
204 "Mesh",
205 "rna_Main_meshes_begin",
206 "Meshes",
207 "Mesh data-blocks",
209 {"lights",
210 "Light",
211 "rna_Main_lights_begin",
212 "Lights",
213 "Light data-blocks",
215 {"libraries",
216 "Library",
217 "rna_Main_libraries_begin",
218 "Libraries",
219 "Library data-blocks",
221 {"screens",
222 "Screen",
223 "rna_Main_screens_begin",
224 "Screens",
225 "Screen data-blocks",
227 {"window_managers",
228 "WindowManager",
229 "rna_Main_wm_begin",
230 "Window Managers",
231 "Window manager data-blocks",
233 {"images",
234 "Image",
235 "rna_Main_images_begin",
236 "Images",
237 "Image data-blocks",
239 {"lattices",
240 "Lattice",
241 "rna_Main_lattices_begin",
242 "Lattices",
243 "Lattice data-blocks",
245 {"curves",
246 "Curve",
247 "rna_Main_curves_begin",
248 "Curves",
249 "Curve data-blocks",
251 {"metaballs",
252 "MetaBall",
253 "rna_Main_metaballs_begin",
254 "Metaballs",
255 "Metaball data-blocks",
257 {"fonts",
258 "VectorFont",
259 "rna_Main_fonts_begin",
260 "Vector Fonts",
261 "Vector font data-blocks",
263 {"textures",
264 "Texture",
265 "rna_Main_textures_begin",
266 "Textures",
267 "Texture data-blocks",
269 {"brushes",
270 "Brush",
271 "rna_Main_brushes_begin",
272 "Brushes",
273 "Brush data-blocks",
275 {"worlds",
276 "World",
277 "rna_Main_worlds_begin",
278 "Worlds",
279 "World data-blocks",
281 {"collections",
282 "Collection",
283 "rna_Main_collections_begin",
284 "Collections",
285 "Collection data-blocks",
287 {"shape_keys",
288 "Key",
289 "rna_Main_shapekeys_begin",
290 "Shape Keys",
291 "Shape Key data-blocks",
292 nullptr},
293 {"texts", "Text", "rna_Main_texts_begin", "Texts", "Text data-blocks", RNA_def_main_texts},
294 {"speakers",
295 "Speaker",
296 "rna_Main_speakers_begin",
297 "Speakers",
298 "Speaker data-blocks",
300 {"sounds",
301 "Sound",
302 "rna_Main_sounds_begin",
303 "Sounds",
304 "Sound data-blocks",
306 {"armatures",
307 "Armature",
308 "rna_Main_armatures_begin",
309 "Armatures",
310 "Armature data-blocks",
312 {"actions",
313 "Action",
314 "rna_Main_actions_begin",
315 "Actions",
316 "Action data-blocks",
318 {"particles",
319 "ParticleSettings",
320 "rna_Main_particles_begin",
321 "Particles",
322 "Particle data-blocks",
324 {"palettes",
325 "Palette",
326 "rna_Main_palettes_begin",
327 "Palettes",
328 "Palette data-blocks",
330 {"grease_pencils",
331 "GreasePencil",
332 "rna_Main_gpencils_begin",
333 "Annotation",
334 "Annotation data-blocks (legacy Grease Pencil)",
336 {"grease_pencils_v3",
337 "GreasePencilv3",
338 "rna_Main_grease_pencils_begin",
339 "Grease Pencil",
340 "Grease Pencil data-blocks",
342 {"movieclips",
343 "MovieClip",
344 "rna_Main_movieclips_begin",
345 "Movie Clips",
346 "Movie Clip data-blocks",
348 {"masks", "Mask", "rna_Main_masks_begin", "Masks", "Masks data-blocks", RNA_def_main_masks},
349 {"linestyles",
350 "FreestyleLineStyle",
351 "rna_Main_linestyles_begin",
352 "Line Styles",
353 "Line Style data-blocks",
355 {"cache_files",
356 "CacheFile",
357 "rna_Main_cachefiles_begin",
358 "Cache Files",
359 "Cache Files data-blocks",
361 {"paint_curves",
362 "PaintCurve",
363 "rna_Main_paintcurves_begin",
364 "Paint Curves",
365 "Paint Curves data-blocks",
367 {"workspaces",
368 "WorkSpace",
369 "rna_Main_workspaces_begin",
370 "Workspaces",
371 "Workspace data-blocks",
373 {"lightprobes",
374 "LightProbe",
375 "rna_Main_lightprobes_begin",
376 "Light Probes",
377 "Light Probe data-blocks",
383 {"hair_curves",
384 "Curves",
385 "rna_Main_hair_curves_begin",
386 "Hair Curves",
387 "Hair curve data-blocks",
389 {"pointclouds",
390 "PointCloud",
391 "rna_Main_pointclouds_begin",
392 "Point Clouds",
393 "Point cloud data-blocks",
395 {"volumes",
396 "Volume",
397 "rna_Main_volumes_begin",
398 "Volumes",
399 "Volume data-blocks",
401 {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
402 };
403
404 int i;
405
406 srna = RNA_def_struct(brna, "BlendData", nullptr);
408 "Blend-File Data",
409 "Main data structure representing a .blend file and all its data-blocks");
410 RNA_def_struct_ui_icon(srna, ICON_BLENDER);
411
412 prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
415 prop, "rna_Main_filepath_get", "rna_Main_filepath_length", nullptr);
417 RNA_def_property_ui_text(prop, "Filename", "Path to the .blend file");
418
419 prop = RNA_def_property(srna, "is_dirty", PROP_BOOLEAN, PROP_NONE);
421 RNA_def_property_boolean_funcs(prop, "rna_Main_is_dirty_get", nullptr);
423 prop, "File Has Unsaved Changes", "Have recent edits been saved to disk");
424
425 prop = RNA_def_property(srna, "is_saved", PROP_BOOLEAN, PROP_NONE);
427 RNA_def_property_boolean_funcs(prop, "rna_Main_is_saved_get", nullptr);
429 prop, "File is Saved", "Has the current session been saved to disk as a .blend file");
430
431 prop = RNA_def_property(srna, "use_autopack", PROP_BOOLEAN, PROP_NONE);
432 RNA_def_property_boolean_funcs(prop, "rna_Main_use_autopack_get", "rna_Main_use_autopack_set");
434 prop, "Use Auto-Pack", "Automatically pack all external data into .blend file");
435
436 prop = RNA_def_int_vector(srna,
437 "version",
438 3,
439 nullptr,
440 0,
441 INT_MAX,
442 "Version",
443 "File format version the .blend file was saved with",
444 0,
445 INT_MAX);
446 RNA_def_property_int_funcs(prop, "rna_Main_version_get", nullptr, nullptr);
449
450 for (i = 0; lists[i].name; i++) {
451 prop = RNA_def_property(srna, lists[i].identifier, PROP_COLLECTION, PROP_NONE);
452 RNA_def_property_struct_type(prop, lists[i].type);
454 lists[i].iter_begin,
455 "rna_iterator_listbase_next",
456 "rna_iterator_listbase_end",
457 "rna_iterator_listbase_get",
458 nullptr,
459 nullptr,
460 nullptr,
461 nullptr);
462 RNA_def_property_ui_text(prop, lists[i].name, lists[i].description);
463
464 /* collection functions */
465 CollectionDefFunc *func = lists[i].func;
466 if (func) {
467 func(brna, prop);
468 }
469 }
470
471 RNA_api_main(srna);
472
473# ifdef UNIT_TEST
474
476
477 prop = RNA_def_property(srna, "test", PROP_POINTER, PROP_NONE);
478 RNA_def_property_struct_type(prop, "Test");
479 RNA_def_property_pointer_funcs(prop, "rna_Test_test_get", nullptr, nullptr, nullptr);
480
482
483# endif
484}
485
486#endif
@ G_FILE_AUTOPACK
#define FILE_MAX
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:688
@ PROP_BOOLEAN
Definition RNA_types.hh:150
@ PROP_STRING
Definition RNA_types.hh:153
@ PROP_POINTER
Definition RNA_types.hh:155
@ PROP_COLLECTION
Definition RNA_types.hh:156
@ PROP_THICK_WRAP
Definition RNA_types.hh:397
@ PROP_EDITABLE
Definition RNA_types.hh:292
@ PROP_NONE
Definition RNA_types.hh:221
@ PROP_FILEPATH
Definition RNA_types.hh:224
#define G(x, y, z)
return ret
void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
void RNA_define_verify_sdna(bool verify)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, const char *next, const char *end, const char *get, const char *length, const char *lookupint, const char *lookupstring, const char *assignint)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
PropertyRNA * RNA_def_int_vector(StructOrFunctionRNA *cont_, const char *identifier, const int len, const int *default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength)
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_main_window_managers(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_curves(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_cameras(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_worlds(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_textures(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_lightprobes(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_grease_pencil(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_movieclips(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_screens(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_images(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_volumes(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_node_groups(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_meshes(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_hair_curves(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_pointclouds(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_libraries(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_paintcurves(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_texts(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_lights(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_actions(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_palettes(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_api_main(StructRNA *srna)
void RNA_def_main_particles(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_annotations(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_lattices(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_masks(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_cachefiles(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_fonts(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_metaballs(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_speakers(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_scenes(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_collections(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_materials(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_workspaces(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_sounds(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_armatures(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_linestyles(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_brushes(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_objects(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main(BlenderRNA *brna)
Definition rna_main.cc:166
void(BlenderRNA *brna, PropertyRNA *cprop) CollectionDefFunc
Definition rna_main.cc:155
const char * name
Definition rna_main.cc:161
const char * identifier
Definition rna_main.cc:158
const char * description
Definition rna_main.cc:162
const char * type
Definition rna_main.cc:159
CollectionDefFunc * func
Definition rna_main.cc:163
const char * iter_begin
Definition rna_main.cc:160
i
Definition text_draw.cc:230
PointerRNA * ptr
Definition wm_files.cc:4226