Blender V5.0
rna_workspace_api.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdlib>
10#include <cstring>
11#include <ctime>
12
13#include "RNA_define.hh"
14
16#include "DNA_workspace_types.h"
17
18#include "RNA_enum_types.hh" /* own include */
19
20#include "rna_internal.hh" /* own include */
21
22#ifdef RNA_RUNTIME
23
24# include "BLI_string.h"
25
26# include "BKE_paint.hh"
27# include "BKE_report.hh"
28
29# include "ED_screen.hh"
30
31# include "WM_api.hh"
32# include "WM_toolsystem.hh"
33
34static void rna_WorkSpaceTool_setup(ID *id,
35 bToolRef *tref,
36 bContext *C,
37 const char *idname,
38 /* Args for: 'bToolRef_Runtime'. */
39 int cursor,
40 const char *keymap,
41 const char *gizmo_group,
42 int brush_type,
43 const char *data_block,
44 const char *op_idname,
45 int index,
46 int options,
47 const char *idname_fallback,
48 const char *keymap_fallback)
49{
50 bToolRef_Runtime tref_rt = {0};
51
52 tref_rt.cursor = cursor;
53 STRNCPY(tref_rt.keymap, keymap);
54 STRNCPY(tref_rt.gizmo_group, gizmo_group);
55 STRNCPY(tref_rt.data_block, data_block);
56 STRNCPY(tref_rt.op, op_idname);
57 tref_rt.brush_type = brush_type;
58 tref_rt.index = index;
59 tref_rt.flag = options;
60
61 /* While it's logical to assign both these values from setup,
62 * it's useful to stored this in DNA for re-use, exceptional case: write to the 'tref'. */
63 STRNCPY(tref->idname_fallback, idname_fallback);
64 STRNCPY(tref_rt.keymap_fallback, keymap_fallback);
65
66 WM_toolsystem_ref_set_from_runtime(C, (WorkSpace *)id, tref, &tref_rt, idname);
67}
68
69static void rna_WorkSpaceTool_refresh_from_context(ID *id, bToolRef *tref, Main *bmain)
70{
72}
73
74static PointerRNA rna_WorkSpaceTool_operator_properties(bToolRef *tref,
75 ReportList *reports,
76 const char *idname)
77{
78 wmOperatorType *ot = WM_operatortype_find(idname, true);
79
80 if (ot != nullptr) {
83 return ptr;
84 }
85
86 BKE_reportf(reports, RPT_ERROR, "Operator '%s' not found!", idname);
87 return PointerRNA_NULL;
88}
89
90static PointerRNA rna_WorkSpaceTool_gizmo_group_properties(bToolRef *tref,
91 ReportList *reports,
92 const char *idname)
93{
94 wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, false);
95 if (gzgt != nullptr) {
98 return ptr;
99 }
100 BKE_reportf(reports, RPT_ERROR, "Gizmo group '%s' not found!", idname);
101
102 return PointerRNA_NULL;
103}
104
105#else
106
108{
109 FunctionRNA *func;
110 PropertyRNA *parm;
111
112 func = RNA_def_function(srna, "status_text_set_internal", "ED_workspace_status_text");
115 func, "Set the status bar text, typically key shortcuts for modal operators");
116 parm = RNA_def_string(
117 func, "text", nullptr, 0, "Text", "New string for the status bar, None clears the text");
120}
121
123{
124 PropertyRNA *parm;
125 FunctionRNA *func;
126
127 static const EnumPropertyItem options_items[] = {
128 {TOOLREF_FLAG_FALLBACK_KEYMAP, "KEYMAP_FALLBACK", 0, "Fallback", ""},
130 "USE_BRUSHES",
131 0,
132 "Uses Brushes",
133 "Allow this tool to use brushes via the asset system"},
134 {0, nullptr, 0, nullptr, nullptr},
135 };
136
137 func = RNA_def_function(srna, "setup", "rna_WorkSpaceTool_setup");
139 RNA_def_function_ui_description(func, "Set the tool settings");
140
141 parm = RNA_def_string(func, "idname", nullptr, MAX_NAME, "Identifier", "");
143
144 /* 'bToolRef_Runtime' */
145 parm = RNA_def_property(func, "cursor", PROP_ENUM, PROP_NONE);
147 RNA_def_string(func, "keymap", nullptr, KMAP_MAX_NAME, "Key Map", "");
148 RNA_def_string(func, "gizmo_group", nullptr, MAX_NAME, "Gizmo Group", "");
149 parm = RNA_def_property(func, "brush_type", PROP_ENUM, PROP_NONE);
151 RNA_def_property_enum_funcs(parm, nullptr, nullptr, "rna_WorkSpaceTool_brush_type_itemf");
153 RNA_def_property_ui_text(parm, "Brush Type", "Limit this tool to a specific type of brush");
154 RNA_def_string(func, "data_block", nullptr, MAX_NAME, "Data Block", "");
155 RNA_def_string(func, "operator", nullptr, MAX_NAME, "Operator", "");
156 RNA_def_int(func, "index", 0, INT_MIN, INT_MAX, "Index", "", INT_MIN, INT_MAX);
157 RNA_def_enum_flag(func, "options", options_items, 0, "Tool Options", "");
158
159 RNA_def_string(func, "idname_fallback", nullptr, MAX_NAME, "Fallback Identifier", "");
160 RNA_def_string(func, "keymap_fallback", nullptr, KMAP_MAX_NAME, "Fallback Key Map", "");
161
162 /* Access tool operator options (optionally create). */
163 func = RNA_def_function(srna, "operator_properties", "rna_WorkSpaceTool_operator_properties");
165 parm = RNA_def_string(func, "operator", nullptr, 0, "", "");
167 /* return */
168 parm = RNA_def_pointer(func, "result", "OperatorProperties", "", "");
170 RNA_def_function_return(func, parm);
171
172 /* Access gizmo-group options (optionally create). */
173 func = RNA_def_function(
174 srna, "gizmo_group_properties", "rna_WorkSpaceTool_gizmo_group_properties");
176 parm = RNA_def_string(func, "group", nullptr, 0, "", "");
178 /* return */
179 parm = RNA_def_pointer(func, "result", "GizmoGroupProperties", "", "");
181 RNA_def_function_return(func, parm);
182
183 func = RNA_def_function(srna, "refresh_from_context", "rna_WorkSpaceTool_refresh_from_context");
185}
186
187#endif
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
@ RPT_ERROR
Definition BKE_report.hh:39
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:693
#define MAX_NAME
Definition DNA_defs.h:50
#define KMAP_MAX_NAME
@ TOOLREF_FLAG_FALLBACK_KEYMAP
@ TOOLREF_FLAG_USE_BRUSHES
@ PARM_RNAPTR
Definition RNA_types.hh:547
@ PARM_REQUIRED
Definition RNA_types.hh:545
@ FUNC_USE_REPORTS
Definition RNA_types.hh:914
@ FUNC_NO_SELF
Definition RNA_types.hh:907
@ FUNC_USE_MAIN
Definition RNA_types.hh:912
@ FUNC_USE_CONTEXT
Definition RNA_types.hh:913
@ FUNC_USE_SELF_ID
Definition RNA_types.hh:889
@ PROP_ENUM
Definition RNA_types.hh:166
PropertyFlag
Definition RNA_types.hh:300
@ PROP_NEVER_NULL
Definition RNA_types.hh:377
@ PROP_NONE
Definition RNA_types.hh:233
#define C
Definition RandGen.cpp:29
#define WM_toolsystem_ref_properties_ensure_from_gizmo_group(tref, gzgroup, r_ptr)
#define WM_toolsystem_ref_properties_ensure_from_operator(tref, ot, r_ptr)
CCL_NAMESPACE_BEGIN struct Options options
const PointerRNA PointerRNA_NULL
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
void RNA_def_property_enum_default(PropertyRNA *prop, int value)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
PropertyRNA * RNA_def_enum_flag(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void RNA_def_function_flag(FunctionRNA *func, int flag)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
const EnumPropertyItem rna_enum_dummy_NULL_items[]
Definition rna_rna.cc:26
const EnumPropertyItem rna_enum_window_cursor_items[]
Definition rna_wm_api.cc:31
void RNA_api_workspace_tool(StructRNA *srna)
void RNA_api_workspace(StructRNA *srna)
Definition DNA_ID.h:414
char idname_fallback[64]
PointerRNA * ptr
Definition wm_files.cc:4238
wmOperatorType * ot
Definition wm_files.cc:4237
wmGizmoGroupType * WM_gizmogrouptype_find(const StringRef idname, bool quiet)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
void WM_toolsystem_ref_set_from_runtime(bContext *C, WorkSpace *workspace, bToolRef *tref, const bToolRef_Runtime *tref_rt, const char *idname)
void WM_toolsystem_ref_sync_from_context(Main *bmain, WorkSpace *workspace, bToolRef *tref)