Browse Source

Make grid snapping depend on grid visibility

Turning the grid view on enables snapping to the grid.  Turning it off
removes the snap and allows free draw
pull/16/head
Seth Hillbrand 5 years ago
parent
commit
4026904cc4
  1. 5
      common/tool/picker_tool.cpp
  2. 2
      eeschema/lib_view_frame.cpp
  3. 2
      eeschema/libedit/lib_edit_frame.cpp
  4. 2
      eeschema/sch_draw_panel.cpp
  5. 2
      eeschema/sch_preview_panel.cpp
  6. 2
      eeschema/tools/lib_drawing_tools.cpp
  7. 5
      eeschema/tools/lib_move_tool.cpp
  8. 2
      eeschema/tools/sch_drawing_tools.cpp
  9. 5
      eeschema/tools/sch_move_tool.cpp
  10. 1
      gerbview/gerbview_draw_panel_gal.cpp
  11. 2
      gerbview/tools/gerbview_selection_tool.cpp
  12. 1
      pagelayout_editor/pl_draw_panel_gal.cpp
  13. 5
      pagelayout_editor/tools/pl_edit_tool.cpp
  14. 1
      pcbnew/pcb_draw_panel_gal.cpp
  15. 29
      pcbnew/tools/drawing_tool.cpp
  16. 3
      pcbnew/tools/edit_tool.cpp
  17. 4
      pcbnew/tools/grid_helper.cpp
  18. 5
      pcbnew/tools/pcb_editor_control.cpp
  19. 2
      pcbnew/tools/pcb_tool_base.cpp
  20. 2
      pcbnew/tools/pcb_viewer_tools.cpp
  21. 5
      pcbnew/tools/pcbnew_picker_tool.cpp
  22. 4
      pcbnew/tools/point_editor.cpp

5
common/tool/picker_tool.cpp

@ -62,15 +62,12 @@ int PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
m_frame->PushTool( tool );
Activate();
// To many things are off-grid in LibEdit; turn snapping off.
bool snap = !m_frame->IsType( FRAME_SCH_LIB_EDITOR );
setControls();
while( TOOL_EVENT* evt = Wait() )
{
m_frame->GetCanvas()->SetCurrentCursor( m_cursor );
VECTOR2D cursorPos = controls->GetCursorPosition( snap && !evt->Modifier( MD_ALT ) );
VECTOR2D cursorPos = controls->GetCursorPosition( m_frame->IsGridVisible() );
if( evt->IsCancelInteractive() || evt->IsActivate() )
{

2
eeschema/lib_view_frame.cpp

@ -194,7 +194,7 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame
}
SyncView();
GetCanvas()->GetViewControls()->SetGridSnapping( true );
GetCanvas()->GetViewControls()->SetGridSnapping( IsGridVisible() );
GetCanvas()->SetCanFocus( false );
// Set the working/draw area size to display a symbol to a reasonable value:

2
eeschema/libedit/lib_edit_frame.cpp

@ -175,7 +175,7 @@ LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
Show( true );
SyncView();
GetCanvas()->GetViewControls()->SetGridSnapping( true );
GetCanvas()->GetViewControls()->SetGridSnapping( IsGridVisible() );
GetCanvas()->GetView()->UseDrawPriority( true );
GetCanvas()->GetGAL()->SetAxesEnabled( true );

2
eeschema/sch_draw_panel.cpp

@ -91,7 +91,7 @@ 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( true );
m_viewControls->SetGridSnapping( m_gal->GetGridVisibility() );
SetEvtHandlerEnabled( true );
SetFocus();

2
eeschema/sch_preview_panel.cpp

@ -70,7 +70,7 @@ 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( true );
m_viewControls->SetGridSnapping( m_gal->GetGridVisibility() );
SetEvtHandlerEnabled( true );
SetFocus();

2
eeschema/tools/lib_drawing_tools.cpp

@ -397,7 +397,7 @@ int LIB_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
int LIB_DRAWING_TOOLS::PlaceAnchor( const TOOL_EVENT& aEvent )
{
getViewControls()->ShowCursor( true );
getViewControls()->SetGridSnapping( true );
getViewControls()->SetGridSnapping( m_frame->IsGridVisible() );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );

5
eeschema/tools/lib_move_tool.cpp

@ -70,7 +70,7 @@ void LIB_MOVE_TOOL::Reset( RESET_REASON aReason )
int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
{
KIGFX::VIEW_CONTROLS* controls = getViewControls();
controls->SetGridSnapping( true );
controls->SetGridSnapping( m_frame->IsGridVisible() );
m_anchorPos = { 0, 0 };
@ -103,7 +103,7 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
do
{
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
controls->SetGridSnapping( !evt->Modifier( MD_ALT ) );
controls->SetGridSnapping( m_frame->IsGridVisible() );
if( evt->IsAction( &EE_ACTIONS::move ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT )
|| evt->IsAction( &ACTIONS::refreshPreview )
@ -271,7 +271,6 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
controls->ForceCursorPosition( false );
controls->ShowCursor( false );
controls->SetGridSnapping( false );
controls->SetAutoPan( false );
if( !chain_commands )

2
eeschema/tools/sch_drawing_tools.cpp

@ -449,7 +449,7 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true );
getViewControls()->SetGridSnapping( true );
getViewControls()->SetGridSnapping( m_frame->IsGridVisible() );
SCH_ITEM* previewItem;
switch( type )

5
eeschema/tools/sch_move_tool.cpp

@ -109,7 +109,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
KIGFX::VIEW_CONTROLS* controls = getViewControls();
controls->SetGridSnapping( true );
controls->SetGridSnapping( m_frame->IsGridVisible() );
m_anchorPos.reset();
@ -171,7 +171,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
do
{
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
controls->SetGridSnapping( !evt->Modifier( MD_ALT ) );
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 )
@ -428,7 +428,6 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
controls->ForceCursorPosition( false );
controls->ShowCursor( false );
controls->SetGridSnapping( false );
controls->SetAutoPan( false );
if( !chain_commands )

1
gerbview/gerbview_draw_panel_gal.cpp

@ -49,6 +49,7 @@ 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();

2
gerbview/tools/gerbview_selection_tool.cpp

@ -571,7 +571,7 @@ int GERBVIEW_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
bool originSet = false;
controls.ShowCursor( true );
controls.SetGridSnapping( true );
controls.SetGridSnapping( m_frame->IsGridVisible() );
while( TOOL_EVENT* evt = Wait() )
{

1
pagelayout_editor/pl_draw_panel_gal.cpp

@ -65,6 +65,7 @@ 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() );
}

5
pagelayout_editor/tools/pl_edit_tool.cpp

@ -93,7 +93,7 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
{
KIGFX::VIEW_CONTROLS* controls = getViewControls();
controls->SetGridSnapping( true );
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 +123,7 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
do
{
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
controls->SetGridSnapping( !evt->Modifier( MD_ALT ) );
controls->SetGridSnapping( m_frame->IsGridVisible() );
if( evt->IsAction( &PL_ACTIONS::move ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT )
|| evt->IsAction( &ACTIONS::refreshPreview ) )
@ -236,7 +236,6 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
controls->ForceCursorPosition( false );
controls->ShowCursor( false );
controls->SetGridSnapping( false );
controls->SetAutoPan( false );
if( !chain_commands )

1
pcbnew/pcb_draw_panel_gal.cpp

@ -126,6 +126,7 @@ 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)

29
pcbnew/tools/drawing_tool.cpp

@ -408,7 +408,7 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
m_controls->ShowCursor( true );
m_controls->SetGridSnapping( 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 +620,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
m_controls->ShowCursor( true );
m_controls->SetGridSnapping( true );
m_controls->SetGridSnapping( m_frame->IsGridVisible() );
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DIMENSION );
@ -650,8 +650,8 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL );
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
m_controls->SetGridSnapping( !evt->Modifier( MD_ALT ) );
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 +916,7 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &newItems );
m_controls->ShowCursor( true );
m_controls->SetGridSnapping( true );
m_controls->SetGridSnapping( m_frame->IsGridVisible() );
m_controls->ForceCursorPosition( false );
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DXF );
@ -1011,7 +1011,6 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
m_controls->ShowCursor( true );
m_controls->SetGridSnapping( true );
m_controls->SetAutoPan( true );
m_controls->CaptureCursor( false );
@ -1020,8 +1019,8 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent )
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_BULLSEYE );
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
m_controls->SetGridSnapping( !evt->Modifier( MD_ALT ) );
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,8 +1123,8 @@ bool DRAWING_TOOL::drawSegment( const std::string& aTool, int aShape, DRAWSEGMEN
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL );
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
m_controls->SetGridSnapping( !evt->Modifier( MD_ALT ) );
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 );
@ -1383,7 +1382,6 @@ bool DRAWING_TOOL::drawArc( const std::string& aTool, DRAWSEGMENT** aGraphic, bo
GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
m_controls->ShowCursor( true );
m_controls->SetGridSnapping( true );
bool firstPoint = false;
bool cancelled = false;
@ -1402,8 +1400,8 @@ 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( !evt->Modifier( MD_ALT ) );
m_controls->SetGridSnapping( !evt->Modifier( MD_ALT ) );
grid.SetUseGrid( m_frame->IsGridVisible() );
m_controls->SetGridSnapping( m_frame->IsGridVisible() );
VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), graphic );
m_controls->ForceCursorPosition( true, cursorPos );
@ -1623,7 +1621,6 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent )
Activate(); // register for events
m_controls->ShowCursor( true );
m_controls->SetGridSnapping( true );
bool started = false;
GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
@ -1641,8 +1638,8 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent )
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL );
LSET layers( m_frame->GetActiveLayer() );
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
m_controls->SetGridSnapping( !evt->Modifier( MD_ALT ) );
grid.SetUseGrid( m_frame->IsGridVisible() );
m_controls->SetGridSnapping( m_frame->IsGridVisible() );
VECTOR2I cursorPos = grid.BestSnapAnchor( evt->IsPrime() ? evt->Position()
: m_controls->GetMousePosition(),
layers );

3
pcbnew/tools/edit_tool.cpp

@ -409,7 +409,7 @@ 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( !evt->Modifier( MD_ALT ) );
controls->SetGridSnapping( frame()->IsGridVisible() );
if( evt->IsAction( &PCB_ACTIONS::move ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT )
|| evt->IsAction( &ACTIONS::refreshPreview )
@ -616,7 +616,6 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference )
m_lockedSelected = false;
controls->ForceCursorPosition( false );
controls->ShowCursor( false );
controls->SetGridSnapping( false );
controls->SetAutoPan( false );
m_dragging = false;

4
pcbnew/tools/grid_helper.cpp

@ -322,9 +322,7 @@ VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLaye
if( nearest && m_enableSnap )
{
double snapDist = nearest->Distance( aOrigin );
if( !m_enableGrid || snapDist <= gridDist )
if( nearest->Distance( aOrigin ) <= snapRange )
{
m_viewSnapPoint.SetPosition( wxPoint( nearest->pos ) );
m_viewSnapLine.SetPosition( wxPoint( nearest->pos ) );

5
pcbnew/tools/pcb_editor_control.cpp

@ -797,7 +797,7 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
controls->ShowCursor( true );
controls->SetGridSnapping( true );
controls->SetGridSnapping( m_frame->IsGridVisible() );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
@ -1280,7 +1280,7 @@ int PCB_EDITOR_CONTROL::PlaceTarget( const TOOL_EVENT& aEvent )
view->Add( &preview );
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
controls->SetGridSnapping( true );
controls->SetGridSnapping( frame()->IsGridVisible() );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );
@ -1363,7 +1363,6 @@ int PCB_EDITOR_CONTROL::PlaceTarget( const TOOL_EVENT& aEvent )
preview.Clear();
delete target;
view->Remove( &preview );
controls->SetGridSnapping( false );
return 0;
}

2
pcbnew/tools/pcb_tool_base.cpp

@ -50,7 +50,7 @@ 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( true );
controls()->SetGridSnapping( frame()->IsGridVisible() );
// Add a VIEW_GROUP that serves as a preview for the new item
PCBNEW_SELECTION preview;

2
pcbnew/tools/pcb_viewer_tools.cpp

@ -225,7 +225,7 @@ 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( !evt->Modifier( MD_ALT ) );
controls.SetGridSnapping( frame()->IsGridVisible() );
const VECTOR2I cursorPos = grid.BestSnapAnchor( controls.GetMousePosition(), nullptr );
controls.ForceCursorPosition(true, cursorPos );

5
pcbnew/tools/pcbnew_picker_tool.cpp

@ -59,7 +59,7 @@ int PCBNEW_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
controls->SetGridSnapping( !evt->Modifier( MD_ALT ) );
controls->SetGridSnapping( frame->IsGridVisible() );
VECTOR2I cursorPos = grid.BestSnapAnchor( controls->GetMousePosition(), nullptr );
controls->ForceCursorPosition(true, cursorPos );
@ -186,9 +186,6 @@ void PCBNEW_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->SetGridSnapping( false );
controls->CaptureCursor( false );
controls->SetAutoPan( false );
}

4
pcbnew/tools/point_editor.cpp

@ -382,8 +382,8 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
while( TOOL_EVENT* evt = Wait() )
{
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
controls->SetGridSnapping( !evt->Modifier( MD_ALT ) );
grid.SetUseGrid( editFrame->IsGridVisible() );
controls->SetGridSnapping( editFrame->IsGridVisible() );
if( !m_editPoints || evt->IsSelectionEvent() )
break;

Loading…
Cancel
Save