From 91632a114b5cf43f213626af1ad0382b75cc3899 Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期六, 02 八月 2025 13:42:27 +0800
Subject: [PATCH] 1. 配方界面区分Master和设备列表

---
 SourceCode/Bond/Servo/PageRecipe.h   |    2 +
 SourceCode/Bond/Servo/PageRecipe.cpp |  103 ++++++++++++++++++++++++++++++++++++++-------------
 2 files changed, 79 insertions(+), 26 deletions(-)

diff --git a/SourceCode/Bond/Servo/PageRecipe.cpp b/SourceCode/Bond/Servo/PageRecipe.cpp
index a625647..2ead2d9 100644
--- a/SourceCode/Bond/Servo/PageRecipe.cpp
+++ b/SourceCode/Bond/Servo/PageRecipe.cpp
@@ -22,6 +22,51 @@
 {
 }
 
+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[3] = { 0, 60, 150 };
+
+	for (int i = 0; i < 3; 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]);
+}
+
 void CPageRecipe::UpdateRecipeByPPID(const CString& strPPID)
 {
 	if (strPPID.IsEmpty()) {
@@ -168,15 +213,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 +222,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 +280,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 +336,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);
 		}
@@ -477,6 +524,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 +536,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,10 +545,12 @@
 
 	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);
 	}
diff --git a/SourceCode/Bond/Servo/PageRecipe.h b/SourceCode/Bond/Servo/PageRecipe.h
index 8f489b4..9f24ba2 100644
--- a/SourceCode/Bond/Servo/PageRecipe.h
+++ b/SourceCode/Bond/Servo/PageRecipe.h
@@ -13,6 +13,8 @@
 	virtual ~CPageRecipe();
 
 private:
+	void InitListCtrlHeaderForMaster();
+	void InitListCtrlHeaderForDevice();
 	void UpdateRecipeByPPID(const CString& strPPID);
 	void FillDataToListCtrl(const std::vector<RecipeInfo>& vecRecipe);
 	void FillRecipeListToListCtrl(SERVO::CRecipeList* pList);

--
Gitblit v1.9.3