From 22c85e78ffd82127da3cc16604cb901016d26b4e Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Wed, 13 Mar 2013 11:17:16 -0500 Subject: [PATCH] EAGLE_PLUGIN cu layer map fix --- pcbnew/eagle_plugin.cpp | 32 ++++++++++++++++++++++++++++---- pcbnew/eagle_plugin.h | 4 +++- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/pcbnew/eagle_plugin.cpp b/pcbnew/eagle_plugin.cpp index 8cd93d8be3..214bbb7c7d 100644 --- a/pcbnew/eagle_plugin.cpp +++ b/pcbnew/eagle_plugin.cpp @@ -1158,6 +1158,10 @@ void EAGLE_PLUGIN::init( PROPERTIES* aProperties ) { m_hole_count = 0; + // all cu layers are invalid until we see one in the section while board loading. + for( unsigned i = 0; i < DIM(m_cu_map); ++i ) + m_cu_map[i] = -1; + m_xpath->clear(); m_pads_to_nets.clear(); @@ -1245,6 +1249,27 @@ void EAGLE_PLUGIN::loadLayerDefs( CPTREE& aLayers ) } } + // establish cu layer map: + int ki_layer_count = 0; + for( EITER it = cu.begin(); it != cu.end(); ++it, ++ki_layer_count ) + { + if( ki_layer_count == 0 ) + m_cu_map[it->number] = LAYER_N_FRONT; + else if( ki_layer_count == int( cu.size()-1 ) ) + m_cu_map[it->number] = LAYER_N_BACK; + else + // some eagle boards do not have contiguous layer number sequences. + m_cu_map[it->number] = cu.size() - 1 - ki_layer_count; + } + +#if 0 && defined(DEBUG) + printf( "m_cu_map:\n" ); + for( unsigned i=0; iSetCopperLayerCount( cu.size() ); for( EITER it = cu.begin(); it != cu.end(); ++it ) @@ -2438,7 +2463,7 @@ void EAGLE_PLUGIN::loadSignals( CPTREE& aSignals ) } -int EAGLE_PLUGIN::kicad_layer( int aEagleLayer ) +int EAGLE_PLUGIN::kicad_layer( int aEagleLayer ) const { /* will assume this is a valid mapping for all eagle boards until I get paid more: @@ -2507,13 +2532,12 @@ int EAGLE_PLUGIN::kicad_layer( int aEagleLayer ) */ - int kiLayer; // eagle copper layer: - if( aEagleLayer >= 1 && aEagleLayer <= 16 ) + if( aEagleLayer >= 1 && aEagleLayer < int( DIM( m_cu_map ) ) ) { - kiLayer = LAYER_N_FRONT - ( aEagleLayer - 1 ); + return m_cu_map[aEagleLayer]; } else diff --git a/pcbnew/eagle_plugin.h b/pcbnew/eagle_plugin.h index e28ad5db07..8e6ccd226c 100644 --- a/pcbnew/eagle_plugin.h +++ b/pcbnew/eagle_plugin.h @@ -116,6 +116,8 @@ public: private: + int m_cu_map[17]; ///< map eagle to kicad, cu layers only. + ERULES* m_rules; ///< Eagle design rules. XPATH* m_xpath; ///< keeps track of what we are working on within ///< XML document during a Load(). @@ -149,7 +151,7 @@ private: wxSize kicad_fontz( double d ) const; /// Convert an Eagle layer to a KiCad layer. - static int kicad_layer( int aLayer ); + int kicad_layer( int aLayer ) const; /// Convert a KiCad distance to an Eagle distance. double eagle( BIU d ) const { return mm_per_biu * d; }