diff options
author | Campbell Barton <campbell@blender.org> | 2022-03-11 07:18:14 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-03-11 07:21:30 +0300 |
commit | d2222d5b2cac203f4ddaae5c99b96701587231e7 (patch) | |
tree | 014e61e54c579bda925b7843cb6460a20b30a611 /source/blender/makesrna | |
parent | 8cc5483331d1a3d5c6eba055ae303788ba843526 (diff) |
RNA: use a function to access the nurbs error message
It makes more sense to use a function in this case as this
creates an error message which is not data associated with
the NURBS curve.
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r-- | source/blender/makesrna/intern/rna_curve.c | 44 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_curve_api.c | 49 |
2 files changed, 49 insertions, 44 deletions
diff --git a/source/blender/makesrna/intern/rna_curve.c b/source/blender/makesrna/intern/rna_curve.c index 2c1ed483de6..fb911725836 100644 --- a/source/blender/makesrna/intern/rna_curve.c +++ b/source/blender/makesrna/intern/rna_curve.c @@ -562,38 +562,6 @@ static void rna_Curve_offset_set(PointerRNA *ptr, float value) cu->offset = 1.0f + value; } -static int rna_Nurb_valid_message_u_length(PointerRNA *ptr) -{ - char buff[64]; - Nurb *nu = (Nurb *)ptr->data; - BKE_nurb_valid_message( - nu->pntsu, nu->orderu, nu->flagu, nu->type, nu->pntsv > 1, "U", buff, sizeof(buff)); - return strlen(buff); -} - -static void rna_Nurb_valid_message_u(PointerRNA *ptr, char *value) -{ - Nurb *nu = (Nurb *)ptr->data; - BKE_nurb_valid_message( - nu->pntsu, nu->orderu, nu->flagu, nu->type, nu->pntsv > 1, "U", value, 64); -} - -static int rna_Nurb_valid_message_v_length(PointerRNA *ptr) -{ - char buff[64]; - Nurb *nu = (Nurb *)ptr->data; - BKE_nurb_valid_message( - nu->pntsv, nu->orderv, nu->flagv, nu->type, nu->pntsv > 1, "V", buff, sizeof(buff)); - return strlen(buff); -} - -static void rna_Nurb_valid_message_v(PointerRNA *ptr, char *value) -{ - Nurb *nu = (Nurb *)ptr->data; - BKE_nurb_valid_message( - nu->pntsv, nu->orderv, nu->flagv, nu->type, nu->pntsv > 1, "V", value, 64); -} - static int rna_Curve_body_length(PointerRNA *ptr); static void rna_Curve_body_get(PointerRNA *ptr, char *value) { @@ -2059,18 +2027,6 @@ static void rna_def_curve_nurb(BlenderRNA *brna) prop, "Bezier V", "Make this nurbs surface act like a Bezier spline in the V direction"); RNA_def_property_update(prop, 0, "rna_Nurb_update_knot_v"); - prop = RNA_def_property(srna, "valid_message_u", PROP_STRING, PROP_NONE); - RNA_def_property_clear_flag(prop, PROP_EDITABLE); - RNA_def_property_string_funcs( - prop, "rna_Nurb_valid_message_u", "rna_Nurb_valid_message_u_length", NULL); - RNA_def_property_ui_text(prop, "Valid U", "Validation message for NURBS definition in U"); - - prop = RNA_def_property(srna, "valid_message_v", PROP_STRING, PROP_NONE); - RNA_def_property_clear_flag(prop, PROP_EDITABLE); - RNA_def_property_string_funcs( - prop, "rna_Nurb_valid_message_v", "rna_Nurb_valid_message_v_length", NULL); - RNA_def_property_ui_text(prop, "Valid V", "Validation message for NURBS definition in V"); - prop = RNA_def_property(srna, "use_smooth", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", CU_SMOOTH); RNA_def_property_ui_text(prop, "Smooth", "Smooth the normals of the surface or beveled curve"); diff --git a/source/blender/makesrna/intern/rna_curve_api.c b/source/blender/makesrna/intern/rna_curve_api.c index d0086a425a2..72c1182ada1 100644 --- a/source/blender/makesrna/intern/rna_curve_api.c +++ b/source/blender/makesrna/intern/rna_curve_api.c @@ -36,6 +36,39 @@ static float rna_Nurb_calc_length(Nurb *nu, int resolution_u) return BKE_nurb_calc_length(nu, resolution_u); } +static void rna_Nurb_valid_message(Nurb *nu, int direction, int *result_len, const char **r_result) +{ + const bool is_surf = nu->pntsv > 1; + const short type = nu->type; + + int pnts; + short order, flag; + const char *dir; + if (direction) { + pnts = nu->pntsu; + order = nu->orderu; + flag = nu->flagu; + dir = "U"; + } + else { + pnts = nu->pntsv; + order = nu->orderv; + flag = nu->flagv; + dir = "V"; + } + + char buf[64]; + if (BKE_nurb_valid_message(pnts, order, flag, type, is_surf, dir, buf, sizeof(buf))) { + const int buf_len = strlen(buf); + *r_result = BLI_strdupn(buf, buf_len); + *result_len = buf_len; + } + else { + *r_result = NULL; + *result_len = 0; + } +} + #else void RNA_api_curve(StructRNA *srna) @@ -86,6 +119,22 @@ void RNA_api_curve_nurb(StructRNA *srna) 0.0f, FLT_MAX); RNA_def_function_return(func, parm); + + func = RNA_def_function(srna, "valid_message", "rna_Nurb_valid_message"); + RNA_def_function_ui_description(func, "Return the message"); + parm = RNA_def_int( + func, "direction", 0, 0, 1, "Direction", "The direction where 0-1 maps to U-V", 0, 1); + RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); + /* return value */ + parm = RNA_def_string(func, + "result", + "nothing", + 64, + "Return value", + "The message or an empty string when there is no error"); + + RNA_def_parameter_flags(parm, PROP_DYNAMIC, PARM_OUTPUT); + RNA_def_property_clear_flag(parm, PROP_NEVER_NULL); } #endif |