Blender V5.0
wm_gizmo_group_type.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 <cstdio>
10
11#include "BLI_vector_set.hh"
12
13#include "MEM_guardedalloc.h"
14
15#include "RNA_access.hh"
16#include "RNA_define.hh"
17#include "RNA_prototypes.hh"
18
19#include "WM_types.hh"
20
21/* Own includes. */
22#include "wm_gizmo_intern.hh"
23#include "wm_gizmo_wmapi.hh"
24
25/* -------------------------------------------------------------------- */
30
32
34{
35 struct IDNameGetter {
36 StringRef operator()(const wmGizmoGroupType *value) const
37 {
38 return StringRef(value->idname);
39 }
40 };
42 return map;
43}
44
46{
47 if (!idname.is_empty()) {
48 if (wmGizmoGroupType *const *gzgt = get_gizmo_group_type_map().lookup_key_ptr_as(idname)) {
49 return *gzgt;
50 }
51
52 if (!quiet) {
53 printf("search for unknown gizmo group '%s'\n", std::string(idname).c_str());
54 }
55 }
56 else {
57 if (!quiet) {
58 printf("search for empty gizmo group\n");
59 }
60 }
61
62 return nullptr;
63}
64
66{
67 wmGizmoGroupType *gzgt = MEM_callocN<wmGizmoGroupType>("gizmogrouptype");
68 gzgt->srna = RNA_def_struct_ptr(&BLENDER_RNA, "", &RNA_GizmoGroupProperties);
69#if 0
70 /* Set the default i18n context now, so that opfunc can redefine it if needed! */
72 ot->translation_context = BLT_I18NCONTEXT_OPERATOR_DEFAULT;
73#endif
74 return gzgt;
75}
77{
78 BLI_assert(gzgt->name != nullptr);
79 BLI_assert(gzgt->idname != nullptr);
80
82
84
85 /* If not set, use default. */
86 if (gzgt->setup_keymap == nullptr) {
87 if (gzgt->flag & WM_GIZMOGROUPTYPE_SELECT) {
89 }
90 else {
92 }
93 }
94
95 get_gizmo_group_type_map().add(gzgt);
96}
97
99{
101 wtfunc(gzgt);
103 return gzgt;
104}
105
107 void *userdata)
108{
110 wtfunc(gzgt, userdata);
112 return gzgt;
113}
114
116 void (*wtfunc)(wmGizmoGroupType *))
117{
119
120 gzgt->gzmap_params.spaceid = gzmap_type->spaceid;
121 gzgt->gzmap_params.regionid = gzmap_type->regionid;
122
123 return WM_gizmomaptype_group_link_ptr(gzmap_type, gzgt);
124}
125
130{
131 /* Python gizmo group, allocates its own string. */
132 if (gzgt->rna_ext.srna) {
133 MEM_freeN(gzgt->idname);
134 }
135
136 MEM_freeN(gzgt);
137}
138
140{
141 BLI_assert(gzgt == WM_gizmogrouptype_find(gzgt->idname, false));
142
143 get_gizmo_group_type_map().remove(gzgt);
144
146
147 /* XXX, TODO: update the world! */
148}
149
151{
152 wmGizmoGroupType *const *gzgt = get_gizmo_group_type_map().lookup_key_ptr_as(idname);
153 if (gzgt == nullptr) {
154 return false;
155 }
156
158
159 return true;
160}
161
163{
166 }
167 get_gizmo_group_type_map().clear();
168}
169
171{
172 /* Reserve size is set based on blender default setup. */
173 get_gizmo_group_type_map().reserve(128);
174}
175
#define BLI_assert(a)
Definition BLI_assert.h:46
#define BLT_I18NCONTEXT_OPERATOR_DEFAULT
Read Guarded memory(de)allocation.
@ WM_GIZMOMAPTYPE_KEYMAP_INIT
@ WM_GIZMOGROUPTYPE_SELECT
SIMD_FORCE_INLINE btVector3 operator()(const btVector3 &x) const
Return the transform of the vector.
Definition btTransform.h:90
constexpr bool is_empty() const
#define printf(...)
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
VectorSet< T, InlineBufferCapacity, DefaultProbingStrategy, CustomIDHash< T, GetIDFn >, CustomIDEqual< T, GetIDFn > > CustomIDVectorSet
void RNA_def_struct_identifier(BlenderRNA *brna, StructRNA *srna, const char *identifier)
StructRNA * RNA_def_struct_ptr(BlenderRNA *brna, const char *identifier, StructRNA *srnafrom)
void RNA_def_struct_translation_context(StructRNA *srna, const char *context)
BlenderRNA BLENDER_RNA
StructRNA * srna
wmGizmoGroupFnSetupKeymap setup_keymap
const char * idname
wmGizmoMapType_Params gzmap_params
eWM_GizmoFlagGroupTypeFlag flag
eWM_GizmoFlagMapTypeUpdateFlag type_update_flag
ExtensionRNA rna_ext
wmOperatorType * ot
Definition wm_files.cc:4237
wmKeyMap * WM_gizmogroup_setup_keymap_generic(const wmGizmoGroupType *, wmKeyConfig *kc)
wmGizmoGroupTypeRef * WM_gizmomaptype_group_link_ptr(wmGizmoMapType *gzmap_type, wmGizmoGroupType *gzgt)
wmKeyMap * WM_gizmogroup_setup_keymap_generic_select(const wmGizmoGroupType *, wmKeyConfig *kc)
void wm_gizmogrouptype_init()
wmGizmoGroupType * WM_gizmogrouptype_append(void(*wtfunc)(wmGizmoGroupType *))
static void gizmogrouptype_free(wmGizmoGroupType *gzgt)
wmGizmoGroupType * WM_gizmogrouptype_find(const StringRef idname, bool quiet)
wmGizmoGroupType * WM_gizmogrouptype_append_ptr(void(*wtfunc)(wmGizmoGroupType *, void *), void *userdata)
static void wm_gizmogrouptype_append__end(wmGizmoGroupType *gzgt)
void WM_gizmo_group_type_free_ptr(wmGizmoGroupType *gzgt)
void wm_gizmogrouptype_free()
static auto & get_gizmo_group_type_map()
wmGizmoGroupTypeRef * WM_gizmogrouptype_append_and_link(wmGizmoMapType *gzmap_type, void(*wtfunc)(wmGizmoGroupType *))
static wmGizmoGroupType * wm_gizmogrouptype_append__begin()
bool WM_gizmo_group_type_free(const StringRef idname)