diff --git a/common/gal/gal_display_options.cpp b/common/gal/gal_display_options.cpp index 40ba608465..c8f8046700 100644 --- a/common/gal/gal_display_options.cpp +++ b/common/gal/gal_display_options.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KICAD, a free EDA CAD application. * -* Copyright (C) 2016-2017 Kicad Developers, see change_log.txt for contributors. +* Copyright (C) 2016-2020 Kicad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -39,6 +39,13 @@ static const UTIL::CFG_MAP gridStyleConfigVals = { KIGFX::GRID_STYLE::SMALL_CROSS,2 }, }; +static const UTIL::CFG_MAP gridSnapConfigVals = +{ + { KIGFX::GRID_SNAPPING::ALWAYS, 0 }, + { KIGFX::GRID_SNAPPING::WITH_GRID, 1 }, + { KIGFX::GRID_SNAPPING::NEVER, 2 } +}; + /** * Flag to enable GAL_DISPLAY_OPTIONS logging @@ -55,6 +62,7 @@ GAL_DISPLAY_OPTIONS::GAL_DISPLAY_OPTIONS() cairo_antialiasing_mode( CAIRO_ANTIALIASING_MODE::NONE ), m_dpi( nullptr, nullptr ), m_gridStyle( GRID_STYLE::DOTS ), + m_gridSnapping( GRID_SNAPPING::ALWAYS ), m_gridLineWidth( 1.0 ), m_gridMinSpacing( 10.0 ), m_axesEnabled( false ), @@ -69,6 +77,7 @@ void GAL_DISPLAY_OPTIONS::ReadWindowSettings( WINDOW_SETTINGS& aCfg ) wxLogTrace( traceGalDispOpts, "Reading app-specific options" ); m_gridStyle = UTIL::GetValFromConfig( gridStyleConfigVals, aCfg.grid.style ); + m_gridSnapping = UTIL::GetValFromConfig( gridSnapConfigVals, aCfg.grid.snap ); m_gridLineWidth = aCfg.grid.line_width; m_gridMinSpacing = aCfg.grid.min_spacing; m_axesEnabled = aCfg.grid.axes_enabled; @@ -113,6 +122,7 @@ void GAL_DISPLAY_OPTIONS::WriteConfig( WINDOW_SETTINGS& aCfg ) wxLogTrace( traceGalDispOpts, "Writing window settings" ); aCfg.grid.style = UTIL::GetConfigForVal( gridStyleConfigVals, m_gridStyle ); + aCfg.grid.snap = UTIL::GetConfigForVal( gridSnapConfigVals, m_gridSnapping ); aCfg.grid.line_width = m_gridLineWidth; aCfg.grid.min_spacing = m_gridMinSpacing; aCfg.grid.axes_enabled = m_axesEnabled; @@ -123,8 +133,11 @@ void GAL_DISPLAY_OPTIONS::WriteConfig( WINDOW_SETTINGS& aCfg ) void GAL_DISPLAY_OPTIONS::UpdateScaleFactor() { - m_scaleFactor = m_dpi.GetScaleFactor(); - NotifyChanged(); + if( m_scaleFactor != m_dpi.GetScaleFactor() ) + { + m_scaleFactor = m_dpi.GetScaleFactor(); + NotifyChanged(); + } } diff --git a/common/settings/app_settings.cpp b/common/settings/app_settings.cpp index 859820a9fe..821c474729 100644 --- a/common/settings/app_settings.cpp +++ b/common/settings/app_settings.cpp @@ -312,6 +312,9 @@ void APP_SETTINGS_BASE::addParamsForWindow( WINDOW_SETTINGS* aWindow, const std: m_params.emplace_back( new PARAM( aJsonPath + ".grid.style", &aWindow->grid.style, 0 ) ); + m_params.emplace_back( new PARAM( aJsonPath + ".grid.snap", + &aWindow->grid.snap, 0 ) ); + m_params.emplace_back( new PARAM( aJsonPath + ".cursor.always_show_cursor", &aWindow->cursor.always_show_cursor, true ) ); diff --git a/common/view/view_controls.cpp b/common/view/view_controls.cpp index 9d366ab47c..b96fb4267d 100644 --- a/common/view/view_controls.cpp +++ b/common/view/view_controls.cpp @@ -87,7 +87,6 @@ void VIEW_CONTROLS::ApplySettings( const VC_SETTINGS& aSettings ) { ShowCursor( aSettings.m_showCursor ); CaptureCursor( aSettings.m_cursorCaptured ); - SetGridSnapping( aSettings.m_snappingEnabled ); SetGrabMouse( aSettings.m_grabMouse ); SetAutoPan( aSettings.m_autoPanEnabled ); SetAutoPanMargin( aSettings.m_autoPanMargin ); diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index ca9e99d498..165488401d 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -498,9 +498,11 @@ VECTOR2D WX_VIEW_CONTROLS::GetMousePosition( bool aWorldCoordinates ) const VECTOR2D WX_VIEW_CONTROLS::GetRawCursorPosition( bool aEnableSnapping ) const { - if( aEnableSnapping ) + GAL* gal = m_view->GetGAL(); + + if( aEnableSnapping && gal->GetGridSnapping() ) { - return m_view->GetGAL()->GetGridPoint( m_cursorPos ); + return gal->GetGridPoint( m_cursorPos ); } else { diff --git a/common/widgets/gal_options_panel.cpp b/common/widgets/gal_options_panel.cpp index 703e0e42a0..f45e088ed1 100644 --- a/common/widgets/gal_options_panel.cpp +++ b/common/widgets/gal_options_panel.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -45,7 +46,7 @@ static const double gridMinSpacingMin = 5; static const double gridMinSpacingMax = 200; static const double gridMinSpacingStep = 5; - +///TODO: These are duplicated in gal_display_options - Unify! static const UTIL::CFG_MAP gridStyleSelectMap = { { KIGFX::GRID_STYLE::DOTS, 0 }, // Default @@ -53,6 +54,12 @@ static const UTIL::CFG_MAP gridStyleSelectMap = { KIGFX::GRID_STYLE::SMALL_CROSS, 2 }, }; +static const UTIL::CFG_MAP gridSnapConfigVals = +{ + { KIGFX::GRID_SNAPPING::ALWAYS, 0 }, + { KIGFX::GRID_SNAPPING::WITH_GRID, 1 }, + { KIGFX::GRID_SNAPPING::NEVER, 2 } +}; GAL_OPTIONS_PANEL::GAL_OPTIONS_PANEL( wxWindow* aParent, KIGFX::GAL_DISPLAY_OPTIONS& aGalOpts ): wxPanel( aParent, wxID_ANY ), @@ -124,6 +131,25 @@ GAL_OPTIONS_PANEL::GAL_OPTIONS_PANEL( wxWindow* aParent, KIGFX::GAL_DISPLAY_OPTI l_gridMinSpacingUnits->Wrap( -1 ); sGridSettingsGrid->Add( l_gridMinSpacingUnits, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); + l_gridSnapOptions = new wxStaticText( sGridSettings->GetStaticBox(), wxID_ANY, _( "Snap to Grid:" ) ); + l_gridSnapOptions->Wrap( -1 ); + sGridSettingsGrid->Add( l_gridSnapOptions, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); + + wxString gridSnapChoices[] = { _( "Always"), _("When grid shown"), _("Never") }; + int gridSnapNChoices = sizeof( gridSnapChoices ) / sizeof( wxString ); + m_gridSnapOptions = new wxChoice( sGridSettings->GetStaticBox(), wxID_ANY, + wxDefaultPosition, wxDefaultSize, gridSnapNChoices, gridSnapChoices ); + m_gridSnapOptions->Select( 0 ); + sGridSettingsGrid->Add( m_gridSnapOptions, 0, wxALIGN_CENTER_VERTICAL | wxEXPAND | wxALL, 5 ); + + l_gridSnapSpace = new wxStaticText( sGridSettings->GetStaticBox(), + wxID_ANY, _( "px" ) ); + l_gridSnapSpace->Wrap( -1 ); + l_gridSnapSpace->Hide(); + sGridSettingsGrid->Add( l_gridSnapSpace, 0, + wxALIGN_CENTER_VERTICAL | wxALL | wxRESERVE_SPACE_EVEN_IF_HIDDEN, 5 ); + + sGridSettings->Add( sGridSettingsGrid, 1, wxALL | wxEXPAND, 5 ); sLeftSizer->Add( sGridSettings, 0, wxTOP | wxBOTTOM | wxRIGHT | wxEXPAND, 5 ); @@ -161,6 +187,9 @@ GAL_OPTIONS_PANEL::GAL_OPTIONS_PANEL( wxWindow* aParent, KIGFX::GAL_DISPLAY_OPTI bool GAL_OPTIONS_PANEL::TransferDataToWindow() { + m_gridSnapOptions->SetSelection( + UTIL::GetConfigForVal( gridSnapConfigVals, m_galOptions.m_gridSnapping ) ); + m_gridStyle->SetSelection( UTIL::GetConfigForVal( gridStyleSelectMap, m_galOptions.m_gridStyle ) ); @@ -178,6 +207,9 @@ bool GAL_OPTIONS_PANEL::TransferDataToWindow() bool GAL_OPTIONS_PANEL::TransferDataFromWindow() { + m_galOptions.m_gridSnapping = UTIL::GetValFromConfig( gridSnapConfigVals, + m_gridSnapOptions->GetSelection() ); + m_galOptions.m_gridStyle = UTIL::GetValFromConfig( gridStyleSelectMap, m_gridStyle->GetSelection() ); diff --git a/eeschema/lib_view_frame.cpp b/eeschema/lib_view_frame.cpp index ba7401e203..ed1ab6ea1d 100644 --- a/eeschema/lib_view_frame.cpp +++ b/eeschema/lib_view_frame.cpp @@ -194,7 +194,6 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame } SyncView(); - GetCanvas()->GetViewControls()->SetGridSnapping( IsGridVisible() ); GetCanvas()->SetCanFocus( false ); // Set the working/draw area size to display a symbol to a reasonable value: diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp index 88835abc69..452b4e56eb 100644 --- a/eeschema/libedit/lib_edit_frame.cpp +++ b/eeschema/libedit/lib_edit_frame.cpp @@ -175,7 +175,6 @@ LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : Show( true ); SyncView(); - GetCanvas()->GetViewControls()->SetGridSnapping( IsGridVisible() ); GetCanvas()->GetView()->UseDrawPriority( true ); GetCanvas()->GetGAL()->SetAxesEnabled( true ); diff --git a/eeschema/sch_draw_panel.cpp b/eeschema/sch_draw_panel.cpp index 6ba82ffe5a..70c9f3fb1a 100644 --- a/eeschema/sch_draw_panel.cpp +++ b/eeschema/sch_draw_panel.cpp @@ -91,8 +91,6 @@ SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId, // on updated viewport data. m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this ); - m_viewControls->SetGridSnapping( m_gal->GetGridVisibility() ); - SetEvtHandlerEnabled( true ); SetFocus(); Show( true ); diff --git a/eeschema/sch_preview_panel.cpp b/eeschema/sch_preview_panel.cpp index 1322e3d2ff..8af42dfbdb 100644 --- a/eeschema/sch_preview_panel.cpp +++ b/eeschema/sch_preview_panel.cpp @@ -70,8 +70,6 @@ SCH_PREVIEW_PANEL::SCH_PREVIEW_PANEL( wxWindow* aParentWindow, wxWindowID aWindo m_gal->SetCursorEnabled( false ); m_gal->SetGridSize( VECTOR2D( Mils2iu( 100.0 ), Mils2iu( 100.0 ) ) ); - m_viewControls->SetGridSnapping( m_gal->GetGridVisibility() ); - SetEvtHandlerEnabled( true ); SetFocus(); Show( true ); diff --git a/eeschema/tools/ee_grid_helper.cpp b/eeschema/tools/ee_grid_helper.cpp index db382b0054..bc34bd2964 100644 --- a/eeschema/tools/ee_grid_helper.cpp +++ b/eeschema/tools/ee_grid_helper.cpp @@ -108,7 +108,7 @@ void EE_GRID_HELPER::SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin ) VECTOR2I EE_GRID_HELPER::Align( const VECTOR2I& aPoint ) const { - if( !m_toolMgr->GetView()->GetGAL()->GetGridVisibility() ) + if( !m_toolMgr->GetView()->GetGAL()->GetGridSnapping() ) return aPoint; const VECTOR2D gridOffset( GetOrigin() ); diff --git a/eeschema/tools/lib_drawing_tools.cpp b/eeschema/tools/lib_drawing_tools.cpp index 3b152adfd3..3c925d3868 100644 --- a/eeschema/tools/lib_drawing_tools.cpp +++ b/eeschema/tools/lib_drawing_tools.cpp @@ -397,7 +397,6 @@ int LIB_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) int LIB_DRAWING_TOOLS::PlaceAnchor( const TOOL_EVENT& aEvent ) { getViewControls()->ShowCursor( true ); - getViewControls()->SetGridSnapping( m_frame->IsGridVisible() ); std::string tool = aEvent.GetCommandStr().get(); m_frame->PushTool( tool ); diff --git a/eeschema/tools/lib_move_tool.cpp b/eeschema/tools/lib_move_tool.cpp index e59c9c0b6f..5cf3435a27 100644 --- a/eeschema/tools/lib_move_tool.cpp +++ b/eeschema/tools/lib_move_tool.cpp @@ -70,7 +70,6 @@ void LIB_MOVE_TOOL::Reset( RESET_REASON aReason ) int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) { KIGFX::VIEW_CONTROLS* controls = getViewControls(); - controls->SetGridSnapping( m_frame->IsGridVisible() ); m_anchorPos = { 0, 0 }; @@ -103,7 +102,6 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) do { m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW ); - controls->SetGridSnapping( m_frame->IsGridVisible() ); if( evt->IsAction( &EE_ACTIONS::move ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT ) || evt->IsAction( &ACTIONS::refreshPreview ) diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index c928046c28..77d8feba65 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -449,7 +449,6 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); getViewControls()->ShowCursor( true ); - getViewControls()->SetGridSnapping( m_frame->IsGridVisible() ); SCH_ITEM* previewItem; switch( type ) diff --git a/eeschema/tools/sch_line_wire_bus_tool.cpp b/eeschema/tools/sch_line_wire_bus_tool.cpp index 979cd7267b..fa105e83a4 100644 --- a/eeschema/tools/sch_line_wire_bus_tool.cpp +++ b/eeschema/tools/sch_line_wire_bus_tool.cpp @@ -469,7 +469,6 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( const std::string& aTool, int aType m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); controls->ShowCursor( true ); - controls->SetGridSnapping( m_frame->IsGridVisible() ); Activate(); @@ -489,7 +488,6 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( const std::string& aTool, int aType m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL ); grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); - controls->SetGridSnapping( m_frame->IsGridVisible() ); wxPoint cursorPos = wxPoint( grid.BestSnapAnchor( evt->IsPrime() ? evt->Position() : controls->GetMousePosition(), nullptr ) ); controls->ForceCursorPosition( true, cursorPos ); diff --git a/eeschema/tools/sch_move_tool.cpp b/eeschema/tools/sch_move_tool.cpp index c7d0582c03..5876ffa7df 100644 --- a/eeschema/tools/sch_move_tool.cpp +++ b/eeschema/tools/sch_move_tool.cpp @@ -110,7 +110,6 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings(); KIGFX::VIEW_CONTROLS* controls = getViewControls(); - controls->SetGridSnapping( m_frame->IsGridVisible() ); EE_GRID_HELPER grid( m_toolMgr ); m_anchorPos.reset(); @@ -173,7 +172,6 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) do { m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW ); - controls->SetGridSnapping( m_frame->IsGridVisible() ); if( evt->IsAction( &EE_ACTIONS::moveActivate ) || evt->IsAction( &EE_ACTIONS::restartMove ) || evt->IsAction( &EE_ACTIONS::move ) || evt->IsAction( &EE_ACTIONS::drag ) diff --git a/gerbview/gerbview_draw_panel_gal.cpp b/gerbview/gerbview_draw_panel_gal.cpp index 29d19e20d7..28b541c806 100644 --- a/gerbview/gerbview_draw_panel_gal.cpp +++ b/gerbview/gerbview_draw_panel_gal.cpp @@ -49,7 +49,6 @@ EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalTy m_view->SetPainter( m_painter.get() ); m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this ); - m_viewControls->SetGridSnapping( m_gal->GetGridVisibility() ); setDefaultLayerDeps(); diff --git a/gerbview/tools/gerbview_selection_tool.cpp b/gerbview/tools/gerbview_selection_tool.cpp index cc830c7eda..8920115c40 100644 --- a/gerbview/tools/gerbview_selection_tool.cpp +++ b/gerbview/tools/gerbview_selection_tool.cpp @@ -571,7 +571,6 @@ int GERBVIEW_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) bool originSet = false; controls.ShowCursor( true ); - controls.SetGridSnapping( m_frame->IsGridVisible() ); while( TOOL_EVENT* evt = Wait() ) { diff --git a/include/gal/gal_display_options.h b/include/gal/gal_display_options.h index 53ab02fe52..2ed2f4b51f 100644 --- a/include/gal/gal_display_options.h +++ b/include/gal/gal_display_options.h @@ -62,6 +62,13 @@ namespace KIGFX BEST, }; + enum class GRID_SNAPPING + { + ALWAYS, + WITH_GRID, + NEVER + }; + class GAL_DISPLAY_OPTIONS; class GAL_DISPLAY_OPTIONS_OBSERVER @@ -116,6 +123,9 @@ namespace KIGFX ///> The grid style to draw the grid in KIGFX::GRID_STYLE m_gridStyle; + ///> Snapping options for the grid + GRID_SNAPPING m_gridSnapping; + ///> Thickness to render grid lines/dots double m_gridLineWidth; diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h index f5c7544176..089761626b 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -861,6 +861,11 @@ public: bool GetGridVisibility() const { return gridVisibility; } + bool GetGridSnapping() const + { + return ( options.m_gridSnapping == KIGFX::GRID_SNAPPING::ALWAYS || + ( gridVisibility && options.m_gridSnapping == KIGFX::GRID_SNAPPING::WITH_GRID ) ); + } /** * @brief Set the origin point for the grid. * diff --git a/include/settings/app_settings.h b/include/settings/app_settings.h index ca19a36588..f71ecfefa3 100644 --- a/include/settings/app_settings.h +++ b/include/settings/app_settings.h @@ -59,6 +59,7 @@ struct GRID_SETTINGS double min_spacing; bool show; int style; + int snap; }; /** diff --git a/include/view/view_controls.h b/include/view/view_controls.h index cd7b209ce8..8124eb4196 100644 --- a/include/view/view_controls.h +++ b/include/view/view_controls.h @@ -153,25 +153,6 @@ public: { } - /** - * Function SetGridSnapping() - * Enables/disables snapping cursor to grid. - * - * @param aEnabled says whether the opion should be enabled or disabled. - */ - virtual void SetGridSnapping( bool aEnabled ) - { - m_settings.m_snappingEnabled = aEnabled; - } - - /** - * @return the current state of the snapping cursor to grid. - */ - virtual bool GetGridSnapping() - { - return m_settings.m_snappingEnabled; - } - /** * Function SetGrabMouse * Turns on/off mouse grabbing. When the mouse is grabbed, it cannot go outside the VIEW. diff --git a/include/widgets/gal_options_panel.h b/include/widgets/gal_options_panel.h index 9ee6fe9ea5..28cd329175 100644 --- a/include/widgets/gal_options_panel.h +++ b/include/widgets/gal_options_panel.h @@ -63,6 +63,10 @@ private: wxSpinCtrlDouble* m_gridMinSpacing; wxStaticText* l_gridMinSpacingUnits; + wxStaticText* l_gridSnapOptions; + wxChoice* m_gridSnapOptions; + wxStaticText* l_gridSnapSpace; + wxRadioBox* m_cursorShape; wxCheckBox* m_forceCursorDisplay; diff --git a/pagelayout_editor/pl_draw_panel_gal.cpp b/pagelayout_editor/pl_draw_panel_gal.cpp index d78d1f3007..a8f370a952 100644 --- a/pagelayout_editor/pl_draw_panel_gal.cpp +++ b/pagelayout_editor/pl_draw_panel_gal.cpp @@ -65,7 +65,6 @@ PL_DRAW_PANEL_GAL::PL_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindo m_view->SetLayerVisible( LAYER_WORKSHEET_PAGEn, false ); m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this ); - m_viewControls->SetGridSnapping( m_gal->GetGridVisibility() ); } diff --git a/pagelayout_editor/tools/pl_edit_tool.cpp b/pagelayout_editor/tools/pl_edit_tool.cpp index 82d08fb21e..8aaecb2740 100644 --- a/pagelayout_editor/tools/pl_edit_tool.cpp +++ b/pagelayout_editor/tools/pl_edit_tool.cpp @@ -93,7 +93,6 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) { KIGFX::VIEW_CONTROLS* controls = getViewControls(); - controls->SetGridSnapping( m_frame->IsGridVisible() ); VECTOR2I originalCursorPos = controls->GetCursorPosition(); // Be sure that there is at least one item that we can move. If there's no selection try @@ -123,7 +122,6 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) do { m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW ); - controls->SetGridSnapping( m_frame->IsGridVisible() ); if( evt->IsAction( &PL_ACTIONS::move ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT ) || evt->IsAction( &ACTIONS::refreshPreview ) ) diff --git a/pcbnew/microwave/microwave_tool.cpp b/pcbnew/microwave/microwave_tool.cpp index c89b5a93fd..2917a76466 100644 --- a/pcbnew/microwave/microwave_tool.cpp +++ b/pcbnew/microwave/microwave_tool.cpp @@ -130,7 +130,6 @@ int MICROWAVE_TOOL::drawMicrowaveInductor( const TOOL_EVENT& aEvent ) bool originSet = false; controls.ShowCursor( true ); - controls.SetGridSnapping( true ); controls.CaptureCursor( false ); controls.SetAutoPan( false ); diff --git a/pcbnew/pcb_draw_panel_gal.cpp b/pcbnew/pcb_draw_panel_gal.cpp index c9ab845a22..39e76e6cd8 100644 --- a/pcbnew/pcb_draw_panel_gal.cpp +++ b/pcbnew/pcb_draw_panel_gal.cpp @@ -126,7 +126,6 @@ PCB_DRAW_PANEL_GAL::PCB_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin // View controls is the first in the event handler chain, so the Tool Framework operates // on updated viewport data. m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this ); - m_viewControls->SetGridSnapping( m_gal->GetGridVisibility() ); // Load display options (such as filled/outline display of items). // Can be made only if the parent window is an EDA_DRAW_FRAME (or a derived class) diff --git a/pcbnew/router/length_tuner_tool.cpp b/pcbnew/router/length_tuner_tool.cpp index d0a37d0f40..755429a5b2 100644 --- a/pcbnew/router/length_tuner_tool.cpp +++ b/pcbnew/router/length_tuner_tool.cpp @@ -270,7 +270,6 @@ int LENGTH_TUNER_TOOL::MainLoop( const TOOL_EVENT& aEvent ) m_router->SetMode( aEvent.Parameter() ); - controls()->SetGridSnapping( true ); controls()->ShowCursor( true ); frame()->UndoRedoBlock( true ); diff --git a/pcbnew/router/pns_tool_base.cpp b/pcbnew/router/pns_tool_base.cpp index b2f1bfb4e1..f305518fa1 100644 --- a/pcbnew/router/pns_tool_base.cpp +++ b/pcbnew/router/pns_tool_base.cpp @@ -2,7 +2,7 @@ * KiRouter - a push-and-(sometimes-)shove PCB router * * Copyright (C) 2013 CERN - * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors. * Author: Tomasz Wlostowski * * This program is free software: you can redistribute it and/or modify it @@ -24,13 +24,15 @@ using namespace std::placeholders; #include +#include #include #include #include #include -#include #include +#include +#include #include "pns_arc.h" #include "pns_kicad_iface.h" @@ -265,7 +267,7 @@ void TOOL_BASE::updateStartItem( const TOOL_EVENT& aEvent, bool aIgnorePads ) VECTOR2I p; controls()->ForceCursorPosition( false ); - m_gridHelper->SetUseGrid( !aEvent.Modifier( MD_ALT ) ); + m_gridHelper->SetUseGrid( m_toolMgr->GetView()->GetGAL()->GetGridSnapping() ); m_gridHelper->SetSnap( !aEvent.Modifier( MD_SHIFT ) ); bool snapEnabled = true; @@ -298,7 +300,7 @@ void TOOL_BASE::updateEndItem( const TOOL_EVENT& aEvent ) { int layer; bool snapEnabled = !aEvent.Modifier( MD_SHIFT ); - m_gridHelper->SetUseGrid( !aEvent.Modifier( MD_ALT ) ); + m_gridHelper->SetUseGrid( m_toolMgr->GetView()->GetGAL()->GetGridSnapping() ); m_gridHelper->SetSnap( snapEnabled ); controls()->ForceCursorPosition( false ); diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index 207d2d94e6..361704fcfa 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -408,7 +408,6 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); m_controls->ShowCursor( true ); - m_controls->SetGridSnapping( m_frame->IsGridVisible() ); // do not capture or auto-pan until we start placing some text SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT ); @@ -620,7 +619,6 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); m_controls->ShowCursor( true ); - m_controls->SetGridSnapping( m_frame->IsGridVisible() ); SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DIMENSION ); @@ -651,7 +649,6 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( m_frame->IsGridVisible() ); - m_controls->SetGridSnapping( m_frame->IsGridVisible() ); VECTOR2I cursorPos = grid.BestSnapAnchor( evt->IsPrime() ? evt->Position() : m_controls->GetMousePosition(), nullptr ); m_controls->ForceCursorPosition( true, cursorPos ); @@ -916,7 +913,6 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &newItems ); m_controls->ShowCursor( true ); - m_controls->SetGridSnapping( m_frame->IsGridVisible() ); m_controls->ForceCursorPosition( false ); SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DXF ); @@ -1020,7 +1016,6 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent ) grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( m_frame->IsGridVisible() ); - m_controls->SetGridSnapping( m_frame->IsGridVisible() ); VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), LSET::AllLayersMask() ); m_controls->ForceCursorPosition( true, cursorPos ); @@ -1124,7 +1119,6 @@ bool DRAWING_TOOL::drawSegment( const std::string& aTool, int aShape, DRAWSEGMEN grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( m_frame->IsGridVisible() ); - m_controls->SetGridSnapping( m_frame->IsGridVisible() ); cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), m_frame->GetActiveLayer() ); m_controls->ForceCursorPosition( true, cursorPos ); @@ -1401,7 +1395,6 @@ bool DRAWING_TOOL::drawArc( const std::string& aTool, DRAWSEGMENT** aGraphic, bo m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL ); grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( m_frame->IsGridVisible() ); - m_controls->SetGridSnapping( m_frame->IsGridVisible() ); VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), graphic ); m_controls->ForceCursorPosition( true, cursorPos ); @@ -1639,7 +1632,6 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent ) LSET layers( m_frame->GetActiveLayer() ); grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( m_frame->IsGridVisible() ); - m_controls->SetGridSnapping( m_frame->IsGridVisible() ); VECTOR2I cursorPos = grid.BestSnapAnchor( evt->IsPrime() ? evt->Position() : m_controls->GetMousePosition(), layers ); diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 18cfd70040..7ecc9493e4 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -407,7 +407,6 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference ) editFrame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW ); grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); - controls->SetGridSnapping( frame()->IsGridVisible() ); if( evt->IsAction( &PCB_ACTIONS::move ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT ) || evt->IsAction( &ACTIONS::refreshPreview ) diff --git a/pcbnew/tools/grid_helper.cpp b/pcbnew/tools/grid_helper.cpp index ce491e583e..f5a5503966 100644 --- a/pcbnew/tools/grid_helper.cpp +++ b/pcbnew/tools/grid_helper.cpp @@ -318,7 +318,6 @@ VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLaye ANCHOR* nearest = nearestAnchor( aOrigin, SNAPPABLE, aLayers ); VECTOR2I nearestGrid = Align( aOrigin ); - double gridDist = ( nearestGrid - aOrigin ).EuclideanNorm(); if( nearest && m_enableSnap ) { diff --git a/pcbnew/tools/grid_helper.h b/pcbnew/tools/grid_helper.h index 9a457ec98b..e9e2f43718 100644 --- a/pcbnew/tools/grid_helper.h +++ b/pcbnew/tools/grid_helper.h @@ -31,9 +31,8 @@ #include #include #include -#include -#include +class TOOL_MANAGER; class GRID_HELPER { public: diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index 74a47a1bbb..26fa39401a 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -798,7 +798,6 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); controls->ShowCursor( true ); - controls->SetGridSnapping( m_frame->IsGridVisible() ); std::string tool = aEvent.GetCommandStr().get(); m_frame->PushTool( tool ); @@ -1281,7 +1280,6 @@ int PCB_EDITOR_CONTROL::PlaceTarget( const TOOL_EVENT& aEvent ) view->Add( &preview ); m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); - controls->SetGridSnapping( frame()->IsGridVisible() ); std::string tool = aEvent.GetCommandStr().get(); m_frame->PushTool( tool ); diff --git a/pcbnew/tools/pcb_tool_base.cpp b/pcbnew/tools/pcb_tool_base.cpp index 49451fc804..d7bc047ed9 100644 --- a/pcbnew/tools/pcb_tool_base.cpp +++ b/pcbnew/tools/pcb_tool_base.cpp @@ -50,7 +50,6 @@ void PCB_TOOL_BASE::doInteractiveItemPlacement( const std::string& aTool, // do not capture or auto-pan until we start placing an item controls()->ShowCursor( true ); - controls()->SetGridSnapping( frame()->IsGridVisible() ); // Add a VIEW_GROUP that serves as a preview for the new item PCBNEW_SELECTION preview; diff --git a/pcbnew/tools/pcb_viewer_tools.cpp b/pcbnew/tools/pcb_viewer_tools.cpp index 182f845f48..999d92feec 100644 --- a/pcbnew/tools/pcb_viewer_tools.cpp +++ b/pcbnew/tools/pcb_viewer_tools.cpp @@ -225,7 +225,6 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent ) frame()->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW ); grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); - controls.SetGridSnapping( frame()->IsGridVisible() ); const VECTOR2I cursorPos = grid.BestSnapAnchor( controls.GetMousePosition(), nullptr ); controls.ForceCursorPosition(true, cursorPos ); diff --git a/pcbnew/tools/pcbnew_picker_tool.cpp b/pcbnew/tools/pcbnew_picker_tool.cpp index 928a002cd1..1ceee5d136 100644 --- a/pcbnew/tools/pcbnew_picker_tool.cpp +++ b/pcbnew/tools/pcbnew_picker_tool.cpp @@ -59,7 +59,6 @@ int PCBNEW_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); - controls->SetGridSnapping( frame->IsGridVisible() ); VECTOR2I cursorPos = grid.BestSnapAnchor( controls->GetMousePosition(), nullptr ); controls->ForceCursorPosition(true, cursorPos ); diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index 112b130805..2a30a27c90 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -383,7 +383,6 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) { grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( editFrame->IsGridVisible() ); - controls->SetGridSnapping( editFrame->IsGridVisible() ); if( !m_editPoints || evt->IsSelectionEvent() ) break;