From ffd829bb69328c9e7f600dc1bac6e5bdc778f520 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Thu, 10 Sep 2026 11:54:52 +1200 Subject: [PATCH] Make the slave limit advisory rather than a refusal max_slaves records how many contacts a part is expected to carry. It was enforced as a rule the drawing had to obey, which obstructs the way both @scorpio810 and @IBSYSLevi described working in #819: draw the schematic first, choose the physical hardware afterwards. A limit that refuses the link forces the hardware decision up front, which is exactly what they said gets in the way. Two changes, both in the UI rather than in isFull(), which stays the query it always was: - MasterPropertiesWidget::on_link_button_clicked() now says the limit is reached and asks whether to link anyway, defaulting to yes, instead of refusing outright. - LinkSingleElementWidget no longer removes a full master from the candidate list. That was the worse half: a master at its limit simply was not there, indistinguishable from one that does not exist, with nothing to say why. It now stays selectable and the user decides. PLC masters are deliberately left alone. Their limit is the number of declared IO slots, which is structural rather than advisory -- a link past it would have no IO index to map to -- and PlcLinkWidget already tells the user when it hides one, via m_hidden_masters_label. Only coils that opt into a limit are affected: max_slaves defaults to -1, and no project in examples/ sets it. Co-Authored-By: Claude Opus 5 --- sources/ui/linksingleelementwidget.cpp | 12 ++++++------ sources/ui/masterpropertieswidget.cpp | 21 +++++++++++++++------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/sources/ui/linksingleelementwidget.cpp b/sources/ui/linksingleelementwidget.cpp index 7cc04559d..e2c3c8b38 100644 --- a/sources/ui/linksingleelementwidget.cpp +++ b/sources/ui/linksingleelementwidget.cpp @@ -17,7 +17,6 @@ */ #include "linksingleelementwidget.h" #include "contactgroupselectiondialog.h" -#include "../qetgraphicsitem/masterelement.h" #include "../qetgraphicsitem/conductor.h" #include "../diagram.h" #include "../diagramposition.h" @@ -418,11 +417,12 @@ QVector > LinkSingleElementWidget::availableElements() continue; } - // If the master is full, we'll remove it from the list! - MasterElement *master = static_cast(elmt); - if (master->isFull()) { - elmt_vector.removeAt(i); - } + // A master at its declared limit stays in the list. Removing + // it made a full master indistinguishable from one that does + // not exist: the candidate simply was not there, with nothing + // to say why. The limit is advisory -- see the prompt in + // MasterPropertiesWidget::on_link_button_clicked() -- so the + // user decides, rather than the list deciding for them. } } return elmt_vector; diff --git a/sources/ui/masterpropertieswidget.cpp b/sources/ui/masterpropertieswidget.cpp index bd5500e09..339938d06 100644 --- a/sources/ui/masterpropertieswidget.cpp +++ b/sources/ui/masterpropertieswidget.cpp @@ -307,15 +307,24 @@ void MasterPropertiesWidget::on_link_button_clicked() int max_slaves = max_slaves_variant.toInt(); int current_slaves = ui->m_link_tree_widget->topLevelItemCount(); - // If a limit is set and reached + // If a limit is set and reached, say so but let the user decide. + // The limit records how many contacts the part is expected to + // carry; it is not a rule the drawing has to obey, and refusing + // the link obstructs drawing a schematic before the hardware has + // been chosen. if (max_slaves != -1 && current_slaves >= max_slaves) { - // Show a message box with the actual window as parent to ensure it's on top - QMessageBox::warning(this->window(), - tr("Nombre maximal d'esclaves atteint."), - tr("Cet élément maître ne peut plus accepter aucun nouveau contact esclave, la limite fixée a été atteinte (Limite: %1).").arg(max_slaves)); - return; + const auto answer = QMessageBox::warning( + this->window(), + tr("Nombre maximal d'esclaves atteint."), + tr("La limite fixée pour cet élément maître est atteinte (Limite: %1).\n\n" + "Voulez-vous tout de même lier ce contact esclave ?").arg(max_slaves), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::Yes); + if (answer != QMessageBox::Yes) { + return; + } } }