LAPTOP-SNT8I5JK\Boounion
2025-09-17 4ef35bf238fc6f7217e4b6de4aee37192ec503ec
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
// CPjPage1.cpp: 实现文件
//
 
#include "stdafx.h"
#include "Servo.h"
#include "CCjPage2.h"
#include "afxdialogex.h"
#include "RecipeManager.h"
 
 
// CPjPage1 对话框
 
IMPLEMENT_DYNAMIC(CCjPage2, CCjPageBase)
 
CCjPage2::CCjPage2(CWnd* pParent /*=nullptr*/)
    : CCjPageBase(IDD_CJ_PAGE2, pParent)
{
 
}
 
CCjPage2::~CCjPage2()
{
}
 
void CCjPage2::DoDataExchange(CDataExchange* pDX)
{
    CCjPageBase::DoDataExchange(pDX);
}
 
 
BEGIN_MESSAGE_MAP(CCjPage2, CCjPageBase)
    ON_WM_DESTROY()
    ON_EN_CHANGE(IDC_EDIT_PJ_ID, &CCjPage2::OnEnChangeEditPjId)
    ON_CBN_SELCHANGE(IDC_COMBO_RECIPE, &CCjPage2::OnCbnSelchangeComboRecipe)
END_MESSAGE_MAP()
 
 
// CPjPage1 消息处理程序
 
 
void CCjPage2::OnSetContext(void* pContext)
{
    UpdatePjData();
}
 
BOOL CCjPage2::OnInitDialog()
{
    CCjPageBase::OnInitDialog();
 
 
    // 若你的资源里有一个占位的 ListCtrl(比如 IDC_LIST1),这里做子类化:
    m_selector.SubclassDlgItem(IDC_LIST_SELECTOR, this);
 
    // 初始化:4 列 × 8 行
    m_selector.InitGrid(4, 8);
    m_selector.SetColumnWidths(100, 180);
    m_selector.SetRowHeight(36);
 
    // 设置列信息
    m_selector.SetPortInfo(0, _T("Port 1"), _T("Carrier A"));
    m_selector.SetPortInfo(1, _T("Port 2"), _T("Carrier B"));
    m_selector.SetPortInfo(2, _T("Port 3"), _T("Carrier C"));
    m_selector.SetPortInfo(3, _T("Port 4"), _T("Carrier D"));
 
    // 设置部分 Glass(核心ID固定)
    m_selector.SetSlotGlass(0, 0, TRUE, _T("001"), CCarrierSlotSelector::MAT_G1);
    m_selector.SetSlotGlass(0, 1, TRUE, _T("002"), CCarrierSlotSelector::MAT_G1);
    m_selector.SetSlotGlass(0, 3, TRUE, _T("004"), CCarrierSlotSelector::MAT_G1);
 
    m_selector.SetSlotGlass(1, 0, TRUE, _T("101"), CCarrierSlotSelector::MAT_G2);
    m_selector.SetSlotGlass(1, 1, TRUE, _T("102"), CCarrierSlotSelector::MAT_G2);
    m_selector.SetSlotGlass(1, 2, TRUE, _T("103"), CCarrierSlotSelector::MAT_G2);
    m_selector.SetSlotGlass(1, 5, TRUE, _T("106"), CCarrierSlotSelector::MAT_G2);
    m_selector.SetSlotGlass(1, 7, TRUE, _T("108"), CCarrierSlotSelector::MAT_G2);
 
    m_selector.SetSlotGlass(2, 5, TRUE, _T("206"), CCarrierSlotSelector::MAT_G1);
    m_selector.SetSlotGlass(2, 6, TRUE, _T("207"), CCarrierSlotSelector::MAT_G1);
    m_selector.SetSlotGlass(2, 7, TRUE, _T("208"), CCarrierSlotSelector::MAT_G1);
 
    m_selector.SetSlotGlass(3, 0, TRUE, _T("301"), CCarrierSlotSelector::MAT_G1);
 
    // 锁定 Port 1(示例)
    m_selector.SetPortAllocated(0, TRUE, _T("ProcessJob 1"));
 
 
    UpdatePjData();
 
        
        ;
    return TRUE;  // return TRUE unless you set the focus to a control
                  // 异常: OCX 属性页应返回 FALSE
}
 
void CCjPage2::OnDestroy()
{
    CCjPageBase::OnDestroy();
 
    // TODO: 在此处添加消息处理程序代码
}
 
void CCjPage2::Resize()
{
    CCjPageBase::Resize();
    /*
    CWnd* pItem;
    CRect rcClient, rcItem;
    GetClientRect(&rcClient);
    pItem = GetDlgItem(IDC_LABEL_TITLE);
    pItem->GetWindowRect(&rcItem);
    pItem->MoveWindow(12, 8, rcClient.Width() - 24, rcItem.Height());
    */
}
 
void CCjPage2::OnApply() 
{
    //SERVO::CProcessJob*
    if (m_pContext == nullptr) return;
    SERVO::CProcessJob* pProcessJob = (SERVO::CProcessJob*)m_pContext;
 
    // 更新名称
    char szBuffer[256];
    GetDlgItemText(IDC_EDIT_PJ_ID, szBuffer, 256);
    pProcessJob->setId(std::string(szBuffer));
 
    // 更新配方
    CString strRecipe;
    CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_RECIPE);
    int idx = pComboBox->GetCurSel();
    if (idx >= 0) {
        pComboBox->GetLBText(idx, strRecipe);
#ifdef UNICODE
        CT2A utf8Str(strRecipe, CP_UTF8);
        std::string recipe(utf8Str);
#else
        std::string recipe(strRecipe.GetString());
#endif
 
        pProcessJob->setRecipe(SERVO::RecipeMethod::NoTuning, recipe);
    }
 
 
 
 
    ContentChanged(1);
}
 
void CCjPage2::UpdatePjData()
{
    m_bContentChangedLock = TRUE;
 
    CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_RECIPE);
    pComboBox->ResetContent();
    std::vector<std::string> vecRecipe = RecipeManager::getInstance().getAllPPID();
    for (const auto& recipe : vecRecipe) {
        pComboBox->AddString(CString(recipe.c_str()));
    }
 
    if (m_pContext) {
        SERVO::CProcessJob* pProcessJob = (SERVO::CProcessJob*)m_pContext;
        SetDlgItemText(IDC_EDIT_PJ_ID, pProcessJob->id().c_str());
        int idx = pComboBox->FindStringExact(-1, pProcessJob->recipeSpec().c_str());
        if (idx != CB_ERR) pComboBox->SetCurSel(idx);
    }
 
    m_bContentChangedLock = FALSE;
}
 
void CCjPage2::OnEnChangeEditPjId()
{
    ContentChanged(0);
}
 
void CCjPage2::OnCbnSelchangeComboRecipe()
{
    ContentChanged(0);
}