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.
This commit is contained in:
parent
8cc5483331
commit
d2222d5b2c
Notes:
blender-bot
2023-02-14 03:03:03 +01:00
Referenced by commitcf58648409
, Correct error ind2222d5b2c
|
@ -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):
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue