From 23485377697c0011c76510f0a41c9222bd02b6c1 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 12 Jun 2019 10:34:13 +0100 Subject: [PATCH] Add a command to toggle between last two highlighted nets. --- pcbnew/tools/edit_tool.cpp | 2 +- pcbnew/tools/pcb_actions.h | 1 + pcbnew/tools/pcb_editor_control.cpp | 77 ++++++++++++++++------------- pcbnew/tools/pcb_editor_control.h | 4 ++ 4 files changed, 49 insertions(+), 35 deletions(-) diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 059ab5c162..9cc96fab74 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -122,7 +122,7 @@ TOOL_ACTION PCB_ACTIONS::rotateCcw( "pcbnew.InteractiveEdit.rotateCcw", TOOL_ACTION PCB_ACTIONS::flip( "pcbnew.InteractiveEdit.flip", AS_GLOBAL, 'F', LEGACY_HK_NAME( "Flip Item" ), - _( "Flip" ), _( "Flips selected item(s)" ), + _( "Flip" ), _( "Flips selected item(s) to opposite side of board" ), swap_layer_xpm ); TOOL_ACTION PCB_ACTIONS::mirror( "pcbnew.InteractiveEdit.mirror", diff --git a/pcbnew/tools/pcb_actions.h b/pcbnew/tools/pcb_actions.h index fa2bd90734..ad09fa0fe9 100644 --- a/pcbnew/tools/pcb_actions.h +++ b/pcbnew/tools/pcb_actions.h @@ -361,6 +361,7 @@ public: static TOOL_ACTION deleteTool; static TOOL_ACTION clearHighlight; static TOOL_ACTION highlightNet; + static TOOL_ACTION toggleLastNetHighlight; static TOOL_ACTION highlightNetTool; static TOOL_ACTION highlightNetSelection; static TOOL_ACTION drillOrigin; diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index 42499ae11e..5fce16e817 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -197,8 +197,13 @@ TOOL_ACTION PCB_ACTIONS::appendBoard( "pcbnew.EditorControl.appendBoard", TOOL_ACTION PCB_ACTIONS::highlightNet( "pcbnew.EditorControl.highlightNet", AS_GLOBAL ); +TOOL_ACTION PCB_ACTIONS::toggleLastNetHighlight( "pcbnew.EditorControl.toggleLastNetHighlight", + AS_GLOBAL, 0, "", + _( "Toggle Last Net Highlight" ), _( "Toggle between last two highlighted nets" ) ); + TOOL_ACTION PCB_ACTIONS::clearHighlight( "pcbnew.EditorControl.clearHighlight", - AS_GLOBAL ); + AS_GLOBAL, 0, "", + _( "Clear Net Highlighting" ), "" ); TOOL_ACTION PCB_ACTIONS::highlightNetTool( "pcbnew.EditorControl.highlightNetTool", AS_GLOBAL, 0, "", @@ -336,6 +341,7 @@ PCB_EDITOR_CONTROL::PCB_EDITOR_CONTROL() : KIGFX::ORIGIN_VIEWITEM::CIRCLE_CROSS ) ); m_probingSchToPcb = false; m_slowRatsnest = false; + m_lastNetcode = -1; } @@ -1203,24 +1209,22 @@ int PCB_EDITOR_CONTROL::DrillOrigin( const TOOL_EVENT& aEvent ) * Look for a BOARD_CONNECTED_ITEM in a given spot and if one is found - it enables * highlight for its net. * - * @param aToolMgr is the TOOL_MANAGER currently in use. * @param aPosition is the point where an item is expected (world coordinates). * @param aUseSelection is true if we should use the current selection to pick the netcode */ -static bool highlightNet( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition, - bool aUseSelection = false ) + bool PCB_EDITOR_CONTROL::highlightNet( const VECTOR2D& aPosition, bool aUseSelection ) { - auto render = aToolMgr->GetView()->GetPainter()->GetSettings(); - auto frame = static_cast( aToolMgr->GetEditFrame() ); + KIGFX::RENDER_SETTINGS* settings = getView()->GetPainter()->GetSettings(); + PCB_EDIT_FRAME* frame = getEditFrame(); - BOARD* board = static_cast( aToolMgr->GetModel() ); + BOARD* board = static_cast( m_toolMgr->GetModel() ); int net = -1; bool enableHighlight = false; if( aUseSelection ) { - auto selectionTool = aToolMgr->GetTool(); + SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); const PCBNEW_SELECTION& selection = selectionTool->GetSelection(); @@ -1233,18 +1237,13 @@ static bool highlightNet( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition, int item_net = ci->GetNetCode(); if( net < 0 ) - { net = item_net; - } - else if( net != item_net ) - { - // more than one net selected: do nothing - return 0; - } + else if( net != item_net ) // more than one net selected: do nothing + return false; } } - enableHighlight = ( net >= 0 && net != render->GetHighlightNetCode() ); + enableHighlight = ( net >= 0 && net != settings->GetHighlightNetCode() ); } // If we didn't get a net to highlight from the selection, use the cursor @@ -1282,13 +1281,15 @@ static bool highlightNet( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition, } // Toggle highlight when the same net was picked - if( net > 0 && net == render->GetHighlightNetCode() ) - enableHighlight = !render->IsHighlightEnabled(); + if( net > 0 && net == settings->GetHighlightNetCode() ) + enableHighlight = !settings->IsHighlightEnabled(); - if( enableHighlight != render->IsHighlightEnabled() || net != render->GetHighlightNetCode() ) + if( enableHighlight != settings->IsHighlightEnabled() + || net != settings->GetHighlightNetCode() ) { - render->SetHighlight( enableHighlight, net ); - aToolMgr->GetView()->UpdateAllLayersColor(); + m_lastNetcode = settings->GetHighlightNetCode(); + settings->SetHighlight( enableHighlight, net ); + m_toolMgr->GetView()->UpdateAllLayersColor(); } // Store the highlighted netcode in the current board (for dialogs for instance) @@ -1319,18 +1320,25 @@ static bool highlightNet( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition, int PCB_EDITOR_CONTROL::HighlightNet( const TOOL_EVENT& aEvent ) { - int netcode = aEvent.Parameter(); + int netcode = aEvent.Parameter(); + KIGFX::RENDER_SETTINGS* settings = m_toolMgr->GetView()->GetPainter()->GetSettings(); if( netcode > 0 ) { - KIGFX::RENDER_SETTINGS* render = m_toolMgr->GetView()->GetPainter()->GetSettings(); - render->SetHighlight( true, netcode ); + m_lastNetcode = settings->GetHighlightNetCode(); + settings->SetHighlight( true, netcode ); m_toolMgr->GetView()->UpdateAllLayersColor(); } - else + else if( aEvent.IsAction( &PCB_ACTIONS::toggleLastNetHighlight ) ) { - // No net code specified, pick the net code belonging to the item under the cursor - highlightNet( m_toolMgr, getViewControls()->GetMousePosition() ); + int temp = settings->GetHighlightNetCode(); + settings->SetHighlight( true, m_lastNetcode ); + m_toolMgr->GetView()->UpdateAllLayersColor(); + m_lastNetcode = temp; + } + else // Highlight the net belonging to the item under the cursor + { + highlightNet( getViewControls()->GetMousePosition(), false ); } return 0; @@ -1354,15 +1362,13 @@ int PCB_EDITOR_CONTROL::ClearHighlight( const TOOL_EVENT& aEvent ) int PCB_EDITOR_CONTROL::HighlightNetCursor( const TOOL_EVENT& aEvent ) { - // If the keyboard hotkey was triggered, the behavior is as follows: - // If we are already in the highlight tool, behave the same as a left click. - // If we are not, highlight the net of the selected item(s), or if there is - // no selection, then behave like a Ctrl+Left Click. + // If the keyboard hotkey was triggered and we are already in the highlight tool, behave + // the same as a left-click. Otherwise highlight the net of the selected item(s), or if + // there is no selection, then behave like a ctrl-left-click. if( aEvent.IsAction( &PCB_ACTIONS::highlightNetSelection ) ) { bool use_selection = ( m_frame->GetToolId() != ID_PCB_HIGHLIGHT_BUTT ); - highlightNet( m_toolMgr, getViewControls()->GetMousePosition(), - use_selection ); + highlightNet( getViewControls()->GetMousePosition(), use_selection ); } Activate(); @@ -1371,7 +1377,9 @@ int PCB_EDITOR_CONTROL::HighlightNetCursor( const TOOL_EVENT& aEvent ) assert( picker ); m_frame->SetToolID( ID_PCB_HIGHLIGHT_BUTT, wxCURSOR_HAND, _( "Highlight net" ) ); - picker->SetClickHandler( std::bind( highlightNet, m_toolMgr, _1, false ) ); + picker->SetClickHandler( [this] ( const VECTOR2D& pt ) -> bool { + return highlightNet( pt, false ); + } ); picker->SetLayerSet( LSET::AllCuMask() ); picker->Activate(); Wait(); @@ -1599,6 +1607,7 @@ void PCB_EDITOR_CONTROL::setTransitions() Go( &PCB_EDITOR_CONTROL::CrossProbePcbToSch, EVENTS::ClearedEvent ); Go( &PCB_EDITOR_CONTROL::CrossProbeSchToPcb, PCB_ACTIONS::crossProbeSchToPcb.MakeEvent() ); Go( &PCB_EDITOR_CONTROL::HighlightNet, PCB_ACTIONS::highlightNet.MakeEvent() ); + Go( &PCB_EDITOR_CONTROL::HighlightNet, PCB_ACTIONS::toggleLastNetHighlight.MakeEvent() ); Go( &PCB_EDITOR_CONTROL::ClearHighlight, PCB_ACTIONS::clearHighlight.MakeEvent() ); Go( &PCB_EDITOR_CONTROL::HighlightNetCursor, PCB_ACTIONS::highlightNetTool.MakeEvent() ); Go( &PCB_EDITOR_CONTROL::HighlightNetCursor, PCB_ACTIONS::highlightNetSelection.MakeEvent() ); diff --git a/pcbnew/tools/pcb_editor_control.h b/pcbnew/tools/pcb_editor_control.h index 8a7675737f..2b09f887c8 100644 --- a/pcbnew/tools/pcb_editor_control.h +++ b/pcbnew/tools/pcb_editor_control.h @@ -147,6 +147,8 @@ public: int ListNets( const TOOL_EVENT& aEvent ); private: + bool highlightNet( const VECTOR2D& aPosition, bool aUseSelection ); + ///> Event handler to recalculate dynamic ratsnest void ratsnestTimer( wxTimerEvent& aEvent ); @@ -165,6 +167,8 @@ private: bool m_slowRatsnest; ///> Indicates current selection ratsnest will be slow to calculate wxTimer m_ratsnestTimer; ///> Timer to initiate lazy ratsnest calculation (ie: when slow) + int m_lastNetcode; ///> Used for toggling between last two highlighted nets + ///> How to modify a property for selected items. enum MODIFY_MODE { ON, OFF, TOGGLE };