Compare commits

...

2 Commits

Author SHA1 Message Date
Seth Hillbrand
5a5191361f Second pass at fixing warping and grids
First attempt caused additional problems for #21535

Fixes https://gitlab.com/kicad/code/kicad/-/issues/18196

(cherry picked from commit 2cdeb0cd7c618d2ff3f5dc95c53a6b217a55af9d)
2025-09-12 10:52:36 +02:00
jean-pierre charras
b47f8f4504 Revert "Remove the forced ancillary grid"
This reverts commit 7b602142b12050dbc517d86d74aa87bba3e1dc5b.
2025-09-12 10:51:29 +02:00
3 changed files with 41 additions and 20 deletions

View File

@ -182,35 +182,38 @@ void GRID_HELPER::SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin )
VECTOR2I GRID_HELPER::AlignGrid( const VECTOR2I& aPoint ) const
{
return computeNearest( aPoint, GetGrid() );
return computeNearest( aPoint, GetGrid(), GetOrigin() );
}
VECTOR2I GRID_HELPER::AlignGrid( const VECTOR2I& aPoint, const VECTOR2D& aGrid ) const
VECTOR2I GRID_HELPER::AlignGrid( const VECTOR2I& aPoint, const VECTOR2D& aGrid,
const VECTOR2D& aOffset ) const
{
return computeNearest( aPoint, aGrid );
return computeNearest( aPoint, aGrid, aOffset );
}
VECTOR2I GRID_HELPER::computeNearest( const VECTOR2I& aPoint, const VECTOR2I& aGrid ) const
VECTOR2I GRID_HELPER::computeNearest( const VECTOR2I& aPoint, const VECTOR2I& aGrid,
const VECTOR2I& aOffset ) const
{
return VECTOR2I( KiROUND( static_cast<double>( aPoint.x ) / aGrid.x ) * aGrid.x,
KiROUND( static_cast<double>( aPoint.y ) / aGrid.y ) * aGrid.y );
return VECTOR2I( KiROUND( (double) ( aPoint.x - aOffset.x ) / aGrid.x ) * aGrid.x + aOffset.x,
KiROUND( (double) ( aPoint.y - aOffset.y ) / aGrid.y ) * aGrid.y + aOffset.y );
}
VECTOR2I GRID_HELPER::Align( const VECTOR2I& aPoint ) const
{
return Align( aPoint, GetGrid() );
return Align( aPoint, GetGrid(), GetOrigin() );
}
VECTOR2I GRID_HELPER::Align( const VECTOR2I& aPoint, const VECTOR2D& aGrid ) const
VECTOR2I GRID_HELPER::Align( const VECTOR2I& aPoint, const VECTOR2D& aGrid,
const VECTOR2D& aOffset ) const
{
if( !canUseGrid() )
return aPoint;
VECTOR2I nearest = AlignGrid( aPoint, aGrid );
VECTOR2I nearest = AlignGrid( aPoint, aGrid, aOffset );
if( !m_auxAxis )
return nearest;

View File

@ -64,19 +64,21 @@ public:
virtual VECTOR2I Align( const VECTOR2I& aPoint, GRID_HELPER_GRIDS aGrid ) const
{
return Align( aPoint, GetGridSize( aGrid ) );
return Align( aPoint, GetGridSize( aGrid ), GetOrigin() );
}
virtual VECTOR2I AlignGrid( const VECTOR2I& aPoint, GRID_HELPER_GRIDS aGrid ) const
{
return AlignGrid( aPoint, GetGridSize( aGrid ) );
return AlignGrid( aPoint, GetGridSize( aGrid ), GetOrigin() );
}
virtual VECTOR2I Align( const VECTOR2I& aPoint ) const;
virtual VECTOR2I Align( const VECTOR2I& aPoint, const VECTOR2D& aGrid ) const;
virtual VECTOR2I Align( const VECTOR2I& aPoint, const VECTOR2D& aGrid,
const VECTOR2D& aOffset ) const;
VECTOR2I AlignGrid( const VECTOR2I& aPoint ) const;
VECTOR2I AlignGrid( const VECTOR2I& aPoint, const VECTOR2D& aGrid ) const;
VECTOR2I AlignGrid( const VECTOR2I& aPoint, const VECTOR2D& aGrid,
const VECTOR2D& aOffset ) const;
/**
* Gets the coarsest grid that applies to a selecion of items.
@ -197,7 +199,8 @@ protected:
*/
bool canUseGrid() const;
VECTOR2I computeNearest( const VECTOR2I& aPoint, const VECTOR2I& aGrid ) const;
VECTOR2I computeNearest( const VECTOR2I& aPoint, const VECTOR2I& aGrid,
const VECTOR2I& aOffset ) const;
protected:
void showConstructionGeometry( bool aShow );

View File

@ -667,15 +667,30 @@ bool EDIT_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, BOARD_COMMIT* aCommit
}
else
{
// Check if user wants to warp the mouse to origin of moved object
if( !editFrame->GetMoveWarpsCursor() )
m_cursor = originalCursorPos; // No, so use original mouse pos instead
VECTOR2I snapped = grid.Align( m_cursor, grid.GetSelectionGrid( selection ) );
VECTOR2I delta = snapped - m_cursor;
selection.SetReferencePoint( m_cursor );
grid.SetAuxAxes( true, m_cursor );
if( delta.x || delta.y )
{
for( BOARD_ITEM* item : sel_items )
{
if( item->GetParent() && item->GetParent()->IsSelected() )
continue;
item->Move( delta );
}
}
selection.SetReferencePoint( snapped );
grid.SetAuxAxes( true, snapped );
if( !editFrame->GetMoveWarpsCursor() )
m_cursor = originalCursorPos;
else
m_cursor = snapped;
}
originalPos = m_cursor;
originalPos = selection.GetReferencePoint();
}
// Update variables for bounding box collision calculations