mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-07-30 07:44:13 +02:00
Fix terminal grouping: use functiondefinition block, not pin designation
The previous grouping compared `connectionDesignation` values (e.g. "1", "2", "3") to detect group boundaries. Those values are pin position numbers within a terminal block, not functional group identifiers, so devices like the ABB ACS880 produced 11+ tiny single-pin "groups" instead of the ~8 functional blocks (AC-IN, Motor-OUT, DC-Bus, Brake-Resistor, Analog-I/O, Digital-I/O, ...) the reviewer identified. Fix: - Add `group` field to EdzPin, populated from the `functiondefinition` attribute on <functiontemplate> (newer EPLAN) or its parent <function> element (older EPLAN). - Sort pins by group first (preserving XML appearance order per group), then by designation within each group using natural sort. - Use `groupKey()` — group when present, designation as fallback — for the group-break detection that drives separator lines and Y-gaps. Parts without any functiondefinition data retain the previous designation-based behaviour unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -204,13 +204,29 @@ bool EdzPart::parse(const QString &part_xml_path)
|
||||
pin.designation = desig;
|
||||
pin.description =
|
||||
ft.attribute(QStringLiteral("connectiondescription")).trimmed();
|
||||
// functiondefinition identifies the functional block (FINP, MOUT, …).
|
||||
// It lives on <functiontemplate> directly in newer EPLAN versions, or on
|
||||
// the parent <function> wrapper element in older ones.
|
||||
pin.group = ft.attribute(QStringLiteral("functiondefinition")).trimmed();
|
||||
if (pin.group.isEmpty())
|
||||
pin.group = ft.parentNode().toElement()
|
||||
.attribute(QStringLiteral("functiondefinition")).trimmed();
|
||||
m_pins.append(pin);
|
||||
}
|
||||
|
||||
// EPLAN lists pins in its own order (e.g. MFH200: 1,3,4,2); order them by
|
||||
// pin number so they stack 1,2,3,4 on the symbol.
|
||||
// Sort: preserve the XML order of functional groups (first-seen wins), and
|
||||
// within each group sort by designation using natural sort so pins stack
|
||||
// numerically (1, 2, 3 …) on the symbol.
|
||||
QMap<QString, int> group_order;
|
||||
for (const EdzPin &p : m_pins) {
|
||||
if (!group_order.contains(p.group))
|
||||
group_order.insert(p.group, group_order.size());
|
||||
}
|
||||
std::stable_sort(m_pins.begin(), m_pins.end(),
|
||||
[](const EdzPin &a, const EdzPin &b) {
|
||||
[&group_order](const EdzPin &a, const EdzPin &b) {
|
||||
const int ga = group_order.value(a.group, 0);
|
||||
const int gb = group_order.value(b.group, 0);
|
||||
if (ga != gb) return ga < gb;
|
||||
return natLess(a.designation, b.designation);
|
||||
});
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user