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

This commit is contained in:
jean-pierre charras 2015-01-05 14:20:04 +01:00
parent 036a7cd8ed
commit ad74a9a191
7 changed files with 145 additions and 108 deletions

View File

@ -165,6 +165,51 @@ bool BASE_SCREEN::SetPreviousZoom()
return false; 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 ) void BASE_SCREEN::SetGridList( GRIDS& gridlist )
{ {

View File

@ -266,43 +266,16 @@ void EDA_DRAW_FRAME::AddMenuZoomAndGrid( wxMenu* MasterMenu )
AddMenuItem( MasterMenu, gridMenu, ID_POPUP_GRID_SELECT, AddMenuItem( MasterMenu, gridMenu, ID_POPUP_GRID_SELECT,
_( "Grid Select" ), KiBitmap( grid_select_xpm ) ); _( "Grid Select" ), KiBitmap( grid_select_xpm ) );
GRID_TYPE tmp; wxArrayString gridsList;
wxRealPoint grid = screen->GetGridSize(); 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 ); GRID_TYPE& grid = screen->GetGrid( i );
double gridValueInch = To_User_Unit( INCHES, tmp.m_Size.x ); gridMenu->Append( grid.m_Id, gridsList[i], wxEmptyString, true );
double gridValue_mm = To_User_Unit( MILLIMETRES, tmp.m_Size.x );
if( tmp.m_Id == ID_POPUP_GRID_USER ) if( (int)i == icurr )
{ gridMenu->Check( grid.m_Id, true );
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 );
} }
} }

View File

@ -452,6 +452,18 @@ public:
return m_grids; 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 * Function GetClass
* returns the class name. * returns the class name.

View File

@ -810,42 +810,16 @@ void PCB_BASE_FRAME::updateGridSelectBox()
// Update grid values with the current units setting. // Update grid values with the current units setting.
m_gridSelectBox->Clear(); m_gridSelectBox->Clear();
wxArrayString gridsList;
wxString msg; int icurr = GetScreen()->BuildGridsChoiceList( gridsList, g_UserUnit != INCHES );
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;
}
for( size_t i = 0; i < GetScreen()->GetGridCount(); i++ ) for( size_t i = 0; i < GetScreen()->GetGridCount(); i++ )
{ {
GRID_TYPE& grid = GetScreen()->GetGrid( i ); GRID_TYPE& grid = GetScreen()->GetGrid( i );
double value = To_User_Unit( g_UserUnit, grid.m_Size.x ); m_gridSelectBox->Append( gridsList[i], (void*) &grid.m_Id );
if( g_UserUnit == INCHES )
value *= 1000;
if( grid.m_Id != ID_POPUP_GRID_USER )
{
msg.Printf( format.GetData(), value );
StripTrailingZeros( msg );
}
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() void PCB_BASE_FRAME::updateZoomSelectBox()
@ -856,19 +830,17 @@ void PCB_BASE_FRAME::updateZoomSelectBox()
wxString msg; wxString msg;
m_zoomSelectBox->Clear(); m_zoomSelectBox->Clear();
m_zoomSelectBox->Append( _( "Auto" ) ); m_zoomSelectBox->Append( _( "Zoom Auto" ) );
m_zoomSelectBox->SetSelection( 0 ); m_zoomSelectBox->SetSelection( 0 );
for( unsigned i = 0; i < GetScreen()->m_ZoomList.size(); ++i ) for( unsigned i = 0; i < GetScreen()->m_ZoomList.size(); ++i )
{ {
msg = _( "Zoom " ); msg = _( "Zoom " );
wxString value = wxString::Format( wxT( "%g" ), // @todo could do scaling here and show the "percentage" depending on
// the screen pixel size
// @todo could do scaling here and show a "percentage" double level = 254000.0 / (double)GetScreen()->m_ZoomList[i];
GetScreen()->m_ZoomList[i] wxString value = wxString::Format( wxT( "%d%%" ), int(level * 100) );
);
msg += value; msg += value;
m_zoomSelectBox->Append( msg ); m_zoomSelectBox->Append( msg );

View File

@ -731,8 +731,7 @@ void PCB_EDIT_FRAME::ShowDesignRulesEditor( wxCommandEvent& event )
if( returncode == wxID_OK ) // New rules, or others changes. if( returncode == wxID_OK ) // New rules, or others changes.
{ {
ReCreateLayerBox(); ReCreateLayerBox();
updateTraceWidthSelectBox(); ReCreateAuxiliaryToolbar();
updateViaSizeSelectBox();
OnModify(); OnModify();
} }
} }
@ -876,8 +875,7 @@ void PCB_EDIT_FRAME::unitsChangeRefresh()
{ {
PCB_BASE_FRAME::unitsChangeRefresh(); // Update the grid size select box. PCB_BASE_FRAME::unitsChangeRefresh(); // Update the grid size select box.
updateTraceWidthSelectBox(); ReCreateAuxiliaryToolbar();
updateViaSizeSelectBox();
} }
@ -1064,8 +1062,7 @@ bool PCB_EDIT_FRAME::SetCurrentNetClass( const wxString& aNetClassName )
if( change ) if( change )
{ {
updateTraceWidthSelectBox(); ReCreateAuxiliaryToolbar();
updateViaSizeSelectBox();
} }
return change; return change;

View File

@ -51,8 +51,7 @@ void PCB_EDIT_FRAME::ToolOnRightClick( wxCommandEvent& event )
if( dlg.ShowModal() == wxID_OK ) if( dlg.ShowModal() == wxID_OK )
{ {
updateTraceWidthSelectBox(); ReCreateAuxiliaryToolbar();
updateViaSizeSelectBox();
} }
break; break;

View File

@ -46,13 +46,6 @@
#include <wx/wupdlock.h> #include <wx/wupdlock.h>
#ifdef __UNIX__
#define LISTBOX_WIDTH 150
#else
#define LISTBOX_WIDTH 130
#endif
#define SEL_LAYER_HELP _( \ #define SEL_LAYER_HELP _( \
"Show active layer selections\nand select layer pair for route and place via" ) "Show active layer selections\nand select layer pair for route and place via" )
@ -551,7 +544,20 @@ void PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar()
wxWindowUpdateLocker dummy( this ); wxWindowUpdateLocker dummy( this );
if( m_auxiliaryToolBar ) if( m_auxiliaryToolBar )
{
updateTraceWidthSelectBox();
updateViaSizeSelectBox();
// combobox sizes can have changed: apply new best sizes
wxAuiToolBarItem* item = m_auxiliaryToolBar->FindTool( ID_AUX_TOOLBAR_PCB_TRACK_WIDTH );
item->SetMinSize( m_SelTrackWidthBox->GetBestSize() );
item = m_auxiliaryToolBar->FindTool( ID_AUX_TOOLBAR_PCB_VIA_SIZE );
item->SetMinSize( m_SelViaSizeBox->GetBestSize() );
m_auxiliaryToolBar->Realize();
m_auimgr.Update();
return; return;
}
m_auxiliaryToolBar = new wxAuiToolBar( this, ID_AUX_TOOLBAR, wxDefaultPosition, wxDefaultSize, m_auxiliaryToolBar = new wxAuiToolBar( this, ID_AUX_TOOLBAR, wxDefaultPosition, wxDefaultSize,
wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_HORZ_LAYOUT ); wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_HORZ_LAYOUT );
@ -562,19 +568,19 @@ void PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar()
m_SelTrackWidthBox = new wxComboBox( m_auxiliaryToolBar, m_SelTrackWidthBox = new wxComboBox( m_auxiliaryToolBar,
ID_AUX_TOOLBAR_PCB_TRACK_WIDTH, ID_AUX_TOOLBAR_PCB_TRACK_WIDTH,
wxEmptyString, wxEmptyString,
wxPoint( -1, -1 ), wxDefaultPosition, wxDefaultSize,
wxSize( LISTBOX_WIDTH, -1 ),
0, NULL, wxCB_READONLY ); 0, NULL, wxCB_READONLY );
updateTraceWidthSelectBox();
m_auxiliaryToolBar->AddControl( m_SelTrackWidthBox ); m_auxiliaryToolBar->AddControl( m_SelTrackWidthBox );
m_auxiliaryToolBar->AddSeparator(); // m_auxiliaryToolBar->AddSeparator();
// Creates box to display and choose vias diameters: // Creates box to display and choose vias diameters:
m_SelViaSizeBox = new wxComboBox( m_auxiliaryToolBar, m_SelViaSizeBox = new wxComboBox( m_auxiliaryToolBar,
ID_AUX_TOOLBAR_PCB_VIA_SIZE, ID_AUX_TOOLBAR_PCB_VIA_SIZE,
wxEmptyString, wxEmptyString,
wxPoint( -1, -1 ), wxDefaultPosition, wxDefaultSize,
wxSize( (LISTBOX_WIDTH*12)/10, -1 ),
0, NULL, wxCB_READONLY ); 0, NULL, wxCB_READONLY );
updateViaSizeSelectBox();
m_auxiliaryToolBar->AddControl( m_SelViaSizeBox ); m_auxiliaryToolBar->AddControl( m_SelViaSizeBox );
m_auxiliaryToolBar->AddSeparator(); m_auxiliaryToolBar->AddSeparator();
@ -591,9 +597,9 @@ an existing track use its width\notherwise, use current width setting" ),
m_gridSelectBox = new wxComboBox( m_auxiliaryToolBar, m_gridSelectBox = new wxComboBox( m_auxiliaryToolBar,
ID_ON_GRID_SELECT, ID_ON_GRID_SELECT,
wxEmptyString, wxEmptyString,
wxPoint( -1, -1 ), wxDefaultPosition, wxDefaultSize,
wxSize( LISTBOX_WIDTH, -1 ),
0, NULL, wxCB_READONLY ); 0, NULL, wxCB_READONLY );
updateGridSelectBox();
m_auxiliaryToolBar->AddControl( m_gridSelectBox ); m_auxiliaryToolBar->AddControl( m_gridSelectBox );
// Add the box to display and select the current Zoom // Add the box to display and select the current Zoom
@ -601,19 +607,14 @@ an existing track use its width\notherwise, use current width setting" ),
m_zoomSelectBox = new wxComboBox( m_auxiliaryToolBar, m_zoomSelectBox = new wxComboBox( m_auxiliaryToolBar,
ID_ON_ZOOM_SELECT, ID_ON_ZOOM_SELECT,
wxEmptyString, wxEmptyString,
wxPoint( -1, -1 ), wxDefaultPosition, wxDefaultSize,
wxSize( LISTBOX_WIDTH, -1 ),
0, NULL, wxCB_READONLY ); 0, NULL, wxCB_READONLY );
m_auxiliaryToolBar->AddControl( m_zoomSelectBox );
updateZoomSelectBox(); updateZoomSelectBox();
updateGridSelectBox(); m_auxiliaryToolBar->AddControl( m_zoomSelectBox );
updateTraceWidthSelectBox();
updateViaSizeSelectBox();
// after adding the buttons to the toolbar, must call Realize() // after adding the buttons to the toolbar, must call Realize()
m_auxiliaryToolBar->Realize(); m_auxiliaryToolBar->Realize();
m_auxiliaryToolBar->AddSeparator(); // m_auxiliaryToolBar->AddSeparator();
} }
@ -623,13 +624,25 @@ void PCB_EDIT_FRAME::updateTraceWidthSelectBox()
return; return;
wxString msg; wxString msg;
bool mmFirst = g_UserUnit != INCHES;
m_SelTrackWidthBox->Clear(); m_SelTrackWidthBox->Clear();
for( unsigned ii = 0; ii < GetDesignSettings().m_TrackWidthList.size(); ii++ ) for( unsigned ii = 0; ii < GetDesignSettings().m_TrackWidthList.size(); ii++ )
{ {
msg = _( "Track " ) + CoordinateToString( GetDesignSettings().m_TrackWidthList[ii], true ); int size = GetDesignSettings().m_TrackWidthList[ii];
double valueMils = To_User_Unit( INCHES, size ) * 1000;
double value_mm = To_User_Unit( MILLIMETRES, size );
if( mmFirst )
msg.Printf( _( "Track: %.3f mm (%.2f mils)" ),
value_mm, valueMils );
else
msg.Printf( _( "Track: %.2f mils (%.3f mm)" ),
valueMils, value_mm );
// Mark the netclass track width value (the first in list)
if( ii == 0 ) if( ii == 0 )
msg << wxT( " *" ); msg << wxT( " *" );
@ -651,16 +664,42 @@ void PCB_EDIT_FRAME::updateViaSizeSelectBox()
wxString msg; wxString msg;
m_SelViaSizeBox->Clear(); m_SelViaSizeBox->Clear();
bool mmFirst = g_UserUnit != INCHES;
for( unsigned ii = 0; ii < GetDesignSettings().m_ViasDimensionsList.size(); ii++ ) for( unsigned ii = 0; ii < GetDesignSettings().m_ViasDimensionsList.size(); ii++ )
{ {
msg = _( "Via " ); int diam = GetDesignSettings().m_ViasDimensionsList[ii].m_Diameter;
msg << CoordinateToString( GetDesignSettings().m_ViasDimensionsList[ii].m_Diameter, true );
if( GetDesignSettings().m_ViasDimensionsList[ii].m_Drill ) double valueMils = To_User_Unit( INCHES, diam ) * 1000;
msg << wxT("/ ") double value_mm = To_User_Unit( MILLIMETRES, diam );
<< CoordinateToString( GetDesignSettings().m_ViasDimensionsList[ii].m_Drill, true );
if( mmFirst )
msg.Printf( _( "Via: %.2f mm (%.1f mils)" ),
value_mm, valueMils );
else
msg.Printf( _( "Via: %.1f mils (%.2f mm)" ),
valueMils, value_mm );
int hole = GetDesignSettings().m_ViasDimensionsList[ii].m_Drill;
if( hole )
{
msg << wxT("/ ");
wxString hole_str;
double valueMils = To_User_Unit( INCHES, hole ) * 1000;
double value_mm = To_User_Unit( MILLIMETRES, hole );
if( mmFirst )
hole_str.Printf( _( "%.2f mm (%.1f mils)" ),
value_mm, valueMils );
else
hole_str.Printf( _( "%.1f mils (%.2f mm)" ),
valueMils, value_mm );
msg += hole_str;
}
// Mark the netclass via size value (the first in list)
if( ii == 0 ) if( ii == 0 )
msg << wxT( " *" ); msg << wxT( " *" );