From 2a6b8de3ee1ed419bbe54213dcb8428d2c436a69 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期一, 13 一月 2025 08:56:24 +0800
Subject: [PATCH] 1.PLC调机程序,警告和其它完善;

---
 SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp |   98 ++++++++++++++++++++++++++++++++++--------------
 1 files changed, 69 insertions(+), 29 deletions(-)

diff --git a/SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp b/SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp
index d31d1c0..3da6b35 100644
--- a/SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp
+++ b/SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp
@@ -8,8 +8,14 @@
 #include "afxdialogex.h"
 #include "Common.h"
 #include "PlcView.h"
-#include "AlarmMonitor.h"
 #include "Log.h"
+#include "InputDialog.h"
+#include "AxisManager.h"
+#include "IOManager.h"
+
+// 测试
+#include "AxisSettingsDlg.h"
+#include "IOMonitoringDlg.h"
 
 
 #ifdef _DEBUG
@@ -113,27 +119,39 @@
 			if (RX_CODE_SELECT_PLC == code) {
 				CPLC* pPlc;
 				if (pAny->getPtrValue("ptr", (void*&)pPlc)) {
-					ASSERT(m_pMainContainer != nullptr);
-					if (m_pActiveView == nullptr) {
-						m_pActiveView = (CPlcView*)CreatePlcView(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) {
+							m_pActiveView->SetWindowText(pPlc->getName().c_str());
+							m_pActiveView->SetContext(pPlc);
+							m_pActiveView->SendMessage(WM_NCPAINT, 0, 0);
+						}
+					} else {
+						CloseView(m_pActiveView);
 					}
-					ASSERT(m_pActiveView);
-					if (m_pActiveView->GetContext() != (void*)pPlc) {
-						m_pActiveView->SetWindowText(pPlc->getName().c_str());
-						m_pActiveView->SetContext(pPlc);
-						m_pActiveView->SendMessage(WM_NCPAINT, 0, 0);
-					}
+
+					theApp.m_model.setCurrentPlc(pPlc);
 				}
 			}
 			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());
+				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) {
-				AlarmOff();
-				// CAlarmMonitor* pComponent = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent(ALARM_MONITOR);
-				// m_pTopToolbar->GetBtn(IDC_BUTTON_ALARM)->EnableWindow(pComponent->isAlarming());
+				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 {
@@ -481,20 +499,42 @@
 {
 	int id = (int)lParam;
 	if (id == IDC_BUTTON_ADD) {
-		static int i = 0;
-		char szName[256];
-		sprintf_s(szName, 256, "PLC%d", ++i);
-		theApp.m_model.addPlc(szName, "192.168.1.188", 1001);
+		CInputDialog inputDialog(_T("新建设备"), _T("请输入设备名称:"));
+		if (inputDialog.DoModal() != IDOK) {
+			AfxMessageBox(_T("取消验证!"));
+			return 0;
+		}
+
+		CString strName;
+		strName = inputDialog.GetInputText();
+		if (!strName.IsEmpty()) {
+			theApp.m_model.addPlc((LPTSTR)(LPCTSTR)strName, "192.168.1.188", 1001);
+
+			// 新建轴文件
+			AxisManager axisManager;
+			axisManager.SaveAxis((LPTSTR)(LPCTSTR)strName);
+
+			// 新建IO文件
+			IOManager ioManager;
+			ioManager.SaveToFile((LPTSTR)(LPCTSTR)strName);
+		}
 	}
 	else if (id == IDC_BUTTON_DELETE) {
-		static int i = 0;
-		i += 1;
-		char szName[256];
-		sprintf_s(szName, 256, "PLC%d", i);
-		theApp.m_model.removePlc(szName);
+		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) {
 		/*
@@ -611,22 +651,22 @@
 	m_pMainContainer->Resize();
 }
 
-void CBoounionPLCDlg::AlarmOn()
+void CBoounionPLCDlg::AlarmOn(CPLC* pPlc)
 {
 	if (m_pAlarmWnd == nullptr) {
 		m_pAlarmWnd = new CAlarmPopupDlg();
-		//m_pAlarmWnd->SetPLC(theApp.m_model.getBonder().getPLC("PLC(1)"));
+		m_pAlarmWnd->SetPLC(pPlc);
 		m_pAlarmWnd->Create(IDD_DIALOG_POPUP_ALARM, this);
 		m_pAlarmWnd->CenterWindow();
 	}
 	m_pAlarmWnd->AlarmOn();
 }
 
-void CBoounionPLCDlg::AlarmOff()
+void CBoounionPLCDlg::AlarmOff(CPLC* pPlc)
 {
 	if (m_pAlarmWnd == nullptr) {
 		m_pAlarmWnd = new CAlarmPopupDlg();
-		//m_pAlarmWnd->SetPLC(theApp.m_model.getBonder().getPLC("PLC(1)"));
+		m_pAlarmWnd->SetPLC(pPlc);
 		m_pAlarmWnd->Create(IDD_DIALOG_POPUP_ALARM, this);
 		m_pAlarmWnd->CenterWindow();
 	}

--
Gitblit v1.9.3