Implement better sheet-path awareness for label text var resolution.
(cherry picked from commit 4b0027a5d7
)
This commit is contained in:
parent
21eb2c8dad
commit
d3311ee231
|
@ -172,12 +172,13 @@ void SCH_FIELD::SetId( int aId )
|
|||
}
|
||||
|
||||
|
||||
wxString SCH_FIELD::GetShownText( int aDepth, bool aAllowExtraText ) const
|
||||
wxString SCH_FIELD::GetShownText( const SCH_SHEET_PATH* aPath, int aDepth,
|
||||
bool aAllowExtraText ) const
|
||||
{
|
||||
std::function<bool( wxString* )> symbolResolver =
|
||||
[&]( wxString* token ) -> bool
|
||||
{
|
||||
return static_cast<SCH_SYMBOL*>( m_parent )->ResolveTextVar( token, aDepth + 1 );
|
||||
return static_cast<SCH_SYMBOL*>( m_parent )->ResolveTextVar( token, aDepth + 1, aPath );
|
||||
};
|
||||
|
||||
std::function<bool( wxString* )> sheetResolver =
|
||||
|
@ -189,7 +190,7 @@ wxString SCH_FIELD::GetShownText( int aDepth, bool aAllowExtraText ) const
|
|||
std::function<bool( wxString* )> labelResolver =
|
||||
[&]( wxString* token ) -> bool
|
||||
{
|
||||
return static_cast<SCH_LABEL_BASE*>( m_parent )->ResolveTextVar( token,
|
||||
return static_cast<SCH_LABEL_BASE*>( m_parent )->ResolveTextVar( aPath, token,
|
||||
aDepth + 1 );
|
||||
};
|
||||
|
||||
|
|
|
@ -126,7 +126,13 @@ public:
|
|||
|
||||
void SetId( int aId );
|
||||
|
||||
wxString GetShownText( int aDepth = 0, bool aAllowExtraText = true ) const override;
|
||||
wxString GetShownText( const SCH_SHEET_PATH* aPath, int aDepth = 0,
|
||||
bool aAllowExtraText = true ) const;
|
||||
|
||||
wxString GetShownText( int aDepth = 0, bool aAllowExtraText = true ) const override
|
||||
{
|
||||
return GetShownText( nullptr, aDepth, aAllowExtraText );
|
||||
}
|
||||
|
||||
COLOR4D GetFieldColor() const;
|
||||
|
||||
|
|
|
@ -494,7 +494,8 @@ void SCH_LABEL_BASE::GetIntersheetRefs( std::vector<std::pair<wxString, wxString
|
|||
}
|
||||
|
||||
|
||||
bool SCH_LABEL_BASE::ResolveTextVar( wxString* token, int aDepth ) const
|
||||
bool SCH_LABEL_BASE::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token,
|
||||
int aDepth ) const
|
||||
{
|
||||
if( !Schematic() )
|
||||
return false;
|
||||
|
@ -543,11 +544,11 @@ bool SCH_LABEL_BASE::ResolveTextVar( wxString* token, int aDepth ) const
|
|||
return true;
|
||||
}
|
||||
|
||||
for( size_t i = 0; i < m_fields.size(); ++i )
|
||||
for( const SCH_FIELD& field : m_fields)
|
||||
{
|
||||
if( token->IsSameAs( m_fields[i].GetName() ) )
|
||||
if( token->IsSameAs( field.GetName() ) )
|
||||
{
|
||||
*token = m_fields[i].GetShownText( aDepth + 1 );
|
||||
*token = field.GetShownText( aDepth + 1 );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -561,9 +562,14 @@ bool SCH_LABEL_BASE::ResolveTextVar( wxString* token, int aDepth ) const
|
|||
if( sheet->ResolveTextVar( token, aDepth + 1 ) )
|
||||
return true;
|
||||
}
|
||||
else if( aPath && aPath->Last() )
|
||||
{
|
||||
if( aPath->Last()->ResolveTextVar( aPath, token, aDepth + 1 ) )
|
||||
return true;
|
||||
}
|
||||
else if( SCH_SHEET* sheet = Schematic()->CurrentSheet().Last() )
|
||||
{
|
||||
if( sheet->ResolveTextVar( token, aDepth + 1 ) )
|
||||
if( sheet->ResolveTextVar( aPath, token, aDepth + 1 ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -571,12 +577,12 @@ bool SCH_LABEL_BASE::ResolveTextVar( wxString* token, int aDepth ) const
|
|||
}
|
||||
|
||||
|
||||
wxString SCH_LABEL_BASE::GetShownText( int aDepth, bool aAllowExtraText ) const
|
||||
wxString SCH_LABEL_BASE::GetShownText( const SCH_SHEET_PATH* aPath, int aDepth, bool aAllowExtraText ) const
|
||||
{
|
||||
std::function<bool( wxString* )> textResolver =
|
||||
[&]( wxString* token ) -> bool
|
||||
{
|
||||
return ResolveTextVar( token, aDepth );
|
||||
return ResolveTextVar( aPath, token, aDepth );
|
||||
};
|
||||
|
||||
wxString text = EDA_TEXT::GetShownText();
|
||||
|
@ -1386,7 +1392,8 @@ void SCH_GLOBALLABEL::MirrorVertically( int aCenter )
|
|||
}
|
||||
|
||||
|
||||
bool SCH_GLOBALLABEL::ResolveTextVar( wxString* token, int aDepth ) const
|
||||
bool SCH_GLOBALLABEL::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token,
|
||||
int aDepth ) const
|
||||
{
|
||||
if( token->IsSameAs( wxT( "INTERSHEET_REFS" ) ) && Schematic() )
|
||||
{
|
||||
|
@ -1433,7 +1440,7 @@ bool SCH_GLOBALLABEL::ResolveTextVar( wxString* token, int aDepth ) const
|
|||
return true;
|
||||
}
|
||||
|
||||
return SCH_LABEL_BASE::ResolveTextVar( token, aDepth );
|
||||
return SCH_LABEL_BASE::ResolveTextVar( aPath, token, aDepth );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -126,9 +126,20 @@ public:
|
|||
*/
|
||||
void GetIntersheetRefs( std::vector<std::pair<wxString, wxString>>* pages );
|
||||
|
||||
virtual bool ResolveTextVar( wxString* token, int aDepth ) const;
|
||||
/**
|
||||
* Resolve any references to system tokens supported by the label.
|
||||
*
|
||||
* @param aDepth a counter to limit recursion and circular references.
|
||||
*/
|
||||
virtual bool ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token, int aDepth ) const;
|
||||
|
||||
wxString GetShownText( int aDepth = 0, bool aAllowExtraText = true ) const override;
|
||||
wxString GetShownText( const SCH_SHEET_PATH* aPath, int aDepth = 0,
|
||||
bool aAllowExtraText = true ) const override;
|
||||
|
||||
wxString GetShownText( int aDepth = 0, bool aAllowExtraText = true ) const override
|
||||
{
|
||||
return GetShownText( nullptr, aDepth, aAllowExtraText );
|
||||
}
|
||||
|
||||
void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) override;
|
||||
|
||||
|
@ -353,7 +364,7 @@ public:
|
|||
void CreateGraphicShape( const RENDER_SETTINGS* aRenderSettings, std::vector<VECTOR2I>& aPoints,
|
||||
const VECTOR2I& aPos ) const override;
|
||||
|
||||
bool ResolveTextVar( wxString* token, int aDepth ) const override;
|
||||
bool ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token, int aDepth ) const override;
|
||||
|
||||
bool IsConnectable() const override { return true; }
|
||||
|
||||
|
|
|
@ -234,7 +234,7 @@ void SCH_SHEET::GetContextualTextVars( wxArrayString* aVars ) const
|
|||
}
|
||||
|
||||
|
||||
bool SCH_SHEET::ResolveTextVar( wxString* token, int aDepth ) const
|
||||
bool SCH_SHEET::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token, int aDepth ) const
|
||||
{
|
||||
if( !Schematic() )
|
||||
return false;
|
||||
|
@ -291,13 +291,13 @@ bool SCH_SHEET::ResolveTextVar( wxString* token, int aDepth ) const
|
|||
|
||||
// See if parent can resolve it (these will recurse to ancestors)
|
||||
|
||||
SCH_SHEET_PATH sheetPath = findSelf();
|
||||
SCH_SHEET_PATH sheetPath = aPath ? *aPath : findSelf();
|
||||
|
||||
if( sheetPath.size() >= 2 )
|
||||
{
|
||||
sheetPath.pop_back();
|
||||
|
||||
if( sheetPath.Last()->ResolveTextVar( token, aDepth + 1 ) )
|
||||
if( sheetPath.Last()->ResolveTextVar( aPath, token, aDepth + 1 ) )
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -152,7 +152,11 @@ public:
|
|||
*
|
||||
* @param aDepth is a counter to limit recursion and circular references.
|
||||
*/
|
||||
bool ResolveTextVar( wxString* token, int aDepth = 0 ) const;
|
||||
bool ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token, int aDepth = 0 ) const;
|
||||
bool ResolveTextVar( wxString* token, int aDepth = 0 )
|
||||
{
|
||||
return ResolveTextVar( nullptr, token, aDepth );
|
||||
}
|
||||
|
||||
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
|
||||
|
||||
|
|
|
@ -827,10 +827,10 @@ void SCH_SYMBOL::SetUnitSelection( int aUnitSelection )
|
|||
}
|
||||
|
||||
|
||||
const wxString SCH_SYMBOL::GetValueFieldText( bool aResolve ) const
|
||||
const wxString SCH_SYMBOL::GetValueFieldText( bool aResolve, const SCH_SHEET_PATH* aPath ) const
|
||||
{
|
||||
if( aResolve )
|
||||
return GetField( VALUE_FIELD )->GetShownText();
|
||||
return GetField( VALUE_FIELD )->GetShownText( aPath );
|
||||
|
||||
return GetField( VALUE_FIELD )->GetText();
|
||||
}
|
||||
|
@ -1155,7 +1155,7 @@ void SCH_SYMBOL::GetContextualTextVars( wxArrayString* aVars ) const
|
|||
}
|
||||
|
||||
|
||||
bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth ) const
|
||||
bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth, const SCH_SHEET_PATH* aPath ) const
|
||||
{
|
||||
SCHEMATIC* schematic = Schematic();
|
||||
|
||||
|
@ -1163,6 +1163,8 @@ bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth ) const
|
|||
if( !schematic )
|
||||
return false;
|
||||
|
||||
SCH_SHEET* sheet = aPath ? aPath->Last() : schematic->CurrentSheet().Last();
|
||||
|
||||
if( token->Contains( ':' ) )
|
||||
{
|
||||
if( schematic->ResolveCrossReference( token, aDepth + 1 ) )
|
||||
|
@ -1278,9 +1280,9 @@ bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth ) const
|
|||
|
||||
// See if parent can resolve it (this will recurse to ancestors)
|
||||
|
||||
if( SCH_SHEET* sheet = schematic->CurrentSheet().Last() )
|
||||
if( sheet )
|
||||
{
|
||||
if( sheet->ResolveTextVar( token, aDepth + 1 ) )
|
||||
if( sheet->ResolveTextVar( aPath, token, aDepth + 1 ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -327,7 +327,8 @@ public:
|
|||
*
|
||||
* @param aDepth a counter to limit recursion and circular references.
|
||||
*/
|
||||
bool ResolveTextVar( wxString* token, int aDepth = 0 ) const;
|
||||
bool ResolveTextVar( wxString* token, int aDepth = 0,
|
||||
const SCH_SHEET_PATH* aPath = nullptr ) const;
|
||||
|
||||
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
|
||||
|
||||
|
@ -461,7 +462,7 @@ public:
|
|||
m_fields = aFields; // vector copying, length is changed possibly
|
||||
}
|
||||
|
||||
const wxString GetValueFieldText( bool aResolve ) const;
|
||||
const wxString GetValueFieldText( bool aResolve, const SCH_SHEET_PATH* aPath = nullptr ) const;
|
||||
void SetValueFieldText( const wxString& aValue );
|
||||
|
||||
const wxString GetFootprintFieldText( bool aResolve ) const;
|
||||
|
|
|
@ -339,14 +339,21 @@ const BOX2I SCH_TEXT::GetBoundingBox() const
|
|||
}
|
||||
|
||||
|
||||
wxString SCH_TEXT::GetShownText( int aDepth, bool aAllowExtraText ) const
|
||||
wxString SCH_TEXT::GetShownText( const SCH_SHEET_PATH* aPath, int aDepth, bool aAllowExtraText ) const
|
||||
{
|
||||
SCH_SHEET* sheet = nullptr;
|
||||
|
||||
if( aPath )
|
||||
sheet = aPath->Last();
|
||||
else if( Schematic() )
|
||||
sheet = Schematic()->CurrentSheet().Last();
|
||||
|
||||
std::function<bool( wxString* )> textResolver =
|
||||
[&]( wxString* token ) -> bool
|
||||
{
|
||||
if( SCH_SHEET* sheet = Schematic()->CurrentSheet().Last() )
|
||||
if( sheet )
|
||||
{
|
||||
if( sheet->ResolveTextVar( token, aDepth + 1 ) )
|
||||
if( sheet->ResolveTextVar( aPath, token, aDepth + 1 ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -128,7 +128,13 @@ public:
|
|||
return wxT( "SCH_TEXT" );
|
||||
}
|
||||
|
||||
wxString GetShownText( int aDepth = 0, bool aAllowExtraText = true ) const override;
|
||||
virtual wxString GetShownText( const SCH_SHEET_PATH* aPath, int aDepth = 0,
|
||||
bool aAllowExtraText = true ) const;
|
||||
|
||||
wxString GetShownText( int aDepth = 0, bool aAllowExtraText = true ) const override
|
||||
{
|
||||
return GetShownText( nullptr, aDepth, aAllowExtraText );
|
||||
}
|
||||
|
||||
bool IsHypertext() const override
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue