Commit 025d4cf2 authored by Maciej Suminski's avatar Maciej Suminski

Alternative way of handling grid settings in GAL.

parent 4be876a1
......@@ -387,46 +387,17 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
else
{
eventId = event.GetId();
/* Update the grid select combobox if the grid size was changed
* by menu event.
*/
if( m_gridSelectBox != NULL )
{
for( size_t i = 0; i < m_gridSelectBox->GetCount(); i++ )
{
clientData = (int*) m_gridSelectBox->wxItemContainer::GetClientData( i );
if( clientData && eventId == *clientData )
{
m_gridSelectBox->SetSelection( i );
break;
}
}
}
}
// Be sure m_LastGridSizeId is up to date.
m_LastGridSizeId = eventId - ID_POPUP_GRID_LEVEL_1000;
BASE_SCREEN* screen = GetScreen();
if( screen->GetGridId() == eventId )
return;
int idx = eventId - ID_POPUP_GRID_LEVEL_1000;
/*
* This allows for saving non-sequential command ID offsets used that
* may be used in the grid size combobox. Do not use the selection
* index returned by GetSelection().
*/
screen->SetGrid( eventId );
SetCrossHairPosition( RefPos( true ) );
// Notify GAL
TOOL_MANAGER* mgr = GetToolManager();
if( IsGalCanvasActive() )
{
GetGalCanvas()->GetGAL()->SetGridSize( VECTOR2D( screen->GetGrid().m_Size ) );
GetGalCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
}
if( mgr && IsGalCanvasActive() )
mgr->RunAction( "common.Control.gridPreset", true, idx );
else
SetPresetGrid( idx );
m_canvas->Refresh();
}
......@@ -556,14 +527,7 @@ wxPoint EDA_DRAW_FRAME::GetGridPosition( const wxPoint& aPosition ) const
void EDA_DRAW_FRAME::SetNextGrid()
{
if( m_gridSelectBox )
{
m_gridSelectBox->SetSelection( ( m_gridSelectBox->GetSelection() + 1 ) %
m_gridSelectBox->GetCount() );
wxCommandEvent cmd( wxEVT_COMMAND_COMBOBOX_SELECTED );
// cmd.SetEventObject( this );
OnSelectGrid( cmd );
}
SetPresetGrid( ( m_gridSelectBox->GetSelection() + 1 ) % m_gridSelectBox->GetCount() );
}
......@@ -571,17 +535,31 @@ void EDA_DRAW_FRAME::SetPrevGrid()
{
if( m_gridSelectBox )
{
int cnt = m_gridSelectBox->GetSelection();
int idx = m_gridSelectBox->GetSelection();
if( --cnt < 0 )
cnt = m_gridSelectBox->GetCount() - 1;
if( --idx < 0 )
idx = m_gridSelectBox->GetCount() - 1;
SetPresetGrid( idx );
}
}
m_gridSelectBox->SetSelection( cnt );
wxCommandEvent cmd( wxEVT_COMMAND_COMBOBOX_SELECTED );
// cmd.SetEventObject( this );
OnSelectGrid( cmd );
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 )
m_gridSelectBox->SetSelection( aIndex );
// Be sure m_LastGridSizeId is up to date.
m_LastGridSizeId = aIndex;
GetScreen()->SetGrid( aIndex + ID_POPUP_GRID_LEVEL_1000 );
SetCrossHairPosition( RefPos( true ) );
}
......
......@@ -439,6 +439,13 @@ public:
*/
virtual void SetPrevGrid();
/**
* Function SetPresetGrid()
* changes 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.
*
......
......@@ -303,26 +303,29 @@ TOOL_ACTION COMMON_ACTIONS::layerChanged( "pcbnew.Control.layerChanged",
// Grid control
TOOL_ACTION COMMON_ACTIONS::gridFast1( "pcbnew.Control.gridFast1",
TOOL_ACTION COMMON_ACTIONS::gridFast1( "common.Control.gridFast1",
AS_GLOBAL, MD_ALT + int( '1' ),
"", "" );
TOOL_ACTION COMMON_ACTIONS::gridFast2( "pcbnew.Control.gridFast2",
TOOL_ACTION COMMON_ACTIONS::gridFast2( "common.Control.gridFast2",
AS_GLOBAL, MD_ALT + int( '2' ),
"", "" );
TOOL_ACTION COMMON_ACTIONS::gridNext( "pcbnew.Control.gridNext",
TOOL_ACTION COMMON_ACTIONS::gridNext( "common.Control.gridNext",
AS_GLOBAL, '`',
"", "" );
TOOL_ACTION COMMON_ACTIONS::gridPrev( "pcbnew.Control.gridPrev",
TOOL_ACTION COMMON_ACTIONS::gridPrev( "common.Control.gridPrev",
AS_GLOBAL, MD_CTRL + int( '`' ),
"", "" );
TOOL_ACTION COMMON_ACTIONS::gridSetOrigin( "pcbnew.Control.gridSetOrigin",
TOOL_ACTION COMMON_ACTIONS::gridSetOrigin( "common.Control.gridSetOrigin",
AS_GLOBAL, 0,
"", "" );
TOOL_ACTION COMMON_ACTIONS::gridPreset( "common.Control.gridPreset",
AS_GLOBAL, 0,
"", "" );
// Track & via size control
TOOL_ACTION COMMON_ACTIONS::trackWidthInc( "pcbnew.EditorControl.trackWidthInc",
......
......@@ -223,6 +223,7 @@ public:
static TOOL_ACTION gridNext;
static TOOL_ACTION gridPrev;
static TOOL_ACTION gridSetOrigin;
static TOOL_ACTION gridPreset;
// Track & via size control
static TOOL_ACTION trackWidthInc;
......
......@@ -446,6 +446,21 @@ int PCBNEW_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent )
}
int PCBNEW_CONTROL::GridPreset( const TOOL_EVENT& aEvent )
{
long idx = aEvent.Parameter<long>();
m_frame->SetPresetGrid( idx );
BASE_SCREEN* screen = m_frame->GetScreen();
GRID_TYPE grid = screen->GetGrid( idx );
getView()->GetGAL()->SetGridSize( VECTOR2D( grid.m_Size ) );
getView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
return 0;
}
// Miscellaneous
int PCBNEW_CONTROL::ResetCoords( const TOOL_EVENT& aEvent )
{
......@@ -549,7 +564,7 @@ void PCBNEW_CONTROL::SetTransitions()
Go( &PCBNEW_CONTROL::GridNext, COMMON_ACTIONS::gridNext.MakeEvent() );
Go( &PCBNEW_CONTROL::GridPrev, COMMON_ACTIONS::gridPrev.MakeEvent() );
Go( &PCBNEW_CONTROL::GridSetOrigin, COMMON_ACTIONS::gridSetOrigin.MakeEvent() );
//Go( &PCBNEW_CONTROL::GridSetPreset, COMMON_ACTIONS::gridSetPreset.MakeEvent() );
Go( &PCBNEW_CONTROL::GridPreset, COMMON_ACTIONS::gridPreset.MakeEvent() );
// Miscellaneous
Go( &PCBNEW_CONTROL::ResetCoords, COMMON_ACTIONS::resetCoords.MakeEvent() );
......
......@@ -72,6 +72,7 @@ public:
int GridNext( const TOOL_EVENT& aEvent );
int GridPrev( const TOOL_EVENT& aEvent );
int GridSetOrigin( const TOOL_EVENT& aEvent );
int GridPreset( const TOOL_EVENT& aEvent );
// Miscellaneous
int ResetCoords( const TOOL_EVENT& aEvent );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment