From 96579a48b3b558f5ce58cffe372b1f563a9e62ce Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期三, 03 九月 2025 17:23:56 +0800
Subject: [PATCH] 1.配方列表和配方参数获取合并在线程中获取,并更新状态到对话框; 2.配方参数获取; 3.Bonder, AOI, 真空烘烤, 冷却烧烤配方参数解释。

---
 SourceCode/Bond/Servo/PageRecipe.cpp |  229 ++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 176 insertions(+), 53 deletions(-)

diff --git a/SourceCode/Bond/Servo/PageRecipe.cpp b/SourceCode/Bond/Servo/PageRecipe.cpp
index a625647..3cadbe0 100644
--- a/SourceCode/Bond/Servo/PageRecipe.cpp
+++ b/SourceCode/Bond/Servo/PageRecipe.cpp
@@ -5,8 +5,8 @@
 #include "Servo.h"
 #include "afxdialogex.h"
 #include "PageRecipe.h"
-#include "MsgDlg.h"
 #include "RecipeDeviceBindDlg.h"
+
 
 // CPageRecipe 瀵硅瘽妗�
 
@@ -20,6 +20,52 @@
 
 CPageRecipe::~CPageRecipe()
 {
+}
+
+void CPageRecipe::InitListCtrlHeaderForMaster()
+{
+	m_listPPID.DeleteAllItems();
+	while (m_listPPID.DeleteColumn(0));
+
+	CString strIniFile, strItem;
+	strIniFile.Format(_T("%s\\configuration.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+	int width[12] = { 0, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 180 };
+	for (int i = 0; i < 12; i++) {
+		strItem.Format(_T("Col_%d_Width"), i);
+		width[i] = GetPrivateProfileInt("PageRecipeListCtrl", strItem, width[i], strIniFile);
+	}
+
+	m_listPPID.InsertColumn(0, _T(""), LVCFMT_RIGHT, 0); // 闅愯棌鍒�
+	m_listPPID.InsertColumn(1, _T("No."), LVCFMT_LEFT, width[1]);
+	m_listPPID.InsertColumn(2, _T("PPID"), LVCFMT_LEFT, width[2]);
+	m_listPPID.InsertColumn(3, _T("鐪熺┖鐑樼儰"), LVCFMT_LEFT, width[6]);
+	m_listPPID.InsertColumn(4, _T("Bonder1"), LVCFMT_LEFT, width[4]);
+	m_listPPID.InsertColumn(5, _T("Bonder2"), LVCFMT_LEFT, width[5]);
+	m_listPPID.InsertColumn(6, _T("鍚庣儤鍐峰嵈"), LVCFMT_LEFT, width[7]);
+	m_listPPID.InsertColumn(7, _T("绮惧害妫�鏌�"), LVCFMT_LEFT, width[8]);
+	m_listPPID.InsertColumn(8, _T("EFEM"), LVCFMT_LEFT, width[3]);
+	m_listPPID.InsertColumn(9, _T("鍒涘缓鏃堕棿"), LVCFMT_LEFT, width[9]);
+	m_listPPID.InsertColumn(10, _T("鎻忚堪"), LVCFMT_LEFT, width[10]);
+}
+
+void CPageRecipe::InitListCtrlHeaderForDevice()
+{
+	m_listPPID.DeleteAllItems();
+	while (m_listPPID.DeleteColumn(0));
+
+	CString strIniFile, strItem;
+	strIniFile.Format(_T("%s\\configuration.ini"), (LPCTSTR)theApp.m_strAppDir);
+	int width[] = { 0, 60, 150, 150 };
+
+	for (int i = 0; i < 4; i++) {
+		strItem.Format(_T("Col_Device_%d_Width"), i);
+		width[i] = GetPrivateProfileInt(_T("PageRecipeListCtrl"), strItem, width[i], strIniFile);
+	}
+
+	m_listPPID.InsertColumn(0, _T(""), LVCFMT_RIGHT, width[0]);
+	m_listPPID.InsertColumn(1, _T("No."), LVCFMT_CENTER, width[1]);
+	m_listPPID.InsertColumn(2, _T("Recipe ID"), LVCFMT_CENTER, width[2]);
+	m_listPPID.InsertColumn(3, _T("Recipe 鍚嶇О"), LVCFMT_CENTER, width[3]);
 }
 
 void CPageRecipe::UpdateRecipeByPPID(const CString& strPPID)
@@ -168,15 +214,6 @@
 {
 	CDialogEx::OnInitDialog();
 
-	// 璇诲嚭鍒楀
-	CString strIniFile, strItem;
-	strIniFile.Format(_T("%s\\configuration.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
-	int width[12] = { 0, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 180 };
-	for (int i = 0; i < 12; i++) {
-		strItem.Format(_T("Col_%d_Width"), i);
-		width[i] = GetPrivateProfileInt("PageRecipeListCtrl", strItem, width[i], strIniFile);
-	}
-
 	// TODO:  鍦ㄦ娣诲姞棰濆鐨勫垵濮嬪寲
 	CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_PPID);
 	DWORD dwStyle = pListCtrl->GetExtendedStyle();
@@ -186,18 +223,7 @@
 
 	HIMAGELIST imageList = ImageList_Create(24, 24, ILC_COLOR24, 1, 1);
 	ListView_SetImageList(pListCtrl->GetSafeHwnd(), imageList, LVSIL_SMALL);
-	pListCtrl->InsertColumn(0, _T(""), LVCFMT_RIGHT, 0); // 闅愯棌鍒�
-	pListCtrl->InsertColumn(1, _T("No."), LVCFMT_LEFT, width[1]);
-	pListCtrl->InsertColumn(2, _T("PPID/Recipe ID"), LVCFMT_LEFT, width[2]);
-	pListCtrl->InsertColumn(3, _T("鐪熺┖鐑樼儰"), LVCFMT_LEFT, width[6]);
-	pListCtrl->InsertColumn(4, _T("Bonder1"), LVCFMT_LEFT, width[4]);
-	pListCtrl->InsertColumn(5, _T("Bonder2"), LVCFMT_LEFT, width[5]);
-	pListCtrl->InsertColumn(6, _T("鍚庣儤鍐峰嵈"), LVCFMT_LEFT, width[7]);
-	pListCtrl->InsertColumn(7, _T("绮惧害妫�鏌�"), LVCFMT_LEFT, width[8]);
-	pListCtrl->InsertColumn(8, _T("EFEM"), LVCFMT_LEFT, width[3]);
-	pListCtrl->InsertColumn(9, _T("鍒涘缓鏃堕棿"), LVCFMT_LEFT, width[9]);
-	pListCtrl->InsertColumn(10, _T("鎻忚堪"), LVCFMT_LEFT, width[10]);
-	pListCtrl->SetColumnWidth(10, LVSCW_AUTOSIZE_USEHEADER);
+	InitListCtrlHeaderForMaster();
 
 	// 鑾峰彇鎵�鏈夋暟鎹�
 	auto vecData = RecipeManager::getInstance().getAllRecipes();
@@ -255,19 +281,37 @@
 
 void CPageRecipe::OnDestroy()
 {
-	CDialogEx::OnDestroy();
+	CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_EQUIPMENT);
+	int nSel = pComboBox->GetCurSel();
+	SERVO::CEquipment* pEq = (SERVO::CEquipment*)pComboBox->GetItemDataPtr(nSel);
 
 	// 淇濆瓨鍒楀
 	CString strIniFile, strItem, strTemp;
-	strIniFile.Format(_T("%s\\configuration.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+	strIniFile.Format(_T("%s\\configuration.ini"), (LPCTSTR)theApp.m_strAppDir);
 	CHeaderCtrl* pHeader = m_listPPID.GetHeaderCtrl();
+
+	if (!pHeader || pHeader->GetItemCount() == 0) {
+		return;
+	}
+
 	for (int i = 0; i < pHeader->GetItemCount(); i++) {
 		RECT rect;
-		pHeader->GetItemRect(i, &rect);
-		strItem.Format(_T("Col_%d_Width"), i);
+		if (!pHeader->GetItemRect(i, &rect)) { 
+			continue;
+		}
+
+		if (pEq == nullptr) {
+			strItem.Format(_T("Col_%d_Width"), i);
+		}
+		else {
+			strItem.Format(_T("Col_Device_%d_Width"), i);
+		}
+
 		strTemp.Format(_T("%d"), rect.right - rect.left);
-		WritePrivateProfileString("PageRecipeListCtrl", strItem, strTemp, strIniFile);
+		WritePrivateProfileString(_T("PageRecipeListCtrl"), strItem, strTemp, strIniFile);
 	}
+
+	CDialogEx::OnDestroy();
 }
 
 void CPageRecipe::OnShowWindow(BOOL bShow, UINT nStatus)
@@ -293,6 +337,10 @@
 				pComboBox->InsertString(i,
 					pEq[i] == nullptr ? _T("Master") : pEq[i]->getName().c_str());
 				pComboBox->SetItemDataPtr(i, pEq[i]);
+
+				if (pEq[i]) {
+					pEq[i]->masterRecipeListRequest(0, nullptr);
+				}
 			}
 			pComboBox->SetCurSel(0);
 		}
@@ -438,32 +486,11 @@
 		FillDataToListCtrl(vecData);
 	}
 	else {
-		// enable port
-		CMsgDlg msgDlg("璇风瓑寰�", "姝e湪鑾峰彇閰嶆柟...");
-		pEq->masterRecipeListRequest(0, [&, pEq](int status) -> void {
-			if (status == SS_FAILED || status == SS_TIMEOUT) {
-				CString strMsg;
-				strMsg.Format(status == SS_FAILED ? _T("鑾峰彇閰嶆柟澶辫触锛�") : _T("鑾峰彇閰嶆柟瓒呮椂锛�"));
-				msgDlg.DelayClose(3000);
-				msgDlg.SetIcon(MSG_BOX_ERROR);
-				msgDlg.SetTitle(_T("鎿嶄綔澶辫触"));
-				msgDlg.SetMessage((LPTSTR)(LPCTSTR)strMsg);
-				msgDlg.SetMarquee(FALSE, 0);
-				msgDlg.SetCompleteCode(-1);
-			}
-			else if (status == SS_COMPLETE) {
-				CString strMsg;
-				strMsg.Format(_T("鑾峰彇閰嶆柟瀹屾垚锛�"));
-				msgDlg.DelayClose(3000);
-				msgDlg.SetIcon(MSG_BOX_SUCCEED);
-				msgDlg.SetTitle(_T("鎿嶄綔鎴愬姛"));
-				msgDlg.SetMessage((LPTSTR)(LPCTSTR)strMsg);
-				msgDlg.SetMarquee(FALSE, 0);
-				msgDlg.SetCompleteCode(0);
-				SERVO::CRecipeList* pRecipeList = pEq->getRecipeList(0);
-				FillRecipeListToListCtrl(pRecipeList);
-			}
-		});
+		// 鑾峰彇閰嶆柟鍒楄〃
+		CMsgDlg msgDlg("璇风瓑寰�", "姝e湪鑾峰彇閰嶆柟鍒楄〃...");
+		msgDlg.SetData((DWORD_PTR)this);
+		msgDlg.SetDataEx((DWORD_PTR)pEq);
+		msgDlg.BeginThread(SyncThreadFunction);
 		msgDlg.DoModal();
 	}
 }
@@ -477,6 +504,7 @@
 	int nEqSel = pComboBox->GetCurSel();
 	int selectedCount = ListView_GetSelectedCount(m_listPPID.GetSafeHwnd());
 
+	GetDlgItem(IDC_BUTTON_NEW)->EnableWindow(nEqSel == 0 && selectedCount > 0);
 	GetDlgItem(IDC_BUTTON_MODIFY)->EnableWindow(nEqSel == 0 && selectedCount > 0);
 	GetDlgItem(IDC_BUTTON_DELETE)->EnableWindow(nEqSel == 0 && selectedCount > 0);
 	GetDlgItem(IDC_BUTTON_DELETE_ALL)->EnableWindow(nEqSel == 0 && selectedCount > 0);
@@ -488,6 +516,7 @@
 	int nEqSel = pComboBox->GetCurSel();
 	int selectedCount = ListView_GetSelectedCount(m_listPPID.GetSafeHwnd());
 
+	GetDlgItem(IDC_BUTTON_NEW)->EnableWindow(nEqSel == 0 && selectedCount > 0);
 	GetDlgItem(IDC_BUTTON_MODIFY)->EnableWindow(nEqSel == 0 && selectedCount > 0);
 	GetDlgItem(IDC_BUTTON_DELETE)->EnableWindow(nEqSel == 0 && selectedCount > 0);
 	GetDlgItem(IDC_BUTTON_DELETE_ALL)->EnableWindow(nEqSel == 0 && selectedCount > 0);
@@ -496,11 +525,105 @@
 
 	SERVO::CEquipment* pEq = (SERVO::CEquipment*)pComboBox->GetItemDataPtr(nEqSel);
 	if (pEq == nullptr) {
+		InitListCtrlHeaderForMaster();
 		auto vecData = RecipeManager::getInstance().getAllRecipes();
 		FillDataToListCtrl(vecData);
 	}
 	else {
+		InitListCtrlHeaderForDevice();
 		SERVO::CRecipeList* pRecipeList = pEq->getRecipeList(0);
 		FillRecipeListToListCtrl(pRecipeList);
 	}
 }
+
+UINT CPageRecipe::SyncThreadFunction(LPVOID lpvData)
+{
+	CMsgDlg* pMsgDlg = (CMsgDlg*)lpvData;
+	CPageRecipe* pPageRecipe = (CPageRecipe*)pMsgDlg->GetData();
+	return pPageRecipe->SyncThreadFunctionInner(pMsgDlg);
+}
+
+UINT CPageRecipe::SyncThreadFunctionInner(CMsgDlg* pMsgDlg)
+{
+	SERVO::CEquipment* pEq = (SERVO::CEquipment*)pMsgDlg->GetDataEx();
+	HANDLE hEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
+	int nStep = 0;
+	pEq->masterRecipeListRequest(0, [&, pEq, pMsgDlg, hEvent](int status) -> void {
+		Sleep(300);
+		if (status == SS_FAILED || status == SS_TIMEOUT) {
+			CString strMsg;
+			strMsg.Format(status == SS_FAILED ? _T("鑾峰彇閰嶆柟鍒楄〃澶辫触锛�") : _T("鑾峰彇閰嶆柟鍒楄〃瓒呮椂锛�"));
+			pMsgDlg->SetIcon(MSG_BOX_ERROR);
+			pMsgDlg->SetTitle(_T("鎿嶄綔澶辫触"));
+			pMsgDlg->SetMessage((LPTSTR)(LPCTSTR)strMsg);
+			SetEvent(hEvent);
+		}
+		else if (status == SS_LIST_COMPLETE) {
+			CString strMsg;
+			strMsg.Format(_T("鑾峰彇閰嶆柟鍒楄〃瀹屾垚锛�"));
+			pMsgDlg->SetTitle(_T("鎿嶄綔鎴愬姛"));
+			pMsgDlg->SetMessage((LPTSTR)(LPCTSTR)strMsg);
+			SERVO::CRecipeList* pRecipeList = pEq->getRecipeList(0);
+			if (pRecipeList != nullptr && !pRecipeList->getIds().empty()) {
+				nStep = 1;
+			}
+			SetEvent(hEvent);
+		}
+	});
+	::WaitForSingleObject(hEvent, INFINITE);
+	if (nStep != 1) {
+		pMsgDlg->SetIcon(MSG_BOX_SUCCEED);
+		pMsgDlg->SetMarquee(FALSE, 0);
+		pMsgDlg->SetCompleteCode(-1);
+		pMsgDlg->DelayClose(3000);
+	}
+	ResetEvent(hEvent);
+
+
+	// 鍙傛暟鍒楄〃
+	if (nStep == 1) {
+		SERVO::CRecipeList* pRecipeList = pEq->getRecipeList(0);
+		ASSERT(pRecipeList);
+		auto& ids = pRecipeList->getIds();
+		pMsgDlg->SetTitle(_T("姝e湪鑾峰彇鍙傛暟"));
+		for (auto item : ids) {
+			CString strMsg;
+			strMsg.Format(_T("姝e湪鑾峰彇閰嶆柟 %d 鍙傛暟..."), item.second);
+			pMsgDlg->SetMessage((LPTSTR)(LPCTSTR)strMsg);
+			pEq->recipeParameterRequest(0, item.second, 0, [&, pEq, pMsgDlg](int status) -> void {
+				Sleep(500);
+				if (status == SS_FAILED || status == SS_TIMEOUT) {
+					CString strMsg;
+					strMsg.Format(status == SS_FAILED ? _T("鑾峰彇閰嶆柟 %d 鍙傛暟澶辫触锛�") : _T("鑾峰彇閰嶆柟 %d 鍙傛暟瓒呮椂锛�"), item.second);
+					pMsgDlg->SetMessage((LPTSTR)(LPCTSTR)strMsg);
+
+					Sleep(300);
+					SetEvent(hEvent);
+				}
+				else if (status == SS_PARAMS_COMPLETE) {
+					CString strMsg;
+					strMsg.Format(_T("鑾峰彇閰嶆柟 %d 鍙傛暟瀹屾垚锛�"), item.second);
+					pMsgDlg->SetMessage((LPTSTR)(LPCTSTR)strMsg);
+
+					Sleep(300);
+					SetEvent(hEvent);
+				}
+				});
+			::WaitForSingleObject(hEvent, INFINITE);
+			ResetEvent(hEvent);
+		}
+		
+		pMsgDlg->SetIcon(MSG_BOX_SUCCEED);
+		pMsgDlg->SetTitle(_T("鎿嶄綔瀹屾垚"));
+		pMsgDlg->SetCompleteCode(0);
+		pMsgDlg->SetMarquee(FALSE, 0);
+		pMsgDlg->DelayClose(3000);
+	};
+
+	SERVO::CRecipeList* pRecipeList = pEq->getRecipeList(0);
+	FillRecipeListToListCtrl(pRecipeList);
+	CloseHandle(hEvent);
+
+
+	return 0;
+}

--
Gitblit v1.9.3