From 904fd149e60f984f4459ff295cd6ae6505fa3f21 Mon Sep 17 00:00:00 2001
From: darker <mr.darker@163.com>
Date: 星期三, 12 二月 2025 17:48:14 +0800
Subject: [PATCH] Merge branch 'clh' into liuyang
---
SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp | 446 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 444 insertions(+), 2 deletions(-)
diff --git a/SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp b/SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp
index a0db823..d859bee 100644
--- a/SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp
+++ b/SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp
@@ -7,11 +7,24 @@
#include "BoounionPLCDlg.h"
#include "afxdialogex.h"
#include "Common.h"
+#include "PlcView.h"
+#include "Log.h"
+#include "InputDialog.h"
+#include "AddPLCInfo.h"
+#include "AxisManager.h"
+#include "IOManager.h"
+
+// 测试
+#include "AxisSettingsDlg.h"
+#include "IOMonitoringDlg.h"
+
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
+
+#define LOG_WND_HEIGHT 258
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
@@ -55,8 +68,12 @@
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_pTopToolbar = nullptr;
+ m_pObserver = nullptr;
m_crBkgnd = APP_MAIN_DLG_BACKGROUND;
m_hbrBkgnd = nullptr;
+ m_pActiveView = nullptr;
+ m_pPageLogcat = nullptr;
+ m_bShowLogWnd = TRUE;
}
void CBoounionPLCDlg::DoDataExchange(CDataExchange* pDX)
@@ -71,10 +88,90 @@
ON_WM_DESTROY()
ON_WM_SIZE()
ON_WM_CTLCOLOR()
+ ON_COMMAND(ID_MENU_FILE_EXIT, &CBoounionPLCDlg::OnMenuFileExit)
+ ON_UPDATE_COMMAND_UI(ID_MENU_FILE_EXIT, &CBoounionPLCDlg::OnUpdateMenuFileExit)
+ ON_COMMAND(ID_MENU_FILE_SETTINGS, &CBoounionPLCDlg::OnMenuFileSettings)
+ ON_UPDATE_COMMAND_UI(ID_MENU_FILE_SETTINGS, &CBoounionPLCDlg::OnUpdateMenuFileSettings)
+ ON_COMMAND(ID_MENU_WND_LOG, &CBoounionPLCDlg::OnMenuWndLog)
+ ON_UPDATE_COMMAND_UI(ID_MENU_WND_LOG, &CBoounionPLCDlg::OnUpdateMenuWndLog)
+ ON_COMMAND(ID_MENU_HELP_ABOUT, &CBoounionPLCDlg::OnMenuHelpAbout)
+ ON_WM_INITMENUPOPUP()
+ ON_MESSAGE(ID_MSG_TOOLBAR_BTN_CLICKED, &CBoounionPLCDlg::OnToolbarBtnClicked)
+ ON_MESSAGE(ID_MSG_VIEW_ACTIVE, &CBoounionPLCDlg::OnViewActive)
+ ON_MESSAGE(ID_MSG_BTN_CLICKED, &CBoounionPLCDlg::OnViewBtnClicked)
+ ON_MESSAGE(ID_MSG_BTN_MENU_ITEM, &CBoounionPLCDlg::OnViewBtnMenuItem)
END_MESSAGE_MAP()
// CBoounionPLCDlg 消息处理程序
+
+
+void CBoounionPLCDlg::InitRxWindows()
+{
+ /* code */
+ // 订阅数据
+ IRxWindows* pRxWindows = RX_GetRxWindows();
+ pRxWindows->enableLog(5);
+ if (m_pObserver == NULL) {
+ m_pObserver = pRxWindows->allocObserver([&](IAny* pAny) -> void {
+ // onNext
+ pAny->addRef();
+ int code = pAny->getCode();
+ if (RX_CODE_SELECT_PLC == code) {
+ CPLC* pPlc;
+ if (pAny->getPtrValue("ptr", (void*&)pPlc)) {
+ if (pPlc != nullptr) {
+ ASSERT(m_pMainContainer != nullptr);
+ if (m_pActiveView == nullptr) {
+ m_pActiveView = (CPlcView*)CreatePlcView(pPlc);
+ }
+ ASSERT(m_pActiveView);
+ if (m_pActiveView->GetContext() != (void*)pPlc) {
+ CString strTitle;
+ strTitle.Format(_T("%s[%s:%d]"), pPlc->getName().c_str(), pPlc->getIp().c_str(),
+ pPlc->getPort());
+ m_pActiveView->SetWindowText(strTitle);
+ m_pActiveView->SetContext(pPlc);
+ m_pActiveView->SendMessage(WM_NCPAINT, 0, 0);
+ }
+ } else {
+ CloseView(m_pActiveView);
+ }
+
+ 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()) {
+ AlarmOn(pPlc);
+ CAlarmMonitor* pComponent = (CAlarmMonitor*)pPlc->getComponent(ALARM_MONITOR);
+ m_pTopToolbar->GetBtn(IDC_BUTTON_ALARM)->EnableWindow(pComponent->isAlarming());
+ }
+ }
+ else if (code == RX_CODE_ALARM_OFF) {
+ CPLC* pPlc;
+ if (pAny->getPtrValue("ptr", (void*&)pPlc) && pPlc == theApp.m_model.getCurrentPlc()) {
+ AlarmOff(pPlc);
+ CAlarmMonitor* pComponent = (CAlarmMonitor*)pPlc->getComponent(ALARM_MONITOR);
+ m_pTopToolbar->GetBtn(IDC_BUTTON_ALARM)->EnableWindow(pComponent->isAlarming());
+ }
+ }
+ pAny->release();
+ }, [&]() -> void {
+ // onComplete
+ }, [&](IThrowable* pThrowable) -> void {
+ // onErrorm
+ pThrowable->printf();
+ });
+
+ theApp.m_model.getObservable()->observeOn(pRxWindows->mainThread())
+ ->subscribe(m_pObserver);
+ }
+}
BOOL CBoounionPLCDlg::OnInitDialog()
{
@@ -104,11 +201,13 @@
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
+ theApp.m_model.init();
// toolbar
m_pTopToolbar = new CTopToolbar();
m_pTopToolbar->Create(IDD_TOP_TOOLBAR, this);
+ m_pTopToolbar->GetBtn(IDC_BUTTON_ALARM)->EnableWindow(FALSE);
m_pTopToolbar->ShowWindow(SW_SHOW);
HMENU hMenu = m_pTopToolbar->GetOperatorMenu();
ASSERT(hMenu);
@@ -121,6 +220,26 @@
m_pPagePlcList->ShowWindow(SW_SHOW);
+ // 主窗口页
+ m_pMainContainer = new CMainContainer();
+ m_pMainContainer->Create(IDD_MAIN_CONTAINER, this);
+ m_pMainContainer->ShowWindow(SW_SHOW);
+
+
+ // 日志
+ m_pPageLogcat = new CPageLogcat();
+ m_pPageLogcat->Create(IDD_PAGE_LOGCAT, m_pMainContainer);
+ m_pPageLogcat->ShowWindow(SW_SHOW);
+ m_pMainContainer->SetBottomWnd(m_pPageLogcat, LOG_WND_HEIGHT);
+
+
+ // 菜单
+ CMenu menu;
+ menu.LoadMenu(IDR_MENU_APP);
+ SetMenu(&menu);
+
+
+ InitRxWindows();
ShowWindow(SW_MAXIMIZE);
Resize();
@@ -177,6 +296,76 @@
return static_cast<HCURSOR>(m_hIcon);
}
+void CBoounionPLCDlg::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
+{
+ ASSERT(pPopupMenu != NULL);
+
+ CCmdUI state;
+ state.m_pMenu = pPopupMenu;
+ ASSERT(state.m_pOther == NULL);
+ ASSERT(state.m_pParentMenu == NULL);
+
+ HMENU hParentMenu;
+ if (AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu)
+ state.m_pParentMenu = pPopupMenu;
+ else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
+ {
+ CWnd* pParent = this;
+ if (pParent != NULL &&
+ (hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)
+ {
+ int nIndexMax = ::GetMenuItemCount(hParentMenu);
+ for (int nIndex = 0; nIndex < nIndexMax; nIndex++)
+ {
+ if (::GetSubMenu(hParentMenu, nIndex) == pPopupMenu->m_hMenu)
+ {
+ state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
+ break;
+ }
+ }
+ }
+ }
+
+ state.m_nIndexMax = pPopupMenu->GetMenuItemCount();
+ for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
+ state.m_nIndex++)
+ {
+ state.m_nID = pPopupMenu->GetMenuItemID(state.m_nIndex);
+ if (state.m_nID == 0)
+ continue;
+
+ ASSERT(state.m_pOther == NULL);
+ ASSERT(state.m_pMenu != NULL);
+ if (state.m_nID == (UINT)-1)
+ {
+ state.m_pSubMenu = pPopupMenu->GetSubMenu(state.m_nIndex);
+ if (state.m_pSubMenu == NULL ||
+ (state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
+ state.m_nID == (UINT)-1)
+ {
+ continue;
+ }
+ state.DoUpdate(this, TRUE);
+ }
+ else
+ {
+ state.m_pSubMenu = NULL;
+ state.DoUpdate(this, FALSE);
+ }
+
+ UINT nCount = pPopupMenu->GetMenuItemCount();
+ if (nCount < state.m_nIndexMax)
+ {
+ state.m_nIndex -= (state.m_nIndexMax - nCount);
+ while (state.m_nIndex < nCount &&
+ pPopupMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
+ {
+ state.m_nIndex++;
+ }
+ }
+ state.m_nIndexMax = nCount;
+ }
+}
void CBoounionPLCDlg::OnDestroy()
{
@@ -194,12 +383,34 @@
m_pPagePlcList = nullptr;
}
+ if (m_pPageLogcat != nullptr) {
+ m_pPageLogcat->DestroyWindow();
+ delete m_pPageLogcat;
+ m_pPageLogcat = nullptr;
+ }
+
+ if (m_pMainContainer != nullptr) {
+ m_pMainContainer->DestroyWindow();
+ delete m_pMainContainer;
+ m_pMainContainer = nullptr;
+ }
+
+ if (m_pActiveView != nullptr) {
+ m_pActiveView->DestroyWindow();
+ delete m_pActiveView;
+ m_pActiveView = nullptr;
+ }
+
if (m_hbrBkgnd != nullptr) {
::DeleteObject(m_hbrBkgnd);
m_hbrBkgnd = nullptr;
}
-}
+ if (m_pObserver != nullptr) {
+ m_pObserver->unsubscribe();
+ m_pObserver = NULL;
+ }
+}
void CBoounionPLCDlg::OnSize(UINT nType, int cx, int cy)
{
@@ -216,13 +427,15 @@
CRect rcClient, rcItem;
GetClientRect(&rcClient);
+ int x = 0;
int y = 0;
m_pTopToolbar->MoveWindow(0, 0, rcClient.Width(), TOOLBAR_HEIGHT);
y += TOOLBAR_HEIGHT;
m_pPagePlcList->MoveWindow(0, y, PAGE_PLC_LIST_WIDTH, rcClient.Height() - y - 2);
+ x = PAGE_PLC_LIST_WIDTH;
+ m_pMainContainer->MoveWindow(x + 1, y, rcClient.Width() - x - 0, rcClient.bottom - y - 2);
}
-
HBRUSH CBoounionPLCDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
@@ -238,3 +451,232 @@
return m_hbrBkgnd;
}
+
+void CBoounionPLCDlg::OnMenuFileSettings()
+{
+ //CSettingsDlg dlg;
+ //dlg.DoModal();
+}
+
+void CBoounionPLCDlg::OnUpdateMenuFileSettings(CCmdUI* pCmdUI)
+{
+ pCmdUI->Enable(FALSE);
+}
+
+void CBoounionPLCDlg::OnMenuFileExit()
+{
+ PostMessage(WM_CLOSE);
+}
+
+void CBoounionPLCDlg::OnUpdateMenuFileExit(CCmdUI* pCmdUI)
+{
+ pCmdUI->Enable(TRUE);
+}
+
+void CBoounionPLCDlg::OnMenuWndLog()
+{
+ m_bShowLogWnd = !m_bShowLogWnd;
+
+ if (m_bShowLogWnd) {
+ m_pPageLogcat->ShowWindow(SW_SHOW);
+ m_pPageLogcat->SetParent(m_pMainContainer);
+ m_pMainContainer->SetBottomWnd(m_pPageLogcat, LOG_WND_HEIGHT);
+ m_pMainContainer->Resize();
+ }
+ else {
+ m_pPageLogcat->ShowWindow(SW_HIDE);
+ m_pPageLogcat->SetParent(this);
+ m_pMainContainer->SetBottomWnd(nullptr, 0);
+ m_pMainContainer->Resize();
+ }
+}
+
+void CBoounionPLCDlg::OnUpdateMenuWndLog(CCmdUI* pCmdUI)
+{
+ pCmdUI->SetCheck(m_bShowLogWnd);
+}
+
+void CBoounionPLCDlg::OnMenuHelpAbout()
+{
+ CAboutDlg dlgAbout;
+ dlgAbout.DoModal();
+}
+
+LRESULT CBoounionPLCDlg::OnToolbarBtnClicked(WPARAM wParam, LPARAM lParam)
+{
+ int id = (int)lParam;
+ if (id == IDC_BUTTON_ADD) {
+ CAddPLCInfo dlgAddPLCInfo;
+ if (dlgAddPLCInfo.DoModal() != IDOK) {
+ return 0;
+ }
+
+ CString strPLCName = dlgAddPLCInfo.GetPLCName();
+ CString strIP = dlgAddPLCInfo.GetIP();
+ CString strPort = dlgAddPLCInfo.GetPort();
+
+ if (!strPLCName.IsEmpty() && !strIP.IsEmpty() && !strPort.IsEmpty()) {
+ theApp.m_model.addPlc((LPTSTR)(LPCTSTR)strPLCName, (LPTSTR)(LPCTSTR)strIP, std::stoi((LPTSTR)(LPCTSTR)strPort));
+
+ // 新建轴文件
+ AxisManager axisManager;
+ axisManager.SaveAxis((LPTSTR)(LPCTSTR)strPLCName);
+
+ // 新建IO文件
+ IOManager ioManager;
+ ioManager.SaveToFile((LPTSTR)(LPCTSTR)strPLCName);
+ }
+ }
+ else if (id == IDC_BUTTON_DELETE) {
+ CPLC* pPlc = theApp.m_model.getCurrentPlc();
+ if (pPlc != nullptr) {
+ theApp.m_model.removePlc(pPlc->getName().c_str());
+ }
+ }
+ else if (id == IDC_BUTTON_SETTINGS) {
+ // 测试 IO模块
+ CPLC* pPLC = theApp.m_model.getCurrentPlc();
+ if (pPLC != nullptr) {
+ //CIOMonitoringDlg dlg;
+ //dlg.DoModal();
+
+ CAxisSettingsDlg dlg;
+ dlg.DoModal();
+ }
+ }
+ else if (id == IDC_BUTTON_OPERATOR) {
+ /*
+ int menuId = (int)wParam;
+ UserManager& userManager = UserManager::getInstance();
+ if (menuId == 0) {
+ CLoginDlg loginDlg;
+ loginDlg.DoModal();
+ }
+ else if (1 == menuId) {
+ CChangePasswordDlg changePasswordDlg;
+ changePasswordDlg.DoModal();
+ }
+ else if (2 == menuId) {
+ CUserManagerDlg dlg;
+ if (dlg.DoModal() != IDOK) {
+ logManager.log(SystemLogManager::LogType::Operation, _T("用户管理的预操作被取消!"));
+ }
+ }
+ else if (3 == menuId) {
+ CSystemLogManagerDlg dlg;
+ dlg.DoModal();
+ }
+ else if (4 == menuId) {
+ int ret = AfxMessageBox(_T("是否切换用户?切换用户会退出当前账号!"), MB_OKCANCEL | MB_ICONEXCLAMATION);
+ if (ret != IDOK) {
+ return 0;
+ }
+
+ logManager.log(SystemLogManager::LogType::Operation, _T("确认切换角色!"));
+ if (userManager.isLoggedIn()) {
+ logManager.log(SystemLogManager::LogType::Info, _T("退出登录!"));
+ userManager.logout();
+ }
+
+ CLoginDlg loginDlg;
+ loginDlg.DoModal();
+ }
+ else {
+ CString cstrMessage;
+ cstrMessage.Format(_T("是否退出用户 [%s]?"), userManager.getCurrentUser().c_str());
+ int ret = AfxMessageBox(_T(cstrMessage), MB_OKCANCEL | MB_ICONEXCLAMATION);
+ if (ret != IDOK) {
+ return 0;
+ }
+
+ logManager.log(SystemLogManager::LogType::Info, _T("退出登录!"));
+ userManager.logout();
+ }
+
+ UpdateLoginStatus();
+ */
+ }
+
+ return 0;
+}
+
+LRESULT CBoounionPLCDlg::OnViewActive(WPARAM wParam, LPARAM lParam)
+{
+ CBaseView* pView = (CBaseView*)wParam;
+ int code = (int)lParam;
+ if (code == MA_ACTIVATE || code == MA_ACTIVATEANDEAT) {
+
+ }
+
+
+ return 0;
+}
+
+LRESULT CBoounionPLCDlg::OnViewBtnClicked(WPARAM wParam, LPARAM lParam)
+{
+ int id = (int)lParam;
+ if (id == VIEW_TOOL_BTN_CLOSE) {
+ CloseView((CBaseView*)wParam);
+ }
+
+ return 0;
+}
+
+LRESULT CBoounionPLCDlg::OnViewBtnMenuItem(WPARAM wParam, LPARAM lParam)
+{
+ UINT id = (UINT)lParam;
+
+ return 0;
+}
+
+CBaseView* CBoounionPLCDlg::CreatePlcView(CPLC* pPlc)
+{
+ CPlcView* pDlg = new CPlcView(m_pMainContainer);
+ pDlg->SetContext(pPlc);
+ pDlg->Create(IDD_VIEW_PLC, m_pMainContainer);
+
+ CString strIcon0, strIcon1, strIcon2, strIcon3;
+ strIcon0.Format(_T("%s\\Res\\small_close0.ico"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+ strIcon1.Format(_T("%s\\Res\\small_close1.ico"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+ strIcon2.Format(_T("%s\\Res\\small_close2.ico"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+ strIcon3.Format(_T("%s\\Res\\small_close3.ico"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+ pDlg->AddToolBtn(VIEW_TOOL_BTN_CLOSE,
+ (LPTSTR)(LPCTSTR)strIcon0,
+ (LPTSTR)(LPCTSTR)strIcon1,
+ (LPTSTR)(LPCTSTR)strIcon2,
+ (LPTSTR)(LPCTSTR)strIcon3, "关闭");
+ pDlg->SetWindowText(pPlc->getName().c_str());
+ m_pMainContainer->Resize();
+
+ return pDlg;
+}
+
+void CBoounionPLCDlg::CloseView(CBaseView* pView)
+{
+ pView->DestroyWindow();
+ delete (CBaseView*)pView;
+ m_pActiveView = nullptr;
+ m_pMainContainer->Resize();
+}
+
+void CBoounionPLCDlg::AlarmOn(CPLC* pPlc)
+{
+ if (m_pAlarmWnd == nullptr) {
+ m_pAlarmWnd = new CAlarmPopupDlg();
+ m_pAlarmWnd->SetPLC(pPlc);
+ m_pAlarmWnd->Create(IDD_DIALOG_POPUP_ALARM, this);
+ m_pAlarmWnd->CenterWindow();
+ }
+ m_pAlarmWnd->AlarmOn();
+}
+
+void CBoounionPLCDlg::AlarmOff(CPLC* pPlc)
+{
+ if (m_pAlarmWnd == nullptr) {
+ m_pAlarmWnd = new CAlarmPopupDlg();
+ m_pAlarmWnd->SetPLC(pPlc);
+ m_pAlarmWnd->Create(IDD_DIALOG_POPUP_ALARM, this);
+ m_pAlarmWnd->CenterWindow();
+ }
+ m_pAlarmWnd->AlarmOff();
+}
--
Gitblit v1.9.3