Remember shown columns in netclass setup.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17852
This commit is contained in:
Jeff Young 2024-04-24 23:51:09 +01:00
parent 0984af1676
commit cd64630661
4 changed files with 123 additions and 117 deletions

View File

@ -119,6 +119,8 @@ PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( wxWindow* aParentWindow, EDA_DRA
m_splitter->SetMinimumPaneSize( FromDIP( m_splitter->GetMinimumPaneSize() ) ); m_splitter->SetMinimumPaneSize( FromDIP( m_splitter->GetMinimumPaneSize() ) );
wxASSERT( m_netclassGrid->GetNumberCols() == GRID_END );
// Calculate a min best size to handle longest usual numeric values: // Calculate a min best size to handle longest usual numeric values:
int const min_best_width = m_netclassGrid->GetTextExtent( "555,555555 mils" ).x; int const min_best_width = m_netclassGrid->GetTextExtent( "555,555555 mils" ).x;
@ -131,36 +133,24 @@ PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( wxWindow* aParentWindow, EDA_DRA
int const weighted_min_best_width = ( i == GRID_LINESTYLE ) ? min_best_width * 3 / 2 int const weighted_min_best_width = ( i == GRID_LINESTYLE ) ? min_best_width * 3 / 2
: min_best_width; : min_best_width;
m_netclassGrid->SetColMinimalWidth( i, min_width );
// We use a "best size" >= min_best_width // We use a "best size" >= min_best_width
m_originalColWidths[ i ] = std::max( min_width, weighted_min_best_width ); m_originalColWidths[ i ] = std::max( min_width, weighted_min_best_width );
m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] ); m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
}
for( int i = GRID_FIRST_PCBNEW; i < GRID_END; ++i )
{
if( i >= GRID_FIRST_EESCHEMA ) if( i >= GRID_FIRST_EESCHEMA )
{
m_netclassGrid->SetUnitsProvider( m_schUnitsProvider.get(), i ); m_netclassGrid->SetUnitsProvider( m_schUnitsProvider.get(), i );
if( !m_isEEschema )
{
m_netclassGrid->HideCol( i );
m_originalColWidths[ i ] = 0;
}
}
else else
{
m_netclassGrid->SetUnitsProvider( m_pcbUnitsProvider.get(), i ); m_netclassGrid->SetUnitsProvider( m_pcbUnitsProvider.get(), i );
}
COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
if( m_isEEschema ) if( m_isEEschema )
{ m_netclassGrid->ShowHideColumns( cfg->m_NetclassPanel.eeschema_visible_columns );
m_netclassGrid->HideCol( i ); else
m_originalColWidths[ i ] = 0; m_netclassGrid->ShowHideColumns( cfg->m_NetclassPanel.pcbnew_visible_columns );
}
} m_shownColumns = m_netclassGrid->GetShownColumns();
}
wxGridCellAttr* attr = new wxGridCellAttr; wxGridCellAttr* attr = new wxGridCellAttr;
attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( PAGED_DIALOG::GetDialog( this ) ) ); attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( PAGED_DIALOG::GetDialog( this ) ) );
@ -170,8 +160,8 @@ PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( wxWindow* aParentWindow, EDA_DRA
attr = new wxGridCellAttr; attr = new wxGridCellAttr;
attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( PAGED_DIALOG::GetDialog( this ) ) ); attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( PAGED_DIALOG::GetDialog( this ) ) );
attr->SetEditor( attr->SetEditor( new GRID_CELL_COLOR_SELECTOR( PAGED_DIALOG::GetDialog( this ),
new GRID_CELL_COLOR_SELECTOR( PAGED_DIALOG::GetDialog( this ), m_netclassGrid ) ); m_netclassGrid ) );
m_netclassGrid->SetColAttr( GRID_PCB_COLOR, attr ); m_netclassGrid->SetColAttr( GRID_PCB_COLOR, attr );
attr = new wxGridCellAttr; attr = new wxGridCellAttr;
@ -218,7 +208,6 @@ PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( wxWindow* aParentWindow, EDA_DRA
m_netclassGrid->SetSelectionMode( wxGrid::wxGridSelectRows ); m_netclassGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
m_assignmentGrid->SetSelectionMode( wxGrid::wxGridSelectRows ); m_assignmentGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
m_splitter->SetSashPosition( cfg->m_NetclassPanel.sash_pos ); m_splitter->SetSashPosition( cfg->m_NetclassPanel.sash_pos );
m_addButton->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) ); m_addButton->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
@ -267,6 +256,11 @@ PANEL_SETUP_NETCLASSES::~PANEL_SETUP_NETCLASSES()
COMMON_SETTINGS* cfg = Pgm().GetCommonSettings(); COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
cfg->m_NetclassPanel.sash_pos = m_splitter->GetSashPosition(); cfg->m_NetclassPanel.sash_pos = m_splitter->GetSashPosition();
if( m_isEEschema )
cfg->m_NetclassPanel.eeschema_visible_columns = m_netclassGrid->GetShownColumnsAsString();
else
cfg->m_NetclassPanel.pcbnew_visible_columns = m_netclassGrid->GetShownColumnsAsString();
// Delete the GRID_TRICKS. // Delete the GRID_TRICKS.
m_netclassGrid->PopEventHandler( true ); m_netclassGrid->PopEventHandler( true );
m_assignmentGrid->PopEventHandler( true ); m_assignmentGrid->PopEventHandler( true );
@ -282,6 +276,7 @@ PANEL_SETUP_NETCLASSES::~PANEL_SETUP_NETCLASSES()
void PANEL_SETUP_NETCLASSES::loadNetclasses() void PANEL_SETUP_NETCLASSES::loadNetclasses()
{ {
KIGFX::PCB_RENDER_SETTINGS* rs = nullptr; KIGFX::PCB_RENDER_SETTINGS* rs = nullptr;
if( !m_isEEschema ) if( !m_isEEschema )
{ {
rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
@ -290,7 +285,8 @@ void PANEL_SETUP_NETCLASSES::loadNetclasses()
int row = 0; int row = 0;
auto netclassToGridRow = [&]( int aRow, const std::shared_ptr<NETCLASS>& nc, bool isDefault ) auto netclassToGridRow =
[&]( int aRow, const std::shared_ptr<NETCLASS>& nc, bool isDefault )
{ {
m_netclassGrid->SetCellValue( aRow, GRID_NAME, nc->GetName() ); m_netclassGrid->SetCellValue( aRow, GRID_NAME, nc->GetName() );
@ -318,18 +314,15 @@ void PANEL_SETUP_NETCLASSES::loadNetclasses()
colorAsString = KIGFX::COLOR4D( 0.0, 0.0, 0.0, 0.0 ).ToCSSString(); colorAsString = KIGFX::COLOR4D( 0.0, 0.0, 0.0, 0.0 ).ToCSSString();
if( m_isEEschema ) if( m_isEEschema )
{
colorAsString = nc->GetPcbColor().ToCSSString(); colorAsString = nc->GetPcbColor().ToCSSString();
}
if( rs ) if( rs )
{ {
std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap(); std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
if( netclassColors.find( nc->GetName() ) != netclassColors.end() ) if( netclassColors.find( nc->GetName() ) != netclassColors.end() )
{
colorAsString = netclassColors[nc->GetName()].ToCSSString(); colorAsString = netclassColors[nc->GetName()].ToCSSString();
} }
}
if( isDefault ) if( isDefault )
{ {
@ -444,7 +437,8 @@ bool PANEL_SETUP_NETCLASSES::TransferDataFromWindow()
int row = 0; int row = 0;
auto gridRowToNetclass = [&]( int aRow, const std::shared_ptr<NETCLASS>& nc, bool isDefault ) auto gridRowToNetclass =
[&]( int aRow, const std::shared_ptr<NETCLASS>& nc, bool isDefault )
{ {
nc->SetName( m_netclassGrid->GetCellValue( aRow, GRID_NAME ) ); nc->SetName( m_netclassGrid->GetCellValue( aRow, GRID_NAME ) );
@ -473,9 +467,7 @@ bool PANEL_SETUP_NETCLASSES::TransferDataFromWindow()
KIGFX::COLOR4D newPcbColor( color ); KIGFX::COLOR4D newPcbColor( color );
if( newPcbColor != KIGFX::COLOR4D::UNSPECIFIED ) if( newPcbColor != KIGFX::COLOR4D::UNSPECIFIED )
{
nc->SetPcbColor( newPcbColor ); nc->SetPcbColor( newPcbColor );
}
if( !m_isEEschema ) if( !m_isEEschema )
{ {
@ -484,15 +476,11 @@ bool PANEL_SETUP_NETCLASSES::TransferDataFromWindow()
std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap(); std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
if( newPcbColor != COLOR4D::UNSPECIFIED ) if( newPcbColor != COLOR4D::UNSPECIFIED )
{
netclassColors[nc->GetName()] = newPcbColor; netclassColors[nc->GetName()] = newPcbColor;
}
else else
{
netclassColors.erase( nc->GetName() ); netclassColors.erase( nc->GetName() );
} }
} }
}
}; };
m_netSettings->m_NetClasses.clear(); m_netSettings->m_NetClasses.clear();
@ -706,10 +694,13 @@ void PANEL_SETUP_NETCLASSES::AdjustNetclassGridColumns( int aWidth )
aWidth -= ( m_netclassGrid->GetSize().x - m_netclassGrid->GetClientSize().x ); aWidth -= ( m_netclassGrid->GetSize().x - m_netclassGrid->GetClientSize().x );
for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ ) for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
{
if( m_netclassGrid->GetColSize( i ) > 0 )
{ {
m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] ); m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
aWidth -= m_originalColWidths[ i ]; aWidth -= m_originalColWidths[ i ];
} }
}
m_netclassGrid->SetColSize( 0, std::max( aWidth - 2, m_originalColWidths[ 0 ] ) ); m_netclassGrid->SetColSize( 0, std::max( aWidth - 2, m_originalColWidths[ 0 ] ) );
} }
@ -806,6 +797,12 @@ void PANEL_SETUP_NETCLASSES::OnUpdateUI( wxUpdateUIEvent& event )
m_netclassesDirty = false; m_netclassesDirty = false;
} }
if( m_shownColumns != m_netclassGrid->GetShownColumns() )
{
AdjustNetclassGridColumns( GetSize().x - 1 );
m_shownColumns = m_netclassGrid->GetShownColumns();
}
if( m_assignmentGrid->GetNumberRows() == 0 ) if( m_assignmentGrid->GetNumberRows() == 0 )
return; return;

View File

@ -341,6 +341,12 @@ COMMON_SETTINGS::COMMON_SETTINGS() :
m_params.emplace_back( new PARAM<int>( "netclass_panel.sash_pos", m_params.emplace_back( new PARAM<int>( "netclass_panel.sash_pos",
&m_NetclassPanel.sash_pos, 160 ) ); &m_NetclassPanel.sash_pos, 160 ) );
m_params.emplace_back( new PARAM<wxString>( "netclass_panel.eeschema_shown_columns",
&m_NetclassPanel.eeschema_visible_columns, "0 10 11 12 13" ) );
m_params.emplace_back( new PARAM<wxString>( "netclass_panel.pcbnew_shown_columns",
&m_NetclassPanel.pcbnew_visible_columns, "0 1 2 3 4 5 6 7 8 9" ) );
m_params.emplace_back( new PARAM<int>( "package_manager.sash_pos", m_params.emplace_back( new PARAM<int>( "package_manager.sash_pos",
&m_PackageManager.sash_pos, 380 ) ); &m_PackageManager.sash_pos, 380 ) );

View File

@ -89,6 +89,7 @@ private:
int m_hoveredCol; // Column being hovered over, for tooltips int m_hoveredCol; // Column being hovered over, for tooltips
wxString m_lastPattern; wxString m_lastPattern;
std::bitset<64> m_shownColumns;
int m_lastNetclassGridWidth; int m_lastNetclassGridWidth;
}; };

View File

@ -140,6 +140,8 @@ public:
struct NETCLASS_PANEL struct NETCLASS_PANEL
{ {
int sash_pos; int sash_pos;
wxString eeschema_visible_columns;
wxString pcbnew_visible_columns;
}; };
struct PACKAGE_MANAGER struct PACKAGE_MANAGER