diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp index 6605db9ed7..5d759c24b3 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp @@ -780,8 +780,24 @@ void SCH_ALTIUM_PLUGIN::ParseLabel( const std::map& aPropert ASCH_LABEL elem( aProperties ); // TODO: text variable support + if( elem.ownerpartid == ALTIUM_COMPONENT_NONE ) { + if( elem.text == "=SheetNumber" ) + elem.text = "${#}"; + else if( elem.text == "=SheetTotal" ) + elem.text = "${##}"; + else if( elem.text == "=Title" ) + elem.text = "${TITLE}"; + else if( elem.text == "=ProjectRev" ) + elem.text = "${REVISION}"; + else if( elem.text == "=Date" ) + elem.text = "${ISSUE_DATE}"; + else if( elem.text == "=CompanyName" ) + elem.text = "${COMPANY}"; + else if( elem.text == "=DocumentName" ) + elem.text = "${FILENAME}"; + SCH_TEXT* text = new SCH_TEXT( elem.location + m_sheetOffset, elem.text ); SetEdaTextJustification( text, elem.justification ); diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index fd5aa6ac48..d636a3e8f0 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -615,6 +615,12 @@ wxString SCH_TEXT::GetShownText( int aDepth ) const return false; }; + std::function schematicTextResolver = + [&]( wxString* token ) -> bool + { + return Schematic()->ResolveTextVar( token, aDepth + 1 ); + }; + wxString text = EDA_TEXT::GetShownText(); if( text == "~" ) // Legacy placeholder for empty string @@ -631,7 +637,7 @@ wxString SCH_TEXT::GetShownText( int aDepth ) const project = &Schematic()->Prj(); if( aDepth < 10 ) - text = ExpandTextVars( text, &textResolver, nullptr, project ); + text = ExpandTextVars( text, &textResolver, &schematicTextResolver, project ); } return text; diff --git a/eeschema/schematic.cpp b/eeschema/schematic.cpp index 1a8fdf8bcb..be7faea822 100644 --- a/eeschema/schematic.cpp +++ b/eeschema/schematic.cpp @@ -120,6 +120,34 @@ SCH_SCREEN* SCHEMATIC::RootScreen() const } +bool SCHEMATIC::ResolveTextVar( wxString* token, int aDepth ) const +{ + if( token->IsSameAs( wxT( "#" ) ) ) + { + *token = CurrentSheet().GetPageNumber(); + return true; + } + else if( token->IsSameAs( wxT( "##" ) ) ) + { + *token = wxString::Format( "%i", Root().CountSheets() ); + return true; + } + else if( token->IsSameAs( wxT( "SHEETNAME" ) ) ) + { + *token = CurrentSheet().PathHumanReadable(); + return true; + } + else if( token->IsSameAs( wxT( "FILENAME" ) ) ) + { + wxFileName fn( GetFileName() ); + *token = fn.GetFullName(); + return true; + } + + return CurrentSheet().LastScreen()->GetTitleBlock().TextVarResolver( token, m_project ); +} + + wxString SCHEMATIC::GetFileName() const { return IsValid() ? m_rootSheet->GetScreen()->GetFileName() : wxString( wxEmptyString ); diff --git a/eeschema/schematic.h b/eeschema/schematic.h index 27b96583d0..3d793729d0 100644 --- a/eeschema/schematic.h +++ b/eeschema/schematic.h @@ -113,6 +113,8 @@ public: /// Helper to retrieve the screen of the root sheet SCH_SCREEN* RootScreen() const; + bool ResolveTextVar( wxString* token, int aDepth ) const; + /// Helper to retrieve the filename from the root sheet screen wxString GetFileName() const override;