From f65a110d7f941ff8826406938408fb2828c43dcb Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期六, 21 六月 2025 16:45:00 +0800
Subject: [PATCH] 1. 初始化读取第一个port数据到界面 2. 切换port下拉框更新界面

---
 SourceCode/Bond/Servo/PortConfigurationDlg.cpp |   76 +++++++++++++++++++++++++++++++++++--
 SourceCode/Bond/Servo/PortConfigurationDlg.h   |    5 ++
 2 files changed, 76 insertions(+), 5 deletions(-)

diff --git a/SourceCode/Bond/Servo/PortConfigurationDlg.cpp b/SourceCode/Bond/Servo/PortConfigurationDlg.cpp
index 895648a..b941707 100644
--- a/SourceCode/Bond/Servo/PortConfigurationDlg.cpp
+++ b/SourceCode/Bond/Servo/PortConfigurationDlg.cpp
@@ -19,7 +19,11 @@
 CPortConfigurationDlg::CPortConfigurationDlg(CWnd* pParent /*=nullptr*/)
 	: CDialogEx(IDD_DIALOG_PORT_CONFIGURATION, pParent)
 {
-
+	// 鍒濆鍖栨垚鍛樺彉閲�
+    m_pPort[0] = dynamic_cast<SERVO::CLoadPort*>(theApp.m_model.m_master.getEquipment(EQ_ID_LOADPORT1));
+    m_pPort[1] = dynamic_cast<SERVO::CLoadPort*>(theApp.m_model.m_master.getEquipment(EQ_ID_LOADPORT2));
+    m_pPort[2] = dynamic_cast<SERVO::CLoadPort*>(theApp.m_model.m_master.getEquipment(EQ_ID_LOADPORT3));
+    m_pPort[3] = dynamic_cast<SERVO::CLoadPort*>(theApp.m_model.m_master.getEquipment(EQ_ID_LOADPORT4));
 }
 
 CPortConfigurationDlg::~CPortConfigurationDlg()
@@ -35,6 +39,52 @@
     return -1; // 鏈煡绔彛
 }
 
+void CPortConfigurationDlg::LoadPortConfigToUI(SERVO::CLoadPort* pPort)
+{
+    if (!pPort) {
+        return;
+    }
+
+    SetDlgItemText(IDC_EDIT_LOTID, "");
+    SetDlgItemText(IDC_EDIT_PRODUCTID, "");
+    SetDlgItemText(IDC_EDIT_OPERATIONID, "");
+    m_comboMaterialsType.SetCurSel(0);
+
+    bool bJobInfoSet = false;
+    for (int i = 0; i < SLOT_MAX; ++i) {
+        SERVO::CSlot* pSlot = pPort->getSlot(i);
+        if (!pSlot) { 
+            continue;
+        }
+
+        SERVO::CGlass* pGlass = dynamic_cast<SERVO::CGlass*>(pSlot->getContext());
+        int nRow = i + 1;
+
+        // 璁剧疆 Panel ID 鍜屽嬀閫夋
+        CGridCellCheck* pCheck = static_cast<CGridCellCheck*>(m_wndGrid.GetCell(nRow, 1));
+        if (pCheck && pGlass) {
+            pCheck->SetCheck(pSlot->isEnable() ? TRUE : FALSE);
+            pCheck->SetText(pGlass ? pGlass->getID().c_str() : _T(""));
+        }
+		else {
+			pCheck->SetCheck(FALSE);
+			pCheck->SetText(_T(""));
+		}
+
+        // 鍥炲~ Job 淇℃伅锛堝彧鍙栫涓�涓湁鏁� Glass锛�
+        if (!bJobInfoSet && pGlass) {
+            SERVO::CJobDataS* pJS = pGlass->getJobDataS();
+            if (pJS) {
+                SetDlgItemText(IDC_EDIT_LOTID, CString(pJS->getLotId().c_str()));
+                SetDlgItemText(IDC_EDIT_PRODUCTID, CString(pJS->getProductId().c_str()));
+                SetDlgItemText(IDC_EDIT_OPERATIONID, CString(pJS->getOperationId().c_str()));
+                m_comboMaterialsType.SetCurSel(pJS->getMaterialsType() - 1);
+                bJobInfoSet = true;
+            }
+        }
+    }
+}
+
 void CPortConfigurationDlg::InitGrid()
 {
     if (m_wndGrid.GetSafeHwnd() == NULL) {
@@ -43,7 +93,7 @@
 
     const int nCols = 2;
     const int nFixRows = 1;
-    const int nRows = 9;
+	const int nRows = SLOT_MAX + 1; // 瀛樺湪琛ㄥご锛屾墍浠� +1
 
     int nColIdx = 0;
     m_wndGrid.DeleteAllItems();
@@ -64,8 +114,6 @@
     // 璁剧疆鍒楀
     m_wndGrid.SetColumnWidth(nColIdx, 50);
     m_wndGrid.SetItemText(0, nColIdx++, _T("Slot ID"));
-    m_wndGrid.SetColumnWidth(nColIdx, 150);
-    m_wndGrid.SetItemText(0, nColIdx++, _T("Panel ID"));
     m_wndGrid.SetColumnWidth(nColIdx, 60);
     m_wndGrid.SetItemText(0, nColIdx++, _T("鍚敤"));
 
@@ -130,6 +178,7 @@
 
 
 BEGIN_MESSAGE_MAP(CPortConfigurationDlg, CDialogEx)
+    ON_CBN_SELCHANGE(IDC_COMBO_PORT, &CPortConfigurationDlg::OnSelchangeComboPort)
     ON_BN_CLICKED(IDC_BUTTON_APPLY, &CPortConfigurationDlg::OnBnClickedButtonApply)
 END_MESSAGE_MAP()
 
@@ -160,14 +209,31 @@
     for (const auto& item : materialTypes) {
         m_comboMaterialsType.AddString(item);
     }
-    m_comboMaterialsType.SetCurSel(0); // 榛樿閫夋嫨绗竴涓墿鏂欑被鍨�
+    m_comboMaterialsType.SetCurSel(0);  // 榛樿閫夋嫨绗竴涓墿鏂欑被鍨�
 
     InitGrid();
 
+	LoadPortConfigToUI(m_pPort[0]);     // 榛樿鍔犺浇绗竴涓鍙g殑閰嶇疆
+
+	// 璁剧疆瀵硅瘽妗嗘爣棰�
+	SetWindowText(_T("Port Configuration"));
+
 	return TRUE;  // return TRUE unless you set the focus to a control
 	// 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
 }
 
+void CPortConfigurationDlg::OnSelchangeComboPort()
+{
+    // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	int selPort = m_comboPort.GetCurSel();
+	if (selPort < 0 || selPort >= 4) {
+		return; // 鏃犳晥閫夋嫨
+	}
+
+	// 鍔犺浇閫変腑绔彛鐨勯厤缃埌 UI
+	LoadPortConfigToUI(m_pPort[selPort]);
+}
+
 void CPortConfigurationDlg::OnBnClickedButtonApply()
 {
     // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
diff --git a/SourceCode/Bond/Servo/PortConfigurationDlg.h b/SourceCode/Bond/Servo/PortConfigurationDlg.h
index dc33c95..f08af7f 100644
--- a/SourceCode/Bond/Servo/PortConfigurationDlg.h
+++ b/SourceCode/Bond/Servo/PortConfigurationDlg.h
@@ -1,6 +1,7 @@
 锘�#pragma once
 #include "afxdialogex.h"
 #include "GridCtrl.h"
+#include "CLoadPort.h"
 
 // CPortConfigurationDlg 瀵硅瘽妗�
 
@@ -20,14 +21,18 @@
 protected:
 	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 鏀寔
 	virtual BOOL OnInitDialog();
+	afx_msg void OnSelchangeComboPort();
 	afx_msg void OnBnClickedButtonApply();
 	DECLARE_MESSAGE_MAP()
 
 private:
 	int GetLoadPortEqID(const std::string& strPortName);
+	void LoadPortConfigToUI(SERVO::CLoadPort* pPort);
 	void InitGrid();
 	void FillGrid();
 
+	SERVO::CLoadPort* m_pPort[4];
+
 	CGridCtrl m_wndGrid;
 	CComboBox m_comboPort;
 	CComboBox m_comboRecipe;

--
Gitblit v1.9.3