Implement Mirror H/V for tracks and vias.

While not that often useful, it's really annoying that it doesn't work
when you *do* find a use-case for it.

Fixes https://gitlab.com/kicad/code/kicad/issues/6853
This commit is contained in:
Jeff Young 2022-09-24 19:54:56 +01:00
parent 328cc27020
commit 7e71dc084c
3 changed files with 48 additions and 2 deletions

View File

@ -25,6 +25,7 @@
*/
#include <pcb_base_frame.h>
#include <core/mirror.h>
#include <connectivity/connectivity_data.h>
#include <board.h>
#include <board_design_settings.h>
@ -295,6 +296,38 @@ void PCB_ARC::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
}
void PCB_TRACK::Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis )
{
if( aMirrorAroundXAxis )
{
MIRROR( m_Start.y, aCentre.y );
MIRROR( m_End.y, aCentre.y );
}
else
{
MIRROR( m_Start.x, aCentre.x );
MIRROR( m_End.x, aCentre.x );
}
}
void PCB_ARC::Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis )
{
if( aMirrorAroundXAxis )
{
MIRROR( m_Start.y, aCentre.y );
MIRROR( m_End.y, aCentre.y );
MIRROR( m_Mid.y, aCentre.y );
}
else
{
MIRROR( m_Start.x, aCentre.x );
MIRROR( m_End.x, aCentre.x );
MIRROR( m_Mid.x, aCentre.x );
}
}
void PCB_TRACK::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
{
if( aFlipLeftRight )

View File

@ -93,6 +93,8 @@ public:
void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
virtual void Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis );
void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) override;
void SetPosition( const VECTOR2I& aPos ) override { m_Start = aPos; }
@ -262,9 +264,11 @@ public:
m_End += aMoveVector;
}
virtual void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
virtual void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) override;
void Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis ) override;
void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) override;
void SetMid( const VECTOR2I& aMid ) { m_Mid = aMid; }
const VECTOR2I& GetMid() const { return m_Mid; }

View File

@ -1326,6 +1326,9 @@ int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
case PCB_FP_ZONE_T:
case PCB_ZONE_T:
case PCB_PAD_T:
case PCB_TRACE_T:
case PCB_ARC_T:
case PCB_VIA_T:
if( !item->IsNew() && !IsFootprintEditor() )
m_commit->Modify( item );
@ -1372,6 +1375,12 @@ int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
break;
case PCB_TRACE_T:
case PCB_ARC_T:
case PCB_VIA_T:
static_cast<PCB_TRACK*>( item )->Mirror( mirrorPoint, mirrorAroundXaxis );
break;
default:
// it's likely the commit object is wrong if you get here
// Unsure if PCB_GROUP_T needs special attention here.