Commit aee56a93 authored by charras's avatar charras
Browse files

Change grid size type from integer to double (using wxRealPoint insteed of wxSize).

Mandatory in Pcbnew to handle without error metric grid used now for some footprints (BGA, connectors)
Not fully tested
parent 35e8a286
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -5,6 +5,17 @@ Started 2007-June-11
Please add newer entries at the top, list the date and your name with
email address.

2009-Feb-7 Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
++All:
    change grid size type from integer to double (using wxRealPoint insteed of wxSize)
    This is mandatory in Pcbnew to handle metric user grids without error
    (was unusable before, using integer grid size).
    A lot of footprints uses not metric grid.
    TODO:
        more refinements for user grid (mainly in read/wrire config).


2009-Feb-06 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
++pcbnew
@@ -20,10 +31,6 @@ email address.
    (near to to Wayne Stambaugh's changes: 15 values are not enought for pcbnew)
    removed minor problems in zoom box selection (removed blank line).
    Added user grid selection in modedit and refinements when user grid is selected.
    TODO:
        more refinements in user grid mode.
        new grid implementation does not used floats when user grid is selected to calculate coordinates.
        so it is unable to handle a metric grid. Todo: see what happened.


++eeschema:
+18 −12
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ BASE_SCREEN::BASE_SCREEN( KICAD_T aType ) : EDA_BaseStruct( aType )
    m_NumberOfScreen   = 1;  /* Hierarchy: Root: ScreenNumber = 1 */
    m_ZoomScalar       = 10;
    m_Zoom             = 32 * m_ZoomScalar;
    m_Grid             = wxSize( 50, 50 );   /* Default grid size */
    m_Grid             = wxRealPoint( 50, 50 );   /* Default grid size */
    m_UserGridIsON     = FALSE;
    m_Center           = true;
    m_CurrentSheetDesc = &g_Sheet_A4;
@@ -170,6 +170,12 @@ void BASE_SCREEN::Scale( wxPoint& pt )
    pt.y = Scale( pt.y );
}

void BASE_SCREEN::Scale( wxRealPoint& pt )
{
    pt.x = Scale( pt.x );
    pt.y = Scale( pt.y );
}


void BASE_SCREEN::Scale( wxSize& sz )
{
@@ -303,14 +309,14 @@ void BASE_SCREEN::SetGridList( GridArray& gridlist )


/**********************************************/
void BASE_SCREEN::SetGrid( const wxSize& size )
void BASE_SCREEN::SetGrid( const wxRealPoint& size )
/**********************************************/
{
    wxASSERT( !m_GridList.IsEmpty() );

    size_t i;

    wxSize nearest_grid = m_GridList[0].m_Size;
    wxRealPoint nearest_grid = m_GridList[0].m_Size;
    for( i = 0; i < m_GridList.GetCount(); i++ )
    {
        if( m_GridList[i].m_Size == size )
@@ -326,8 +332,8 @@ void BASE_SCREEN::SetGrid( const wxSize& size )

    m_Grid = nearest_grid;

    wxLogWarning( _( "Grid size( %d, %d ) not in grid list, falling back to " \
                     "grid size( %d, %d )." ),
    wxLogWarning( _( "Grid size( %f, %f ) not in grid list, falling back to " \
                     "grid size( %f, %f )." ),
                  size.x, size.y, m_Grid.x, m_Grid.y );
}

@@ -350,7 +356,7 @@ void BASE_SCREEN::SetGrid( int id )
    m_Grid = m_GridList[0].m_Size;

    wxLogWarning( _( "Grid ID %d not in grid list, falling back to " \
                     "grid size( %d, %d )." ), id, m_Grid.x, m_Grid.y );
                     "grid size( %f, %f )." ), id, m_Grid.x, m_Grid.y );
}

void BASE_SCREEN::AddGrid( const GRID_TYPE& grid )
@@ -381,7 +387,7 @@ void BASE_SCREEN::AddGrid( const GRID_TYPE& grid )
    m_GridList.Add( grid );
}

void BASE_SCREEN::AddGrid( const wxSize& size, int id )
void BASE_SCREEN::AddGrid( const wxRealPoint& size, int id )
{
    GRID_TYPE grid;

@@ -393,7 +399,7 @@ void BASE_SCREEN::AddGrid( const wxSize& size, int id )
void BASE_SCREEN::AddGrid( const wxRealPoint& size, int units, int id )
{
    double x, y;
    wxSize new_size;
    wxRealPoint new_size;
    GRID_TYPE new_grid;

    if( units == MILLIMETRE )
@@ -412,8 +418,8 @@ void BASE_SCREEN::AddGrid( const wxRealPoint& size, int units, int id )
        y = size.y;
    }

    new_size = wxSize( (int) round( x * (double) GetInternalUnits() ),
                       (int) round( y * (double) GetInternalUnits() ) );
    new_size = wxRealPoint( x * (double) GetInternalUnits(),
                       y * (double) GetInternalUnits()  );

    new_grid.m_Id = id;
    new_grid.m_Size = new_size;
@@ -421,7 +427,7 @@ void BASE_SCREEN::AddGrid( const wxRealPoint& size, int units, int id )
}

/*********************************/
wxSize BASE_SCREEN::GetGrid()
wxRealPoint BASE_SCREEN::GetGrid()
/*********************************/
{
    return m_Grid;
+2 −2
Original line number Diff line number Diff line
@@ -262,9 +262,9 @@ void WinEDA_DrawFrame::OnSelectGrid( wxCommandEvent& event )
    BASE_SCREEN* screen = GetBaseScreen();

    screen->m_Curseur = DrawPanel->GetScreenCenterRealPosition();
    wxSize current_grid = screen->GetGrid();
    wxRealPoint current_grid = screen->GetGrid();
    screen->SetGrid( event.GetSelection() + ID_POPUP_GRID_LEVEL_1000 );
    wxSize selected_grid = screen->GetGrid();
    wxRealPoint selected_grid = screen->GetGrid();

    if( selected_grid != current_grid )
        Recadre_Trace( FALSE );
+10 −17
Original line number Diff line number Diff line
@@ -175,7 +175,7 @@ void WinEDA_DrawPanel::SetZoom( int zoom )


/************************************/
wxSize WinEDA_DrawPanel::GetGrid()
wxRealPoint WinEDA_DrawPanel::GetGrid()
/************************************/
{
    return GetScreen()->GetGrid();
@@ -685,11 +685,10 @@ void WinEDA_DrawPanel::DrawBackGround( wxDC* DC )
    int          Color  = BLUE;
    BASE_SCREEN* screen = GetScreen();
    int          ii, jj, xg, yg, color;
    wxSize       pas_grille_affichee;
    wxRealPoint  pas_grille_affichee;
    bool         drawgrid = FALSE;
    wxSize       size;
    wxPoint      org;
    double       pasx, pasy;

    color = g_GridColor;

@@ -702,32 +701,29 @@ void WinEDA_DrawPanel::DrawBackGround( wxDC* DC )

    pas_grille_affichee = screen->GetGrid();

    ii = screen->Scale( pas_grille_affichee.x );
    if( ii  < 5 )
    double dgrid = screen->Scale( pas_grille_affichee.x );
    if( dgrid  < 5 )
    {
        pas_grille_affichee.x *= 2;
        ii *= 2;
        dgrid *= 2;
    }
    if( ii < 5 )
    if( dgrid < 5 )
        drawgrid = FALSE; // The gris is small

    ii = screen->Scale( pas_grille_affichee.y );
    if( ii  < 5 )
    dgrid = screen->Scale( pas_grille_affichee.y );
    if( ii  < dgrid )
    {
        pas_grille_affichee.y *= 2;
        ii *= 2;
        dgrid *= 2;
    }
    if( ii < 5 )
    if( dgrid < 5 )
        drawgrid = FALSE; // The gris is small

    GetViewStart( &org.x, &org.y );
    GetScrollPixelsPerUnit( &ii, &jj );
    wxLogDebug( _T( "View start: %d, %d,  scroll bar PPI: %d, %d" ),
                org.x, org.y, ii, jj );
    org.x *= ii;
    org.y *= jj;
    screen->m_StartVisu = org;
    wxLogDebug( _T( "Scroll bar drawing position: %d. %d" ), org.x, org.y );
    screen->Unscale( org );

    org += screen->m_DrawOrg;
@@ -735,9 +731,6 @@ void WinEDA_DrawPanel::DrawBackGround( wxDC* DC )
    size = GetClientSize();
    screen->Unscale( size );

    pasx = screen->m_Grid.x * m_Parent->m_InternalUnits;
    pasy = screen->m_Grid.y * m_Parent->m_InternalUnits;

    if( drawgrid )
    {
        m_Parent->PutOnGrid( &org );
+6 −6
Original line number Diff line number Diff line
@@ -47,14 +47,14 @@ void WinEDA_DrawFrame::PutOnGrid( wxPoint* coord )
* @param coord = coordinate to adjust
*/
{
    wxSize grid_size = GetBaseScreen()->GetGrid();
    wxRealPoint grid_size = GetBaseScreen()->GetGrid();

    if( !GetBaseScreen()->m_UserGridIsON )
    {
        coord->x = ( (int) round( (double) coord->x /
                                  (double) grid_size.x ) ) * grid_size.x;
        coord->y = ( (int) round( (double) coord->y /
                                  (double) grid_size.y ) ) * grid_size.y;
        coord->x = ( (int) round( coord->x /
                                  grid_size.x ) ) * grid_size.x;
        coord->y = ( (int) round( coord->y /
                                  grid_size.y ) ) * grid_size.y;
    }
}

@@ -193,7 +193,7 @@ void WinEDA_DrawPanel::AddMenuZoom( wxMenu* MasterMenu )
    size_t      i;
    int         maxZoomIds;
    int         zoom;
    wxSize      grid;
    wxRealPoint      grid;
    wxString    msg;
    GRID_TYPE   tmp;
    wxMenu*     gridMenu;
Loading