Commit 8a4e7235 authored by Maciej Suminski's avatar Maciej Suminski
Browse files

NETINFO_ITEMs are not stored in a vector anymore, instead they are held in a...

NETINFO_ITEMs are not stored in a vector anymore, instead they are held in a unordered_map. Now, the net codes may be not consecutive. There is another way for assigning net codes (using a static int that holds a possible empty net code and a function that makes sure it is not used [getFreeNetCode()]).
Removed some unused fields (NETINFO_ITEM::m_NbNodes, m_NbLink, m_NbNoconn, m_Flag).
parent d62b47a0
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -2571,8 +2571,7 @@ void BOARD::ReplaceNetlist( NETLIST& aNetlist, bool aDeleteSinglePadNets,
                        if( netinfo == NULL )
                        {
                            // It is a new net, we have to add it
                            netinfo = new NETINFO_ITEM( this, net.GetNetName(),
                                                        m_NetInfo.GetNetCount() );
                            netinfo = new NETINFO_ITEM( this, net.GetNetName() );
                            m_NetInfo.AppendNet( netinfo );
                        }

+25 −21
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@
#define __CLASSES_NETINFO__


#include <vector>
#include <gr_basic.h>
#include <class_netclass.h>
#include <boost/unordered_map.hpp>
@@ -132,14 +131,16 @@ public:

    /**
     * Function GetItem
     * @param aNetcode = netcode to identify a given NETINFO_ITEM
     * @return NETINFO_ITEM* - by \a aNetcode, or NULL if not found
     * @param aNetCode = netcode to identify a given NETINFO_ITEM
     * @return NETINFO_ITEM* - by \a aNetCode, or NULL if not found
     */
    NETINFO_ITEM* GetNetItem( int aNetcode ) const
    NETINFO_ITEM* GetNetItem( int aNetCode ) const
    {
        if( unsigned( aNetcode ) >= GetNetCount() )     // catches < 0 too
        NETCODES_MAP::const_iterator result = m_netCodes.find( aNetCode );
        if( result != m_netCodes.end() )
            return (*result).second;

        return NULL;
        return m_NetBuffer[aNetcode];
    }

    /**
@@ -161,7 +162,7 @@ public:
     * @return the number of nets ( always >= 1 )
     * because the first net is the "not connected" net and always exists
     */
    unsigned GetNetCount() const { return m_NetBuffer.size(); }
    unsigned GetNetCount() const { return m_netNames.size(); }

    /**
     * Function Append
@@ -211,9 +212,9 @@ public:
#endif

    typedef boost::unordered_map<const wxString, NETINFO_ITEM*, WXSTRING_HASH> NETNAMES_MAP;
    typedef boost::unordered_map<const int, NETINFO_ITEM*> NETCODES_MAP;

private:

    /**
     * Function DeleteData
     * deletes the list of nets (and free memory)
@@ -237,9 +238,20 @@ private:
     */
    void buildPadsFullList();

    /**
     * Function getFreeNetCode
     * returns the first available net code that is not used by any other net.
     */
    int getFreeNetCode() const;

    BOARD*                      m_Parent;

    NETNAMES_MAP m_netNames;                    ///< map for a fast look up by net names
    std::vector<NETINFO_ITEM*>  m_NetBuffer;    ///< net list (name, design constraints ..)
    NETCODES_MAP m_netCodes;                    ///< map for a fast look up by net codes

    static int m_newNetCode;                    ///< number that has a *high* chance to be unused
                                                ///< (to be sure, it is advised to use
                                                ///< getFreeNetCode() function)

    std::vector<D_PAD*>         m_PadsFullList; ///< contains all pads, sorted by pad's netname.
                                                ///< can be used in ratsnest calculations.
@@ -252,6 +264,8 @@ private:
 */
class NETINFO_ITEM
{
    friend class NETINFO_LIST;

private:
    const int m_NetCode;        ///< A number equivalent to the net name.
                                ///< Used for fast comparisons in ratsnest and DRC computations.
@@ -271,12 +285,6 @@ private:
    BOARD_ITEM* m_parent;       ///< The parent board item object the net belongs to.

public:
    int m_NbNodes;                     // Pads count for this net
    int m_NbLink;                      // Ratsnets count for this net
    int m_NbNoconn;                    // Ratsnets remaining to route count
    int m_Flag;                        // used in some calculations. Had no
                                       // special meaning

    std::vector <D_PAD*> m_PadInNetList;    // List of pads connected to this net

    unsigned m_RatsnestStartIdx;       /* Starting point of ratsnests of this
@@ -287,7 +295,7 @@ public:
    unsigned m_RatsnestEndIdx;         // Ending point of ratsnests of this net
                                       // (excluded) in this buffer

    NETINFO_ITEM( BOARD_ITEM* aParent, const wxString& aNetName = wxEmptyString, int aNetCode = 0 );
    NETINFO_ITEM( BOARD_ITEM* aParent, const wxString& aNetName = wxEmptyString, int aNetCode = -1 );
    ~NETINFO_ITEM();

    /**
@@ -446,10 +454,6 @@ public:
    {
        m_PadInNetList.clear();

        m_NbNodes           = 0;
        m_NbLink            = 0;
        m_NbNoconn          = 0;
        m_Flag              = 0;
        m_RatsnestStartIdx  = 0;     // Starting point of ratsnests of this net in a
                                     // general buffer of ratsnest
        m_RatsnestEndIdx    = 0;     // Ending point of ratsnests of this net
+0 −4
Original line number Diff line number Diff line
@@ -53,10 +53,6 @@ NETINFO_ITEM::NETINFO_ITEM( BOARD_ITEM* aParent, const wxString& aNetName, int a
    m_NetCode( aNetCode ), m_Netname( aNetName ), m_ShortNetname( m_Netname.AfterLast( '/' ) )
{
    m_parent   = aParent;
    m_NbNodes  = 0;
    m_NbLink   = 0;
    m_NbNoconn = 0;
    m_Flag     = 0;
    m_RatsnestStartIdx = 0;     // Starting point of ratsnests of this net in a
                                // general buffer of ratsnest
    m_RatsnestEndIdx   = 0;     // Ending point of ratsnests of this net
+26 −8
Original line number Diff line number Diff line
@@ -30,25 +30,29 @@ NETINFO_LIST::~NETINFO_LIST()

void NETINFO_LIST::clear()
{
    for( unsigned ii = 0; ii < GetNetCount(); ii++ )
        delete m_NetBuffer[ii];
    NETNAMES_MAP::iterator it, itEnd;
    for( it = m_netNames.begin(), itEnd = m_netNames.end(); it != itEnd; ++it )
        delete it->second;

    m_NetBuffer.clear();
    m_PadsFullList.clear();
    m_netNames.clear();
    m_netCodes.clear();
}


void NETINFO_LIST::AppendNet( NETINFO_ITEM* aNewElement )
{
    // negative net code means that it has to be auto assigned
    if( aNewElement->m_NetCode < 0 )
        const_cast<int&>( aNewElement->m_NetCode ) = getFreeNetCode();

    // net names & codes are supposed to be unique
    assert( GetNetItem( aNewElement->GetNetname() ) == NULL );
    assert( GetNetItem( aNewElement->GetNet() ) == NULL );

    m_NetBuffer.push_back( aNewElement );

    // add an entry for fast look up by a net name using a map
    m_netNames.insert( std::make_pair( aNewElement->GetNetname(), aNewElement ) );
    m_netCodes.insert( std::make_pair( aNewElement->GetNet(), aNewElement ) );
}


@@ -115,11 +119,13 @@ void NETINFO_LIST::buildListOfNets()
#if defined(DEBUG)
void NETINFO_LIST::Show() const
{
    for( unsigned i=0; i < m_NetBuffer.size();  ++i )
    int i = 0;
    NETNAMES_MAP::const_iterator it, itEnd;
    for( it = m_netNames.begin(), itEnd = m_netNames.end(); it != itEnd; ++it )
    {
        printf( "[%d]: netcode:%d  netname:<%s>\n",
            i, m_NetBuffer[i]->GetNet(),
            TO_UTF8( m_NetBuffer[i]->GetNetname() ) );
            i++, it->second->GetNet(),
            TO_UTF8( it->second->GetNetname() ) );
    }
}
#endif
@@ -164,5 +170,17 @@ void NETINFO_LIST::buildPadsFullList()
}


int NETINFO_LIST::getFreeNetCode() const
{
    do {
        if( m_newNetCode < 0 )
            m_newNetCode = 0;
    } while( m_netCodes.count( ++NETINFO_LIST::m_newNetCode ) != 0 );

    return m_newNetCode;
}


const NETINFO_ITEM NETINFO_LIST::ORPHANED = NETINFO_ITEM( NULL, wxString( "orphaned" ), -1 );
const int NETINFO_LIST::UNCONNECTED = 0;
int NETINFO_LIST::m_newNetCode = 0;
+1 −1
Original line number Diff line number Diff line
@@ -278,7 +278,7 @@ void PCB_PAD::AddToModule( MODULE* aModule, int aRotation, bool aEncapsulatedPad
        if( netinfo == NULL )   // I believe this should not happen, but just in case
        {
            // It is a new net
            netinfo = new NETINFO_ITEM( m_board, m_net, m_board->GetNetCount() );
            netinfo = new NETINFO_ITEM( m_board, m_net );
            m_board->AppendNet( netinfo );
        }