aboutsummaryrefslogtreecommitdiff
path: root/src/ee/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/tools')
-rwxr-xr-xsrc/ee/tools/kicad_gerber.py81
-rw-r--r--src/ee/tools/kicad_make_bom.py8
-rw-r--r--src/ee/tools/kicad_mkdeps.py78
3 files changed, 143 insertions, 24 deletions
diff --git a/src/ee/tools/kicad_gerber.py b/src/ee/tools/kicad_gerber.py
index be0e34d..7f15154 100755
--- a/src/ee/tools/kicad_gerber.py
+++ b/src/ee/tools/kicad_gerber.py
@@ -1,8 +1,29 @@
-#!/usr/bin/env python
+from __future__ import print_function
import sys
import os
import argparse
-from pcbnew import *
+
+try:
+ from pcbnew import *
+except ImportError:
+
+ ee_hack = os.environ.get("EE_HACK", "0")
+ print("ee_hack={}".format(ee_hack), file=sys.stderr)
+ try_p2 = sys.version_info.major == 2 and ee_hack != "1"
+ print("Could not import 'pcbnew' module. Make sure you run this command with KiCAD's python.", file=sys.stderr)
+
+ argv = sys.argv[1:]
+ cmd = "python2 {} {}".format(__file__, " ".join(argv))
+ print(cmd, file=sys.stderr)
+
+ import subprocess
+
+ subprocess.call("sleep 1", shell=True)
+ env = dict(os.environ)
+ env["EE_HACK"] = "1"
+ ret = subprocess.call(cmd, shell=True, env=env)
+ print("ret={}".format(ret), file=sys.stderr)
+ sys.exit(ret)
def layer_name_parser(s):
@@ -32,6 +53,11 @@ parser.add_argument('--detect-files-only',
action='store_true',
help='Don\'t create the GERBER files, just list the files to be created')
+parser.add_argument('-M',
+ dest='mkdep',
+ action='store_true',
+ help='Don\'t create the GERBER files, output a Makefile-compatible file')
+
parser.add_argument('--create-drill-map-file',
dest='create_drill_map_file',
action='store_true',
@@ -42,6 +68,11 @@ parser.add_argument('--protel-extensions',
action='store_true',
help='Use Protel filename extensions instead of .gbr')
+parser.add_argument('--extended-gerber-attributes',
+ dest='extended_gerber_attributes',
+ action='store_true',
+ help='Use extended Gerber attributes')
+
parser.add_argument('--uppercase-extensions',
action='store_true',
help='Uppercase all extensions')
@@ -101,7 +132,16 @@ for layerNum in layers.CuStack():
pctl = PLOT_CONTROLLER(board)
popt = pctl.GetPlotOptions()
-popt.SetOutputDirectory(args.output_directory)
+
+output_directory = args.output_directory
+popt.SetOutputDirectory(output_directory)
+
+if not os.path.isdir(output_directory):
+ try:
+ os.makedirs(output_directory)
+ except:
+ print("Could not make output directory", file=sys.stderr)
+ sys.exit(1)
# A nasty hack to get the base filename
pctl.SetLayer(F_Cu)
@@ -113,12 +153,12 @@ except:
pass
pctl.ClosePlot()
-if args.protel_extensions:
- popt.SetUseGerberProtelExtensions(True)
+# "Use protel filename extensions", default=False
+popt.SetUseGerberProtelExtensions(args.protel_extensions)
basename = os.path.splitext(filename)[0]
-drlFileOut = drlFile = basename + ".drl"
+drlFileOut = drlFile = basename + "-PTH.drl"
drlNpthFileOut = drlNpthFile = basename + "-NPTH.drl"
if args.protel_extensions:
@@ -162,16 +202,21 @@ for plan in plot_plan:
# print "filename = " + plan.filename + ", postfix=" + plan.postfix
# print "filename: " + plan.filename
-if args.detect_files_only:
- for plan in plot_plan:
- print
- plan.filename
+if args.detect_files_only or args.mkdep:
+ if not args.mkdep:
+ for plan in plot_plan:
+ print(plan.filename)
+
+ print(drlFileOut)
+ print(drlNpthFileOut)
+ else:
+ print("GERBERS = ")
+ for plan in plot_plan:
+ print("GERBERS += {}".format(plan.filename))
+ print("GERBERS += {}".format(drlFileOut, args.pcb))
+ print("GERBERS += {}".format(drlNpthFileOut, args.pcb))
+ print("$(GERBERS): {}".format(args.pcb))
- if args.protel_extensions:
- print
- drlFileOut
- print
- drlNpthFileOut
sys.exit(0)
# Set some important plot options:
@@ -181,7 +226,7 @@ popt.SetLineWidth(FromMM(0.35))
popt.SetAutoScale(False)
popt.SetScale(1)
popt.SetMirror(False)
-popt.SetUseGerberAttributes(True)
+popt.SetUseGerberAttributes(args.extended_gerber_attributes)
popt.SetScale(1)
popt.SetUseAuxOrigin(True)
@@ -226,8 +271,6 @@ drlwriter.CreateDrillandMapFilesSet(pctl.GetPlotDirName(), genDrl, genMap)
if drlFile != drlFileOut:
os.rename(drlFile, drlFileOut)
- pass
-if drlFile != drlNpthFileOut:
+if drlNpthFile != drlNpthFileOut:
os.rename(drlNpthFile, drlNpthFileOut)
- pass
diff --git a/src/ee/tools/kicad_make_bom.py b/src/ee/tools/kicad_make_bom.py
index 9f67899..2600968 100644
--- a/src/ee/tools/kicad_make_bom.py
+++ b/src/ee/tools/kicad_make_bom.py
@@ -4,6 +4,8 @@ from ee.tools import mk_parents
from xml.etree import ElementTree
from xml.dom import minidom
+pretty = True # we always pretty print the XML
+
parser = argparse.ArgumentParser(description="Create a bom XML file from a KiCAD schematic")
parser.add_argument("--sch",
@@ -15,10 +17,6 @@ parser.add_argument("--out",
metavar="FILE",
help="The output file")
-parser.add_argument("--pretty",
- action='store_true',
- help="Pretty print the XML")
-
args = parser.parse_args()
sch = kicad.read_schematics(args.sch)
@@ -26,7 +24,7 @@ sch = kicad.read_schematics(args.sch)
bom = kicad.to_bom_xml(sch)
xml = ElementTree.tostring(bom, encoding='unicode')
-if args.pretty:
+if pretty:
xml = minidom.parseString(xml).toprettyxml(indent=" ")
if args.out:
diff --git a/src/ee/tools/kicad_mkdeps.py b/src/ee/tools/kicad_mkdeps.py
new file mode 100644
index 0000000..10c7e97
--- /dev/null
+++ b/src/ee/tools/kicad_mkdeps.py
@@ -0,0 +1,78 @@
+from __future__ import print_function
+import sys
+import argparse
+import ee.kicad as kicad
+
+out_file = sys.stdout
+
+
+def p(msg):
+ global out_file
+ print(msg, file=out_file)
+
+
+def work(args):
+ sch = kicad.read_schematics(args.sch)
+
+ p("# This file is generated")
+ p("ifeq ($(EE),)")
+ p(" $(error EE must be set)")
+ p("endif")
+ p("")
+ p("SCH_FILES =")
+ for s in sch.schematics:
+ p("SCH_FILES += {}".format(s.path))
+
+ if args.gerber:
+ p("# Gerber rules")
+ p("ifeq ($(GERBER_ZIP),)")
+ p(" $(error GERBER_ZIP must be set)")
+ p("endif")
+ p("gerbers: $(GERBER_ZIP)")
+ p("$(GERBER_ZIP): $(SCH_FILES)")
+ p("\t@echo GERBER")
+ p("\t$(EE) kicad-gerber \\")
+ p("\t\t--output-dir $(GERBER_DIR) \\")
+ p("\t\t--pcb $(PROJECT).kicad_pcb \\")
+ p("\t\t$(GERBER_ARGS)")
+ p("\tmkdir -p $(dir $@)")
+ p("\t(cd $(GERBER_DIR); zip tmp.zip $(foreach GBR,$(GERBERS),$(notdir $(GBR))))")
+ p("\tmv $(GERBER_DIR)/tmp.zip $@")
+ p("EE_OUTPUTS += $(GERBER_ZIP)")
+ p("")
+
+ p("")
+ p("# Utility targets")
+ p(".PHONY: schematic pcb gerber")
+ p("schematic: $(SCH_FILES)")
+ p("pcb: {}".format(args.pcb))
+
+
+parser = argparse.ArgumentParser(description="Create a Makefile with all dependencies")
+
+parser.add_argument("--sch",
+ required=True,
+ metavar="SCH",
+ help="Schematic file")
+
+parser.add_argument("--pcb",
+ required=True,
+ metavar="PCB",
+ help="PCB file")
+
+parser.add_argument("--out",
+ metavar="OUT",
+ help="Output file")
+
+parser.add_argument("--gerber",
+ action="store_true",
+ help="Enable gerber.zip target")
+
+args = parser.parse_args()
+
+if args.out:
+ with open(args.out, "w") as f:
+ out_file = f
+ work(args)
+else:
+ work(args)