Blender V5.3
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.hh"
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
34namespace blender {
35
36static void rna_WorkSpaceTool_setup(ID *id,
37 bToolRef *tref,
38 bContext *C,
39 const char *idname,
40 /* Args for: 'bToolRef_Runtime'. */
41 int cursor,
42 const char *keymap,
43 const char *gizmo_group,
44 int brush_type,
45 const char *data_block,
46 const char *op_idname,
47 int index,
48 int options,
49 const char *idname_fallback,
50 const char *keymap_fallback)
51{
52 bToolRef_Runtime tref_rt = {0};
53
54 tref_rt.cursor = cursor;
55 STRNCPY(tref_rt.keymap, keymap);
56 STRNCPY(tref_rt.gizmo_group, gizmo_group);
57 STRNCPY(tref_rt.data_block, data_block);
58 STRNCPY(tref_rt.op, op_idname);
59 tref_rt.brush_type = brush_type;
60 tref_rt.index = index;
61 tref_rt.flag = ebToolRef_Runtime_Flag(options);
62
63 /* While it's logical to assign both these values from setup,
64 * it's useful to stored this in DNA for re-use, exceptional case: write to the 'tref'. */
65 STRNCPY(tref->idname_fallback, idname_fallback);
66 STRNCPY(tref_rt.keymap_fallback, keymap_fallback);
67
68 WM_toolsystem_ref_set_from_runtime(C, id_cast<WorkSpace *>(id), tref, &tref_rt, idname);
69}
70
71static void rna_WorkSpaceTool_refresh_from_context(ID *id, bToolRef *tref, Main *bmain)
72{
73 WM_toolsystem_ref_sync_from_context(bmain, id_cast<WorkSpace *>(id), tref);
74}
75
76static PointerRNA rna_WorkSpaceTool_operator_properties(bToolRef *tref,
77 ReportList *reports,
78 const char *idname)
79{
80 wmOperatorType *ot = WM_operatortype_find(idname, true);
81
82 if (ot != nullptr) {
83 PointerRNA ptr;
85 return ptr;
86 }
87
88 BKE_reportf(reports, RPT_ERROR, "Operator '%s' not found!", idname);
89 return {};
90}
91
92static PointerRNA rna_WorkSpaceTool_gizmo_group_properties(bToolRef *tref,
93 ReportList *reports,
94 const char *idname)
95{
96 wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, false);
97 if (gzgt != nullptr) {
98 PointerRNA ptr;
100 return ptr;
101 }
102 BKE_reportf(reports, RPT_ERROR, "Gizmo group '%s' not found!", idname);
103
104 return {};
105}
106
107} // namespace blender
108
109#else
110
111namespace blender {
112
114{
115 FunctionRNA *func;
116 PropertyRNA *parm;
117
118 func = RNA_def_function(srna, "status_text_set_internal", "ED_workspace_status_text");
121 func, "Set the status bar text, typically key shortcuts for modal operators");
122 parm = RNA_def_string(
123 func, "text", nullptr, 0, "Text", "New string for the status bar, None clears the text");
126}
127
129{
130 PropertyRNA *parm;
131 FunctionRNA *func;
132
133 static const EnumPropertyItem options_items[] = {
134 {TOOLREF_FLAG_FALLBACK_KEYMAP, "KEYMAP_FALLBACK", 0, "Fallback", ""},
136 "USE_BRUSHES",
137 0,
138 "Uses Brushes",
139 "Allow this tool to use brushes via the asset system"},
140 {0, nullptr, 0, nullptr, nullptr},
141 };
142
143 func = RNA_def_function(srna, "setup", "rna_WorkSpaceTool_setup");
145 RNA_def_function_ui_description(func, "Set the tool settings");
146
147 parm = RNA_def_string(func, "idname", nullptr, MAX_NAME, "Identifier", "");
149
150 /* 'bToolRef_Runtime' */
151 parm = RNA_def_property(func, "cursor", PROP_ENUM, PROP_NONE);
153 RNA_def_string(func, "keymap", nullptr, KMAP_MAX_NAME, "Key Map", "");
154 RNA_def_string(func, "gizmo_group", nullptr, MAX_NAME, "Gizmo Group", "");
155 parm = RNA_def_property(func, "brush_type", PROP_ENUM, PROP_NONE);
157 RNA_def_property_enum_funcs(parm, nullptr, nullptr, "rna_WorkSpaceTool_brush_type_itemf");
159 RNA_def_property_ui_text(parm, "Brush Type", "Limit this tool to a specific type of brush");
160 RNA_def_string(func, "data_block", nullptr, MAX_NAME, "Data Block", "");
161 RNA_def_string(func, "operator", nullptr, MAX_NAME, "Operator", "");
162 RNA_def_int(func, "index", 0, INT_MIN, INT_MAX, "Index", "", INT_MIN, INT_MAX);
163 RNA_def_enum_flag(func, "options", options_items, 0, "Tool Options", "");
164
165 RNA_def_string(func, "idname_fallback", nullptr, MAX_NAME, "Fallback Identifier", "");
166 RNA_def_string(func, "keymap_fallback", nullptr, KMAP_MAX_NAME, "Fallback Key Map", "");
167
168 /* Access tool operator options (optionally create). */
169 func = RNA_def_function(srna, "operator_properties", "rna_WorkSpaceTool_operator_properties");
171 parm = RNA_def_string(func, "operator", nullptr, 0, "", "");
173 /* return */
174 parm = RNA_def_pointer(func, "result", "OperatorProperties", "", "");
176 RNA_def_function_return(func, parm);
177
178 /* Access gizmo-group options (optionally create). */
179 func = RNA_def_function(
180 srna, "gizmo_group_properties", "rna_WorkSpaceTool_gizmo_group_properties");
182 parm = RNA_def_string(func, "group", nullptr, 0, "", "");
184 /* return */
185 parm = RNA_def_pointer(func, "result", "GizmoGroupProperties", "", "");
187 RNA_def_function_return(func, parm);
188
189 func = RNA_def_function(srna, "refresh_from_context", "rna_WorkSpaceTool_refresh_from_context");
191}
192
193} // namespace blender
194
195#endif
#define MAX_NAME
Definition DNA_defs.h:63
#define KMAP_MAX_NAME
#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
#define INT_MAX
BMesh Iterators.
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
char * STRNCPY(char(&dst)[N], const char *src)
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_property_enum_default(PropertyRNA *prop, int value)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
@ FUNC_USE_REPORTS
@ FUNC_USE_SELF_ID
Definition RNA_types.hh:980
@ FUNC_USE_MAIN
@ FUNC_NO_SELF
Definition RNA_types.hh:998
@ FUNC_USE_CONTEXT
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
wmGizmoGroupType * WM_gizmogrouptype_find(const StringRef idname, bool quiet)
@ TOOLREF_FLAG_FALLBACK_KEYMAP
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier_c_str, int type, int subtype)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
void RNA_api_workspace(StructRNA *srna)
const EnumPropertyItem rna_enum_window_cursor_items[]
Definition rna_wm_api.cc:36
void WM_toolsystem_ref_set_from_runtime(bContext *C, WorkSpace *workspace, bToolRef *tref, const bToolRef_Runtime *tref_rt, const char *idname)
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_api_workspace_tool(StructRNA *srna)
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier_c_str, const char *call)
const EnumPropertyItem rna_enum_dummy_NULL_items[]
Definition rna_rna.cc:28
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
void RNA_def_function_flag(FunctionRNA *func, FunctionFlag 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 BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
@ PROP_NEVER_NULL
Definition RNA_types.hh:447
void WM_toolsystem_ref_sync_from_context(Main *bmain, WorkSpace *workspace, bToolRef *tref)
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)
@ PARM_REQUIRED
Definition RNA_types.hh:631
@ PARM_RNAPTR
Definition RNA_types.hh:633