aboutsummaryrefslogtreecommitdiff
path: root/src/ee/tools
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2017-12-12 12:02:29 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2017-12-15 07:30:35 +0100
commit102614dc8fe2f5aefd0fd92c1b6e48107a9629b0 (patch)
tree341436f8afc4a29819e59b199eb629a80ffd2df0 /src/ee/tools
parent6cd194703674268b313918b590f2bc483c641efa (diff)
downloadee-python-102614dc8fe2f5aefd0fd92c1b6e48107a9629b0.tar.gz
ee-python-102614dc8fe2f5aefd0fd92c1b6e48107a9629b0.tar.bz2
ee-python-102614dc8fe2f5aefd0fd92c1b6e48107a9629b0.tar.xz
ee-python-102614dc8fe2f5aefd0fd92c1b6e48107a9629b0.zip
o Adding a kicad-make-pos tool.
Diffstat (limited to 'src/ee/tools')
-rw-r--r--src/ee/tools/kicad_make_pos.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/ee/tools/kicad_make_pos.py b/src/ee/tools/kicad_make_pos.py
new file mode 100644
index 0000000..cd381a5
--- /dev/null
+++ b/src/ee/tools/kicad_make_pos.py
@@ -0,0 +1,56 @@
+import sys
+import argparse
+import csv
+from . import mk_parents
+from ..kicad import pcb, parse_ref
+from .._utils import run_filters
+
+parser = argparse.ArgumentParser(description="Create a pick and place file from a KiCAD schematic")
+
+parser.add_argument("--kicad-pcb",
+ required=True,
+ dest="pcb",
+ metavar="PCB",
+ help="The pcb to read")
+
+parser.add_argument("--out",
+ metavar="FILE",
+ help="The output file")
+
+args = parser.parse_args()
+
+pcb = pcb.parse(args.pcb)
+
+def run(stream):
+ rows = []
+ for m in pcb.modules:
+ row = {}
+ ref_fp_text = next(m.filter_fp_text(kind = "reference"), None)
+ row["ref"] = ref= ref_fp_text and ref_fp_text.value
+ row["r"] = parse_ref(ref)
+ value_fp_text = next(m.filter_fp_text(kind = "value"), None)
+ row["value"] = value_fp_text and value_fp_text.value
+ (row["library"], row["footprint"]) = m.footprint.split(":")
+ (row["x"], row["y"], row["rot"]) = m.at
+ if m.layer == "F.Cu":
+ row["side"] = "top"
+ elif m.layer == "B.Cu":
+ row["side"] = "bottom"
+ else:
+ row["side"] = None
+ rows.append(row)
+
+ rows = sorted(rows, key=lambda row: row["r"])
+
+ out = csv.writer(stream)
+ out.writerow(["ref", "value", "library", "footprint", "x", "y", "rotation", "side"])
+ for row in rows:
+ del row["r"]
+ out.writerow(row.values())
+
+if args.out:
+ mk_parents(args.out)
+ with open(args.out, "w") as f:
+ run(f)
+else:
+ run(sys.stdout)