[Bf-blender-cvs] [e9c022b7d35] custom-manipulators: Using default keymap now works for RNA manipulators

Campbell Barton noreply at git.blender.org
Thu Jun 8 20:20:18 CEST 2017


Commit: e9c022b7d358ababa30d85bcc0bc91f7d9d098aa
Author: Campbell Barton
Date:   Fri Jun 9 04:20:49 2017 +1000
Branches: custom-manipulators
https://developer.blender.org/rBe9c022b7d358ababa30d85bcc0bc91f7d9d098aa

Using default keymap now works for RNA manipulators

All widget groups must now define a name and idname.

Also fix crash where keymap's wouldnt be initialized for runtime
registered types.

===================================================================

M	source/blender/editors/space_image/space_image.c
M	source/blender/editors/space_node/node_widgets.c
M	source/blender/editors/space_view3d/view3d_manipulators.c
M	source/blender/editors/transform/transform_manipulator.c
M	source/blender/makesrna/intern/rna_wm_manipulator.c
M	source/blender/windowmanager/manipulators/WM_manipulator_api.h
M	source/blender/windowmanager/manipulators/WM_manipulator_types.h
M	source/blender/windowmanager/manipulators/intern/wm_manipulator.c
M	source/blender/windowmanager/manipulators/intern/wm_manipulatorgroup.c
M	source/blender/windowmanager/manipulators/intern/wm_manipulatormap.c

===================================================================

diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c
index 6032b276a1b..af8ed40149f 100644
--- a/source/blender/editors/space_image/space_image.c
+++ b/source/blender/editors/space_image/space_image.c
@@ -592,6 +592,7 @@ static int image_context(const bContext *C, const char *member, bContextDataResu
 static void IMAGE_WGT_manipulator2d(wmManipulatorGroupType *wgt)
 {
 	wgt->name = "UV Transform Manipulator";
+	wgt->idname = "IMAGE_WGT_manipulator2d";
 
 	wgt->poll = WIDGETGROUP_manipulator2d_poll;
 	wgt->init = WIDGETGROUP_manipulator2d_init;
diff --git a/source/blender/editors/space_node/node_widgets.c b/source/blender/editors/space_node/node_widgets.c
index 0862499e567..7c056e5592c 100644
--- a/source/blender/editors/space_node/node_widgets.c
+++ b/source/blender/editors/space_node/node_widgets.c
@@ -108,6 +108,7 @@ static void WIDGETGROUP_node_transform_refresh(const bContext *C, wmManipulatorG
 void NODE_WGT_backdrop_transform(wmManipulatorGroupType *wgt)
 {
 	wgt->name = "Backdrop Transform Widgets";
+	wgt->idname = "NODE_WGT_backdrop_transform";
 
 	wgt->poll = WIDGETGROUP_node_transform_poll;
 	wgt->init = WIDGETGROUP_node_transform_init;
diff --git a/source/blender/editors/space_view3d/view3d_manipulators.c b/source/blender/editors/space_view3d/view3d_manipulators.c
index b249936f6fe..5f0379ded80 100644
--- a/source/blender/editors/space_view3d/view3d_manipulators.c
+++ b/source/blender/editors/space_view3d/view3d_manipulators.c
@@ -110,6 +110,7 @@ static void WIDGETGROUP_lamp_refresh(const bContext *C, wmManipulatorGroup *wgro
 void VIEW3D_WGT_lamp(wmManipulatorGroupType *wgt)
 {
 	wgt->name = "Lamp Widgets";
+	wgt->idname = "VIEW3D_WGT_lamp";
 
 	wgt->poll = WIDGETGROUP_lamp_poll;
 	wgt->init = WIDGETGROUP_lamp_init;
@@ -281,6 +282,7 @@ static void WIDGETGROUP_camera_refresh(const bContext *C, wmManipulatorGroup *wg
 void VIEW3D_WGT_camera(wmManipulatorGroupType *wgt)
 {
 	wgt->name = "Camera Widgets";
+	wgt->idname = "VIEW3D_WGT_camera";
 
 	wgt->poll = WIDGETGROUP_camera_poll;
 	wgt->init = WIDGETGROUP_camera_init;
@@ -348,6 +350,7 @@ static void WIDGETGROUP_forcefield_refresh(const bContext *C, wmManipulatorGroup
 void VIEW3D_WGT_force_field(wmManipulatorGroupType *wgt)
 {
 	wgt->name = "Force Field Widgets";
+	wgt->idname = "VIEW3D_WGT_force_field";
 
 	wgt->poll = WIDGETGROUP_forcefield_poll;
 	wgt->init = WIDGETGROUP_forcefield_init;
@@ -548,6 +551,7 @@ static void WIDGETGROUP_armature_facemaps_refresh(const bContext *C, wmManipulat
 void VIEW3D_WGT_armature_facemaps(wmManipulatorGroupType *wgt)
 {
 	wgt->name = "Face Map Widgets";
+	wgt->idname = "VIEW3D_WGT_armature_facemaps";
 
 	wgt->poll = WIDGETGROUP_armature_facemaps_poll;
 	wgt->init = WIDGETGROUP_armature_facemaps_init;
diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c
index 1309e5bcf42..149f5086846 100644
--- a/source/blender/editors/transform/transform_manipulator.c
+++ b/source/blender/editors/transform/transform_manipulator.c
@@ -1343,6 +1343,7 @@ static bool WIDGETGROUP_manipulator_poll(const struct bContext *C, struct wmMani
 void TRANSFORM_WGT_manipulator(wmManipulatorGroupType *wgt)
 {
 	wgt->name = "Transform Manipulator";
+	wgt->idname = "TRANSFORM_WGT_manipulator";
 
 	wgt->poll = WIDGETGROUP_manipulator_poll;
 	wgt->init = WIDGETGROUP_manipulator_init;
diff --git a/source/blender/makesrna/intern/rna_wm_manipulator.c b/source/blender/makesrna/intern/rna_wm_manipulator.c
index a0b19cf3c78..e054d4ab2b2 100644
--- a/source/blender/makesrna/intern/rna_wm_manipulator.c
+++ b/source/blender/makesrna/intern/rna_wm_manipulator.c
@@ -280,9 +280,9 @@ static StructRNA *rna_Manipulator_register(
 	if (validate(&mnp_ptr, data, have_function) != 0)
 		return NULL;
 
-	if (strlen(identifier) >= MAX_NAME) {
+	if (strlen(identifier) >= sizeof(_manipulator_idname)) {
 		BKE_reportf(reports, RPT_ERROR, "Registering manipulator class: '%s' is too long, maximum length is %d",
-		            identifier, MAX_NAME);
+		            identifier, (int)sizeof(_manipulator_idname));
 		return NULL;
 	}
 
@@ -402,12 +402,23 @@ static int rna_ManipulatorGroup_name_length(PointerRNA *ptr)
 	(void)wgroup;
 }
 
+/* just to work around 'const char *' warning and to ensure this is a python op */
+static void rna_ManipulatorGroup_bl_idname_set(PointerRNA *ptr, const char *value)
+{
+	wmManipulatorGroup *data = ptr->data;
+	char *str = (char *)data->type->idname;
+	if (!str[0])
+		BLI_strncpy(str, value, MAX_NAME);    /* utf8 already ensured */
+	else
+		assert(!"setting the bl_idname on a non-builtin operator");
+}
+
 static void rna_ManipulatorGroup_bl_label_set(PointerRNA *ptr, const char *value)
 {
 	wmManipulatorGroup *data = ptr->data;
-	const char *str = data->type->name;
-	if (!str)
-		str = value;
+	char *str = (char *)data->type->name;
+	if (!str[0])
+		BLI_strncpy(str, value, MAX_NAME);    /* utf8 already ensured */
 	else
 		assert(!"setting the bl_label on a non-builtin operator");
 }
@@ -492,6 +503,9 @@ static wmKeyMap *manipulatorgroup_keymap_init(const wmManipulatorGroupType *wgt,
 
 void manipulatorgroup_wrapper(wmManipulatorGroupType *wgt, void *userdata);
 
+static char _manipulatorgroup_name[MAX_NAME];
+static char _manipulatorgroup_idname[MAX_NAME];
+
 static StructRNA *rna_ManipulatorGroup_register(
         Main *bmain, ReportList *reports, void *data, const char *identifier,
         StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
@@ -501,21 +515,22 @@ static StructRNA *rna_ManipulatorGroup_register(
 	PointerRNA wgptr;
 
 	/* Two sets of functions. */
-#define GROUP_FN_LEN 3
-#define MANIP_FN_LEN 7
-	int have_function[GROUP_FN_LEN + MANIP_FN_LEN];
+	int have_function[3];
 
 	/* setup dummy manipulatorgroup & manipulatorgroup type to store static properties in */
 	dummywg.type = &dummywgt;
+	dummywgt.name = _manipulatorgroup_name;
+	dummywgt.idname = _manipulatorgroup_idname;
+
 	RNA_pointer_create(NULL, &RNA_ManipulatorGroup, &dummywg, &wgptr);
 
 	/* validate the python class */
 	if (validate(&wgptr, data, have_function) != 0)
 		return NULL;
 
-	if (strlen(identifier) >= sizeof(dummywgt.idname)) {
+	if (strlen(identifier) >= sizeof(_manipulatorgroup_idname)) {
 		BKE_reportf(reports, RPT_ERROR, "Registering manipulatorgroup class: '%s' is too long, maximum length is %d",
-		            identifier, (int)sizeof(dummywgt.idname));
+		            identifier, (int)sizeof(_manipulatorgroup_idname));
 		return NULL;
 	}
 
@@ -532,6 +547,19 @@ static StructRNA *rna_ManipulatorGroup_register(
 		return NULL;
 	}
 
+	{
+		int idlen = strlen(_manipulatorgroup_idname) + 1;
+		int namelen = strlen(_manipulatorgroup_name) + 1;
+
+		char *ch;
+		ch = MEM_callocN(sizeof(char) * (idlen + namelen), "_manipulatorgroup_idname");
+		dummywgt.idname = ch;
+		memcpy(ch, _manipulatorgroup_idname, idlen);
+		ch += idlen;
+		dummywgt.name = ch;
+		memcpy(ch, _manipulatorgroup_name, namelen);
+	}
+
 	/* check if we have registered this manipulatorgroup type before, and remove it */
 	{
 		wmManipulatorGroupType *wgt = WM_manipulatorgrouptype_find(wmaptype, dummywgt.idname);
@@ -566,9 +594,6 @@ static StructRNA *rna_ManipulatorGroup_register(
 	WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL);
 
 	return dummywgt.ext.srna;
-
-#undef GROUP_FN_LEN
-#undef MANIP_FN_LEN
 }
 
 static void rna_ManipulatorGroup_unregister(struct Main *bmain, StructRNA *type)
@@ -821,13 +846,14 @@ static void rna_def_manipulatorgroup(BlenderRNA *brna)
 
 	prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
 	RNA_def_property_string_sdna(prop, NULL, "type->idname");
-	/* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
+	RNA_def_property_string_maxlength(prop, MAX_NAME);
+	RNA_def_property_string_funcs(prop, NULL, NULL, "rna_ManipulatorGroup_bl_idname_set");
 	RNA_def_property_flag(prop, PROP_REGISTER);
 	RNA_def_struct_name_property(srna, prop);
 
 	prop = RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
 	RNA_def_property_string_sdna(prop, NULL, "type->name");
-	RNA_def_property_string_maxlength(prop, 64); /* else it uses the pointer size! */
+	RNA_def_property_string_maxlength(prop, MAX_NAME); /* else it uses the pointer size! */
 	RNA_def_property_string_funcs(prop, NULL, NULL, "rna_ManipulatorGroup_bl_label_set");
 	/* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
 	RNA_def_property_flag(prop, PROP_REGISTER);
@@ -864,8 +890,10 @@ static void rna_def_manipulatorgroup(BlenderRNA *brna)
 
 	/* keymap_init */
 	func = RNA_def_function(srna, "init_keymap", NULL);
-	RNA_def_function_ui_description(func, "Initialize keymaps for this manipulator group");
-	RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_REGISTER);
+	RNA_def_function_ui_description(
+	        func,
+	        "Initialize keymaps for this manipulator group, use fallback keymap when not present");
+	RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_REGISTER_OPTIONAL);
 	parm = RNA_def_pointer(func, "keyconf", "KeyConfig", "", "");
 	RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
 	parm = RNA_def_property(func, "manipulator_group", PROP_STRING, PROP_NONE);
diff --git a/source/blender/windowmanager/manipulators/WM_manipulator_api.h b/source/blender/windowmanager/manipulators/WM_manipulator_api.h
index 07242306191..031d0eea148 100644
--- a/source/blender/windowmanager/manipulators/WM_manipulator_api.h
+++ b/source/blender/windowmanager/manipulators/WM_manipulator_api.h
@@ -113,6 +113,7 @@ struct wmManipulatorGroupType *WM_manipulatorgrouptype_append_ptr_runtime(
 void WM_manipulatorgrouptype_init_runtime(
         const struct Main *bmain, struct wmManipulatorMapType *mmaptype,
         struct wmManipulatorGroupType *wgt);
+void WM_manipulatorgrouptype_free(struct wmManipulatorGroupType *wgt);
 void WM_manipulatorgrouptype_remove_ptr(
         struct bContext *C, struct Main *bmain, struct wmManipulatorGroupType *mgroup);
 
diff --git a/source/blender/windowmanager/manipulators/WM_manipulator_types.h b/source/blender/windowmanager/manipulators/WM_manipulator_types.h
index 257e6133c57..033fe1b9773 100644
--- a/source/blender/windowmanager/manipulator

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list