From 5a02b91e5f20265a169fbb99f67c07eb7a7b6789 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 1 May 2015 11:31:23 +0200 Subject: [PATCH] Fix some issues created by rev 5632: * Use only double to store zoom levels in class BASE_SCREEN (int type is not working for eeschema or page layout editor) (this fix Bug #1450551, Assertion failed on wxRound() when zooming) * Fix crash in all apps but Pcbnew when a grid or a zoom was selected from the popup menu. * Modify default hotkeys for Next Grid and Previous Grid: the initial key was a dead key, not suitable as hotkey. the 'N' and Shift N keys are used instead (with a change for unfill zone hotkey) * Modify code in EDA_DRAW_FRAME::SetNextGrid() and EDA_DRAW_FRAME::SetPreviousGrid() to make them compatible with other editors than the board editor. --- common/draw_frame.cpp | 41 ++++++++++++++++++++------------- common/zoom.cpp | 5 ++-- include/class_base_screen.h | 2 +- pcbnew/hotkeys.cpp | 6 ++--- pcbnew/tools/common_actions.cpp | 6 ++--- pcbnew/tools/pcbnew_control.cpp | 2 +- pcbnew/tools/zoom_menu.cpp | 2 +- 7 files changed, 37 insertions(+), 27 deletions(-) diff --git a/common/draw_frame.cpp b/common/draw_frame.cpp index 59ebf87e5a..9e83778ebc 100644 --- a/common/draw_frame.cpp +++ b/common/draw_frame.cpp @@ -369,7 +369,7 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event ) if( event.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED ) { - if( m_gridSelectBox == NULL ) + if( m_gridSelectBox == NULL ) // Should no happen return; /* @@ -526,35 +526,44 @@ wxPoint EDA_DRAW_FRAME::GetGridPosition( const wxPoint& aPosition ) const void EDA_DRAW_FRAME::SetNextGrid() { - if( m_gridSelectBox ) - SetPresetGrid( ( m_gridSelectBox->GetSelection() + 1 ) % m_gridSelectBox->GetCount() ); + BASE_SCREEN * screen = GetScreen(); + int grid_cnt = screen->GetGridCount(); + + int new_grid_idx = screen->GetGridId() - ID_POPUP_GRID_LEVEL_1000 + 1; + + if( new_grid_idx >= grid_cnt ) + new_grid_idx = 0; + + SetPresetGrid( new_grid_idx ); } void EDA_DRAW_FRAME::SetPrevGrid() { - if( m_gridSelectBox ) - { - int idx = m_gridSelectBox->GetSelection(); + BASE_SCREEN * screen = GetScreen(); + int grid_cnt = screen->GetGridCount(); - if( --idx < 0 ) - idx = m_gridSelectBox->GetCount() - 1; + int new_grid_idx = screen->GetGridId() - ID_POPUP_GRID_LEVEL_1000 - 1; - SetPresetGrid( idx ); - } + if( new_grid_idx < 0 ) + new_grid_idx = grid_cnt - 1; + + SetPresetGrid( new_grid_idx ); } void EDA_DRAW_FRAME::SetPresetGrid( int aIndex ) { - if( aIndex < 0 || aIndex >= (int) m_gridSelectBox->GetCount() ) - { - wxASSERT_MSG( false, "Invalid grid index" ); - return; - } - if( m_gridSelectBox ) + { + if( aIndex < 0 || aIndex >= (int) m_gridSelectBox->GetCount() ) + { + wxASSERT_MSG( false, "Invalid grid index" ); + return; + } + m_gridSelectBox->SetSelection( aIndex ); + } // Be sure m_LastGridSizeId is up to date. m_LastGridSizeId = aIndex; diff --git a/common/zoom.cpp b/common/zoom.cpp index 8d4ae6740f..a44b9b1a80 100644 --- a/common/zoom.cpp +++ b/common/zoom.cpp @@ -223,7 +223,8 @@ void EDA_DRAW_FRAME::SetPresetZoom( int aIndex ) return; } - m_zoomSelectBox->SetSelection( aIndex ); + if( m_zoomSelectBox ) + m_zoomSelectBox->SetSelection( aIndex ); if( screen->SetZoom( screen->m_ZoomList[aIndex] ) ) RedrawScreen( GetScrollCenterPosition(), true ); @@ -238,7 +239,7 @@ void EDA_DRAW_FRAME::SetPresetZoom( int aIndex ) void EDA_DRAW_FRAME::AddMenuZoomAndGrid( wxMenu* MasterMenu ) { int maxZoomIds; - int zoom; + double zoom; wxString msg; BASE_SCREEN* screen = m_canvas->GetScreen(); diff --git a/include/class_base_screen.h b/include/class_base_screen.h index 64aba0e999..0ea8fa9e7b 100644 --- a/include/class_base_screen.h +++ b/include/class_base_screen.h @@ -215,7 +215,7 @@ public: int m_ScreenNumber; int m_NumberOfScreens; - std::vector m_ZoomList; ///< standard zoom (i.e. scale) coefficients. + std::vector m_ZoomList; ///< standard zoom (i.e. scale) coefficients. bool m_IsPrinting; public: diff --git a/pcbnew/hotkeys.cpp b/pcbnew/hotkeys.cpp index 7dc8325129..80213c70cf 100644 --- a/pcbnew/hotkeys.cpp +++ b/pcbnew/hotkeys.cpp @@ -141,7 +141,7 @@ static EDA_HOTKEY HkCanvasCairo( _HKI( "Switch to Cairo Canvas" ), static EDA_HOTKEY HkZoneFillOrRefill( _HKI( "Fill or Refill All Zones" ), HK_ZONE_FILL_OR_REFILL, 'B' ); static EDA_HOTKEY HkZoneRemoveFilled( _HKI( "Remove Filled Areas in All Zones" ), - HK_ZONE_REMOVE_FILLED, 'N' ); + HK_ZONE_REMOVE_FILLED, 'B' + GR_KB_CTRL ); /* Fit on Screen */ #if !defined( __WXMAC__ ) static EDA_HOTKEY HkZoomAuto( _HKI( "Zoom Auto" ), HK_ZOOM_AUTO, WXK_HOME ); @@ -203,10 +203,10 @@ static EDA_HOTKEY HkSwitchGridToFastGrid2( _HKI( "Switch Grid To Fast Grid2" ), HK_SWITCH_GRID_TO_FASTGRID2, GR_KB_ALT + '2' ); static EDA_HOTKEY HkSwitchGridToNext( _HKI( "Switch Grid To Next" ), - HK_SWITCH_GRID_TO_NEXT, '`' ); + HK_SWITCH_GRID_TO_NEXT, 'N' ); static EDA_HOTKEY HkSwitchGridToPrevious( _HKI( "Switch Grid To Previous" ), - HK_SWITCH_GRID_TO_PREVIOUS, '`' + GR_KB_CTRL ); + HK_SWITCH_GRID_TO_PREVIOUS, 'N' + GR_KB_SHIFT ); static EDA_HOTKEY HkSwitchUnits( _HKI( "Switch Units" ), HK_SWITCH_UNITS, 'U' + GR_KB_CTRL ); static EDA_HOTKEY HkTrackDisplayMode( _HKI( "Track Display Mode" ), diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index 8eac887772..c676f8c73f 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -312,11 +312,11 @@ TOOL_ACTION COMMON_ACTIONS::gridFast2( "common.Control.gridFast2", "", "" ); TOOL_ACTION COMMON_ACTIONS::gridNext( "common.Control.gridNext", - AS_GLOBAL, '`', + AS_GLOBAL, 'N', "", "" ); TOOL_ACTION COMMON_ACTIONS::gridPrev( "common.Control.gridPrev", - AS_GLOBAL, MD_CTRL + int( '`' ), + AS_GLOBAL, MD_SHIFT + int( 'N' ), "", "" ); TOOL_ACTION COMMON_ACTIONS::gridSetOrigin( "common.Control.gridSetOrigin", @@ -363,7 +363,7 @@ TOOL_ACTION COMMON_ACTIONS::zoneUnfill( "pcbnew.EditorControl.zoneUnfill", _( "Unfill" ), _( "Unfill zone(s)" ), zone_unfill_xpm ); TOOL_ACTION COMMON_ACTIONS::zoneUnfillAll( "pcbnew.EditorControl.zoneUnfillAll", - AS_GLOBAL, int( 'N' ), + AS_GLOBAL, MD_CTRL + int( 'B' ), _( "Unfill all" ), _( "Unfill all zones" ) ); diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 99da5fa518..d0f9e3aa8e 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -129,7 +129,7 @@ int PCBNEW_CONTROL::ZoomFitScreen( const TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::ZoomPreset( const TOOL_EVENT& aEvent ) { unsigned int idx = aEvent.Parameter(); - std::vector& zoomList = m_frame->GetScreen()->m_ZoomList; + std::vector& zoomList = m_frame->GetScreen()->m_ZoomList; KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView(); KIGFX::GAL* gal = m_frame->GetGalCanvas()->GetGAL(); diff --git a/pcbnew/tools/zoom_menu.cpp b/pcbnew/tools/zoom_menu.cpp index a7c5355909..3fb9e346eb 100644 --- a/pcbnew/tools/zoom_menu.cpp +++ b/pcbnew/tools/zoom_menu.cpp @@ -64,7 +64,7 @@ OPT_TOOL_EVENT ZOOM_MENU::EventHandler( const wxMenuEvent& aEvent ) void ZOOM_MENU::Update() { double zoom = m_parent->GetScreen()->GetZoom(); - const std::vector& zoomList = m_parent->GetScreen()->m_ZoomList; + const std::vector& zoomList = m_parent->GetScreen()->m_ZoomList; for( unsigned int i = 0; i < GetMenuItemCount(); ++i ) Check( ID_POPUP_ZOOM_LEVEL_START + i, zoomList[i] == zoom );