Eeschema, directive labels: fix some issues:

- honor mirroring of fields attached to labels (all types)
- fix incorrect orientation of the graphic shape of SCH_DIRECTIVE_LABEL items
after mirroring the item.
Form master branch
Fixes #14758
https://gitlab.com/kicad/code/kicad/issues/14758
This commit is contained in:
jean-pierre charras 2023-05-18 10:28:27 +02:00
parent a72fd0ebdd
commit a5a8b93a2e
2 changed files with 63 additions and 0 deletions

View File

@ -374,6 +374,34 @@ void SCH_LABEL_BASE::Rotate90( bool aClockwise )
} }
void SCH_LABEL_BASE::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 );
}
}
bool SCH_LABEL_BASE::IncrementLabel( int aIncrement ) bool SCH_LABEL_BASE::IncrementLabel( int aIncrement )
{ {
wxString text = GetText(); wxString text = GetText();
@ -1124,6 +1152,37 @@ int SCH_DIRECTIVE_LABEL::GetPenWidth() const
} }
void SCH_DIRECTIVE_LABEL::MirrorSpinStyle( bool aLeftRight )
{
// 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
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_DIRECTIVE_LABEL::CreateGraphicShape( const RENDER_SETTINGS* aRenderSettings, void SCH_DIRECTIVE_LABEL::CreateGraphicShape( const RENDER_SETTINGS* aRenderSettings,
std::vector<VECTOR2I>& aPoints, std::vector<VECTOR2I>& aPoints,
const VECTOR2I& aPos ) const const VECTOR2I& aPos ) const

View File

@ -116,6 +116,8 @@ public:
void Rotate( const VECTOR2I& aCenter ) override; void Rotate( const VECTOR2I& aCenter ) override;
void Rotate90( bool aClockwise ) override; void Rotate90( bool aClockwise ) override;
void MirrorSpinStyle( bool aLeftRight ) override;
void SetPosition( const VECTOR2I& aPosition ) override; void SetPosition( const VECTOR2I& aPosition ) override;
void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) override; void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) override;
@ -320,6 +322,8 @@ public:
bool AutoRotateOnPlacementSupported() const override { return false; } bool AutoRotateOnPlacementSupported() const override { return false; }
void MirrorSpinStyle( bool aLeftRight ) override;
private: private:
int m_pinLength; int m_pinLength;
int m_symbolSize; int m_symbolSize;