Topic: Suggestion: Use Terminal-Names in schematic-file
Hello everyone!
For some time now, it is possible to assign a name to terminals in the element files. A unique UUID is automatically added in the background. If such a component is then inserted into a schematic and provided with connections, the UUIDs of the terminals are already used in the qet file to identify the connection.
At some point in the future, when the developers have (a lot of) time for the project again, the "UUID" and "Name" information will be used to automatically generate cable plans and wiring instructions.
As a "programming exercise", I looked in the source code for a way to include the names of the terminals in the connection line in the schematic file and actually found what I was looking for!
However, there is one "difficulty":
What name may automatically be used if the creator of the element has not assigned any names?
I made it easy for myself here and also saved the UUID of the connection for the name.
Here is the resulting diff file:
diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp
diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp
index dc9d23595..df0e9fdc6 100644
--- a/sources/qetgraphicsitem/conductor.cpp
+++ b/sources/qetgraphicsitem/conductor.cpp
@@ -1048,6 +1048,7 @@ QDomElement Conductor::toXml(QDomDocument &dom_document,
} else {
dom_element.setAttribute("element1", terminal1->parentElement()->uuid().toString());
dom_element.setAttribute("terminal1", terminal1->uuid().toString());
+ dom_element.setAttribute("terminalname1", terminal1->name());
}
if (terminal2->uuid().isNull()) {
@@ -1056,6 +1057,7 @@ QDomElement Conductor::toXml(QDomDocument &dom_document,
} else {
dom_element.setAttribute("element2", terminal2->parentElement()->uuid().toString());
dom_element.setAttribute("terminal2", terminal2->uuid().toString());
+ dom_element.setAttribute("terminalname2", terminal2->name());
}
dom_element.setAttribute("freezeLabel", m_freeze_label? "true" : "false");
diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp
index 54f9ece5f..951d67aa0 100644
--- a/sources/qetgraphicsitem/terminal.cpp
+++ b/sources/qetgraphicsitem/terminal.cpp
@@ -744,6 +744,16 @@ QUuid Terminal::uuid() const
return d->m_uuid;
}
+QString Terminal::name() const
+{
+ if (d->m_name == "")
+ {
+ return ((d->m_uuid).toString());
+ } else {
+ return d->m_name;
+ }
+}
+
/**
@brief Conductor::relatedPotentialTerminal
Return terminal at the same potential from the same
diff --git a/sources/qetgraphicsitem/terminal.h b/sources/qetgraphicsitem/terminal.h
index e014d2a1f..a8d22abc8 100644
--- a/sources/qetgraphicsitem/terminal.h
+++ b/sources/qetgraphicsitem/terminal.h
@@ -74,6 +74,7 @@ class Terminal : public QGraphicsObject
Diagram *diagram () const;
Element *parentElement () const;
QUuid uuid () const;
+ QString name () const;
QList<Conductor *> conductors() const;
Qet::Orientation orientation() const;
I understand this code fragment explicitly as a basis for discussion:
Please have a look at it and leave comments!
Best regards
plc-user