From ee8012a5cc7c1134a782e021022851b35e240033 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 17 Oct 2017 10:19:43 +0200 Subject: [PATCH] Eagle import plugin: Code clean-up and formatting --- common/eagle_parser.cpp | 5 ++-- eeschema/sch_eagle_plugin.cpp | 51 +++++++++-------------------------- include/eagle_parser.h | 10 +++---- pcbnew/eagle_plugin.cpp | 30 +++++++++++---------- 4 files changed, 36 insertions(+), 60 deletions(-) diff --git a/common/eagle_parser.cpp b/common/eagle_parser.cpp index c4a57ed19d..6739112118 100644 --- a/common/eagle_parser.cpp +++ b/common/eagle_parser.cpp @@ -178,7 +178,7 @@ ECOORD Convert( const wxString& aCoord ) * @return T - the attributed parsed as the specified type. */ template -T parseRequiredAttribute( wxXmlNode* aNode, string aAttribute ) +T parseRequiredAttribute( wxXmlNode* aNode, const string& aAttribute ) { wxString value; @@ -197,7 +197,7 @@ T parseRequiredAttribute( wxXmlNode* aNode, string aAttribute ) * found. */ template -OPTIONAL_XML_ATTRIBUTE parseOptionalAttribute( wxXmlNode* aNode, string aAttribute ) +OPTIONAL_XML_ATTRIBUTE parseOptionalAttribute( wxXmlNode* aNode, const string& aAttribute ) { return OPTIONAL_XML_ATTRIBUTE( aNode->GetAttribute( aAttribute ) ); } @@ -859,7 +859,6 @@ EPART::EPART( wxXmlNode* aPart ) device = parseRequiredAttribute( aPart, "device" ); technology = parseOptionalAttribute( aPart, "technology" ); value = parseOptionalAttribute( aPart, "value" ); - } diff --git a/eeschema/sch_eagle_plugin.cpp b/eeschema/sch_eagle_plugin.cpp index 90607234ff..f25294fd90 100644 --- a/eeschema/sch_eagle_plugin.cpp +++ b/eeschema/sch_eagle_plugin.cpp @@ -658,10 +658,10 @@ void SCH_EAGLE_PLUGIN::loadSheet( wxXmlNode* aSheetNode, int aSheetIndex ) PAGE_INFO pageInfo = m_currentSheet->GetScreen()->GetPageSettings(); // Increase if necessary - if( pageSizeIU.x1 ) + if( m_netCounts[netName.ToStdString()] > 1 ) { std::unique_ptr glabel( new SCH_GLOBALLABEL ); 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. - if( m_netCounts[aNetName.ToStdString()]>1 ) + if( m_netCounts[aNetName.ToStdString()] > 1 ) { std::unique_ptr glabel( new SCH_GLOBALLABEL ); glabel->SetPosition( elabelpos ); @@ -902,7 +902,7 @@ SCH_TEXT* SCH_EAGLE_PLUGIN::loadLabel( wxXmlNode* aLabelNode, std::unique_ptr label( new SCH_LABEL ); label->SetPosition( elabelpos ); 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 ); @@ -998,8 +998,6 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode ) { auto einstance = EINSTANCE( aInstanceNode ); - bool smashed = false; - SCH_SCREEN* screen = m_currentSheet->GetScreen(); // 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 gatename = epart->deviceset + epart->device + einstance.gate; - wxString sntemp = wxString( epart->deviceset + epart->device ); + wxString sntemp = wxString( epart->deviceset + epart->device ); sntemp.Replace( "*", "" ); std::string symbolname = sntemp.ToStdString(); @@ -1086,20 +1084,8 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode ) } // Set the visibility of fields. - if( part->GetField( REFERENCE )->IsVisible() ) - component->GetField( REFERENCE )->SetVisible( true ); - 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(); - } + component->GetField( REFERENCE )->SetVisible( part->GetField( REFERENCE )->IsVisible() ); + component->GetField( VALUE )->SetVisible( part->GetField( VALUE )->IsVisible() ); bool valueAttributeFound = false; bool nameAttributeFound = false; @@ -1108,7 +1094,6 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode ) wxXmlNode* attributeNode = aInstanceNode->GetChildren(); // Parse attributes for the instance - // while( attributeNode ) { if( attributeNode->GetName() == "attribute" ) @@ -1136,20 +1121,15 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode ) bool mirror = attr.rot ? attr.rot->mirror : false; if( einstance.rot && einstance.rot->mirror ) - { mirror = !mirror; - } - bool spin = attr.rot ? attr.rot->spin : false; if( attr.display == EATTR::Off ) - { field->SetVisible( false ); - } int rotation = einstance.rot ? einstance.rot->degrees : 0; - int reldegrees = ( absdegrees - rotation + 360.0); + int reldegrees = ( absdegrees - rotation + 360.0 ); reldegrees %= 360; eagleToKicadAlignment( (EDA_TEXT*) field, align, reldegrees, mirror, spin, @@ -1160,7 +1140,7 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode ) attributeNode = attributeNode->GetNext(); } - if( smashed ) + if( einstance.smashed && einstance.smashed.Get() ) { if( !valueAttributeFound ) component->GetField( VALUE )->SetVisible( false ); @@ -1226,14 +1206,10 @@ EAGLE_LIBRARY* SCH_EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLibraryNode, LIB_FIELD* reference = kpart->GetField( REFERENCE ); - if( prefix.length() ==0 ) - { + if( prefix.length() == 0 ) reference->SetVisible( false ); - } else - { reference->SetText( prefix ); - } int gateindex = 1; bool ispower = false; @@ -1348,7 +1324,7 @@ bool SCH_EAGLE_PLUGIN::loadSymbol( wxXmlNode* aSymbolNode, { 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->SetUnit( aGateNumber ); @@ -1365,10 +1341,9 @@ bool SCH_EAGLE_PLUGIN::loadSymbol( wxXmlNode* aSymbolNode, wxString padname( pads[i] ); apin->SetNumber( padname ); - aPart->AddDrawItem( apin); + aPart->AddDrawItem( apin ); } break; - } } } diff --git a/include/eagle_parser.h b/include/eagle_parser.h index fa68c9cbe9..cb8d5beb8e 100644 --- a/include/eagle_parser.h +++ b/include/eagle_parser.h @@ -446,10 +446,10 @@ struct ECOORD /// Eagle net struct ENET { - int netcode; - std::string netname; + int netcode; + string netname; - ENET( int aNetCode, const std::string& aNetName ) : + ENET( int aNetCode, const string& aNetName ) : netcode( aNetCode ), netname( aNetName ) {} @@ -991,7 +991,7 @@ struct EDEVICE package %String; #IMPLIED > */ - std::string name; + string name; opt_string package; std::vector connects; @@ -1011,7 +1011,7 @@ struct EDEVICE_SET > */ - std::string name; + string name; opt_string prefix; opt_bool uservalue; //std::vector devices; diff --git a/pcbnew/eagle_plugin.cpp b/pcbnew/eagle_plugin.cpp index cb91b9a3fe..448d811c69 100644 --- a/pcbnew/eagle_plugin.cpp +++ b/pcbnew/eagle_plugin.cpp @@ -1167,9 +1167,9 @@ void EAGLE_PLUGIN::orientModuleText( MODULE* m, const EELEMENT& e, MODULE* EAGLE_PLUGIN::makeModule( wxXmlNode* aPackage, const string& aPkgName ) const { - std::unique_ptr m( new MODULE( m_board ) ); + std::unique_ptr m( new MODULE( m_board ) ); - m->SetFPID( LIB_ID( UTF8(aPkgName) ) ); + m->SetFPID( LIB_ID( UTF8( aPkgName ) ) ); // Get the first package item and iterate 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 // with flat ends. EDGE_MODULE* dwg; + if( !w.curve ) { dwg = new EDGE_MODULE( aModule, S_SEGMENT ); @@ -1252,10 +1253,9 @@ void EAGLE_PLUGIN::packageWire( MODULE* aModule, wxXmlNode* aTree ) const dwg->SetLayer( layer ); dwg->SetWidth( width ); - 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 { - 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; } @@ -1471,7 +1473,9 @@ void EAGLE_PLUGIN::packageRectangle( MODULE* aModule, wxXmlNode* aTree ) const 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; } @@ -1497,7 +1501,6 @@ void EAGLE_PLUGIN::packageRectangle( MODULE* aModule, wxXmlNode* aTree ) const dwg->SetStart0( start ); dwg->SetEnd0( end ); - } @@ -1508,7 +1511,9 @@ void EAGLE_PLUGIN::packagePolygon( MODULE* aModule, wxXmlNode* aTree ) const 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; } @@ -1541,11 +1546,9 @@ void EAGLE_PLUGIN::packagePolygon( MODULE* aModule, wxXmlNode* aTree ) const } dwg->SetPolyPoints( pts ); - dwg->SetStart0( *pts.begin() ); dwg->SetEnd0( pts.back() ); dwg->SetDrawCoord(); - } @@ -1556,7 +1559,9 @@ void EAGLE_PLUGIN::packageCircle( MODULE* aModule, wxXmlNode* aTree ) const 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; } @@ -1579,12 +1584,9 @@ void EAGLE_PLUGIN::packageCircle( MODULE* aModule, wxXmlNode* aTree ) const gr->SetLayer( layer ); gr->SetTimeStamp( EagleTimeStamp( aTree ) ); - 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->SetDrawCoord(); - - }