diff --git a/eeschema/sch_plugins/altium/altium_parser_sch.cpp b/eeschema/sch_plugins/altium/altium_parser_sch.cpp index 4c354ae08f..20a686bc47 100644 --- a/eeschema/sch_plugins/altium/altium_parser_sch.cpp +++ b/eeschema/sch_plugins/altium/altium_parser_sch.cpp @@ -174,8 +174,11 @@ ASCH_LABEL::ASCH_LABEL( const std::map& aProperties ) location = wxPoint( PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.X" ), -PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.Y" ) ); - text = ALTIUM_PARSER::PropertiesReadString( aProperties, "TEXT", "" ); - isMirrored = ALTIUM_PARSER::PropertiesReadBool( aProperties, "ISMIRRORED", false ); + text = ALTIUM_PARSER::PropertiesReadString( aProperties, "TEXT", "" ); + + fontId = ALTIUM_PARSER::PropertiesReadInt( aProperties, "FONTID", 0 ); + isMirrored = ALTIUM_PARSER::PropertiesReadBool( aProperties, "ISMIRRORED", false ); + justification = PropertiesReadEnum( aProperties, "JUSTIFICATION", 0, 8, ASCH_LABEL_JUSTIFICATION::UNKNOWN ); } @@ -358,7 +361,7 @@ ASCH_NET_LABEL::ASCH_NET_LABEL( const std::map& aProperties { wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::NET_LABEL ); - text = ALTIUM_PARSER::PropertiesReadString( aProperties, "TEXT", "" ); + text = ALTIUM_PARSER::PropertiesReadString( aProperties, "TEXT", "" ); location = wxPoint( PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.X" ), -PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.Y" ) ); @@ -422,6 +425,32 @@ ASCH_JUNCTION::ASCH_JUNCTION( const std::map& aProperties ) -PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.Y" ) ); } +ASCH_SHEET_FONT::ASCH_SHEET_FONT( const std::map& aProperties, int aId ) +{ + wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::SHEET ); + + const wxString sid = std::to_string( aId ); + + fontname = ALTIUM_PARSER::PropertiesReadString( aProperties, "FONTNAME" + sid, "" ); + + size = PropertiesReadKiCadUnitFrac( aProperties, "SIZE" + sid ); + rotation = ALTIUM_PARSER::PropertiesReadInt( aProperties, "ROTATION" + sid, 0 ); + + italic = ALTIUM_PARSER::PropertiesReadBool( aProperties, "ITALIC" + sid, false ); + bold = ALTIUM_PARSER::PropertiesReadBool( aProperties, "BOLD" + sid, false ); + underline = ALTIUM_PARSER::PropertiesReadBool( aProperties, "UNDERLINE" + sid, false ); +} + +ASCH_SHEET::ASCH_SHEET( const std::map& aProperties ) +{ + wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::SHEET ); + + int fontidcount = ALTIUM_PARSER::PropertiesReadInt( aProperties, "FONTIDCOUNT", 0 ); + for( int i = 1; i <= fontidcount; i++ ) + { + fonts.emplace_back( aProperties, i ); + } +} ASCH_DESIGNATOR::ASCH_DESIGNATOR( const std::map& aProperties ) { diff --git a/eeschema/sch_plugins/altium/altium_parser_sch.h b/eeschema/sch_plugins/altium/altium_parser_sch.h index ecd20ff613..a964ffe9ca 100644 --- a/eeschema/sch_plugins/altium/altium_parser_sch.h +++ b/eeschema/sch_plugins/altium/altium_parser_sch.h @@ -220,8 +220,11 @@ struct ASCH_LABEL wxPoint location; - wxString text; - bool isMirrored; + wxString text; + + int fontId; + bool isMirrored; + ASCH_LABEL_JUSTIFICATION justification; explicit ASCH_LABEL( const std::map& aProperties ); @@ -407,6 +410,28 @@ struct ASCH_JUNCTION }; +struct ASCH_SHEET_FONT +{ + wxString fontname; + + int size; + int rotation; + + bool italic; + bool bold; + bool underline; + + explicit ASCH_SHEET_FONT( const std::map& aProperties, int aId ); +}; + +struct ASCH_SHEET +{ + std::vector fonts; + + explicit ASCH_SHEET( const std::map& aProperties ); +}; + + struct ASCH_DESIGNATOR { int ownerindex; diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp index aef6a78ead..0c86d5baa2 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp @@ -365,6 +365,7 @@ void SCH_ALTIUM_PLUGIN::Parse( const CFB::CompoundFileReader& aReader ) case ALTIUM_SCH_RECORD::IMAGE: break; case ALTIUM_SCH_RECORD::SHEET: + ParseSheet( properties ); break; case ALTIUM_SCH_RECORD::SHEET_NAME: break; @@ -652,6 +653,7 @@ void SCH_ALTIUM_PLUGIN::ParseLabel( const std::map& aPropert { ASCH_LABEL elem( aProperties ); + // TODO: text variable support if( elem.ownerpartid == ALTIUM_COMPONENT_NONE ) { SCH_TEXT* text = new SCH_TEXT( elem.location, elem.text ); @@ -659,6 +661,15 @@ void SCH_ALTIUM_PLUGIN::ParseLabel( const std::map& aPropert SetEdaTextJustification( text, elem.justification ); + 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 ); } @@ -683,6 +694,15 @@ void SCH_ALTIUM_PLUGIN::ParseLabel( const std::map& aPropert text->SetText( elem.text ); SetEdaTextJustification( text, elem.justification ); + + 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 } ); + } } } @@ -1219,6 +1239,12 @@ void SCH_ALTIUM_PLUGIN::ParseJunction( const std::map& aProp } +void SCH_ALTIUM_PLUGIN::ParseSheet( const std::map& aProperties ) +{ + m_altiumSheet = std::make_unique( aProperties ); +} + + void SCH_ALTIUM_PLUGIN::ParseDesignator( const std::map& aProperties ) { ASCH_DESIGNATOR elem( aProperties ); diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.h b/eeschema/sch_plugins/altium/sch_altium_plugin.h index 34319313de..c7461f3f2c 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.h +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.h @@ -28,6 +28,8 @@ #include #include +struct ASCH_SHEET; + class SCH_COMPONENT; namespace CFB @@ -113,6 +115,7 @@ private: void ParseBus( const std::map& aProperties ); void ParseWire( const std::map& aProperties ); void ParseJunction( const std::map& aProperties ); + void ParseSheet( const std::map& aProperties ); void ParseDesignator( const std::map& aProperties ); private: @@ -125,6 +128,7 @@ private: SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi; ///< Plugin to create the KiCad symbol library. std::unique_ptr m_properties; ///< Library plugin properties. + std::unique_ptr m_altiumSheet; std::map m_components; std::map m_symbols; // for the start, every component has its unique symbol };