From bc7f1c4e028e69be51079b59dae4ae5c4d43f5bb Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期六, 31 一月 2026 21:54:56 +0800
Subject: [PATCH] 1.状态指示图,目前灰色表示掉线,绿色表示在线。增加Slot的小点表示有没有料,及加工状态 。 2.增加图示
---
SourceCode/Bond/Servo/CEquipmentPage1.cpp | 229 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 228 insertions(+), 1 deletions(-)
diff --git a/SourceCode/Bond/Servo/CEquipmentPage1.cpp b/SourceCode/Bond/Servo/CEquipmentPage1.cpp
index a6a80f4..684c23b 100644
--- a/SourceCode/Bond/Servo/CEquipmentPage1.cpp
+++ b/SourceCode/Bond/Servo/CEquipmentPage1.cpp
@@ -9,12 +9,20 @@
// CEquipmentPage1 瀵硅瘽妗�
+#define SIGNAL_GRID_ROWS 8
+#define SIGNAL_GRID_COLS 8
+#define SIGNAL_GRID_SIZE (SIGNAL_GRID_ROWS * SIGNAL_GRID_COLS)
+
+#define TIMER_ID_SIGNAL_UPDATE 1001
+#define TIMER_INTERVAL_MS 1000 // 姣� 1 绉掓洿鏂颁竴娆�
+
IMPLEMENT_DYNAMIC(CEquipmentPage1, CHMPropertyPage)
CEquipmentPage1::CEquipmentPage1(CWnd* pParent /*=nullptr*/)
: CHMPropertyPage(IDD_PAGE_EQUIPMENT1, pParent)
{
m_pEquipment = nullptr;
+ m_nCurrentDeviceID = 0;
}
CEquipmentPage1::~CEquipmentPage1()
@@ -28,6 +36,10 @@
BEGIN_MESSAGE_MAP(CEquipmentPage1, CHMPropertyPage)
+ ON_WM_CTLCOLOR()
+ ON_WM_DESTROY()
+ ON_WM_SIZE()
+ ON_WM_TIMER()
END_MESSAGE_MAP()
@@ -35,12 +47,154 @@
void CEquipmentPage1::OnApply()
{
__super::OnApply();
- AfxMessageBox("CEquipmentPage1::OnApply()");
}
void CEquipmentPage1::setEquipment(SERVO::CEquipment* pEquipment)
{
m_pEquipment = pEquipment;
+
+ if (m_pEquipment != nullptr) {
+ InitSignalListForDevice(pEquipment->getID());
+ }
+ else {
+ ResetSignalPanel();
+ }
+}
+
+void CEquipmentPage1::LoadSignalListFromCSV(const CString& strFilePath)
+{
+ m_mapSignalListByID.clear();
+
+ CStdioFile file;
+ if (!file.Open(strFilePath, CFile::modeRead | CFile::typeText)) {
+ AfxMessageBox(_T("鏃犳硶鎵撳紑淇″彿瀹氫箟鏂囦欢: ") + strFilePath);
+ return;
+ }
+
+ CString strLine;
+ int nLineNum = 0;
+
+ while (file.ReadString(strLine)) {
+ ++nLineNum;
+ strLine.Trim();
+ if (strLine.IsEmpty() || strLine.Left(1) == _T("#") || strLine.Left(2) == _T("//")) {
+ continue; // 璺宠繃娉ㄩ噴琛屾垨绌鸿
+ }
+
+ // 鍒嗗壊涓� tokens
+ std::vector<CString> tokens;
+ int curPos = 0;
+ CString token = strLine.Tokenize(_T(","), curPos);
+ while (!token.IsEmpty()) {
+ token.Trim(); // 鍘婚櫎姣忎釜瀛楁鐨勭┖鏍�
+ tokens.push_back(token);
+ token = strLine.Tokenize(_T(","), curPos);
+ }
+
+ // 鏍煎紡妫�鏌�
+ if (tokens.size() < 3) {
+ TRACE(_T("CSV 鏍煎紡閿欒 [琛� %d]锛氬瓧娈垫暟涓嶈冻銆俓n"), nLineNum);
+ continue;
+ }
+
+ // 瑙f瀽瀛楁
+ int nDeviceID = _ttoi(tokens[0]);
+ CString strSignalName = tokens[1];
+ bool bClickable = _ttoi(tokens[2]) ? TRUE : FALSE;
+
+ if (nDeviceID <= 0 || nDeviceID > 999 || strSignalName.IsEmpty()) {
+ TRACE(_T("CSV 琛� %d锛氭棤鏁堣澶嘔D=%d 鎴栦俊鍙峰悕涓虹┖\n"), nLineNum, nDeviceID);
+ continue;
+ }
+
+ SignalInfo info = { strSignalName, false, bClickable };
+ m_mapSignalListByID[nDeviceID].push_back(info);
+ }
+
+ file.Close();
+ TRACE(_T("淇″彿瀹氫箟鍔犺浇瀹屾垚锛屽叡 %d 涓澶囥�俓n"), (int)m_mapSignalListByID.size());
+}
+
+void CEquipmentPage1::InitSignalListForDevice(int nDeviceID)
+{
+ m_nCurrentDeviceID = nDeviceID;
+ m_vSignalList.clear();
+
+ auto it = m_mapSignalListByID.find(nDeviceID);
+ if (it != m_mapSignalListByID.end()) {
+ m_vSignalList = it->second;
+ }
+ else {
+ TRACE(_T("Warning: No signals found for DeviceID=%d\n"), nDeviceID);
+ }
+
+ // 琛ラ綈鍒� 64 椤�
+ while (m_vSignalList.size() < SIGNAL_GRID_SIZE) {
+ m_vSignalList.push_back({ _T(""), false, false });
+ }
+
+ InitSignalSlotTextAndClickable();
+ UpdateAllSignalStatesFromDevice();
+}
+
+void CEquipmentPage1::UpdateSignalState(int nRow, int nCol, bool bNewState)
+{
+ if (!::IsWindow(m_ctrlSignalPanel.GetSafeHwnd())) {
+ return;
+ }
+
+ int nIndex = nRow * SIGNAL_GRID_COLS + nCol;
+ if (nIndex < 0 || nIndex >= static_cast<int>(m_vSignalList.size())) {
+ return;
+ }
+
+ if (m_vSignalList[nIndex].bCurrentState != bNewState) {
+ m_vSignalList[nIndex].bCurrentState = bNewState;
+ m_ctrlSignalPanel.SetSlotStatus(nRow, nCol, bNewState);
+
+ TRACE(_T("[Device %d] UpdateSignalState: [%d, %d] = %d\n"), m_nCurrentDeviceID, nRow, nCol, bNewState);
+ }
+}
+
+void CEquipmentPage1::InitSignalSlotTextAndClickable()
+{
+ if (!::IsWindow(m_ctrlSignalPanel.GetSafeHwnd())) {
+ return;
+ }
+
+ for (int i = 0; i < SIGNAL_GRID_SIZE; ++i) {
+ int nRow = i / SIGNAL_GRID_COLS;
+ int nCol = i % SIGNAL_GRID_COLS;
+
+ const auto& signal = m_vSignalList[i];
+ m_ctrlSignalPanel.SetSlotText(nRow, nCol, signal.strName);
+ m_ctrlSignalPanel.SetSlotClickable(nRow, nCol, signal.bClickable);
+ }
+}
+
+void CEquipmentPage1::UpdateAllSignalStatesFromDevice()
+{
+ if (!m_pEquipment) {
+ return;
+ }
+
+ for (int nRow = 0; nRow < SIGNAL_GRID_ROWS; ++nRow) {
+ for (int nCol = 0; nCol < SIGNAL_GRID_COLS; ++nCol) {
+ BOOL bCurrentState = m_pEquipment->isLinkSignalUpstreamOn(nRow, nCol);
+ UpdateSignalState(nRow, nCol, bCurrentState);
+ }
+ }
+}
+
+void CEquipmentPage1::ResetSignalPanel()
+{
+ if (!::IsWindow(m_ctrlSignalPanel.GetSafeHwnd())) {
+ return;
+ }
+
+ m_ctrlSignalPanel.ClearAll();
+ m_vSignalList.clear();
+ m_nCurrentDeviceID = 0;
}
BOOL CEquipmentPage1::OnInitDialog()
@@ -48,7 +202,80 @@
CHMPropertyPage::OnInitDialog();
// TODO: 鍦ㄦ娣诲姞棰濆鐨勫垵濮嬪寲
+ m_ctrlSignalPanel.Create(AfxRegisterWndClass(0), _T("SignalGrid"), WS_CHILD | WS_VISIBLE, CRect(0, 0, 100, 100), this, 1002);
+ m_ctrlSignalPanel.SetColors(RGB(0, 200, 0), RGB(220, 220, 220));
+ m_ctrlSignalPanel.SetGridSize(SIGNAL_GRID_ROWS, SIGNAL_GRID_COLS);
+ m_ctrlSignalPanel.SetTextFont(_T("Microsoft YaHei"), 10);
+ m_ctrlSignalPanel.SetSlotClickCallback([this](int nRow, int nCol) {
+ int index = nRow * SIGNAL_GRID_COLS + nCol;
+ if (index >= 0 && index < (int)m_vSignalList.size() && m_vSignalList[index].bClickable && m_pEquipment != nullptr) {
+ // 璇诲彇褰撳墠鐘舵�佸苟鍒囨崲
+ const BOOL bCurrentState = m_pEquipment->isLinkSignalUpstreamOn(nRow, nCol);
+ m_pEquipment->setLinkSignalUpstream(nRow, nCol, !bCurrentState);
+ }
+ });
+
+ {
+ TCHAR szPath[MAX_PATH] = {};
+ GetModuleFileName(nullptr, szPath, MAX_PATH);
+ PathRemoveFileSpec(szPath);
+ CString strCSVFile = CString(szPath) + _T("\\Config\\signals.csv");
+ LoadSignalListFromCSV(strCSVFile);
+ }
+
+ // 濡傛灉璁惧宸茶缃紝鍒欏垵濮嬪寲淇″彿鍒楄〃
+ if (m_pEquipment != nullptr) {
+ InitSignalListForDevice(m_pEquipment->getID());
+ }
+
+ KillTimer(TIMER_ID_SIGNAL_UPDATE);
+ SetTimer(TIMER_ID_SIGNAL_UPDATE, TIMER_INTERVAL_MS, nullptr);
return TRUE; // return TRUE unless you set the focus to a control
// 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
}
+
+HBRUSH CEquipmentPage1::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
+{
+ HBRUSH hbr = CHMPropertyPage::OnCtlColor(pDC, pWnd, nCtlColor);
+
+ // TODO: 鍦ㄦ鏇存敼 DC 鐨勪换浣曠壒鎬�
+
+ // TODO: 濡傛灉榛樿鐨勪笉鏄墍闇�鐢荤瑪锛屽垯杩斿洖鍙︿竴涓敾绗�
+ return hbr;
+}
+
+void CEquipmentPage1::OnDestroy()
+{
+ CHMPropertyPage::OnDestroy();
+
+ // TODO: 鍦ㄦ澶勬坊鍔犳秷鎭鐞嗙▼搴忎唬鐮�
+ KillTimer(TIMER_ID_SIGNAL_UPDATE);
+ if (::IsWindow(m_ctrlSignalPanel.GetSafeHwnd())) {
+ m_ctrlSignalPanel.DestroyWindow();
+ }
+}
+
+void CEquipmentPage1::OnSize(UINT nType, int cx, int cy)
+{
+ CHMPropertyPage::OnSize(nType, cx, cy);
+
+ // TODO: 鍦ㄦ澶勬坊鍔犳秷鎭鐞嗙▼搴忎唬鐮�
+ if (::IsWindow(m_ctrlSignalPanel.GetSafeHwnd())) {
+ CRect rc;
+ GetClientRect(&rc);
+ rc.DeflateRect(10, 10);
+ m_ctrlSignalPanel.MoveWindow(rc);
+ }
+}
+
+void CEquipmentPage1::OnTimer(UINT_PTR nIDEvent)
+{
+ if (nIDEvent == TIMER_ID_SIGNAL_UPDATE) {
+ if (m_pEquipment && !m_vSignalList.empty()) {
+ UpdateAllSignalStatesFromDevice();
+ }
+ }
+
+ CHMPropertyPage::OnTimer(nIDEvent);
+}
\ No newline at end of file
--
Gitblit v1.9.3