Performance enhancements.
This commit is contained in:
parent
32db9eb0f1
commit
2fb2eac4d5
|
@ -379,6 +379,8 @@ wxString ExpandTextVars( const wxString& aSource,
|
|||
wxString newbuf;
|
||||
size_t sourceLen = aSource.length();
|
||||
|
||||
newbuf.Alloc( sourceLen ); // best guess (improves performance)
|
||||
|
||||
for( size_t i = 0; i < sourceLen; ++i )
|
||||
{
|
||||
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();
|
||||
|
||||
wxString strResult;
|
||||
strResult.Alloc( strlen );
|
||||
strResult.Alloc( strlen ); // best guess (improves performance)
|
||||
|
||||
for( size_t n = 0; n < strlen; n++ )
|
||||
{
|
||||
|
|
|
@ -91,7 +91,10 @@ EDA_TEXT::EDA_TEXT( const wxString& text ) :
|
|||
SetTextSize( wxSize( sz, sz ) );
|
||||
|
||||
if( !text.IsEmpty() )
|
||||
{
|
||||
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_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_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_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_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 );
|
||||
m_shown_text = UnescapeString( m_text );
|
||||
m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) );
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
|
|
@ -90,8 +90,11 @@ wxString SCH_FIELD::GetShownText( int aDepth ) const
|
|||
};
|
||||
|
||||
PROJECT* project = nullptr;
|
||||
wxString text = EDA_TEXT::GetShownText();
|
||||
bool processTextVars = false;
|
||||
wxString text = EDA_TEXT::GetShownText( &processTextVars );
|
||||
|
||||
if( processTextVars )
|
||||
{
|
||||
if( g_RootSheet && g_RootSheet->GetScreen() )
|
||||
project = &g_RootSheet->GetScreen()->Kiway().Prj();
|
||||
|
||||
|
@ -104,6 +107,7 @@ wxString SCH_FIELD::GetShownText( int aDepth ) const
|
|||
else
|
||||
text = ExpandTextVars( text, nullptr, project );
|
||||
}
|
||||
}
|
||||
|
||||
// WARNING: the IDs of FIELDS and SHEETS overlap, so one must check *both* the
|
||||
// id and the parent's type.
|
||||
|
@ -204,11 +208,7 @@ void SCH_FIELD::SwapData( SCH_ITEM* aItem )
|
|||
const EDA_RECT SCH_FIELD::GetBoundingBox() const
|
||||
{
|
||||
// Calculate the text bounding box:
|
||||
EDA_RECT rect;
|
||||
SCH_FIELD text( *this ); // Make a local copy to change text
|
||||
// because GetBoundingBox() is const
|
||||
text.SetText( GetShownText() );
|
||||
rect = text.GetTextBox();
|
||||
EDA_RECT rect = GetTextBox();
|
||||
|
||||
// Calculate the bounding box position relative to the parent:
|
||||
wxPoint origin = GetParentPosition();
|
||||
|
|
|
@ -602,9 +602,9 @@ void SCH_PAINTER::draw( LIB_FIELD *aField, int aLayer )
|
|||
|
||||
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 );
|
||||
else
|
||||
return;
|
||||
|
@ -666,7 +666,7 @@ void SCH_PAINTER::draw( LIB_TEXT *aText, int aLayer )
|
|||
|
||||
if( !aText->IsVisible() )
|
||||
{
|
||||
if( m_schSettings.m_ShowHiddenText || aText->IsBrightened() )
|
||||
if( m_schSettings.m_ShowHiddenText )
|
||||
color = getRenderColor( aText, LAYER_HIDDEN, drawingShadows );
|
||||
else
|
||||
return;
|
||||
|
@ -1265,9 +1265,9 @@ void SCH_PAINTER::draw( SCH_TEXT *aText, int aLayer )
|
|||
if( conn && conn->IsBus() )
|
||||
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 );
|
||||
else
|
||||
return;
|
||||
|
@ -1430,7 +1430,7 @@ void SCH_PAINTER::draw( SCH_FIELD *aField, int aLayer )
|
|||
|
||||
if( !( aField->IsVisible() || aField->IsForceVisible() ) )
|
||||
{
|
||||
if( m_schSettings.m_ShowHiddenText || aField->IsBrightened() )
|
||||
if( m_schSettings.m_ShowHiddenText )
|
||||
color = getRenderColor( aField, LAYER_HIDDEN, drawingShadows );
|
||||
else
|
||||
return;
|
||||
|
|
|
@ -509,15 +509,19 @@ wxString SCH_TEXT::GetShownText( int aDepth ) const
|
|||
return false;
|
||||
};
|
||||
|
||||
bool processTextVars = false;
|
||||
wxString text = EDA_TEXT::GetShownText( &processTextVars );
|
||||
|
||||
if( processTextVars )
|
||||
{
|
||||
PROJECT* project = nullptr;
|
||||
|
||||
if( g_RootSheet && g_RootSheet->GetScreen() )
|
||||
project = &g_RootSheet->GetScreen()->Kiway().Prj();
|
||||
|
||||
wxString text = EDA_TEXT::GetShownText( aDepth );
|
||||
|
||||
if( aDepth < 10 )
|
||||
text = ExpandTextVars( text, &textResolver, project );
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
|
|
@ -132,6 +132,17 @@ public:
|
|||
*/
|
||||
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
|
||||
*/
|
||||
|
@ -351,6 +362,7 @@ public:
|
|||
private:
|
||||
wxString m_text;
|
||||
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
|
||||
// provides accessor funcs.
|
||||
|
|
|
@ -96,9 +96,10 @@ wxString TEXTE_PCB::GetShownText( int aDepth ) const
|
|||
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() );
|
||||
|
||||
return text;
|
||||
|
|
|
@ -381,7 +381,7 @@ const BOX2I TEXTE_MODULE::ViewBBox() const
|
|||
double angle = GetDrawRotation();
|
||||
EDA_RECT text_area = GetTextBox();
|
||||
|
||||
if( angle )
|
||||
if( angle != 0.0 )
|
||||
text_area = text_area.GetBoundingBoxRotated( GetTextPos(), angle );
|
||||
|
||||
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 );
|
||||
};
|
||||
|
||||
bool processTextVars = false;
|
||||
wxString text = EDA_TEXT::GetShownText( &processTextVars );
|
||||
|
||||
if( processTextVars )
|
||||
{
|
||||
PROJECT* project = nullptr;
|
||||
wxString text = EDA_TEXT::GetShownText( aDepth );
|
||||
|
||||
if( module && module->GetParent() )
|
||||
project = static_cast<BOARD*>( module->GetParent() )->GetProject();
|
||||
|
||||
if( aDepth < 10 )
|
||||
text = ExpandTextVars( text, &moduleResolver, project );
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue