Fix textbox mirroring and rotation (again).
Fixes https://gitlab.com/kicad/code/kicad/-/issues/15576 Fixes https://gitlab.com/kicad/code/kicad/-/issues/14159 Fixes https://gitlab.com/kicad/code/kicad/-/issues/14912 Fixes https://gitlab.com/kicad/code/kicad/-/issues/14178
This commit is contained in:
parent
6c21e0607b
commit
7788c8f21c
|
@ -156,40 +156,80 @@ void PCB_TEXTBOX::SetTextAngle( const EDA_ANGLE& aAngle )
|
|||
std::vector<VECTOR2I> PCB_TEXTBOX::GetAnchorAndOppositeCorner() const
|
||||
{
|
||||
std::vector<VECTOR2I> pts;
|
||||
std::vector<VECTOR2I> corners = GetCorners();
|
||||
EDA_ANGLE textAngle( GetDrawRotation() );
|
||||
|
||||
textAngle.Normalize();
|
||||
|
||||
pts.emplace_back( corners[0] );
|
||||
if( textAngle.IsCardinal() )
|
||||
{
|
||||
BOX2I bbox = PCB_SHAPE::GetBoundingBox();
|
||||
bbox.Normalize();
|
||||
|
||||
if( textAngle < ANGLE_90 )
|
||||
{
|
||||
if( corners[1].y <= corners[0].y )
|
||||
pts.emplace_back( corners[1] );
|
||||
else
|
||||
pts.emplace_back( corners[3] );
|
||||
}
|
||||
else if( textAngle < ANGLE_180 )
|
||||
{
|
||||
if( corners[1].x <= corners[0].x )
|
||||
pts.emplace_back( corners[1] );
|
||||
else
|
||||
pts.emplace_back( corners[3] );
|
||||
}
|
||||
else if( textAngle < ANGLE_270 )
|
||||
{
|
||||
if( corners[1].y >= corners[0].y )
|
||||
pts.emplace_back( corners[1] );
|
||||
else
|
||||
pts.emplace_back( corners[3] );
|
||||
if( textAngle == ANGLE_0 )
|
||||
{
|
||||
pts.emplace_back( VECTOR2I( bbox.GetLeft(), bbox.GetTop() ) );
|
||||
pts.emplace_back( VECTOR2I( bbox.GetRight(), bbox.GetTop() ) );
|
||||
}
|
||||
else if( textAngle == ANGLE_90 )
|
||||
{
|
||||
pts.emplace_back( VECTOR2I( bbox.GetLeft(), bbox.GetBottom() ) );
|
||||
pts.emplace_back( VECTOR2I( bbox.GetLeft(), bbox.GetTop() ) );
|
||||
}
|
||||
else if( textAngle == ANGLE_180 )
|
||||
{
|
||||
pts.emplace_back( VECTOR2I( bbox.GetRight(), bbox.GetBottom() ) );
|
||||
pts.emplace_back( VECTOR2I( bbox.GetLeft(), bbox.GetBottom() ) );
|
||||
}
|
||||
else if( textAngle == ANGLE_270 )
|
||||
{
|
||||
pts.emplace_back( VECTOR2I( bbox.GetRight(), bbox.GetTop() ) );
|
||||
pts.emplace_back( VECTOR2I( bbox.GetRight(), bbox.GetBottom() ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( corners[1].x >= corners[0].x )
|
||||
pts.emplace_back( corners[1] );
|
||||
std::vector<VECTOR2I> corners = GetCorners();
|
||||
|
||||
VECTOR2I minX = corners[0];
|
||||
VECTOR2I maxX = corners[0];
|
||||
VECTOR2I minY = corners[0];
|
||||
VECTOR2I maxY = corners[0];
|
||||
|
||||
for( const VECTOR2I& corner : corners )
|
||||
{
|
||||
if( corner.x < minX.x )
|
||||
minX = corner;
|
||||
|
||||
if( corner.x > maxX.x )
|
||||
maxX = corner;
|
||||
|
||||
if( corner.y < minY.y )
|
||||
minY = corner;
|
||||
|
||||
if( corner.y > maxY.y )
|
||||
maxY = corner;
|
||||
}
|
||||
|
||||
if( textAngle < ANGLE_90 )
|
||||
{
|
||||
pts.emplace_back( minX );
|
||||
pts.emplace_back( minY );
|
||||
}
|
||||
else if( textAngle < ANGLE_180 )
|
||||
{
|
||||
pts.emplace_back( maxY );
|
||||
pts.emplace_back( minX );
|
||||
}
|
||||
else if( textAngle < ANGLE_270 )
|
||||
{
|
||||
pts.emplace_back( maxX );
|
||||
pts.emplace_back( maxY );
|
||||
}
|
||||
else
|
||||
pts.emplace_back( corners[3] );
|
||||
{
|
||||
pts.emplace_back( minY );
|
||||
pts.emplace_back( maxX );
|
||||
}
|
||||
}
|
||||
|
||||
return pts;
|
||||
|
@ -203,9 +243,6 @@ VECTOR2I PCB_TEXTBOX::GetDrawPos() const
|
|||
VECTOR2I textAnchor;
|
||||
VECTOR2I offset;
|
||||
|
||||
if( IsBackLayer( GetLayer() ) )
|
||||
std::swap( corners[0], corners[1] );
|
||||
|
||||
if( IsMirrored() )
|
||||
{
|
||||
switch( GetHorizJustify() )
|
||||
|
@ -379,32 +416,24 @@ void PCB_TEXTBOX::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
|
|||
|
||||
void PCB_TEXTBOX::Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis )
|
||||
{
|
||||
// the position is mirrored, but not the text (or its justification)
|
||||
// the position and angle are mirrored, but not the text (or its justification)
|
||||
PCB_SHAPE::Mirror( aCentre, aMirrorAroundXAxis );
|
||||
|
||||
BOX2I rect( m_start, m_end - m_start );
|
||||
rect.Normalize();
|
||||
m_start = VECTOR2I( rect.GetLeft(), rect.GetTop() );
|
||||
m_end = VECTOR2I( rect.GetRight(), rect.GetBottom() );
|
||||
if( aMirrorAroundXAxis )
|
||||
EDA_TEXT::SetTextAngle( ANGLE_180 - GetTextAngle() );
|
||||
else
|
||||
EDA_TEXT::SetTextAngle( -GetTextAngle() );
|
||||
}
|
||||
|
||||
|
||||
void PCB_TEXTBOX::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
|
||||
{
|
||||
if( aFlipLeftRight )
|
||||
{
|
||||
m_start.x = aCentre.x - ( m_start.x - aCentre.x );
|
||||
m_end.x = aCentre.x - ( m_end.x - aCentre.x );
|
||||
EDA_TEXT::SetTextAngle( -GetTextAngle() );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_start.y = aCentre.y - ( m_start.y - aCentre.y );
|
||||
m_end.y = aCentre.y - ( m_end.y - aCentre.y );
|
||||
EDA_TEXT::SetTextAngle( ANGLE_180 - GetTextAngle() );
|
||||
}
|
||||
PCB_SHAPE::Flip( aCentre, aFlipLeftRight );
|
||||
|
||||
SetLayer( FlipLayer( GetLayer(), GetBoard()->GetCopperLayerCount() ) );
|
||||
if( aFlipLeftRight )
|
||||
EDA_TEXT::SetTextAngle( -GetTextAngle() );
|
||||
else
|
||||
EDA_TEXT::SetTextAngle( ANGLE_180 - GetTextAngle() );
|
||||
|
||||
if( ( GetLayerSet() & LSET::SideSpecificMask() ).any() )
|
||||
SetMirrored( !IsMirrored() );
|
||||
|
|
|
@ -1721,7 +1721,15 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
|
|||
if( selection.Empty() )
|
||||
return 0;
|
||||
|
||||
updateModificationPoint( selection );
|
||||
if( selection.Size() == 1 )
|
||||
{
|
||||
if( BOARD_ITEM* item = dynamic_cast<BOARD_ITEM*>( selection.Front() ) )
|
||||
selection.SetReferencePoint( item->GetCenter() );
|
||||
}
|
||||
else
|
||||
{
|
||||
updateModificationPoint( selection );
|
||||
}
|
||||
|
||||
VECTOR2I refPt = selection.GetReferencePoint();
|
||||
EDA_ANGLE rotateAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *editFrame, aEvent );
|
||||
|
@ -2029,12 +2037,7 @@ int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent )
|
|||
// If only one item selected, flip around the selection or item anchor point (instead
|
||||
// of the bounding box center) to avoid moving the item anchor
|
||||
if( selection.GetSize() == 1 )
|
||||
{
|
||||
if( m_dragging && selection.HasReferencePoint() )
|
||||
refPt = selection.GetReferencePoint();
|
||||
else if( BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( selection.Front() ) )
|
||||
refPt = boardItem->GetPosition();
|
||||
}
|
||||
refPt = selection.GetReferencePoint();
|
||||
|
||||
bool leftRight = frame()->GetPcbNewSettings()->m_FlipLeftRight;
|
||||
|
||||
|
|
Loading…
Reference in New Issue