From 526a56428d2111aef216cfca5bc63c806048a0e6 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期一, 13 一月 2025 16:54:42 +0800
Subject: [PATCH] 1.PLC连接状态在最左侧树控件中的小圆点展示; 2.当前PLC名称修改为CPLC指针;
---
SourceCode/Bond/BoounionPLC/BoounionPLC.cpp | 8 ++++++++
SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp | 3 +++
SourceCode/Bond/BoounionPLC/Model.cpp | 16 ++++------------
SourceCode/Bond/BoounionPLC/Common.h | 7 +++++++
SourceCode/Bond/BoounionPLC/Model.h | 2 +-
SourceCode/Bond/BoounionPLC/BoounionPLC.h | 1 +
SourceCode/Bond/BoounionPLC/PagePlcList.cpp | 16 ++++++++++++++++
7 files changed, 40 insertions(+), 13 deletions(-)
diff --git a/SourceCode/Bond/BoounionPLC/BoounionPLC.cpp b/SourceCode/Bond/BoounionPLC/BoounionPLC.cpp
index 3f49216..1ceaee6 100644
--- a/SourceCode/Bond/BoounionPLC/BoounionPLC.cpp
+++ b/SourceCode/Bond/BoounionPLC/BoounionPLC.cpp
@@ -136,6 +136,11 @@
m_model.setWorkDir((LPTSTR)(LPCTSTR)m_strAppDir);
+ // gdi+
+ Gdiplus::GdiplusStartupInput gdiplusStartupInput;
+ Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
+
+
CString strIniFile;
strIniFile.Format(_T("%s\\BoounionPLCconfiguration.ini"), (LPTSTR)(LPCTSTR)m_strAppDir);
int plcTimeout = GetPrivateProfileInt("PLC", "Timeout", 700, strIniFile);
@@ -192,6 +197,9 @@
int CBoounionPLCApp::ExitInstance()
{
+ // gdi+
+ Gdiplus::GdiplusShutdown(m_gdiplusToken);
+
m_model.term();
RX_Term();
MCL_Term();
diff --git a/SourceCode/Bond/BoounionPLC/BoounionPLC.h b/SourceCode/Bond/BoounionPLC/BoounionPLC.h
index 94ff2c0..42ad356 100644
--- a/SourceCode/Bond/BoounionPLC/BoounionPLC.h
+++ b/SourceCode/Bond/BoounionPLC/BoounionPLC.h
@@ -28,6 +28,7 @@
CString m_strAppFile;
int m_nVersionNumber;
CString m_strVersionName;
+ ULONG_PTR m_gdiplusToken;
// 重写
public:
diff --git a/SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp b/SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp
index 70c30d3..b5276ea 100644
--- a/SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp
+++ b/SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp
@@ -140,6 +140,9 @@
theApp.m_model.setCurrentPlc(pPlc);
}
}
+ else if (RX_PLC_STATE_CHANGED == code) {
+
+ }
else if (code == RX_CODE_ALARM_ON) {
CPLC* pPlc;
if (pAny->getPtrValue("ptr", (void*&)pPlc) && pPlc == theApp.m_model.getCurrentPlc()) {
diff --git a/SourceCode/Bond/BoounionPLC/Common.h b/SourceCode/Bond/BoounionPLC/Common.h
index dedacdb..2942408 100644
--- a/SourceCode/Bond/BoounionPLC/Common.h
+++ b/SourceCode/Bond/BoounionPLC/Common.h
@@ -20,6 +20,7 @@
#define RX_CODE_TACT_TIME 1014 // 节拍时间
#define RX_CODE_DAY_SHIFT_CAPACTITY 1015 // 白班产量
#define RX_CODE_NIGHT_SHIFT_CAPACTITY 1016 // 夜班产量
+#define RX_PLC_STATE_CHANGED 1017 /* PLC状态改变 */
/* 定制颜色 */
@@ -115,6 +116,12 @@
#define BTN_SOUND_ON_BKGND_HOVER RGB(150, 250, 150)
#define BTN_SOUND_ON_BKGND_PRESS RGB(50, 150, 50)
+/* 树控件小圆点 */
+#define TREE_BADGE_BACKGROUND RGB(34, 177, 76)
+#define TREE_BADGE_FOREGROUND RGB(222, 222, 222)
+#define TREE_BADGE2_BACKGROUND RGB(255, 127, 39)
+#define TREE_BADGE2_FOREGROUND RGB(222, 222, 222)
+
/* 按钮id */
#define VIEW_TOOL_BTN_CLOSE 0x1016
diff --git a/SourceCode/Bond/BoounionPLC/Model.cpp b/SourceCode/Bond/BoounionPLC/Model.cpp
index 59587a7..051b050 100644
--- a/SourceCode/Bond/BoounionPLC/Model.cpp
+++ b/SourceCode/Bond/BoounionPLC/Model.cpp
@@ -21,6 +21,7 @@
m_pObservableEmitter = nullptr;
m_pObservable = nullptr;
m_nTimerID = 0;
+ m_pActivePlc = nullptr;
}
@@ -337,7 +338,7 @@
pPLC->setWorkDir((LPTSTR)(LPCTSTR)strPlcDir);
PLCListener listener;
listener.onStateChanged = [&](void* pFrom, int state) -> void {
- LOGD("PLC状态改变,%d", state);
+ notifyPtr(RX_PLC_STATE_CHANGED, pFrom);
};
listener.onMonitorData = [&](void* pFrom, int id) -> void {
LOGD("PLConMonitorData,%d", id);
@@ -388,19 +389,10 @@
void CModel::setCurrentPlc(CPLC* pPlc)
{
- if (pPlc != nullptr) {
- m_strCurrPlc = pPlc->getName();
- } else {
- m_strCurrPlc = "";
- }
+ m_pActivePlc = pPlc;
}
CPLC* CModel::getCurrentPlc()
{
- auto item = m_mapPlc.find(m_strCurrPlc);
- if (item != m_mapPlc.end()) {
- return item->second;
- }
-
- return nullptr;
+ return m_pActivePlc;
}
\ No newline at end of file
diff --git a/SourceCode/Bond/BoounionPLC/Model.h b/SourceCode/Bond/BoounionPLC/Model.h
index 48a52cb..55401e4 100644
--- a/SourceCode/Bond/BoounionPLC/Model.h
+++ b/SourceCode/Bond/BoounionPLC/Model.h
@@ -46,7 +46,7 @@
IObservableEmitter* m_pObservableEmitter;
CString m_strWorkDir;
std::map<std::string, CPLC*> m_mapPlc;
- std::string m_strCurrPlc;
+ CPLC* m_pActivePlc;
private:
int m_nTimerID;
diff --git a/SourceCode/Bond/BoounionPLC/PagePlcList.cpp b/SourceCode/Bond/BoounionPLC/PagePlcList.cpp
index 56b9ff5..fd94ec0 100644
--- a/SourceCode/Bond/BoounionPLC/PagePlcList.cpp
+++ b/SourceCode/Bond/BoounionPLC/PagePlcList.cpp
@@ -85,6 +85,18 @@
theApp.m_model.notifyPtr(RX_CODE_SELECT_PLC, pSelectedPlc);
}
}
+ else if (RX_PLC_STATE_CHANGED == code) {
+ CPLC* pPlc;
+ if (pAny->getPtrValue("ptr", (void*&)pPlc)) {
+ HTREEITEM hItem = FindItem(pPlc);
+ if (hItem != nullptr && pPlc->isConnected()) {
+ m_treeCtrl.ShowItemBadgeDotMode(hItem);
+ }
+ else {
+ m_treeCtrl.HideItemBadge(hItem);
+ }
+ }
+ }
pAny->release();
}, [&]() -> void {
@@ -191,6 +203,10 @@
for (auto item : plcs) {
HTREEITEM hItem = m_treeCtrl.InsertItem(item.second->getName().c_str(), nullptr, nullptr);
m_treeCtrl.SetItemData(hItem, (DWORD_PTR)item.second);
+ m_treeCtrl.SetItemBadge(hItem, TREE_BADGE_BACKGROUND, TREE_BADGE_FOREGROUND);
+ if (item.second->isConnected()) {
+ m_treeCtrl.ShowItemBadgeDotMode(hItem);
+ }
if (hItemFirst == nullptr) {
hItemFirst = hItem;
}
--
Gitblit v1.9.3