|
|
|
@@ -311,6 +311,12 @@ DashboardPage::DashboardPage(QWidget *parent)
|
|
|
|
|
this, &DashboardPage::onRecoveryDecisionRequired);
|
|
|
|
|
connect(productionWorker, &ProductionWorker::recoveryBusyChanged,
|
|
|
|
|
this, &DashboardPage::onRecoveryBusyChanged);
|
|
|
|
|
connect(productionWorker, &ProductionWorker::resetContextReady,
|
|
|
|
|
this, &DashboardPage::onResetContextReady);
|
|
|
|
|
connect(productionWorker, &ProductionWorker::alarmOperationBusyChanged,
|
|
|
|
|
this, &DashboardPage::onAlarmOperationBusyChanged);
|
|
|
|
|
connect(productionWorker, &ProductionWorker::alarmOperationFinished,
|
|
|
|
|
this, &DashboardPage::onAlarmOperationFinished);
|
|
|
|
|
connect(this, &DashboardPage::recoveryDecisionSubmitted,
|
|
|
|
|
productionWorker, &ProductionWorker::requestRecoveryDecision,
|
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
@@ -338,6 +344,8 @@ DashboardPage::DashboardPage(QWidget *parent)
|
|
|
|
|
|
|
|
|
|
DashboardPage::~DashboardPage()
|
|
|
|
|
{
|
|
|
|
|
closing = true;
|
|
|
|
|
if (alarmDialog) alarmDialog->reject();
|
|
|
|
|
recoveryBusy = false;
|
|
|
|
|
if (recoveryDialog) recoveryDialog->reject();
|
|
|
|
|
if (productionThread->isRunning()) {
|
|
|
|
@@ -426,6 +434,7 @@ void DashboardPage::updateRackSize()
|
|
|
|
|
|
|
|
|
|
void DashboardPage::startProduction()
|
|
|
|
|
{
|
|
|
|
|
if (!ui->startButton->isEnabled()) return;
|
|
|
|
|
if (!productionSnapshot.initialized) return;
|
|
|
|
|
if (recoveryBusy || visionRecoveryRequired) return;
|
|
|
|
|
if (productionState == ProductionService::Paused) {
|
|
|
|
@@ -484,12 +493,140 @@ void DashboardPage::stopProduction()
|
|
|
|
|
|
|
|
|
|
void DashboardPage::clearAlarm()
|
|
|
|
|
{
|
|
|
|
|
if (!ui->clearAlarmButton->isEnabled()
|
|
|
|
|
|| !confirmControlOperation("清除报警", "向 PLC 写清报警命令;成功后清除 ssp 活动报警记录,不恢复生产。")) return;
|
|
|
|
|
QMetaObject::invokeMethod(productionWorker, "requestClearAlarm",
|
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
|
emit logRequested("报警日志", "控制面板", "清除报警",
|
|
|
|
|
"已请求 PLC 清除报警", "待处理");
|
|
|
|
|
if (closing || controlConfirmationOpen || !ui->clearAlarmButton->isEnabled()) return;
|
|
|
|
|
alarmContextPending = true;
|
|
|
|
|
updateRecoveryButtons();
|
|
|
|
|
if (!QMetaObject::invokeMethod(productionWorker, "requestResetContext", Qt::QueuedConnection)) {
|
|
|
|
|
QJsonObject context;
|
|
|
|
|
context.insert("valid", false);
|
|
|
|
|
context.insert("error", "提交复位目标查询失败");
|
|
|
|
|
onResetContextReady(context);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DashboardPage::onResetContextReady(const QJsonObject &context)
|
|
|
|
|
{
|
|
|
|
|
if (closing || !alarmContextPending) return;
|
|
|
|
|
alarmContextPending = false;
|
|
|
|
|
QDialog *dialog = new QDialog(this);
|
|
|
|
|
alarmDialog = dialog;
|
|
|
|
|
dialog->setObjectName("clearAlarmResetDialog");
|
|
|
|
|
dialog->setWindowTitle("清除报警");
|
|
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
|
dialog->setWindowModality(Qt::WindowModal);
|
|
|
|
|
dialog->setMinimumWidth(560);
|
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout(dialog);
|
|
|
|
|
const bool valid = context.value("valid").toBool();
|
|
|
|
|
QString target;
|
|
|
|
|
if (!valid) {
|
|
|
|
|
target = "无法核实旧任务,暂不能复位;仍可仅清除报警。\n原因:"
|
|
|
|
|
+ context.value("error").toString();
|
|
|
|
|
} else if (context.value("run_id").toInt() > 0) {
|
|
|
|
|
target = QString("将结束的旧任务:订单 %1(ID %2),运行 %3")
|
|
|
|
|
.arg(context.value("order_no").toString())
|
|
|
|
|
.arg(context.value("order_id").toInt())
|
|
|
|
|
.arg(context.value("run_id").toInt());
|
|
|
|
|
} else {
|
|
|
|
|
target = "没有活动旧任务:仅清理遗留状态,不删除订单。";
|
|
|
|
|
}
|
|
|
|
|
if (!context.value("preserved_order_no").toString().isEmpty())
|
|
|
|
|
target += "\n保留的未开始订单:" + context.value("preserved_order_no").toString();
|
|
|
|
|
QLabel *details = new QLabel(target + "\n\n是否同时复位自动线?\n"
|
|
|
|
|
"复位将结束旧生产任务、清除遗留动作及视觉状态,回到待机。"
|
|
|
|
|
"不会继续旧订单,也不会自动启动新订单。\n"
|
|
|
|
|
"旧任务无测量记录:删除旧订单、关联工件及动作/运行记录,释放其料位。\n"
|
|
|
|
|
"旧任务已有测量记录:结束旧任务,保留订单和历史数据。\n"
|
|
|
|
|
"新建未开始订单、正常完成订单均保留。\n"
|
|
|
|
|
"软件复位不代替机器人急停或回原点。", dialog);
|
|
|
|
|
details->setTextFormat(Qt::PlainText);
|
|
|
|
|
details->setWordWrap(true);
|
|
|
|
|
details->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
|
|
|
|
layout->addWidget(details);
|
|
|
|
|
QCheckBox *confirmed = new QCheckBox("已确认机器人停止,现场位置允许结束旧任务", dialog);
|
|
|
|
|
confirmed->setObjectName("resetFieldConfirmed");
|
|
|
|
|
confirmed->setEnabled(valid);
|
|
|
|
|
layout->addWidget(confirmed);
|
|
|
|
|
QDialogButtonBox *buttons = new QDialogButtonBox(dialog);
|
|
|
|
|
QPushButton *reset = buttons->addButton("是,清警并复位", QDialogButtonBox::YesRole);
|
|
|
|
|
QPushButton *clear = buttons->addButton("否,仅清除报警", QDialogButtonBox::NoRole);
|
|
|
|
|
QPushButton *cancel = buttons->addButton("取消", QDialogButtonBox::RejectRole);
|
|
|
|
|
reset->setObjectName("resetProductionButton");
|
|
|
|
|
clear->setObjectName("clearAlarmOnlyButton");
|
|
|
|
|
cancel->setObjectName("cancelClearAlarmButton");
|
|
|
|
|
reset->setEnabled(false);
|
|
|
|
|
reset->setAutoDefault(false);
|
|
|
|
|
cancel->setAutoDefault(false);
|
|
|
|
|
clear->setDefault(true);
|
|
|
|
|
layout->addWidget(buttons);
|
|
|
|
|
connect(confirmed, &QCheckBox::toggled, dialog, [reset, valid](bool checked) {
|
|
|
|
|
reset->setEnabled(valid && checked);
|
|
|
|
|
});
|
|
|
|
|
connect(reset, &QPushButton::clicked, dialog, [dialog]() { dialog->done(2); });
|
|
|
|
|
connect(clear, &QPushButton::clicked, dialog, &QDialog::accept);
|
|
|
|
|
connect(cancel, &QPushButton::clicked, dialog, &QDialog::reject);
|
|
|
|
|
connect(dialog, &QDialog::finished, this,
|
|
|
|
|
[this, context, confirmed](int result) {
|
|
|
|
|
alarmDialog = nullptr;
|
|
|
|
|
if (closing) return;
|
|
|
|
|
const bool resetRequested = result == 2;
|
|
|
|
|
if (result != QDialog::Accepted && !resetRequested) {
|
|
|
|
|
updateRecoveryButtons();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (resetRequested && (!context.value("valid").toBool() || !confirmed->isChecked())) {
|
|
|
|
|
updateRecoveryButtons();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
alarmRequestPending = true;
|
|
|
|
|
if (resetRequested) {
|
|
|
|
|
recoveryBusy = false;
|
|
|
|
|
if (recoveryDialog) recoveryDialog->reject();
|
|
|
|
|
}
|
|
|
|
|
updateRecoveryButtons();
|
|
|
|
|
ui->actionLabel->setText(resetRequested ? "正在清警并复位..." : "正在清除报警...");
|
|
|
|
|
QJsonObject request = context;
|
|
|
|
|
request.insert("field_confirmed", confirmed->isChecked());
|
|
|
|
|
const bool submitted = resetRequested
|
|
|
|
|
? QMetaObject::invokeMethod(productionWorker, "requestReset", Qt::QueuedConnection,
|
|
|
|
|
Q_ARG(QJsonObject, request))
|
|
|
|
|
: QMetaObject::invokeMethod(productionWorker, "requestClearAlarm", Qt::QueuedConnection);
|
|
|
|
|
if (!submitted)
|
|
|
|
|
onAlarmOperationFinished(resetRequested, false, "提交清警/复位请求失败");
|
|
|
|
|
});
|
|
|
|
|
updateRecoveryButtons();
|
|
|
|
|
dialog->open();
|
|
|
|
|
clear->setFocus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DashboardPage::onAlarmOperationBusyChanged(bool busy)
|
|
|
|
|
{
|
|
|
|
|
if (closing) return;
|
|
|
|
|
alarmOperationBusy = busy;
|
|
|
|
|
updateRecoveryButtons();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DashboardPage::onAlarmOperationFinished(bool resetRequested, bool success,
|
|
|
|
|
const QString &message)
|
|
|
|
|
{
|
|
|
|
|
if (closing) return;
|
|
|
|
|
alarmRequestPending = false;
|
|
|
|
|
alarmOperationBusy = false;
|
|
|
|
|
if (resetRequested && success) {
|
|
|
|
|
loadCurrentOrder();
|
|
|
|
|
refreshProcessRecords();
|
|
|
|
|
updateProductionStats();
|
|
|
|
|
updateRackSummary();
|
|
|
|
|
emit productionDataChanged();
|
|
|
|
|
}
|
|
|
|
|
updateRecoveryButtons();
|
|
|
|
|
ui->actionLabel->setText(message);
|
|
|
|
|
emit logRequested("报警日志", "控制面板", resetRequested ? "清警并复位" : "清除报警",
|
|
|
|
|
message, success ? "成功" : "失败");
|
|
|
|
|
QMessageBox *result = new QMessageBox(success ? QMessageBox::Information : QMessageBox::Warning,
|
|
|
|
|
resetRequested ? "清警并复位" : "清除报警", message, QMessageBox::Ok, this);
|
|
|
|
|
result->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
|
result->setTextFormat(Qt::PlainText);
|
|
|
|
|
result->open();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString DashboardPage::controlOperationContext(QString *identity) const
|
|
|
|
@@ -561,7 +698,8 @@ QString DashboardPage::controlOperationContext(QString *identity) const
|
|
|
|
|
|
|
|
|
|
bool DashboardPage::confirmControlOperation(const QString &title, const QString &effect)
|
|
|
|
|
{
|
|
|
|
|
if (controlConfirmationOpen) return false;
|
|
|
|
|
if (controlConfirmationOpen || alarmContextPending || alarmDialog
|
|
|
|
|
|| alarmRequestPending || alarmOperationBusy || productionSnapshot.resetInProgress) return false;
|
|
|
|
|
QString identity;
|
|
|
|
|
const QString context = controlOperationContext(&identity);
|
|
|
|
|
if (context.isEmpty()) {
|
|
|
|
@@ -696,7 +834,7 @@ void DashboardPage::onRecoveryCompleted(const QString &mode)
|
|
|
|
|
|
|
|
|
|
void DashboardPage::recoverProduction()
|
|
|
|
|
{
|
|
|
|
|
if (recoveryBusy || !ui->recoveryButton->isEnabled()) return;
|
|
|
|
|
if (recoveryBusy || productionSnapshot.resetRequired || !ui->recoveryButton->isEnabled()) return;
|
|
|
|
|
if (!productionSnapshot.initialized) {
|
|
|
|
|
onRecoveryBusyChanged(true);
|
|
|
|
|
QMetaObject::invokeMethod(productionWorker, "requestRestore", Qt::QueuedConnection);
|
|
|
|
@@ -721,14 +859,15 @@ void DashboardPage::onRecoveryBusyChanged(bool busy)
|
|
|
|
|
|
|
|
|
|
void DashboardPage::onRecoveryDecisionRequired(const QJsonObject &context)
|
|
|
|
|
{
|
|
|
|
|
if (!recoveryBusy || recoveryDialog) return;
|
|
|
|
|
if (closing || !recoveryBusy || recoveryDialog
|
|
|
|
|
|| productionSnapshot.resetInProgress) return;
|
|
|
|
|
|
|
|
|
|
QDialog *dialog = new QDialog(this);
|
|
|
|
|
recoveryDialog = dialog;
|
|
|
|
|
dialog->setObjectName("recoveryDecisionDialog");
|
|
|
|
|
dialog->setWindowTitle("恢复/重试 · 人工核对");
|
|
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
|
dialog->setWindowModality(Qt::WindowModal);
|
|
|
|
|
dialog->setWindowModality(Qt::NonModal);
|
|
|
|
|
dialog->setMinimumWidth(520);
|
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout(dialog);
|
|
|
|
|
const auto signalText = [](const QJsonValue &value) {
|
|
|
|
@@ -822,7 +961,7 @@ void DashboardPage::onRecoveryDecisionRequired(const QJsonObject &context)
|
|
|
|
|
connect(dialog, &QDialog::finished, this,
|
|
|
|
|
[this, context, choice, operatorName, note, confirmed](int result) {
|
|
|
|
|
recoveryDialog = nullptr;
|
|
|
|
|
if (!recoveryBusy) return;
|
|
|
|
|
if (closing || !recoveryBusy) return;
|
|
|
|
|
QJsonObject decision = context;
|
|
|
|
|
decision.insert("decision", result == QDialog::Accepted
|
|
|
|
|
? choice->currentData().toString() : QString("CANCEL"));
|
|
|
|
@@ -832,11 +971,13 @@ void DashboardPage::onRecoveryDecisionRequired(const QJsonObject &context)
|
|
|
|
|
emit recoveryDecisionSubmitted(decision);
|
|
|
|
|
});
|
|
|
|
|
cancel->setFocus();
|
|
|
|
|
dialog->open();
|
|
|
|
|
dialog->show();
|
|
|
|
|
updateRecoveryButtons();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DashboardPage::markWorkpieceNg()
|
|
|
|
|
{
|
|
|
|
|
if (!markNgButton->isEnabled()) return;
|
|
|
|
|
if (QMessageBox::question(
|
|
|
|
|
this, "标记工件 NG",
|
|
|
|
|
"确认将当前工件标记为 NG,并继续处理下一个工件吗?",
|
|
|
|
@@ -851,13 +992,18 @@ void DashboardPage::markWorkpieceNg()
|
|
|
|
|
|
|
|
|
|
void DashboardPage::updateRecoveryButtons()
|
|
|
|
|
{
|
|
|
|
|
const bool alarmBlocked = closing || alarmContextPending || alarmDialog
|
|
|
|
|
|| alarmRequestPending || alarmOperationBusy || productionSnapshot.resetInProgress;
|
|
|
|
|
if (recoveryDialog) recoveryDialog->setEnabled(!alarmBlocked);
|
|
|
|
|
const bool terminating = productionState == ProductionService::Terminating;
|
|
|
|
|
if (!productionSnapshot.initialized) {
|
|
|
|
|
ui->startButton->setEnabled(false);
|
|
|
|
|
ui->pauseButton->setEnabled(false);
|
|
|
|
|
stopButton->setEnabled(false);
|
|
|
|
|
ui->clearAlarmButton->setEnabled(false);
|
|
|
|
|
ui->clearAlarmButton->setEnabled(!alarmBlocked && !terminating);
|
|
|
|
|
markNgButton->setEnabled(false);
|
|
|
|
|
ui->recoveryButton->setEnabled(!productionSnapshot.error.isEmpty() && !recoveryBusy);
|
|
|
|
|
ui->recoveryButton->setEnabled(!productionSnapshot.error.isEmpty() && !recoveryBusy
|
|
|
|
|
&& !alarmBlocked && !productionSnapshot.resetRequired);
|
|
|
|
|
ui->recoveryButton->setText("重新检查生产状态");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@@ -867,34 +1013,33 @@ void DashboardPage::updateRecoveryButtons()
|
|
|
|
|
|| state == ProductionService::Error || visionRecoveryRequired;
|
|
|
|
|
const bool running = state != ProductionService::Idle
|
|
|
|
|
&& state != ProductionService::Completed;
|
|
|
|
|
const bool terminating = state == ProductionService::Terminating;
|
|
|
|
|
const bool canStart = (((state == ProductionService::Idle
|
|
|
|
|
|| state == ProductionService::Completed)
|
|
|
|
|
&& currentOrderStartable)
|
|
|
|
|
|| (state == ProductionService::Paused
|
|
|
|
|
&& currentOrderResumable))
|
|
|
|
|
&& !visionRecoveryRequired && !recoveryBusy;
|
|
|
|
|
&& !visionRecoveryRequired && !recoveryBusy && !alarmBlocked;
|
|
|
|
|
ui->startButton->setEnabled(canStart);
|
|
|
|
|
ui->startButton->setToolTip(visionRecoveryRequired
|
|
|
|
|
? "上次视觉任务尚未清理,请先解除视觉遗留锁或恢复/终止当前任务" : QString());
|
|
|
|
|
ui->startButton->setText(state == ProductionService::Paused
|
|
|
|
|
? "继续" : "启动");
|
|
|
|
|
ui->recoveryButton->setVisible(true);
|
|
|
|
|
ui->recoveryButton->setEnabled(recoveryRequired && !terminating && !recoveryBusy
|
|
|
|
|
&& !productionSnapshot.terminationRequired);
|
|
|
|
|
ui->recoveryButton->setEnabled(recoveryRequired && !terminating && !recoveryBusy && !alarmBlocked
|
|
|
|
|
&& !productionSnapshot.terminationRequired && !productionSnapshot.resetRequired);
|
|
|
|
|
ui->recoveryButton->setText(recoveryBusy ? "恢复检查中..."
|
|
|
|
|
: state == ProductionService::Idle && visionRecoveryRequired
|
|
|
|
|
? "解除视觉遗留锁" : "恢复/重试");
|
|
|
|
|
ui->pauseButton->setEnabled(running && !recoveryRequired
|
|
|
|
|
&& state != ProductionService::Paused
|
|
|
|
|
&& !recoveryBusy && !terminating);
|
|
|
|
|
ui->clearAlarmButton->setEnabled(!recoveryBusy && !terminating);
|
|
|
|
|
&& !recoveryBusy && !terminating && !alarmBlocked);
|
|
|
|
|
ui->clearAlarmButton->setEnabled(!terminating && !alarmBlocked);
|
|
|
|
|
markNgButton->setVisible(recoveryRequired
|
|
|
|
|
&& productionWorkpiece.id > 0 && !visionRecoveryRequired);
|
|
|
|
|
markNgButton->setEnabled(!recoveryBusy && !terminating
|
|
|
|
|
markNgButton->setEnabled(!recoveryBusy && !terminating && !alarmBlocked
|
|
|
|
|
&& !productionSnapshot.terminationRequired);
|
|
|
|
|
stopButton->setVisible(true);
|
|
|
|
|
stopButton->setEnabled(currentOrderId > 0 && !terminating);
|
|
|
|
|
stopButton->setEnabled(currentOrderId > 0 && !terminating && !alarmBlocked);
|
|
|
|
|
stopButton->setText(terminating ? "终止中..." : "终止");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|