easyeda-mcp-pro 0.32.0 → 0.34.0
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 +8 -6
- package/dist/bridge/protocol.d.ts +1 -1
- package/dist/bridge/types.d.ts +1 -0
- package/dist/bridge/types.js +1 -0
- package/dist/bridge/types.js.map +1 -1
- package/dist/circuit/circuit-ir.d.ts +15 -2
- package/dist/circuit/circuit-ir.js +2 -0
- package/dist/circuit/circuit-ir.js.map +1 -1
- package/dist/circuit/compiler.js +1 -0
- package/dist/circuit/compiler.js.map +1 -1
- package/dist/circuit/design-intent.d.ts +13 -0
- package/dist/circuit/design-intent.js +2 -0
- package/dist/circuit/design-intent.js.map +1 -1
- package/dist/circuit/index.d.ts +2 -0
- package/dist/circuit/index.js +2 -0
- package/dist/circuit/index.js.map +1 -1
- package/dist/circuit/reference-design.d.ts +16 -0
- package/dist/circuit/reference-design.js +16 -0
- package/dist/circuit/reference-design.js.map +1 -0
- package/dist/config/env.js +10 -4
- package/dist/config/env.js.map +1 -1
- package/dist/config/profiles.js +4 -4
- package/dist/config/version.d.ts +1 -1
- package/dist/config/version.js +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/layout/autofix.d.ts +93 -0
- package/dist/layout/autofix.js +376 -0
- package/dist/layout/autofix.js.map +1 -0
- package/dist/layout/block-detector.d.ts +3 -0
- package/dist/layout/block-detector.js +252 -0
- package/dist/layout/block-detector.js.map +1 -0
- package/dist/layout/geometry.d.ts +20 -0
- package/dist/layout/geometry.js +150 -0
- package/dist/layout/geometry.js.map +1 -0
- package/dist/layout/graph.d.ts +5 -0
- package/dist/layout/graph.js +185 -0
- package/dist/layout/graph.js.map +1 -0
- package/dist/layout/index.d.ts +8 -0
- package/dist/layout/index.js +9 -0
- package/dist/layout/index.js.map +1 -0
- package/dist/layout/operations.d.ts +7 -0
- package/dist/layout/operations.js +170 -0
- package/dist/layout/operations.js.map +1 -0
- package/dist/layout/placement.d.ts +79 -0
- package/dist/layout/placement.js +248 -0
- package/dist/layout/placement.js.map +1 -0
- package/dist/layout/planner.d.ts +98 -0
- package/dist/layout/planner.js +338 -0
- package/dist/layout/planner.js.map +1 -0
- package/dist/layout/types.d.ts +281 -0
- package/dist/layout/types.js +2 -0
- package/dist/layout/types.js.map +1 -0
- package/dist/live/readback.d.ts +16 -0
- package/dist/live/readback.js +38 -0
- package/dist/live/readback.js.map +1 -0
- package/dist/professional-layout-templates/catalog.v1.d.ts +390 -0
- package/dist/professional-layout-templates/catalog.v1.js +460 -0
- package/dist/professional-layout-templates/catalog.v1.js.map +1 -0
- package/dist/professional-layout-templates/index.d.ts +14 -0
- package/dist/professional-layout-templates/index.js +118 -0
- package/dist/professional-layout-templates/index.js.map +1 -0
- package/dist/professional-layout-templates/types.d.ts +74 -0
- package/dist/professional-layout-templates/types.js +2 -0
- package/dist/professional-layout-templates/types.js.map +1 -0
- package/dist/remote/approval-policy.d.ts +9 -0
- package/dist/remote/approval-policy.js +30 -2
- package/dist/remote/approval-policy.js.map +1 -1
- package/dist/remote/gateway.d.ts +45 -9
- package/dist/remote/gateway.js +360 -37
- package/dist/remote/gateway.js.map +1 -1
- package/dist/remote/session-dispatch-queue.d.ts +5 -0
- package/dist/remote/session-dispatch-queue.js +25 -0
- package/dist/remote/session-dispatch-queue.js.map +1 -0
- package/dist/router/astar.d.ts +23 -0
- package/dist/router/astar.js +177 -0
- package/dist/router/astar.js.map +1 -0
- package/dist/router/geometry.d.ts +39 -0
- package/dist/router/geometry.js +240 -0
- package/dist/router/geometry.js.map +1 -0
- package/dist/router/grid.d.ts +24 -0
- package/dist/router/grid.js +50 -0
- package/dist/router/grid.js.map +1 -0
- package/dist/router/obstacles.d.ts +33 -0
- package/dist/router/obstacles.js +243 -0
- package/dist/router/obstacles.js.map +1 -0
- package/dist/router/path-simplifier.d.ts +6 -0
- package/dist/router/path-simplifier.js +35 -0
- package/dist/router/path-simplifier.js.map +1 -0
- package/dist/router/pin-escape.d.ts +24 -0
- package/dist/router/pin-escape.js +155 -0
- package/dist/router/pin-escape.js.map +1 -0
- package/dist/router/route-cost.d.ts +10 -0
- package/dist/router/route-cost.js +82 -0
- package/dist/router/route-cost.js.map +1 -0
- package/dist/router/types.d.ts +187 -0
- package/dist/router/types.js +2 -0
- package/dist/router/types.js.map +1 -0
- package/dist/schematic-engine/errors.d.ts +22 -0
- package/dist/schematic-engine/errors.js +83 -0
- package/dist/schematic-engine/errors.js.map +1 -0
- package/dist/schematic-engine/geometry.d.ts +33 -0
- package/dist/schematic-engine/geometry.js +49 -0
- package/dist/schematic-engine/geometry.js.map +1 -0
- package/dist/schematic-engine/index.d.ts +2 -0
- package/dist/schematic-engine/index.js +3 -0
- package/dist/schematic-engine/index.js.map +1 -0
- package/dist/schematic-model/connectivity-fingerprint.d.ts +60 -0
- package/dist/schematic-model/connectivity-fingerprint.js +117 -0
- package/dist/schematic-model/connectivity-fingerprint.js.map +1 -0
- package/dist/schematic-model/geometry-model.d.ts +329 -0
- package/dist/schematic-model/geometry-model.js +8 -0
- package/dist/schematic-model/geometry-model.js.map +1 -0
- package/dist/schematic-model/geometry-net-names.d.ts +23 -0
- package/dist/schematic-model/geometry-net-names.js +166 -0
- package/dist/schematic-model/geometry-net-names.js.map +1 -0
- package/dist/schematic-model/geometry-normalize.d.ts +18 -0
- package/dist/schematic-model/geometry-normalize.js +281 -0
- package/dist/schematic-model/geometry-normalize.js.map +1 -0
- package/dist/schematic-model/imported-symbols.d.ts +13 -0
- package/dist/schematic-model/imported-symbols.js +155 -0
- package/dist/schematic-model/imported-symbols.js.map +1 -0
- package/dist/schematic-model/live-functional-layout.d.ts +45 -0
- package/dist/schematic-model/live-functional-layout.js +109 -0
- package/dist/schematic-model/live-functional-layout.js.map +1 -0
- package/dist/schematic-model/live-layout-autofix.d.ts +59 -0
- package/dist/schematic-model/live-layout-autofix.js +132 -0
- package/dist/schematic-model/live-layout-autofix.js.map +1 -0
- package/dist/schematic-model/live-placement-check.d.ts +32 -0
- package/dist/schematic-model/live-placement-check.js +56 -0
- package/dist/schematic-model/live-placement-check.js.map +1 -0
- package/dist/schematic-model/live-primitive-bounds.d.ts +18 -0
- package/dist/schematic-model/live-primitive-bounds.js +83 -0
- package/dist/schematic-model/live-primitive-bounds.js.map +1 -0
- package/dist/schematic-model/live-snapshot.d.ts +16 -0
- package/dist/schematic-model/live-snapshot.js +99 -0
- package/dist/schematic-model/live-snapshot.js.map +1 -0
- package/dist/schematic-model/model-builder.d.ts +7 -0
- package/dist/schematic-model/model-builder.js +429 -0
- package/dist/schematic-model/model-builder.js.map +1 -0
- package/dist/schematic-model/model-validator.d.ts +8 -0
- package/dist/schematic-model/model-validator.js +180 -0
- package/dist/schematic-model/model-validator.js.map +1 -0
- package/dist/schematic-model/pin-semantics.d.ts +17 -0
- package/dist/schematic-model/pin-semantics.js +70 -0
- package/dist/schematic-model/pin-semantics.js.map +1 -0
- package/dist/schematic-model/primitive-bounds.d.ts +69 -0
- package/dist/schematic-model/primitive-bounds.js +141 -0
- package/dist/schematic-model/primitive-bounds.js.map +1 -0
- package/dist/server/factory.d.ts +1 -0
- package/dist/server/factory.js +42 -20
- package/dist/server/factory.js.map +1 -1
- package/dist/server/transports/http.d.ts +3 -0
- package/dist/server/transports/http.js +136 -7
- package/dist/server/transports/http.js.map +1 -1
- package/dist/tools/L1_bom_core.js +3 -2
- package/dist/tools/L1_bom_core.js.map +1 -1
- package/dist/tools/L1_schematic_read.js +29 -4
- package/dist/tools/L1_schematic_read.js.map +1 -1
- package/dist/tools/L1_visual.js +146 -0
- package/dist/tools/L1_visual.js.map +1 -1
- package/dist/tools/L2_schematic_layout.d.ts +141 -0
- package/dist/tools/L2_schematic_layout.js +1155 -0
- package/dist/tools/L2_schematic_layout.js.map +1 -0
- package/dist/tools/L2_workflows.js +301 -10
- package/dist/tools/L2_workflows.js.map +1 -1
- package/dist/tools/register.js +2 -0
- package/dist/tools/register.js.map +1 -1
- package/dist/tools/registry.d.ts +1 -1
- package/dist/tools/registry.js +92 -30
- package/dist/tools/registry.js.map +1 -1
- package/dist/transactions/operation-log.d.ts +32 -0
- package/dist/transactions/operation-log.js +58 -0
- package/dist/transactions/operation-log.js.map +1 -0
- package/dist/workflows/index.d.ts +1 -1
- package/dist/workflows/led-blinker-template.d.ts +131 -0
- package/dist/workflows/led-blinker-template.js +212 -0
- package/dist/workflows/led-blinker-template.js.map +1 -0
- package/dist/workflows/ne555-astable-template.js +2 -2
- package/dist/workflows/ne555-astable-template.js.map +1 -1
- package/dist/workflows/ne555-wire-stubs.d.ts +17 -0
- package/dist/workflows/ne555-wire-stubs.js +114 -31
- package/dist/workflows/ne555-wire-stubs.js.map +1 -1
- package/dist/workflows/planner.js +58 -8
- package/dist/workflows/planner.js.map +1 -1
- package/dist/workflows/rp2040-servo-module-scaffold.d.ts +22 -1
- package/dist/workflows/rp2040-servo-module-scaffold.js +218 -77
- package/dist/workflows/rp2040-servo-module-scaffold.js.map +1 -1
- package/dist/workflows/schematic-layout-qa.d.ts +177 -0
- package/dist/workflows/schematic-layout-qa.js +727 -0
- package/dist/workflows/schematic-layout-qa.js.map +1 -0
- package/dist/workflows/types.d.ts +50 -0
- package/dist/workflows/wire-stub-generator.d.ts +104 -0
- package/dist/workflows/wire-stub-generator.js +105 -0
- package/dist/workflows/wire-stub-generator.js.map +1 -0
- package/easyeda-bridge-extension.eext +0 -0
- package/package.json +1 -1
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { compareIds } from './geometry.js';
|
|
2
|
+
const KIND_TITLES = {
|
|
3
|
+
'power-input': 'Power Input',
|
|
4
|
+
regulation: 'Power Regulation',
|
|
5
|
+
mcu: 'Microcontroller',
|
|
6
|
+
memory: 'Memory',
|
|
7
|
+
crystal: 'Crystal and Clock',
|
|
8
|
+
usb: 'USB',
|
|
9
|
+
'motor-driver': 'Motor Driver',
|
|
10
|
+
'led-chain': 'LED Chain',
|
|
11
|
+
connector: 'Connectors',
|
|
12
|
+
debug: 'Debug',
|
|
13
|
+
sensor: 'Sensors',
|
|
14
|
+
'analog-front-end': 'Analog Front End',
|
|
15
|
+
other: 'Other',
|
|
16
|
+
};
|
|
17
|
+
const KIND_PRIORITY = [
|
|
18
|
+
'usb',
|
|
19
|
+
'debug',
|
|
20
|
+
'regulation',
|
|
21
|
+
'power-input',
|
|
22
|
+
'mcu',
|
|
23
|
+
'memory',
|
|
24
|
+
'crystal',
|
|
25
|
+
'motor-driver',
|
|
26
|
+
'led-chain',
|
|
27
|
+
'sensor',
|
|
28
|
+
'analog-front-end',
|
|
29
|
+
'connector',
|
|
30
|
+
'other',
|
|
31
|
+
];
|
|
32
|
+
function searchableText(component) {
|
|
33
|
+
return [
|
|
34
|
+
component.reference,
|
|
35
|
+
component.value,
|
|
36
|
+
component.deviceName,
|
|
37
|
+
component.description,
|
|
38
|
+
component.category,
|
|
39
|
+
...(component.tags ?? []),
|
|
40
|
+
]
|
|
41
|
+
.filter((value) => typeof value === 'string')
|
|
42
|
+
.join(' ')
|
|
43
|
+
.toLowerCase();
|
|
44
|
+
}
|
|
45
|
+
function matchesAny(text, expressions) {
|
|
46
|
+
return expressions.some((expression) => expression.test(text));
|
|
47
|
+
}
|
|
48
|
+
export function inferFunctionalBlockKind(component) {
|
|
49
|
+
const text = searchableText(component);
|
|
50
|
+
const reference = component.reference.toUpperCase();
|
|
51
|
+
if (matchesAny(text, [/\busb(?:-?c)?\b/, /type[\s-]*c/, /usb connector/]))
|
|
52
|
+
return 'usb';
|
|
53
|
+
if (matchesAny(text, [/\bjtag\b/, /\bswd\b/, /debug/, /program(?:mer|ming) header/]))
|
|
54
|
+
return 'debug';
|
|
55
|
+
if (matchesAny(text, [
|
|
56
|
+
/\bldo\b/,
|
|
57
|
+
/regulat/,
|
|
58
|
+
/buck converter/,
|
|
59
|
+
/boost converter/,
|
|
60
|
+
/dc[- ]?dc/,
|
|
61
|
+
/ams1117/,
|
|
62
|
+
/tps62/,
|
|
63
|
+
])) {
|
|
64
|
+
return 'regulation';
|
|
65
|
+
}
|
|
66
|
+
if (matchesAny(text, [
|
|
67
|
+
/power input/,
|
|
68
|
+
/barrel jack/,
|
|
69
|
+
/dc input/,
|
|
70
|
+
/mains input/,
|
|
71
|
+
/power entry/,
|
|
72
|
+
/battery input/,
|
|
73
|
+
])) {
|
|
74
|
+
return 'power-input';
|
|
75
|
+
}
|
|
76
|
+
if (matchesAny(text, [
|
|
77
|
+
/microcontroller/,
|
|
78
|
+
/\bmcu\b/,
|
|
79
|
+
/rp2040/,
|
|
80
|
+
/stm32/,
|
|
81
|
+
/esp32/,
|
|
82
|
+
/atmega/,
|
|
83
|
+
/samd2/,
|
|
84
|
+
/nrf5/,
|
|
85
|
+
])) {
|
|
86
|
+
return 'mcu';
|
|
87
|
+
}
|
|
88
|
+
if (matchesAny(text, [/\bflash\b/, /\beeprom\b/, /\bsram\b/, /\bmemory\b/, /w25q/, /qspi/])) {
|
|
89
|
+
return 'memory';
|
|
90
|
+
}
|
|
91
|
+
if (matchesAny(text, [/\bcrystal\b/, /\bxtal\b/, /oscillator/, /resonator/]) ||
|
|
92
|
+
/^[XY]\d+/i.test(reference)) {
|
|
93
|
+
return 'crystal';
|
|
94
|
+
}
|
|
95
|
+
if (matchesAny(text, [
|
|
96
|
+
/motor driver/,
|
|
97
|
+
/h[- ]?bridge/,
|
|
98
|
+
/drv8\d/,
|
|
99
|
+
/tb66/,
|
|
100
|
+
/stepper driver/,
|
|
101
|
+
/gate driver/,
|
|
102
|
+
])) {
|
|
103
|
+
return 'motor-driver';
|
|
104
|
+
}
|
|
105
|
+
if (matchesAny(text, [/ws2812/, /neopixel/, /led chain/, /addressable led/]))
|
|
106
|
+
return 'led-chain';
|
|
107
|
+
if (matchesAny(text, [
|
|
108
|
+
/accelerometer/,
|
|
109
|
+
/gyroscope/,
|
|
110
|
+
/\bimu\b/,
|
|
111
|
+
/temperature sensor/,
|
|
112
|
+
/pressure sensor/,
|
|
113
|
+
/proximity sensor/,
|
|
114
|
+
/\bsensor\b/,
|
|
115
|
+
])) {
|
|
116
|
+
return 'sensor';
|
|
117
|
+
}
|
|
118
|
+
if (matchesAny(text, [
|
|
119
|
+
/analog front[- ]?end/,
|
|
120
|
+
/\bop[- ]?amp\b/,
|
|
121
|
+
/instrumentation amplifier/,
|
|
122
|
+
/transimpedance/,
|
|
123
|
+
/\badc\b/,
|
|
124
|
+
/\bdac\b/,
|
|
125
|
+
])) {
|
|
126
|
+
return 'analog-front-end';
|
|
127
|
+
}
|
|
128
|
+
if (matchesAny(text, [/connector/, /header/, /terminal block/, /\bjack\b/]) ||
|
|
129
|
+
/^(J|P|CN)\d+/i.test(reference)) {
|
|
130
|
+
return 'connector';
|
|
131
|
+
}
|
|
132
|
+
if (matchesAny(text, [/led/, /light emitting diode/]) || /^D\d+/i.test(reference))
|
|
133
|
+
return 'led-chain';
|
|
134
|
+
return 'other';
|
|
135
|
+
}
|
|
136
|
+
function dominantKind(components) {
|
|
137
|
+
const counts = new Map();
|
|
138
|
+
for (const component of components) {
|
|
139
|
+
const kind = inferFunctionalBlockKind(component);
|
|
140
|
+
counts.set(kind, (counts.get(kind) ?? 0) + 1);
|
|
141
|
+
}
|
|
142
|
+
return ([...counts.entries()].sort(([kindA, countA], [kindB, countB]) => countB - countA || KIND_PRIORITY.indexOf(kindA) - KIND_PRIORITY.indexOf(kindB))[0]?.[0] ?? 'other');
|
|
143
|
+
}
|
|
144
|
+
function inferredBlock(id, kind, componentIds, confidence) {
|
|
145
|
+
return {
|
|
146
|
+
id,
|
|
147
|
+
kind,
|
|
148
|
+
title: KIND_TITLES[kind],
|
|
149
|
+
componentIds: [...componentIds].sort(compareIds),
|
|
150
|
+
source: 'inferred',
|
|
151
|
+
confidence,
|
|
152
|
+
locked: false,
|
|
153
|
+
preferredOrientation: kind === 'power-input' || kind === 'regulation' || kind === 'crystal'
|
|
154
|
+
? 'vertical'
|
|
155
|
+
: 'horizontal',
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function repeatSignature(block, componentById) {
|
|
159
|
+
if (block.source === 'explicit' || block.kind === 'other' || block.componentIds.length === 0) {
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
const anchorId = block.componentIds[0];
|
|
163
|
+
if (!anchorId)
|
|
164
|
+
return undefined;
|
|
165
|
+
const anchor = componentById.get(anchorId);
|
|
166
|
+
const part = (anchor?.deviceName ?? anchor?.value ?? anchor?.category ?? '').trim().toLowerCase();
|
|
167
|
+
return part ? `${block.kind}:${part}` : undefined;
|
|
168
|
+
}
|
|
169
|
+
export function detectFunctionalBlocks(components, graph, explicitBlocks = []) {
|
|
170
|
+
const componentById = new Map(components.map((component) => [component.id, component]));
|
|
171
|
+
const claimed = new Set();
|
|
172
|
+
const blocks = [];
|
|
173
|
+
for (const explicit of [...explicitBlocks].sort((a, b) => compareIds(a.id, b.id))) {
|
|
174
|
+
const componentIds = [...new Set(explicit.componentIds)]
|
|
175
|
+
.filter((componentId) => componentById.has(componentId) && !claimed.has(componentId))
|
|
176
|
+
.sort(compareIds);
|
|
177
|
+
if (componentIds.length === 0)
|
|
178
|
+
continue;
|
|
179
|
+
componentIds.forEach((componentId) => claimed.add(componentId));
|
|
180
|
+
blocks.push({
|
|
181
|
+
id: explicit.id,
|
|
182
|
+
kind: explicit.kind,
|
|
183
|
+
title: explicit.title ?? KIND_TITLES[explicit.kind],
|
|
184
|
+
sectionTitle: explicit.sectionTitle,
|
|
185
|
+
componentIds,
|
|
186
|
+
source: 'explicit',
|
|
187
|
+
confidence: 1,
|
|
188
|
+
locked: explicit.locked ?? false,
|
|
189
|
+
repeatedGroupId: explicit.repeatedGroupId,
|
|
190
|
+
preferredOrientation: explicit.preferredOrientation ?? 'horizontal',
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
const groupedByDeclaredBlock = new Map();
|
|
194
|
+
for (const component of components) {
|
|
195
|
+
if (claimed.has(component.id) || !component.blockId)
|
|
196
|
+
continue;
|
|
197
|
+
const grouped = groupedByDeclaredBlock.get(component.blockId) ?? [];
|
|
198
|
+
grouped.push(component);
|
|
199
|
+
groupedByDeclaredBlock.set(component.blockId, grouped);
|
|
200
|
+
}
|
|
201
|
+
for (const [blockId, members] of [...groupedByDeclaredBlock.entries()].sort(([a], [b]) => compareIds(a, b))) {
|
|
202
|
+
members.forEach((component) => claimed.add(component.id));
|
|
203
|
+
blocks.push(inferredBlock(`inferred:${blockId}`, dominantKind(members), members.map((component) => component.id), 0.9));
|
|
204
|
+
}
|
|
205
|
+
const anchorBlockByComponent = new Map();
|
|
206
|
+
for (const component of [...components].sort((a, b) => compareIds(a.id, b.id))) {
|
|
207
|
+
if (claimed.has(component.id))
|
|
208
|
+
continue;
|
|
209
|
+
const kind = inferFunctionalBlockKind(component);
|
|
210
|
+
if (kind === 'other')
|
|
211
|
+
continue;
|
|
212
|
+
const block = inferredBlock(`inferred:${kind}:${component.id}`, kind, [component.id], 0.82);
|
|
213
|
+
blocks.push(block);
|
|
214
|
+
anchorBlockByComponent.set(component.id, block);
|
|
215
|
+
claimed.add(component.id);
|
|
216
|
+
}
|
|
217
|
+
// Attach passive/helper parts to the nearest inferred anchor using the canonical graph.
|
|
218
|
+
for (const component of [...components].sort((a, b) => compareIds(a.id, b.id))) {
|
|
219
|
+
if (claimed.has(component.id))
|
|
220
|
+
continue;
|
|
221
|
+
const candidateBlocks = (graph.adjacency[component.id] ?? [])
|
|
222
|
+
.map((neighborId) => anchorBlockByComponent.get(neighborId))
|
|
223
|
+
.filter((block) => block !== undefined)
|
|
224
|
+
.sort((a, b) => KIND_PRIORITY.indexOf(a.kind) - KIND_PRIORITY.indexOf(b.kind) || compareIds(a.id, b.id));
|
|
225
|
+
const owner = candidateBlocks[0];
|
|
226
|
+
if (owner) {
|
|
227
|
+
owner.componentIds.push(component.id);
|
|
228
|
+
owner.componentIds.sort(compareIds);
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
blocks.push(inferredBlock(`inferred:other:${component.id}`, 'other', [component.id], 0.35));
|
|
232
|
+
}
|
|
233
|
+
claimed.add(component.id);
|
|
234
|
+
}
|
|
235
|
+
const repeatBuckets = new Map();
|
|
236
|
+
for (const block of blocks) {
|
|
237
|
+
const signature = repeatSignature(block, componentById);
|
|
238
|
+
if (!signature)
|
|
239
|
+
continue;
|
|
240
|
+
const bucket = repeatBuckets.get(signature) ?? [];
|
|
241
|
+
bucket.push(block);
|
|
242
|
+
repeatBuckets.set(signature, bucket);
|
|
243
|
+
}
|
|
244
|
+
for (const [signature, repeated] of repeatBuckets) {
|
|
245
|
+
if (repeated.length < 2)
|
|
246
|
+
continue;
|
|
247
|
+
for (const block of repeated)
|
|
248
|
+
block.repeatedGroupId = `repeat:${signature}`;
|
|
249
|
+
}
|
|
250
|
+
return blocks.sort((a, b) => compareIds(a.id, b.id));
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL=block-detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-detector.js","sourceRoot":"","sources":["../../src/layout/block-detector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAS3C,MAAM,WAAW,GAAkD;IACjE,aAAa,EAAE,aAAa;IAC5B,UAAU,EAAE,kBAAkB;IAC9B,GAAG,EAAE,iBAAiB;IACtB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,mBAAmB;IAC5B,GAAG,EAAE,KAAK;IACV,cAAc,EAAE,cAAc;IAC9B,WAAW,EAAE,WAAW;IACxB,SAAS,EAAE,YAAY;IACvB,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,SAAS;IACjB,kBAAkB,EAAE,kBAAkB;IACtC,KAAK,EAAE,OAAO;CACf,CAAC;AAEF,MAAM,aAAa,GAAmC;IACpD,KAAK;IACL,OAAO;IACP,YAAY;IACZ,aAAa;IACb,KAAK;IACL,QAAQ;IACR,SAAS;IACT,cAAc;IACd,WAAW;IACX,QAAQ;IACR,kBAAkB;IAClB,WAAW;IACX,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oint, LayoutRect, LayoutSheet } from './types.js';
|
|
2
|
+
export declare function compareIds(a: string, b: string): number;
|
|
3
|
+
export declare function rectFromCenter(center: LayoutPoint, width: number, height: number, id?: string): LayoutRect;
|
|
4
|
+
export declare function rectCenter(rect: LayoutRect): LayoutPoint;
|
|
5
|
+
export declare function rectArea(rect: LayoutRect): number;
|
|
6
|
+
export declare function rectsOverlap(a: LayoutRect, b: LayoutRect, clearance?: number): boolean;
|
|
7
|
+
export declare function inflateRect(rect: LayoutRect, amount: number): LayoutRect;
|
|
8
|
+
export declare function rectInsideRect(inner: LayoutRect, outer: LayoutRect): boolean;
|
|
9
|
+
export declare function sheetRect(sheet: LayoutSheet): LayoutRect;
|
|
10
|
+
export declare function intersectionArea(a: LayoutRect, b: LayoutRect): number;
|
|
11
|
+
export declare function boundingRect(rects: readonly LayoutRect[]): LayoutRect | undefined;
|
|
12
|
+
export declare function translateRect(rect: LayoutRect, dx: number, dy: number): LayoutRect;
|
|
13
|
+
export declare function clampRect(rect: LayoutRect, bounds: LayoutRect): LayoutRect;
|
|
14
|
+
export declare function pointInsideRect(point: LayoutPoint, rect: LayoutRect): boolean;
|
|
15
|
+
export declare function pointsEqual(a: LayoutPoint, b: LayoutPoint): boolean;
|
|
16
|
+
export declare function segmentsIntersect(a1: LayoutPoint, a2: LayoutPoint, b1: LayoutPoint, b2: LayoutPoint): boolean;
|
|
17
|
+
export declare function segmentIntersectsRect(a: LayoutPoint, b: LayoutPoint, rect: LayoutRect): boolean;
|
|
18
|
+
export declare function polylineLength(points: readonly LayoutPoint[]): number;
|
|
19
|
+
export declare function polylineBends(points: readonly LayoutPoint[]): number;
|
|
20
|
+
export declare function candidateGrid(bounds: LayoutRect, step: number): LayoutPoint[];
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
const EPSILON = 1e-9;
|
|
2
|
+
export function compareIds(a, b) {
|
|
3
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
4
|
+
}
|
|
5
|
+
export function rectFromCenter(center, width, height, id) {
|
|
6
|
+
return {
|
|
7
|
+
id,
|
|
8
|
+
x: center.x - width / 2,
|
|
9
|
+
y: center.y - height / 2,
|
|
10
|
+
width,
|
|
11
|
+
height,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function rectCenter(rect) {
|
|
15
|
+
return { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 };
|
|
16
|
+
}
|
|
17
|
+
export function rectArea(rect) {
|
|
18
|
+
return Math.max(0, rect.width) * Math.max(0, rect.height);
|
|
19
|
+
}
|
|
20
|
+
export function rectsOverlap(a, b, clearance = 0) {
|
|
21
|
+
return !(a.x + a.width + clearance <= b.x ||
|
|
22
|
+
b.x + b.width + clearance <= a.x ||
|
|
23
|
+
a.y + a.height + clearance <= b.y ||
|
|
24
|
+
b.y + b.height + clearance <= a.y);
|
|
25
|
+
}
|
|
26
|
+
export function inflateRect(rect, amount) {
|
|
27
|
+
return {
|
|
28
|
+
...rect,
|
|
29
|
+
x: rect.x - amount,
|
|
30
|
+
y: rect.y - amount,
|
|
31
|
+
width: rect.width + amount * 2,
|
|
32
|
+
height: rect.height + amount * 2,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export function rectInsideRect(inner, outer) {
|
|
36
|
+
return (inner.x >= outer.x - EPSILON &&
|
|
37
|
+
inner.y >= outer.y - EPSILON &&
|
|
38
|
+
inner.x + inner.width <= outer.x + outer.width + EPSILON &&
|
|
39
|
+
inner.y + inner.height <= outer.y + outer.height + EPSILON);
|
|
40
|
+
}
|
|
41
|
+
export function sheetRect(sheet) {
|
|
42
|
+
const origin = sheet.origin ?? { x: 0, y: 0 };
|
|
43
|
+
return { x: origin.x, y: origin.y, width: sheet.width, height: sheet.height };
|
|
44
|
+
}
|
|
45
|
+
export function intersectionArea(a, b) {
|
|
46
|
+
const width = Math.max(0, Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x));
|
|
47
|
+
const height = Math.max(0, Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y));
|
|
48
|
+
return width * height;
|
|
49
|
+
}
|
|
50
|
+
export function boundingRect(rects) {
|
|
51
|
+
if (rects.length === 0)
|
|
52
|
+
return undefined;
|
|
53
|
+
const minX = Math.min(...rects.map((rect) => rect.x));
|
|
54
|
+
const minY = Math.min(...rects.map((rect) => rect.y));
|
|
55
|
+
const maxX = Math.max(...rects.map((rect) => rect.x + rect.width));
|
|
56
|
+
const maxY = Math.max(...rects.map((rect) => rect.y + rect.height));
|
|
57
|
+
return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
|
|
58
|
+
}
|
|
59
|
+
export function translateRect(rect, dx, dy) {
|
|
60
|
+
return { ...rect, x: rect.x + dx, y: rect.y + dy };
|
|
61
|
+
}
|
|
62
|
+
export function clampRect(rect, bounds) {
|
|
63
|
+
return {
|
|
64
|
+
...rect,
|
|
65
|
+
x: Math.min(Math.max(rect.x, bounds.x), bounds.x + Math.max(0, bounds.width - rect.width)),
|
|
66
|
+
y: Math.min(Math.max(rect.y, bounds.y), bounds.y + Math.max(0, bounds.height - rect.height)),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export function pointInsideRect(point, rect) {
|
|
70
|
+
return (point.x >= rect.x - EPSILON &&
|
|
71
|
+
point.x <= rect.x + rect.width + EPSILON &&
|
|
72
|
+
point.y >= rect.y - EPSILON &&
|
|
73
|
+
point.y <= rect.y + rect.height + EPSILON);
|
|
74
|
+
}
|
|
75
|
+
function cross(a, b, c) {
|
|
76
|
+
return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
|
|
77
|
+
}
|
|
78
|
+
function pointOnSegment(point, a, b) {
|
|
79
|
+
return (Math.abs(cross(a, b, point)) <= EPSILON &&
|
|
80
|
+
point.x >= Math.min(a.x, b.x) - EPSILON &&
|
|
81
|
+
point.x <= Math.max(a.x, b.x) + EPSILON &&
|
|
82
|
+
point.y >= Math.min(a.y, b.y) - EPSILON &&
|
|
83
|
+
point.y <= Math.max(a.y, b.y) + EPSILON);
|
|
84
|
+
}
|
|
85
|
+
export function pointsEqual(a, b) {
|
|
86
|
+
return Math.abs(a.x - b.x) <= EPSILON && Math.abs(a.y - b.y) <= EPSILON;
|
|
87
|
+
}
|
|
88
|
+
export function segmentsIntersect(a1, a2, b1, b2) {
|
|
89
|
+
const d1 = cross(a1, a2, b1);
|
|
90
|
+
const d2 = cross(a1, a2, b2);
|
|
91
|
+
const d3 = cross(b1, b2, a1);
|
|
92
|
+
const d4 = cross(b1, b2, a2);
|
|
93
|
+
if (((d1 > EPSILON && d2 < -EPSILON) || (d1 < -EPSILON && d2 > EPSILON)) &&
|
|
94
|
+
((d3 > EPSILON && d4 < -EPSILON) || (d3 < -EPSILON && d4 > EPSILON))) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
return ((Math.abs(d1) <= EPSILON && pointOnSegment(b1, a1, a2)) ||
|
|
98
|
+
(Math.abs(d2) <= EPSILON && pointOnSegment(b2, a1, a2)) ||
|
|
99
|
+
(Math.abs(d3) <= EPSILON && pointOnSegment(a1, b1, b2)) ||
|
|
100
|
+
(Math.abs(d4) <= EPSILON && pointOnSegment(a2, b1, b2)));
|
|
101
|
+
}
|
|
102
|
+
export function segmentIntersectsRect(a, b, rect) {
|
|
103
|
+
if (pointInsideRect(a, rect) || pointInsideRect(b, rect))
|
|
104
|
+
return true;
|
|
105
|
+
const topLeft = { x: rect.x, y: rect.y + rect.height };
|
|
106
|
+
const topRight = { x: rect.x + rect.width, y: rect.y + rect.height };
|
|
107
|
+
const bottomLeft = { x: rect.x, y: rect.y };
|
|
108
|
+
const bottomRight = { x: rect.x + rect.width, y: rect.y };
|
|
109
|
+
return (segmentsIntersect(a, b, bottomLeft, bottomRight) ||
|
|
110
|
+
segmentsIntersect(a, b, bottomRight, topRight) ||
|
|
111
|
+
segmentsIntersect(a, b, topRight, topLeft) ||
|
|
112
|
+
segmentsIntersect(a, b, topLeft, bottomLeft));
|
|
113
|
+
}
|
|
114
|
+
export function polylineLength(points) {
|
|
115
|
+
let total = 0;
|
|
116
|
+
for (let index = 1; index < points.length; index += 1) {
|
|
117
|
+
const current = points[index];
|
|
118
|
+
const previous = points[index - 1];
|
|
119
|
+
if (!current || !previous)
|
|
120
|
+
continue;
|
|
121
|
+
total += Math.hypot(current.x - previous.x, current.y - previous.y);
|
|
122
|
+
}
|
|
123
|
+
return total;
|
|
124
|
+
}
|
|
125
|
+
export function polylineBends(points) {
|
|
126
|
+
let bends = 0;
|
|
127
|
+
for (let index = 2; index < points.length; index += 1) {
|
|
128
|
+
const previous = points[index - 2];
|
|
129
|
+
const current = points[index - 1];
|
|
130
|
+
const next = points[index];
|
|
131
|
+
if (!previous || !current || !next)
|
|
132
|
+
continue;
|
|
133
|
+
const first = { x: current.x - previous.x, y: current.y - previous.y };
|
|
134
|
+
const second = { x: next.x - current.x, y: next.y - current.y };
|
|
135
|
+
if (Math.abs(first.x * second.y - first.y * second.x) > EPSILON)
|
|
136
|
+
bends += 1;
|
|
137
|
+
}
|
|
138
|
+
return bends;
|
|
139
|
+
}
|
|
140
|
+
export function candidateGrid(bounds, step) {
|
|
141
|
+
const safeStep = Math.max(step, EPSILON);
|
|
142
|
+
const points = [];
|
|
143
|
+
for (let y = bounds.y; y <= bounds.y + bounds.height + EPSILON; y += safeStep) {
|
|
144
|
+
for (let x = bounds.x; x <= bounds.x + bounds.width + EPSILON; x += safeStep) {
|
|
145
|
+
points.push({ x, y });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return points;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=geometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry.js","sourceRoot":"","sources":["../../src/layout/geometry.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,GAAG,IAAI,CAAC;AAErB,MAAM,UAAU,UAAU,CAAC,CAAS,EAAE,CAAS;IAC7C,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAA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C,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO;YAAE,KAAK,IAAI,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,MAAkB,EAAE,IAAY;IAC5D,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACzC,MAAM,MAAM,GAAkB,EAAE,CAAC;IACjC,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,OAAO,EAAE,CAAC,IAAI,QAAQ,EAAE,CAAC;QAC9E,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,GAAG,OAAO,EAAE,CAAC,IAAI,QAAQ,EAAE,CAAC;YAC7E,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { DetectedFunctionalBlock, FunctionalBlockGraph, FunctionalBlockGraphNode, FunctionalBlockKind, LayoutComponentInput, LayoutNetInput, SchematicLayoutGraph } from './types.js';
|
|
2
|
+
export declare const BLOCK_FLOW_BASE_RANK: Readonly<Record<FunctionalBlockKind, number>>;
|
|
3
|
+
export declare function buildSchematicLayoutGraph(components: readonly LayoutComponentInput[], nets?: readonly LayoutNetInput[]): SchematicLayoutGraph;
|
|
4
|
+
export declare function buildFunctionalBlockGraph(blocks: readonly DetectedFunctionalBlock[], componentGraph: SchematicLayoutGraph): FunctionalBlockGraph;
|
|
5
|
+
export declare function orderBlocksForPlacement(graph: FunctionalBlockGraph): FunctionalBlockGraphNode[];
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { compareIds } from './geometry.js';
|
|
2
|
+
export const BLOCK_FLOW_BASE_RANK = {
|
|
3
|
+
'power-input': 0,
|
|
4
|
+
connector: 0,
|
|
5
|
+
usb: 1,
|
|
6
|
+
regulation: 1,
|
|
7
|
+
crystal: 2,
|
|
8
|
+
mcu: 3,
|
|
9
|
+
memory: 3,
|
|
10
|
+
sensor: 3,
|
|
11
|
+
'analog-front-end': 3,
|
|
12
|
+
debug: 4,
|
|
13
|
+
'motor-driver': 4,
|
|
14
|
+
'led-chain': 5,
|
|
15
|
+
other: 3,
|
|
16
|
+
};
|
|
17
|
+
function endpointOrder(a, b) {
|
|
18
|
+
return compareIds(a.componentId, b.componentId) || compareIds(a.pinId ?? '', b.pinId ?? '');
|
|
19
|
+
}
|
|
20
|
+
function directedPairs(endpoints) {
|
|
21
|
+
const uniqueByComponent = new Map();
|
|
22
|
+
for (const endpoint of [...endpoints].sort(endpointOrder)) {
|
|
23
|
+
const existing = uniqueByComponent.get(endpoint.componentId);
|
|
24
|
+
if (!existing || endpoint.direction === 'output' || endpoint.direction === 'power') {
|
|
25
|
+
uniqueByComponent.set(endpoint.componentId, endpoint);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const unique = [...uniqueByComponent.values()].sort(endpointOrder);
|
|
29
|
+
if (unique.length < 2)
|
|
30
|
+
return [];
|
|
31
|
+
const sources = unique.filter((endpoint) => endpoint.direction === 'output' || endpoint.direction === 'power');
|
|
32
|
+
if (sources.length > 0) {
|
|
33
|
+
const result = [];
|
|
34
|
+
for (const source of sources) {
|
|
35
|
+
for (const target of unique) {
|
|
36
|
+
if (source.componentId !== target.componentId && !sources.includes(target)) {
|
|
37
|
+
result.push({ source, target, directed: true });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
const anchor = unique[0];
|
|
44
|
+
if (!anchor)
|
|
45
|
+
return [];
|
|
46
|
+
return unique.slice(1).map((target) => ({ source: anchor, target, directed: false }));
|
|
47
|
+
}
|
|
48
|
+
export function buildSchematicLayoutGraph(components, nets = []) {
|
|
49
|
+
const componentById = new Map([...components]
|
|
50
|
+
.sort((a, b) => compareIds(a.id, b.id))
|
|
51
|
+
.map((component) => [component.id, component]));
|
|
52
|
+
const incoming = new Map();
|
|
53
|
+
const outgoing = new Map();
|
|
54
|
+
const adjacency = new Map();
|
|
55
|
+
for (const id of componentById.keys()) {
|
|
56
|
+
incoming.set(id, new Set());
|
|
57
|
+
outgoing.set(id, new Set());
|
|
58
|
+
adjacency.set(id, new Set());
|
|
59
|
+
}
|
|
60
|
+
const edges = [];
|
|
61
|
+
const edgeKeys = new Set();
|
|
62
|
+
for (const net of [...nets].sort((a, b) => compareIds(a.id, b.id))) {
|
|
63
|
+
const endpoints = net.endpoints.filter((endpoint) => componentById.has(endpoint.componentId));
|
|
64
|
+
for (const pair of directedPairs(endpoints)) {
|
|
65
|
+
const sourceComponentId = pair.source.componentId;
|
|
66
|
+
const targetComponentId = pair.target.componentId;
|
|
67
|
+
const key = `${net.id}\u0000${sourceComponentId}\u0000${targetComponentId}`;
|
|
68
|
+
if (edgeKeys.has(key))
|
|
69
|
+
continue;
|
|
70
|
+
edgeKeys.add(key);
|
|
71
|
+
edges.push({
|
|
72
|
+
id: `${net.id}:${sourceComponentId}:${targetComponentId}`,
|
|
73
|
+
netId: net.id,
|
|
74
|
+
sourceComponentId,
|
|
75
|
+
targetComponentId,
|
|
76
|
+
directed: pair.directed,
|
|
77
|
+
});
|
|
78
|
+
outgoing.get(sourceComponentId)?.add(net.id);
|
|
79
|
+
incoming.get(targetComponentId)?.add(net.id);
|
|
80
|
+
if (!pair.directed) {
|
|
81
|
+
outgoing.get(targetComponentId)?.add(net.id);
|
|
82
|
+
incoming.get(sourceComponentId)?.add(net.id);
|
|
83
|
+
}
|
|
84
|
+
adjacency.get(sourceComponentId)?.add(targetComponentId);
|
|
85
|
+
adjacency.get(targetComponentId)?.add(sourceComponentId);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
edges.sort((a, b) => compareIds(a.id, b.id));
|
|
89
|
+
const nodes = [...componentById.values()].map((component) => ({
|
|
90
|
+
id: component.id,
|
|
91
|
+
component,
|
|
92
|
+
incomingNetIds: [...(incoming.get(component.id) ?? [])].sort(compareIds),
|
|
93
|
+
outgoingNetIds: [...(outgoing.get(component.id) ?? [])].sort(compareIds),
|
|
94
|
+
}));
|
|
95
|
+
const adjacencyRecord = {};
|
|
96
|
+
for (const id of [...adjacency.keys()].sort(compareIds)) {
|
|
97
|
+
adjacencyRecord[id] = [...(adjacency.get(id) ?? [])].sort(compareIds);
|
|
98
|
+
}
|
|
99
|
+
return { nodes, edges, adjacency: adjacencyRecord };
|
|
100
|
+
}
|
|
101
|
+
export function buildFunctionalBlockGraph(blocks, componentGraph) {
|
|
102
|
+
const blockById = new Map(blocks.map((block) => [block.id, block]));
|
|
103
|
+
const blockForComponent = new Map();
|
|
104
|
+
for (const block of blocks) {
|
|
105
|
+
for (const componentId of block.componentIds)
|
|
106
|
+
blockForComponent.set(componentId, block.id);
|
|
107
|
+
}
|
|
108
|
+
const edges = [];
|
|
109
|
+
const edgeKeys = new Set();
|
|
110
|
+
for (const edge of componentGraph.edges) {
|
|
111
|
+
let sourceBlockId = blockForComponent.get(edge.sourceComponentId);
|
|
112
|
+
let targetBlockId = blockForComponent.get(edge.targetComponentId);
|
|
113
|
+
if (!sourceBlockId || !targetBlockId || sourceBlockId === targetBlockId)
|
|
114
|
+
continue;
|
|
115
|
+
if (!edge.directed) {
|
|
116
|
+
const source = blockById.get(sourceBlockId);
|
|
117
|
+
const target = blockById.get(targetBlockId);
|
|
118
|
+
if (source &&
|
|
119
|
+
target &&
|
|
120
|
+
(BLOCK_FLOW_BASE_RANK[source.kind] > BLOCK_FLOW_BASE_RANK[target.kind] ||
|
|
121
|
+
(BLOCK_FLOW_BASE_RANK[source.kind] === BLOCK_FLOW_BASE_RANK[target.kind] &&
|
|
122
|
+
compareIds(sourceBlockId, targetBlockId) > 0))) {
|
|
123
|
+
[sourceBlockId, targetBlockId] = [targetBlockId, sourceBlockId];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const key = `${edge.netId}\u0000${sourceBlockId}\u0000${targetBlockId}`;
|
|
127
|
+
if (edgeKeys.has(key))
|
|
128
|
+
continue;
|
|
129
|
+
edgeKeys.add(key);
|
|
130
|
+
edges.push({
|
|
131
|
+
id: `${edge.netId}:${sourceBlockId}:${targetBlockId}`,
|
|
132
|
+
netId: edge.netId,
|
|
133
|
+
sourceBlockId,
|
|
134
|
+
targetBlockId,
|
|
135
|
+
directed: edge.directed,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
edges.sort((a, b) => compareIds(a.id, b.id));
|
|
139
|
+
const incoming = new Map();
|
|
140
|
+
const outgoing = new Map();
|
|
141
|
+
const ranks = new Map();
|
|
142
|
+
for (const block of blocks) {
|
|
143
|
+
incoming.set(block.id, new Set());
|
|
144
|
+
outgoing.set(block.id, new Set());
|
|
145
|
+
ranks.set(block.id, BLOCK_FLOW_BASE_RANK[block.kind]);
|
|
146
|
+
}
|
|
147
|
+
for (const edge of edges) {
|
|
148
|
+
incoming.get(edge.targetBlockId)?.add(edge.sourceBlockId);
|
|
149
|
+
outgoing.get(edge.sourceBlockId)?.add(edge.targetBlockId);
|
|
150
|
+
}
|
|
151
|
+
// Bounded relaxation preserves deterministic ranks even when the schematic graph has cycles.
|
|
152
|
+
for (let pass = 0; pass < blocks.length; pass += 1) {
|
|
153
|
+
let changed = false;
|
|
154
|
+
for (const edge of edges) {
|
|
155
|
+
if (!edge.directed)
|
|
156
|
+
continue;
|
|
157
|
+
const sourceRank = ranks.get(edge.sourceBlockId) ?? 0;
|
|
158
|
+
const target = blockById.get(edge.targetBlockId);
|
|
159
|
+
if (!target)
|
|
160
|
+
continue;
|
|
161
|
+
const next = Math.max(ranks.get(edge.targetBlockId) ?? 0, Math.min(9, sourceRank + 1), BLOCK_FLOW_BASE_RANK[target.kind]);
|
|
162
|
+
if (next !== ranks.get(edge.targetBlockId)) {
|
|
163
|
+
ranks.set(edge.targetBlockId, next);
|
|
164
|
+
changed = true;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (!changed)
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
const nodes = [...blocks]
|
|
171
|
+
.sort((a, b) => compareIds(a.id, b.id))
|
|
172
|
+
.map((block) => ({
|
|
173
|
+
blockId: block.id,
|
|
174
|
+
kind: block.kind,
|
|
175
|
+
componentIds: [...block.componentIds].sort(compareIds),
|
|
176
|
+
incomingBlockIds: [...(incoming.get(block.id) ?? [])].sort(compareIds),
|
|
177
|
+
outgoingBlockIds: [...(outgoing.get(block.id) ?? [])].sort(compareIds),
|
|
178
|
+
flowRank: ranks.get(block.id) ?? BLOCK_FLOW_BASE_RANK[block.kind],
|
|
179
|
+
}));
|
|
180
|
+
return { nodes, edges };
|
|
181
|
+
}
|
|
182
|
+
export function orderBlocksForPlacement(graph) {
|
|
183
|
+
return [...graph.nodes].sort((a, b) => a.flowRank - b.flowRank || compareIds(a.blockId, b.blockId));
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=graph.js.map
|