diff --git a/eeschema/dialogs/dialog_field_properties.cpp b/eeschema/dialogs/dialog_field_properties.cpp index 3c9ba1194f..0e18219a87 100644 --- a/eeschema/dialogs/dialog_field_properties.cpp +++ b/eeschema/dialogs/dialog_field_properties.cpp @@ -283,8 +283,6 @@ bool DIALOG_FIELD_PROPERTIES::TransferDataFromWindow() void DIALOG_FIELD_PROPERTIES::updateText( EDA_TEXT* aText ) { - aText->SetTextPos( m_position ); - if( aText->GetTextWidth() != m_size ) aText->SetTextSize( wxSize( m_size, m_size ) ); @@ -292,8 +290,6 @@ void DIALOG_FIELD_PROPERTIES::updateText( EDA_TEXT* aText ) aText->SetTextAngle( m_isVertical ? TEXT_ANGLE_VERT : TEXT_ANGLE_HORIZ ); aText->SetItalic( m_isItalic ); aText->SetBold( m_isBold ); - aText->SetHorizJustify( EDA_TEXT::MapHorizJustify( m_horizontalJustification - 1 ) ); - aText->SetVertJustify( EDA_TEXT::MapVertJustify( m_verticalJustification - 1 ) ); } @@ -354,6 +350,11 @@ DIALOG_SCH_FIELD_PROPERTIES::DIALOG_SCH_FIELD_PROPERTIES( SCH_BASE_FRAME* aParen m_textLabel->SetLabel( m_field->GetName() + ":" ); + m_position = m_field->GetPosition(); + + m_horizontalJustification = m_field->GetEffectiveHorizJustify() + 1; + m_verticalJustification = m_field->GetEffectiveVertJustify() + 1; + // The library symbol may have been removed so using SCH_SYMBOL::GetLibSymbolRef() here // could result in a segfault. If the library symbol is no longer available, the // schematic fields can still edit so set the power symbol flag to false. This may not @@ -488,18 +489,20 @@ void DIALOG_SCH_FIELD_PROPERTIES::UpdateField( SCH_FIELD* aField, SCH_SHEET_PATH symbol->SetFootprint( m_text ); } + EDA_TEXT_HJUSTIFY_T hJustify = EDA_TEXT::MapHorizJustify( m_horizontalJustification - 1 ); + EDA_TEXT_VJUSTIFY_T vJustify = EDA_TEXT::MapVertJustify( m_verticalJustification - 1 ); bool positioningModified = false; - if( aField->GetTextPos() != m_position ) + if( aField->GetPosition() != m_position ) positioningModified = true; if( ( aField->GetTextAngle() == TEXT_ANGLE_VERT ) != m_isVertical ) positioningModified = true; - if( aField->GetHorizJustify() != EDA_TEXT::MapHorizJustify( m_horizontalJustification - 1 ) ) + if( aField->GetEffectiveHorizJustify() != hJustify ) positioningModified = true; - if( aField->GetVertJustify() != EDA_TEXT::MapVertJustify( m_verticalJustification - 1 ) ) + if( aField->GetEffectiveVertJustify() != vJustify ) positioningModified = true; // convert any text variable cross-references to their UUIDs @@ -507,6 +510,19 @@ void DIALOG_SCH_FIELD_PROPERTIES::UpdateField( SCH_FIELD* aField, SCH_SHEET_PATH aField->SetText( m_text ); updateText( aField ); + aField->SetPosition( m_position ); + + // Note that we must set justifications before we can ask if they're flipped. If the old + // justification is center then it won't know (whereas if the new justification is center + // the we don't care). + aField->SetHorizJustify( hJustify ); + aField->SetVertJustify( vJustify ); + + if( aField->IsHorizJustifyFlipped() ) + aField->SetHorizJustify( EDA_TEXT::MapHorizJustify( -hJustify ) ); + + if( aField->IsVertJustifyFlipped() ) + aField->SetVertJustify( EDA_TEXT::MapVertJustify( -vJustify ) ); // The value, footprint and datasheet fields should be kept in sync in multi-unit parts. // Of course the symbol must be annotated to collect other units. diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 8311996373..e753284924 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -352,15 +352,72 @@ bool SCH_FIELD::IsHorizJustifyFlipped() const switch( GetHorizJustify() ) { case GR_TEXT_HJUSTIFY_LEFT: - return render_center.x < pos.x; + if( GetDrawRotation() == TEXT_ANGLE_VERT ) + return render_center.y > pos.y; + else + return render_center.x < pos.x; case GR_TEXT_HJUSTIFY_RIGHT: - return render_center.x > pos.x; + if( GetDrawRotation() == TEXT_ANGLE_VERT ) + return render_center.y < pos.y; + else + return render_center.x > pos.x; default: return false; } } +EDA_TEXT_HJUSTIFY_T SCH_FIELD::GetEffectiveHorizJustify() const +{ + switch( GetHorizJustify() ) + { + case GR_TEXT_HJUSTIFY_LEFT: + return IsHorizJustifyFlipped() ? GR_TEXT_HJUSTIFY_RIGHT : GR_TEXT_HJUSTIFY_LEFT; + case GR_TEXT_HJUSTIFY_RIGHT: + return IsHorizJustifyFlipped() ? GR_TEXT_HJUSTIFY_LEFT : GR_TEXT_HJUSTIFY_RIGHT; + default: + return GR_TEXT_HJUSTIFY_CENTER; + } +} + + +bool SCH_FIELD::IsVertJustifyFlipped() const +{ + wxPoint render_center = GetBoundingBox().Centre(); + wxPoint pos = GetPosition(); + + switch( GetVertJustify() ) + { + case GR_TEXT_VJUSTIFY_TOP: + if( GetDrawRotation() == TEXT_ANGLE_VERT ) + return render_center.x < pos.x; + else + return render_center.y < pos.y; + case GR_TEXT_VJUSTIFY_BOTTOM: + if( GetDrawRotation() == TEXT_ANGLE_VERT ) + return render_center.x > pos.x; + else + return render_center.y > pos.y; + default: + return false; + } +} + + +EDA_TEXT_VJUSTIFY_T SCH_FIELD::GetEffectiveVertJustify() const +{ + switch( GetVertJustify() ) + { + case GR_TEXT_VJUSTIFY_TOP: + return IsVertJustifyFlipped() ? GR_TEXT_VJUSTIFY_BOTTOM : GR_TEXT_VJUSTIFY_TOP; + case GR_TEXT_VJUSTIFY_BOTTOM: + return IsVertJustifyFlipped() ? GR_TEXT_VJUSTIFY_TOP : GR_TEXT_VJUSTIFY_BOTTOM; + default: + return GR_TEXT_VJUSTIFY_CENTER; + } +} + + bool SCH_FIELD::IsVoid() const { return GetText().Len() == 0; diff --git a/eeschema/sch_field.h b/eeschema/sch_field.h index f02274af04..46f7e7db06 100644 --- a/eeschema/sch_field.h +++ b/eeschema/sch_field.h @@ -131,6 +131,10 @@ public: * inverted due to rotation or mirroring of the parent. */ bool IsHorizJustifyFlipped() const; + bool IsVertJustifyFlipped() const; + + EDA_TEXT_HJUSTIFY_T GetEffectiveHorizJustify() const; + EDA_TEXT_VJUSTIFY_T GetEffectiveVertJustify() const; /** * @return true if the field is either empty or holds "~".