From a2f118d2fa2524dead2c71f7d7abcf49ec961abc Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Tue, 3 Apr 2018 13:54:10 +0200 Subject: [PATCH] Gerbview: fix not working menu item "Zoom to Selection" in main menu. This also fixes a wxASSERT for this menu item --- gerbview/events_called_functions.cpp | 3 +++ gerbview/hotkeys.cpp | 7 ++++++- gerbview/menubar.cpp | 3 ++- gerbview/tools/gerbview_actions.cpp | 3 +++ gerbview/tools/gerbview_actions.h | 1 + gerbview/tools/gerbview_control.cpp | 20 ++++++++++++++++++++ gerbview/tools/gerbview_control.h | 1 + 7 files changed, 36 insertions(+), 2 deletions(-) diff --git a/gerbview/events_called_functions.cpp b/gerbview/events_called_functions.cpp index d0f33cb1a3..668c5c3d24 100644 --- a/gerbview/events_called_functions.cpp +++ b/gerbview/events_called_functions.cpp @@ -116,6 +116,8 @@ BEGIN_EVENT_TABLE( GERBVIEW_FRAME, EDA_DRAW_FRAME ) EVT_SELECT_DCODE( ID_TOOLBARH_GERBER_SELECT_ACTIVE_DCODE, GERBVIEW_FRAME::OnSelectActiveDCode ) + EVT_MENU( ID_MENU_ZOOM_SELECTION, GERBVIEW_FRAME::Process_Special_Functions ) + // Vertical toolbar: EVT_TOOL( ID_NO_TOOL_SELECTED, GERBVIEW_FRAME::Process_Special_Functions ) @@ -231,6 +233,7 @@ void GERBVIEW_FRAME::Process_Special_Functions( wxCommandEvent& event ) SetNoToolSelected(); break; + case ID_MENU_ZOOM_SELECTION: case ID_ZOOM_SELECTION: // This tool is located on the main toolbar: switch it on or off on click if( GetToolId() != ID_ZOOM_SELECTION ) diff --git a/gerbview/hotkeys.cpp b/gerbview/hotkeys.cpp index 278b5ecdd1..0d64bff193 100644 --- a/gerbview/hotkeys.cpp +++ b/gerbview/hotkeys.cpp @@ -64,7 +64,7 @@ static EDA_HOTKEY HkZoomRedraw( _HKI( "Zoom Redraw" ), HK_ZOOM_REDRAW, WXK_F3 static EDA_HOTKEY HkZoomOut( _HKI( "Zoom Out" ), HK_ZOOM_OUT, WXK_F2 ); static EDA_HOTKEY HkZoomIn( _HKI( "Zoom In" ), HK_ZOOM_IN, WXK_F1 ); static EDA_HOTKEY HkZoomSelection( _HKI( "Zoom to Selection" ), - HK_ZOOM_SELECTION, '@' ); + HK_ZOOM_SELECTION, GR_KB_CTRL + WXK_F5 ); static EDA_HOTKEY HkHelp( _HKI( "Help (this window)" ), HK_HELP, '?' ); static EDA_HOTKEY HkSwitchUnits( _HKI( "Switch Units" ), HK_SWITCH_UNITS, 'U' ); static EDA_HOTKEY HkResetLocalCoord( _HKI( "Reset Local Coordinates" ), @@ -192,6 +192,11 @@ bool GERBVIEW_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit GetEventHandler()->ProcessEvent( cmd ); break; + case HK_ZOOM_SELECTION: + //cmd.SetId( ID_ZOOM_SELECTION ); + //GetEventHandler()->ProcessEvent( cmd ); + break; + case HK_ZOOM_AUTO: cmd.SetId( ID_ZOOM_PAGE ); GetEventHandler()->ProcessEvent( cmd ); diff --git a/gerbview/menubar.cpp b/gerbview/menubar.cpp index cd5e1443ca..83dea3ebe8 100644 --- a/gerbview/menubar.cpp +++ b/gerbview/menubar.cpp @@ -212,7 +212,8 @@ void GERBVIEW_FRAME::ReCreateMenuBar() AddMenuItem( viewMenu, ID_ZOOM_PAGE, text, _( "Zoom to fit" ), KiBitmap( zoom_fit_in_page_xpm ) ); - AddMenuItem( viewMenu, ID_ZOOM_SELECTION, _( "Zoom to Selection" ), + text = AddHotkeyName( _( "Zoom to Selection" ), GerbviewHokeysDescr, HK_ZOOM_SELECTION ); + AddMenuItem( viewMenu, ID_MENU_ZOOM_SELECTION, text, KiBitmap( zoom_area_xpm ) ); text = AddHotkeyName( _( "&Redraw" ), GerbviewHokeysDescr, HK_ZOOM_REDRAW ); diff --git a/gerbview/tools/gerbview_actions.cpp b/gerbview/tools/gerbview_actions.cpp index 250fffb8db..230f6d49e4 100644 --- a/gerbview/tools/gerbview_actions.cpp +++ b/gerbview/tools/gerbview_actions.cpp @@ -49,6 +49,9 @@ OPT GERBVIEW_ACTIONS::TranslateLegacyId( int aId ) case ID_ZOOM_PAGE: // toolbar button "Fit on Screen" return ACTIONS::zoomFitScreen.MakeEvent(); + case ID_MENU_ZOOM_SELECTION: + return GERBVIEW_ACTIONS::switchZoomToSelectionTool.MakeEvent(); + case ID_ZOOM_SELECTION: return ACTIONS::zoomTool.MakeEvent(); diff --git a/gerbview/tools/gerbview_actions.h b/gerbview/tools/gerbview_actions.h index 7ee2e6e06e..c6e6febbec 100644 --- a/gerbview/tools/gerbview_actions.h +++ b/gerbview/tools/gerbview_actions.h @@ -124,6 +124,7 @@ public: static TOOL_ACTION switchCursor; static TOOL_ACTION switchUnits; static TOOL_ACTION showHelp; + static TOOL_ACTION switchZoomToSelectionTool; static TOOL_ACTION toBeDone; // Highlighting diff --git a/gerbview/tools/gerbview_control.cpp b/gerbview/tools/gerbview_control.cpp index 38f48f39ed..7ff415f86c 100644 --- a/gerbview/tools/gerbview_control.cpp +++ b/gerbview/tools/gerbview_control.cpp @@ -33,6 +33,9 @@ TOOL_ACTION GERBVIEW_ACTIONS::selectionTool( "gerbview.Control.selectionTool", AS_GLOBAL, 0, "", "", NULL, AF_ACTIVATE ); +TOOL_ACTION GERBVIEW_ACTIONS::switchZoomToSelectionTool( "gerbview.Control.switchZoomToSelectionTool", + AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ZOOM_SELECTION ), "", "" ); + TOOL_ACTION GERBVIEW_ACTIONS::layerChanged( "gerbview.Control.layerChanged", AS_GLOBAL, 0, "", "", NULL, AF_NOTIFY ); @@ -257,6 +260,21 @@ int GERBVIEW_CONTROL::ShowHelp( const TOOL_EVENT& aEvent ) } +int GERBVIEW_CONTROL::SwitchZoomToSelectionTool( const TOOL_EVENT& aEvent ) +{ + // Update the Zoom to Selection Tool state changed from the zoom menuitem + bool state = m_frame->GetToolToggled( ID_ZOOM_SELECTION ); + m_frame->GetMainToolBar()->ToggleTool( ID_ZOOM_SELECTION, !state ); + m_frame->GetMainToolBar()->Refresh(); + + // Send the Zoom to Selection Tool event similar to a tool click: + wxCommandEvent evt( wxEVT_TOOL ); + evt.SetId( ID_ZOOM_SELECTION ); + m_frame->ProcessEvent( evt ); + return 0; +} + + void GERBVIEW_CONTROL::setTransitions() { Go( &GERBVIEW_CONTROL::HighlightControl, GERBVIEW_ACTIONS::highlightClear.MakeEvent() ); @@ -276,4 +294,6 @@ void GERBVIEW_CONTROL::setTransitions() Go( &GERBVIEW_CONTROL::ResetCoords, GERBVIEW_ACTIONS::resetCoords.MakeEvent() ); Go( &GERBVIEW_CONTROL::SwitchUnits, GERBVIEW_ACTIONS::switchUnits.MakeEvent() ); Go( &GERBVIEW_CONTROL::ShowHelp, GERBVIEW_ACTIONS::showHelp.MakeEvent() ); + Go( &GERBVIEW_CONTROL::SwitchZoomToSelectionTool, + GERBVIEW_ACTIONS::switchZoomToSelectionTool.MakeEvent() ); } diff --git a/gerbview/tools/gerbview_control.h b/gerbview/tools/gerbview_control.h index a34e65168a..3d93c1d981 100644 --- a/gerbview/tools/gerbview_control.h +++ b/gerbview/tools/gerbview_control.h @@ -60,6 +60,7 @@ public: int ResetCoords( const TOOL_EVENT& aEvent ); int SwitchUnits( const TOOL_EVENT& aEvent ); int ShowHelp( const TOOL_EVENT& aEvent ); + int SwitchZoomToSelectionTool( const TOOL_EVENT& aEvent ); // On/off main toolbar Zoom to selection tool ///> Sets up handlers for various events. void setTransitions() override;