Clean exposure of CONNECTION_SUBGRAPH

Removes internals from public consumption.
This commit is contained in:
Seth Hillbrand 2023-03-03 14:06:41 -08:00
parent d545216432
commit 48740dd3f8
10 changed files with 83 additions and 42 deletions

View File

@ -81,17 +81,19 @@ public:
m_multiple_drivers( false ), m_multiple_drivers( false ),
m_strong_driver( false ), m_strong_driver( false ),
m_local_driver( false ), m_local_driver( false ),
m_no_connect( nullptr ),
m_bus_entry( nullptr ), m_bus_entry( nullptr ),
m_driver( nullptr ),
m_driver_connection( nullptr ),
m_hier_parent( nullptr ), m_hier_parent( nullptr ),
m_driver( nullptr ),
m_first_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; ~CONNECTION_SUBGRAPH() = default;
friend class CONNECTION_GRAPH;
/** /**
* Determines which potential driver should drive the subgraph. * Determines which potential driver should drive the subgraph.
* *
@ -125,6 +127,12 @@ public:
/// Updates all items to match the driver connection /// Updates all items to match the driver connection
void UpdateItemConnections(); void UpdateItemConnections();
/// Provides a read-only reference to the items in the subgraph
const std::vector<SCH_ITEM*>& GetItems() const
{
return m_items;
}
/** /**
* Return the priority (higher is more important) of a candidate driver * Return the priority (higher is more important) of a candidate driver
* *
@ -149,10 +157,39 @@ public:
return PRIORITY::NONE; 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: private:
wxString driverName( SCH_ITEM* aItem ) const; wxString driverName( SCH_ITEM* aItem ) const;
public:
CONNECTION_GRAPH* m_graph; CONNECTION_GRAPH* m_graph;
bool m_dirty; bool m_dirty;
@ -178,23 +215,11 @@ public:
/// True if the driver is a local (i.e. non-global) type /// True if the driver is a local (i.e. non-global) type
bool m_local_driver; bool m_local_driver;
/// No-connect item in graph, if any
SCH_ITEM* m_no_connect;
/// Bus entry in graph, if any /// Bus entry in graph, if any
SCH_ITEM* m_bus_entry; SCH_ITEM* m_bus_entry;
std::vector<SCH_ITEM*> m_items;
std::vector<SCH_ITEM*> m_drivers; std::vector<SCH_ITEM*> 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 * If a subgraph is a bus, this map contains links between the bus members and any
* local sheet neighbors with the same connection name. * local sheet neighbors with the same connection name.
@ -226,6 +251,9 @@ public:
/// A cache of escaped netnames from schematic items /// A cache of escaped netnames from schematic items
mutable std::unordered_map<SCH_ITEM*, wxString> m_driver_name_cache; mutable std::unordered_map<SCH_ITEM*, wxString> 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 * 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) * 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) /// Used for multiple drivers ERC message; stores the second possible driver (or nullptr)
SCH_ITEM* m_second_driver; SCH_ITEM* m_second_driver;
/// Contents of the subgraph
std::vector<SCH_ITEM*> 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 struct NET_NAME_CODE_CACHE_KEY

View File

@ -207,7 +207,7 @@ void SCH_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
wxString netName = FROM_UTF8( text ); wxString netName = FROM_UTF8( text );
if( auto sg = Schematic().ConnectionGraph()->FindFirstSubgraphByName( netName ) ) if( auto sg = Schematic().ConnectionGraph()->FindFirstSubgraphByName( netName ) )
m_highlightedConn = sg->m_driver_connection; m_highlightedConn = sg->GetDriverConnection();
else else
m_highlightedConn = nullptr; m_highlightedConn = nullptr;

View File

@ -113,7 +113,7 @@ void DIALOG_MIGRATE_BUSES::updateUi()
auto i = m_migration_list->InsertItem( m_migration_list->GetItemCount(), wxEmptyString ); 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, 1, old );
m_migration_list->SetItem( i, 2, item.possible_labels[0] ); m_migration_list->SetItem( i, 2, item.possible_labels[0] );
m_migration_list->SetItem( i, 3, "" ); m_migration_list->SetItem( i, 3, "" );
@ -172,8 +172,8 @@ void DIALOG_MIGRATE_BUSES::onItemSelected( wxListEvent& aEvent )
m_selected_index = sel; m_selected_index = sel;
const CONNECTION_SUBGRAPH* subgraph = m_items[sel].subgraph; const CONNECTION_SUBGRAPH* subgraph = m_items[sel].subgraph;
const SCH_SHEET_PATH& sheet = subgraph->m_sheet; const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
SCH_ITEM* driver = subgraph->m_driver; const SCH_ITEM* driver = subgraph->GetDriver();
if( sheet != m_frame->GetCurrentSheet() ) if( sheet != m_frame->GetCurrentSheet() )
{ {

View File

@ -606,15 +606,15 @@ int ERC_TESTER::TestPinToPin()
for( CONNECTION_SUBGRAPH* subgraph: net.second ) for( CONNECTION_SUBGRAPH* subgraph: net.second )
{ {
if( subgraph->m_no_connect ) if( subgraph->GetNoConnect() )
has_noconnect = true; has_noconnect = true;
for( EDA_ITEM* item : subgraph->m_items ) for( SCH_ITEM* item : subgraph->GetItems() )
{ {
if( item->Type() == SCH_PIN_T ) if( item->Type() == SCH_PIN_T )
{ {
pins.emplace_back( static_cast<SCH_PIN*>( item ), subgraph->m_sheet ); pins.emplace_back( static_cast<SCH_PIN*>( item ), subgraph->GetSheet() );
pinToScreenMap[item] = subgraph->m_sheet.LastScreen(); pinToScreenMap[item] = subgraph->GetSheet().LastScreen();
} }
} }
} }
@ -757,16 +757,17 @@ int ERC_TESTER::TestMultUnitPinConflicts()
for( CONNECTION_SUBGRAPH* subgraph : net.second ) 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 ) if( item->Type() == SCH_PIN_T )
{ {
SCH_PIN* pin = static_cast<SCH_PIN*>( item ); SCH_PIN* pin = static_cast<SCH_PIN*>( item );
const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
if( !pin->GetLibPin()->GetParent()->IsMulti() ) if( !pin->GetLibPin()->GetParent()->IsMulti() )
continue; continue;
wxString name = pin->GetParentSymbol()->GetRef( &subgraph->m_sheet ) + wxString name = pin->GetParentSymbol()->GetRef( &sheet ) +
+ ":" + pin->GetShownNumber(); + ":" + pin->GetShownNumber();
if( !pinToNetMap.count( name ) ) if( !pinToNetMap.count( name ) )
@ -785,12 +786,12 @@ int ERC_TESTER::TestMultUnitPinConflicts()
pinToNetMap[name].first ) ); pinToNetMap[name].first ) );
ercItem->SetItems( pin, pinToNetMap[name].second ); ercItem->SetItems( pin, pinToNetMap[name].second );
ercItem->SetSheetSpecificPath( subgraph->m_sheet ); ercItem->SetSheetSpecificPath( sheet );
ercItem->SetItemsSheetPaths( subgraph->m_sheet, subgraph->m_sheet ); ercItem->SetItemsSheetPaths( sheet, sheet );
SCH_MARKER* marker = new SCH_MARKER( ercItem, SCH_MARKER* marker = new SCH_MARKER( ercItem,
pin->GetTransformedPosition() ); pin->GetTransformedPosition() );
subgraph->m_sheet.LastScreen()->Append( marker ); sheet.LastScreen()->Append( marker );
errors += 1; errors += 1;
} }
} }
@ -814,7 +815,7 @@ int ERC_TESTER::TestSimilarLabels()
{ {
for( CONNECTION_SUBGRAPH* subgraph : net.second ) for( CONNECTION_SUBGRAPH* subgraph : net.second )
{ {
for( EDA_ITEM* item : subgraph->m_items ) for( SCH_ITEM* item : subgraph->GetItems() )
{ {
switch( item->Type() ) switch( item->Type() )
{ {
@ -836,7 +837,7 @@ int ERC_TESTER::TestSimilarLabels()
ercItem->SetItems( label, labelMap.at( normalized ) ); ercItem->SetItems( label, labelMap.at( normalized ) );
SCH_MARKER* marker = new SCH_MARKER( ercItem, label->GetPosition() ); SCH_MARKER* marker = new SCH_MARKER( ercItem, label->GetPosition() );
subgraph->m_sheet.LastScreen()->Append( marker ); subgraph->GetSheet().LastScreen()->Append( marker );
errors += 1; errors += 1;
} }

View File

@ -157,7 +157,7 @@ std::vector<PIN_INFO> NETLIST_EXPORTER_BASE::CreatePinList( SCH_SYMBOL* aSymbol,
{ {
CONNECTION_SUBGRAPH* sg = graph->FindSubgraphByName( netName, *aSheetPath ); 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; continue;
} }
@ -250,7 +250,7 @@ void NETLIST_EXPORTER_BASE::findAllUnitsOfSymbol( SCH_SYMBOL* aSchSymbol,
{ {
CONNECTION_SUBGRAPH* sg = graph->FindSubgraphByName( netName, sheet ); 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; continue;
} }

View File

@ -127,9 +127,9 @@ bool NETLIST_EXPORTER_CADSTAR::writeListOfNets( FILE* f )
for( CONNECTION_SUBGRAPH* subgraph : subgraphs ) 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 ) if( item->Type() == SCH_PIN_T )
sorted_items.emplace_back( static_cast<SCH_PIN*>( item ), sheet ); sorted_items.emplace_back( static_cast<SCH_PIN*>( item ), sheet );

View File

@ -678,13 +678,13 @@ XNODE* NETLIST_EXPORTER_XML::makeListOfNets( unsigned aCtl )
for( CONNECTION_SUBGRAPH* subgraph : subgraphs ) for( CONNECTION_SUBGRAPH* subgraph : subgraphs )
{ {
bool nc = subgraph->m_no_connect && subgraph->m_no_connect->Type() == SCH_NO_CONNECT_T; bool nc = subgraph->GetNoConnect() && subgraph->GetNoConnect()->Type() == SCH_NO_CONNECT_T;
const SCH_SHEET_PATH& sheet = subgraph->m_sheet; const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
if( nc ) if( nc )
net_record->m_HasNoConnect = true; net_record->m_HasNoConnect = true;
for( SCH_ITEM* item : subgraph->m_items ) for( SCH_ITEM* item : subgraph->GetItems() )
{ {
if( item->Type() == SCH_PIN_T ) if( item->Type() == SCH_PIN_T )
{ {

View File

@ -1399,7 +1399,7 @@ void SCH_EDIT_FRAME::RefreshOperatingPointDisplay()
SCH_LINE* longestWire = nullptr; SCH_LINE* longestWire = nullptr;
double length = 0.0; 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 } ) ) if( item->IsType( { SCH_ITEM_LOCATE_WIRE_T } ) )
{ {

View File

@ -311,7 +311,7 @@ std::set<wxString> SCHEMATIC::GetNetClassAssignmentCandidates()
{ {
CONNECTION_SUBGRAPH* firstSubgraph = subgraphList[0]; CONNECTION_SUBGRAPH* firstSubgraph = subgraphList[0];
if( !firstSubgraph->m_driver_connection->IsBus() if( !firstSubgraph->GetDriverConnection()->IsBus()
&& firstSubgraph->GetDriverPriority() >= CONNECTION_SUBGRAPH::PRIORITY::PIN ) && firstSubgraph->GetDriverPriority() >= CONNECTION_SUBGRAPH::PRIORITY::PIN )
{ {
names.insert( key.Name ); names.insert( key.Name );

View File

@ -1053,7 +1053,7 @@ int SCH_EDITOR_CONTROL::UpdateNetHighlighting( const TOOL_EVENT& aEvent )
if( selectedIsNoNet && selectedSubgraph ) if( selectedIsNoNet && selectedSubgraph )
{ {
for( SCH_ITEM* subgraphItem : selectedSubgraph->m_items ) for( SCH_ITEM* subgraphItem : selectedSubgraph->GetItems() )
{ {
if( item == subgraphItem ) if( item == subgraphItem )
{ {