[Bf-blender-cvs] [18bcd8321a6] master: Curves: show warning when using Add brush without surface

Jacques Lucke noreply at git.blender.org
Thu May 5 12:24:36 CEST 2022


Commit: 18bcd8321a68832d01a0fedeed38b80767f70a64
Author: Jacques Lucke
Date:   Thu May 5 12:24:08 2022 +0200
Branches: master
https://developer.blender.org/rB18bcd8321a68832d01a0fedeed38b80767f70a64

Curves: show warning when using Add brush without surface

===================================================================

M	source/blender/editors/sculpt_paint/curves_sculpt_add.cc
M	source/blender/editors/sculpt_paint/curves_sculpt_intern.hh
M	source/blender/editors/sculpt_paint/curves_sculpt_ops.cc

===================================================================

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<CurvesSculptStrokeOperation> new_add_operation()
+std::unique_ptr<CurvesSculptStrokeOperation> 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<Curves *>(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<AddOperation>();
 }
 
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<CurvesSculptStrokeOperation> new_add_operation();
+std::unique_ptr<CurvesSculptStrokeOperation> new_add_operation(bContext &C, ReportList *reports);
 std::unique_ptr<CurvesSculptStrokeOperation> new_comb_operation();
 std::unique_ptr<CurvesSculptStrokeOperation> new_delete_operation();
 std::unique_ptr<CurvesSculptStrokeOperation> 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<CurvesSculptStrokeOperation> start_brush_operation(bContext *C,
-                                                                          wmOperator *op)
+static std::unique_ptr<CurvesSculptStrokeOperation> start_brush_operation(bContext &C,
+                                                                          wmOperator &op)
 {
-  const BrushStrokeMode mode = static_cast<BrushStrokeMode>(RNA_enum_get(op->ptr, "mode"));
+  const BrushStrokeMode mode = static_cast<BrushStrokeMode>(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<CurvesSculptStrokeOperation> 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;



More information about the Bf-blender-cvs mailing list