[Bf-blender-cvs] [d8fe0d04ffe] soc-2021-curves: Clean up: Refactored and commented

dilithjay noreply at git.blender.org
Wed Jun 9 20:23:12 CEST 2021


Commit: d8fe0d04ffef3b8c5f40f4c1e3f255eda19e815d
Author: dilithjay
Date:   Wed Jun 9 23:52:18 2021 +0530
Branches: soc-2021-curves
https://developer.blender.org/rBd8fe0d04ffef3b8c5f40f4c1e3f255eda19e815d

Clean up: Refactored and commented

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

M	release/datafiles/locale
M	release/scripts/addons
M	release/scripts/addons_contrib
M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M	source/blender/editors/curve/CMakeLists.txt
M	source/blender/editors/curve/curve_intern.h
M	source/blender/editors/curve/curve_ops.c
A	source/blender/editors/curve/editcurve_tool.c
M	source/tools

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

diff --git a/release/datafiles/locale b/release/datafiles/locale
index 2cef4877edc..4833954c0ac 160000
--- a/release/datafiles/locale
+++ b/release/datafiles/locale
@@ -1 +1 @@
-Subproject commit 2cef4877edc40875978c4e95322bb5193f5815bf
+Subproject commit 4833954c0ac85cc407e1d5a153aa11b1d1823ec0
diff --git a/release/scripts/addons b/release/scripts/addons
index 4fcdbfe7c20..f86f25e6221 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit 4fcdbfe7c20edfc1204c0aa46c98ea25354abcd9
+Subproject commit f86f25e62217264495d05f116ccb09d575fe9841
diff --git a/release/scripts/addons_contrib b/release/scripts/addons_contrib
index 7d78c8a63f2..5a82baad9f9 160000
--- a/release/scripts/addons_contrib
+++ b/release/scripts/addons_contrib
@@ -1 +1 @@
-Subproject commit 7d78c8a63f2f4b146f9327ddc0d567a5921b94ea
+Subproject commit 5a82baad9f986722104280e8354a4427d8e9eab1
diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index dbc7ce650a3..2e58783a86f 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -4276,6 +4276,7 @@ def km_curve(params):
         ("curve.dissolve_verts", {"type": 'X', "value": 'PRESS', "ctrl": True}, None),
         ("curve.dissolve_verts", {"type": 'DEL', "value": 'PRESS', "ctrl": True}, None),
         ("curve.tilt_clear", {"type": 'T', "value": 'PRESS', "alt": True}, None),
+        ("curve.edit", {"type": 'X', "value": 'PRESS', "alt": True}, None),
         ("transform.tilt", {"type": 'T', "value": 'PRESS', "ctrl": True}, None),
         ("transform.transform", {"type": 'S', "value": 'PRESS', "alt": True},
          {"properties": [("mode", 'CURVE_SHRINKFATTEN')]}),
@@ -6461,6 +6462,19 @@ def km_3d_view_tool_edit_curve_draw(params):
     )
 
 
+def km_3d_view_tool_edit_curve_edit(params):
+    return (
+        "3D View Tool: Edit Curve, Edit Curve",
+        {"space_type": 'VIEW_3D', "region_type": 'WINDOW'},
+        {"items": [
+            ("curve.edit", {"type": params.tool_mouse, "value": 'PRESS'},
+             {"properties": [("wait_for_input", False)]}),
+            ("curve.edit", {"type": params.tool_mouse, "value": 'PRESS', "ctrl": True},
+             {"properties": [("ctrl", True)]}),
+        ]},
+    )
+
+
 def km_3d_view_tool_edit_curve_tilt(params):
     return (
         "3D View Tool: Edit Curve, Tilt",
@@ -7237,6 +7251,7 @@ def generate_keymaps(params=None):
         km_3d_view_tool_edit_mesh_rip_region(params),
         km_3d_view_tool_edit_mesh_rip_edge(params),
         km_3d_view_tool_edit_curve_draw(params),
+        km_3d_view_tool_edit_curve_edit(params),
         km_3d_view_tool_edit_curve_radius(params),
         km_3d_view_tool_edit_curve_tilt(params),
         km_3d_view_tool_edit_curve_randomize(params),
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index c55f637f8b2..d53072985c9 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -1191,6 +1191,17 @@ class _defs_edit_curve:
             keymap=(),
         )
 
+    @ToolDef.from_fn
+    def edit():
+        return dict(
+            idname="builtin.edit",
+            label="Edit Curve",
+            cursor='PAINT_BRUSH',
+            icon="ops.curve.draw",
+            widget=None,
+            keymap=(),
+        )
+
     @ToolDef.from_fn
     def tilt():
         return dict(
@@ -2790,6 +2801,8 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
             None,
             _defs_transform.shear,
             _defs_edit_curve.curve_vertex_randomize,
+            None,
+            _defs_edit_curve.edit,
         ],
         'EDIT_SURFACE': [
             *_tools_default,
diff --git a/source/blender/editors/curve/CMakeLists.txt b/source/blender/editors/curve/CMakeLists.txt
index 877c2d99102..2cc5a0c0c3d 100644
--- a/source/blender/editors/curve/CMakeLists.txt
+++ b/source/blender/editors/curve/CMakeLists.txt
@@ -38,6 +38,7 @@ set(SRC
   editcurve_paint.c
   editcurve_query.c
   editcurve_select.c
+  editcurve_tool.c
   editcurve_undo.c
   editfont.c
   editfont_undo.c
diff --git a/source/blender/editors/curve/curve_intern.h b/source/blender/editors/curve/curve_intern.h
index 8ecf41162e9..ab70effe8c9 100644
--- a/source/blender/editors/curve/curve_intern.h
+++ b/source/blender/editors/curve/curve_intern.h
@@ -196,3 +196,7 @@ void ED_curve_nurb_vert_selected_find(
 
 /* editcurve_paint.c */
 void CURVE_OT_draw(struct wmOperatorType *ot);
+
+/* editcurve_tool.c */
+void CURVE_OT_edit(struct wmOperatorType *ot);
+// struct wmKeyMap *edit_curve_tool_modal_keymap(struct wmKeyConfig *keyconf);
diff --git a/source/blender/editors/curve/curve_ops.c b/source/blender/editors/curve/curve_ops.c
index 02cb1ee8e1c..bd54e4202f6 100644
--- a/source/blender/editors/curve/curve_ops.c
+++ b/source/blender/editors/curve/curve_ops.c
@@ -127,6 +127,7 @@ void ED_operatortypes_curve(void)
   WM_operatortype_append(CURVE_OT_spin);
   WM_operatortype_append(CURVE_OT_vertex_add);
   WM_operatortype_append(CURVE_OT_draw);
+  WM_operatortype_append(CURVE_OT_edit);
   WM_operatortype_append(CURVE_OT_extrude);
   WM_operatortype_append(CURVE_OT_cyclic_toggle);
 
diff --git a/source/blender/editors/curve/editcurve_tool.c b/source/blender/editors/curve/editcurve_tool.c
new file mode 100644
index 00000000000..1791b8ebee1
--- /dev/null
+++ b/source/blender/editors/curve/editcurve_tool.c
@@ -0,0 +1,907 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup edcurve
+ */
+
+#include "DNA_curve_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_linklist.h"
+#include "BLI_math.h"
+#include "BLI_mempool.h"
+
+#include "BKE_context.h"
+#include "BKE_curve.h"
+#include "BKE_fcurve.h"
+#include "BKE_layer.h"
+#include "BKE_report.h"
+
+#include "DEG_depsgraph.h"
+
+#include "WM_api.h"
+#include "WM_toolsystem.h"
+#include "WM_types.h"
+
+#include "ED_curve.h"
+#include "ED_object.h"
+#include "ED_outliner.h"
+#include "ED_screen.h"
+#include "ED_select_utils.h"
+#include "ED_space_api.h"
+#include "ED_view3d.h"
+
+#include "GPU_batch.h"
+#include "GPU_batch_presets.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
+#include "GPU_state.h"
+
+#include "BKE_object.h"
+#include "BKE_paint.h"
+
+#include "curve_intern.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+#include "RNA_enum_types.h"
+
+static bool ed_editcurve_extrude(Curve *cu, EditNurb *editnurb, View3D *v3d)
+{
+  bool changed = false;
+
+  Nurb *cu_actnu;
+  union {
+    BezTriple *bezt;
+    BPoint *bp;
+    void *p;
+  } cu_actvert;
+
+  if (BLI_listbase_is_empty(&editnurb->nurbs)) {
+    return changed;
+  }
+
+  BKE_curve_nurb_vert_active_get(cu, &cu_actnu, &cu_actvert.p);
+  int act_offset = 0;
+
+  LISTBASE_FOREACH (Nurb *, nu, &editnurb->nurbs) {
+    BLI_assert(nu->pntsu > 0);
+    int i;
+    int pnt_len = nu->pntsu;
+    int new_points = 0;
+    int offset = 0;
+    bool is_prev_selected = false;
+    bool duplic_first = false;
+    bool duplic_last = false;
+    if (nu->type == CU_BEZIER) {
+      BezTriple *bezt, *bezt_prev = NULL;
+      BezTriple bezt_stack;
+      bool is_cyclic = false;
+      if (pnt_len == 1) {
+        /* Single point extrusion.
+         * Keep `is_prev_selected` false to force extrude. */
+        bezt_prev = &nu->bezt[0];
+      }
+      else if (nu->flagu & CU_NURB_CYCLIC) {
+        is_cyclic = true;
+        bezt_prev = &nu->bezt[pnt_len - 1];
+        is_prev_selected = BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt_prev);
+      }
+      else {
+        duplic_first = BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, &nu->bezt[0]) &&
+                       BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, &nu->bezt[1]);
+
+        duplic_last = BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, &nu->bezt[pnt_len - 2]) &&
+                      BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, &nu->bezt[pnt_len - 1]);
+
+        if (duplic_first) {
+          bezt_stack = nu->bezt[0];
+          BEZT_DESEL_ALL(&bezt_stack);
+          bezt_prev = &bezt_stack;
+        }
+        if (duplic_last) {
+          new_points++;
+        }
+      }
+      i = pnt_len;
+      for (bezt = &nu->bezt[0]; i--; bezt++) {
+        bool is_selected = BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt);
+        if (bezt_prev && is_prev_selected != is_selected) {
+          new_points++;
+        }
+        if (bezt == cu_actvert.bezt) {
+          act_offset = new_points;
+        }
+        bezt_prev = bezt;
+        is_prev_selected = is_selected;
+      }
+
+      if (new_points) {
+        if (pnt_len == 1) {
+          /* Single point extrusion.
+           * Set `is_prev_selected` as false to force extrude. */
+          BLI_assert(bezt_prev == &nu->bezt[0]);
+          is_prev_selected = false;
+        }
+        else if (is_cyclic) {
+          BLI_assert(bezt_prev == &nu->bezt[pnt_len - 1]);
+          BLI_assert(is_prev_selected == BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt_prev));
+        }
+        else if (duplic_first) {
+          bezt_prev = &bezt_stack;
+          is_prev_selected = false;
+        }
+        else {
+          bezt_prev = NULL;
+        }
+        BezTrip

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list