Blender  V3.3
wm_gizmo_group_type.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include <stdio.h>
8 
9 #include "BLI_ghash.h"
10 #include "BLI_utildefines.h"
11 
12 #include "BKE_context.h"
13 
14 #include "MEM_guardedalloc.h"
15 
16 #include "RNA_access.h"
17 #include "RNA_define.h"
18 #include "RNA_prototypes.h"
19 
20 #include "WM_api.h"
21 #include "WM_types.h"
22 
23 /* only for own init/exit calls (wm_gizmogrouptype_init/wm_gizmogrouptype_free) */
24 #include "wm.h"
25 
26 /* own includes */
27 #include "wm_gizmo_intern.h"
28 #include "wm_gizmo_wmapi.h"
29 
30 /* -------------------------------------------------------------------- */
37 
38 wmGizmoGroupType *WM_gizmogrouptype_find(const char *idname, bool quiet)
39 {
40  if (idname[0]) {
41  wmGizmoGroupType *gzgt;
42 
44  if (gzgt) {
45  return gzgt;
46  }
47 
48  if (!quiet) {
49  printf("search for unknown gizmo group '%s'\n", idname);
50  }
51  }
52  else {
53  if (!quiet) {
54  printf("search for empty gizmo group\n");
55  }
56  }
57 
58  return NULL;
59 }
60 
62 {
64 }
65 
67 {
68  wmGizmoGroupType *gzgt = MEM_callocN(sizeof(wmGizmoGroupType), "gizmogrouptype");
69  gzgt->srna = RNA_def_struct_ptr(&BLENDER_RNA, "", &RNA_GizmoGroupProperties);
70 #if 0
71  /* Set the default i18n context now, so that opfunc can redefine it if needed! */
74 #endif
75  return gzgt;
76 }
78 {
79  BLI_assert(gzgt->name != NULL);
80  BLI_assert(gzgt->idname != NULL);
81 
83 
85 
86  /* if not set, use default */
87  if (gzgt->setup_keymap == NULL) {
88  if (gzgt->flag & WM_GIZMOGROUPTYPE_SELECT) {
90  }
91  else {
93  }
94  }
95 
97 }
98 
100 {
102  wtfunc(gzgt);
104  return gzgt;
105 }
106 
108  void *userdata)
109 {
111  wtfunc(gzgt, userdata);
113  return gzgt;
114 }
115 
117  void (*wtfunc)(struct wmGizmoGroupType *))
118 {
120 
121  gzgt->gzmap_params.spaceid = gzmap_type->spaceid;
122  gzgt->gzmap_params.regionid = gzmap_type->regionid;
123 
124  return WM_gizmomaptype_group_link_ptr(gzmap_type, gzgt);
125 }
126 
131 {
132  if (gzgt->rna_ext.srna) { /* python gizmo group, allocs own string */
133  MEM_freeN((void *)gzgt->idname);
134  }
135 
136  MEM_freeN(gzgt);
137 }
138 
140 {
141  BLI_assert(gzgt == WM_gizmogrouptype_find(gzgt->idname, false));
142 
144 
145  gizmogrouptype_free(gzgt);
146 
147  /* XXX, TODO: update the world! */
148 }
149 
150 bool WM_gizmo_group_type_free(const char *idname)
151 {
153 
154  if (gzgt == NULL) {
155  return false;
156  }
157 
159 
160  return true;
161 }
162 
164 {
165  gizmogrouptype_free(gzgt);
166 }
167 
169 {
173 }
174 
176 {
177  /* reserve size is set based on blender default setup */
178  global_gizmogrouptype_hash = BLI_ghash_str_new_ex("wm_gizmogrouptype_init gh", 128);
179 }
180 
#define BLI_assert(a)
Definition: BLI_assert.h:46
GHash * BLI_ghash_str_new_ex(const char *info, unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void(* GHashValFreeFP)(void *val)
Definition: BLI_ghash.h:38
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:734
bool BLI_ghash_remove(GHash *gh, const void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:790
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition: BLI_ghash.c:710
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:863
void BLI_ghashIterator_init(GHashIterator *ghi, GHash *gh)
Definition: BLI_ghash.c:898
#define BLT_I18NCONTEXT_OPERATOR_DEFAULT
Read Guarded memory(de)allocation.
@ WM_GIZMOMAPTYPE_KEYMAP_INIT
@ WM_GIZMOGROUPTYPE_SELECT
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
void RNA_def_struct_identifier(BlenderRNA *brna, StructRNA *srna, const char *identifier)
Definition: rna_define.c:1205
StructRNA * RNA_def_struct_ptr(BlenderRNA *brna, const char *identifier, StructRNA *srnafrom)
Definition: rna_define.c:900
void RNA_def_struct_translation_context(StructRNA *srna, const char *context)
Definition: rna_define.c:1250
BlenderRNA BLENDER_RNA
StructRNA * srna
Definition: RNA_types.h:766
wmGizmoGroupFnSetupKeymap setup_keymap
const char * idname
eWM_GizmoFlagGroupTypeFlag flag
eWM_GizmoFlagMapTypeUpdateFlag type_update_flag
ExtensionRNA rna_ext
struct StructRNA * srna
struct wmGizmoMapType_Params gzmap_params
const char * name
struct StructRNA * srna
Definition: WM_types.h:969
const char * translation_context
Definition: WM_types.h:891
wmOperatorType * ot
Definition: wm_files.c:3479
wmGizmoGroupTypeRef * WM_gizmomaptype_group_link_ptr(wmGizmoMapType *gzmap_type, wmGizmoGroupType *gzgt)
wmKeyMap * WM_gizmogroup_setup_keymap_generic_select(const wmGizmoGroupType *UNUSED(gzgt), wmKeyConfig *kc)
wmKeyMap * WM_gizmogroup_setup_keymap_generic(const wmGizmoGroupType *UNUSED(gzgt), wmKeyConfig *kc)
wmGizmoGroupType * WM_gizmogrouptype_append_ptr(void(*wtfunc)(struct wmGizmoGroupType *, void *), void *userdata)
static void wm_gizmogrouptype_ghash_free_cb(wmGizmoGroupType *gzgt)
void WM_gizmogrouptype_iter(GHashIterator *ghi)
static void gizmogrouptype_free(wmGizmoGroupType *gzgt)
static void wm_gizmogrouptype_append__end(wmGizmoGroupType *gzgt)
void wm_gizmogrouptype_free(void)
void WM_gizmo_group_type_free_ptr(wmGizmoGroupType *gzgt)
wmGizmoGroupTypeRef * WM_gizmogrouptype_append_and_link(wmGizmoMapType *gzmap_type, void(*wtfunc)(struct wmGizmoGroupType *))
bool WM_gizmo_group_type_free(const char *idname)
wmGizmoGroupType * WM_gizmogrouptype_find(const char *idname, bool quiet)
wmGizmoGroupType * WM_gizmogrouptype_append(void(*wtfunc)(struct wmGizmoGroupType *))
void wm_gizmogrouptype_init(void)
static wmGizmoGroupType * wm_gizmogrouptype_append__begin(void)
static GHash * global_gizmogrouptype_hash