Items removed from board are removed from ratsnest as well. Corrected the way of items removal from ratsnest.

This commit is contained in:
Maciej Suminski 2014-01-07 14:15:40 +01:00
parent bc71a2c007
commit aaf857e894
3 changed files with 94 additions and 51 deletions

View File

@ -867,26 +867,41 @@ BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem )
break; break;
case PCB_ZONE_AREA_T: // this one uses a vector case PCB_ZONE_AREA_T: // this one uses a vector
{
ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( aBoardItem );
// find the item in the vector, then delete then erase it. // find the item in the vector, then delete then erase it.
for( unsigned i = 0; i<m_ZoneDescriptorList.size(); ++i ) for( unsigned i = 0; i < m_ZoneDescriptorList.size(); ++i )
{ {
if( m_ZoneDescriptorList[i] == (ZONE_CONTAINER*) aBoardItem ) if( m_ZoneDescriptorList[i] == zone )
{ {
m_ZoneDescriptorList.erase( m_ZoneDescriptorList.begin() + i ); m_ZoneDescriptorList.erase( m_ZoneDescriptorList.begin() + i );
break; break;
} }
} }
break; m_ratsnest->GetNets()[zone->GetNet()].RemoveItem( zone );
}
break;
case PCB_MODULE_T: case PCB_MODULE_T:
{
MODULE* module = static_cast<MODULE*>( aBoardItem );
m_Modules.Remove( (MODULE*) aBoardItem ); m_Modules.Remove( (MODULE*) aBoardItem );
break;
for( D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() )
m_ratsnest->GetNets()[pad->GetNet()].RemoveItem( pad );
}
break;
case PCB_TRACE_T: case PCB_TRACE_T:
case PCB_VIA_T: case PCB_VIA_T:
m_Track.Remove( (TRACK*) aBoardItem ); {
break; TRACK* track = static_cast<TRACK*>( aBoardItem );
m_Track.Remove( track );
m_ratsnest->GetNets()[track->GetNet()].RemoveItem( track );
}
break;
case PCB_ZONE_T: case PCB_ZONE_T:
m_Zone.Remove( (SEGZONE*) aBoardItem ); m_Zone.Remove( (SEGZONE*) aBoardItem );

View File

@ -201,12 +201,18 @@ const RN_NODE_PTR& RN_LINKS::AddNode( int aX, int aY )
} }
void RN_LINKS::RemoveNode( const RN_NODE_PTR& aNode ) bool RN_LINKS::RemoveNode( const RN_NODE_PTR& aNode )
{ {
aNode->DecRefCount(); // TODO use the shared_ptr use_count aNode->DecRefCount(); // TODO use the shared_ptr use_count
if( aNode->GetRefCount() == 0 ) if( aNode->GetRefCount() == 0 )
{
m_nodes.erase( aNode ); m_nodes.erase( aNode );
return true;
}
return false;
} }
@ -270,6 +276,9 @@ void RN_NET::compute()
void RN_NET::clearNode( const RN_NODE_PTR& aNode ) void RN_NET::clearNode( const RN_NODE_PTR& aNode )
{ {
if( !m_rnEdges )
return;
std::vector<RN_EDGE_PTR>::iterator newEnd; std::vector<RN_EDGE_PTR>::iterator newEnd;
// Remove all ratsnest edges for associated with the node // Remove all ratsnest edges for associated with the node
@ -430,75 +439,92 @@ void RN_NET::AddItem( const ZONE_CONTAINER* aZone )
void RN_NET::RemoveItem( const D_PAD* aPad ) void RN_NET::RemoveItem( const D_PAD* aPad )
{ {
RN_NODE_PTR& node = m_pads[aPad]; try
if( !node ) {
return; RN_NODE_PTR node = m_pads.at( aPad );
// Remove edges associated with the node if( m_links.RemoveNode( node ) )
clearNode( node ); clearNode( node );
m_links.RemoveNode( node );
m_pads.erase( aPad ); m_pads.erase( aPad );
m_dirty = true; m_dirty = true;
}
catch( ... )
{
}
} }
void RN_NET::RemoveItem( const SEGVIA* aVia ) void RN_NET::RemoveItem( const SEGVIA* aVia )
{ {
RN_NODE_PTR& node = m_vias[aVia]; try
if( !node ) {
return; RN_NODE_PTR node = m_vias.at( aVia );
// Remove edges associated with the node if( m_links.RemoveNode( node ) )
clearNode( node ); clearNode( node );
m_links.RemoveNode( node );
m_vias.erase( aVia ); m_vias.erase( aVia );
m_dirty = true; m_dirty = true;
}
catch( ... )
{
}
} }
void RN_NET::RemoveItem( const TRACK* aTrack ) void RN_NET::RemoveItem( const TRACK* aTrack )
{ {
RN_EDGE_PTR& edge = m_tracks[aTrack]; try
if( !edge ) {
return; RN_EDGE_PTR& edge = m_tracks.at( aTrack );
// Save nodes, so they can be cleared later // Save nodes, so they can be cleared later
const RN_NODE_PTR& aBegin = edge->getSourceNode(); RN_NODE_PTR aBegin = edge->getSourceNode();
const RN_NODE_PTR& aEnd = edge->getTargetNode(); RN_NODE_PTR aEnd = edge->getTargetNode();
m_links.RemoveConnection( edge ); m_links.RemoveConnection( edge );
// Remove nodes associated with the edge. It is done in a safe way, there is a check // Remove nodes associated with the edge. It is done in a safe way, there is a check
// if nodes are not used by other edges. // if nodes are not used by other edges.
clearNode( aBegin ); if( m_links.RemoveNode( aBegin ) )
clearNode( aEnd ); clearNode( aBegin );
m_links.RemoveNode( aBegin );
m_links.RemoveNode( aEnd );
m_tracks.erase( aTrack ); if( m_links.RemoveNode( aEnd ) )
clearNode( aEnd );
m_dirty = true; m_tracks.erase( aTrack );
m_dirty = true;
}
catch( ... )
{
}
} }
void RN_NET::RemoveItem( const ZONE_CONTAINER* aZone ) void RN_NET::RemoveItem( const ZONE_CONTAINER* aZone )
{ {
// Remove all subpolygons that make the zone try
std::deque<RN_POLY>& polygons = m_zonePolygons[aZone]; {
BOOST_FOREACH( RN_POLY& polygon, polygons ) // Remove all subpolygons that make the zone
m_links.RemoveNode( polygon.GetNode() ); std::deque<RN_POLY>& polygons = m_zonePolygons.at( aZone );
polygons.clear(); BOOST_FOREACH( RN_POLY& polygon, polygons )
m_links.RemoveNode( polygon.GetNode() );
polygons.clear();
// Remove all connections added by the zone // Remove all connections added by the zone
std::deque<RN_EDGE_PTR>& edges = m_zoneConnections[aZone]; std::deque<RN_EDGE_PTR>& edges = m_zoneConnections.at( aZone );
BOOST_FOREACH( RN_EDGE_PTR& edge, edges ) BOOST_FOREACH( RN_EDGE_PTR& edge, edges )
m_links.RemoveConnection( edge ); m_links.RemoveConnection( edge );
edges.clear(); edges.clear();
m_dirty = true; m_dirty = true;
}
catch( ... )
{
}
} }
@ -832,6 +858,7 @@ void RN_DATA::Recalculate( int aNet )
// Start with net number 1, as 0 stand for not connected // Start with net number 1, as 0 stand for not connected
for( unsigned int i = 1; i < m_board->GetNetCount(); ++i ) for( unsigned int i = 1; i < m_board->GetNetCount(); ++i )
{ {
// Recompute only nets that require it
if( m_nets[i].IsDirty() ) if( m_nets[i].IsDirty() )
updateNet( i ); updateNet( i );
} }

View File

@ -129,8 +129,9 @@ public:
* Function RemoveNode() * Function RemoveNode()
* Removes a node described by a given node pointer. * Removes a node described by a given node pointer.
* @param aNode is a pointer to node to be removed. * @param aNode is a pointer to node to be removed.
* @return True if node was removed, false if there were other references, so it was kept.
*/ */
void RemoveNode( const RN_NODE_PTR& aNode ); bool RemoveNode( const RN_NODE_PTR& aNode );
/** /**
* Function GetNodes() * Function GetNodes()
@ -577,7 +578,7 @@ public:
* Returns ratsnest grouped by net numbers. * Returns ratsnest grouped by net numbers.
* @return Vector of ratsnest grouped by net numbers. * @return Vector of ratsnest grouped by net numbers.
*/ */
const std::vector<RN_NET>& GetNets() const std::vector<RN_NET>& GetNets()
{ {
return m_nets; return m_nets;
} }