[Bf-blender-cvs] [aaf53a05125] soc-2021-knife-tools: Knife: Added show measurements RNA toggle

Cian Jinks noreply at git.blender.org
Tue Aug 10 21:20:00 CEST 2021


Commit: aaf53a05125cb1a37ef560ee6080d607a6d6bdde
Author: Cian Jinks
Date:   Tue Aug 10 20:18:25 2021 +0100
Branches: soc-2021-knife-tools
https://developer.blender.org/rBaaf53a05125cb1a37ef560ee6080d607a6d6bdde

Knife: Added show measurements RNA toggle

Adds an RNA setting to enable visible distance and angle measurements by default for the knife tool.
Fixes compiler warnings as well.

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

M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M	source/blender/editors/mesh/editmesh_knife.c

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

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index ca52746d80a..b79b7a670c0 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -4732,9 +4732,9 @@ def km_mesh(params):
         ("mesh.dissolve_mode", {"type": 'X', "value": 'PRESS', "ctrl": True}, None),
         ("mesh.dissolve_mode", {"type": 'DEL', "value": 'PRESS', "ctrl": True}, None),
         ("mesh.knife_tool", {"type": 'K', "value": 'PRESS'},
-         {"properties": [("use_occlude_geometry", True), ("only_selected", False), ("angle_snapping_increment", 30.0)]}),
+         {"properties": [("use_occlude_geometry", True), ("only_selected", False), ("visible_measurements", False), ("angle_snapping_increment", 30.0)]}),
         ("mesh.knife_tool", {"type": 'K', "value": 'PRESS', "shift": True},
-         {"properties": [("use_occlude_geometry", False), ("only_selected", True), ("angle_snapping_increment", 30.0)]}),
+         {"properties": [("use_occlude_geometry", False), ("only_selected", True), ("visible_measurements", False), ("angle_snapping_increment", 30.0)]}),
         ("object.vertex_parent_set", {"type": 'P', "value": 'PRESS', "ctrl": True}, None),
         # Menus.
         op_menu("VIEW3D_MT_edit_mesh_faces", {"type": 'F', "value": 'PRESS', "ctrl": True}),
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 56639557f67..0feb3dd3085 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -1087,6 +1087,7 @@ class _defs_edit_mesh:
                     extra = True
             if extra:
                 layout.use_property_split = True
+                layout.prop(props, "visible_measurements")
                 layout.label(text="Angle Snapping")
                 layout.row().prop(props, "angle_snapping_increment", text="", expand=True)
             if show_extra:
diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c
index e710bc14c65..a65888155bb 100644
--- a/source/blender/editors/mesh/editmesh_knife.c
+++ b/source/blender/editors/mesh/editmesh_knife.c
@@ -1349,8 +1349,7 @@ static BMFace *knife_bvh_raycast(KnifeTool_OpData *kcd,
   hit.dist = dist;
   hit.index = -1;
 
-  int index = BLI_bvhtree_ray_cast(
-      kcd->bvh.tree, co, dir, radius, &hit, knife_bvh_raycast_cb, kcd);
+  BLI_bvhtree_ray_cast(kcd->bvh.tree, co, dir, radius, &hit, knife_bvh_raycast_cb, kcd);
 
   // Handle Hit
   if (hit.index != -1 && hit.dist != dist) {
@@ -1408,8 +1407,7 @@ static BMFace *knife_bvh_raycast_filter(
   hit.dist = dist;
   hit.index = -1;
 
-  int index = BLI_bvhtree_ray_cast(
-      kcd->bvh.tree, co, dir, radius, &hit, knife_bvh_raycast_cb, kcd);
+  BLI_bvhtree_ray_cast(kcd->bvh.tree, co, dir, radius, &hit, knife_bvh_raycast_cb, kcd);
 
   kcd->bvh.filter_cb = NULL;
   kcd->bvh.filter_data = NULL;
@@ -2834,7 +2832,6 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd)
 {
   SmallHash faces, kfes, kfvs;
   float v1[3], v2[3], v3[3], v4[3], s1[2], s2[2];
-  BVHTree *tree;
   int *results, *result;
   BMLoop **ls;
   BMFace *f;
@@ -3998,6 +3995,7 @@ static void knifetool_init(bContext *C,
                            KnifeTool_OpData *kcd,
                            const bool only_select,
                            const bool cut_through,
+                           const bool visible_measurements,
                            const float angle_snapping_increment,
                            const bool is_interactive)
 {
@@ -4033,6 +4031,8 @@ static void knifetool_init(bContext *C,
   kcd->is_interactive = is_interactive;
   kcd->cut_through = cut_through;
   kcd->only_select = only_select;
+  kcd->show_dist_angle = visible_measurements;
+  kcd->dist_angle_mode = (visible_measurements ? KNF_MEASUREMENT_BOTH : KNF_MEASUREMENT_NONE);
   kcd->angle_snapping_increment = angle_snapping_increment;
 
   kcd->arena = BLI_memarena_new(MEM_SIZE_OPTIMAL(1 << 15), "knife");
@@ -4647,6 +4647,7 @@ static int knifetool_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
   const bool only_select = RNA_boolean_get(op->ptr, "only_selected");
   const bool cut_through = !RNA_boolean_get(op->ptr, "use_occlude_geometry");
+  const bool visible_measurements = RNA_boolean_get(op->ptr, "visible_measurements");
   const bool wait_for_input = RNA_boolean_get(op->ptr, "wait_for_input");
   const float angle_snapping_increment = RAD2DEGF(
       RNA_float_get(op->ptr, "angle_snapping_increment"));
@@ -4656,6 +4657,12 @@ static int knifetool_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
   em_setup_viewcontext(C, &vc);
 
+  /* alloc new customdata */
+  kcd = op->customdata = MEM_callocN(sizeof(KnifeTool_OpData), __func__);
+
+  knifetool_init(
+      C, &vc, kcd, only_select, cut_through, visible_measurements, angle_snapping_increment, true);
+
   if (only_select) {
     Object *obedit;
     bool faces_selected = false;
@@ -4675,11 +4682,6 @@ static int knifetool_invoke(bContext *C, wmOperator *op, const wmEvent *event)
     }
   }
 
-  /* alloc new customdata */
-  kcd = op->customdata = MEM_callocN(sizeof(KnifeTool_OpData), __func__);
-
-  knifetool_init(C, &vc, kcd, only_select, cut_through, angle_snapping_increment, true);
-
   op->flag |= OP_IS_MODAL_CURSOR_REGION;
 
   /* Add a modal handler for this operator - handles loop selection. */
@@ -4729,6 +4731,11 @@ void MESH_OT_knife_tool(wmOperatorType *ot)
                   "Occlude Geometry",
                   "Only cut the front most geometry");
   RNA_def_boolean(ot->srna, "only_selected", false, "Only Selected", "Only cut selected geometry");
+  RNA_def_boolean(ot->srna,
+                  "visible_measurements",
+                  false,
+                  "Measurements",
+                  "Show visible distance and angle measurements");
   prop = RNA_def_float(ot->srna,
                        "angle_snapping_increment",
                        DEG2RADF(KNIFE_DEFAULT_ANGLE_SNAPPING_INCREMENT),
@@ -4781,11 +4788,19 @@ void EDBM_mesh_knife(bContext *C, ViewContext *vc, LinkNode *polys, bool use_tag
   {
     const bool only_select = false;
     const bool is_interactive = false; /* Can enable for testing. */
+    const bool visible_measurements = false;
     const float angle_snapping_increment = KNIFE_DEFAULT_ANGLE_SNAPPING_INCREMENT;
 
     kcd = MEM_callocN(sizeof(KnifeTool_OpData), __func__);
 
-    knifetool_init(C, vc, kcd, only_select, cut_through, angle_snapping_increment, is_interactive);
+    knifetool_init(C,
+                   vc,
+                   kcd,
+                   only_select,
+                   cut_through,
+                   visible_measurements,
+                   angle_snapping_increment,
+                   is_interactive);
 
     kcd->ignore_edge_snapping = true;
     kcd->ignore_vert_snapping = true;



More information about the Bf-blender-cvs mailing list