Eeschema: Fix bug #1271155 relative to Grid selection in Eeschema.

This commit is contained in:
jean-pierre charras 2014-02-02 20:51:50 +01:00
parent 5a6665ec08
commit 8afe2dfbce
8 changed files with 57 additions and 29 deletions

View File

@ -182,23 +182,27 @@ void BASE_SCREEN::GetGrids( GRIDS& aList )
}
void BASE_SCREEN::SetGrid( const wxRealPoint& size )
int BASE_SCREEN::SetGrid( const wxRealPoint& size )
{
wxASSERT( !m_grids.empty() );
GRID_TYPE nearest_grid = m_grids[0];
int gridIdx = 0;
for( unsigned i = 0; i < m_grids.size(); i++ )
{
if( m_grids[i].m_Size == size )
{
m_Grid = m_grids[i];
return;
return m_grids[i].m_Id - ID_POPUP_GRID_LEVEL_1000;
}
// keep track of the nearest larger grid size, if the exact size is not found
if ( size.x < m_grids[i].m_Size.x )
{
gridIdx = m_grids[i].m_Id - ID_POPUP_GRID_LEVEL_1000;
nearest_grid = m_grids[i];
}
}
m_Grid = nearest_grid;
@ -206,27 +210,31 @@ void BASE_SCREEN::SetGrid( const wxRealPoint& size )
wxLogWarning( wxT( "Grid size( %f, %f ) not in grid list, falling back " ) \
wxT( "to grid size( %f, %f )." ),
size.x, size.y, m_Grid.m_Size.x, m_Grid.m_Size.y );
return gridIdx;
}
void BASE_SCREEN::SetGrid( int id )
int BASE_SCREEN::SetGrid( int aCommandId )
{
wxASSERT( !m_grids.empty() );
for( unsigned i = 0; i < m_grids.size(); i++ )
{
if( m_grids[i].m_Id == id )
if( m_grids[i].m_Id == aCommandId )
{
m_Grid = m_grids[i];
return;
return m_grids[i].m_Id - ID_POPUP_GRID_LEVEL_1000;
}
}
m_Grid = m_grids[0];
wxLogWarning( wxT( "Grid ID %d not in grid list, falling back to " ) \
wxT( "grid size( %g, %g )." ), id, m_Grid.m_Size.x,
m_Grid.m_Size.y );
wxT( "grid size( %g, %g )." ), aCommandId,
m_Grid.m_Size.x, m_Grid.m_Size.y );
return m_grids[0].m_Id - ID_POPUP_GRID_LEVEL_1000;
}

View File

@ -60,7 +60,7 @@ static const wxString traceScrollSettings( wxT( "KicadScrollSettings" ) );
static const wxString CursorShapeEntryKeyword( wxT( "CursorShape" ) );
static const wxString ShowGridEntryKeyword( wxT( "ShowGrid" ) );
static const wxString GridColorEntryKeyword( wxT( "GridColor" ) );
static const wxString LastGridSizeId( wxT( "_LastGridSize" ) );
static const wxString LastGridSizeIdKeyword( wxT( "_LastGridSize" ) );
BEGIN_EVENT_TABLE( EDA_DRAW_FRAME, EDA_BASE_FRAME )
@ -334,7 +334,7 @@ void EDA_DRAW_FRAME::PrintPage( wxDC* aDC,LAYER_MSK aPrintMask, bool aPrintMirro
void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
{
int* clientData;
int id = ID_POPUP_GRID_LEVEL_100;
int eventId = ID_POPUP_GRID_LEVEL_100;
if( event.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED )
{
@ -351,11 +351,11 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
clientData = (int*) m_gridSelectBox->wxItemContainer::GetClientData( index );
if( clientData != NULL )
id = *clientData;
eventId = *clientData;
}
else
{
id = event.GetId();
eventId = event.GetId();
/* Update the grid select combobox if the grid size was changed
* by menu event.
@ -366,7 +366,7 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
{
clientData = (int*) m_gridSelectBox->wxItemContainer::GetClientData( i );
if( clientData && id == *clientData )
if( clientData && eventId == *clientData )
{
m_gridSelectBox->SetSelection( i );
break;
@ -375,9 +375,12 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
}
}
// Be sure m_LastGridSizeId is up to date.
m_LastGridSizeId = eventId - ID_POPUP_GRID_LEVEL_1000;
BASE_SCREEN* screen = GetScreen();
if( screen->GetGridId() == id )
if( screen->GetGridId() == eventId )
return;
/*
@ -385,8 +388,7 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
* may be used in the grid size combobox. Do not use the selection
* index returned by GetSelection().
*/
m_LastGridSizeId = id - ID_POPUP_GRID_LEVEL_1000;
screen->SetGrid( id );
screen->SetGrid( eventId );
SetCrossHairPosition( RefPos( true ) );
if( IsGalCanvasActive() )
@ -598,7 +600,11 @@ void EDA_DRAW_FRAME::LoadSettings()
if( cfg->Read( m_FrameName + GridColorEntryKeyword, &itmp ) )
SetGridColor( ColorFromInt( itmp ) );
cfg->Read( m_FrameName + LastGridSizeId, &m_LastGridSizeId, 0L );
cfg->Read( m_FrameName + LastGridSizeIdKeyword, &m_LastGridSizeId, 0L );
// m_LastGridSizeId is an offset, expected to be >= 0
if( m_LastGridSizeId < 0 )
m_LastGridSizeId = 0;
}
@ -612,7 +618,7 @@ void EDA_DRAW_FRAME::SaveSettings()
cfg->Write( m_FrameName + CursorShapeEntryKeyword, m_cursorShape );
cfg->Write( m_FrameName + ShowGridEntryKeyword, IsGridVisible() );
cfg->Write( m_FrameName + GridColorEntryKeyword, ( long ) GetGridColor() );
cfg->Write( m_FrameName + LastGridSizeId, ( long ) m_LastGridSizeId );
cfg->Write( m_FrameName + LastGridSizeIdKeyword, ( long ) m_LastGridSizeId );
}

View File

@ -302,7 +302,8 @@ void SCH_EDIT_FRAME::OnSetOptions( wxCommandEvent& event )
g_UserUnit = (EDA_UNITS_T)dlg.GetUnitsSelection();
GetScreen()->SetGrid( grid_list[ (size_t) dlg.GetGridSelection() ].m_Size );
wxRealPoint gridsize = grid_list[ (size_t) dlg.GetGridSelection() ].m_Size;
m_LastGridSizeId = GetScreen()->SetGrid( gridsize );
int sep, firstId;
dlg.GetRefIdSeparator( sep, firstId);

View File

@ -329,7 +329,7 @@ bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& aFileName, bool aIsNew )
*/
screen->SetZoom( 32 );
screen->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
m_LastGridSizeId = screen->SetGrid( ID_POPUP_GRID_LEVEL_50 );
TITLE_BLOCK tb;
wxString title;

View File

@ -30,6 +30,7 @@
#include <fctsys.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <id.h>
#include <wxEeschemaStruct.h>
#include <general.h>
@ -274,7 +275,10 @@ void SCH_EDIT_FRAME::DisplayCurrentSheet()
SCH_SCREEN* screen = m_CurrentSheet->LastScreen();
// Switch to current sheet,
// and update the grid size, because it can be modified in latest screen
SetScreen( screen );
GetScreen()->SetGrid( m_LastGridSizeId + ID_POPUP_GRID_LEVEL_1000 );
// update the References
m_CurrentSheet->UpdateAllScreenReferences();

View File

@ -207,23 +207,18 @@ LIB_EDIT_FRAME::LIB_EDIT_FRAME( SCH_EDIT_FRAME* aParent,
m_tempCopyComponent = NULL;
m_HotkeysZoomAndGridList = s_Libedit_Hokeys_Descr;
m_editPinsPerPartOrConvert = false;
// Initialize grid id to the default value 50 mils:
m_LastGridSizeId = ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000;
wxIcon icon;
icon.CopyFromBitmap( KiBitmap( libedit_icon_xpm ) );
SetIcon( icon );
SetScreen( new SCH_SCREEN() );
GetScreen()->m_Center = true;
SetCrossHairPosition( wxPoint( 0, 0 ) );
// Initialize grid id to the default value 50 mils:
m_LastGridSizeId = ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000;
LoadSettings();
SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );

View File

@ -402,13 +402,25 @@ public:
*/
const GRID_TYPE& GetGrid() const { return m_Grid; }
void SetGrid( const wxRealPoint& size );
/**
* set the current grid size m_Grid.
* The size must be existing in grid list (in m_grids)
* If not, the near existing grid size is used
* @param size = the size of the new grid
* @return the grid id offset (id from ID_POPUP_GRID_LEVEL_1000 )
* of the currently selected grid.
*/
int SetGrid( const wxRealPoint& size );
/**
* Function SetGrid
* sets the grid size from command ID.
* sets the grid size from command ID (not an index in grid list, but a wxID).
* @param aCommandId = the wxWidgets command ID
* @return the grid id offset (id from ID_POPUP_GRID_LEVEL_1000 )
* of the currently selected grid.
*/
void SetGrid( int id );
int SetGrid( int aCommandId );
void SetGridList( GRIDS& sizelist );
void AddGrid( const GRID_TYPE& grid );
void AddGrid( const wxRealPoint& size, int id );

View File

@ -414,7 +414,9 @@ class EDA_DRAW_FRAME : public EDA_BASE_FRAME
protected:
EDA_HOTKEY_CONFIG* m_HotkeysZoomAndGridList;
int m_LastGridSizeId;
int m_LastGridSizeId; // the command id offset (>= 0) of the last selected grid
// 0 is for the grid corresponding to
// a wxCommand ID = ID_POPUP_GRID_LEVEL_1000.
bool m_DrawGrid; // hide/Show grid
EDA_COLOR_T m_GridColor; // Grid color