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
This commit is contained in:
Jeff Young 2021-07-06 20:26:22 +01:00
parent 190b0ecdeb
commit 3b288b1b1b
4 changed files with 70 additions and 13 deletions

View File

@ -229,9 +229,10 @@ ASCH_LABEL::ASCH_LABEL( const std::map<wxString, wxString>& aProperties )
}
ASCH_NOTE::ASCH_NOTE( const std::map<wxString, wxString>& aProperties )
ASCH_TEXT_FRAME::ASCH_TEXT_FRAME( const std::map<wxString, wxString>& 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<wxString, wxString>& 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<ASCH_NOTE_ALIGNMENT>(
aProperties, "ALIGNMENT", 1, 3, ASCH_NOTE_ALIGNMENT::LEFT );
alignment = PropertiesReadEnum<ASCH_TEXT_FRAME_ALIGNMENT>(
aProperties, "ALIGNMENT", 1, 3, ASCH_TEXT_FRAME_ALIGNMENT::LEFT );
}
ASCH_NOTE::ASCH_NOTE( const std::map<wxString, wxString>& aProperties ) :
ASCH_TEXT_FRAME( aProperties )
{
wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::NOTE );
author = ALTIUM_PARSER::PropertiesReadString( aProperties, "AUTHOR", "" );
}

View File

@ -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<wxString, wxString>& aProperties );
};
struct ASCH_NOTE : ASCH_TEXT_FRAME
{
wxString author;
explicit ASCH_NOTE( const std::map<wxString, wxString>& aProperties );
};

View File

@ -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<wxString, wxString>& aPropert
}
void SCH_ALTIUM_PLUGIN::ParseTextFrame( const std::map<wxString, wxString>& 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<int>( 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<wxString, wxString>& aProperties )
{
ASCH_NOTE elem( aProperties );
@ -863,14 +904,14 @@ void SCH_ALTIUM_PLUGIN::ParseNote( const std::map<wxString, wxString>& 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;
}

View File

@ -115,6 +115,7 @@ private:
void ParseComponent( int aIndex, const std::map<wxString, wxString>& aProperties );
void ParsePin( const std::map<wxString, wxString>& aProperties );
void ParseLabel( const std::map<wxString, wxString>& aProperties );
void ParseTextFrame( const std::map<wxString, wxString>& aProperties );
void ParseNote( const std::map<wxString, wxString>& aProperties );
void ParseBezier( const std::map<wxString, wxString>& aProperties );
void ParsePolyline( const std::map<wxString, wxString>& aProperties );