LAPTOP-SNT8I5JK\Boounion
2025-08-21 b31770cfb61272f0bcf148198d1b95ef445fe079
SourceCode/Bond/Servo/CControlJobDlg.cpp
@@ -14,7 +14,7 @@
CControlJobDlg::CControlJobDlg(CWnd* pParent /*=nullptr*/)
   : CDialogEx(IDD_DIALOG_CONTROL_JOB, pParent)
{
    m_pControlJob = nullptr;
}
CControlJobDlg::~CControlJobDlg()
@@ -29,40 +29,127 @@
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_list 已经是对话框上的 CExpandableListCtrl 成员(拖控件改类)
    m_listCtrl.ModifyStyle(0, LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS);
    m_listCtrl.InsertColumn(0, _T("名称"), LVCFMT_LEFT, 260);
    m_listCtrl.InsertColumn(0, _T("名称"), LVCFMT_LEFT, 180);
    m_listCtrl.InsertColumn(1, _T("状态"), LVCFMT_LEFT, 120);
    m_listCtrl.InsertColumn(2, _T("描述"), LVCFMT_LEFT, 260);
    m_listCtrl.InsertColumn(3, _T("配方"), LVCFMT_LEFT, 180);
    auto* root1 = m_listCtrl.InsertRoot({ _T("EFEM"), _T("Ready"), _T("Front End Module") });
    m_listCtrl.InsertChild(root1, { _T("Slot #1"), _T("OK"), _T("150mm wafer") });
    m_listCtrl.InsertChild(root1, { _T("Slot #2"), _T("Empty"), _T("") });
    auto* root2 = m_listCtrl.InsertRoot({ _T("Bonder"), _T("Run"), _T("G1+G2 Process") });
    auto* ch21 = m_listCtrl.InsertChild(root2, { _T("Job A"), _T("Proc"), _T("Step 1") });
    m_listCtrl.InsertChild(ch21, { _T("SubStep A1"), _T("Done"), _T("Align") });
    m_listCtrl.InsertChild(ch21, { _T("SubStep A2"), _T("Run"),  _T("Bond") });
    // 初始让顶层展开
    root1->expanded = true;
    root2->expanded = true;
    m_listCtrl.RebuildVisible();
    // 控件状态
    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(),
            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(),
                pj->getStateText().c_str(), _T(""), pj->recipeSpec().c_str()});
            auto cs = pj->carriers();
            for (auto c : cs) {
                m_listCtrl.InsertChild(root2, {c.carrierId.c_str(), _T(""), _T("") });
            }
            root2->expanded = true;
        }
        root1->expanded = true;
        m_listCtrl.RebuildVisible();
    }
}