Commit 441e0317 authored by Maciej Suminski's avatar Maciej Suminski

Added iterators for NETINFO_LIST (as net codes for existing net codes may be not consecutive).

parent af7520cc
...@@ -1440,10 +1440,11 @@ int BOARD::ReturnSortedNetnamesList( wxArrayString& aNames, bool aSortbyPadsCoun ...@@ -1440,10 +1440,11 @@ int BOARD::ReturnSortedNetnamesList( wxArrayString& aNames, bool aSortbyPadsCoun
netBuffer.reserve( m_NetInfo.GetNetCount() ); netBuffer.reserve( m_NetInfo.GetNetCount() );
for( unsigned ii = 1; ii < m_NetInfo.GetNetCount(); ii++ ) for( NETINFO_LIST::iterator net( m_NetInfo.begin() ), netEnd( m_NetInfo.end() );
net != netEnd; ++net )
{ {
if( m_NetInfo.GetNetItem( ii )->GetNet() > 0 ) if( net->GetNet() > 0 )
netBuffer.push_back( m_NetInfo.GetNetItem( ii ) ); netBuffer.push_back( *net );
} }
// sort the list // sort the list
......
...@@ -845,6 +845,24 @@ public: ...@@ -845,6 +845,24 @@ public:
m_NetInfo.AppendNet( aNewNet ); m_NetInfo.AppendNet( aNewNet );
} }
/**
* Function BeginNets
* @return iterator to the first element of the NETINFO_ITEMs list
*/
NETINFO_LIST::iterator BeginNets() const
{
return m_NetInfo.begin();
}
/**
* Function EndNets
* @return iterator to the last element of the NETINFO_ITEMs list
*/
NETINFO_LIST::iterator EndNets() const
{
return m_NetInfo.end();
}
/** /**
* Function GetNetCount * Function GetNetCount
* @return the number of nets (NETINFO_ITEM) * @return the number of nets (NETINFO_ITEM)
......
...@@ -203,11 +203,9 @@ void BOARD::SynchronizeNetsAndNetClasses() ...@@ -203,11 +203,9 @@ void BOARD::SynchronizeNetsAndNetClasses()
// set all NETs to the default NETCLASS, then later override some // set all NETs to the default NETCLASS, then later override some
// as we go through the NETCLASSes. // as we go through the NETCLASSes.
int count = m_NetInfo.GetNetCount(); for( NETINFO_LIST::iterator net( m_NetInfo.begin() ), netEnd( m_NetInfo.end() );
for( int i=0; i<count; ++i ) net != netEnd; ++net )
{ {
NETINFO_ITEM* net = FindNet( i );
if( net )
net->SetClass( m_NetClasses.GetDefault() ); net->SetClass( m_NetClasses.GetDefault() );
} }
...@@ -248,10 +246,8 @@ void BOARD::SynchronizeNetsAndNetClasses() ...@@ -248,10 +246,8 @@ void BOARD::SynchronizeNetsAndNetClasses()
m_NetClasses.GetDefault()->Clear(); m_NetClasses.GetDefault()->Clear();
for( int i=0; i<count; ++i ) for( NETINFO_LIST::iterator net( m_NetInfo.begin() ), netEnd( m_NetInfo.end() );
{ net != netEnd; ++net )
NETINFO_ITEM* net = FindNet( i );
if( net )
{ {
const wxString& classname = net->GetClassName(); const wxString& classname = net->GetClassName();
...@@ -263,7 +259,6 @@ void BOARD::SynchronizeNetsAndNetClasses() ...@@ -263,7 +259,6 @@ void BOARD::SynchronizeNetsAndNetClasses()
netclass->Add( net->GetNetname() ); netclass->Add( net->GetNetname() );
} }
}
// D(printf("stop\n");) // D(printf("stop\n");)
} }
...@@ -337,8 +332,15 @@ void NETCLASS::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControl ...@@ -337,8 +332,15 @@ void NETCLASS::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControl
aFormatter->Print( aNestLevel+1, "(uvia_dia %s)\n", FMT_IU( GetuViaDiameter() ).c_str() ); aFormatter->Print( aNestLevel+1, "(uvia_dia %s)\n", FMT_IU( GetuViaDiameter() ).c_str() );
aFormatter->Print( aNestLevel+1, "(uvia_drill %s)\n", FMT_IU( GetuViaDrill() ).c_str() ); aFormatter->Print( aNestLevel+1, "(uvia_drill %s)\n", FMT_IU( GetuViaDrill() ).c_str() );
for( NETCLASS::const_iterator it = begin(); it!= end(); ++it ) for( NETCLASS::const_iterator it = begin(); it != end(); ++it )
{
NETINFO_ITEM* netinfo = m_Parent->FindNet( *it );
if( netinfo && netinfo->GetNodesCount() > 0 )
{
aFormatter->Print( aNestLevel+1, "(add_net %s)\n", aFormatter->Quotew( *it ).c_str() ); aFormatter->Print( aNestLevel+1, "(add_net %s)\n", aFormatter->Quotew( *it ).c_str() );
}
}
aFormatter->Print( aNestLevel, ")\n\n" ); aFormatter->Print( aNestLevel, ")\n\n" );
} }
...@@ -214,6 +214,66 @@ public: ...@@ -214,6 +214,66 @@ public:
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; typedef boost::unordered_map<const int, NETINFO_ITEM*> NETCODES_MAP;
///> Wrapper class, so you can iterate through NETINFO_ITEM*s, not
///> std::pair<int/wxString, NETINFO_ITEM*>
class iterator
{
public:
iterator( NETNAMES_MAP::const_iterator aIter ) : m_iterator( aIter )
{
}
/// pre-increment operator
const iterator& operator++()
{
++m_iterator;
return *this;
}
/// post-increment operator
iterator operator++( int )
{
iterator ret = *this;
++m_iterator;
return ret;
}
NETINFO_ITEM* operator*() const
{
return m_iterator->second;
}
NETINFO_ITEM* operator->() const
{
return m_iterator->second;
}
bool operator!=( const iterator& aOther ) const
{
return m_iterator != aOther.m_iterator;
}
bool operator==( const iterator& aOther ) const
{
return m_iterator == aOther.m_iterator;
}
private:
NETNAMES_MAP::const_iterator m_iterator;
};
iterator begin() const
{
return iterator( m_netNames.begin() );
}
iterator end() const
{
return iterator( m_netNames.end() );
}
private: private:
/** /**
* Function DeleteData * Function DeleteData
......
...@@ -90,8 +90,8 @@ void NETINFO_LIST::buildListOfNets() ...@@ -90,8 +90,8 @@ void NETINFO_LIST::buildListOfNets()
buildPadsFullList(); buildPadsFullList();
// Restore the initial state of NETINFO_ITEMs // Restore the initial state of NETINFO_ITEMs
for( unsigned i = 0; i < GetNetCount(); ++i ) for( NETINFO_LIST::iterator net( begin() ), netEnd( end() ); net != netEnd; ++net )
GetNetItem( i )->Clear(); net->Clear();
// Assign pads to appropriate NETINFO_ITEMs // Assign pads to appropriate NETINFO_ITEMs
for( unsigned ii = 0; ii < m_PadsFullList.size(); ii++ ) for( unsigned ii = 0; ii < m_PadsFullList.size(); ii++ )
......
...@@ -654,15 +654,20 @@ void PCB_IO::format( BOARD* aBoard, int aNestLevel ) const ...@@ -654,15 +654,20 @@ void PCB_IO::format( BOARD* aBoard, int aNestLevel ) const
m_out->Print( aNestLevel, ")\n\n" ); m_out->Print( aNestLevel, ")\n\n" );
int netcount = aBoard->GetNetCount(); // Unconditionally save the unconnected net
m_out->Print( aNestLevel, "(net 0 \"\")\n" );
for( int i = 0; i < netcount; ++i ) // and now the rest of nets
for( NETINFO_LIST::iterator net( aBoard->BeginNet() ), netEnd( aBoard->EndNet() );
net != netEnd; ++net )
{
if( net->GetNodesCount() > 0 ) // save only not empty nets
{ {
NETINFO_ITEM* net = aBoard->FindNet( i );
m_out->Print( aNestLevel, "(net %d %s)\n", m_out->Print( aNestLevel, "(net %d %s)\n",
net->GetNet(), net->GetNet(),
m_out->Quotew( net->GetNetname() ).c_str() ); m_out->Quotew( net->GetNetname() ).c_str() );
} }
}
m_out->Print( 0, "\n" ); m_out->Print( 0, "\n" );
......
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