diff --git a/common/eda_draw_frame.cpp b/common/eda_draw_frame.cpp index df3c4c4744..536710fd39 100644 --- a/common/eda_draw_frame.cpp +++ b/common/eda_draw_frame.cpp @@ -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(); diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 1d8214c330..83268dccc7 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -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++ ) { diff --git a/eeschema/tools/symbol_editor_edit_tool.cpp b/eeschema/tools/symbol_editor_edit_tool.cpp index 9a9ac45c20..632c49b843 100644 --- a/eeschema/tools/symbol_editor_edit_tool.cpp +++ b/eeschema/tools/symbol_editor_edit_tool.cpp @@ -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++ ) { diff --git a/include/eda_draw_frame.h b/include/eda_draw_frame.h index b8fe5b8748..634f274b33 100644 --- a/include/eda_draw_frame.h +++ b/include/eda_draw_frame.h @@ -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 */