diff --git a/eeschema/connection_graph.cpp b/eeschema/connection_graph.cpp index 8c4864fb9d..6408cf30a6 100644 --- a/eeschema/connection_graph.cpp +++ b/eeschema/connection_graph.cpp @@ -143,26 +143,18 @@ bool CONNECTION_SUBGRAPH::ResolveDrivers( bool aCreateMarkers ) } // For power connections, we allow multiple drivers - if( highest_priority == 5 && candidates.size() > 1 && - candidates[0]->Type() == SCH_PIN_T ) - { - auto pin = static_cast( candidates[0] ); + if( highest_priority >= 4 && candidates.size() > 1 ) + m_multiple_drivers = true; - wxASSERT( pin->IsPowerConnection() ); - - m_multiple_power_ports = true; - } - - if( aCreateMarkers && !m_multiple_power_ports && - candidates.size() > 1 && highest_priority > 1 ) + if( aCreateMarkers && m_multiple_drivers ) { // First check if all the candidates are actually the same bool same = true; - auto first = candidates[0]->Connection( m_sheet )->Name(); + auto first = GetNameForDriver( candidates[0] ); for( unsigned i = 1; i < candidates.size(); i++ ) { - if( candidates[i]->Connection( m_sheet )->Name() != first ) + if( GetNameForDriver( candidates[i] ) != first ) { same = false; break; @@ -249,6 +241,39 @@ std::vector CONNECTION_SUBGRAPH::GetBusLabels() } +wxString CONNECTION_SUBGRAPH::GetNameForDriver( SCH_ITEM* aItem ) +{ + wxString name; + + switch( aItem->Type() ) + { + case SCH_PIN_T: + { + auto power_object = static_cast( aItem ); + name = power_object->GetDefaultNetName( m_sheet ); + break; + } + + case SCH_LABEL_T: + case SCH_GLOBAL_LABEL_T: + { + auto label = static_cast( aItem ); + + SCH_CONNECTION conn; + conn.ConfigureFromLabel( label->GetText() ); + + name = conn.Name(); + break; + } + + default: + break; + } + + return name; +}; + + void CONNECTION_GRAPH::Reset() { for( auto sg : m_subgraphs ) @@ -1032,25 +1057,20 @@ void CONNECTION_GRAPH::buildConnectionGraph() // Collapse power nets that are shorted together - if( subgraph->m_multiple_power_ports ) + if( subgraph->m_multiple_drivers ) { for( auto obj : subgraph->m_drivers ) { if( obj == subgraph->m_driver ) continue; - auto power_object = dynamic_cast( obj ); - - // Skip drivers that aren't power ports - if( !power_object ) - continue; - - auto name = power_object->GetDefaultNetName( subgraph->m_sheet ); - int code = -1; + wxString name = subgraph->GetNameForDriver( obj ); if( m_net_name_to_code_map.count( name ) == 0 ) continue; + int code = m_net_name_to_code_map.at( name ); + for( auto subgraph_to_update : m_subgraphs ) { if( !subgraph_to_update->m_driver ) diff --git a/eeschema/connection_graph.h b/eeschema/connection_graph.h index 28d10cf7c1..72408b2c9a 100644 --- a/eeschema/connection_graph.h +++ b/eeschema/connection_graph.h @@ -61,7 +61,7 @@ class CONNECTION_SUBGRAPH { public: CONNECTION_SUBGRAPH( SCH_EDIT_FRAME* aFrame ) : - m_dirty( false ), m_code( -1 ), m_multiple_power_ports( false ), + m_dirty( false ), m_code( -1 ), m_multiple_drivers( false ), m_strong_driver( false ), m_no_connect( nullptr ), m_bus_entry( nullptr ), m_driver( nullptr ), m_frame( aFrame ), m_driver_connection( nullptr ) {} @@ -84,12 +84,19 @@ public: /// Returns all the bus labels attached to this subgraph (if any) std::vector GetBusLabels(); + // Returns the candidate net name for a driver + wxString GetNameForDriver( SCH_ITEM* aItem ); + bool m_dirty; long m_code; - /// True if this subgraph contains multiple power ports to join in one net - bool m_multiple_power_ports; + /** + * True if this subgraph contains more than one driver that should be + * shorted together in the netlist. For example, two labels or + * two power ports. + */ + bool m_multiple_drivers; /// True if the driver is "strong": a label or power object bool m_strong_driver;