diff --git a/eeschema/connection_graph.cpp b/eeschema/connection_graph.cpp index 3f772bad44..7f15327477 100644 --- a/eeschema/connection_graph.cpp +++ b/eeschema/connection_graph.cpp @@ -552,17 +552,20 @@ void CONNECTION_GRAPH::updateItemConnectivity( const SCH_SHEET_PATH& aSheet, for( SCH_PIN* pin : symbol->GetPins( &aSheet ) ) { - pin->InitializeConnection( aSheet, this ); + SCH_CONNECTION* conn = pin->InitializeConnection( aSheet, this ); VECTOR2I pos = pin->GetPosition(); // because calling the first time is not thread-safe - pin->GetDefaultNetName( aSheet ); + wxString name = pin->GetDefaultNetName( aSheet ); pin->ConnectedItems( aSheet ).clear(); // power symbol pins need to be post-processed later if( pin->IsGlobalPower() ) + { + conn->SetName( name ); m_global_power_pins.emplace_back( std::make_pair( aSheet, pin ) ); + } connection_map[ pos ].push_back( pin ); m_items.emplace_back( pin ); @@ -1000,7 +1003,7 @@ void CONNECTION_GRAPH::generateGlobalPowerPinSubGraphs() // in the symbol, but we support legacy non-power symbols with global // power connections based on invisible, power-in, pin's names. if( pin->GetLibPin()->GetParent()->IsPower() ) - connection->SetName( pin->GetParentSymbol()->GetValueFieldText( true ) ); + connection->SetName( pin->GetParentSymbol()->GetValueFieldText( true, &sheet ) ); else connection->SetName( pin->GetShownName() ); diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 1aa2b9b99b..990c992b4c 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -172,12 +172,13 @@ void SCH_FIELD::SetId( int aId ) } -wxString SCH_FIELD::GetShownText( int aDepth, bool aAllowExtraText ) const +wxString SCH_FIELD::GetShownText( const SCH_SHEET_PATH* aPath, int aDepth, + bool aAllowExtraText ) const { std::function symbolResolver = [&]( wxString* token ) -> bool { - return static_cast( m_parent )->ResolveTextVar( token, aDepth + 1 ); + return static_cast( m_parent )->ResolveTextVar( token, aDepth + 1, aPath ); }; std::function sheetResolver = diff --git a/eeschema/sch_field.h b/eeschema/sch_field.h index 7335a4c066..9dc4be5c53 100644 --- a/eeschema/sch_field.h +++ b/eeschema/sch_field.h @@ -126,7 +126,12 @@ public: void SetId( int aId ); - wxString GetShownText( int aDepth = 0, bool aAllowExtraText = true ) const override; + wxString GetShownText( const SCH_SHEET_PATH* aPath, int aDepth = 0, + bool aAllowExtraText = true ) const; + wxString GetShownText( int aDepth = 0, bool aAllowExtraText = true ) const override + { + return GetShownText( nullptr, aDepth, aAllowExtraText ); + } COLOR4D GetFieldColor() const; diff --git a/eeschema/sch_pin.cpp b/eeschema/sch_pin.cpp index b5af371eb0..7c7a7ebdc8 100644 --- a/eeschema/sch_pin.cpp +++ b/eeschema/sch_pin.cpp @@ -274,7 +274,8 @@ wxString SCH_PIN::GetDefaultNetName( const SCH_SHEET_PATH& aPath, bool aForceNoC if( IsGlobalPower() ) { if( GetLibPin()->GetParent()->IsPower() ) - return EscapeString( GetParentSymbol()->GetValueFieldText( true ), CTX_NETNAME ); + return EscapeString( GetParentSymbol()->GetValueFieldText( true, &aPath ), + CTX_NETNAME ); else return EscapeString( m_libPin->GetName(), CTX_NETNAME ); } diff --git a/eeschema/sch_symbol.cpp b/eeschema/sch_symbol.cpp index 713eb1ce76..e7473da2e2 100644 --- a/eeschema/sch_symbol.cpp +++ b/eeschema/sch_symbol.cpp @@ -832,10 +832,10 @@ void SCH_SYMBOL::SetUnitSelection( int aUnitSelection ) } -const wxString SCH_SYMBOL::GetValueFieldText( bool aResolve ) const +const wxString SCH_SYMBOL::GetValueFieldText( bool aResolve, const SCH_SHEET_PATH* aPath ) const { if( aResolve ) - return GetField( VALUE_FIELD )->GetShownText(); + return GetField( VALUE_FIELD )->GetShownText( aPath ); return GetField( VALUE_FIELD )->GetText(); } @@ -1153,7 +1153,7 @@ void SCH_SYMBOL::GetContextualTextVars( wxArrayString* aVars ) const } -bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth ) const +bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth, const SCH_SHEET_PATH* aPath ) const { static wxRegEx operatingPoint( wxT( "^" "OP" @@ -1167,6 +1167,8 @@ bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth ) const if( !schematic ) return false; + SCH_SHEET* sheet = aPath ? aPath->Last() : schematic->CurrentSheet().Last(); + if( operatingPoint.Matches( *token ) ) { wxString port( operatingPoint.GetMatch( *token, 1 ) ); @@ -1309,7 +1311,7 @@ bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth ) const // See if parent can resolve it (this will recurse to ancestors) - if( SCH_SHEET* sheet = schematic->CurrentSheet().Last() ) + if( sheet ) { if( sheet->ResolveTextVar( token, aDepth + 1 ) ) return true; diff --git a/eeschema/sch_symbol.h b/eeschema/sch_symbol.h index f36a06bdc2..7aa4169cbb 100644 --- a/eeschema/sch_symbol.h +++ b/eeschema/sch_symbol.h @@ -327,7 +327,8 @@ public: * * @param aDepth a counter to limit recursion and circular references. */ - bool ResolveTextVar( wxString* token, int aDepth = 0 ) const; + bool ResolveTextVar( wxString* token, int aDepth = 0, + const SCH_SHEET_PATH* aPath = nullptr ) const; void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& aList ) override; @@ -461,7 +462,7 @@ public: m_fields = aFields; // vector copying, length is changed possibly } - const wxString GetValueFieldText( bool aResolve ) const; + const wxString GetValueFieldText( bool aResolve, const SCH_SHEET_PATH* aPath = nullptr ) const; void SetValueFieldText( const wxString& aValue ); const wxString GetFootprintFieldText( bool aResolve ) const;