diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index 216ffc8d82..5428703aaa 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr - * 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 @@ -221,6 +221,10 @@ void SCH_SHEET::GetContextualTextVars( wxArrayString* aVars ) const sheetPath.pop_back(); sheetPath.Last()->GetContextualTextVars( aVars ); } + else if( Schematic() ) + { + Schematic()->GetContextualTextVars( aVars ); + } add( wxT( "#" ) ); add( wxT( "##" ) ); diff --git a/eeschema/schematic.cpp b/eeschema/schematic.cpp index a2635b026b..d94ae3908b 100644 --- a/eeschema/schematic.cpp +++ b/eeschema/schematic.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-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 as published by the @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -122,6 +123,30 @@ SCH_SCREEN* SCHEMATIC::RootScreen() const } +void SCHEMATIC::GetContextualTextVars( wxArrayString* aVars ) const +{ + auto add = + [&]( const wxString& aVar ) + { + if( !alg::contains( *aVars, aVar ) ) + aVars->push_back( aVar ); + }; + + add( wxT( "#" ) ); + add( wxT( "##" ) ); + add( wxT( "SHEETPATH" ) ); + add( wxT( "SHEETNAME" ) ); + add( wxT( "FILENAME" ) ); + add( wxT( "PROJECTNAME" ) ); + + if( !CurrentSheet().empty() ) + CurrentSheet().LastScreen()->GetTitleBlock().GetContextualTextVars( aVars ); + + for( std::pair entry : Prj().GetTextVars() ) + add( entry.first ); +} + + bool SCHEMATIC::ResolveTextVar( wxString* token, int aDepth ) const { if( !CurrentSheet().empty() ) diff --git a/eeschema/schematic.h b/eeschema/schematic.h index 43ecb340a3..32cccb9439 100644 --- a/eeschema/schematic.h +++ b/eeschema/schematic.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-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 as published by the @@ -112,6 +112,8 @@ public: /// Helper to retrieve the screen of the root sheet SCH_SCREEN* RootScreen() const; + void GetContextualTextVars( wxArrayString* aVars ) const; + bool ResolveTextVar( wxString* token, int aDepth ) const; /// Helper to retrieve the filename from the root sheet screen