From c313e6de8c06017739402ea89f55ce3b36ac0f2b Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 9 Feb 2019 23:37:02 +0100 Subject: o kicad-mkdeps: new tool, new -M option for kicad-gerber. Both output a Makefile-compatible dependencies file. --- src/ee/kicad/export_gerber.py | 2 ++ src/ee/kicad/model.py | 6 ++++-- src/ee/kicad/read_schematic.py | 38 +++++++++++++++++++++----------------- 3 files changed, 27 insertions(+), 19 deletions(-) (limited to 'src/ee/kicad') diff --git a/src/ee/kicad/export_gerber.py b/src/ee/kicad/export_gerber.py index c4c72fd..fb3247f 100755 --- a/src/ee/kicad/export_gerber.py +++ b/src/ee/kicad/export_gerber.py @@ -69,6 +69,7 @@ if args.layer_extensions is not None: board = LoadBoard(args.pcb) + class Plan: def __init__(self, layerNum, layerName, description): self.layerNum = layerNum @@ -88,6 +89,7 @@ class Plan: description = "Copper Layer " + layerName return Plan(layerNum, layerName, description) + plot_plan = [Plan.standard(layerNum, description) for (layerNum, description) in [ (F_SilkS, "Silk front"), (F_Mask, "Mask front"), diff --git a/src/ee/kicad/model.py b/src/ee/kicad/model.py index 8a514cd..f6bd8c1 100644 --- a/src/ee/kicad/model.py +++ b/src/ee/kicad/model.py @@ -156,7 +156,8 @@ class Library(object): class Schematic(object): - def __init__(self): + def __init__(self, path): + self.path = path self._libraries = set() self._sheets = [] self._components = [] @@ -183,7 +184,7 @@ class Schematic(object): self._components.append(component) def get_component(self, ref, unit=1): - c = find_component(self, ref, unit) + c = self.find_component(ref, unit) if c: return c @@ -195,6 +196,7 @@ class Schematic(object): if c.ref == ref and unit == unit: return c + class Schematics(object): def __init__(self, schematics): self._schematics = schematics diff --git a/src/ee/kicad/read_schematic.py b/src/ee/kicad/read_schematic.py index 56cdca8..4a9bbdc 100644 --- a/src/ee/kicad/read_schematic.py +++ b/src/ee/kicad/read_schematic.py @@ -4,28 +4,32 @@ from ee.kicad.model import * import os.path -def read_schematics(path): - def read(path): - schematic = read_schematic(path) +# Reads all .sch files referenced from the given .sch file. +def read_schematics(path) -> Schematics: + def read(schematic_path): + schematic = read_schematic(schematic_path) schematics = [schematic] for sheet in schematic.sheets: - p = os.path.join(os.path.dirname(path), sheet.path) + p = os.path.join(os.path.dirname(schematic_path), sheet.path) children = read(p) schematics.extend(children) return schematics return Schematics(read(path)) -def read_schematic(path): + +# Reads a single .sch file. All references to other sheets are read and available as schematic.sheets +def read_schematic(path: str) -> Schematic: path_basename = os.path.basename(path) - schematic = Schematic() + schematic = Schematic(path) def descr_section(lines): # print("descr_section: len={}".format(len(lines))) pass def sheet_section(lines): - + name = None + sheet_path = None for line in lines: parts = shlex.split(line) if len(parts) < 2: @@ -33,9 +37,9 @@ def read_schematic(path): if parts[0] == "F0": name = parts[1] elif parts[0] == "F1": - path = parts[1] + sheet_path = parts[1] - schematic.add_sheet(Sheet(name, path)) + schematic.add_sheet(Sheet(name, sheet_path)) def comp_section(lines): # print("comp_section: len={}".format(len(lines))) @@ -95,7 +99,7 @@ def read_schematic(path): schematic.add_component(Component(position, timestamp, library, name, unit, ref, fields)) - def load(path, f): + def load(f): header = f.readline() line_number = 1 if "EESchema Schematic File Version" not in header: @@ -140,12 +144,12 @@ def read_schematic(path): # print("SECTION: {}".format(section_name)) section = [] elif parts[0:3] == ["Entry", "Wire", "Line"] or \ - parts[0:2] == ["Text", "Label"] or \ - parts[0:2] == ["Text", "Notes"] or \ - parts[0:2] == ["Text", "HLabel"] or \ - parts[0:3] == ["Wire", "Notes", "Line"] or \ - parts[0:3] == ["Wire", "Wire", "Line"] or \ - parts[0:3] == ["Wire", "Bus", "Line"]: + parts[0:2] == ["Text", "Label"] or \ + parts[0:2] == ["Text", "Notes"] or \ + parts[0:2] == ["Text", "HLabel"] or \ + parts[0:3] == ["Wire", "Notes", "Line"] or \ + parts[0:3] == ["Wire", "Wire", "Line"] or \ + parts[0:3] == ["Wire", "Bus", "Line"]: f.readline() # ignore the next line for now line_number = line_number + 1 elif line.startswith("NoConn "): @@ -159,4 +163,4 @@ def read_schematic(path): return schematic with open(path) as file: - return load(path, file) + return load(file) -- cgit v1.2.3