chenluhua1980
6 天以前 d400f022161ff47f02cd0ea95a5076d0187ecd4d
SourceCode/Bond/Servo/PageRobotCmd.cpp
@@ -10,19 +10,32 @@
// CPageRobotCmd 对话框
std::map<CString, int> g_deviceSlotCount = {
   {_T("PORT 1"), 1},
   {_T("PORT 2"), 1},
   {_T("PORT 3"), 1},
   {_T("PORT 4"), 1},
   {_T("PORT 1"), 8},
   {_T("PORT 2"), 8},
   {_T("PORT 3"), 8},
   {_T("PORT 4"), 8},
   {_T("RB1"), 1},
   {_T("RB2"), 1},
   {_T("ALIGN"), 1},
   {_T("FLIP"), 1},
   {_T("VAC BAKE"), 2},
   {_T("VAC BAKE"), 4},
   {_T("BONDER1"), 2},
   {_T("BONDER2"), 2},
   {_T("POST BAKE(COOLING)"), 4},
   {_T("POST BAKE(COOLING)"), 2},
   {_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 } },
   { SERVO::RCMD::Two_Action_Exchange, { true, true, true, true, true, false } },
   { SERVO::RCMD::Command_Clear, { false, false, false, false, false, false } },
   { SERVO::RCMD::Batch_get, { false, true, false, true, false, false } },
   { SERVO::RCMD::Batch_put, { false, false, true, false, true, false } }
};
IMPLEMENT_DYNAMIC(CPageRobotCmd, CDialogEx)
@@ -55,22 +68,67 @@
   }
}
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 + 1);
   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);
   // 特殊命令处理
   const auto enRcmd = static_cast<SERVO::RCMD>(m_nRcmd + 1);
   if (SERVO::RCMD::Move == enRcmd) {
      if (m_nSubCmd == 0) {
         param.putPosition = 0;
         param.putSlotNo = 0;
      }
      else if (m_nSubCmd == 1) {
         param.getPosition = 0;
         param.getSlotNo = 0;
      }
   }
   else if (SERVO::RCMD::Batch_get == enRcmd || SERVO::RCMD::Batch_put == enRcmd) {
      param.armNo = ARM_ALL;
   }
   return param;
}
@@ -90,8 +148,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,22 +214,29 @@
   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)
{
   if (pComboDevice == nullptr || pComboSlot == nullptr) return;
   if (pComboDevice == nullptr || pComboSlot == nullptr) {
      return;
   }
   int nSelIndex = pComboDevice->GetCurSel();
   if (nSelIndex < 0) return;
   if (nSelIndex < 0) {
      return;
   }
   CString strDeviceName;
   pComboDevice->GetLBText(nSelIndex, strDeviceName);
@@ -191,6 +258,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 +314,9 @@
   CComboBox* pDevice = (CComboBox*)GetDlgItem(IDC_COMBO_PUT_POS);
   CComboBox* pSlot = (CComboBox*)GetDlgItem(IDC_COMBO_PUT_SLOT);
   UpdateSlotList(pDevice, pSlot);
}
void CPageRobotCmd::OnCbnSelchangeComboSubCmd()
{
   UpdateMoveSubFields();
}