diff --git a/KiBOM/component.py b/KiBOM/component.py index cc127683..fb7923ef 100644 --- a/KiBOM/component.py +++ b/KiBOM/component.py @@ -54,7 +54,7 @@ class Component(): if pn1 == pn2: return True #compare part aliases e.g. "c" to "c_small" - for alias in ALIASES: + for alias in self.prefs.aliases: if pn1 in alias and pn2 in alias: return True diff --git a/KiBOM/netlist_reader.py b/KiBOM/netlist_reader.py index 83ae9b25..41e03c91 100644 --- a/KiBOM/netlist_reader.py +++ b/KiBOM/netlist_reader.py @@ -26,15 +26,6 @@ from sort import natural_sort from preferences import BomPref -# When comparing part names, components will match if they are both elements of the -# same set defined here -ALIASES = [ - ["c", "c_small", "cap", "capacitor"], - ["r", "r_small", "res", "resistor"], - ["sw", "switch"], - ["l, l_small", "inductor"] - ] - #-------------------------------------------------------------------- class xmlElement(): diff --git a/KiBOM/preferences.py b/KiBOM/preferences.py index 830cfd2e..f310c677 100644 --- a/KiBOM/preferences.py +++ b/KiBOM/preferences.py @@ -15,6 +15,7 @@ class BomPref: SECTION_EXCLUDE_VALUES = "EXCLUDE_COMPONENT_VALUES" SECTION_EXCLUDE_REFS = "EXCLUDE_COMPONENT_REFS" SECTION_EXCLUDE_FP = "EXCLUDE_COMPONENT_FP" + SECTION_ALIASES = "COMPONENT_ALIASES" OPT_IGNORE_DNF = "ignore_dnf" OPT_NUMBER_ROWS = "number_rows" @@ -46,6 +47,14 @@ class BomPref: #default footprint exclusions self.excluded_footprints = [ ] + + #default component groupings + self.aliases = [ + ["c", "c_small", "cap", "capacitor"], + ["r", "r_small", "res", "resistor"], + ["sw", "switch"], + ["l", "l_small", "inductor"] + ] #read KiBOM preferences from file def Read(self, file, verbose=False): @@ -71,6 +80,23 @@ class BomPref: #read out ignored-rows if self.SECTION_IGNORE in cf.sections(): self.ignore = [i for i in cf.options(self.SECTION_IGNORE)] + + #read out excluded values + if self.SECTION_EXCLUDE_VALUES in cf.sections(): + self.excludedValues = [e for e in cf.options(self.SECTION_EXCLUDE_VALUES)] + + #read out excluded values + if self.SECTION_EXCLUDE_REFS in cf.sections(): + self.excludedValues = [e for e in cf.options(self.SECTION_EXCLUDE_REFS)] + + #read out excluded values + if self.SECTION_EXCLUDE_FP in cf.sections(): + self.excludedValues = [e for e in cf.options(self.SECTION_EXCLUDE_FP)] + + #read out component aliases + if self.SECTION_ALIASES in cf.sections(): + self.aliases = [a.split(" ") for a in cf.options(self.SECTION_ALIASES)] + #write KiBOM preferences to file def Write(self, file): @@ -112,5 +138,12 @@ class BomPref: for e in self.excluded_footprints: cf.set(self.SECTION_EXCLUDE_FP, e) + cf.add_section(self.SECTION_ALIASES) + cf.set(self.SECTION_ALIASES, "; A series of values which are considered to be equivalent for the part name") + cf.set(self.SECTION_ALIASES, "; Each line represents a space-separated list of equivalent component name values") + cf.set(self.SECTION_ALIASES, "; e.g. 'c c_small cap' will ensure the equivalent capacitor symbols can be grouped together") + for a in self.aliases: + cf.set(self.SECTION_ALIASES, " ".join(a)) + with open(file, 'wb') as configfile: cf.write(configfile) \ No newline at end of file