diff --git a/sources/import/edz/edzelementbuilder.cpp b/sources/import/edz/edzelementbuilder.cpp index 6ec12bc92..84fda9a17 100644 --- a/sources/import/edz/edzelementbuilder.cpp +++ b/sources/import/edz/edzelementbuilder.cpp @@ -73,12 +73,16 @@ QDomDocument EdzElementBuilder::build(const EdzPart &part) const int pitch = 10; const int group_gap = 5; // extra px inserted between designation groups - // Pins arrive sorted by designation (see EdzPart::parse). Identify group - // boundaries and compute per-pin Y coordinates, inserting group_gap extra - // pixels before each new designation group so they read as distinct blocks. + // Pins arrive sorted by functional group then by designation within each + // group (see EdzPart::parse). A group break occurs when the + // functiondefinition block changes; fall back to designation comparison for + // parts that carry no functiondefinition information. + auto groupKey = [](const EdzPin &p) { + return p.group.isEmpty() ? p.designation : p.group; + }; QVector is_group_break(n, false); for (int i = 1; i < n; ++i) - is_group_break[i] = (pins.at(i).designation != pins.at(i - 1).designation); + is_group_break[i] = (groupKey(pins.at(i)) != groupKey(pins.at(i - 1))); QVector pin_y(n); int cur_y = 0; diff --git a/sources/import/edz/edzpart.cpp b/sources/import/edz/edzpart.cpp index 950eee400..a3e39e026 100644 --- a/sources/import/edz/edzpart.cpp +++ b/sources/import/edz/edzpart.cpp @@ -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 directly in newer EPLAN versions, or on + // the parent 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 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; diff --git a/sources/import/edz/edzpart.h b/sources/import/edz/edzpart.h index 5dafda5f6..a2d02e46f 100644 --- a/sources/import/edz/edzpart.h +++ b/sources/import/edz/edzpart.h @@ -26,6 +26,7 @@ struct EdzPin { QString designation; ///< terminal id, e.g. "1", "PE" QString description; ///< function label, e.g. "L+" + QString group; ///< functiondefinition block, e.g. "FINP", "MOUT" }; /**