Commit 79631def authored by Maciej Suminski's avatar Maciej Suminski

Improved ratsnest updating in GAL.

parent 2af3e5f6
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
#include <class_board.h> #include <class_board.h>
#include <class_board_item.h> #include <class_board_item.h>
#include <ratsnest_data.h>
BOARD_CONNECTED_ITEM::BOARD_CONNECTED_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) : BOARD_CONNECTED_ITEM::BOARD_CONNECTED_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) :
BOARD_ITEM( aParent, idtype ), m_netinfo( &NETINFO_LIST::ORPHANED ), BOARD_ITEM( aParent, idtype ), m_netinfo( &NETINFO_LIST::ORPHANED ),
m_Subnet( 0 ), m_ZoneSubnet( 0 ) m_Subnet( 0 ), m_ZoneSubnet( 0 )
...@@ -53,18 +55,29 @@ BOARD_CONNECTED_ITEM::BOARD_CONNECTED_ITEM( const BOARD_CONNECTED_ITEM& aItem ) ...@@ -53,18 +55,29 @@ BOARD_CONNECTED_ITEM::BOARD_CONNECTED_ITEM( const BOARD_CONNECTED_ITEM& aItem )
void BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode ) void BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode )
{ {
BOARD* board = GetBoard(); BOARD* board = GetBoard();
NETINFO_ITEM* oldNetInfo = m_netinfo;
NETINFO_ITEM* newNetInfo;
if( board ) if( board )
{ {
m_netinfo = board->FindNet( aNetCode ); newNetInfo = board->FindNet( aNetCode );
// The requested net does not exist, mark it as unconnected // The requested net does not exist, mark it as unconnected
if( m_netinfo == NULL ) if( newNetInfo == NULL )
m_netinfo = board->FindNet( NETINFO_LIST::UNCONNECTED ); newNetInfo = board->FindNet( NETINFO_LIST::UNCONNECTED );
} }
else else
{ {
// There is no board that contains list of nets, the item is orphaned // 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 );
} }
} }
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include <class_board.h> #include <class_board.h>
#include <class_module.h> #include <class_module.h>
#include <ratsnest_data.h>
#include <pcbnew.h> #include <pcbnew.h>
#include <io_mgr.h> #include <io_mgr.h>
...@@ -121,7 +122,7 @@ void PCB_EDIT_FRAME::ReadPcbNetlist( const wxString& aNetlistFileName, ...@@ -121,7 +122,7 @@ void PCB_EDIT_FRAME::ReadPcbNetlist( const wxString& aNetlistFileName,
for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() ) for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() )
{ {
module->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, view, _1 ) ); module->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, view, _1 ) );
GetGalCanvas()->GetView()->Add( module ); view->Add( module );
} }
if( aDeleteUnconnectedTracks && GetBoard()->m_Track ) if( aDeleteUnconnectedTracks && GetBoard()->m_Track )
...@@ -131,7 +132,11 @@ void PCB_EDIT_FRAME::ReadPcbNetlist( const wxString& aNetlistFileName, ...@@ -131,7 +132,11 @@ void PCB_EDIT_FRAME::ReadPcbNetlist( const wxString& aNetlistFileName,
} }
// Rebuild the board connectivity: // Rebuild the board connectivity:
if( IsGalCanvasActive() )
GetBoard()->GetRatsnest()->Recalculate();
else
Compile_Ratsnest( NULL, true ); Compile_Ratsnest( NULL, true );
SetMsgPanel( GetBoard() ); SetMsgPanel( GetBoard() );
m_canvas->Refresh(); m_canvas->Refresh();
} }
......
...@@ -841,8 +841,7 @@ void RN_DATA::Add( const BOARD_ITEM* aItem ) ...@@ -841,8 +841,7 @@ void RN_DATA::Add( const BOARD_ITEM* aItem )
if( net < 1 ) // do not process unconnected items if( net < 1 ) // do not process unconnected items
return; return;
// Autoresize if( net >= (int) m_nets.size() ) // Autoresize
if( net >= (int) m_nets.size() )
m_nets.resize( net + 1 ); m_nets.resize( net + 1 );
} }
else if( aItem->Type() == PCB_MODULE_T ) else if( aItem->Type() == PCB_MODULE_T )
...@@ -851,11 +850,11 @@ void RN_DATA::Add( const BOARD_ITEM* aItem ) ...@@ -851,11 +850,11 @@ void RN_DATA::Add( const BOARD_ITEM* aItem )
for( const D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() ) for( const D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() )
{ {
net = pad->GetNetCode(); net = pad->GetNetCode();
if( net < 1 ) // do not process unconnected items if( net < 1 ) // do not process unconnected items
continue; continue;
// Autoresize if( net >= (int) m_nets.size() ) // Autoresize
if( net >= (int) m_nets.size() )
m_nets.resize( net + 1 ); m_nets.resize( net + 1 );
m_nets[net].AddItem( pad ); m_nets[net].AddItem( pad );
...@@ -897,8 +896,19 @@ void RN_DATA::Remove( const BOARD_ITEM* aItem ) ...@@ -897,8 +896,19 @@ void RN_DATA::Remove( const BOARD_ITEM* aItem )
if( aItem->IsConnected() ) if( aItem->IsConnected() )
{ {
net = static_cast<const BOARD_CONNECTED_ITEM*>( aItem )->GetNetCode(); net = static_cast<const BOARD_CONNECTED_ITEM*>( aItem )->GetNetCode();
if( net < 1 ) // do not process unconnected items if( net < 1 ) // do not process unconnected items
return; 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 ) else if( aItem->Type() == PCB_MODULE_T )
{ {
...@@ -906,9 +916,20 @@ void RN_DATA::Remove( const BOARD_ITEM* aItem ) ...@@ -906,9 +916,20 @@ void RN_DATA::Remove( const BOARD_ITEM* aItem )
for( const D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() ) for( const D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() )
{ {
net = pad->GetNetCode(); net = pad->GetNetCode();
if( net < 1 ) // do not process unconnected items if( net < 1 ) // do not process unconnected items
continue; 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 ); m_nets[net].RemoveItem( pad );
} }
...@@ -993,14 +1014,14 @@ void RN_DATA::ProcessBoard() ...@@ -993,14 +1014,14 @@ void RN_DATA::ProcessBoard()
void RN_DATA::Recalculate( int aNet ) void RN_DATA::Recalculate( int aNet )
{ {
if( m_board->GetNetCount() > m_nets.size() ) unsigned int netCount = m_board->GetNetCount();
m_nets.resize( m_board->GetNetCount() );
if( netCount > m_nets.size() )
m_nets.resize( netCount );
if( aNet < 0 ) // Recompute everything if( aNet < 0 ) // Recompute everything
{ {
unsigned int i, netCount; unsigned int i;
netCount = m_board->GetNetCount();
#ifdef USE_OPENMP #ifdef USE_OPENMP
#pragma omp parallel shared(netCount) private(i) #pragma omp parallel shared(netCount) private(i)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment