[Bf-blender-cvs] [123af0cd5f9] custom-manipulators: Unregister support for manipulator type
Campbell Barton
noreply at git.blender.org
Thu Jun 8 13:31:04 CEST 2017
Commit: 123af0cd5f9ccf7cbb590c1d726e00a3e766c3bc
Author: Campbell Barton
Date: Thu Jun 8 21:32:02 2017 +1000
Branches: custom-manipulators
https://developer.blender.org/rB123af0cd5f9ccf7cbb590c1d726e00a3e766c3bc
Unregister support for manipulator type
===================================================================
M source/blender/makesrna/intern/rna_wm_manipulator.c
M source/blender/windowmanager/intern/wm_operators.c
M source/blender/windowmanager/manipulators/WM_manipulator_api.h
M source/blender/windowmanager/manipulators/intern/wm_manipulator.c
M source/blender/windowmanager/manipulators/intern/wm_manipulatorgroup.c
===================================================================
diff --git a/source/blender/makesrna/intern/rna_wm_manipulator.c b/source/blender/makesrna/intern/rna_wm_manipulator.c
index f06bc9657fc..101ebb75df8 100644
--- a/source/blender/makesrna/intern/rna_wm_manipulator.c
+++ b/source/blender/makesrna/intern/rna_wm_manipulator.c
@@ -252,12 +252,13 @@ static void rna_Manipulator_color_hi_set(PointerRNA *ptr, const float *values)
WM_manipulator_set_color_highlight(mnp, values);
}
+static void rna_Manipulator_unregister(struct Main *bmain, StructRNA *type);
void manipulator_wrapper(wmManipulatorType *wgt, void *userdata);
static char _manipulator_idname[OP_MAX_TYPENAME];
static StructRNA *rna_Manipulator_register(
- Main *UNUSED(bmain), ReportList *reports, void *data, const char *identifier,
+ Main *bmain, ReportList *reports, void *data, const char *identifier,
StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
{
wmManipulatorType dummywt = {NULL};
@@ -286,17 +287,12 @@ static StructRNA *rna_Manipulator_register(
}
/* check if we have registered this manipulator type before, and remove it */
-
- /* TODO: unregister */
-#if 0
{
- const wmManipulatorType *wtype = WM_manipulatortype_find(dummywt.idname, true);
- if (wtype && wtype->ext.srna) {
- WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL);
- WM_manipulatortype_unregister(NULL, bmain, wtype);
+ const wmManipulatorType *wt = WM_manipulatortype_find(dummywt.idname, true);
+ if (wt && wt->ext.srna) {
+ rna_Manipulator_unregister(bmain, wt->ext.srna);
}
}
-#endif
/* create a new manipulator type */
dummywt.ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, dummywt.idname, &RNA_Manipulator);
@@ -332,10 +328,12 @@ static StructRNA *rna_Manipulator_register(
return dummywt.ext.srna;
}
-static void rna_Manipulator_unregister(struct Main *bmain, StructRNA *type)
+static void rna_Manipulator_unregister(struct Main *UNUSED(bmain), StructRNA *type)
{
wmManipulatorType *wt = RNA_struct_blender_type_get(type);
+ /* TODO, remove widgets from interface! */
+
if (!wt)
return;
@@ -343,8 +341,7 @@ static void rna_Manipulator_unregister(struct Main *bmain, StructRNA *type)
RNA_struct_free_extension(type, &wt->ext);
- WM_manipulatortype_unregister(wt);
- //WM_operatortype_remove_ptr(ot);
+ WM_manipulatortype_remove_ptr(wt);
RNA_struct_free(&BLENDER_RNA, type);
}
@@ -367,9 +364,14 @@ static StructRNA *rna_Manipulator_refine(PointerRNA *mnp_ptr)
* \{ */
static wmManipulator *rna_ManipulatorGroup_manipulator_new(
- wmManipulatorGroup *mgroup, const char *idname, const char *name)
+ wmManipulatorGroup *mgroup, ReportList *reports, const char *idname, const char *name)
{
- wmManipulator *mpr = WM_manipulator_new(idname, mgroup, name);
+ const wmManipulatorType *wt = WM_manipulatortype_find(idname, true);
+ if (wt == NULL) {
+ BKE_reportf(reports, RPT_ERROR, "ManipulatorType '%s' not known", idname);
+ return NULL;
+ }
+ wmManipulator *mpr = WM_manipulator_new_ptr(wt, mgroup, name);
return mpr;
}
@@ -536,7 +538,7 @@ static StructRNA *rna_ManipulatorGroup_register(
wmManipulatorGroupType *wgt = WM_manipulatorgrouptype_find(wmaptype, dummywgt.idname);
if (wgt && wgt->ext.srna) {
WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL);
- WM_manipulatorgrouptype_unregister(NULL, bmain, wgt);
+ WM_manipulatorgrouptype_remove_ptr(NULL, bmain, wgt);
}
}
@@ -581,10 +583,7 @@ static StructRNA *rna_ManipulatorGroup_register(
static void rna_ManipulatorGroup_unregister(struct Main *bmain, StructRNA *type)
{
- //const char *idname;
wmManipulatorGroupType *wgt = RNA_struct_blender_type_get(type);
- //wmWindowManager *wm;
- //wmManipulatorMapType *wmap = NULL;
if (!wgt)
return;
@@ -593,8 +592,7 @@ static void rna_ManipulatorGroup_unregister(struct Main *bmain, StructRNA *type)
RNA_struct_free_extension(type, &wgt->ext);
- WM_manipulatorgrouptype_unregister(NULL, bmain, wgt);
- //WM_operatortype_remove_ptr(ot);
+ WM_manipulatorgrouptype_remove_ptr(NULL, bmain, wgt);
RNA_struct_free(&BLENDER_RNA, type);
}
@@ -634,6 +632,7 @@ static void rna_def_manipulators(BlenderRNA *brna, PropertyRNA *cprop)
func = RNA_def_function(srna, "new", "rna_ManipulatorGroup_manipulator_new");
RNA_def_function_ui_description(func, "Add manipulator");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
RNA_def_string(func, "type", "Type", 0, "", "Manipulator identifier"); /* optional */
RNA_def_string(func, "name", "Name", 0, "", "Manipulator name"); /* optional */
parm = RNA_def_pointer(func, "manipulator", "Manipulator", "", "New manipulator");
@@ -725,7 +724,7 @@ static void rna_def_manipulator(BlenderRNA *brna, PropertyRNA *cprop)
/* wmManipulator.handler */
static EnumPropertyItem tweak_actions[] = {
- {1 /* WM_MANIPULATOR_TWEAK_PRECISE */, "PRECISE", 0, "Precise", ""},
+ {WM_MANIPULATOR_TWEAK_PRECISE, "PRECISE", 0, "Precise", ""},
{0, NULL, 0, NULL, NULL}
};
func = RNA_def_function(srna, "handler", NULL);
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 429e35c7043..03e3ab2e7be 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -499,7 +499,7 @@ void WM_operatortype_remove_ptr(wmOperatorType *ot)
WM_keyconfig_update_operatortype();
if (ot->mgrouptype) {
- WM_manipulatorgrouptype_unregister(NULL, G.main, ot->mgrouptype);
+ WM_manipulatorgrouptype_remove_ptr(NULL, G.main, ot->mgrouptype);
}
MEM_freeN(ot);
diff --git a/source/blender/windowmanager/manipulators/WM_manipulator_api.h b/source/blender/windowmanager/manipulators/WM_manipulator_api.h
index 62a863c081f..00cc4274847 100644
--- a/source/blender/windowmanager/manipulators/WM_manipulator_api.h
+++ b/source/blender/windowmanager/manipulators/WM_manipulator_api.h
@@ -85,7 +85,8 @@ void WM_manipulator_set_color_highlight(struct wmManipulator *manipulator, const
const struct wmManipulatorType *WM_manipulatortype_find(const char *idname, bool quiet);
void WM_manipulatortype_append(void (*wtfunc)(struct wmManipulatorType *));
void WM_manipulatortype_append_ptr(void (*mnpfunc)(struct wmManipulatorType *, void *), void *userdata);
-void WM_manipulatortype_unregister(struct wmManipulatorType *wt);
+bool WM_manipulatortype_remove(const char *idname);
+void WM_manipulatortype_remove_ptr(struct wmManipulatorType *wt);
void WM_manipulatortype_iter(struct GHashIterator *ghi);
/* -------------------------------------------------------------------- */
@@ -112,7 +113,7 @@ struct wmManipulatorGroupType *WM_manipulatorgrouptype_append_ptr_runtime(
void WM_manipulatorgrouptype_init_runtime(
const struct Main *bmain, struct wmManipulatorMapType *mmaptype,
struct wmManipulatorGroupType *mgrouptype);
-void WM_manipulatorgrouptype_unregister(
+void WM_manipulatorgrouptype_remove_ptr(
struct bContext *C, struct Main *bmain, struct wmManipulatorGroupType *mgroup);
struct wmKeyMap *WM_manipulatorgroup_keymap_common(
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
index 5f2c2ddf73d..37f60f72aaa 100644
--- a/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
@@ -133,20 +133,44 @@ void WM_manipulatortype_append_ptr(void (*wtfunc)(struct wmManipulatorType *, vo
wm_manipulatortype_append__end(mt);
}
-void WM_manipulatortype_unregister(wmManipulatorType *UNUSED(wt))
+/**
+ * Free but don't remove from ghash.
+ */
+static void manipulatortype_free(wmManipulatorType *wt)
+{
+ MEM_freeN(wt);
+}
+
+void WM_manipulatortype_remove_ptr(wmManipulatorType *wt)
+{
+ BLI_assert(wt == WM_manipulatortype_find(wt->idname, false));
+
+ BLI_ghash_remove(global_manipulatortype_hash, wt->idname, NULL, NULL);
+
+ manipulatortype_free(wt);
+}
+
+bool WM_manipulatortype_remove(const char *idname)
{
- /* TODO */
- BLI_assert(0);
+ wmManipulatorType *wt = BLI_ghash_lookup(global_manipulatortype_hash, idname);
+
+ if (wt == NULL) {
+ return false;
+ }
+
+ WM_manipulatortype_remove_ptr(wt);
+
+ return true;
}
-static void manipulatortype_ghash_free_cb(wmManipulatorType *mt)
+static void wm_manipulatortype_ghash_free_cb(wmManipulatorType *mt)
{
- MEM_freeN(mt);
+ manipulatortype_free(mt);
}
void wm_manipulatortype_free(void)
{
- BLI_ghash_free(global_manipulatortype_hash, NULL, (GHashValFreeFP)manipulatortype_ghash_free_cb);
+ BLI_ghash_free(global_manipulatortype_hash, NULL, (GHashValFreeFP)wm_manipulatortype_ghash_free_cb);
global_manipulatortype_hash = NULL;
}
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulatorgroup.c b/source/blender/windowmanager/manipulators/intern/wm_manipulatorgroup.c
index 191f0eb36a2..37681eb60b2 100644
--- a/source/blender/windowmanager/manipulators/intern/wm_manipulatorgroup.c
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulatorgroup.c
@@ -611,7 +611,7 @@ void WM_manipulatorgrouptype_init_runtime(
}
}
-void WM_manipulatorgrouptype_unregister(bContext *C, Main *bmain, wmManipulatorGroupType *mgrouptype)
+void WM_manipulatorgrouptype_remove_ptr(bContext *C, Main *bmain, wmManipulatorGroupType *mgrouptype)
{
for (bScreen *sc = bmain->screen.first; sc; sc = sc->id.next) {
for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
More information about the Bf-blender-cvs
mailing list