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

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
...@@ -2571,8 +2571,7 @@ void BOARD::ReplaceNetlist( NETLIST& aNetlist, bool aDeleteSinglePadNets, ...@@ -2571,8 +2571,7 @@ void BOARD::ReplaceNetlist( NETLIST& aNetlist, bool aDeleteSinglePadNets,
if( netinfo == NULL ) if( netinfo == NULL )
{ {
// It is a new net, we have to add it // It is a new net, we have to add it
netinfo = new NETINFO_ITEM( this, net.GetNetName(), netinfo = new NETINFO_ITEM( this, net.GetNetName() );
m_NetInfo.GetNetCount() );
m_NetInfo.AppendNet( netinfo ); m_NetInfo.AppendNet( netinfo );
} }
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#define __CLASSES_NETINFO__ #define __CLASSES_NETINFO__
#include <vector>
#include <gr_basic.h> #include <gr_basic.h>
#include <class_netclass.h> #include <class_netclass.h>
#include <boost/unordered_map.hpp> #include <boost/unordered_map.hpp>
...@@ -132,14 +131,16 @@ public: ...@@ -132,14 +131,16 @@ public:
/** /**
* Function GetItem * Function GetItem
* @param aNetcode = netcode to identify a given NETINFO_ITEM * @param aNetCode = netcode to identify a given NETINFO_ITEM
* @return NETINFO_ITEM* - by \a aNetcode, or NULL if not found * @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 );
return NULL; if( result != m_netCodes.end() )
return m_NetBuffer[aNetcode]; return (*result).second;
return NULL;
} }
/** /**
...@@ -161,7 +162,7 @@ public: ...@@ -161,7 +162,7 @@ public:
* @return the number of nets ( always >= 1 ) * @return the number of nets ( always >= 1 )
* because the first net is the "not connected" net and always exists * 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 * Function Append
...@@ -211,9 +212,9 @@ public: ...@@ -211,9 +212,9 @@ public:
#endif #endif
typedef boost::unordered_map<const wxString, NETINFO_ITEM*, WXSTRING_HASH> NETNAMES_MAP; typedef boost::unordered_map<const wxString, NETINFO_ITEM*, WXSTRING_HASH> NETNAMES_MAP;
typedef boost::unordered_map<const int, NETINFO_ITEM*> NETCODES_MAP;
private: private:
/** /**
* Function DeleteData * Function DeleteData
* deletes the list of nets (and free memory) * deletes the list of nets (and free memory)
...@@ -237,9 +238,20 @@ private: ...@@ -237,9 +238,20 @@ private:
*/ */
void buildPadsFullList(); void buildPadsFullList();
/**
* Function getFreeNetCode
* returns the first available net code that is not used by any other net.
*/
int getFreeNetCode() const;
BOARD* m_Parent; BOARD* m_Parent;
NETNAMES_MAP m_netNames; ///< map for a fast look up by net names 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. std::vector<D_PAD*> m_PadsFullList; ///< contains all pads, sorted by pad's netname.
///< can be used in ratsnest calculations. ///< can be used in ratsnest calculations.
...@@ -252,6 +264,8 @@ private: ...@@ -252,6 +264,8 @@ private:
*/ */
class NETINFO_ITEM class NETINFO_ITEM
{ {
friend class NETINFO_LIST;
private: private:
const int m_NetCode; ///< A number equivalent to the net name. const int m_NetCode; ///< A number equivalent to the net name.
///< Used for fast comparisons in ratsnest and DRC computations. ///< Used for fast comparisons in ratsnest and DRC computations.
...@@ -271,12 +285,6 @@ private: ...@@ -271,12 +285,6 @@ private:
BOARD_ITEM* m_parent; ///< The parent board item object the net belongs to. BOARD_ITEM* m_parent; ///< The parent board item object the net belongs to.
public: 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 std::vector <D_PAD*> m_PadInNetList; // List of pads connected to this net
unsigned m_RatsnestStartIdx; /* Starting point of ratsnests of this unsigned m_RatsnestStartIdx; /* Starting point of ratsnests of this
...@@ -287,7 +295,7 @@ public: ...@@ -287,7 +295,7 @@ public:
unsigned m_RatsnestEndIdx; // Ending point of ratsnests of this net unsigned m_RatsnestEndIdx; // Ending point of ratsnests of this net
// (excluded) in this buffer // (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(); ~NETINFO_ITEM();
/** /**
...@@ -446,10 +454,6 @@ public: ...@@ -446,10 +454,6 @@ public:
{ {
m_PadInNetList.clear(); 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 m_RatsnestStartIdx = 0; // Starting point of ratsnests of this net in a
// general buffer of ratsnest // general buffer of ratsnest
m_RatsnestEndIdx = 0; // Ending point of ratsnests of this net m_RatsnestEndIdx = 0; // Ending point of ratsnests of this net
......
...@@ -53,10 +53,6 @@ NETINFO_ITEM::NETINFO_ITEM( BOARD_ITEM* aParent, const wxString& aNetName, int a ...@@ -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_NetCode( aNetCode ), m_Netname( aNetName ), m_ShortNetname( m_Netname.AfterLast( '/' ) )
{ {
m_parent = aParent; 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 m_RatsnestStartIdx = 0; // Starting point of ratsnests of this net in a
// general buffer of ratsnest // general buffer of ratsnest
m_RatsnestEndIdx = 0; // Ending point of ratsnests of this net m_RatsnestEndIdx = 0; // Ending point of ratsnests of this net
......
...@@ -30,25 +30,29 @@ NETINFO_LIST::~NETINFO_LIST() ...@@ -30,25 +30,29 @@ NETINFO_LIST::~NETINFO_LIST()
void NETINFO_LIST::clear() void NETINFO_LIST::clear()
{ {
for( unsigned ii = 0; ii < GetNetCount(); ii++ ) NETNAMES_MAP::iterator it, itEnd;
delete m_NetBuffer[ii]; for( it = m_netNames.begin(), itEnd = m_netNames.end(); it != itEnd; ++it )
delete it->second;
m_NetBuffer.clear();
m_PadsFullList.clear(); m_PadsFullList.clear();
m_netNames.clear(); m_netNames.clear();
m_netCodes.clear();
} }
void NETINFO_LIST::AppendNet( NETINFO_ITEM* aNewElement ) 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 // net names & codes are supposed to be unique
assert( GetNetItem( aNewElement->GetNetname() ) == NULL ); assert( GetNetItem( aNewElement->GetNetname() ) == NULL );
assert( GetNetItem( aNewElement->GetNet() ) == 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 // add an entry for fast look up by a net name using a map
m_netNames.insert( std::make_pair( aNewElement->GetNetname(), aNewElement ) ); 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() ...@@ -115,11 +119,13 @@ void NETINFO_LIST::buildListOfNets()
#if defined(DEBUG) #if defined(DEBUG)
void NETINFO_LIST::Show() const 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", printf( "[%d]: netcode:%d netname:<%s>\n",
i, m_NetBuffer[i]->GetNet(), i++, it->second->GetNet(),
TO_UTF8( m_NetBuffer[i]->GetNetname() ) ); TO_UTF8( it->second->GetNetname() ) );
} }
} }
#endif #endif
...@@ -164,5 +170,17 @@ void NETINFO_LIST::buildPadsFullList() ...@@ -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 NETINFO_ITEM NETINFO_LIST::ORPHANED = NETINFO_ITEM( NULL, wxString( "orphaned" ), -1 );
const int NETINFO_LIST::UNCONNECTED = 0; const int NETINFO_LIST::UNCONNECTED = 0;
int NETINFO_LIST::m_newNetCode = 0;
...@@ -278,7 +278,7 @@ void PCB_PAD::AddToModule( MODULE* aModule, int aRotation, bool aEncapsulatedPad ...@@ -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 if( netinfo == NULL ) // I believe this should not happen, but just in case
{ {
// It is a new net // 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 ); m_board->AppendNet( netinfo );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment