From 331f447bb0e5eccf0b3161ab287c1372b14b8480 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期五, 08 八月 2025 11:53:58 +0800
Subject: [PATCH] 1.增加千传计数,保存计数,重启软件时恢复; 2.千传测试模式,打印相关日志,方便后期提取,用于统计; 3.千传模式时烘烤两腔体都要进入; 4.千传模式时,Fliper到Bonder修改为用手臂2取料; 5.修复千传模式不计运行时的问题; 6.千传模式,最后收料强制放入第一层; 6.修复Buf, 当任务未生成(在符合条件后仍有1秒间隙)而机器单元发送FetchOutJob时,数据检验失败的问题,增加Sleep, 缩小间隙;

---
 SourceCode/Bond/Servo/RecipeDeviceBindDlg.cpp |  211 ++++++++++++++++++++++++++++++++++------------------
 1 files changed, 138 insertions(+), 73 deletions(-)

diff --git a/SourceCode/Bond/Servo/RecipeDeviceBindDlg.cpp b/SourceCode/Bond/Servo/RecipeDeviceBindDlg.cpp
index 4d3440d..549fb19 100644
--- a/SourceCode/Bond/Servo/RecipeDeviceBindDlg.cpp
+++ b/SourceCode/Bond/Servo/RecipeDeviceBindDlg.cpp
@@ -47,6 +47,97 @@
     m_recipe = info;
 }
 
+void CRecipeDeviceBindDlg::ReleaseDeviceControls()
+{
+    for (auto& ctrl : m_vecDevices) {
+        delete ctrl.editDeviceID;    ctrl.editDeviceID = nullptr;
+        delete ctrl.editDeviceName;  ctrl.editDeviceName = nullptr;
+        delete ctrl.comboRecipeID;   ctrl.comboRecipeID = nullptr;
+    }
+    m_vecDevices.clear();
+}
+
+void CRecipeDeviceBindDlg::CreateDeviceControls(int nXStart, int nYStart, int nTotalControlWidth, int nRowHeight)
+{
+    for (size_t i = 0; i < g_vecBindDevices.size(); ++i) {
+        int y = nYStart + static_cast<int>(i) * nRowHeight;
+        auto* pEditID = new CEdit;
+        pEditID->Create(WS_CHILD | WS_VISIBLE | WS_BORDER | ES_CENTER, CRect(nXStart, y, nXStart + 100, y + 25), this, (UINT)(IDC_EDIT_DEVICEID_BASE + i));
+        pEditID->SetFont(&m_font);
+
+        auto* pEditName = new CEdit;
+        pEditName->Create(WS_CHILD | WS_VISIBLE | WS_BORDER | ES_CENTER, CRect(nXStart + 110, y, nXStart + 210, y + 25), this, (UINT)(IDC_EDIT_DEVICENAME_BASE + i));
+        pEditName->SetFont(&m_font);
+
+        auto* pCombo = new CComboBox;
+        pCombo->Create(WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST, CRect(nXStart + 220, y, nXStart + nTotalControlWidth, y + 25), this, (UINT)(IDC_COMBO_RECIPEID_BASE + i));
+        pCombo->SetFont(&m_font);
+
+        m_vecDevices.push_back({ pEditID, pEditName, pCombo });
+    }
+}
+
+bool CRecipeDeviceBindDlg::FillComboRecipeList(CComboBox* pCombo, int nDeviceID, int nSelectedRecipeID)
+{
+    auto& master = theApp.m_model.getMaster();
+    auto* pEq = master.getEquipment(nDeviceID);
+    if (!pEq) {
+        return false;
+    }
+
+    auto* pRecipeList = pEq->getRecipeList(0);
+    if (!pRecipeList) { 
+        return false;
+    }
+
+    auto& mapRecipeIds = pRecipeList->getIds();
+    bool bFound = false;
+    pCombo->ResetContent();
+    for (const auto& pair : mapRecipeIds) {
+        int nRecipeID = pair.second;
+        CString strRecipeName;
+        strRecipeName.Format(_T("%d"), nRecipeID);
+        int idx = pCombo->AddString(strRecipeName);
+        pCombo->SetItemData(idx, nRecipeID);
+        if (nSelectedRecipeID == nRecipeID) {
+            pCombo->SetCurSel(idx);
+            bFound = true;
+        }
+    }
+
+    if (nSelectedRecipeID != -1 && !bFound) {
+        pCombo->SetCurSel(CB_ERR);
+    }
+    else if (pCombo->GetCount() > 0 && nSelectedRecipeID == -1) {
+        pCombo->SetCurSel(0);
+    }
+
+    return true;
+}
+
+bool CRecipeDeviceBindDlg::FillDeviceInfo(int idx, int nDeviceID, const CString& strDeviceName, int nSelectedRecipeID)
+{
+    if (idx < 0 || idx >= (int)m_vecDevices.size()) {
+        return false;
+    }
+
+    auto& ctrl = m_vecDevices[idx];
+    CString strID;
+    strID.Format(_T("%d"), nDeviceID);
+    ctrl.editDeviceID->SetWindowText(strID);
+    ctrl.editDeviceID->SetReadOnly(TRUE);
+    ctrl.editDeviceName->SetWindowText(strDeviceName);
+    ctrl.editDeviceName->SetReadOnly(TRUE);
+
+    if (!FillComboRecipeList(ctrl.comboRecipeID, nDeviceID, nSelectedRecipeID)) {
+        CString str;
+        str.Format(_T("璁惧 [%s] 鎴栧叾閰嶆柟鍒楄〃鏈壘鍒帮紝璇锋鏌ヨ澶囬厤缃�"), strDeviceName.GetString());
+        AfxMessageBox(str);
+        return false;
+    }
+    return true;
+}
+
 void CRecipeDeviceBindDlg::DoDataExchange(CDataExchange* pDX)
 {
     CDialogEx::DoDataExchange(pDX);
@@ -67,75 +158,63 @@
 {
 	CDialogEx::OnInitDialog();
 
-    // TODO:  鍦ㄦ娣诲姞棰濆鐨勫垵濮嬪寲
-    if (m_recipe.vecDeviceList.empty()) {
-        SetWindowText(_T("鏂板缓閰嶆柟"));
+	// 璁剧疆瀵硅瘽妗嗘爣棰�
+    SetWindowText(m_recipe.vecDeviceList.empty() ? _T("鏂板缓閰嶆柟") : _T("缂栬緫閰嶆柟"));
 
-        // 璁剧疆鍥哄畾澶у皬锛堜緥濡� 600x400锛�
-        SetWindowPos(nullptr, 0, 0, 600, 400, SWP_NOMOVE | SWP_NOZORDER);
-
-        // 鍒涘缓鎺т欢
-        const int totalControlWidth = 340;
-        CRect clientRect;
-        GetClientRect(&clientRect);
-        int xStart = (clientRect.Width() - totalControlWidth) / 2;
-
-        const int nRowHeight = 30;
-        const int yStart = 30; // 椤堕儴璧峰楂樺害
-
-        const int nRowCount = static_cast<int>(g_vecBindDevices.size());
-        for (int i = 0; i < nRowCount; ++i) {
-            int y = yStart + i * nRowHeight;
-            const auto& meta = g_vecBindDevices[i];
-
-            CEdit* pEditID = new CEdit();
-            pEditID->Create(WS_CHILD | WS_VISIBLE | WS_BORDER, CRect(xStart, y, xStart + 100, y + 25), this, IDC_EDIT_DEVICEID_BASE + i);
-
-            CString strID;
-            strID.Format(_T("%d"), meta.nDeviceID);
-            pEditID->SetWindowText(strID);
-            pEditID->SetReadOnly(TRUE);     // 璁惧ID鍙
-
-            CEdit* pEditName = new CEdit();
-            pEditName->Create(WS_CHILD | WS_VISIBLE | WS_BORDER, CRect(xStart + 110, y, xStart + 210, y + 25), this, IDC_EDIT_DEVICENAME_BASE + i);
-            pEditName->SetWindowText(CA2T(meta.strDeviceName));
-            pEditName->SetReadOnly(TRUE);   // 璁惧鍚嶇О鍙
-
-            CComboBox* pCombo = new CComboBox();
-            pCombo->Create(WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST, CRect(xStart + 220, y, xStart + 340, y + 300), this, IDC_COMBO_RECIPEID_BASE + i);
-
-            // 娣诲姞閫夐」鍒� ComboBox
-            m_vecDevices.push_back({ pEditID, pEditName, pCombo });
+	// 鍒涘缓鍔ㄦ�佹帶浠跺瓧浣�
+    if (!m_font.m_hObject) {
+        CFont* pDlgFont = GetFont();
+        LOGFONT lf;
+        if (pDlgFont && pDlgFont->GetLogFont(&lf)) {
+            lf.lfHeight = -16;
+            m_font.CreateFontIndirect(&lf);
         }
     }
-    else {
-        SetWindowText(_T("缂栬緫閰嶆柟"));
 
+    // 璁$畻鍧愭爣
+    CRect rDesc;
+    int nXStart = 30, nYStart = 30, nTotalControlWidth = 340;
+    if (auto* pWndDesc = GetDlgItem(IDC_STATIC_DESC)) {
+        pWndDesc->GetWindowRect(&rDesc); ScreenToClient(&rDesc);
+        nXStart = rDesc.left;
+    }
+    if (auto* pWndEdit = GetDlgItem(IDC_EDIT_DESC)) {
+        pWndEdit->GetWindowRect(&rDesc); ScreenToClient(&rDesc);
+        nYStart = rDesc.bottom + 20;
+    }
+    CRect rClient; GetClientRect(&rClient);
+    nTotalControlWidth = rClient.Width() - nXStart * 2;
+    const int nRowHeight = 30;
+
+    // 娓呯┖鏃ф帶浠�
+    ReleaseDeviceControls();
+
+    // 鍒涘缓鏂版帶浠�
+    CreateDeviceControls(nXStart, nYStart, nTotalControlWidth, nRowHeight);
+
+    auto& master = theApp.m_model.getMaster();
+
+    // 濉厖鍐呭
+    if (m_recipe.vecDeviceList.empty()) { 
+        // 鏂板缓
+        for (size_t i = 0; i < g_vecBindDevices.size(); ++i) {
+            const auto& meta = g_vecBindDevices[i];
+            FillDeviceInfo((int)i, meta.nDeviceID, meta.strDeviceName);
+        }
+    }
+    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);
-
-            str.Format(_T("%s"), d.strDeviceName.c_str());
-            m_vecDevices[i].editDeviceName->SetWindowText(str);
-
-            /*ComboBox閫夋嫨閰嶆柟ID锛屽悗闈㈤渶瑕佷慨鏀�****/
-            //int nCount = m_vecDevices[i].comboRecipeID->GetCount();
-            //for (int idx = 0; idx < nCount; ++idx) {
-            //    if ((int)m_vecDevices[i].comboRecipeID->GetItemData(idx) == d.nRecipeID) {
-            //        m_vecDevices[i].comboRecipeID->SetCurSel(idx);
-            //        break;
-            //    }
-            //}
+            const auto& d = m_recipe.vecDeviceList[i];
+            FillDeviceInfo((int)i, d.nDeviceID, d.strDeviceName.c_str(), d.nRecipeID);
         }
     }
+
+    CenterWindow();
 
 	return TRUE;  // return TRUE unless you set the focus to a control
 	// 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
@@ -147,21 +226,7 @@
     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();
+    ReleaseDeviceControls();
 }
 
 void CRecipeDeviceBindDlg::OnSize(UINT nType, int cx, int cy)

--
Gitblit v1.9.3