diff --git a/common/common.cpp b/common/common.cpp index eaa07be1d1..f586760fad 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -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* aLocalResolver, - const PROJECT* aProject, - const std::function* aFallbackResolver ) + const std::function* 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 ); diff --git a/common/page_layout/ws_painter.cpp b/common/page_layout/ws_painter.cpp index f267241e80..eaee5f1476 100644 --- a/common/page_layout/ws_painter.cpp +++ b/common/page_layout/ws_painter.cpp @@ -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 ); } diff --git a/common/title_block.cpp b/common/title_block.cpp index eb4e891fbb..f5841be5e0 100644 --- a/common/title_block.cpp +++ b/common/title_block.cpp @@ -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; } diff --git a/eeschema/netlist_exporters/netlist_exporter_xml.cpp b/eeschema/netlist_exporters/netlist_exporter_xml.cpp index 319ca912ee..a230f72cd0 100644 --- a/eeschema/netlist_exporters/netlist_exporter_xml.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_xml.cpp @@ -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; diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index fa9652efb6..803888bf56 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -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 ); } } diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index 427ab071e7..206da69370 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -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; diff --git a/include/common.h b/include/common.h index e568187504..173c6c3cc8 100644 --- a/include/common.h +++ b/include/common.h @@ -113,8 +113,10 @@ const wxString ExpandEnvVarSubstitutions( const wxString& aString, PROJECT* aPro */ wxString ExpandTextVars( const wxString& aSource, const std::function* aLocalResolver, - const PROJECT* aProject, - const std::function* aFallbackResolver = nullptr ); + const std::function* 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 diff --git a/pcbnew/fp_text.cpp b/pcbnew/fp_text.cpp index fd90b4905c..cd776475ef 100644 --- a/pcbnew/fp_text.cpp +++ b/pcbnew/fp_text.cpp @@ -434,7 +434,7 @@ wxString FP_TEXT::GetShownText( int aDepth ) const project = static_cast( parentFootprint->GetParent() )->GetProject(); if( aDepth < 10 ) - text = ExpandTextVars( text, &footprintResolver, project, &boardTextResolver ); + text = ExpandTextVars( text, &footprintResolver, &boardTextResolver, project ); } return text; diff --git a/pcbnew/pcb_text.cpp b/pcbnew/pcb_text.cpp index 3df6698390..a3b5ede87e 100644 --- a/pcbnew/pcb_text.cpp +++ b/pcbnew/pcb_text.cpp @@ -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; } diff --git a/pcbnew/pcbplot.cpp b/pcbnew/pcbplot.cpp index da9f47f279..6b11e657f5 100644 --- a/pcbnew/pcbplot.cpp +++ b/pcbnew/pcbplot.cpp @@ -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 string. All non ASCII chars and comma are replaced by '_' - wxString rev = ((BOARD*)aBoard)->GetTitleBlock().GetRevision(); + // build the 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() )