Eeschema: Copy attributes from eagle.

Eagle allows for variants of components to be listed in the schematic.
This patch copies the variant data into the imported schematic item,
prefixing the alternate variant names with "VARIANT_" and keeping the
alternate values.
This commit is contained in:
Mark van Doesburg 2018-07-10 16:32:10 +02:00 committed by Seth Hillbrand
parent 1dbaef303e
commit 91e3d21d68
3 changed files with 86 additions and 13 deletions

View File

@ -886,6 +886,41 @@ EPART::EPART( wxXmlNode* aPart )
device = parseRequiredAttribute<wxString>( aPart, "device" );
technology = parseOptionalAttribute<wxString>( aPart, "technology" );
value = parseOptionalAttribute<wxString>( aPart, "value" );
for( auto child = aPart->GetChildren(); child; child = child->GetNext() )
{
if( child->GetName() == "attribute" )
{
std::string aname, avalue;
for( auto x = child->GetAttributes(); x; x = x->GetNext() )
{
if( x->GetName() == "name" )
aname = x->GetValue();
else if( x->GetName() == "value" )
avalue = x->GetValue();
}
if( aname.size() && avalue.size() )
attribute[aname] = avalue;
}
else if( child->GetName() == "variant" )
{
std::string aname, avalue;
for( auto x = child->GetAttributes(); x; x = x->GetNext() )
{
if( x->GetName() == "name" )
aname = x->GetValue();
else if( x->GetName() == "value" )
avalue = x->GetValue();
}
if( aname.size() && avalue.size() )
variant[aname] = avalue;
}
}
}

View File

@ -1142,6 +1142,22 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
component->GetField( REFERENCE )->SetVisible( part->GetField( REFERENCE )->IsVisible() );
component->GetField( VALUE )->SetVisible( part->GetField( VALUE )->IsVisible() );
for( auto a:epart->attribute )
{
auto field = component->AddField( *component->GetField( VALUE ) );
field->SetName( a.first );
field->SetText( a.second );
field->SetVisible( false );
}
for( auto a:epart->variant )
{
auto field = component->AddField( *component->GetField( VALUE ) );
field->SetName( "VARIANT_" + a.first );
field->SetText( a.second );
field->SetVisible( false );
}
bool valueAttributeFound = false;
bool nameAttributeFound = false;
@ -1154,21 +1170,28 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
if( attributeNode->GetName() == "attribute" )
{
auto attr = EATTR( attributeNode );
SCH_FIELD* field = NULL;
SCH_FIELD* field;
if( attr.name.Lower() == "name" || attr.name.Lower() == "value" )
if( attr.name.Lower() == "name" )
{
field = component->GetField( REFERENCE );
nameAttributeFound = true;
}
else if( attr.name.Lower() == "value" )
{
field = component->GetField( VALUE );
valueAttributeFound = true;
}
else
{
field = component->FindField( attr.name );
if(field)
field->SetVisible( false );
}
if( field )
{
if( attr.name.Lower() == "name" )
{
field = component->GetField( REFERENCE );
nameAttributeFound = true;
}
else
{
field = component->GetField( VALUE );
valueAttributeFound = true;
}
field->SetPosition( wxPoint( attr.x->ToSchUnits(), -attr.y->ToSchUnits() ) );
int align = attr.align ? *attr.align : ETEXT::BOTTOM_LEFT;
@ -1191,6 +1214,19 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
absdegrees );
}
}
else if( attributeNode->GetName() == "variant" )
{
wxString variant, value;
if( attributeNode->GetAttribute( "name", &variant )
&& attributeNode->GetAttribute( "value", &value ) )
{
auto field = component->AddField( *component->GetField( VALUE ) );
field->SetName( "VARIANT_" + variant );
field->SetText( value );
field->SetVisible( false );
}
}
attributeNode = attributeNode->GetNext();
}

View File

@ -913,6 +913,8 @@ struct EPART
wxString device;
opt_wxString technology;
opt_wxString value;
std::map<std::string,std::string> attribute;
std::map<std::string,std::string> variant;
EPART( wxXmlNode* aPart );
};