From 4a8bea998787b969093e4e9cf0c437830a4ab246 Mon Sep 17 00:00:00 2001 From: Matt Mets Date: Mon, 14 Nov 2022 13:43:19 +0100 Subject: [PATCH] PCB library: add parts * Rectangular footprint for TK-1 test pads * BOM generation script used for TK-1 and TP-1 releases --- .../bom_csv_grouped_by_extended_value.py | 113 ++++++++++++++++++ .../TestPoint_Pad_D1.0mm.kicad_mod | 28 +++++ 2 files changed, 141 insertions(+) create mode 100644 hw/boards/mta1-library/bom_csv_grouped_by_extended_value.py create mode 100644 hw/boards/mta1-library/mta1.pretty/TestPoint_Pad_D1.0mm.kicad_mod diff --git a/hw/boards/mta1-library/bom_csv_grouped_by_extended_value.py b/hw/boards/mta1-library/bom_csv_grouped_by_extended_value.py new file mode 100644 index 0000000..dc6cf03 --- /dev/null +++ b/hw/boards/mta1-library/bom_csv_grouped_by_extended_value.py @@ -0,0 +1,113 @@ +# +# Example python script to generate a BOM from a KiCad generic netlist +# +# Example: Sorted and Grouped CSV BOM +# + +""" + @package + Output: CSV (comma-separated) + Grouped By: Value, Extended Value, Footprint + Sorted By: Ref + Fields: Ref, Qnty, Value, Footprint, Description, Manufacturer, Manufacturer Part Number + + Command line: + python "pathToFile/bom_csv_grouped_by_extended_value.py" "%I" "%O.csv" +""" + +# Import the KiCad python helper module and the csv formatter +import kicad_netlist_reader +import kicad_utils +import csv +import sys + +# A helper function to convert a UTF8/Unicode/locale string read in netlist +# for python2 or python3 +def fromNetlistText( aText ): + if sys.platform.startswith('win32'): + try: + return aText.encode('utf-8').decode('cp1252') + except UnicodeDecodeError: + return aText + else: + return aText + +# Group components if their value, extended value, footprint, and reference designator type (?) are the same +import string +def equate_value_extended_value_footprint(self, other): + """ Equivalency operator, remember this can be easily overloaded + 2 components are equivalent ( i.e. can be grouped + if they have same value and same footprint + + Override the component equivalence operator must be done before + loading the netlist, otherwise all components will have the original + equivalency operator. + + You have to define a comparison module (for instance named myEqu) + and add the line; + kicad_netlist_reader.comp.__eq__ = myEqu + in your bom generator script before calling the netliste reader by something like: + net = kicad_netlist_reader.netlist(sys.argv[1]) + """ + result = False + if self.getValue() == other.getValue(): + if self.getField("Extended Value") == other.getField("Extended Value"): + if self.getFootprint() == other.getFootprint(): + if self.getRef().rstrip(string.digits) == other.getRef().rstrip(string.digits): + result = True + return result + +kicad_netlist_reader.comp.__eq__ = equate_value_extended_value_footprint + +# Generate an instance of a generic netlist, and load the netlist tree from +# the command line option. If the file doesn't exist, execution will stop +net = kicad_netlist_reader.netlist(sys.argv[1]) + +# Open a file to write to, if the file cannot be opened output to stdout +# instead +try: + f = kicad_utils.open_file_write(sys.argv[2], 'w') +except IOError: + e = "Can't open output file for writing: " + sys.argv[2] + print(__file__, ":", e, sys.stderr) + f = sys.stdout + +# Create a new csv writer object to use as the output formatter +out = csv.writer(f, delimiter=',', lineterminator='\n', quotechar='\"', quoting=csv.QUOTE_ALL) + +# Output a set of rows for a header providing general information +out.writerow(['Source:', net.getSource()]) +out.writerow(['Date:', net.getDate()]) +out.writerow(['Tool:', net.getTool()]) +out.writerow( ['Generator:', sys.argv[0]] ) +out.writerow(['Component Count:', len(net.components)]) +out.writerow(['Ref', 'Qnty', 'Value', 'Footprint', 'Description', 'Manufacturer', 'Manufacturer Part Number', 'Supplier', 'Supplier Part Number']) + + +# Get all of the components in groups of matching parts + values +# (see ky_generic_netlist_reader.py) +grouped = net.groupComponents() + +# Output all of the component information +for group in grouped: + refs = ','.join([fromNetlistText( component.getRef() ) for component in group]) + c = group[-1] + + combinedvalue = c.getValue() + if c.getField("Extended Value") != '': + combinedvalue += ',' + c.getField("Extended Value") + + # Fill in the component groups common data + out.writerow([ + refs, + len(group), + combinedvalue, + fromNetlistText( c.getFootprint() ), + fromNetlistText( c.getDescription() ), + fromNetlistText( c.getField("Manufacturer") ), + fromNetlistText( c.getField("Manufacturer Part Number") ), + fromNetlistText( c.getField("Supplier") ), + fromNetlistText( c.getField("Supplier Part Number") ) + ]) + + diff --git a/hw/boards/mta1-library/mta1.pretty/TestPoint_Pad_D1.0mm.kicad_mod b/hw/boards/mta1-library/mta1.pretty/TestPoint_Pad_D1.0mm.kicad_mod new file mode 100644 index 0000000..0ad2aa5 --- /dev/null +++ b/hw/boards/mta1-library/mta1.pretty/TestPoint_Pad_D1.0mm.kicad_mod @@ -0,0 +1,28 @@ +(footprint "TestPoint_Pad_D1.0mm" (version 20211014) (generator pcbnew) + (layer "F.Cu") + (tedit 5A0F774F) + (descr "SMD pad as test Point, diameter 1.0mm") + (tags "test point SMD pad") + (attr exclude_from_pos_files exclude_from_bom) + (fp_text reference "REF**" (at 0 -2) (layer "F.SilkS") + (effects (font (size 1 1) (thickness 0.15))) + (tstamp ed08342a-eaee-43e9-b96e-1dd00b47763e) + ) + (fp_text value "TestPoint_rect1_1.6" (at 0 2) (layer "F.Fab") + (effects (font (size 1 1) (thickness 0.15))) + (tstamp a41410ba-6764-40d3-8271-3889cd1f68dc) + ) + (fp_text user "${REFERENCE}" (at 0 -2) (layer "F.Fab") + (effects (font (size 1 1) (thickness 0.15))) + (tstamp ecb9d95d-c3e5-4a80-b7be-d742b8cad331) + ) + (fp_line (start 0.7 1) (end -0.7 1) (layer "F.SilkS") (width 0.12) (tstamp 0f426fa1-fc2f-405a-ad53-6e830f7ee04b)) + (fp_line (start -0.7 1) (end -0.7 -1) (layer "F.SilkS") (width 0.12) (tstamp 0f47421c-1e82-4036-b8e8-a06d02b43b87)) + (fp_line (start -0.7 -1) (end 0.7 -1) (layer "F.SilkS") (width 0.12) (tstamp 3bad0292-560e-4959-9af2-db7bbf622092)) + (fp_line (start 0.7 -1) (end 0.7 1) (layer "F.SilkS") (width 0.12) (tstamp f094a04e-97d3-4bf8-800d-8371147afe46)) + (fp_line (start 0.9 1.2) (end -0.9 1.2) (layer "F.CrtYd") (width 0.05) (tstamp 37081654-8f99-4a40-95a5-cb89ab90304e)) + (fp_line (start -0.9 -1.2) (end 0.9 -1.2) (layer "F.CrtYd") (width 0.05) (tstamp 97660885-3db5-4ad6-a54d-91f2fd79e84a)) + (fp_line (start -0.9 1.2) (end -0.9 -1.2) (layer "F.CrtYd") (width 0.05) (tstamp df586b02-02b3-429d-a0c0-fe4a87110a37)) + (fp_line (start 0.9 -1.2) (end 0.9 1.2) (layer "F.CrtYd") (width 0.05) (tstamp e2dc4785-3e17-472a-82b9-5050a49344b6)) + (pad "1" smd roundrect (at 0 0) (size 1 1.6) (layers "F.Cu" "F.Mask") (roundrect_rratio 0.25) (tstamp bab732e9-e79a-410d-8a2b-e7d9e8d299bb)) +)