LineArt: Prevent depsgraph warning when camera is NULL.
[blender.git] / source / blender / makesrna / intern / rna_main.c
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
17 /** \file
18  * \ingroup RNA
19  */
20
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_SIMULATION_DATABLOCK
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;
182   CollectionDefFunc *func;
183 } MainCollectionDef;
184
185 void RNA_def_main(BlenderRNA *brna)
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",
198        RNA_def_main_cameras},
199       {"scenes",
200        "Scene",
201        "rna_Main_scenes_begin",
202        "Scenes",
203        "Scene data-blocks",
204        RNA_def_main_scenes},
205       {"objects",
206        "Object",
207        "rna_Main_objects_begin",
208        "Objects",
209        "Object data-blocks",
210        RNA_def_main_objects},
211       {"materials",
212        "Material",
213        "rna_Main_materials_begin",
214        "Materials",
215        "Material data-blocks",
216        RNA_def_main_materials},
217       {"node_groups",
218        "NodeTree",
219        "rna_Main_nodetrees_begin",
220        "Node Groups",
221        "Node group data-blocks",
222        RNA_def_main_node_groups},
223       {"meshes",
224        "Mesh",
225        "rna_Main_meshes_begin",
226        "Meshes",
227        "Mesh data-blocks",
228        RNA_def_main_meshes},
229       {"lights",
230        "Light",
231        "rna_Main_lights_begin",
232        "Lights",
233        "Light data-blocks",
234        RNA_def_main_lights},
235       {"libraries",
236        "Library",
237        "rna_Main_libraries_begin",
238        "Libraries",
239        "Library data-blocks",
240        RNA_def_main_libraries},
241       {"screens",
242        "Screen",
243        "rna_Main_screens_begin",
244        "Screens",
245        "Screen data-blocks",
246        RNA_def_main_screens},
247       {"window_managers",
248        "WindowManager",
249        "rna_Main_wm_begin",
250        "Window Managers",
251        "Window manager data-blocks",
252        RNA_def_main_window_managers},
253       {"images",
254        "Image",
255        "rna_Main_images_begin",
256        "Images",
257        "Image data-blocks",
258        RNA_def_main_images},
259       {"lattices",
260        "Lattice",
261        "rna_Main_lattices_begin",
262        "Lattices",
263        "Lattice data-blocks",
264        RNA_def_main_lattices},
265       {"curves",
266        "Curve",
267        "rna_Main_curves_begin",
268        "Curves",
269        "Curve data-blocks",
270        RNA_def_main_curves},
271       {"metaballs",
272        "MetaBall",
273        "rna_Main_metaballs_begin",
274        "Metaballs",
275        "Metaball data-blocks",
276        RNA_def_main_metaballs},
277       {"fonts",
278        "VectorFont",
279        "rna_Main_fonts_begin",
280        "Vector Fonts",
281        "Vector font data-blocks",
282        RNA_def_main_fonts},
283       {"textures",
284        "Texture",
285        "rna_Main_textures_begin",
286        "Textures",
287        "Texture data-blocks",
288        RNA_def_main_textures},
289       {"brushes",
290        "Brush",
291        "rna_Main_brushes_begin",
292        "Brushes",
293        "Brush data-blocks",
294        RNA_def_main_brushes},
295       {"worlds",
296        "World",
297        "rna_Main_worlds_begin",
298        "Worlds",
299        "World data-blocks",
300        RNA_def_main_worlds},
301       {"collections",
302        "Collection",
303        "rna_Main_collections_begin",
304        "Collections",
305        "Collection data-blocks",
306        RNA_def_main_collections},
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",
319        RNA_def_main_speakers},
320       {"sounds",
321        "Sound",
322        "rna_Main_sounds_begin",
323        "Sounds",
324        "Sound data-blocks",
325        RNA_def_main_sounds},
326       {"armatures",
327        "Armature",
328        "rna_Main_armatures_begin",
329        "Armatures",
330        "Armature data-blocks",
331        RNA_def_main_armatures},
332       {"actions",
333        "Action",
334        "rna_Main_actions_begin",
335        "Actions",
336        "Action data-blocks",
337        RNA_def_main_actions},
338       {"particles",
339        "ParticleSettings",
340        "rna_Main_particles_begin",
341        "Particles",
342        "Particle data-blocks",
343        RNA_def_main_particles},
344       {"palettes",
345        "Palette",
346        "rna_Main_palettes_begin",
347        "Palettes",
348        "Palette data-blocks",
349        RNA_def_main_palettes},
350       {"grease_pencils",
351        "GreasePencil",
352        "rna_Main_gpencils_begin",
353        "Grease Pencil",
354        "Grease Pencil data-blocks",
355        RNA_def_main_gpencil},
356       {"movieclips",
357        "MovieClip",
358        "rna_Main_movieclips_begin",
359        "Movie Clips",
360        "Movie Clip data-blocks",
361        RNA_def_main_movieclips},
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",
368        RNA_def_main_linestyles},
369       {"cache_files",
370        "CacheFile",
371        "rna_Main_cachefiles_begin",
372        "Cache Files",
373        "Cache Files data-blocks",
374        RNA_def_main_cachefiles},
375       {"paint_curves",
376        "PaintCurve",
377        "rna_Main_paintcurves_begin",
378        "Paint Curves",
379        "Paint Curves data-blocks",
380        RNA_def_main_paintcurves},
381       {"workspaces",
382        "WorkSpace",
383        "rna_Main_workspaces_begin",
384        "Workspaces",
385        "Workspace data-blocks",
386        RNA_def_main_workspaces},
387       {"lightprobes",
388        "LightProbe",
389        "rna_Main_lightprobes_begin",
390        "Light Probes",
391        "Light Probe data-blocks",
392        RNA_def_main_lightprobes},
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",
409        RNA_def_main_volumes},
410 #  ifdef WITH_SIMULATION_DATABLOCK
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);
424   RNA_def_struct_ui_text(srna,
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);
430   RNA_def_property_string_maxlength(prop, FILE_MAX);
431   RNA_def_property_string_funcs(
432       prop, "rna_Main_filepath_get", "rna_Main_filepath_length", "rna_Main_filepath_set");
433   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
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);
437   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
438   RNA_def_property_boolean_funcs(prop, "rna_Main_is_dirty_get", NULL);
439   RNA_def_property_ui_text(
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);
443   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
444   RNA_def_property_boolean_funcs(prop, "rna_Main_is_saved_get", NULL);
445   RNA_def_property_ui_text(
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");
450   RNA_def_property_ui_text(
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);
464   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
465   RNA_def_property_flag(prop, PROP_THICK_WRAP);
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);
470     RNA_def_property_collection_funcs(prop,
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
492   RNA_define_verify_sdna(0);
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
498   RNA_define_verify_sdna(1);
499
500 #  endif
501 }
502
503 #endif