From ee676b74d5324deb58d460100a166fcba4915674 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 4 Oct 2018 21:19:12 -0700 Subject: [PATCH] pcbnew: Move measure tool to common GRID_HELPER This removes the last of the Magnetize legacy code from GAL, standardizing the key bindings and magnetic effects in the GAL canvas --- pcbnew/magnetic_tracks_functions.cpp | 4 ++-- pcbnew/tools/edit_tool.cpp | 27 ++++++--------------------- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/pcbnew/magnetic_tracks_functions.cpp b/pcbnew/magnetic_tracks_functions.cpp index dce658490c..181db5d971 100644 --- a/pcbnew/magnetic_tracks_functions.cpp +++ b/pcbnew/magnetic_tracks_functions.cpp @@ -129,8 +129,8 @@ bool FindBestGridPointOnTrack( wxPoint* aNearPos, wxPoint on_grid, const TRACK* bool Magnetize( PCB_BASE_EDIT_FRAME* frame, int aCurrentTool, wxSize aGridSize, wxPoint on_grid, wxPoint* curpos ) { - // Note: only used for routing in the Legacy Toolset and for the measurement tool in the - // Modern Toolset. Can be greatly simplified when the Legacy Toolset is retired. + // Note: only used for routing in the Legacy Toolset + // Can be greatly simplified when the Legacy Toolset is retired. bool doCheckNet = frame->Settings().m_magneticPads != CAPTURE_ALWAYS && frame->Settings().m_legacyDrcOn; bool doCheckLayer = aCurrentTool == ID_TRACK_BUTT; diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 662e1cbd6d..6d03011bd8 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -72,10 +72,6 @@ using namespace std::placeholders; #include -extern bool Magnetize( PCB_BASE_EDIT_FRAME* frame, int aCurrentTool, - wxSize aGridSize, wxPoint on_grid, wxPoint* curpos ); - - // Edit tool actions TOOL_ACTION PCB_ACTIONS::editFootprintInFpEditor( "pcbnew.InteractiveEdit.editFootprintInFpEditor", AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_EDIT_MODULE_WITH_MODEDIT ), @@ -1201,35 +1197,24 @@ int EDIT_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) frame()->SetToolID( toolID, wxCURSOR_PENCIL, _( "Measure distance" ) ); KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER twoPtMgr; - KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, frame()->GetUserUnits() ); view.Add( &ruler ); view.SetVisible( &ruler, false ); + GRID_HELPER grid( frame() ); + bool originSet = false; controls.ShowCursor( true ); - controls.SetSnapping( true ); + controls.SetSnapping( false ); controls.SetAutoPan( false ); while( auto evt = Wait() ) { - // TODO: magnetic pad & track processing needs to move to VIEW_CONTROLS. - wxPoint pos( controls.GetMousePosition().x, controls.GetMousePosition().y ); - frame()->SetMousePosition( pos ); - - wxRealPoint gridSize = frame()->GetScreen()->GetGridSize(); - wxSize igridsize; - igridsize.x = KiROUND( gridSize.x ); - igridsize.y = KiROUND( gridSize.y ); - - if( Magnetize( frame(), toolID, igridsize, pos, &pos ) ) - controls.ForceCursorPosition( true, pos ); - else - controls.ForceCursorPosition( false ); - - const VECTOR2I cursorPos = controls.GetCursorPosition(); + grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); + grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); + const VECTOR2I cursorPos = grid.BestSnapAnchor( controls.GetCursorPosition(), nullptr ); if( evt->IsCancel() || TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() ) {