Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-03-11 07:18:14 +0300
committerCampbell Barton <campbell@blender.org>2022-03-11 07:21:30 +0300
commitd2222d5b2cac203f4ddaae5c99b96701587231e7 (patch)
tree014e61e54c579bda925b7843cb6460a20b30a611
parent8cc5483331d1a3d5c6eba055ae303788ba843526 (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.
-rw-r--r--release/scripts/startup/bl_ui/properties_data_curve.py21
-rw-r--r--source/blender/makesrna/intern/rna_curve.c44
-rw-r--r--source/blender/makesrna/intern/rna_curve_api.c49
3 files changed, 59 insertions, 55 deletions
diff --git a/release/scripts/startup/bl_ui/properties_data_curve.py b/release/scripts/startup/bl_ui/properties_data_curve.py
index 2ad6e5bae8a..d6e21053e3b 100644
--- a/release/scripts/startup/bl_ui/properties_data_curve.py
+++ b/release/scripts/startup/bl_ui/properties_data_curve.py
@@ -321,17 +321,16 @@ class DATA_PT_active_spline(CurveButtonsPanelActive, Panel):
layout.prop(act_spline, "use_smooth")
if act_spline.type == 'NURBS':
- messages = [act_spline.valid_message_u]
- if is_surf and act_spline.point_count_v > 1:
- messages.append(act_spline.valid_message_v)
-
- messages = list(filter(None, messages))
-
- if len(messages) > 0:
- layout.separator()
- col = layout.column(align=True)
- for message in messages:
- col.label(text=message, icon='INFO')
+ col = None
+ for direction in range(2):
+ message = act_spline.valid_message(direction)
+ if not message:
+ continue
+ if col is None:
+ layout.separator()
+ col = layout.column(align=True)
+ col.label(text=message, icon='INFO')
+ del col
class DATA_PT_font(CurveButtonsPanelText, Panel):
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