altium-toolkit 1.0.8 → 1.0.10
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 +18 -6
- package/docs/api.md +78 -16
- package/docs/model-format.md +229 -8
- package/docs/schemas/altium_toolkit/ci_artifact_bundle_a1.schema.json +76 -0
- package/docs/schemas/altium_toolkit/draftsman_digest_a1.schema.json +35 -0
- package/docs/schemas/altium_toolkit/netlist_a1.schema.json +53 -0
- package/docs/schemas/altium_toolkit/normalized_model_a1.schema.json +1826 -110
- package/docs/schemas/altium_toolkit/parser_compatibility_fuzz_a1.schema.json +25 -0
- package/docs/schemas/altium_toolkit/pcb_svg_semantics_a1.schema.json +86 -0
- package/docs/schemas/altium_toolkit/project_bundle_a1.schema.json +63 -0
- package/docs/schemas/altium_toolkit/project_document_graph_a1.schema.json +33 -0
- package/docs/schemas/altium_toolkit/schematic_svg_semantics_a1.schema.json +50 -0
- package/docs/schemas/altium_toolkit/svg_model_cross_link_a1.schema.json +39 -0
- package/docs/testing.md +9 -3
- package/package.json +1 -1
- package/spec/library-scope.md +7 -1
- package/src/core/altium/AltiumLayoutParser.mjs +104 -8
- package/src/core/altium/AltiumParser.mjs +196 -45
- package/src/core/altium/CiArtifactBundleBuilder.mjs +202 -0
- package/src/core/altium/DraftsmanDigestParser.mjs +689 -0
- package/src/core/altium/EmbeddedFileInventoryBuilder.mjs +255 -0
- package/src/core/altium/IntLibModelParser.mjs +240 -0
- package/src/core/altium/IntLibStreamExtractor.mjs +366 -0
- package/src/core/altium/LibraryRenderManifestBuilder.mjs +417 -0
- package/src/core/altium/LibrarySearchIndex.mjs +215 -0
- package/src/core/altium/NormalizedModelSchema.mjs +36 -0
- package/src/core/altium/ParserCompatibilityFuzzer.mjs +192 -0
- package/src/core/altium/PcbCustomPadShapeParser.mjs +244 -0
- package/src/core/altium/PcbDefaultsParser.mjs +171 -0
- package/src/core/altium/PcbDimensionParser.mjs +229 -0
- package/src/core/altium/PcbEmbeddedModelExtractor.mjs +232 -6
- package/src/core/altium/PcbExtendedPrimitiveInformationParser.mjs +256 -0
- package/src/core/altium/PcbLibModelParser.mjs +235 -14
- package/src/core/altium/PcbLibStreamExtractor.mjs +62 -4
- package/src/core/altium/PcbMaskPasteResolver.mjs +354 -0
- package/src/core/altium/PcbMechanicalLayerPairParser.mjs +204 -0
- package/src/core/altium/PcbModelParser.mjs +495 -32
- package/src/core/altium/PcbOwnershipGraphBuilder.mjs +245 -0
- package/src/core/altium/PcbPadPrimitiveParser.mjs +78 -65
- package/src/core/altium/PcbPadStackParser.mjs +229 -2
- package/src/core/altium/PcbPickPlacePositionResolver.mjs +224 -0
- package/src/core/altium/PcbPrimitiveParameterParser.mjs +3 -2
- package/src/core/altium/PcbRawRecordRegistry.mjs +121 -130
- package/src/core/altium/PcbRegionPrimitiveParser.mjs +76 -3
- package/src/core/altium/PcbRouteAnalysisBuilder.mjs +730 -0
- package/src/core/altium/PcbRuleParser.mjs +354 -33
- package/src/core/altium/PcbSidecarRecordParser.mjs +177 -0
- package/src/core/altium/PcbSpecialStringResolver.mjs +220 -0
- package/src/core/altium/PcbStatisticsBuilder.mjs +541 -0
- package/src/core/altium/PcbStreamExtractor.mjs +111 -4
- package/src/core/altium/PcbTextPrimitiveParser.mjs +60 -0
- package/src/core/altium/PcbUnionParser.mjs +307 -0
- package/src/core/altium/PcbViaStackParser.mjs +98 -10
- package/src/core/altium/PcbViaStructureParser.mjs +335 -0
- package/src/core/altium/PrintableTextDecoder.mjs +53 -3
- package/src/core/altium/PrjPcbModelParser.mjs +281 -7
- package/src/core/altium/ProjectAnnotationParser.mjs +205 -0
- package/src/core/altium/ProjectDesignBundleBuilder.mjs +492 -0
- package/src/core/altium/ProjectDocumentGraphBuilder.mjs +280 -0
- package/src/core/altium/ProjectNetlistExporter.mjs +503 -0
- package/src/core/altium/ProjectOutJobDigestBuilder.mjs +109 -0
- package/src/core/altium/ProjectVariantViewBuilder.mjs +334 -0
- package/src/core/altium/SchematicBindingProvenanceParser.mjs +223 -0
- package/src/core/altium/SchematicComponentOwnerTextResolver.mjs +312 -0
- package/src/core/altium/SchematicComponentTextResolver.mjs +72 -19
- package/src/core/altium/SchematicConnectivityQaBuilder.mjs +271 -0
- package/src/core/altium/SchematicCrossSheetConnectorParser.mjs +140 -0
- package/src/core/altium/SchematicDirectiveParser.mjs +312 -0
- package/src/core/altium/SchematicDisplayModeCatalogParser.mjs +231 -0
- package/src/core/altium/SchematicHarnessParser.mjs +302 -0
- package/src/core/altium/SchematicImageParser.mjs +474 -3
- package/src/core/altium/SchematicImplementationParser.mjs +518 -0
- package/src/core/altium/SchematicNetlistBuilder.mjs +15 -2
- package/src/core/altium/SchematicOwnershipGraphParser.mjs +195 -0
- package/src/core/altium/SchematicPinParser.mjs +84 -1
- package/src/core/altium/SchematicPrimitiveParser.mjs +301 -0
- package/src/core/altium/SchematicProjectParameterResolver.mjs +361 -0
- package/src/core/altium/SchematicQaReportBuilder.mjs +284 -0
- package/src/core/altium/SchematicRecordTypeRegistry.mjs +137 -0
- package/src/core/altium/SchematicRepeatedChannelParser.mjs +229 -0
- package/src/core/altium/SchematicStreamExtractor.mjs +10 -1
- package/src/core/altium/SchematicTemplateParser.mjs +256 -0
- package/src/core/altium/SchematicTextParser.mjs +123 -0
- package/src/core/altium/SvgModelCrossLinkValidator.mjs +402 -0
- package/src/core/circuit-json/CircuitJsonModelAdapter.mjs +136 -96
- package/src/core/circuit-json/CircuitJsonModelAdapterPcbElements.mjs +244 -0
- package/src/core/circuit-json/CircuitJsonModelSchema.mjs +1 -1
- package/src/core/ole/OleCompoundDocument.mjs +20 -0
- package/src/parser.mjs +35 -0
- package/src/styles/altium-renderers.css +19 -0
- package/src/ui/PcbBarcodeTextRenderer.mjs +436 -0
- package/src/ui/PcbInteractionIndex.mjs +9 -4
- package/src/ui/PcbScene3dBuilder.mjs +137 -3
- package/src/ui/PcbScene3dModelRegistry.mjs +74 -0
- package/src/ui/PcbSvgRenderer.mjs +1252 -34
- package/src/ui/PcbTextPrimitiveRenderer.mjs +193 -7
- package/src/ui/SchematicNoteRenderer.mjs +9 -2
- package/src/ui/SchematicOwnerPinLabelLayout.mjs +206 -0
- package/src/ui/SchematicShapeRenderer.mjs +362 -0
- package/src/ui/SchematicSvgRenderer.mjs +1442 -92
- package/src/ui/SchematicTypography.mjs +48 -5
- package/src/ui/TextGeometrySidecarBuilder.mjs +147 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 André Fiedler
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Builds a read-only project document graph from parsed PrjPcb metadata.
|
|
7
|
+
*/
|
|
8
|
+
export class ProjectDocumentGraphBuilder {
|
|
9
|
+
static SCHEMA = 'altium-toolkit.project.document-graph.a1'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Builds a normalized document graph index.
|
|
13
|
+
* @param {object} projectModel Parsed project model or project payload.
|
|
14
|
+
* @param {{ availablePaths?: string[] | Set<string> }} options Graph options.
|
|
15
|
+
* @returns {object}
|
|
16
|
+
*/
|
|
17
|
+
static build(projectModel = {}, options = {}) {
|
|
18
|
+
const project = projectModel?.project || projectModel || {}
|
|
19
|
+
const documents = ProjectDocumentGraphBuilder.#documentRows(
|
|
20
|
+
project.documents || [],
|
|
21
|
+
project.outputGroups || [],
|
|
22
|
+
options
|
|
23
|
+
)
|
|
24
|
+
const groups = ProjectDocumentGraphBuilder.#groups(
|
|
25
|
+
documents,
|
|
26
|
+
project.outputGroups || []
|
|
27
|
+
)
|
|
28
|
+
const indexes = ProjectDocumentGraphBuilder.#indexes(
|
|
29
|
+
documents,
|
|
30
|
+
project.outputGroups || []
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
schema: ProjectDocumentGraphBuilder.SCHEMA,
|
|
35
|
+
summary: {
|
|
36
|
+
documentCount: documents.length,
|
|
37
|
+
sourceSheetCount: groups.sourceSheets.length,
|
|
38
|
+
pcbDocumentCount: groups.pcbs.length,
|
|
39
|
+
linkedLibraryCount: groups.linkedLibraries.length,
|
|
40
|
+
harnessFileCount: groups.harnessFiles.length,
|
|
41
|
+
outJobReferenceCount: groups.outJobs.length,
|
|
42
|
+
generatedOutputCount: groups.generatedOutputs.length,
|
|
43
|
+
missingPathCount: groups.missingPaths.length
|
|
44
|
+
},
|
|
45
|
+
documents,
|
|
46
|
+
groups,
|
|
47
|
+
indexes
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Builds detailed document graph rows.
|
|
53
|
+
* @param {object[]} documents Project document rows.
|
|
54
|
+
* @param {object[]} outputGroups Project output groups.
|
|
55
|
+
* @param {{ availablePaths?: string[] | Set<string> }} options Graph options.
|
|
56
|
+
* @returns {object[]}
|
|
57
|
+
*/
|
|
58
|
+
static #documentRows(documents, outputGroups, options) {
|
|
59
|
+
const availablePaths =
|
|
60
|
+
options.availablePaths == null
|
|
61
|
+
? null
|
|
62
|
+
: new Set(
|
|
63
|
+
[...options.availablePaths].map((path) =>
|
|
64
|
+
ProjectDocumentGraphBuilder.#normalizePath(path)
|
|
65
|
+
)
|
|
66
|
+
)
|
|
67
|
+
const outputsByDocumentPath =
|
|
68
|
+
ProjectDocumentGraphBuilder.#outputsByDocumentPath(outputGroups)
|
|
69
|
+
|
|
70
|
+
return (documents || []).map((document, index) =>
|
|
71
|
+
ProjectDocumentGraphBuilder.#stripUndefined({
|
|
72
|
+
graphIndex: index,
|
|
73
|
+
documentIndex: document.index,
|
|
74
|
+
section: document.section,
|
|
75
|
+
path: document.path || '',
|
|
76
|
+
normalizedPath:
|
|
77
|
+
document.normalizedPath ||
|
|
78
|
+
ProjectDocumentGraphBuilder.#normalizePath(document.path),
|
|
79
|
+
fileName:
|
|
80
|
+
document.fileName ||
|
|
81
|
+
ProjectDocumentGraphBuilder.#basename(document.path),
|
|
82
|
+
extension: document.extension || '',
|
|
83
|
+
kind: document.kind || 'other',
|
|
84
|
+
uniqueId: document.uniqueId || '',
|
|
85
|
+
isStub: document.isStub === true ? true : undefined,
|
|
86
|
+
exists:
|
|
87
|
+
availablePaths === null
|
|
88
|
+
? undefined
|
|
89
|
+
: availablePaths.has(
|
|
90
|
+
document.normalizedPath ||
|
|
91
|
+
ProjectDocumentGraphBuilder.#normalizePath(
|
|
92
|
+
document.path
|
|
93
|
+
)
|
|
94
|
+
),
|
|
95
|
+
linkedOutputs:
|
|
96
|
+
outputsByDocumentPath[
|
|
97
|
+
document.normalizedPath ||
|
|
98
|
+
ProjectDocumentGraphBuilder.#normalizePath(
|
|
99
|
+
document.path
|
|
100
|
+
)
|
|
101
|
+
] || []
|
|
102
|
+
})
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Groups document and generated-output paths by public role.
|
|
108
|
+
* @param {object[]} documents Document graph rows.
|
|
109
|
+
* @param {object[]} outputGroups Output groups.
|
|
110
|
+
* @returns {object}
|
|
111
|
+
*/
|
|
112
|
+
static #groups(documents, outputGroups) {
|
|
113
|
+
const pathsForKind = (kind) =>
|
|
114
|
+
documents
|
|
115
|
+
.filter((document) => document.kind === kind)
|
|
116
|
+
.map((document) => document.normalizedPath)
|
|
117
|
+
const libraryKinds = new Set([
|
|
118
|
+
'schematic-library',
|
|
119
|
+
'pcb-library',
|
|
120
|
+
'integrated-library'
|
|
121
|
+
])
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
sourceSheets: pathsForKind('schematic'),
|
|
125
|
+
pcbs: pathsForKind('pcb'),
|
|
126
|
+
linkedLibraries: documents
|
|
127
|
+
.filter((document) => libraryKinds.has(document.kind))
|
|
128
|
+
.map((document) => document.normalizedPath),
|
|
129
|
+
schematicLibraries: pathsForKind('schematic-library'),
|
|
130
|
+
pcbLibraries: pathsForKind('pcb-library'),
|
|
131
|
+
integratedLibraries: pathsForKind('integrated-library'),
|
|
132
|
+
harnessFiles: pathsForKind('harness'),
|
|
133
|
+
outJobs: pathsForKind('output-job'),
|
|
134
|
+
generatedOutputs:
|
|
135
|
+
ProjectDocumentGraphBuilder.#generatedOutputPaths(outputGroups),
|
|
136
|
+
missingPaths: documents
|
|
137
|
+
.filter((document) => document.exists === false)
|
|
138
|
+
.map((document) => document.normalizedPath)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Builds graph lookup indexes.
|
|
144
|
+
* @param {object[]} documents Document graph rows.
|
|
145
|
+
* @param {object[]} outputGroups Output groups.
|
|
146
|
+
* @returns {object}
|
|
147
|
+
*/
|
|
148
|
+
static #indexes(documents, outputGroups) {
|
|
149
|
+
const byPath = {}
|
|
150
|
+
const byKind = {}
|
|
151
|
+
for (const document of documents) {
|
|
152
|
+
byPath[document.normalizedPath] = document.graphIndex
|
|
153
|
+
byKind[document.kind] ||= []
|
|
154
|
+
byKind[document.kind].push(document.normalizedPath)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
byPath,
|
|
159
|
+
byKind,
|
|
160
|
+
outputsByDocumentPath:
|
|
161
|
+
ProjectDocumentGraphBuilder.#outputsByDocumentPath(
|
|
162
|
+
outputGroups
|
|
163
|
+
),
|
|
164
|
+
generatedOutputsByPath:
|
|
165
|
+
ProjectDocumentGraphBuilder.#generatedOutputsByPath(
|
|
166
|
+
outputGroups
|
|
167
|
+
)
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Builds generated-output descriptors keyed by source document path.
|
|
173
|
+
* @param {object[]} outputGroups Project output groups.
|
|
174
|
+
* @returns {Record<string, object[]>}
|
|
175
|
+
*/
|
|
176
|
+
static #outputsByDocumentPath(outputGroups) {
|
|
177
|
+
const outputsByPath = {}
|
|
178
|
+
for (const outputGroup of outputGroups || []) {
|
|
179
|
+
for (const output of outputGroup.outputs || []) {
|
|
180
|
+
const documentPath = ProjectDocumentGraphBuilder.#normalizePath(
|
|
181
|
+
output.normalizedDocumentPath || output.documentPath
|
|
182
|
+
)
|
|
183
|
+
if (!documentPath) {
|
|
184
|
+
continue
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
outputsByPath[documentPath] ||= []
|
|
188
|
+
outputsByPath[documentPath].push(
|
|
189
|
+
ProjectDocumentGraphBuilder.#stripUndefined({
|
|
190
|
+
outputGroupName: outputGroup.name || '',
|
|
191
|
+
outputGroupIndex: outputGroup.index,
|
|
192
|
+
outputIndex: output.index,
|
|
193
|
+
type: output.type || '',
|
|
194
|
+
name: output.name || '',
|
|
195
|
+
variantName: output.variantName || '',
|
|
196
|
+
targetPath:
|
|
197
|
+
ProjectDocumentGraphBuilder.#normalizePath(
|
|
198
|
+
output.targetPath ||
|
|
199
|
+
output.normalizedTargetPath ||
|
|
200
|
+
''
|
|
201
|
+
) || undefined,
|
|
202
|
+
isDefault: output.isDefault === true ? true : undefined
|
|
203
|
+
})
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return outputsByPath
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Lists generated output target paths.
|
|
213
|
+
* @param {object[]} outputGroups Project output groups.
|
|
214
|
+
* @returns {string[]}
|
|
215
|
+
*/
|
|
216
|
+
static #generatedOutputPaths(outputGroups) {
|
|
217
|
+
const paths = []
|
|
218
|
+
for (const outputs of Object.values(
|
|
219
|
+
ProjectDocumentGraphBuilder.#outputsByDocumentPath(outputGroups)
|
|
220
|
+
)) {
|
|
221
|
+
for (const output of outputs) {
|
|
222
|
+
if (output.targetPath && !paths.includes(output.targetPath)) {
|
|
223
|
+
paths.push(output.targetPath)
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return paths
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Builds generated-output descriptors keyed by target path.
|
|
232
|
+
* @param {object[]} outputGroups Project output groups.
|
|
233
|
+
* @returns {Record<string, object>}
|
|
234
|
+
*/
|
|
235
|
+
static #generatedOutputsByPath(outputGroups) {
|
|
236
|
+
const byPath = {}
|
|
237
|
+
for (const [sourcePath, outputs] of Object.entries(
|
|
238
|
+
ProjectDocumentGraphBuilder.#outputsByDocumentPath(outputGroups)
|
|
239
|
+
)) {
|
|
240
|
+
for (const output of outputs) {
|
|
241
|
+
if (!output.targetPath) continue
|
|
242
|
+
byPath[output.targetPath] = {
|
|
243
|
+
sourceDocumentPath: sourcePath,
|
|
244
|
+
...output
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return byPath
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Normalizes project-relative path separators.
|
|
253
|
+
* @param {string} path Project path.
|
|
254
|
+
* @returns {string}
|
|
255
|
+
*/
|
|
256
|
+
static #normalizePath(path) {
|
|
257
|
+
return String(path || '').replace(/\\/g, '/')
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Extracts a basename without resolving the path.
|
|
262
|
+
* @param {string} path Project path.
|
|
263
|
+
* @returns {string}
|
|
264
|
+
*/
|
|
265
|
+
static #basename(path) {
|
|
266
|
+
const parts = String(path || '').split(/[\\/]/u)
|
|
267
|
+
return parts[parts.length - 1] || ''
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Removes undefined object properties for stable JSON output.
|
|
272
|
+
* @param {Record<string, unknown>} value Candidate object.
|
|
273
|
+
* @returns {Record<string, unknown>}
|
|
274
|
+
*/
|
|
275
|
+
static #stripUndefined(value) {
|
|
276
|
+
return Object.fromEntries(
|
|
277
|
+
Object.entries(value).filter(([, entry]) => entry !== undefined)
|
|
278
|
+
)
|
|
279
|
+
}
|
|
280
|
+
}
|