← Back to team overview

kicad-developers team mailing list archive

Net names and net codes

 

I am wondering if there are any special reasons to keep net names and net codes separated. This gives programmer a chance to set a net code that is actually not related to the appropriate net name. One is even able to set a net name that does not exist using D_PAD::SetNetname() for a single pad or a group of pads.
I have seen that in many places there are pairs of functions:
item->SetNet( .. );
item->SetNetname( .. );
but if I recall correctly, that is not always the case.

Also, net names are kept (and directly available) only for some specific classes (D_PAD, ZONE_CONTAINER, they are delivered via different functions - respectively GetNetname() and GetNetName()) but not all BOARD_CONNECTED_ITEMs (TRACK and its derivatives does not contain this information). For classes that miss net name, there can be used NETINFO_ITEM, which stores both net code and net name. Again, question arises - is it done on purpose?

Another thing that I observed is that net codes may be subject to change during edition of a board (I guess it happens when you remove all pads that belong to a single net). As I understand, it is to keep net codes consecutive, but it also disallows to reliably index items using their net codes. Is the only right way to index items by nets is to use their net names?

As I am not as familiar with the KiCad's core as you are, then I would like to ask what do you think of: - removing m_Netname & m_ShortNetname fields from D_PAD and m_Netname from ZONE_CONTAINER

- use net codes to refer to a specific NETINFO_ITEMs, that actually store useful informations for nets

- adding something similar to (it actually exists in the code as ZONE_CONTAINER::SetNetNameFromNetCode()):
wxString BOARD_CONNECTED_ITEM::GetNetname() const
{
    BOARD* board = GetBoard();
    if( board == NULL )
        return wxString( "" );

    NETINFO_ITEM* netinfo = board->FindNet( m_NetCode );
    if( netinfo == NULL )
        return wxString( "" );

    return netinfo->GetNetname();
}


wxString BOARD_CONNECTED_ITEM::GetShortNetname() const
{
    BOARD* board = GetBoard();
    if( board == NULL )
        return wxString( "" );

    NETINFO_ITEM* netinfo = board->FindNet( m_NetCode );
    if( netinfo == NULL )
        return wxString( "" );

    return netinfo->GetShortNetname();
}

or improve it to make it faster, if it is necessary.

Regards,
Orson


Follow ups