sch_symbol: always require sheet path for text variable resolution

This commit is contained in:
Mike Williams 2023-05-06 14:22:14 -04:00
parent b0c5993f93
commit 5d116245c6
6 changed files with 18 additions and 30 deletions

View File

@ -178,8 +178,7 @@ wxString SCH_FIELD::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraT
std::function<bool( wxString* )> symbolResolver = std::function<bool( wxString* )> symbolResolver =
[&]( wxString* token ) -> bool [&]( wxString* token ) -> bool
{ {
return static_cast<SCH_SYMBOL*>( m_parent )->ResolveTextVar( token, aDepth + 1, return static_cast<SCH_SYMBOL*>( m_parent )->ResolveTextVar( aPath, token, aDepth + 1 );
aPath );
}; };
std::function<bool( wxString* )> sheetResolver = std::function<bool( wxString* )> sheetResolver =

View File

@ -2339,12 +2339,12 @@ static void orientSymbol( LIB_SYMBOL* symbol, int orientation )
} }
wxString expandLibItemTextVars( const wxString& aSourceText, const SCH_SYMBOL* aSymbolContext ) wxString SCH_PAINTER::expandLibItemTextVars( const wxString& aSourceText, const SCH_SYMBOL* aSymbolContext )
{ {
std::function<bool( wxString* )> symbolResolver = std::function<bool( wxString* )> symbolResolver =
[&]( wxString* token ) -> bool [&]( wxString* token ) -> bool
{ {
return aSymbolContext->ResolveTextVar( token, 0 ); return aSymbolContext->ResolveTextVar( &m_schematic->CurrentSheet(), token );
}; };
return ExpandTextVars( aSourceText, &symbolResolver ); return ExpandTextVars( aSourceText, &symbolResolver );

View File

@ -203,6 +203,8 @@ private:
void boxText( const wxString& aText, const VECTOR2D& aPosition, void boxText( const wxString& aText, const VECTOR2D& aPosition,
const TEXT_ATTRIBUTES& aAttrs ); const TEXT_ATTRIBUTES& aAttrs );
wxString expandLibItemTextVars( const wxString& aSourceText, const SCH_SYMBOL* aSymbolContext );
public: public:
static std::vector<KICAD_T> g_ScaledSelectionTypes; static std::vector<KICAD_T> g_ScaledSelectionTypes;

View File

@ -1187,7 +1187,7 @@ void SCH_SYMBOL::GetContextualTextVars( wxArrayString* aVars ) const
} }
bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth, const SCH_SHEET_PATH* aPath ) const bool SCH_SYMBOL::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token, int aDepth ) const
{ {
static wxRegEx operatingPoint( wxT( "^" static wxRegEx operatingPoint( wxT( "^"
"OP" "OP"
@ -1197,19 +1197,17 @@ bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth, const SCH_SHEET_PA
SCHEMATIC* schematic = Schematic(); SCHEMATIC* schematic = Schematic();
// SCH_SYMOL object has no context outside a schematic. // SCH_SYMBOL object has no context outside a schematic and the instance on a path.
if( !schematic ) if( !schematic || !aPath )
return false; return false;
SCH_SHEET* sheet = aPath ? aPath->Last() : schematic->CurrentSheet().Last();
if( operatingPoint.Matches( *token ) ) if( operatingPoint.Matches( *token ) )
{ {
wxString port( operatingPoint.GetMatch( *token, 1 ) ); wxString port( operatingPoint.GetMatch( *token, 1 ) );
wxString precisionStr( operatingPoint.GetMatch( *token, 3 ) ); wxString precisionStr( operatingPoint.GetMatch( *token, 3 ) );
wxString range( operatingPoint.GetMatch( *token, 4 ) ); wxString range( operatingPoint.GetMatch( *token, 4 ) );
wxString signal = GetRef( &schematic->CurrentSheet() ) + port; wxString signal = GetRef( aPath ) + port;
int precision = 3; int precision = 3;
if( !precisionStr.IsEmpty() ) if( !precisionStr.IsEmpty() )
@ -1223,7 +1221,7 @@ bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth, const SCH_SHEET_PA
range = wxS( "~A" ); range = wxS( "~A" );
} }
*token = Schematic()->GetOperatingPoint( signal.Lower(), precision, range ); *token = schematic->GetOperatingPoint( signal.Lower(), precision, range );
return true; return true;
} }
@ -1239,7 +1237,7 @@ bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth, const SCH_SHEET_PA
if( token->IsSameAs( m_fields[ i ].GetCanonicalName().Upper() ) ) if( token->IsSameAs( m_fields[ i ].GetCanonicalName().Upper() ) )
{ {
if( i == REFERENCE_FIELD ) if( i == REFERENCE_FIELD )
*token = GetRef( &schematic->CurrentSheet(), true ); *token = GetRef( aPath, true );
else if( i == VALUE_FIELD ) else if( i == VALUE_FIELD )
*token = GetValueFieldText( true, aPath, false ); *token = GetValueFieldText( true, aPath, false );
else if( i == FOOTPRINT_FIELD ) else if( i == FOOTPRINT_FIELD )
@ -1276,9 +1274,7 @@ bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth, const SCH_SHEET_PA
if( token->IsSameAs( wxT( "FOOTPRINT_LIBRARY" ) ) ) if( token->IsSameAs( wxT( "FOOTPRINT_LIBRARY" ) ) )
{ {
wxString footprint; wxString footprint = GetFootprintFieldText( true, aPath, false );
footprint = GetFootprintFieldText( true, aPath, false );
wxArrayString parts = wxSplit( footprint, ':' ); wxArrayString parts = wxSplit( footprint, ':' );
@ -1287,9 +1283,7 @@ bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth, const SCH_SHEET_PA
} }
else if( token->IsSameAs( wxT( "FOOTPRINT_NAME" ) ) ) else if( token->IsSameAs( wxT( "FOOTPRINT_NAME" ) ) )
{ {
wxString footprint; wxString footprint = GetFootprintFieldText( true, aPath, false );
footprint = GetFootprintFieldText( true, aPath, false );
wxArrayString parts = wxSplit( footprint, ':' ); wxArrayString parts = wxSplit( footprint, ':' );
@ -1298,9 +1292,7 @@ bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth, const SCH_SHEET_PA
} }
else if( token->IsSameAs( wxT( "UNIT" ) ) ) else if( token->IsSameAs( wxT( "UNIT" ) ) )
{ {
int unit; int unit = GetUnitSelection( aPath );
unit = GetUnitSelection( &schematic->CurrentSheet() );
*token = LIB_SYMBOL::SubReference( unit ); *token = LIB_SYMBOL::SubReference( unit );
return true; return true;
@ -1344,12 +1336,8 @@ bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth, const SCH_SHEET_PA
} }
// See if parent can resolve it (this will recurse to ancestors) // See if parent can resolve it (this will recurse to ancestors)
if( aPath->Last()->ResolveTextVar( aPath, token, aDepth + 1 ) )
if( sheet ) return true;
{
if( sheet->ResolveTextVar( aPath, token, aDepth + 1 ) )
return true;
}
return false; return false;
} }

View File

@ -330,8 +330,7 @@ public:
* *
* @param aDepth a counter to limit recursion and circular references. * @param aDepth a counter to limit recursion and circular references.
*/ */
bool ResolveTextVar( wxString* token, int aDepth = 0, bool ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token, int aDepth = 0 ) const;
const SCH_SHEET_PATH* aPath = nullptr ) const;
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override; void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;

View File

@ -334,7 +334,7 @@ bool SCHEMATIC::ResolveCrossReference( wxString* token, int aDepth ) const
{ {
SCH_SYMBOL* refSymbol = static_cast<SCH_SYMBOL*>( refItem ); SCH_SYMBOL* refSymbol = static_cast<SCH_SYMBOL*>( refItem );
if( refSymbol->ResolveTextVar( &remainder, aDepth + 1 ) ) if( refSymbol->ResolveTextVar( &sheetPath, &remainder, aDepth + 1 ) )
*token = remainder; *token = remainder;
else else
*token = refSymbol->GetRef( &sheetPath, true ) + wxS( ":" ) + remainder; *token = refSymbol->GetRef( &sheetPath, true ) + wxS( ":" ) + remainder;