kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #36605
Re: [PATCH] Import attributes and variants from eagle.
Hi Mark-
Thank you for your contribution. It would be helpful to evaluating the
patch if you could provide an example Eagle project that uses the variants
feature.
Best-
Seth
Am Mo., 16. Juli 2018 um 23:49 Uhr schrieb <mdoesbur@xxxxxxxxx>:
> From: Mark van Doesburg <mark.vandoesburg@xxxxxxxxx>
>
> Here is a patch that copies all attributes from an original eagle
> schematic. This is necessary for me to keep the BOM the same.
>
> Since kicad does not yet support variants, it creates additional fields
> for values that differ for variants. It prefixes them with "VARIANT_"
>
>
> ---
> common/eagle_parser.cpp | 31 ++++++++++++++++++++++++++++
> eeschema/sch_eagle_plugin.cpp | 39 +++++++++++++++++++++++++++++++----
> include/eagle_parser.h | 2 ++
> 3 files changed, 68 insertions(+), 4 deletions(-)
>
> diff --git a/common/eagle_parser.cpp b/common/eagle_parser.cpp
> index 60aa52612..6d8aa3fe5 100644
> --- a/common/eagle_parser.cpp
> +++ b/common/eagle_parser.cpp
> @@ -884,8 +884,39 @@ EPART::EPART( wxXmlNode* aPart )
> library = parseRequiredAttribute<wxString>( aPart, "library" );
> deviceset = parseRequiredAttribute<wxString>( aPart, "deviceset" );
> 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;
> + }
> + }
> }
>
>
> diff --git a/eeschema/sch_eagle_plugin.cpp b/eeschema/sch_eagle_plugin.cpp
> index 0b36e1f25..c7a999c5b 100644
> --- a/eeschema/sch_eagle_plugin.cpp
> +++ b/eeschema/sch_eagle_plugin.cpp
> @@ -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( SCH_FIELD( *component->GetField(
> VALUE ) ) );
> + field->SetName( a.first );
> + field->SetText( a.second );
> + field->SetVisible( false );
> + }
> +
> + for( auto a:epart->variant )
> + {
> + auto field = component->AddField( SCH_FIELD( *component->GetField(
> VALUE ) ) );
> + field->SetName( "VARIANT_" + a.first );
> + field->SetText( a.second );
> + field->SetVisible( false );
> + }
> +
> bool valueAttributeFound = false;
> bool nameAttributeFound = false;
>
> @@ -1157,18 +1173,20 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode*
> aInstanceNode )
>
> SCH_FIELD* field;
>
> - if( attr.name.Lower() == "name" || attr.name.Lower() ==
> "value" )
> + if( attr.name.Lower() == "name" || attr.name.Lower() ==
> "value" || (field = component->FindField( attr.name )))
> {
> if( attr.name.Lower() == "name" )
> {
> field = component->GetField( REFERENCE );
> nameAttributeFound = true;
> }
> - else
> + else if( attr.name.Lower() == "value" )
> {
> field = component->GetField( VALUE );
> valueAttributeFound = true;
> - }
> + } else {
> + field->SetVisible( false );
> + }
>
> field->SetPosition( wxPoint( attr.x->ToSchUnits(),
> -attr.y->ToSchUnits() ) );
> int align = attr.align ? *attr.align : ETEXT::BOTTOM_LEFT;
> @@ -1189,7 +1207,20 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode*
> aInstanceNode )
>
> eagleToKicadAlignment( (EDA_TEXT*) field, align,
> reldegrees, mirror, spin,
> absdegrees );
> - }
> + }
> + }
> + else if( attributeNode->GetName() == "variant" )
> + {
> + wxString variant, value;
> +
> + if( attributeNode->GetAttribute( "name", &variant )
> + && attributeNode->GetAttribute( "value", &value ) )
> + {
> + auto field = component->AddField( SCH_FIELD(
> *component->GetField( VALUE ) ) );
> + field->SetName( "VARIANT_" + variant );
> + field->SetText( value );
> + field->SetVisible( false );
> + }
> }
>
> attributeNode = attributeNode->GetNext();
> diff --git a/include/eagle_parser.h b/include/eagle_parser.h
> index 257aa2e6a..59f74ccae 100644
> --- a/include/eagle_parser.h
> +++ b/include/eagle_parser.h
> @@ -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 );
> };
> --
> 2.17.0
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help : https://help.launchpad.net/ListHelp
>
Follow ups
References