← Back to team overview

kicad-developers team mailing list archive

Re: [PATCH] Hotkey for editing module with module editor (Ctrl-E)

 

On Sat, 2014-12-06 at 15:37 -0500, Wayne Stambaugh wrote:
> This still doesn't work correctly unless the footprint is already the
> current item selected.  It behaves the same in both the GAL and legacy
> rendering modes.  You should not have to select an item first to make a
> hot keys work.  Try adding a test for an item under the cursor and then
> launch the footprint editor rather than just exiting when nothing is
> selected.

That makes sense. Here is an amended patch, where Ctrl-E over an item in
either legacy or GAL will launch the footprint editor. A single
selection works as before.

Thanks for reviewing,

John
diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h
index d44bfd8..ff2d41a 100644
--- a/include/wxPcbStruct.h
+++ b/include/wxPcbStruct.h
@@ -1036,6 +1036,9 @@ public:
     // Footprint edition (see also PCB_BASE_FRAME)
     void InstallModuleOptionsFrame( MODULE* Module, wxDC* DC );
 
+    // Directly open module editor
+    void ShowModuleEditorForModule( MODULE* aModule );
+
     /**
      * Function StartMoveModule
      * Initialize a drag or move pad command
diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp
index d5077f0..8e49b33 100644
--- a/pcbnew/edit.cpp
+++ b/pcbnew/edit.cpp
@@ -842,6 +842,11 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
         break;
 
     case ID_POPUP_PCB_EDIT_MODULE_WITH_MODEDIT:
+
+        // If we don't have a current item, there's nothing we can do here
+        if( !GetCurItem() )
+            break;
+
         // If the current Item is a pad, text module ...: Get its parent
         if( GetCurItem()->Type() != PCB_MODULE_T )
             SetCurItem( GetCurItem()->GetParent() );
@@ -855,16 +860,8 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
             OnModify();
         }
 
-        {
-            FOOTPRINT_EDIT_FRAME* editor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_PCB_MODULE_EDITOR, true );
+        ShowModuleEditorForModule( static_cast<MODULE*>( GetCurItem() ) );
 
-            editor->Load_Module_From_BOARD( (MODULE*)GetCurItem() );
-            SetCurItem( NULL );     // the current module could be deleted by
-
-            editor->Show( true );
-
-            editor->Raise();        // Iconize( false );
-        }
         m_canvas->MoveCursorToCrossHair();
         break;
 
diff --git a/pcbnew/editmod.cpp b/pcbnew/editmod.cpp
index 1046888..abe39c1 100644
--- a/pcbnew/editmod.cpp
+++ b/pcbnew/editmod.cpp
@@ -75,16 +75,22 @@ void PCB_EDIT_FRAME::InstallModuleOptionsFrame( MODULE* Module, wxDC* DC )
 
     if( retvalue == 2 )
     {
-        FOOTPRINT_EDIT_FRAME* editor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_PCB_MODULE_EDITOR, true );
-
-        editor->Load_Module_From_BOARD( Module );
-        SetCurItem( NULL );
-
-        editor->Show( true );
-        editor->Raise();        // Iconize( false );
+        ShowModuleEditorForModule( Module );
     }
 }
 
+void PCB_EDIT_FRAME::ShowModuleEditorForModule( MODULE* aModule )
+{
+    FOOTPRINT_EDIT_FRAME* editor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player(
+            FRAME_PCB_MODULE_EDITOR, true );
+
+    editor->Load_Module_From_BOARD( aModule );
+    SetCurItem( NULL );
+
+    editor->Show( true );
+    editor->Raise();
+    // Iconize( false );
+}
 
 void FOOTPRINT_EDIT_FRAME::RemoveStruct( EDA_ITEM* Item )
 {
diff --git a/pcbnew/hotkeys.cpp b/pcbnew/hotkeys.cpp
index 8f903b7..1475b89 100644
--- a/pcbnew/hotkeys.cpp
+++ b/pcbnew/hotkeys.cpp
@@ -105,6 +105,7 @@ static EDA_HOTKEY HkSwitchTrackPosture( wxT( "Switch Track Posture" ),  HK_SWITC
 static EDA_HOTKEY HkDragTrackKeepSlope( wxT( "Drag Track Keep Slope" ), HK_DRAG_TRACK_KEEP_SLOPE, 'D' );
 static EDA_HOTKEY HkPlaceItem( wxT( "Place Item" ), HK_PLACE_ITEM, 'P' );
 static EDA_HOTKEY HkEditBoardItem( wxT( "Edit Item" ), HK_EDIT_ITEM, 'E' );
+static EDA_HOTKEY HkEditWithModedit( wxT( "Edit with Footprint Editor" ), HK_EDIT_MODULE_WITH_MODEDIT, 'E' + GR_KB_CTRL );
 static EDA_HOTKEY HkFlipItem( wxT( "Flip Item" ), HK_FLIP_ITEM, 'F' );
 static EDA_HOTKEY HkRotateItem( wxT( "Rotate Item" ), HK_ROTATE_ITEM, 'R' );
 static EDA_HOTKEY HkMoveItem( wxT( "Move Item" ), HK_MOVE_ITEM, 'M' );
@@ -280,6 +281,7 @@ EDA_HOTKEY* board_edit_Hotkey_List[] =
     &HkRotateItem,             &HkDragFootprint,
     &HkGetAndMoveFootprint,    &HkLock_Unlock_Footprint,     &HkSavefile, &HkSavefileAs,
     &HkLoadfile,               &HkFindItem,                  &HkEditBoardItem,
+    &HkEditWithModedit,
     &HkSwitch2CopperLayer,     &HkSwitch2InnerLayer1,
     &HkSwitch2InnerLayer2,     &HkSwitch2InnerLayer3,        &HkSwitch2InnerLayer4,
     &HkSwitch2InnerLayer5,     &HkSwitch2InnerLayer6,        &HkSwitch2ComponentLayer,
diff --git a/pcbnew/hotkeys.h b/pcbnew/hotkeys.h
index ca58a7f..a344ad0 100644
--- a/pcbnew/hotkeys.h
+++ b/pcbnew/hotkeys.h
@@ -86,6 +86,7 @@ enum hotkey_id_commnand {
     HK_SWITCH_LAYER_TO_INNER13,
     HK_SWITCH_LAYER_TO_INNER14,
     HK_ADD_MODULE,
+    HK_EDIT_MODULE_WITH_MODEDIT,
     HK_SLIDE_TRACK,
     HK_MACRO_ID_BEGIN,
     HK_RECORD_MACROS_0,     // keep these id ordered from 0 to 9
diff --git a/pcbnew/hotkeys_board_editor.cpp b/pcbnew/hotkeys_board_editor.cpp
index 5682dd7..b0331c2 100644
--- a/pcbnew/hotkeys_board_editor.cpp
+++ b/pcbnew/hotkeys_board_editor.cpp
@@ -509,6 +509,10 @@ bool PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit
         OnHotkeyEditItem( HK_EDIT_ITEM );
         break;
 
+    case HK_EDIT_MODULE_WITH_MODEDIT:      // Edit module with module editor
+        OnHotkeyEditItem( HK_EDIT_MODULE_WITH_MODEDIT );
+        break;
+
     // Footprint edition:
     case HK_LOCK_UNLOCK_FOOTPRINT: // toggle module "MODULE_is_LOCKED" status:
         // get any module, locked or not locked and toggle its locked status
@@ -693,6 +697,8 @@ bool PCB_EDIT_FRAME::OnHotkeyEditItem( int aIdCommand )
     case PCB_MODULE_T:
         if( aIdCommand == HK_EDIT_ITEM )
             evt_type = ID_POPUP_PCB_EDIT_MODULE_PRMS;
+        else if( aIdCommand == HK_EDIT_MODULE_WITH_MODEDIT )
+            evt_type = ID_POPUP_PCB_EDIT_MODULE_WITH_MODEDIT;
 
         break;
 
diff --git a/pcbnew/onrightclick.cpp b/pcbnew/onrightclick.cpp
index 9de056f..91b34d4 100644
--- a/pcbnew/onrightclick.cpp
+++ b/pcbnew/onrightclick.cpp
@@ -761,9 +761,11 @@ void PCB_EDIT_FRAME::createPopUpMenuForFootprints( MODULE* aModule, wxMenu* menu
                              g_Board_Editor_Hokeys_Descr, HK_EDIT_ITEM );
         AddMenuItem( sub_menu_footprint, ID_POPUP_PCB_EDIT_MODULE_PRMS, msg,
                      KiBitmap( edit_module_xpm ) );
+
+        msg = AddHotkeyName( _( "Edit with Footprint Editor" ),
+                             g_Board_Editor_Hokeys_Descr, HK_EDIT_MODULE_WITH_MODEDIT );
         AddMenuItem( sub_menu_footprint, ID_POPUP_PCB_EDIT_MODULE_WITH_MODEDIT,
-                     _( "Edit with Footprint Editor" ),
-                     KiBitmap( module_editor_xpm ) );
+                     msg, KiBitmap( module_editor_xpm ) );
         sub_menu_footprint->AppendSeparator();
         msg = AddHotkeyName( _( "Delete Footprint" ),
                              g_Board_Editor_Hokeys_Descr, HK_DELETE );
diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp
index 456a021..c5b142a 100644
--- a/pcbnew/tools/common_actions.cpp
+++ b/pcbnew/tools/common_actions.cpp
@@ -301,7 +301,6 @@ TOOL_ACTION COMMON_ACTIONS::trackViaSizeChanged( "pcbnew.EditorControl.trackViaS
         AS_GLOBAL, 0,
         "", "", AF_NOTIFY );
 
-
 // Zone actions
 TOOL_ACTION COMMON_ACTIONS::zoneFill( "pcbnew.EditorControl.zoneFill",
         AS_GLOBAL, 0,
@@ -316,6 +315,12 @@ TOOL_ACTION COMMON_ACTIONS::zoneUnfill( "pcbnew.EditorControl.zoneUnfill",
         "Unfill", "Unfill zone(s)" );
 
 
+// PCB editor module tools
+TOOL_ACTION COMMON_ACTIONS::editWithModedit( "pcbnew.EditorControl.editWithModedit",
+        AS_GLOBAL, MD_CTRL + int('E'),
+        "Edit with module editor", "Edit with module editor", AF_ACTIVATE );
+
+
 // Module editor tools
 TOOL_ACTION COMMON_ACTIONS::placePad( "pcbnew.ModuleEditor.placePad",
         AS_GLOBAL, 0,
diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h
index 366f444..a82c707 100644
--- a/pcbnew/tools/common_actions.h
+++ b/pcbnew/tools/common_actions.h
@@ -65,6 +65,9 @@ public:
     /// Activation of the edit tool
     static TOOL_ACTION properties;
 
+    /// Edit a module in the module editor
+    static TOOL_ACTION editWithModedit;
+
     /// Deleting a BOARD_ITEM
     static TOOL_ACTION remove;
 
diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp
index f1c8fe3..380efac 100644
--- a/pcbnew/tools/pcb_editor_control.cpp
+++ b/pcbnew/tools/pcb_editor_control.cpp
@@ -29,6 +29,7 @@
 
 #include <wxPcbStruct.h>
 #include <class_board.h>
+#include <class_module.h>
 #include <class_zone.h>
 #include <class_draw_panel_gal.h>
 
@@ -219,6 +220,41 @@ int PCB_EDITOR_CONTROL::ZoneUnfill( TOOL_EVENT& aEvent )
 }
 
 
+int PCB_EDITOR_CONTROL::EditWithModedit( TOOL_EVENT& aEvent )
+{
+    SELECTION_TOOL* selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
+    const SELECTION& selection = selTool->GetSelection();
+
+    if( selection.Empty() )
+        m_toolMgr->RunAction( COMMON_ACTIONS::selectionCursor, true );
+
+    // we can only edit a single module at once
+    if( selection.Size() != 1 )
+    {
+        setTransitions();
+        return 0;
+    }
+
+    BOARD_ITEM* item = selection.Item<BOARD_ITEM>( 0 );
+
+    MODULE* selectedModule = NULL;
+
+    if( item->Type() == PCB_MODULE_T )
+        selectedModule = static_cast<MODULE*>( item );
+    else
+        selectedModule = static_cast<MODULE*>( item->GetParent() );
+
+    wxASSERT_MSG( selectedModule, wxT("Failed to get a module to edit with modedit") );
+
+    m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
+
+    m_frame->ShowModuleEditorForModule( selectedModule );
+
+    setTransitions();
+    return 0;
+}
+
+
 void PCB_EDITOR_CONTROL::setTransitions()
 {
     // Track & via size control
@@ -231,4 +267,7 @@ void PCB_EDITOR_CONTROL::setTransitions()
     Go( &PCB_EDITOR_CONTROL::ZoneFill,           COMMON_ACTIONS::zoneFill.MakeEvent() );
     Go( &PCB_EDITOR_CONTROL::ZoneFillAll,        COMMON_ACTIONS::zoneFillAll.MakeEvent() );
     Go( &PCB_EDITOR_CONTROL::ZoneUnfill,         COMMON_ACTIONS::zoneUnfill.MakeEvent() );
+
+    // Module editor
+    Go( &PCB_EDITOR_CONTROL::EditWithModedit,    COMMON_ACTIONS::editWithModedit.MakeEvent() );
 }
diff --git a/pcbnew/tools/pcb_editor_control.h b/pcbnew/tools/pcb_editor_control.h
index 6d27288..ff8c5c5 100644
--- a/pcbnew/tools/pcb_editor_control.h
+++ b/pcbnew/tools/pcb_editor_control.h
@@ -56,6 +56,13 @@ public:
     int ZoneFillAll( TOOL_EVENT& aEvent );
     int ZoneUnfill( TOOL_EVENT& aEvent );
 
+    /**
+     * Function EditModuleWithModedit()
+     *
+     * Opens a currently selected module in modedit
+     */
+    int EditWithModedit( TOOL_EVENT& aEvent );
+
 private:
     ///> Sets up handlers for various events.
     void setTransitions();

Follow ups

References