Keep colors & visibility with layer objects, not layer number.

Also fixes a bug where the Layers manager would keep getting wider
each time the longest item was moved

Fixes https://gitlab.com/kicad/code/kicad/-/issues/15790
This commit is contained in:
Jeff Young 2023-10-01 16:52:21 +01:00
parent c5471bbe9f
commit d9f1aaa8e3
4 changed files with 31 additions and 22 deletions

View File

@ -492,7 +492,7 @@ void GERBVIEW_FRAME::ApplyDisplaySettingsToGAL()
int GERBVIEW_FRAME::getNextAvailableLayer() const int GERBVIEW_FRAME::getNextAvailableLayer() const
{ {
for( unsigned i = 0; i < ImagesMaxCount(); ++i ) for( int i = 0; i < (int) ImagesMaxCount(); ++i )
{ {
const GERBER_FILE_IMAGE* gerber = GetGbrImage( i ); const GERBER_FILE_IMAGE* gerber = GetGbrImage( i );
@ -544,10 +544,23 @@ void GERBVIEW_FRAME::SortLayersByX2Attributes()
} }
void GERBVIEW_FRAME::RemapLayers( std::unordered_map<int, int> remapping ) void GERBVIEW_FRAME::RemapLayers( const std::unordered_map<int, int>& remapping )
{ {
ReFillLayerWidget(); std::unordered_map<int, COLOR4D> oldColors;
syncLayerBox( true ); std::unordered_map<int, bool> oldVisibility;
LSET newVisibility;
for( const std::pair<const int, int>& entry : remapping )
{
oldColors[ entry.second ] = GetLayerColor( GERBER_DRAW_LAYER( entry.second ) );
oldVisibility[ entry.second ] = IsLayerVisible( entry.second );
}
for( const std::pair<const int, int>& entry : remapping )
{
SetLayerColor( GERBER_DRAW_LAYER( entry.first ), oldColors[ entry.second ] );
newVisibility.set( entry.first, oldVisibility[ entry.second ] );
}
std::unordered_map<int, int> view_remapping; std::unordered_map<int, int> view_remapping;
@ -558,6 +571,10 @@ void GERBVIEW_FRAME::RemapLayers( std::unordered_map<int, int> remapping )
} }
GetCanvas()->GetView()->ReorderLayerData( view_remapping ); GetCanvas()->GetView()->ReorderLayerData( view_remapping );
SetVisibleLayers( newVisibility );
ReFillLayerWidget();
syncLayerBox( true );
GetCanvas()->Refresh(); GetCanvas()->Refresh();
} }

View File

@ -359,7 +359,7 @@ public:
* @param remapping A map of old layer number -> new layer number mapping. * @param remapping A map of old layer number -> new layer number mapping.
* Generally sourced from the SortImagesBy* functions. * Generally sourced from the SortImagesBy* functions.
*/ */
void RemapLayers( std::unordered_map<int, int> remapping ); void RemapLayers( const std::unordered_map<int, int>& remapping );
/** /**
* Update each layers' differential option. Needed when xor mode changes or the active layer * Update each layers' differential option. Needed when xor mode changes or the active layer

View File

@ -318,7 +318,9 @@ void GERBER_LAYER_WIDGET::ReFill()
SetLayerVisible( layer, visible ); SetLayerVisible( layer, visible );
} }
else else
{
AppendLayerRow( LAYER_WIDGET::ROW( msg, layer, color, wxEmptyString, visible, true ) ); AppendLayerRow( LAYER_WIDGET::ROW( msg, layer, color, wxEmptyString, visible, true ) );
}
} }
UpdateLayouts(); UpdateLayouts();

View File

@ -339,7 +339,7 @@ void LAYER_WIDGET::insertLayerRow( int aRow, const ROW& aSpec )
bmb->Bind( COLOR_SWATCH_CHANGED, &LAYER_WIDGET::OnLayerSwatchChanged, this ); bmb->Bind( COLOR_SWATCH_CHANGED, &LAYER_WIDGET::OnLayerSwatchChanged, this );
bmb->SetToolTip( _( "Left double click or middle click for color change, right click for " bmb->SetToolTip( _( "Left double click or middle click for color change, right click for "
"menu" ) ); "menu" ) );
m_LayersFlexGridSizer->wxSizer::Insert( index+col, bmb, 0, flags ); m_LayersFlexGridSizer->wxSizer::Insert( index+col, bmb, 0, flags | wxRIGHT, 2 );
// column 2 (COLUMN_COLOR_LYR_CB) // column 2 (COLUMN_COLOR_LYR_CB)
col = COLUMN_COLOR_LYR_CB; col = COLUMN_COLOR_LYR_CB;
@ -517,7 +517,7 @@ LAYER_WIDGET::LAYER_WIDGET( wxWindow* aParent, wxWindow* aFocusOwner, wxWindowID
m_LayerScrolledWindow = new wxScrolledWindow( m_LayerPanel, wxID_ANY, wxDefaultPosition, m_LayerScrolledWindow = new wxScrolledWindow( m_LayerPanel, wxID_ANY, wxDefaultPosition,
wxDefaultSize, wxNO_BORDER ); wxDefaultSize, wxNO_BORDER );
m_LayerScrolledWindow->SetScrollRate( 5, 5 ); m_LayerScrolledWindow->SetScrollRate( 5, 5 );
m_LayersFlexGridSizer = new wxFlexGridSizer( 0, LYR_COLUMN_COUNT, 0, 1 ); m_LayersFlexGridSizer = new wxFlexGridSizer( 0, LYR_COLUMN_COUNT, 3, 4 );
m_LayersFlexGridSizer->SetFlexibleDirection( wxHORIZONTAL ); m_LayersFlexGridSizer->SetFlexibleDirection( wxHORIZONTAL );
m_LayersFlexGridSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_NONE ); m_LayersFlexGridSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_NONE );
@ -542,7 +542,7 @@ LAYER_WIDGET::LAYER_WIDGET( wxWindow* aParent, wxWindow* aFocusOwner, wxWindowID
m_RenderScrolledWindow = new wxScrolledWindow( m_RenderingPanel, wxID_ANY, wxDefaultPosition, m_RenderScrolledWindow = new wxScrolledWindow( m_RenderingPanel, wxID_ANY, wxDefaultPosition,
wxDefaultSize, wxNO_BORDER ); wxDefaultSize, wxNO_BORDER );
m_RenderScrolledWindow->SetScrollRate( 5, 5 ); m_RenderScrolledWindow->SetScrollRate( 5, 5 );
m_RenderFlexGridSizer = new wxFlexGridSizer( 0, RND_COLUMN_COUNT, 0, 1 ); m_RenderFlexGridSizer = new wxFlexGridSizer( 0, RND_COLUMN_COUNT, 3, 4 );
m_RenderFlexGridSizer->SetFlexibleDirection( wxHORIZONTAL ); m_RenderFlexGridSizer->SetFlexibleDirection( wxHORIZONTAL );
m_RenderFlexGridSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_NONE ); m_RenderFlexGridSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_NONE );
@ -583,13 +583,8 @@ wxSize LAYER_WIDGET::GetBestSize() const
wxArrayInt widths = m_LayersFlexGridSizer->GetColWidths(); wxArrayInt widths = m_LayersFlexGridSizer->GetColWidths();
int totWidth = 0; int totWidth = 0;
if( widths.GetCount() ) for( int i = 0; i < LYR_COLUMN_COUNT && i < widths.GetCount(); ++i )
{ totWidth += widths[i];
for( int i = 0; i < LYR_COLUMN_COUNT; ++i )
{
totWidth += widths[i] + m_LayersFlexGridSizer->GetHGap();
}
}
// Account for the parent's frame: // Account for the parent's frame:
totWidth += 15; totWidth += 15;
@ -607,13 +602,8 @@ wxSize LAYER_WIDGET::GetBestSize() const
widths = m_RenderFlexGridSizer->GetColWidths(); widths = m_RenderFlexGridSizer->GetColWidths();
totWidth = 0; totWidth = 0;
if( widths.GetCount() ) for( int i = 0; i < RND_COLUMN_COUNT && i < widths.GetCount(); ++i )
{ totWidth += widths[i];
for( int i = 0; i < RND_COLUMN_COUNT; ++i )
{
totWidth += widths[i] + m_RenderFlexGridSizer->GetHGap();
}
}
// account for the parent's frame, this one has void space of 10 PLUS a border: // account for the parent's frame, this one has void space of 10 PLUS a border:
totWidth += 15; totWidth += 15;