schematizer 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- schematizer/__init__.py +18 -0
- schematizer/_utils.py +80 -0
- schematizer/cli.py +90 -0
- schematizer/data/power.kicad_sym +12144 -0
- schematizer/engine/__init__.py +2 -0
- schematizer/engine/backend.py +183 -0
- schematizer/engine/bboxes.py +375 -0
- schematizer/engine/constants.py +16 -0
- schematizer/engine/debug_draw.py +351 -0
- schematizer/engine/decisions.py +479 -0
- schematizer/engine/gen_schematic.py +899 -0
- schematizer/engine/kicad_backend.py +247 -0
- schematizer/engine/net_terminal.py +62 -0
- schematizer/engine/place.py +2103 -0
- schematizer/engine/route.py +3247 -0
- schematizer/engine/sch_node.py +402 -0
- schematizer/engine/sexp_schematic.py +1667 -0
- schematizer/engine/snap.py +641 -0
- schematizer/engine/svg_draw.py +351 -0
- schematizer/engine/svg_schematic.py +647 -0
- schematizer/engine/tool_module.py +23 -0
- schematizer/geometry.py +1075 -0
- schematizer/ir.py +381 -0
- schematizer/loader.py +146 -0
- schematizer/render.py +137 -0
- schematizer-0.1.0.dist-info/METADATA +150 -0
- schematizer-0.1.0.dist-info/RECORD +31 -0
- schematizer-0.1.0.dist-info/WHEEL +5 -0
- schematizer-0.1.0.dist-info/entry_points.txt +2 -0
- schematizer-0.1.0.dist-info/licenses/LICENSE +21 -0
- schematizer-0.1.0.dist-info/top_level.txt +1 -0
schematizer/__init__.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
# The MIT License (MIT) - Copyright (c) Dave Vandenbout.
|
|
4
|
+
|
|
5
|
+
"""schematizer: generic JSON netlist -> KiCad schematic."""
|
|
6
|
+
|
|
7
|
+
# Defined before importing render so the vendored engine (which does
|
|
8
|
+
# ``from .. import __version__`` at import time) can see it.
|
|
9
|
+
__version__ = "0.2.0"
|
|
10
|
+
|
|
11
|
+
from .render import render # noqa: E402
|
|
12
|
+
|
|
13
|
+
# Part of render()'s contract: the exceptions the engine raises when placement
|
|
14
|
+
# or routing can't complete. Exported so callers (e.g. SKiDL) can catch them.
|
|
15
|
+
from .engine.place import PlacementFailure # noqa: E402
|
|
16
|
+
from .engine.route import RoutingFailure # noqa: E402
|
|
17
|
+
|
|
18
|
+
__all__ = ["render", "PlacementFailure", "RoutingFailure", "__version__"]
|
schematizer/_utils.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
# The MIT License (MIT) - Copyright (c) Dave Vandenbout.
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
Minimal, skidl-free utility surface used by the vendored schematic engine.
|
|
7
|
+
|
|
8
|
+
The engine originally pulled a few helpers from ``skidl.utilities``,
|
|
9
|
+
``skidl.logger`` and ``skidl.scriptinfo``. Only a small, stable subset is
|
|
10
|
+
actually used; it is reproduced here so the package does not depend on skidl.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import logging
|
|
14
|
+
import os
|
|
15
|
+
import sys
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"export_to_all",
|
|
19
|
+
"rmv_attr",
|
|
20
|
+
"sgn",
|
|
21
|
+
"get_script_name",
|
|
22
|
+
"active_logger",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def export_to_all(fn):
|
|
27
|
+
"""Append ``fn.__name__`` to its module's ``__all__`` (decorator, no-op else).
|
|
28
|
+
|
|
29
|
+
Same behavior as ``skidl.utilities.export_to_all``: it lets a module opt a
|
|
30
|
+
name into ``from module import *`` and otherwise returns the function
|
|
31
|
+
unchanged.
|
|
32
|
+
"""
|
|
33
|
+
mod = sys.modules[fn.__module__]
|
|
34
|
+
if hasattr(mod, "__all__"):
|
|
35
|
+
mod.__all__.append(fn.__name__)
|
|
36
|
+
else:
|
|
37
|
+
mod.__all__ = [fn.__name__]
|
|
38
|
+
return fn
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _to_list(x):
|
|
42
|
+
"""Return ``x`` as a list; wrap scalars, pass sequences through."""
|
|
43
|
+
if isinstance(x, (list, tuple, set)):
|
|
44
|
+
return list(x)
|
|
45
|
+
return [x]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def rmv_attr(objs, attrs):
|
|
49
|
+
"""Remove one or more attributes from one or more objects (ignore missing)."""
|
|
50
|
+
for o in _to_list(objs):
|
|
51
|
+
for a in _to_list(attrs):
|
|
52
|
+
try:
|
|
53
|
+
delattr(o, a)
|
|
54
|
+
except AttributeError:
|
|
55
|
+
pass
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def sgn(x):
|
|
59
|
+
"""Return the sign of a number as -1, 0, or +1."""
|
|
60
|
+
return (x > 0) - (x < 0)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def get_script_name():
|
|
64
|
+
"""Return the top-level script name without extension.
|
|
65
|
+
|
|
66
|
+
Used only as the default ``top_name`` for schematic output; callers
|
|
67
|
+
(``render``/CLI) normally pass an explicit name.
|
|
68
|
+
"""
|
|
69
|
+
try:
|
|
70
|
+
name = os.path.basename(sys.argv[0]) if sys.argv and sys.argv[0] else ""
|
|
71
|
+
except Exception:
|
|
72
|
+
name = ""
|
|
73
|
+
return os.path.splitext(name)[0] or "schematic"
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
# A plain stdlib logger stands in for skidl's ``active_logger``. The engine only
|
|
77
|
+
# calls ``.info`` / ``.warning`` on it.
|
|
78
|
+
active_logger = logging.getLogger("schematizer")
|
|
79
|
+
if not active_logger.handlers:
|
|
80
|
+
active_logger.addHandler(logging.NullHandler())
|
schematizer/cli.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
# The MIT License (MIT) - Copyright (c) Dave Vandenbout.
|
|
4
|
+
|
|
5
|
+
"""Command-line interface: generic netlist JSON -> schematic files."""
|
|
6
|
+
|
|
7
|
+
import argparse
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
from . import __version__
|
|
11
|
+
from .render import SUPPORTED_FORMATS, SUPPORTED_TOOLS, render
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def build_parser():
|
|
15
|
+
parser = argparse.ArgumentParser(
|
|
16
|
+
prog="schematizer",
|
|
17
|
+
description="Generate KiCad schematic or SVG files from a generic "
|
|
18
|
+
"hierarchical netlist (JSON).",
|
|
19
|
+
)
|
|
20
|
+
parser.add_argument(
|
|
21
|
+
"netlist",
|
|
22
|
+
help="Path to the generic netlist JSON file.",
|
|
23
|
+
)
|
|
24
|
+
parser.add_argument(
|
|
25
|
+
"-t",
|
|
26
|
+
"--tool",
|
|
27
|
+
default="kicad9",
|
|
28
|
+
choices=SUPPORTED_TOOLS,
|
|
29
|
+
help="Target KiCad version (default: kicad9).",
|
|
30
|
+
)
|
|
31
|
+
parser.add_argument(
|
|
32
|
+
"-f",
|
|
33
|
+
"--format",
|
|
34
|
+
default="kicad",
|
|
35
|
+
choices=SUPPORTED_FORMATS,
|
|
36
|
+
help="Output format: editable .kicad_sch files, or static "
|
|
37
|
+
"cross-linked .svg pages (default: kicad).",
|
|
38
|
+
)
|
|
39
|
+
parser.add_argument(
|
|
40
|
+
"-o",
|
|
41
|
+
"--output",
|
|
42
|
+
default=".",
|
|
43
|
+
help="Output directory for the generated files (default: .).",
|
|
44
|
+
)
|
|
45
|
+
parser.add_argument(
|
|
46
|
+
"--top-name",
|
|
47
|
+
default=None,
|
|
48
|
+
help="Base name for output files (default: from the netlist).",
|
|
49
|
+
)
|
|
50
|
+
parser.add_argument(
|
|
51
|
+
"--title",
|
|
52
|
+
default="SKiDL-Generated Schematic",
|
|
53
|
+
help="Schematic title-block text.",
|
|
54
|
+
)
|
|
55
|
+
parser.add_argument(
|
|
56
|
+
"--flatness",
|
|
57
|
+
type=float,
|
|
58
|
+
default=0.0,
|
|
59
|
+
help="Hierarchy flattening, 0.0 (fully hierarchical, one file per "
|
|
60
|
+
"sheet) .. 1.0 (everything on one sheet).",
|
|
61
|
+
)
|
|
62
|
+
parser.add_argument(
|
|
63
|
+
"--version",
|
|
64
|
+
action="version",
|
|
65
|
+
version=f"%(prog)s {__version__}",
|
|
66
|
+
)
|
|
67
|
+
return parser
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def main(argv=None):
|
|
71
|
+
args = build_parser().parse_args(argv)
|
|
72
|
+
try:
|
|
73
|
+
out = render(
|
|
74
|
+
args.netlist,
|
|
75
|
+
tool=args.tool,
|
|
76
|
+
filepath=args.output,
|
|
77
|
+
top_name=args.top_name,
|
|
78
|
+
title=args.title,
|
|
79
|
+
format=args.format,
|
|
80
|
+
flatness=args.flatness,
|
|
81
|
+
)
|
|
82
|
+
except (ValueError, TypeError, FileNotFoundError) as e:
|
|
83
|
+
print(f"schematizer: error: {e}", file=sys.stderr)
|
|
84
|
+
return 1
|
|
85
|
+
print(f"Wrote {args.format} files to {out}")
|
|
86
|
+
return 0
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
if __name__ == "__main__":
|
|
90
|
+
sys.exit(main())
|