diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 691e379cc7..acde874db3 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -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 ); } diff --git a/pcbnew/class_netinfo.h b/pcbnew/class_netinfo.h index 3e836d0b95..34f38188ae 100644 --- a/pcbnew/class_netinfo.h +++ b/pcbnew/class_netinfo.h @@ -34,7 +34,6 @@ #define __CLASSES_NETINFO__ -#include #include #include #include @@ -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 - return NULL; - return m_NetBuffer[aNetcode]; + NETCODES_MAP::const_iterator result = m_netCodes.find( aNetCode ); + if( result != m_netCodes.end() ) + return (*result).second; + + return NULL; } /** @@ -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 NETNAMES_MAP; + typedef boost::unordered_map 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 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 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 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 diff --git a/pcbnew/class_netinfo_item.cpp b/pcbnew/class_netinfo_item.cpp index 05bcabb1bc..1ca37ec3a1 100644 --- a/pcbnew/class_netinfo_item.cpp +++ b/pcbnew/class_netinfo_item.cpp @@ -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 diff --git a/pcbnew/class_netinfolist.cpp b/pcbnew/class_netinfolist.cpp index e2f16a014b..4c5221f372 100644 --- a/pcbnew/class_netinfolist.cpp +++ b/pcbnew/class_netinfolist.cpp @@ -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( 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; diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_pad.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_pad.cpp index c3cd2e34af..c5c05d849b 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb_pad.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcb_pad.cpp @@ -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 ); }