Commit 8afe2dfb authored by jean-pierre charras's avatar jean-pierre charras

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

parent 5a6665ec
...@@ -182,23 +182,27 @@ void BASE_SCREEN::GetGrids( GRIDS& aList ) ...@@ -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() ); wxASSERT( !m_grids.empty() );
GRID_TYPE nearest_grid = m_grids[0]; GRID_TYPE nearest_grid = m_grids[0];
int gridIdx = 0;
for( unsigned i = 0; i < m_grids.size(); i++ ) for( unsigned i = 0; i < m_grids.size(); i++ )
{ {
if( m_grids[i].m_Size == size ) if( m_grids[i].m_Size == size )
{ {
m_Grid = m_grids[i]; 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 // keep track of the nearest larger grid size, if the exact size is not found
if ( size.x < m_grids[i].m_Size.x ) 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]; nearest_grid = m_grids[i];
}
} }
m_Grid = nearest_grid; m_Grid = nearest_grid;
...@@ -206,27 +210,31 @@ void BASE_SCREEN::SetGrid( const wxRealPoint& size ) ...@@ -206,27 +210,31 @@ void BASE_SCREEN::SetGrid( const wxRealPoint& size )
wxLogWarning( wxT( "Grid size( %f, %f ) not in grid list, falling back " ) \ wxLogWarning( wxT( "Grid size( %f, %f ) not in grid list, falling back " ) \
wxT( "to grid size( %f, %f )." ), wxT( "to grid size( %f, %f )." ),
size.x, size.y, m_Grid.m_Size.x, m_Grid.m_Size.y ); 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() ); wxASSERT( !m_grids.empty() );
for( unsigned i = 0; i < m_grids.size(); i++ ) 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]; m_Grid = m_grids[i];
return; return m_grids[i].m_Id - ID_POPUP_GRID_LEVEL_1000;
} }
} }
m_Grid = m_grids[0]; m_Grid = m_grids[0];
wxLogWarning( wxT( "Grid ID %d not in grid list, falling back to " ) \ wxLogWarning( wxT( "Grid ID %d not in grid list, falling back to " ) \
wxT( "grid size( %g, %g )." ), id, m_Grid.m_Size.x, wxT( "grid size( %g, %g )." ), aCommandId,
m_Grid.m_Size.y ); m_Grid.m_Size.x, m_Grid.m_Size.y );
return m_grids[0].m_Id - ID_POPUP_GRID_LEVEL_1000;
} }
......
...@@ -60,7 +60,7 @@ static const wxString traceScrollSettings( wxT( "KicadScrollSettings" ) ); ...@@ -60,7 +60,7 @@ static const wxString traceScrollSettings( wxT( "KicadScrollSettings" ) );
static const wxString CursorShapeEntryKeyword( wxT( "CursorShape" ) ); static const wxString CursorShapeEntryKeyword( wxT( "CursorShape" ) );
static const wxString ShowGridEntryKeyword( wxT( "ShowGrid" ) ); static const wxString ShowGridEntryKeyword( wxT( "ShowGrid" ) );
static const wxString GridColorEntryKeyword( wxT( "GridColor" ) ); 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 ) 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 ...@@ -334,7 +334,7 @@ void EDA_DRAW_FRAME::PrintPage( wxDC* aDC,LAYER_MSK aPrintMask, bool aPrintMirro
void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event ) void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
{ {
int* clientData; int* clientData;
int id = ID_POPUP_GRID_LEVEL_100; int eventId = ID_POPUP_GRID_LEVEL_100;
if( event.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED ) if( event.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED )
{ {
...@@ -351,11 +351,11 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event ) ...@@ -351,11 +351,11 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
clientData = (int*) m_gridSelectBox->wxItemContainer::GetClientData( index ); clientData = (int*) m_gridSelectBox->wxItemContainer::GetClientData( index );
if( clientData != NULL ) if( clientData != NULL )
id = *clientData; eventId = *clientData;
} }
else else
{ {
id = event.GetId(); eventId = event.GetId();
/* Update the grid select combobox if the grid size was changed /* Update the grid select combobox if the grid size was changed
* by menu event. * by menu event.
...@@ -366,7 +366,7 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event ) ...@@ -366,7 +366,7 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
{ {
clientData = (int*) m_gridSelectBox->wxItemContainer::GetClientData( i ); clientData = (int*) m_gridSelectBox->wxItemContainer::GetClientData( i );
if( clientData && id == *clientData ) if( clientData && eventId == *clientData )
{ {
m_gridSelectBox->SetSelection( i ); m_gridSelectBox->SetSelection( i );
break; break;
...@@ -375,9 +375,12 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event ) ...@@ -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(); BASE_SCREEN* screen = GetScreen();
if( screen->GetGridId() == id ) if( screen->GetGridId() == eventId )
return; return;
/* /*
...@@ -385,8 +388,7 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event ) ...@@ -385,8 +388,7 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
* may be used in the grid size combobox. Do not use the selection * may be used in the grid size combobox. Do not use the selection
* index returned by GetSelection(). * index returned by GetSelection().
*/ */
m_LastGridSizeId = id - ID_POPUP_GRID_LEVEL_1000; screen->SetGrid( eventId );
screen->SetGrid( id );
SetCrossHairPosition( RefPos( true ) ); SetCrossHairPosition( RefPos( true ) );
if( IsGalCanvasActive() ) if( IsGalCanvasActive() )
...@@ -598,7 +600,11 @@ void EDA_DRAW_FRAME::LoadSettings() ...@@ -598,7 +600,11 @@ void EDA_DRAW_FRAME::LoadSettings()
if( cfg->Read( m_FrameName + GridColorEntryKeyword, &itmp ) ) if( cfg->Read( m_FrameName + GridColorEntryKeyword, &itmp ) )
SetGridColor( ColorFromInt( 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() ...@@ -612,7 +618,7 @@ void EDA_DRAW_FRAME::SaveSettings()
cfg->Write( m_FrameName + CursorShapeEntryKeyword, m_cursorShape ); cfg->Write( m_FrameName + CursorShapeEntryKeyword, m_cursorShape );
cfg->Write( m_FrameName + ShowGridEntryKeyword, IsGridVisible() ); cfg->Write( m_FrameName + ShowGridEntryKeyword, IsGridVisible() );
cfg->Write( m_FrameName + GridColorEntryKeyword, ( long ) GetGridColor() ); cfg->Write( m_FrameName + GridColorEntryKeyword, ( long ) GetGridColor() );
cfg->Write( m_FrameName + LastGridSizeId, ( long ) m_LastGridSizeId ); cfg->Write( m_FrameName + LastGridSizeIdKeyword, ( long ) m_LastGridSizeId );
} }
......
...@@ -302,7 +302,8 @@ void SCH_EDIT_FRAME::OnSetOptions( wxCommandEvent& event ) ...@@ -302,7 +302,8 @@ void SCH_EDIT_FRAME::OnSetOptions( wxCommandEvent& event )
g_UserUnit = (EDA_UNITS_T)dlg.GetUnitsSelection(); 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; int sep, firstId;
dlg.GetRefIdSeparator( sep, firstId); dlg.GetRefIdSeparator( sep, firstId);
......
...@@ -329,7 +329,7 @@ bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& aFileName, bool aIsNew ) ...@@ -329,7 +329,7 @@ bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& aFileName, bool aIsNew )
*/ */
screen->SetZoom( 32 ); screen->SetZoom( 32 );
screen->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId ); m_LastGridSizeId = screen->SetGrid( ID_POPUP_GRID_LEVEL_50 );
TITLE_BLOCK tb; TITLE_BLOCK tb;
wxString title; wxString title;
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <fctsys.h> #include <fctsys.h>
#include <class_drawpanel.h> #include <class_drawpanel.h>
#include <confirm.h> #include <confirm.h>
#include <id.h>
#include <wxEeschemaStruct.h> #include <wxEeschemaStruct.h>
#include <general.h> #include <general.h>
...@@ -274,7 +275,10 @@ void SCH_EDIT_FRAME::DisplayCurrentSheet() ...@@ -274,7 +275,10 @@ void SCH_EDIT_FRAME::DisplayCurrentSheet()
SCH_SCREEN* screen = m_CurrentSheet->LastScreen(); 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 ); SetScreen( screen );
GetScreen()->SetGrid( m_LastGridSizeId + ID_POPUP_GRID_LEVEL_1000 );
// update the References // update the References
m_CurrentSheet->UpdateAllScreenReferences(); m_CurrentSheet->UpdateAllScreenReferences();
......
...@@ -207,23 +207,18 @@ LIB_EDIT_FRAME::LIB_EDIT_FRAME( SCH_EDIT_FRAME* aParent, ...@@ -207,23 +207,18 @@ LIB_EDIT_FRAME::LIB_EDIT_FRAME( SCH_EDIT_FRAME* aParent,
m_tempCopyComponent = NULL; m_tempCopyComponent = NULL;
m_HotkeysZoomAndGridList = s_Libedit_Hokeys_Descr; m_HotkeysZoomAndGridList = s_Libedit_Hokeys_Descr;
m_editPinsPerPartOrConvert = false; m_editPinsPerPartOrConvert = false;
// Initialize grid id to the default value 50 mils:
m_LastGridSizeId = ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000; m_LastGridSizeId = ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000;
wxIcon icon; wxIcon icon;
icon.CopyFromBitmap( KiBitmap( libedit_icon_xpm ) ); icon.CopyFromBitmap( KiBitmap( libedit_icon_xpm ) );
SetIcon( icon ); SetIcon( icon );
SetScreen( new SCH_SCREEN() ); SetScreen( new SCH_SCREEN() );
GetScreen()->m_Center = true; GetScreen()->m_Center = true;
SetCrossHairPosition( wxPoint( 0, 0 ) ); 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(); LoadSettings();
SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
......
...@@ -402,13 +402,25 @@ public: ...@@ -402,13 +402,25 @@ public:
*/ */
const GRID_TYPE& GetGrid() const { return m_Grid; } 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 * 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 SetGridList( GRIDS& sizelist );
void AddGrid( const GRID_TYPE& grid ); void AddGrid( const GRID_TYPE& grid );
void AddGrid( const wxRealPoint& size, int id ); void AddGrid( const wxRealPoint& size, int id );
......
...@@ -414,7 +414,9 @@ class EDA_DRAW_FRAME : public EDA_BASE_FRAME ...@@ -414,7 +414,9 @@ class EDA_DRAW_FRAME : public EDA_BASE_FRAME
protected: protected:
EDA_HOTKEY_CONFIG* m_HotkeysZoomAndGridList; 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 bool m_DrawGrid; // hide/Show grid
EDA_COLOR_T m_GridColor; // Grid color EDA_COLOR_T m_GridColor; // Grid color
......
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