From f075166a215a8b6a0f30ea5f21cb7df82c2ac4a2 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 9 Jan 2014 15:51:47 +0100 Subject: [PATCH] Removed NETINFO_ITEM::SetNet() and NETINFO_ITEM::SetNetname() methods. NETINFO_ITEM::m_Net and NETINFO_ITEM::m_Netname are const. Changes to be verified: - pcbnew/minimun_spanning_tree.cpp: It segfaults is m_Size == 0 - pcbnew/exporters/export_gencad.cpp: I removed the SetNetname() call, as it changes only the unconnected net and in the next line it returns if the net is unconnected. Still, I wonder if name for the unconnected net matters. What about tests that check if a net name is empty to decide if it is unconnected net or not. --- pcbnew/class_netinfo.h | 39 ++++++++++++++++++-------- pcbnew/class_netinfo_item.cpp | 19 ++----------- pcbnew/class_netinfolist.cpp | 45 ++++++++---------------------- pcbnew/exporters/export_gencad.cpp | 1 - pcbnew/legacy_plugin.cpp | 7 ++--- pcbnew/minimun_spanning_tree.cpp | 2 +- pcbnew/pcb_parser.cpp | 4 +-- 7 files changed, 45 insertions(+), 72 deletions(-) diff --git a/pcbnew/class_netinfo.h b/pcbnew/class_netinfo.h index 427a7b5685..a3c1807e14 100644 --- a/pcbnew/class_netinfo.h +++ b/pcbnew/class_netinfo.h @@ -228,14 +228,14 @@ private: class NETINFO_ITEM { private: - 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. - wxString m_Netname; ///< Full net name like /mysheet/mysubsheet/vout + const wxString m_Netname; ///< Full net name like /mysheet/mysubsheet/vout ///< used by Eeschema - wxString m_ShortNetname; // short net name, like vout from - // /mysheet/mysubsheet/vout + const wxString m_ShortNetname; // short net name, like vout from + // /mysheet/mysubsheet/vout wxString m_NetClassName; // Net Class name. if void this is equivalent // to "default" (the first @@ -386,8 +386,10 @@ public: */ int GetNet() const { return m_NetCode; } - void SetNet( int aNetCode ) { m_NetCode = aNetCode; } - + /** + * Function GetNodesCount + * @return int - number of nodes in the net + */ int GetNodesCount() const { return m_PadInNetList.size(); } /** @@ -402,12 +404,6 @@ public: */ wxString GetShortNetname() const { return m_ShortNetname; } - /** - * Function SetNetname - * @param aNetname : the new netname - */ - void SetNetname( const wxString& aNetname ); - /** * Function GetMsgPanelInfo * returns the information about the #NETINFO_ITEM in \a aList to display in the @@ -416,6 +412,25 @@ public: * @param aList is the list in which to place the status information. */ void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ); + + /** + * Function Clear + * sets all fields to their defaults values. + */ + void 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 + // general buffer of ratsnest + m_RatsnestEndIdx = 0; // Ending point of ratsnests of this net + + SetClass( NULL ); + } }; diff --git a/pcbnew/class_netinfo_item.cpp b/pcbnew/class_netinfo_item.cpp index f96132dfc1..05bcabb1bc 100644 --- a/pcbnew/class_netinfo_item.cpp +++ b/pcbnew/class_netinfo_item.cpp @@ -49,13 +49,9 @@ /* class NETINFO_ITEM: handle data relative to a given net */ /*********************************************************/ -NETINFO_ITEM::NETINFO_ITEM( BOARD_ITEM* aParent, const wxString& aNetName, int aNetCode ) +NETINFO_ITEM::NETINFO_ITEM( BOARD_ITEM* aParent, const wxString& aNetName, int aNetCode ) : + m_NetCode( aNetCode ), m_Netname( aNetName ), m_ShortNetname( m_Netname.AfterLast( '/' ) ) { - SetNet( aNetCode ); - - if( aNetName.size() ) - SetNetname( aNetName ); - m_parent = aParent; m_NbNodes = 0; m_NbLink = 0; @@ -77,17 +73,6 @@ NETINFO_ITEM::~NETINFO_ITEM() } -/** - * Function SetNetname - * @param aNetname : the new netname - */ -void NETINFO_ITEM::SetNetname( const wxString& aNetname ) -{ - m_Netname = aNetname; - m_ShortNetname = m_Netname.AfterLast( '/' ); -} - - /** * Function Draw (TODO) */ diff --git a/pcbnew/class_netinfolist.cpp b/pcbnew/class_netinfolist.cpp index df5f8039de..75bad023a2 100644 --- a/pcbnew/class_netinfolist.cpp +++ b/pcbnew/class_netinfolist.cpp @@ -37,10 +37,6 @@ void NETINFO_LIST::clear() } -/** - * Function Append - * adds \a aNewElement to the end of the list. - */ void NETINFO_LIST::AppendNet( NETINFO_ITEM* aNewElement ) { m_NetBuffer.push_back( aNewElement ); @@ -80,46 +76,29 @@ void NETINFO_LIST::buildListOfNets() int nodes_count = 0; NETINFO_ITEM* net_item; - clear(); // Remove all nets info and free memory - - // Create and add the "unconnected net", always existing, - // used to handle pads and tracks that are not member of a "real" net - net_item = new NETINFO_ITEM( m_Parent ); - AppendNet( net_item ); - // Build the PAD list, sorted by net buildPadsFullList(); - // Build netnames list, and create a netcode for each netname - D_PAD* last_pad = NULL; - int netcode = 0; + // Restore the initial state of NETINFO_ITEMs + for( unsigned i = 0; i < GetNetCount(); ++i ) + { + GetNetItem( i )->Clear(); + } + std::cout << m_PadsFullList.size() << std::endl; + + // Assign pads to appropriate NETINFO_ITEMs for( unsigned ii = 0; ii < m_PadsFullList.size(); ii++ ) { pad = m_PadsFullList[ii]; - if( pad->GetNetname().IsEmpty() ) // pad not connected - { - pad->SetNet( 0 ); + if( pad->GetNet() == 0 ) // pad not connected continue; - } - /* if the current netname was already found: add pad to the current net_item , - * else create a new net_code and a new net_item - */ - if( last_pad == NULL || ( pad->GetNetname() != last_pad->GetNetname() ) ) - { - netcode++; - net_item = new NETINFO_ITEM( m_Parent, pad->GetNetname(), netcode ); - AppendNet( net_item ); - } - - pad->SetNet( netcode ); + net_item = GetNetItem( pad->GetNet() ); net_item->m_PadInNetList.push_back( pad ); - nodes_count++; - - last_pad = pad; + ++nodes_count; } m_Parent->SetNodeCount( nodes_count ); @@ -129,8 +108,6 @@ void NETINFO_LIST::buildListOfNets() m_Parent->m_Status_Pcb |= NET_CODES_OK; m_Parent->SetAreasNetCodesFromNetNames(); - - // D( Show(); ) } #if defined(DEBUG) diff --git a/pcbnew/exporters/export_gencad.cpp b/pcbnew/exporters/export_gencad.cpp index f04496ff7c..394a39f808 100644 --- a/pcbnew/exporters/export_gencad.cpp +++ b/pcbnew/exporters/export_gencad.cpp @@ -647,7 +647,6 @@ static void CreateSignalsSection( FILE* aFile, BOARD* aPcb ) if( net->GetNetname() == wxEmptyString ) // dummy netlist (no connection) { wxString msg; msg << wxT( "NoConnection" ) << NbNoConn++; - net->SetNetname( msg ); } if( net->GetNet() <= 0 ) // dummy netlist (no connection) diff --git a/pcbnew/legacy_plugin.cpp b/pcbnew/legacy_plugin.cpp index 4bc6e4550a..ab5a4fe34f 100644 --- a/pcbnew/legacy_plugin.cpp +++ b/pcbnew/legacy_plugin.cpp @@ -1811,7 +1811,7 @@ void LEGACY_PLUGIN::loadNETINFO_ITEM() { char buf[1024]; - NETINFO_ITEM* net = new NETINFO_ITEM( m_board ); + NETINFO_ITEM* net; char* line; while( ( line = READLINE( m_reader ) ) != NULL ) @@ -1822,11 +1822,10 @@ void LEGACY_PLUGIN::loadNETINFO_ITEM() { // e.g. "Na 58 "/cpu.sch/PAD7"\r\n" - int tmp = intParse( line + SZ( "Na" ), &data ); - net->SetNet( tmp ); + int netCode = intParse( line + SZ( "Na" ), &data ); ReadDelimitedText( buf, data, sizeof(buf) ); - net->SetNetname( FROM_UTF8( buf ) ); + net = new NETINFO_ITEM( m_board, FROM_UTF8( buf ), netCode ); } else if( TESTLINE( "$EndEQUIPOT" ) ) diff --git a/pcbnew/minimun_spanning_tree.cpp b/pcbnew/minimun_spanning_tree.cpp index f107590d6c..8d683f7786 100644 --- a/pcbnew/minimun_spanning_tree.cpp +++ b/pcbnew/minimun_spanning_tree.cpp @@ -69,7 +69,7 @@ MIN_SPAN_TREE::MIN_SPAN_TREE() void MIN_SPAN_TREE::MSP_Init( int aNodesCount ) { - m_Size = aNodesCount; + m_Size = std::max( aNodesCount, 1 ); inTree.clear(); linkedTo.clear(); distTo.clear(); diff --git a/pcbnew/pcb_parser.cpp b/pcbnew/pcb_parser.cpp index 1b47c69158..f1eaa3026c 100644 --- a/pcbnew/pcb_parser.cpp +++ b/pcbnew/pcb_parser.cpp @@ -1066,9 +1066,7 @@ void PCB_PARSER::parseNETINFO_ITEM() throw( IO_ERROR, PARSE_ERROR ) // (TODO: a better test.) if( number > 0 || m_board->FindNet( 0 ) == NULL ) { - NETINFO_ITEM* net = new NETINFO_ITEM( m_board ); - net->SetNet( number ); - net->SetNetname( name ); + NETINFO_ITEM* net = new NETINFO_ITEM( m_board, name, number ); m_board->AppendNet( net ); } }