diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ee/kicad/__init__.py | 24 | ||||
-rw-r--r-- | src/ee/kicad/model.py | 4 |
2 files changed, 22 insertions, 6 deletions
diff --git a/src/ee/kicad/__init__.py b/src/ee/kicad/__init__.py index b270ba1..adf8ddd 100644 --- a/src/ee/kicad/__init__.py +++ b/src/ee/kicad/__init__.py @@ -25,27 +25,39 @@ def to_pandas(obj: Any, **kwarg): return False return True - def to_pandas_schematic(sch: Schematic, **kwarg): + def to_pandas_schematic(sch: Schematic): + # These fields will always be put first. + special_fields = ["ref", "ref_type", "ref_num", "value"] def make_dict(c: Component): - return { + fields = { "ref": c.ref, "ref_type": c.ref_type, "ref_num": c.ref_num, - "value": c.value + "value": c.value, + "footprint": c.footprint, } + fields.update({f.name:f.value for f in c.fields if f.is_custom}) + return fields components = sch.components filters = [] - if not kwarg.get("include_pwr", False): + include_pwr = kwarg.get("include_pwr", False) + if not include_pwr: filters.append(lambda c: not c.is_pwr) + include_flg = kwarg.get("include_flg", False) + if not include_flg: + filters.append(lambda c: c.ref_type != "#FLG") + data = [make_dict(c) for c in components if run_filter(filters, c)] + columns = set([key for row in data for key in list(row)]) - set(special_fields) + columns = special_fields + list(columns) - return pandas.DataFrame(data=data, columns=["ref", "ref_type", "ref_num", "value"]).\ + return pandas.DataFrame(data=data, columns=columns).\ set_index("ref").\ - sort_index() + sort_values(["ref_type", "ref_num"]) if isinstance(obj, Schematic): return to_pandas_schematic(obj) diff --git a/src/ee/kicad/model.py b/src/ee/kicad/model.py index 519a978..f112e72 100644 --- a/src/ee/kicad/model.py +++ b/src/ee/kicad/model.py @@ -43,6 +43,10 @@ class ComponentField(object): def position(self): return self._position + @property + def is_custom(self): + return self._index >= len(ComponentField.names) + @total_ordering class Component(object): |