From 1ff993133315c411ba0b4227e0ce9010fe0a9fe6 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Wed, 3 Oct 2018 22:10:50 -0700 Subject: [PATCH] pcbnew: Remove legacy Magnetize() from GAL picker Magnetic items handled by GRID_HELPER in GAL. Also includes the standard keyboard modifier shift to change magnetic items on/off --- pcbnew/tools/grid_helper.cpp | 2 +- pcbnew/tools/grid_helper.h | 2 +- pcbnew/tools/pcb_editor_control.cpp | 2 +- pcbnew/tools/picker_tool.cpp | 33 +++++++++---------------- pcbnew/tools/picker_tool.h | 9 +++++++ pcbnew/tools/position_relative_tool.cpp | 1 - 6 files changed, 23 insertions(+), 26 deletions(-) diff --git a/pcbnew/tools/grid_helper.cpp b/pcbnew/tools/grid_helper.cpp index c383af8d9a..87545925f7 100644 --- a/pcbnew/tools/grid_helper.cpp +++ b/pcbnew/tools/grid_helper.cpp @@ -255,7 +255,7 @@ VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aDrag } -VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, LSET& aLayers ) +VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLayers ) { double worldScale = m_frame->GetGalCanvas()->GetGAL()->GetWorldScale(); int snapRange = (int) ( m_snapSize / worldScale ); diff --git a/pcbnew/tools/grid_helper.h b/pcbnew/tools/grid_helper.h index d68fee50ed..426f859efa 100644 --- a/pcbnew/tools/grid_helper.h +++ b/pcbnew/tools/grid_helper.h @@ -57,7 +57,7 @@ public: VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, BOARD_ITEM* aItem ); VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aDraggedItem ); - VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, LSET& aLayers ); + VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLayers ); void SetSnap( bool aSnap ) { diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index 62639d135c..843c41a24e 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -1061,7 +1061,7 @@ int PCB_EDITOR_CONTROL::HighlightNetCursor( const TOOL_EVENT& aEvent ) m_frame->SetToolID( ID_PCB_HIGHLIGHT_BUTT, wxCURSOR_HAND, _( "Highlight net" ) ); picker->SetClickHandler( std::bind( highlightNet, m_toolMgr, _1, false ) ); - picker->SetSnapping( false ); + picker->SetLayerSet( LSET::AllCuMask() ); picker->Activate(); Wait(); diff --git a/pcbnew/tools/picker_tool.cpp b/pcbnew/tools/picker_tool.cpp index a11fa4d9be..96d818595a 100644 --- a/pcbnew/tools/picker_tool.cpp +++ b/pcbnew/tools/picker_tool.cpp @@ -25,18 +25,11 @@ #include "picker_tool.h" #include "pcb_actions.h" #include "grid_helper.h" -#include -#include #include #include #include "tool_event_utils.h" #include "selection_tool.h" - -extern bool Magnetize( PCB_BASE_EDIT_FRAME* frame, int aCurrentTool, - wxSize aGridSize, wxPoint on_grid, wxPoint* curpos ); - - TOOL_ACTION PCB_ACTIONS::pickerTool( "pcbnew.Picker", AS_GLOBAL, 0, "", "", NULL, AF_ACTIVATE ); @@ -51,30 +44,23 @@ int PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) { KIGFX::VIEW_CONTROLS* controls = getViewControls(); GRID_HELPER grid( frame() ); - setControls(); while( OPT_TOOL_EVENT evt = Wait() ) { - // TODO: magnetic pad & track processing needs to move to VIEW_CONTROLS. - wxPoint pos( controls->GetMousePosition().x, controls->GetMousePosition().y ); - frame()->SetMousePosition( pos ); + VECTOR2I cursorPos = controls->GetCursorPosition(); - wxRealPoint gridSize = frame()->GetScreen()->GetGridSize(); - wxSize igridsize; - igridsize.x = KiROUND( gridSize.x ); - igridsize.y = KiROUND( gridSize.y ); - - if( Magnetize( frame(), ID_PCB_HIGHLIGHT_BUTT, igridsize, pos, &pos ) ) - controls->ForceCursorPosition( true, pos ); - else - controls->ForceCursorPosition( false ); + if( m_cursorSnapping ) + { + grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); + cursorPos = grid.BestSnapAnchor( cursorPos, m_layerMask ); + } if( evt->IsClick( BUT_LEFT ) ) { bool getNext = false; - m_picked = VECTOR2D( controls->GetCursorPosition() ); + m_picked = cursorPos; if( m_clickHandler ) { @@ -139,6 +125,7 @@ void PICKER_TOOL::reset() m_cursorVisible = true; m_cursorCapture = false; m_autoPanning = false; + m_layerMask = LSET::AllLayersMask(); m_picked = NULLOPT; m_clickHandler = NULLOPT; @@ -150,8 +137,10 @@ void PICKER_TOOL::setControls() { KIGFX::VIEW_CONTROLS* controls = getViewControls(); + // Ensure that the view controls do not handle our snapping as we use the GRID_HELPER + controls->SetSnapping( false ); + controls->ShowCursor( m_cursorVisible ); - controls->SetSnapping( m_cursorSnapping ); controls->CaptureCursor( m_cursorCapture ); controls->SetAutoPan( m_autoPanning ); } diff --git a/pcbnew/tools/picker_tool.h b/pcbnew/tools/picker_tool.h index 7adb3a9ef4..8909062aa5 100644 --- a/pcbnew/tools/picker_tool.h +++ b/pcbnew/tools/picker_tool.h @@ -71,6 +71,12 @@ public: */ inline void SetCursorCapture( bool aEnable ) { m_cursorCapture = aEnable; } + /** + * Function SetLayerSet() + * Sets the tool's snap layer set + */ + inline void SetLayerSet( LSET aLayerSet ) { m_layerMask = aLayerSet; } + /** * Function SetClickHandler() * Sets a handler for mouse click event. Handler may decide to receive further click by @@ -102,6 +108,9 @@ private: bool m_cursorCapture; bool m_autoPanning; + ///> The layer set to use for optional snapping + LSET m_layerMask; + ///> Optional event handlers. OPT m_clickHandler; OPT m_cancelHandler; diff --git a/pcbnew/tools/position_relative_tool.cpp b/pcbnew/tools/position_relative_tool.cpp index c366dfe752..4d998cbefc 100644 --- a/pcbnew/tools/position_relative_tool.cpp +++ b/pcbnew/tools/position_relative_tool.cpp @@ -139,7 +139,6 @@ int POSITION_RELATIVE_TOOL::SelectPositionRelativeItem( const TOOL_EVENT& aEvent bool picking = true; statusPopup.SetText( _( "Select reference item..." ) ); - picker->SetSnapping( false ); picker->Activate(); picker->SetClickHandler( [&]( const VECTOR2D& aPoint ) -> bool