Performance enhancements.

This commit is contained in:
Jeff Young 2020-04-24 21:33:59 +01:00
parent 32db9eb0f1
commit 2fb2eac4d5
8 changed files with 73 additions and 41 deletions

View File

@ -379,6 +379,8 @@ wxString ExpandTextVars( const wxString& aSource,
wxString newbuf; wxString newbuf;
size_t sourceLen = aSource.length(); size_t sourceLen = aSource.length();
newbuf.Alloc( sourceLen ); // best guess (improves performance)
for( size_t i = 0; i < sourceLen; ++i ) for( size_t i = 0; i < sourceLen; ++i )
{ {
if( aSource[i] == '$' && i + 1 < sourceLen && aSource[i+1] == '{' ) if( aSource[i] == '$' && i + 1 < sourceLen && aSource[i+1] == '{' )
@ -428,7 +430,7 @@ wxString KIwxExpandEnvVars( const wxString& str, const PROJECT* aProject )
size_t strlen = str.length(); size_t strlen = str.length();
wxString strResult; wxString strResult;
strResult.Alloc( strlen ); strResult.Alloc( strlen ); // best guess (improves performance)
for( size_t n = 0; n < strlen; n++ ) for( size_t n = 0; n < strlen; n++ )
{ {

View File

@ -91,7 +91,10 @@ EDA_TEXT::EDA_TEXT( const wxString& text ) :
SetTextSize( wxSize( sz, sz ) ); SetTextSize( wxSize( sz, sz ) );
if( !text.IsEmpty() ) if( !text.IsEmpty() )
{
m_shown_text = UnescapeString( text ); m_shown_text = UnescapeString( text );
m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
}
} }
@ -100,6 +103,7 @@ EDA_TEXT::EDA_TEXT( const EDA_TEXT& aText ) :
m_e( aText.m_e ) m_e( aText.m_e )
{ {
m_shown_text = UnescapeString( m_text ); m_shown_text = UnescapeString( m_text );
m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
} }
@ -112,6 +116,7 @@ void EDA_TEXT::SetText( const wxString& aText )
{ {
m_text = aText; m_text = aText;
m_shown_text = UnescapeString( aText ); m_shown_text = UnescapeString( aText );
m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
} }
@ -119,6 +124,7 @@ void EDA_TEXT::CopyText( const EDA_TEXT& aSrc )
{ {
m_text = aSrc.m_text; m_text = aSrc.m_text;
m_shown_text = aSrc.m_shown_text; m_shown_text = aSrc.m_shown_text;
m_shown_text_has_text_var_refs = aSrc.m_shown_text_has_text_var_refs;
} }
@ -132,6 +138,7 @@ void EDA_TEXT::SwapText( EDA_TEXT& aTradingPartner )
{ {
std::swap( m_text, aTradingPartner.m_text ); std::swap( m_text, aTradingPartner.m_text );
std::swap( m_shown_text, aTradingPartner.m_shown_text ); std::swap( m_shown_text, aTradingPartner.m_shown_text );
std::swap( m_shown_text_has_text_var_refs, aTradingPartner.m_shown_text_has_text_var_refs );
} }
@ -164,6 +171,7 @@ bool EDA_TEXT::Replace( wxFindReplaceData& aSearchData )
{ {
bool retval = EDA_ITEM::Replace( aSearchData, m_text ); bool retval = EDA_ITEM::Replace( aSearchData, m_text );
m_shown_text = UnescapeString( m_text ); m_shown_text = UnescapeString( m_text );
m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
return retval; return retval;
} }

View File

@ -90,19 +90,23 @@ wxString SCH_FIELD::GetShownText( int aDepth ) const
}; };
PROJECT* project = nullptr; PROJECT* project = nullptr;
wxString text = EDA_TEXT::GetShownText(); bool processTextVars = false;
wxString text = EDA_TEXT::GetShownText( &processTextVars );
if( g_RootSheet && g_RootSheet->GetScreen() ) if( processTextVars )
project = &g_RootSheet->GetScreen()->Kiway().Prj();
if( aDepth < 10 )
{ {
if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T ) if( g_RootSheet && g_RootSheet->GetScreen() )
text = ExpandTextVars( text, &symbolResolver, project ); project = &g_RootSheet->GetScreen()->Kiway().Prj();
else if( m_Parent && m_Parent->Type() == SCH_SHEET_T )
text = ExpandTextVars( text, &sheetResolver, project ); if( aDepth < 10 )
else {
text = ExpandTextVars( text, nullptr, project ); if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T )
text = ExpandTextVars( text, &symbolResolver, project );
else if( m_Parent && m_Parent->Type() == SCH_SHEET_T )
text = ExpandTextVars( text, &sheetResolver, project );
else
text = ExpandTextVars( text, nullptr, project );
}
} }
// WARNING: the IDs of FIELDS and SHEETS overlap, so one must check *both* the // WARNING: the IDs of FIELDS and SHEETS overlap, so one must check *both* the
@ -204,11 +208,7 @@ void SCH_FIELD::SwapData( SCH_ITEM* aItem )
const EDA_RECT SCH_FIELD::GetBoundingBox() const const EDA_RECT SCH_FIELD::GetBoundingBox() const
{ {
// Calculate the text bounding box: // Calculate the text bounding box:
EDA_RECT rect; EDA_RECT rect = GetTextBox();
SCH_FIELD text( *this ); // Make a local copy to change text
// because GetBoundingBox() is const
text.SetText( GetShownText() );
rect = text.GetTextBox();
// Calculate the bounding box position relative to the parent: // Calculate the bounding box position relative to the parent:
wxPoint origin = GetParentPosition(); wxPoint origin = GetParentPosition();

View File

@ -602,9 +602,9 @@ void SCH_PAINTER::draw( LIB_FIELD *aField, int aLayer )
COLOR4D color = getRenderColor( aField, aLayer, drawingShadows ); COLOR4D color = getRenderColor( aField, aLayer, drawingShadows );
if( !aField->IsVisible() ) if( !( aField->IsVisible() || aField->IsForceVisible() ) )
{ {
if( m_schSettings.m_ShowHiddenText || aField->IsBrightened() ) if( m_schSettings.m_ShowHiddenText )
color = getRenderColor( aField, LAYER_HIDDEN, drawingShadows ); color = getRenderColor( aField, LAYER_HIDDEN, drawingShadows );
else else
return; return;
@ -666,7 +666,7 @@ void SCH_PAINTER::draw( LIB_TEXT *aText, int aLayer )
if( !aText->IsVisible() ) if( !aText->IsVisible() )
{ {
if( m_schSettings.m_ShowHiddenText || aText->IsBrightened() ) if( m_schSettings.m_ShowHiddenText )
color = getRenderColor( aText, LAYER_HIDDEN, drawingShadows ); color = getRenderColor( aText, LAYER_HIDDEN, drawingShadows );
else else
return; return;
@ -1265,9 +1265,9 @@ void SCH_PAINTER::draw( SCH_TEXT *aText, int aLayer )
if( conn && conn->IsBus() ) if( conn && conn->IsBus() )
color = getRenderColor( aText, LAYER_BUS, drawingShadows ); color = getRenderColor( aText, LAYER_BUS, drawingShadows );
if( !aText->IsVisible() ) if( !( aText->IsVisible() || aText->IsForceVisible() ) )
{ {
if( m_schSettings.m_ShowHiddenText || aText->IsBrightened() ) if( m_schSettings.m_ShowHiddenText )
color = getRenderColor( aText, LAYER_HIDDEN, drawingShadows ); color = getRenderColor( aText, LAYER_HIDDEN, drawingShadows );
else else
return; return;
@ -1430,7 +1430,7 @@ void SCH_PAINTER::draw( SCH_FIELD *aField, int aLayer )
if( !( aField->IsVisible() || aField->IsForceVisible() ) ) if( !( aField->IsVisible() || aField->IsForceVisible() ) )
{ {
if( m_schSettings.m_ShowHiddenText || aField->IsBrightened() ) if( m_schSettings.m_ShowHiddenText )
color = getRenderColor( aField, LAYER_HIDDEN, drawingShadows ); color = getRenderColor( aField, LAYER_HIDDEN, drawingShadows );
else else
return; return;

View File

@ -509,15 +509,19 @@ wxString SCH_TEXT::GetShownText( int aDepth ) const
return false; return false;
}; };
PROJECT* project = nullptr; bool processTextVars = false;
wxString text = EDA_TEXT::GetShownText( &processTextVars );
if( g_RootSheet && g_RootSheet->GetScreen() ) if( processTextVars )
project = &g_RootSheet->GetScreen()->Kiway().Prj(); {
PROJECT* project = nullptr;
wxString text = EDA_TEXT::GetShownText( aDepth ); if( g_RootSheet && g_RootSheet->GetScreen() )
project = &g_RootSheet->GetScreen()->Kiway().Prj();
if( aDepth < 10 ) if( aDepth < 10 )
text = ExpandTextVars( text, &textResolver, project ); text = ExpandTextVars( text, &textResolver, project );
}
return text; return text;
} }

View File

@ -132,6 +132,17 @@ public:
*/ */
virtual wxString GetShownText( int aDepth = 0 ) const { return m_shown_text; } virtual wxString GetShownText( int aDepth = 0 ) const { return m_shown_text; }
/**
* A version of GetShownText() which also indicates whether or not the text needs
* to be processed for text variables.
* @param processTextVars [out]
*/
wxString GetShownText( bool* processTextVars ) const
{
*processTextVars = m_shown_text_has_text_var_refs;
return m_shown_text;
}
/** /**
* Returns a shortened version (max 15 characters) of the shown text * Returns a shortened version (max 15 characters) of the shown text
*/ */
@ -350,10 +361,11 @@ public:
private: private:
wxString m_text; wxString m_text;
wxString m_shown_text; // Cache of unescaped text for efficient access wxString m_shown_text; // Cache of unescaped text for efficient access
bool m_shown_text_has_text_var_refs;
TEXT_EFFECTS m_e; // Private bitflags for text styling. API above TEXT_EFFECTS m_e; // Private bitflags for text styling. API above
// provides accessor funcs. // provides accessor funcs.
enum TE_FLAGS { enum TE_FLAGS {
TE_MIRROR, TE_MIRROR,
TE_ITALIC, TE_ITALIC,

View File

@ -96,9 +96,10 @@ wxString TEXTE_PCB::GetShownText( int aDepth ) const
return false; return false;
}; };
wxString text = EDA_TEXT::GetShownText( aDepth ); bool processTextVars = false;
wxString text = EDA_TEXT::GetShownText( &processTextVars );
if( aDepth < 10 ) if( processTextVars && aDepth < 10 )
text = ExpandTextVars( text, &pcbTextResolver, board->GetProject() ); text = ExpandTextVars( text, &pcbTextResolver, board->GetProject() );
return text; return text;

View File

@ -381,7 +381,7 @@ const BOX2I TEXTE_MODULE::ViewBBox() const
double angle = GetDrawRotation(); double angle = GetDrawRotation();
EDA_RECT text_area = GetTextBox(); EDA_RECT text_area = GetTextBox();
if( angle ) if( angle != 0.0 )
text_area = text_area.GetBoundingBoxRotated( GetTextPos(), angle ); text_area = text_area.GetBoundingBoxRotated( GetTextPos(), angle );
return BOX2I( text_area.GetPosition(), text_area.GetSize() ); return BOX2I( text_area.GetPosition(), text_area.GetSize() );
@ -448,14 +448,19 @@ wxString TEXTE_MODULE::GetShownText( int aDepth ) const
return module && module->ResolveTextVar( token, aDepth ); return module && module->ResolveTextVar( token, aDepth );
}; };
PROJECT* project = nullptr; bool processTextVars = false;
wxString text = EDA_TEXT::GetShownText( aDepth ); wxString text = EDA_TEXT::GetShownText( &processTextVars );
if( module && module->GetParent() ) if( processTextVars )
project = static_cast<BOARD*>( module->GetParent() )->GetProject(); {
PROJECT* project = nullptr;
if( aDepth < 10 ) if( module && module->GetParent() )
text = ExpandTextVars( text, &moduleResolver, project ); project = static_cast<BOARD*>( module->GetParent() )->GetProject();
if( aDepth < 10 )
text = ExpandTextVars( text, &moduleResolver, project );
}
return text; return text;
} }