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;
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.
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 );
break;
}
}
break;
m_ratsnest->GetNets()[zone->GetNet()].RemoveItem( zone );
}
break;
case PCB_MODULE_T:
{
MODULE* module = static_cast<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_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:
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
if( aNode->GetRefCount() == 0 )
{
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 )
{
if( !m_rnEdges )
return;
std::vector<RN_EDGE_PTR>::iterator newEnd;
// 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 )
{
RN_NODE_PTR& node = m_pads[aPad];
if( !node )
return;
try
{
RN_NODE_PTR node = m_pads.at( aPad );
// Remove edges associated with the node
clearNode( node );
m_links.RemoveNode( node );
if( m_links.RemoveNode( node ) )
clearNode( node );
m_pads.erase( aPad );
m_pads.erase( aPad );
m_dirty = true;
m_dirty = true;
}
catch( ... )
{
}
}
void RN_NET::RemoveItem( const SEGVIA* aVia )
{
RN_NODE_PTR& node = m_vias[aVia];
if( !node )
return;
try
{
RN_NODE_PTR node = m_vias.at( aVia );
// Remove edges associated with the node
clearNode( node );
m_links.RemoveNode( node );
if( m_links.RemoveNode( node ) )
clearNode( node );
m_vias.erase( aVia );
m_vias.erase( aVia );
m_dirty = true;
m_dirty = true;
}
catch( ... )
{
}
}
void RN_NET::RemoveItem( const TRACK* aTrack )
{
RN_EDGE_PTR& edge = m_tracks[aTrack];
if( !edge )
return;
try
{
RN_EDGE_PTR& edge = m_tracks.at( aTrack );
// Save nodes, so they can be cleared later
const RN_NODE_PTR& aBegin = edge->getSourceNode();
const RN_NODE_PTR& aEnd = edge->getTargetNode();
m_links.RemoveConnection( edge );
// Save nodes, so they can be cleared later
RN_NODE_PTR aBegin = edge->getSourceNode();
RN_NODE_PTR aEnd = edge->getTargetNode();
m_links.RemoveConnection( edge );
// 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.
clearNode( aBegin );
clearNode( aEnd );
m_links.RemoveNode( aBegin );
m_links.RemoveNode( aEnd );
// 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( m_links.RemoveNode( aBegin ) )
clearNode( aBegin );
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 )
{
// Remove all subpolygons that make the zone
std::deque<RN_POLY>& polygons = m_zonePolygons[aZone];
BOOST_FOREACH( RN_POLY& polygon, polygons )
m_links.RemoveNode( polygon.GetNode() );
polygons.clear();
try
{
// Remove all subpolygons that make the zone
std::deque<RN_POLY>& polygons = m_zonePolygons.at( aZone );
BOOST_FOREACH( RN_POLY& polygon, polygons )
m_links.RemoveNode( polygon.GetNode() );
polygons.clear();
// Remove all connections added by the zone
std::deque<RN_EDGE_PTR>& edges = m_zoneConnections[aZone];
BOOST_FOREACH( RN_EDGE_PTR& edge, edges )
m_links.RemoveConnection( edge );
edges.clear();
// Remove all connections added by the zone
std::deque<RN_EDGE_PTR>& edges = m_zoneConnections.at( aZone );
BOOST_FOREACH( RN_EDGE_PTR& edge, edges )
m_links.RemoveConnection( edge );
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
for( unsigned int i = 1; i < m_board->GetNetCount(); ++i )
{
// Recompute only nets that require it
if( m_nets[i].IsDirty() )
updateNet( i );
}

View File

@ -129,8 +129,9 @@ public:
* Function RemoveNode()
* Removes a node described by a given node pointer.
* @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()
@ -577,7 +578,7 @@ public:
* Returns 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;
}