diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index a26cc908ed..a29081db5f 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -383,6 +383,10 @@ TOOL_ACTION COMMON_ACTIONS::placeModule( "pcbnew.EditorControl.placeModule", AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ADD_MODULE ), _( "Add modules" ), _( "Add modules" ), NULL, AF_ACTIVATE ); +TOOL_ACTION COMMON_ACTIONS::highlightNet( "pcbnew.EditorControl.highlightNet", + AS_GLOBAL, 0, + "", "" ); + // Module editor tools TOOL_ACTION COMMON_ACTIONS::placePad( "pcbnew.ModuleEditor.placePad", diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h index 8835a951f2..9a6631195c 100644 --- a/pcbnew/tools/common_actions.h +++ b/pcbnew/tools/common_actions.h @@ -270,6 +270,7 @@ public: static TOOL_ACTION resetCoords; static TOOL_ACTION switchCursor; static TOOL_ACTION switchUnits; + static TOOL_ACTION highlightNet; static TOOL_ACTION showHelp; static TOOL_ACTION toBeDone; diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index 00ee0a1854..970dc357f0 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -30,6 +30,7 @@ #include "selection_tool.h" +#include #include #include #include @@ -39,6 +40,7 @@ #include #include #include +#include #include #include @@ -466,6 +468,47 @@ int PCB_EDITOR_CONTROL::SelectionCrossProbe( const TOOL_EVENT& aEvent ) } +/** + * 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). + */ +static bool highlightNet( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition ) +{ + KIGFX::RENDER_SETTINGS* render = aToolMgr->GetView()->GetPainter()->GetSettings(); + GENERAL_COLLECTORS_GUIDE guide = static_cast( aToolMgr->GetEditFrame() )->GetCollectorsGuide(); + BOARD* board = static_cast( aToolMgr->GetModel() ); + GENERAL_COLLECTOR collector; + int net = -1; + + // Find a connected item for which we are going to highlight a net + collector.Collect( board, GENERAL_COLLECTOR::PadsTracksOrZones, + wxPoint( aPosition.x, aPosition.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 ); + aToolMgr->GetView()->UpdateAllLayersColor(); + } + + return true; +} + + +int PCB_EDITOR_CONTROL::HighlightNet( const TOOL_EVENT& aEvent ) +{ + highlightNet( m_toolMgr, getView()->ToWorld( getViewControls()->GetMousePosition() ) ); + + return 0; +} + + void PCB_EDITOR_CONTROL::SetTransitions() { // Track & via size control @@ -484,7 +527,9 @@ void PCB_EDITOR_CONTROL::SetTransitions() Go( &PCB_EDITOR_CONTROL::PlaceTarget, COMMON_ACTIONS::placeTarget.MakeEvent() ); Go( &PCB_EDITOR_CONTROL::PlaceModule, COMMON_ACTIONS::placeModule.MakeEvent() ); + // Other Go( &PCB_EDITOR_CONTROL::SelectionCrossProbe, SELECTION_TOOL::SelectedEvent ); + Go( &PCB_EDITOR_CONTROL::HighlightNet, COMMON_ACTIONS::highlightNet.MakeEvent() ); } diff --git a/pcbnew/tools/pcb_editor_control.h b/pcbnew/tools/pcb_editor_control.h index 31ba8ebddb..e13aefc526 100644 --- a/pcbnew/tools/pcb_editor_control.h +++ b/pcbnew/tools/pcb_editor_control.h @@ -72,6 +72,9 @@ public: ///> Notifies eeschema about the selected item. int SelectionCrossProbe( const TOOL_EVENT& aEvent ); + ///> Highlights net belonging to the item under the cursor. + int HighlightNet( const TOOL_EVENT& aEvent ); + ///> Sets up handlers for various events. void SetTransitions(); diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index e11abf5547..ba1b7902b9 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -146,7 +146,7 @@ int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) { if( evt->Modifier( MD_CTRL ) && !m_editModules ) { - highlightNet( evt->Position() ); + m_toolMgr->RunAction( COMMON_ACTIONS::highlightNet, true ); } else { @@ -1004,30 +1004,6 @@ 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 = m_frame->GetCollectorsGuide(); - GENERAL_COLLECTOR collector; - int net = -1; - - // Find a connected item for which we are going to highlight a net - collector.Collect( getModel(), 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(); - } -} - - static double calcArea( BOARD_ITEM* aItem ) { switch( aItem -> Type() ) diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index 84d72f48b7..c0cf58d595 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -294,14 +294,6 @@ 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 ); - /** * Function guessSelectionCandidates() * Tries to guess best selection candidates in case multiple items are clicked, by