From 3f577bd16c36f0f28236d00dfc76fe0f23ad735e Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 3 Jun 2014 16:08:23 +0200 Subject: [PATCH] Improved ratsnest updating in GAL. --- pcbnew/class_board_connected_item.cpp | 21 ++++++++++++--- pcbnew/netlist.cpp | 9 +++++-- pcbnew/ratsnest_data.cpp | 39 ++++++++++++++++++++------- 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/pcbnew/class_board_connected_item.cpp b/pcbnew/class_board_connected_item.cpp index d7c54e7925..de349b26fd 100644 --- a/pcbnew/class_board_connected_item.cpp +++ b/pcbnew/class_board_connected_item.cpp @@ -34,6 +34,8 @@ #include #include +#include + BOARD_CONNECTED_ITEM::BOARD_CONNECTED_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) : BOARD_ITEM( aParent, idtype ), m_netinfo( &NETINFO_LIST::ORPHANED ), m_Subnet( 0 ), m_ZoneSubnet( 0 ) @@ -53,18 +55,29 @@ BOARD_CONNECTED_ITEM::BOARD_CONNECTED_ITEM( const BOARD_CONNECTED_ITEM& aItem ) void BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode ) { BOARD* board = GetBoard(); + NETINFO_ITEM* oldNetInfo = m_netinfo; + NETINFO_ITEM* newNetInfo; + if( board ) { - m_netinfo = board->FindNet( aNetCode ); + newNetInfo = board->FindNet( aNetCode ); // The requested net does not exist, mark it as unconnected - if( m_netinfo == NULL ) - m_netinfo = board->FindNet( NETINFO_LIST::UNCONNECTED ); + if( newNetInfo == NULL ) + newNetInfo = board->FindNet( NETINFO_LIST::UNCONNECTED ); } else { // There is no board that contains list of nets, the item is orphaned - m_netinfo = &NETINFO_LIST::ORPHANED; + newNetInfo = &NETINFO_LIST::ORPHANED; + } + + // Update ratsnest, if necessary + if( oldNetInfo != newNetInfo && board ) + { + board->GetRatsnest()->Remove( this ); + m_netinfo = newNetInfo; + board->GetRatsnest()->Add( this ); } } diff --git a/pcbnew/netlist.cpp b/pcbnew/netlist.cpp index bb840c658f..0d5725cf63 100644 --- a/pcbnew/netlist.cpp +++ b/pcbnew/netlist.cpp @@ -44,6 +44,7 @@ #include #include +#include #include #include @@ -121,7 +122,7 @@ void PCB_EDIT_FRAME::ReadPcbNetlist( const wxString& aNetlistFileName, for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() ) { module->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, view, _1 ) ); - GetGalCanvas()->GetView()->Add( module ); + view->Add( module ); } if( aDeleteUnconnectedTracks && GetBoard()->m_Track ) @@ -131,7 +132,11 @@ void PCB_EDIT_FRAME::ReadPcbNetlist( const wxString& aNetlistFileName, } // Rebuild the board connectivity: - Compile_Ratsnest( NULL, true ); + if( IsGalCanvasActive() ) + GetBoard()->GetRatsnest()->Recalculate(); + else + Compile_Ratsnest( NULL, true ); + SetMsgPanel( GetBoard() ); m_canvas->Refresh(); } diff --git a/pcbnew/ratsnest_data.cpp b/pcbnew/ratsnest_data.cpp index f6638a3835..9271f00f42 100644 --- a/pcbnew/ratsnest_data.cpp +++ b/pcbnew/ratsnest_data.cpp @@ -841,8 +841,7 @@ void RN_DATA::Add( const BOARD_ITEM* aItem ) if( net < 1 ) // do not process unconnected items return; - // Autoresize - if( net >= (int) m_nets.size() ) + if( net >= (int) m_nets.size() ) // Autoresize m_nets.resize( net + 1 ); } else if( aItem->Type() == PCB_MODULE_T ) @@ -851,11 +850,11 @@ void RN_DATA::Add( const BOARD_ITEM* aItem ) for( const D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() ) { net = pad->GetNetCode(); + if( net < 1 ) // do not process unconnected items continue; - // Autoresize - if( net >= (int) m_nets.size() ) + if( net >= (int) m_nets.size() ) // Autoresize m_nets.resize( net + 1 ); m_nets[net].AddItem( pad ); @@ -897,8 +896,19 @@ void RN_DATA::Remove( const BOARD_ITEM* aItem ) if( aItem->IsConnected() ) { net = static_cast( aItem )->GetNetCode(); + if( net < 1 ) // do not process unconnected items return; + +#ifdef NDEBUG + if( net >= (int) m_nets.size() ) // Autoresize + { + m_nets.resize( net + 1 ); + + return; // if it was resized, then surely the item had not been added before + } +#endif + assert( net < (int) m_nets.size() ); } else if( aItem->Type() == PCB_MODULE_T ) { @@ -906,9 +916,20 @@ void RN_DATA::Remove( const BOARD_ITEM* aItem ) for( const D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() ) { net = pad->GetNetCode(); + if( net < 1 ) // do not process unconnected items continue; +#ifdef NDEBUG + if( net >= (int) m_nets.size() ) // Autoresize + { + m_nets.resize( net + 1 ); + + return; // if it was resized, then surely the item had not been added before + } +#endif + assert( net < (int) m_nets.size() ); + m_nets[net].RemoveItem( pad ); } @@ -993,14 +1014,14 @@ void RN_DATA::ProcessBoard() void RN_DATA::Recalculate( int aNet ) { - if( m_board->GetNetCount() > m_nets.size() ) - m_nets.resize( m_board->GetNetCount() ); + unsigned int netCount = m_board->GetNetCount(); + + if( netCount > m_nets.size() ) + m_nets.resize( netCount ); if( aNet < 0 ) // Recompute everything { - unsigned int i, netCount; - netCount = m_board->GetNetCount(); - + unsigned int i; #ifdef USE_OPENMP #pragma omp parallel shared(netCount) private(i) {