From 742757b98b77a951ce8a2911b1d603ef6760a6d8 Mon Sep 17 00:00:00 2001 From: WhiteChairFromIkea Date: Tue, 16 Aug 2022 17:45:11 +0300 Subject: [PATCH] Altium: import NOTE and TEXT_FRAME as TextBoxes instead of text objects --- .../sch_plugins/altium/altium_parser_sch.cpp | 31 ++++--- .../sch_plugins/altium/altium_parser_sch.h | 24 +++-- .../sch_plugins/altium/sch_altium_plugin.cpp | 89 ++++++++----------- .../sch_plugins/altium/sch_altium_plugin.h | 1 + 4 files changed, 72 insertions(+), 73 deletions(-) diff --git a/eeschema/sch_plugins/altium/altium_parser_sch.cpp b/eeschema/sch_plugins/altium/altium_parser_sch.cpp index 7d7ff70667..6dc542e48e 100644 --- a/eeschema/sch_plugins/altium/altium_parser_sch.cpp +++ b/eeschema/sch_plugins/altium/altium_parser_sch.cpp @@ -249,22 +249,29 @@ ASCH_TEXT_FRAME::ASCH_TEXT_FRAME( const std::map& aProps ) wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::NOTE || ReadRecord( aProps ) == ALTIUM_SCH_RECORD::TEXT_FRAME ); - location = VECTOR2I( ReadKiCadUnitFrac( aProps, "LOCATION.X" ), + BottomLeft = VECTOR2I( ReadKiCadUnitFrac( aProps, "LOCATION.X" ), -ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) ); - size = wxSize( ReadKiCadUnitFrac( aProps, "CORNER.X" ) - location.x, - -ReadKiCadUnitFrac( aProps, "CORNER.Y" ) - location.y ); + TopRight = VECTOR2I( ReadKiCadUnitFrac( aProps, "CORNER.X" ), + -ReadKiCadUnitFrac( aProps, "CORNER.Y" ) ); - text = ALTIUM_PARSER::ReadString( aProps, "TEXT", "" ); - text.Replace( "~1", "\n", true ); + Location = VECTOR2I( ReadKiCadUnitFrac( aProps, "LOCATION.X" ), + -ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) ); + Size = wxSize( ReadKiCadUnitFrac( aProps, "CORNER.X" ) - Location.x, + -ReadKiCadUnitFrac( aProps, "CORNER.Y" ) - Location.y ); - fontId = ALTIUM_PARSER::ReadInt( aProps, "FONTID", 0 ); - isWordWrapped = ALTIUM_PARSER::ReadBool( aProps, "WORDWRAP", false ); - border = ALTIUM_PARSER::ReadBool( aProps, "SHOWBORDER", false ); - textMargin = ReadKiCadUnitFrac( aProps, "TEXTMARGIN" ); - areaColor = ALTIUM_PARSER::ReadInt( aProps, "AREACOLOR", 0 ); + Text = ALTIUM_PARSER::ReadString( aProps, "TEXT", "" ); + Text.Replace( "~1", "\n", true ); - alignment = ReadEnum( aProps, "ALIGNMENT", 1, 3, - ASCH_TEXT_FRAME_ALIGNMENT::LEFT ); + FontID = ALTIUM_PARSER::ReadInt( aProps, "FONTID", 0 ); + IsWordWrapped = ALTIUM_PARSER::ReadBool( aProps, "WORDWRAP", false ); + ShowBorder = ALTIUM_PARSER::ReadBool( aProps, "SHOWBORDER", false ); + TextMargin = ReadKiCadUnitFrac( aProps, "TEXTMARGIN" ); + AreaColor = ALTIUM_PARSER::ReadInt( aProps, "AREACOLOR", 0 ); + BorderColor = ALTIUM_PARSER::ReadInt( aProps, "COLOR", 0 ); + + IsSolid = ALTIUM_PARSER::ReadBool( aProps, "WORDWRAP", true ); + + Alignment = ReadEnum( aProps, "ALIGNMENT", 1, 3, ASCH_TEXT_FRAME_ALIGNMENT::LEFT ); } diff --git a/eeschema/sch_plugins/altium/altium_parser_sch.h b/eeschema/sch_plugins/altium/altium_parser_sch.h index df2cbc2618..8937b04cf9 100644 --- a/eeschema/sch_plugins/altium/altium_parser_sch.h +++ b/eeschema/sch_plugins/altium/altium_parser_sch.h @@ -289,18 +289,24 @@ struct ASCH_LABEL struct ASCH_TEXT_FRAME { - VECTOR2I location; - wxSize size; + VECTOR2I Location; + wxSize Size; + // have both coordinates, for convenience + VECTOR2I BottomLeft; + VECTOR2I TopRight; - wxString text; + wxString Text; - int fontId; - bool isWordWrapped; - bool border; - int textMargin; - int areaColor; + bool IsWordWrapped; // to do when kicad supports this + bool ShowBorder; + bool IsSolid; - ASCH_TEXT_FRAME_ALIGNMENT alignment; + int FontID; + int TextMargin; // to do when kicad supports this + int AreaColor; + int BorderColor; + + ASCH_TEXT_FRAME_ALIGNMENT Alignment; explicit ASCH_TEXT_FRAME( const std::map& aProps ); }; diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp index 7967966042..5ff9f0d311 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp @@ -975,82 +975,67 @@ 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->SetTextSpinStyle( TEXT_SPIN_STYLE::SPIN::RIGHT ); - break; - case ASCH_TEXT_FRAME_ALIGNMENT::CENTER: - // No support for centered text in Eeschema yet... - text->SetTextSpinStyle( TEXT_SPIN_STYLE::SPIN::RIGHT ); - break; - case ASCH_TEXT_FRAME_ALIGNMENT::RIGHT: - text->SetTextSpinStyle( TEXT_SPIN_STYLE::SPIN::LEFT ); - break; - } - - // JEY TODO: set size and word-wrap once KiCad supports wrapped text. - - // JEY 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 ); + AddTextBox( &elem ); } void SCH_ALTIUM_PLUGIN::ParseNote( const std::map& aProperties ) -{ + { ASCH_NOTE elem( aProperties ); + AddTextBox( static_cast( &elem ) ); - SCH_TEXT* text = new SCH_TEXT( elem.location + m_sheetOffset, elem.text ); + // TODO: need some sort of property system for storing author.... +} - switch( elem.alignment ) + +void SCH_ALTIUM_PLUGIN::AddTextBox(const ASCH_TEXT_FRAME *aElem ) + { + SCH_TEXTBOX* textBox = new SCH_TEXTBOX(); + + VECTOR2I sheetTopRight = aElem->TopRight + m_sheetOffset; + VECTOR2I sheetBottomLeft = aElem->BottomLeft + m_sheetOffset; + textBox->SetStart( sheetTopRight ); + textBox->SetEnd( sheetBottomLeft ); + + textBox->SetText( aElem->Text ); + + textBox->SetFillColor( GetColorFromInt( aElem->AreaColor ) ); + textBox->SetFilled( aElem->IsSolid ); + + if( aElem->ShowBorder ) + textBox->SetStroke( STROKE_PARAMS( 0, PLOT_DASH_TYPE::DEFAULT, GetColorFromInt( aElem->BorderColor ) ) ); + else + textBox->SetStroke( STROKE_PARAMS( -1, PLOT_DASH_TYPE::DEFAULT, GetColorFromInt( aElem->BorderColor ) ) ); + + switch( aElem->Alignment ) { default: case ASCH_TEXT_FRAME_ALIGNMENT::LEFT: - text->SetTextSpinStyle( TEXT_SPIN_STYLE::SPIN::RIGHT ); + textBox->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); break; case ASCH_TEXT_FRAME_ALIGNMENT::CENTER: - // No support for centered text in Eeschema yet... - text->SetTextSpinStyle( TEXT_SPIN_STYLE::SPIN::RIGHT ); + textBox->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER ); break; case ASCH_TEXT_FRAME_ALIGNMENT::RIGHT: - text->SetTextSpinStyle( TEXT_SPIN_STYLE::SPIN::LEFT ); + textBox->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT ); break; } - // TODO: set size and word-wrap once KiCad supports wrapped text. + // JEY TODO: word-wrap once KiCad supports wrapped text. - // TODO: set border and background color once KiCad supports them. - - // TODO: need some sort of property system for storing author.... - - size_t fontId = static_cast( elem.fontId ); + size_t fontId = static_cast( aElem->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 } ); + textBox->SetItalic( font.Italic ); + textBox->SetBold( font.Bold ); + textBox->SetTextSize( { font.Size / 2, font.Size / 2 } ); + //textBox->SetFont( //how to set font, we have a font mane here: ( font.fontname ); } - text->SetFlags( IS_NEW ); - m_currentSheet->GetScreen()->Append( text ); + textBox->SetFlags( IS_NEW ); + m_currentSheet->GetScreen()->Append( textBox ); } diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.h b/eeschema/sch_plugins/altium/sch_altium_plugin.h index 7d2ddb4d35..cdbdbb20fa 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.h +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.h @@ -109,6 +109,7 @@ public: private: bool IsComponentPartVisible( int aOwnerindex, int aOwnerpartdisplaymode ) const; const ASCH_STORAGE_FILE* GetFileFromStorage( const wxString& aFilename ) const; + void AddTextBox( const ASCH_TEXT_FRAME* aElem ); void ParseComponent( int aIndex, const std::map& aProperties ); void ParsePin( const std::map& aProperties );