Standardize placement tool modifiers

PlaceImage, PlaceImportedGraphics and PlaceText need to handle the grid
and hotpoint snapping as well as the modifiers to disable them
This commit is contained in:
Seth Hillbrand 2022-11-30 10:57:42 -08:00
parent 3c4c4e5166
commit cf33f33899
1 changed files with 26 additions and 3 deletions

View File

@ -603,7 +603,13 @@ int DRAWING_TOOL::PlaceImage( const TOOL_EVENT& aEvent )
while( TOOL_EVENT* evt = Wait() ) while( TOOL_EVENT* evt = Wait() )
{ {
setCursor(); setCursor();
cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() );
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
cursorPos = GetClampedCoords(
grid.BestSnapAnchor( m_controls->GetMousePosition(), m_frame->GetActiveLayer() ),
COORDS_PADDING );
m_controls->ForceCursorPosition( true, cursorPos );
if( evt->IsCancelInteractive() ) if( evt->IsCancelInteractive() )
{ {
@ -780,6 +786,7 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent )
const BOARD_DESIGN_SETTINGS& bds = m_frame->GetDesignSettings(); const BOARD_DESIGN_SETTINGS& bds = m_frame->GetDesignSettings();
BOARD_COMMIT commit( m_frame ); BOARD_COMMIT commit( m_frame );
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT ); SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT );
PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
auto cleanup = auto cleanup =
[&]() [&]()
@ -828,7 +835,13 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent )
while( TOOL_EVENT* evt = Wait() ) while( TOOL_EVENT* evt = Wait() )
{ {
setCursor(); setCursor();
VECTOR2I cursorPos = m_controls->GetCursorPosition();
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
VECTOR2I cursorPos = GetClampedCoords(
grid.BestSnapAnchor( m_controls->GetMousePosition(), m_frame->GetActiveLayer() ),
COORDS_PADDING );
m_controls->ForceCursorPosition( true, cursorPos );
if( evt->IsCancelInteractive() ) if( evt->IsCancelInteractive() )
{ {
@ -1517,6 +1530,7 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent )
PCB_SELECTION preview; PCB_SELECTION preview;
BOARD_COMMIT commit( m_frame ); BOARD_COMMIT commit( m_frame );
PCB_GROUP* group = nullptr; PCB_GROUP* group = nullptr;
PCB_LAYER_ID layer = F_Cu;
if( dlg.ShouldGroupItems() ) if( dlg.ShouldGroupItems() )
{ {
@ -1560,6 +1574,8 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent )
return 0; return 0;
} }
layer = newItems.front()->GetLayer();
m_view->Add( &preview ); m_view->Add( &preview );
// Clear the current selection then select the drawings so that edit tools work on them // Clear the current selection then select the drawings so that edit tools work on them
@ -1582,6 +1598,7 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent )
setCursor(); setCursor();
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DXF ); SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DXF );
PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
// Now move the new items to the current cursor position: // Now move the new items to the current cursor position:
VECTOR2I cursorPos = m_controls->GetCursorPosition( !aEvent.DisableGridSnapping() ); VECTOR2I cursorPos = m_controls->GetCursorPosition( !aEvent.DisableGridSnapping() );
@ -1596,7 +1613,13 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent )
while( TOOL_EVENT* evt = Wait() ) while( TOOL_EVENT* evt = Wait() )
{ {
setCursor(); setCursor();
cursorPos = m_controls->GetCursorPosition( !evt->DisableGridSnapping() );
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
cursorPos = GetClampedCoords(
grid.BestSnapAnchor( m_controls->GetMousePosition(), layer ),
COORDS_PADDING );
m_controls->ForceCursorPosition( true, cursorPos );
if( evt->IsCancelInteractive() || evt->IsActivate() ) if( evt->IsCancelInteractive() || evt->IsActivate() )
{ {