From fe32492252ba19687cdefcc71b5e797e72d20461 Mon Sep 17 00:00:00 2001 From: Mike Williams Date: Mon, 7 Aug 2023 15:04:46 -0400 Subject: [PATCH] Symbol Fields Table: scope control for limited view of symbols --- .../dialogs/dialog_symbol_fields_table.cpp | 18 ++++- eeschema/dialogs/dialog_symbol_fields_table.h | 2 + .../dialog_symbol_fields_table_base.cpp | 8 +++ .../dialog_symbol_fields_table_base.fbp | 67 +++++++++++++++++++ .../dialogs/dialog_symbol_fields_table_base.h | 2 + eeschema/eeschema_settings.cpp | 2 + eeschema/eeschema_settings.h | 1 + eeschema/fields_data_model.cpp | 9 +++ eeschema/fields_data_model.h | 19 +++++- 9 files changed, 124 insertions(+), 4 deletions(-) diff --git a/eeschema/dialogs/dialog_symbol_fields_table.cpp b/eeschema/dialogs/dialog_symbol_fields_table.cpp index 55da4ffbb7..94b1d7aa79 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table.cpp +++ b/eeschema/dialogs/dialog_symbol_fields_table.cpp @@ -264,9 +264,8 @@ DIALOG_SYMBOL_FIELDS_TABLE::DIALOG_SYMBOL_FIELDS_TABLE( SCH_EDIT_FRAME* parent ) ApplyBomFmtPreset( m_schSettings.m_BomFmtSettings ); syncBomFmtPresetSelection(); - m_grid->SelectRow( 0 ); - m_grid->SetGridCursor( 0, 1 ); SetInitialFocus( m_grid ); + m_grid->ClearSelection(); SetupStandardButtons(); @@ -281,6 +280,7 @@ DIALOG_SYMBOL_FIELDS_TABLE::DIALOG_SYMBOL_FIELDS_TABLE( SCH_EDIT_FRAME* parent ) m_nbPages->SetSelection( cfg->m_FieldEditorPanel.page ); m_radioSelect->SetSelection( cfg->m_FieldEditorPanel.selection_mode ); + m_radioScope->SetSelection( cfg->m_FieldEditorPanel.scope ); m_outputFileName->SetValue( cfg->m_FieldEditorPanel.export_filename ); @@ -423,6 +423,7 @@ DIALOG_SYMBOL_FIELDS_TABLE::~DIALOG_SYMBOL_FIELDS_TABLE() cfg->m_FieldEditorPanel.page = m_nbPages->GetSelection(); cfg->m_FieldEditorPanel.export_filename = m_outputFileName->GetValue(); cfg->m_FieldEditorPanel.selection_mode = m_radioSelect->GetSelection(); + cfg->m_FieldEditorPanel.scope = m_radioScope->GetSelection(); for( int i = 0; i < m_grid->GetNumberCols(); i++ ) @@ -493,6 +494,8 @@ bool DIALOG_SYMBOL_FIELDS_TABLE::TransferDataToWindow() } } + UpdateScope(); + return true; } @@ -961,6 +964,17 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnRegroupSymbols( wxCommandEvent& aEvent ) m_grid->ForceRefresh(); } +void DIALOG_SYMBOL_FIELDS_TABLE::OnScopeChanged( wxCommandEvent& aEvent ) +{ + UpdateScope(); +} + +void DIALOG_SYMBOL_FIELDS_TABLE::UpdateScope() +{ + m_dataModel->SetPath( m_parent->GetCurrentSheet() ); + m_dataModel->SetScope( (FIELDS_EDITOR_GRID_DATA_MODEL::SCOPE) m_radioScope->GetSelection() ); + m_dataModel->RebuildRows(); +} void DIALOG_SYMBOL_FIELDS_TABLE::OnTableCellClick( wxGridEvent& event ) { diff --git a/eeschema/dialogs/dialog_symbol_fields_table.h b/eeschema/dialogs/dialog_symbol_fields_table.h index 4db936fb0a..b142606992 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table.h +++ b/eeschema/dialogs/dialog_symbol_fields_table.h @@ -67,6 +67,8 @@ private: void OnGroupSymbolsToggled( wxCommandEvent& event ) override; void OnExcludeDNPToggled( wxCommandEvent& event ) override; void OnRegroupSymbols( wxCommandEvent& aEvent ) override; + void OnScopeChanged( wxCommandEvent& aEvent ) override; + void UpdateScope(); void OnTableValueChanged( wxGridEvent& event ) override; void OnTableCellClick( wxGridEvent& event ) override; void OnTableItemContextMenu( wxGridEvent& event ) override; diff --git a/eeschema/dialogs/dialog_symbol_fields_table_base.cpp b/eeschema/dialogs/dialog_symbol_fields_table_base.cpp index 0e82715fa1..fefdab58b3 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table_base.cpp +++ b/eeschema/dialogs/dialog_symbol_fields_table_base.cpp @@ -128,6 +128,12 @@ DIALOG_SYMBOL_FIELDS_TABLE_BASE::DIALOG_SYMBOL_FIELDS_TABLE_BASE( wxWindow* pare m_radioSelect->SetSelection( 0 ); bControls1->Add( m_radioSelect, 0, wxALL, 5 ); + wxString m_radioScopeChoices[] = { _("Entire Project"), _("Current sheet only"), _("Recursive") }; + int m_radioScopeNChoices = sizeof( m_radioScopeChoices ) / sizeof( wxString ); + m_radioScope = new wxRadioBox( m_rightPanel, wxID_ANY, _("Scope"), wxDefaultPosition, wxDefaultSize, m_radioScopeNChoices, m_radioScopeChoices, 3, wxRA_SPECIFY_COLS ); + m_radioScope->SetSelection( 0 ); + bControls1->Add( m_radioScope, 0, wxALL, 5 ); + bRightSizer->Add( bControls1, 0, wxEXPAND|wxLEFT, 5 ); @@ -336,6 +342,7 @@ DIALOG_SYMBOL_FIELDS_TABLE_BASE::DIALOG_SYMBOL_FIELDS_TABLE_BASE( wxWindow* pare m_checkExcludeDNP->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnExcludeDNPToggled ), NULL, this ); m_groupSymbolsBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnGroupSymbolsToggled ), NULL, this ); m_bRefresh->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnRegroupSymbols ), NULL, this ); + m_radioScope->Connect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnScopeChanged ), NULL, this ); m_grid->Connect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnTableValueChanged ), NULL, this ); m_grid->Connect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnTableCellClick ), NULL, this ); m_grid->Connect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnTableCellClick ), NULL, this ); @@ -370,6 +377,7 @@ DIALOG_SYMBOL_FIELDS_TABLE_BASE::~DIALOG_SYMBOL_FIELDS_TABLE_BASE() m_checkExcludeDNP->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnExcludeDNPToggled ), NULL, this ); m_groupSymbolsBox->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnGroupSymbolsToggled ), NULL, this ); m_bRefresh->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnRegroupSymbols ), NULL, this ); + m_radioScope->Disconnect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnScopeChanged ), NULL, this ); m_grid->Disconnect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnTableValueChanged ), NULL, this ); m_grid->Disconnect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnTableCellClick ), NULL, this ); m_grid->Disconnect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnTableCellClick ), NULL, this ); diff --git a/eeschema/dialogs/dialog_symbol_fields_table_base.fbp b/eeschema/dialogs/dialog_symbol_fields_table_base.fbp index b4c025952b..055662cf9f 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table_base.fbp +++ b/eeschema/dialogs/dialog_symbol_fields_table_base.fbp @@ -1333,6 +1333,73 @@ + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + "Entire Project" "Current sheet only" "Recursive" + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Scope + 3 + + 0 + + + 0 + + 1 + m_radioScope + 1 + + + protected + 1 + + Resizable + 0 + 1 + + wxRA_SPECIFY_COLS + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + OnScopeChanged + + diff --git a/eeschema/dialogs/dialog_symbol_fields_table_base.h b/eeschema/dialogs/dialog_symbol_fields_table_base.h index 532ed3ed11..92e899adf2 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table_base.h +++ b/eeschema/dialogs/dialog_symbol_fields_table_base.h @@ -70,6 +70,7 @@ class DIALOG_SYMBOL_FIELDS_TABLE_BASE : public DIALOG_SHIM BITMAP_BUTTON* m_separator3; wxBitmapButton* m_bRefresh; wxRadioBox* m_radioSelect; + wxRadioBox* m_radioScope; WX_GRID* m_grid; wxPanel* m_panelExport; wxStaticText* m_labelBomExportPresets; @@ -112,6 +113,7 @@ class DIALOG_SYMBOL_FIELDS_TABLE_BASE : public DIALOG_SHIM virtual void OnExcludeDNPToggled( wxCommandEvent& event ) { event.Skip(); } virtual void OnGroupSymbolsToggled( wxCommandEvent& event ) { event.Skip(); } virtual void OnRegroupSymbols( wxCommandEvent& event ) { event.Skip(); } + virtual void OnScopeChanged( wxCommandEvent& event ) { event.Skip(); } virtual void OnTableValueChanged( wxGridEvent& event ) { event.Skip(); } virtual void OnTableCellClick( wxGridEvent& event ) { event.Skip(); } virtual void OnTableItemContextMenu( wxGridEvent& event ) { event.Skip(); } diff --git a/eeschema/eeschema_settings.cpp b/eeschema/eeschema_settings.cpp index 4880006b58..c834a4072c 100644 --- a/eeschema/eeschema_settings.cpp +++ b/eeschema/eeschema_settings.cpp @@ -462,6 +462,8 @@ EESCHEMA_SETTINGS::EESCHEMA_SETTINGS() : m_params.emplace_back( new PARAM( "field_editor.selection_mode", &m_FieldEditorPanel.selection_mode, 0 ) ); + m_params.emplace_back( new PARAM( "field_editor.scope", &m_FieldEditorPanel.scope, 0 ) ); + m_params.emplace_back( new PARAM( "plot.background_color", &m_PlotPanel.background_color, false ) ); diff --git a/eeschema/eeschema_settings.h b/eeschema/eeschema_settings.h index 4d31b0775f..4388304a18 100644 --- a/eeschema/eeschema_settings.h +++ b/eeschema/eeschema_settings.h @@ -221,6 +221,7 @@ public: int page; wxString export_filename; int selection_mode; + int scope; }; struct PANEL_LIB_VIEW diff --git a/eeschema/fields_data_model.cpp b/eeschema/fields_data_model.cpp index 9fee6c3993..08aa0bf685 100644 --- a/eeschema/fields_data_model.cpp +++ b/eeschema/fields_data_model.cpp @@ -492,6 +492,15 @@ void FIELDS_EDITOR_GRID_DATA_MODEL::RebuildRows() if( !m_includeExcluded && ref.GetSymbol()->GetExcludedFromBOM() ) continue; + // Check if the symbol if on the current sheet or, in the sheet path somewhere + // depending on scope + if( ( m_scope == SCOPE::SCOPE_SHEET && ref.GetSheetPath() != m_path ) + || ( m_scope == SCOPE::SCOPE_SHEET_RECURSIVE + && !ref.GetSheetPath().IsContainedWithin( m_path ) ) ) + { + continue; + } + bool matchFound = false; // Performance optimization for ungrouped case to skip the N^2 for loop diff --git a/eeschema/fields_data_model.h b/eeschema/fields_data_model.h index 1072ea721f..c86b8ec6c6 100644 --- a/eeschema/fields_data_model.h +++ b/eeschema/fields_data_model.h @@ -51,10 +51,17 @@ struct DATA_MODEL_COL class FIELDS_EDITOR_GRID_DATA_MODEL : public wxGridTableBase { public: + enum SCOPE : int + { + SCOPE_ALL = 0, + SCOPE_SHEET = 1, + SCOPE_SHEET_RECURSIVE = 2 + }; + FIELDS_EDITOR_GRID_DATA_MODEL( SCH_REFERENCE_LIST& aSymbolsList ) : m_symbolsList( aSymbolsList ), m_edited( false ), m_sortColumn( 0 ), - m_sortAscending( false ), m_groupingEnabled( false ), m_excludeDNP( false ), - m_includeExcluded( false ), m_rebuildsEnabled( true ) + m_sortAscending( false ), m_scope( SCOPE_ALL ), m_groupingEnabled( false ), + m_excludeDNP( false ), m_includeExcluded( false ), m_rebuildsEnabled( true ) { m_symbolsList.SplitReferences(); } @@ -158,6 +165,12 @@ public: void SetFilter( const wxString& aFilter ) { m_filter = aFilter; } const wxString& GetFilter() { return m_filter; } + void SetScope( SCOPE aScope ) { m_scope = aScope; } + SCOPE GetScope() { return m_scope; } + + void SetPath( const SCH_SHEET_PATH& aPath ) { m_path = aPath; } + const SCH_SHEET_PATH& GetPath() { return m_path; } + void SetGroupingEnabled( bool group ) { m_groupingEnabled = group; } bool GetGroupingEnabled() { return m_groupingEnabled; } @@ -225,6 +238,8 @@ protected: int m_sortColumn; bool m_sortAscending; wxString m_filter; + enum SCOPE m_scope; + SCH_SHEET_PATH m_path; bool m_groupingEnabled; bool m_excludeDNP; bool m_includeExcluded;