← Back to team overview

kicad-developers team mailing list archive

[PATCH] Add Insert hotkey to add a zone/segment corner

 

This patch adds a hotkey for adding a corner to a zone or segment.
This is an action I have really struggled without a hotkey for! I have
used Insert, as:

1) it's available and
2) it's what Inkscape uses (but Inkscape adds the point at the
midpoint of the segment, this adds at the cursor).

It doesn't work on polygons, as that is still unimplemented in the
underlying action.

Cheers,

John
From 9a4da96b7df9941e6dcbb61201adfeaed70bea95 Mon Sep 17 00:00:00 2001
From: John Beard <john.j.beard@xxxxxxxxx>
Date: Tue, 24 Jul 2018 16:15:05 +0100
Subject: [PATCH 1/2] Add hotkey (Insert) for zone create corner

Adds a hotkey to the TOOL_ACTION, and also checks for
action validity prior to running the actions (previously
implicitly gated by  the enablement of the menu item).
---
 pcbnew/hotkeys.cpp            |  6 ++++++
 pcbnew/hotkeys.h              |  3 ++-
 pcbnew/tools/point_editor.cpp | 23 +++++++++++++++++------
 pcbnew/tools/point_editor.h   |  3 +++
 4 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/pcbnew/hotkeys.cpp b/pcbnew/hotkeys.cpp
index 25a93e694..32fcc3192 100644
--- a/pcbnew/hotkeys.cpp
+++ b/pcbnew/hotkeys.cpp
@@ -310,6 +310,9 @@ static EDA_HOTKEY HkToggleCursor( _HKI( "Toggle Cursor Display (Modern Toolset o
 static EDA_HOTKEY HkMeasureTool( _HKI( "Measure Distance (Modern Toolset only)" ),
                                  HK_MEASURE_TOOL, 'M' + GR_KB_SHIFTCTRL );
 
+static EDA_HOTKEY HkInsertCorner( _HKI( "Insert Corner (Modern Toolset only)" ),
+                                 HK_INSERT_CORNER, WXK_INSERT );
+
 // List of common hotkey descriptors
 EDA_HOTKEY* common_Hotkey_List[] =
 {
@@ -384,6 +387,9 @@ EDA_HOTKEY* board_edit_Hotkey_List[] =
     &HkZoneFillOrRefill,
     &HkZoneRemoveFilled,
 
+    // Point editor (zones and segments)
+    &HkInsertCorner,
+
     // Highlight and display
     &HkSelectConnection,
     &HkSelectCopper,
diff --git a/pcbnew/hotkeys.h b/pcbnew/hotkeys.h
index f4e6fa446..b22817675 100644
--- a/pcbnew/hotkeys.h
+++ b/pcbnew/hotkeys.h
@@ -133,7 +133,8 @@ enum hotkey_id_commnand {
     HK_DP_DIMENSIONS,
     HK_VIA_SIZE_INC,
     HK_VIA_SIZE_DEC,
-    HK_HIGHLIGHT_NET_SELECTION
+    HK_HIGHLIGHT_NET_SELECTION,
+    HK_INSERT_CORNER
 };
 
 // Full list of hotkey descriptors for board editor and footprint editor
diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp
index 9d994479e..a63bdb944 100644
--- a/pcbnew/tools/point_editor.cpp
+++ b/pcbnew/tools/point_editor.cpp
@@ -50,7 +50,7 @@ using namespace std::placeholders;
 
 // Point editor
 TOOL_ACTION PCB_ACTIONS::pointEditorAddCorner( "pcbnew.PointEditor.addCorner",
-        AS_GLOBAL, 0,
+        AS_GLOBAL, WXK_INSERT,
         _( "Create Corner" ), _( "Create a corner" ), add_corner_xpm );
 
 TOOL_ACTION PCB_ACTIONS::pointEditorRemoveCorner( "pcbnew.PointEditor.removeCorner",
@@ -850,17 +850,25 @@ void POINT_EDITOR::setTransitions()
 }
 
 
+bool POINT_EDITOR::canAddCorner( const EDA_ITEM& aItem )
+{
+    const auto type = aItem.Type();
+
+    // Works only for zones and line segments
+    return type == PCB_ZONE_AREA_T ||
+           ( ( type == PCB_LINE_T || type == PCB_MODULE_EDGE_T ) &&
+               static_cast<const DRAWSEGMENT&>( aItem ).GetShape() == S_SEGMENT );
+}
+
+
 bool POINT_EDITOR::addCornerCondition( const SELECTION& aSelection )
 {
     if( aSelection.Size() != 1 )
         return false;
 
-    auto item = aSelection.Front();
+    const EDA_ITEM* item = aSelection.Front();
 
-    // Works only for zones and line segments
-    return item->Type() == PCB_ZONE_AREA_T ||
-           ( ( item->Type() == PCB_LINE_T || item->Type() == PCB_MODULE_EDGE_T ) &&
-               static_cast<DRAWSEGMENT*>( item )->GetShape() == S_SEGMENT );
+    return ( item != nullptr ) && canAddCorner( *item );
 }
 
 
@@ -921,6 +929,9 @@ int POINT_EDITOR::addCorner( const TOOL_EVENT& aEvent )
     const VECTOR2I& cursorPos = getViewControls()->GetCursorPosition();
     BOARD_COMMIT commit( frame );
 
+    if( !canAddCorner( *item ) )
+        return 0;
+
     if( item->Type() == PCB_ZONE_AREA_T )
     {
         ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( item );
diff --git a/pcbnew/tools/point_editor.h b/pcbnew/tools/point_editor.h
index 230a6f5c7..6ebcb1787 100644
--- a/pcbnew/tools/point_editor.h
+++ b/pcbnew/tools/point_editor.h
@@ -129,6 +129,9 @@ private:
     ///> Condition to display "Create corner" context menu entry.
     static bool addCornerCondition( const SELECTION& aSelection );
 
+    ///> Determine if the tool can currently add a corner to the given item
+    static bool canAddCorner( const EDA_ITEM& aItem );
+
     ///> Condition to display "Remove corner" context menu entry.
     bool removeCornerCondition( const SELECTION& aSelection );
 
-- 
2.17.1


Follow ups