diff --git a/common/legacy_gal/eda_draw_frame.cpp b/common/legacy_gal/eda_draw_frame.cpp index 676d54ab31..b27c5695ff 100644 --- a/common/legacy_gal/eda_draw_frame.cpp +++ b/common/legacy_gal/eda_draw_frame.cpp @@ -63,6 +63,7 @@ #include #include #include +#include /** * Definition for enabling and disabling scroll bar setting trace output. See the @@ -522,7 +523,7 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event ) int idx = eventId - ID_POPUP_GRID_LEVEL_1000; - SetPresetGrid( idx ); + GetToolManager()->RunAction( "common.Control.gridPreset", true, idx ); } @@ -624,69 +625,6 @@ wxPoint EDA_DRAW_FRAME::GetGridPosition( const wxPoint& aPosition ) const } -void EDA_DRAW_FRAME::SetNextGrid() -{ - BASE_SCREEN * screen = GetScreen(); - - int new_grid_cmd = screen->GetGridCmdId(); - - // if the grid id is the not the last, increment it - if( screen->GridExists( new_grid_cmd + 1 ) ) - new_grid_cmd += 1; - - SetPresetGrid( new_grid_cmd - ID_POPUP_GRID_LEVEL_1000 ); -} - - -void EDA_DRAW_FRAME::SetPrevGrid() -{ - BASE_SCREEN * screen = GetScreen(); - - int new_grid_cmd = screen->GetGridCmdId(); - - // if the grid id is the not the first, increment it - if( screen->GridExists( new_grid_cmd - 1 ) ) - new_grid_cmd -= 1; - - SetPresetGrid( new_grid_cmd - ID_POPUP_GRID_LEVEL_1000 ); -} - - -void EDA_DRAW_FRAME::SetPresetGrid( int aIndex ) -{ - BASE_SCREEN* screen = GetScreen(); - KIGFX::VIEW* view = GetGalCanvas()->GetView(); - - if( ! screen->GridExists( aIndex + ID_POPUP_GRID_LEVEL_1000 ) ) - aIndex = 0; - - // aIndex is a Command Id relative to ID_POPUP_GRID_LEVEL_1000 comand id code. - // we need an index in grid list (the cmd id in list is is screen->GetGrids()[0].m_CmdId): - int glistIdx = aIndex + ID_POPUP_GRID_LEVEL_1000 - screen->GetGrids()[0].m_CmdId; - - if( m_gridSelectBox ) - { - if( glistIdx < 0 || glistIdx >= (int) m_gridSelectBox->GetCount() ) - { - wxASSERT_MSG( false, "Invalid grid index" ); - return; - } - - m_gridSelectBox->SetSelection( glistIdx ); - } - - // Be sure m_LastGridSizeId is up to date. - m_LastGridSizeId = aIndex; - - screen->SetGrid( aIndex + ID_POPUP_GRID_LEVEL_1000 ); - view->GetGAL()->SetGridSize( VECTOR2D( screen->GetGridSize() ) ); - view->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); - - // Put cursor on new grid - SetCrossHairPosition( RefPos( true ) ); -} - - int EDA_DRAW_FRAME::BlockCommand( EDA_KEY key ) { return 0; diff --git a/common/legacy_wx/eda_draw_frame.cpp b/common/legacy_wx/eda_draw_frame.cpp index 6c366fa999..f235b9cdc0 100644 --- a/common/legacy_wx/eda_draw_frame.cpp +++ b/common/legacy_wx/eda_draw_frame.cpp @@ -531,13 +531,7 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event ) int idx = eventId - ID_POPUP_GRID_LEVEL_1000; - // Notify GAL - TOOL_MANAGER* mgr = GetToolManager(); - - if( mgr && IsGalCanvasActive() ) - mgr->RunAction( "common.Control.gridPreset", true, idx ); - else - SetPresetGrid( idx ); + GetToolManager()->RunAction( "common.Control.gridPreset", true, idx ); m_canvas->Refresh(); } @@ -680,65 +674,6 @@ wxPoint EDA_DRAW_FRAME::GetGridPosition( const wxPoint& aPosition ) const } -void EDA_DRAW_FRAME::SetNextGrid() -{ - BASE_SCREEN * screen = GetScreen(); - - int new_grid_cmd = screen->GetGridCmdId(); - - // if the grid id is the not the last, increment it - if( screen->GridExists( new_grid_cmd + 1 ) ) - new_grid_cmd += 1; - - SetPresetGrid( new_grid_cmd - ID_POPUP_GRID_LEVEL_1000 ); -} - - -void EDA_DRAW_FRAME::SetPrevGrid() -{ - BASE_SCREEN * screen = GetScreen(); - - int new_grid_cmd = screen->GetGridCmdId(); - - // if the grid id is the not the first, increment it - if( screen->GridExists( new_grid_cmd - 1 ) ) - new_grid_cmd -= 1; - - SetPresetGrid( new_grid_cmd - ID_POPUP_GRID_LEVEL_1000 ); -} - - -void EDA_DRAW_FRAME::SetPresetGrid( int aIndex ) -{ - BASE_SCREEN * screen = GetScreen(); - - if( ! screen->GridExists( aIndex + ID_POPUP_GRID_LEVEL_1000 ) ) - aIndex = screen->GetGrids()[0].m_CmdId; - - // aIndex is a Command Id relative to ID_POPUP_GRID_LEVEL_1000 comand id code. - // we need an index in grid list (the cmd id in list is is screen->GetGrids()[0].m_CmdId): - int glistIdx = aIndex + ID_POPUP_GRID_LEVEL_1000 - screen->GetGrids()[0].m_CmdId; - - if( m_gridSelectBox ) - { - if( glistIdx < 0 || glistIdx >= (int) m_gridSelectBox->GetCount() - 2 ) - { - wxASSERT_MSG( false, "Invalid grid index" ); - return; - } - - m_gridSelectBox->SetSelection( glistIdx ); - } - - // Be sure m_LastGridSizeId is up to date. - m_LastGridSizeId = aIndex; - GetScreen()->SetGrid( aIndex + ID_POPUP_GRID_LEVEL_1000 ); - - // Put cursor on new grid - SetCrossHairPosition( RefPos( true ) ); -} - - int EDA_DRAW_FRAME::BlockCommand( EDA_KEY key ) { return 0; diff --git a/common/tool/common_tools.cpp b/common/tool/common_tools.cpp index bd0d594b07..c50bc525ae 100644 --- a/common/tool/common_tools.cpp +++ b/common/tool/common_tools.cpp @@ -336,28 +336,60 @@ int COMMON_TOOLS::doZoomToPreset( int idx, bool aCenterOnCursor ) // Grid control int COMMON_TOOLS::GridNext( const TOOL_EVENT& aEvent ) { - m_frame->SetNextGrid(); - updateGrid(); + BASE_SCREEN * screen = m_frame->GetScreen(); - return 0; + int new_grid_cmd = screen->GetGridCmdId(); + + // if the grid id is the not the last, increment it + if( screen->GridExists( new_grid_cmd + 1 ) ) + new_grid_cmd += 1; + + return doGridPreset( new_grid_cmd - ID_POPUP_GRID_LEVEL_1000 ); } int COMMON_TOOLS::GridPrev( const TOOL_EVENT& aEvent ) { - m_frame->SetPrevGrid(); - updateGrid(); + BASE_SCREEN * screen = m_frame->GetScreen(); - return 0; + int new_grid_cmd = screen->GetGridCmdId(); + + // if the grid id is the not the first, increment it + if( screen->GridExists( new_grid_cmd - 1 ) ) + new_grid_cmd -= 1; + + return doGridPreset( new_grid_cmd - ID_POPUP_GRID_LEVEL_1000 ); } int COMMON_TOOLS::GridPreset( const TOOL_EVENT& aEvent ) { - long idx = aEvent.Parameter(); + return doGridPreset( aEvent.Parameter() ); +} - m_frame->SetPresetGrid( idx ); - updateGrid(); + +int COMMON_TOOLS::doGridPreset( int idx ) +{ + BASE_SCREEN* screen = m_frame->GetScreen(); + + if( !screen->GridExists( idx + ID_POPUP_GRID_LEVEL_1000 ) ) + idx = 0; + + screen->SetGrid( idx + ID_POPUP_GRID_LEVEL_1000 ); + + // Be sure m_LastGridSizeId is up to date. + m_frame->SetLastGridSizeId( idx ); + + // Update the combobox (if any) + wxUpdateUIEvent dummy; + m_frame->OnUpdateSelectGrid( dummy ); + + // Update GAL canvas from screen + getView()->GetGAL()->SetGridSize( VECTOR2D( screen->GetGridSize() ) ); + getView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); + + // Put cursor on new grid + m_frame->SetCrossHairPosition( m_frame->RefPos( true ) ); return 0; } @@ -415,9 +447,3 @@ void COMMON_TOOLS::setTransitions() } -void COMMON_TOOLS::updateGrid() -{ - BASE_SCREEN* screen = m_frame->GetScreen(); - getView()->GetGAL()->SetGridSize( VECTOR2D( screen->GetGridSize() ) ); - getView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); -} diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp index 303f5811fc..27ac6a1254 100644 --- a/eeschema/libedit/lib_edit_frame.cpp +++ b/eeschema/libedit/lib_edit_frame.cpp @@ -61,6 +61,7 @@ #include #include +#include #include #include #include @@ -231,8 +232,6 @@ LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : SetCrossHairPosition( wxPoint( 0, 0 ) ); - SetPresetGrid( m_LastGridSizeId ); - SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); if( m_canvas ) @@ -268,6 +267,9 @@ LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : m_auimgr.Update(); + setupTools(); + GetToolManager()->RunAction( "common.Control.gridPreset", true, m_LastGridSizeId ); + Raise(); Show( true ); diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp index 5421a7c76c..528914a277 100644 --- a/eeschema/sch_base_frame.cpp +++ b/eeschema/sch_base_frame.cpp @@ -37,6 +37,9 @@ #include #include #include +#include +#include +#include #include "dialogs/panel_sym_lib_table.h" @@ -107,6 +110,22 @@ SCH_BASE_FRAME::~SCH_BASE_FRAME() } +void SCH_BASE_FRAME::setupTools() +{ + // Create the manager and dispatcher & route draw panel events to the dispatcher + m_toolManager = new TOOL_MANAGER; + m_toolManager->SetEnvironment( GetScreen(), GetCanvas()->GetView(), + GetCanvas()->GetViewControls(), this ); + m_actions = new SCH_ACTIONS(); + m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions ); + + // Register tools + m_actions->RegisterAllTools( m_toolManager ); + m_toolManager->InitTools(); + GetCanvas()->SetEventDispatcher( m_toolDispatcher ); +} + + void SCH_BASE_FRAME::OnUpdateSwitchCanvas( wxUpdateUIEvent& aEvent ) { wxMenuBar* menuBar = GetMenuBar(); diff --git a/eeschema/sch_base_frame.h b/eeschema/sch_base_frame.h index d49f40558e..c837f9e156 100644 --- a/eeschema/sch_base_frame.h +++ b/eeschema/sch_base_frame.h @@ -327,6 +327,9 @@ public: protected: + // Sets up the tool framework + void setupTools(); + /** * Open the library viewer only to browse library contents. * If the viewed is already opened from this, raise the viewer diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 1e3bc50867..290274ab72 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -65,7 +65,6 @@ #include #include #include -#include #include #include @@ -414,8 +413,6 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ): CreateScreens(); - SetPresetGrid( m_LastGridSizeId ); - SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); if( m_canvas ) @@ -444,8 +441,8 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ): m_auimgr.Update(); setupTools(); - - Zoom_Automatique( false ); + GetToolManager()->RunAction( "common.Control.gridPreset", true, m_LastGridSizeId ); + GetToolManager()->RunAction( "common.Control.zoomFitScreen", true ); if( GetGalCanvas() ) GetGalCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() ); @@ -482,22 +479,6 @@ SCH_EDIT_FRAME::~SCH_EDIT_FRAME() } -void SCH_EDIT_FRAME::setupTools() -{ - // Create the manager and dispatcher & route draw panel events to the dispatcher - m_toolManager = new TOOL_MANAGER; - m_toolManager->SetEnvironment( GetScreen(), GetCanvas()->GetView(), - GetCanvas()->GetViewControls(), this ); - m_actions = new SCH_ACTIONS(); - m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions ); - - // Register tools - m_actions->RegisterAllTools( m_toolManager ); - m_toolManager->InitTools(); - GetCanvas()->SetEventDispatcher( m_toolDispatcher ); -} - - void SCH_EDIT_FRAME::SetRepeatItem( SCH_ITEM* aItem ) { // we cannot store a pointer to an item in the display list here since diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index 0547fea29b..b230c8409d 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -203,9 +203,6 @@ private: static wxPoint m_lastSheetPinPosition; ///< Last sheet pin position. protected: - // The Tool Framework initalization - void setupTools(); - /** * Initializing accessor for the pin text size */ diff --git a/eeschema/tools/sch_actions.cpp b/eeschema/tools/sch_actions.cpp index 83ddd66693..48da85ffd7 100644 --- a/eeschema/tools/sch_actions.cpp +++ b/eeschema/tools/sch_actions.cpp @@ -60,6 +60,12 @@ OPT SCH_ACTIONS::TranslateLegacyId( int aId ) case ID_ZOOM_SELECTION: return ACTIONS::zoomTool.MakeEvent(); + + case ID_POPUP_GRID_NEXT: + return ACTIONS::gridNext.MakeEvent(); + + case ID_POPUP_GRID_PREV: + return ACTIONS::gridPrev.MakeEvent(); } return OPT(); diff --git a/eeschema/viewlib_frame.cpp b/eeschema/viewlib_frame.cpp index 81311a6ce5..aed5cd84d5 100644 --- a/eeschema/viewlib_frame.cpp +++ b/eeschema/viewlib_frame.cpp @@ -48,6 +48,7 @@ #include #include #include +#include // Save previous component library viewer state. wxString LIB_VIEW_FRAME::m_libraryName; @@ -141,8 +142,6 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); - SetPresetGrid( m_LastGridSizeId ); - // Menu bar is not mandatory: uncomment/comment the next line // to add/remove the menubar ReCreateMenuBar(); @@ -189,12 +188,9 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame m_auimgr.Update(); - // Now Drawpanel is sized, we can use BestZoom to show the component (if any) -#ifdef USE_WX_GRAPHICS_CONTEXT - GetScreen()->SetScalingFactor( BestZoom() ); -#else - Zoom_Automatique( false ); -#endif + setupTools(); + GetToolManager()->RunAction( "common.Control.gridPreset", true, m_LastGridSizeId ); + GetToolManager()->RunAction( "common.Control.zoomFitScreen", true ); if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame { diff --git a/include/draw_frame.h b/include/draw_frame.h index f80ad6efb9..0e0419822c 100644 --- a/include/draw_frame.h +++ b/include/draw_frame.h @@ -566,23 +566,6 @@ public: */ wxPoint GetGridPosition( const wxPoint& aPosition ) const; - /** - * Change the grid size settings to the next one available. - */ - virtual void SetNextGrid(); - - /** - * Change the grid size settings to the previous one available. - */ - virtual void SetPrevGrid(); - - /** - * Change the grid size to one of the preset values. - * - * @param aIndex is the index from the list. - */ - void SetPresetGrid( int aIndex ); - /** * Command event handler for selecting grid sizes. * diff --git a/include/id.h b/include/id.h index 3b4e509abc..c8bde799ba 100644 --- a/include/id.h +++ b/include/id.h @@ -207,8 +207,8 @@ enum main_id ID_POPUP_ZOOM_END_RANGE, // last zoom id ID_ON_GRID_SELECT, - ID_POPUP_GRID_PLUS, - ID_POPUP_GRID_MOINS, + ID_POPUP_GRID_NEXT, + ID_POPUP_GRID_PREV, ID_POPUP_GRID_SELECT, ID_POPUP_GRID_LEVEL_1000, // id for first predefined grid in inches (1000 * 0.0001 inch) ID_POPUP_GRID_LEVEL_500, diff --git a/include/pcb_base_frame.h b/include/pcb_base_frame.h index 92a390a81b..1bcf2a16e0 100644 --- a/include/pcb_base_frame.h +++ b/include/pcb_base_frame.h @@ -599,18 +599,6 @@ public: */ void SetFastGrid2(); - /** - * Virtual function SetNextGrid() - * changes the grid size settings to the next one available. - */ - void SetNextGrid() override; - - /** - * Virtual function SetPrevGrid() - * changes the grid size settings to the previous one available. - */ - void SetPrevGrid() override; - ///> @copydoc EDA_DRAW_FRAME::UseGalCanvas virtual void UseGalCanvas( bool aEnable ) override; diff --git a/include/tool/common_tools.h b/include/tool/common_tools.h index ced8464682..826df337ce 100644 --- a/include/tool/common_tools.h +++ b/include/tool/common_tools.h @@ -77,8 +77,7 @@ private: ///> Note: idx == 0 is Auto; idx == 1 is first entry in zoomList int doZoomToPreset( int idx, bool aCenterOnCursor ); - ///> Applies the legacy canvas grid settings for GAL. - void updateGrid(); + int doGridPreset( int idx ); }; #endif diff --git a/pcbnew/hotkeys_board_editor.cpp b/pcbnew/hotkeys_board_editor.cpp index 7a343a43fd..a9e99427d0 100644 --- a/pcbnew/hotkeys_board_editor.cpp +++ b/pcbnew/hotkeys_board_editor.cpp @@ -148,11 +148,11 @@ bool PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit break; case HK_SWITCH_GRID_TO_NEXT: - SetNextGrid(); + evt_type = ID_POPUP_GRID_NEXT; break; case HK_SWITCH_GRID_TO_PREVIOUS: - SetPrevGrid(); + evt_type = ID_POPUP_GRID_PREV; break; case HK_SWITCH_LAYER_TO_PREVIOUS: diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index dcf825c2a6..8e9447cf78 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -1075,17 +1075,8 @@ void PCB_BASE_FRAME::SetFastGrid1() if( m_FastGrid1 >= (int)GetScreen()->GetGridCount() ) return; - int cmdId = GetScreen()->GetGrids()[m_FastGrid1].m_CmdId; - SetPresetGrid( cmdId - ID_POPUP_GRID_LEVEL_1000 ); - - if( m_gridSelectBox ) - { - wxCommandEvent cmd( wxEVT_CHOICE ); - cmd.SetEventObject( this ); - OnSelectGrid( cmd ); - } - else - GetCanvas()->Refresh(); + int cmdId = GetScreen()->GetGrids()[m_FastGrid1].m_CmdId - ID_POPUP_GRID_LEVEL_1000; + GetToolManager()->RunAction( "common.Control.gridPreset", true, cmdId ); } @@ -1094,46 +1085,8 @@ void PCB_BASE_FRAME::SetFastGrid2() if( m_FastGrid2 >= (int)GetScreen()->GetGridCount() ) return; - int cmdId = GetScreen()->GetGrids()[m_FastGrid2].m_CmdId; - SetPresetGrid( cmdId - ID_POPUP_GRID_LEVEL_1000 ); - - if( m_gridSelectBox ) - { - wxCommandEvent cmd( wxEVT_CHOICE ); - cmd.SetEventObject( this ); - OnSelectGrid( cmd ); - } - else - GetCanvas()->Refresh(); -} - -void PCB_BASE_FRAME::SetNextGrid() -{ - EDA_DRAW_FRAME::SetNextGrid(); - - if( m_gridSelectBox ) - { - wxCommandEvent cmd( wxEVT_CHOICE ); - cmd.SetEventObject( this ); - OnSelectGrid( cmd ); - } - else - GetCanvas()->Refresh(); -} - - -void PCB_BASE_FRAME::SetPrevGrid() -{ - EDA_DRAW_FRAME::SetPrevGrid(); - - if( m_gridSelectBox ) - { - wxCommandEvent cmd( wxEVT_CHOICE ); - cmd.SetEventObject( this ); - OnSelectGrid( cmd ); - } - else - GetCanvas()->Refresh(); + int cmdId = GetScreen()->GetGrids()[m_FastGrid2].m_CmdId - ID_POPUP_GRID_LEVEL_1000; + GetToolManager()->RunAction( "common.Control.gridPreset", true, cmdId ); } diff --git a/pcbnew/tools/pcb_actions.cpp b/pcbnew/tools/pcb_actions.cpp index 564f1fdc26..ffd3882122 100644 --- a/pcbnew/tools/pcb_actions.cpp +++ b/pcbnew/tools/pcb_actions.cpp @@ -103,6 +103,12 @@ OPT PCB_ACTIONS::TranslateLegacyId( int aId ) case ID_MODEDIT_PLACE_GRID_COORD: return ACTIONS::gridSetOrigin.MakeEvent(); + case ID_POPUP_GRID_NEXT: + return ACTIONS::gridNext.MakeEvent(); + + case ID_POPUP_GRID_PREV: + return ACTIONS::gridPrev.MakeEvent(); + case ID_ZOOM_REDRAW: case ID_POPUP_ZOOM_REDRAW: case ID_VIEWER_ZOOM_REDRAW: