Choose half-grid for mirror

Using the half-grid allows for odd-grid counts to remain on-grid,
closer to the actual center.

Fixes https://gitlab.com/kicad/code/kicad/issues/7493
This commit is contained in:
Seth Hillbrand 2021-02-15 11:58:12 -08:00
parent 55e34592a6
commit d93ba0a06a
4 changed files with 28 additions and 3 deletions

View File

@ -744,6 +744,20 @@ wxPoint EDA_DRAW_FRAME::GetNearestGridPosition( const wxPoint& aPosition ) const
}
wxPoint EDA_DRAW_FRAME::GetNearestHalfGridPosition( const wxPoint& aPosition ) const
{
const wxPoint& gridOrigin = GetGridOrigin();
VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize() / 2.0;
double xOffset = fmod( gridOrigin.x, gridSize.x );
int x = KiROUND( (aPosition.x - xOffset) / gridSize.x );
double yOffset = fmod( gridOrigin.y, gridSize.y );
int y = KiROUND( (aPosition.y - yOffset) / gridSize.y );
return wxPoint( KiROUND( x * gridSize.x + xOffset ), KiROUND( y * gridSize.y + yOffset ) );
}
const BOX2I EDA_DRAW_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
{
return BOX2I();

View File

@ -699,7 +699,7 @@ int SCH_EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
case SCH_SHEET_T:
// Mirror the sheet on itself. Sheets do not have a anchor point.
mirrorPoint = m_frame->GetNearestGridPosition( item->GetBoundingBox().Centre() );
mirrorPoint = m_frame->GetNearestHalfGridPosition( item->GetBoundingBox().Centre() );
if( xAxis )
item->MirrorX( mirrorPoint.y );
@ -717,7 +717,7 @@ int SCH_EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
}
else if( selection.GetSize() > 1 )
{
mirrorPoint = m_frame->GetNearestGridPosition( (wxPoint)selection.GetCenter() );
mirrorPoint = m_frame->GetNearestHalfGridPosition( (wxPoint)selection.GetCenter() );
for( unsigned ii = 0; ii < selection.GetSize(); ii++ )
{

View File

@ -206,7 +206,7 @@ int SYMBOL_EDITOR_EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
if( selection.GetSize() == 1 )
mirrorPoint = item->GetPosition();
else
mirrorPoint = m_frame->GetNearestGridPosition( mapCoords( selection.GetCenter() ) );
mirrorPoint = m_frame->GetNearestHalfGridPosition( mapCoords( selection.GetCenter() ) );
for( unsigned ii = 0; ii < selection.GetSize(); ii++ )
{

View File

@ -135,6 +135,17 @@ public:
*/
wxPoint GetNearestGridPosition( const wxPoint& aPosition ) const;
/**
* Return the nearest \a aGridSize / 2 location to \a aPosition.
*
* This is useful when attempting for keep outer points on grid but
* not the middle point.
*
* @param aPosition The position to check.
* @return The nearest half-grid position.
*/
wxPoint GetNearestHalfGridPosition( const wxPoint& aPosition ) const;
/**
* Return a reference to the default ORIGIN_TRANSFORMS object
*/