// CRobotTaskDlg.cpp: 实现文件
|
//
|
|
#include "stdafx.h"
|
#include "Servo.h"
|
#include "CRobotTaskDlg.h"
|
#include "afxdialogex.h"
|
|
|
// CRobotTaskDlg 对话框
|
|
IMPLEMENT_DYNAMIC(CRobotTaskDlg, CDialogEx)
|
|
CRobotTaskDlg::CRobotTaskDlg(CWnd* pParent /*=nullptr*/)
|
: CDialogEx(IDD_DIALOG_ROBOT_TASK, pParent)
|
{
|
m_pRobotTask = nullptr;
|
}
|
|
CRobotTaskDlg::~CRobotTaskDlg()
|
{
|
}
|
|
void CRobotTaskDlg::DoDataExchange(CDataExchange* pDX)
|
{
|
CDialogEx::DoDataExchange(pDX);
|
}
|
|
|
BEGIN_MESSAGE_MAP(CRobotTaskDlg, CDialogEx)
|
ON_WM_CTLCOLOR()
|
ON_WM_DESTROY()
|
ON_WM_SIZE()
|
ON_WM_ACTIVATE()
|
ON_BN_CLICKED(IDC_BUTTON_ABORT_TASK, &CRobotTaskDlg::OnBnClickedAbortTask)
|
END_MESSAGE_MAP()
|
|
|
// CRobotTaskDlg 消息处理程序
|
|
|
void CRobotTaskDlg::SetRobotTask(SERVO::CRobotTask* pRobotTask)
|
{
|
m_pRobotTask = pRobotTask;
|
|
|
// 各控件是否显示;
|
GetDlgItem(IDC_LABEL_NO_TASK)->ShowWindow(m_pRobotTask == nullptr ? SW_SHOW : SW_HIDE);
|
GetDlgItem(IDC_LABEL_GET_PUT)->ShowWindow(m_pRobotTask != nullptr ? SW_SHOW : SW_HIDE);
|
|
if (m_btnAbortTask.m_hWnd) {
|
m_btnAbortTask.ShowWindow(m_pRobotTask ? SW_SHOW : SW_HIDE);
|
}
|
|
if (m_pRobotTask != nullptr) {
|
using namespace SERVO;
|
|
CEquipment* pSrcEq = theApp.m_model.getMaster().getEquipment(pRobotTask->getSrcPosition());
|
CEquipment* pDstEq = theApp.m_model.getMaster().getEquipment(pRobotTask->getTarPosition());
|
|
ROBOT_CMD_PARAM& param = pRobotTask->getRobotCmdParam();
|
|
auto format_time = [](time_t t) -> CString {
|
if (t == 0) {
|
return _T("-");
|
}
|
CTime time(t);
|
return time.Format(_T("%Y-%m-%d %H:%M:%S"));
|
};
|
|
CString strDetail;
|
strDetail.Format(
|
_T("任务 ID: %s\r\n源位置: %s (P%d)\r\n目标位置: %s (P%d)\r\n")
|
_T("源槽位: Slot %d\r\n目标槽位: Slot %d\r\n手臂编号: Arm %d\r\n任务状态: %s\r\n")
|
_T("创建时间: %s\r\n取片时间: %s\r\n放片时间: %s\r\n结束时间: %s"),
|
pRobotTask->getId().c_str(),
|
pSrcEq ? pSrcEq->getName().c_str() : _T("未知"),
|
param.getPosition,
|
pDstEq ? pDstEq->getName().c_str() : _T("未知"),
|
param.putPosition,
|
param.getSlotNo,
|
param.putSlotNo,
|
param.armNo,
|
pRobotTask->getStateString(),
|
format_time(pRobotTask->getCreateTime()),
|
format_time(pRobotTask->getFetchoutTime()),
|
format_time(pRobotTask->getStoredTime()),
|
format_time(pRobotTask->getFinishTime())
|
);
|
|
SetDlgItemText(IDC_LABEL_GET_PUT, strDetail);
|
}
|
}
|
|
BOOL CRobotTaskDlg::OnInitDialog()
|
{
|
CDialogEx::OnInitDialog();
|
|
// TODO: 在此添加额外的初始化
|
// 创建“停止任务”按钮
|
m_btnAbortTask.Create(_T("停止任务"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0, 0, 100, 30), this, IDC_BUTTON_ABORT_TASK);
|
|
// 动态按钮创建后设置字体
|
if (m_fontButton.GetSafeHandle() == nullptr) {
|
m_fontButton.CreatePointFont(110, _T("微软雅黑")); // 或 "Segoe UI"
|
}
|
m_btnAbortTask.SetFont(&m_fontButton);
|
|
// 设置 LABEL 控件的字体
|
if (m_fontDetail.GetSafeHandle() == nullptr) {
|
m_fontDetail.CreatePointFont(100, _T("微软雅黑"));
|
}
|
GetDlgItem(IDC_LABEL_GET_PUT)->SetFont(&m_fontDetail);
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
// 异常: OCX 属性页应返回 FALSE
|
}
|
|
|
HBRUSH CRobotTaskDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
|
{
|
HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
|
|
// TODO: 在此更改 DC 的任何特性
|
|
// TODO: 如果默认的不是所需画笔,则返回另一个画笔
|
return hbr;
|
}
|
|
|
void CRobotTaskDlg::OnDestroy()
|
{
|
CDialogEx::OnDestroy();
|
|
// TODO: 在此处添加消息处理程序代码
|
if (m_fontButton.GetSafeHandle()) {
|
m_fontButton.DeleteObject();
|
}
|
|
if (m_fontDetail.GetSafeHandle()) {
|
m_fontDetail.DeleteObject();
|
}
|
}
|
|
void CRobotTaskDlg::OnSize(UINT nType, int cx, int cy)
|
{
|
CDialogEx::OnSize(nType, cx, cy);
|
if (GetDlgItem(IDC_LABEL_NO_TASK) == nullptr) return;
|
Resize();
|
}
|
|
void CRobotTaskDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
|
{
|
CWnd::OnActivate(nState, pWndOther, bMinimized);
|
|
if (nState == WA_INACTIVE) {
|
ShowWindow(SW_HIDE);
|
}
|
}
|
|
void CRobotTaskDlg::Resize()
|
{
|
CRect rcClient, rcItem;
|
CWnd* pItem;
|
GetClientRect(&rcClient);
|
|
pItem = GetDlgItem(IDC_LABEL_NO_TASK);
|
pItem->GetClientRect(&rcItem);
|
pItem->MoveWindow((rcClient.Width() - rcItem.Width()) / 2,
|
(rcClient.Height() - rcItem.Height()) / 2, rcItem.Width(), rcItem.Height());
|
|
pItem = GetDlgItem(IDC_LABEL_GET_PUT);
|
if (pItem && pItem->m_hWnd) {
|
const int nLabelX = 12;
|
const int nLabelY = 12;
|
const int nLabelWidth = rcClient.Width() - 24;
|
const int nLabelHeight = rcClient.Height() - 24;
|
|
pItem->MoveWindow(nLabelX, nLabelY, nLabelWidth, nLabelHeight);
|
}
|
|
// 设置“停止任务”按钮位置(右下角)
|
if (m_btnAbortTask.m_hWnd != nullptr) {
|
const int nBtnWidth = 100;
|
const int nBtnHeight = 28;
|
const int nMargin = 12;
|
|
const int nPosX = rcClient.right - nBtnWidth - nMargin;
|
const int nPosY = rcClient.bottom - nBtnHeight - nMargin;
|
|
m_btnAbortTask.MoveWindow(nPosX, nPosY, nBtnWidth, nBtnHeight);
|
}
|
}
|
|
void CRobotTaskDlg::OnBnClickedAbortTask()
|
{
|
int ret = AfxMessageBox(_T("确认要终止当前搬送任务吗?除非发生了异常,否则请不要手动终止任务!"), MB_OKCANCEL | MB_ICONEXCLAMATION);
|
if (ret != IDOK) {
|
return;
|
}
|
|
theApp.m_model.getMaster().abortCurrentTask();
|
}
|