← Back to team overview

kicad-developers team mailing list archive

Re: Net names and net codes

 

Le 08/01/2014 15:35, Maciej Sumiński a écrit :
> 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?

Net names come from the netlist created by the schematic.
Because a netlist knows only pads numbers, net names are stored in pads,
to handle netlist info.

A net code is a number only for internal use, equivalent to the net
name, and used to compare, sort ... nets (just because compare 2 numbers
is faster ans easier than compare 2 strings.

The net code is only for internal use, and has no meaning outside pcbnew.

Zones store a net name because they are connected to a net name which
comes from the netlist.

(An issue happen when this net name does not exist after a schematic
change, and the user should edit this zone when it net name is lost.

By the way, Pcbnew currently crashes in RN_LINKS::AddNode(), when
reading a board which contains a zone which has a non existent net name,
i.e. which has a net code = -1)

Tracks do not store the net name but just the net code, because they are
expected to be connected to pads which store this info.
(this is the reason tracks and vias not connected to a pad lose their
net after loading a board, or reading a netlist)
Therefore, after loading a board, or reading a netlist, the track net
code should be initialized, but you have to store this net name in pads.
(Of course, one can use an other way to store net names, and an other
way to calculate net codes)

Therefore net names cannot be easily removed from pads, unless rewriting
the way net codes are set from net names.
I do not know if rewriting that is worth (nad I do not see an advantage
to change this).

However zones should store a net name anyway, because the user set a
zone net name, not a zone net code (which is not equivalent, after
schematic changes, because netlists do not store info for zones).

Having both GetNetname() and GetNetName() is certainly a bug. One is enough.

The "short" net name is only used to display the net name. It could be
computed on the fly from the "full" net name (which includes the sheet
path).
It exists only for computing time reasons, to display the net name in
pads on screen.
(m_ShortNetname can be removed, if the cost to calculate it is small)

> 
> 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
> 
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp
> 


-- 
Jean-Pierre CHARRAS


Follow ups

References