From 8e29a054f39d41653f967a9df91d07a62fa8d1d4 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 13 Apr 2023 13:45:22 +0100 Subject: [PATCH] Performance improvement for GetShownColumns. (This needs to be fast as it's called from OnUpdateUI events.) --- common/widgets/wx_grid.cpp | 25 ++++++++++++++++++- eeschema/dialogs/dialog_label_properties.cpp | 25 ++++++++----------- eeschema/dialogs/dialog_label_properties.h | 2 +- .../dialogs/dialog_lib_edit_pin_table.cpp | 15 +++++------ eeschema/dialogs/dialog_lib_edit_pin_table.h | 2 +- .../dialogs/dialog_lib_symbol_properties.cpp | 6 ++--- .../dialogs/dialog_lib_symbol_properties.h | 2 +- eeschema/dialogs/dialog_sheet_properties.cpp | 18 +++++-------- eeschema/dialogs/dialog_sheet_properties.h | 2 +- eeschema/dialogs/dialog_symbol_properties.cpp | 16 +++++------- eeschema/dialogs/dialog_symbol_properties.h | 14 +++++------ include/widgets/wx_grid.h | 8 +++++- .../dialogs/dialog_footprint_properties.cpp | 8 +++--- .../dialog_footprint_properties_fp_editor.cpp | 4 +-- 14 files changed, 82 insertions(+), 65 deletions(-) diff --git a/common/widgets/wx_grid.cpp b/common/widgets/wx_grid.cpp index 81ccf8f2a0..f1b57ec3e3 100644 --- a/common/widgets/wx_grid.cpp +++ b/common/widgets/wx_grid.cpp @@ -273,7 +273,7 @@ void WX_GRID::DestroyTable( wxGridTableBase* aTable ) } -wxString WX_GRID::GetShownColumns() +wxString WX_GRID::GetShownColumnsAsString() { wxString shownColumns; @@ -292,6 +292,17 @@ wxString WX_GRID::GetShownColumns() } +std::bitset<64> WX_GRID::GetShownColumns() +{ + std::bitset<64> shownColumns; + + for( int ii = 0; ii < GetNumberCols(); ++ii ) + shownColumns[ii] = IsColShown( ii ); + + return shownColumns; +} + + void WX_GRID::ShowHideColumns( const wxString& shownColumns ) { for( int i = 0; i < GetNumberCols(); ++i ) @@ -310,6 +321,18 @@ void WX_GRID::ShowHideColumns( const wxString& shownColumns ) } +void WX_GRID::ShowHideColumns( const std::bitset<64>& aShownColumns ) +{ + for( int ii = 0; ii < GetNumberCols(); ++ ii ) + { + if( aShownColumns[ii] ) + ShowCol( ii ); + else + HideCol( ii ); + } +} + + void WX_GRID::DrawCornerLabel( wxDC& dc ) { if( m_nativeColumnLabels ) diff --git a/eeschema/dialogs/dialog_label_properties.cpp b/eeschema/dialogs/dialog_label_properties.cpp index 1420834da5..2d3b3f5dc5 100644 --- a/eeschema/dialogs/dialog_label_properties.cpp +++ b/eeschema/dialogs/dialog_label_properties.cpp @@ -118,13 +118,10 @@ DIALOG_LABEL_PROPERTIES::DIALOG_LABEL_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_L m_grid->SetSelectionMode( wxGrid::wxGridSelectRows ); // Show/hide columns according to user's preference - auto cfg = dynamic_cast( Kiface().KifaceSettings() ); - wxASSERT( cfg ); - - if( cfg ) + if( EESCHEMA_SETTINGS* cfg = dynamic_cast( Kiface().KifaceSettings() ) ) { - m_shownColumns = cfg->m_Appearance.edit_label_visible_columns; - m_grid->ShowHideColumns( m_shownColumns ); + m_grid->ShowHideColumns( cfg->m_Appearance.edit_label_visible_columns ); + m_shownColumns = m_grid->GetShownColumns(); } // Configure button logos @@ -221,19 +218,19 @@ DIALOG_LABEL_PROPERTIES::DIALOG_LABEL_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_L // Now all widgets have the size fixed, call FinishDialogSettings finishDialogSettings(); - if( cfg && cfg->m_Appearance.edit_label_width > 0 && cfg->m_Appearance.edit_label_height > 0 ) - SetSize( cfg->m_Appearance.edit_label_width, cfg->m_Appearance.edit_label_height ); + if( EESCHEMA_SETTINGS* cfg = dynamic_cast( Kiface().KifaceSettings() ) ) + { + if( cfg->m_Appearance.edit_label_width > 0 && cfg->m_Appearance.edit_label_height > 0 ) + SetSize( cfg->m_Appearance.edit_label_width, cfg->m_Appearance.edit_label_height ); + } } DIALOG_LABEL_PROPERTIES::~DIALOG_LABEL_PROPERTIES() { - EESCHEMA_SETTINGS* cfg = dynamic_cast( Kiface().KifaceSettings() ); - wxASSERT( cfg ); - - if( cfg ) + if( EESCHEMA_SETTINGS* cfg = dynamic_cast( Kiface().KifaceSettings() ) ) { - cfg->m_Appearance.edit_label_visible_columns = m_grid->GetShownColumns(); + cfg->m_Appearance.edit_label_visible_columns = m_grid->GetShownColumnsAsString(); cfg->m_Appearance.edit_label_width = GetSize().x; cfg->m_Appearance.edit_label_height = GetSize().y; } @@ -776,7 +773,7 @@ void DIALOG_LABEL_PROPERTIES::AdjustGridColumns( int aWidth ) void DIALOG_LABEL_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event ) { - wxString shownColumns = m_grid->GetShownColumns(); + std::bitset<64> shownColumns = m_grid->GetShownColumns(); if( shownColumns != m_shownColumns ) { diff --git a/eeschema/dialogs/dialog_label_properties.h b/eeschema/dialogs/dialog_label_properties.h index 09c2610cb2..111d45b771 100644 --- a/eeschema/dialogs/dialog_label_properties.h +++ b/eeschema/dialogs/dialog_label_properties.h @@ -71,7 +71,7 @@ private: SCH_NETNAME_VALIDATOR m_netNameValidator; FIELDS_GRID_TABLE* m_fields; - wxString m_shownColumns; + std::bitset<64> m_shownColumns; UNIT_BINDER m_textSize; diff --git a/eeschema/dialogs/dialog_lib_edit_pin_table.cpp b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp index df89f772c5..fcefb2c402 100644 --- a/eeschema/dialogs/dialog_lib_edit_pin_table.cpp +++ b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp @@ -723,10 +723,11 @@ DIALOG_LIB_EDIT_PIN_TABLE::DIALOG_LIB_EDIT_PIN_TABLE( SYMBOL_EDIT_FRAME* parent, } ) ); // Show/hide columns according to the user's preference - SYMBOL_EDITOR_SETTINGS* cfg = parent->GetSettings(); - m_columnsShown = cfg->m_PinTableVisibleColumns; - - m_grid->ShowHideColumns( m_columnsShown ); + if( SYMBOL_EDITOR_SETTINGS* cfg = parent->GetSettings() ) + { + m_grid->ShowHideColumns( cfg->m_PinTableVisibleColumns ); + m_columnsShown = m_grid->GetShownColumns(); + } // Set special attributes wxGridCellAttr* attr; @@ -838,8 +839,8 @@ DIALOG_LIB_EDIT_PIN_TABLE::DIALOG_LIB_EDIT_PIN_TABLE( SYMBOL_EDIT_FRAME* parent, DIALOG_LIB_EDIT_PIN_TABLE::~DIALOG_LIB_EDIT_PIN_TABLE() { - SYMBOL_EDITOR_SETTINGS* cfg = m_editFrame->GetSettings(); - cfg->m_PinTableVisibleColumns = m_grid->GetShownColumns().ToStdString(); + if( SYMBOL_EDITOR_SETTINGS* cfg = m_editFrame->GetSettings() ) + cfg->m_PinTableVisibleColumns = m_grid->GetShownColumnsAsString(); // Disconnect Events m_grid->Disconnect( wxEVT_GRID_COL_SORT, @@ -1130,7 +1131,7 @@ void DIALOG_LIB_EDIT_PIN_TABLE::OnSize( wxSizeEvent& event ) void DIALOG_LIB_EDIT_PIN_TABLE::OnUpdateUI( wxUpdateUIEvent& event ) { - wxString columnsShown = m_grid->GetShownColumns(); + std::bitset<64> columnsShown = m_grid->GetShownColumns(); if( columnsShown != m_columnsShown ) { diff --git a/eeschema/dialogs/dialog_lib_edit_pin_table.h b/eeschema/dialogs/dialog_lib_edit_pin_table.h index 6e80d6f420..f9f0094d64 100644 --- a/eeschema/dialogs/dialog_lib_edit_pin_table.h +++ b/eeschema/dialogs/dialog_lib_edit_pin_table.h @@ -84,7 +84,7 @@ protected: SYMBOL_EDIT_FRAME* m_editFrame; bool m_initialized = false; int m_originalColWidths[ COL_COUNT ]; - wxString m_columnsShown; + std::bitset<64> m_columnsShown; LIB_SYMBOL* m_symbol; LIB_PINS m_pins; // a copy of the pins owned by me bool m_modified; ///< true when there are unsaved changes diff --git a/eeschema/dialogs/dialog_lib_symbol_properties.cpp b/eeschema/dialogs/dialog_lib_symbol_properties.cpp index fcfad0931a..ef8e16bbb5 100644 --- a/eeschema/dialogs/dialog_lib_symbol_properties.cpp +++ b/eeschema/dialogs/dialog_lib_symbol_properties.cpp @@ -127,8 +127,8 @@ DIALOG_LIB_SYMBOL_PROPERTIES::~DIALOG_LIB_SYMBOL_PROPERTIES() { m_lastOpenedPage = m_NoteBook->GetSelection( ); - SYMBOL_EDITOR_SETTINGS* cfg = m_Parent->GetSettings(); - cfg->m_EditSymbolVisibleColumns = m_grid->GetShownColumns(); + if( SYMBOL_EDITOR_SETTINGS* cfg = m_Parent->GetSettings() ) + cfg->m_EditSymbolVisibleColumns = m_grid->GetShownColumnsAsString(); // Prevents crash bug in wxGrid's d'tor m_grid->DestroyTable( m_fields ); @@ -839,7 +839,7 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event ) } // Handle shown columns changes - wxString shownColumns = m_grid->GetShownColumns(); + std::bitset<64> shownColumns = m_grid->GetShownColumns(); if( shownColumns != m_shownColumns ) { diff --git a/eeschema/dialogs/dialog_lib_symbol_properties.h b/eeschema/dialogs/dialog_lib_symbol_properties.h index d59bcb3a62..a6efd7c485 100644 --- a/eeschema/dialogs/dialog_lib_symbol_properties.h +++ b/eeschema/dialogs/dialog_lib_symbol_properties.h @@ -90,7 +90,7 @@ public: int m_delayedFocusPage; wxString m_delayedErrorMessage; - wxString m_shownColumns; + std::bitset<64> m_shownColumns; wxSize m_size; private: diff --git a/eeschema/dialogs/dialog_sheet_properties.cpp b/eeschema/dialogs/dialog_sheet_properties.cpp index 4b53741fa7..bf1341af22 100644 --- a/eeschema/dialogs/dialog_sheet_properties.cpp +++ b/eeschema/dialogs/dialog_sheet_properties.cpp @@ -70,13 +70,10 @@ DIALOG_SHEET_PROPERTIES::DIALOG_SHEET_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_S m_grid->SetSelectionMode( wxGrid::wxGridSelectRows ); // Show/hide columns according to user's preference - EESCHEMA_SETTINGS* cfg = dynamic_cast( Kiface().KifaceSettings() ); - wxASSERT( cfg ); - - if( cfg ) + if( EESCHEMA_SETTINGS* cfg = dynamic_cast( Kiface().KifaceSettings() ) ) { - m_shownColumns = cfg->m_Appearance.edit_sheet_visible_columns; - m_grid->ShowHideColumns( m_shownColumns ); + m_grid->ShowHideColumns( cfg->m_Appearance.edit_sheet_visible_columns ); + m_shownColumns = m_grid->GetShownColumns(); } if( m_frame->GetColorSettings()->GetOverrideSchItemColors() ) @@ -109,12 +106,9 @@ DIALOG_SHEET_PROPERTIES::DIALOG_SHEET_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_S DIALOG_SHEET_PROPERTIES::~DIALOG_SHEET_PROPERTIES() { - EESCHEMA_SETTINGS* cfg = dynamic_cast( Kiface().KifaceSettings() ); - wxASSERT( cfg ); - - if( cfg ) + if( EESCHEMA_SETTINGS* cfg = dynamic_cast( Kiface().KifaceSettings() ) ) { - cfg->m_Appearance.edit_sheet_visible_columns = m_grid->GetShownColumns(); + cfg->m_Appearance.edit_sheet_visible_columns = m_grid->GetShownColumnsAsString(); cfg->m_Appearance.edit_sheet_width = GetSize().x; cfg->m_Appearance.edit_sheet_height = GetSize().y; } @@ -833,7 +827,7 @@ void DIALOG_SHEET_PROPERTIES::AdjustGridColumns() void DIALOG_SHEET_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event ) { - wxString shownColumns = m_grid->GetShownColumns(); + std::bitset<64> shownColumns = m_grid->GetShownColumns(); if( shownColumns != m_shownColumns ) { diff --git a/eeschema/dialogs/dialog_sheet_properties.h b/eeschema/dialogs/dialog_sheet_properties.h index 14ca86639c..4770b24403 100644 --- a/eeschema/dialogs/dialog_sheet_properties.h +++ b/eeschema/dialogs/dialog_sheet_properties.h @@ -70,7 +70,7 @@ private: wxSize m_size; int m_delayedFocusRow; int m_delayedFocusColumn; - wxString m_shownColumns; + std::bitset<64> m_shownColumns; FIELDS_GRID_TABLE* m_fields; UNIT_BINDER m_borderWidth; diff --git a/eeschema/dialogs/dialog_symbol_properties.cpp b/eeschema/dialogs/dialog_symbol_properties.cpp index 4540946040..10ceb88649 100644 --- a/eeschema/dialogs/dialog_symbol_properties.cpp +++ b/eeschema/dialogs/dialog_symbol_properties.cpp @@ -326,12 +326,10 @@ DIALOG_SYMBOL_PROPERTIES::DIALOG_SYMBOL_PROPERTIES( SCH_EDIT_FRAME* aParent, m_fieldsGrid->SetSelectionMode( wxGrid::wxGridSelectRows ); // Show/hide columns according to user's preference - EESCHEMA_SETTINGS* cfg = dynamic_cast( Kiface().KifaceSettings() ); - - if( cfg ) + if( EESCHEMA_SETTINGS* cfg = dynamic_cast( Kiface().KifaceSettings() ) ) { - m_shownColumns = cfg->m_Appearance.edit_symbol_visible_columns; - m_fieldsGrid->ShowHideColumns( m_shownColumns ); + m_fieldsGrid->ShowHideColumns( cfg->m_Appearance.edit_symbol_visible_columns ); + m_shownColumns = m_fieldsGrid->GetShownColumns(); } if( m_part && m_part->HasConversion() ) @@ -387,11 +385,9 @@ DIALOG_SYMBOL_PROPERTIES::DIALOG_SYMBOL_PROPERTIES( SCH_EDIT_FRAME* aParent, DIALOG_SYMBOL_PROPERTIES::~DIALOG_SYMBOL_PROPERTIES() { - EESCHEMA_SETTINGS* cfg = dynamic_cast( Kiface().KifaceSettings() ); - - if( cfg ) + if( EESCHEMA_SETTINGS* cfg = dynamic_cast( Kiface().KifaceSettings() ) ) { - cfg->m_Appearance.edit_symbol_visible_columns = m_fieldsGrid->GetShownColumns(); + cfg->m_Appearance.edit_symbol_visible_columns = m_fieldsGrid->GetShownColumnsAsString(); cfg->m_Appearance.edit_symbol_width = GetSize().x; cfg->m_Appearance.edit_symbol_height = GetSize().y; } @@ -1165,7 +1161,7 @@ void DIALOG_SYMBOL_PROPERTIES::AdjustPinsGridColumns() void DIALOG_SYMBOL_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event ) { - wxString shownColumns = m_fieldsGrid->GetShownColumns(); + std::bitset<64> shownColumns = m_fieldsGrid->GetShownColumns(); if( shownColumns != m_shownColumns ) { diff --git a/eeschema/dialogs/dialog_symbol_properties.h b/eeschema/dialogs/dialog_symbol_properties.h index 316d38b23e..f85d72905b 100644 --- a/eeschema/dialogs/dialog_symbol_properties.h +++ b/eeschema/dialogs/dialog_symbol_properties.h @@ -102,14 +102,14 @@ private: void AdjustGridColumns( int aWidth ); private: - SCH_SYMBOL* m_symbol; - LIB_SYMBOL* m_part; + SCH_SYMBOL* m_symbol; + LIB_SYMBOL* m_part; - wxSize m_fieldsSize; - wxSize m_lastRequestedSize; - wxSize m_pinsSize; - bool m_editorShown; - wxString m_shownColumns; + wxSize m_fieldsSize; + wxSize m_lastRequestedSize; + wxSize m_pinsSize; + bool m_editorShown; + std::bitset<64> m_shownColumns; FIELDS_GRID_TABLE* m_fields; SCH_PIN_TABLE_DATA_MODEL* m_dataModel; diff --git a/include/widgets/wx_grid.h b/include/widgets/wx_grid.h index a41182171b..8033fb1989 100644 --- a/include/widgets/wx_grid.h +++ b/include/widgets/wx_grid.h @@ -61,13 +61,19 @@ public: * Get a tokenized string containing the shown column indexes. * Tokens are separated by spaces. */ - wxString GetShownColumns(); + wxString GetShownColumnsAsString(); + std::bitset<64> GetShownColumns(); /** * Show/hide the grid columns based on a tokenized string of shown column indexes. */ void ShowHideColumns( const wxString& shownColumns ); + /** + * A more performant version of ShowHideColumns (primarily for OnUpdateUI handlers). + */ + void ShowHideColumns( const std::bitset<64>& aShownColumns ); + /** * Hide wxGrid's SetTable() method with one which doesn't mess up the grid column * widths when setting the table. diff --git a/pcbnew/dialogs/dialog_footprint_properties.cpp b/pcbnew/dialogs/dialog_footprint_properties.cpp index 2d6b555ead..5c4d25029d 100644 --- a/pcbnew/dialogs/dialog_footprint_properties.cpp +++ b/pcbnew/dialogs/dialog_footprint_properties.cpp @@ -97,10 +97,9 @@ DIALOG_FOOTPRINT_PROPERTIES::DIALOG_FOOTPRINT_PROPERTIES( PCB_EDIT_FRAME* aParen m_itemsGrid->SetTable( m_texts ); m_itemsGrid->PushEventHandler( new GRID_TRICKS( m_itemsGrid ) ); - PCBNEW_SETTINGS* cfg = m_frame->GetPcbNewSettings(); - // Show/hide text item columns according to the user's preference - m_itemsGrid->ShowHideColumns( cfg->m_FootprintTextShownColumns ); + if( PCBNEW_SETTINGS* cfg = m_frame->GetPcbNewSettings() ) + m_itemsGrid->ShowHideColumns( cfg->m_FootprintTextShownColumns ); m_orientation.SetUnits( EDA_UNITS::DEGREES ); m_orientation.SetPrecision( 3 ); @@ -175,7 +174,8 @@ DIALOG_FOOTPRINT_PROPERTIES::DIALOG_FOOTPRINT_PROPERTIES( PCB_EDIT_FRAME* aParen DIALOG_FOOTPRINT_PROPERTIES::~DIALOG_FOOTPRINT_PROPERTIES() { - m_frame->GetPcbNewSettings()->m_FootprintTextShownColumns = m_itemsGrid->GetShownColumns().ToStdString(); + if( PCBNEW_SETTINGS* cfg = m_frame->GetPcbNewSettings() ) + cfg->m_FootprintTextShownColumns = m_itemsGrid->GetShownColumnsAsString(); // Prevents crash bug in wxGrid's d'tor m_itemsGrid->DestroyTable( m_texts ); diff --git a/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp b/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp index 74a8e183d2..bb6cfb9d87 100644 --- a/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp +++ b/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp @@ -229,8 +229,8 @@ DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR( DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::~DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR() { - m_frame->GetSettings()->m_FootprintTextShownColumns = - m_itemsGrid->GetShownColumns().ToStdString(); + if( FOOTPRINT_EDITOR_SETTINGS* cfg = m_frame->GetSettings() ) + cfg->m_FootprintTextShownColumns = m_itemsGrid->GetShownColumnsAsString(); // Prevents crash bug in wxGrid's d'tor m_itemsGrid->DestroyTable( m_texts );