[KiCad 8] Added abstraction for Properties vs Fields
Now footprint properties are PCB_FIELDS
This commit is contained in:
parent
048ca3d158
commit
0c03f33912
|
|
@ -1109,7 +1109,7 @@ class PcbPlotter():
|
|||
value = footprint.GetValue().strip()
|
||||
if not LEGACY_KICAD:
|
||||
# Look for a tolerance in the properties
|
||||
prop = footprint.GetProperties()
|
||||
prop = GS.get_fields(footprint)
|
||||
tol = next(filter(lambda x: x, map(prop.get, GS.global_field_tolerance)), None)
|
||||
if tol:
|
||||
value = value+' '+tol.strip()
|
||||
|
|
|
|||
23
kibot/gs.py
23
kibot/gs.py
|
|
@ -855,3 +855,26 @@ class GS(object):
|
|||
def write_to_file(content, name):
|
||||
with GS.create_file(name, bin=isinstance(content, bytes)) as f:
|
||||
f.write(content)
|
||||
|
||||
@staticmethod
|
||||
def get_fields(footprint):
|
||||
""" Returns a dict with the field/value for the fields in a FOOTPRINT (aka MODULE) """
|
||||
if GS.ki8:
|
||||
# KiCad 8 defines a special object (PCB_FIELD) and its iterator
|
||||
return {f.GetName(): f.GetText() for f in footprint.GetFields()}
|
||||
if GS.ki6:
|
||||
return footprint.GetProperties()
|
||||
# KiCad 5 didn't have fields in the modules
|
||||
return {}
|
||||
|
||||
@staticmethod
|
||||
def set_fields(footprint, flds):
|
||||
""" Sets the fields in a FOOTPRINT (aka MODULE) from a dict """
|
||||
if GS.ki8:
|
||||
new_fields = [fld for fld in flds.keys() if not footprint.HasField(fld)]
|
||||
footprint.SetFields(flds)
|
||||
# New fields are added as visible, so we must hide them (OMG!)
|
||||
for fld in new_fields:
|
||||
footprint.GetFieldByName(fld).SetVisible(False)
|
||||
elif GS.ki6:
|
||||
footprint.SetProperties(flds)
|
||||
|
|
|
|||
|
|
@ -301,8 +301,7 @@ def create_component_from_footprint(m, ref):
|
|||
f.number = 3
|
||||
c.add_field(f)
|
||||
# Other fields
|
||||
if GS.ki6:
|
||||
for name, val in m.GetProperties().items():
|
||||
for name, val in GS.get_fields(m).items():
|
||||
f = SchematicField()
|
||||
f.name = name
|
||||
f.value = val
|
||||
|
|
|
|||
|
|
@ -869,22 +869,16 @@ class VariantOptions(BaseOptions):
|
|||
ref = m.GetReference()
|
||||
comp = comps_hash.get(ref, None)
|
||||
if comp is not None:
|
||||
properties = {f.name: f.value for f in comp.fields}
|
||||
old_value = m.GetValue()
|
||||
m.SetValue(properties['Value'])
|
||||
if GS.ki6:
|
||||
old_properties = m.GetProperties()
|
||||
m.SetProperties(properties)
|
||||
if has_GetFPIDAsString:
|
||||
old_fields = GS.get_fields(m)
|
||||
# Introduced in 6.0.6
|
||||
old_fp = m.GetFPIDAsString()
|
||||
m.SetFPIDAsString(properties['Footprint'])
|
||||
data = (old_value, old_properties, old_fp)
|
||||
else:
|
||||
data = (old_value, old_properties)
|
||||
else:
|
||||
data = old_value
|
||||
self.sch_fields_to_pcb_bkp[ref] = data
|
||||
old_fp = m.GetFPIDAsString() if has_GetFPIDAsString else None
|
||||
fields = {f.name: f.value for f in comp.fields}
|
||||
GS.set_fields(m, fields)
|
||||
m.SetValue(fields['Value'])
|
||||
if has_GetFPIDAsString:
|
||||
m.SetFPIDAsString(fields['Footprint'])
|
||||
self.sch_fields_to_pcb_bkp[ref] = (old_value, old_fields, old_fp)
|
||||
self._has_GetFPIDAsString = has_GetFPIDAsString
|
||||
|
||||
def restore_sch_fields_to_pcb(self, board):
|
||||
|
|
@ -894,13 +888,10 @@ class VariantOptions(BaseOptions):
|
|||
ref = m.GetReference()
|
||||
data = self.sch_fields_to_pcb_bkp.get(ref, None)
|
||||
if data is not None:
|
||||
if GS.ki6:
|
||||
m.SetValue(data[0])
|
||||
m.SetProperties(data[1])
|
||||
if has_GetFPIDAsString:
|
||||
m.SetFPIDAsString(data[2])
|
||||
else:
|
||||
m.SetValue(data)
|
||||
GS.set_fields(m, data[1])
|
||||
|
||||
def save_tmp_board(self, dir=None):
|
||||
""" Save the PCB to a temporal file.
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ class Update_XML(BasePreFlight): # noqa: F821
|
|||
excluded = set()
|
||||
for m in GS.get_modules():
|
||||
ref = m.GetReference()
|
||||
pcb_props = m.GetProperties()
|
||||
pcb_props = GS.get_fields(m)
|
||||
found_comps.add(ref)
|
||||
if ref not in comps:
|
||||
if GS.ki6_only and pcb_props.get('exclude_from_bom') is not None:
|
||||
|
|
|
|||
Loading…
Reference in New Issue