Commit d62b47a0 authored by Maciej Suminski's avatar Maciej Suminski

BOARD_CONNECTED_ITEMs do not store net code anymore (m_NetCode field), instead...

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
parent 3017b617
...@@ -83,8 +83,7 @@ protected: ...@@ -83,8 +83,7 @@ protected:
public: public:
BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) : BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) :
EDA_ITEM( aParent, idtype ) EDA_ITEM( aParent, idtype ), m_Layer( FIRST_LAYER )
, m_Layer( FIRST_LAYER )
{ {
} }
......
...@@ -2571,7 +2571,8 @@ void BOARD::ReplaceNetlist( NETLIST& aNetlist, bool aDeleteSinglePadNets, ...@@ -2571,7 +2571,8 @@ 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(), m_NetInfo.GetNetCount() ); netinfo = new NETINFO_ITEM( this, net.GetNetName(),
m_NetInfo.GetNetCount() );
m_NetInfo.AppendNet( netinfo ); m_NetInfo.AppendNet( netinfo );
} }
......
...@@ -34,34 +34,50 @@ ...@@ -34,34 +34,50 @@
#include <class_board.h> #include <class_board.h>
#include <class_board_item.h> #include <class_board_item.h>
BOARD_CONNECTED_ITEM::BOARD_CONNECTED_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) : 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_CONNECTED_ITEM::BOARD_CONNECTED_ITEM( const BOARD_CONNECTED_ITEM& aItem ) :
BOARD_ITEM( aItem ), m_NetCode( aItem.m_NetCode ), m_Subnet( aItem.m_Subnet ), BOARD_ITEM( aItem ), m_Subnet( aItem.m_Subnet ), m_ZoneSubnet( aItem.m_ZoneSubnet ),
m_ZoneSubnet( aItem.m_ZoneSubnet ) m_netinfo( aItem.m_netinfo )
{ {
} }
const wxString& BOARD_CONNECTED_ITEM::GetNetname() const int BOARD_CONNECTED_ITEM::GetNet() const
{
return m_netinfo->GetNet();
}
void BOARD_CONNECTED_ITEM::SetNet( int aNetCode )
{ {
BOARD* board = GetBoard(); BOARD* board = GetBoard();
NETINFO_ITEM* netinfo = board->FindNet( m_NetCode ); if( board )
{
m_netinfo = board->FindNet( aNetCode );
return netinfo->GetNetname(); if( m_netinfo == NULL )
m_netinfo = board->FindNet( NETINFO_LIST::UNCONNECTED );
}
} }
const wxString& BOARD_CONNECTED_ITEM::GetShortNetname() const const wxString& BOARD_CONNECTED_ITEM::GetNetname() const
{ {
NETINFO_ITEM* netinfo = GetBoard()->FindNet( m_NetCode ); return m_netinfo->GetNetname();
}
return netinfo->GetShortNetname();
const wxString& BOARD_CONNECTED_ITEM::GetShortNetname() const
{
return m_netinfo->GetShortNetname();
} }
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <class_board_item.h> #include <class_board_item.h>
class NETINFO_ITEM;
class NETCLASS; class NETCLASS;
class TRACK; class TRACK;
class D_PAD; class D_PAD;
...@@ -54,8 +55,6 @@ public: ...@@ -54,8 +55,6 @@ public:
std::vector<D_PAD*> m_PadsConnected; // list of other pads connected to me std::vector<D_PAD*> m_PadsConnected; // list of other pads connected to me
private: private:
int m_NetCode; // Net number
int m_Subnet; /* In rastnest routines : for the current net, block number int m_Subnet; /* In rastnest routines : for the current net, block number
* (number common to the current connected items found) * (number common to the current connected items found)
*/ */
...@@ -63,6 +62,9 @@ private: ...@@ -63,6 +62,9 @@ private:
int m_ZoneSubnet; // used in rastnest computations : for the current net, int m_ZoneSubnet; // used in rastnest computations : for the current net,
// handle cluster number in zone connection // handle cluster number in zone connection
/// Stores all informations about the net that item belongs to
const NETINFO_ITEM* m_netinfo;
public: public:
BOARD_CONNECTED_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ); BOARD_CONNECTED_ITEM( BOARD_ITEM* aParent, KICAD_T idtype );
...@@ -72,15 +74,15 @@ public: ...@@ -72,15 +74,15 @@ public:
* Function GetNet * Function GetNet
* @return int - the net code. * @return int - the net code.
*/ */
int GetNet() const int GetNet() const;
{
return m_NetCode;
}
virtual void SetNet( int aNetCode ) /**
{ * Function SetNet
m_NetCode = aNetCode; * 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 * Function GetSubNet
...@@ -112,13 +114,13 @@ public: ...@@ -112,13 +114,13 @@ public:
/** /**
* Function GetNetname * Function GetNetname
* @return const wxString& - the full netname * @return wxString - the full netname
*/ */
const wxString& GetNetname() const; const wxString& GetNetname() const;
/** /**
* Function GetShortNetname * Function GetShortNetname
* @return const wxString& - the short netname * @return wxString - the short netname
*/ */
const wxString& GetShortNetname() const; const wxString& GetShortNetname() const;
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
BOARD_DESIGN_SETTINGS::BOARD_DESIGN_SETTINGS() : BOARD_DESIGN_SETTINGS::BOARD_DESIGN_SETTINGS() :
m_Pad_Master( 0 ) m_Pad_Master( NULL )
{ {
m_EnabledLayers = ALL_LAYERS; // All layers enabled at first. m_EnabledLayers = ALL_LAYERS; // All layers enabled at first.
// SetCopperLayerCount() will adjust this. // SetCopperLayerCount() will adjust this.
......
...@@ -202,6 +202,10 @@ public: ...@@ -202,6 +202,10 @@ public:
///> Constant that holds the unconnected net number ///> Constant that holds the unconnected net number
static const int UNCONNECTED; 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) #if defined(DEBUG)
void Show() const; void Show() const;
#endif #endif
......
...@@ -164,4 +164,5 @@ void NETINFO_LIST::buildPadsFullList() ...@@ -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; const int NETINFO_LIST::UNCONNECTED = 0;
...@@ -53,7 +53,6 @@ ...@@ -53,7 +53,6 @@
ZONE_CONTAINER::ZONE_CONTAINER( BOARD* aBoard ) : ZONE_CONTAINER::ZONE_CONTAINER( BOARD* aBoard ) :
BOARD_CONNECTED_ITEM( aBoard, PCB_ZONE_AREA_T ) BOARD_CONNECTED_ITEM( aBoard, PCB_ZONE_AREA_T )
{ {
SetNet( -1 ); // Net number for fast comparisons
m_CornerSelection = -1; m_CornerSelection = -1;
m_IsFilled = false; // fill status : true when the zone is filled 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 m_FillMode = 0; // How to fill areas: 0 = use filled polygons, != 0 fill with segments
......
...@@ -1879,7 +1879,7 @@ void EAGLE_PLUGIN::orientModuleText( MODULE* m, const EELEMENT& e, ...@@ -1879,7 +1879,7 @@ void EAGLE_PLUGIN::orientModuleText( MODULE* m, const EELEMENT& e,
MODULE* EAGLE_PLUGIN::makeModule( CPTREE& aPackage, const string& aPkgName ) const MODULE* EAGLE_PLUGIN::makeModule( CPTREE& aPackage, const string& aPkgName ) const
{ {
std::auto_ptr<MODULE> m( new MODULE( NULL ) ); std::auto_ptr<MODULE> m( new MODULE( m_board ) );
m->SetFPID( FPID( aPkgName ) ); m->SetFPID( FPID( aPkgName ) );
...@@ -2351,6 +2351,7 @@ void EAGLE_PLUGIN::loadSignals( CPTREE& aSignals ) ...@@ -2351,6 +2351,7 @@ void EAGLE_PLUGIN::loadSignals( CPTREE& aSignals )
const string& nname = net->second.get<string>( "<xmlattr>.name" ); const string& nname = net->second.get<string>( "<xmlattr>.name" );
wxString netName = FROM_UTF8( nname.c_str() ); wxString netName = FROM_UTF8( nname.c_str() );
m_board->AppendNet( new NETINFO_ITEM( m_board, netName, netCode ) );
m_xpath->Value( nname.c_str() ); m_xpath->Value( nname.c_str() );
...@@ -2555,7 +2556,7 @@ void EAGLE_PLUGIN::loadSignals( CPTREE& aSignals ) ...@@ -2555,7 +2556,7 @@ void EAGLE_PLUGIN::loadSignals( CPTREE& aSignals )
// therefore omit this signal/net. // therefore omit this signal/net.
} }
else else
m_board->AppendNet( new NETINFO_ITEM( m_board, netName, netCode++ ) ); netCode++;
} }
m_xpath->pop(); // "signals.signal" m_xpath->pop(); // "signals.signal"
......
...@@ -1731,7 +1731,7 @@ MODULE* PCB_PARSER::parseMODULE( wxArrayString* aInitialComments ) throw( IO_ERR ...@@ -1731,7 +1731,7 @@ MODULE* PCB_PARSER::parseMODULE( wxArrayString* aInitialComments ) throw( IO_ERR
case T_pad: case T_pad:
{ {
D_PAD* pad = parseD_PAD(); D_PAD* pad = parseD_PAD( module.get() );
wxPoint pt = pad->GetPos0(); wxPoint pt = pad->GetPos0();
RotatePoint( &pt, module->GetOrientation() ); RotatePoint( &pt, module->GetOrientation() );
pad->SetPosition( pt + module->GetPosition() ); pad->SetPosition( pt + module->GetPosition() );
...@@ -2011,14 +2011,14 @@ EDGE_MODULE* PCB_PARSER::parseEDGE_MODULE() throw( IO_ERROR, PARSE_ERROR ) ...@@ -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, wxCHECK_MSG( CurTok() == T_pad, NULL,
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as D_PAD." ) ); wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as D_PAD." ) );
wxSize sz; wxSize sz;
wxPoint pt; wxPoint pt;
std::auto_ptr< D_PAD > pad( new D_PAD( NULL ) ); std::auto_ptr< D_PAD > pad( new D_PAD( aParent ) );
NeedSYMBOLorNUMBER(); NeedSYMBOLorNUMBER();
pad->SetPadName( FromUTF8() ); pad->SetPadName( FromUTF8() );
......
...@@ -99,7 +99,7 @@ class PCB_PARSER : public PCB_LEXER ...@@ -99,7 +99,7 @@ class PCB_PARSER : public PCB_LEXER
MODULE* parseMODULE( wxArrayString* aInitialComments = 0 ) throw( IO_ERROR, PARSE_ERROR ); MODULE* parseMODULE( wxArrayString* aInitialComments = 0 ) throw( IO_ERROR, PARSE_ERROR );
TEXTE_MODULE* parseTEXTE_MODULE() throw( IO_ERROR, PARSE_ERROR ); TEXTE_MODULE* parseTEXTE_MODULE() throw( IO_ERROR, PARSE_ERROR );
EDGE_MODULE* parseEDGE_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 ); TRACK* parseTRACK() throw( IO_ERROR, PARSE_ERROR );
SEGVIA* parseSEGVIA() throw( IO_ERROR, PARSE_ERROR ); SEGVIA* parseSEGVIA() throw( IO_ERROR, PARSE_ERROR );
ZONE_CONTAINER* parseZONE_CONTAINER() throw( IO_ERROR, PARSE_ERROR ); ZONE_CONTAINER* parseZONE_CONTAINER() throw( IO_ERROR, PARSE_ERROR );
......
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