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.py35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/ee/kicad/read_schematic.py b/src/ee/kicad/read_schematic.py
index e70d1a7..ed5ce21 100644
--- a/src/ee/kicad/read_schematic.py
+++ b/src/ee/kicad/read_schematic.py
@@ -1,16 +1,42 @@
import shlex
from ee import EeException
from ee.kicad.model import *
+import os.path
+def read_schematics(path):
+ def read(path):
+ schematic = read_schematic(path)
+ schematics = [schematic]
+ for sheet in schematic.sheets:
+ p = os.path.join(os.path.dirname(path), sheet.path)
+ print("Loading {} from {}, path: {}".format(sheet.name, sheet.path, p))
+ children = read(p)
+ schematics.extend(children)
+ return schematics
+
+ return Schematics(read(path))
+
def read_schematic(path):
schematic = Schematic()
- sheet = None
def descr_section(lines):
# print("descr_section: len={}".format(len(lines)))
pass
+ def sheet_section(lines):
+
+ for line in lines:
+ parts = shlex.split(line)
+ if len(parts) < 2:
+ continue
+ if parts[0] == "F0":
+ name = parts[1]
+ elif parts[0] == "F1":
+ path = parts[1]
+
+ schematic.add_sheet(Sheet(name, path))
+
def comp_section(lines):
# print("comp_section: len={}".format(len(lines)))
timestamp = None
@@ -65,16 +91,13 @@ def read_schematic(path):
else:
raise EeException("Bad component field: '{}'".format(line))
- sheet.add_component(Component(position, timestamp, library, name, unit, ref, fields))
+ schematic.add_component(Component(position, timestamp, library, name, unit, ref, fields))
def load(f):
header = f.readline()
if "EESchema Schematic File Version" not in header:
raise EeException("Not a KiCAD schematic file.")
- nonlocal sheet
- sheet = schematic.first_sheet
-
section_name = None
section = []
@@ -93,6 +116,8 @@ def read_schematic(path):
comp_section(section)
elif section_name == "$Descr":
descr_section(section)
+ elif section_name == "$Sheet":
+ sheet_section(section)
else:
if line == "$EndSCHEMATIC":
seen_end = True