fix(Tray): 托盘传感器显示修改

This commit is contained in:
lidg
2026-11-09 18:16:54 +08:00
parent a8b2b31ce7
commit c248954b87
14 changed files with 170 additions and 51 deletions
+15 -4
View File
@@ -1152,6 +1152,7 @@ void DashboardPage::updateCurrentProcessDuration(int elapsedMs)
void DashboardPage::onDeviceStatusChanged(const DeviceStatus &status)
{
deviceStatus = status;
emit deviceStatusChanged(status);
const bool offline = !status.statusValid || !status.plcConnected;
const QString plcText = offline ? "离线"
@@ -1254,14 +1255,24 @@ void DashboardPage::updateRackSummary()
}
const Tray &tray = trays.at(index);
const QString status = tray.present ? tray.status : "离位";
const bool sensorAvailable = deviceStatus.statusValid
&& deviceStatus.plcConnected;
const bool present = !sensorAvailable || deviceStatus.trayPresent[index];
if (!present) {
updateStatusCell(cell,
QString("托盘 %1\n不在位:0/49").arg(index + 1),
"#90a4ae",
highlightedTrayIds.contains(tray.id));
continue;
}
const QString status = tray.status;
const QString statusText = status == "OK" ? "已完成"
: status == "NG" ? "有 NG"
: status == "PROCESSING" ? "加工中"
: status == "PENDING" ? "待检测"
: tray.present ? "在位" : "离位";
const QString color = !tray.present ? "#90a4ae"
: status == "NG" ? "#d32f2f"
: "有托盘";
const QString color = status == "NG" ? "#d32f2f"
: status == "PROCESSING" ? "#1e88e5"
: status == "OK" ? "#2e7d32" : "#78909c";
updateStatusCell(cell,
+1
View File
@@ -113,6 +113,7 @@ private:
int currentOrderId;
bool currentOrderStartable;
bool currentOrderResumable;
DeviceStatus deviceStatus;
Workpiece productionWorkpiece;
int productionTrayNo;
int productionSlotNo;
+27 -2
View File
@@ -4,6 +4,7 @@
#include "squaretraybutton.h"
#include "uihelpers.h"
#include "../services/deviceservice.h"
#include "../services/trayservice.h"
#include <QAbstractButton>
@@ -14,6 +15,19 @@
#include <QSizePolicy>
#include <QtGlobal>
namespace {
QString displayTrayStatus(const QString &status)
{
if (status == "OK") return "已完成";
if (status == "NG") return "有 NG";
if (status == "PROCESSING") return "加工中";
if (status == "PENDING") return "待检测";
return "有托盘";
}
}
RackPage::RackPage(QWidget *parent)
: QWidget(parent)
, ui(new Ui::RackPage)
@@ -106,6 +120,15 @@ void RackPage::refresh()
loadTrays();
}
void RackPage::updateDeviceStatus(const DeviceStatus &status)
{
trayPresenceAvailable = status.statusValid && status.plcConnected;
for (int index = 0; index < 6; ++index) {
trayPresent[index] = status.trayPresent[index];
}
updateTrayButtons();
}
void RackPage::loadTrays()
{
QString error;
@@ -148,15 +171,17 @@ void RackPage::updateTrayButtons()
for (int index = 0; index < rackTrayButtons.size(); ++index) {
SquareTrayButton *button = rackTrayButtons.at(index);
if (index >= trays.size()) {
button->setTrayInfo(0, QString(), 0, "无数据", false);
button->setTrayInfo(0, QString(), 0, "无数据", false, true);
button->setPlanned(false);
button->setChecked(false);
continue;
}
const Tray &tray = trays.at(index);
const bool sensorPresent = !trayPresenceAvailable || trayPresent[index];
button->setTrayInfo(tray.id, tray.code, tray.loadedCount,
tray.status, tray.present);
displayTrayStatus(tray.status), tray.present,
sensorPresent);
bool planned = false;
QString error;
const QList<TraySlot> traySlots =
+4
View File
@@ -11,6 +11,7 @@ class QLabel;
class QButtonGroup;
class QResizeEvent;
class SquareTrayButton;
struct DeviceStatus;
namespace Ui { class RackPage; }
@@ -24,6 +25,7 @@ public:
public slots:
void refresh();
void updateDeviceStatus(const DeviceStatus &status);
signals:
void logRequested(const QString &type, const QString &module, const QString &action,
@@ -48,6 +50,8 @@ private:
QList<Tray> trays;
int selectedTrayId;
int selectedTrayIndex;
bool trayPresenceAvailable = false;
bool trayPresent[6] = {};
};
#endif // RACKPAGE_H
+15 -10
View File
@@ -7,6 +7,7 @@ SquareTrayButton::SquareTrayButton(int trayIndex, int loadedCount, QWidget *pare
: QAbstractButton(parent)
, m_trayId(0)
, m_planned(false)
, m_sensorPresent(true)
{
setCheckable(true);
setCursor(Qt::PointingHandCursor);
@@ -14,16 +15,17 @@ SquareTrayButton::SquareTrayButton(int trayIndex, int loadedCount, QWidget *pare
}
void SquareTrayButton::setTrayInfo(int trayId, const QString &code, int loadedCount,
const QString &status, bool present)
const QString &status, bool databasePresent,
bool sensorPresent)
{
m_trayId = trayId;
m_sensorPresent = sensorPresent;
const QString displayCode = code.isEmpty() ? QString("托盘 %1").arg(trayId) : code;
const QString displayStatus = present ? status : "离位";
setText(QString("%1\n7 x 7\n%2 %3/49")
.arg(displayCode)
.arg(displayStatus)
.arg(loadedCount));
setEnabled(present);
setText(sensorPresent
? QString("%1\n7 x 7\n%2:%3/49")
.arg(displayCode).arg(status).arg(loadedCount)
: QString("%1\n7 x 7\n不在位:0/49").arg(displayCode));
setEnabled(databasePresent);
update();
}
@@ -51,11 +53,14 @@ void SquareTrayButton::paintEvent(QPaintEvent *event)
painter.setRenderHint(QPainter::Antialiasing, true);
const QRectF rect = QRectF(1, 1, width() - 2, height() - 2);
const QColor background = isChecked() ? QColor("#00897b")
const QColor background = !m_sensorPresent ? QColor("#90a4ae")
: isChecked() ? QColor("#00897b")
: m_planned ? QColor("#f9a825") : QColor("#eceff1");
const QColor border = isChecked() ? QColor("#004d40")
const QColor border = !m_sensorPresent ? QColor("#78909c")
: isChecked() ? QColor("#004d40")
: m_planned ? QColor("#ef6c00") : QColor("#b0bec5");
const QColor textColor = isChecked() ? QColor("#ffffff") : QColor("#263238");
const QColor textColor = !m_sensorPresent || isChecked()
? QColor("#ffffff") : QColor("#263238");
painter.setPen(QPen(border, 2));
painter.setBrush(background);
+3 -1
View File
@@ -9,7 +9,8 @@ public:
explicit SquareTrayButton(int trayIndex, int loadedCount, QWidget *parent = nullptr);
void setTrayInfo(int trayId, const QString &code, int loadedCount,
const QString &status, bool present);
const QString &status, bool databasePresent,
bool sensorPresent);
void setPlanned(bool planned);
QSize sizeHint() const override;
@@ -21,6 +22,7 @@ protected:
private:
int m_trayId;
bool m_planned;
bool m_sensorPresent;
};
#endif // SQUARETRAYBUTTON_H