From 83f7c7e35e8bf16f9317fc957c03593039b76ae5 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 28 Jan 2014 16:30:58 +0100 Subject: [PATCH] Added RN_DATA::Add()/Remove() methods. RN_DATA::Update()/AddSimple() take BOARD_ITEM* as the parameter (instead of being split to versions with BOARD_CONNECTED_ITEM* and MODULE*), to make the code look clearer. --- pcbnew/ratsnest_data.cpp | 177 +++++++++++++++++++++++------------ pcbnew/ratsnest_data.h | 35 ++++--- pcbnew/router/pns_router.cpp | 2 +- pcbnew/tools/edit_tool.cpp | 17 +--- 4 files changed, 140 insertions(+), 91 deletions(-) diff --git a/pcbnew/ratsnest_data.cpp b/pcbnew/ratsnest_data.cpp index f33d5e96e6..ea9d8a7c57 100644 --- a/pcbnew/ratsnest_data.cpp +++ b/pcbnew/ratsnest_data.cpp @@ -673,6 +673,39 @@ std::list RN_NET::GetNodes( const BOARD_CONNECTED_ITEM* aItem ) con } +void RN_DATA::AddSimple( const BOARD_ITEM* aItem ) +{ + int net; + + if( aItem->IsConnected() ) + { + const BOARD_CONNECTED_ITEM* item = static_cast( aItem ); + net = item->GetNet(); + + if( net < 1 ) // do not process unconnected items + return; + + // Get list of nodes responding to the item + std::list nodes = m_nets[net].GetNodes( item ); + std::list::iterator it, itEnd; + + for( it = nodes.begin(), itEnd = nodes.end(); it != itEnd; ++it ) + m_nets[net].AddSimpleNode( *it ); + } + else if( aItem->Type() == PCB_MODULE_T ) + { + const MODULE* module = static_cast( aItem ); + + for( const D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() ) + AddSimple( pad ); + + return; + } + else + return; +} + + void RN_NET::ClearSimple() { BOOST_FOREACH( const RN_NODE_PTR& node, m_simpleNodes ) @@ -682,28 +715,6 @@ void RN_NET::ClearSimple() } -void RN_DATA::AddSimple( const BOARD_CONNECTED_ITEM* aItem ) -{ - int net = aItem->GetNet(); - if( net < 1 ) // do not process unconnected items - return; - - // Get list of nodes responding to the item - std::list nodes = m_nets[net].GetNodes( aItem ); - std::list::iterator it, itEnd; - - for( it = nodes.begin(), itEnd = nodes.end(); it != itEnd; ++it ) - m_nets[net].AddSimpleNode( *it ); -} - - -void RN_DATA::AddSimple( const MODULE* aModule ) -{ - for( const D_PAD* pad = aModule->Pads().GetFirst(); pad; pad = pad->Next() ) - AddSimple( pad ); -} - - void RN_NET::processZones() { BOOST_FOREACH( std::deque& edges, m_zoneConnections | boost::adaptors::map_values ) @@ -762,45 +773,51 @@ void RN_DATA::updateNet( int aNetCode ) } -void RN_DATA::Update( const BOARD_CONNECTED_ITEM* aItem ) +void RN_DATA::Add( const BOARD_ITEM* aItem ) { - int net = aItem->GetNet(); - if( net < 1 ) // do not process unconnected items + int net; + + if( aItem->IsConnected() ) + { + net = static_cast( aItem )->GetNet(); + if( net < 1 ) // do not process unconnected items + return; + } + else if( aItem->Type() == PCB_MODULE_T ) + { + const MODULE* module = static_cast( 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; + + m_nets[net].AddItem( pad ); + } + + return; + } + else return; switch( aItem->Type() ) { case PCB_PAD_T: - { - const D_PAD* pad = static_cast( aItem ); - m_nets[net].RemoveItem( pad ); - m_nets[net].AddItem( pad ); - } - break; + m_nets[net].AddItem( static_cast( aItem ) ); + break; case PCB_TRACE_T: - { - const TRACK* track = static_cast( aItem ); - m_nets[net].RemoveItem( track ); - m_nets[net].AddItem( track ); - } - break; + m_nets[net].AddItem( static_cast( aItem ) ); + break; case PCB_VIA_T: - { - const SEGVIA* via = static_cast( aItem ); - m_nets[net].RemoveItem( via ); - m_nets[net].AddItem( via ); - } - break; + m_nets[net].AddItem( static_cast( aItem ) ); + break; case PCB_ZONE_AREA_T: - { - const ZONE_CONTAINER* zone = static_cast( aItem ); - m_nets[net].RemoveItem( zone); - m_nets[net].AddItem( zone ); - } - break; + m_nets[net].AddItem( static_cast( aItem ) ); + break; default: break; @@ -808,18 +825,62 @@ void RN_DATA::Update( const BOARD_CONNECTED_ITEM* aItem ) } -void RN_DATA::Update( const MODULE* aModule ) +void RN_DATA::Remove( const BOARD_ITEM* aItem ) { - for( const D_PAD* pad = aModule->Pads().GetFirst(); pad; pad = pad->Next() ) - { - int net = pad->GetNet(); + int net; - if( net > 0 ) // do not process unconnected items - { - m_nets[net].RemoveItem( pad ); - m_nets[net].AddItem( pad ); - } + if( aItem->IsConnected() ) + { + net = static_cast( aItem )->GetNet(); + if( net < 1 ) // do not process unconnected items + return; } + else if( aItem->Type() == PCB_MODULE_T ) + { + const MODULE* module = static_cast( 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; + + m_nets[net].RemoveItem( pad ); + } + + return; + } + else + return; + + switch( aItem->Type() ) + { + case PCB_PAD_T: + m_nets[net].RemoveItem( static_cast( aItem ) ); + break; + + case PCB_TRACE_T: + m_nets[net].RemoveItem( static_cast( aItem ) ); + break; + + case PCB_VIA_T: + m_nets[net].RemoveItem( static_cast( aItem ) ); + break; + + case PCB_ZONE_AREA_T: + m_nets[net].RemoveItem( static_cast( aItem ) ); + break; + + default: + break; + } +} + + +void RN_DATA::Update( const BOARD_ITEM* aItem ) +{ + Remove( aItem ); + Add( aItem ); } diff --git a/pcbnew/ratsnest_data.h b/pcbnew/ratsnest_data.h index f8ffbf2406..860fffa5fa 100644 --- a/pcbnew/ratsnest_data.h +++ b/pcbnew/ratsnest_data.h @@ -524,34 +524,33 @@ public: RN_DATA( const BOARD* aBoard ) : m_board( aBoard ) {} /** - * Function UpdateItem() - * Updates ratsnest data for an item. - * @param aItem is an item to be updated. + * Function Add() + * Adds an item to the ratsnest data. + * @param aItem is an item to be added. */ - void Update( const BOARD_CONNECTED_ITEM* aItem ); + void Add( const BOARD_ITEM* aItem ); /** - * Function UpdateItem() - * Updates ratsnest data for a module. - * @param aItem is a module to be updated. + * Function Remove() + * Removes an item from the ratsnest data. + * @param aItem is an item to be updated. */ - void Update( const MODULE* aModule ); + void Remove( const BOARD_ITEM* aItem ); + + /** + * Function Update() + * Updates the ratsnest data for an item. + * @param aItem is an item to be updated. + */ + void Update( const BOARD_ITEM* aItem ); /** * Function AddSimple() * Sets an item to be drawn in simple mode (ie. one line per node, instead of full ratsnest). - * It is used for drawing temporary ratsnest, eg. while moving an item. + * It is used for drawing quick, temporary ratsnest, eg. while moving an item. * @param aItem is an item to be drawn in simple node. */ - void AddSimple( const BOARD_CONNECTED_ITEM* aItem ); - - /** - * Function AddSimple() - * Sets a module to be drawn in simple mode (ie. one line per node, instead of full ratsnest). - * It is used for drawing temporary ratsnest, eg. while moving a module. - * @param aModule is a module to be drawn in simple node. - */ - void AddSimple( const MODULE* aModule ); + void AddSimple( const BOARD_ITEM* aItem ); /** * Function ClearSimple() diff --git a/pcbnew/router/pns_router.cpp b/pcbnew/router/pns_router.cpp index e70fe550bf..9373ff985f 100644 --- a/pcbnew/router/pns_router.cpp +++ b/pcbnew/router/pns_router.cpp @@ -631,7 +631,7 @@ void PNS_ROUTER::commitRouting( PNS_NODE* aNode ) newBI->ClearFlags(); m_view->Add( newBI ); m_board->Add( newBI ); - m_board->GetRatsnest()->Update( static_cast( newBI ) ); + m_board->GetRatsnest()->Update( newBI ); newBI->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 277fefa8c1..706134d1bc 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -376,20 +376,9 @@ void EDIT_TOOL::updateRatsnest( bool aRedraw ) { BOARD_ITEM* item = static_cast( selection.items.GetPickedItem( i ) ); - if( item->Type() == PCB_PAD_T || item->Type() == PCB_TRACE_T || - item->Type() == PCB_VIA_T || item->Type() == PCB_ZONE_AREA_T ) - { - ratsnest->Update( static_cast( item ) ); + ratsnest->Update( static_cast( item ) ); - if( aRedraw ) - ratsnest->AddSimple( static_cast( item ) ); - } - else if( item->Type() == PCB_MODULE_T ) - { - ratsnest->Update( static_cast( item ) ); - - if( aRedraw ) - ratsnest->AddSimple( static_cast( item ) ); - } + if( aRedraw ) + ratsnest->AddSimple( item ); } }