mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
Compare commits
2 Commits
00ae91d6b5
...
5a5191361f
Author | SHA1 | Date | |
---|---|---|---|
|
5a5191361f | ||
|
b47f8f4504 |
@ -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;
|
||||
|
@ -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 );
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user