LAPTOP-SNT8I5JK\Boounion
2025-08-26 73f93ffcc9f292e6b17c51fbf4d7cda42356a16d
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
// CControlJobDlg.cpp: 实现文件
//
 
#include "stdafx.h"
#include "Servo.h"
#include "CControlJobDlg.h"
#include "afxdialogex.h"
 
 
// CControlJobDlg 对话框
 
IMPLEMENT_DYNAMIC(CControlJobDlg, CDialogEx)
 
CControlJobDlg::CControlJobDlg(CWnd* pParent /*=nullptr*/)
    : CDialogEx(IDD_DIALOG_CONTROL_JOB, pParent)
{
    m_pControlJob = nullptr;
}
 
CControlJobDlg::~CControlJobDlg()
{
}
 
void CControlJobDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_LIST1, m_listCtrl);
}
 
 
BEGIN_MESSAGE_MAP(CControlJobDlg, CDialogEx)
    ON_WM_SIZE()
END_MESSAGE_MAP()
 
 
void CControlJobDlg::SetControlJob(SERVO::CControlJob* pControlJob)
{
    m_pControlJob = pControlJob;
}
 
// CControlJobDlg 消息处理程序
BOOL CControlJobDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();
 
 
    // label字体
    LOGFONT lf{};
    GetFont()->GetLogFont(&lf);
    lf.lfHeight = -20;
    lf.lfWeight = FW_BOLD;
    _tcscpy_s(lf.lfFaceName, _T("Arial"));
    m_fontNoJob.CreateFontIndirect(&lf);
    GetDlgItem(IDC_LABEL_NO_JOB)->SetFont(&m_fontNoJob);
 
 
    // 列表控件
    HIMAGELIST imageList = ImageList_Create(24, 24, ILC_COLOR24, 1, 1);
    ListView_SetImageList(m_listCtrl.GetSafeHwnd(), imageList, LVSIL_SMALL);
    m_listCtrl.ModifyStyle(0, LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS);
    m_listCtrl.InsertColumn(0, _T("ID"), LVCFMT_LEFT, 180);
    m_listCtrl.InsertColumn(1, _T("类型"), LVCFMT_LEFT, 120);
    m_listCtrl.InsertColumn(2, _T("状态"), LVCFMT_LEFT, 120);
    m_listCtrl.InsertColumn(3, _T("配方"), LVCFMT_LEFT, 120);
    m_listCtrl.InsertColumn(4, _T("Port / Carrier / Slot"), LVCFMT_LEFT, 180);
    m_listCtrl.InsertColumn(5, _T("描述"), LVCFMT_LEFT, 220);
 
 
    // 控件状态
    Resize();
    ShowGroup1(m_pControlJob == nullptr);
    ShowGroup2(m_pControlJob != nullptr);
    LoadData();
 
    return TRUE;  // return TRUE unless you set the focus to a control
                  // 异常: OCX 属性页应返回 FALSE
}
 
void CControlJobDlg::OnSize(UINT nType, int cx, int cy)
{
    CDialogEx::OnSize(nType, cx, cy);
    if (GetDlgItem(IDC_LIST1) == nullptr) return;
    Resize();
}
 
void CControlJobDlg::Resize()
{
    CRect rcClient, rcItem;
    CWnd* pItem;
 
    GetClientRect(rcClient);
 
 
    // 关闭按钮
    int y = rcClient.bottom - 12;
    pItem = GetDlgItem(IDCANCEL);
    pItem->GetClientRect(&rcItem);
    pItem->MoveWindow(rcClient.right - 12 - rcItem.Width(),
        y - rcItem.Height(),
        rcItem.Width(), rcItem.Height());
    y -= rcItem.Height();
    y -= 12;
 
 
    // 线
    pItem = GetDlgItem(IDC_LINE1);
    pItem->MoveWindow(12, y, rcClient.Width() - 24, 2);
    y -= 2;
 
 
    // Label
    pItem = GetDlgItem(IDC_LABEL_NO_JOB);
    pItem->GetClientRect(&rcItem);
    pItem->MoveWindow((rcClient.Width() - rcItem.Width()) / 2,
        (y - rcItem.Height()) / 2,
        rcItem.Width(), rcItem.Height());
 
 
    // ListCtrl
    pItem = GetDlgItem(IDC_LIST1);
    pItem->MoveWindow(12, 12, rcClient.Width() - 24, y - 12);
}
 
void CControlJobDlg::ShowGroup1(BOOL bShow)
{
    GetDlgItem(IDC_LABEL_NO_JOB)->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
    GetDlgItem(IDC_LINE1)->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
}
 
void CControlJobDlg::ShowGroup2(BOOL bShow)
{
    GetDlgItem(IDC_LIST1)->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
}
 
void CControlJobDlg::LoadData()
{
    m_listCtrl.DeleteAllItems();
 
    if (m_pControlJob != nullptr) {
        auto* root1 = m_listCtrl.InsertRoot({ m_pControlJob->id().c_str(), _T("ControlJob"), 
            m_pControlJob->getStateText().c_str(), _T("") });
        auto pjs = m_pControlJob->getPjs();
        for (auto pj : pjs) {
            auto* root2 = m_listCtrl.InsertChild(root1, {pj->id().c_str(),  _T("ProcessJob"),
                pj->getStateText().c_str(), pj->recipeSpec().c_str(), _T(""), _T(""), _T("") });
            auto cs = pj->carriers();
            for (auto c : cs) {
                for (auto g : c.contexts) {
                    SERVO::CGlass* pGlass = (SERVO::CGlass*)g;
                    if (pGlass != nullptr) {
                        int port, slot;
                        pGlass->getOrginPort(port, slot);
                        std::string carrier = c.carrierId + " / Port" + std::to_string(port + 1) + " / Slot" + std::to_string(slot + 1);
                        m_listCtrl.InsertChild(root2, { pGlass->getID().c_str(), _T("Glass"),
                            pGlass->getStateText().c_str(), _T(""), carrier.c_str(), _T("") });
                    }
                    else {
                        m_listCtrl.InsertChild(root2, { "Null", _T("Glass"), _T(""), _T(""), c.carrierId.c_str(), _T("") });
                    }
                }
            }
            root2->expanded = true;
        }
        root1->expanded = true;
 
 
        m_listCtrl.RebuildVisible();
    }
}