SCH_SYMBOL's GetFields() VS LIB_SYMBOL's GetFields(std::vector<LIB_FIELD>& aList)

We’re using code to GetFields. From the demo project “flat_hierarchy.kicad_pro”, we can get the KiCAD netlist. The following is only part of the netlist file.

(comp (ref "U4")
  (value "LT1373")
  (footprint "Package_DIP:DIP-8_W7.62mm_LongPads")
  (datasheet "http://www.google.com")
  (fields
    (field (name "Field4") "1111")
    (field (name "Field5") "2222")
    (field (name "Sim_Device") "R")
    (field (name "Sim_Pins") "1 2"))
  (libsource (lib "flat_hierarchy_schlib") (part "LT1373") (description ""))
  (property (name "Field4") (value "1111"))
  (property (name "Field5") (value "2222"))
  (property (name "Sim_Device") (value "R"))
  (property (name "Sim_Pins") (value "1 2"))
  (property (name "Sheetname") (value "pic_programmer"))
  (property (name "Sheetfile") (value "File: pic_programmer.kicad_sch"))
  (sheetpath (names "/pic_programmer/") (tstamps "/00000000-0000-0000-0000-000048553e53/"))
  (tstamps "00000000-0000-0000-0000-0000442a5e20"))
  
(libpart (lib "flat_hierarchy_schlib") (part "LT1373")
  (fields
    (field (name "Reference") "U")
    (field (name "Value") "LT1373"))
  (pins
    (pin (num "1") (name "Vc") (type "input"))
    (pin (num "2") (name "FB+") (type "input"))
    (pin (num "3") (name "FB-") (type "passive"))
    (pin (num "4") (name "S/S") (type "passive"))
    (pin (num "5") (name "Vin") (type "power_in"))
    (pin (num "6") (name "GND_S") (type "input"))
    (pin (num "7") (name "GND") (type "input"))
    (pin (num "8") (name "Vsw") (type "input"))))      

The following code sym->GetFields could get the all fields of “comp” section. The Field4, Field5, Sim_Device, and Sim_Pins are in the “fields” part in the “comp” section; however, the ref, value, footprint, and datasheet are not in the “fields” part in the “comp” section.
SCH_SYMBOL* sym;
sym->GetFields(): field is Reference
sym->GetFields(): field is Value
sym->GetFields(): field is Footprint
sym->GetFields(): field is Datasheet
sym->GetFields(): field is Field4
sym->GetFields(): field is Field5
sym->GetFields(): field is Sim_Device
sym->GetFields(): field is Sim_Pins

The code sym->GetLibSymbolRef()->GetFields(fields_in_libpart) allways get the same four fields: Reference, Value, Footprint, Datasheet. However, Footprint and Datasheet are not in the “fields” part in the “libpart” section (Since there is a statement “if( !field->GetText().IsEmpty()” which keeps Footprint and Datasheet fields out due to they are empty. )
).
sym->GetLibSymbolRef()->GetFields(fields_in_libpart): field.GetName() is Reference
sym->GetLibSymbolRef()->GetFields(fields_in_libpart): field.GetFullText() is U?
sym->GetLibSymbolRef()->GetFields(fields_in_libpart): field.GetName() is Value
sym->GetLibSymbolRef()->GetFields(fields_in_libpart): field.GetFullText() is LT1373
sym->GetLibSymbolRef()->GetFields(fields_in_libpart): field.GetName() is Footprint
sym->GetLibSymbolRef()->GetFields(fields_in_libpart): field.GetFullText is
sym->GetLibSymbolRef()->GetFields(fields_in_libpart): field.GetName() is Datasheet
sym->GetLibSymbolRef()->GetFields(fields_in_libpart): field.GetFullText is

It seems that the results of the code are consistent with the symbol’s GUI content, at least for the SCH_SYMBOL’s GetFields().

After adding “MyAddedField” (We’re thinking this is LIB_SYMBOL’s field.), the new exported KiCAD’s netlist file is not updated with the new added “MyAddedField” field in “libpart” section.

I am comfused about the GetFields(…).

Our version info is as following.

Application: KiCad

Version: (6.99.0-2955-gb2a2d66005-dirty), debug build

Libraries:
wxWidgets 3.0.5
FreeType 2.10.4
HarfBuzz 2.7.4
FontConfig 2.13.1
libcurl/7.74.0 OpenSSL/1.1.1k zlib/1.2.11 brotli/1.0.9 libidn2/2.3.0 libpsl/0.21.0 (+libidn2/2.3.0) libssh2/1.9.0 nghttp2/1.43.0 librtmp/2.3

Platform: Linux 5.10.0-9-amd64 x86_64, 64 bit, Little endian, wxGTK, gnome, wayland

Build Info:
Date: Sep 3 2022 00:08:21
wxWidgets: 3.0.5 (wchar_t,wx containers,compatible with 2.8) GTK+ 3.24
Boost: 1.74.0
OCC: 7.5.1
Curl: 7.74.0
ngspice: 31
Compiler: GCC 10.2.1 with C++ ABI 1014

Build settings:
KICAD_SPICE=ON
KICAD_STDLIB_DEBUG=OFF
KICAD_STDLIB_LIGHT_DEBUG=OFF
KICAD_SANITIZE_ADDRESS=OFF
KICAD_SANITIZE_THREADS=OFF

It’s hard to follow what exactly you are asking and what the code snippets have to do with anything but I think the main thing you are missing is that updating fields of a library symbol doesn’t automatically update components that are already on the schematic. You have to propagate those changes by updating symbols from library

image

It has options to deal specifically with fields

image

1 Like

Yes, that(“Update Symbols from Library…”) is what I was missing. This solved one of my question. Thanks @qu1ck

The other question is that the “ref”, “value”, “footprint” and “datasheet” are actually not in the fields’ range (based on the KiCAD’s netlist file as following part), but we could get them through calling “sym->GetFields()”.

(comp (ref "U4")
  (value "LT1373")
  (footprint "Package_DIP:DIP-8_W7.62mm_LongPads")
  (datasheet "http://www.google.com")
  (fields
    (field (name "Field4") "1111")

Those 4 fields are mandatory and due to legacy reasons are separately in the file format. But in the code they are treated more or less the same.

I’ve gotten it. Thank you @qu1ck.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.