Commit d62b47a0 authored by Maciej Suminski's avatar Maciej Suminski
Browse files

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
Loading
Loading
Loading
Loading
+1 −2
Original line number Original line Diff line number Diff line
@@ -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 )
    {
    {
    }
    }


+2 −1
Original line number Original line Diff line number Diff line
@@ -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 );
                        }
                        }


+26 −10
Original line number Original line Diff line number Diff line
@@ -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();
}
}




+14 −12
Original line number Original line Diff line number Diff line
@@ -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:
    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:
    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:
     * 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:


    /**
    /**
     * 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;


+1 −1
Original line number Original line Diff line number Diff line
@@ -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.
Loading