Reattach wires to a terminal that moved a little since the project was saved

A project saves, for every placed symbol, where each terminal docked, its
orientation and its number. When the symbol's definition is replaced by one
whose terminal sits a few units elsewhere, wires were matched by exact
position and so were dropped on the next open: legacy wires by Terminal::
fromXml(), uuid wires by the uuid derived from the terminal's new place.

Element::fromXml() now pairs each saved terminal that nothing matched
exactly with the live terminal of the same orientation whose docking point
is within 5 units in x and y, only when each is the other's only candidate.
A pair registers the saved number, and the uuid derived from the old place,
which Diagram::findTerminals() checks after the derived uuid of the current
place. Wire ends reattached this way are counted and logged once per folio.

tst_movedterminals covers a move of 3 and 5 units (number and derived
uuid), 6 units, two candidates, and an unmoved terminal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-15 20:26:30 +13:00
parent 6af9c097d8
commit 786f8574d9
5 changed files with 344 additions and 1 deletions
+14
View File
@@ -1790,6 +1790,11 @@ QList<Terminal *> findTerminals(int conductor_index,
if (terminal->derivedUuid() == terminal_uuid)
match = terminal;
}
//A terminal that moved since the project was saved: the
//uuid worked out from its old place was paired with it
//when the symbol was read (Element::fromXml()).
if (!match)
match = element->terminalFromOldPlace(terminal_uuid);
if (match)
found << match;
else
@@ -2241,6 +2246,7 @@ bool Diagram::fromXml(QDomElement &document,
if (consider_informations)
m_wires_not_reconnected.clear();
QList<Conductor *> added_conductors;
int moved_ends = 0;
for (auto f : QET::findInDomElement(root,
QStringLiteral("conductors"),
QStringLiteral("conductor")))
@@ -2312,11 +2318,19 @@ bool Diagram::fromXml(QDomElement &document,
ends.join(QLatin1Char('\n'))));
}
added_conductors << c;
for (Terminal *end : {p1, p2})
if (end->parentElement()->terminalWasMoved(end)) ++moved_ends;
}
else
delete c;
}
}
if (consider_informations && moved_ends) {
qInfo().noquote() << "Diagram::fromXml():"
<< moved_ends
<< "wire end(s) on a terminal that moved since the project was saved,"
<< "matched to it by place";
}
if (consider_informations && !m_wires_not_reconnected.isEmpty()) {
qWarning().noquote() << "Diagram::fromXml():"
<< m_wires_not_reconnected.size()