From e466bf50ae312137fbe945f74cd945170f7b21ce Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 18 Oct 2017 09:21:32 +0200 Subject: [PATCH] Eagle PCB import plugin: fix dimensions import --- common/eagle_parser.cpp | 8 +------- pcbnew/eagle_plugin.cpp | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/common/eagle_parser.cpp b/common/eagle_parser.cpp index 6739112118..ec58b16a82 100644 --- a/common/eagle_parser.cpp +++ b/common/eagle_parser.cpp @@ -524,13 +524,7 @@ EDIMENSION::EDIMENSION( wxXmlNode* aDimension ) x3 = parseRequiredAttribute( aDimension, "x3" ); y3 = parseRequiredAttribute( aDimension, "y3" ); layer = parseRequiredAttribute( aDimension, "layer" ); - - opt_string dimType = parseOptionalAttribute( aDimension, "dtype" ); - - if( !dimType ) - { - // default type is parallel - } + dimensionType = parseOptionalAttribute( aDimension, "dtype" ); } diff --git a/pcbnew/eagle_plugin.cpp b/pcbnew/eagle_plugin.cpp index 448d811c69..470e2af63e 100644 --- a/pcbnew/eagle_plugin.cpp +++ b/pcbnew/eagle_plugin.cpp @@ -694,6 +694,24 @@ void EAGLE_PLUGIN::loadPlain( wxXmlNode* aGraphics ) DIMENSION* dimension = new DIMENSION( m_board ); m_board->Add( dimension, ADD_APPEND ); + if( d.dimensionType ) + { + // Eagle dimension graphic arms may have different lengths, but they look + // incorrect in KiCad (the graphic is tilted). Make them even lenght in such case. + if( *d.dimensionType == "horizontal" ) + { + int newY = ( d.y1.ToPcbUnits() + d.y2.ToPcbUnits() ) / 2; + d.y1 = ECOORD( newY, ECOORD::UNIT::NM ); + d.y2 = ECOORD( newY, ECOORD::UNIT::NM ); + } + else if( *d.dimensionType == "vertical" ) + { + int newX = ( d.x1.ToPcbUnits() + d.x2.ToPcbUnits() ) / 2; + d.x1 = ECOORD( newX, ECOORD::UNIT::NM ); + d.x2 = ECOORD( newX, ECOORD::UNIT::NM ); + } + } + dimension->SetLayer( layer ); // The origin and end are assumed to always be in this order from eagle dimension->SetOrigin( wxPoint( kicad_x( d.x1 ), kicad_y( d.y1 ) ) ); @@ -714,7 +732,7 @@ void EAGLE_PLUGIN::loadPlain( wxXmlNode* aGraphics ) // Note the check is just if two axes are close enough to each other // Eagle appears to have some rounding errors if( abs( ( d.x1 - d.x2 ).ToPcbUnits() ) < 50000 ) // 50000 nm = 0.05 mm - dimension->SetHeight( kicad_x( d.x1 - d.x3 ) ); + dimension->SetHeight( kicad_x( d.x3 - d.x1 ) ); else dimension->SetHeight( kicad_y( d.y3 - d.y1 ) );