diff --git a/pcbnew/legacy_plugin.cpp b/pcbnew/legacy_plugin.cpp index c369ebf65c..42ef2aa80b 100644 --- a/pcbnew/legacy_plugin.cpp +++ b/pcbnew/legacy_plugin.cpp @@ -1305,13 +1305,13 @@ void LEGACY_PLUGIN::loadPAD( MODULE* aModule ) int netcode = intParse( line + SZ( "Ne" ), &data ); // Store the new code mapping - pad->SetNetCode( m_netCodes[netcode] ); + pad->SetNetCode( getNetCode( netcode ) ); // read Netname ReadDelimitedText( buf, data, sizeof(buf) ); #ifndef NDEBUG if( m_board ) - assert( m_board->FindNet( m_netCodes[netcode] )->GetNetname() == + assert( m_board->FindNet( getNetCode( netcode ) )->GetNetname() == FROM_UTF8( StrPurge( buf ) ) ); #endif /* NDEBUG */ } @@ -2102,7 +2102,7 @@ void LEGACY_PLUGIN::loadTrackList( int aStructType ) via->SetLayerPair( LAYER_N_FRONT, LAYER_N_BACK ); } - newTrack->SetNetCode( m_netCodes[net_code] ); + newTrack->SetNetCode( getNetCode( net_code ) ); newTrack->SetState( flags, true ); m_board->Add( newTrack ); @@ -2250,7 +2250,7 @@ void LEGACY_PLUGIN::loadZONE_CONTAINER() // Init the net code only, not the netname, to be sure // the zone net name is the name read in file. // (When mismatch, the user will be prompted in DRC, to fix the actual name) - zc->BOARD_CONNECTED_ITEM::SetNetCode( m_netCodes[netcode] ); + zc->BOARD_CONNECTED_ITEM::SetNetCode( getNetCode( netcode ) ); } else if( TESTLINE( "ZLayer" ) ) // layer found diff --git a/pcbnew/legacy_plugin.h b/pcbnew/legacy_plugin.h index 96747bf84d..37f0ef2f45 100644 --- a/pcbnew/legacy_plugin.h +++ b/pcbnew/legacy_plugin.h @@ -139,6 +139,16 @@ protected: double diskToBiu; ///< convert from disk engineering units to BIUs ///< with this scale factor + ///> Converts net code using the mapping table if available, + ///> otherwise returns unchanged net code + inline int getNetCode( int aNetCode ) + { + if( aNetCode < (int) m_netCodes.size() ) + return m_netCodes[aNetCode]; + + return aNetCode; + } + /** * Function biuParse * parses an ASCII decimal floating point value and scales it into a BIU diff --git a/pcbnew/pcb_parser.cpp b/pcbnew/pcb_parser.cpp index 8c883099ad..4bf36597af 100644 --- a/pcbnew/pcb_parser.cpp +++ b/pcbnew/pcb_parser.cpp @@ -2201,7 +2201,7 @@ D_PAD* PCB_PARSER::parseD_PAD( MODULE* aParent ) throw( IO_ERROR, PARSE_ERROR ) break; case T_net: - pad->SetNetCode( m_netCodes[parseInt( "net number" )] ); + pad->SetNetCode( getNetCode( parseInt( "net number" ) ) ); NeedSYMBOLorNUMBER(); assert( FromUTF8() == m_board->FindNet( pad->GetNetCode() )->GetNetname() ); NeedRIGHT(); @@ -2299,7 +2299,7 @@ TRACK* PCB_PARSER::parseTRACK() throw( IO_ERROR, PARSE_ERROR ) break; case T_net: - track->SetNetCode( m_netCodes[parseInt( "net number" )] ); + track->SetNetCode( getNetCode( parseInt( "net number" ) ) ); break; case T_tstamp: @@ -2377,7 +2377,7 @@ VIA* PCB_PARSER::parseVIA() throw( IO_ERROR, PARSE_ERROR ) break; case T_net: - via->SetNetCode( m_netCodes[parseInt( "net number" )] ); + via->SetNetCode( getNetCode( parseInt( "net number" ) ) ); NeedRIGHT(); break; @@ -2429,7 +2429,7 @@ ZONE_CONTAINER* PCB_PARSER::parseZONE_CONTAINER() throw( IO_ERROR, PARSE_ERROR ) // Init the net code only, not the netname, to be sure // the zone net name is the name read in file. // (When mismatch, the user will be prompted in DRC, to fix the actual name) - zone->SetNetCode( m_netCodes[parseInt( "net number" )] ); + zone->SetNetCode( getNetCode( parseInt( "net number" ) ) ); NeedRIGHT(); break; diff --git a/pcbnew/pcb_parser.h b/pcbnew/pcb_parser.h index a07beb3bec..2169bf9ed5 100644 --- a/pcbnew/pcb_parser.h +++ b/pcbnew/pcb_parser.h @@ -69,6 +69,16 @@ class PCB_PARSER : public PCB_LEXER LAYER_MSK_MAP m_layerMasks; ///< map layer names to their masks std::vector m_netCodes; ///< net codes mapping for boards being loaded + ///> Converts net code using the mapping table if available, + ///> otherwise returns unchanged net code + inline int getNetCode( int aNetCode ) + { + if( aNetCode < (int) m_netCodes.size() ) + return m_netCodes[aNetCode]; + + return aNetCode; + } + /** * Function init * clears and re-establishes m_layerMap with the default layer names.