feat(production): modify
- 添加终止按钮 - 点击操作前进行提示 - 取放料的时候,除了写slot,也写行和列
This commit is contained in:
+115
-8
@@ -197,7 +197,7 @@ DashboardPage::DashboardPage(QWidget *parent)
|
||||
ui->buttonLayout->insertWidget(ui->buttonLayout->indexOf(ui->recoveryButton),
|
||||
markNgButton);
|
||||
stopButton->setObjectName("stopButton");
|
||||
stopButton->setVisible(false);
|
||||
stopButton->setVisible(true);
|
||||
ui->buttonLayout->insertWidget(6, stopButton);
|
||||
deviceStatusLabel->setStyleSheet("color: #546e7a;");
|
||||
ui->taskLayout->insertWidget(0, deviceStatusLabel);
|
||||
@@ -425,6 +425,7 @@ void DashboardPage::startProduction()
|
||||
if (recoveryBusy || visionRecoveryRequired) return;
|
||||
if (productionState == ProductionService::Paused) {
|
||||
if (!currentOrderResumable) return;
|
||||
if (!confirmControlOperation("继续订单", "安全检查通过后,从保存的动作边界继续此暂停订单。")) return;
|
||||
ui->startButton->setEnabled(false);
|
||||
QMetaObject::invokeMethod(productionWorker, "requestResume",
|
||||
Qt::QueuedConnection);
|
||||
@@ -442,6 +443,7 @@ void DashboardPage::startProduction()
|
||||
return;
|
||||
}
|
||||
|
||||
if (!confirmControlOperation("启动订单", "设备检查通过后,启动此订单并执行下述首件工件。")) return;
|
||||
ui->startButton->setEnabled(false);
|
||||
if (!QMetaObject::invokeMethod(
|
||||
productionWorker, "requestStart", Qt::QueuedConnection,
|
||||
@@ -454,26 +456,123 @@ void DashboardPage::startProduction()
|
||||
|
||||
void DashboardPage::pauseProduction()
|
||||
{
|
||||
if (!ui->pauseButton->isEnabled()
|
||||
|| !confirmControlOperation("暂停订单", "机器人当前独立动作完成及握手结束后暂停;未提交的视觉请求作废。")) return;
|
||||
QMetaObject::invokeMethod(productionWorker, "requestPause",
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void DashboardPage::stopProduction()
|
||||
{
|
||||
productionWorker->requestStopImmediate();
|
||||
if (!stopButton->isEnabled()
|
||||
|| !confirmControlOperation("终止订单", "将当前订单标记为已完成,保留实际加工数量及记录,剩余工件不再执行。此操作不是机器人急停。")) return;
|
||||
if (recoveryDialog) recoveryDialog->reject();
|
||||
QMetaObject::invokeMethod(productionWorker, "requestStop",
|
||||
Qt::QueuedConnection);
|
||||
QMetaObject::invokeMethod(productionWorker, "requestStopOrder",
|
||||
Qt::QueuedConnection, Q_ARG(int, currentOrderId));
|
||||
}
|
||||
|
||||
void DashboardPage::clearAlarm()
|
||||
{
|
||||
if (!ui->clearAlarmButton->isEnabled()
|
||||
|| !confirmControlOperation("清除报警", "向 PLC 写清报警命令;成功后清除 ssp 活动报警记录,不恢复生产。")) return;
|
||||
QMetaObject::invokeMethod(productionWorker, "requestClearAlarm",
|
||||
Qt::QueuedConnection);
|
||||
emit logRequested("报警日志", "控制面板", "清除报警",
|
||||
"已请求 PLC 清除报警", "待处理");
|
||||
}
|
||||
|
||||
QString DashboardPage::controlOperationContext(QString *identity) const
|
||||
{
|
||||
QString error;
|
||||
Order order;
|
||||
ProductionRunSnapshot run;
|
||||
if (currentOrderId > 0
|
||||
&& !OrderService::instance().findOrder(currentOrderId, &order, &error)) return QString();
|
||||
if (!ProductionRepository().findActiveRun(&run, &error)) return QString();
|
||||
if (run.id > 0 && run.orderId != currentOrderId) return QString();
|
||||
|
||||
Workpiece piece;
|
||||
if (run.currentWorkpieceId > 0) {
|
||||
if (!WorkpieceService::instance().findWorkpiece(run.currentWorkpieceId, &piece, &error)
|
||||
|| piece.orderId != currentOrderId) return QString();
|
||||
} else if (order.id > 0) {
|
||||
const QList<Workpiece> pieces = WorkpieceService::instance().listByOrder(order.id, &error);
|
||||
if (!error.isEmpty()) return QString();
|
||||
for (const Workpiece &candidate : pieces) {
|
||||
if (candidate.state == "PENDING") { piece = candidate; break; }
|
||||
}
|
||||
}
|
||||
int trayNo = 0;
|
||||
if (piece.trayId > 0) {
|
||||
const QList<Tray> trays = TrayService::instance().listTrays(&error);
|
||||
if (!error.isEmpty()) return QString();
|
||||
for (int i = 0; i < trays.size(); ++i) {
|
||||
if (trays.at(i).id == piece.trayId) { trayNo = i + 1; break; }
|
||||
}
|
||||
}
|
||||
QString step = piece.processStep;
|
||||
if (run.currentWorkpieceId <= 0 && piece.id > 0) step = "WAITING_DEVICE_READY";
|
||||
const QString position = piece.id > 0
|
||||
? QString("工件:%1\n料盘:%2,格位:%3(第 %4 行,第 %5 列)\n工序:%6")
|
||||
.arg(piece.barcode).arg(trayNo).arg(piece.trayPos)
|
||||
.arg((piece.trayPos - 1) / 7 + 1).arg((piece.trayPos - 1) % 7 + 1)
|
||||
.arg(displayProcessStep(step))
|
||||
: QString("工件:暂无当前或待加工工件");
|
||||
QString text = order.id > 0
|
||||
? QString("订单:%1\n订单状态:%2(%3暂停订单)\n%4")
|
||||
.arg(order.no, displayOrderStatus(order.status),
|
||||
order.status == "PAUSED" ? "是" : "不是", position)
|
||||
: QString("当前没有未完成订单");
|
||||
if (run.id > 0) {
|
||||
text += QString("\n生产状态:%1\n动作记录:%2 / %3\n记录的下一工序:%4")
|
||||
.arg(displayState(run.productionState), displayRecoveryAction(run.action.type),
|
||||
displayActionPhase(run.action.phase), displayProcessStep(run.action.nextStep));
|
||||
} else if (piece.id > 0) {
|
||||
text += "\n开始步骤:等待设备就绪 → 移动到拍照位置";
|
||||
}
|
||||
// Exclude elapsed time: only changes affecting the confirmed operation invalidate it.
|
||||
const QJsonObject snapshot{
|
||||
{"order", order.id}, {"status", order.status}, {"run", run.id},
|
||||
{"state", int(productionState)}, {"run_state", run.productionState},
|
||||
{"piece", piece.id}, {"tray", trayNo}, {"slot", piece.trayPos}, {"step", step},
|
||||
{"token", run.action.token}, {"attempt", run.action.attempt},
|
||||
{"version", run.action.version}, {"phase", run.action.phase},
|
||||
{"next", run.action.nextStep}, {"busy", recoveryBusy},
|
||||
{"vision_recovery", visionRecoveryRequired}};
|
||||
if (identity) *identity = QString::fromUtf8(QJsonDocument(snapshot).toJson(QJsonDocument::Compact));
|
||||
return text;
|
||||
}
|
||||
|
||||
bool DashboardPage::confirmControlOperation(const QString &title, const QString &effect)
|
||||
{
|
||||
if (controlConfirmationOpen) return false;
|
||||
QString identity;
|
||||
const QString context = controlOperationContext(&identity);
|
||||
if (context.isEmpty()) {
|
||||
QMessageBox::warning(this, title, "无法读取一致的订单和动作记录,请刷新状态后再操作。");
|
||||
return false;
|
||||
}
|
||||
controlConfirmationOpen = true;
|
||||
QMessageBox question(QMessageBox::Question, title,
|
||||
context + "\n\n" + effect + "\n\n是否执行本步操作?",
|
||||
QMessageBox::Yes | QMessageBox::No, this);
|
||||
question.setObjectName("controlConfirmation");
|
||||
question.setTextFormat(Qt::PlainText);
|
||||
question.button(QMessageBox::Yes)->setText("执行");
|
||||
question.button(QMessageBox::No)->setText("取消");
|
||||
question.setDefaultButton(QMessageBox::No);
|
||||
question.setEscapeButton(QMessageBox::No);
|
||||
const int answer = question.exec();
|
||||
controlConfirmationOpen = false;
|
||||
if (answer != QMessageBox::Yes) return false;
|
||||
QString currentIdentity;
|
||||
if (controlOperationContext(¤tIdentity).isEmpty() || currentIdentity != identity) {
|
||||
QMessageBox::information(this, title, "订单、工件或动作状态已经变化,本次操作未执行,请重新确认。");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void DashboardPage::onProductionStateChanged(ProductionService::State state,
|
||||
const QString &name)
|
||||
{
|
||||
@@ -569,6 +668,7 @@ void DashboardPage::onRecoveryCompleted(const QString &mode)
|
||||
void DashboardPage::recoverProduction()
|
||||
{
|
||||
if (recoveryBusy || !ui->recoveryButton->isEnabled()) return;
|
||||
if (!confirmControlOperation("恢复/重试", "先读取设备及动作记录,检查能否安全恢复;状态不明确时再由人工选择。本次确认不保证立即继续生产。")) return;
|
||||
onRecoveryBusyChanged(true);
|
||||
ui->actionLabel->setText("正在检查设备状态和动作记录...");
|
||||
if (!QMetaObject::invokeMethod(productionWorker, "requestRecover",
|
||||
@@ -736,13 +836,15 @@ void DashboardPage::updateRecoveryButtons()
|
||||
ui->recoveryButton->setVisible(true);
|
||||
ui->recoveryButton->setEnabled(recoveryRequired && !terminating && !recoveryBusy);
|
||||
ui->recoveryButton->setText(recoveryBusy ? "恢复检查中..." : "恢复/重试");
|
||||
ui->pauseButton->setEnabled(!recoveryBusy && !terminating);
|
||||
ui->pauseButton->setEnabled(running && !recoveryRequired
|
||||
&& state != ProductionService::Paused
|
||||
&& !recoveryBusy && !terminating);
|
||||
ui->clearAlarmButton->setEnabled(!recoveryBusy && !terminating);
|
||||
markNgButton->setVisible(recoveryRequired
|
||||
&& productionWorkpiece.id > 0 && !visionRecoveryRequired);
|
||||
markNgButton->setEnabled(!recoveryBusy && !terminating);
|
||||
stopButton->setVisible(running);
|
||||
stopButton->setEnabled(!terminating);
|
||||
stopButton->setVisible(true);
|
||||
stopButton->setEnabled(currentOrderId > 0 && !terminating);
|
||||
stopButton->setText(terminating ? "终止中..." : "终止");
|
||||
}
|
||||
|
||||
@@ -967,7 +1069,12 @@ void DashboardPage::loadCurrentOrder()
|
||||
{
|
||||
QString error;
|
||||
Order order;
|
||||
if (!OrderService::instance().findUnfinishedOrder(&order, &error)) {
|
||||
ProductionRunSnapshot run;
|
||||
const bool loaded = ProductionRepository().findActiveRun(&run, &error)
|
||||
&& (run.id > 0
|
||||
? OrderService::instance().findOrder(run.orderId, &order, &error)
|
||||
: OrderService::instance().findUnfinishedOrder(&order, &error));
|
||||
if (!loaded) {
|
||||
currentOrderId = 0;
|
||||
currentOrderStartable = false;
|
||||
currentOrderResumable = false;
|
||||
|
||||
Reference in New Issue
Block a user