from typing import List class Position(object): def __init__(self, x, y): self._x = x self._y = y @property def x(self): return _x @property def y(self): return _y class ComponentField(object): names = ["Reference", "Value", "Footprint", "Datasheet"] def __init__(self, index, name, value, position): self._index = index self._name = name if index >= len(ComponentField.names) else ComponentField.names[index] self._value = value self._position = position @property def index(self): return self._index @property def name(self): return self._name @property def value(self): return self._value @property def position(self): return self._position class Component(object): def __init__(self, position, timestamp, library, name, unit, ref, fields): self._position = position self._timestamp = timestamp self._library = library self._name = name self._unit = unit self._ref = ref self._fields = fields # type List[ComponentField] @property def unit(self): return self._unit @property def ref(self): return self._ref @property def value(self): return self._fields[1].value @property def footprint(self): return self._fields[2].value @property def fields(self) -> List[ComponentField]: return list(self._fields) @property def named_fields(self): return [f for f in self._fields if f.name] class Sheet(object): def __init__(self): self._components = [] pass @property def components(self): return frozenset(self._components) def add_component(self, component): self._components.append(component) class Library(object): def __init__(self, name): self.name = name class Schematic(object): def __init__(self): self._libraries = set() self._sheets = [Sheet()] pass @property def first_sheet(self): return self._sheets[0] @property def libraries(self): return frozenset(self._libraries) def add_library(self, library): self._libraries.add(Library(library)) # Getters @property def components(self): a = [] for s in self._sheets: for c in s.components: a.append(c) return a def get_component(self, ref, unit = 1): for c in self.components: if c.ref == ref and unit == unit: return c raise KeyError("No such component: {}".format(ref))