Move title block fields to global availability in PCBNew.

Fixes https://gitlab.com/kicad/code/kicad/issues/7118
This commit is contained in:
Jeff Young 2021-01-15 15:40:35 +00:00
parent 82cf747ca8
commit 08d595c9bf
4 changed files with 68 additions and 40 deletions

View File

@ -162,46 +162,9 @@ wxString WS_DRAW_ITEM_LIST::BuildFullText( const wxString& aTextbase )
*token = m_sheetLayer ? *m_sheetLayer : wxString( "" );
tokenUpdated = true;
}
else if( token->IsSameAs( wxT( "ISSUE_DATE" ) ) )
else if( m_titleBlock )
{
*token = m_titleBlock ? m_titleBlock->GetDate() : wxString( "" );
tokenUpdated = true;
}
else if( token->IsSameAs( wxT( "REVISION" ) ) )
{
*token = m_titleBlock ? m_titleBlock->GetRevision() : wxString( "" );
tokenUpdated = true;
}
else if( token->IsSameAs( wxT( "TITLE" ) ) )
{
*token = m_titleBlock ? m_titleBlock->GetTitle() : wxString( "" );
tokenUpdated = true;
}
else if( token->IsSameAs( wxT( "COMPANY" ) ) )
{
*token = m_titleBlock ? m_titleBlock->GetCompany() : wxString( "" );
tokenUpdated = true;
}
else if( token->Left( token->Len() - 1 ).IsSameAs( wxT( "COMMENT" ) ) )
{
wxChar c = token->Last();
switch( c )
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
*token = m_titleBlock ? m_titleBlock->GetComment( c - '0' )
: wxString( "" );
tokenUpdated = true;
}
m_titleBlock->TextVarResolver( token, m_project );
}
if( tokenUpdated )

View File

@ -23,6 +23,7 @@
*/
#include <richio.h>
#include <common.h>
#include <title_block.h>
void TITLE_BLOCK::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
@ -68,3 +69,60 @@ void TITLE_BLOCK::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aCont
aFormatter->Print( aNestLevel, ")\n\n" );
}
}
bool TITLE_BLOCK::TextVarResolver( wxString* aToken, const PROJECT* aProject ) const
{
bool tokenUpdated = false;
if( aToken->IsSameAs( wxT( "ISSUE_DATE" ) ) )
{
*aToken = GetDate();
tokenUpdated = true;
}
else if( aToken->IsSameAs( wxT( "REVISION" ) ) )
{
*aToken = GetRevision();
tokenUpdated = true;
}
else if( aToken->IsSameAs( wxT( "TITLE" ) ) )
{
*aToken = GetTitle();
tokenUpdated = true;
}
else if( aToken->IsSameAs( wxT( "COMPANY" ) ) )
{
*aToken = GetCompany();
tokenUpdated = true;
}
else if( aToken->Left( aToken->Len() - 1 ).IsSameAs( wxT( "COMMENT" ) ) )
{
wxChar c = aToken->Last();
switch( c )
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
*aToken = GetComment( c - '0' );
tokenUpdated = true;
}
}
if( tokenUpdated )
{
*aToken = ExpandTextVars( *aToken, nullptr, aProject );
return true;
}
return false;
}

View File

@ -29,6 +29,7 @@
#include <ki_exception.h>
class OUTPUTFORMATTER;
class PROJECT;
/**
* Hold the information shown in the lower right corner of a plot, printout, or
@ -115,6 +116,8 @@ public:
m_tbTexts.Clear();
}
bool TextVarResolver( wxString* aToken, const PROJECT* aProject ) const;
/**
* Output the object to \a aFormatter in s-expression form.
*

View File

@ -219,7 +219,11 @@ std::vector<PCB_MARKER*> BOARD::ResolveDRCExclusions()
bool BOARD::ResolveTextVar( wxString* token, int aDepth ) const
{
if( m_properties.count( *token ) )
if( GetTitleBlock().TextVarResolver( token, m_project ) )
{
return true;
}
else if( m_properties.count( *token ) )
{
*token = m_properties.at( *token );
return true;