From 85194989b20729de47eb87aa03b8a4019a895219 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sat, 6 Oct 2018 19:55:20 -0700 Subject: [PATCH] pcbnew: Ensure that dimension tool snaps to anything The dimension tool is used to measure physical dimensions on the board therefore it should be able to snap to any other object, not just those on its own layer set as is the case for other items. This also deals with a corner snap case for constraints by first snapping, then constraining, then aligning to grid. This ensures OoO for alignment from least to most constraining. --- pcbnew/tools/point_editor.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index e8de3d6f91..4e65537f27 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -307,10 +307,11 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) KIGFX::VIEW* view = getView(); PCB_BASE_EDIT_FRAME* editFrame = getEditFrame(); + controls->ShowCursor( true ); controls->SetSnapping( false ); GRID_HELPER grid( editFrame ); - auto item = selection.Front(); + BOARD_ITEM* item = static_cast( selection.Front() ); m_editPoints = EDIT_POINTS_FACTORY::Make( item, getView()->GetGAL() ); @@ -324,6 +325,10 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) bool revert = false; BOARD_COMMIT commit( editFrame ); + LSET snapLayers = item->GetLayerSet(); + + if( item->Type() == PCB_DIMENSION_T ) + snapLayers = LSET::AllLayersMask(); // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) @@ -357,6 +362,8 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) grid.SetAuxAxes( true, m_original.GetPosition(), true ); } + m_editedPoint->SetPosition( grid.BestSnapAnchor( evt->Position(), snapLayers ) ); + bool enableAltConstraint = !!evt->Modifier( MD_CTRL ); if( enableAltConstraint != (bool) m_altConstraint ) // alternative constraint @@ -367,9 +374,10 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) else m_editedPoint->ApplyConstraint(); + // There is a chance that the constraint above knocked us off grid + // This ensures the final point is on a grid line if requested. + m_editedPoint->SetPosition( grid.Align( m_editedPoint->GetPosition() ) ); - m_editedPoint->SetPosition( grid.BestSnapAnchor( evt->Position(), - static_cast( item ) ) ); updateItem(); updatePoints(); }