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

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

parent 036a7cd8
......@@ -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 )
{
......
......@@ -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 );
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 );
GRID_TYPE& grid = screen->GetGrid( i );
gridMenu->Append( grid.m_Id, gridsList[i], wxEmptyString, true );
if( (int)i == icurr )
gridMenu->Check( grid.m_Id, true );
}
}
......
......@@ -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.
......
......@@ -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 );
}
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->Append( gridsList[i], (void*) &grid.m_Id );
}
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 );
......
......@@ -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;
......
......@@ -51,8 +51,7 @@ void PCB_EDIT_FRAME::ToolOnRightClick( wxCommandEvent& event )
if( dlg.ShowModal() == wxID_OK )
{
updateTraceWidthSelectBox();
updateViaSizeSelectBox();
ReCreateAuxiliaryToolbar();
}
break;
......
......@@ -46,13 +46,6 @@
#include <wx/wupdlock.h>
#ifdef __UNIX__
#define LISTBOX_WIDTH 150
#else
#define LISTBOX_WIDTH 130
#endif
#define SEL_LAYER_HELP _( \
"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 );
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;
}
m_auxiliaryToolBar = new wxAuiToolBar( this, ID_AUX_TOOLBAR, wxDefaultPosition, wxDefaultSize,
wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_HORZ_LAYOUT );
......@@ -562,19 +568,19 @@ void PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar()
m_SelTrackWidthBox = new wxComboBox( m_auxiliaryToolBar,
ID_AUX_TOOLBAR_PCB_TRACK_WIDTH,
wxEmptyString,
wxPoint( -1, -1 ),
wxSize( LISTBOX_WIDTH, -1 ),
wxDefaultPosition, wxDefaultSize,
0, NULL, wxCB_READONLY );
updateTraceWidthSelectBox();
m_auxiliaryToolBar->AddControl( m_SelTrackWidthBox );
m_auxiliaryToolBar->AddSeparator();
// m_auxiliaryToolBar->AddSeparator();
// Creates box to display and choose vias diameters:
m_SelViaSizeBox = new wxComboBox( m_auxiliaryToolBar,
ID_AUX_TOOLBAR_PCB_VIA_SIZE,
wxEmptyString,
wxPoint( -1, -1 ),
wxSize( (LISTBOX_WIDTH*12)/10, -1 ),
wxDefaultPosition, wxDefaultSize,
0, NULL, wxCB_READONLY );
updateViaSizeSelectBox();
m_auxiliaryToolBar->AddControl( m_SelViaSizeBox );
m_auxiliaryToolBar->AddSeparator();
......@@ -591,9 +597,9 @@ an existing track use its width\notherwise, use current width setting" ),
m_gridSelectBox = new wxComboBox( m_auxiliaryToolBar,
ID_ON_GRID_SELECT,
wxEmptyString,
wxPoint( -1, -1 ),
wxSize( LISTBOX_WIDTH, -1 ),
wxDefaultPosition, wxDefaultSize,
0, NULL, wxCB_READONLY );
updateGridSelectBox();
m_auxiliaryToolBar->AddControl( m_gridSelectBox );
// 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,
ID_ON_ZOOM_SELECT,
wxEmptyString,
wxPoint( -1, -1 ),
wxSize( LISTBOX_WIDTH, -1 ),
wxDefaultPosition, wxDefaultSize,
0, NULL, wxCB_READONLY );
m_auxiliaryToolBar->AddControl( m_zoomSelectBox );
updateZoomSelectBox();
updateGridSelectBox();
updateTraceWidthSelectBox();
updateViaSizeSelectBox();
m_auxiliaryToolBar->AddControl( m_zoomSelectBox );
// after adding the buttons to the toolbar, must call Realize()
m_auxiliaryToolBar->Realize();
m_auxiliaryToolBar->AddSeparator();
// m_auxiliaryToolBar->AddSeparator();
}
......@@ -623,13 +624,25 @@ void PCB_EDIT_FRAME::updateTraceWidthSelectBox()
return;
wxString msg;
bool mmFirst = g_UserUnit != INCHES;
m_SelTrackWidthBox->Clear();
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 )
msg << wxT( " *" );
......@@ -651,16 +664,42 @@ void PCB_EDIT_FRAME::updateViaSizeSelectBox()
wxString msg;
m_SelViaSizeBox->Clear();
bool mmFirst = g_UserUnit != INCHES;
for( unsigned ii = 0; ii < GetDesignSettings().m_ViasDimensionsList.size(); ii++ )
{
msg = _( "Via " );
msg << CoordinateToString( GetDesignSettings().m_ViasDimensionsList[ii].m_Diameter, true );
int diam = GetDesignSettings().m_ViasDimensionsList[ii].m_Diameter;
double valueMils = To_User_Unit( INCHES, diam ) * 1000;
double value_mm = To_User_Unit( MILLIMETRES, diam );
if( mmFirst )
msg.Printf( _( "Via: %.2f mm (%.1f mils)" ),
value_mm, valueMils );
else
msg.Printf( _( "Via: %.1f mils (%.2f mm)" ),
valueMils, value_mm );
if( GetDesignSettings().m_ViasDimensionsList[ii].m_Drill )
msg << wxT("/ ")
<< CoordinateToString( GetDesignSettings().m_ViasDimensionsList[ii].m_Drill, true );
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 )
msg << wxT( " *" );
......
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