From df0863b2c29fa227d186e6b8aeb4a856dcae12f3 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期一, 02 十二月 2024 13:57:42 +0800
Subject: [PATCH] 1.增加PLC组件页

---
 SourceCode/Bond/BondEq/BondEqDlg.cpp |  112 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 102 insertions(+), 10 deletions(-)

diff --git a/SourceCode/Bond/BondEq/BondEqDlg.cpp b/SourceCode/Bond/BondEq/BondEqDlg.cpp
index 9668aa4..70bde1c 100644
--- a/SourceCode/Bond/BondEq/BondEqDlg.cpp
+++ b/SourceCode/Bond/BondEq/BondEqDlg.cpp
@@ -8,14 +8,17 @@
 #include "afxdialogex.h"
 #include "Common.h"
 #include "CBonder.h"
+#include "ToolUnits.h"
 #include "SettingsDlg.h"
+#include "InputDialog.h"
 #include "LoginDlg.h"
 #include "ChangePasswordDlg.h"
-#include "InputDialog.h"
 #include "UserManagerDlg.h"
+#include "SystemLogManagerDlg.h"
 
 // test
-#include "SystemLogManagerDlg.h"
+#include "AxisSettingsDlg.h"
+#include "IOMonitoringDlg.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -71,6 +74,7 @@
 	m_pMainContainer = nullptr;
 	m_pHomeDialog = nullptr;
 	m_pActiveView = nullptr;
+	m_pActiveComponentDlg = nullptr;
 }
 
 void CBondEqDlg::DoDataExchange(CDataExchange* pDX)
@@ -131,7 +135,26 @@
 					}
 				}
 			}
+			else if (RX_CODE_SELECT_COMPONENT == code) {
+				CComponent* pComponent;
+				if (pAny->getPtrValue("ptr", (void*&)pComponent)) {
+					if (pComponent->getClassName().compare("CPLC") == 0) {
+						if (m_pMainContainer != nullptr) {
+							if (m_pActiveComponentDlg != nullptr) {
+								if (m_pActiveComponentDlg->GetContext() != (void*)pComponent) {
+									m_pActiveComponentDlg->DestroyWindow();
+									delete m_pActiveComponentDlg;
+									m_pActiveComponentDlg = nullptr;
+								}
+							}
 
+							if (m_pActiveComponentDlg == nullptr) {
+								m_pActiveComponentDlg = CreateComponentPLCDlg(pComponent);
+							}
+						}
+					}
+				}
+			}
 			pAny->release();
 		}, [&]() -> void {
 			// onComplete
@@ -186,13 +209,27 @@
 
 	// 设置运行日志模块的数据库连接
 	SystemLogManager& logManager = SystemLogManager::getInstance();
-	logManager.setDatabase(db);
+	logManager.setDatabase(db.get());
 
 	// 初始化运行日志表
-	if (!logManager.initializeLogTable()) {
-		AfxMessageBox("初始化系统日志表失败!");
+	try {
+		if (!logManager.initializeLogTable()) {
+			AfxMessageBox("初始化系统日志模块失败!");
+			return FALSE;
+		}
+	}
+	catch (const std::exception& ex) {
+		CString errorMsg;
+		errorMsg.Format(_T("初始化系统日志模块失败:%s"), CString(ex.what()));
+		AfxMessageBox(errorMsg, MB_ICONERROR);
 		return FALSE;
 	}
+
+	// 设置配方文件夹路径
+	RecipeManager& recipeManager = RecipeManager::getInstance();
+	std::string strRecipePath =  CToolUnits::getCurrentExePath() + _T("\\Recipe");
+	CToolUnits::createDir(strRecipePath.c_str());
+	recipeManager.setRecipeFolder(strRecipePath);
 
 
 	// 菜单
@@ -349,6 +386,12 @@
 		m_pActiveView = nullptr;
 	}
 
+	if (m_pActiveComponentDlg != nullptr) {
+		m_pActiveComponentDlg->DestroyWindow();
+		delete m_pActiveComponentDlg;
+		m_pActiveComponentDlg = nullptr;
+	}
+
 	if (m_hbrBkgnd != nullptr) {
 		::DeleteObject(m_hbrBkgnd);
 	}
@@ -465,8 +508,23 @@
 
 void CBondEqDlg::OnMenuFileSettings()
 {
+	CAxisSettingsDlg axisDlg;
+	axisDlg.SetPLC(theApp.m_model.getBonder().getPLC("PLC(1)"));
+	axisDlg.SetRecipeName(_T("Default"));
+	axisDlg.DoModal();
+
+	// Cavity VacuumBake AfterBake AOI
+	/*
+	CIOMonitoringDlg dlg;
+	dlg.SetIOManager("Cavity");
+	dlg.SetPLC(theApp.m_model.getBonder().getPLC("PLC(1)"));
+	dlg.DoModal();
+	*/
+
+	/*
 	CSettingsDlg dlg;
 	dlg.DoModal();
+	*/
 }
 
 void CBondEqDlg::OnUpdateMenuFileSettings(CCmdUI* pCmdUI)
@@ -515,7 +573,7 @@
 {
 	int id = (int)lParam;
 	if (id == VIEW_TOOL_BTN_CLOSE) {
-		CloseView((CBaseView*)wParam);
+		CloseView((CComponentDlg*)wParam);
 	}
 
 	return 0;
@@ -564,10 +622,6 @@
 			loginDlg.DoModal();
 		}
 		else if (1 == menuId) {
-			// test 
-			CSystemLogManagerDlg dlg;
-			dlg.DoModal();
-
 			CChangePasswordDlg changePasswordDlg;
 			changePasswordDlg.DoModal();
 		}
@@ -578,6 +632,10 @@
 			}
 		}
 		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;
@@ -622,6 +680,14 @@
 	pView->DestroyWindow();
 	delete (CBaseView*)pView;
 	m_pActiveView = nullptr;
+	m_pMainContainer->Resize();
+}
+
+void CBondEqDlg::CloseView(CComponentDlg* pView)
+{
+	pView->DestroyWindow();
+	delete pView;
+	m_pActiveComponentDlg = nullptr;
 	m_pMainContainer->Resize();
 }
 
@@ -684,6 +750,7 @@
 	{
 		::EnableMenuItem(hMenu, ID_OPEATOR_LOGIN, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
 		::EnableMenuItem(hMenu, ID_OPERATOR_CHANGE_PASSWORD, MF_BYCOMMAND | MF_ENABLED);
+		::EnableMenuItem(hMenu, ID_OPERATOR_SYSTEM_LOG, MF_BYCOMMAND | MF_ENABLED);
 		::EnableMenuItem(hMenu, ID_OPEATOR_SWITCH, MF_BYCOMMAND | MF_ENABLED);
 		::EnableMenuItem(hMenu, ID_OPERATOR_LOGOUT, MF_BYCOMMAND | MF_ENABLED);
 
@@ -700,9 +767,34 @@
 		::EnableMenuItem(hMenu, ID_OPEATOR_LOGIN, MF_BYCOMMAND | MF_ENABLED);
 		::EnableMenuItem(hMenu, ID_OPERATOR_CHANGE_PASSWORD, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
 		::EnableMenuItem(hMenu, ID_OPEATOR_USER_MANAGER, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
+		::EnableMenuItem(hMenu, ID_OPERATOR_SYSTEM_LOG, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
 		::EnableMenuItem(hMenu, ID_OPEATOR_SWITCH, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
 		::EnableMenuItem(hMenu, ID_OPERATOR_LOGOUT, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
 
 		m_pTopToolbar->SetOperatorBtnText(_T("未登录"));
 	}
 }
+
+CComponentPLCDlg* CBondEqDlg::CreateComponentPLCDlg(CComponent* pComponent)
+{
+	CComponentPLCDlg* pDlg = new CComponentPLCDlg(m_pMainContainer);
+	pDlg->Create(IDD_COMPONENT_PLC, m_pMainContainer);
+	pDlg->SetContext(pComponent);
+
+	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->ShowWindow(SW_SHOW);
+	pDlg->SetWindowText(pComponent->getName().c_str());
+	m_pMainContainer->Resize();
+
+	return pDlg;
+}
+

--
Gitblit v1.9.3