altium: add initial support for labels
This commit is contained in:
parent
4355e91a41
commit
a6072a40f5
|
@ -54,6 +54,18 @@ int PropertiesReadKiCadUnitFrac(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T PropertiesReadEnum( const std::map<wxString, wxString>& aProperties, const wxString& aKey,
|
||||||
|
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
|
||||||
|
return static_cast<T>( value );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ASCH_COMPONENT::ASCH_COMPONENT( const std::map<wxString, wxString>& aProperties )
|
ASCH_COMPONENT::ASCH_COMPONENT( const std::map<wxString, wxString>& aProperties )
|
||||||
{
|
{
|
||||||
wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::COMPONENT );
|
wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::COMPONENT );
|
||||||
|
@ -98,11 +110,8 @@ ASCH_PIN::ASCH_PIN( const std::map<wxString, wxString>& aProperties )
|
||||||
symbolInnerEdge = ( symbolInnerEdgeInt == 0 || symbolInnerEdgeInt == 3 ) ?
|
symbolInnerEdge = ( symbolInnerEdgeInt == 0 || symbolInnerEdgeInt == 3 ) ?
|
||||||
static_cast<ASCH_PIN_SYMBOL_INNEREDGE>( symbolInnerEdgeInt ) :
|
static_cast<ASCH_PIN_SYMBOL_INNEREDGE>( symbolInnerEdgeInt ) :
|
||||||
ASCH_PIN_SYMBOL_INNEREDGE::UNKNOWN;
|
ASCH_PIN_SYMBOL_INNEREDGE::UNKNOWN;
|
||||||
|
electrical = PropertiesReadEnum<ASCH_PIN_ELECTRICAL>(
|
||||||
int electricalInt = ALTIUM_PARSER::PropertiesReadInt( aProperties, "ELECTRICAL", 0 );
|
aProperties, "ELECTRICAL", 0, 7, ASCH_PIN_ELECTRICAL::UNKNOWN );
|
||||||
electrical = ( electricalInt >= 0 && electricalInt <= 7 ) ?
|
|
||||||
static_cast<ASCH_PIN_ELECTRICAL>( electricalInt ) :
|
|
||||||
ASCH_PIN_ELECTRICAL::UNKNOWN;
|
|
||||||
|
|
||||||
int pinconglomerate = ALTIUM_PARSER::PropertiesReadInt( aProperties, "PINCONGLOMERATE", 0 );
|
int pinconglomerate = ALTIUM_PARSER::PropertiesReadInt( aProperties, "PINCONGLOMERATE", 0 );
|
||||||
|
|
||||||
|
@ -153,6 +162,25 @@ ASCH_PIN::ASCH_PIN( const std::map<wxString, wxString>& aProperties )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ASCH_LABEL::ASCH_LABEL( const std::map<wxString, wxString>& aProperties )
|
||||||
|
{
|
||||||
|
wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::LABEL );
|
||||||
|
|
||||||
|
ownerindex =
|
||||||
|
ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERINDEX", ALTIUM_COMPONENT_NONE );
|
||||||
|
ownerpartid =
|
||||||
|
ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTID", ALTIUM_COMPONENT_NONE );
|
||||||
|
|
||||||
|
location = wxPoint( PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.X" ),
|
||||||
|
-PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.Y" ) );
|
||||||
|
|
||||||
|
text = ALTIUM_PARSER::PropertiesReadString( aProperties, "TEXT", "" );
|
||||||
|
isMirrored = ALTIUM_PARSER::PropertiesReadBool( aProperties, "ISMIRRORED", false );
|
||||||
|
justification = PropertiesReadEnum<ASCH_LABEL_JUSTIFICATION>(
|
||||||
|
aProperties, "JUSTIFICATION", 0, 8, ASCH_LABEL_JUSTIFICATION::UNKNOWN );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ASCH_BEZIER::ASCH_BEZIER( const std::map<wxString, wxString>& aProperties )
|
ASCH_BEZIER::ASCH_BEZIER( const std::map<wxString, wxString>& aProperties )
|
||||||
{
|
{
|
||||||
wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::BEZIER );
|
wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::BEZIER );
|
||||||
|
@ -335,10 +363,8 @@ ASCH_NET_LABEL::ASCH_NET_LABEL( const std::map<wxString, wxString>& aProperties
|
||||||
location = wxPoint( PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.X" ),
|
location = wxPoint( PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.X" ),
|
||||||
-PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.Y" ) );
|
-PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.Y" ) );
|
||||||
|
|
||||||
int orientationRaw = ALTIUM_PARSER::PropertiesReadInt( aProperties, "ORIENTATION", 0 );
|
orientation = PropertiesReadEnum<ASCH_RECORD_ORIENTATION>(
|
||||||
orientation = orientationRaw >= 0 && orientationRaw <= 3 ?
|
aProperties, "ORIENTATION", 0, 3, ASCH_RECORD_ORIENTATION::RIGHTWARDS );
|
||||||
static_cast<ASCH_RECORD_ORIENTATION>( orientationRaw ) :
|
|
||||||
ASCH_RECORD_ORIENTATION::RIGHTWARDS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -197,6 +197,37 @@ struct ASCH_PIN
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum class ASCH_LABEL_JUSTIFICATION
|
||||||
|
{
|
||||||
|
UNKNOWN = -1,
|
||||||
|
|
||||||
|
BOTTOM_LEFT = 0,
|
||||||
|
BOTTOM_CENTER = 1,
|
||||||
|
BOTTOM_RIGHT = 2,
|
||||||
|
CENTER_LEFT = 3,
|
||||||
|
CENTER_CENTER = 4,
|
||||||
|
CENTER_RIGHT = 5,
|
||||||
|
TOP_LEFT = 6,
|
||||||
|
TOP_CENTER = 7,
|
||||||
|
TOP_RIGHT = 8
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct ASCH_LABEL
|
||||||
|
{
|
||||||
|
int ownerindex;
|
||||||
|
int ownerpartid;
|
||||||
|
|
||||||
|
wxPoint location;
|
||||||
|
|
||||||
|
wxString text;
|
||||||
|
bool isMirrored;
|
||||||
|
ASCH_LABEL_JUSTIFICATION justification;
|
||||||
|
|
||||||
|
explicit ASCH_LABEL( const std::map<wxString, wxString>& aProperties );
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
struct ASCH_BEZIER
|
struct ASCH_BEZIER
|
||||||
{
|
{
|
||||||
int ownerindex;
|
int ownerindex;
|
||||||
|
|
|
@ -308,6 +308,7 @@ void SCH_ALTIUM_PLUGIN::Parse( const CFB::CompoundFileReader& aReader )
|
||||||
case ALTIUM_SCH_RECORD::IEEE_SYMBOL:
|
case ALTIUM_SCH_RECORD::IEEE_SYMBOL:
|
||||||
break;
|
break;
|
||||||
case ALTIUM_SCH_RECORD::LABEL:
|
case ALTIUM_SCH_RECORD::LABEL:
|
||||||
|
ParseLabel( properties );
|
||||||
break;
|
break;
|
||||||
case ALTIUM_SCH_RECORD::BEZIER:
|
case ALTIUM_SCH_RECORD::BEZIER:
|
||||||
ParseBezier( properties );
|
ParseBezier( properties );
|
||||||
|
@ -601,6 +602,91 @@ void SCH_ALTIUM_PLUGIN::ParsePin( const std::map<wxString, wxString>& aPropertie
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SetEdaTextJustification( EDA_TEXT* text, ASCH_LABEL_JUSTIFICATION justification )
|
||||||
|
{
|
||||||
|
switch( justification )
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case ASCH_LABEL_JUSTIFICATION::UNKNOWN:
|
||||||
|
case ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT:
|
||||||
|
case ASCH_LABEL_JUSTIFICATION::BOTTOM_CENTER:
|
||||||
|
case ASCH_LABEL_JUSTIFICATION::BOTTOM_RIGHT:
|
||||||
|
text->SetVertJustify( EDA_TEXT_VJUSTIFY_T::GR_TEXT_VJUSTIFY_BOTTOM );
|
||||||
|
break;
|
||||||
|
case ASCH_LABEL_JUSTIFICATION::CENTER_LEFT:
|
||||||
|
case ASCH_LABEL_JUSTIFICATION::CENTER_CENTER:
|
||||||
|
case ASCH_LABEL_JUSTIFICATION::CENTER_RIGHT:
|
||||||
|
text->SetVertJustify( EDA_TEXT_VJUSTIFY_T::GR_TEXT_VJUSTIFY_CENTER );
|
||||||
|
break;
|
||||||
|
case ASCH_LABEL_JUSTIFICATION::TOP_LEFT:
|
||||||
|
case ASCH_LABEL_JUSTIFICATION::TOP_CENTER:
|
||||||
|
case ASCH_LABEL_JUSTIFICATION::TOP_RIGHT:
|
||||||
|
text->SetVertJustify( EDA_TEXT_VJUSTIFY_T::GR_TEXT_VJUSTIFY_TOP );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch( justification )
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case ASCH_LABEL_JUSTIFICATION::UNKNOWN:
|
||||||
|
case ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT:
|
||||||
|
case ASCH_LABEL_JUSTIFICATION::CENTER_LEFT:
|
||||||
|
case ASCH_LABEL_JUSTIFICATION::TOP_LEFT:
|
||||||
|
text->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_LEFT );
|
||||||
|
break;
|
||||||
|
case ASCH_LABEL_JUSTIFICATION::BOTTOM_CENTER:
|
||||||
|
case ASCH_LABEL_JUSTIFICATION::CENTER_CENTER:
|
||||||
|
case ASCH_LABEL_JUSTIFICATION::TOP_CENTER:
|
||||||
|
text->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_CENTER );
|
||||||
|
break;
|
||||||
|
case ASCH_LABEL_JUSTIFICATION::BOTTOM_RIGHT:
|
||||||
|
case ASCH_LABEL_JUSTIFICATION::CENTER_RIGHT:
|
||||||
|
case ASCH_LABEL_JUSTIFICATION::TOP_RIGHT:
|
||||||
|
text->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_RIGHT );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SCH_ALTIUM_PLUGIN::ParseLabel( const std::map<wxString, wxString>& aProperties )
|
||||||
|
{
|
||||||
|
ASCH_LABEL elem( aProperties );
|
||||||
|
|
||||||
|
if( elem.ownerpartid == ALTIUM_COMPONENT_NONE )
|
||||||
|
{
|
||||||
|
SCH_TEXT* text = new SCH_TEXT( elem.location, elem.text );
|
||||||
|
text->SetMirrored( elem.isMirrored );
|
||||||
|
|
||||||
|
SetEdaTextJustification( text, elem.justification );
|
||||||
|
|
||||||
|
text->SetFlags( IS_NEW );
|
||||||
|
m_currentSheet->GetScreen()->Append( text );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const auto& symbol = m_symbols.find( elem.ownerindex );
|
||||||
|
if( symbol == m_symbols.end() )
|
||||||
|
{
|
||||||
|
// TODO: e.g. can depend on Template (RECORD=39
|
||||||
|
wxLogWarning( wxString::Format(
|
||||||
|
"Label tries to access symbol with ownerindex %d which does not exist",
|
||||||
|
elem.ownerindex ) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& component = m_components.at( symbol->first );
|
||||||
|
|
||||||
|
LIB_TEXT* text = new LIB_TEXT( symbol->second );
|
||||||
|
symbol->second->AddDrawItem( text );
|
||||||
|
|
||||||
|
text->SetPosition( GetRelativePosition( elem.location, component ) );
|
||||||
|
text->SetText( elem.text );
|
||||||
|
|
||||||
|
SetEdaTextJustification( text, elem.justification );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SCH_ALTIUM_PLUGIN::ParseBezier( const std::map<wxString, wxString>& aProperties )
|
void SCH_ALTIUM_PLUGIN::ParseBezier( const std::map<wxString, wxString>& aProperties )
|
||||||
{
|
{
|
||||||
ASCH_BEZIER elem( aProperties );
|
ASCH_BEZIER elem( aProperties );
|
||||||
|
|
|
@ -100,6 +100,7 @@ public:
|
||||||
private:
|
private:
|
||||||
void ParseComponent( int index, const std::map<wxString, wxString>& aProperties );
|
void ParseComponent( int index, const std::map<wxString, wxString>& aProperties );
|
||||||
void ParsePin( const std::map<wxString, wxString>& aProperties );
|
void ParsePin( const std::map<wxString, wxString>& aProperties );
|
||||||
|
void ParseLabel( const std::map<wxString, wxString>& aProperties );
|
||||||
void ParseBezier( const std::map<wxString, wxString>& aProperties );
|
void ParseBezier( const std::map<wxString, wxString>& aProperties );
|
||||||
void ParsePolyline( const std::map<wxString, wxString>& aProperties );
|
void ParsePolyline( const std::map<wxString, wxString>& aProperties );
|
||||||
void ParsePolygon( const std::map<wxString, wxString>& aProperties );
|
void ParsePolygon( const std::map<wxString, wxString>& aProperties );
|
||||||
|
|
Loading…
Reference in New Issue