From 09a0bd46861c8df221983f4ea1458a36c5d8a7c2 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期五, 13 十二月 2024 11:58:21 +0800
Subject: [PATCH] 1.工具条增加“警告”按钮

---
 SourceCode/Bond/BondEq/Resource.h               |    0 
 SourceCode/Bond/BondEq/TopToolbar.h             |    1 +
 SourceCode/Bond/x64/Debug/Res/alarm_o_32.ico    |    0 
 SourceCode/Bond/BondEq/AlarmPopupDlg.cpp        |    2 +-
 SourceCode/Bond/BondEq/BondEq.rc                |    0 
 SourceCode/Bond/BondEq/CBonder.h                |    3 +++
 SourceCode/Bond/x64/Debug/Res/alarm_gray_32.ico |    0 
 SourceCode/Bond/BondEq/TopToolbar.cpp           |    8 ++++++++
 SourceCode/Bond/BondEq/BondEqDlg.cpp            |    8 ++++++++
 SourceCode/Bond/BondEq/CPageAlarm.cpp           |    6 +++---
 10 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/SourceCode/Bond/BondEq/AlarmPopupDlg.cpp b/SourceCode/Bond/BondEq/AlarmPopupDlg.cpp
index a7084ee..5a6e0de 100644
--- a/SourceCode/Bond/BondEq/AlarmPopupDlg.cpp
+++ b/SourceCode/Bond/BondEq/AlarmPopupDlg.cpp
@@ -202,7 +202,7 @@
 	}
 
 	CString strText;
-	CAlarmMonitor* pAlarmMonitor = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent("警告信息");
+	CAlarmMonitor* pAlarmMonitor = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent(ALARM_MONITOR);
 	m_pActiveAlarm = pAlarmMonitor->getActiveAlarm();
 	if (m_pActiveAlarm != nullptr) {
 		m_pActiveAlarm->addRef();
diff --git a/SourceCode/Bond/BondEq/BondEq.rc b/SourceCode/Bond/BondEq/BondEq.rc
index b81e838..a0dffc3 100644
--- a/SourceCode/Bond/BondEq/BondEq.rc
+++ b/SourceCode/Bond/BondEq/BondEq.rc
Binary files differ
diff --git a/SourceCode/Bond/BondEq/BondEqDlg.cpp b/SourceCode/Bond/BondEq/BondEqDlg.cpp
index 85f7894..4f29b69 100644
--- a/SourceCode/Bond/BondEq/BondEqDlg.cpp
+++ b/SourceCode/Bond/BondEq/BondEqDlg.cpp
@@ -155,9 +155,13 @@
 			}
 			else if (code == RX_CODE_ALARM_ON) {
 				AlarmOn();
+				CAlarmMonitor* pComponent = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent(ALARM_MONITOR);
+				m_pTopToolbar->GetBtn(IDC_BUTTON_ALARM)->EnableWindow(pComponent->isAlarming());
 			}
 			else if (code == RX_CODE_ALARM_OFF) {
 				AlarmOff();
+				CAlarmMonitor* pComponent = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent(ALARM_MONITOR);
+				m_pTopToolbar->GetBtn(IDC_BUTTON_ALARM)->EnableWindow(pComponent->isAlarming());
 			}
 			pAny->release();
 		}, [&]() -> void {
@@ -251,6 +255,7 @@
 	m_pTopToolbar->Create(IDD_TOP_TOOLBAR, this);
 	m_pTopToolbar->ShowWindow(SW_SHOW);
 	m_pTopToolbar->GetBtn(IDC_BUTTON_STOP)->EnableWindow(FALSE);
+	m_pTopToolbar->GetBtn(IDC_BUTTON_ALARM)->EnableWindow(FALSE);
 	HMENU hMenu = m_pTopToolbar->GetOperatorMenu();
 	ASSERT(hMenu);
 	::EnableMenuItem(hMenu, ID_OPEATOR_SWITCH, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
@@ -608,6 +613,9 @@
 		m_pTopToolbar->GetBtn(IDC_BUTTON_STOP)->EnableWindow(FALSE);
 		logManager.log(SystemLogManager::LogType::Operation, _T("停止..."));
 	}
+	else if (id == IDC_BUTTON_ALARM) {
+		AlarmOn();
+	}
 	else if (id == IDC_BUTTON_SETTINGS) {
 		CSettingsDlg dlg;
 		dlg.DoModal();
diff --git a/SourceCode/Bond/BondEq/CBonder.h b/SourceCode/Bond/BondEq/CBonder.h
index c932b47..25969f4 100644
--- a/SourceCode/Bond/BondEq/CBonder.h
+++ b/SourceCode/Bond/BondEq/CBonder.h
@@ -18,6 +18,9 @@
 #define STATE_ERROR			3		/* 发生故障 */
 
 
+#define ALARM_MONITOR		_T("警告信息")
+
+
 typedef std::function<void(void* pFrom, int)> ONBONDSTATECHANGED;
 typedef std::function<void(void* pFrom, int)> ONPLCSTATECHANGED;
 typedef std::function<void(void* pFrom, const char* pszAddr, int port, int)> ONEFEMSTATECHANGED;
diff --git a/SourceCode/Bond/BondEq/CPageAlarm.cpp b/SourceCode/Bond/BondEq/CPageAlarm.cpp
index 0d76752..f38aba3 100644
--- a/SourceCode/Bond/BondEq/CPageAlarm.cpp
+++ b/SourceCode/Bond/BondEq/CPageAlarm.cpp
@@ -155,7 +155,7 @@
 
 void CPageAlarm::LoadAlarms()
 {
-	CAlarmMonitor* pMonitor = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent("警告信息");
+	CAlarmMonitor* pMonitor = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent(ALARM_MONITOR);
 
 	pMonitor->Lock();
 	std::map<int, CAlarm*>& alarmings = pMonitor->getAlarmingMap();
@@ -174,7 +174,7 @@
 void CPageAlarm::AddAlarm(CAlarmMonitor* pMonitor, CAlarm* pAlarm)
 {
 	if (pMonitor == nullptr) {
-		pMonitor = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent("警告信息");
+		pMonitor = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent(ALARM_MONITOR);
 	}
 	CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_ALARM);
 	pListCtrl->InsertItem(0, _T(""));
@@ -191,7 +191,7 @@
 void CPageAlarm::UpdateAlarm(CAlarmMonitor* pMonitor, CAlarm* pAlarm)
 {
 	if (pMonitor == nullptr) {
-		pMonitor = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent("警告信息");
+		pMonitor = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent(ALARM_MONITOR);
 	}
 	CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_ALARM);
 	for (int i = 0; i < pListCtrl->GetItemCount(); i++) {
diff --git a/SourceCode/Bond/BondEq/Resource.h b/SourceCode/Bond/BondEq/Resource.h
index bbb9b9c..38eeaf8 100644
--- a/SourceCode/Bond/BondEq/Resource.h
+++ b/SourceCode/Bond/BondEq/Resource.h
Binary files differ
diff --git a/SourceCode/Bond/BondEq/TopToolbar.cpp b/SourceCode/Bond/BondEq/TopToolbar.cpp
index f0cdca2..fa03ee4 100644
--- a/SourceCode/Bond/BondEq/TopToolbar.cpp
+++ b/SourceCode/Bond/BondEq/TopToolbar.cpp
@@ -28,6 +28,7 @@
 	CDialogEx::DoDataExchange(pDX);
 	DDX_Control(pDX, IDC_BUTTON_RUN, m_btnRun);
 	DDX_Control(pDX, IDC_BUTTON_STOP, m_btnStop);
+	DDX_Control(pDX, IDC_BUTTON_ALARM, m_btnAlarm);
 	DDX_Control(pDX, IDC_BUTTON_SETTINGS, m_btnSettings);
 	DDX_Control(pDX, IDC_BUTTON_OPERATOR, m_btnOperator);
 }
@@ -50,6 +51,7 @@
 
 	InitBtn(m_btnRun, "Run_High_32.ico", "Run_Gray_32.ico");
 	InitBtn(m_btnStop, "Stop_High_32.ico", "Stop_Gray_32.ico");
+	InitBtn(m_btnAlarm, "Alarm_o_32.ico", "Alarm_gray_32.ico");
 	InitBtn(m_btnSettings, "Settings_High_32.ico", "Settings_Gray_32.ico");
 	InitBtn(m_btnOperator, "Operator_High_32.ico", "Operator_Gray_32.ico");
 	HMENU hMenu = LoadMenu(AfxGetInstanceHandle(), MAKEINTRESOURCEA(IDR_MENU_OPEATOR));
@@ -115,6 +117,11 @@
 	x += BTN_WIDTH;
 	x += 2;
 
+	pItem = GetDlgItem(IDC_BUTTON_ALARM);
+	pItem->MoveWindow(x, y, BTN_WIDTH, nBthHeight);
+	x += BTN_WIDTH;
+	x += 2;
+
 	pItem = GetDlgItem(IDC_TOOLBAR_LINE1);
 	pItem->MoveWindow(x, y + 6, 2, nBthHeight - 12);
 	x += 4;
@@ -170,6 +177,7 @@
 	switch (LOWORD(wParam)) {
 	case IDC_BUTTON_RUN:
 	case IDC_BUTTON_STOP:
+	case IDC_BUTTON_ALARM:
 	case IDC_BUTTON_SETTINGS:
 		GetParent()->SendMessage(ID_MSG_TOOLBAR_BTN_CLICKED, 0, LOWORD(wParam));
 		break;
diff --git a/SourceCode/Bond/BondEq/TopToolbar.h b/SourceCode/Bond/BondEq/TopToolbar.h
index 1261d35..157b60e 100644
--- a/SourceCode/Bond/BondEq/TopToolbar.h
+++ b/SourceCode/Bond/BondEq/TopToolbar.h
@@ -32,6 +32,7 @@
 private:
 	CBlButton m_btnRun;
 	CBlButton m_btnStop;
+	CBlButton m_btnAlarm;
 	CBlButton m_btnSettings;
 	CBlButton m_btnOperator;
 
diff --git a/SourceCode/Bond/x64/Debug/Res/alarm_gray_32.ico b/SourceCode/Bond/x64/Debug/Res/alarm_gray_32.ico
new file mode 100644
index 0000000..59e5228
--- /dev/null
+++ b/SourceCode/Bond/x64/Debug/Res/alarm_gray_32.ico
Binary files differ
diff --git a/SourceCode/Bond/x64/Debug/Res/alarm_o_32.ico b/SourceCode/Bond/x64/Debug/Res/alarm_o_32.ico
new file mode 100644
index 0000000..279b80c
--- /dev/null
+++ b/SourceCode/Bond/x64/Debug/Res/alarm_o_32.ico
Binary files differ

--
Gitblit v1.9.3