From 510fee13587862e66c0059ec53c2200cdbb08981 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Jan 2014 15:46:39 +0100 Subject: [PATCH] Another way of handling items for the ratsnest (clearer and now finally supports undo/redo of the PNS created tracks). --- pcbnew/board_undo_redo.cpp | 12 +++++----- pcbnew/class_board.cpp | 46 +++++++++----------------------------- pcbnew/pcb_parser.cpp | 4 ++-- pcbnew/pcbframe.cpp | 1 - pcbnew/ratsnest_data.cpp | 14 ++++++++---- 5 files changed, 28 insertions(+), 49 deletions(-) diff --git a/pcbnew/board_undo_redo.cpp b/pcbnew/board_undo_redo.cpp index 3112bc5e27..68d008bebb 100644 --- a/pcbnew/board_undo_redo.cpp +++ b/pcbnew/board_undo_redo.cpp @@ -548,8 +548,7 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed if( item->Type() == PCB_MODULE_T ) { MODULE* module = static_cast( item ); - module->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Remove ), - view ) ); + module->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Remove ), view ) ); } view->Remove( item ); @@ -563,8 +562,7 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed if( item->Type() == PCB_MODULE_T ) { MODULE* module = static_cast( item ); - module->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Add ), - view ) ); + module->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Add ), view ) ); } view->Add( item ); @@ -575,23 +573,27 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed case UR_MOVED: item->Move( aRedoCommand ? aList->m_TransformPoint : -aList->m_TransformPoint ); item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); + ratsnest->Update( item ); break; case UR_ROTATED: item->Rotate( aList->m_TransformPoint, aRedoCommand ? m_rotationAngle : -m_rotationAngle ); item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); + ratsnest->Update( item ); break; case UR_ROTATED_CLOCKWISE: item->Rotate( aList->m_TransformPoint, aRedoCommand ? -m_rotationAngle : m_rotationAngle ); item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); + ratsnest->Update( item ); break; case UR_FLIPPED: item->Flip( aList->m_TransformPoint ); item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS ); + ratsnest->Update( item ); break; default: @@ -603,8 +605,6 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed } break; } - - ratsnest->Update( item ); } if( not_found ) diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 896e44b8f6..da3bd81fa9 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -842,6 +842,8 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl ) } break; } + + m_ratsnest->Add( aBoardItem ); } @@ -867,56 +869,26 @@ BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem ) break; case PCB_ZONE_AREA_T: // this one uses a vector - { - ZONE_CONTAINER* zone = static_cast( aBoardItem ); - // find the item in the vector, then delete then erase it. - for( unsigned i = 0; i < m_ZoneDescriptorList.size(); ++i ) + for( unsigned i = 0; iGetNet() > 0 ) - m_ratsnest->GetNet( zone->GetNet() ).RemoveItem( zone ); - } - break; + break; case PCB_MODULE_T: - { - MODULE* module = static_cast( aBoardItem ); m_Modules.Remove( (MODULE*) aBoardItem ); - - for( D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() ) - { - if( pad->GetNet() > 0 ) - m_ratsnest->GetNet( pad->GetNet() ).RemoveItem( pad ); - } - } - break; + break; case PCB_TRACE_T: - { - TRACK* track = static_cast( aBoardItem ); - m_Track.Remove( track ); - - if( track->GetNet() > 0 ) - m_ratsnest->GetNet( track->GetNet() ).RemoveItem( track ); - } - break; - case PCB_VIA_T: - { - SEGVIA* via = static_cast( aBoardItem ); - m_Track.Remove( via ); - - if( via->GetNet() > 0 ) - m_ratsnest->GetNet( via->GetNet() ).RemoveItem( via ); - } - break; + m_Track.Remove( (TRACK*) aBoardItem ); + break; case PCB_ZONE_T: m_Zone.Remove( (SEGZONE*) aBoardItem ); @@ -935,6 +907,8 @@ BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem ) wxFAIL_MSG( wxT( "BOARD::Remove() needs more ::Type() support" ) ); } + m_ratsnest->Remove( aBoardItem ); + return aBoardItem; } diff --git a/pcbnew/pcb_parser.cpp b/pcbnew/pcb_parser.cpp index 41fb0037e5..1f06ac2ed1 100644 --- a/pcbnew/pcb_parser.cpp +++ b/pcbnew/pcb_parser.cpp @@ -428,11 +428,11 @@ BOARD* PCB_PARSER::parseBOARD() throw( IO_ERROR, PARSE_ERROR ) break; case T_segment: - m_board->m_Track.Append( parseTRACK() ); + m_board->Add( parseTRACK(), ADD_APPEND ); break; case T_via: - m_board->m_Track.Append( parseSEGVIA() ); + m_board->Add( parseSEGVIA(), ADD_APPEND ); break; case T_zone: diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 8823dcf4c3..72930927ca 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -612,7 +612,6 @@ void PCB_EDIT_FRAME::ViewReloadBoard( const BOARD* aBoard ) const // Add an entry for the ratsnest RN_DATA* ratsnest = aBoard->GetRatsnest(); - ratsnest->ProcessBoard(); ratsnest->Recalculate(); view->Add( new KIGFX::RATSNEST_VIEWITEM( ratsnest ) ); diff --git a/pcbnew/ratsnest_data.cpp b/pcbnew/ratsnest_data.cpp index ea9d8a7c57..99c84d05eb 100644 --- a/pcbnew/ratsnest_data.cpp +++ b/pcbnew/ratsnest_data.cpp @@ -782,6 +782,10 @@ void RN_DATA::Add( const BOARD_ITEM* aItem ) net = static_cast( aItem )->GetNet(); if( net < 1 ) // do not process unconnected items return; + + // Autoresize + if( net >= (int) m_nets.size() ) + m_nets.resize( net + 1 ); } else if( aItem->Type() == PCB_MODULE_T ) { @@ -789,10 +793,13 @@ void RN_DATA::Add( const BOARD_ITEM* aItem ) for( const D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() ) { net = pad->GetNet(); - if( net < 1 ) // do not process unconnected items continue; + // Autoresize + if( net >= (int) m_nets.size() ) + m_nets.resize( net + 1 ); + m_nets[net].AddItem( pad ); } @@ -841,7 +848,6 @@ void RN_DATA::Remove( const BOARD_ITEM* aItem ) for( const D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() ) { net = pad->GetNet(); - if( net < 1 ) // do not process unconnected items continue; @@ -916,8 +922,8 @@ void RN_DATA::Recalculate( int aNet ) { if( aNet < 0 ) // Recompute everything { - // Start with net number 1, as 0 stand for not connected - for( unsigned int i = 1; i < m_board->GetNetCount(); ++i ) + // Start with net number 1, as 0 stands for not connected + for( unsigned int i = 1; i < m_nets.size(); ++i ) { // Recompute only nets that require it if( m_nets[i].IsDirty() )