aboutsummaryrefslogtreecommitdiff
path: root/src/ee/kicad/model.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/kicad/model.py')
-rw-r--r--src/ee/kicad/model.py80
1 files changed, 60 insertions, 20 deletions
diff --git a/src/ee/kicad/model.py b/src/ee/kicad/model.py
index 7d9a437..eacf8e2 100644
--- a/src/ee/kicad/model.py
+++ b/src/ee/kicad/model.py
@@ -133,16 +133,17 @@ class Component(object):
class Sheet(object):
- def __init__(self):
- self._components = []
- pass
+ def __init__(self, name, path):
+ self._name = name
+ self._path = path
@property
- def components(self):
- return frozenset(self._components)
+ def path(self):
+ return self._path
- def add_component(self, component):
- self._components.append(component)
+ @property
+ def name(self):
+ return self._name
class Library(object):
@@ -153,12 +154,8 @@ class Library(object):
class Schematic(object):
def __init__(self):
self._libraries = set()
- self._sheets = [Sheet()]
- pass
-
- @property
- def first_sheet(self):
- return self._sheets[0]
+ self._sheets = []
+ self._components = []
@property
def libraries(self):
@@ -167,18 +164,61 @@ class Schematic(object):
def add_library(self, library):
self._libraries.add(Library(library))
- # Getters
@property
- def components(self) -> List[Component]:
- a = []
- for s in self._sheets:
- for c in s.components:
- a.append(c)
- return a
+ def sheets(self):
+ return frozenset(self._sheets)
+
+ def add_sheet(self, sheet):
+ self._sheets.append(sheet)
+
+ @property
+ def components(self):
+ return frozenset(self._components)
+
+ def add_component(self, component):
+ self._components.append(component)
def get_component(self, ref, unit=1):
+ c = find_component(self, ref, unit)
+
+ if c:
+ return c
+
+ raise KeyError("No such component: {}".format(ref))
+
+ def find_component(self, ref, unit=1):
for c in self.components:
if c.ref == ref and unit == unit:
return c
+class Schematics(object):
+ def __init__(self, schematics):
+ self._schematics = schematics
+
+ @property
+ def schematics(self) -> List[Schematic]:
+ return list(self._schematics)
+
+ @property
+ def components(self) -> List[Component]:
+ cs = []
+ for s in self._schematics:
+ for c in s.components:
+ cs.append(c)
+ return cs
+
+ def get_component(self, ref, unit=1):
+ for s in self._schematics:
+ c = s.find_component(ref, unit)
+ if c:
+ return c
+
raise KeyError("No such component: {}".format(ref))
+
+ @property
+ def libraries(self) -> List[Library]:
+ ls = []
+ for s in self._schematics:
+ for l in s.libraries:
+ ls.append(l)
+ return ls