From 6067fa682b0c70778f614ab68af20455befe5a76 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 1 Oct 2013 02:51:39 +0000 Subject: de-duplicate report strings for freestyle error checks --- source/blender/editors/render/render_shading.c | 67 ++++++++++---------------- 1 file changed, 25 insertions(+), 42 deletions(-) (limited to 'source/blender/editors/render') diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c index c19c5a38517..d04639f95e7 100644 --- a/source/blender/editors/render/render_shading.c +++ b/source/blender/editors/render/render_shading.c @@ -588,6 +588,20 @@ void SCENE_OT_render_layer_remove(wmOperatorType *ot) #ifdef WITH_FREESTYLE +static bool freestyle_linestyle_check_report(FreestyleLineSet *lineset, ReportList *reports) +{ + if (!lineset) { + BKE_report(reports, RPT_ERROR, "No active lineset and associated line style to add the modifier to"); + return false; + } + if (!lineset->linestyle) { + BKE_report(reports, RPT_ERROR, "The active lineset does not have a line style (indicating data corruption)"); + return false; + } + + return true; +} + static int freestyle_active_module_poll(bContext *C) { PointerRNA ptr = CTX_data_pointer_get_type(C, "freestyle_module", &RNA_FreestyleModuleSettings); @@ -894,14 +908,10 @@ static int freestyle_color_modifier_add_exec(bContext *C, wmOperator *op) FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&srl->freestyleConfig); int type = RNA_enum_get(op->ptr, "type"); - if (!lineset) { - BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style to add the modifier to"); - return OPERATOR_CANCELLED; - } - if (!lineset->linestyle) { - BKE_report(op->reports, RPT_ERROR, "The active lineset does not have a line style (indicating data corruption)"); + if (!freestyle_linestyle_check_report(lineset, op->reports)) { return OPERATOR_CANCELLED; } + if (BKE_add_linestyle_color_modifier(lineset->linestyle, type) == NULL) { BKE_report(op->reports, RPT_ERROR, "Unknown line color modifier type"); return OPERATOR_CANCELLED; @@ -937,14 +947,10 @@ static int freestyle_alpha_modifier_add_exec(bContext *C, wmOperator *op) FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&srl->freestyleConfig); int type = RNA_enum_get(op->ptr, "type"); - if (!lineset) { - BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style to add the modifier to"); - return OPERATOR_CANCELLED; - } - if (!lineset->linestyle) { - BKE_report(op->reports, RPT_ERROR, "The active lineset does not have a line style (indicating data corruption)"); + if (!freestyle_linestyle_check_report(lineset, op->reports)) { return OPERATOR_CANCELLED; } + if (BKE_add_linestyle_alpha_modifier(lineset->linestyle, type) == NULL) { BKE_report(op->reports, RPT_ERROR, "Unknown alpha transparency modifier type"); return OPERATOR_CANCELLED; @@ -980,14 +986,10 @@ static int freestyle_thickness_modifier_add_exec(bContext *C, wmOperator *op) FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&srl->freestyleConfig); int type = RNA_enum_get(op->ptr, "type"); - if (!lineset) { - BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style to add the modifier to"); - return OPERATOR_CANCELLED; - } - if (!lineset->linestyle) { - BKE_report(op->reports, RPT_ERROR, "The active lineset does not have a line style (indicating data corruption)"); + if (!freestyle_linestyle_check_report(lineset, op->reports)) { return OPERATOR_CANCELLED; } + if (BKE_add_linestyle_thickness_modifier(lineset->linestyle, type) == NULL) { BKE_report(op->reports, RPT_ERROR, "Unknown line thickness modifier type"); return OPERATOR_CANCELLED; @@ -1023,14 +1025,10 @@ static int freestyle_geometry_modifier_add_exec(bContext *C, wmOperator *op) FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&srl->freestyleConfig); int type = RNA_enum_get(op->ptr, "type"); - if (!lineset) { - BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style to add the modifier to"); - return OPERATOR_CANCELLED; - } - if (!lineset->linestyle) { - BKE_report(op->reports, RPT_ERROR, "The active lineset does not have a line style (indicating data corruption)"); + if (!freestyle_linestyle_check_report(lineset, op->reports)) { return OPERATOR_CANCELLED; } + if (BKE_add_linestyle_geometry_modifier(lineset->linestyle, type) == NULL) { BKE_report(op->reports, RPT_ERROR, "Unknown stroke geometry modifier type"); return OPERATOR_CANCELLED; @@ -1080,12 +1078,7 @@ static int freestyle_modifier_remove_exec(bContext *C, wmOperator *op) PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", &RNA_LineStyleModifier); LineStyleModifier *modifier = ptr.data; - if (!lineset) { - BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style the modifier belongs to"); - return OPERATOR_CANCELLED; - } - if (!lineset->linestyle) { - BKE_report(op->reports, RPT_ERROR, "The active lineset does not have a line style (indicating data corruption)"); + if (!freestyle_linestyle_check_report(lineset, op->reports)) { return OPERATOR_CANCELLED; } @@ -1134,12 +1127,7 @@ static int freestyle_modifier_copy_exec(bContext *C, wmOperator *op) PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", &RNA_LineStyleModifier); LineStyleModifier *modifier = ptr.data; - if (!lineset) { - BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style the modifier belongs to"); - return OPERATOR_CANCELLED; - } - if (!lineset->linestyle) { - BKE_report(op->reports, RPT_ERROR, "The active lineset does not have a line style (indicating data corruption)"); + if (!freestyle_linestyle_check_report(lineset, op->reports)) { return OPERATOR_CANCELLED; } @@ -1189,12 +1177,7 @@ static int freestyle_modifier_move_exec(bContext *C, wmOperator *op) LineStyleModifier *modifier = ptr.data; int dir = RNA_enum_get(op->ptr, "direction"); - if (!lineset) { - BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style the modifier belongs to"); - return OPERATOR_CANCELLED; - } - if (!lineset->linestyle) { - BKE_report(op->reports, RPT_ERROR, "The active lineset does not have a line style (indicating data corruption)"); + if (!freestyle_linestyle_check_report(lineset, op->reports)) { return OPERATOR_CANCELLED; } -- cgit v1.2.3