aboutsummaryrefslogtreecommitdiff
path: root/src/ee/kicad/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/kicad/__init__.py')
-rw-r--r--src/ee/kicad/__init__.py41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/ee/kicad/__init__.py b/src/ee/kicad/__init__.py
index c4c3af5..b270ba1 100644
--- a/src/ee/kicad/__init__.py
+++ b/src/ee/kicad/__init__.py
@@ -1,4 +1,5 @@
-import re
+from typing import Any
+
from ee import EeException
from ee.kicad.read_schematic import read_schematic
from ee.kicad.to_bom import to_bom
@@ -11,4 +12,42 @@ __all__ = [
"Schematic",
"read_schematic",
"to_bom",
+ "to_pandas",
]
+
+
+def to_pandas(obj: Any, **kwarg):
+ import pandas
+
+ def run_filter(filters, obj):
+ for f in filters:
+ if not f(obj):
+ return False
+ return True
+
+ def to_pandas_schematic(sch: Schematic, **kwarg):
+ def make_dict(c: Component):
+ return {
+ "ref": c.ref,
+ "ref_type": c.ref_type,
+ "ref_num": c.ref_num,
+ "value": c.value
+ }
+
+ components = sch.components
+
+ filters = []
+
+ if not kwarg.get("include_pwr", False):
+ filters.append(lambda c: not c.is_pwr)
+
+ data = [make_dict(c) for c in components if run_filter(filters, c)]
+
+ return pandas.DataFrame(data=data, columns=["ref", "ref_type", "ref_num", "value"]).\
+ set_index("ref").\
+ sort_index()
+
+ if isinstance(obj, Schematic):
+ return to_pandas_schematic(obj)
+ else:
+ raise EeException("Unsupported type: {}".format(type(obj)))