Array: add option to centre grid on the original location

Especially for SMD footprint array, it's awkward to have to
offset the pad to the corner first before making the array.

Relates-To: https://gitlab.com/kicad/code/kicad/-/issues/16882
This commit is contained in:
John Beard
2024-10-28 00:47:01 +08:00
parent 3ad92bc8db
commit b931dc5299
7 changed files with 485 additions and 294 deletions
+20 -2
View File
@@ -49,7 +49,7 @@ VECTOR2I ARRAY_GRID_OPTIONS::getGridCoords( int n ) const
}
ARRAY_OPTIONS::TRANSFORM ARRAY_GRID_OPTIONS::GetTransform( int n, const VECTOR2I& aPos ) const
VECTOR2I ARRAY_GRID_OPTIONS::gtItemPosRelativeToItem0( int n ) const
{
VECTOR2I point;
@@ -74,7 +74,25 @@ ARRAY_OPTIONS::TRANSFORM ARRAY_GRID_OPTIONS::GetTransform( int n, const VECTOR2I
point += stagger_delta * copysign( stagger_idx, m_stagger ) / stagger;
}
// this is already relative to the first array entry
return point;
}
ARRAY_OPTIONS::TRANSFORM ARRAY_GRID_OPTIONS::GetTransform( int n, const VECTOR2I& aPos ) const
{
VECTOR2I point = gtItemPosRelativeToItem0( n );
// Bump the item by half the array size
if( m_centred )
{
// Get the array extents
const int arrayExtentX = ( m_nx - 1 ) * m_delta.x + ( m_ny - 1 ) * m_offset.x;
const int arrayExtentY = ( m_ny - 1 ) * m_delta.y + ( m_nx - 1 ) * m_offset.y;
std::cout << "Subtracting " << VECTOR2I( arrayExtentX, arrayExtentY ) / 2 << std::endl;
point -= VECTOR2I( arrayExtentX, arrayExtentY ) / 2;
}
return { point, ANGLE_0 };
}