Blender  V2.93
rna_workspace_api.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 <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <time.h>
25 
26 #include "BLI_utildefines.h"
27 
28 #include "RNA_define.h"
29 
30 #include "DNA_object_types.h"
32 
33 #include "RNA_enum_types.h" /* own include */
34 
35 #include "rna_internal.h" /* own include */
36 
37 #ifdef RNA_RUNTIME
38 
39 # include "BKE_paint.h"
40 
41 # include "ED_screen.h"
42 
43 static void rna_WorkSpaceTool_setup(ID *id,
44  bToolRef *tref,
45  bContext *C,
46  const char *idname,
47  /* Args for: 'bToolRef_Runtime'. */
48  int cursor,
49  const char *keymap,
50  const char *gizmo_group,
51  const char *data_block,
52  const char *op_idname,
53  int index,
54  const char *idname_fallback,
55  const char *keymap_fallback)
56 {
57  bToolRef_Runtime tref_rt = {0};
58 
59  tref_rt.cursor = cursor;
60  STRNCPY(tref_rt.keymap, keymap);
61  STRNCPY(tref_rt.gizmo_group, gizmo_group);
62  STRNCPY(tref_rt.data_block, data_block);
63  STRNCPY(tref_rt.op, op_idname);
64  tref_rt.index = index;
65 
66  /* While it's logical to assign both these values from setup,
67  * it's useful to stored this in DNA for re-use, exceptional case: write to the 'tref'. */
68  STRNCPY(tref->idname_fallback, idname_fallback);
69  STRNCPY(tref_rt.keymap_fallback, keymap_fallback);
70 
71  WM_toolsystem_ref_set_from_runtime(C, (WorkSpace *)id, tref, &tref_rt, idname);
72 }
73 
74 static void rna_WorkSpaceTool_refresh_from_context(ID *id, bToolRef *tref, Main *bmain)
75 {
77 }
78 
79 static PointerRNA rna_WorkSpaceTool_operator_properties(bToolRef *tref,
80  ReportList *reports,
81  const char *idname)
82 {
83  wmOperatorType *ot = WM_operatortype_find(idname, true);
84 
85  if (ot != NULL) {
88  return ptr;
89  }
90  else {
91  BKE_reportf(reports, RPT_ERROR, "Operator '%s' not found!", idname);
92  }
93  return PointerRNA_NULL;
94 }
95 
96 static PointerRNA rna_WorkSpaceTool_gizmo_group_properties(bToolRef *tref,
97  ReportList *reports,
98  const char *idname)
99 {
100  wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, false);
101  if (gzgt != NULL) {
102  PointerRNA ptr;
104  return ptr;
105  }
106  else {
107  BKE_reportf(reports, RPT_ERROR, "Gizmo group '%s' not found!", idname);
108  }
109  return PointerRNA_NULL;
110 }
111 
112 #else
113 
115 {
116  FunctionRNA *func;
117  PropertyRNA *parm;
118 
119  func = RNA_def_function(srna, "status_text_set_internal", "ED_workspace_status_text");
122  func, "Set the status bar text, typically key shortcuts for modal operators");
123  parm = RNA_def_string(
124  func, "text", NULL, 0, "Text", "New string for the status bar, None clears the text");
127 }
128 
130 {
131  PropertyRNA *parm;
132  FunctionRNA *func;
133 
134  func = RNA_def_function(srna, "setup", "rna_WorkSpaceTool_setup");
136  RNA_def_function_ui_description(func, "Set the tool settings");
137 
138  parm = RNA_def_string(func, "idname", NULL, MAX_NAME, "Identifier", "");
140 
141  /* 'bToolRef_Runtime' */
142  parm = RNA_def_property(func, "cursor", PROP_ENUM, PROP_NONE);
144  RNA_def_string(func, "keymap", NULL, KMAP_MAX_NAME, "Key Map", "");
145  RNA_def_string(func, "gizmo_group", NULL, MAX_NAME, "Gizmo Group", "");
146  RNA_def_string(func, "data_block", NULL, MAX_NAME, "Data Block", "");
147  RNA_def_string(func, "operator", NULL, MAX_NAME, "Operator", "");
148  RNA_def_int(func, "index", 0, INT_MIN, INT_MAX, "Index", "", INT_MIN, INT_MAX);
149 
150  RNA_def_string(func, "idname_fallback", NULL, MAX_NAME, "Fallback Identifier", "");
151  RNA_def_string(func, "keymap_fallback", NULL, KMAP_MAX_NAME, "Fallback Key Map", "");
152 
153  /* Access tool operator options (optionally create). */
154  func = RNA_def_function(srna, "operator_properties", "rna_WorkSpaceTool_operator_properties");
156  parm = RNA_def_string(func, "operator", NULL, 0, "", "");
158  /* return */
159  parm = RNA_def_pointer(func, "result", "OperatorProperties", "", "");
161  RNA_def_function_return(func, parm);
162 
163  /* Access gizmo-group options (optionally create). */
164  func = RNA_def_function(
165  srna, "gizmo_group_properties", "rna_WorkSpaceTool_gizmo_group_properties");
167  parm = RNA_def_string(func, "group", NULL, 0, "", "");
169  /* return */
170  parm = RNA_def_pointer(func, "result", "GizmoGroupProperties", "", "");
172  RNA_def_function_return(func, parm);
173 
174  func = RNA_def_function(srna, "refresh_from_context", "rna_WorkSpaceTool_refresh_from_context");
176 }
177 
178 #endif
void BKE_reportf(ReportList *reports, ReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
#define STRNCPY(dst, src)
Definition: BLI_string.h:163
#define MAX_NAME
Definition: DNA_defs.h:62
Object is a sort of wrapper for general info.
#define KMAP_MAX_NAME
@ PARM_RNAPTR
Definition: RNA_types.h:339
@ PARM_REQUIRED
Definition: RNA_types.h:337
@ FUNC_USE_REPORTS
Definition: RNA_types.h:578
@ FUNC_NO_SELF
Definition: RNA_types.h:571
@ FUNC_USE_MAIN
Definition: RNA_types.h:576
@ FUNC_USE_CONTEXT
Definition: RNA_types.h:577
@ FUNC_USE_SELF_ID
Definition: RNA_types.h:565
@ PROP_ENUM
Definition: RNA_types.h:77
@ PROP_NEVER_NULL
Definition: RNA_types.h:225
@ PROP_NONE
Definition: RNA_types.h:113
#define C
Definition: RandGen.cpp:39
#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)
const PointerRNA PointerRNA_NULL
Definition: rna_access.c:71
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_function_return(FunctionRNA *func, PropertyRNA *ret)
Definition: rna_define.c:4302
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
Definition: rna_define.c:4262
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
Definition: rna_define.c:1892
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
Definition: rna_define.c:4337
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1279
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
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_int(StructOrFunctionRNA *cont_, const char *identifier, int default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3585
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
Definition: rna_define.c:1547
const EnumPropertyItem rna_enum_window_cursor_items[]
Definition: rna_wm_api.c:45
void RNA_api_workspace_tool(StructRNA *srna)
void RNA_api_workspace(StructRNA *srna)
Definition: DNA_ID.h:273
Definition: BKE_main.h:116
char idname_fallback[64]
PointerRNA * ptr
Definition: wm_files.c:3157
wmOperatorType * ot
Definition: wm_files.c:3156
wmGizmoGroupType * WM_gizmogrouptype_find(const char *idname, bool quiet)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
void WM_toolsystem_ref_sync_from_context(Main *bmain, WorkSpace *workspace, bToolRef *tref)
void WM_toolsystem_ref_set_from_runtime(struct bContext *C, struct WorkSpace *workspace, bToolRef *tref, const bToolRef_Runtime *tref_rt, const char *idname)