Blender  V2.93
wm_gizmo_group_type.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 
23 #include "BLI_ghash.h"
24 #include "BLI_utildefines.h"
25 
26 #include "BKE_context.h"
27 
28 #include "MEM_guardedalloc.h"
29 
30 #include "RNA_access.h"
31 #include "RNA_define.h"
32 
33 #include "WM_api.h"
34 #include "WM_types.h"
35 
36 /* only for own init/exit calls (wm_gizmogrouptype_init/wm_gizmogrouptype_free) */
37 #include "wm.h"
38 
39 /* own includes */
40 #include "wm_gizmo_intern.h"
41 #include "wm_gizmo_wmapi.h"
42 
43 /* -------------------------------------------------------------------- */
50 
51 wmGizmoGroupType *WM_gizmogrouptype_find(const char *idname, bool quiet)
52 {
53  if (idname[0]) {
54  wmGizmoGroupType *gzgt;
55 
57  if (gzgt) {
58  return gzgt;
59  }
60 
61  if (!quiet) {
62  printf("search for unknown gizmo group '%s'\n", idname);
63  }
64  }
65  else {
66  if (!quiet) {
67  printf("search for empty gizmo group\n");
68  }
69  }
70 
71  return NULL;
72 }
73 
74 /* caller must free */
76 {
78 }
79 
81 {
82  wmGizmoGroupType *gzgt = MEM_callocN(sizeof(wmGizmoGroupType), "gizmogrouptype");
84 #if 0
85  /* Set the default i18n context now, so that opfunc can redefine it if needed! */
88 #endif
89  return gzgt;
90 }
92 {
93  BLI_assert(gzgt->name != NULL);
94  BLI_assert(gzgt->idname != NULL);
95 
97 
99 
100  /* if not set, use default */
101  if (gzgt->setup_keymap == NULL) {
102  if (gzgt->flag & WM_GIZMOGROUPTYPE_SELECT) {
104  }
105  else {
107  }
108  }
109 
110  BLI_ghash_insert(global_gizmogrouptype_hash, (void *)gzgt->idname, gzgt);
111 }
112 
114 {
116  wtfunc(gzgt);
118  return gzgt;
119 }
120 
122  void *userdata)
123 {
125  wtfunc(gzgt, userdata);
127  return gzgt;
128 }
129 
135  void (*wtfunc)(struct wmGizmoGroupType *))
136 {
138 
139  gzgt->gzmap_params.spaceid = gzmap_type->spaceid;
140  gzgt->gzmap_params.regionid = gzmap_type->regionid;
141 
142  return WM_gizmomaptype_group_link_ptr(gzmap_type, gzgt);
143 }
144 
149 {
150  if (gzgt->rna_ext.srna) { /* python gizmo group, allocs own string */
151  MEM_freeN((void *)gzgt->idname);
152  }
153 
154  MEM_freeN(gzgt);
155 }
156 
158 {
159  BLI_assert(gzgt == WM_gizmogrouptype_find(gzgt->idname, false));
160 
162 
163  gizmogrouptype_free(gzgt);
164 
165  /* XXX, TODO, update the world! */
166 }
167 
168 bool WM_gizmo_group_type_free(const char *idname)
169 {
171 
172  if (gzgt == NULL) {
173  return false;
174  }
175 
177 
178  return true;
179 }
180 
182 {
183  gizmogrouptype_free(gzgt);
184 }
185 
187 {
191 }
192 
193 /* called on initialize WM_init() */
195 {
196  /* reserve size is set based on blender default setup */
197  global_gizmogrouptype_hash = BLI_ghash_str_new_ex("wm_gizmogrouptype_init gh", 128);
198 }
199 
#define BLI_assert(a)
Definition: BLI_assert.h:58
void(* GHashValFreeFP)(void *val)
Definition: BLI_ghash.h:50
GHash * BLI_ghash_str_new_ex(const char *info, const unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
bool BLI_ghash_remove(GHash *gh, const void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:900
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition: BLI_ghash.c:756
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:1008
void BLI_ghashIterator_init(GHashIterator *ghi, GHash *gh)
Definition: BLI_ghash.c:1065
void * BLI_ghash_lookup(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:803
#define BLT_I18NCONTEXT_OPERATOR_DEFAULT
Read Guarded memory(de)allocation.
StructRNA RNA_GizmoGroupProperties
@ WM_GIZMOMAPTYPE_KEYMAP_INIT
@ WM_GIZMOGROUPTYPE_SELECT
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
void RNA_def_struct_identifier(BlenderRNA *brna, StructRNA *srna, const char *identifier)
Definition: rna_define.c:1224
StructRNA * RNA_def_struct_ptr(BlenderRNA *brna, const char *identifier, StructRNA *srnafrom)
Definition: rna_define.c:919
void RNA_def_struct_translation_context(StructRNA *srna, const char *context)
Definition: rna_define.c:1272
BlenderRNA BLENDER_RNA
StructRNA * srna
Definition: RNA_types.h:681
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:802
const char * translation_context
Definition: WM_types.h:724
wmOperatorType * ot
Definition: wm_files.c:3156
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