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

Pcbnew: better display of tracks/vias/grid sizes in toolbar

parent 036a7cd8
Loading
Loading
Loading
Loading
+45 −0
Original line number Diff line number Diff line
@@ -165,6 +165,51 @@ bool BASE_SCREEN::SetPreviousZoom()
    return false;
}

/* Build the list of human readable grid list.
 * The list shows the grid size both in mils or mm.
 * aMmFirst = true to have mm first and mils after
 *            false to have mils first and mm after
 */
int BASE_SCREEN::BuildGridsChoiceList( wxArrayString& aGridsList, bool aMmFirst) const
{
    wxString msg;
    wxRealPoint curr_grid_size = GetGridSize();
    int idx = -1;
    int idx_usergrid = -1;

    for( size_t i = 0; i < GetGridCount(); i++ )
    {
        const GRID_TYPE& grid = m_grids[i];
        double gridValueMils = To_User_Unit( INCHES, grid.m_Size.x ) * 1000;
        double gridValue_mm = To_User_Unit( MILLIMETRES, grid.m_Size.x );

        if( grid.m_Id == ID_POPUP_GRID_USER )
        {
            msg = _( "User Grid" );
            idx_usergrid = i;
        }
        else
        {
            if( aMmFirst )
                msg.Printf( _( "Grid: %.4f mm (%.2f mils)" ),
                            gridValue_mm, gridValueMils );
            else
                msg.Printf( _( "Grid: %.2f mils (%.4f mm)" ),
                            gridValueMils, gridValue_mm );
        }

        aGridsList.Add( msg );

        if( curr_grid_size == grid.m_Size )
            idx = i;
    }

    if( idx < 0 )
        idx = idx_usergrid;

    return idx;
}


void BASE_SCREEN::SetGridList( GRIDS& gridlist )
{
+8 −35
Original line number Diff line number Diff line
@@ -266,43 +266,16 @@ void EDA_DRAW_FRAME::AddMenuZoomAndGrid( wxMenu* MasterMenu )
        AddMenuItem( MasterMenu, gridMenu, ID_POPUP_GRID_SELECT,
                     _( "Grid Select" ), KiBitmap( grid_select_xpm ) );

        GRID_TYPE   tmp;
        wxRealPoint grid = screen->GetGridSize();
        wxArrayString gridsList;
        int icurr = screen->BuildGridsChoiceList( gridsList, g_UserUnit != INCHES );

        for( size_t i = 0; i < screen->GetGridCount(); i++ )
        for( unsigned i = 0; i < gridsList.GetCount(); i++ )
        {
            tmp = screen->GetGrid( i );
            double gridValueInch = To_User_Unit( INCHES, tmp.m_Size.x );
            double gridValue_mm = To_User_Unit( MILLIMETRES, tmp.m_Size.x );
            GRID_TYPE& grid = screen->GetGrid( i );
            gridMenu->Append( grid.m_Id, gridsList[i], wxEmptyString, true );

            if( tmp.m_Id == ID_POPUP_GRID_USER )
            {
                msg = _( "User Grid" );
            }
            else
            {
                switch( g_UserUnit )
                {
                case INCHES:
                    msg.Printf( wxT( "%.1f mils, (%.4f mm)" ),
                                gridValueInch * 1000, gridValue_mm );
                    break;

                case MILLIMETRES:
                    msg.Printf( wxT( "%.4f mm, (%.1f mils)" ),
                                gridValue_mm, gridValueInch * 1000 );
                    break;

                case UNSCALED_UNITS:
                    msg = wxT( "???" );
                    break;
                }
            }

            gridMenu->Append( tmp.m_Id, msg, wxEmptyString, true );

            if( grid == tmp.m_Size )
                gridMenu->Check( tmp.m_Id, true );
            if( (int)i == icurr )
                gridMenu->Check( grid.m_Id, true );
        }
    }

+12 −0
Original line number Diff line number Diff line
@@ -452,6 +452,18 @@ public:
        return m_grids;
    }

    /**
     * Function BuildGridsChoiceList().
     * Build the human readable list of grid list, for menus or combo boxes
     * the list shows the grid size both in mils or mm.
     * @param aGridsList = a wxArrayString to populate
     * @param aMmFirst = true to have mm first and mils after
     *                   false to have mils first and mm after
     * @return the index of the curr grid in list, if found or -1
     */
    int BuildGridsChoiceList( wxArrayString& aGridsList, bool aMmFirst) const;


    /**
     * Function GetClass
     * returns the class name.
+10 −38
Original line number Diff line number Diff line
@@ -810,42 +810,16 @@ void PCB_BASE_FRAME::updateGridSelectBox()

    // Update grid values with the current units setting.
    m_gridSelectBox->Clear();

    wxString msg;
    wxString format = _( "Grid:");

    switch( g_UserUnit )
    {
    case INCHES:    // the grid size is displayed in mils
    case MILLIMETRES:
        format += wxT( " %.6f" );
        break;

    case UNSCALED_UNITS:
        format += wxT( " %f" );
        break;
    }
    wxArrayString gridsList;
    int icurr = GetScreen()->BuildGridsChoiceList( gridsList, g_UserUnit != INCHES );

    for( size_t i = 0; i < GetScreen()->GetGridCount(); i++ )
    {
        GRID_TYPE& grid = GetScreen()->GetGrid( i );
        double value = To_User_Unit( g_UserUnit, grid.m_Size.x );
        if( g_UserUnit == INCHES )
            value *= 1000;

        if( grid.m_Id != ID_POPUP_GRID_USER )
        {
            msg.Printf( format.GetData(), value );
            StripTrailingZeros( msg );
        m_gridSelectBox->Append( gridsList[i], (void*) &grid.m_Id );
    }
        else
            msg = _( "User Grid" );

        m_gridSelectBox->Append( msg, (void*) &grid.m_Id );

        if( ( m_LastGridSizeId + ID_POPUP_GRID_LEVEL_1000 ) == GetScreen()->GetGrid( i ).m_Id )
            m_gridSelectBox->SetSelection( i );
    }
    m_gridSelectBox->SetSelection( icurr );
}

void PCB_BASE_FRAME::updateZoomSelectBox()
@@ -856,19 +830,17 @@ void PCB_BASE_FRAME::updateZoomSelectBox()
    wxString msg;

    m_zoomSelectBox->Clear();
    m_zoomSelectBox->Append( _( "Auto" ) );
    m_zoomSelectBox->Append( _( "Zoom Auto" ) );
    m_zoomSelectBox->SetSelection( 0 );

    for( unsigned i = 0;  i < GetScreen()->m_ZoomList.size();  ++i )
    {
        msg = _( "Zoom " );

        wxString value = wxString::Format( wxT( "%g" ),

                                // @todo could do scaling here and show a "percentage"
                                GetScreen()->m_ZoomList[i]
                                );

        // @todo could do scaling here and show the "percentage" depending on
        // the screen pixel size
        double level =  254000.0 / (double)GetScreen()->m_ZoomList[i];
        wxString value = wxString::Format( wxT( "%d%%" ), int(level * 100) );
        msg += value;

        m_zoomSelectBox->Append( msg );
+3 −6
Original line number Diff line number Diff line
@@ -731,8 +731,7 @@ void PCB_EDIT_FRAME::ShowDesignRulesEditor( wxCommandEvent& event )
    if( returncode == wxID_OK )     // New rules, or others changes.
    {
        ReCreateLayerBox();
        updateTraceWidthSelectBox();
        updateViaSizeSelectBox();
        ReCreateAuxiliaryToolbar();
        OnModify();
    }
}
@@ -876,8 +875,7 @@ void PCB_EDIT_FRAME::unitsChangeRefresh()
{
    PCB_BASE_FRAME::unitsChangeRefresh();    // Update the grid size select box.

    updateTraceWidthSelectBox();
    updateViaSizeSelectBox();
    ReCreateAuxiliaryToolbar();
}


@@ -1064,8 +1062,7 @@ bool PCB_EDIT_FRAME::SetCurrentNetClass( const wxString& aNetClassName )

    if( change )
    {
        updateTraceWidthSelectBox();
        updateViaSizeSelectBox();
        ReCreateAuxiliaryToolbar();
    }

    return change;
Loading