From c3f30f69f3da4e4ed018ba0307e64e327915d4ca Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期二, 22 七月 2025 13:41:24 +0800
Subject: [PATCH] 1. PPID配方绑定界面优化,动态控件获取窗口画笔
---
SourceCode/Bond/Servo/RecipeDeviceBindDlg.cpp | 243 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 240 insertions(+), 3 deletions(-)
diff --git a/SourceCode/Bond/Servo/RecipeDeviceBindDlg.cpp b/SourceCode/Bond/Servo/RecipeDeviceBindDlg.cpp
index fec07da..22ef3ca 100644
--- a/SourceCode/Bond/Servo/RecipeDeviceBindDlg.cpp
+++ b/SourceCode/Bond/Servo/RecipeDeviceBindDlg.cpp
@@ -5,7 +5,22 @@
#include "Servo.h"
#include "afxdialogex.h"
#include "RecipeDeviceBindDlg.h"
+#include "RecipeManager.h"
+#include "Common.h"
+#define IDC_EDIT_DEVICEID_BASE 3000
+#define IDC_EDIT_DEVICENAME_BASE 3050
+#define IDC_COMBO_RECIPEID_BASE 3100
+
+// 缁戝畾鐣岄潰闇�瑕佹樉绀虹殑璁惧
+static const std::vector<DeviceMetaInfo> g_vecBindDevices = {
+ { EQ_ID_VACUUMBAKE, EQ_NAME_VACUUMBAKE },
+ { EQ_ID_Bonder1, EQ_NAME_BONDER1 },
+ { EQ_ID_Bonder2, EQ_NAME_BONDER2 },
+ { EQ_ID_BAKE_COOLING, EQ_NAME_BAKE_COOLING },
+ { EQ_ID_MEASUREMENT, EQ_NAME_MEASUREMENT },
+ { EQ_ID_EFEM, EQ_NAME_EFEM }
+};
// CRecipeDeviceBindDlg 瀵硅瘽妗�
@@ -13,6 +28,8 @@
CRecipeDeviceBindDlg::CRecipeDeviceBindDlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_DIALOG_RECIPE_DEVICE_BIND, pParent)
+ , m_strPPID(_T(""))
+ , m_strDesc(_T(""))
{
}
@@ -21,14 +38,234 @@
{
}
-void CRecipeDeviceBindDlg::DoDataExchange(CDataExchange* pDX)
-{
- CDialogEx::DoDataExchange(pDX);
+const RecipeInfo& CRecipeDeviceBindDlg::GetRecipeInfo() const {
+ return m_recipe;
}
+void CRecipeDeviceBindDlg::SetRecipeInfo(const RecipeInfo& info)
+{
+ m_recipe = info;
+}
+
+void CRecipeDeviceBindDlg::DoDataExchange(CDataExchange* pDX)
+{
+ CDialogEx::DoDataExchange(pDX);
+ DDX_Text(pDX, IDC_EDIT_PPID, m_strPPID);
+ DDX_Text(pDX, IDC_EDIT_DESC, m_strDesc);
+}
BEGIN_MESSAGE_MAP(CRecipeDeviceBindDlg, CDialogEx)
+ ON_WM_CLOSE()
+ ON_WM_SIZE()
+ ON_BN_CLICKED(IDOK, &CRecipeDeviceBindDlg::OnBnClickedOk)
END_MESSAGE_MAP()
// CRecipeDeviceBindDlg 娑堟伅澶勭悊绋嬪簭
+
+BOOL CRecipeDeviceBindDlg::OnInitDialog()
+{
+ CDialogEx::OnInitDialog();
+
+ // 璁剧疆瀵硅瘽妗嗘爣棰�
+ SetWindowText(m_recipe.vecDeviceList.empty() ? _T("鏂板缓閰嶆柟") : _T("缂栬緫閰嶆柟"));
+
+ if (m_font.m_hObject == NULL) {
+ // 鑾峰彇瀵硅瘽妗嗙殑瀛椾綋
+ CFont* pDlgFont = GetFont();
+ LOGFONT lf;
+ if (pDlgFont && pDlgFont->GetLogFont(&lf)) {
+ m_font.CreateFontIndirect(&lf);
+ }
+ }
+
+ // 璁$畻x璧峰鍧愭爣
+ CWnd* pWndDesc = GetDlgItem(IDC_STATIC_DESC);
+ CRect rDesc;
+ int nYStart = 0;
+ int nXStart = 0;
+ int nTotalControlWidth = 340; // 榛樿鍏滃簳
+ if (pWndDesc) {
+ pWndDesc->GetWindowRect(&rDesc);
+ ScreenToClient(&rDesc);
+ nXStart = rDesc.left;
+ }
+ else {
+ nXStart = 30;
+ }
+
+ // 璁$畻x璧峰鍧愭爣
+ pWndDesc = GetDlgItem(IDC_EDIT_DESC);
+ if (pWndDesc) {
+ pWndDesc->GetWindowRect(&rDesc);
+ ScreenToClient(&rDesc);
+ nYStart = rDesc.bottom + 20;
+ }
+ else {
+ nYStart = 30;
+ }
+
+ // 淇濊瘉姣忔杩涙潵閮芥竻绌�
+ for (auto& ctrl : m_vecDevices) {
+ if (ctrl.editDeviceID) {
+ delete ctrl.editDeviceID;
+ ctrl.editDeviceID = nullptr;
+ }
+
+ if (ctrl.editDeviceName) {
+ delete ctrl.editDeviceName;
+ ctrl.editDeviceName = nullptr;
+ }
+
+ if (ctrl.comboRecipeID) {
+ delete ctrl.comboRecipeID;
+ ctrl.comboRecipeID = nullptr;
+ }
+ }
+ m_vecDevices.clear();
+
+ // 鍒涘缓鎺т欢锛堜笉绠℃柊寤鸿繕鏄紪杈戯紝閮藉厛鍒涘缓濂斤級
+ CRect rClient;
+ GetClientRect(&rClient);
+ nTotalControlWidth = (rClient.Width() - nXStart * 2);
+ const int nRowHeight = 30;
+ const int nRowCount = static_cast<int>(g_vecBindDevices.size());
+ for (int i = 0; i < nRowCount; ++i) {
+ int y = nYStart + i * nRowHeight;
+ const auto& meta = g_vecBindDevices[i];
+
+ CEdit* pEditID = new CEdit();
+ pEditID->Create(WS_CHILD | WS_VISIBLE | WS_BORDER, CRect(nXStart, y, nXStart + 100, y + 25), this, IDC_EDIT_DEVICEID_BASE + i);
+
+ CEdit* pEditName = new CEdit();
+ pEditName->Create(WS_CHILD | WS_VISIBLE | WS_BORDER, CRect(nXStart + 110, y, nXStart + 210, y + 25), this, IDC_EDIT_DEVICENAME_BASE + i);
+
+ CComboBox* pCombo = new CComboBox();
+ pCombo->Create(WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST, CRect(nXStart + 220, y, nXStart + nTotalControlWidth, y + 25), this, IDC_COMBO_RECIPEID_BASE + i);
+
+ pEditID->SetFont(&m_font);
+ pEditName->SetFont(&m_font);
+ pCombo->SetFont(&m_font);
+
+ m_vecDevices.push_back({ pEditID, pEditName, pCombo });
+ }
+
+ // 濉厖鍐呭
+ if (m_recipe.vecDeviceList.empty()) {
+ // 鏂板缓妯″紡
+ for (int i = 0; i < nRowCount; ++i) {
+ const auto& meta = g_vecBindDevices[i];
+ CString strID;
+ strID.Format(_T("%d"), meta.nDeviceID);
+ m_vecDevices[i].editDeviceID->SetWindowText(strID);
+ m_vecDevices[i].editDeviceID->SetReadOnly(TRUE);
+
+ m_vecDevices[i].editDeviceName->SetWindowText(CA2T(meta.strDeviceName));
+ m_vecDevices[i].editDeviceName->SetReadOnly(TRUE);
+
+ // 杩欓噷浣犲彲浠ュ垵濮嬪寲 ComboBox 閫夐」锛屼緥濡傦細
+ // for (const auto& r : GetRecipeListForDevice(meta.nDeviceID)) {
+ // int idx = m_vecDevices[i].comboRecipeID->AddString(CA2T(r.strRecipeName));
+ // m_vecDevices[i].comboRecipeID->SetItemData(idx, r.nRecipeID);
+ // }
+ }
+ }
+ else {
+ // 缂栬緫妯″紡
+ m_strPPID = CA2T(m_recipe.strPPID.c_str());
+ m_strDesc = CA2T(m_recipe.strDescription.c_str());
+ UpdateData(FALSE);
+
+ for (size_t i = 0; i < m_recipe.vecDeviceList.size() && i < m_vecDevices.size(); ++i) {
+ const DeviceRecipe& d = m_recipe.vecDeviceList[i];
+ CString str;
+ // 璁惧ID
+ str.Format(_T("%d"), d.nDeviceID);
+ m_vecDevices[i].editDeviceID->SetWindowText(str);
+ m_vecDevices[i].editDeviceID->SetReadOnly(TRUE);
+
+ // 璁惧鍚嶇О
+ m_vecDevices[i].editDeviceName->SetWindowText(CA2T(d.strDeviceName.c_str()));
+ m_vecDevices[i].editDeviceName->SetReadOnly(TRUE);
+
+ // ComboBox 閫夐」濉厖
+ // for (const auto& r : GetRecipeListForDevice(d.nDeviceID)) {
+ // int idx = m_vecDevices[i].comboRecipeID->AddString(CA2T(r.strRecipeName));
+ // m_vecDevices[i].comboRecipeID->SetItemData(idx, r.nRecipeID);
+ // // 榛樿閫変腑瀵瑰簲閰嶆柟ID
+ // if (r.nRecipeID == d.nRecipeID)
+ // m_vecDevices[i].comboRecipeID->SetCurSel(idx);
+ // }
+ }
+ }
+
+ return TRUE; // return TRUE unless you set the focus to a control
+ // 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
+}
+
+void CRecipeDeviceBindDlg::OnClose()
+{
+ // TODO: 鍦ㄦ娣诲姞娑堟伅澶勭悊绋嬪簭浠g爜鍜�/鎴栬皟鐢ㄩ粯璁ゅ��
+ CDialogEx::OnClose();
+
+ // 娓呯悊鎺т欢
+ for (auto& device : m_vecDevices) {
+ if (device.editDeviceID) {
+ device.editDeviceID->DestroyWindow();
+ delete device.editDeviceID;
+ }
+ if (device.editDeviceName) {
+ device.editDeviceName->DestroyWindow();
+ delete device.editDeviceName;
+ }
+ if (device.comboRecipeID) {
+ device.comboRecipeID->DestroyWindow();
+ delete device.comboRecipeID;
+ }
+ }
+ m_vecDevices.clear();
+}
+
+void CRecipeDeviceBindDlg::OnSize(UINT nType, int cx, int cy)
+{
+ CDialogEx::OnSize(nType, cx, cy);
+
+ // TODO: 鍦ㄦ澶勬坊鍔犳秷鎭鐞嗙▼搴忎唬鐮�
+}
+
+void CRecipeDeviceBindDlg::OnBnClickedOk()
+{
+ // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+ UpdateData(TRUE);
+
+ // 鏀堕泦鎵�鏈夎澶囨槧灏�
+ m_recipe.vecDeviceList.clear();
+ for (const auto& dev : m_vecDevices) {
+ DeviceRecipe info;
+ CString strID, strName;
+ dev.editDeviceID->GetWindowText(strID);
+ dev.editDeviceName->GetWindowText(strName);
+
+ int sel = dev.comboRecipeID->GetCurSel();
+ info.nRecipeID = -1;
+ if (sel != CB_ERR) {
+ info.nRecipeID = (int)dev.comboRecipeID->GetItemData(sel);
+ }
+ info.nDeviceID = _ttoi(strID);
+ info.strDeviceName = CT2A(strName);
+
+ m_recipe.vecDeviceList.push_back(info);
+ }
+
+ // 妫�鏌� PPID 鏄惁涓虹┖
+ if (m_strPPID.IsEmpty()) {
+ AfxMessageBox(_T("閰嶆柟 PPID 涓嶈兘涓虹┖"));
+ return;
+ }
+
+ // PPID鍜屾弿杩�
+ m_recipe.strPPID = CT2A(m_strPPID);
+ m_recipe.strDescription = CT2A(m_strDesc);
+
+ CDialogEx::OnOK();
+}
--
Gitblit v1.9.3