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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
// ThresSetDlg.cpp : ÊµÏÖÎļþ
//
 
#include "stdafx.h"
#include "BlVisionPro.h"
#include "ThresSetDlg.h"
#include "afxdialogex.h"
#include "VisionRecipe.h"
#include "SoftVisionApp.h"
 
 
// CThresSetDlg ¶Ô»°¿ò
 
IMPLEMENT_DYNAMIC(CThresSetDlg, CDialogEx)
 
CThresSetDlg::CThresSetDlg(CWnd* pParent /*=NULL*/)
    : CDialogEx(IDD_DIALOG_THRES_SET, pParent)
{
    m_dot = NULL;
    m_eDir = DIMENSION_NONE;
}
 
CThresSetDlg::~CThresSetDlg()
{
}
 
void CThresSetDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
 
    DDX_Control(pDX, IDC_PANEL_THRES_INFO, m_PanelThres);
}
 
 
BEGIN_MESSAGE_MAP(CThresSetDlg, CDialogEx)
    ON_WM_DESTROY()
    ON_BN_CLICKED(IDC_BUTTON_THRES_SAVE, &CThresSetDlg::OnBnClickedButtonThresSave)
    ON_BN_CLICKED(IDC_BUTTON_THRES_ROI_SET, &CThresSetDlg::OnBnClickedButtonThresRoiSet)
    ON_BN_CLICKED(IDC_BUTTON_THRES_PROCESS, &CThresSetDlg::OnBnClickedButtonThresProcess)
END_MESSAGE_MAP()
 
 
// CThresSetDlg ÏûÏ¢´¦Àí³ÌÐò
 
 
BOOL CThresSetDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();
 
    // TODO:  ÔÚ´ËÌí¼Ó¶îÍâµÄ³õʼ»¯
    InitPanel();
 
    return TRUE;  // return TRUE unless you set the focus to a control
                  // Òì³£: OCX ÊôÐÔÒ³Ó¦·µ»Ø FALSE
}
 
 
BOOL CThresSetDlg::PreTranslateMessage(MSG* pMsg)
{
    // TODO: ÔÚ´ËÌí¼ÓרÓôúÂëºÍ/»òµ÷ÓûùÀà
    if (pMsg->message == WM_KEYDOWN) {
        if ((pMsg->wParam == VK_RETURN) || (pMsg->wParam == VK_ESCAPE)) {
            return TRUE;
        }
    }
 
    return CDialogEx::PreTranslateMessage(pMsg);
}
 
 
void CThresSetDlg::OnDestroy()
{
    CDialogEx::OnDestroy();
 
    // TODO: ÔÚ´Ë´¦Ìí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂë
}
 
int CThresSetDlg::setDimensionDir(DimensionDir eDir) {
    /* code */
    ChangeVisionType(eDir);
 
    return 0;
}
 
void CThresSetDlg::InitPanel(void) {
    /* code */
    m_vParams.clear();
 
    CString strText;
    //1. ID
    strText = _T("ID.");
    m_vParams.push_back(strText);
    //2. Name
    strText = _T("Name");
    m_vParams.push_back(strText);
    //3. use
    strText = _T("use");
    m_vParams.push_back(strText);
    //4. use
    strText = _T("Pos type");
    m_vParams.push_back(strText);
    //5. Min Thres
    strText = _T("Min Thres");
    m_vParams.push_back(strText);
    //6. Max Thres
    strText = _T("Max Thres");
    m_vParams.push_back(strText);
    //7. Max Thres
    strText = _T("Smooth");
    m_vParams.push_back(strText);
    //8. Pos X
    strText = _T("X Size(um)");
    m_vParams.push_back(strText);
    //9. Pos Y
    strText = _T("Y Size(um)");
    m_vParams.push_back(strText);
    //10.Result
    strText = _T("Result");
    m_vParams.push_back(strText);
 
    int nRows = 13;
    int nCols = (int)(m_vParams.size());
    int nFixRows = 1;
    int nFixCols = 0;
    int nRowIdx = 0;
    int nColIdx = 0;
 
    m_PanelThres.DeleteAllItems();
    m_PanelThres.SetVirtualMode(FALSE);
    m_PanelThres.GetDefaultCell(TRUE, FALSE)->SetBackClr(_gGridFixCellColor);
    m_PanelThres.GetDefaultCell(FALSE, TRUE)->SetBackClr(_gGridFixCellColor);
    m_PanelThres.GetDefaultCell(FALSE, FALSE)->SetBackClr(_gGridCellColor);
    m_PanelThres.SetFixedTextColor(_gGridFixFontColor);
 
    m_PanelThres.SetRowCount(nRows);
    m_PanelThres.SetColumnCount(nCols);
    m_PanelThres.SetFixedRowCount(nFixRows);
    m_PanelThres.SetFixedColumnCount(nFixCols);
 
    CFont *pFont = m_PanelThres.GetFont();
    if (pFont) {
        LOGFONT lf;
        pFont->GetLogFont(&lf);
        lf.lfItalic = 0;
        lf.lfHeight = 14;
        lf.lfWeight = FW_BOLD;
        _tcscpy_s(lf.lfFaceName, _T("Malgun Gothic"));
 
        m_PanelThres.GetDefaultCell(FALSE, TRUE)->SetFont(&lf);
        m_PanelThres.GetDefaultCell(TRUE, FALSE)->SetFont(&lf);
        m_PanelThres.GetDefaultCell(FALSE, FALSE)->SetFont(&lf);
        m_PanelThres.GetDefaultCell(TRUE, TRUE)->SetFont(&lf);
    }
 
    // Col
    for (int i = 0; i < nCols; i++) {
        if (1 == i) {
            m_PanelThres.SetColumnWidth(nColIdx, 115);
        }
        else {
            m_PanelThres.SetColumnWidth(nColIdx, 75);
        }
        strText = m_vParams[i];
        m_PanelThres.SetItemText(nRowIdx, nColIdx++, strText);
    }
 
    for (int i = 1; i < nRows; i++) {
        m_PanelThres.GetCell(i, 0)->SetState(GVIS_READONLY);
    }
}
 
void CThresSetDlg::ChangeVisionType(DimensionDir eDir) {
    /* code */
    SaveThresParam();
 
    m_eDir = eDir;
    m_dot = CVisionRecipe::getInstance()->getThresProcess(eDir);
 
    ShowThresParam();
}
 
void CThresSetDlg::ShowThresParam(void) {
    /* code */
    if (DIMENSION_NONE == m_eDir) return;
    if (NULL == m_dot) return;
 
    CString strText;
    for (int i = 0; i < 12; i++) {
        CThresDotProcess *dot = m_dot->m_dots[i];
        if (NULL == dot) continue;
 
        //1. ID
        int idRow = dot->getID();
        int idx = 0;
        strText.Format(_T("%d"), dot->getID());
        m_PanelThres.SetItemText(idRow, idx, strText);
        idx += 1;
 
        //2. Name
        strText = dot->m_strName;
        m_PanelThres.SetItemText(idRow, idx, strText);
        idx += 1;
 
        //3. USE
        strText.Format(_T("%d"), dot->m_nUse);
        m_PanelThres.SetItemText(idRow, idx, strText);
        idx += 1;
 
        //4. pose type
        strText.Format(_T("%d"), dot->m_poseType);
        m_PanelThres.SetItemText(idRow, idx, strText);
        idx += 1;
 
        //5. Min Thres
        strText.Format(_T("%d"), dot->m_minThres);
        m_PanelThres.SetItemText(idRow, idx, strText);
        idx += 1;
 
        //6. Max Thres
        strText.Format(_T("%d"), dot->m_maxThres);
        m_PanelThres.SetItemText(idRow, idx, strText);
        idx += 1;
 
        //7. smooth
        strText.Format(_T("%d"), dot->m_nSmoothSize);
        m_PanelThres.SetItemText(idRow, idx, strText);
        idx += 1;
 
        //8. Min SizeX
        strText.Format(_T("%d"), dot->m_minSizeX);
        m_PanelThres.SetItemText(idRow, idx, strText);
        idx += 1;
 
        //9. Min SizeY
        strText.Format(_T("%d"), dot->m_minSizeY);
        m_PanelThres.SetItemText(idRow, idx, strText);
        idx += 1;
 
        //10. Result
        strText.Format(_T("%.1f"), (int)(dot->m_nNgInfo.size()));
        m_PanelThres.SetItemText(idRow, idx, strText);
        idx += 1;
    }
 
    UpdateData(FALSE);
}
 
void CThresSetDlg::SaveThresParam(void) {
    /* code */
    if (DIMENSION_NONE == m_eDir) return;
    if (NULL == m_dot) return;
 
    CString strText;
    for (int i = 0; i < 12; i++) {
        CThresDotProcess *dot = m_dot->m_dots[i];
        if (NULL == dot) continue;
 
        //1. ID
        int idRow = dot->getID();
        int idx = 0;
        strText = m_PanelThres.GetItemText(idRow, idx);
        idx += 1;
 
        //2. Name
        strText = m_PanelThres.GetItemText(idRow, idx);
        dot->m_strName = strText;
        idx += 1;
 
        //3. Use
        strText = m_PanelThres.GetItemText(idRow, idx);
        dot->m_nUse = _wtoi(strText);
        idx += 1;
 
        //4. pose type
        strText = m_PanelThres.GetItemText(idRow, idx);
        dot->m_poseType = _wtoi(strText);
        idx += 1;
 
        //5.Min Thres
        strText = m_PanelThres.GetItemText(idRow, idx);
        dot->m_minThres = _wtoi(strText);
        idx += 1;
 
        //6. Max Thres
        strText = m_PanelThres.GetItemText(idRow, idx);
        dot->m_maxThres = _wtoi(strText);
        idx += 1;
 
        //7.smooth
        strText = m_PanelThres.GetItemText(idRow, idx);
        dot->m_nSmoothSize = _wtoi(strText);
        idx += 1;
 
        //8. Min SizeX
        strText = m_PanelThres.GetItemText(idRow, idx);
        dot->m_minSizeX = _wtoi(strText);
        idx += 1;
 
        //9. Max SizeX
        strText = m_PanelThres.GetItemText(idRow, idx);
        dot->m_minSizeY = _wtoi(strText);
        idx += 1;
    }
}
 
 
void CThresSetDlg::OnBnClickedButtonThresSave()
{
    // TODO: ÔÚ´ËÌí¼Ó¿Ø¼þ֪ͨ´¦Àí³ÌÐò´úÂë
    SaveThresParam();
}
 
 
void CThresSetDlg::OnBnClickedButtonThresRoiSet()
{
    // TODO: ÔÚ´ËÌí¼Ó¿Ø¼þ֪ͨ´¦Àí³ÌÐò´úÂë
    if (NULL == m_dot) return;
 
    CCellID selCell = m_PanelThres.GetFocusCell();
    int id = selCell.row;
    if (id < 1) return;
 
    CThresDotProcess *dot = m_dot->m_dots[id - 1];
    if (nullptr == dot) return;
 
    //1. ·¢ËÍÐÅÏ¢
    CSoftVisionApp::getInstance()->sendMessage(1, m_eDir);
 
    //2. »ñȡλÖÃÐÅÏ¢
    int x1 = 0;
    int y1 = 0;
    int x2 = 0;
    int y2 = 0;
    if (!CVisionRecipe::getInstance()->getFrame(x1, y1, x2, y2)) return;
 
    dot->setRegion(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
}
 
 
void CThresSetDlg::OnBnClickedButtonThresProcess()
{
    // TODO: ÔÚ´ËÌí¼Ó¿Ø¼þ֪ͨ´¦Àí³ÌÐò´úÂë
    CBlSideData *pSideData = CVisionRecipe::getInstance()->getSideData(m_eDir);
    if (nullptr != pSideData) {
        pSideData->m_vDispVisionResult.clear();
    }
 
    SaveThresParam();
    if (nullptr == m_dot) return;
 
    m_dot->execute(m_eDir);
 
    DispResult();
}
 
void CThresSetDlg::DispResult(void) {
    /* code */
    CSoftVisionApp::getInstance()->sendMessage(2, m_eDir);
 
    DispAllResult();
}
 
void CThresSetDlg::DispAllResult(void) {
    /* code */
    int nCount = 12;
    for (int i = 0; i < nCount; i++) {
        CThresDotProcess *dot = m_dot->m_dots[i];
        if (NULL == dot) continue;
        bool isDo = true;
        if (1 != dot->m_nUse)  isDo = false;
        if (!isDo) {
            int id = dot->getID();
            m_PanelThres.SetItemText(id, 9, _T("NAN"));
        }
        else {   //ÏÔʾ½á¹û
            CString strResult;
            strResult.Format(_T("%d"), (int)dot->m_nNgInfo.size());
            int id = dot->getID();
            m_PanelThres.SetItemText(id, 9, strResult);
        }
    }
 
    m_PanelThres.Invalidate(FALSE);
}