Allow the current sheet a chance to resolve text variables.

Fixes https://gitlab.com/kicad/code/kicad/issues/8692
This commit is contained in:
Jeff Young 2022-09-08 14:09:33 +01:00
parent a619ef9d53
commit 9bed145475
3 changed files with 52 additions and 62 deletions

View File

@ -502,12 +502,7 @@ bool SCH_LABEL_BASE::ResolveTextVar( wxString* token, int aDepth ) const
*token = wxEmptyString; *token = wxEmptyString;
if( connection ) if( connection )
{ *token = GetEffectiveNetClass()->GetName();
PROJECT_FILE& projectFile = Schematic()->Prj().GetProjectFile();
std::shared_ptr<NET_SETTINGS>& netSettings = projectFile.NetSettings();
*token = UnescapeString( netSettings->GetEffectiveNetClass( connection->Name() )->GetName() );
}
return true; return true;
} }
@ -528,6 +523,11 @@ bool SCH_LABEL_BASE::ResolveTextVar( wxString* token, int aDepth ) const
if( sheet->ResolveTextVar( token, aDepth ) ) if( sheet->ResolveTextVar( token, aDepth ) )
return true; return true;
} }
else if( SCH_SHEET* sheet = Schematic()->CurrentSheet().Last() )
{
if( sheet->ResolveTextVar( token, aDepth ) )
return true;
}
return false; return false;
} }
@ -914,23 +914,18 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground ) const
for( const SCH_FIELD& field : m_fields ) for( const SCH_FIELD& field : m_fields )
field.Plot( aPlotter, aBackground ); field.Plot( aPlotter, aBackground );
if( !m_fields.empty() ) // Plot attributes to a hypertext menu
{
std::vector<wxString> properties; std::vector<wxString> properties;
if( schematic && connection ) if( connection )
{ {
auto& netSettings = schematic->Prj().GetProjectFile().m_NetSettings;
wxString netName = connection->Name();
wxString className = netSettings->GetEffectiveNetClass( netName )->GetName();
properties.emplace_back( wxString::Format( wxT( "!%s = %s" ), properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
_( "Net" ), _( "Net" ),
UnescapeString( netName ) ) ); connection->Name() ) );
properties.emplace_back( wxString::Format( wxT( "!%s = %s" ), properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
_( "Resolved netclass" ), _( "Resolved netclass" ),
UnescapeString( className ) ) ); GetEffectiveNetClass()->GetName() ) );
} }
for( const SCH_FIELD& field : GetFields() ) for( const SCH_FIELD& field : GetFields() )
@ -940,9 +935,9 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground ) const
field.GetShownText() ) ); field.GetShownText() ) );
} }
if( !properties.empty() )
aPlotter->HyperlinkMenu( GetBodyBoundingBox(), properties ); aPlotter->HyperlinkMenu( GetBodyBoundingBox(), properties );
} }
}
void SCH_LABEL_BASE::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) void SCH_LABEL_BASE::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )

View File

@ -839,8 +839,7 @@ void SCH_LINE::Plot( PLOTTER* aPlotter, bool aBackground ) const
aPlotter->SetDash( penWidth, PLOT_DASH_TYPE::SOLID ); aPlotter->SetDash( penWidth, PLOT_DASH_TYPE::SOLID );
if( SCHEMATIC* schematic = Schematic() ) // Plot attributes to a hypertext menu
{
std::vector<wxString> properties; std::vector<wxString> properties;
BOX2I bbox = GetBoundingBox(); BOX2I bbox = GetBoundingBox();
bbox.Inflate( GetPenWidth() * 3 ); bbox.Inflate( GetPenWidth() * 3 );
@ -849,17 +848,13 @@ void SCH_LINE::Plot( PLOTTER* aPlotter, bool aBackground ) const
{ {
if( SCH_CONNECTION* connection = Connection() ) if( SCH_CONNECTION* connection = Connection() )
{ {
auto& netSettings = schematic->Prj().GetProjectFile().m_NetSettings;
wxString netName = connection->Name();
wxString className = netSettings->GetEffectiveNetClass( netName )->GetName();
properties.emplace_back( wxString::Format( wxT( "!%s = %s" ), properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
_( "Net" ), _( "Net" ),
UnescapeString( netName ) ) ); connection->Name() ) );
properties.emplace_back( wxString::Format( wxT( "!%s = %s" ), properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
_( "Resolved netclass" ), _( "Resolved netclass" ),
UnescapeString( className ) ) ); GetEffectiveNetClass()->GetName() ) );
} }
} }
else if( GetLayer() == LAYER_BUS ) else if( GetLayer() == LAYER_BUS )
@ -867,7 +862,7 @@ void SCH_LINE::Plot( PLOTTER* aPlotter, bool aBackground ) const
if( SCH_CONNECTION* connection = Connection() ) if( SCH_CONNECTION* connection = Connection() )
{ {
for( std::shared_ptr<SCH_CONNECTION>& member : connection->Members() ) for( std::shared_ptr<SCH_CONNECTION>& member : connection->Members() )
properties.emplace_back( wxT( "!" ) + UnescapeString( member->Name() ) ); properties.emplace_back( wxT( "!" ) + member->Name() );
} }
} }
@ -875,7 +870,6 @@ void SCH_LINE::Plot( PLOTTER* aPlotter, bool aBackground ) const
if( !properties.empty() ) if( !properties.empty() )
aPlotter->HyperlinkMenu( bbox, properties ); aPlotter->HyperlinkMenu( bbox, properties );
} }
}
void SCH_LINE::SetPosition( const VECTOR2I& aPosition ) void SCH_LINE::SetPosition( const VECTOR2I& aPosition )

View File

@ -2006,6 +2006,7 @@ void SCH_SYMBOL::Plot( PLOTTER* aPlotter, bool aBackground ) const
field.Plot( aPlotter, local_background ); field.Plot( aPlotter, local_background );
} }
// Plot attributes to a hypertext menu
std::vector<wxString> properties; std::vector<wxString> properties;
for( const SCH_FIELD& field : GetFields() ) for( const SCH_FIELD& field : GetFields() )