kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #15981
Re: [PATCH] Hotkey for editing module with module editor (Ctrl-E)
On Mon, 2014-12-01 at 13:22 -0500, Wayne Stambaugh wrote:
> Hi John,
>
> Sorry it took so long to try out this patch but I've been busy. I found
> a segfault on the first attempt to use Ctrl-E when no previous item has
> been selected.
D'oh, what a clanger!
> Once you fix this issue, I'll commit the patch.
I have fixed the issue, and I have also added the same functionality to
the GAL PCB editor. I have also taken the opportunity to break some
duplicated code out into a re-usable function:
void PCB_EDIT_FRAME::ShowModuleEditorForModule( MODULE* aModule )
I think I'm starting to get the hang of the GAL, now! Hopefully I got it
more or less right!
Cheers,
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 f43ebab..8c5d372 100644
--- a/pcbnew/edit.cpp
+++ b/pcbnew/edit.cpp
@@ -839,6 +839,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() );
@@ -852,16 +857,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 1cfb3b4..26a7d12 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' );
@@ -276,6 +277,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 b3bd3c1..d8d9549 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 3be8c52..b955f81 100644
--- a/pcbnew/hotkeys_board_editor.cpp
+++ b/pcbnew/hotkeys_board_editor.cpp
@@ -508,6 +508,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
+ evt_type = ID_POPUP_PCB_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
diff --git a/pcbnew/onrightclick.cpp b/pcbnew/onrightclick.cpp
index bafbffe..6f125a1 100644
--- a/pcbnew/onrightclick.cpp
+++ b/pcbnew/onrightclick.cpp
@@ -757,9 +757,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..08eaa05 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,38 @@ 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();
+
+ // we can only edit one module at a time
+ 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 +264,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