Move grid selection for both Eeschema and Pcbnew to COMMON_TOOLS.

This commit is contained in:
Jeff Young 2019-04-13 18:41:11 +01:00
parent fc7f5630c7
commit 94a948fdd1
17 changed files with 97 additions and 265 deletions

View File

@ -63,6 +63,7 @@
#include <page_info.h>
#include <title_block.h>
#include <advanced_config.h>
#include <eeschema/tools/sch_actions.h>
/**
* 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;

View File

@ -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;

View File

@ -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<intptr_t>();
return doGridPreset( aEvent.Parameter<intptr_t>() );
}
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 );
}

View File

@ -61,6 +61,7 @@
#include <menus_helpers.h>
#include <wx/progdlg.h>
#include <tool/tool_manager.h>
#include <tool/context_menu.h>
#include <sch_view.h>
#include <sch_painter.h>
@ -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 );

View File

@ -37,6 +37,9 @@
#include <sch_base_frame.h>
#include <symbol_lib_table.h>
#include <dialog_configure_paths.h>
#include <tool/tool_manager.h>
#include <tool/tool_dispatcher.h>
#include <tools/sch_actions.h>
#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();

View File

@ -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

View File

@ -65,7 +65,6 @@
#include <dialog_symbol_remap.h>
#include <view/view.h>
#include <tool/tool_manager.h>
#include <tool/tool_dispatcher.h>
#include <tools/sch_actions.h>
#include <wx/display.h>
@ -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

View File

@ -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
*/

View File

@ -60,6 +60,12 @@ OPT<TOOL_EVENT> 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<TOOL_EVENT>();

View File

@ -48,6 +48,7 @@
#include <view/view_controls.h>
#include <sch_painter.h>
#include <confirm.h>
#include <tool/tool_manager.h>
// 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
{

View File

@ -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.
*

View File

@ -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,

View File

@ -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;

View File

@ -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

View File

@ -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:

View File

@ -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 );
}

View File

@ -103,6 +103,12 @@ OPT<TOOL_EVENT> 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: