Eagle import plugin: Code clean-up and formatting

This commit is contained in:
Maciej Suminski 2017-10-17 10:19:43 +02:00
parent 25b8111341
commit ee8012a5cc
4 changed files with 36 additions and 60 deletions

View File

@ -178,7 +178,7 @@ ECOORD Convert<ECOORD>( const wxString& aCoord )
* @return T - the attributed parsed as the specified type. * @return T - the attributed parsed as the specified type.
*/ */
template<typename T> template<typename T>
T parseRequiredAttribute( wxXmlNode* aNode, string aAttribute ) T parseRequiredAttribute( wxXmlNode* aNode, const string& aAttribute )
{ {
wxString value; wxString value;
@ -197,7 +197,7 @@ T parseRequiredAttribute( wxXmlNode* aNode, string aAttribute )
* found. * found.
*/ */
template<typename T> template<typename T>
OPTIONAL_XML_ATTRIBUTE<T> parseOptionalAttribute( wxXmlNode* aNode, string aAttribute ) OPTIONAL_XML_ATTRIBUTE<T> parseOptionalAttribute( wxXmlNode* aNode, const string& aAttribute )
{ {
return OPTIONAL_XML_ATTRIBUTE<T>( aNode->GetAttribute( aAttribute ) ); return OPTIONAL_XML_ATTRIBUTE<T>( aNode->GetAttribute( aAttribute ) );
} }
@ -859,7 +859,6 @@ EPART::EPART( wxXmlNode* aPart )
device = parseRequiredAttribute<string>( aPart, "device" ); device = parseRequiredAttribute<string>( aPart, "device" );
technology = parseOptionalAttribute<string>( aPart, "technology" ); technology = parseOptionalAttribute<string>( aPart, "technology" );
value = parseOptionalAttribute<string>( aPart, "value" ); value = parseOptionalAttribute<string>( aPart, "value" );
} }

View File

@ -658,10 +658,10 @@ void SCH_EAGLE_PLUGIN::loadSheet( wxXmlNode* aSheetNode, int aSheetIndex )
PAGE_INFO pageInfo = m_currentSheet->GetScreen()->GetPageSettings(); PAGE_INFO pageInfo = m_currentSheet->GetScreen()->GetPageSettings();
// Increase if necessary // Increase if necessary
if( pageSizeIU.x<targetSheetSize.x ) if( pageSizeIU.x < targetSheetSize.x )
pageInfo.SetWidthMils( targetSheetSize.x ); pageInfo.SetWidthMils( targetSheetSize.x );
if( pageSizeIU.y<targetSheetSize.y ) if( pageSizeIU.y < targetSheetSize.y )
pageInfo.SetHeightMils( targetSheetSize.y ); pageInfo.SetHeightMils( targetSheetSize.y );
// Set the new sheet size. // Set the new sheet size.
@ -765,7 +765,7 @@ void SCH_EAGLE_PLUGIN::loadSegments( wxXmlNode* aSegmentsNode, const wxString& n
wxString netname = escapeName( netName ); wxString netname = escapeName( netName );
// Add a global label if the net appears on more than one Eagle sheet // Add a global label if the net appears on more than one Eagle sheet
if( m_netCounts[netName.ToStdString()]>1 ) if( m_netCounts[netName.ToStdString()] > 1 )
{ {
std::unique_ptr<SCH_GLOBALLABEL> glabel( new SCH_GLOBALLABEL ); std::unique_ptr<SCH_GLOBALLABEL> glabel( new SCH_GLOBALLABEL );
glabel->SetPosition( wire->MidPoint() ); glabel->SetPosition( wire->MidPoint() );
@ -847,7 +847,7 @@ SCH_TEXT* SCH_EAGLE_PLUGIN::loadLabel( wxXmlNode* aLabelNode,
// Determine if the Label is a local and global label based on the number of sheets the net appears on. // Determine if the Label is a local and global label based on the number of sheets the net appears on.
if( m_netCounts[aNetName.ToStdString()]>1 ) if( m_netCounts[aNetName.ToStdString()] > 1 )
{ {
std::unique_ptr<SCH_GLOBALLABEL> glabel( new SCH_GLOBALLABEL ); std::unique_ptr<SCH_GLOBALLABEL> glabel( new SCH_GLOBALLABEL );
glabel->SetPosition( elabelpos ); glabel->SetPosition( elabelpos );
@ -902,7 +902,7 @@ SCH_TEXT* SCH_EAGLE_PLUGIN::loadLabel( wxXmlNode* aLabelNode,
std::unique_ptr<SCH_LABEL> label( new SCH_LABEL ); std::unique_ptr<SCH_LABEL> label( new SCH_LABEL );
label->SetPosition( elabelpos ); label->SetPosition( elabelpos );
label->SetText( netname ); label->SetText( netname );
label->SetTextSize( wxSize( elabel.size * EUNIT_TO_MIL, elabel.size * EUNIT_TO_MIL ) ); label->SetTextSize( wxSize( elabel.size.ToSchUnits(), elabel.size.ToSchUnits() ) );
label->SetLabelSpinStyle( 0 ); label->SetLabelSpinStyle( 0 );
@ -998,8 +998,6 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
{ {
auto einstance = EINSTANCE( aInstanceNode ); auto einstance = EINSTANCE( aInstanceNode );
bool smashed = false;
SCH_SCREEN* screen = m_currentSheet->GetScreen(); SCH_SCREEN* screen = m_currentSheet->GetScreen();
// Find the part in the list for the sheet. // Find the part in the list for the sheet.
@ -1011,8 +1009,8 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
std::string libraryname = epart->library; std::string libraryname = epart->library;
std::string gatename = epart->deviceset + epart->device + einstance.gate; std::string gatename = epart->deviceset + epart->device + einstance.gate;
wxString sntemp = wxString( epart->deviceset + epart->device );
wxString sntemp = wxString( epart->deviceset + epart->device );
sntemp.Replace( "*", "" ); sntemp.Replace( "*", "" );
std::string symbolname = sntemp.ToStdString(); std::string symbolname = sntemp.ToStdString();
@ -1086,20 +1084,8 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
} }
// Set the visibility of fields. // Set the visibility of fields.
if( part->GetField( REFERENCE )->IsVisible() ) component->GetField( REFERENCE )->SetVisible( part->GetField( REFERENCE )->IsVisible() );
component->GetField( REFERENCE )->SetVisible( true ); component->GetField( VALUE )->SetVisible( part->GetField( VALUE )->IsVisible() );
else
component->GetField( REFERENCE )->SetVisible( false );
if( part->GetField( VALUE )->IsVisible() )
component->GetField( VALUE )->SetVisible( true );
else
component->GetField( VALUE )->SetVisible( false );
if( einstance.smashed )
{
smashed = einstance.smashed.Get();
}
bool valueAttributeFound = false; bool valueAttributeFound = false;
bool nameAttributeFound = false; bool nameAttributeFound = false;
@ -1108,7 +1094,6 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
wxXmlNode* attributeNode = aInstanceNode->GetChildren(); wxXmlNode* attributeNode = aInstanceNode->GetChildren();
// Parse attributes for the instance // Parse attributes for the instance
//
while( attributeNode ) while( attributeNode )
{ {
if( attributeNode->GetName() == "attribute" ) if( attributeNode->GetName() == "attribute" )
@ -1136,20 +1121,15 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
bool mirror = attr.rot ? attr.rot->mirror : false; bool mirror = attr.rot ? attr.rot->mirror : false;
if( einstance.rot && einstance.rot->mirror ) if( einstance.rot && einstance.rot->mirror )
{
mirror = !mirror; mirror = !mirror;
}
bool spin = attr.rot ? attr.rot->spin : false; bool spin = attr.rot ? attr.rot->spin : false;
if( attr.display == EATTR::Off ) if( attr.display == EATTR::Off )
{
field->SetVisible( false ); field->SetVisible( false );
}
int rotation = einstance.rot ? einstance.rot->degrees : 0; int rotation = einstance.rot ? einstance.rot->degrees : 0;
int reldegrees = ( absdegrees - rotation + 360.0); int reldegrees = ( absdegrees - rotation + 360.0 );
reldegrees %= 360; reldegrees %= 360;
eagleToKicadAlignment( (EDA_TEXT*) field, align, reldegrees, mirror, spin, eagleToKicadAlignment( (EDA_TEXT*) field, align, reldegrees, mirror, spin,
@ -1160,7 +1140,7 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
attributeNode = attributeNode->GetNext(); attributeNode = attributeNode->GetNext();
} }
if( smashed ) if( einstance.smashed && einstance.smashed.Get() )
{ {
if( !valueAttributeFound ) if( !valueAttributeFound )
component->GetField( VALUE )->SetVisible( false ); component->GetField( VALUE )->SetVisible( false );
@ -1226,14 +1206,10 @@ EAGLE_LIBRARY* SCH_EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLibraryNode,
LIB_FIELD* reference = kpart->GetField( REFERENCE ); LIB_FIELD* reference = kpart->GetField( REFERENCE );
if( prefix.length() ==0 ) if( prefix.length() == 0 )
{
reference->SetVisible( false ); reference->SetVisible( false );
}
else else
{
reference->SetText( prefix ); reference->SetText( prefix );
}
int gateindex = 1; int gateindex = 1;
bool ispower = false; bool ispower = false;
@ -1348,7 +1324,7 @@ bool SCH_EAGLE_PLUGIN::loadSymbol( wxXmlNode* aSymbolNode,
{ {
if( connect.gate == aGateName and pin->GetName().ToStdString() == connect.pin ) if( connect.gate == aGateName and pin->GetName().ToStdString() == connect.pin )
{ {
wxArrayString pads = wxSplit( wxString(connect.pad), ' '); wxArrayString pads = wxSplit( wxString( connect.pad ), ' ');
pin->SetPartNumber( aGateNumber ); pin->SetPartNumber( aGateNumber );
pin->SetUnit( aGateNumber ); pin->SetUnit( aGateNumber );
@ -1365,10 +1341,9 @@ bool SCH_EAGLE_PLUGIN::loadSymbol( wxXmlNode* aSymbolNode,
wxString padname( pads[i] ); wxString padname( pads[i] );
apin->SetNumber( padname ); apin->SetNumber( padname );
aPart->AddDrawItem( apin); aPart->AddDrawItem( apin );
} }
break; break;
} }
} }
} }

View File

@ -447,9 +447,9 @@ struct ECOORD
struct ENET struct ENET
{ {
int netcode; int netcode;
std::string netname; string netname;
ENET( int aNetCode, const std::string& aNetName ) : ENET( int aNetCode, const string& aNetName ) :
netcode( aNetCode ), netcode( aNetCode ),
netname( aNetName ) netname( aNetName )
{} {}
@ -991,7 +991,7 @@ struct EDEVICE
package %String; #IMPLIED package %String; #IMPLIED
> >
*/ */
std::string name; string name;
opt_string package; opt_string package;
std::vector<ECONNECT> connects; std::vector<ECONNECT> connects;
@ -1011,7 +1011,7 @@ struct EDEVICE_SET
> >
*/ */
std::string name; string name;
opt_string prefix; opt_string prefix;
opt_bool uservalue; opt_bool uservalue;
//std::vector<EDEVICE> devices; //std::vector<EDEVICE> devices;

View File

@ -1169,7 +1169,7 @@ MODULE* EAGLE_PLUGIN::makeModule( wxXmlNode* aPackage, const string& aPkgName )
{ {
std::unique_ptr<MODULE> m( new MODULE( m_board ) ); std::unique_ptr<MODULE> m( new MODULE( m_board ) );
m->SetFPID( LIB_ID( UTF8(aPkgName) ) ); m->SetFPID( LIB_ID( UTF8( aPkgName ) ) );
// Get the first package item and iterate // Get the first package item and iterate
wxXmlNode* packageItem = aPackage->GetChildren(); wxXmlNode* packageItem = aPackage->GetChildren();
@ -1233,6 +1233,7 @@ void EAGLE_PLUGIN::packageWire( MODULE* aModule, wxXmlNode* aTree ) const
// FIXME: the cap attribute is ignored because kicad can't create lines // FIXME: the cap attribute is ignored because kicad can't create lines
// with flat ends. // with flat ends.
EDGE_MODULE* dwg; EDGE_MODULE* dwg;
if( !w.curve ) if( !w.curve )
{ {
dwg = new EDGE_MODULE( aModule, S_SEGMENT ); dwg = new EDGE_MODULE( aModule, S_SEGMENT );
@ -1252,10 +1253,9 @@ void EAGLE_PLUGIN::packageWire( MODULE* aModule, wxXmlNode* aTree ) const
dwg->SetLayer( layer ); dwg->SetLayer( layer );
dwg->SetWidth( width ); dwg->SetWidth( width );
dwg->SetDrawCoord(); dwg->SetDrawCoord();
aModule->GraphicalItemsList().PushBack( dwg );
aModule->GraphicalItemsList().PushBack( dwg );
} }
@ -1352,7 +1352,9 @@ void EAGLE_PLUGIN::packageText( MODULE* aModule, wxXmlNode* aTree ) const
if( IsCopperLayer( layer ) ) // skip copper "package.circle"s if( IsCopperLayer( layer ) ) // skip copper "package.circle"s
{ {
wxLogMessage( wxString::Format( "Unsupported text on copper layer in package %s \n Moving to drawings layer.", aModule->GetFPID().GetLibItemName().c_str() ) ); wxLogMessage( wxString::Format(
"Unsupported text on copper layer in package %s\nMoving to drawings layer.",
aModule->GetFPID().GetLibItemName().c_str() ) );
layer = Dwgs_User; layer = Dwgs_User;
} }
@ -1471,7 +1473,9 @@ void EAGLE_PLUGIN::packageRectangle( MODULE* aModule, wxXmlNode* aTree ) const
if( IsCopperLayer( layer ) ) // skip copper "package.circle"s if( IsCopperLayer( layer ) ) // skip copper "package.circle"s
{ {
wxLogMessage( wxString::Format( "Unsupported rectangle on copper layer in package %s \n Moving to drawings layer.", aModule->GetFPID().GetLibItemName().c_str() ) ); wxLogMessage( wxString::Format(
"Unsupported rectangle on copper layer in package %s\nMoving to drawings layer.",
aModule->GetFPID().GetLibItemName().c_str() ) );
layer = Dwgs_User; layer = Dwgs_User;
} }
@ -1497,7 +1501,6 @@ void EAGLE_PLUGIN::packageRectangle( MODULE* aModule, wxXmlNode* aTree ) const
dwg->SetStart0( start ); dwg->SetStart0( start );
dwg->SetEnd0( end ); dwg->SetEnd0( end );
} }
@ -1508,7 +1511,9 @@ void EAGLE_PLUGIN::packagePolygon( MODULE* aModule, wxXmlNode* aTree ) const
if( IsCopperLayer( layer ) ) // skip copper "package.circle"s if( IsCopperLayer( layer ) ) // skip copper "package.circle"s
{ {
wxLogMessage( wxString::Format( "Unsupported polygon on copper layer in package %s \n Moving to drawings layer.", aModule->GetFPID().GetLibItemName().c_str() ) ); wxLogMessage( wxString::Format(
"Unsupported polygon on copper layer in package %s\nMoving to drawings layer.",
aModule->GetFPID().GetLibItemName().c_str() ) );
layer = Dwgs_User; layer = Dwgs_User;
} }
@ -1541,11 +1546,9 @@ void EAGLE_PLUGIN::packagePolygon( MODULE* aModule, wxXmlNode* aTree ) const
} }
dwg->SetPolyPoints( pts ); dwg->SetPolyPoints( pts );
dwg->SetStart0( *pts.begin() ); dwg->SetStart0( *pts.begin() );
dwg->SetEnd0( pts.back() ); dwg->SetEnd0( pts.back() );
dwg->SetDrawCoord(); dwg->SetDrawCoord();
} }
@ -1556,7 +1559,9 @@ void EAGLE_PLUGIN::packageCircle( MODULE* aModule, wxXmlNode* aTree ) const
if( IsCopperLayer( layer ) ) // skip copper "package.circle"s if( IsCopperLayer( layer ) ) // skip copper "package.circle"s
{ {
wxLogMessage( wxString::Format( "Unsupported circle on copper layer in package %s \n Moving to drawings layer.", aModule->GetFPID().GetLibItemName().c_str() ) ); wxLogMessage( wxString::Format(
"Unsupported circle on copper layer in package%s\nMoving to drawings layer.",
aModule->GetFPID().GetLibItemName().c_str() ) );
layer = Dwgs_User; layer = Dwgs_User;
} }
@ -1579,12 +1584,9 @@ void EAGLE_PLUGIN::packageCircle( MODULE* aModule, wxXmlNode* aTree ) const
gr->SetLayer( layer ); gr->SetLayer( layer );
gr->SetTimeStamp( EagleTimeStamp( aTree ) ); gr->SetTimeStamp( EagleTimeStamp( aTree ) );
gr->SetStart0( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) ); gr->SetStart0( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) );
gr->SetEnd0( wxPoint( kicad_x( e.x + e.radius ), kicad_y( e.y ) ) ); gr->SetEnd0( wxPoint( kicad_x( e.x + e.radius ), kicad_y( e.y ) ) );
gr->SetDrawCoord(); gr->SetDrawCoord();
} }