Commit: e8a04a5a18f76c1ebea570af5aacb43da3d47ddc
Author: Campbell Barton
Date:   Thu Jun 22 07:49:24 2017 +1000
Branches: custom-manipulators
https://developer.blender.org/rBe8a04a5a18f76c1ebea570af5aacb43da3d47ddc

PyAPI: Add Manipulator.target_prop_set_property

RNA method for Python to call into C or Py defined manipulators.
naming might change.

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

M       source/blender/makesrna/intern/rna_wm_manipulator_api.c
M       source/blender/windowmanager/manipulators/WM_manipulator_api.h
M       
source/blender/windowmanager/manipulators/intern/wm_manipulator_target_props.c

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

diff --git a/source/blender/makesrna/intern/rna_wm_manipulator_api.c 
b/source/blender/makesrna/intern/rna_wm_manipulator_api.c
index dd678a278d1..c413eff76b7 100644
--- a/source/blender/makesrna/intern/rna_wm_manipulator_api.c
+++ b/source/blender/makesrna/intern/rna_wm_manipulator_api.c
@@ -69,6 +69,70 @@ static void rna_manipulator_draw_preset_facemap(
        ED_manipulator_draw_preset_facemap(mpr, scene, ob, facemap, select_id);
 }
 
+static void rna_manipulator_target_prop_set_property(
+        wmManipulator *mpr, ReportList *reports, const char *target_propname,
+        PointerRNA *ptr, const char *propname, int index)
+{
+       const wmManipulatorPropertyType *mpr_prop_type =
+               WM_manipulatortype_target_property_find(mpr->type, 
target_propname);
+       if (mpr_prop_type == NULL) {
+               BKE_reportf(reports, RPT_ERROR, "Manipulator target property 
'%s.%s' not found",
+                           mpr->type->idname, target_propname);
+               return;
+       }
+
+       PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
+       if (prop == NULL) {
+               BKE_reportf(reports, RPT_ERROR, "Property '%s.%s' not found",
+                           RNA_struct_identifier(ptr->type), target_propname);
+               return;
+       }
+
+       if (mpr_prop_type->type != RNA_property_type(prop)) {
+               const int manipulator_type_index = 
RNA_enum_from_value(rna_enum_property_type_items, mpr_prop_type->type);
+               const int prop_type_index = 
RNA_enum_from_value(rna_enum_property_type_items, RNA_property_type(prop));
+               BLI_assert((manipulator_type_index != -1) && (prop_type_index 
== -1));
+
+               BKE_reportf(reports, RPT_ERROR, "Manipulator target '%s.%s' 
expects '%s', '%s.%s' is '%s'",
+                           mpr->type->idname, target_propname,
+                           
rna_enum_property_type_items[manipulator_type_index].identifier,
+                           RNA_struct_identifier(ptr->type), propname,
+                           
rna_enum_property_type_items[prop_type_index].identifier);
+               return;
+       }
+
+       if (RNA_property_array_check(prop)) {
+               if (index == -1) {
+                       const int prop_array_length = 
RNA_property_array_length(ptr, prop);
+                       if (mpr_prop_type->array_length != prop_array_length) {
+                               BKE_reportf(reports, RPT_ERROR,
+                                           "Manipulator target property 
'%s.%s' expects an array of length %d, found %d",
+                                           mpr->type->idname, target_propname,
+                                           mpr_prop_type->array_length,
+                                           prop_array_length);
+                               return;
+                       }
+               }
+       }
+       else {
+               if (mpr_prop_type->array_length != 1) {
+                       BKE_reportf(reports, RPT_ERROR,
+                                   "Manipulator target property '%s.%s' 
expects an array of length %d",
+                                   mpr->type->idname, target_propname,
+                                   mpr_prop_type->array_length);
+                       return;
+               }
+       }
+
+       if (index >= mpr_prop_type->array_length) {
+               BKE_reportf(reports, RPT_ERROR, "Manipulator target property 
'%s.%s', index %d must be below %d",
+                           mpr->type->idname, target_propname, index, 
mpr_prop_type->array_length);
+               return;
+       }
+
+       WM_manipulator_target_property_def_rna_ptr(mpr, mpr_prop_type, ptr, 
prop, index);
+}
+
 #else
 
 void RNA_api_manipulator(StructRNA *srna)
@@ -124,6 +188,22 @@ void RNA_api_manipulator(StructRNA *srna)
        RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
        RNA_def_int(func, "facemap", 0, 0, INT_MAX, "Face map index", "", 0, 
INT_MAX);
        RNA_def_int(func, "select_id", -1, -1, INT_MAX, "Zero when not 
selecting", "", -1, INT_MAX);
+
+
+       /* -------------------------------------------------------------------- 
*/
+       /* Property API */
+
+       func = RNA_def_function(srna, "target_prop_set_property", 
"rna_manipulator_target_prop_set_property");
+       RNA_def_function_flag(func, FUNC_USE_REPORTS);
+       RNA_def_function_ui_description(func, "");
+       parm = RNA_def_string(func, "target_property", NULL, 0, "", "Target 
property");
+       RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+       /* similar to UILayout.prop */
+       parm = RNA_def_pointer(func, "data", "AnyType", "", "Data from which to 
take property");
+       RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | 
PARM_RNAPTR);
+       parm = RNA_def_string(func, "property", NULL, 0, "", "Identifier of 
property in data");
+       RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+       RNA_def_int(func, "index", -1, -1, INT_MAX, "", "", -1, INT_MAX); /* 
RNA_NO_INDEX == -1 */
 }
 
 
diff --git a/source/blender/windowmanager/manipulators/WM_manipulator_api.h 
b/source/blender/windowmanager/manipulators/WM_manipulator_api.h
index 5766f9f8050..e63e27372eb 100644
--- a/source/blender/windowmanager/manipulators/WM_manipulator_api.h
+++ b/source/blender/windowmanager/manipulators/WM_manipulator_api.h
@@ -39,9 +39,11 @@
 struct ARegion;
 struct GHashIterator;
 struct Main;
+struct PropertyRNA;
 struct wmKeyConfig;
 struct wmManipulator;
 struct wmManipulatorProperty;
+struct wmManipulatorPropertyType;
 struct wmManipulatorType;
 struct wmManipulatorGroup;
 struct wmManipulatorGroupType;
@@ -135,9 +137,16 @@ void WM_manipulatorconfig_update(struct Main *bmain);
 struct wmManipulatorProperty *WM_manipulator_target_property_find(
         struct wmManipulator *mpr, const char *idname);
 
+void WM_manipulator_target_property_def_rna_ptr(
+        struct wmManipulator *mpr, const struct wmManipulatorPropertyType 
*mpr_prop_type,
+        struct PointerRNA *ptr, struct PropertyRNA *prop, int index);
 void WM_manipulator_target_property_def_rna(
         struct wmManipulator *mpr, const char *idname,
         struct PointerRNA *ptr, const char *propname, int index);
+
+void WM_manipulator_target_property_def_func_ptr(
+        struct wmManipulator *mpr, const struct wmManipulatorPropertyType 
*mpr_prop_type,
+        const struct wmManipulatorPropertyFnParams *params);
 void WM_manipulator_target_property_def_func(
         struct wmManipulator *mpr, const char *idname,
         const struct wmManipulatorPropertyFnParams *params);
@@ -162,8 +171,8 @@ void WM_manipulator_target_property_range_get(
         float range[2]);
 
 /* definitions */
-struct wmManipulatorPropertyType *WM_manipulatortype_target_property_find(
-        struct wmManipulatorType *wt, const char *idname);
+const struct wmManipulatorPropertyType 
*WM_manipulatortype_target_property_find(
+        const struct wmManipulatorType *wt, const char *idname);
 void WM_manipulatortype_target_property_def(
         struct wmManipulatorType *wt, const char *idname, int type, int 
array_length);
 
diff --git 
a/source/blender/windowmanager/manipulators/intern/wm_manipulator_target_props.c
 
b/source/blender/windowmanager/manipulators/intern/wm_manipulator_target_props.c
index b9897b32f44..b629213b11b 100644
--- 
a/source/blender/windowmanager/manipulators/intern/wm_manipulator_target_props.c
+++ 
b/source/blender/windowmanager/manipulators/intern/wm_manipulator_target_props.c
@@ -59,30 +59,30 @@ wmManipulatorProperty 
*WM_manipulator_target_property_find(wmManipulator *mpr, c
 }
 
 static wmManipulatorProperty *wm_manipulator_target_property_def_internal(
-        wmManipulator *mpr, const char *idname)
+        wmManipulator *mpr, const wmManipulatorPropertyType *mpr_prop_type)
 {
-       wmManipulatorProperty *mpr_prop = 
WM_manipulator_target_property_find(mpr, idname);
+       wmManipulatorProperty *mpr_prop = 
WM_manipulator_target_property_find(mpr, mpr_prop_type->idname);
 
        if (mpr_prop == NULL) {
-               const uint idname_size = strlen(idname) + 1;
+               const uint idname_size = strlen(mpr_prop_type->idname) + 1;
                mpr_prop = MEM_callocN(sizeof(wmManipulatorProperty) + 
idname_size, __func__);
-               memcpy(mpr_prop->idname, idname, idname_size);
+               memcpy(mpr_prop->idname, mpr_prop_type->idname, idname_size);
                BLI_addtail(&mpr->target_properties, mpr_prop);
        }
        return mpr_prop;
 }
 
-void WM_manipulator_target_property_def_rna(
-        wmManipulator *mpr, const char *idname,
-        PointerRNA *ptr, const char *propname, int index)
+void WM_manipulator_target_property_def_rna_ptr(
+        wmManipulator *mpr, const wmManipulatorPropertyType *mpr_prop_type,
+        PointerRNA *ptr, PropertyRNA *prop, int index)
 {
-       wmManipulatorProperty *mpr_prop = 
wm_manipulator_target_property_def_internal(mpr, idname);
+       wmManipulatorProperty *mpr_prop = 
wm_manipulator_target_property_def_internal(mpr, mpr_prop_type);
 
        /* if manipulator evokes an operator we cannot use it for property 
manipulation */
        mpr->op_data.type = NULL;
 
        mpr_prop->ptr = *ptr;
-       mpr_prop->prop = RNA_struct_find_property(ptr, propname);
+       mpr_prop->prop = prop;
        mpr_prop->index = index;
 
        if (mpr->type->property_update) {
@@ -90,11 +90,20 @@ void WM_manipulator_target_property_def_rna(
        }
 }
 
-void WM_manipulator_target_property_def_func(
+void WM_manipulator_target_property_def_rna(
         wmManipulator *mpr, const char *idname,
+        PointerRNA *ptr, const char *propname, int index)
+{
+       const wmManipulatorPropertyType *mpr_prop_type = 
WM_manipulatortype_target_property_find(mpr->type, idname);
+       PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
+       WM_manipulator_target_property_def_rna_ptr(mpr, mpr_prop_type, ptr, 
prop, index);
+}
+
+void WM_manipulator_target_property_def_func_ptr(
+        wmManipulator *mpr, const wmManipulatorPropertyType *mpr_prop_type,
         const wmManipulatorPropertyFnParams *params)
 {
-       wmManipulatorProperty *mpr_prop = 
wm_manipulator_target_property_def_internal(mpr, idname);
+       wmManipulatorProperty *mpr_prop = 
wm_manipulator_target_property_def_internal(mpr, mpr_prop_type);
 
        /* if manipulator evokes an operator we cannot use it for property 
manipulation */
        mpr->op_data.type = NULL;
@@ -109,6 +118,14 @@ void WM_manipulator_target_property_def_func(
        }
 }
 
+void WM_manipulator_target_property_def_func(
+        wmManipulator *mpr, const char *idname,
+        const wmManipulatorPropertyFnParams *params)
+{
+       const wmManipulatorPropertyType *mpr_prop_type = 
WM_manipulatortype_target_property_find(mpr->type, idname);
+       WM_manipulator_target_property_def_func_ptr(mpr, mpr_prop_type, params);
+}
+
 /** \} */
 
 
@@ -208,8 +225,8 @@ void WM_manipulator_target_property_range_get(
 /** \name Property Define
  * \{ */
 
-wmManipulatorPropertyType *WM_manipulatortype_target_property_find(
-        wmManipulatorType *wt, const char *idname)
+const wmManipulatorPropertyType *WM_manipulatortype_target

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to