Add importing of Altium notes.
Import is incomplete because KiCad doesn't support text boxes yet (so we can't do borders, word-wrap, background fills, etc.). Fixes https://gitlab.com/kicad/code/kicad/issues/8734
This commit is contained in:
parent
81fa40d659
commit
b0c07a28b3
|
@ -47,8 +47,8 @@ constexpr int Altium2KiCadUnit( const int val, const int frac )
|
|||
}
|
||||
|
||||
|
||||
int PropertiesReadKiCadUnitFrac(
|
||||
const std::map<wxString, wxString>& aProperties, const wxString& aKey )
|
||||
int PropertiesReadKiCadUnitFrac( const std::map<wxString, wxString>& aProperties,
|
||||
const wxString& aKey )
|
||||
{
|
||||
// a unit is stored using two fields, denoting the size in mils and a fraction size
|
||||
int key = ALTIUM_PARSER::PropertiesReadInt( aProperties, aKey, 0 );
|
||||
|
@ -57,8 +57,8 @@ int PropertiesReadKiCadUnitFrac(
|
|||
}
|
||||
|
||||
|
||||
int PropertiesReadKiCadUnitFrac1(
|
||||
const std::map<wxString, wxString>& aProperties, const wxString& aKey )
|
||||
int PropertiesReadKiCadUnitFrac1( const std::map<wxString, wxString>& aProperties,
|
||||
const wxString& aKey )
|
||||
{
|
||||
// a unit is stored using two fields, denoting the size in mils and a fraction size
|
||||
// Dunno why Altium invents different units for the same purpose
|
||||
|
@ -73,6 +73,7 @@ T PropertiesReadEnum( const std::map<wxString, wxString>& aProperties, const wxS
|
|||
int aLower, int aUpper, T aDefault )
|
||||
{
|
||||
int value = ALTIUM_PARSER::PropertiesReadInt( aProperties, aKey, static_cast<int>( aDefault ) );
|
||||
|
||||
if( value < aLower || value > aUpper )
|
||||
return aDefault;
|
||||
else
|
||||
|
@ -98,12 +99,12 @@ ASCH_SYMBOL::ASCH_SYMBOL( const std::map<wxString, wxString>& aProperties )
|
|||
{
|
||||
wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::COMPONENT );
|
||||
|
||||
currentpartid =
|
||||
ALTIUM_PARSER::PropertiesReadInt( aProperties, "CURRENTPARTID", ALTIUM_COMPONENT_NONE );
|
||||
currentpartid = ALTIUM_PARSER::PropertiesReadInt( aProperties, "CURRENTPARTID",
|
||||
ALTIUM_COMPONENT_NONE );
|
||||
libreference = ALTIUM_PARSER::PropertiesReadString( aProperties, "LIBREFERENCE", "" );
|
||||
sourcelibraryname = ALTIUM_PARSER::PropertiesReadString( aProperties, "SOURCELIBRARYNAME", "" );
|
||||
componentdescription =
|
||||
ALTIUM_PARSER::PropertiesReadString( aProperties, "COMPONENTDESCRIPTION", "" );
|
||||
componentdescription = ALTIUM_PARSER::PropertiesReadString( aProperties, "COMPONENTDESCRIPTION",
|
||||
"" );
|
||||
|
||||
orientation = ALTIUM_PARSER::PropertiesReadInt( aProperties, "ORIENTATION", 0 );
|
||||
isMirrored = ALTIUM_PARSER::PropertiesReadBool( aProperties, "ISMIRRORED", false );
|
||||
|
@ -120,12 +121,12 @@ ASCH_PIN::ASCH_PIN( const std::map<wxString, wxString>& aProperties )
|
|||
{
|
||||
wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::PIN );
|
||||
|
||||
ownerindex =
|
||||
ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERINDEX", ALTIUM_COMPONENT_NONE );
|
||||
ownerpartid =
|
||||
ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTID", ALTIUM_COMPONENT_NONE );
|
||||
ownerpartdisplaymode =
|
||||
ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTDISPLAYMODE", 0 );
|
||||
ownerindex = ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERINDEX",
|
||||
ALTIUM_COMPONENT_NONE );
|
||||
ownerpartid = ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTID",
|
||||
ALTIUM_COMPONENT_NONE );
|
||||
ownerpartdisplaymode = ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTDISPLAYMODE",
|
||||
0 );
|
||||
|
||||
name = ALTIUM_PARSER::PropertiesReadString( aProperties, "NAME", "" );
|
||||
text = ALTIUM_PARSER::PropertiesReadString( aProperties, "TEXT", "" );
|
||||
|
@ -221,6 +222,31 @@ ASCH_LABEL::ASCH_LABEL( const std::map<wxString, wxString>& aProperties )
|
|||
}
|
||||
|
||||
|
||||
ASCH_NOTE::ASCH_NOTE( const std::map<wxString, wxString>& aProperties )
|
||||
{
|
||||
wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::NOTE );
|
||||
|
||||
location = wxPoint( PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.X" ),
|
||||
-PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.Y" ) );
|
||||
size = wxSize( PropertiesReadKiCadUnitFrac( aProperties, "CORNER.X" ) - location.x,
|
||||
-PropertiesReadKiCadUnitFrac( aProperties, "CORNER.Y" ) - location.y );
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
|
||||
ASCH_BEZIER::ASCH_BEZIER( const std::map<wxString, wxString>& aProperties )
|
||||
{
|
||||
wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::BEZIER );
|
||||
|
|
|
@ -88,7 +88,7 @@ enum class ALTIUM_SCH_RECORD
|
|||
RECORD_46 = 46,
|
||||
RECORD_47 = 47,
|
||||
RECORD_48 = 48,
|
||||
RECORD_209 = 209,
|
||||
NOTE = 209,
|
||||
RECORD_215 = 215,
|
||||
RECORD_216 = 216,
|
||||
RECORD_217 = 217,
|
||||
|
@ -236,6 +236,14 @@ enum class ASCH_LABEL_JUSTIFICATION
|
|||
};
|
||||
|
||||
|
||||
enum class ASCH_NOTE_ALIGNMENT
|
||||
{
|
||||
LEFT = 1,
|
||||
CENTER = 2,
|
||||
RIGHT = 3
|
||||
};
|
||||
|
||||
|
||||
struct ASCH_LABEL
|
||||
{
|
||||
int ownerindex;
|
||||
|
@ -254,6 +262,26 @@ struct ASCH_LABEL
|
|||
};
|
||||
|
||||
|
||||
struct ASCH_NOTE
|
||||
{
|
||||
wxPoint location;
|
||||
wxSize size;
|
||||
|
||||
wxString text;
|
||||
wxString author;
|
||||
|
||||
int fontId;
|
||||
bool isWordWrapped;
|
||||
bool border;
|
||||
int textMargin;
|
||||
int areaColor;
|
||||
|
||||
ASCH_NOTE_ALIGNMENT alignment;
|
||||
|
||||
explicit ASCH_NOTE( const std::map<wxString, wxString>& aProperties );
|
||||
};
|
||||
|
||||
|
||||
struct ASCH_BEZIER
|
||||
{
|
||||
int ownerindex;
|
||||
|
|
|
@ -462,7 +462,8 @@ void SCH_ALTIUM_PLUGIN::ParseFileHeader( const CFB::CompoundFileReader& aReader
|
|||
break;
|
||||
case ALTIUM_SCH_RECORD::RECORD_48:
|
||||
break;
|
||||
case ALTIUM_SCH_RECORD::RECORD_209:
|
||||
case ALTIUM_SCH_RECORD::NOTE:
|
||||
ParseNote( properties );
|
||||
break;
|
||||
case ALTIUM_SCH_RECORD::RECORD_215:
|
||||
break;
|
||||
|
@ -834,6 +835,48 @@ void SCH_ALTIUM_PLUGIN::ParseLabel( const std::map<wxString, wxString>& aPropert
|
|||
}
|
||||
|
||||
|
||||
void SCH_ALTIUM_PLUGIN::ParseNote( const std::map<wxString, wxString>& aProperties )
|
||||
{
|
||||
ASCH_NOTE elem( aProperties );
|
||||
|
||||
SCH_TEXT* text = new SCH_TEXT( elem.location + m_sheetOffset, elem.text );
|
||||
|
||||
switch( elem.alignment )
|
||||
{
|
||||
default:
|
||||
case ASCH_NOTE_ALIGNMENT::LEFT:
|
||||
text->SetLabelSpinStyle( LABEL_SPIN_STYLE::SPIN::RIGHT );
|
||||
break;
|
||||
case ASCH_NOTE_ALIGNMENT::CENTER:
|
||||
// No support for centered text in Eeschema yet...
|
||||
text->SetLabelSpinStyle( LABEL_SPIN_STYLE::SPIN::RIGHT );
|
||||
break;
|
||||
case ASCH_NOTE_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.
|
||||
|
||||
// TODO: need some sort of propety system for storing author....
|
||||
|
||||
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::ParseBezier( const std::map<wxString, wxString>& aProperties )
|
||||
{
|
||||
ASCH_BEZIER elem( aProperties );
|
||||
|
|
|
@ -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 ParseNote( const std::map<wxString, wxString>& aProperties );
|
||||
void ParseBezier( const std::map<wxString, wxString>& aProperties );
|
||||
void ParsePolyline( const std::map<wxString, wxString>& aProperties );
|
||||
void ParsePolygon( const std::map<wxString, wxString>& aProperties );
|
||||
|
|
Loading…
Reference in New Issue