Eeschema: fix block mirroring of fields attached to labels (all types)

Fix incorrect orientation of the graphic shape of SCH_DIRECTIVE_LABEL items
after mirroring the item.
Similar to commit 898d88cc, but for block mirroring.
Fixes #14758
https://gitlab.com/kicad/code/kicad/-/issues/14758
This commit is contained in:
jean-pierre charras 2023-05-23 09:42:24 +02:00
parent 7ea907c343
commit b968bac318
2 changed files with 111 additions and 79 deletions

View File

@ -40,6 +40,7 @@
#include <project/project_file.h>
#include <project/net_settings.h>
#include <core/kicad_algo.h>
#include <core/mirror.h>
#include <trigo.h>
#include <sch_label.h>
@ -402,6 +403,52 @@ void SCH_LABEL_BASE::MirrorSpinStyle( bool aLeftRight )
}
void SCH_LABEL_BASE::MirrorHorizontally( int aCenter )
{
VECTOR2I old_pos = GetPosition();
SCH_TEXT::MirrorHorizontally( aCenter );
for( SCH_FIELD& field : m_fields )
{
switch( field.GetHorizJustify() )
{
case GR_TEXT_H_ALIGN_LEFT:
field.SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
break;
case GR_TEXT_H_ALIGN_CENTER:
break;
case GR_TEXT_H_ALIGN_RIGHT:
field.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
break;
}
VECTOR2I pos = field.GetTextPos();
VECTOR2I delta = old_pos - pos;
pos.x = GetPosition().x + delta.x;
field.SetPosition( pos );
}
}
void SCH_LABEL_BASE::MirrorVertically( int aCenter )
{
VECTOR2I old_pos = GetPosition();
SCH_TEXT::MirrorVertically( aCenter );
for( SCH_FIELD& field : m_fields )
{
VECTOR2I pos = field.GetTextPos();
VECTOR2I delta = old_pos - pos;
pos.y = GetPosition().y + delta.y;
field.SetPosition( pos );
}
}
bool SCH_LABEL_BASE::IncrementLabel( int aIncrement )
{
wxString text = GetText();
@ -1183,6 +1230,64 @@ void SCH_DIRECTIVE_LABEL::MirrorSpinStyle( bool aLeftRight )
}
void SCH_DIRECTIVE_LABEL::MirrorHorizontally( int aCenter )
{
VECTOR2I old_pos = GetPosition();
// The "text" is in fact a graphic shape. For a horizontal "text", it looks like a
// vertical shape (like a text reduced to only "I" letter).
// So the mirroring is not exactly similar to a SCH_TEXT item
// Text is NOT really mirrored; it is moved to a suitable horizontal position
SetTextSpinStyle( GetTextSpinStyle().MirrorX() );
SetTextX( MIRRORVAL( GetTextPos().x, aCenter ) );
for( SCH_FIELD& field : m_fields )
{
switch( field.GetHorizJustify() )
{
case GR_TEXT_H_ALIGN_LEFT:
field.SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
break;
case GR_TEXT_H_ALIGN_CENTER:
break;
case GR_TEXT_H_ALIGN_RIGHT:
field.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
break;
}
VECTOR2I pos = field.GetTextPos();
VECTOR2I delta = old_pos - pos;
pos.x = GetPosition().x + delta.x;
field.SetPosition( pos );
}
}
void SCH_DIRECTIVE_LABEL::MirrorVertically( int aCenter )
{
VECTOR2I old_pos = GetPosition();
// The "text" is in fact a graphic shape. For a horizontal "text", it looks like a
// vertical shape (like a text reduced to only "I" letter).
// So the mirroring is not exactly similar to a SCH_TEXT item
// Text is NOT really mirrored; it is moved to a suitable vertical position
SetTextSpinStyle( GetTextSpinStyle().MirrorY() );
SetTextY( MIRRORVAL( GetTextPos().y, aCenter ) );
for( SCH_FIELD& field : m_fields )
{
VECTOR2I pos = field.GetTextPos();
VECTOR2I delta = old_pos - pos;
pos.y = GetPosition().y + delta.y;
field.SetPosition( pos );
}
}
void SCH_DIRECTIVE_LABEL::CreateGraphicShape( const RENDER_SETTINGS* aRenderSettings,
std::vector<VECTOR2I>& aPoints,
const VECTOR2I& aPos ) const
@ -1379,80 +1484,6 @@ void SCH_GLOBALLABEL::SetTextSpinStyle( TEXT_SPIN_STYLE aSpinStyle )
}
void SCH_GLOBALLABEL::MirrorSpinStyle( bool aLeftRight )
{
SCH_TEXT::MirrorSpinStyle( aLeftRight );
for( SCH_FIELD& field : m_fields )
{
if( ( aLeftRight && field.GetTextAngle().IsHorizontal() )
|| ( !aLeftRight && field.GetTextAngle().IsVertical() ) )
{
if( field.GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT )
field.SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
else
field.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
}
VECTOR2I pos = field.GetTextPos();
VECTOR2I delta = (VECTOR2I)GetPosition() - pos;
if( aLeftRight )
pos.x = GetPosition().x + delta.x;
else
pos.y = GetPosition().y + delta.y;
field.SetTextPos( pos );
}
}
void SCH_GLOBALLABEL::MirrorHorizontally( int aCenter )
{
VECTOR2I old_pos = GetPosition();
SCH_TEXT::MirrorHorizontally( aCenter );
for( SCH_FIELD& field : m_fields )
{
switch( field.GetHorizJustify() )
{
case GR_TEXT_H_ALIGN_LEFT:
field.SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
break;
case GR_TEXT_H_ALIGN_CENTER:
break;
case GR_TEXT_H_ALIGN_RIGHT:
field.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
break;
}
VECTOR2I pos = field.GetTextPos();
VECTOR2I delta = old_pos - pos;
pos.x = GetPosition().x + delta.x;
field.SetPosition( pos );
}
}
void SCH_GLOBALLABEL::MirrorVertically( int aCenter )
{
VECTOR2I old_pos = GetPosition();
SCH_TEXT::MirrorVertically( aCenter );
for( SCH_FIELD& field : m_fields )
{
VECTOR2I pos = field.GetTextPos();
VECTOR2I delta = old_pos - pos;
pos.y = GetPosition().y + delta.y;
field.SetPosition( pos );
}
}
bool SCH_GLOBALLABEL::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token,
int aDepth ) const
{

View File

@ -118,6 +118,9 @@ public:
void MirrorSpinStyle( bool aLeftRight ) override;
void MirrorHorizontally( int aCenter ) override;
void MirrorVertically( int aCenter ) override;
void SetPosition( const VECTOR2I& aPosition ) override;
void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) override;
@ -324,6 +327,9 @@ public:
void MirrorSpinStyle( bool aLeftRight ) override;
void MirrorHorizontally( int aCenter ) override;
void MirrorVertically( int aCenter ) override;
private:
int m_pinLength;
int m_symbolSize;
@ -356,11 +362,6 @@ public:
int GetMandatoryFieldCount() override { return 1; }
void MirrorSpinStyle( bool aLeftRight ) override;
void MirrorHorizontally( int aCenter ) override;
void MirrorVertically( int aCenter ) override;
void SetTextSpinStyle( TEXT_SPIN_STYLE aSpinStyle ) override;
VECTOR2I GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const override;