diff --git a/eeschema/connection_graph.cpp b/eeschema/connection_graph.cpp index e422fd3b3f..2bb9e020fe 100644 --- a/eeschema/connection_graph.cpp +++ b/eeschema/connection_graph.cpp @@ -337,6 +337,7 @@ wxString CONNECTION_SUBGRAPH::driverName( SCH_ITEM* aItem ) const case SCH_LABEL_T: case SCH_GLOBAL_LABEL_T: case SCH_HIER_LABEL_T: + // NB: any changes here will need corresponding changes in SCH_LABEL_BASE::cacheShownText() return EscapeString( static_cast( aItem )->GetShownText( &m_sheet, false ), CTX_NETNAME ); @@ -357,6 +358,9 @@ wxString CONNECTION_SUBGRAPH::driverName( SCH_ITEM* aItem ) const const wxString& CONNECTION_SUBGRAPH::GetNameForDriver( SCH_ITEM* aItem ) const { + if( aItem->HasCachedDriverName() ) + return aItem->GetCachedDriverName(); + auto it = m_driver_name_cache.find( aItem ); if( it != m_driver_name_cache.end() ) diff --git a/eeschema/sch_item.cpp b/eeschema/sch_item.cpp index 8b311cfc39..1dfe0a271d 100644 --- a/eeschema/sch_item.cpp +++ b/eeschema/sch_item.cpp @@ -253,6 +253,13 @@ SCH_CONNECTION* SCH_ITEM::GetOrInitConnection( const SCH_SHEET_PATH& aSheet, } +const wxString& SCH_ITEM::GetCachedDriverName() const +{ + static wxString s_empty; + return s_empty; +} + + void SCH_ITEM::SwapData( SCH_ITEM* aItem ) { UNIMPLEMENTED_FOR( GetClass() ); diff --git a/eeschema/sch_item.h b/eeschema/sch_item.h index 3e44f721dd..a0abc024e4 100644 --- a/eeschema/sch_item.h +++ b/eeschema/sch_item.h @@ -430,6 +430,9 @@ public: /// Updates the connection graph for all connections in this item void SetConnectionGraph( CONNECTION_GRAPH* aGraph ); + virtual bool HasCachedDriverName() const { return false; } + virtual const wxString& GetCachedDriverName() const; + virtual void SetLastResolvedState( const SCH_ITEM* aItem ) { } std::shared_ptr GetEffectiveNetClass( const SCH_SHEET_PATH* aSheet = nullptr ) const; diff --git a/eeschema/sch_label.cpp b/eeschema/sch_label.cpp index e7f800b088..d6e9bf51df 100644 --- a/eeschema/sch_label.cpp +++ b/eeschema/sch_label.cpp @@ -691,6 +691,27 @@ bool SCH_LABEL_BASE::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* toke } +bool SCH_LABEL_BASE::HasCachedDriverName() const +{ + return !HasTextVars(); +} + + +const wxString& SCH_LABEL_BASE::GetCachedDriverName() const +{ + return m_cached_driver_name; +} + + +void SCH_LABEL_BASE::cacheShownText() +{ + EDA_TEXT::cacheShownText(); + + if( !HasTextVars() ) + m_cached_driver_name = EscapeString( EDA_TEXT::GetShownText( true, 0 ), CTX_NETNAME ); +} + + wxString SCH_LABEL_BASE::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText, int aDepth ) const { diff --git a/eeschema/sch_label.h b/eeschema/sch_label.h index d08cd57f09..36d0578603 100644 --- a/eeschema/sch_label.h +++ b/eeschema/sch_label.h @@ -156,6 +156,9 @@ public: return GetShownText( nullptr, aAllowExtraText, aDepth ); } + bool HasCachedDriverName() const override; + const wxString& GetCachedDriverName() const override; + void RunOnChildren( const std::function& aFunction ) override; INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, @@ -231,6 +234,9 @@ public: */ virtual bool AutoRotateOnPlacementSupported() const = 0; +protected: + void cacheShownText() override; + protected: std::vector m_fields; @@ -241,6 +247,8 @@ protected: bool m_autoRotateOnPlacement = false; mutable COLOR4D m_lastResolvedColor; + + wxString m_cached_driver_name; }; diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index f2a56a1167..63bfb96e94 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -356,8 +356,8 @@ wxString SCH_TEXT::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraTe if( aPath ) sheet = aPath->Last(); - else if( Schematic() ) - sheet = Schematic()->CurrentSheet().Last(); + else if( SCHEMATIC* schematic = Schematic() ) + sheet = schematic->CurrentSheet().Last(); std::function textResolver = [&]( wxString* token ) -> bool diff --git a/include/eda_text.h b/include/eda_text.h index 57714f808a..b305a60778 100644 --- a/include/eda_text.h +++ b/include/eda_text.h @@ -368,7 +368,7 @@ protected: virtual const KIFONT::METRICS& getFontMetrics() const; - void cacheShownText(); + virtual void cacheShownText(); /** * Print each line of this EDA_TEXT.