// PageRobotCmd.cpp: 实现文件
|
//
|
|
#include "stdafx.h"
|
#include "Servo.h"
|
#include "afxdialogex.h"
|
#include "PageRobotCmd.h"
|
|
|
// CPageRobotCmd 对话框
|
|
std::map<CString, int> g_deviceSlotCount = {
|
{_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"), 4},
|
{_T("BONDER1"), 2},
|
{_T("BONDER2"), 2},
|
{_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)
|
|
CPageRobotCmd::CPageRobotCmd(CWnd* pParent /*=nullptr*/)
|
: CDialogEx(IDD_PAGE_ROBOT_CMD, pParent)
|
{
|
m_nSequenceNo = -1;
|
m_nRcmd = -1;
|
m_nArmNo = -1;
|
m_nGetPosition = -1;
|
m_nPutPosition = -1;
|
m_nGetSlotNo = -1;
|
m_nPutSlotNo = -1;
|
m_nSubCmd = -1;
|
}
|
|
CPageRobotCmd::~CPageRobotCmd()
|
{
|
}
|
|
void CPageRobotCmd::SetSequenceNo(int nSeq)
|
{
|
m_nSequenceNo = nSeq;
|
|
if (CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT_SEQ_NO)) {
|
CString str;
|
str.Format(_T("%d"), m_nSequenceNo);
|
pEdit->SetWindowText(str);
|
}
|
}
|
|
BOOL CPageRobotCmd::SetControlsEnabled(BOOL bEnable)
|
{
|
if (!IsWindow(m_hWnd)) {
|
return FALSE;
|
}
|
|
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);
|
|
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;
|
}
|
|
void CPageRobotCmd::DoDataExchange(CDataExchange* pDX)
|
{
|
CDialogEx::DoDataExchange(pDX);
|
DDX_Text(pDX, IDC_EDIT_SEQ_NO, m_nSequenceNo);
|
DDX_CBIndex(pDX, IDC_COMBO_RCMD, m_nRcmd);
|
DDX_Radio(pDX, IDC_RADIO_ARM_A, m_nArmNo);
|
DDX_CBIndex(pDX, IDC_COMBO_GET_POS, m_nGetPosition);
|
DDX_CBIndex(pDX, IDC_COMBO_PUT_POS, m_nPutPosition);
|
DDX_CBIndex(pDX, IDC_COMBO_GET_SLOT, m_nGetSlotNo);
|
DDX_CBIndex(pDX, IDC_COMBO_PUT_SLOT, m_nPutSlotNo);
|
DDX_CBIndex(pDX, IDC_COMBO_SUB_CMD, m_nSubCmd);
|
}
|
|
|
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()
|
|
|
// CPageRobotCmd 消息处理程序
|
|
BOOL CPageRobotCmd::OnInitDialog()
|
{
|
CDialogEx::OnInitDialog();
|
|
// TODO: 在此添加额外的初始化
|
// 初始化 RCMD 下拉框
|
CComboBox* pComboRcmd = (CComboBox*)GetDlgItem(IDC_COMBO_RCMD);
|
pComboRcmd->AddString(_T("Robot_home")); // 1
|
pComboRcmd->AddString(_T("Transfer")); // 2
|
pComboRcmd->AddString(_T("Move")); // 3
|
pComboRcmd->AddString(_T("Get")); // 4
|
pComboRcmd->AddString(_T("Put")); // 5
|
pComboRcmd->AddString(_T("One_Action_Exchange")); // 6
|
pComboRcmd->AddString(_T("Two_Action_Exchange")); // 7
|
pComboRcmd->AddString(_T("Command_Clear")); // 8
|
pComboRcmd->AddString(_T("Batch_get")); // 9
|
pComboRcmd->AddString(_T("Batch_put")); // 10
|
pComboRcmd->SetCurSel(0);
|
|
// 初始化设备名称下拉框(Get/Put Position)
|
CStringList eqNameList;
|
eqNameList.AddTail(_T("PORT 1")); // 1 1 UNIT
|
eqNameList.AddTail(_T("PORT 2")); // 2 1 UNIT
|
eqNameList.AddTail(_T("PORT 3")); // 3 1 UNIT
|
eqNameList.AddTail(_T("PORT 4")); // 4 1 UNIT
|
eqNameList.AddTail(_T("RB1")); // 5 1 UNIT
|
eqNameList.AddTail(_T("RB2")); // 6 1 UNIT
|
eqNameList.AddTail(_T("ALIGN")); // 7 1 UNIT
|
eqNameList.AddTail(_T("FLIP")); // 8 1 UNIT
|
eqNameList.AddTail(_T("VAC BAKE")); // 9 2 UNIT
|
eqNameList.AddTail(_T("BONDER1")); // 10 2 UNIT
|
eqNameList.AddTail(_T("BONDER2")); // 11 2 UNIT
|
eqNameList.AddTail(_T("POST BAKE(COOLING)")); // 12 4 UNIT
|
eqNameList.AddTail(_T("MEASUREMENT")); // 13 1 UNIT
|
|
CComboBox* pComboGetPos = (CComboBox*)GetDlgItem(IDC_COMBO_GET_POS);
|
CComboBox* pComboPutPos = (CComboBox*)GetDlgItem(IDC_COMBO_PUT_POS);
|
CComboBox* pComboGetSlot = (CComboBox*)GetDlgItem(IDC_COMBO_GET_SLOT);
|
CComboBox* pComboPutSlot = (CComboBox*)GetDlgItem(IDC_COMBO_PUT_SLOT);
|
|
for (POSITION pos = eqNameList.GetHeadPosition(); pos != NULL;) {
|
CString item = eqNameList.GetNext(pos);
|
pComboGetPos->AddString(item);
|
pComboPutPos->AddString(item);
|
}
|
|
pComboGetPos->SetCurSel(0);
|
pComboPutPos->SetCurSel(0);
|
UpdateSlotList(pComboGetPos, pComboGetSlot);
|
UpdateSlotList(pComboPutPos, pComboPutSlot);
|
|
// 初始化 Sub CMD 下拉框
|
CComboBox* pComboSubCmd = (CComboBox*)GetDlgItem(IDC_COMBO_SUB_CMD);
|
pComboSubCmd->AddString(_T("1: Get Ready"));
|
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;
|
}
|
|
int nSelIndex = pComboDevice->GetCurSel();
|
if (nSelIndex < 0) {
|
return;
|
}
|
|
CString strDeviceName;
|
pComboDevice->GetLBText(nSelIndex, strDeviceName);
|
|
int nMaxSlot = 1; // 默认槽位数
|
auto it = g_deviceSlotCount.find(strDeviceName);
|
if (it != g_deviceSlotCount.end()) {
|
nMaxSlot = it->second;
|
}
|
|
// 清空并添加槽号
|
pComboSlot->ResetContent();
|
for (int i = 1; i <= nMaxSlot; ++i) {
|
CString str;
|
str.Format(_T("%d"), i);
|
pComboSlot->AddString(str);
|
}
|
|
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);
|
CComboBox* pSlot = (CComboBox*)GetDlgItem(IDC_COMBO_GET_SLOT);
|
UpdateSlotList(pDevice, pSlot);
|
|
GetRobotCmdParam();
|
}
|
|
void CPageRobotCmd::OnCbnSelchangeComboPutPos()
|
{
|
CComboBox* pDevice = (CComboBox*)GetDlgItem(IDC_COMBO_PUT_POS);
|
CComboBox* pSlot = (CComboBox*)GetDlgItem(IDC_COMBO_PUT_SLOT);
|
UpdateSlotList(pDevice, pSlot);
|
}
|
|
void CPageRobotCmd::OnCbnSelchangeComboSubCmd()
|
{
|
UpdateMoveSubFields();
|
}
|