← Back to team overview

kicad-developers team mailing list archive

Modedit hotkeys patch, part 2

 

Hi,

A new patch to replace the previous one I submitted. This one follows the
hotkey coding style introduced in revision 2450. Adds hotkey support for
moving, rotating, editing, and deleting pads, texts and edges in module
editor.

Marco

On Mon, Aug 23, 2010 at 10:05 PM, Marco Mattila <marcom99@xxxxxxxxx> wrote:

> Hi,
>
> The attached patch adds hotkey support for moving, rotating, editing, and
> deleting pads, texts, and edges in module editor.
>
> Regards,
>
> Marco
>
=== modified file 'pcbnew/hotkeys.cpp'
--- pcbnew/hotkeys.cpp	2010-08-17 17:45:45 +0000
+++ pcbnew/hotkeys.cpp	2010-08-26 19:36:53 +0000
@@ -171,7 +171,11 @@
 };
 
 // List of hotkey descriptors for the module editor
-Ki_HotkeyInfo* s_module_edit_Hotkey_List[] = { NULL };
+Ki_HotkeyInfo* s_module_edit_Hotkey_List[] = {
+    &HkMoveItem,               &HkRotateItem,                &HkEditBoardItem,
+    &HkDelete,
+    NULL
+ };
 
 // list of sections and corresponding hotkey list for pcbnew (used to create an hotkey config file)
 struct Ki_HotkeyInfoSectionDescriptor s_Pcbnew_Editor_Hokeys_Descr[] =
@@ -635,9 +639,211 @@
         cmd.SetId( ID_ZOOM_PAGE );
         GetEventHandler()->ProcessEvent( cmd );
         break;
-    }
-}
-
+
+    case HK_EDIT_ITEM:
+        OnHotkeyEditItem( HK_EDIT_ITEM );
+        break;
+
+    case HK_DELETE:
+        OnHotkeyDeleteItem( HK_DELETE );
+        break;
+
+    case HK_MOVE_ITEM:
+        OnHotkeyMoveItem( HK_MOVE_ITEM );
+        break;
+
+    case HK_ROTATE_ITEM:
+        OnHotkeyRotateItem( HK_ROTATE_ITEM );
+        break;
+    }
+}
+
+bool WinEDA_ModuleEditFrame::OnHotkeyEditItem( int aIdCommand )
+{
+    BOARD_ITEM* item = GetCurItem();
+    bool itemCurrentlyEdited = item && item->m_Flags;
+
+    if( itemCurrentlyEdited )
+        return false;
+
+    item = ModeditLocateAndDisplay();
+
+    if( item == NULL )
+        return false;
+
+    SetCurItem( item );
+
+    int evt_type = 0;       //Used to post a wxCommandEvent on demand
+
+    switch( item->Type() )
+    {
+    case TYPE_MODULE:
+        if( aIdCommand == HK_EDIT_ITEM )
+            evt_type = ID_POPUP_PCB_EDIT_MODULE;
+        break;
+
+    case TYPE_PAD:
+        if( aIdCommand == HK_EDIT_ITEM )
+            evt_type = ID_POPUP_PCB_EDIT_PAD;
+        break;
+
+    case TYPE_TEXTE_MODULE:
+        if( aIdCommand == HK_EDIT_ITEM )
+            evt_type = ID_POPUP_PCB_EDIT_TEXTMODULE;
+        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;
+}
+
+bool WinEDA_ModuleEditFrame::OnHotkeyDeleteItem( int aIdCommand )
+{
+    BOARD_ITEM* item = GetCurItem();
+    bool itemCurrentlyEdited = item && item->m_Flags;
+
+    if( itemCurrentlyEdited )
+        return false;
+
+    item = ModeditLocateAndDisplay();
+
+    if( item == NULL )
+        return false;
+
+    SetCurItem( item );
+
+    int evt_type = 0;       //Used to post a wxCommandEvent on demand
+
+    switch( item->Type() )
+    {
+    case TYPE_PAD:
+        if( aIdCommand == HK_DELETE )
+            evt_type = ID_POPUP_PCB_DELETE_PAD;
+        break;
+
+    case TYPE_TEXTE_MODULE:
+        if( aIdCommand == HK_DELETE )
+            evt_type = ID_POPUP_PCB_DELETE_TEXTMODULE;
+        break;
+
+    case TYPE_EDGE_MODULE:
+        if( aIdCommand == HK_DELETE )
+            evt_type = ID_POPUP_PCB_DELETE_EDGE;
+        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;
+}
+
+bool WinEDA_ModuleEditFrame::OnHotkeyMoveItem( int aIdCommand )
+{
+    BOARD_ITEM* item = GetCurItem();
+    bool itemCurrentlyEdited = item && item->m_Flags;
+
+    if( itemCurrentlyEdited )
+        return false;
+
+    item = ModeditLocateAndDisplay();
+
+    if( item == NULL )
+        return false;
+
+    SetCurItem( item );
+
+    int evt_type = 0;       //Used to post a wxCommandEvent on demand
+
+    switch( item->Type() )
+    {
+    case TYPE_PAD:
+        if( aIdCommand == HK_MOVE_ITEM )
+            evt_type = ID_POPUP_PCB_MOVE_PAD_REQUEST;
+        break;
+
+    case TYPE_TEXTE_MODULE:
+        if( aIdCommand == HK_MOVE_ITEM )
+            evt_type = ID_POPUP_PCB_MOVE_TEXTMODULE_REQUEST;
+        break;
+
+    case TYPE_EDGE_MODULE:
+        if( aIdCommand == HK_MOVE_ITEM )
+            evt_type = ID_POPUP_PCB_MOVE_EDGE;
+        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;
+}
+
+bool WinEDA_ModuleEditFrame::OnHotkeyRotateItem( int aIdCommand )
+{
+    BOARD_ITEM* item = GetCurItem();
+    bool        itemCurrentlyEdited = item && item->m_Flags;
+    int         evt_type = 0; // Used to post a wxCommandEvent on demand
+
+    if( !itemCurrentlyEdited )
+        item = ModeditLocateAndDisplay();
+
+    if( item == NULL )
+        return false;
+
+    SetCurItem( item );
+
+    switch( item->Type() )
+    {
+    case TYPE_TEXTE_MODULE:
+        if( aIdCommand == HK_ROTATE_ITEM )                      // Rotation
+            evt_type = ID_POPUP_PCB_ROTATE_TEXTMODULE;
+        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 OnHotkeyDeleteItem
  * Delete the item found under the mouse cursor

=== modified file 'pcbnew/modedit_onclick.cpp'
--- pcbnew/modedit_onclick.cpp	2010-08-11 13:15:30 +0000
+++ pcbnew/modedit_onclick.cpp	2010-08-26 19:36:39 +0000
@@ -17,6 +17,7 @@
 #include "protos.h"
 #include "pcbnew_id.h"
 
+#include "hotkeys.h"
 
 /* Handle the left click in footprint editor
  */
@@ -264,8 +265,10 @@
                       _( "Rotate" ), rotate_module_pos_xpm );
         ADD_MENUITEM( transform_choice, ID_MODEDIT_MODULE_MIRROR,
                       _( "Mirror" ), mirror_H_xpm );
+        msg = AddHotkeyName( _( "Edit Module" ), s_Module_Editor_Hokeys_Descr,
+                             HK_EDIT_ITEM );
         ADD_MENUITEM( PopMenu, ID_POPUP_PCB_EDIT_MODULE,
-                      _( "Edit Module" ), edit_module_xpm );
+                      msg, edit_module_xpm );
         ADD_MENUITEM_WITH_SUBMENU( PopMenu, transform_choice,
                                    ID_MODEDIT_TRANSFORM_MODULE,
                                    _( "Transform Module" ), edit_xpm );
@@ -275,17 +278,23 @@
     case TYPE_PAD:
         if( !flags )
         {
+            msg = AddHotkeyName( _("Move Pad" ), s_Module_Editor_Hokeys_Descr,
+                                 HK_MOVE_ITEM );
             ADD_MENUITEM( PopMenu, ID_POPUP_PCB_MOVE_PAD_REQUEST,
-                          _( "Move Pad" ), move_pad_xpm );
+                          msg, move_pad_xpm );
         }
-        ADD_MENUITEM( PopMenu, ID_POPUP_PCB_EDIT_PAD, _( "Edit Pad" ),
-                      options_pad_xpm );
+        msg = AddHotkeyName( _("Edit Pad" ), s_Module_Editor_Hokeys_Descr,
+                             HK_EDIT_ITEM );
+        ADD_MENUITEM( PopMenu, ID_POPUP_PCB_EDIT_PAD,
+                      msg, options_pad_xpm );
         ADD_MENUITEM( PopMenu, ID_POPUP_PCB_IMPORT_PAD_SETTINGS,
                       _( "New Pad Settings" ), options_new_pad_xpm );
         ADD_MENUITEM( PopMenu, ID_POPUP_PCB_EXPORT_PAD_SETTINGS,
                       _( "Export Pad Settings" ), export_options_pad_xpm );
+        msg = AddHotkeyName( _("Delete Pad" ), s_Module_Editor_Hokeys_Descr,
+                             HK_DELETE );
         ADD_MENUITEM( PopMenu, ID_POPUP_PCB_DELETE_PAD,
-                      _( "delete Pad" ), delete_pad_xpm );
+                      msg, delete_pad_xpm );
         if( !flags )
         {
             PopMenu->AppendSeparator();
@@ -297,18 +306,28 @@
     case TYPE_TEXTE_MODULE:
         if( !flags )
         {
+            msg = AddHotkeyName( _("Move Text Mod." ), s_Module_Editor_Hokeys_Descr,
+                                 HK_MOVE_ITEM );
             ADD_MENUITEM( PopMenu, ID_POPUP_PCB_MOVE_TEXTMODULE_REQUEST,
-                          _( "Move Text Mod." ), move_field_xpm );
+                          msg, move_field_xpm );
         }
+        msg = AddHotkeyName( _("Rotate Text Mod." ), s_Module_Editor_Hokeys_Descr,
+                             HK_ROTATE_ITEM );
         ADD_MENUITEM( PopMenu, ID_POPUP_PCB_ROTATE_TEXTMODULE,
-                      _( "Rotate Text Mod." ), rotate_field_xpm );
+                      msg, rotate_field_xpm );
         if( !flags )
         {
+            msg = AddHotkeyName( _("Edit Text Mod." ), s_Module_Editor_Hokeys_Descr,
+                                 HK_EDIT_ITEM );
             ADD_MENUITEM( PopMenu, ID_POPUP_PCB_EDIT_TEXTMODULE,
-                          _( "Edit Text Mod." ), edit_text_xpm );
+                          msg, edit_text_xpm );
             if( ( (TEXTE_MODULE*) DrawStruct )->m_Type == TEXT_is_DIVERS )
+            {
+                msg = AddHotkeyName( _("Delete Text Mod." ), s_Module_Editor_Hokeys_Descr,
+                                     HK_DELETE );
                 ADD_MENUITEM( PopMenu, ID_POPUP_PCB_DELETE_TEXTMODULE,
-                              _( "Delete Text Mod." ), delete_text_xpm );
+                              msg, delete_text_xpm );
+            }
         }
         break;
 
@@ -318,8 +337,12 @@
             ADD_MENUITEM( PopMenu, ID_POPUP_PCB_STOP_CURRENT_DRAWING,
                           _( "End edge" ), apply_xpm );
         if( !flags )
+        {
+            msg = AddHotkeyName( _("Move edge" ), s_Module_Editor_Hokeys_Descr,
+                                 HK_MOVE_ITEM );
             ADD_MENUITEM( PopMenu, ID_POPUP_PCB_MOVE_EDGE,
-                          _( "Move edge" ), move_line_xpm );
+                          msg, move_line_xpm );
+        }
         if( ( flags & (IS_NEW | IS_MOVED) ) == IS_MOVED )
             ADD_MENUITEM( PopMenu, ID_POPUP_PCB_PLACE_EDGE,
                           _( "Place edge" ), apply_xpm );
@@ -335,8 +358,10 @@
                       _( "Edit Layer (Current)" ), select_layer_pair_xpm );
         ADD_MENUITEM( edit_mnu, ID_POPUP_PCB_EDIT_LAYER_ALL_EDGE,
                       _( "Edit Layer (All)" ), select_layer_pair_xpm );
+        msg = AddHotkeyName( _("Delete edge" ), s_Module_Editor_Hokeys_Descr,
+                             HK_DELETE );
         ADD_MENUITEM( PopMenu, ID_POPUP_PCB_DELETE_EDGE,
-                      _( "Delete edge" ), delete_xpm );
+                      msg, delete_xpm );
         append_set_width = TRUE;
     }
     break;
@@ -375,7 +400,7 @@
                || ( m_ID_current_state == ID_PCB_ARC_BUTT ) ) ) )
     {
         ADD_MENUITEM( PopMenu, ID_POPUP_PCB_ENTER_EDGE_WIDTH,
-                      _( "Set Width" ), width_segment_xpm );
+                      _("Set Width" ), width_segment_xpm );
         PopMenu->AppendSeparator();
     }
 

=== modified file 'pcbnew/module_editor_frame.h'
--- pcbnew/module_editor_frame.h	2010-08-10 18:34:26 +0000
+++ pcbnew/module_editor_frame.h	2010-08-26 18:38:01 +0000
@@ -41,6 +41,10 @@
     void         ToolOnRightClick( wxCommandEvent& event );
     void         OnSelectOptionToolbar( wxCommandEvent& event );
     void         OnHotKey( wxDC* DC, int hotkey, EDA_BaseStruct* DrawStruct );
+    bool         OnHotkeyEditItem( int aIdCommand );
+    bool         OnHotkeyDeleteItem( int aIdCommand );
+    bool         OnHotkeyMoveItem( int aIdCommand );
+    bool         OnHotkeyRotateItem( int aIdCommand );
     void         Show3D_Frame( wxCommandEvent& event );
     void         GeneralControle( wxDC* DC, wxPoint Mouse );
 


Follow ups