From 18bcd8321a68832d01a0fedeed38b80767f70a64 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Thu, 5 May 2022 12:24:08 +0200 Subject: Curves: show warning when using Add brush without surface --- source/blender/editors/sculpt_paint/curves_sculpt_add.cc | 11 ++++++++++- .../blender/editors/sculpt_paint/curves_sculpt_intern.hh | 2 +- source/blender/editors/sculpt_paint/curves_sculpt_ops.cc | 14 +++++++------- 3 files changed, 18 insertions(+), 9 deletions(-) (limited to 'source') diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_add.cc b/source/blender/editors/sculpt_paint/curves_sculpt_add.cc index 64dac56ecfb..1fdecf47bbd 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_add.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_add.cc @@ -21,6 +21,7 @@ #include "BKE_mesh.h" #include "BKE_mesh_runtime.h" #include "BKE_paint.h" +#include "BKE_report.h" #include "BKE_spline.hh" #include "DNA_brush_enums.h" @@ -836,8 +837,16 @@ void AddOperation::on_stroke_extended(bContext *C, const StrokeExtension &stroke executor.execute(*this, C, stroke_extension); } -std::unique_ptr new_add_operation() +std::unique_ptr new_add_operation(bContext &C, ReportList *reports) { + Object &ob_active = *CTX_data_active_object(&C); + BLI_assert(ob_active.type == OB_CURVES); + Curves &curves_id = *static_cast(ob_active.data); + if (curves_id.surface == nullptr || curves_id.surface->type != OB_MESH) { + BKE_report(reports, RPT_WARNING, "Can not use Add brush when there is no surface mesh"); + return {}; + } + return std::make_unique(); } diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_intern.hh b/source/blender/editors/sculpt_paint/curves_sculpt_intern.hh index b5835abecbd..9d000649d62 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_intern.hh +++ b/source/blender/editors/sculpt_paint/curves_sculpt_intern.hh @@ -33,7 +33,7 @@ class CurvesSculptStrokeOperation { virtual void on_stroke_extended(bContext *C, const StrokeExtension &stroke_extension) = 0; }; -std::unique_ptr new_add_operation(); +std::unique_ptr new_add_operation(bContext &C, ReportList *reports); std::unique_ptr new_comb_operation(); std::unique_ptr new_delete_operation(); std::unique_ptr new_snake_hook_operation(); diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc b/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc index 992ac77803a..d773b4e70a7 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc @@ -74,12 +74,12 @@ using blender::bke::CurvesGeometry; /** \name * SCULPT_CURVES_OT_brush_stroke * \{ */ -static std::unique_ptr start_brush_operation(bContext *C, - wmOperator *op) +static std::unique_ptr start_brush_operation(bContext &C, + wmOperator &op) { - const BrushStrokeMode mode = static_cast(RNA_enum_get(op->ptr, "mode")); + const BrushStrokeMode mode = static_cast(RNA_enum_get(op.ptr, "mode")); - Scene &scene = *CTX_data_scene(C); + Scene &scene = *CTX_data_scene(&C); CurvesSculpt &curves_sculpt = *scene.toolsettings->curves_sculpt; Brush &brush = *BKE_paint_brush(&curves_sculpt.paint); switch (brush.curves_sculpt_tool) { @@ -90,9 +90,9 @@ static std::unique_ptr start_brush_operation(bConte case CURVES_SCULPT_TOOL_SNAKE_HOOK: return new_snake_hook_operation(); case CURVES_SCULPT_TOOL_ADD: - return new_add_operation(); + return new_add_operation(C, op.reports); case CURVES_SCULPT_TOOL_GROW_SHRINK: - return new_grow_shrink_operation(mode, C); + return new_grow_shrink_operation(mode, &C); } BLI_assert_unreachable(); return {}; @@ -131,7 +131,7 @@ static void stroke_update_step(bContext *C, if (!op_data->operation) { stroke_extension.is_first = true; - op_data->operation = start_brush_operation(C, op); + op_data->operation = start_brush_operation(*C, *op); } else { stroke_extension.is_first = false; -- cgit v1.2.3