Merge branch 'master' into blender2.8
[blender.git] / source / blender / makesrna / intern / rna_workspace.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * ***** END GPL LICENSE BLOCK *****
19  */
20
21 /** \file blender/makesrna/intern/rna_workspace.c
22  *  \ingroup RNA
23  */
24
25 #include "RNA_define.h"
26 #include "RNA_enum_types.h"
27 #include "RNA_types.h"
28
29 #include "BKE_workspace.h"
30
31 #include "WM_api.h"
32 #include "WM_types.h"
33
34 #include "rna_internal.h"
35
36
37 #ifdef RNA_RUNTIME
38
39 #include "BKE_global.h"
40
41 #include "BLI_listbase.h"
42
43 #include "DNA_object_types.h"
44 #include "DNA_screen_types.h"
45 #include "DNA_workspace_types.h"
46
47 #include "RNA_access.h"
48
49
50 void rna_workspace_screens_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
51 {
52         WorkSpace *workspace = ptr->id.data;
53         rna_iterator_listbase_begin(iter, BKE_workspace_layouts_get(workspace), NULL);
54 }
55
56 static PointerRNA rna_workspace_screens_item_get(CollectionPropertyIterator *iter)
57 {
58         WorkSpaceLayout *layout = rna_iterator_listbase_get(iter);
59         bScreen *screen = BKE_workspace_layout_screen_get(layout);
60
61         return rna_pointer_inherit_refine(&iter->parent, &RNA_Screen, screen);
62 }
63
64 #ifdef USE_WORKSPACE_MODE
65
66 static int rna_workspace_object_mode_get(PointerRNA *ptr)
67 {
68         WorkSpace *workspace = ptr->data;
69         return (int)BKE_workspace_object_mode_get(workspace);
70 }
71
72 static void rna_workspace_object_mode_set(PointerRNA *ptr, int value)
73 {
74         WorkSpace *workspace = ptr->data;
75         BKE_workspace_object_mode_set(workspace, value);
76 }
77
78 #endif /* USE_WORKSPACE_MODE */
79
80 void rna_workspace_transform_orientations_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
81 {
82         WorkSpace *workspace = ptr->id.data;
83         rna_iterator_listbase_begin(iter, BKE_workspace_transform_orientations_get(workspace), NULL);
84 }
85
86 static PointerRNA rna_workspace_transform_orientations_item_get(CollectionPropertyIterator *iter)
87 {
88         TransformOrientation *transform_orientation = rna_iterator_listbase_get(iter);
89         return rna_pointer_inherit_refine(&iter->parent, &RNA_TransformOrientation, transform_orientation);
90 }
91
92 static PointerRNA rna_workspace_render_layer_get(PointerRNA *ptr)
93 {
94         WorkSpace *workspace = ptr->data;
95         SceneLayer *render_layer = BKE_workspace_render_layer_get(workspace);
96
97         /* XXX hmrf... lookup in getter... but how could we avoid it? */
98         for (Scene *scene = G.main->scene.first; scene; scene = scene->id.next) {
99                 if (BLI_findindex(&scene->render_layers, render_layer) != -1) {
100                         PointerRNA scene_ptr;
101
102                         RNA_id_pointer_create(&scene->id, &scene_ptr);
103                         return rna_pointer_inherit_refine(&scene_ptr, &RNA_SceneLayer, render_layer);
104                 }
105         }
106
107         return PointerRNA_NULL;
108 }
109
110 static void rna_workspace_render_layer_set(PointerRNA *ptr, PointerRNA value)
111 {
112         WorkSpace *workspace = ptr->data;
113         BKE_workspace_render_layer_set(workspace, value.data);
114 }
115
116 #else /* RNA_RUNTIME */
117
118 static void rna_def_workspace(BlenderRNA *brna)
119 {
120         StructRNA *srna;
121         PropertyRNA *prop;
122
123         srna = RNA_def_struct(brna, "WorkSpace", "ID");
124         RNA_def_struct_sdna(srna, "WorkSpace");
125         RNA_def_struct_ui_text(srna, "Workspace", "Workspace data-block, defining the working environment for the user");
126         /* TODO: real icon, just to show something */
127         RNA_def_struct_ui_icon(srna, ICON_RENDER_RESULT);
128
129         prop = RNA_def_property(srna, "screens", PROP_COLLECTION, PROP_NONE);
130         RNA_def_property_collection_sdna(prop, NULL, "layouts", NULL);
131         RNA_def_property_struct_type(prop, "Screen");
132         RNA_def_property_collection_funcs(prop, "rna_workspace_screens_begin", NULL, NULL,
133                                           "rna_workspace_screens_item_get", NULL, NULL, NULL, NULL);
134         RNA_def_property_ui_text(prop, "Screens", "Screen layouts of a workspace");
135
136 #ifdef USE_WORKSPACE_MODE
137         prop = RNA_def_property(srna, "object_mode", PROP_ENUM, PROP_NONE);
138         RNA_def_property_enum_items(prop, rna_enum_object_mode_items);
139         RNA_def_property_enum_funcs(prop, "rna_workspace_object_mode_get", "rna_workspace_object_mode_set", NULL);
140         RNA_def_property_ui_text(prop, "Mode", "Object interaction mode");
141 #endif
142
143         prop = RNA_def_property(srna, "orientations", PROP_COLLECTION, PROP_NONE);
144         RNA_def_property_collection_sdna(prop, NULL, "transform_orientations", NULL);
145         RNA_def_property_struct_type(prop, "TransformOrientation");
146         RNA_def_property_collection_funcs(prop, "rna_workspace_transform_orientations_begin", NULL, NULL,
147                                           "rna_workspace_transform_orientations_item_get", NULL, NULL, NULL, NULL);
148         RNA_def_property_ui_text(prop, "Transform Orientations", "");
149
150         prop = RNA_def_property(srna, "render_layer", PROP_POINTER, PROP_NONE);
151         RNA_def_property_struct_type(prop, "SceneLayer");
152         RNA_def_property_pointer_funcs(prop, "rna_workspace_render_layer_get", "rna_workspace_render_layer_set",
153                                        NULL, NULL);
154         RNA_def_property_ui_text(prop, "Active Render Layer", "The active render layer used in this workspace");
155         RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_NULL);
156         RNA_def_property_update(prop, NC_SCREEN | ND_LAYER, NULL);
157 }
158
159 static void rna_def_transform_orientation(BlenderRNA *brna)
160 {
161         StructRNA *srna;
162         PropertyRNA *prop;
163
164         srna = RNA_def_struct(brna, "TransformOrientation", NULL);
165
166         prop = RNA_def_property(srna, "matrix", PROP_FLOAT, PROP_MATRIX);
167         RNA_def_property_float_sdna(prop, NULL, "mat");
168         RNA_def_property_multi_array(prop, 2, rna_matrix_dimsize_3x3);
169         RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
170
171         prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
172         RNA_def_struct_name_property(srna, prop);
173         RNA_def_property_ui_text(prop, "Name", "Name of the custom transform orientation");
174         RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
175 }
176
177 void RNA_def_workspace(BlenderRNA *brna)
178 {
179         rna_def_workspace(brna);
180         rna_def_transform_orientation(brna);
181 }
182
183 #endif /* RNA_RUNTIME */