Blender V4.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
9#include <cstdio>
10#include <cstdlib>
11#include <cstring>
12#include <ctime>
13
14#include "BLI_utildefines.h"
15
16#include "RNA_define.hh"
17
18#include "DNA_object_types.h"
20#include "DNA_workspace_types.h"
21
22#include "RNA_enum_types.hh" /* own include */
23
24#include "rna_internal.hh" /* own include */
25
26#ifdef RNA_RUNTIME
27
28# include "BKE_paint.hh"
29
30# include "ED_screen.hh"
31
32static void rna_WorkSpaceTool_setup(ID *id,
33 bToolRef *tref,
34 bContext *C,
35 const char *idname,
36 /* Args for: 'bToolRef_Runtime'. */
37 int cursor,
38 const char *keymap,
39 const char *gizmo_group,
40 int brush_type,
41 const char *data_block,
42 const char *op_idname,
43 int index,
44 int options,
45 const char *idname_fallback,
46 const char *keymap_fallback)
47{
48 bToolRef_Runtime tref_rt = {0};
49
50 tref_rt.cursor = cursor;
51 STRNCPY(tref_rt.keymap, keymap);
52 STRNCPY(tref_rt.gizmo_group, gizmo_group);
53 STRNCPY(tref_rt.data_block, data_block);
54 STRNCPY(tref_rt.op, op_idname);
55 tref_rt.brush_type = brush_type;
56 tref_rt.index = index;
57 tref_rt.flag = options;
58
59 /* While it's logical to assign both these values from setup,
60 * it's useful to stored this in DNA for re-use, exceptional case: write to the 'tref'. */
61 STRNCPY(tref->idname_fallback, idname_fallback);
62 STRNCPY(tref_rt.keymap_fallback, keymap_fallback);
63
64 WM_toolsystem_ref_set_from_runtime(C, (WorkSpace *)id, tref, &tref_rt, idname);
65}
66
67static void rna_WorkSpaceTool_refresh_from_context(ID *id, bToolRef *tref, Main *bmain)
68{
70}
71
72static PointerRNA rna_WorkSpaceTool_operator_properties(bToolRef *tref,
73 ReportList *reports,
74 const char *idname)
75{
76 wmOperatorType *ot = WM_operatortype_find(idname, true);
77
78 if (ot != nullptr) {
81 return ptr;
82 }
83 else {
84 BKE_reportf(reports, RPT_ERROR, "Operator '%s' not found!", idname);
85 }
86 return PointerRNA_NULL;
87}
88
89static PointerRNA rna_WorkSpaceTool_gizmo_group_properties(bToolRef *tref,
90 ReportList *reports,
91 const char *idname)
92{
93 wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, false);
94 if (gzgt != nullptr) {
97 return ptr;
98 }
99 else {
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
#define STRNCPY(dst, src)
Definition BLI_string.h:593
#define MAX_NAME
Definition DNA_defs.h:50
Object is a sort of wrapper for general info.
#define KMAP_MAX_NAME
@ TOOLREF_FLAG_FALLBACK_KEYMAP
@ TOOLREF_FLAG_USE_BRUSHES
@ PARM_RNAPTR
Definition RNA_types.hh:399
@ PARM_REQUIRED
Definition RNA_types.hh:397
@ FUNC_USE_REPORTS
Definition RNA_types.hh:680
@ FUNC_NO_SELF
Definition RNA_types.hh:673
@ FUNC_USE_MAIN
Definition RNA_types.hh:678
@ FUNC_USE_CONTEXT
Definition RNA_types.hh:679
@ FUNC_USE_SELF_ID
Definition RNA_types.hh:667
@ PROP_ENUM
Definition RNA_types.hh:69
PropertyFlag
Definition RNA_types.hh:201
@ PROP_NEVER_NULL
Definition RNA_types.hh:266
@ PROP_NONE
Definition RNA_types.hh:136
constexpr PointerRNA PointerRNA_NULL
Definition RNA_types.hh:45
#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
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:29
const EnumPropertyItem rna_enum_window_cursor_items[]
Definition rna_wm_api.cc:33
void RNA_api_workspace_tool(StructRNA *srna)
void RNA_api_workspace(StructRNA *srna)
Definition DNA_ID.h:413
char idname_fallback[64]
PointerRNA * ptr
Definition wm_files.cc:4126
wmOperatorType * ot
Definition wm_files.cc:4125
wmGizmoGroupType * WM_gizmogrouptype_find(const char *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)