From d62b47a0dfe59bfe0e5722c8375a1e8fbf0d37ea Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 15 Jan 2014 18:03:06 +0100 Subject: [PATCH] BOARD_CONNECTED_ITEMs do not store net code anymore (m_NetCode field), instead net info is stored using a pointer to NETINFO_ITEM. GetNet() refers to the net code stored in the NETINFO_ITEM. SetNet() finds an appropriate NETINFO_ITEM and uses it. Removing GetNet() & SetNet() (and the whole net code idea) requires too many changes in the code (~250 references to the mentioned functions). BOARD_CONNECTED_ITEMs by default get a pointer to NETINFO_ITEM that stores unconnected items. This requires for all BOARD_CONNECTED_ITEMs to have a parent (so BOARD* is accessible). The only orphaned item is BOARD_DESIGN_SETTINGS::m_Pad_Master, but it does not cause any issues so far. Items that do not have access to a BOARD (do not have set parents) and therefore cannot get net assigned, by default get const static NETINFO_LIST::ORPHANED. Performed tests: - loaded .kicad_pcb, KiCad legacy board, Eagle 6.0 board, P-CAD board - all ok - load a simple project, reload netlist after changing connections in eeschema - ok - save & reload a board - ok, but still contain empty nets - remove everything, restore with undo - ok - remove everything, reload netlist - ok - changing net names (all possibilites: empty->existing, empty->not existing, existing->empty, existing->not existing) - all ok - zones: when net is changed to a net that does not have any nodes besides the zone itself, it does not get filled --- include/class_board_item.h | 3 +- pcbnew/class_board.cpp | 3 +- pcbnew/class_board_connected_item.cpp | 38 ++++++++++++++++++-------- pcbnew/class_board_connected_item.h | 26 ++++++++++-------- pcbnew/class_board_design_settings.cpp | 2 +- pcbnew/class_netinfo.h | 4 +++ pcbnew/class_netinfolist.cpp | 1 + pcbnew/class_zone.cpp | 1 - pcbnew/eagle_plugin.cpp | 5 ++-- pcbnew/pcb_parser.cpp | 6 ++-- pcbnew/pcb_parser.h | 2 +- 11 files changed, 57 insertions(+), 34 deletions(-) diff --git a/include/class_board_item.h b/include/class_board_item.h index 6f6bf201d6..b6e5e905a6 100644 --- a/include/class_board_item.h +++ b/include/class_board_item.h @@ -83,8 +83,7 @@ protected: public: BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) : - EDA_ITEM( aParent, idtype ) - , m_Layer( FIRST_LAYER ) + EDA_ITEM( aParent, idtype ), m_Layer( FIRST_LAYER ) { } diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 416044cc5d..691e379cc7 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -2571,7 +2571,8 @@ 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.GetNetCount() ); m_NetInfo.AppendNet( netinfo ); } diff --git a/pcbnew/class_board_connected_item.cpp b/pcbnew/class_board_connected_item.cpp index cf44e1dc7a..69bcfacb7e 100644 --- a/pcbnew/class_board_connected_item.cpp +++ b/pcbnew/class_board_connected_item.cpp @@ -34,34 +34,50 @@ #include #include - BOARD_CONNECTED_ITEM::BOARD_CONNECTED_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) : - BOARD_ITEM( aParent, idtype ), m_NetCode( 0 ), m_Subnet( 0 ), m_ZoneSubnet( 0 ) + BOARD_ITEM( aParent, idtype ), m_Subnet( 0 ), m_ZoneSubnet( 0 ), + m_netinfo( &NETINFO_LIST::ORPHANED ) { + // The unconnected is set only in case the item belongs to a BOARD + SetNet( NETINFO_LIST::UNCONNECTED ); } BOARD_CONNECTED_ITEM::BOARD_CONNECTED_ITEM( const BOARD_CONNECTED_ITEM& aItem ) : - BOARD_ITEM( aItem ), m_NetCode( aItem.m_NetCode ), m_Subnet( aItem.m_Subnet ), - m_ZoneSubnet( aItem.m_ZoneSubnet ) + BOARD_ITEM( aItem ), m_Subnet( aItem.m_Subnet ), m_ZoneSubnet( aItem.m_ZoneSubnet ), + m_netinfo( aItem.m_netinfo ) { } +int BOARD_CONNECTED_ITEM::GetNet() const +{ + return m_netinfo->GetNet(); +} + + +void BOARD_CONNECTED_ITEM::SetNet( int aNetCode ) +{ + BOARD* board = GetBoard(); + if( board ) + { + m_netinfo = board->FindNet( aNetCode ); + + if( m_netinfo == NULL ) + m_netinfo = board->FindNet( NETINFO_LIST::UNCONNECTED ); + } +} + + const wxString& BOARD_CONNECTED_ITEM::GetNetname() const { - BOARD* board = GetBoard(); - NETINFO_ITEM* netinfo = board->FindNet( m_NetCode ); - - return netinfo->GetNetname(); + return m_netinfo->GetNetname(); } const wxString& BOARD_CONNECTED_ITEM::GetShortNetname() const { - NETINFO_ITEM* netinfo = GetBoard()->FindNet( m_NetCode ); - - return netinfo->GetShortNetname(); + return m_netinfo->GetShortNetname(); } diff --git a/pcbnew/class_board_connected_item.h b/pcbnew/class_board_connected_item.h index 9b2f5df7b8..b7a059c9f4 100644 --- a/pcbnew/class_board_connected_item.h +++ b/pcbnew/class_board_connected_item.h @@ -33,6 +33,7 @@ #include +class NETINFO_ITEM; class NETCLASS; class TRACK; class D_PAD; @@ -54,8 +55,6 @@ public: std::vector m_PadsConnected; // list of other pads connected to me private: - int m_NetCode; // Net number - int m_Subnet; /* In rastnest routines : for the current net, block number * (number common to the current connected items found) */ @@ -63,6 +62,9 @@ private: int m_ZoneSubnet; // used in rastnest computations : for the current net, // handle cluster number in zone connection + /// Stores all informations about the net that item belongs to + const NETINFO_ITEM* m_netinfo; + public: BOARD_CONNECTED_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ); @@ -72,15 +74,15 @@ public: * Function GetNet * @return int - the net code. */ - int GetNet() const - { - return m_NetCode; - } + int GetNet() const; - virtual void SetNet( int aNetCode ) - { - m_NetCode = aNetCode; - } + /** + * Function SetNet + * sets net using a net code. + * @param aNetCode is a net code for the new net. It has to exist in NETINFO_LIST held by BOARD. + * Otherwise, item is assigned to the unconnected net. + */ + void SetNet( int aNetCode ); /** * Function GetSubNet @@ -112,13 +114,13 @@ public: /** * Function GetNetname - * @return const wxString& - the full netname + * @return wxString - the full netname */ const wxString& GetNetname() const; /** * Function GetShortNetname - * @return const wxString& - the short netname + * @return wxString - the short netname */ const wxString& GetShortNetname() const; diff --git a/pcbnew/class_board_design_settings.cpp b/pcbnew/class_board_design_settings.cpp index e98dc81ef1..a24e6bf94e 100644 --- a/pcbnew/class_board_design_settings.cpp +++ b/pcbnew/class_board_design_settings.cpp @@ -52,7 +52,7 @@ BOARD_DESIGN_SETTINGS::BOARD_DESIGN_SETTINGS() : - m_Pad_Master( 0 ) + m_Pad_Master( NULL ) { m_EnabledLayers = ALL_LAYERS; // All layers enabled at first. // SetCopperLayerCount() will adjust this. diff --git a/pcbnew/class_netinfo.h b/pcbnew/class_netinfo.h index 8ea47c3676..3e836d0b95 100644 --- a/pcbnew/class_netinfo.h +++ b/pcbnew/class_netinfo.h @@ -202,6 +202,10 @@ public: ///> Constant that holds the unconnected net number static const int UNCONNECTED; + ///> NETINFO_ITEM meaning that there was no net assigned for an item, as there was no + ///> board storing net list available. + static const NETINFO_ITEM ORPHANED; + #if defined(DEBUG) void Show() const; #endif diff --git a/pcbnew/class_netinfolist.cpp b/pcbnew/class_netinfolist.cpp index 590cd352ce..e2f16a014b 100644 --- a/pcbnew/class_netinfolist.cpp +++ b/pcbnew/class_netinfolist.cpp @@ -164,4 +164,5 @@ void NETINFO_LIST::buildPadsFullList() } +const NETINFO_ITEM NETINFO_LIST::ORPHANED = NETINFO_ITEM( NULL, wxString( "orphaned" ), -1 ); const int NETINFO_LIST::UNCONNECTED = 0; diff --git a/pcbnew/class_zone.cpp b/pcbnew/class_zone.cpp index 941f95f3b5..cf5ab48ff7 100644 --- a/pcbnew/class_zone.cpp +++ b/pcbnew/class_zone.cpp @@ -53,7 +53,6 @@ ZONE_CONTAINER::ZONE_CONTAINER( BOARD* aBoard ) : BOARD_CONNECTED_ITEM( aBoard, PCB_ZONE_AREA_T ) { - SetNet( -1 ); // Net number for fast comparisons m_CornerSelection = -1; m_IsFilled = false; // fill status : true when the zone is filled m_FillMode = 0; // How to fill areas: 0 = use filled polygons, != 0 fill with segments diff --git a/pcbnew/eagle_plugin.cpp b/pcbnew/eagle_plugin.cpp index cc60db125f..078600f081 100644 --- a/pcbnew/eagle_plugin.cpp +++ b/pcbnew/eagle_plugin.cpp @@ -1879,7 +1879,7 @@ void EAGLE_PLUGIN::orientModuleText( MODULE* m, const EELEMENT& e, MODULE* EAGLE_PLUGIN::makeModule( CPTREE& aPackage, const string& aPkgName ) const { - std::auto_ptr m( new MODULE( NULL ) ); + std::auto_ptr m( new MODULE( m_board ) ); m->SetFPID( FPID( aPkgName ) ); @@ -2351,6 +2351,7 @@ void EAGLE_PLUGIN::loadSignals( CPTREE& aSignals ) const string& nname = net->second.get( ".name" ); wxString netName = FROM_UTF8( nname.c_str() ); + m_board->AppendNet( new NETINFO_ITEM( m_board, netName, netCode ) ); m_xpath->Value( nname.c_str() ); @@ -2555,7 +2556,7 @@ void EAGLE_PLUGIN::loadSignals( CPTREE& aSignals ) // therefore omit this signal/net. } else - m_board->AppendNet( new NETINFO_ITEM( m_board, netName, netCode++ ) ); + netCode++; } m_xpath->pop(); // "signals.signal" diff --git a/pcbnew/pcb_parser.cpp b/pcbnew/pcb_parser.cpp index b05ce179f2..db9ed25acf 100644 --- a/pcbnew/pcb_parser.cpp +++ b/pcbnew/pcb_parser.cpp @@ -1731,7 +1731,7 @@ MODULE* PCB_PARSER::parseMODULE( wxArrayString* aInitialComments ) throw( IO_ERR case T_pad: { - D_PAD* pad = parseD_PAD(); + D_PAD* pad = parseD_PAD( module.get() ); wxPoint pt = pad->GetPos0(); RotatePoint( &pt, module->GetOrientation() ); pad->SetPosition( pt + module->GetPosition() ); @@ -2011,14 +2011,14 @@ EDGE_MODULE* PCB_PARSER::parseEDGE_MODULE() throw( IO_ERROR, PARSE_ERROR ) } -D_PAD* PCB_PARSER::parseD_PAD() throw( IO_ERROR, PARSE_ERROR ) +D_PAD* PCB_PARSER::parseD_PAD( MODULE* aParent ) throw( IO_ERROR, PARSE_ERROR ) { wxCHECK_MSG( CurTok() == T_pad, NULL, wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as D_PAD." ) ); wxSize sz; wxPoint pt; - std::auto_ptr< D_PAD > pad( new D_PAD( NULL ) ); + std::auto_ptr< D_PAD > pad( new D_PAD( aParent ) ); NeedSYMBOLorNUMBER(); pad->SetPadName( FromUTF8() ); diff --git a/pcbnew/pcb_parser.h b/pcbnew/pcb_parser.h index 233acb1291..0dfb0bbdc5 100644 --- a/pcbnew/pcb_parser.h +++ b/pcbnew/pcb_parser.h @@ -99,7 +99,7 @@ class PCB_PARSER : public PCB_LEXER MODULE* parseMODULE( wxArrayString* aInitialComments = 0 ) throw( IO_ERROR, PARSE_ERROR ); TEXTE_MODULE* parseTEXTE_MODULE() throw( IO_ERROR, PARSE_ERROR ); EDGE_MODULE* parseEDGE_MODULE() throw( IO_ERROR, PARSE_ERROR ); - D_PAD* parseD_PAD() throw( IO_ERROR, PARSE_ERROR ); + D_PAD* parseD_PAD( MODULE* aParent = NULL ) throw( IO_ERROR, PARSE_ERROR ); TRACK* parseTRACK() throw( IO_ERROR, PARSE_ERROR ); SEGVIA* parseSEGVIA() throw( IO_ERROR, PARSE_ERROR ); ZONE_CONTAINER* parseZONE_CONTAINER() throw( IO_ERROR, PARSE_ERROR );