Resolve text variables in title blocks for outputing to netlist.

Fixes https://gitlab.com/kicad/code/kicad/issues/7153
This commit is contained in:
Jeff Young 2021-01-17 15:47:04 +00:00
parent 1754504234
commit f1221a9ca3
10 changed files with 40 additions and 33 deletions

View File

@ -55,10 +55,16 @@ enum Bracket
};
wxString ExpandTextVars( const wxString& aSource, const PROJECT* aProject )
{
return ExpandTextVars( aSource, nullptr, nullptr, aProject );
}
wxString ExpandTextVars( const wxString& aSource,
const std::function<bool( wxString* )>* aLocalResolver,
const PROJECT* aProject,
const std::function<bool( wxString* )>* aFallbackResolver )
const std::function<bool( wxString* )>* aFallbackResolver,
const PROJECT* aProject )
{
wxString newbuf;
size_t sourceLen = aSource.length();
@ -267,7 +273,7 @@ const wxString ExpandEnvVarSubstitutions( const wxString& aString, PROJECT* aPro
const wxString ResolveUriByEnvVars( const wxString& aUri, PROJECT* aProject )
{
wxString uri = ExpandTextVars( aUri, nullptr, aProject );
wxString uri = ExpandTextVars( aUri, aProject );
// URL-like URI: return as is.
wxURL url( uri );

View File

@ -171,14 +171,14 @@ wxString WS_DRAW_ITEM_LIST::BuildFullText( const wxString& aTextbase )
if( tokenUpdated )
{
*token = ExpandTextVars( *token, nullptr, m_project );
*token = ExpandTextVars( *token, m_project );
return true;
}
return false;
};
return ExpandTextVars( aTextbase, &wsResolver, m_project );
return ExpandTextVars( aTextbase, &wsResolver, nullptr, m_project );
}

View File

@ -118,7 +118,7 @@ bool TITLE_BLOCK::TextVarResolver( wxString* aToken, const PROJECT* aProject ) c
if( tokenUpdated )
{
*aToken = ExpandTextVars( *aToken, nullptr, aProject );
*aToken = ExpandTextVars( *aToken, aProject );
return true;
}

View File

@ -377,15 +377,15 @@ XNODE* NETLIST_EXPORTER_XML::makeDesignHeader()
xsheet->AddAttribute( "name", sheetList[i].PathHumanReadable() );
xsheet->AddAttribute( "tstamps", sheetList[i].PathAsString() );
TITLE_BLOCK tb = screen->GetTitleBlock();
PROJECT* prj = &m_schematic->Prj();
xsheet->AddChild( xtitleBlock = node( "title_block" ) );
xtitleBlock->AddChild( node( "title", tb.GetTitle() ) );
xtitleBlock->AddChild( node( "company", tb.GetCompany() ) );
xtitleBlock->AddChild( node( "rev", tb.GetRevision() ) );
xtitleBlock->AddChild( node( "date", tb.GetDate() ) );
xtitleBlock->AddChild( node( "title", ExpandTextVars( tb.GetTitle(), prj ) ) );
xtitleBlock->AddChild( node( "company", ExpandTextVars( tb.GetCompany(), prj ) ) );
xtitleBlock->AddChild( node( "rev", ExpandTextVars( tb.GetRevision(), prj ) ) );
xtitleBlock->AddChild( node( "date", ExpandTextVars( tb.GetDate(), prj ) ) );
// We are going to remove the fileName directories.
sourceFileName = wxFileName( screen->GetFileName() );
@ -393,39 +393,39 @@ XNODE* NETLIST_EXPORTER_XML::makeDesignHeader()
xtitleBlock->AddChild( xcomment = node( "comment" ) );
xcomment->AddAttribute( "number", "1" );
xcomment->AddAttribute( "value", tb.GetComment( 0 ) );
xcomment->AddAttribute( "value", ExpandTextVars( tb.GetComment( 0 ), prj ) );
xtitleBlock->AddChild( xcomment = node( "comment" ) );
xcomment->AddAttribute( "number", "2" );
xcomment->AddAttribute( "value", tb.GetComment( 1 ) );
xcomment->AddAttribute( "value", ExpandTextVars( tb.GetComment( 1 ), prj ) );
xtitleBlock->AddChild( xcomment = node( "comment" ) );
xcomment->AddAttribute( "number", "3" );
xcomment->AddAttribute( "value", tb.GetComment( 2 ) );
xcomment->AddAttribute( "value", ExpandTextVars( tb.GetComment( 2 ), prj ) );
xtitleBlock->AddChild( xcomment = node( "comment" ) );
xcomment->AddAttribute( "number", "4" );
xcomment->AddAttribute( "value", tb.GetComment( 3 ) );
xcomment->AddAttribute( "value", ExpandTextVars( tb.GetComment( 3 ), prj ) );
xtitleBlock->AddChild( xcomment = node( "comment" ) );
xcomment->AddAttribute( "number", "5" );
xcomment->AddAttribute( "value", tb.GetComment( 4 ) );
xcomment->AddAttribute( "value", ExpandTextVars( tb.GetComment( 4 ), prj ) );
xtitleBlock->AddChild( xcomment = node( "comment" ) );
xcomment->AddAttribute( "number", "6" );
xcomment->AddAttribute( "value", tb.GetComment( 5 ) );
xcomment->AddAttribute( "value", ExpandTextVars( tb.GetComment( 5 ), prj ) );
xtitleBlock->AddChild( xcomment = node( "comment" ) );
xcomment->AddAttribute( "number", "7" );
xcomment->AddAttribute( "value", tb.GetComment( 6 ) );
xcomment->AddAttribute( "value", ExpandTextVars( tb.GetComment( 6 ), prj ) );
xtitleBlock->AddChild( xcomment = node( "comment" ) );
xcomment->AddAttribute( "number", "8" );
xcomment->AddAttribute( "value", tb.GetComment( 7 ) );
xcomment->AddAttribute( "value", ExpandTextVars( tb.GetComment( 7 ), prj ) );
xtitleBlock->AddChild( xcomment = node( "comment" ) );
xcomment->AddAttribute( "number", "9" );
xcomment->AddAttribute( "value", tb.GetComment( 8 ) );
xcomment->AddAttribute( "value", ExpandTextVars( tb.GetComment( 8 ), prj ) );
}
return xdesign;

View File

@ -154,13 +154,13 @@ wxString SCH_FIELD::GetShownText( int aDepth ) const
if( aDepth < 10 )
{
if( m_parent && m_parent->Type() == SCH_COMPONENT_T )
text = ExpandTextVars( text, &symbolResolver, project );
text = ExpandTextVars( text, &symbolResolver, nullptr, project );
else if( m_parent && m_parent->Type() == SCH_SHEET_T )
text = ExpandTextVars( text, &sheetResolver, project );
text = ExpandTextVars( text, &sheetResolver, nullptr, project );
else if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
text = ExpandTextVars( text, &globalLabelResolver, project );
text = ExpandTextVars( text, &globalLabelResolver, nullptr, project );
else
text = ExpandTextVars( text, nullptr, project );
text = ExpandTextVars( text, project );
}
}

View File

@ -560,7 +560,7 @@ wxString SCH_TEXT::GetShownText( int aDepth ) const
project = &Schematic()->Prj();
if( aDepth < 10 )
text = ExpandTextVars( text, &textResolver, project );
text = ExpandTextVars( text, &textResolver, nullptr, project );
}
return text;

View File

@ -113,8 +113,10 @@ const wxString ExpandEnvVarSubstitutions( const wxString& aString, PROJECT* aPro
*/
wxString ExpandTextVars( const wxString& aSource,
const std::function<bool( wxString* )>* aLocalResolver,
const PROJECT* aProject,
const std::function<bool( wxString* )>* aFallbackResolver = nullptr );
const std::function<bool( wxString* )>* aFallbackResolver,
const PROJECT* aProject );
wxString ExpandTextVars( const wxString& aSource, const PROJECT* aProject );
/**
* Replace any environment and/or text variables in file-path uris (leaving network-path URIs

View File

@ -434,7 +434,7 @@ wxString FP_TEXT::GetShownText( int aDepth ) const
project = static_cast<BOARD*>( parentFootprint->GetParent() )->GetProject();
if( aDepth < 10 )
text = ExpandTextVars( text, &footprintResolver, project, &boardTextResolver );
text = ExpandTextVars( text, &footprintResolver, &boardTextResolver, project );
}
return text;

View File

@ -92,7 +92,7 @@ wxString PCB_TEXT::GetShownText( int aDepth ) const
wxString text = EDA_TEXT::GetShownText( &processTextVars );
if( board && processTextVars && aDepth < 10 )
text = ExpandTextVars( text, &pcbTextResolver, board->GetProject(), &boardTextResolver );
text = ExpandTextVars( text, &pcbTextResolver, &boardTextResolver, board->GetProject() );
return text;
}

View File

@ -276,8 +276,7 @@ static wxString& makeStringCompatX1( wxString& aText, bool aUseX1CompatibilityMo
}
void AddGerberX2Header( PLOTTER * aPlotter,
const BOARD *aBoard, bool aUseX1CompatibilityMode )
void AddGerberX2Header( PLOTTER * aPlotter, const BOARD *aBoard, bool aUseX1CompatibilityMode )
{
wxString text;
@ -312,8 +311,8 @@ void AddGerberX2Header( PLOTTER * aPlotter,
msg = fn.GetName();
msg.Replace( wxT( "," ), wxT( "_" ) );
// build the <rec> string. All non ASCII chars and comma are replaced by '_'
wxString rev = ((BOARD*)aBoard)->GetTitleBlock().GetRevision();
// build the <revision id> string. All non ASCII chars and comma are replaced by '_'
wxString rev = ExpandTextVars( aBoard->GetTitleBlock().GetRevision(), aBoard->GetProject() );
rev.Replace( wxT( "," ), wxT( "_" ) );
if( rev.IsEmpty() )