QA: PCB Fields bug fixes

This commit is contained in:
Mike Williams 2023-06-19 14:40:54 -04:00
parent 85f889bc19
commit 85c633eb00
3 changed files with 34 additions and 26 deletions

View File

@ -332,6 +332,11 @@ constexpr bool IsInstantiableType( const KICAD_T aType )
case SCH_SYMBOL_LOCATE_POWER_T:
case PCB_FIELD_LOCATE_REFERENCE_T:
case PCB_FIELD_LOCATE_VALUE_T:
case PCB_FIELD_LOCATE_FOOTPRINT_T:
case PCB_FIELD_LOCATE_DATASHEET_T:
case PCB_LOCATE_STDVIA_T:
case PCB_LOCATE_UVIA_T:
case PCB_LOCATE_BBVIA_T:
@ -448,6 +453,10 @@ constexpr bool IsPcbnewType( const KICAD_T aType )
case PCB_NETINFO_T:
case PCB_GROUP_T:
case PCB_FIELD_LOCATE_REFERENCE_T:
case PCB_FIELD_LOCATE_VALUE_T:
case PCB_FIELD_LOCATE_FOOTPRINT_T:
case PCB_FIELD_LOCATE_DATASHEET_T:
case PCB_LOCATE_STDVIA_T:
case PCB_LOCATE_UVIA_T:
case PCB_LOCATE_BBVIA_T:

View File

@ -30,9 +30,8 @@
%template(MAP_STRING_STRING) std::map<wxString, wxString>;
%rename(GetPropertiesNative) FOOTPRINT::GetProperties;
%rename(GetPropertyNative) FOOTPRINT::GetProperty;
%rename(SetPropertiesNative) FOOTPRINT::SetProperties;
%rename(GetFieldsNative) FOOTPRINT::GetFields;
%rename(SetFieldsNative) FOOTPRINT::SetFields;
%feature("flatnested");
%include footprint.h
%feature("flatnested", "");
@ -61,24 +60,24 @@
# the object in the garbage collector
#
def GetProperties(self):
""" Returns footprint properties map. """
properties = self.GetPropertiesNative()
return {str(k): str(v) for k, v in properties.items()}
def GetFields(self):
""" Returns footprint fields map. """
fields = self.GetFieldsNative()
return {str(k): str(v) for k, v in fields.items()}
def GetProperty(self, key):
""" Returns property with a given key if it exists, throws KeyError otherwise. """
if self.HasProperty(key):
return self.GetPropertyNative(key)
def GetField(self, key):
""" Returns Field with a given key if it exists, throws KeyError otherwise. """
if self.HasField(key):
return self.GetFieldByName(key)
else:
raise KeyError("Property not found: " + key)
raise KeyError("Field not found: " + key)
def SetProperties(self, properties):
""" Sets footprint properties map. """
wxproperties = MAP_STRING_STRING()
for k, v in properties.items():
wxproperties[k] = v
self.SetPropertiesNative(wxproperties)
def SetFields(self, fields):
""" Sets footprint fields map. """
wxfields = MAP_STRING_STRING()
for k, v in fields.items():
wxfields[k] = v
self.SetFieldsNative(wxfields)
%}
}

View File

@ -123,15 +123,15 @@ class TestBoardClass:
def test_footprint_properties(self):
pcb = LoadBoard("../data/pcbnew/custom_fields.kicad_pcb")
footprint = pcb.FindFootprintByReference('J1')
expected_properties = {
expected_fields = {
'Sheet file': 'custom_fields.kicad_sch',
'Sheet name': '',
'myfield': 'myvalue'
}
assert footprint.GetProperties() == expected_properties
assert footprint.GetProperty('myfield') == 'myvalue'
assert footprint.HasProperty('myfield') == True
assert footprint.HasProperty('abcd') == False
footprint.SetProperty('abcd', 'efgh')
assert footprint.HasProperty('abcd') == True
assert footprint.GetProperty('abcd') == 'efgh'
assert footprint.GetFields() == expected_fields
assert footprint.GetField('myfield') == 'myvalue'
assert footprint.HasField('myfield') == True
assert footprint.HasField('abcd') == False
footprint.SetField('abcd', 'efgh')
assert footprint.HasField('abcd') == True
assert footprint.GetField('abcd') == 'efgh'