Scripting: find a terminal by its uuid

The conductor calls name a wire end as element uuid + terminal index.
The index is the terminal's place in Element::terminals(), a sort by
position that is undefined between two terminals at the same point, and
the documentation ruled terminal uuids out as "empty for most of the
installed base". Since #1118 every terminal of an opened project has one.

- elementTerminals() ends each line with the terminal's uuid
  (Terminal::stableUuid()); the text before it is unchanged.
- terminalIndex(folio, elementUuid, terminalUuid) returns the index the
  calls take, or -1 if the element or terminal is not there, or if two of
  the element's terminals carry that uuid.
- The class documentation says what does address a terminal: its uuid
  together with its element's.

tst_scriptterminaluuid runs --run on perceuse.qet (552 elements, two
terminals at one point in some): every terminal listed with a uuid,
distinct within its element, found again at its own index; -1 for an
unknown or malformed uuid, an unknown element and a bad folio. Red when
terminalIndex() returns the wrong index. qet-mcp suite 253/253.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-09-29 10:40:11 +13:00
parent b411a08340
commit 9fdd6ac333
4 changed files with 186 additions and 21 deletions
+12 -8
View File
@@ -96,14 +96,16 @@ class QetGraphicsTableItem;
no way to connect them.
Terminals are addressed by their @b index in Element::terminals(),
not by uuid, and elementTerminals() prints that indexing so a script
can see what it is about to wire. The index is the terminal's place
in the element's own top-to-bottom, left-to-right ordering, not the
order its definition file lists them. Terminal uuids look like the
obvious key and are not one: Terminal::uuid() is a property of the
catalog .elmt definition, empty for most of the installed base and,
where present, identical across every instance of that element -- so
it does not distinguish one placed coil's A1 from another's.
and elementTerminals() prints that indexing so a script can see what
it is about to wire. The index is the terminal's place in the
element's own top-to-bottom, left-to-right ordering, not the order
its definition file lists them, and it is undefined between two
terminals at the same point. What does not move is the terminal's
uuid together with its element's: each elementTerminals() line ends
with the terminal's uuid, and terminalIndex() turns element uuid +
terminal uuid back into the index. A terminal uuid alone is not an
address -- it comes from the symbol's definition, so every placed
instance of one symbol has the same ones.
- @b Conductor properties and @b cross-references: set a conductor's
number, formula, colour or section (and its look: style normal/
dashed/dashdotted, two-colour mode and second colour, dash size,
@@ -384,6 +386,8 @@ class QetScriptApi : public QObject
Q_INVOKABLE QStringList elementUuids(int folioIndex) const;
Q_INVOKABLE QString elementName(int folioIndex, const QString &elementUuid) const;
Q_INVOKABLE QStringList elementTerminals(int folioIndex, const QString &elementUuid) const;
Q_INVOKABLE int terminalIndex(int folioIndex, const QString &elementUuid,
const QString &terminalUuid) const;
// -- element information, through ChangeElementInformationCommand --
Q_INVOKABLE QString elementInfo(int folioIndex, const QString &elementUuid, const QString &key) const;