From 207c0c9544f5dce9fe461b23066cc05e899bb6ac Mon Sep 17 00:00:00 2001 From: Shane Ringrose Date: Sat, 20 Jun 2026 22:39:11 +1200 Subject: [PATCH] Fix copyright years and deduplicate terminal names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two issues raised in PR review: 1. Copyright year: new files carried "2006" (the project's founding year). Updated to "2006-2026" to reflect the actual authorship period. 2. Duplicate terminal names: EPLAN parts can have multiple connection templates sharing the same connectionDesignation (e.g. a drive where both wire entries of terminal "1" are labelled "1"). QET requires unique terminal names for wiring and terminal-diagram generation. Resolution order in EdzElementBuilder::build(): - Unique designation → used as-is. - Duplicated designation with distinct sanitised description → "designation_description" (e.g. "1_L_P"). - Otherwise → numeric suffix: "1", "1_2", "1_3", … Co-Authored-By: Claude Sonnet 4.6 --- sources/import/edz/edzarchive.cpp | 2 +- sources/import/edz/edzarchive.h | 2 +- sources/import/edz/edzelementbuilder.cpp | 66 +++++++++++++++++++++++- sources/import/edz/edzelementbuilder.h | 2 +- sources/import/edz/edzimporter.cpp | 2 +- sources/import/edz/edzimporter.h | 2 +- sources/import/edz/edzpart.cpp | 2 +- sources/import/edz/edzpart.h | 2 +- sources/import/edz/edzsevenzip.cpp | 2 +- sources/import/edz/edzsevenzip.h | 2 +- 10 files changed, 73 insertions(+), 11 deletions(-) diff --git a/sources/import/edz/edzarchive.cpp b/sources/import/edz/edzarchive.cpp index 5c7b3526f..62207502b 100644 --- a/sources/import/edz/edzarchive.cpp +++ b/sources/import/edz/edzarchive.cpp @@ -1,5 +1,5 @@ /* - Copyright 2006 The QElectroTech Team + Copyright 2006-2026 The QElectroTech Team This file is part of QElectroTech. QElectroTech is free software: you can redistribute it and/or modify diff --git a/sources/import/edz/edzarchive.h b/sources/import/edz/edzarchive.h index 7d154e56d..b526f16f3 100644 --- a/sources/import/edz/edzarchive.h +++ b/sources/import/edz/edzarchive.h @@ -1,5 +1,5 @@ /* - Copyright 2006 The QElectroTech Team + Copyright 2006-2026 The QElectroTech Team This file is part of QElectroTech. QElectroTech is free software: you can redistribute it and/or modify diff --git a/sources/import/edz/edzelementbuilder.cpp b/sources/import/edz/edzelementbuilder.cpp index 6bccbce32..9e5597130 100644 --- a/sources/import/edz/edzelementbuilder.cpp +++ b/sources/import/edz/edzelementbuilder.cpp @@ -1,5 +1,5 @@ /* - Copyright 2006 The QElectroTech Team + Copyright 2006-2026 The QElectroTech Team This file is part of QElectroTech. QElectroTech is free software: you can redistribute it and/or modify @@ -19,7 +19,10 @@ #include "edzpart.h" +#include +#include #include +#include #include #include @@ -213,11 +216,70 @@ QDomDocument EdzElementBuilder::build(const EdzPart &part) dyn.appendChild(info_name); desc.appendChild(dyn); + // Build unique terminal names. QET requires every terminal in an element + // to have a distinct name for wiring and terminal-diagram generation to + // work. EPLAN parts sometimes repeat the same connectionDesignation across + // multiple function templates (e.g. a drive with several connections named + // "1", "2", "3"). Resolve duplicates: + // 1. If a designation is unique, keep it as-is. + // 2. If duplicated, append "_" + sanitised description when that yields + // a unique result (e.g. "1_L+_P" -> "1_L_P"). + // 3. Fall back to appending "_2", "_3", … when descriptions are missing + // or still collide. + auto sanitise = [](const QString &s) -> QString { + QString out; + for (const QChar c : s) { + out += (c.isLetterOrNumber() || c == QLatin1Char('-')) ? c + : QLatin1Char('_'); + } + // Collapse consecutive underscores and strip trailing ones. + while (out.contains(QStringLiteral("__"))) + out.replace(QStringLiteral("__"), QStringLiteral("_")); + while (out.endsWith(QLatin1Char('_'))) + out.chop(1); + return out; + }; + + // Count occurrences of each raw designation. + QMap desig_count; + for (const EdzPin &p : pins) + desig_count[p.designation]++; + + QSet used_names; + QVector terminal_names(n); + // Per-designation occurrence counter for the fallback suffix. + QMap desig_seen; + + for (int i = 0; i < n; ++i) { + const EdzPin &pin = pins.at(i); + desig_seen[pin.designation]++; + + if (desig_count[pin.designation] == 1) { + // Unique designation — use directly. + terminal_names[i] = pin.designation; + } else { + // Try designation + sanitised description first. + const QString candidate = pin.description.isEmpty() + ? QString() + : pin.designation + QLatin1Char('_') + sanitise(pin.description); + if (!candidate.isEmpty() && !used_names.contains(candidate)) { + terminal_names[i] = candidate; + } else { + // Numeric suffix fallback: "1", "1_2", "1_3", … + const int occ = desig_seen[pin.designation]; + terminal_names[i] = (occ == 1) + ? pin.designation + : pin.designation + QLatin1Char('_') + QString::number(occ); + } + } + used_names.insert(terminal_names[i]); + } + // Terminals. for (int i = 0; i < n; ++i) { QDomElement t = doc.createElement(QStringLiteral("terminal")); t.setAttribute(QStringLiteral("uuid"), uuidStr()); - t.setAttribute(QStringLiteral("name"), pins.at(i).designation); + t.setAttribute(QStringLiteral("name"), terminal_names[i]); t.setAttribute(QStringLiteral("x"), 0); t.setAttribute(QStringLiteral("y"), i * pitch); t.setAttribute(QStringLiteral("orientation"), QStringLiteral("w")); diff --git a/sources/import/edz/edzelementbuilder.h b/sources/import/edz/edzelementbuilder.h index 8af8350a8..4c0c0794d 100644 --- a/sources/import/edz/edzelementbuilder.h +++ b/sources/import/edz/edzelementbuilder.h @@ -1,5 +1,5 @@ /* - Copyright 2006 The QElectroTech Team + Copyright 2006-2026 The QElectroTech Team This file is part of QElectroTech. QElectroTech is free software: you can redistribute it and/or modify diff --git a/sources/import/edz/edzimporter.cpp b/sources/import/edz/edzimporter.cpp index 16fb15ba7..07143e23b 100644 --- a/sources/import/edz/edzimporter.cpp +++ b/sources/import/edz/edzimporter.cpp @@ -1,5 +1,5 @@ /* - Copyright 2006 The QElectroTech Team + Copyright 2006-2026 The QElectroTech Team This file is part of QElectroTech. QElectroTech is free software: you can redistribute it and/or modify diff --git a/sources/import/edz/edzimporter.h b/sources/import/edz/edzimporter.h index 4abf8a79a..aae5fedda 100644 --- a/sources/import/edz/edzimporter.h +++ b/sources/import/edz/edzimporter.h @@ -1,5 +1,5 @@ /* - Copyright 2006 The QElectroTech Team + Copyright 2006-2026 The QElectroTech Team This file is part of QElectroTech. QElectroTech is free software: you can redistribute it and/or modify diff --git a/sources/import/edz/edzpart.cpp b/sources/import/edz/edzpart.cpp index 5a2364698..950eee400 100644 --- a/sources/import/edz/edzpart.cpp +++ b/sources/import/edz/edzpart.cpp @@ -1,5 +1,5 @@ /* - Copyright 2006 The QElectroTech Team + Copyright 2006-2026 The QElectroTech Team This file is part of QElectroTech. QElectroTech is free software: you can redistribute it and/or modify diff --git a/sources/import/edz/edzpart.h b/sources/import/edz/edzpart.h index 45d31620a..5dafda5f6 100644 --- a/sources/import/edz/edzpart.h +++ b/sources/import/edz/edzpart.h @@ -1,5 +1,5 @@ /* - Copyright 2006 The QElectroTech Team + Copyright 2006-2026 The QElectroTech Team This file is part of QElectroTech. QElectroTech is free software: you can redistribute it and/or modify diff --git a/sources/import/edz/edzsevenzip.cpp b/sources/import/edz/edzsevenzip.cpp index c557defaa..3f51a3987 100644 --- a/sources/import/edz/edzsevenzip.cpp +++ b/sources/import/edz/edzsevenzip.cpp @@ -1,5 +1,5 @@ /* - Copyright 2006 The QElectroTech Team + Copyright 2006-2026 The QElectroTech Team This file is part of QElectroTech. QElectroTech is free software: you can redistribute it and/or modify diff --git a/sources/import/edz/edzsevenzip.h b/sources/import/edz/edzsevenzip.h index 27659dd67..6546b671c 100644 --- a/sources/import/edz/edzsevenzip.h +++ b/sources/import/edz/edzsevenzip.h @@ -1,5 +1,5 @@ /* - Copyright 2006 The QElectroTech Team + Copyright 2006-2026 The QElectroTech Team This file is part of QElectroTech. QElectroTech is free software: you can redistribute it and/or modify