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

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

parent 5a6665ec
Loading
Loading
Loading
Loading
+15 −7
Original line number Diff line number Diff line
@@ -182,51 +182,59 @@ 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;

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


+16 −10
Original line number Diff line number Diff line
@@ -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 );
}


+2 −1
Original line number Diff line number Diff line
@@ -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);
+1 −1
Original line number Diff line number Diff line
@@ -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;
+4 −0
Original line number Diff line number Diff line
@@ -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();
Loading