Blender  V3.3
rna_main.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include <stdlib.h>
8 #include <string.h>
9 
10 #include "BLI_path_util.h"
11 #include "BLI_utildefines.h"
12 
13 #include "RNA_access.h"
14 #include "RNA_define.h"
15 
16 #include "rna_internal.h"
17 
18 #ifdef RNA_RUNTIME
19 
20 # include "BKE_global.h"
21 # include "BKE_main.h"
22 # include "BKE_mesh.h"
23 
24 /* all the list begin functions are added manually here, Main is not in SDNA */
25 
26 static bool rna_Main_use_autopack_get(PointerRNA *UNUSED(ptr))
27 {
28  if (G.fileflags & G_FILE_AUTOPACK) {
29  return 1;
30  }
31 
32  return 0;
33 }
34 
35 static void rna_Main_use_autopack_set(PointerRNA *UNUSED(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 
45 static bool rna_Main_is_saved_get(PointerRNA *ptr)
46 {
47  const Main *bmain = (Main *)ptr->data;
48  return (bmain->filepath[0] != '\0');
49 }
50 
51 static 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;
55  wmWindowManager *wm;
56  if ((wm = bmain->wm.first)) {
57  return !wm->file_saved;
58  }
59 
60  return true;
61 }
62 
63 static void rna_Main_filepath_get(PointerRNA *ptr, char *value)
64 {
65  Main *bmain = (Main *)ptr->data;
66  BLI_strncpy(value, bmain->filepath, sizeof(bmain->filepath));
67 }
68 
69 static int rna_Main_filepath_length(PointerRNA *ptr)
70 {
71  Main *bmain = (Main *)ptr->data;
72  return strlen(bmain->filepath);
73 }
74 
75 # if 0
76 static 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, &((Main *)ptr->data)->_listbase_name, NULL); \
88  }
89 
90 RNA_MAIN_LISTBASE_FUNCS_DEF(actions)
91 RNA_MAIN_LISTBASE_FUNCS_DEF(armatures)
92 RNA_MAIN_LISTBASE_FUNCS_DEF(brushes)
93 RNA_MAIN_LISTBASE_FUNCS_DEF(cachefiles)
94 RNA_MAIN_LISTBASE_FUNCS_DEF(cameras)
95 RNA_MAIN_LISTBASE_FUNCS_DEF(collections)
96 RNA_MAIN_LISTBASE_FUNCS_DEF(curves)
97 RNA_MAIN_LISTBASE_FUNCS_DEF(fonts)
98 RNA_MAIN_LISTBASE_FUNCS_DEF(gpencils)
99 RNA_MAIN_LISTBASE_FUNCS_DEF(hair_curves)
100 RNA_MAIN_LISTBASE_FUNCS_DEF(images)
101 RNA_MAIN_LISTBASE_FUNCS_DEF(lattices)
102 RNA_MAIN_LISTBASE_FUNCS_DEF(libraries)
103 RNA_MAIN_LISTBASE_FUNCS_DEF(lightprobes)
104 RNA_MAIN_LISTBASE_FUNCS_DEF(lights)
105 RNA_MAIN_LISTBASE_FUNCS_DEF(linestyles)
106 RNA_MAIN_LISTBASE_FUNCS_DEF(masks)
107 RNA_MAIN_LISTBASE_FUNCS_DEF(materials)
108 RNA_MAIN_LISTBASE_FUNCS_DEF(meshes)
109 RNA_MAIN_LISTBASE_FUNCS_DEF(metaballs)
110 RNA_MAIN_LISTBASE_FUNCS_DEF(movieclips)
111 RNA_MAIN_LISTBASE_FUNCS_DEF(nodetrees)
112 RNA_MAIN_LISTBASE_FUNCS_DEF(objects)
113 RNA_MAIN_LISTBASE_FUNCS_DEF(paintcurves)
114 RNA_MAIN_LISTBASE_FUNCS_DEF(palettes)
115 RNA_MAIN_LISTBASE_FUNCS_DEF(particles)
116 RNA_MAIN_LISTBASE_FUNCS_DEF(pointclouds)
117 RNA_MAIN_LISTBASE_FUNCS_DEF(scenes)
118 RNA_MAIN_LISTBASE_FUNCS_DEF(screens)
119 RNA_MAIN_LISTBASE_FUNCS_DEF(shapekeys)
120 # ifdef WITH_SIMULATION_DATABLOCK
121 RNA_MAIN_LISTBASE_FUNCS_DEF(simulations)
122 # endif
123 RNA_MAIN_LISTBASE_FUNCS_DEF(sounds)
124 RNA_MAIN_LISTBASE_FUNCS_DEF(speakers)
125 RNA_MAIN_LISTBASE_FUNCS_DEF(texts)
126 RNA_MAIN_LISTBASE_FUNCS_DEF(textures)
127 RNA_MAIN_LISTBASE_FUNCS_DEF(volumes)
128 RNA_MAIN_LISTBASE_FUNCS_DEF(wm)
129 RNA_MAIN_LISTBASE_FUNCS_DEF(workspaces)
130 RNA_MAIN_LISTBASE_FUNCS_DEF(worlds)
131 
132 # undef RNA_MAIN_LISTBASE_FUNCS_DEF
133 
134 static 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 
144 static 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 */
157 typedef void(CollectionDefFunc)(struct BlenderRNA *brna, struct PropertyRNA *cprop);
158 
159 typedef struct MainCollectionDef {
160  const char *identifier;
161  const char *type;
162  const char *iter_begin;
163  const char *name;
164  const char *description;
167 
169 {
170  StructRNA *srna;
171  PropertyRNA *prop;
172  CollectionDefFunc *func;
173 
174  /* plural must match idtypes in readblenentry.c */
175  MainCollectionDef lists[] = {
176  {"cameras",
177  "Camera",
178  "rna_Main_cameras_begin",
179  "Cameras",
180  "Camera data-blocks",
182  {"scenes",
183  "Scene",
184  "rna_Main_scenes_begin",
185  "Scenes",
186  "Scene data-blocks",
188  {"objects",
189  "Object",
190  "rna_Main_objects_begin",
191  "Objects",
192  "Object data-blocks",
194  {"materials",
195  "Material",
196  "rna_Main_materials_begin",
197  "Materials",
198  "Material data-blocks",
200  {"node_groups",
201  "NodeTree",
202  "rna_Main_nodetrees_begin",
203  "Node Groups",
204  "Node group data-blocks",
206  {"meshes",
207  "Mesh",
208  "rna_Main_meshes_begin",
209  "Meshes",
210  "Mesh data-blocks",
212  {"lights",
213  "Light",
214  "rna_Main_lights_begin",
215  "Lights",
216  "Light data-blocks",
218  {"libraries",
219  "Library",
220  "rna_Main_libraries_begin",
221  "Libraries",
222  "Library data-blocks",
224  {"screens",
225  "Screen",
226  "rna_Main_screens_begin",
227  "Screens",
228  "Screen data-blocks",
230  {"window_managers",
231  "WindowManager",
232  "rna_Main_wm_begin",
233  "Window Managers",
234  "Window manager data-blocks",
236  {"images",
237  "Image",
238  "rna_Main_images_begin",
239  "Images",
240  "Image data-blocks",
242  {"lattices",
243  "Lattice",
244  "rna_Main_lattices_begin",
245  "Lattices",
246  "Lattice data-blocks",
248  {"curves",
249  "Curve",
250  "rna_Main_curves_begin",
251  "Curves",
252  "Curve data-blocks",
254  {"metaballs",
255  "MetaBall",
256  "rna_Main_metaballs_begin",
257  "Metaballs",
258  "Metaball data-blocks",
260  {"fonts",
261  "VectorFont",
262  "rna_Main_fonts_begin",
263  "Vector Fonts",
264  "Vector font data-blocks",
266  {"textures",
267  "Texture",
268  "rna_Main_textures_begin",
269  "Textures",
270  "Texture data-blocks",
272  {"brushes",
273  "Brush",
274  "rna_Main_brushes_begin",
275  "Brushes",
276  "Brush data-blocks",
278  {"worlds",
279  "World",
280  "rna_Main_worlds_begin",
281  "Worlds",
282  "World data-blocks",
284  {"collections",
285  "Collection",
286  "rna_Main_collections_begin",
287  "Collections",
288  "Collection data-blocks",
290  {"shape_keys",
291  "Key",
292  "rna_Main_shapekeys_begin",
293  "Shape Keys",
294  "Shape Key data-blocks",
295  NULL},
296  {"texts", "Text", "rna_Main_texts_begin", "Texts", "Text data-blocks", RNA_def_main_texts},
297  {"speakers",
298  "Speaker",
299  "rna_Main_speakers_begin",
300  "Speakers",
301  "Speaker data-blocks",
303  {"sounds",
304  "Sound",
305  "rna_Main_sounds_begin",
306  "Sounds",
307  "Sound data-blocks",
309  {"armatures",
310  "Armature",
311  "rna_Main_armatures_begin",
312  "Armatures",
313  "Armature data-blocks",
315  {"actions",
316  "Action",
317  "rna_Main_actions_begin",
318  "Actions",
319  "Action data-blocks",
321  {"particles",
322  "ParticleSettings",
323  "rna_Main_particles_begin",
324  "Particles",
325  "Particle data-blocks",
327  {"palettes",
328  "Palette",
329  "rna_Main_palettes_begin",
330  "Palettes",
331  "Palette data-blocks",
333  {"grease_pencils",
334  "GreasePencil",
335  "rna_Main_gpencils_begin",
336  "Grease Pencil",
337  "Grease Pencil data-blocks",
339  {"movieclips",
340  "MovieClip",
341  "rna_Main_movieclips_begin",
342  "Movie Clips",
343  "Movie Clip data-blocks",
345  {"masks", "Mask", "rna_Main_masks_begin", "Masks", "Masks data-blocks", RNA_def_main_masks},
346  {"linestyles",
347  "FreestyleLineStyle",
348  "rna_Main_linestyles_begin",
349  "Line Styles",
350  "Line Style data-blocks",
352  {"cache_files",
353  "CacheFile",
354  "rna_Main_cachefiles_begin",
355  "Cache Files",
356  "Cache Files data-blocks",
358  {"paint_curves",
359  "PaintCurve",
360  "rna_Main_paintcurves_begin",
361  "Paint Curves",
362  "Paint Curves data-blocks",
364  {"workspaces",
365  "WorkSpace",
366  "rna_Main_workspaces_begin",
367  "Workspaces",
368  "Workspace data-blocks",
370  {"lightprobes",
371  "LightProbe",
372  "rna_Main_lightprobes_begin",
373  "Light Probes",
374  "Light Probe data-blocks",
380  {"hair_curves",
381  "Curves",
382  "rna_Main_hair_curves_begin",
383  "Hair Curves",
384  "Hair curve data-blocks",
386  {"pointclouds",
387  "PointCloud",
388  "rna_Main_pointclouds_begin",
389  "Point Clouds",
390  "Point cloud data-blocks",
392  {"volumes",
393  "Volume",
394  "rna_Main_volumes_begin",
395  "Volumes",
396  "Volume data-blocks",
398 # ifdef WITH_SIMULATION_DATABLOCK
399  {"simulations",
400  "Simulation",
401  "rna_Main_simulations_begin",
402  "Simulations",
403  "Simulation data-blocks",
404  RNA_def_main_simulations},
405 # endif
406  {NULL, NULL, NULL, NULL, NULL, NULL},
407  };
408 
409  int i;
410 
411  srna = RNA_def_struct(brna, "BlendData", NULL);
413  "Blend-File Data",
414  "Main data structure representing a .blend file and all its data-blocks");
415  RNA_def_struct_ui_icon(srna, ICON_BLENDER);
416 
417  prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
420  prop, "rna_Main_filepath_get", "rna_Main_filepath_length", "rna_Main_filepath_set");
422  RNA_def_property_ui_text(prop, "Filename", "Path to the .blend file");
423 
424  prop = RNA_def_property(srna, "is_dirty", PROP_BOOLEAN, PROP_NONE);
426  RNA_def_property_boolean_funcs(prop, "rna_Main_is_dirty_get", NULL);
428  prop, "File Has Unsaved Changes", "Have recent edits been saved to disk");
429 
430  prop = RNA_def_property(srna, "is_saved", PROP_BOOLEAN, PROP_NONE);
432  RNA_def_property_boolean_funcs(prop, "rna_Main_is_saved_get", NULL);
434  prop, "File is Saved", "Has the current session been saved to disk as a .blend file");
435 
436  prop = RNA_def_property(srna, "use_autopack", PROP_BOOLEAN, PROP_NONE);
437  RNA_def_property_boolean_funcs(prop, "rna_Main_use_autopack_get", "rna_Main_use_autopack_set");
439  prop, "Use Auto-Pack", "Automatically pack all external data into .blend file");
440 
441  prop = RNA_def_int_vector(srna,
442  "version",
443  3,
444  NULL,
445  0,
446  INT_MAX,
447  "Version",
448  "File format version the .blend file was saved with",
449  0,
450  INT_MAX);
451  RNA_def_property_int_funcs(prop, "rna_Main_version_get", NULL, NULL);
454 
455  for (i = 0; lists[i].name; i++) {
456  prop = RNA_def_property(srna, lists[i].identifier, PROP_COLLECTION, PROP_NONE);
457  RNA_def_property_struct_type(prop, lists[i].type);
459  lists[i].iter_begin,
460  "rna_iterator_listbase_next",
461  "rna_iterator_listbase_end",
462  "rna_iterator_listbase_get",
463  NULL,
464  NULL,
465  NULL,
466  NULL);
467  RNA_def_property_ui_text(prop, lists[i].name, lists[i].description);
468 
469  /* collection functions */
470  func = lists[i].func;
471  if (func) {
472  func(brna, prop);
473  }
474  }
475 
476  RNA_api_main(srna);
477 
478 # ifdef UNIT_TEST
479 
481 
482  prop = RNA_def_property(srna, "test", PROP_POINTER, PROP_NONE);
483  RNA_def_property_struct_type(prop, "Test");
484  RNA_def_property_pointer_funcs(prop, "rna_Test_test_get", NULL, NULL, NULL);
485 
487 
488 # endif
489 }
490 
491 #endif
@ G_FILE_AUTOPACK
Definition: BKE_global.h:209
#define FILE_MAX
#define STRNCPY(dst, src)
Definition: BLI_string.h:483
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Definition: string.c:64
#define UNUSED(x)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint * textures
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to curves
@ PROP_BOOLEAN
Definition: RNA_types.h:59
@ PROP_STRING
Definition: RNA_types.h:62
@ PROP_POINTER
Definition: RNA_types.h:64
@ PROP_COLLECTION
Definition: RNA_types.h:65
@ PROP_THICK_WRAP
Definition: RNA_types.h:285
@ PROP_EDITABLE
Definition: RNA_types.h:189
@ PROP_NONE
Definition: RNA_types.h:126
@ PROP_FILEPATH
Definition: RNA_types.h:129
return(oflags[bm->toolflag_index].f &oflag) !=0
SyclQueue void void size_t num_bytes void
smooth(Type::VEC4, "color_mul") .smooth(Type gpFillTexture gpSceneDepthTexture materials[GPENCIL_MATERIAL_BUFFER_LEN]
Definition: gpencil_info.hh:29
#define G(x, y, z)
return ret
void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
Definition: rna_define.c:3285
void RNA_define_verify_sdna(bool verify)
Definition: rna_define.c:737
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
Definition: rna_define.c:1645
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)
Definition: rna_define.c:3420
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
Definition: rna_define.c:1237
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
Definition: rna_define.c:2944
void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength)
Definition: rna_define.c:1920
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
Definition: rna_define.c:1772
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1257
PropertyRNA * RNA_def_int_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, const int *default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3623
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1495
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
Definition: rna_define.c:3385
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
Definition: rna_define.c:1028
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
Definition: rna_define.c:3028
void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
Definition: rna_define.c:1245
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1490
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)
Definition: rna_main_api.c:878
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_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_api_main(struct StructRNA *srna)
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_gpencil(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_actions(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_palettes(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_particles(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)
Definition: rna_main_api.c:922
void RNA_def_main_collections(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_main_materials(BlenderRNA *brna, PropertyRNA *cprop)
Definition: rna_main_api.c:999
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)
Definition: rna_main_api.c:955
void RNA_def_main(BlenderRNA *brna)
Definition: rna_main.c:168
void() CollectionDefFunc(struct BlenderRNA *brna, struct PropertyRNA *cprop)
Definition: rna_main.c:157
struct MainCollectionDef MainCollectionDef
void * first
Definition: DNA_listBase.h:31
const char * name
Definition: rna_main.c:163
const char * identifier
Definition: rna_main.c:160
const char * description
Definition: rna_main.c:164
const char * type
Definition: rna_main.c:161
CollectionDefFunc * func
Definition: rna_main.c:165
const char * iter_begin
Definition: rna_main.c:162
Definition: BKE_main.h:121
ListBase wm
Definition: BKE_main.h:197
short subversionfile
Definition: BKE_main.h:125
char filepath[1024]
Definition: BKE_main.h:124
short versionfile
Definition: BKE_main.h:125
void * data
Definition: RNA_types.h:38
PointerRNA * ptr
Definition: wm_files.c:3480