altium: parse fonts from sheet record and use them for label styling

This commit is contained in:
Thomas Pointhuber 2020-10-17 14:33:30 +02:00
parent a6072a40f5
commit 1ce215a1f2
4 changed files with 89 additions and 5 deletions

View File

@ -174,8 +174,11 @@ ASCH_LABEL::ASCH_LABEL( const std::map<wxString, wxString>& 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<ASCH_LABEL_JUSTIFICATION>(
aProperties, "JUSTIFICATION", 0, 8, ASCH_LABEL_JUSTIFICATION::UNKNOWN );
}
@ -358,7 +361,7 @@ ASCH_NET_LABEL::ASCH_NET_LABEL( const std::map<wxString, wxString>& 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<wxString, wxString>& aProperties )
-PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.Y" ) );
}
ASCH_SHEET_FONT::ASCH_SHEET_FONT( const std::map<wxString, wxString>& 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<wxString, wxString>& 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<wxString, wxString>& aProperties )
{

View File

@ -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<wxString, wxString>& 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<wxString, wxString>& aProperties, int aId );
};
struct ASCH_SHEET
{
std::vector<ASCH_SHEET_FONT> fonts;
explicit ASCH_SHEET( const std::map<wxString, wxString>& aProperties );
};
struct ASCH_DESIGNATOR
{
int ownerindex;

View File

@ -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<wxString, wxString>& 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<wxString, wxString>& aPropert
SetEdaTextJustification( text, elem.justification );
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 );
}
@ -683,6 +694,15 @@ void SCH_ALTIUM_PLUGIN::ParseLabel( const std::map<wxString, wxString>& aPropert
text->SetText( elem.text );
SetEdaTextJustification( text, elem.justification );
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 } );
}
}
}
@ -1219,6 +1239,12 @@ void SCH_ALTIUM_PLUGIN::ParseJunction( const std::map<wxString, wxString>& aProp
}
void SCH_ALTIUM_PLUGIN::ParseSheet( const std::map<wxString, wxString>& aProperties )
{
m_altiumSheet = std::make_unique<ASCH_SHEET>( aProperties );
}
void SCH_ALTIUM_PLUGIN::ParseDesignator( const std::map<wxString, wxString>& aProperties )
{
ASCH_DESIGNATOR elem( aProperties );

View File

@ -28,6 +28,8 @@
#include <sch_io_mgr.h>
#include <wx/filename.h>
struct ASCH_SHEET;
class SCH_COMPONENT;
namespace CFB
@ -113,6 +115,7 @@ private:
void ParseBus( const std::map<wxString, wxString>& aProperties );
void ParseWire( const std::map<wxString, wxString>& aProperties );
void ParseJunction( const std::map<wxString, wxString>& aProperties );
void ParseSheet( const std::map<wxString, wxString>& aProperties );
void ParseDesignator( const std::map<wxString, wxString>& aProperties );
private:
@ -125,6 +128,7 @@ private:
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi; ///< Plugin to create the KiCad symbol library.
std::unique_ptr<PROPERTIES> m_properties; ///< Library plugin properties.
std::unique_ptr<ASCH_SHEET> m_altiumSheet;
std::map<int, SCH_COMPONENT*> m_components;
std::map<int, LIB_PART*> m_symbols; // for the start, every component has its unique symbol
};