From 3f000671e15acd2de87c8588d7f09c0dc103bd7b Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期一, 08 九月 2025 13:56:23 +0800
Subject: [PATCH] 1.SVData获取和解释,待测试;

---
 SourceCode/Bond/Servo/PageRecipe.cpp |  127 +++++++++++++++++++++++++++++++++--------
 1 files changed, 101 insertions(+), 26 deletions(-)

diff --git a/SourceCode/Bond/Servo/PageRecipe.cpp b/SourceCode/Bond/Servo/PageRecipe.cpp
index 891f274..f19cae0 100644
--- a/SourceCode/Bond/Servo/PageRecipe.cpp
+++ b/SourceCode/Bond/Servo/PageRecipe.cpp
@@ -5,6 +5,8 @@
 #include "Servo.h"
 #include "afxdialogex.h"
 #include "PageRecipe.h"
+#include "MsgDlg.h"
+#include "InputDialog.h"
 #include "RecipeDeviceBindDlg.h"
 
 
@@ -55,9 +57,9 @@
 
 	CString strIniFile, strItem;
 	strIniFile.Format(_T("%s\\configuration.ini"), (LPCTSTR)theApp.m_strAppDir);
-	int width[] = { 0, 60, 150, 150 };
+	int width[] = { 0, 60, 100, 100, 150 };
 
-	for (int i = 0; i < 4; i++) {
+	for (int i = 0; i < 5; i++) {
 		strItem.Format(_T("Col_Device_%d_Width"), i);
 		width[i] = GetPrivateProfileInt(_T("PageRecipeListCtrl"), strItem, width[i], strIniFile);
 	}
@@ -66,6 +68,7 @@
 	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]);
+	m_listPPID.InsertColumn(4, _T("Recipe 鍙傛暟"), LVCFMT_CENTER, width[4]);
 }
 
 void CPageRecipe::UpdateRecipeByPPID(const CString& strPPID)
@@ -146,8 +149,18 @@
 		m_listPPID.SetItemText(i, 2, CA2T(recipe.strPPID.c_str()));
 
 		for (int j = 0; j < recipe.vecDeviceList.size(); j++){
+			int nRecipeID = recipe.vecDeviceList.at(j).nRecipeID;
+			std::string strDeviceName = recipe.vecDeviceList.at(j).strDeviceName;
+			std::string strRecipeName = RecipeManager::getInstance().getDeviceRecipeName(strDeviceName, nRecipeID);
+
 			CString str;
-			str.Format(_T("%d"), recipe.vecDeviceList.at(j).nRecipeID);
+			if (strRecipeName.empty()) {
+				str.Format(_T("%d"), recipe.vecDeviceList.at(j).nRecipeID);
+			}
+			else {
+				str.Format(_T("%s"), CA2T(strRecipeName.c_str()));
+			}
+	
 			m_listPPID.SetItemText(i, j + 3, str);
 		}
 
@@ -175,6 +188,7 @@
 	}
 
 	// 閬嶅巻鏁版嵁骞舵彃鍏ュ埌CListCtrl涓�
+	auto& mgr = RecipeManager::getInstance();
 	std::map<int, short>& ids = pRecipeList->getIds();
 	auto rawDatas = pRecipeList->getParamsRawData();
 	for (auto item : ids) {
@@ -182,10 +196,19 @@
 		m_listPPID.SetItemText(index, 1, std::to_string(item.first).c_str());
 		m_listPPID.SetItemText(index, 2, std::to_string(item.second).c_str());
 
+		std::string strRecipeName = mgr.getDeviceRecipeName(pEq->getName(), item.second);
+		m_listPPID.SetItemText(index, 3, strRecipeName.c_str());
+
+		std::string strDescription;
 		auto iter = rawDatas.find(item.second);
 		if (iter != rawDatas.end()) {
-			std::string strDescription;
 			pEq->parsingParams((const char*)iter->second.data(), iter->second.size(), strDescription);
+			m_listPPID.SetItemText(index, 4, strDescription.c_str());
+		}
+
+		if (strRecipeName.empty()) {
+			strRecipeName = std::to_string(item.second);
+			mgr.addDeviceRecipe(pEq->getName(), item.second, strRecipeName, strDescription);
 		}
 	}
 
@@ -211,7 +234,8 @@
 	ON_BN_CLICKED(IDC_BUTTON_DELETE, &CPageRecipe::OnBnClickedButtonDelete)
 	ON_BN_CLICKED(IDC_BUTTON_DELETE_ALL, &CPageRecipe::OnBnClickedButtonDeleteAll)
 	ON_BN_CLICKED(IDC_BUTTON_REFRESH, &CPageRecipe::OnBnClickedButtonRefresh)
-	ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_PPID, &CPageRecipe::OnLvnItemChangedListPPID)
+	ON_NOTIFY(NM_CLICK, IDC_LIST_PPID, &CPageRecipe::OnClickListPPID)
+	ON_NOTIFY(NM_DBLCLK, IDC_LIST_PPID, &CPageRecipe::OnDblclkListPPID)
 	ON_CBN_SELCHANGE(IDC_COMBO_EQUIPMENT, &CPageRecipe::OnCbnSelchangeComboEquipment)
 END_MESSAGE_MAP()
 
@@ -428,15 +452,41 @@
 void CPageRecipe::OnBnClickedButtonModify()
 {
 	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_EQUIPMENT);
+	if (pComboBox == nullptr || !::IsWindow(pComboBox->m_hWnd)) {
+		return;
+	}
+
 	POSITION pos = m_listPPID.GetFirstSelectedItemPosition();
 	if (!pos) {
 		AfxMessageBox(_T("璇峰厛閫夋嫨涓�鏉¢厤鏂硅褰曡繘琛屼慨鏀癸紒"));
 		return;
 	}
 
-	int nSel = m_listPPID.GetNextSelectedItem(pos);
-	CString strPPID = m_listPPID.GetItemText(nSel, 2);
-	UpdateRecipeByPPID(strPPID);
+	int nLine = m_listPPID.GetNextSelectedItem(pos);
+	CString strID = m_listPPID.GetItemText(nLine, 2);
+
+	int nSel = pComboBox->GetCurSel();
+	SERVO::CEquipment* pEq = (SERVO::CEquipment*)pComboBox->GetItemDataPtr(nSel);
+	if (pEq == nullptr) {
+		UpdateRecipeByPPID(strID);
+	}
+	else {
+		CInputDialog dlg(_T("淇敼閰嶆柟鍚嶇О"), _T("璇疯緭鍏ラ厤鏂瑰悕绉帮細"));
+		if (dlg.DoModal() != IDOK) {
+			return;
+		}
+
+		CString strText = dlg.GetInputText();
+		if (strText.IsEmpty()) {
+			AfxMessageBox(_T("閰嶆柟鍚嶇О涓嶈兘涓虹┖锛�"));
+			return;
+		}
+
+		if (RecipeManager::getInstance().updateDeviceRecipeName(pEq->getName(), _ttoi(strID), std::string(CT2A(strText)))) {
+			m_listPPID.SetItemText(nLine, 3, strText);
+		}
+	}
 }
 
 void CPageRecipe::OnBnClickedButtonDelete()
@@ -507,31 +557,60 @@
 	}
 }
 
-void CPageRecipe::OnLvnItemChangedListPPID(NMHDR* pNMHDR, LRESULT* pResult)
+void CPageRecipe::OnClickListPPID(NMHDR* pNMHDR, LRESULT* pResult)
 {
-	LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
+	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
+	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
 	*pResult = 0;
 
 	CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_EQUIPMENT);
-	int nEqSel = pComboBox->GetCurSel();
-	int selectedCount = ListView_GetSelectedCount(m_listPPID.GetSafeHwnd());
+	if (pComboBox == nullptr) {
+		return;
+	}
 
-	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);
+	int nItem = pNMItemActivate->iItem;
+	int nEqSel = pComboBox->GetCurSel();
+
+	GetDlgItem(IDC_BUTTON_NEW)->EnableWindow(nEqSel == 0);
+	GetDlgItem(IDC_BUTTON_MODIFY)->EnableWindow(nItem != -1);
+	GetDlgItem(IDC_BUTTON_DELETE)->EnableWindow(nEqSel == 0 && nItem != -1);
+	GetDlgItem(IDC_BUTTON_DELETE_ALL)->EnableWindow(nEqSel == 0 && nItem != -1);
+}
+
+void CPageRecipe::OnDblclkListPPID(NMHDR* pNMHDR, LRESULT* pResult)
+{
+	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
+	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	*pResult = 0;
+
+	int nItem = pNMItemActivate->iItem;
+	if (nItem < 0) {
+		return;
+	}
+
+	CString strText = m_listPPID.GetItemText(nItem, 2);
+	CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_EQUIPMENT);
+	int nEqSel = pComboBox->GetCurSel();
+	if (nEqSel == CB_ERR) {
+		return;
+	}
+
+	SERVO::CEquipment* pEq = (SERVO::CEquipment*)pComboBox->GetItemDataPtr(nEqSel);
+	if (pEq == nullptr) {
+		return;
+	}
 }
 
 void CPageRecipe::OnCbnSelchangeComboEquipment()
 {
 	CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_EQUIPMENT);
 	int nEqSel = pComboBox->GetCurSel();
-	int selectedCount = ListView_GetSelectedCount(m_listPPID.GetSafeHwnd());
+	int nItem = 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);
+	GetDlgItem(IDC_BUTTON_NEW)->EnableWindow(nEqSel == 0);
+	GetDlgItem(IDC_BUTTON_MODIFY)->EnableWindow(nEqSel == 0 && nItem != -1);
+	GetDlgItem(IDC_BUTTON_DELETE)->EnableWindow(nEqSel == 0 && nItem != -1);
+	GetDlgItem(IDC_BUTTON_DELETE_ALL)->EnableWindow(nEqSel == 0 && nItem != -1);
 	GetDlgItem(IDC_EDIT_KEYWORD)->EnableWindow(nEqSel == 0);
 	GetDlgItem(IDC_BUTTON_SEARCH)->EnableWindow(nEqSel == 0);
 
@@ -632,7 +711,7 @@
 			ResetEvent(hEvent);
 		}
 		
-		
+
 		pEq->saveRecipeList(0, strFilepath);
 		pMsgDlg->SetIcon(MSG_BOX_SUCCEED);
 		pMsgDlg->SetTitle(_T("鎿嶄綔瀹屾垚"));
@@ -643,7 +722,6 @@
 
 	FillRecipeListToListCtrl(pEq);
 	CloseHandle(hEvent);
-
 
 
 	// 鍦ㄦ鎵撳嵃閰嶆柟鍙傛暟浠ヤ究鏍稿鏁版嵁
@@ -665,9 +743,6 @@
 		}
 
 	}
-
-
-
 
 	return 0;
 }

--
Gitblit v1.9.3