From bab2b6c4b6bdb87fbada7e92944ca7ee4fd9c923 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 19 Nov 2022 11:50:54 +0000 Subject: [PATCH] Don't assume a 1:1 map between Altium and Kicad nets. We've found at least one Altium board which has duplicate netcodes for the same net. Fixes https://gitlab.com/kicad/code/kicad/issues/12909 --- pcbnew/plugins/altium/altium_pcb.cpp | 14 ++++++++------ pcbnew/plugins/altium/altium_pcb.h | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pcbnew/plugins/altium/altium_pcb.cpp b/pcbnew/plugins/altium/altium_pcb.cpp index 8b2947afe3..af16bc466f 100644 --- a/pcbnew/plugins/altium/altium_pcb.cpp +++ b/pcbnew/plugins/altium/altium_pcb.cpp @@ -341,7 +341,6 @@ ALTIUM_PCB::ALTIUM_PCB( BOARD* aBoard, PROGRESS_REPORTER* aProgressReporter ) m_doneCount = 0; m_lastProgressCount = 0; m_totalCount = 0; - m_num_nets = 0; m_highest_pour_index = 0; } @@ -807,15 +806,15 @@ int ALTIUM_PCB::GetNetCode( uint16_t aId ) const { return NETINFO_LIST::UNCONNECTED; } - else if( m_num_nets < aId ) + else if( m_altiumToKicadNetcodes.size() < aId ) { THROW_IO_ERROR( wxString::Format( wxT( "Netcode with id %d does not exist. Only %d nets " "are known" ), - aId, m_num_nets ) ); + aId, m_altiumToKicadNetcodes.size() ) ); } else { - return aId + 1; + return m_altiumToKicadNetcodes[ aId ]; } } @@ -1695,13 +1694,16 @@ void ALTIUM_PCB::ParseNets6Data( const ALTIUM_COMPOUND_FILE& aAltiumPcbFile, ALTIUM_PARSER reader( aAltiumPcbFile, aEntry ); - wxASSERT( m_num_nets == 0 ); + wxASSERT( m_altiumToKicadNetcodes.empty() ); while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ ) { checkpoint(); ANET6 elem( reader ); - m_board->Add( new NETINFO_ITEM( m_board, elem.name, ++m_num_nets ), ADD_MODE::APPEND ); + NETINFO_ITEM* netInfo = new NETINFO_ITEM( m_board, elem.name, 0 ); + m_board->Add( netInfo, ADD_MODE::APPEND ); + + m_altiumToKicadNetcodes.push_back( netInfo->GetNetCode() ); } if( reader.GetRemainingBytes() != 0 ) diff --git a/pcbnew/plugins/altium/altium_pcb.h b/pcbnew/plugins/altium/altium_pcb.h index 65cb94c5e8..3cec9c0ae7 100644 --- a/pcbnew/plugins/altium/altium_pcb.h +++ b/pcbnew/plugins/altium/altium_pcb.h @@ -243,7 +243,7 @@ private: std::vector m_radialDimensions; std::map m_models; std::map m_unicodeStrings; - size_t m_num_nets; + std::vector m_altiumToKicadNetcodes; std::map m_layermap; // used to correctly map copper layers std::map> m_rules; std::map>