From 4055c435a5ad3700750576e3408fa4a7027f59ae Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 13 Mar 2018 14:34:53 +0100 Subject: [PATCH] Eagle PCB import: unified code for handling pad properties --- common/eagle_parser.cpp | 27 ++++++++++++++------------- include/eagle_parser.h | 29 +++++++++++++++-------------- pcbnew/eagle_plugin.cpp | 38 ++++++++++++++++++-------------------- pcbnew/eagle_plugin.h | 8 ++++++-- 4 files changed, 53 insertions(+), 49 deletions(-) diff --git a/common/eagle_parser.cpp b/common/eagle_parser.cpp index c583ca3b33..509e778036 100644 --- a/common/eagle_parser.cpp +++ b/common/eagle_parser.cpp @@ -621,7 +621,20 @@ wxSize ETEXT::ConvertSize() const } +EPAD_COMMON::EPAD_COMMON( wxXmlNode* aPad ) +{ + // #REQUIRED says DTD, throw exception if not found + name = parseRequiredAttribute( aPad, "name" ); + x = parseRequiredAttribute( aPad, "x" ); + y = parseRequiredAttribute( aPad, "y" ); + rot = parseOptionalAttribute( aPad, "rot" ); + stop = parseOptionalAttribute( aPad, "stop" ); + thermals = parseOptionalAttribute( aPad, "thermals" ); +} + + EPAD::EPAD( wxXmlNode* aPad ) + : EPAD_COMMON( aPad ) { /* @@ -640,9 +653,6 @@ EPAD::EPAD( wxXmlNode* aPad ) */ // #REQUIRED says DTD, throw exception if not found - name = parseRequiredAttribute( aPad, "name" ); - x = parseRequiredAttribute( aPad, "x" ); - y = parseRequiredAttribute( aPad, "y" ); drill = parseRequiredAttribute( aPad, "drill" ); // Optional attributes @@ -662,14 +672,12 @@ EPAD::EPAD( wxXmlNode* aPad ) else if( s == "offset" ) shape = EPAD::OFFSET; - rot = parseOptionalAttribute( aPad, "rot" ); - stop = parseOptionalAttribute( aPad, "stop" ); - thermals = parseOptionalAttribute( aPad, "thermals" ); first = parseOptionalAttribute( aPad, "first" ); } ESMD::ESMD( wxXmlNode* aSMD ) + : EPAD_COMMON( aSMD ) { /* ( aSMD, "name" ); - x = parseRequiredAttribute( aSMD, "x" ); - y = parseRequiredAttribute( aSMD, "y" ); dx = parseRequiredAttribute( aSMD, "dx" ); dy = parseRequiredAttribute( aSMD, "dy" ); layer = parseRequiredAttribute( aSMD, "layer" ); roundness = parseOptionalAttribute( aSMD, "roundness" ); - rot = parseOptionalAttribute( aSMD, "rot" ); - thermals = parseOptionalAttribute( aSMD, "thermals" ); - stop = parseOptionalAttribute( aSMD, "stop" ); - thermals = parseOptionalAttribute( aSMD, "thermals" ); cream = parseOptionalAttribute( aSMD, "cream" ); } diff --git a/include/eagle_parser.h b/include/eagle_parser.h index f808a2f5af..853a501d2e 100644 --- a/include/eagle_parser.h +++ b/include/eagle_parser.h @@ -676,12 +676,22 @@ struct ETEXT }; -/// Eagle thru hol pad -struct EPAD +/// Structure holding common properties for through-hole and SMD pads +struct EPAD_COMMON { wxString name; - ECOORD x; - ECOORD y; + ECOORD x, y; + opt_erot rot; + opt_bool stop; + opt_bool thermals; + + EPAD_COMMON( wxXmlNode* aPad ); +}; + + +/// Eagle thru hole pad +struct EPAD : public EPAD_COMMON +{ ECOORD drill; opt_ecoord diameter; @@ -694,9 +704,6 @@ struct EPAD OFFSET, }; opt_int shape; - opt_erot rot; - opt_bool stop; - opt_bool thermals; opt_bool first; EPAD( wxXmlNode* aPad ); @@ -704,18 +711,12 @@ struct EPAD /// Eagle SMD pad -struct ESMD +struct ESMD : public EPAD_COMMON { - wxString name; - ECOORD x; - ECOORD y; ECOORD dx; ECOORD dy; int layer; opt_int roundness; - opt_erot rot; - opt_bool stop; - opt_bool thermals; opt_bool cream; ESMD( wxXmlNode* aSMD ); diff --git a/pcbnew/eagle_plugin.cpp b/pcbnew/eagle_plugin.cpp index ff1d3b9b87..918065c536 100644 --- a/pcbnew/eagle_plugin.cpp +++ b/pcbnew/eagle_plugin.cpp @@ -1283,18 +1283,8 @@ void EAGLE_PLUGIN::packagePad( MODULE* aModule, wxXmlNode* aTree ) const D_PAD* pad = new D_PAD( aModule ); aModule->PadsList().PushBack( pad ); + transferPad( e, pad ); - pad->SetName( FROM_UTF8( e.name.c_str() ) ); - - // pad's "Position" is not relative to the module's, - // whereas Pos0 is relative to the module's but is the unrotated coordinate. - - wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) ); - pad->SetPos0( padpos ); - - RotatePoint( &padpos, aModule->GetOrientation() ); - - pad->SetPosition( padpos + aModule->GetPosition() ); pad->SetDrillSize( wxSize( e.drill.ToPcbUnits(), e.drill.ToPcbUnits() ) ); pad->SetLayerSet( LSET::AllCuMask().set( B_Mask ).set( F_Mask ) ); @@ -1639,19 +1629,11 @@ void EAGLE_PLUGIN::packageSMD( MODULE* aModule, wxXmlNode* aTree ) const D_PAD* pad = new D_PAD( aModule ); aModule->PadsList().PushBack( pad ); + transferPad( e, pad ); - pad->SetName( FROM_UTF8( e.name.c_str() ) ); pad->SetShape( PAD_SHAPE_RECT ); pad->SetAttribute( PAD_ATTRIB_SMD ); - // pad's "Position" is not relative to the module's, - // whereas Pos0 is relative to the module's but is the unrotated coordinate. - - wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) ); - pad->SetPos0( padpos ); - - RotatePoint( &padpos, aModule->GetOrientation() ); - pad->SetPosition( padpos + aModule->GetPosition() ); pad->SetSize( wxSize( e.dx.ToPcbUnits(), e.dy.ToPcbUnits() ) ); pad->SetLayer( layer ); @@ -1677,6 +1659,22 @@ void EAGLE_PLUGIN::packageSMD( MODULE* aModule, wxXmlNode* aTree ) const } // don't know what stop, thermals, and cream should look like now. + + + +void EAGLE_PLUGIN::transferPad( const EPAD_COMMON& aEaglePad, D_PAD* aPad ) const +{ + aPad->SetName( FROM_UTF8( aEaglePad.name.c_str() ) ); + + // pad's "Position" is not relative to the module's, + // whereas Pos0 is relative to the module's but is the unrotated coordinate. + wxPoint padPos( kicad_x( aEaglePad.x ), kicad_y( aEaglePad.y ) ); + aPad->SetPos0( padPos ); + + MODULE* module = aPad->GetParent(); + wxCHECK( module, /* void */ ); + RotatePoint( &padPos, module->GetOrientation() ); + aPad->SetPosition( padPos + module->GetPosition() ); } diff --git a/pcbnew/eagle_plugin.h b/pcbnew/eagle_plugin.h index d0c5d164bf..6c94ae4247 100644 --- a/pcbnew/eagle_plugin.h +++ b/pcbnew/eagle_plugin.h @@ -32,6 +32,7 @@ #include #include +class D_PAD; typedef std::map MODULE_MAP; typedef std::map NET_MAP; @@ -166,8 +167,8 @@ private: void clear_cu_map(); /// Convert an Eagle distance to a KiCad distance. - int kicad_y( const ECOORD& y ) const { return -y.ToPcbUnits(); } - int kicad_x( const ECOORD& x ) const { return x.ToPcbUnits(); } + int kicad_y( const ECOORD& y ) const { return -y.ToPcbUnits(); } + int kicad_x( const ECOORD& x ) const { return x.ToPcbUnits(); } /// create a font size (fontz) from an eagle font size scalar wxSize kicad_fontz( const ECOORD& d ) const; @@ -238,6 +239,9 @@ private: void packageHole( MODULE* aModule, wxXmlNode* aTree ) const; void packageSMD( MODULE* aModule, wxXmlNode* aTree ) const; + ///> Handles common pad properties + void transferPad( const EPAD_COMMON& aEaglePad, D_PAD* aPad ) const; + ///> Deletes the footprint templates list void deleteTemplates(); };