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> PCB_TEXTBOX::GetAnchorAndOppositeCorner() const
|
||||||
{
|
{
|
||||||
std::vector<VECTOR2I> pts;
|
std::vector<VECTOR2I> pts;
|
||||||
std::vector<VECTOR2I> corners = GetCorners();
|
|
||||||
EDA_ANGLE textAngle( GetDrawRotation() );
|
EDA_ANGLE textAngle( GetDrawRotation() );
|
||||||
|
|
||||||
textAngle.Normalize();
|
textAngle.Normalize();
|
||||||
|
|
||||||
pts.emplace_back( corners[0] );
|
if( textAngle.IsCardinal() )
|
||||||
|
{
|
||||||
|
BOX2I bbox = PCB_SHAPE::GetBoundingBox();
|
||||||
|
bbox.Normalize();
|
||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
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 )
|
if( textAngle < ANGLE_90 )
|
||||||
{
|
{
|
||||||
if( corners[1].y <= corners[0].y )
|
pts.emplace_back( minX );
|
||||||
pts.emplace_back( corners[1] );
|
pts.emplace_back( minY );
|
||||||
else
|
|
||||||
pts.emplace_back( corners[3] );
|
|
||||||
}
|
}
|
||||||
else if( textAngle < ANGLE_180 )
|
else if( textAngle < ANGLE_180 )
|
||||||
{
|
{
|
||||||
if( corners[1].x <= corners[0].x )
|
pts.emplace_back( maxY );
|
||||||
pts.emplace_back( corners[1] );
|
pts.emplace_back( minX );
|
||||||
else
|
|
||||||
pts.emplace_back( corners[3] );
|
|
||||||
}
|
}
|
||||||
else if( textAngle < ANGLE_270 )
|
else if( textAngle < ANGLE_270 )
|
||||||
{
|
{
|
||||||
if( corners[1].y >= corners[0].y )
|
pts.emplace_back( maxX );
|
||||||
pts.emplace_back( corners[1] );
|
pts.emplace_back( maxY );
|
||||||
else
|
|
||||||
pts.emplace_back( corners[3] );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( corners[1].x >= corners[0].x )
|
pts.emplace_back( minY );
|
||||||
pts.emplace_back( corners[1] );
|
pts.emplace_back( maxX );
|
||||||
else
|
}
|
||||||
pts.emplace_back( corners[3] );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return pts;
|
return pts;
|
||||||
|
@ -203,9 +243,6 @@ VECTOR2I PCB_TEXTBOX::GetDrawPos() const
|
||||||
VECTOR2I textAnchor;
|
VECTOR2I textAnchor;
|
||||||
VECTOR2I offset;
|
VECTOR2I offset;
|
||||||
|
|
||||||
if( IsBackLayer( GetLayer() ) )
|
|
||||||
std::swap( corners[0], corners[1] );
|
|
||||||
|
|
||||||
if( IsMirrored() )
|
if( IsMirrored() )
|
||||||
{
|
{
|
||||||
switch( GetHorizJustify() )
|
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 )
|
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 );
|
PCB_SHAPE::Mirror( aCentre, aMirrorAroundXAxis );
|
||||||
|
|
||||||
BOX2I rect( m_start, m_end - m_start );
|
if( aMirrorAroundXAxis )
|
||||||
rect.Normalize();
|
EDA_TEXT::SetTextAngle( ANGLE_180 - GetTextAngle() );
|
||||||
m_start = VECTOR2I( rect.GetLeft(), rect.GetTop() );
|
else
|
||||||
m_end = VECTOR2I( rect.GetRight(), rect.GetBottom() );
|
EDA_TEXT::SetTextAngle( -GetTextAngle() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PCB_TEXTBOX::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
|
void PCB_TEXTBOX::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
|
||||||
{
|
{
|
||||||
if( aFlipLeftRight )
|
PCB_SHAPE::Flip( aCentre, 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() );
|
|
||||||
}
|
|
||||||
|
|
||||||
SetLayer( FlipLayer( GetLayer(), GetBoard()->GetCopperLayerCount() ) );
|
if( aFlipLeftRight )
|
||||||
|
EDA_TEXT::SetTextAngle( -GetTextAngle() );
|
||||||
|
else
|
||||||
|
EDA_TEXT::SetTextAngle( ANGLE_180 - GetTextAngle() );
|
||||||
|
|
||||||
if( ( GetLayerSet() & LSET::SideSpecificMask() ).any() )
|
if( ( GetLayerSet() & LSET::SideSpecificMask() ).any() )
|
||||||
SetMirrored( !IsMirrored() );
|
SetMirrored( !IsMirrored() );
|
||||||
|
|
|
@ -1721,7 +1721,15 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
|
||||||
if( selection.Empty() )
|
if( selection.Empty() )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if( selection.Size() == 1 )
|
||||||
|
{
|
||||||
|
if( BOARD_ITEM* item = dynamic_cast<BOARD_ITEM*>( selection.Front() ) )
|
||||||
|
selection.SetReferencePoint( item->GetCenter() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
updateModificationPoint( selection );
|
updateModificationPoint( selection );
|
||||||
|
}
|
||||||
|
|
||||||
VECTOR2I refPt = selection.GetReferencePoint();
|
VECTOR2I refPt = selection.GetReferencePoint();
|
||||||
EDA_ANGLE rotateAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *editFrame, aEvent );
|
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
|
// 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
|
// of the bounding box center) to avoid moving the item anchor
|
||||||
if( selection.GetSize() == 1 )
|
if( selection.GetSize() == 1 )
|
||||||
{
|
|
||||||
if( m_dragging && selection.HasReferencePoint() )
|
|
||||||
refPt = selection.GetReferencePoint();
|
refPt = selection.GetReferencePoint();
|
||||||
else if( BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( selection.Front() ) )
|
|
||||||
refPt = boardItem->GetPosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool leftRight = frame()->GetPcbNewSettings()->m_FlipLeftRight;
|
bool leftRight = frame()->GetPcbNewSettings()->m_FlipLeftRight;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue