Allow titleblock vars to be resolved outside the titleblock.

Also implements some variable resolving for Altium imports.
This commit is contained in:
Jeff Young 2021-07-06 13:27:36 +01:00
parent 799d6690c0
commit 3288971a7c
4 changed files with 53 additions and 1 deletions

View File

@ -780,8 +780,24 @@ void SCH_ALTIUM_PLUGIN::ParseLabel( const std::map<wxString, wxString>& 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 );

View File

@ -615,6 +615,12 @@ wxString SCH_TEXT::GetShownText( int aDepth ) const
return false;
};
std::function<bool( wxString* )> 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;

View File

@ -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 );

View File

@ -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;