From 3b288b1b1be33e88a9d840e0e16e2c4184052631 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 6 Jul 2021 20:26:22 +0100 Subject: [PATCH] Pull textframe processing out from under note and allow both. Note that there's still a bunch of stuff we don't support regarding textframes such as wordwrap and background colours, but this at least keeps the text from getting lost. Fixes https://gitlab.com/kicad/code/kicad/issues/8741 --- .../sch_plugins/altium/altium_parser_sch.cpp | 20 +++++--- .../sch_plugins/altium/altium_parser_sch.h | 15 ++++-- .../sch_plugins/altium/sch_altium_plugin.cpp | 47 +++++++++++++++++-- .../sch_plugins/altium/sch_altium_plugin.h | 1 + 4 files changed, 70 insertions(+), 13 deletions(-) diff --git a/eeschema/sch_plugins/altium/altium_parser_sch.cpp b/eeschema/sch_plugins/altium/altium_parser_sch.cpp index 8012339051..3775d9efcb 100644 --- a/eeschema/sch_plugins/altium/altium_parser_sch.cpp +++ b/eeschema/sch_plugins/altium/altium_parser_sch.cpp @@ -229,9 +229,10 @@ ASCH_LABEL::ASCH_LABEL( const std::map& aProperties ) } -ASCH_NOTE::ASCH_NOTE( const std::map& aProperties ) +ASCH_TEXT_FRAME::ASCH_TEXT_FRAME( const std::map& aProperties ) { - wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::NOTE ); + wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::NOTE + || PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::TEXT_FRAME ); location = wxPoint( PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.X" ), -PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.Y" ) ); @@ -241,16 +242,23 @@ ASCH_NOTE::ASCH_NOTE( const std::map& aProperties ) text = ALTIUM_PARSER::PropertiesReadString( aProperties, "TEXT", "" ); text.Replace( "~1", "\n", true ); - author = ALTIUM_PARSER::PropertiesReadString( aProperties, "AUTHOR", "" ); - fontId = ALTIUM_PARSER::PropertiesReadInt( aProperties, "FONTID", 0 ); isWordWrapped = ALTIUM_PARSER::PropertiesReadBool( aProperties, "WORDWRAP", false ); border = ALTIUM_PARSER::PropertiesReadBool( aProperties, "SHOWBORDER", false ); textMargin = PropertiesReadKiCadUnitFrac( aProperties, "TEXTMARGIN" ); areaColor = ALTIUM_PARSER::PropertiesReadInt( aProperties, "AREACOLOR", 0 ); - alignment = PropertiesReadEnum( - aProperties, "ALIGNMENT", 1, 3, ASCH_NOTE_ALIGNMENT::LEFT ); + alignment = PropertiesReadEnum( + aProperties, "ALIGNMENT", 1, 3, ASCH_TEXT_FRAME_ALIGNMENT::LEFT ); +} + + +ASCH_NOTE::ASCH_NOTE( const std::map& aProperties ) : + ASCH_TEXT_FRAME( aProperties ) +{ + wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::NOTE ); + + author = ALTIUM_PARSER::PropertiesReadString( aProperties, "AUTHOR", "" ); } diff --git a/eeschema/sch_plugins/altium/altium_parser_sch.h b/eeschema/sch_plugins/altium/altium_parser_sch.h index 9ccce4ed53..9410c2581b 100644 --- a/eeschema/sch_plugins/altium/altium_parser_sch.h +++ b/eeschema/sch_plugins/altium/altium_parser_sch.h @@ -236,7 +236,7 @@ enum class ASCH_LABEL_JUSTIFICATION }; -enum class ASCH_NOTE_ALIGNMENT +enum class ASCH_TEXT_FRAME_ALIGNMENT { LEFT = 1, CENTER = 2, @@ -262,13 +262,12 @@ struct ASCH_LABEL }; -struct ASCH_NOTE +struct ASCH_TEXT_FRAME { wxPoint location; wxSize size; wxString text; - wxString author; int fontId; bool isWordWrapped; @@ -276,7 +275,15 @@ struct ASCH_NOTE int textMargin; int areaColor; - ASCH_NOTE_ALIGNMENT alignment; + ASCH_TEXT_FRAME_ALIGNMENT alignment; + + explicit ASCH_TEXT_FRAME( const std::map& aProperties ); +}; + + +struct ASCH_NOTE : ASCH_TEXT_FRAME +{ + wxString author; explicit ASCH_NOTE( const std::map& aProperties ); }; diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp index 25b53d21d3..2a39d96a35 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp @@ -421,6 +421,7 @@ void SCH_ALTIUM_PLUGIN::ParseFileHeader( const CFB::CompoundFileReader& aReader ParseWire( properties ); break; case ALTIUM_SCH_RECORD::TEXT_FRAME: + ParseTextFrame( properties ); break; case ALTIUM_SCH_RECORD::JUNCTION: ParseJunction( properties ); @@ -854,6 +855,46 @@ void SCH_ALTIUM_PLUGIN::ParseLabel( const std::map& aPropert } +void SCH_ALTIUM_PLUGIN::ParseTextFrame( const std::map& aProperties ) +{ + ASCH_TEXT_FRAME elem( aProperties ); + + SCH_TEXT* text = new SCH_TEXT( elem.location + m_sheetOffset, elem.text ); + + switch( elem.alignment ) + { + default: + case ASCH_TEXT_FRAME_ALIGNMENT::LEFT: + text->SetLabelSpinStyle( LABEL_SPIN_STYLE::SPIN::RIGHT ); + break; + case ASCH_TEXT_FRAME_ALIGNMENT::CENTER: + // No support for centered text in Eeschema yet... + text->SetLabelSpinStyle( LABEL_SPIN_STYLE::SPIN::RIGHT ); + break; + case ASCH_TEXT_FRAME_ALIGNMENT::RIGHT: + text->SetLabelSpinStyle( LABEL_SPIN_STYLE::SPIN::LEFT ); + break; + } + + // TODO: set size and word-wrap once KiCad supports wrapped text. + + // TODO: set border and background color once KiCad supports them. + + size_t fontId = static_cast( elem.fontId ); + + if( m_altiumSheet && fontId > 0 && fontId <= m_altiumSheet->fonts.size() ) + { + const ASCH_SHEET_FONT& font = m_altiumSheet->fonts.at( fontId - 1 ); + text->SetItalic( font.italic ); + text->SetBold( font.bold ); + text->SetTextSize( { font.size / 2, font.size / 2 } ); + } + + text->SetFlags( IS_NEW ); + m_currentSheet->GetScreen()->Append( text ); +} + + void SCH_ALTIUM_PLUGIN::ParseNote( const std::map& aProperties ) { ASCH_NOTE elem( aProperties ); @@ -863,14 +904,14 @@ void SCH_ALTIUM_PLUGIN::ParseNote( const std::map& aProperti switch( elem.alignment ) { default: - case ASCH_NOTE_ALIGNMENT::LEFT: + case ASCH_TEXT_FRAME_ALIGNMENT::LEFT: text->SetLabelSpinStyle( LABEL_SPIN_STYLE::SPIN::RIGHT ); break; - case ASCH_NOTE_ALIGNMENT::CENTER: + case ASCH_TEXT_FRAME_ALIGNMENT::CENTER: // No support for centered text in Eeschema yet... text->SetLabelSpinStyle( LABEL_SPIN_STYLE::SPIN::RIGHT ); break; - case ASCH_NOTE_ALIGNMENT::RIGHT: + case ASCH_TEXT_FRAME_ALIGNMENT::RIGHT: text->SetLabelSpinStyle( LABEL_SPIN_STYLE::SPIN::LEFT ); break; } diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.h b/eeschema/sch_plugins/altium/sch_altium_plugin.h index c7d0fbb4d0..f88b941ce0 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.h +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.h @@ -115,6 +115,7 @@ private: void ParseComponent( int aIndex, const std::map& aProperties ); void ParsePin( const std::map& aProperties ); void ParseLabel( const std::map& aProperties ); + void ParseTextFrame( const std::map& aProperties ); void ParseNote( const std::map& aProperties ); void ParseBezier( const std::map& aProperties ); void ParsePolyline( const std::map& aProperties );