diff --git a/include/painter.h b/include/painter.h index 004c93e35e..34376d985d 100644 --- a/include/painter.h +++ b/include/painter.h @@ -109,6 +109,26 @@ public: return ( m_activeLayers.count( aLayerId ) > 0 ); } + /** + * Function GetHighlight + * Returns current highlight setting. + * @return True if highlight is enabled, false otherwise. + */ + bool GetHighlight() const + { + return m_highlightEnabled; + } + + /** + * Function GetHighlightNetCode + * Returns netcode of currently highlighted net. + * @return Netcode of currently highlighted net. + */ + int GetHighlightNetCode() const + { + return m_highlightNetcode; + } + /** * Function SetHighlight * Turns on/off highlighting - it may be done for the active layer or the specified net. @@ -119,9 +139,7 @@ public: inline void SetHighlight( bool aEnabled, int aNetcode = -1 ) { m_highlightEnabled = aEnabled; - - if( aNetcode > 0 ) - m_highlightNetcode = aNetcode; + m_highlightNetcode = aNetcode; } /** diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 1b8f013a0b..6fdc83dd4e 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -112,10 +112,17 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) // single click? Select single object else if( evt->IsClick( BUT_LEFT ) ) { - if( !m_additive ) - clearSelection(); + if( evt->Modifier( MD_CTRL ) ) + { + highlightNet( evt->Position() ); + } + else + { + if( !m_additive ) + clearSelection(); - selectSingle( evt->Position() ); + selectSingle( evt->Position() ); + } } // right click? if there is any object - show the context menu @@ -650,6 +657,30 @@ bool SELECTION_TOOL::selectionContains( const VECTOR2I& aPoint ) const } +void SELECTION_TOOL::highlightNet( const VECTOR2I& aPoint ) +{ + KIGFX::RENDER_SETTINGS* render = getView()->GetPainter()->GetSettings(); + GENERAL_COLLECTORS_GUIDE guide = getEditFrame()->GetCollectorsGuide(); + GENERAL_COLLECTOR collector; + int net = -1; + + // Find a connected item for which we are going to highlight a net + collector.Collect( getModel( PCB_T ), GENERAL_COLLECTOR::PadsTracksOrZones, + wxPoint( aPoint.x, aPoint.y ), guide ); + bool enableHighlight = ( collector.GetCount() > 0 ); + + // Obtain net code for the clicked item + if( enableHighlight ) + net = static_cast( collector[0] )->GetNetCode(); + + if( enableHighlight != render->GetHighlight() || net != render->GetHighlightNetCode() ) + { + render->SetHighlight( enableHighlight, net ); + getView()->UpdateAllLayersColor(); + } +} + + void SELECTION_TOOL::SELECTION::clear() { items.ClearItemsList(); diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index ca46f8bbdd..609fcafda5 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -221,6 +221,14 @@ private: */ bool selectionContains( const VECTOR2I& aPoint ) const; + /** + * Function highlightNet() + * Looks for a BOARD_CONNECTED_ITEM in a given spot, and if one is found - it enables + * highlight for its net. + * @param aPoint is the point where an item is expected (world coordinates). + */ + void highlightNet( const VECTOR2I& aPoint ); + /// Visual representation of selection box SELECTION_AREA* m_selArea;