aboutsummaryrefslogtreecommitdiff
path: root/src/ee/kicad/read_schematic.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/kicad/read_schematic.py')
-rw-r--r--src/ee/kicad/read_schematic.py38
1 files changed, 21 insertions, 17 deletions
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)