Commit aaf857e8 authored by Maciej Suminski's avatar Maciej Suminski
Browse files

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

Items removed from board are removed from ratsnest as well. Corrected the way of items removal from ratsnest.
parent bc71a2c0
Loading
Loading
Loading
Loading
+21 −6
Original line number Original line Diff line number Diff line
@@ -867,25 +867,40 @@ 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;
            }
            }
        }
        }


        m_ratsnest->GetNets()[zone->GetNet()].RemoveItem( zone );
    }
    break;
    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 );

        for( D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() )
            m_ratsnest->GetNets()[pad->GetNet()].RemoveItem( pad );
    }
    break;
    break;


    case PCB_TRACE_T:
    case PCB_TRACE_T:
    case PCB_VIA_T:
    case PCB_VIA_T:
        m_Track.Remove( (TRACK*) aBoardItem );
    {
        TRACK* track = static_cast<TRACK*>( aBoardItem );
        m_Track.Remove( track );
        m_ratsnest->GetNets()[track->GetNet()].RemoveItem( track );
    }
    break;
    break;


    case PCB_ZONE_T:
    case PCB_ZONE_T:
+71 −44
Original line number Original line Diff line number Diff line
@@ -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,76 +439,93 @@ 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.
        if( m_links.RemoveNode( aBegin ) )
            clearNode( aBegin );
            clearNode( aBegin );

        if( m_links.RemoveNode( aEnd ) )
            clearNode( aEnd );
            clearNode( aEnd );
    m_links.RemoveNode( aBegin );
    m_links.RemoveNode( aEnd );


        m_tracks.erase( aTrack );
        m_tracks.erase( aTrack );


        m_dirty = true;
        m_dirty = true;
    }
    }
    catch( ... )
    {
    }
}




void RN_NET::RemoveItem( const ZONE_CONTAINER* aZone )
void RN_NET::RemoveItem( const ZONE_CONTAINER* aZone )
{
    try
    {
    {
        // Remove all subpolygons that make the zone
        // Remove all subpolygons that make the zone
    std::deque<RN_POLY>& polygons = m_zonePolygons[aZone];
        std::deque<RN_POLY>& polygons = m_zonePolygons.at( aZone );
        BOOST_FOREACH( RN_POLY& polygon, polygons )
        BOOST_FOREACH( RN_POLY& polygon, polygons )
            m_links.RemoveNode( polygon.GetNode() );
            m_links.RemoveNode( polygon.GetNode() );
        polygons.clear();
        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( ... )
    {
    }
}




const RN_NODE_PTR RN_NET::GetClosestNode( const RN_NODE_PTR& aNode ) const
const RN_NODE_PTR RN_NET::GetClosestNode( const RN_NODE_PTR& aNode ) const
@@ -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 );
        }
        }
+3 −2
Original line number Original line Diff line number Diff line
@@ -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;
    }
    }