Blender V4.3
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
9#include <cstdlib>
10#include <cstring>
11
12#include "BLI_path_utils.hh"
13#include "BLI_utildefines.h"
14
15#include "RNA_access.hh"
16#include "RNA_define.hh"
17
18#include "rna_internal.hh"
19
20#ifdef RNA_RUNTIME
21
22# include "BKE_global.hh"
23# include "BKE_main.hh"
24# include "BKE_mesh.hh"
25
26/* all the list begin functions are added manually here, Main is not in SDNA */
27
28static bool rna_Main_use_autopack_get(PointerRNA * /*ptr*/)
29{
30 if (G.fileflags & G_FILE_AUTOPACK) {
31 return 1;
32 }
33
34 return 0;
35}
36
37static void rna_Main_use_autopack_set(PointerRNA * /*ptr*/, bool value)
38{
39 if (value) {
40 G.fileflags |= G_FILE_AUTOPACK;
41 }
42 else {
43 G.fileflags &= ~G_FILE_AUTOPACK;
44 }
45}
46
47static bool rna_Main_is_saved_get(PointerRNA *ptr)
48{
49 const Main *bmain = (Main *)ptr->data;
50 return (bmain->filepath[0] != '\0');
51}
52
53static bool rna_Main_is_dirty_get(PointerRNA *ptr)
54{
55 /* XXX, not totally nice to do it this way, should store in main ? */
56 Main *bmain = (Main *)ptr->data;
58 if ((wm = static_cast<wmWindowManager *>(bmain->wm.first))) {
59 return !wm->file_saved;
60 }
61
62 return true;
63}
64
65static void rna_Main_filepath_get(PointerRNA *ptr, char *value)
66{
67 Main *bmain = (Main *)ptr->data;
68 strcpy(value, bmain->filepath);
69}
70
71static int rna_Main_filepath_length(PointerRNA *ptr)
72{
73 Main *bmain = (Main *)ptr->data;
74 return strlen(bmain->filepath);
75}
76
77# if 0
78static void rna_Main_filepath_set(PointerRNA *ptr, const char *value)
79{
80 Main *bmain = (Main *)ptr->data;
81 STRNCPY(bmain->filepath, value);
82}
83# endif
84
85# define RNA_MAIN_LISTBASE_FUNCS_DEF(_listbase_name) \
86 static void rna_Main_##_listbase_name##_begin(CollectionPropertyIterator *iter, \
87 PointerRNA *ptr) \
88 { \
89 rna_iterator_listbase_begin(iter, &((Main *)ptr->data)->_listbase_name, nullptr); \
90 }
91
92RNA_MAIN_LISTBASE_FUNCS_DEF(actions)
93RNA_MAIN_LISTBASE_FUNCS_DEF(armatures)
94RNA_MAIN_LISTBASE_FUNCS_DEF(brushes)
95RNA_MAIN_LISTBASE_FUNCS_DEF(cachefiles)
96RNA_MAIN_LISTBASE_FUNCS_DEF(cameras)
97RNA_MAIN_LISTBASE_FUNCS_DEF(collections)
98RNA_MAIN_LISTBASE_FUNCS_DEF(curves)
99RNA_MAIN_LISTBASE_FUNCS_DEF(fonts)
100RNA_MAIN_LISTBASE_FUNCS_DEF(gpencils)
101RNA_MAIN_LISTBASE_FUNCS_DEF(grease_pencils)
102RNA_MAIN_LISTBASE_FUNCS_DEF(hair_curves)
103RNA_MAIN_LISTBASE_FUNCS_DEF(images)
104RNA_MAIN_LISTBASE_FUNCS_DEF(lattices)
105RNA_MAIN_LISTBASE_FUNCS_DEF(libraries)
106RNA_MAIN_LISTBASE_FUNCS_DEF(lightprobes)
107RNA_MAIN_LISTBASE_FUNCS_DEF(lights)
108RNA_MAIN_LISTBASE_FUNCS_DEF(linestyles)
109RNA_MAIN_LISTBASE_FUNCS_DEF(masks)
110RNA_MAIN_LISTBASE_FUNCS_DEF(materials)
111RNA_MAIN_LISTBASE_FUNCS_DEF(meshes)
112RNA_MAIN_LISTBASE_FUNCS_DEF(metaballs)
113RNA_MAIN_LISTBASE_FUNCS_DEF(movieclips)
114RNA_MAIN_LISTBASE_FUNCS_DEF(nodetrees)
115RNA_MAIN_LISTBASE_FUNCS_DEF(objects)
116RNA_MAIN_LISTBASE_FUNCS_DEF(paintcurves)
117RNA_MAIN_LISTBASE_FUNCS_DEF(palettes)
118RNA_MAIN_LISTBASE_FUNCS_DEF(particles)
119RNA_MAIN_LISTBASE_FUNCS_DEF(pointclouds)
120RNA_MAIN_LISTBASE_FUNCS_DEF(scenes)
121RNA_MAIN_LISTBASE_FUNCS_DEF(screens)
122RNA_MAIN_LISTBASE_FUNCS_DEF(shapekeys)
123RNA_MAIN_LISTBASE_FUNCS_DEF(sounds)
124RNA_MAIN_LISTBASE_FUNCS_DEF(speakers)
125RNA_MAIN_LISTBASE_FUNCS_DEF(texts)
126RNA_MAIN_LISTBASE_FUNCS_DEF(textures)
127RNA_MAIN_LISTBASE_FUNCS_DEF(volumes)
128RNA_MAIN_LISTBASE_FUNCS_DEF(wm)
129RNA_MAIN_LISTBASE_FUNCS_DEF(workspaces)
130RNA_MAIN_LISTBASE_FUNCS_DEF(worlds)
131
132# undef RNA_MAIN_LISTBASE_FUNCS_DEF
133
134static void rna_Main_version_get(PointerRNA *ptr, int *value)
135{
136 Main *bmain = (Main *)ptr->data;
137 value[0] = bmain->versionfile / 100;
138 value[1] = bmain->versionfile % 100;
139 value[2] = bmain->subversionfile;
140}
141
142# ifdef UNIT_TEST
143
144static PointerRNA rna_Test_test_get(PointerRNA *ptr)
145{
146 PointerRNA ret = *ptr;
147 ret.type = &RNA_Test;
148
149 return ret;
150}
151
152# endif
153
154#else
155
156/* local convenience types */
157using CollectionDefFunc = void(BlenderRNA *brna, PropertyRNA *cprop);
158
160 const char *identifier;
161 const char *type;
162 const char *iter_begin;
163 const char *name;
164 const char *description;
166};
167
169{
170 StructRNA *srna;
171 PropertyRNA *prop;
172
173 /* Plural must match ID-types in `readblenentry.cc`. */
174 MainCollectionDef lists[] = {
175 {"cameras",
176 "Camera",
177 "rna_Main_cameras_begin",
178 "Cameras",
179 "Camera data-blocks",
181 {"scenes",
182 "Scene",
183 "rna_Main_scenes_begin",
184 "Scenes",
185 "Scene data-blocks",
187 {"objects",
188 "Object",
189 "rna_Main_objects_begin",
190 "Objects",
191 "Object data-blocks",
193 {"materials",
194 "Material",
195 "rna_Main_materials_begin",
196 "Materials",
197 "Material data-blocks",
199 {"node_groups",
200 "NodeTree",
201 "rna_Main_nodetrees_begin",
202 "Node Groups",
203 "Node group data-blocks",
205 {"meshes",
206 "Mesh",
207 "rna_Main_meshes_begin",
208 "Meshes",
209 "Mesh data-blocks",
211 {"lights",
212 "Light",
213 "rna_Main_lights_begin",
214 "Lights",
215 "Light data-blocks",
217 {"libraries",
218 "Library",
219 "rna_Main_libraries_begin",
220 "Libraries",
221 "Library data-blocks",
223 {"screens",
224 "Screen",
225 "rna_Main_screens_begin",
226 "Screens",
227 "Screen data-blocks",
229 {"window_managers",
230 "WindowManager",
231 "rna_Main_wm_begin",
232 "Window Managers",
233 "Window manager data-blocks",
235 {"images",
236 "Image",
237 "rna_Main_images_begin",
238 "Images",
239 "Image data-blocks",
241 {"lattices",
242 "Lattice",
243 "rna_Main_lattices_begin",
244 "Lattices",
245 "Lattice data-blocks",
247 {"curves",
248 "Curve",
249 "rna_Main_curves_begin",
250 "Curves",
251 "Curve data-blocks",
253 {"metaballs",
254 "MetaBall",
255 "rna_Main_metaballs_begin",
256 "Metaballs",
257 "Metaball data-blocks",
259 {"fonts",
260 "VectorFont",
261 "rna_Main_fonts_begin",
262 "Vector Fonts",
263 "Vector font data-blocks",
265 {"textures",
266 "Texture",
267 "rna_Main_textures_begin",
268 "Textures",
269 "Texture data-blocks",
271 {"brushes",
272 "Brush",
273 "rna_Main_brushes_begin",
274 "Brushes",
275 "Brush data-blocks",
277 {"worlds",
278 "World",
279 "rna_Main_worlds_begin",
280 "Worlds",
281 "World data-blocks",
283 {"collections",
284 "Collection",
285 "rna_Main_collections_begin",
286 "Collections",
287 "Collection data-blocks",
289 {"shape_keys",
290 "Key",
291 "rna_Main_shapekeys_begin",
292 "Shape Keys",
293 "Shape Key data-blocks",
294 nullptr},
295 {"texts", "Text", "rna_Main_texts_begin", "Texts", "Text data-blocks", RNA_def_main_texts},
296 {"speakers",
297 "Speaker",
298 "rna_Main_speakers_begin",
299 "Speakers",
300 "Speaker data-blocks",
302 {"sounds",
303 "Sound",
304 "rna_Main_sounds_begin",
305 "Sounds",
306 "Sound data-blocks",
308 {"armatures",
309 "Armature",
310 "rna_Main_armatures_begin",
311 "Armatures",
312 "Armature data-blocks",
314 {"actions",
315 "Action",
316 "rna_Main_actions_begin",
317 "Actions",
318 "Action data-blocks",
320 {"particles",
321 "ParticleSettings",
322 "rna_Main_particles_begin",
323 "Particles",
324 "Particle data-blocks",
326 {"palettes",
327 "Palette",
328 "rna_Main_palettes_begin",
329 "Palettes",
330 "Palette data-blocks",
332 {"grease_pencils",
333 "GreasePencil",
334 "rna_Main_gpencils_begin",
335 "Annotation",
336 "Annotation data-blocks (legacy Grease Pencil)",
338 {"grease_pencils_v3",
339 "GreasePencilv3",
340 "rna_Main_grease_pencils_begin",
341 "Grease Pencil",
342 "Grease Pencil data-blocks",
344 {"movieclips",
345 "MovieClip",
346 "rna_Main_movieclips_begin",
347 "Movie Clips",
348 "Movie Clip data-blocks",
350 {"masks", "Mask", "rna_Main_masks_begin", "Masks", "Masks data-blocks", RNA_def_main_masks},
351 {"linestyles",
352 "FreestyleLineStyle",
353 "rna_Main_linestyles_begin",
354 "Line Styles",
355 "Line Style data-blocks",
357 {"cache_files",
358 "CacheFile",
359 "rna_Main_cachefiles_begin",
360 "Cache Files",
361 "Cache Files data-blocks",
363 {"paint_curves",
364 "PaintCurve",
365 "rna_Main_paintcurves_begin",
366 "Paint Curves",
367 "Paint Curves data-blocks",
369 {"workspaces",
370 "WorkSpace",
371 "rna_Main_workspaces_begin",
372 "Workspaces",
373 "Workspace data-blocks",
375 {"lightprobes",
376 "LightProbe",
377 "rna_Main_lightprobes_begin",
378 "Light Probes",
379 "Light Probe data-blocks",
385 {"hair_curves",
386 "Curves",
387 "rna_Main_hair_curves_begin",
388 "Hair Curves",
389 "Hair curve data-blocks",
391 {"pointclouds",
392 "PointCloud",
393 "rna_Main_pointclouds_begin",
394 "Point Clouds",
395 "Point cloud data-blocks",
397 {"volumes",
398 "Volume",
399 "rna_Main_volumes_begin",
400 "Volumes",
401 "Volume data-blocks",
403 {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
404 };
405
406 int i;
407
408 srna = RNA_def_struct(brna, "BlendData", nullptr);
410 "Blend-File Data",
411 "Main data structure representing a .blend file and all its data-blocks");
412 RNA_def_struct_ui_icon(srna, ICON_BLENDER);
413
414 prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
417 prop, "rna_Main_filepath_get", "rna_Main_filepath_length", nullptr);
419 RNA_def_property_ui_text(prop, "Filename", "Path to the .blend file");
420
421 prop = RNA_def_property(srna, "is_dirty", PROP_BOOLEAN, PROP_NONE);
423 RNA_def_property_boolean_funcs(prop, "rna_Main_is_dirty_get", nullptr);
425 prop, "File Has Unsaved Changes", "Have recent edits been saved to disk");
426
427 prop = RNA_def_property(srna, "is_saved", PROP_BOOLEAN, PROP_NONE);
429 RNA_def_property_boolean_funcs(prop, "rna_Main_is_saved_get", nullptr);
431 prop, "File is Saved", "Has the current session been saved to disk as a .blend file");
432
433 prop = RNA_def_property(srna, "use_autopack", PROP_BOOLEAN, PROP_NONE);
434 RNA_def_property_boolean_funcs(prop, "rna_Main_use_autopack_get", "rna_Main_use_autopack_set");
436 prop, "Use Auto-Pack", "Automatically pack all external data into .blend file");
437
438 prop = RNA_def_int_vector(srna,
439 "version",
440 3,
441 nullptr,
442 0,
443 INT_MAX,
444 "Version",
445 "File format version the .blend file was saved with",
446 0,
447 INT_MAX);
448 RNA_def_property_int_funcs(prop, "rna_Main_version_get", nullptr, nullptr);
451
452 for (i = 0; lists[i].name; i++) {
453 prop = RNA_def_property(srna, lists[i].identifier, PROP_COLLECTION, PROP_NONE);
454 RNA_def_property_struct_type(prop, lists[i].type);
456 lists[i].iter_begin,
457 "rna_iterator_listbase_next",
458 "rna_iterator_listbase_end",
459 "rna_iterator_listbase_get",
460 nullptr,
461 nullptr,
462 nullptr,
463 nullptr);
464 RNA_def_property_ui_text(prop, lists[i].name, lists[i].description);
465
466 /* collection functions */
467 CollectionDefFunc *func = lists[i].func;
468 if (func) {
469 func(brna, prop);
470 }
471 }
472
473 RNA_api_main(srna);
474
475# ifdef UNIT_TEST
476
478
479 prop = RNA_def_property(srna, "test", PROP_POINTER, PROP_NONE);
480 RNA_def_property_struct_type(prop, "Test");
481 RNA_def_property_pointer_funcs(prop, "rna_Test_test_get", nullptr, nullptr, nullptr);
482
484
485# endif
486}
487
488#endif
@ G_FILE_AUTOPACK
#define FILE_MAX
#define STRNCPY(dst, src)
Definition BLI_string.h:593
@ PROP_BOOLEAN
Definition RNA_types.hh:65
@ PROP_STRING
Definition RNA_types.hh:68
@ PROP_POINTER
Definition RNA_types.hh:70
@ PROP_COLLECTION
Definition RNA_types.hh:71
@ PROP_THICK_WRAP
Definition RNA_types.hh:312
@ PROP_EDITABLE
Definition RNA_types.hh:207
@ PROP_NONE
Definition RNA_types.hh:136
@ PROP_FILEPATH
Definition RNA_types.hh:139
#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:168
void(BlenderRNA *brna, PropertyRNA *cprop) CollectionDefFunc
Definition rna_main.cc:157
const char * name
Definition rna_main.cc:163
const char * identifier
Definition rna_main.cc:160
const char * description
Definition rna_main.cc:164
const char * type
Definition rna_main.cc:161
CollectionDefFunc * func
Definition rna_main.cc:165
const char * iter_begin
Definition rna_main.cc:162
StructRNA * type
Definition RNA_types.hh:41
void * data
Definition RNA_types.hh:42
PointerRNA * ptr
Definition wm_files.cc:4126