Preserve pin UI metadata during symbol pin migrations
This commit is contained in:
parent
b7ba158880
commit
bb3edfdc76
@ -800,7 +800,8 @@ function renamePinAcrossSymbolInstances(symbolId, oldPinName, newPinName) {
|
|||||||
if (!state.model || !oldPinName || !newPinName || oldPinName === newPinName) {
|
if (!state.model || !oldPinName || !newPinName || oldPinName === newPinName) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const refs = new Set((state.model.instances ?? []).filter((i) => i.symbol === symbolId).map((i) => i.ref));
|
const instances = (state.model.instances ?? []).filter((i) => i.symbol === symbolId);
|
||||||
|
const refs = new Set(instances.map((i) => i.ref));
|
||||||
for (const net of state.model.nets ?? []) {
|
for (const net of state.model.nets ?? []) {
|
||||||
for (const node of net.nodes ?? []) {
|
for (const node of net.nodes ?? []) {
|
||||||
if (refs.has(node.ref) && node.pin === oldPinName) {
|
if (refs.has(node.ref) && node.pin === oldPinName) {
|
||||||
@ -808,6 +809,20 @@ function renamePinAcrossSymbolInstances(symbolId, oldPinName, newPinName) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const inst of instances) {
|
||||||
|
const pinUi = inst.properties?.pin_ui;
|
||||||
|
if (!pinUi || typeof pinUi !== "object" || Array.isArray(pinUi)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (Object.prototype.hasOwnProperty.call(pinUi, oldPinName) && !Object.prototype.hasOwnProperty.call(pinUi, newPinName)) {
|
||||||
|
pinUi[newPinName] = pinUi[oldPinName];
|
||||||
|
delete pinUi[oldPinName];
|
||||||
|
} else if (Object.prototype.hasOwnProperty.call(pinUi, oldPinName) && Object.prototype.hasOwnProperty.call(pinUi, newPinName)) {
|
||||||
|
delete pinUi[oldPinName];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (state.selectedPin && refs.has(state.selectedPin.ref) && state.selectedPin.pin === oldPinName) {
|
if (state.selectedPin && refs.has(state.selectedPin.ref) && state.selectedPin.pin === oldPinName) {
|
||||||
state.selectedPin.pin = newPinName;
|
state.selectedPin.pin = newPinName;
|
||||||
}
|
}
|
||||||
@ -2256,6 +2271,7 @@ function setupEvents() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pushHistory("symbol-edit");
|
pushHistory("symbol-edit");
|
||||||
|
const beforePins = new Set((sym.pins ?? []).map((p) => p.name));
|
||||||
for (const entry of parsedPins) {
|
for (const entry of parsedPins) {
|
||||||
if (entry.oldName && entry.oldName !== entry.pin.name) {
|
if (entry.oldName && entry.oldName !== entry.pin.name) {
|
||||||
renamePinAcrossSymbolInstances(inst.symbol, entry.oldName, entry.pin.name);
|
renamePinAcrossSymbolInstances(inst.symbol, entry.oldName, entry.pin.name);
|
||||||
@ -2270,6 +2286,20 @@ function setupEvents() {
|
|||||||
sym.pins = parsedPins.map((p) => p.pin);
|
sym.pins = parsedPins.map((p) => p.pin);
|
||||||
const allowedPins = new Set(sym.pins.map((p) => p.name));
|
const allowedPins = new Set(sym.pins.map((p) => p.name));
|
||||||
const refs = new Set((state.model.instances ?? []).filter((i) => i.symbol === inst.symbol).map((i) => i.ref));
|
const refs = new Set((state.model.instances ?? []).filter((i) => i.symbol === inst.symbol).map((i) => i.ref));
|
||||||
|
for (const ii of state.model.instances ?? []) {
|
||||||
|
if (!refs.has(ii.ref)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const pinUi = ii.properties?.pin_ui;
|
||||||
|
if (!pinUi || typeof pinUi !== "object" || Array.isArray(pinUi)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (const key of Object.keys(pinUi)) {
|
||||||
|
if (!allowedPins.has(key)) {
|
||||||
|
delete pinUi[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
for (const net of state.model.nets ?? []) {
|
for (const net of state.model.nets ?? []) {
|
||||||
net.nodes = (net.nodes ?? []).filter((node) => !refs.has(node.ref) || allowedPins.has(node.pin));
|
net.nodes = (net.nodes ?? []).filter((node) => !refs.has(node.ref) || allowedPins.has(node.pin));
|
||||||
}
|
}
|
||||||
@ -2278,7 +2308,10 @@ function setupEvents() {
|
|||||||
if (state.selectedPin && !pinExists(state.selectedPin.ref, state.selectedPin.pin)) {
|
if (state.selectedPin && !pinExists(state.selectedPin.ref, state.selectedPin.pin)) {
|
||||||
state.selectedPin = null;
|
state.selectedPin = null;
|
||||||
}
|
}
|
||||||
el.jsonFeedback.textContent = `Updated symbol ${inst.symbol}.`;
|
const removedPinCount = [...beforePins].filter((p) => !allowedPins.has(p)).length;
|
||||||
|
el.jsonFeedback.textContent = removedPinCount
|
||||||
|
? `Updated symbol ${inst.symbol}. Removed ${removedPinCount} pin mappings from nets/UI metadata.`
|
||||||
|
: `Updated symbol ${inst.symbol}.`;
|
||||||
queueCompile(true, "symbol-edit");
|
queueCompile(true, "symbol-edit");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user