From a9c4534a38c1de3308807fa1a8ad3a99a168772c Mon Sep 17 00:00:00 2001 From: Mike Williams Date: Sun, 20 Aug 2023 16:13:07 -0400 Subject: [PATCH] Schematic/Fields Table: handle sheet changes --- .../dialogs/dialog_symbol_fields_table.cpp | 9 ++++++++ eeschema/dialogs/dialog_symbol_fields_table.h | 2 ++ eeschema/sch_edit_frame.cpp | 2 ++ eeschema/schematic.cpp | 20 +++++++++++------ eeschema/schematic.h | 22 ++++++++++++++----- 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/eeschema/dialogs/dialog_symbol_fields_table.cpp b/eeschema/dialogs/dialog_symbol_fields_table.cpp index 69adec59ae..10cfdd4fd9 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table.cpp +++ b/eeschema/dialogs/dialog_symbol_fields_table.cpp @@ -2113,6 +2113,15 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnSchItemsChanged( SCHEMATIC& aSch } +void DIALOG_SYMBOL_FIELDS_TABLE::OnSchSheetChanged( SCHEMATIC& aSch ) +{ + m_dataModel->SetPath( aSch.CurrentSheet() ); + + if( m_dataModel->GetScope() != FIELDS_EDITOR_GRID_DATA_MODEL::SCOPE::SCOPE_ALL ) + m_dataModel->RebuildRows(); +} + + SCH_REFERENCE_LIST DIALOG_SYMBOL_FIELDS_TABLE::getSymbolReferences( SCH_SYMBOL* aSymbol ) { SCH_SHEET_LIST allSheets = m_parent->Schematic().GetSheets(); diff --git a/eeschema/dialogs/dialog_symbol_fields_table.h b/eeschema/dialogs/dialog_symbol_fields_table.h index c54ccc766c..37fb29d4ef 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table.h +++ b/eeschema/dialogs/dialog_symbol_fields_table.h @@ -105,9 +105,11 @@ private: void ApplyBomFmtPreset( const wxString& aPresetName ); void ApplyBomFmtPreset( const BOM_FMT_PRESET& aPreset ); + // Schematic listener event handlers void OnSchItemsAdded( SCHEMATIC& aSch, std::vector& aSchItem ) override; void OnSchItemsRemoved( SCHEMATIC& aSch, std::vector& aSchItem ) override; void OnSchItemsChanged( SCHEMATIC& aSch, std::vector& aSchItem ) override; + void OnSchSheetChanged( SCHEMATIC& aSch ) override; private: SCH_REFERENCE_LIST getSymbolReferences( SCH_SYMBOL* aSymbol ); diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 91de3ed983..92354cc1cc 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -2191,6 +2191,8 @@ void SCH_EDIT_FRAME::DisplayCurrentSheet() editTool->UpdateNetHighlighting( dummy ); m_hierarchy->UpdateHierarchySelection(); + + m_schematic->OnSchSheetChanged(); } diff --git a/eeschema/schematic.cpp b/eeschema/schematic.cpp index 5167fad172..64e1e218fa 100644 --- a/eeschema/schematic.cpp +++ b/eeschema/schematic.cpp @@ -691,6 +691,18 @@ void SCHEMATIC::OnItemsRemoved( std::vector& aRemovedItems ) } +void SCHEMATIC::OnItemsChanged( std::vector& aItems ) +{ + InvokeListeners( &SCHEMATIC_LISTENER::OnSchItemsChanged, *this, aItems ); +} + + +void SCHEMATIC::OnSchSheetChanged() +{ + InvokeListeners( &SCHEMATIC_LISTENER::OnSchSheetChanged, *this ); +} + + void SCHEMATIC::AddListener( SCHEMATIC_LISTENER* aListener ) { if( !alg::contains( m_listeners, aListener ) ) @@ -716,12 +728,6 @@ void SCHEMATIC::RemoveAllListeners() } -void SCHEMATIC::OnItemsChanged( std::vector& aItems ) -{ - InvokeListeners( &SCHEMATIC_LISTENER::OnSchItemsChanged, *this, aItems ); -} - - void SCHEMATIC::RecordERCExclusions() { SCH_SHEET_LIST sheetList = GetSheets(); @@ -756,4 +762,4 @@ void SCHEMATIC::ResolveERCExclusionsPostUpdate() else RootScreen()->Append( marker ); } -} \ No newline at end of file +} diff --git a/eeschema/schematic.h b/eeschema/schematic.h index e5f756e539..718d91c703 100644 --- a/eeschema/schematic.h +++ b/eeschema/schematic.h @@ -59,6 +59,9 @@ public: virtual void OnSchItemsAdded( SCHEMATIC& aSch, std::vector& aSchItem ) {} virtual void OnSchItemsRemoved( SCHEMATIC& aSch, std::vector& aSchItem ) {} virtual void OnSchItemsChanged( SCHEMATIC& aSch, std::vector& aSchItem ) {} + // This is called when the user changes to a new sheet, not when a sheet is altered. + // Sheet alteration events will call OnSchItems* + virtual void OnSchSheetChanged( SCHEMATIC& aSch ) {} }; /** @@ -261,6 +264,19 @@ public: */ void OnItemsRemoved( std::vector& aRemovedItems ); + /** + * Notify the schematic and its listeners that an item on the schematic has + * been modified in some way. + */ + void OnItemsChanged( std::vector& aItems ); + + /** + * Notify the schematic and its listeners that the current sheet has been changed. + * This is called when the user navigates to a different sheet, not when the sheet is + * altered. + */ + void OnSchSheetChanged(); + /** * Add a listener to the schematic to receive calls whenever something on the * schematic has been modified. The schematic does not take ownership of the @@ -282,12 +298,6 @@ public: */ void RemoveAllListeners(); - /** - * Notify the schematic and its listeners that an item on the schematic has - * been modified in some way. - */ - void OnItemsChanged( std::vector& aItems ); - #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ) const override {} #endif