altium-toolkit 0.1.23 → 1.0.1
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.
- package/README.md +4 -3
- package/docs/api.md +47 -8
- package/docs/model-format.md +30 -6
- package/package.json +2 -1
- package/spec/library-scope.md +2 -1
- package/src/core/altium/AltiumParser.mjs +17 -4
- package/src/core/circuit-json/CircuitJsonModelAdapter.mjs +826 -0
- package/src/core/circuit-json/CircuitJsonModelAdapterPrimitives.mjs +354 -0
- package/src/core/circuit-json/CircuitJsonModelSchema.mjs +83 -0
- package/src/core/netlist-query/CircuitTraversal.mjs +325 -0
- package/src/core/netlist-query/ComponentGrouping.mjs +355 -0
- package/src/core/netlist-query/LoadedDesignNetlistService.mjs +732 -0
- package/src/core/netlist-query/QueryNetlistBuilder.mjs +180 -0
- package/src/core/netlist-query/RegexPattern.mjs +89 -0
- package/src/netlist-query.mjs +12 -0
- package/src/parser.mjs +2 -0
- package/src/ui/PcbScene3dBoardOutlineRefiner.mjs +402 -0
- package/src/ui/PcbScene3dBuilder.mjs +16 -5
- package/src/ui/PcbScene3dDrillCutoutBuilder.mjs +26 -15
package/README.md
CHANGED
|
@@ -27,10 +27,11 @@ browser or Node-based tools.
|
|
|
27
27
|
basic text metrics
|
|
28
28
|
- Preserve raw PCB primitive records through a read-only record registry so
|
|
29
29
|
unsupported or partially decoded stream data remains inspectable
|
|
30
|
-
- Emit
|
|
31
|
-
|
|
30
|
+
- Emit Circuit JSON arrays from parser roots, with non-serialized
|
|
31
|
+
renderer-compatibility fields for existing consumers
|
|
32
32
|
- Render schematic SVG, PCB SVG, and grouped BOM HTML
|
|
33
|
-
- Build non-interactive PCB 3D scene-description data for host applications
|
|
33
|
+
- Build non-interactive PCB 3D scene-description data for host applications,
|
|
34
|
+
including refined board outlines and silkscreen drill cutouts
|
|
34
35
|
- Render a static 3D board summary
|
|
35
36
|
- Run entirely with local input data; no network calls are made by the parser
|
|
36
37
|
|
package/docs/api.md
CHANGED
|
@@ -14,6 +14,7 @@ scene-description classes from one entrypoint.
|
|
|
14
14
|
Specialized entrypoints are also available:
|
|
15
15
|
|
|
16
16
|
- `altium-toolkit/parser`
|
|
17
|
+
- `altium-toolkit/netlist-query`
|
|
17
18
|
- `altium-toolkit/renderers`
|
|
18
19
|
- `altium-toolkit/scene3d`
|
|
19
20
|
- `altium-toolkit/workers/altium-parser.worker.mjs`
|
|
@@ -24,15 +25,16 @@ Specialized entrypoints are also available:
|
|
|
24
25
|
```js
|
|
25
26
|
import { AltiumParser } from 'altium-toolkit/parser'
|
|
26
27
|
|
|
27
|
-
const
|
|
28
|
+
const circuitJson = AltiumParser.parseArrayBuffer(fileName, arrayBuffer)
|
|
28
29
|
```
|
|
29
30
|
|
|
30
31
|
`fileName` is used to infer schematic, PCB document, PCB footprint-library, or
|
|
31
32
|
PCB project parsing from the extension. The parser accepts native `.SchDoc`,
|
|
32
|
-
`.PcbDoc`, `.PcbLib`, and `.PrjPcb` bytes as an `ArrayBuffer` and returns
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
`.PcbDoc`, `.PcbLib`, and `.PrjPcb` bytes as an `ArrayBuffer` and returns a
|
|
34
|
+
Circuit JSON element array. The returned array carries non-serialized
|
|
35
|
+
renderer-compatibility fields such as `kind`, `fileType`, `schematic`, `pcb`,
|
|
36
|
+
`pcbLibrary`, `project`, `summary`, `diagnostics`, and `bom` so existing
|
|
37
|
+
renderers can consume parser output directly during the migration.
|
|
36
38
|
|
|
37
39
|
PCB parsing reads the main primitive streams together with sidecar streams such
|
|
38
40
|
as `PrimitiveParameters/Data` and `WideStrings6/Data`. Component parameters are
|
|
@@ -41,13 +43,18 @@ resolve their display string through the wide-string table before the
|
|
|
41
43
|
normalized component list and BOM are built.
|
|
42
44
|
|
|
43
45
|
```js
|
|
44
|
-
import {
|
|
46
|
+
import { CircuitJsonModelSchema } from 'altium-toolkit/parser'
|
|
45
47
|
|
|
46
|
-
if (
|
|
47
|
-
throw new Error('Unsupported
|
|
48
|
+
if (!CircuitJsonModelSchema.isModel(circuitJson)) {
|
|
49
|
+
throw new Error('Unsupported Circuit JSON model')
|
|
48
50
|
}
|
|
49
51
|
```
|
|
50
52
|
|
|
53
|
+
Use `AltiumParser.parseArrayBufferToRendererModel(fileName, arrayBuffer)` when
|
|
54
|
+
an integration still needs the legacy renderer model object. The
|
|
55
|
+
`CircuitJsonModelAdapter` export also exposes `fromRendererModel()`,
|
|
56
|
+
`toRendererModel()`, and `isCircuitJson()` for explicit conversions.
|
|
57
|
+
|
|
51
58
|
Specialized parser helpers are exported for lower-level integrations, including
|
|
52
59
|
`PcbBoardRegionSemanticsParser`, `PcbComponentPrimitiveIndexer`,
|
|
53
60
|
`PcbEmbeddedFontExtractor`, `PcbFontMetricsParser`, `PcbPadStackParser`,
|
|
@@ -63,6 +70,35 @@ to normalized models. `PcbRawRecordRegistry` exposes immutable primitive stream
|
|
|
63
70
|
descriptors and the raw-record preservation helpers used by the PcbDoc/PcbLib
|
|
64
71
|
extractors.
|
|
65
72
|
|
|
73
|
+
## Netlist Query
|
|
74
|
+
|
|
75
|
+
```js
|
|
76
|
+
import { LoadedDesignNetlistService } from 'altium-toolkit/netlist-query'
|
|
77
|
+
|
|
78
|
+
const service = new LoadedDesignNetlistService({
|
|
79
|
+
getDocuments: () => [
|
|
80
|
+
{
|
|
81
|
+
id: 'active-sheet',
|
|
82
|
+
active: true,
|
|
83
|
+
documentModel
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
const nets = service.searchNets({ pattern: 'i2c' })
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The `netlist-query` entrypoint exposes browser-safe helpers for loaded document
|
|
92
|
+
inspection: `LoadedDesignNetlistService`, `QueryNetlistBuilder`,
|
|
93
|
+
`CircuitTraversal`, `ComponentGrouping`, `MPN_MISSING_NOTE`, and
|
|
94
|
+
`RegexPattern`.
|
|
95
|
+
|
|
96
|
+
The service accepts host-provided loaded document entries and returns plain
|
|
97
|
+
JSON-compatible query results. It can list designs, components, and nets; search
|
|
98
|
+
components by reference designator, MPN, or description; query one component's
|
|
99
|
+
pin connections; and trace extended connectivity from a net or `REFDES.PIN`.
|
|
100
|
+
Normal user-query failures return `{ error: string }`.
|
|
101
|
+
|
|
66
102
|
## Renderers
|
|
67
103
|
|
|
68
104
|
```js
|
|
@@ -100,6 +136,9 @@ import {
|
|
|
100
136
|
|
|
101
137
|
- `PcbScene3dBuilder.build(documentModel, options)` returns procedural board,
|
|
102
138
|
placement, copper, silkscreen, and external-model scene-description data.
|
|
139
|
+
It includes refined board-region outlines when a recovered outline is a
|
|
140
|
+
rasterized stair-step fallback, and each silkscreen side exposes
|
|
141
|
+
`drillCutouts` plus fill holes for drilled pads and vias.
|
|
103
142
|
- `PcbScene3dModelRegistry` resolves embedded or session model candidates for
|
|
104
143
|
component placements.
|
|
105
144
|
- `PcbScene3dScenePreparator.prepare(documentModel, options)` prepares the same
|
package/docs/model-format.md
CHANGED
|
@@ -6,8 +6,30 @@ SPDX-License-Identifier: CC-BY-SA-4.0
|
|
|
6
6
|
|
|
7
7
|
# Model Format
|
|
8
8
|
|
|
9
|
-
The
|
|
10
|
-
|
|
9
|
+
The public parser returns one Circuit JSON element array per parsed native
|
|
10
|
+
document. Circuit JSON is the serialized model contract. The returned array
|
|
11
|
+
also carries non-serialized renderer-compatibility fields that preserve the
|
|
12
|
+
previous ECAD Forge parser model for renderers and migration code.
|
|
13
|
+
|
|
14
|
+
## Circuit JSON Fields
|
|
15
|
+
|
|
16
|
+
Every parser result is an array of elements with a `type` field. The adapter
|
|
17
|
+
emits Circuit JSON elements for source project metadata, source components,
|
|
18
|
+
ports, nets, schematic symbols, schematic lines, schematic text, PCB boards,
|
|
19
|
+
PCB components, PCB pads, PCB traces, and PCB vias where those structures are
|
|
20
|
+
available in the source document.
|
|
21
|
+
|
|
22
|
+
Use `CircuitJsonModelSchema.isModel(result)` to validate that a value is a
|
|
23
|
+
Circuit JSON array. `JSON.stringify(result)` serializes only the Circuit JSON
|
|
24
|
+
elements; compatibility fields are intentionally omitted from serialized JSON.
|
|
25
|
+
|
|
26
|
+
## Renderer Compatibility Fields
|
|
27
|
+
|
|
28
|
+
For compatibility, `AltiumParser.parseArrayBuffer()` attaches the previous
|
|
29
|
+
renderer model fields directly to the Circuit JSON array. Integrations that need
|
|
30
|
+
the object form can call
|
|
31
|
+
`AltiumParser.parseArrayBufferToRendererModel(fileName, arrayBuffer)` or
|
|
32
|
+
`CircuitJsonModelAdapter.toRendererModel(circuitJson)`.
|
|
11
33
|
|
|
12
34
|
## Common Fields
|
|
13
35
|
|
|
@@ -21,11 +43,13 @@ The parser returns one object per parsed native document.
|
|
|
21
43
|
|
|
22
44
|
## Schema Contracts
|
|
23
45
|
|
|
24
|
-
The
|
|
46
|
+
The legacy renderer compatibility contract is published as a JSON Schema at
|
|
25
47
|
[`docs/schemas/altium_toolkit/normalized_model_a1.schema.json`](schemas/altium_toolkit/normalized_model_a1.schema.json).
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
48
|
+
Compatibility fields expose the same id through the top-level `schema` field,
|
|
49
|
+
and consumers can compare it with `NormalizedModelSchema.CURRENT_SCHEMA_ID`.
|
|
50
|
+
The serialized parser return value follows the upstream
|
|
51
|
+
[`tscircuit/circuit-json`](https://github.com/tscircuit/circuit-json) element
|
|
52
|
+
array convention.
|
|
29
53
|
|
|
30
54
|
## Schematic Fields
|
|
31
55
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "altium-toolkit",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Altium document parsing and non-interactive rendering utilities",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"altium",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"exports": {
|
|
24
24
|
".": "./src/index.mjs",
|
|
25
25
|
"./parser": "./src/parser.mjs",
|
|
26
|
+
"./netlist-query": "./src/netlist-query.mjs",
|
|
26
27
|
"./renderers": "./src/renderers.mjs",
|
|
27
28
|
"./scene3d": "./src/scene3d.mjs",
|
|
28
29
|
"./workers/altium-parser.worker.mjs": "./src/workers/altium-parser.worker.mjs",
|
package/spec/library-scope.md
CHANGED
|
@@ -16,7 +16,8 @@ rendering primitives.
|
|
|
16
16
|
- Schematic SVG rendering
|
|
17
17
|
- PCB SVG rendering
|
|
18
18
|
- BOM HTML rendering
|
|
19
|
-
- PCB 3D scene-description data
|
|
19
|
+
- PCB 3D scene-description data, including board-region outline refinement and
|
|
20
|
+
silkscreen drill cutout contours
|
|
20
21
|
- Embedded PCB/PcbLib font extraction and basic text metrics for deterministic
|
|
21
22
|
SVG rendering
|
|
22
23
|
- Read-only PCB primitive record registry metadata and base64 raw-record
|
|
@@ -27,6 +27,7 @@ import { SchematicImageParser } from './SchematicImageParser.mjs'
|
|
|
27
27
|
import { SchematicNetlistBuilder } from './SchematicNetlistBuilder.mjs'
|
|
28
28
|
import { SchematicComponentTextResolver } from './SchematicComponentTextResolver.mjs'
|
|
29
29
|
import { SchematicStreamExtractor } from './SchematicStreamExtractor.mjs'
|
|
30
|
+
import { CircuitJsonModelAdapter } from '../circuit-json/CircuitJsonModelAdapter.mjs'
|
|
30
31
|
const {
|
|
31
32
|
countMatchingKeys,
|
|
32
33
|
getDisplayText,
|
|
@@ -53,16 +54,28 @@ const {
|
|
|
53
54
|
} = SchematicPinParser
|
|
54
55
|
|
|
55
56
|
/**
|
|
56
|
-
* Parses native Altium files into
|
|
57
|
+
* Parses native Altium files into Circuit JSON element arrays.
|
|
57
58
|
*/
|
|
58
59
|
export class AltiumParser {
|
|
59
60
|
/**
|
|
60
|
-
* Parses a native Altium buffer into a
|
|
61
|
+
* Parses a native Altium buffer into a Circuit JSON element array.
|
|
61
62
|
* @param {string} fileName
|
|
62
63
|
* @param {ArrayBuffer} arrayBuffer
|
|
63
|
-
* @returns {
|
|
64
|
+
* @returns {object[]}
|
|
64
65
|
*/
|
|
65
66
|
static parseArrayBuffer(fileName, arrayBuffer) {
|
|
67
|
+
return CircuitJsonModelAdapter.fromRendererModel(
|
|
68
|
+
AltiumParser.parseArrayBufferToRendererModel(fileName, arrayBuffer)
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Parses a native Altium buffer into the renderer compatibility model.
|
|
74
|
+
* @param {string} fileName
|
|
75
|
+
* @param {ArrayBuffer} arrayBuffer
|
|
76
|
+
* @returns {{ schema: string, kind: 'schematic' | 'pcb' | 'pcb-library' | 'project', fileType: 'SchDoc' | 'PcbDoc' | 'PcbLib' | 'PrjPcb', fileName: string, summary: Record<string, number | string>, diagnostics: { severity: 'info' | 'warning', message: string }[], schematic?: Record<string, unknown>, pcb?: Record<string, unknown>, pcbLibrary?: Record<string, unknown>, project?: Record<string, unknown>, bom: { designators: string[], quantity: number, pattern: string, source: string, value: string }[] }}
|
|
77
|
+
*/
|
|
78
|
+
static parseArrayBufferToRendererModel(fileName, arrayBuffer) {
|
|
66
79
|
const records = AsciiRecordParser.parse(arrayBuffer)
|
|
67
80
|
const fileType = AltiumParser.#sniffFileType(fileName, records)
|
|
68
81
|
if (fileType === 'SchDoc') {
|
|
@@ -118,7 +131,7 @@ export class AltiumParser {
|
|
|
118
131
|
* @param {string} fileName
|
|
119
132
|
* @param {{ raw: string, fields: Record<string, string | string[]> }[]} records
|
|
120
133
|
* @param {ArrayBuffer} arrayBuffer
|
|
121
|
-
* @returns {ReturnType<typeof AltiumParser.
|
|
134
|
+
* @returns {ReturnType<typeof AltiumParser.parseArrayBufferToRendererModel>}
|
|
122
135
|
*/
|
|
123
136
|
static #parseSchematic(fileName, records, arrayBuffer) {
|
|
124
137
|
const componentRecords = records.filter(
|