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