Blender  V2.93
rna_workspace.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 "RNA_define.h"
22 #include "RNA_enum_types.h"
23 #include "RNA_types.h"
24 
25 #include "BKE_workspace.h"
26 
27 #include "ED_render.h"
28 
29 #include "RE_engine.h"
30 
31 #include "WM_api.h"
32 #include "WM_types.h"
33 
34 #include "rna_internal.h"
35 
36 #include "DNA_workspace_types.h"
37 
38 #ifdef RNA_RUNTIME
39 
40 # include "BLI_listbase.h"
41 
42 # include "BKE_global.h"
43 
44 # include "DNA_object_types.h"
45 # include "DNA_screen_types.h"
46 # include "DNA_space_types.h"
47 
48 # include "RNA_access.h"
49 
50 # include "WM_toolsystem.h"
51 
52 static void rna_window_update_all(Main *UNUSED(bmain),
53  Scene *UNUSED(scene),
55 {
57 }
58 
59 void rna_workspace_screens_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
60 {
61  WorkSpace *workspace = (WorkSpace *)ptr->owner_id;
62  rna_iterator_listbase_begin(iter, &workspace->layouts, NULL);
63 }
64 
65 static PointerRNA rna_workspace_screens_item_get(CollectionPropertyIterator *iter)
66 {
68  bScreen *screen = BKE_workspace_layout_screen_get(layout);
69 
70  return rna_pointer_inherit_refine(&iter->parent, &RNA_Screen, screen);
71 }
72 
73 /* workspace.owner_ids */
74 
75 static wmOwnerID *rna_WorkSpace_owner_ids_new(WorkSpace *workspace, const char *name)
76 {
77  wmOwnerID *owner_id = MEM_callocN(sizeof(*owner_id), __func__);
78  BLI_addtail(&workspace->owner_ids, owner_id);
79  BLI_strncpy(owner_id->name, name, sizeof(owner_id->name));
81  return owner_id;
82 }
83 
84 static void rna_WorkSpace_owner_ids_remove(WorkSpace *workspace,
85  ReportList *reports,
86  PointerRNA *wstag_ptr)
87 {
88  wmOwnerID *owner_id = wstag_ptr->data;
89  if (BLI_remlink_safe(&workspace->owner_ids, owner_id) == false) {
90  BKE_reportf(reports,
91  RPT_ERROR,
92  "wmOwnerID '%s' not in workspace '%s'",
93  owner_id->name,
94  workspace->id.name + 2);
95  return;
96  }
97 
98  MEM_freeN(owner_id);
99  RNA_POINTER_INVALIDATE(wstag_ptr);
100 
102 }
103 
104 static void rna_WorkSpace_owner_ids_clear(WorkSpace *workspace)
105 {
106  BLI_freelistN(&workspace->owner_ids);
108 }
109 
110 static bToolRef *rna_WorkSpace_tools_from_tkey(WorkSpace *workspace,
111  const bToolKey *tkey,
112  bool create)
113 {
114  if (create) {
115  bToolRef *tref;
116  WM_toolsystem_ref_ensure(workspace, tkey, &tref);
117  return tref;
118  }
119  return WM_toolsystem_ref_find(workspace, tkey);
120 }
121 
122 static bToolRef *rna_WorkSpace_tools_from_space_view3d_mode(WorkSpace *workspace,
123  int mode,
124  bool create)
125 {
126  return rna_WorkSpace_tools_from_tkey(workspace,
127  &(bToolKey){
128  .space_type = SPACE_VIEW3D,
129  .mode = mode,
130  },
131  create);
132 }
133 
134 static bToolRef *rna_WorkSpace_tools_from_space_image_mode(WorkSpace *workspace,
135  int mode,
136  bool create)
137 {
138  return rna_WorkSpace_tools_from_tkey(workspace,
139  &(bToolKey){
140  .space_type = SPACE_IMAGE,
141  .mode = mode,
142  },
143  create);
144 }
145 
146 static bToolRef *rna_WorkSpace_tools_from_space_node(WorkSpace *workspace, bool create)
147 {
148  return rna_WorkSpace_tools_from_tkey(workspace,
149  &(bToolKey){
150  .space_type = SPACE_NODE,
151  .mode = 0,
152  },
153  create);
154 }
155 static bToolRef *rna_WorkSpace_tools_from_space_sequencer(WorkSpace *workspace,
156  int mode,
157  bool create)
158 {
159  return rna_WorkSpace_tools_from_tkey(workspace,
160  &(bToolKey){
161  .space_type = SPACE_SEQ,
162  .mode = mode,
163  },
164  create);
165 }
166 const EnumPropertyItem *rna_WorkSpace_tools_mode_itemf(bContext *UNUSED(C),
167  PointerRNA *ptr,
168  PropertyRNA *UNUSED(prop),
169  bool *UNUSED(r_free))
170 {
171  bToolRef *tref = ptr->data;
172  switch (tref->space_type) {
173  case SPACE_VIEW3D:
175  case SPACE_IMAGE:
177  case SPACE_SEQ:
179  }
180  return DummyRNA_DEFAULT_items;
181 }
182 
183 static int rna_WorkSpaceTool_index_get(PointerRNA *ptr)
184 {
185  bToolRef *tref = ptr->data;
186  return (tref->runtime) ? tref->runtime->index : 0;
187 }
188 
189 static int rna_WorkSpaceTool_has_datablock_get(PointerRNA *ptr)
190 {
191  bToolRef *tref = ptr->data;
192  return (tref->runtime) ? (tref->runtime->data_block[0] != '\0') : false;
193 }
194 
195 static void rna_WorkSpaceTool_widget_get(PointerRNA *ptr, char *value)
196 {
197  bToolRef *tref = ptr->data;
198  strcpy(value, tref->runtime ? tref->runtime->gizmo_group : "");
199 }
200 
201 static int rna_WorkSpaceTool_widget_length(PointerRNA *ptr)
202 {
203  bToolRef *tref = ptr->data;
204  return tref->runtime ? strlen(tref->runtime->gizmo_group) : 0;
205 }
206 
207 #else /* RNA_RUNTIME */
208 
210 {
211  StructRNA *srna;
212  PropertyRNA *prop;
213 
214  srna = RNA_def_struct(brna, "wmOwnerID", NULL);
215  RNA_def_struct_sdna(srna, "wmOwnerID");
217  RNA_def_struct_ui_text(srna, "Work Space UI Tag", "");
218 
219  prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
220  RNA_def_property_ui_text(prop, "Name", "");
221  RNA_def_struct_name_property(srna, prop);
222 }
223 
225 {
226  StructRNA *srna;
227 
228  FunctionRNA *func;
229  PropertyRNA *parm;
230 
231  RNA_def_property_srna(cprop, "wmOwnerIDs");
232  srna = RNA_def_struct(brna, "wmOwnerIDs", NULL);
233  RNA_def_struct_sdna(srna, "WorkSpace");
234  RNA_def_struct_ui_text(srna, "WorkSpace UI Tags", "");
235 
236  /* add owner_id */
237  func = RNA_def_function(srna, "new", "rna_WorkSpace_owner_ids_new");
238  RNA_def_function_ui_description(func, "Add ui tag");
239  parm = RNA_def_string(func, "name", "Name", 0, "", "New name for the tag");
241  /* return type */
242  parm = RNA_def_pointer(func, "owner_id", "wmOwnerID", "", "");
243  RNA_def_function_return(func, parm);
244 
245  /* remove owner_id */
246  func = RNA_def_function(srna, "remove", "rna_WorkSpace_owner_ids_remove");
248  RNA_def_function_ui_description(func, "Remove ui tag");
249  /* owner_id to remove */
250  parm = RNA_def_pointer(func, "owner_id", "wmOwnerID", "", "Tag to remove");
253 
254  /* clear all modifiers */
255  func = RNA_def_function(srna, "clear", "rna_WorkSpace_owner_ids_clear");
256  RNA_def_function_ui_description(func, "Remove all tags");
257 }
258 
260 {
261  StructRNA *srna;
262  PropertyRNA *prop;
263 
264  srna = RNA_def_struct(brna, "WorkSpaceTool", NULL);
265  RNA_def_struct_sdna(srna, "bToolRef");
267  RNA_def_struct_ui_text(srna, "Work Space Tool", "");
268 
269  prop = RNA_def_property(srna, "idname", PROP_STRING, PROP_NONE);
270  RNA_def_property_ui_text(prop, "Identifier", "");
271  RNA_def_struct_name_property(srna, prop);
272 
273  prop = RNA_def_property(srna, "idname_fallback", PROP_STRING, PROP_NONE);
274  RNA_def_property_ui_text(prop, "Identifier Fallback", "");
275 
276  prop = RNA_def_property(srna, "index", PROP_INT, PROP_NONE);
278  RNA_def_property_ui_text(prop, "Index", "");
279  RNA_def_property_int_funcs(prop, "rna_WorkSpaceTool_index_get", NULL, NULL);
280 
281  prop = RNA_def_property(srna, "space_type", PROP_ENUM, PROP_NONE);
282  RNA_def_property_enum_sdna(prop, NULL, "space_type");
285  RNA_def_property_ui_text(prop, "Space Type", "");
286 
287  prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
288  RNA_def_property_enum_sdna(prop, NULL, "mode");
290  RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_WorkSpace_tools_mode_itemf");
291  RNA_def_property_ui_text(prop, "Tool Mode", "");
293 
295  prop = RNA_def_property(srna, "has_datablock", PROP_BOOLEAN, PROP_NONE);
297  RNA_def_property_ui_text(prop, "Has Data-Block", "");
298  RNA_def_property_boolean_funcs(prop, "rna_WorkSpaceTool_has_datablock_get", NULL);
300 
301  prop = RNA_def_property(srna, "widget", PROP_STRING, PROP_NONE);
303  RNA_def_property_ui_text(prop, "Widget", "");
305  prop, "rna_WorkSpaceTool_widget_get", "rna_WorkSpaceTool_widget_length", NULL);
306 
308 }
309 
311 {
312  StructRNA *srna;
313 
314  FunctionRNA *func;
315  PropertyRNA *parm;
316 
317  RNA_def_property_srna(cprop, "wmTools");
318  srna = RNA_def_struct(brna, "wmTools", NULL);
319  RNA_def_struct_sdna(srna, "WorkSpace");
320  RNA_def_struct_ui_text(srna, "WorkSpace UI Tags", "");
321 
322  /* add owner_id */
323  func = RNA_def_function(
324  srna, "from_space_view3d_mode", "rna_WorkSpace_tools_from_space_view3d_mode");
326  parm = RNA_def_enum(func, "mode", rna_enum_context_mode_items, 0, "", "");
328  RNA_def_boolean(func, "create", false, "Create", "");
329  /* return type */
330  parm = RNA_def_pointer(func, "result", "WorkSpaceTool", "", "");
331  RNA_def_function_return(func, parm);
332 
333  func = RNA_def_function(
334  srna, "from_space_image_mode", "rna_WorkSpace_tools_from_space_image_mode");
336  parm = RNA_def_enum(func, "mode", rna_enum_space_image_mode_all_items, 0, "", "");
338  RNA_def_boolean(func, "create", false, "Create", "");
339  /* return type */
340  parm = RNA_def_pointer(func, "result", "WorkSpaceTool", "", "");
341  RNA_def_function_return(func, parm);
342 
343  func = RNA_def_function(srna, "from_space_node", "rna_WorkSpace_tools_from_space_node");
345  RNA_def_boolean(func, "create", false, "Create", "");
346  /* return type */
347  parm = RNA_def_pointer(func, "result", "WorkSpaceTool", "", "");
348  RNA_def_function_return(func, parm);
349 
350  func = RNA_def_function(
351  srna, "from_space_sequencer", "rna_WorkSpace_tools_from_space_sequencer");
353  parm = RNA_def_enum(func, "mode", rna_enum_space_sequencer_view_type_items, 0, "", "");
355  RNA_def_boolean(func, "create", false, "Create", "");
356  /* return type */
357  parm = RNA_def_pointer(func, "result", "WorkSpaceTool", "", "");
358  RNA_def_function_return(func, parm);
359 }
360 
361 static void rna_def_workspace(BlenderRNA *brna)
362 {
363  StructRNA *srna;
364  PropertyRNA *prop;
365 
366  srna = RNA_def_struct(brna, "WorkSpace", "ID");
367  RNA_def_struct_sdna(srna, "WorkSpace");
369  srna, "Workspace", "Workspace data-block, defining the working environment for the user");
370  /* TODO: real icon, just to show something */
371  RNA_def_struct_ui_icon(srna, ICON_WORKSPACE);
372 
373  prop = RNA_def_property(srna, "screens", PROP_COLLECTION, PROP_NONE);
374  RNA_def_property_collection_sdna(prop, NULL, "layouts", NULL);
375  RNA_def_property_struct_type(prop, "Screen");
377  "rna_workspace_screens_begin",
378  NULL,
379  NULL,
380  "rna_workspace_screens_item_get",
381  NULL,
382  NULL,
383  NULL,
384  NULL);
385  RNA_def_property_ui_text(prop, "Screens", "Screen layouts of a workspace");
386 
387  prop = RNA_def_property(srna, "owner_ids", PROP_COLLECTION, PROP_NONE);
388  RNA_def_property_struct_type(prop, "wmOwnerID");
389  RNA_def_property_ui_text(prop, "UI Tags", "");
390  rna_def_workspace_owner_ids(brna, prop);
391 
392  prop = RNA_def_property(srna, "tools", PROP_COLLECTION, PROP_NONE);
393  RNA_def_property_collection_sdna(prop, NULL, "tools", NULL);
394  RNA_def_property_struct_type(prop, "WorkSpaceTool");
395  RNA_def_property_ui_text(prop, "Tools", "");
396  rna_def_workspace_tools(brna, prop);
397 
398  prop = RNA_def_property(srna, "object_mode", PROP_ENUM, PROP_NONE);
401  prop, "Object Mode", "Switch to this object mode when activating the workspace");
402 
403  /* Flags */
404  prop = RNA_def_property(srna, "use_filter_by_owner", PROP_BOOLEAN, PROP_NONE);
407  RNA_def_property_ui_text(prop, "Use UI Tags", "Filter the UI by tags");
408  RNA_def_property_update(prop, 0, "rna_window_update_all");
409 
410  RNA_api_workspace(srna);
411 }
412 
414 {
417 
418  rna_def_workspace(brna);
419 }
420 
421 #endif /* RNA_RUNTIME */
void BKE_reportf(ReportList *reports, ReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
struct bScreen * BKE_workspace_layout_screen_get(const struct WorkSpaceLayout *layout) GETTER_ATTRS
bool BLI_remlink_safe(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:159
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:547
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
Definition: string.c:108
#define UNUSED(x)
Object is a sort of wrapper for general info.
@ SPACE_NODE
@ SPACE_SEQ
@ SPACE_IMAGE
@ SPACE_VIEW3D
@ WORKSPACE_USE_FILTER_BY_ORIGIN
#define RNA_POINTER_INVALIDATE(ptr)
Definition: RNA_access.h:1425
StructRNA RNA_Screen
@ PARM_RNAPTR
Definition: RNA_types.h:339
@ PARM_REQUIRED
Definition: RNA_types.h:337
@ FUNC_USE_REPORTS
Definition: RNA_types.h:578
@ STRUCT_UNDO
Definition: RNA_types.h:623
@ PROP_BOOLEAN
Definition: RNA_types.h:73
@ PROP_ENUM
Definition: RNA_types.h:77
@ PROP_INT
Definition: RNA_types.h:74
@ PROP_STRING
Definition: RNA_types.h:76
@ PROP_COLLECTION
Definition: RNA_types.h:79
@ PROP_THICK_WRAP
Definition: RNA_types.h:270
@ PROP_ANIMATABLE
Definition: RNA_types.h:188
@ PROP_EDITABLE
Definition: RNA_types.h:175
@ PROP_NEVER_NULL
Definition: RNA_types.h:225
@ PROP_NONE
Definition: RNA_types.h:113
#define C
Definition: RandGen.cpp:39
#define NC_WINDOW
Definition: WM_types.h:277
#define ND_MODIFIER
Definition: WM_types.h:363
#define NA_REMOVED
Definition: WM_types.h:465
#define NC_OBJECT
Definition: WM_types.h:280
Scene scene
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
void rna_iterator_listbase_begin(CollectionPropertyIterator *iter, ListBase *lb, IteratorSkipFunc skip)
Definition: rna_access.c:4823
PointerRNA rna_pointer_inherit_refine(PointerRNA *ptr, StructRNA *type, void *data)
Definition: rna_access.c:196
void * rna_iterator_listbase_get(CollectionPropertyIterator *iter)
Definition: rna_access.c:4855
const EnumPropertyItem rna_enum_context_mode_items[]
Definition: rna_context.c:35
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3481
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
Definition: rna_define.c:4159
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t bit)
Definition: rna_define.c:2257
void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
Definition: rna_define.c:1555
void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
Definition: rna_define.c:3312
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
Definition: rna_define.c:4302
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
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
Definition: rna_define.c:4262
void RNA_def_property_srna(PropertyRNA *prop, const char *type)
Definition: rna_define.c:3462
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_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
Definition: rna_define.c:1892
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
Definition: rna_define.c:1067
void RNA_def_struct_clear_flag(StructRNA *srna, int flag)
Definition: rna_define.c:1157
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
Definition: rna_define.c:1792
void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
Definition: rna_define.c:2791
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
Definition: rna_define.c:4337
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
Definition: rna_define.c:2927
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
Definition: rna_define.c:3251
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1279
void RNA_def_struct_name_property(struct StructRNA *srna, struct PropertyRNA *prop)
Definition: rna_define.c:1122
void RNA_def_function_flag(FunctionRNA *func, int flag)
Definition: rna_define.c:4332
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1517
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
Definition: rna_define.c:1047
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2623
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
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3675
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3771
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
Definition: rna_define.c:1547
void RNA_api_workspace(struct StructRNA *srna)
void RNA_api_workspace_tool(struct StructRNA *srna)
const EnumPropertyItem rna_enum_workspace_object_mode_items[]
Definition: rna_object.c:103
const EnumPropertyItem DummyRNA_DEFAULT_items[]
Definition: rna_rna.c:45
const EnumPropertyItem rna_enum_space_type_items[]
Definition: rna_space.c:72
const EnumPropertyItem rna_enum_space_sequencer_view_type_items[]
Definition: rna_space.c:177
const EnumPropertyItem rna_enum_space_image_mode_all_items[]
Definition: rna_space.c:279
static void rna_def_workspace_tool(BlenderRNA *brna)
static void rna_def_workspace_owner_ids(BlenderRNA *brna, PropertyRNA *cprop)
static void rna_def_workspace_tools(BlenderRNA *brna, PropertyRNA *cprop)
static void rna_def_workspace_owner(BlenderRNA *brna)
void RNA_def_workspace(BlenderRNA *brna)
static void rna_def_workspace(BlenderRNA *brna)
char name[66]
Definition: DNA_ID.h:283
Definition: BKE_main.h:116
void * data
Definition: RNA_types.h:52
struct ID * owner_id
Definition: RNA_types.h:50
Wrapper for bScreen.
ListBase owner_ids
bToolRef_Runtime * runtime
void WM_main_add_notifier(unsigned int type, void *reference)
PointerRNA * ptr
Definition: wm_files.c:3157
bToolRef * WM_toolsystem_ref_find(WorkSpace *workspace, const bToolKey *tkey)
Definition: wm_toolsystem.c:97
bool WM_toolsystem_ref_ensure(struct WorkSpace *workspace, const bToolKey *tkey, bToolRef **r_tref)