[Bf-blender-cvs] [ab6411e32cd] custom-manipulators: Python support for manipulator target-property definitions

Campbell Barton noreply at git.blender.org
Wed Jun 21 13:07:04 CEST 2017


Commit: ab6411e32cd53751ed42fc0ae1beffddc9616895
Author: Campbell Barton
Date:   Wed Jun 21 21:10:17 2017 +1000
Branches: custom-manipulators
https://developer.blender.org/rBab6411e32cd53751ed42fc0ae1beffddc9616895

Python support for manipulator target-property definitions

Note that these aren't used at the moment.

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

M	source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c
M	source/blender/editors/manipulator_library/manipulator_types/cage2d_manipulator.c
M	source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c
M	source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c
M	source/blender/python/intern/bpy_intern_string.c
M	source/blender/python/intern/bpy_intern_string.h
M	source/blender/python/intern/bpy_manipulator_wrap.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_target_props.c
M	source/blender/windowmanager/manipulators/intern/wm_manipulator_type.c

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

diff --git a/source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c
index e13815f3997..42724007176 100644
--- a/source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c
+++ b/source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c
@@ -484,6 +484,8 @@ static void MANIPULATOR_WT_arrow_3d(wmManipulatorType *wt)
 
 	RNA_def_float(wt->srna, "length", 1.0f, 0.0f, FLT_MAX, "Arrow Line Length", "", 0.0f, FLT_MAX);
 	RNA_def_float_vector(wt->srna, "aspect", 2, NULL, 0, FLT_MAX, "Aspect", "Cone/box style only", 0.0f, FLT_MAX);
+
+	WM_manipulatortype_target_property_def(wt, "offset", PROP_FLOAT, 1);
 }
 
 void ED_manipulatortypes_arrow_3d(void)
diff --git a/source/blender/editors/manipulator_library/manipulator_types/cage2d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/cage2d_manipulator.c
index f35e3b481a6..9ef81481638 100644
--- a/source/blender/editors/manipulator_library/manipulator_types/cage2d_manipulator.c
+++ b/source/blender/editors/manipulator_library/manipulator_types/cage2d_manipulator.c
@@ -228,7 +228,7 @@ static void manipulator_rect_transform_draw(const bContext *UNUSED(C), wmManipul
 		aspy = w / h;
 	}
 	w = min_ff(aspx * w / MANIPULATOR_RESIZER_WIDTH, MANIPULATOR_RESIZER_WIDTH / scale[0]);
-	h = min_ff(aspy * h / MANIPULATOR_RESIZER_WIDTH, MANIPULATOR_RESIZER_WIDTH / 
+	h = min_ff(aspy * h / MANIPULATOR_RESIZER_WIDTH, MANIPULATOR_RESIZER_WIDTH /
 	           ((transform_flag & ED_MANIPULATOR_RECT_TRANSFORM_FLAG_SCALE_UNIFORM) ? scale[0] : scale[1]));
 
 	/* corner manipulators */
@@ -303,7 +303,7 @@ static int manipulator_rect_transform_test_select(
 		aspy = w / h;
 	}
 	w = min_ff(aspx * w / MANIPULATOR_RESIZER_WIDTH, MANIPULATOR_RESIZER_WIDTH / scale[0]);
-	h = min_ff(aspy * h / MANIPULATOR_RESIZER_WIDTH, MANIPULATOR_RESIZER_WIDTH / 
+	h = min_ff(aspy * h / MANIPULATOR_RESIZER_WIDTH, MANIPULATOR_RESIZER_WIDTH /
 	           ((transform_flag & ED_MANIPULATOR_RECT_TRANSFORM_FLAG_SCALE_UNIFORM) ? scale[0] : scale[1]));
 
 
@@ -610,6 +610,10 @@ static void MANIPULATOR_WT_cage_2d(wmManipulatorType *wt)
 	RNA_def_float_vector(wt->srna, "scale", 2, scale_default, 0, FLT_MAX, "Scale", "", 0.0f, FLT_MAX);
 	RNA_def_float_vector(wt->srna, "dimensions", 2, NULL, 0, FLT_MAX, "Dimensions", "", 0.0f, FLT_MAX);
 	RNA_def_enum_flag(wt->srna, "transform", rna_enum_transform, 0, "Transform Options", "");
+
+	WM_manipulatortype_target_property_def(wt, "offset", PROP_FLOAT, 1);
+	WM_manipulatortype_target_property_def(wt, "scale", PROP_FLOAT, 2);
+	WM_manipulatortype_target_property_def(wt, "scale_uniform", PROP_FLOAT, 1);
 }
 
 void ED_manipulatortypes_cage_2d(void)
diff --git a/source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c
index 40cf67e1133..098bd7c495f 100644
--- a/source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c
+++ b/source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c
@@ -457,6 +457,8 @@ static void MANIPULATOR_WT_dial_3d(wmManipulatorType *wt)
 		{0, NULL, 0, NULL, NULL}
 	};
 	RNA_def_enum_flag(wt->srna, "draw_options", rna_enum_draw_options, 0, "Draw Options", "");
+
+	WM_manipulatortype_target_property_def(wt, "offset", PROP_FLOAT, 1);
 }
 
 void ED_manipulatortypes_dial_3d(void)
diff --git a/source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c
index 527e29c79e8..4fcb44af3c9 100644
--- a/source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c
+++ b/source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c
@@ -250,6 +250,8 @@ static void MANIPULATOR_WT_grab_3d(wmManipulatorType *wt)
 
 	RNA_def_enum(wt->srna, "draw_style", rna_enum_draw_style, ED_MANIPULATOR_GRAB_STYLE_RING, "Draw Style", "");
 	RNA_def_enum_flag(wt->srna, "draw_options", rna_enum_draw_options, 0, "Draw Options", "");
+
+	WM_manipulatortype_target_property_def(wt, "offset", PROP_FLOAT, 3);
 }
 
 void ED_manipulatortypes_grab_3d(void)
diff --git a/source/blender/python/intern/bpy_intern_string.c b/source/blender/python/intern/bpy_intern_string.c
index e9d84b2099b..6911e985e93 100644
--- a/source/blender/python/intern/bpy_intern_string.c
+++ b/source/blender/python/intern/bpy_intern_string.c
@@ -34,7 +34,7 @@
 
 #include "BLI_utildefines.h"
 
-static PyObject *bpy_intern_str_arr[15];
+static PyObject *bpy_intern_str_arr[16];
 
 PyObject *bpy_intern_str___doc__;
 PyObject *bpy_intern_str___main__;
@@ -44,6 +44,7 @@ PyObject *bpy_intern_str___slots__;
 PyObject *bpy_intern_str_attr;
 PyObject *bpy_intern_str_bl_property;
 PyObject *bpy_intern_str_bl_rna;
+PyObject *bpy_intern_str_bl_target_properties;
 PyObject *bpy_intern_str_bpy_types;
 PyObject *bpy_intern_str_frame;
 PyObject *bpy_intern_str_order;
@@ -67,6 +68,7 @@ void bpy_intern_string_init(void)
 	BPY_INTERN_STR(bpy_intern_str_attr, "attr");
 	BPY_INTERN_STR(bpy_intern_str_bl_property, "bl_property");
 	BPY_INTERN_STR(bpy_intern_str_bl_rna, "bl_rna");
+	BPY_INTERN_STR(bpy_intern_str_bl_target_properties, "bl_target_properties");
 	BPY_INTERN_STR(bpy_intern_str_bpy_types, "bpy.types");
 	BPY_INTERN_STR(bpy_intern_str_frame, "frame");
 	BPY_INTERN_STR(bpy_intern_str_order, "order");
diff --git a/source/blender/python/intern/bpy_intern_string.h b/source/blender/python/intern/bpy_intern_string.h
index 66c469f70bc..998c312c321 100644
--- a/source/blender/python/intern/bpy_intern_string.h
+++ b/source/blender/python/intern/bpy_intern_string.h
@@ -38,6 +38,7 @@ extern PyObject *bpy_intern_str___slots__;
 extern PyObject *bpy_intern_str_attr;
 extern PyObject *bpy_intern_str_bl_property;
 extern PyObject *bpy_intern_str_bl_rna;
+extern PyObject *bpy_intern_str_bl_target_properties;
 extern PyObject *bpy_intern_str_bpy_types;
 extern PyObject *bpy_intern_str_frame;
 extern PyObject *bpy_intern_str_order;
diff --git a/source/blender/python/intern/bpy_manipulator_wrap.c b/source/blender/python/intern/bpy_manipulator_wrap.c
index 19af5ce624d..f8dd5232dbb 100644
--- a/source/blender/python/intern/bpy_manipulator_wrap.c
+++ b/source/blender/python/intern/bpy_manipulator_wrap.c
@@ -39,6 +39,7 @@
 
 #include "RNA_access.h"
 #include "RNA_define.h"
+#include "RNA_enum_types.h"
 
 #include "bpy_rna.h"
 #include "bpy_intern_string.h"
@@ -52,6 +53,64 @@
  * \{ */
 
 
+static bool bpy_manipulatortype_target_property_def(
+        wmManipulatorType *wt, PyObject *item)
+{
+	/* Note: names based on 'rna_rna.c' */
+	PyObject *empty_tuple = PyTuple_New(0);
+	static const char * const _keywords[] = {"id", "type", "array_length", NULL};
+	static _PyArg_Parser _parser = {"|$ssi:register_class", _keywords, 0};
+
+	struct {
+		char *id;
+		char *type_id; int type;
+		int array_length;
+	} args = {
+		.id = NULL, /* not optional */
+		.type = PROP_FLOAT,
+		.type_id = NULL,
+		.array_length = 1,
+	};
+
+	if (!_PyArg_ParseTupleAndKeywordsFast(
+	        empty_tuple, item,
+	        &_parser,
+	        &args.id,
+	        &args.type_id,
+	        &args.array_length))
+	{
+		goto fail;
+	}
+
+	if (args.id == NULL) {
+		PyErr_SetString(PyExc_ValueError, "'id' argument not given");
+		goto fail;
+	}
+
+	if ((args.type_id != NULL) &&
+	    pyrna_enum_value_from_id(
+	        rna_enum_property_type_items, args.type_id, &args.type, "'type' enum value") == -1)
+	{
+		goto fail;
+	}
+	else {
+		args.type = rna_enum_property_type_items[args.type].value;
+	}
+
+	if ((args.array_length < 1 || args.array_length > RNA_MAX_ARRAY_LENGTH)) {
+		PyErr_SetString(PyExc_ValueError, "'array_length' out of range");
+		goto fail;
+	}
+
+	WM_manipulatortype_target_property_def(wt, args.id, args.type, args.array_length);
+	Py_DECREF(empty_tuple);
+	return true;
+
+fail:
+	Py_DECREF(empty_tuple);
+	return false;
+}
+
 static void manipulator_properties_init(wmManipulatorType *wt)
 {
 	PyTypeObject *py_class = wt->ext.data;
@@ -66,6 +125,35 @@ static void manipulator_properties_init(wmManipulatorType *wt)
 		PyErr_Print(); /* failed to register operator props */
 		PyErr_Clear();
 	}
+
+	/* Extract target property definitions from 'bl_target_properties' */
+	{
+		/* picky developers will notice that 'bl_targets' won't work with inheritance
+		 * get direct from the dict to avoid raising a load of attribute errors (yes this isnt ideal) - campbell */
+		PyObject *py_class_dict = py_class->tp_dict;
+		PyObject *bl_target_properties = PyDict_GetItem(py_class_dict, bpy_intern_str_bl_target_properties);
+		PyObject *bl_target_properties_fast;
+
+		if (!(bl_target_properties_fast = PySequence_Fast(bl_target_properties, "bl_target_properties sequence"))) {
+			/* PySequence_Fast sets the error */
+			PyErr_Print();
+			PyErr_Clear();
+			return;
+		}
+
+		const uint items_len = PySequence_Fast_GET_SIZE(bl_target_properties_fast);
+		PyObject **items = PySequence_Fast_ITEMS(bl_target_properties_fast);
+
+		for (uint i = 0; i < items_len; i++) {
+			if (!bpy_manipulatortype_target_property_def(wt, items[i])) {
+				PyErr_Print();
+				PyErr_Clear();
+				break;
+			}
+		}
+
+		Py_DECREF(bl_target_properties_fast);
+	}
 }
 
 void BPY_RNA_manipulator_wrapper(wmManipulatorType *wt, void *userdata)
diff --git a/source/blender/windowmanager/manipulators/WM_manipulator_api.h b/source/blender/windowmanager/manipulators/WM_manipulator_api.h
index 6a5c2aeef71..5766f9f8050 100644
--- a/source/blender/windowmanager/manipulators/WM_manipulator_api.h
+++ b/source/blender/windowmanager/manipulators/WM_manipulator_api.h
@@ -161,6 +161,13 @@ void WM_manipulator_target_property_range_get(
         const struct wmManipulator *mpr, struct wmManipulatorProperty *mpr_prop,
         float range[2]);
 
+/* definitions */
+struct wmManipulatorPropertyType *WM_manipulatortype_target_property_find(
+        struct wmManipulatorType *wt, const char *idname);
+void WM_manipulatortype_target_property_def(
+        struct wmManipulatorType *wt, const char *idname, int type, int array_length)

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list