Schematic Editor: apply grid overrides to more tools

This commit is contained in:
Mike Williams 2023-08-23 11:13:46 -04:00
parent a44dd4d88f
commit 66ed9cfe57
2 changed files with 47 additions and 15 deletions

View File

@ -436,6 +436,8 @@ int EE_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
Activate();
KIGFX::VIEW_CONTROLS* controls = getViewControls();
EE_GRID_HELPER grid( m_toolMgr );
VECTOR2I cursorPos;
KIGFX::VIEW* view = getView();
EDA_ITEM* item = selection.Front();
SCH_COMMIT commit( m_toolMgr );
@ -451,6 +453,12 @@ int EE_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
cursorPos = grid.Align( controls->GetMousePosition(), GRID_HELPER_GRIDS::GRID_GRAPHICS );
controls->ForceCursorPosition( true, cursorPos );
if( !m_editPoints || evt->IsSelectionEvent() )
break;
@ -476,7 +484,6 @@ int EE_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
commit.Modify( connected.first, m_frame->GetScreen() );
}
controls->ForceCursorPosition( false );
inDrag = true;
}
@ -560,7 +567,7 @@ void EE_POINT_EDITOR::pinEditedCorner( int minWidth, int minHeight, VECTOR2I& to
topLeft.y = std::min( topLeft.y, botRight.y - minHeight );
if( aGrid->GetSnap() )
topLeft = aGrid->AlignGrid( topLeft );
topLeft = aGrid->AlignGrid( topLeft, GRID_HELPER_GRIDS::GRID_GRAPHICS );
// push edited point edges to adjacent corners
topRight.y = topLeft.y;
@ -573,7 +580,7 @@ void EE_POINT_EDITOR::pinEditedCorner( int minWidth, int minHeight, VECTOR2I& to
topRight.y = std::min( topRight.y, botLeft.y - minHeight );
if( aGrid->GetSnap() )
topRight = aGrid->AlignGrid( topRight );
topRight = aGrid->AlignGrid( topRight, GRID_HELPER_GRIDS::GRID_GRAPHICS );
// push edited point edges to adjacent corners
topLeft.y = topRight.y;
@ -586,7 +593,7 @@ void EE_POINT_EDITOR::pinEditedCorner( int minWidth, int minHeight, VECTOR2I& to
botLeft.y = std::max( botLeft.y, topRight.y + minHeight );
if( aGrid->GetSnap() )
botLeft = aGrid->AlignGrid( botLeft );
botLeft = aGrid->AlignGrid( botLeft, GRID_HELPER_GRIDS::GRID_GRAPHICS );
// push edited point edges to adjacent corners
botRight.y = botLeft.y;
@ -599,7 +606,7 @@ void EE_POINT_EDITOR::pinEditedCorner( int minWidth, int minHeight, VECTOR2I& to
botRight.y = std::max( botRight.y, topLeft.y + minHeight );
if( aGrid->GetSnap() )
botRight = aGrid->AlignGrid( botRight );
botRight = aGrid->AlignGrid( botRight, GRID_HELPER_GRIDS::GRID_GRAPHICS );
// push edited point edges to adjacent corners
botLeft.y = botRight.y;
@ -610,28 +617,28 @@ void EE_POINT_EDITOR::pinEditedCorner( int minWidth, int minHeight, VECTOR2I& to
topLeft.y = std::min( topLeft.y, botRight.y - minHeight );
if( aGrid->GetSnap() )
topLeft = aGrid->AlignGrid( topLeft );
topLeft = aGrid->AlignGrid( topLeft, GRID_HELPER_GRIDS::GRID_GRAPHICS );
}
else if( isModified( m_editPoints->Line( RECT_LEFT ) ) )
{
topLeft.x = std::min( topLeft.x, botRight.x - minWidth );
if( aGrid->GetSnap() )
topLeft = aGrid->AlignGrid( topLeft );
topLeft = aGrid->AlignGrid( topLeft, GRID_HELPER_GRIDS::GRID_GRAPHICS );
}
else if( isModified( m_editPoints->Line( RECT_BOT ) ) )
{
botRight.y = std::max( botRight.y, topLeft.y + minHeight );
if( aGrid->GetSnap() )
botRight = aGrid->AlignGrid( botRight );
botRight = aGrid->AlignGrid( botRight, GRID_HELPER_GRIDS::GRID_GRAPHICS );
}
else if( isModified( m_editPoints->Line( RECT_RIGHT ) ) )
{
botRight.x = std::max( botRight.x, topLeft.x + minWidth );
if( aGrid->GetSnap() )
botRight = aGrid->AlignGrid( botRight );
botRight = aGrid->AlignGrid( botRight, GRID_HELPER_GRIDS::GRID_GRAPHICS );
}
}

View File

@ -111,7 +111,6 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent )
std::vector<PICKED_SYMBOL>* historyList = nullptr;
bool ignorePrimePosition = false;
COMMON_SETTINGS* common_settings = Pgm().GetCommonSettings();
EE_GRID_HELPER grid( m_toolMgr );
SCH_SCREEN* screen = m_frame->GetScreen();
if( m_inPlaceSymbol )
@ -119,6 +118,10 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent )
REENTRANCY_GUARD guard( &m_inPlaceSymbol );
KIGFX::VIEW_CONTROLS* controls = getViewControls();
EE_GRID_HELPER grid( m_toolMgr );
VECTOR2I cursorPos;
// First we need to get all instances of this sheet so we can annotate
// whatever symbols we place on all copies
SCH_SHEET_LIST hierarchy = m_frame->Schematic().GetSheets();
@ -248,7 +251,8 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent )
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() );
cursorPos = grid.Align( controls->GetMousePosition(), GRID_HELPER_GRIDS::GRID_GRAPHICS );
controls->ForceCursorPosition( true, cursorPos );
// The tool hotkey is interpreted as a click when drawing
bool isSyntheticClick = symbol && evt->IsActivate() && evt->HasPosition()
@ -478,7 +482,6 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
{
SCH_BITMAP* image = aEvent.Parameter<SCH_BITMAP*>();
bool immediateMode = image != nullptr;
EE_GRID_HELPER grid( m_toolMgr );
bool ignorePrimePosition = false;
COMMON_SETTINGS* common_settings = Pgm().GetCommonSettings();
@ -487,6 +490,10 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
REENTRANCY_GUARD guard( &m_inPlaceImage );
EE_GRID_HELPER grid( m_toolMgr );
KIGFX::VIEW_CONTROLS* controls = getViewControls();
VECTOR2I cursorPos;
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
// Add all the drawable symbols to preview
@ -545,7 +552,11 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
while( TOOL_EVENT* evt = Wait() )
{
setCursor();
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() );
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
cursorPos = grid.Align( controls->GetMousePosition(), GRID_HELPER_GRIDS::GRID_GRAPHICS );
controls->ForceCursorPosition( true, cursorPos );
// The tool hotkey is interpreted as a click when drawing
bool isSyntheticClick = image && evt->IsActivate() && evt->HasPosition()
@ -1505,6 +1516,10 @@ int SCH_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
REENTRANCY_GUARD guard( &m_inDrawShape );
KIGFX::VIEW_CONTROLS* controls = getViewControls();
EE_GRID_HELPER grid( m_toolMgr );
VECTOR2I cursorPos;
// We might be running as the same shape in another co-routine. Make sure that one
// gets whacked.
m_toolMgr->DeactivateTool();
@ -1543,8 +1558,11 @@ int SCH_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
while( TOOL_EVENT* evt = Wait() )
{
setCursor();
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() );
cursorPos = grid.Align( controls->GetMousePosition(), GRID_HELPER_GRIDS::GRID_GRAPHICS );
controls->ForceCursorPosition( true, cursorPos );
// The tool hotkey is interpreted as a click when drawing
bool isSyntheticClick = item && evt->IsActivate() && evt->HasPosition()
@ -1729,6 +1747,10 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent )
REENTRANCY_GUARD guard( &m_inDrawSheet );
KIGFX::VIEW_CONTROLS* controls = getViewControls();
EE_GRID_HELPER grid( m_toolMgr );
VECTOR2I cursorPos;
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
m_frame->PushTool( aEvent );
@ -1763,8 +1785,11 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent )
while( TOOL_EVENT* evt = Wait() )
{
setCursor();
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() );
cursorPos = grid.Align( controls->GetMousePosition(), GRID_HELPER_GRIDS::GRID_GRAPHICS );
controls->ForceCursorPosition( true, cursorPos );
// The tool hotkey is interpreted as a click when drawing
bool isSyntheticClick = sheet && evt->IsActivate() && evt->HasPosition()