This commit is contained in:
1 parent
cd007ba431
commit
0d53bdaf9a
2 files changed
+54
-6
No files matched your search
+40
-2
@@ -118,6 +118,41 @@ function rotateSide(side, rotation) {
|
||||
return order[(idx + steps) % 4];
|
||||
}
|
||||
|
||||
function hasValidPlacement(inst) {
|
||||
return Number.isFinite(inst?.placement?.x) && Number.isFinite(inst?.placement?.y);
|
||||
}
|
||||
|
||||
function preservePlacedInstances(model, options = {}) {
|
||||
const respectLocks = options.respectLocks ?? true;
|
||||
const autoRotate = options.autoRotate ?? false;
|
||||
const fallback = placeInstances(model, { respectLocks, autoRotate });
|
||||
const fallbackByRef = new Map((fallback?.placed ?? []).map((inst) => [inst.ref, inst]));
|
||||
const instances = [...model.instances].sort((a, b) => a.ref.localeCompare(b.ref));
|
||||
|
||||
return instances.map((inst) => {
|
||||
if (hasValidPlacement(inst)) {
|
||||
return {
|
||||
...inst,
|
||||
placement: {
|
||||
x: toGrid(Number(inst.placement.x)),
|
||||
y: toGrid(Number(inst.placement.y)),
|
||||
rotation: normalizeRotation(inst.placement.rotation ?? 0),
|
||||
locked: respectLocks ? Boolean(inst.placement.locked) : false
|
||||
}
|
||||
};
|
||||
}
|
||||
return fallbackByRef.get(inst.ref) ?? {
|
||||
...inst,
|
||||
placement: {
|
||||
x: toGrid(MARGIN_X),
|
||||
y: toGrid(MARGIN_Y),
|
||||
rotation: normalizeRotation(inst.placement?.rotation ?? 0),
|
||||
locked: respectLocks ? Boolean(inst.placement?.locked) : false
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function getNodePin(model, placedMap, node) {
|
||||
const inst = placedMap.get(node.ref);
|
||||
if (!inst) {
|
||||
@@ -2358,8 +2393,11 @@ export function layoutAndRoute(model, options = {}) {
|
||||
const renderMode = options.render_mode === "explicit" ? "explicit" : DEFAULT_RENDER_MODE;
|
||||
const respectLocks = options.respect_locks ?? true;
|
||||
const autoRotate = options.auto_rotate ?? true;
|
||||
|
||||
const { placed, placedMap } = placeInstances(model, { respectLocks, autoRotate });
|
||||
const preservePlacement = options.preserve_placement === true;
|
||||
const placed = preservePlacement
|
||||
? preservePlacedInstances(model, { respectLocks, autoRotate: false })
|
||||
: placeInstances(model, { respectLocks, autoRotate }).placed;
|
||||
const placedMap = new Map(placed.map((inst) => [inst.ref, inst]));
|
||||
const bounds = buildBounds(model, placed);
|
||||
const { routed, busGroups } = routeAllNets(model, placed, placedMap, bounds, {
|
||||
renderMode
|
||||
|
||||
Reference in new issue
Block a user