From 48740dd3f83668176c315313fd6b688586e9c298 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Fri, 3 Mar 2023 14:06:41 -0800 Subject: [PATCH] Clean exposure of CONNECTION_SUBGRAPH Removes internals from public consumption. --- eeschema/connection_graph.h | 74 ++++++++++++++----- eeschema/cross-probing.cpp | 2 +- eeschema/dialogs/dialog_migrate_buses.cpp | 6 +- eeschema/erc.cpp | 23 +++--- .../netlist_exporter_base.cpp | 4 +- .../netlist_exporter_cadstar.cpp | 4 +- .../netlist_exporter_xml.cpp | 6 +- eeschema/sch_edit_frame.cpp | 2 +- eeschema/schematic.cpp | 2 +- eeschema/tools/sch_editor_control.cpp | 2 +- 10 files changed, 83 insertions(+), 42 deletions(-) diff --git a/eeschema/connection_graph.h b/eeschema/connection_graph.h index b71eee2705..0d098e5711 100644 --- a/eeschema/connection_graph.h +++ b/eeschema/connection_graph.h @@ -81,17 +81,19 @@ public: m_multiple_drivers( false ), m_strong_driver( false ), m_local_driver( false ), - m_no_connect( nullptr ), m_bus_entry( nullptr ), - m_driver( nullptr ), - m_driver_connection( nullptr ), m_hier_parent( nullptr ), + m_driver( nullptr ), m_first_driver( nullptr ), - m_second_driver( nullptr ) + m_second_driver( nullptr ), + m_no_connect( nullptr ), + m_driver_connection( nullptr ) {} ~CONNECTION_SUBGRAPH() = default; + friend class CONNECTION_GRAPH; + /** * Determines which potential driver should drive the subgraph. * @@ -125,6 +127,12 @@ public: /// Updates all items to match the driver connection void UpdateItemConnections(); + /// Provides a read-only reference to the items in the subgraph + const std::vector& GetItems() const + { + return m_items; + } + /** * Return the priority (higher is more important) of a candidate driver * @@ -149,10 +157,39 @@ public: return PRIORITY::NONE; } + /** + * @return pointer to the SCH_ITEM whose name sets the subgraph netname. + * N.B. This item may not be in the subgraph + */ + const SCH_ITEM* GetDriver() const + { + return m_driver; + } + + /** + * @return SCH_CONNECTION object for m_driver on m_sheet + */ + const SCH_CONNECTION* GetDriverConnection() const + { + return m_driver_connection; + } + + /** + * @return pointer to the item causing a no-connect or nullptr if none + */ + const SCH_ITEM* GetNoConnect() const + { + return m_no_connect; + } + + const SCH_SHEET_PATH& GetSheet() const + { + return m_sheet; + } + private: wxString driverName( SCH_ITEM* aItem ) const; -public: CONNECTION_GRAPH* m_graph; bool m_dirty; @@ -178,23 +215,11 @@ public: /// True if the driver is a local (i.e. non-global) type bool m_local_driver; - /// No-connect item in graph, if any - SCH_ITEM* m_no_connect; - /// Bus entry in graph, if any SCH_ITEM* m_bus_entry; - std::vector m_items; - std::vector m_drivers; - SCH_ITEM* m_driver; - - SCH_SHEET_PATH m_sheet; - - /// Cache for driver connection - SCH_CONNECTION* m_driver_connection; - /** * If a subgraph is a bus, this map contains links between the bus members and any * local sheet neighbors with the same connection name. @@ -226,6 +251,9 @@ public: /// A cache of escaped netnames from schematic items mutable std::unordered_map m_driver_name_cache; + /// Fully-resolved driver for the subgraph (might not exist in this subgraph) + SCH_ITEM* m_driver; + /** * Stores the primary driver for the multiple drivers ERC check. This is the chosen driver * before subgraphs are absorbed (so m_driver may be different) @@ -234,6 +262,18 @@ public: /// Used for multiple drivers ERC message; stores the second possible driver (or nullptr) SCH_ITEM* m_second_driver; + + /// Contents of the subgraph + std::vector m_items; + + /// No-connect item in graph, if any + SCH_ITEM* m_no_connect; + + /// On which logical sheet is the subgraph contained + SCH_SHEET_PATH m_sheet; + + /// Cache for driver connection + SCH_CONNECTION* m_driver_connection; }; struct NET_NAME_CODE_CACHE_KEY diff --git a/eeschema/cross-probing.cpp b/eeschema/cross-probing.cpp index 99d74d110a..b37bd61c0b 100644 --- a/eeschema/cross-probing.cpp +++ b/eeschema/cross-probing.cpp @@ -207,7 +207,7 @@ void SCH_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline ) wxString netName = FROM_UTF8( text ); if( auto sg = Schematic().ConnectionGraph()->FindFirstSubgraphByName( netName ) ) - m_highlightedConn = sg->m_driver_connection; + m_highlightedConn = sg->GetDriverConnection(); else m_highlightedConn = nullptr; diff --git a/eeschema/dialogs/dialog_migrate_buses.cpp b/eeschema/dialogs/dialog_migrate_buses.cpp index 47da63ca01..610c80140d 100644 --- a/eeschema/dialogs/dialog_migrate_buses.cpp +++ b/eeschema/dialogs/dialog_migrate_buses.cpp @@ -113,7 +113,7 @@ void DIALOG_MIGRATE_BUSES::updateUi() auto i = m_migration_list->InsertItem( m_migration_list->GetItemCount(), wxEmptyString ); - m_migration_list->SetItem( i, 0, item.subgraph->m_sheet.PathHumanReadable() ); + m_migration_list->SetItem( i, 0, item.subgraph->GetSheet().PathHumanReadable() ); m_migration_list->SetItem( i, 1, old ); m_migration_list->SetItem( i, 2, item.possible_labels[0] ); m_migration_list->SetItem( i, 3, "" ); @@ -172,8 +172,8 @@ void DIALOG_MIGRATE_BUSES::onItemSelected( wxListEvent& aEvent ) m_selected_index = sel; const CONNECTION_SUBGRAPH* subgraph = m_items[sel].subgraph; - const SCH_SHEET_PATH& sheet = subgraph->m_sheet; - SCH_ITEM* driver = subgraph->m_driver; + const SCH_SHEET_PATH& sheet = subgraph->GetSheet(); + const SCH_ITEM* driver = subgraph->GetDriver(); if( sheet != m_frame->GetCurrentSheet() ) { diff --git a/eeschema/erc.cpp b/eeschema/erc.cpp index 9f39d7fb0e..a2a1b0cc5d 100644 --- a/eeschema/erc.cpp +++ b/eeschema/erc.cpp @@ -606,15 +606,15 @@ int ERC_TESTER::TestPinToPin() for( CONNECTION_SUBGRAPH* subgraph: net.second ) { - if( subgraph->m_no_connect ) + if( subgraph->GetNoConnect() ) has_noconnect = true; - for( EDA_ITEM* item : subgraph->m_items ) + for( SCH_ITEM* item : subgraph->GetItems() ) { if( item->Type() == SCH_PIN_T ) { - pins.emplace_back( static_cast( item ), subgraph->m_sheet ); - pinToScreenMap[item] = subgraph->m_sheet.LastScreen(); + pins.emplace_back( static_cast( item ), subgraph->GetSheet() ); + pinToScreenMap[item] = subgraph->GetSheet().LastScreen(); } } } @@ -757,16 +757,17 @@ int ERC_TESTER::TestMultUnitPinConflicts() for( CONNECTION_SUBGRAPH* subgraph : net.second ) { - for( EDA_ITEM* item : subgraph->m_items ) + for( SCH_ITEM* item : subgraph->GetItems() ) { if( item->Type() == SCH_PIN_T ) { SCH_PIN* pin = static_cast( item ); + const SCH_SHEET_PATH& sheet = subgraph->GetSheet(); if( !pin->GetLibPin()->GetParent()->IsMulti() ) continue; - wxString name = pin->GetParentSymbol()->GetRef( &subgraph->m_sheet ) + + wxString name = pin->GetParentSymbol()->GetRef( &sheet ) + + ":" + pin->GetShownNumber(); if( !pinToNetMap.count( name ) ) @@ -785,12 +786,12 @@ int ERC_TESTER::TestMultUnitPinConflicts() pinToNetMap[name].first ) ); ercItem->SetItems( pin, pinToNetMap[name].second ); - ercItem->SetSheetSpecificPath( subgraph->m_sheet ); - ercItem->SetItemsSheetPaths( subgraph->m_sheet, subgraph->m_sheet ); + ercItem->SetSheetSpecificPath( sheet ); + ercItem->SetItemsSheetPaths( sheet, sheet ); SCH_MARKER* marker = new SCH_MARKER( ercItem, pin->GetTransformedPosition() ); - subgraph->m_sheet.LastScreen()->Append( marker ); + sheet.LastScreen()->Append( marker ); errors += 1; } } @@ -814,7 +815,7 @@ int ERC_TESTER::TestSimilarLabels() { for( CONNECTION_SUBGRAPH* subgraph : net.second ) { - for( EDA_ITEM* item : subgraph->m_items ) + for( SCH_ITEM* item : subgraph->GetItems() ) { switch( item->Type() ) { @@ -836,7 +837,7 @@ int ERC_TESTER::TestSimilarLabels() ercItem->SetItems( label, labelMap.at( normalized ) ); SCH_MARKER* marker = new SCH_MARKER( ercItem, label->GetPosition() ); - subgraph->m_sheet.LastScreen()->Append( marker ); + subgraph->GetSheet().LastScreen()->Append( marker ); errors += 1; } diff --git a/eeschema/netlist_exporters/netlist_exporter_base.cpp b/eeschema/netlist_exporters/netlist_exporter_base.cpp index b558b54911..fec19d9ddb 100644 --- a/eeschema/netlist_exporters/netlist_exporter_base.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_base.cpp @@ -157,7 +157,7 @@ std::vector NETLIST_EXPORTER_BASE::CreatePinList( SCH_SYMBOL* aSymbol, { CONNECTION_SUBGRAPH* sg = graph->FindSubgraphByName( netName, *aSheetPath ); - if( !sg || sg->m_no_connect || sg->m_items.size() < 2 ) + if( !sg || sg->GetNoConnect() || sg->GetItems().size() < 2 ) continue; } @@ -250,7 +250,7 @@ void NETLIST_EXPORTER_BASE::findAllUnitsOfSymbol( SCH_SYMBOL* aSchSymbol, { CONNECTION_SUBGRAPH* sg = graph->FindSubgraphByName( netName, sheet ); - if( !sg || sg->m_no_connect || sg->m_items.size() < 2 ) + if( !sg || sg->GetNoConnect() || sg->GetItems().size() < 2 ) continue; } diff --git a/eeschema/netlist_exporters/netlist_exporter_cadstar.cpp b/eeschema/netlist_exporters/netlist_exporter_cadstar.cpp index 8f43d49c7d..1d126e3641 100644 --- a/eeschema/netlist_exporters/netlist_exporter_cadstar.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_cadstar.cpp @@ -127,9 +127,9 @@ bool NETLIST_EXPORTER_CADSTAR::writeListOfNets( FILE* f ) for( CONNECTION_SUBGRAPH* subgraph : subgraphs ) { - SCH_SHEET_PATH sheet = subgraph->m_sheet; + SCH_SHEET_PATH sheet = subgraph->GetSheet(); - for( SCH_ITEM* item : subgraph->m_items ) + for( SCH_ITEM* item : subgraph->GetItems() ) { if( item->Type() == SCH_PIN_T ) sorted_items.emplace_back( static_cast( item ), sheet ); diff --git a/eeschema/netlist_exporters/netlist_exporter_xml.cpp b/eeschema/netlist_exporters/netlist_exporter_xml.cpp index 87cae7e6fd..0b09b8f605 100644 --- a/eeschema/netlist_exporters/netlist_exporter_xml.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_xml.cpp @@ -678,13 +678,13 @@ XNODE* NETLIST_EXPORTER_XML::makeListOfNets( unsigned aCtl ) for( CONNECTION_SUBGRAPH* subgraph : subgraphs ) { - bool nc = subgraph->m_no_connect && subgraph->m_no_connect->Type() == SCH_NO_CONNECT_T; - const SCH_SHEET_PATH& sheet = subgraph->m_sheet; + bool nc = subgraph->GetNoConnect() && subgraph->GetNoConnect()->Type() == SCH_NO_CONNECT_T; + const SCH_SHEET_PATH& sheet = subgraph->GetSheet(); if( nc ) net_record->m_HasNoConnect = true; - for( SCH_ITEM* item : subgraph->m_items ) + for( SCH_ITEM* item : subgraph->GetItems() ) { if( item->Type() == SCH_PIN_T ) { diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 8b15fcb754..b99e138b31 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -1399,7 +1399,7 @@ void SCH_EDIT_FRAME::RefreshOperatingPointDisplay() SCH_LINE* longestWire = nullptr; double length = 0.0; - for( SCH_ITEM* item : subgraph->m_items ) + for( SCH_ITEM* item : subgraph->GetItems() ) { if( item->IsType( { SCH_ITEM_LOCATE_WIRE_T } ) ) { diff --git a/eeschema/schematic.cpp b/eeschema/schematic.cpp index a09041d1c3..367d28599e 100644 --- a/eeschema/schematic.cpp +++ b/eeschema/schematic.cpp @@ -311,7 +311,7 @@ std::set SCHEMATIC::GetNetClassAssignmentCandidates() { CONNECTION_SUBGRAPH* firstSubgraph = subgraphList[0]; - if( !firstSubgraph->m_driver_connection->IsBus() + if( !firstSubgraph->GetDriverConnection()->IsBus() && firstSubgraph->GetDriverPriority() >= CONNECTION_SUBGRAPH::PRIORITY::PIN ) { names.insert( key.Name ); diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 4d035b1979..0e55460950 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -1053,7 +1053,7 @@ int SCH_EDITOR_CONTROL::UpdateNetHighlighting( const TOOL_EVENT& aEvent ) if( selectedIsNoNet && selectedSubgraph ) { - for( SCH_ITEM* subgraphItem : selectedSubgraph->m_items ) + for( SCH_ITEM* subgraphItem : selectedSubgraph->GetItems() ) { if( item == subgraphItem ) {