diff --git a/common/common.cpp b/common/common.cpp index 1896233dda..303825530d 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2014-2020 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008 Wayne Stambaugh - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -56,14 +56,18 @@ enum Bracket wxString ExpandTextVars( const wxString& aSource, const PROJECT* aProject ) { - return ExpandTextVars( aSource, nullptr, nullptr, aProject ); + std::function projectResolver = + [&]( wxString* token ) -> bool + { + return aProject->TextVarResolver( token ); + }; + + return ExpandTextVars( aSource, &projectResolver ); } wxString ExpandTextVars( const wxString& aSource, - const std::function* aLocalResolver, - const std::function* aFallbackResolver, - const PROJECT* aProject ) + const std::function* aResolver ) { wxString newbuf; size_t sourceLen = aSource.length(); @@ -87,15 +91,7 @@ wxString ExpandTextVars( const wxString& aSource, if( token.IsEmpty() ) continue; - if( aLocalResolver && (*aLocalResolver)( &token ) ) - { - newbuf.append( token ); - } - else if( aProject && aProject->TextVarResolver( &token ) ) - { - newbuf.append( token ); - } - else if( aFallbackResolver && (*aFallbackResolver)( &token ) ) + if( aResolver && (*aResolver)( &token ) ) { newbuf.append( token ); } diff --git a/common/drawing_sheet/ds_painter.cpp b/common/drawing_sheet/ds_painter.cpp index ac08860269..a3b9a16c67 100644 --- a/common/drawing_sheet/ds_painter.cpp +++ b/common/drawing_sheet/ds_painter.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * * This program is free software; you can redistribute it and/or @@ -182,10 +182,13 @@ wxString DS_DRAW_ITEM_LIST::BuildFullText( const wxString& aTextbase ) return true; } + if( m_project && m_project->TextVarResolver( token ) ) + return true; + return false; }; - return ExpandTextVars( aTextbase, &wsResolver, nullptr, m_project ); + return ExpandTextVars( aTextbase, &wsResolver ); } diff --git a/eeschema/dialogs/dialog_plot_schematic.cpp b/eeschema/dialogs/dialog_plot_schematic.cpp index d36697d627..fdc6e2dd94 100644 --- a/eeschema/dialogs/dialog_plot_schematic.cpp +++ b/eeschema/dialogs/dialog_plot_schematic.cpp @@ -4,7 +4,7 @@ * Copyright (C) 1992-2018 Jean-Pierre Charras jp.charras at wanadoo.fr * Copyright (C) 1992-2010 Lorenzo Marcantonio * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -418,7 +418,7 @@ wxString DIALOG_PLOT_SCHEMATIC::getOutputPath() }; wxString path = m_outputDirectoryName->GetValue(); - path = ExpandTextVars( path, &textResolver, nullptr, &Prj() ); + path = ExpandTextVars( path, &textResolver ); path = ExpandEnvVarSubstitutions( path, &Prj() ); fn.SetPath( path ); diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 755c308f31..7b62a64864 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -177,44 +177,22 @@ wxString SCH_FIELD::GetShownText( int aDepth, bool aAllowExtraText ) const std::function symbolResolver = [&]( wxString* token ) -> bool { - if( token->Contains( ':' ) ) - { - if( Schematic()->ResolveCrossReference( token, aDepth ) ) - return true; - } - else - { - SCH_SYMBOL* parentSymbol = static_cast( m_parent ); - - if( parentSymbol->ResolveTextVar( token, aDepth + 1 ) ) - return true; - - SCHEMATIC* schematic = parentSymbol->Schematic(); - SCH_SHEET* sheet = schematic ? schematic->CurrentSheet().Last() : nullptr; - - if( sheet && sheet->ResolveTextVar( token, aDepth + 1 ) ) - return true; - } - - return false; + return static_cast( m_parent )->ResolveTextVar( token, aDepth + 1 ); }; std::function sheetResolver = [&]( wxString* token ) -> bool { - SCH_SHEET* sheet = static_cast( m_parent ); - return sheet->ResolveTextVar( token, aDepth + 1 ); + return static_cast( m_parent )->ResolveTextVar( token, aDepth + 1 ); }; std::function labelResolver = [&]( wxString* token ) -> bool { - SCH_LABEL_BASE* label = static_cast( m_parent ); - return label->ResolveTextVar( token, aDepth + 1 ); + return static_cast( m_parent )->ResolveTextVar( token, aDepth + 1 ); }; - PROJECT* project = nullptr; - wxString text = EDA_TEXT::GetShownText(); + wxString text = EDA_TEXT::GetShownText(); if( IsNameShown() ) text = GetName() << wxS( ": " ) << text; @@ -225,19 +203,16 @@ wxString SCH_FIELD::GetShownText( int aDepth, bool aAllowExtraText ) const } else if( HasTextVars() ) { - if( Schematic() ) - project = &Schematic()->Prj(); - if( aDepth < 10 ) { if( m_parent && m_parent->Type() == SCH_SYMBOL_T ) - text = ExpandTextVars( text, &symbolResolver, nullptr, project ); + text = ExpandTextVars( text, &symbolResolver ); else if( m_parent && m_parent->Type() == SCH_SHEET_T ) - text = ExpandTextVars( text, &sheetResolver, nullptr, project ); + text = ExpandTextVars( text, &sheetResolver ); else if( m_parent && m_parent->IsType( { SCH_LABEL_LOCATE_ANY_T } ) ) - text = ExpandTextVars( text, &labelResolver, nullptr, project ); - else - text = ExpandTextVars( text, project ); + text = ExpandTextVars( text, &labelResolver ); + else if( Schematic() ) + text = ExpandTextVars( text, &Schematic()->Prj() ); } } diff --git a/eeschema/sch_label.cpp b/eeschema/sch_label.cpp index 4c3acc3f5b..ba8b6a17e5 100644 --- a/eeschema/sch_label.cpp +++ b/eeschema/sch_label.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2015 Wayne Stambaugh - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -481,12 +481,12 @@ void SCH_LABEL_BASE::GetIntersheetRefs( std::vectorContains( ':' ) ) { - if( !Schematic() ) - return false; - - if( Schematic()->ResolveCrossReference( token, aDepth ) ) + if( Schematic()->ResolveCrossReference( token, aDepth + 1 ) ) return true; } @@ -537,20 +537,19 @@ bool SCH_LABEL_BASE::ResolveTextVar( wxString* token, int aDepth ) const } } + // See if parent can resolve it (these will recurse to ancestors) + if( Type() == SCH_SHEET_PIN_T && m_parent ) { SCH_SHEET* sheet = static_cast( m_parent ); - if( sheet->ResolveTextVar( token, aDepth ) ) + if( sheet->ResolveTextVar( token, aDepth + 1 ) ) return true; } - else if( Schematic() ) + else if( SCH_SHEET* sheet = Schematic()->CurrentSheet().Last() ) { - if( SCH_SHEET* sheet = Schematic()->CurrentSheet().Last() ) - { - if( sheet->ResolveTextVar( token, aDepth ) ) - return true; - } + if( sheet->ResolveTextVar( token, aDepth + 1 ) ) + return true; } return false; @@ -565,12 +564,6 @@ wxString SCH_LABEL_BASE::GetShownText( int aDepth, bool aAllowExtraText ) const return ResolveTextVar( token, aDepth ); }; - std::function schematicTextResolver = - [&]( wxString* token ) -> bool - { - return Schematic()->ResolveTextVar( token, aDepth + 1 ); - }; - wxString text = EDA_TEXT::GetShownText(); if( text == wxS( "~" ) ) // Legacy placeholder for empty string @@ -579,13 +572,8 @@ wxString SCH_LABEL_BASE::GetShownText( int aDepth, bool aAllowExtraText ) const } else if( HasTextVars() ) { - PROJECT* project = nullptr; - - if( Schematic() ) - project = &Schematic()->Prj(); - if( aDepth < 10 ) - text = ExpandTextVars( text, &textResolver, &schematicTextResolver, project ); + text = ExpandTextVars( text, &textResolver ); } return text; diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 17cf11c7e7..8c34e97498 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -2186,40 +2186,15 @@ static void orientSymbol( LIB_SYMBOL* symbol, int orientation ) } -wxString resolveTextVars( const wxString& aSourceText, const SCH_SYMBOL* aSymbolContext ) +wxString expandLibItemTextVars( const wxString& aSourceText, const SCH_SYMBOL* aSymbolContext ) { std::function symbolResolver = [&]( wxString* token ) -> bool { - if( token->Contains( ':' ) ) - { - if( aSymbolContext->Schematic()->ResolveCrossReference( token, 0 ) ) - return true; - } - else - { - if( aSymbolContext->ResolveTextVar( token, 0 ) ) - return true; - - SCHEMATIC* schematic = aSymbolContext->Schematic(); - SCH_SHEET* sheet = schematic ? schematic->CurrentSheet().Last() : nullptr; - - if( sheet && sheet->ResolveTextVar( token, 0 ) ) - return true; - } - - return false; + return aSymbolContext->ResolveTextVar( token, 0 ); }; - PROJECT* project = nullptr; - wxString text = aSourceText; - - if( aSymbolContext->Schematic() ) - project = &aSymbolContext->Schematic()->Prj(); - - text = ExpandTextVars( text, &symbolResolver, nullptr, project ); - - return text; + return ExpandTextVars( aSourceText, &symbolResolver ); } @@ -2270,14 +2245,14 @@ void SCH_PAINTER::draw( const SCH_SYMBOL* aSymbol, int aLayer ) LIB_TEXT* textItem = static_cast( &tempItem ); if( textItem->HasTextVars() ) - textItem->SetText( resolveTextVars( textItem->GetText(), aSymbol ) ); + textItem->SetText( expandLibItemTextVars( textItem->GetText(), aSymbol ) ); } else if( tempItem.Type() == LIB_TEXTBOX_T ) { LIB_TEXTBOX* textboxItem = static_cast( &tempItem ); if( textboxItem->HasTextVars() ) - textboxItem->SetText( resolveTextVars( textboxItem->GetText(), aSymbol ) ); + textboxItem->SetText( expandLibItemTextVars( textboxItem->GetText(), aSymbol ) ); } } diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index a3ad3d3a54..216ffc8d82 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -232,6 +232,15 @@ void SCH_SHEET::GetContextualTextVars( wxArrayString* aVars ) const bool SCH_SHEET::ResolveTextVar( wxString* token, int aDepth ) const { + if( !Schematic() ) + return false; + + if( token->Contains( ':' ) ) + { + if( Schematic()->ResolveCrossReference( token, aDepth + 1 ) ) + return true; + } + for( int i = 0; i < SHEET_MANDATORY_FIELDS; ++i ) { if( token->IsSameAs( m_fields[i].GetCanonicalName().Upper() ) ) @@ -275,19 +284,22 @@ bool SCH_SHEET::ResolveTextVar( wxString* token, int aDepth ) const *token = findSelf().PathHumanReadable(); return true; } + + // See if parent can resolve it (these will recurse to ancestors) + + SCH_SHEET_PATH sheetPath = findSelf(); + + if( sheetPath.size() >= 2 ) + { + sheetPath.pop_back(); + + if( sheetPath.Last()->ResolveTextVar( token, aDepth + 1 ) ) + return true; + } else { - // See if any of the sheets up the hierarchy can resolve it: - - SCH_SHEET_PATH sheetPath = findSelf(); - - if( sheetPath.size() >= 2 ) - { - sheetPath.pop_back(); - - if( sheetPath.Last()->ResolveTextVar( token, aDepth ) ) - return true; - } + if( Schematic()->ResolveTextVar( token, aDepth + 1 ) ) + return true; } return false; diff --git a/eeschema/sch_symbol.cpp b/eeschema/sch_symbol.cpp index f89e70eb60..af0a8fccb7 100644 --- a/eeschema/sch_symbol.cpp +++ b/eeschema/sch_symbol.cpp @@ -1138,6 +1138,12 @@ bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth ) const if( !schematic ) return false; + if( token->Contains( ':' ) ) + { + if( schematic->ResolveCrossReference( token, aDepth + 1 ) ) + return true; + } + for( int i = 0; i < MANDATORY_FIELDS; ++i ) { if( token->IsSameAs( m_fields[ i ].GetCanonicalName().Upper() ) ) @@ -1245,6 +1251,14 @@ bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth ) const return true; } + // See if parent can resolve it (this will recurse to ancestors) + + if( SCH_SHEET* sheet = schematic->CurrentSheet().Last() ) + { + if( sheet->ResolveTextVar( token, aDepth + 1 ) ) + return true; + } + return false; } diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index 9b5f382f40..1b6be4e712 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2015 Wayne Stambaugh - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -344,29 +344,15 @@ wxString SCH_TEXT::GetShownText( int aDepth, bool aAllowExtraText ) const std::function textResolver = [&]( wxString* token ) -> bool { - if( token->Contains( ':' ) ) + if( SCH_SHEET* sheet = Schematic()->CurrentSheet().Last() ) { - if( Schematic()->ResolveCrossReference( token, aDepth ) ) - return true; - } - else - { - SCHEMATIC* schematic = Schematic(); - SCH_SHEET* sheet = schematic ? schematic->CurrentSheet().Last() : nullptr; - - if( sheet && sheet->ResolveTextVar( token, aDepth + 1 ) ) + if( sheet->ResolveTextVar( token, aDepth + 1 ) ) return true; } return false; }; - std::function schematicTextResolver = - [&]( wxString* token ) -> bool - { - return Schematic()->ResolveTextVar( token, aDepth + 1 ); - }; - wxString text = EDA_TEXT::GetShownText(); if( text == wxS( "~" ) ) // Legacy placeholder for empty string @@ -375,13 +361,8 @@ wxString SCH_TEXT::GetShownText( int aDepth, bool aAllowExtraText ) const } else if( HasTextVars() ) { - PROJECT* project = nullptr; - - if( Schematic() ) - project = &Schematic()->Prj(); - if( aDepth < 10 ) - text = ExpandTextVars( text, &textResolver, &schematicTextResolver, project ); + text = ExpandTextVars( text, &textResolver ); } return text; diff --git a/eeschema/sch_textbox.cpp b/eeschema/sch_textbox.cpp index 79017eb744..57038c7002 100644 --- a/eeschema/sch_textbox.cpp +++ b/eeschema/sch_textbox.cpp @@ -283,40 +283,21 @@ wxString SCH_TEXTBOX::GetShownText( int aDepth, bool aAllowExtraText ) const std::function textResolver = [&]( wxString* token ) -> bool { - if( token->Contains( ':' ) ) + if( SCH_SHEET* sheet = Schematic()->CurrentSheet().Last() ) { - if( Schematic()->ResolveCrossReference( token, aDepth ) ) - return true; - } - else - { - SCHEMATIC* schematic = Schematic(); - SCH_SHEET* sheet = schematic ? schematic->CurrentSheet().Last() : nullptr; - - if( sheet && sheet->ResolveTextVar( token, aDepth + 1 ) ) + if( sheet->ResolveTextVar( token, aDepth + 1 ) ) return true; } return false; }; - std::function schematicTextResolver = - [&]( wxString* token ) -> bool - { - return Schematic()->ResolveTextVar( token, aDepth + 1 ); - }; - wxString text = EDA_TEXT::GetShownText(); if( HasTextVars() ) { - PROJECT* project = nullptr; - - if( Schematic() ) - project = &Schematic()->Prj(); - if( aDepth < 10 ) - text = ExpandTextVars( text, &textResolver, &schematicTextResolver, project ); + text = ExpandTextVars( text, &textResolver ); } KIFONT::FONT* font = GetFont(); diff --git a/eeschema/schematic.cpp b/eeschema/schematic.cpp index 6c5f2036bc..6b8ec7fbb5 100644 --- a/eeschema/schematic.cpp +++ b/eeschema/schematic.cpp @@ -161,6 +161,9 @@ bool SCHEMATIC::ResolveTextVar( wxString* token, int aDepth ) const return CurrentSheet().LastScreen()->GetTitleBlock().TextVarResolver( token, m_project ); } + if( Prj().TextVarResolver( token ) ) + return true; + return false; } diff --git a/include/common.h b/include/common.h index f74f6f468a..c7f92b2ed3 100644 --- a/include/common.h +++ b/include/common.h @@ -4,7 +4,7 @@ * Copyright (C) 2014-2020 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2007-2015 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2008 Wayne Stambaugh - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -79,13 +79,10 @@ bool EnsureFileDirectoryExists( wxFileName* aTargetFullFileName, const wxString ExpandEnvVarSubstitutions( const wxString& aString, const PROJECT* aProject ); /** - * Expand '${var-name}' templates in text. The LocalResolver is given first crack at it, - * after which the PROJECT's resolver is called. + * Expand '${var-name}' templates in text. */ wxString ExpandTextVars( const wxString& aSource, - const std::function* aLocalResolver, - const std::function* aFallbackResolver, - const PROJECT* aProject ); + const std::function* aResolver ); wxString ExpandTextVars( const wxString& aSource, const PROJECT* aProject ); diff --git a/pcbnew/board.cpp b/pcbnew/board.cpp index 640fa25abf..a6f029da97 100644 --- a/pcbnew/board.cpp +++ b/pcbnew/board.cpp @@ -5,7 +5,7 @@ * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2011 Wayne Stambaugh * - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -324,6 +324,24 @@ std::vector BOARD::ResolveDRCExclusions() bool BOARD::ResolveTextVar( wxString* token, int aDepth ) const { + if( token->Contains( ':' ) ) + { + wxString remainder; + wxString ref = token->BeforeFirst( ':', &remainder ); + BOARD_ITEM* refItem = GetItem( KIID( ref ) ); + + if( refItem && refItem->Type() == PCB_FOOTPRINT_T ) + { + FOOTPRINT* refFP = static_cast( refItem ); + + if( refFP->ResolveTextVar( &remainder, aDepth + 1 ) ) + { + *token = remainder; + return true; + } + } + } + wxString var = *token; if( GetTitleBlock().TextVarResolver( token, m_project ) ) @@ -336,6 +354,9 @@ bool BOARD::ResolveTextVar( wxString* token, int aDepth ) const return true; } + if( GetProject() && GetProject()->TextVarResolver( token ) ) + return true; + return false; } diff --git a/pcbnew/dialogs/dialog_export_svg.cpp b/pcbnew/dialogs/dialog_export_svg.cpp index fac1281ddd..61d867d082 100644 --- a/pcbnew/dialogs/dialog_export_svg.cpp +++ b/pcbnew/dialogs/dialog_export_svg.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -259,7 +259,7 @@ void DIALOG_EXPORT_SVG::ExportSVGFile( bool aOnlyOneFile ) }; wxString path = m_outputDirectory; - path = ExpandTextVars( path, &textResolver, nullptr, nullptr ); + path = ExpandTextVars( path, &textResolver ); path = ExpandEnvVarSubstitutions( path, nullptr ); wxFileName outputDir = wxFileName::DirName( path ); diff --git a/pcbnew/dialogs/dialog_gen_footprint_position.cpp b/pcbnew/dialogs/dialog_gen_footprint_position.cpp index df2d8c6c48..485c1baacc 100644 --- a/pcbnew/dialogs/dialog_gen_footprint_position.cpp +++ b/pcbnew/dialogs/dialog_gen_footprint_position.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2015-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2015-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -267,7 +267,7 @@ bool DIALOG_GEN_FOOTPRINT_POSITION::CreateGerberFiles() }; wxString path = m_parent->GetPcbNewSettings()->m_PlaceFile.output_directory; - path = ExpandTextVars( path, &textResolver, nullptr, nullptr ); + path = ExpandTextVars( path, &textResolver ); path = ExpandEnvVarSubstitutions( path, nullptr ); wxFileName outputDir = wxFileName::DirName( path ); @@ -375,7 +375,7 @@ bool DIALOG_GEN_FOOTPRINT_POSITION::CreateAsciiFiles() }; wxString path = m_parent->GetPcbNewSettings()->m_PlaceFile.output_directory; - path = ExpandTextVars( path, &textResolver, nullptr, nullptr ); + path = ExpandTextVars( path, &textResolver ); path = ExpandEnvVarSubstitutions( path, nullptr ); wxFileName outputDir = wxFileName::DirName( path ); diff --git a/pcbnew/dialogs/dialog_gendrill.cpp b/pcbnew/dialogs/dialog_gendrill.cpp index 5ca5eef840..44be669987 100644 --- a/pcbnew/dialogs/dialog_gendrill.cpp +++ b/pcbnew/dialogs/dialog_gendrill.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 1992-2019 Jean_Pierre Charras - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -395,7 +395,7 @@ void DIALOG_GENDRILL::GenDrillAndMapFiles( bool aGenDrill, bool aGenMap ) }; wxString path = m_plotOpts.GetOutputDirectory(); - path = ExpandTextVars( path, &textResolver, nullptr, nullptr ); + path = ExpandTextVars( path, &textResolver ); path = ExpandEnvVarSubstitutions( path, nullptr ); wxFileName outputDir = wxFileName::DirName( path ); diff --git a/pcbnew/dialogs/dialog_plot.cpp b/pcbnew/dialogs/dialog_plot.cpp index 34963e8d9c..cde571539b 100644 --- a/pcbnew/dialogs/dialog_plot.cpp +++ b/pcbnew/dialogs/dialog_plot.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -508,7 +508,7 @@ void DIALOG_PLOT::OnOutputDirectoryBrowseClicked( wxCommandEvent& event ) }; wxString path = m_outputDirectoryName->GetValue(); - path = ExpandTextVars( path, &textResolver, nullptr, &Prj() ); + path = ExpandTextVars( path, &textResolver ); path = ExpandEnvVarSubstitutions( path, &Prj() ); path = Prj().AbsolutePath( path ); @@ -978,7 +978,7 @@ void DIALOG_PLOT::Plot( wxCommandEvent& event ) }; wxString path = m_plotOpts.GetOutputDirectory(); - path = ExpandTextVars( path, &textResolver, nullptr, board->GetProject() ); + path = ExpandTextVars( path, &textResolver ); path = ExpandEnvVarSubstitutions( path, board->GetProject() ); wxFileName outputDir = wxFileName::DirName( path ); diff --git a/pcbnew/footprint.cpp b/pcbnew/footprint.cpp index a61ddcfd76..9f656fd451 100644 --- a/pcbnew/footprint.cpp +++ b/pcbnew/footprint.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2015 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2015 Wayne Stambaugh - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -548,6 +548,9 @@ bool FOOTPRINT::ResolveTextVar( wxString* token, int aDepth ) const return true; } + if( GetBoard() && GetBoard()->ResolveTextVar( token, aDepth + 1 ) ) + return true; + return false; } diff --git a/pcbnew/fp_text.cpp b/pcbnew/fp_text.cpp index 428b8005b2..5caef0bf68 100644 --- a/pcbnew/fp_text.cpp +++ b/pcbnew/fp_text.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -415,8 +415,6 @@ double FP_TEXT::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const wxString FP_TEXT::GetShownText( int aDepth, bool aAllowExtraText ) const { const FOOTPRINT* parentFootprint = static_cast( GetParent() ); - wxASSERT( parentFootprint ); - const BOARD* board = parentFootprint->GetBoard(); std::function footprintResolver = [&]( wxString* token ) -> bool @@ -424,23 +422,12 @@ wxString FP_TEXT::GetShownText( int aDepth, bool aAllowExtraText ) const return parentFootprint && parentFootprint->ResolveTextVar( token, aDepth ); }; - std::function boardTextResolver = - [&]( wxString* token ) -> bool - { - return board->ResolveTextVar( token, aDepth + 1 ); - }; - wxString text = EDA_TEXT::GetShownText(); if( HasTextVars() ) { - PROJECT* project = nullptr; - - if( parentFootprint && parentFootprint->GetParent() ) - project = static_cast( parentFootprint->GetParent() )->GetProject(); - if( aDepth < 10 ) - text = ExpandTextVars( text, &footprintResolver, &boardTextResolver, project ); + text = ExpandTextVars( text, &footprintResolver ); } return text; diff --git a/pcbnew/fp_textbox.cpp b/pcbnew/fp_textbox.cpp index 404ebf1254..0818ff5c95 100644 --- a/pcbnew/fp_textbox.cpp +++ b/pcbnew/fp_textbox.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -393,8 +393,6 @@ double FP_TEXTBOX::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const wxString FP_TEXTBOX::GetShownText( int aDepth, bool aAllowExtraText ) const { const FOOTPRINT* parentFootprint = static_cast( GetParent() ); - wxASSERT( parentFootprint ); - const BOARD* board = parentFootprint->GetBoard(); std::function footprintResolver = [&]( wxString* token ) -> bool @@ -402,23 +400,12 @@ wxString FP_TEXTBOX::GetShownText( int aDepth, bool aAllowExtraText ) const return parentFootprint && parentFootprint->ResolveTextVar( token, aDepth ); }; - std::function boardTextResolver = - [&]( wxString* token ) -> bool - { - return board->ResolveTextVar( token, aDepth + 1 ); - }; - wxString text = EDA_TEXT::GetShownText(); if( HasTextVars() ) { - PROJECT* project = nullptr; - - if( parentFootprint && parentFootprint->GetParent() ) - project = static_cast( parentFootprint->GetParent() )->GetProject(); - if( aDepth < 10 ) - text = ExpandTextVars( text, &footprintResolver, &boardTextResolver, project ); + text = ExpandTextVars( text, &footprintResolver ); } KIFONT::FONT* font = getDrawFont(); diff --git a/pcbnew/pcb_text.cpp b/pcbnew/pcb_text.cpp index 5ad79a0887..437108523f 100644 --- a/pcbnew/pcb_text.cpp +++ b/pcbnew/pcb_text.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -65,36 +65,18 @@ wxString PCB_TEXT::GetShownText( int aDepth, bool aAllowExtraText ) const return true; } - if( token->Contains( ':' ) ) + if( board->ResolveTextVar( token, aDepth + 1 ) ) { - wxString remainder; - wxString ref = token->BeforeFirst( ':', &remainder ); - BOARD_ITEM* refItem = board->GetItem( KIID( ref ) ); - - if( refItem && refItem->Type() == PCB_FOOTPRINT_T ) - { - FOOTPRINT* refFP = static_cast( refItem ); - - if( refFP->ResolveTextVar( &remainder, aDepth + 1 ) ) - { - *token = remainder; - return true; - } - } + return true; } - return false; - }; - std::function boardTextResolver = - [&]( wxString* token ) -> bool - { - return board->ResolveTextVar( token, aDepth + 1 ); + return false; }; wxString text = EDA_TEXT::GetShownText(); if( board && HasTextVars() && aDepth < 10 ) - text = ExpandTextVars( text, &pcbTextResolver, &boardTextResolver, board->GetProject() ); + text = ExpandTextVars( text, &pcbTextResolver ); return text; } diff --git a/pcbnew/pcb_textbox.cpp b/pcbnew/pcb_textbox.cpp index f9b892b581..01870075e0 100644 --- a/pcbnew/pcb_textbox.cpp +++ b/pcbnew/pcb_textbox.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -252,36 +252,18 @@ wxString PCB_TEXTBOX::GetShownText( int aDepth, bool aAllowExtraText ) const return true; } - if( token->Contains( ':' ) ) + if( board->ResolveTextVar( token, aDepth + 1 ) ) { - wxString remainder; - wxString ref = token->BeforeFirst( ':', &remainder ); - BOARD_ITEM* refItem = board->GetItem( KIID( ref ) ); - - if( refItem && refItem->Type() == PCB_FOOTPRINT_T ) - { - FOOTPRINT* refFP = static_cast( refItem ); - - if( refFP->ResolveTextVar( &remainder, aDepth + 1 ) ) - { - *token = remainder; - return true; - } - } + return true; } - return false; - }; - std::function boardTextResolver = - [&]( wxString* token ) -> bool - { - return board->ResolveTextVar( token, aDepth + 1 ); + return false; }; wxString text = EDA_TEXT::GetShownText(); if( board && HasTextVars() && aDepth < 10 ) - text = ExpandTextVars( text, &pcbTextResolver, &boardTextResolver, board->GetProject() ); + text = ExpandTextVars( text, &pcbTextResolver ); KIFONT::FONT* font = getDrawFont(); std::vector corners = GetAnchorAndOppositeCorner(); diff --git a/pcbnew/pcbplot.cpp b/pcbnew/pcbplot.cpp index 6bb08309b6..d8788da573 100644 --- a/pcbnew/pcbplot.cpp +++ b/pcbnew/pcbplot.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -447,7 +447,7 @@ bool PLOT_CONTROLLER::OpenPlotfile( const wxString& aSuffix, PLOT_FORMAT aFormat }; wxString outputDirName = GetPlotOptions().GetOutputDirectory(); - outputDirName = ExpandTextVars( outputDirName, &textResolver, nullptr, nullptr ); + outputDirName = ExpandTextVars( outputDirName, &textResolver ); outputDirName = ExpandEnvVarSubstitutions( outputDirName, nullptr ); wxFileName outputDir = wxFileName::DirName( outputDirName );