jitxlib-odb 1.0.0__tar.gz
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.
- jitxlib_odb-1.0.0/.gitignore +5 -0
- jitxlib_odb-1.0.0/CLAUDE.md +55 -0
- jitxlib_odb-1.0.0/PKG-INFO +6 -0
- jitxlib_odb-1.0.0/README.md +42 -0
- jitxlib_odb-1.0.0/build.err +1 -0
- jitxlib_odb-1.0.0/build.log +1 -0
- jitxlib_odb-1.0.0/lint.log +4 -0
- jitxlib_odb-1.0.0/pyproject.toml +92 -0
- jitxlib_odb-1.0.0/pyrightconfig.json +14 -0
- jitxlib_odb-1.0.0/src/jitxlib/odb/__init__.py +6 -0
- jitxlib_odb-1.0.0/src/jitxlib/odb/extract/__init__.py +5 -0
- jitxlib_odb-1.0.0/src/jitxlib/odb/extract/components.py +311 -0
- jitxlib_odb-1.0.0/src/jitxlib/odb/extract/copper.py +44 -0
- jitxlib_odb-1.0.0/src/jitxlib/odb/extract/features.py +118 -0
- jitxlib_odb-1.0.0/src/jitxlib/odb/extract/geometry.py +398 -0
- jitxlib_odb-1.0.0/src/jitxlib/odb/extract/job.py +96 -0
- jitxlib_odb-1.0.0/src/jitxlib/odb/extract/layers.py +60 -0
- jitxlib_odb-1.0.0/src/jitxlib/odb/extract/nets.py +66 -0
- jitxlib_odb-1.0.0/src/jitxlib/odb/extract/outline.py +62 -0
- jitxlib_odb-1.0.0/src/jitxlib/odb/extract/padstacks.py +379 -0
- jitxlib_odb-1.0.0/src/jitxlib/odb/extract/stackup.py +186 -0
- jitxlib_odb-1.0.0/src/jitxlib/odb/format/__init__.py +54 -0
- jitxlib_odb-1.0.0/src/jitxlib/odb/format/emit.py +435 -0
- jitxlib_odb-1.0.0/src/jitxlib/odb/format/font.py +119 -0
- jitxlib_odb-1.0.0/src/jitxlib/odb/format/model.py +481 -0
- jitxlib_odb-1.0.0/src/jitxlib/odb/format/pack.py +141 -0
- jitxlib_odb-1.0.0/src/jitxlib/odb/format/symbols.py +68 -0
- jitxlib_odb-1.0.0/src/jitxlib/odb/plugin.py +81 -0
- jitxlib_odb-1.0.0/test.err +5 -0
- jitxlib_odb-1.0.0/test.log +123 -0
- jitxlib_odb-1.0.0/tests/extract/test_geometry.py +129 -0
- jitxlib_odb-1.0.0/tests/extract/test_labels.py +45 -0
- jitxlib_odb-1.0.0/tests/extract/test_layers.py +47 -0
- jitxlib_odb-1.0.0/tests/extract/test_nets.py +54 -0
- jitxlib_odb-1.0.0/tests/extract/test_padstacks.py +10 -0
- jitxlib_odb-1.0.0/tests/extract/test_stackup.py +124 -0
- jitxlib_odb-1.0.0/tests/extract/test_text_symbols.py +67 -0
- jitxlib_odb-1.0.0/tests/format/test_eda.py +104 -0
- jitxlib_odb-1.0.0/tests/format/test_emit.py +307 -0
- jitxlib_odb-1.0.0/tests/format/test_pack.py +80 -0
- jitxlib_odb-1.0.0/tests/format/test_symbols.py +47 -0
- jitxlib_odb-1.0.0/typecheck.err +0 -0
- jitxlib_odb-1.0.0/typecheck.log +1 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Preamble
|
|
2
|
+
|
|
3
|
+
This package exports ODB++ Design jobs (spec 8.1 update 4) from JITX designs
|
|
4
|
+
through the jitx-plugin export entry point, registered as `odb`. The sibling
|
|
5
|
+
`jitxlib-ansys` repo is the reference for how to consume the JITX query APIs.
|
|
6
|
+
|
|
7
|
+
# Architecture
|
|
8
|
+
|
|
9
|
+
Two layers, strictly separated:
|
|
10
|
+
|
|
11
|
+
- `src/jitxlib/odb/format/`: a standalone ODB++ writer. No jitx imports
|
|
12
|
+
anywhere in this package; it is fully unit-testable without a runtime.
|
|
13
|
+
- `src/jitxlib/odb/extract/`: walks a captured `RuntimeDesign` via the jitx
|
|
14
|
+
query APIs and populates the format model. JITX geometry stays in mm here;
|
|
15
|
+
the mm-to-inch conversion happens exactly once, in `geometry.Placer`.
|
|
16
|
+
|
|
17
|
+
# Units policy
|
|
18
|
+
|
|
19
|
+
Everything is emitted imperial: `UNITS=INCH` in every measured file, mils in
|
|
20
|
+
symbol names and tools files. Never emit `UNITS=MM`: consuming tools have a
|
|
21
|
+
history of mishandling metric jobs and the spec changed layer-thickness units
|
|
22
|
+
incompatibly once. Thickness metadata obeys the same rule: the tools-file
|
|
23
|
+
`THICKNESS` and `matrix/stackup.xml` are mils, the `.board_thickness` and
|
|
24
|
+
`.layer_dielectric` attributes inches, `.copper_weight` oz.
|
|
25
|
+
|
|
26
|
+
Rotations in ODB++ records are clockwise degrees; JITX transforms are CCW.
|
|
27
|
+
Only 2-fold symmetric standard symbols are emitted as P records, so mirrored
|
|
28
|
+
placements fold into the rotation; irregular or mirrored-asymmetric shapes
|
|
29
|
+
fall back to exact S surfaces.
|
|
30
|
+
|
|
31
|
+
# Preparation
|
|
32
|
+
|
|
33
|
+
Install with `pip install -e .`. The entry point registers on import; the
|
|
34
|
+
CLI flags come from the keyword parameters of `OdbExport.export`.
|
|
35
|
+
|
|
36
|
+
# Exporting
|
|
37
|
+
|
|
38
|
+
A running jitx runtime is needed in the project being exported:
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
python -m jitx design export odb --output <path> [--overwrite] [--tgz] <design>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`--output` is the job directory path (its basename, scrubbed, becomes the job
|
|
45
|
+
name); default is the design name in the cwd. `--tgz` additionally packs a
|
|
46
|
+
single-root `<job>.tgz`.
|
|
47
|
+
|
|
48
|
+
# Validation
|
|
49
|
+
|
|
50
|
+
- `python -m pytest`, `pyright`, `ruff check src tests` must all be clean.
|
|
51
|
+
- Reference material (fetched during planning, may need re-fetching): the
|
|
52
|
+
spec PDF at odbplusplus.com, the official sample job
|
|
53
|
+
`designodb_rigidflex.tgz`, and the free Siemens ODB++ Viewer (Windows) as
|
|
54
|
+
the de-facto acceptance test. KiCad's exporter (GPLv3) is a behavior
|
|
55
|
+
reference only; never translate its code into this repo.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# jitxlib-odb
|
|
2
|
+
|
|
3
|
+
Export ODB++ Design jobs from JITX designs.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
pip install -e .
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Run this in the project's environment, the one holding the design to export
|
|
12
|
+
and its own `jitx`. It registers the `odb` exporter with that `jitx`.
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
With a jitx runtime running in the project:
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
jitx design export odb --output out/myboard --overwrite --tgz my.design.Module
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Writes the ODB++ job tree to `out/myboard/` (and `out/myboard.tgz` with
|
|
23
|
+
`--tgz`). Without `--output` the job is written to the current directory
|
|
24
|
+
under the design's name.
|
|
25
|
+
|
|
26
|
+
The exporter is discovered through the `jitx-plugin` entry point in the
|
|
27
|
+
environment `jitx` runs from, so this is the project's `jitx` that the
|
|
28
|
+
install above registered with; `python -m jitx` is equivalent.
|
|
29
|
+
|
|
30
|
+
## Scope
|
|
31
|
+
|
|
32
|
+
Fabrication and assembly data: matrix plus `matrix/stackup.xml` (thickness,
|
|
33
|
+
Dk/Df when the design defines them), signal/dielectric layers, copper traces
|
|
34
|
+
and pours, pads, via and through-hole drill layers with tools, soldermask,
|
|
35
|
+
silkscreen, paste, board profile with cutouts, a cadnet netlist, `eda/data`
|
|
36
|
+
(NET/SNT/FID, PKG/PIN), and `comp_+_top`/`comp_+_bot` component layers
|
|
37
|
+
(CMP/PRP/TOP with `.comp_mount_type`). Silkscreen text emits T records,
|
|
38
|
+
capsule pad cutouts emit drill slots, and irregular pad shapes get
|
|
39
|
+
content-hashed user symbols. Backdrills are detected but not emitted (the
|
|
40
|
+
design API does not expose stub depth yet).
|
|
41
|
+
|
|
42
|
+
All files are emitted with `UNITS=INCH` (see CLAUDE.md for why).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Inspecting build dependencies
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
──────────────────────────────────── sdist ─────────────────────────────────────
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# pyproject.toml
|
|
2
|
+
|
|
3
|
+
[build-system]
|
|
4
|
+
requires = [
|
|
5
|
+
"hatchling>=1.27.0,<2.0",
|
|
6
|
+
"hatch-vcs>=0.5.0,<0.6.0",
|
|
7
|
+
"ruff==0.14.9",
|
|
8
|
+
"pyright>=1.1.398,<1.2.0",
|
|
9
|
+
]
|
|
10
|
+
build-backend = "hatchling.build"
|
|
11
|
+
|
|
12
|
+
[project]
|
|
13
|
+
name = "jitxlib-odb"
|
|
14
|
+
dynamic = ["version"]
|
|
15
|
+
description = "Export ODB++ Design jobs from JITX designs"
|
|
16
|
+
dependencies = [
|
|
17
|
+
"jitx>=4.6.0,<5",
|
|
18
|
+
]
|
|
19
|
+
requires-python = ">=3.12"
|
|
20
|
+
|
|
21
|
+
[project.entry-points.jitx-plugin]
|
|
22
|
+
export = "jitxlib.odb.plugin"
|
|
23
|
+
|
|
24
|
+
[tool.hatch.build.targets.wheel]
|
|
25
|
+
packages = ["src/jitxlib"]
|
|
26
|
+
|
|
27
|
+
[tool]
|
|
28
|
+
|
|
29
|
+
# tests: run "hatch test --cover"
|
|
30
|
+
[tool.hatch.envs.hatch-test]
|
|
31
|
+
randomize = true
|
|
32
|
+
parallel = false
|
|
33
|
+
installer = "pip"
|
|
34
|
+
extra-args = ["-vv"]
|
|
35
|
+
dependencies = [
|
|
36
|
+
"coverage[toml]",
|
|
37
|
+
"pytest",
|
|
38
|
+
"pytest-cov",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
# `jitx build-all` (the integration-test contract) discovers designs by
|
|
42
|
+
# importing every module under the project root. tests/ imports pytest, so
|
|
43
|
+
# keep discovery out of it; pytest runs the tests. This repo has no designs,
|
|
44
|
+
# so build-all builds nothing and succeeds.
|
|
45
|
+
[tool.jitx]
|
|
46
|
+
exclude = ["tests"]
|
|
47
|
+
|
|
48
|
+
[[tool.hatch.envs.test.matrix]]
|
|
49
|
+
python = ["3.12", "3.13", "3.14"]
|
|
50
|
+
|
|
51
|
+
[tool.hatch.metadata]
|
|
52
|
+
allow-direct-references = true
|
|
53
|
+
|
|
54
|
+
[tool.hatch.version]
|
|
55
|
+
source = "vcs"
|
|
56
|
+
fallback-version = "0.0.0+undefined"
|
|
57
|
+
|
|
58
|
+
# formatting: run "hatch fmt --check"
|
|
59
|
+
[tool.hatch.envs.hatch-static-analysis]
|
|
60
|
+
dependencies = ["ruff==0.14.9"]
|
|
61
|
+
config-path = "none" # don't use hatch defaults
|
|
62
|
+
|
|
63
|
+
[tool.ruff]
|
|
64
|
+
line-length = 88
|
|
65
|
+
indent-width = 4
|
|
66
|
+
target-version = "py312"
|
|
67
|
+
|
|
68
|
+
[tool.ruff.lint]
|
|
69
|
+
# To enable:
|
|
70
|
+
# UP, TC
|
|
71
|
+
select = ["E", "F", "W", "A", "B", "C"]
|
|
72
|
+
# E501 line too long - let ruff format handle that
|
|
73
|
+
# A002 variable shadowing built-in (id, min, max)
|
|
74
|
+
# A005 builtin module shadowing (false positive)
|
|
75
|
+
# C901 mccabe complexity check, limits to 10
|
|
76
|
+
ignore = ["E501", "A005", "C901", "A002"]
|
|
77
|
+
|
|
78
|
+
[tool.ruff.format]
|
|
79
|
+
quote-style = "double"
|
|
80
|
+
indent-style = "space"
|
|
81
|
+
|
|
82
|
+
# pyright: run "hatch run types:check"
|
|
83
|
+
[tool.hatch.envs.types]
|
|
84
|
+
extra-dependencies = [
|
|
85
|
+
"pyright>=1.1.0",
|
|
86
|
+
# pyrightconfig.json type-checks tests/ too, which imports pytest
|
|
87
|
+
"pytest",
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
[tool.hatch.envs.types.scripts]
|
|
91
|
+
check = "pyright ."
|
|
92
|
+
stats = "pyright --stats ."
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"""Export ODB++ Design jobs from JITX designs.
|
|
2
|
+
|
|
3
|
+
The package splits in two: `format` is a standalone ODB++ writer with no JITX
|
|
4
|
+
dependencies, and `extract` populates the format model from a captured JITX
|
|
5
|
+
RuntimeDesign. The `plugin` module registers the jitx export entry point.
|
|
6
|
+
"""
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
"""Component enumeration and the eda/data recorder.
|
|
2
|
+
|
|
3
|
+
Components are discovered with query(Component); their pads are visited in
|
|
4
|
+
tree order, which defines the pin/toeprint indices. Padstack and copper
|
|
5
|
+
builders report the features they emit through EdaRecorder, which patches the
|
|
6
|
+
eda/data FID layer indices once the matrix (and thus the LYR list) is final.
|
|
7
|
+
|
|
8
|
+
Verified API surface (see the M3 spike): reference_designator is assigned by
|
|
9
|
+
the runtime during capture; landpatterns arrive Proxy-wrapped, so their true
|
|
10
|
+
type comes from jitx.proxy.typeof; nets resolve directly on pad objects.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from dataclasses import dataclass, field
|
|
16
|
+
from logging import getLogger
|
|
17
|
+
|
|
18
|
+
from jitx.component import Component
|
|
19
|
+
from jitx.feature import Cutout
|
|
20
|
+
from jitx.inspect import extract, visit
|
|
21
|
+
from jitx.landpattern import Landpattern, Pad, PadShape
|
|
22
|
+
from jitx.layerindex import Side
|
|
23
|
+
from jitx.placement import Placement
|
|
24
|
+
from jitx.proxy import typeof
|
|
25
|
+
from jitx.refpath import RefPath
|
|
26
|
+
|
|
27
|
+
from jitx.run.runtime import RuntimeDesign
|
|
28
|
+
from jitx.transform import IDENTITY
|
|
29
|
+
from jitx.units import PlainQuantity, rkm_code
|
|
30
|
+
|
|
31
|
+
from ..format.model import (
|
|
32
|
+
ComponentRecord,
|
|
33
|
+
ComponentsFile,
|
|
34
|
+
EdaData,
|
|
35
|
+
EdaNet,
|
|
36
|
+
Fid,
|
|
37
|
+
Package,
|
|
38
|
+
PackagePin,
|
|
39
|
+
Subnet,
|
|
40
|
+
Toeprint,
|
|
41
|
+
legal_name,
|
|
42
|
+
)
|
|
43
|
+
from .geometry import MM_PER_INCH, to_contours
|
|
44
|
+
from .nets import NetIndex
|
|
45
|
+
|
|
46
|
+
logger = getLogger(__name__)
|
|
47
|
+
|
|
48
|
+
COMP_TOP = "comp_+_top"
|
|
49
|
+
COMP_BOT = "comp_+_bot"
|
|
50
|
+
|
|
51
|
+
REF_LABEL = ">REF"
|
|
52
|
+
VALUE_LABEL = ">VALUE"
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@dataclass
|
|
56
|
+
class Pin:
|
|
57
|
+
"""One component pin: its eda TOP subnet plus the TOP record data."""
|
|
58
|
+
|
|
59
|
+
subnet: Subnet
|
|
60
|
+
net: int
|
|
61
|
+
toeprint: Toeprint
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@dataclass
|
|
65
|
+
class ComponentIndex:
|
|
66
|
+
"""Components split per side, with pads keyed by their full design path
|
|
67
|
+
so the padstack builder can attribute features to pins."""
|
|
68
|
+
|
|
69
|
+
files: dict[str, ComponentsFile] = field(default_factory=dict)
|
|
70
|
+
packages: list[Package] = field(default_factory=list)
|
|
71
|
+
pins: dict[str, Pin] = field(default_factory=dict)
|
|
72
|
+
# label substitutions per component, keyed by the component's path
|
|
73
|
+
labels: dict[RefPath, dict[str, str]] = field(default_factory=dict)
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def layer_names(self) -> list[str]:
|
|
77
|
+
return list(self.files)
|
|
78
|
+
|
|
79
|
+
def labels_for(self, path: RefPath) -> dict[str, str]:
|
|
80
|
+
"""Label placeholder substitutions (>REF, >VALUE) for a feature at
|
|
81
|
+
`path`, taken from the innermost component enclosing it. Empty when no
|
|
82
|
+
exported component owns the feature."""
|
|
83
|
+
for end in range(len(path), 0, -1):
|
|
84
|
+
found = self.labels.get(path[:end])
|
|
85
|
+
if found is not None:
|
|
86
|
+
return found
|
|
87
|
+
return {}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class EdaRecorder:
|
|
91
|
+
"""Collects SNT subnets and their FIDs during feature emission. FID layer
|
|
92
|
+
references are recorded by name and patched to LYR indices at assembly."""
|
|
93
|
+
|
|
94
|
+
def __init__(self, nets: NetIndex, components: ComponentIndex) -> None:
|
|
95
|
+
self._nets = nets
|
|
96
|
+
self._components = components
|
|
97
|
+
# net index -> ordered subnets
|
|
98
|
+
self._subnets: dict[int, list[Subnet]] = {}
|
|
99
|
+
self._trc: dict[int, Subnet] = {}
|
|
100
|
+
self._layer_names: list[tuple[Fid, str]] = []
|
|
101
|
+
|
|
102
|
+
def _register(self, net: int, subnet: Subnet) -> Subnet:
|
|
103
|
+
self._subnets.setdefault(net, []).append(subnet)
|
|
104
|
+
return subnet
|
|
105
|
+
|
|
106
|
+
def via(self, net: int) -> Subnet:
|
|
107
|
+
"""A new VIA subnet on the net."""
|
|
108
|
+
return self._register(net, Subnet("VIA"))
|
|
109
|
+
|
|
110
|
+
def trace(self, net: int) -> Subnet:
|
|
111
|
+
"""The net's shared TRC subnet, created on first use."""
|
|
112
|
+
subnet = self._trc.get(net)
|
|
113
|
+
if subnet is None:
|
|
114
|
+
subnet = self._trc[net] = self._register(net, Subnet("TRC"))
|
|
115
|
+
return subnet
|
|
116
|
+
|
|
117
|
+
def pin(self, path: str) -> Pin | None:
|
|
118
|
+
"""The component pin for a pad's full design path, if any."""
|
|
119
|
+
return self._components.pins.get(path)
|
|
120
|
+
|
|
121
|
+
def register_pin(self, net: int, pin: Pin) -> None:
|
|
122
|
+
self._register(net, pin.subnet)
|
|
123
|
+
|
|
124
|
+
def fid(self, subnet: Subnet, kind: str, layer_name: str, feature: int) -> None:
|
|
125
|
+
"""Record one feature reference; the layer index is patched later."""
|
|
126
|
+
fid = Fid(kind, -1, feature)
|
|
127
|
+
subnet.fids.append(fid)
|
|
128
|
+
self._layer_names.append((fid, layer_name))
|
|
129
|
+
|
|
130
|
+
def assemble(self, layers: list[str]) -> EdaData:
|
|
131
|
+
"""Build the EdaData with LYR indices patched and TOP subnet indices
|
|
132
|
+
filled into the toeprint records."""
|
|
133
|
+
index = {name: i for i, name in enumerate(layers)}
|
|
134
|
+
for fid, name in self._layer_names:
|
|
135
|
+
fid.layer = index[name]
|
|
136
|
+
by_subnet = {id(pin.subnet): pin for pin in self._components.pins.values()}
|
|
137
|
+
nets = []
|
|
138
|
+
for net_num, name in enumerate(self._nets.names):
|
|
139
|
+
subnets = self._subnets.get(net_num, [])
|
|
140
|
+
nets.append(EdaNet(name, subnets))
|
|
141
|
+
for position, subnet in enumerate(subnets):
|
|
142
|
+
pin = by_subnet.get(id(subnet))
|
|
143
|
+
if pin is not None:
|
|
144
|
+
pin.toeprint.subnet = position
|
|
145
|
+
pin.toeprint.net = net_num
|
|
146
|
+
return EdaData(layers, nets, self._components.packages)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def build_components(design: RuntimeDesign, nets: NetIndex) -> ComponentIndex:
|
|
150
|
+
"""Enumerate soldered components into per-side components files, package
|
|
151
|
+
definitions, and the pad-path index used by the padstack builder."""
|
|
152
|
+
out = ComponentIndex()
|
|
153
|
+
packages: dict[type, int] = {}
|
|
154
|
+
|
|
155
|
+
for trace, comp in design.query(Component):
|
|
156
|
+
if comp.soldered is False:
|
|
157
|
+
continue
|
|
158
|
+
if not trace.transform or not comp.transform:
|
|
159
|
+
logger.warning("Skipping unplaced component %s", trace.path)
|
|
160
|
+
continue
|
|
161
|
+
placement = trace.transform * comp.transform
|
|
162
|
+
side = placement.side if isinstance(placement, Placement) else Side.Top
|
|
163
|
+
layer_name = COMP_TOP if side == Side.Top else COMP_BOT
|
|
164
|
+
file = out.files.setdefault(layer_name, ComponentsFile())
|
|
165
|
+
|
|
166
|
+
pads = list(visit(comp, Pad))
|
|
167
|
+
pkg_ref = _package(out, packages, comp, pads)
|
|
168
|
+
|
|
169
|
+
refdes = comp.reference_designator or f"UNK{len(file.records)}"
|
|
170
|
+
part = legal_name(str(comp.mpn or typeof(comp).__name__))
|
|
171
|
+
properties: list[tuple[str, str]] = []
|
|
172
|
+
if comp.mpn:
|
|
173
|
+
properties.append(("PART_NO", str(comp.mpn)))
|
|
174
|
+
if comp.manufacturer:
|
|
175
|
+
properties.append(("MANUFACTURER", str(comp.manufacturer)))
|
|
176
|
+
if comp.value is not None:
|
|
177
|
+
properties.append(("VALUE", _value_text(comp.value)))
|
|
178
|
+
|
|
179
|
+
# .comp_mount_type options: Other;SMT;THMT;PressFit
|
|
180
|
+
through = any(list(extract(pad, Cutout)) for _, pad in pads)
|
|
181
|
+
record = ComponentRecord(
|
|
182
|
+
package=pkg_ref,
|
|
183
|
+
x=placement.translation[0] / MM_PER_INCH,
|
|
184
|
+
y=placement.translation[1] / MM_PER_INCH,
|
|
185
|
+
rotation=(-placement.rotation) % 360.0,
|
|
186
|
+
mirror=side == Side.Bottom,
|
|
187
|
+
name=refdes,
|
|
188
|
+
part=part,
|
|
189
|
+
properties=properties,
|
|
190
|
+
attributes=[(".comp_mount_type", 2 if through else 1)],
|
|
191
|
+
)
|
|
192
|
+
cmp_num = len(file.records)
|
|
193
|
+
file.records.append(record)
|
|
194
|
+
|
|
195
|
+
for pin_num, (ptrace, pad) in enumerate(pads):
|
|
196
|
+
local = (ptrace.transform or IDENTITY) * (pad.transform or IDENTITY)
|
|
197
|
+
placed = placement * local
|
|
198
|
+
net = nets.index_for(pad)
|
|
199
|
+
toeprint = Toeprint(
|
|
200
|
+
pin=pin_num,
|
|
201
|
+
x=placed.translation[0] / MM_PER_INCH,
|
|
202
|
+
y=placed.translation[1] / MM_PER_INCH,
|
|
203
|
+
rotation=(-placed.rotation) % 360.0,
|
|
204
|
+
mirror=side == Side.Bottom,
|
|
205
|
+
net=net,
|
|
206
|
+
subnet=0,
|
|
207
|
+
name=_pin_name(ptrace.path, pin_num),
|
|
208
|
+
)
|
|
209
|
+
record.toeprints.append(toeprint)
|
|
210
|
+
subnet = Subnet(
|
|
211
|
+
"TOP",
|
|
212
|
+
side="T" if side == Side.Top else "B",
|
|
213
|
+
component=cmp_num,
|
|
214
|
+
toeprint=pin_num,
|
|
215
|
+
)
|
|
216
|
+
out.pins[f"{trace.path}.{ptrace.path}"] = Pin(subnet, net, toeprint)
|
|
217
|
+
|
|
218
|
+
labels = {REF_LABEL: refdes}
|
|
219
|
+
if comp.value is not None:
|
|
220
|
+
labels[VALUE_LABEL] = _label_text(comp.value)
|
|
221
|
+
out.labels[trace.path] = labels
|
|
222
|
+
return out
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def _value_text(value: str | PlainQuantity) -> str:
|
|
226
|
+
"""Render a component value the way the jitx translate layer does, so the
|
|
227
|
+
exported text agrees with what the rest of the toolchain shows.
|
|
228
|
+
|
|
229
|
+
`str()` on a quantity gives `1e-07 farad`; `:g~P` gives `100 nF` for a
|
|
230
|
+
value written with the prefix its author meant."""
|
|
231
|
+
if isinstance(value, str):
|
|
232
|
+
return value
|
|
233
|
+
return f"{value:g~P}"
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def _label_text(value: str | PlainQuantity) -> str:
|
|
237
|
+
"""Render a component value for a silkscreen label.
|
|
238
|
+
|
|
239
|
+
RKM codes are compact and pure ASCII, which matters on silkscreen and in
|
|
240
|
+
ODB++ text records; the `:g~P` form used for the VALUE property emits the
|
|
241
|
+
micro and ohm signs."""
|
|
242
|
+
if isinstance(value, str):
|
|
243
|
+
return value
|
|
244
|
+
return rkm_code(value)
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def _pin_name(path: object, fallback: int) -> str:
|
|
248
|
+
leaf = str(path).rsplit(".", 1)[-1]
|
|
249
|
+
return legal_name(leaf) if leaf else str(fallback)
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def _package(
|
|
253
|
+
out: ComponentIndex,
|
|
254
|
+
packages: dict[type, int],
|
|
255
|
+
comp: Component,
|
|
256
|
+
pads: list,
|
|
257
|
+
) -> int:
|
|
258
|
+
"""The package index for a component, created from its landpattern (pad
|
|
259
|
+
layout in component-local coordinates) on first sight.
|
|
260
|
+
|
|
261
|
+
Packages are keyed by the landpattern's true class (typeof unwraps the
|
|
262
|
+
Proxy), falling back to the component class when there is no landpattern;
|
|
263
|
+
same-named classes from different modules stay distinct."""
|
|
264
|
+
landpattern = next(iter(extract(comp, Landpattern)), None)
|
|
265
|
+
cls = typeof(landpattern if landpattern is not None else comp)
|
|
266
|
+
existing = packages.get(cls)
|
|
267
|
+
if existing is not None:
|
|
268
|
+
return existing
|
|
269
|
+
|
|
270
|
+
pins: list[PackagePin] = []
|
|
271
|
+
centers: list[tuple[float, float]] = []
|
|
272
|
+
bounds: list[tuple[float, float]] = []
|
|
273
|
+
for pin_num, (ptrace, pad) in enumerate(pads):
|
|
274
|
+
local = (ptrace.transform or IDENTITY) * (pad.transform or IDENTITY)
|
|
275
|
+
x, y = local.translation
|
|
276
|
+
centers.append((x / MM_PER_INCH, y / MM_PER_INCH))
|
|
277
|
+
shape = pad.shape.shape if isinstance(pad.shape, PadShape) else pad.shape
|
|
278
|
+
outline = to_contours(shape, transform=local)
|
|
279
|
+
for contour in outline:
|
|
280
|
+
bounds.append(contour.start)
|
|
281
|
+
bounds.extend((seg.x, seg.y) for seg in contour.segments)
|
|
282
|
+
pins.append(
|
|
283
|
+
PackagePin(
|
|
284
|
+
name=_pin_name(ptrace.path, pin_num),
|
|
285
|
+
x=x / MM_PER_INCH,
|
|
286
|
+
y=y / MM_PER_INCH,
|
|
287
|
+
type="T" if list(extract(pad, Cutout)) else "S",
|
|
288
|
+
outline=outline,
|
|
289
|
+
)
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
points = bounds or centers or [(0.0, 0.0)]
|
|
293
|
+
xs = [p[0] for p in points]
|
|
294
|
+
ys = [p[1] for p in points]
|
|
295
|
+
pitch = 0.0
|
|
296
|
+
if len(centers) > 1:
|
|
297
|
+
pitch = min(
|
|
298
|
+
((ax - bx) ** 2 + (ay - by) ** 2) ** 0.5
|
|
299
|
+
for i, (ax, ay) in enumerate(centers)
|
|
300
|
+
for bx, by in centers[i + 1 :]
|
|
301
|
+
)
|
|
302
|
+
name = legal_name(cls.__name__)
|
|
303
|
+
taken = {pkg.name for pkg in out.packages}
|
|
304
|
+
suffix = 1
|
|
305
|
+
while name in taken:
|
|
306
|
+
suffix += 1
|
|
307
|
+
name = f"{legal_name(cls.__name__)}_{suffix}"
|
|
308
|
+
package = Package(name, pitch, min(xs), min(ys), max(xs), max(ys), pins)
|
|
309
|
+
packages[cls] = len(out.packages)
|
|
310
|
+
out.packages.append(package)
|
|
311
|
+
return packages[cls]
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Convert JITX copper (traces and pours) to signal-layer features.
|
|
2
|
+
|
|
3
|
+
Pours arrive from the runtime already computed with isolation and clearance,
|
|
4
|
+
so they are plain positive surfaces. Vias and pads are opaque here; their
|
|
5
|
+
copper is built by padstacks.py.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from jitx import Copper, Placement, Via
|
|
11
|
+
from jitx.landpattern import Pad
|
|
12
|
+
|
|
13
|
+
from jitx.run.runtime import RuntimeDesign
|
|
14
|
+
|
|
15
|
+
from ..format.model import Step
|
|
16
|
+
from .components import EdaRecorder
|
|
17
|
+
from .geometry import add_surface, add_trace, is_trace
|
|
18
|
+
from .layers import LayerModel
|
|
19
|
+
from .nets import NetIndex
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def build_copper(
|
|
23
|
+
design: RuntimeDesign,
|
|
24
|
+
layer_model: LayerModel,
|
|
25
|
+
step: Step,
|
|
26
|
+
nets: NetIndex,
|
|
27
|
+
recorder: EdaRecorder,
|
|
28
|
+
) -> None:
|
|
29
|
+
"""Add L/A records for traces and S records for other copper, reporting
|
|
30
|
+
each feature to the net's TRC subnet."""
|
|
31
|
+
for trace, copper in design.query(Copper, opaque=Via | Pad):
|
|
32
|
+
if not trace.transform:
|
|
33
|
+
continue
|
|
34
|
+
placement = Placement(trace.transform)
|
|
35
|
+
name = layer_model.signal_name(placement.side.apply(copper.layer))
|
|
36
|
+
file = step.layer(name)
|
|
37
|
+
if is_trace(copper.shape):
|
|
38
|
+
ids = add_trace(file, copper.shape, transform=trace.transform)
|
|
39
|
+
else:
|
|
40
|
+
ids = add_surface(file, copper.shape, transform=trace.transform)
|
|
41
|
+
if ids:
|
|
42
|
+
subnet = recorder.trace(nets.index_for(copper))
|
|
43
|
+
for feature in ids:
|
|
44
|
+
recorder.fid(subnet, "C", name, feature)
|