← Back to team overview

kicad-developers team mailing list archive

Disable hotkeys for pads in pcbnew (patch)

 

Hi,

Moving of pads using hotkeys in pcbnew was found to be little problematic in
earlier discussions. The attached patch changes hotkey behavior so that
pressing M, G, or E over a pad moves, drags, or edits the parent footprint
(pads can still be moved via the right-click menu). The patch is a little
bigger than absolutely necessary to achieve this goal. However, I added a
new method to WinEDA_PcbFrame (OnHotkeyEditItem in hotkeys.cpp) so that also
item editing is handled in the same way as, e.g., moving or rotation. Thus,
OnEditItemRequest is no longer used in hotkeys.cpp at all. I think that the
remaining calls to OnEditItemRequest in onleftclick.cpp should also be
replaced with postings of events (such as ID_POPUP_PCB_EDIT_DIMENSION) that
would be handled by Process_Special_Functions. This way code to do one thing
would be in one place only and OnEditItemRequest could be removed.

marco
=== modified file 'include/wxPcbStruct.h'
--- include/wxPcbStruct.h	2010-08-17 10:41:44 +0000
+++ include/wxPcbStruct.h	2010-09-01 18:45:25 +0000
@@ -277,6 +277,8 @@
      */
     bool             OnHotkeyDeleteItem( wxDC* aDC );
 
+    bool             OnHotkeyEditItem( int aIdCommand );
+
     /** Function OnHotkeyMoveItem
      * Moves or drag the item (footprint, track, text .. ) found under the mouse cursor
      * Only a footprint or a track can be dragged

=== modified file 'pcbnew/hotkeys.cpp'
--- pcbnew/hotkeys.cpp	2010-08-29 21:31:27 +0000
+++ pcbnew/hotkeys.cpp	2010-09-01 19:44:27 +0000
@@ -503,15 +503,7 @@
         break;
 
     case HK_EDIT_ITEM:      // Edit board item
-        if( !itemCurrentlyEdited )
-        {
-            BOARD_ITEM* item = PcbGeneralLocateAndDisplay();
-            if( item == NULL )
-                break;
-
-            //An item is found, and some can be edited:
-            OnEditItemRequest( aDC, item );
-        }
+        OnHotkeyEditItem( HK_EDIT_ITEM );
         break;
 
     // Footprint edition:
@@ -908,6 +900,90 @@
     return true;
 }
 
+bool WinEDA_PcbFrame::OnHotkeyEditItem( int aIdCommand )
+{
+    BOARD_ITEM* item = GetCurItem();
+    bool itemCurrentlyEdited = item && item->m_Flags;
+
+    if( itemCurrentlyEdited )
+        return false;
+
+    item = PcbGeneralLocateAndDisplay();
+
+    if( item == NULL )
+        return false;
+
+    SetCurItem( item );
+
+    int evt_type = 0;       //Used to post a wxCommandEvent on demand
+
+    switch( item->Type() )
+    {
+    case TYPE_TRACK:
+    case TYPE_VIA:
+        if( aIdCommand == HK_EDIT_ITEM )
+            evt_type = ID_POPUP_PCB_EDIT_TRACKSEG;
+        break;
+
+    case TYPE_TEXTE:
+        if( aIdCommand == HK_EDIT_ITEM )
+            evt_type = ID_POPUP_PCB_EDIT_TEXTEPCB;
+        break;
+
+    case TYPE_MODULE:
+        if( aIdCommand == HK_EDIT_ITEM )
+            evt_type = ID_POPUP_PCB_EDIT_MODULE;
+        break;
+
+    case TYPE_PAD:
+        // Post a EDIT_MODULE event here to prevent pads
+        // from being edited by hotkeys.
+        // Process_Special_Functions takes care of finding
+        // the parent.
+        if( aIdCommand == HK_EDIT_ITEM )
+            evt_type = ID_POPUP_PCB_EDIT_MODULE;
+        break;
+
+    case TYPE_MIRE:
+        if( aIdCommand == HK_EDIT_ITEM )
+            evt_type = ID_POPUP_PCB_EDIT_MIRE;
+        break;
+
+    case TYPE_DIMENSION:
+        if( aIdCommand == HK_EDIT_ITEM )
+            evt_type = ID_POPUP_PCB_EDIT_DIMENSION;
+        break;
+
+    case TYPE_TEXTE_MODULE:
+        if( aIdCommand == HK_EDIT_ITEM )
+            evt_type = ID_POPUP_PCB_EDIT_TEXTMODULE;
+        break;
+
+    case TYPE_DRAWSEGMENT:
+        if( aIdCommand == HK_EDIT_ITEM )
+            evt_type = ID_POPUP_PCB_EDIT_DRAWING;
+        break;
+
+    case TYPE_ZONE_CONTAINER:
+        if( aIdCommand == HK_EDIT_ITEM )
+            evt_type = ID_POPUP_PCB_EDIT_ZONE_PARAMS;
+        break;
+
+    default:
+        break;
+    }
+
+    if( evt_type != 0 )
+    {
+        wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED );
+        evt.SetEventObject( this );
+        evt.SetId( evt_type );
+        wxPostEvent( this, evt );
+        return true;
+    }
+
+    return false;
+}
 
 /** Function OnHotkeyMoveItem
  * Move or drag the item (footprint, track, text .. ) found under the mouse cursor
@@ -953,10 +1029,14 @@
     break;
 
     case TYPE_PAD:
+        // Post MODULE_REQUEST events here to prevent pads
+        // from being moved or dragged by hotkeys.
+        // Process_Special_Functions takes care of finding
+        // the parent.
         if( aIdCommand == HK_MOVE_ITEM )
-            evt_type = ID_POPUP_PCB_MOVE_PAD_REQUEST;
+            evt_type = ID_POPUP_PCB_MOVE_MODULE_REQUEST;
         if( aIdCommand == HK_DRAG_ITEM )
-            evt_type = ID_POPUP_PCB_DRAG_PAD_REQUEST;
+            evt_type = ID_POPUP_PCB_DRAG_MODULE_REQUEST;
         break;
 
     case TYPE_TEXTE:

=== modified file 'pcbnew/onrightclick.cpp'
--- pcbnew/onrightclick.cpp	2010-08-17 17:45:45 +0000
+++ pcbnew/onrightclick.cpp	2010-09-01 20:14:42 +0000
@@ -741,15 +741,13 @@
     sub_menu_Pad = new wxMenu;
     ADD_MENUITEM_WITH_SUBMENU( menu, sub_menu_Pad, -1, msg, pad_xpm );
 
-    msg = AddHotkeyName( _( "Move" ), s_Board_Editor_Hokeys_Descr, HK_MOVE_ITEM );
     ADD_MENUITEM( sub_menu_Pad, ID_POPUP_PCB_MOVE_PAD_REQUEST,
-                  msg, move_pad_xpm );
-    msg = AddHotkeyName( _( "Drag" ), s_Board_Editor_Hokeys_Descr, HK_DRAG_ITEM );
+                  _( "Move" ), move_pad_xpm );
     ADD_MENUITEM( sub_menu_Pad, ID_POPUP_PCB_DRAG_PAD_REQUEST,
-                  msg, drag_pad_xpm );
+                  _( "Drag" ), drag_pad_xpm );
 
-    msg = AddHotkeyName( _( "Edit Pad" ), s_Board_Editor_Hokeys_Descr, HK_EDIT_ITEM );
-    ADD_MENUITEM( sub_menu_Pad, ID_POPUP_PCB_EDIT_PAD, msg, options_pad_xpm );
+    ADD_MENUITEM( sub_menu_Pad, ID_POPUP_PCB_EDIT_PAD,
+                  _( "Edit" ), options_pad_xpm );
     sub_menu_Pad->AppendSeparator();
 
     ADD_MENUITEM_WITH_HELP( sub_menu_Pad, ID_POPUP_PCB_IMPORT_PAD_SETTINGS,