From decceeb6669cadea0302c2e5a8035b920a04f836 Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期四, 12 二月 2026 15:54:16 +0800
Subject: [PATCH] 1.SVdata不主动上报,但先缓存。且bonder1和bonder2分开变量。

---
 SourceCode/Bond/Servo/CCjPage2.cpp |  391 ++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 242 insertions(+), 149 deletions(-)

diff --git a/SourceCode/Bond/Servo/CCjPage2.cpp b/SourceCode/Bond/Servo/CCjPage2.cpp
index 0a1bf21..7a79783 100644
--- a/SourceCode/Bond/Servo/CCjPage2.cpp
+++ b/SourceCode/Bond/Servo/CCjPage2.cpp
@@ -14,6 +14,64 @@
     IDC_BUTTON_PORT4_PROCESS_START };
 
 namespace {
+    constexpr int kPortCount = 4;
+    constexpr int kSlotCount = 8;
+
+    int NormalizeMaterial(int material)
+    {
+        return (material == CCarrierSlotGrid::MAT_G2)
+            ? CCarrierSlotGrid::MAT_G2
+            : CCarrierSlotGrid::MAT_G1;
+    }
+
+    void EnsureWarpDefaults(PJWarp& warp)
+    {
+        bool hasSelectedPort = false;
+        for (int p = 0; p < kPortCount; ++p) {
+            if (warp.selectedPorts[p]) {
+                hasSelectedPort = true;
+            }
+            for (int s = 0; s < kSlotCount; ++s) {
+                warp.materialSlots[p][s] = NormalizeMaterial(warp.materialSlots[p][s]);
+            }
+        }
+
+        for (int s = 0; s < kSlotCount; ++s) {
+            warp.material[s] = NormalizeMaterial(warp.material[s]);
+        }
+
+        // Migrate legacy single-port data into multi-port fields.
+        if (!hasSelectedPort && 0 <= warp.port && warp.port < kPortCount) {
+            warp.selectedPorts[warp.port] = TRUE;
+            for (int s = 0; s < kSlotCount; ++s) {
+                warp.checkSlots[warp.port][s] = warp.checkSlot[s];
+                warp.materialSlots[warp.port][s] = NormalizeMaterial(warp.material[s]);
+            }
+        }
+
+        int firstSelectedPort = -1;
+        for (int p = 0; p < kPortCount; ++p) {
+            if (warp.selectedPorts[p]) {
+                firstSelectedPort = p;
+                break;
+            }
+        }
+
+        warp.port = firstSelectedPort;
+        if (firstSelectedPort >= 0) {
+            for (int s = 0; s < kSlotCount; ++s) {
+                warp.checkSlot[s] = warp.checkSlots[firstSelectedPort][s];
+                warp.material[s] = NormalizeMaterial(warp.materialSlots[firstSelectedPort][s]);
+            }
+        }
+        else {
+            for (int s = 0; s < kSlotCount; ++s) {
+                warp.checkSlot[s] = FALSE;
+                warp.material[s] = CCarrierSlotGrid::MAT_G1;
+            }
+        }
+    }
+
     void BuildCassetteCtrlMaps(SERVO::CLoadPort* pPort, short (&jobExistence)[12], short& slotProcess)
     {
         slotProcess = 0;
@@ -185,9 +243,10 @@
 
 int CCjPage2::OnApply() 
 {
-    //SERVO::CProcessJob*
     if (m_pContext == nullptr) return -1;
+
     PJWarp* pPjWarp = (PJWarp*)m_pContext;
+    EnsureWarpDefaults(*pPjWarp);
     SERVO::CProcessJob* pProcessJob = (SERVO::CProcessJob*)pPjWarp->pj;
 
     // 鏇存柊鍚嶇О
@@ -208,7 +267,6 @@
         return -1;
     }
 
-
     pProcessJob->setId(std::string(szBuffer));
 
     // 鏇存柊閰嶆柟
@@ -223,27 +281,45 @@
 #else
         std::string recipe(strRecipe.GetString());
 #endif
-
         pProcessJob->setRecipe(SERVO::RecipeMethod::NoTuning, recipe);
     }
 
-
-    // 鏇存柊Port
-    int port = -1;
     static int ids[] = { IDC_RADIO1, IDC_RADIO2, IDC_RADIO3, IDC_RADIO4 };
-    for (int i = 0; i < 4; i++) {
-        int state = ((CButton*)GetDlgItem(ids[i]))->GetCheck();
-        if (state == BST_CHECKED) port = i;
-    }
-    pPjWarp->port = port;
 
-    if (pPjWarp->port != -1) {
-        for (int i = 0; i < 8; i++) {
-            pPjWarp->checkSlot[i] = m_grid.GetSlotChecked(pPjWarp->port, i);
-            pPjWarp->material[i] = m_grid.GetSlotMaterialType(pPjWarp->port, i);
+    int firstSelectedPort = -1;
+    for (int p = 0; p < kPortCount; ++p) {
+        BOOL selected = (((CButton*)GetDlgItem(ids[p]))->GetCheck() == BST_CHECKED) ? TRUE : FALSE;
+        pPjWarp->selectedPorts[p] = selected;
+        if (selected && firstSelectedPort < 0) {
+            firstSelectedPort = p;
+        }
+
+        for (int s = 0; s < kSlotCount; ++s) {
+            if (selected) {
+                pPjWarp->checkSlots[p][s] = m_grid.GetSlotChecked(p, s);
+                pPjWarp->materialSlots[p][s] = NormalizeMaterial(m_grid.GetSlotMaterialType(p, s));
+            }
+            else {
+                pPjWarp->checkSlots[p][s] = FALSE;
+                pPjWarp->materialSlots[p][s] = CCarrierSlotGrid::MAT_G1;
+            }
         }
     }
 
+    // Keep legacy single-port fields in sync for compatibility.
+    pPjWarp->port = firstSelectedPort;
+    if (firstSelectedPort >= 0) {
+        for (int s = 0; s < kSlotCount; ++s) {
+            pPjWarp->checkSlot[s] = pPjWarp->checkSlots[firstSelectedPort][s];
+            pPjWarp->material[s] = NormalizeMaterial(pPjWarp->materialSlots[firstSelectedPort][s]);
+        }
+    }
+    else {
+        for (int s = 0; s < kSlotCount; ++s) {
+            pPjWarp->checkSlot[s] = FALSE;
+            pPjWarp->material[s] = CCarrierSlotGrid::MAT_G1;
+        }
+    }
 
     ContentChanged(1);
     return 0;
@@ -255,6 +331,13 @@
 
     m_bContentChangedLock = TRUE;
 
+    PJWarp* pPjWarp = (PJWarp*)m_pContext;
+    EnsureWarpDefaults(*pPjWarp);
+
+    for (auto& item : m_pjWarps) {
+        EnsureWarpDefaults(item);
+    }
+
     CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_RECIPE);
     pComboBox->ResetContent();
     std::vector<std::string> vecRecipe = RecipeManager::getInstance().getAllPPID();
@@ -262,82 +345,47 @@
         pComboBox->AddString(CString(recipe.c_str()));
     }
 
-
-    // ComboBox
-    PJWarp* pPjWarp = (PJWarp*)m_pContext;
     SERVO::CProcessJob* pProcessJob = (SERVO::CProcessJob*)pPjWarp->pj;
     SetDlgItemText(IDC_EDIT_PJ_ID, pProcessJob->id().c_str());
     int idx = pComboBox->FindStringExact(-1, pProcessJob->recipeSpec().c_str());
     if (idx != CB_ERR) pComboBox->SetCurSel(idx);
 
-
-    // 4涓猚heckbox
-    static int ids[] = { IDC_RADIO1, IDC_RADIO2, IDC_RADIO3, IDC_RADIO4};
-    static char* pszUsed[] = { "Port1(宸插崰鐢�)", "Port2(宸插崰鐢�)", "Port3(宸插崰鐢�)", "Port4(宸插崰鐢�)" };
-    static char* pszUnUsed[] = { "Port1(鍙敤)", "Port2(鍙敤)", "Port3(鍙敤)", "Port4(鍙敤)" };
-
-    int portIndex = -1;
-    bool enable[] = {true, true, true, true};
-    bool checked[] = { false, false, false, false };
-    for (auto item : m_pjWarps) {
-        if (0 <= item.port && item.port <= 4 && item.pj != ((PJWarp*)m_pContext)->pj) {
-            enable[item.port] = false;
-        }
-    }
-    if (0 <= ((PJWarp*)m_pContext)->port && ((PJWarp*)m_pContext)->port <= 3) {
-        checked[((PJWarp*)m_pContext)->port] = true;
-        portIndex = ((PJWarp*)m_pContext)->port;
-        m_nSelRadioId = ids[((PJWarp*)m_pContext)->port];
-    }
-
-    for (int i = 0; i < 4; i++) {
-        CButton* pButton = (CButton*)GetDlgItem(ids[i]);
-        pButton->SetCheck(checked[i] ? BST_CHECKED : BST_UNCHECKED);
-        pButton->SetWindowText(enable[i] ? pszUnUsed[i] : pszUsed[i]);
-        pButton->EnableWindow(enable[i]);
-
-        m_grid.SetPortAllocated(i, !checked[i], _T(""));
-        GetDlgItem(btnID[i])->EnableWindow(checked[i]);
-    }
-
-
-    // 璇诲彇鍑虹湡瀹炴暟鎹�
+    // 璇诲彇鐪熷疄鏁版嵁
     auto& master = theApp.m_model.getMaster();
-    int EQID[] = {EQ_ID_LOADPORT1, EQ_ID_LOADPORT2, EQ_ID_LOADPORT3, EQ_ID_LOADPORT4};
-    for (int p = 0; p < 4; p++) {
+    int EQID[] = { EQ_ID_LOADPORT1, EQ_ID_LOADPORT2, EQ_ID_LOADPORT3, EQ_ID_LOADPORT4 };
+    for (int p = 0; p < kPortCount; p++) {
         SERVO::CLoadPort* pPort = (SERVO::CLoadPort*)master.getEquipment(EQID[p]);
-        m_grid.SetPortInfo(p, 
-            (std::string("Port ") + std::to_string(p+1)).c_str(),
-            pPort->getCassetteId().c_str()
-        );
-        for (int i = 0; i < SLOT_MAX; ++i) {
-            SERVO::CSlot* pSlot = pPort->getSlot(i);
-            if (!pSlot) {
-                continue;
-            }
+        m_grid.SetPortInfo(p,
+            (std::string("Port ") + std::to_string(p + 1)).c_str(),
+            pPort->getCassetteId().c_str());
 
-            // 璁剧疆 Panel ID 
+        for (int s = 0; s < SLOT_MAX; ++s) {
+            SERVO::CSlot* pSlot = pPort->getSlot(s);
+            if (!pSlot) continue;
+
             SERVO::CGlass* pGlass = dynamic_cast<SERVO::CGlass*>(pSlot->getContext());
-            SERVO::CJobDataS* pJobDataS = pGlass->getJobDataS();
+            SERVO::CJobDataS* pJobDataS = (pGlass != nullptr) ? pGlass->getJobDataS() : nullptr;
             if (pGlass != nullptr && pJobDataS != nullptr) {
-                m_grid.SetSlotGlass(p, i, TRUE, 
-                    pGlass->getID().c_str(), 
-                    m_pjWarps[p].material[i]);
+                const int mat = (s < kSlotCount)
+                    ? NormalizeMaterial(pPjWarp->materialSlots[p][s])
+                    : CCarrierSlotGrid::MAT_G1;
+                m_grid.SetSlotGlass(p, s, TRUE, pGlass->getID().c_str(), mat);
             }
             else {
-                m_grid.SetSlotGlass(p, i, FALSE, nullptr, CCarrierSlotGrid::MAT_G1);
+                m_grid.SetSlotGlass(p, s, FALSE, nullptr, CCarrierSlotGrid::MAT_G1);
             }
         }
     }
 
-
-    // 璁剧疆鍕鹃�夋暟鎹�
-    if (portIndex != -1) {
-        for (int i = 0; i < 8; i++) {
-            m_grid.SetSlotChecked(portIndex, i, ((PJWarp*)m_pContext)->checkSlot[i]);
+    static int ids[] = { IDC_RADIO1, IDC_RADIO2, IDC_RADIO3, IDC_RADIO4 };
+    for (int p = 0; p < kPortCount; ++p) {
+        ((CButton*)GetDlgItem(ids[p]))->SetCheck(pPjWarp->selectedPorts[p] ? BST_CHECKED : BST_UNCHECKED);
+        for (int s = 0; s < kSlotCount; ++s) {
+            m_grid.SetSlotChecked(p, s, pPjWarp->selectedPorts[p] ? pPjWarp->checkSlots[p][s] : FALSE);
         }
     }
 
+    RefreshPortLocksAndButtons();
     m_bContentChangedLock = FALSE;
 }
 
@@ -351,87 +399,108 @@
     ContentChanged(0);
 }
 
+void CCjPage2::RefreshPortLocksAndButtons()
+{
+    if (m_pContext == nullptr) return;
+
+    PJWarp* pCurrent = (PJWarp*)m_pContext;
+    EnsureWarpDefaults(*pCurrent);
+
+    bool usedByOthers[kPortCount] = { false, false, false, false };
+    for (auto& item : m_pjWarps) {
+        if (item.pj == pCurrent->pj) {
+            continue;
+        }
+        EnsureWarpDefaults(item);
+        for (int p = 0; p < kPortCount; ++p) {
+            if (item.selectedPorts[p]) {
+                usedByOthers[p] = true;
+            }
+        }
+    }
+
+    static int ids[] = { IDC_RADIO1, IDC_RADIO2, IDC_RADIO3, IDC_RADIO4 };
+    static const char* pszUsed[] = { "Port1(宸插崰鐢�)", "Port2(宸插崰鐢�)", "Port3(宸插崰鐢�)", "Port4(宸插崰鐢�)" };
+    static const char* pszUnUsed[] = { "Port1(鍙敤)", "Port2(鍙敤)", "Port3(鍙敤)", "Port4(鍙敤)" };
+
+    for (int p = 0; p < kPortCount; ++p) {
+        CButton* pButton = (CButton*)GetDlgItem(ids[p]);
+        BOOL checked = (pButton->GetCheck() == BST_CHECKED) ? TRUE : FALSE;
+        const bool enable = !usedByOthers[p] || checked;
+
+        pButton->EnableWindow(enable ? TRUE : FALSE);
+        pButton->SetWindowText((enable || checked) ? pszUnUsed[p] : pszUsed[p]);
+
+        if (!enable && !checked) {
+            pButton->SetCheck(BST_UNCHECKED);
+        }
+
+        checked = (pButton->GetCheck() == BST_CHECKED) ? TRUE : FALSE;
+        pCurrent->selectedPorts[p] = checked;
+        m_grid.SetPortAllocated(p, !checked, _T(""));
+        GetDlgItem(btnID[p])->EnableWindow(checked);
+    }
+    // Keep one material type across all selected ports.
+    int syncMat = CCarrierSlotGrid::MAT_G1;
+    bool hasSyncMat = false;
+    for (int p = 0; p < kPortCount && !hasSyncMat; ++p) {
+        if (!pCurrent->selectedPorts[p]) continue;
+        for (int s = 0; s < kSlotCount; ++s) {
+            if (m_grid.GetSlotChecked(p, s)) {
+                syncMat = m_grid.GetSlotMaterialType(p, s);
+                hasSyncMat = true;
+                break;
+            }
+        }
+    }
+    if (!hasSyncMat) {
+        for (int p = 0; p < kPortCount; ++p) {
+            if (!pCurrent->selectedPorts[p]) continue;
+            syncMat = m_grid.GetSlotMaterialType(p, 0);
+            hasSyncMat = true;
+            break;
+        }
+    }
+    SyncMaterialAcrossSelectedPorts(syncMat);
+
+    EnsureWarpDefaults(*pCurrent);
+}
+
+void CCjPage2::SyncMaterialAcrossSelectedPorts(int material)
+{
+    if (m_pContext == nullptr) return;
+
+    const int mat = NormalizeMaterial(material);
+    PJWarp* pCurrent = (PJWarp*)m_pContext;
+    for (int p = 0; p < kPortCount; ++p) {
+        if (!pCurrent->selectedPorts[p]) continue;
+        for (int s = 0; s < kSlotCount; ++s) {
+            m_grid.SetSlotMaterialType(p, s, mat, FALSE);
+        }
+    }
+}
+
 void CCjPage2::OnBnClickedRadio1()
 {
-    BOOL lock[] = {TRUE, TRUE, TRUE, TRUE};
-    if (IDC_RADIO1 == m_nSelRadioId) {
-        CheckRadioButton(IDC_RADIO1, IDC_RADIO4, 0);
-        m_nSelRadioId = 0;
-    }
-    else {
-        CheckRadioButton(IDC_RADIO1, IDC_RADIO4, IDC_RADIO1);
-        m_nSelRadioId = IDC_RADIO1;
-        lock[0] = FALSE;
-    }
-
-    for (int i = 0; i < 4; i++) {
-        m_grid.SetPortAllocated(i, lock[i], _T(""));
-        GetDlgItem(btnID[i])->EnableWindow(!lock[i]);
-    }
-
+    RefreshPortLocksAndButtons();
     ContentChanged(0);
 }
 
 void CCjPage2::OnBnClickedRadio2()
 {
-    BOOL lock[] = { TRUE, TRUE, TRUE, TRUE };
-    if (IDC_RADIO2 == m_nSelRadioId) {
-        CheckRadioButton(IDC_RADIO1, IDC_RADIO4, 0);
-        m_nSelRadioId = 0;
-    }
-    else {
-        CheckRadioButton(IDC_RADIO1, IDC_RADIO4, IDC_RADIO2);
-        m_nSelRadioId = IDC_RADIO2;
-        lock[1] = FALSE;
-    }
-
-    for (int i = 0; i < 4; i++) {
-        m_grid.SetPortAllocated(i, lock[i], _T(""));
-        GetDlgItem(btnID[i])->EnableWindow(!lock[i]);
-    }
-
+    RefreshPortLocksAndButtons();
     ContentChanged(0);
 }
 
 void CCjPage2::OnBnClickedRadio3()
 {
-    BOOL lock[] = { TRUE, TRUE, TRUE, TRUE };
-    if (IDC_RADIO3 == m_nSelRadioId) {
-        CheckRadioButton(IDC_RADIO1, IDC_RADIO4, 0);
-        m_nSelRadioId = 0;
-    }
-    else {
-        CheckRadioButton(IDC_RADIO1, IDC_RADIO4, IDC_RADIO3);
-        m_nSelRadioId = IDC_RADIO3;
-        lock[2] = FALSE;
-    }
-
-    for (int i = 0; i < 4; i++) {
-        m_grid.SetPortAllocated(i, lock[i], _T(""));
-        GetDlgItem(btnID[i])->EnableWindow(!lock[i]);
-    }
-
+    RefreshPortLocksAndButtons();
     ContentChanged(0);
 }
 
 void CCjPage2::OnBnClickedRadio4()
 {
-    BOOL lock[] = { TRUE, TRUE, TRUE, TRUE };
-    if (IDC_RADIO4 == m_nSelRadioId) {
-        CheckRadioButton(IDC_RADIO1, IDC_RADIO4, 0);
-        m_nSelRadioId = 0;
-    }
-    else {
-        CheckRadioButton(IDC_RADIO1, IDC_RADIO4, IDC_RADIO4);
-        m_nSelRadioId = IDC_RADIO4;
-        lock[3] = FALSE;
-    }
-
-    for (int i = 0; i < 4; i++) {
-        m_grid.SetPortAllocated(i, lock[i], _T(""));
-        GetDlgItem(btnID[i])->EnableWindow(!lock[i]);
-    }
-
+    RefreshPortLocksAndButtons();
     ContentChanged(0);
 }
 
@@ -462,22 +531,10 @@
 void CCjPage2::OnGridMatChanged(NMHDR* pNMHDR, LRESULT* pResult)
 {
     auto* nm = reinterpret_cast<CSG_MAT_CHANGE*>(pNMHDR);
-    const int port = nm->port;
-    const int slot = nm->slot;
     const int mat = nm->material; // 1/2
 
-    // 渚嬪锛氬嵆鍒诲埛鏂板彸渚ч瑙�/璁板綍鏃ュ織绛�
+    SyncMaterialAcrossSelectedPorts(mat);
     ContentChanged(0);
-
-    /*
-    if (m_pContext != nullptr) {
-        PJWarp* pjWarp = (PJWarp*)m_pContext;
-        for (int i = 0; i < 8; i++) {
-            pjWarp->checkSlot[i] = m_grid.GetSlotChecked(port, i);
-            pjWarp->material[i] = m_grid.GetSlotMaterialType(port, i);
-        }
-    }
-    */
 
     *pResult = 0;
 }
@@ -490,6 +547,15 @@
     short jobExistence[12] = { 0 };
     short slotProcess = 0;
     BuildCassetteCtrlMaps(port, jobExistence, slotProcess);
+    bool hasExistence = false;
+    for (short w : jobExistence) {
+        if (w != 0) { hasExistence = true; break; }
+    }
+    if (!hasExistence) {
+        LOGE("ProcessStart blocked (P1): no JobExistence map (portStatus=%d, scanMap=%d).",
+            port->getPortStatus(), port->getScanCassetteMap());
+        return;
+    }
     port->sendCassetteCtrlCmd(CCC_PROCESS_START, jobExistence, 12, slotProcess, 0, nullptr, nullptr);
 
 }
@@ -502,6 +568,15 @@
     short jobExistence[12] = { 0 };
     short slotProcess = 0;
     BuildCassetteCtrlMaps(port, jobExistence, slotProcess);
+    bool hasExistence = false;
+    for (short w : jobExistence) {
+        if (w != 0) { hasExistence = true; break; }
+    }
+    if (!hasExistence) {
+        LOGE("ProcessStart blocked (P2): no JobExistence map (portStatus=%d, scanMap=%d).",
+            port->getPortStatus(), port->getScanCassetteMap());
+        return;
+    }
     port->sendCassetteCtrlCmd(CCC_PROCESS_START, jobExistence, 12, slotProcess, 0, nullptr, nullptr);
 }
 
@@ -513,6 +588,15 @@
     short jobExistence[12] = { 0 };
     short slotProcess = 0;
     BuildCassetteCtrlMaps(port, jobExistence, slotProcess);
+    bool hasExistence = false;
+    for (short w : jobExistence) {
+        if (w != 0) { hasExistence = true; break; }
+    }
+    if (!hasExistence) {
+        LOGE("ProcessStart blocked (P3): no JobExistence map (portStatus=%d, scanMap=%d).",
+            port->getPortStatus(), port->getScanCassetteMap());
+        return;
+    }
     port->sendCassetteCtrlCmd(CCC_PROCESS_START, jobExistence, 12, slotProcess, 0, nullptr, nullptr);
 }
 
@@ -524,6 +608,15 @@
     short jobExistence[12] = { 0 };
     short slotProcess = 0;
     BuildCassetteCtrlMaps(port, jobExistence, slotProcess);
+    bool hasExistence = false;
+    for (short w : jobExistence) {
+        if (w != 0) { hasExistence = true; break; }
+    }
+    if (!hasExistence) {
+        LOGE("ProcessStart blocked (P4): no JobExistence map (portStatus=%d, scanMap=%d).",
+            port->getPortStatus(), port->getScanCassetteMap());
+        return;
+    }
     port->sendCassetteCtrlCmd(CCC_PROCESS_START, jobExistence, 12, slotProcess, 0, nullptr, nullptr);
 }
 

--
Gitblit v1.9.3