From 78793ce8e51b9a2b175483213017b154e3a5f952 Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期三, 21 五月 2025 14:15:59 +0800
Subject: [PATCH] 1. 完善机械臂组合界面的控件状态显示和操作

---
 SourceCode/Bond/Servo/PageRobotCmd.cpp |  126 +++++++++++++++++++++++++++++++++++++----
 1 files changed, 113 insertions(+), 13 deletions(-)

diff --git a/SourceCode/Bond/Servo/PageRobotCmd.cpp b/SourceCode/Bond/Servo/PageRobotCmd.cpp
index bd89ce1..52dcb29 100644
--- a/SourceCode/Bond/Servo/PageRobotCmd.cpp
+++ b/SourceCode/Bond/Servo/PageRobotCmd.cpp
@@ -25,6 +25,15 @@
 	{_T("MEASUREMENT"), 1}
 };
 
+static const std::map < SERVO:: RCMD, RCMDFieldMask > g_cmdFieldMap = {
+	{ SERVO::RCMD::Robot_home, { false, false, false, false, false, false } },
+	{ SERVO::RCMD::Transfer,   { true, true, true, true, true, false } },
+	{ SERVO::RCMD::Move,       { true, true, true, true, true, true } },
+	{ SERVO::RCMD::Get,        { true, true, false, true, false, false } },
+	{ SERVO::RCMD::Put,        { true, false, true, false, true, false } },
+	{ SERVO::RCMD::One_Action_Exchange, { true, true, true, true, true, false } },
+};
+
 IMPLEMENT_DYNAMIC(CPageRobotCmd, CDialogEx)
 
 CPageRobotCmd::CPageRobotCmd(CWnd* pParent /*=nullptr*/)
@@ -55,22 +64,62 @@
 	}
 }
 
-SERVO::ROBOT_CMD_PARAM CPageRobotCmd::GetRobotCmdParam()
+BOOL CPageRobotCmd::SetControlsEnabled(BOOL bEnable)
 {
-	// 绐楀彛閿�姣佹椂涓嶅彲鐢�
-	if (IsWindow(m_hWnd)) {
-		UpdateData(TRUE); // 鍚屾鎴愬憳鍙橀噺鍒扮晫闈�
+	if (!IsWindow(m_hWnd)) {
+		return FALSE;
 	}
 
-	SERVO::ROBOT_CMD_PARAM param;
+	if (bEnable) {
+		UpdateData(TRUE);
+		UpdateInputUI(static_cast<SERVO::RCMD>(m_nRcmd + 1));
+	}
+	else {
+		// 閬嶅巻鎵�鏈夊瓙鎺т欢骞惰缃姸鎬�
+		CWnd* pChild = GetWindow(GW_CHILD);
+		while (pChild) {
+			pChild->EnableWindow(bEnable);
+			pChild = pChild->GetNextWindow();
+		}
+	}
+
+	return CDialogEx::EnableWindow(bEnable);
+}
+
+SERVO::ROBOT_CMD_PARAM CPageRobotCmd::GetRobotCmdParam()
+{
+	if (!IsWindow(m_hWnd)) {
+		return {};
+	}
+	UpdateData(TRUE);  // 鍚屾 UI 鍒板彉閲�
+
+	SERVO::ROBOT_CMD_PARAM param = {};
 	param.sequenceNo = static_cast<short>(m_nSequenceNo);
 	param.rcmd = static_cast<short>(m_nRcmd + 1);
-	param.armNo = static_cast<short>(m_nArmNo);
-	param.getPosition = static_cast<short>(m_nGetPosition + 1);
-	param.putPosition = static_cast<short>(m_nPutPosition + 1);
-	param.getSlotNo = static_cast<short>(m_nGetSlotNo + 1);
-	param.putSlotNo = static_cast<short>(m_nPutSlotNo + 1);
-	param.subCmd = static_cast<short>(m_nSubCmd + 1);
+
+	const auto it = g_cmdFieldMap.find(static_cast<SERVO::RCMD>(param.rcmd));
+	if (it == g_cmdFieldMap.end()) {
+		return {};
+	}
+
+	const RCMDFieldMask& mask = it->second;
+	if (mask.useArm)       param.armNo = static_cast<short>(m_nArmNo);
+	if (mask.useGetPos)    param.getPosition = static_cast<short>(m_nGetPosition + 1);
+	if (mask.usePutPos)    param.putPosition = static_cast<short>(m_nPutPosition + 1);
+	if (mask.useGetSlot)   param.getSlotNo = static_cast<short>(m_nGetSlotNo + 1);
+	if (mask.usePutSlot)   param.putSlotNo = static_cast<short>(m_nPutSlotNo + 1);
+	if (mask.useSubCmd)    param.subCmd = static_cast<short>(m_nSubCmd + 1);
+
+	if (param.rcmd == static_cast<short>(SERVO::RCMD::Move)) {
+		if (m_nSubCmd == 0) {
+			param.putPosition = 0;
+			param.putSlotNo = 0;
+		}
+		else if (m_nSubCmd == 1) {
+			param.getPosition = 0;
+			param.getSlotNo = 0;
+		}
+	}
 
 	return param;
 }
@@ -90,8 +139,10 @@
 
 
 BEGIN_MESSAGE_MAP(CPageRobotCmd, CDialogEx)
+	ON_CBN_SELCHANGE(IDC_COMBO_RCMD, &CPageRobotCmd::OnCbnSelchangeComboRcmd)
 	ON_CBN_SELCHANGE(IDC_COMBO_GET_POS, &CPageRobotCmd::OnCbnSelchangeComboGetPos)
 	ON_CBN_SELCHANGE(IDC_COMBO_PUT_POS, &CPageRobotCmd::OnCbnSelchangeComboPutPos)
+	ON_CBN_SELCHANGE(IDC_COMBO_SUB_CMD, &CPageRobotCmd::OnCbnSelchangeComboSubCmd)
 END_MESSAGE_MAP()
 
 
@@ -154,16 +205,18 @@
 	pComboSubCmd->AddString(_T("2: Put Ready"));
 	pComboSubCmd->SetCurSel(0);
 
-	// 鍒濆鍖栧崟閫夋
+	// 鍒濆鍖� ARM 鍗曢�夋
 	CButton* pRadioArmA = (CButton*)GetDlgItem(IDC_RADIO_ARM_A);
 	CButton* pRadioArmB = (CButton*)GetDlgItem(IDC_RADIO_ARM_B);
 	pRadioArmA->SetCheck(BST_CHECKED);
 	pRadioArmB->SetCheck(BST_UNCHECKED);
 
+	// 鍒濆鍖栬緭鍏ユ帶浠剁姸鎬�
+	UpdateInputUI(SERVO::RCMD::Robot_home);
+
 	return TRUE;  // return TRUE unless you set the focus to a control
 	// 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
 }
-
 
 void CPageRobotCmd::UpdateSlotList(CComboBox* pComboDevice, CComboBox* pComboSlot)
 {
@@ -191,6 +244,48 @@
 	pComboSlot->SetCurSel(0);
 }
 
+void CPageRobotCmd::UpdateMoveSubFields()
+{
+	UpdateData(TRUE);
+	if (SERVO::RCMD::Move == static_cast<SERVO::RCMD>(m_nRcmd + 1)) {
+		const bool bMoveToGet = (m_nSubCmd == 0); // Move to Get
+		const bool bMoveToPut = (m_nSubCmd == 1); // Move to Put
+
+		GetDlgItem(IDC_COMBO_GET_POS)->EnableWindow(bMoveToGet);
+		GetDlgItem(IDC_COMBO_GET_SLOT)->EnableWindow(bMoveToGet);
+		GetDlgItem(IDC_COMBO_PUT_POS)->EnableWindow(bMoveToPut);
+		GetDlgItem(IDC_COMBO_PUT_SLOT)->EnableWindow(bMoveToPut);
+	}
+}
+
+void CPageRobotCmd::UpdateInputUI(SERVO::RCMD cmd)
+{
+	const auto it = g_cmdFieldMap.find(cmd);
+	if (it == g_cmdFieldMap.end()) {
+		return;
+	}
+
+	const RCMDFieldMask& mask = it->second;
+	GetDlgItem(IDC_EDIT_SEQ_NO)->EnableWindow(TRUE);
+	GetDlgItem(IDC_COMBO_RCMD)->EnableWindow(TRUE);
+	GetDlgItem(IDC_RADIO_ARM_A)->EnableWindow(mask.useArm);
+	GetDlgItem(IDC_RADIO_ARM_B)->EnableWindow(mask.useArm);
+	GetDlgItem(IDC_COMBO_GET_POS)->EnableWindow(mask.useGetPos);
+	GetDlgItem(IDC_COMBO_PUT_POS)->EnableWindow(mask.usePutPos);
+	GetDlgItem(IDC_COMBO_GET_SLOT)->EnableWindow(mask.useGetSlot);
+	GetDlgItem(IDC_COMBO_PUT_SLOT)->EnableWindow(mask.usePutSlot);
+	GetDlgItem(IDC_COMBO_SUB_CMD)->EnableWindow(mask.useSubCmd);
+
+	// 鐗规畩澶勭悊 Move 绫诲瀷
+	UpdateMoveSubFields();
+}
+
+void CPageRobotCmd::OnCbnSelchangeComboRcmd()
+{
+	UpdateData(TRUE);
+	UpdateInputUI(static_cast<SERVO::RCMD>(m_nRcmd + 1));
+}
+
 void CPageRobotCmd::OnCbnSelchangeComboGetPos()
 {
 	CComboBox* pDevice = (CComboBox*)GetDlgItem(IDC_COMBO_GET_POS);
@@ -205,4 +300,9 @@
 	CComboBox* pDevice = (CComboBox*)GetDlgItem(IDC_COMBO_PUT_POS);
 	CComboBox* pSlot = (CComboBox*)GetDlgItem(IDC_COMBO_PUT_SLOT);
 	UpdateSlotList(pDevice, pSlot);
+}
+
+void CPageRobotCmd::OnCbnSelchangeComboSubCmd()
+{
+	UpdateMoveSubFields();
 }
\ No newline at end of file

--
Gitblit v1.9.3