From cf7ffda5f68bd30245107977ef80ecefbfc2876b Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 2 May 2020 21:09:43 +0100 Subject: [PATCH] Performance improvements for Gerber loading. The entire issue (at least on OSX) was the layers palette. Go figure. Fixes https://gitlab.com/kicad/code/kicad/issues/1892 --- common/widgets/indicator_icon.cpp | 24 +++++----- gerbview/gerbview_frame.cpp | 6 ++- gerbview/gerbview_layer_widget.cpp | 14 +++--- pcbnew/layer_widget.cpp | 70 ++++++++++++++++++++++-------- pcbnew/layer_widget.h | 2 + 5 files changed, 74 insertions(+), 42 deletions(-) diff --git a/common/widgets/indicator_icon.cpp b/common/widgets/indicator_icon.cpp index e777d8b570..ef4dcc4eab 100644 --- a/common/widgets/indicator_icon.cpp +++ b/common/widgets/indicator_icon.cpp @@ -39,9 +39,10 @@ INDICATOR_ICON::INDICATOR_ICON( wxWindow* aParent, ICON_PROVIDER& aIconProvider, sizer->Add( m_bitmap, 0, 0 ); - auto evtSkipper = [this] ( wxEvent& aEvent ) { - wxPostEvent( this, aEvent ); - }; + auto evtSkipper = [this] ( wxEvent& aEvent ) + { + wxPostEvent( this, aEvent ); + }; m_bitmap->Bind( wxEVT_LEFT_DOWN, evtSkipper ); } @@ -166,16 +167,11 @@ const wxBitmap& ROW_ICON_PROVIDER::GetIndicatorIcon( INDICATOR_ICON::ICON_ID aId { switch( aId ) { - case STATE::UP: - return m_upArrowBitmap; - case STATE::DOWN: - return m_downArrowBitmap; - case STATE::ON: - return m_rightArrowBitmap; - case STATE::DIMMED: - return m_dotBitmap; - case STATE::OFF: - default: - return m_blankBitmap; + case STATE::UP: return m_upArrowBitmap; + case STATE::DOWN: return m_downArrowBitmap; + case STATE::ON: return m_rightArrowBitmap; + case STATE::DIMMED: return m_dotBitmap; + case STATE::OFF: return m_blankBitmap; + default: return m_blankBitmap; } } diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index 4ca1644086..c8a8653272 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -56,7 +56,7 @@ #include #include #include - +#include GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent ) : EDA_DRAW_FRAME( aKiway, aParent, FRAME_GERBER, wxT( "GerbView" ), wxDefaultPosition, @@ -350,6 +350,8 @@ void GERBVIEW_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) void GERBVIEW_FRAME::ReFillLayerWidget() { + wxWindowUpdateLocker no_update( m_LayersManager ); + m_LayersManager->ReFill(); m_SelLayerBox->Resync(); ReCreateAuxiliaryToolbar(); @@ -852,7 +854,7 @@ void GERBVIEW_FRAME::SetActiveLayer( int aLayer, bool doLayerWidgetUpdate ) ( (GBR_SCREEN*) GetScreen() )->m_Active_Layer = aLayer; if( doLayerWidgetUpdate ) - m_LayersManager->SelectLayer( GetActiveLayer() ); + m_LayersManager->SelectLayer( aLayer ); UpdateTitleAndInfo(); diff --git a/gerbview/gerbview_layer_widget.cpp b/gerbview/gerbview_layer_widget.cpp index e2062a27a3..8077f357c4 100644 --- a/gerbview/gerbview_layer_widget.cpp +++ b/gerbview/gerbview_layer_widget.cpp @@ -216,22 +216,22 @@ void GERBER_LAYER_WIDGET::ReFill() { Freeze(); - ClearLayerRows(); - for( int layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer ) { + int aRow = findLayerRow( layer ); + bool visible = true; + COLOR4D color = myframe->GetLayerColor( GERBER_DRAW_LAYER( layer ) ); wxString msg = GetImagesList()->GetDisplayName( layer ); - bool visible = true; - if( myframe->GetCanvas() ) visible = myframe->GetCanvas()->GetView()->IsLayerVisible( GERBER_DRAW_LAYER( layer ) ); else visible = myframe->IsLayerVisible( layer ); - AppendLayerRow( LAYER_WIDGET::ROW( msg, layer, - myframe->GetLayerColor( GERBER_DRAW_LAYER( layer ) ), - wxEmptyString, visible, true ) ); + if( aRow >= 0 ) + updateLayerRow( findLayerRow( layer ), msg ); + else + AppendLayerRow( LAYER_WIDGET::ROW( msg, layer, color, wxEmptyString, visible, true ) ); } UpdateLayouts(); diff --git a/pcbnew/layer_widget.cpp b/pcbnew/layer_widget.cpp index fa3d29d8c8..b5b3b23e3b 100644 --- a/pcbnew/layer_widget.cpp +++ b/pcbnew/layer_widget.cpp @@ -182,13 +182,14 @@ void LAYER_WIDGET::OnRightDownRender( wxMouseEvent& aEvent, COLOR_SWATCH* aColor _( "Change Render Color for " ) + aRenderName, KiBitmap( setcolor_board_body_xpm ) ); - menu.Bind( wxEVT_COMMAND_MENU_SELECTED, [aColorSwatch]( wxCommandEvent& event ) { - if ( event.GetId() == ID_CHANGE_RENDER_COLOR ) { - aColorSwatch->GetNewSwatchColor(); - } else { - event.Skip(); - } - } ); + menu.Bind( wxEVT_COMMAND_MENU_SELECTED, + [aColorSwatch]( wxCommandEvent& event ) + { + if( event.GetId() == ID_CHANGE_RENDER_COLOR ) + aColorSwatch->GetNewSwatchColor(); + else + event.Skip(); + } ); PopupMenu( &menu ); passOnFocus(); @@ -209,18 +210,22 @@ void LAYER_WIDGET::OnRenderSwatchChanged( wxCommandEvent& aEvent ) int count = GetLayerRowCount(); int row; int col = 1; // bitmap button is column 1 in layers tab + for( row = 0; row < count; ++row ) { COLOR_SWATCH* swatch = dynamic_cast( getLayerComp( row, col ) ); + if( swatch ) swatch->SetSwatchBackground( newColor ); } count = GetRenderRowCount(); col = 0; // bitmap button is column 0 in render tab + for( row = 0; row < count; ++row ) { COLOR_SWATCH* swatch = dynamic_cast( getRenderComp( row, col ) ); + if( swatch ) swatch->SetSwatchBackground( newColor ); } @@ -359,18 +364,43 @@ void LAYER_WIDGET::insertLayerRow( int aRow, const ROW& aSpec ) // Bind right click eventhandler to all columns wxString layerName( aSpec.rowName ); - sbm->Bind( wxEVT_RIGHT_DOWN, [this, bmb, layerName] ( wxMouseEvent& aEvt ) { - OnRightDownLayer( aEvt, bmb, layerName ); - } ); - bmb->Bind( wxEVT_RIGHT_DOWN, [this, bmb, layerName] ( wxMouseEvent& aEvt ) { - OnRightDownLayer( aEvt, bmb, layerName ); - } ); - cb->Bind( wxEVT_RIGHT_DOWN, [this, bmb, layerName] ( wxMouseEvent& aEvt ) { - OnRightDownLayer( aEvt, bmb, layerName ); - } ); - st->Bind( wxEVT_RIGHT_DOWN, [this, bmb, layerName] ( wxMouseEvent& aEvt ) { - OnRightDownLayer( aEvt, bmb, layerName ); - } ); + sbm->Bind( wxEVT_RIGHT_DOWN, [this, bmb, layerName] ( wxMouseEvent& aEvt ) + { + OnRightDownLayer( aEvt, bmb, layerName ); + } ); + bmb->Bind( wxEVT_RIGHT_DOWN, [this, bmb, layerName] ( wxMouseEvent& aEvt ) + { + OnRightDownLayer( aEvt, bmb, layerName ); + } ); + cb->Bind( wxEVT_RIGHT_DOWN, [this, bmb, layerName] ( wxMouseEvent& aEvt ) + { + OnRightDownLayer( aEvt, bmb, layerName ); + } ); + st->Bind( wxEVT_RIGHT_DOWN, [this, bmb, layerName] ( wxMouseEvent& aEvt ) + { + OnRightDownLayer( aEvt, bmb, layerName ); + } ); +} + + +void LAYER_WIDGET::updateLayerRow( int aRow, const wxString& aName ) +{ + wxStaticText* label = dynamic_cast( getLayerComp( aRow, COLUMN_COLOR_LYRNAME ) ); + + if( label ) + label->SetLabel( aName ); + + INDICATOR_ICON* indicator = (INDICATOR_ICON*) getLayerComp( aRow, 0 ); + + if( indicator ) + { + if( aRow == m_CurrentRow ) + indicator->SetIndicatorState( ROW_ICON_PROVIDER::STATE::ON ); + if( useAlternateBitmap( aRow ) ) + indicator->SetIndicatorState( ROW_ICON_PROVIDER::STATE::DIMMED ); + else + indicator->SetIndicatorState( ROW_ICON_PROVIDER::STATE::OFF ); + } } @@ -638,6 +668,7 @@ void LAYER_WIDGET::SelectLayerRow( int aRow ) m_notebook->SetSelection( 0 ); INDICATOR_ICON* oldIndicator = (INDICATOR_ICON*) getLayerComp( m_CurrentRow, 0 ); + if( oldIndicator ) { if( useAlternateBitmap( m_CurrentRow ) ) @@ -647,6 +678,7 @@ void LAYER_WIDGET::SelectLayerRow( int aRow ) } INDICATOR_ICON* newIndicator = (INDICATOR_ICON*) getLayerComp( aRow, 0 ); + if( newIndicator ) { newIndicator->SetIndicatorState( ROW_ICON_PROVIDER::STATE::ON ); diff --git a/pcbnew/layer_widget.h b/pcbnew/layer_widget.h index 55b6241451..c7616eacf4 100644 --- a/pcbnew/layer_widget.h +++ b/pcbnew/layer_widget.h @@ -238,6 +238,8 @@ protected: void setLayerCheckbox( LAYER_NUM aLayer, bool isVisible ); + void updateLayerRow( int aRow, const wxString& aName ); + /** * Function passOnFocus * gives away the keyboard focus up to the main parent window.