diff --git a/eeschema/highlight_connection.cpp b/eeschema/highlight_connection.cpp index 37d4980701..7597699d2f 100644 --- a/eeschema/highlight_connection.cpp +++ b/eeschema/highlight_connection.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -93,38 +94,54 @@ bool SCH_EDIT_FRAME::SetCurrentSheetHighlightFlags( std::vector* aIte if( !screen ) return true; - // Disable highlight flag on all items in the current screen for( SCH_ITEM* ptr = screen->GetDrawItems(); ptr; ptr = ptr->Next() ) { auto conn = ptr->Connection( *g_CurrentSheet ); - bool bright = ptr->GetState( BRIGHTENED ); - - if( bright && aItemsToRedrawList ) - aItemsToRedrawList->push_back( ptr ); + bool redraw = ptr->GetState( BRIGHTENED ); ptr->SetState( BRIGHTENED, ( conn && conn->Name() == m_SelectedNetName ) ); - if( !bright && ptr->GetState( BRIGHTENED ) && aItemsToRedrawList ) - aItemsToRedrawList->push_back( ptr ); + redraw |= ptr->GetState( BRIGHTENED ); - if( ptr->Type() == SCH_SHEET_T ) + if( ptr->Type() == SCH_COMPONENT_T ) + { + SCH_COMPONENT* comp = static_cast( ptr ); + + redraw |= comp->HasBrightenedPins(); + + comp->ClearBrightenedPins(); + std::vector pins; + comp->GetPins( pins ); + + for( LIB_PIN* pin : pins ) + { + auto pin_conn = comp->GetConnectionForPin( pin, *g_CurrentSheet ); + + if( pin_conn && pin_conn->Name( false, true ) == m_SelectedNetName ) + { + comp->BrightenPin( pin ); + redraw = true; + } + } + } + else if( ptr->Type() == SCH_SHEET_T ) { for( SCH_SHEET_PIN& pin : static_cast( ptr )->GetPins() ) { auto pin_conn = pin.Connection( *g_CurrentSheet ); + bool redrawPin = pin.GetState( BRIGHTENED ); - bright = pin.GetState( BRIGHTENED ); + pin.SetState( BRIGHTENED, ( pin_conn && pin_conn->Name() == m_SelectedNetName ) ); - if( bright && aItemsToRedrawList ) - aItemsToRedrawList->push_back( &pin ); + redrawPin |= pin.GetState( BRIGHTENED ); - pin.SetState( BRIGHTENED, ( pin_conn && - pin_conn->Name() == m_SelectedNetName ) ); - - if( !bright && pin.GetState( BRIGHTENED ) && aItemsToRedrawList ) + if( redrawPin && aItemsToRedrawList ) aItemsToRedrawList->push_back( &pin ); } } + + if( redraw && aItemsToRedrawList ) + aItemsToRedrawList->push_back( ptr ); } if( m_SelectedNetName == "" ) diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp index 7c63a54026..20c5d453c4 100644 --- a/eeschema/lib_pin.cpp +++ b/eeschema/lib_pin.cpp @@ -1774,14 +1774,10 @@ void LIB_PIN::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > #if defined(DEBUG) - if( auto pin_connection = aComponent->GetConnectionForPin( this ) ) - { - auto conn = pin_connection->Connection( *g_CurrentSheet ); - - wxASSERT( conn ); + auto conn = aComponent->GetConnectionForPin( this, *g_CurrentSheet ); + if( conn ) conn->AppendDebugInfoToMsgPanel( aList ); - } #endif } diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp index e15e2b5ba8..b9833800f6 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.cpp @@ -566,17 +566,17 @@ void SCH_COMPONENT::UpdatePinConnections( SCH_SHEET_PATH aSheet ) } -SCH_PIN_CONNECTION* SCH_COMPONENT::GetConnectionForPin( LIB_PIN* aPin ) +SCH_CONNECTION* SCH_COMPONENT::GetConnectionForPin( LIB_PIN* aPin, const SCH_SHEET_PATH& aSheet ) { - try + if( m_pin_connections.count( aPin ) ) { - return m_pin_connections.at( aPin ); - } - catch( const std::out_of_range& oor ) - { - return nullptr; + SCH_PIN_CONNECTION* pin_conn = m_pin_connections.at( aPin ); + + if( pin_conn ) + return pin_conn->Connection( aSheet ); } + return nullptr; } @@ -2028,6 +2028,30 @@ void SCH_COMPONENT::Plot( PLOTTER* aPlotter ) } +bool SCH_COMPONENT::HasBrightenedPins() +{ + return m_brightenedPins.size() > 0; +} + + +void SCH_COMPONENT::ClearBrightenedPins() +{ + m_brightenedPins.clear(); +} + + +void SCH_COMPONENT::BrightenPin( LIB_PIN* aPin ) +{ + m_brightenedPins.insert( aPin->GetNumber() ); +} + + +bool SCH_COMPONENT::IsPinBrightened( const LIB_PIN* aPin ) +{ + return m_brightenedPins.find( aPin->GetNumber() ) != m_brightenedPins.end(); +} + + void SCH_COMPONENT::ClearHighlightedPins() { m_highlightedPins.clear(); diff --git a/eeschema/sch_component.h b/eeschema/sch_component.h index db24c58bc2..cf71e4930a 100644 --- a/eeschema/sch_component.h +++ b/eeschema/sch_component.h @@ -96,6 +96,7 @@ private: std::vector m_isDangling; ///< One isDangling per pin std::vector m_Pins; std::set m_highlightedPins; ///< God forgive me - Tom + std::set m_brightenedPins; ///< ... and me too - Jeff AUTOPLACED m_fieldsAutoplaced; ///< indicates status of field autoplacement @@ -221,9 +222,9 @@ public: void UpdatePinConnections( SCH_SHEET_PATH aSheet ); /** - * Retrieves the pin connection for a given pin of the component + * Retrieves the connection for a given pin of the component */ - SCH_PIN_CONNECTION* GetConnectionForPin( LIB_PIN* aPin ); + SCH_CONNECTION* GetConnectionForPin( LIB_PIN* aPin, const SCH_SHEET_PATH& aSheet ); const std::unordered_map& PinConnections() { @@ -662,6 +663,14 @@ public: void Show( int nestLevel, std::ostream& os ) const override; #endif + void ClearBrightenedPins(); + + bool HasBrightenedPins(); + + void BrightenPin( LIB_PIN* aPin ); + + bool IsPinBrightened( const LIB_PIN* aPin ); + void ClearHighlightedPins(); void HighlightPin( LIB_PIN* aPin ); diff --git a/eeschema/sch_connection.cpp b/eeschema/sch_connection.cpp index 09fb7e8ae4..7aa4e685c5 100644 --- a/eeschema/sch_connection.cpp +++ b/eeschema/sch_connection.cpp @@ -243,7 +243,7 @@ bool SCH_CONNECTION::IsDriver() const } -wxString SCH_CONNECTION::Name( bool aIgnoreSheet ) const +wxString SCH_CONNECTION::Name( bool aIgnoreSheet, bool aForceSheet ) const { wxString ret = m_name + m_suffix; @@ -271,7 +271,7 @@ wxString SCH_CONNECTION::Name( bool aIgnoreSheet ) const } } - if( prepend_path && !aIgnoreSheet ) + if( aForceSheet || ( prepend_path && !aIgnoreSheet ) ) ret = m_sheet.PathHumanReadable() + ret; return ret; diff --git a/eeschema/sch_connection.h b/eeschema/sch_connection.h index 295dedd3a8..6987c09853 100644 --- a/eeschema/sch_connection.h +++ b/eeschema/sch_connection.h @@ -145,7 +145,7 @@ public: m_dirty = false; } - wxString Name( bool aIgnoreSheet = false ) const; + wxString Name( bool aIgnoreSheet = false, bool aForceSheet = false ) const; wxString Prefix() const { diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 8e697a148a..a01a421504 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -540,8 +540,12 @@ void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer, bool aIsDangling, bool isMovi isMoving = true; VECTOR2I pos = mapCoords( aPin->GetPosition() ); + COLOR4D color; - COLOR4D color = getOverlayColor( aPin, m_schSettings.GetLayerColor( LAYER_PIN ), false ); + if( aPin->IsBrightened() ) + color = m_schSettings.GetLayerColor( LAYER_BRIGHTENED ); + else + color = getOverlayColor( aPin, m_schSettings.GetLayerColor( LAYER_PIN ), false ); if( !aPin->IsVisible() ) { @@ -1144,10 +1148,11 @@ void SCH_PAINTER::draw( SCH_COMPONENT *aComp, int aLayer ) if( item.Type() == LIB_PIN_T ) { auto pin = static_cast( &item ); - if( aComp->IsPinHighlighted( pin ) ) - { + + if( aComp->IsPinBrightened( pin ) ) + pin->SetFlags( BRIGHTENED ); + else if( aComp->IsPinHighlighted( pin ) ) pin->SetFlags( HIGHLIGHTED ); - } } } diff --git a/eeschema/sch_pin_connection.cpp b/eeschema/sch_pin_connection.cpp index 5e434f2265..737c143386 100644 --- a/eeschema/sch_pin_connection.cpp +++ b/eeschema/sch_pin_connection.cpp @@ -53,26 +53,20 @@ wxString SCH_PIN_CONNECTION::GetDefaultNetName( const SCH_SHEET_PATH aPath ) if( m_pin->IsPowerConnection() ) return m_pin->GetName(); - wxString name; + if( m_net_name_map.count( aPath ) > 0 ) + return m_net_name_map.at( aPath ); - try - { - name = m_net_name_map.at( aPath ); - } - catch( const std::out_of_range& oor ) - { - name = wxT( "Net-(" ); + wxString name = wxT( "Net-(" ); - name << m_comp->GetRef( &aPath ); + name << m_comp->GetRef( &aPath ); - // TODO(JE) do we need adoptTimestamp? - if( /* adoptTimestamp && */ name.Last() == '?' ) - name << m_comp->GetTimeStamp(); + // TODO(JE) do we need adoptTimestamp? + if( /* adoptTimestamp && */ name.Last() == '?' ) + name << m_comp->GetTimeStamp(); - name << _( "-Pad" ) << m_pin->GetNumber() << _( ")" ); + name << _( "-Pad" ) << m_pin->GetNumber() << _( ")" ); - m_net_name_map[ aPath ] = name; - } + m_net_name_map[ aPath ] = name; return name; }