mrDarker
2025-06-21 173172803858304548943d530d59be6d93136841
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// 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)
    ON_BN_CLICKED(IDC_BUTTON_RESTORE, &CRobotTaskDlg::OnBnClickedRestore)
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_btnRestore.m_hWnd) {
        m_btnRestore.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(ACTION_TRANSFER);
 
        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);
    m_btnRestore.Create(_T("撤回"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0, 0, 100, 30), this, IDC_BUTTON_RESTORE);
 
    // 动态按钮创建后设置字体
    if (m_fontButton.GetSafeHandle() == nullptr) {
        m_fontButton.CreatePointFont(110, _T("微软雅黑")); // 或 "Segoe UI"
    }
    m_btnAbortTask.SetFont(&m_fontButton);
    m_btnRestore.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);
    }
 
    // 设置“停止任务”按钮位置(右下角)
    const int nBtnWidth = 100;
    const int nBtnHeight = 28;
    const int nMargin = 12;
    const int nMargin2 = 8;
    const int x = rcClient.right - nBtnWidth - nMargin;
    int y = rcClient.bottom - nMargin;
    if (m_btnAbortTask.m_hWnd != nullptr) {
        m_btnAbortTask.MoveWindow(x, y - nBtnHeight, nBtnWidth, nBtnHeight);
        y -= nBtnHeight;
        y -= nMargin2;
    }
 
    // 设置“停止任务”按钮位置(右下角)
    if (m_btnRestore.m_hWnd != nullptr) {
        m_btnRestore.MoveWindow(x, y - nBtnHeight, nBtnWidth, nBtnHeight);
    }
}
 
void CRobotTaskDlg::OnBnClickedAbortTask()
{
    int ret = AfxMessageBox(_T("确认要终止当前搬送任务吗?除非发生了异常,否则请不要手动终止任务!"), MB_OKCANCEL | MB_ICONEXCLAMATION);
    if (ret != IDOK) {
        return;
    }
 
    theApp.m_model.getMaster().abortCurrentTask();
}
 
void CRobotTaskDlg::OnBnClickedRestore()
{
    int ret = AfxMessageBox(_T("物料将会被搬运回原位置,确认要回撤当前任务吗?除非发生了异常,否则请不要回撤任务!"), MB_OKCANCEL | MB_ICONEXCLAMATION);
    if (ret != IDOK) {
        return;
    }
 
    theApp.m_model.getMaster().restoreCurrentTask();
}