LWQ
2025-07-14 aef42eef51d1b86ac7217a88ce17c5156c30fe6d
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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
 
// MainFrm.cpp : CMainFrame Å¬·¡½ºÀÇ ±¸Çö
//
 
#include "stdafx.h"
#include "EdgeInspector_App.h"
#include "MainFrm.h"
#include "HardwareSettings.h"
#include "io.h"
#include "MulticamControl.h"
#include <TlHelp32.h>
#include <Shlwapi.h>
 
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
 
// CMainFrame
#define TOTAL_WINDOW_SIZE_X        1920
#define TOTAL_WINDOW_SIZE_Y        1040
 
#define ID_TIMER_INITDONE        1001
 
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
 
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
    ON_WM_CREATE()
    ON_WM_TIMER()
    ON_WM_GETMINMAXINFO()
END_MESSAGE_MAP()
 
// CMainFrame »ý¼º/¼Ò¸ê
 
CMainFrame::CMainFrame()
{
    m_pView = NULL;
    m_bManualProcessStart = FALSE;    
 
}
 
CMainFrame::~CMainFrame()
{
    
}
 
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
        return -1;
         
    //new CDisplayMessage(static_cast<IDisplyMessage2Parent*>(this));
    //new CStatusMonitor();
 
    g_pLog->SetDM2P(static_cast<IDisplyMessage2Parent*>(this));
 
    ModifyStyle(WS_CAPTION, NULL);
 
    SetMenu(NULL);    
 
    return 0;
}
 
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
    if( !CFrameWnd::PreCreateWindow(cs) )
        return FALSE;
 
    cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE;
    cs.style = cs.style & ~FWS_ADDTOTITLE;
    cs.x = 0;
    cs.y = 0;
    cs.cx = TOTAL_WINDOW_SIZE_X;
    cs.cy = TOTAL_WINDOW_SIZE_Y;
    cs.lpszName = _T("EdgeInspector");
    this->SetTitle(_T("EdgeInspector"));
 
    return TRUE;
}
 
// CMainFrame ¸Þ½ÃÁö Ã³¸®±â
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{
    // TODO: ¿©±â¿¡ ¸Þ½ÃÁö Ã³¸®±â Äڵ带 Ãß°¡ ¹×/¶Ç´Â ±âº»°ªÀ» È£ÃâÇÕ´Ï´Ù.
    //CFrameWndEx::OnGetMinMaxInfo(lpMMI);
 
    lpMMI->ptMinTrackSize.x = TOTAL_WINDOW_SIZE_X;
    lpMMI->ptMinTrackSize.y = TOTAL_WINDOW_SIZE_Y;
 
    lpMMI->ptMaxTrackSize.x = TOTAL_WINDOW_SIZE_X;
    lpMMI->ptMaxTrackSize.y = TOTAL_WINDOW_SIZE_Y;
}
 
// CMainFrame Áø´Ü
 
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
    CFrameWnd::AssertValid();
}
 
void CMainFrame::Dump(CDumpContext& dc) const
{
    CFrameWnd::Dump(dc);
}
#endif //_DEBUG
 
 
// CMainFrame ¸Þ½ÃÁö Ã³¸®±â
void CMainFrame::SetView(CEdgeInspector_AppView    *pView)
{
    m_pView = pView;
    if(NULL != m_pView)
    {
        m_pView->CreateChildView();
        m_pView->SetV2M(static_cast<IViewInterface2Parent*>(this));        
    }
 
    m_splash.SetBitmap(IDB_SPLASH);
    m_splash.SetTransparentColor(RGB(128,128,128));
 
    SetTimer(ID_TIMER_INITDONE, 500, NULL);    
}
 
void CMainFrame::OnTimer(UINT_PTR nIDEvent) 
{        
    switch(nIDEvent)
    {
    case ID_TIMER_INITDONE:
        KillTimer(ID_TIMER_INITDONE);
        Timer_InitDone();
        break;            
    }
 
    CFrameWnd::OnTimer(nIDEvent);
}
 
void CMainFrame::KillProcessByName(LPCTSTR lpProcessName)
{
    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if (hSnapshot == INVALID_HANDLE_VALUE) return;
 
    PROCESSENTRY32 pe = { sizeof(PROCESSENTRY32) };
    if (Process32First(hSnapshot, &pe)) {
        do {
            if (_tcsstr(_tcslwr(pe.szExeFile), _tcslwr(_tcsdup(lpProcessName))) != NULL) {
                HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pe.th32ProcessID);
                if (hProcess) {
                    TerminateProcess(hProcess, 0);
                    CloseHandle(hProcess);
                }
            }
        } while (Process32Next(hSnapshot, &pe));
    }
    CloseHandle(hSnapshot);
}
 
void CMainFrame::Timer_InitDone()
{
    g_pLog->DisplayMessage(_T("** Run Inspector **[%s %s]"), _T(__DATE__), _T(__TIME__));
 
#ifndef _DEBUG
    SetSlashText(GLOBAL_DEFINE::emShow, _T(""), RGB(0,0,0));
#endif // _DEBUG
 
    SetSlashText(GLOBAL_DEFINE::emText, _T("System Initializing .."), RGB(0,0,0));
 
    ReadHardwareSetting();    
 
    SetSlashText(GLOBAL_DEFINE::emText, _T("Read Hardware Setting Complete"), RGB(0,0,0));
 
    g_pBase->ReadInspectConfigFile(INSPECTBASE_FILENAME,m_HardwareRecipe.GetCameraCount());
    
    SetSlashText(GLOBAL_DEFINE::emText, _T("Read Inspect Confie Complete"), RGB(0,0,0));
 
    InterfaceInit();
 
    CString            strRecipeName;    
 
    GetRegistryRcpName(strRecipeName);
    if(LoadGlassRecipe(strRecipeName,TRUE) == TRUE)
    {
        SetRegistryRcpName(strRecipeName);        
    }    
    
    ApplyViewRecipeSettingss();
 
    SetSlashText(GLOBAL_DEFINE::emText, _T("Read Recipe Complete"), RGB(0,0,0));
 
    g_pLog->DisplayMessage(_T("Start Process Completed"));
 
    Sleep(1000);
 
    HINSTANCE hViewer = ShellExecute(NULL, _T("open"), _T("C:\\EdgeInspector_App\\LogView.exe"), NULL, NULL, SW_SHOWNORMAL);
 
    hViewer = ShellExecute(NULL, _T("open"), _T("C:\\EdgeInspector_App\\PLCConnector.exe"), NULL, NULL, SW_SHOWNORMAL);
 
    // ly, 2025.07.07
    CString strExePath = m_HardwareRecipe.m_strCopyToolExePath;
    CString strConfigPath = m_HardwareRecipe.m_strCopyToolConfigPath;
    if (PathFileExists(strExePath) && PathFileExists(strConfigPath)) {
        LPCTSTR pszExeName = PathFindFileName(strExePath);
 
        // È¥µô .exe£¬²¢É±ËÀ½ø³Ì
        TCHAR szNameWithoutExt[MAX_PATH] = { 0 };
        _tcscpy_s(szNameWithoutExt, pszExeName);
        PathRemoveExtension(szNameWithoutExt);
        KillProcessByName(szNameWithoutExt);
 
        if (TRUE == m_HardwareRecipe.m_bEnableAutoCopy) {
            ShellExecute(NULL, _T("open"), strExePath, strConfigPath, NULL, SW_SHOWNORMAL);
            g_pLog->DisplayMessage(_T("Started Copy Tool process."));
        }
    }
    else {
        g_pLog->DisplayMessage(_T("Copy Tool executable or config file not found."));
    }
 
    strExePath = m_HardwareRecipe.m_strDeleteToolExePath;
    strConfigPath = m_HardwareRecipe.m_strDeleteToolConfigPath;
    if (PathFileExists(strExePath) && PathFileExists(strConfigPath)) {
        LPCTSTR pszExeName = PathFindFileName(strExePath);
 
        // È¥µô .exe£¬²¢É±ËÀ½ø³Ì
        TCHAR szNameWithoutExt[MAX_PATH] = { 0 };
        _tcscpy_s(szNameWithoutExt, pszExeName);
        PathRemoveExtension(szNameWithoutExt);
        KillProcessByName(szNameWithoutExt);
 
        if (TRUE == m_HardwareRecipe.m_bEnableAutoDelete) {
            ShellExecute(NULL, _T("open"), strExePath, strConfigPath, NULL, SW_SHOWNORMAL);
            g_pLog->DisplayMessage(_T("Started Delete Tool process."));
        }
    }
    else {
        g_pLog->DisplayMessage(_T("Delete Tool executable not found."));
    }
 
    SetSlashText(GLOBAL_DEFINE::emHide, _T(""), RGB(0,0,0));
}
 
BOOL CMainFrame::GetRegistryRcpName(CString& strRecipe)
{
    CConfig RegiSetting;
 
    RegiSetting.SetRegiConfig(SHCU, KEY_BASIC, NULL, Registery_mode);
    RegiSetting.GetItemValue(_T("RECIPE_CURRENT"), strRecipe);
    
    return TRUE;
}
 
void CMainFrame::SetRegistryRcpName(CString strRecipe)
{
    CConfig RegiSetting;
 
    RegiSetting.SetRegiConfig(SHCU, KEY_BASIC, NULL, Registery_mode);
    RegiSetting.SetItemValue(_T("RECIPE_CURRENT"), (TCHAR*)(LPCTSTR)strRecipe);    
}
 
void CMainFrame::CommandExitButtonClick()
{
    DestroyThread();    
 
    AfxGetMainWnd()->PostMessage(WM_COMMAND,ID_APP_EXIT,0);        
}
 
 
void CMainFrame::MapDefect_ReqDefectImage(CDefect* pDefect,int nGlassDefectIdx)
{
 
}
 
CDefect *CMainFrame::ListDefect_ReqDefectImage(CDefect* pDefect,int nGlassDefectIdx)
{
    if(pDefect == NULL || nGlassDefectIdx < 0)
    {
        g_pLog->DisplayMessage(_T("List Request Defect Image Fail : Data is Null"));
        return NULL;
    }
 
    if(pDefect->m_DefectInfo.m_nCamID < 0 || pDefect->m_DefectInfo.m_nCamID >= m_HardwareRecipe.GetCameraCount())
        return NULL;
 
    //return m_pInspectSequence->GetDefectData(pDefect->m_nCameraID,pDefect->m_nDefectIdx);
 
    return NULL;
}
 
void CMainFrame::IV2M_InitView(Init_View_Command eVew)
{
    m_GlassData.ResetGlass();
 
    m_pView->InitView(eVew);    
}
 
void CMainFrame::ApplyViewRecipeSettingss()
{
    if(m_pView == NULL)
        return;
 
    m_pView->SetHardwareSetting(&m_HardwareRecipe);
    m_pView->SetRecipeSettings(&m_GlassRecipe);
    m_pView->SetGlassData(&m_GlassData);
    m_pView->SetTransferData(&m_TransferData);
}
 
BOOL CMainFrame::IV2M_RecipeChange(CString strRecipe)
{
    m_strReserveRecipe.Empty();
 
    if(!IsScanNow())        // °Ë»ç Áß
    {                
        if(LoadGlassRecipe(strRecipe,TRUE) == TRUE)
        {
            SetRegistryRcpName(strRecipe);
            g_pLog->DisplayMessage(_T("Apply Recipe by RecipeView Success : [%s]"), strRecipe);
            //ApplyViewRecipeSettingss();
        }
        else
        {
            g_pLog->DisplayMessage(_T("Apply Recipe by RecipeView Fail: [%s]"), strRecipe);
        }
    }
    else
    {
        g_pLog->DisplayMessage(_T("Reserve Recipe application by RecipeView : [%s]"), strRecipe);
        m_strReserveRecipe = strRecipe;
    }
 
    return TRUE;
}
 
BOOL CMainFrame::IV2M_SaveFullImage(CString strPath,int iSide,CPoint ptStart,int nLength)
{
    if(IsScanNow())
    {
        g_pLog->DisplayMessage(_T("Doing Inspection"));
        return TRUE;
    }
 
    SetSlashText(GLOBAL_DEFINE::emShow, _T(""), RGB(0,0,0));
 
    //SetSlashText(GLOBAL_DEFINE::emText, _T("Image Save Start"), RGB(0,0,0));
 
    BOOL bRet = SaveFullImage(strPath,iSide,ptStart,nLength);
 
    SetSlashText(GLOBAL_DEFINE::emText, strPath, RGB(0,0,0));
 
    SetSlashText(GLOBAL_DEFINE::emHide, _T(""), RGB(0,0,0));
 
    return bRet;
}
 
BOOL CMainFrame::IV2M_InspectionProcessAll(int iProceMode)
{
    if(IsScanNow())
    {
        g_pLog->DisplayMessage(_T("Doing Inspection"));
        return FALSE;
    }
 
    switch(iProceMode)
    {
    case 0: g_pBase->m_eProcessMode = PROC_MODE_SIMULATION_SIDELONG; break;
    case 1: g_pBase->m_eProcessMode = PROC_MODE_SIMULATION_SIDESHORT; break;
    case 2: g_pBase->m_eProcessMode = PROC_MODE_SIMULATION_ALL; break;
    }
 
    AfxBeginThread(ManualInspectProcess,this);
 
    return TRUE;
}
 
UINT CMainFrame::ManualInspectProcess(LPVOID pParam)
{
    CMainFrame        *pMain = (CMainFrame *)pParam;
 
    pMain->SetInspectionEnd();
 
    DWORD dwTick = GetTickCount();
    DWORD dwWaitTick;
    DWORD dwWaitTime = 3000;
 
    while(TRUE)
    {
        Sleep(0);
 
        dwWaitTick = GetTickCount() - dwTick;
        if(dwWaitTime < dwWaitTick)
            break;
 
        if(pMain->IsScanNow())        
            continue;    
        else
            break;
    }
 
    if(pMain->IsScanNow())
    {
        g_pLog->DisplayMessage(_T("Doing Inspection"));
        return 0;
    }
 
    DWORD        tTime = GetTickCount();
    int            iScan = 0;
    int            iScanEnd = 0;
    int            iCam = 0;
    double        dOneScanTime = pMain->m_GlassRecipe.m_RecieParm.m_dOneScanTime_sec;    
    
    pMain->InitLoadingProcess();    
    pMain->m_GlassData.SetScanStart(TRUE);
    pMain->m_GlassData.SetLoadingTime();
    pMain->m_GlassData.SetScanStartTime();    
          
    g_pBase->m_strRecipeName = pMain->m_GlassRecipe.GetRecipeName();
    g_pBase->m_strLoadingDay = pMain->m_GlassData.GetLoadingDayFileName();
    g_pBase->m_strLoadingTime = pMain->m_GlassData.GetLoadingTimeFileName();
 
    g_pBase->m_strHPanelID = _T("Manual");
 
    switch(g_pBase->m_eProcessMode)
    {
    case PROC_MODE_SIMULATION_ONESIDE:
        {                
            pMain->m_GlassData.SetScanStartCount(1);
            int iCam = pMain->m_HardwareRecipe.GetCameraIndexToDimension(pMain->m_eManualInspectSide);
            int iScan = pMain->m_HardwareRecipe.GetScanToDimension(pMain->m_eManualInspectSide);
            
            pMain->SendGlassRecipe();             
             pMain->ScanStartGrabManual(iCam,iScan);            
             pMain->ScanStartManual(iCam,iScan, TRUE);    
        }
        break;
    case PROC_MODE_SIMULATION_SIDESHORT:
        {            
            pMain->m_GlassData.SetScanStartCount(MAX_CAMERA_COUNT);
            pMain->SendGlassRecipe();
            for(iCam=0;iCam<MAX_CAMERA_COUNT;iCam++)
            {                    
                pMain->ScanStartGrabManual(iCam,0);
                pMain->ScanStartManual(iCam,0);                        
            }
        }
        break;
    case PROC_MODE_SIMULATION_SIDELONG:
        {                
            pMain->m_GlassData.SetScanStartCount(MAX_CAMERA_COUNT);
            pMain->SendGlassRecipe();
            for(iCam=0;iCam<MAX_CAMERA_COUNT;iCam++)
            {                    
                pMain->ScanStartGrabManual(iCam,1);
                pMain->ScanStartManual(iCam,1);                
            }
        }
        break;
    case PROC_MODE_SIMULATION_ALL:
        {
            g_pLog->DisplayMessage(_T("Simulation Full "));                        
            pMain->m_GlassData.SetScanStartCount(MAX_DIMENSION_COUNT);
            pMain->SendGlassRecipe();
            for(iCam=0;iCam<MAX_CAMERA_COUNT;iCam++)
            {                
                pMain->ScanStartGrabManual(iCam,0);
                pMain->ScanStartGrabManual(iCam,1);
            }
 
            if(pMain->m_pThread_CheckSequence != NULL)        
            {
                double dOneScanTime = pMain->m_GlassRecipe.m_RecieParm.m_dOneScanTime_sec;
                
                pMain->m_pThread_CheckSequence->AddCheckSeqMSG(CHECKSEQ_GLASS_INSPECTION_OVERTIME,(int)(dOneScanTime* 1000.),pMain->m_HardwareRecipe.GetScanCount()-1);    
 
                g_pLog->DisplayMessage(_T("Simulation Time Out Set : %.1f"),dOneScanTime);
            }
 
            for(iCam=0;iCam<MAX_CAMERA_COUNT;iCam++)
            {
                pMain->ScanStartManual(iCam,0);                        
            }            
 
            DWORD        sTime = GetTickCount();
            while(TRUE)
            {
                if(pMain->m_GlassData.GetScanEnd(0) == TRUE)
                    break;
 
                if(GetTickCount() - sTime >= 5000)
                    break;
            
                Sleep(10);
            }
 
            for(iCam=0;iCam<MAX_CAMERA_COUNT;iCam++)
            {
                pMain->ScanStartManual(iCam,1);                        
            }    
        }
        break;
    }
    
    return 0;
}
 
BOOL CMainFrame::IV2M_InspectionProcess(DimensionDir eDim)
{
    if(IsScanNow())
    {
        g_pLog->DisplayMessage(_T("Doing Inspection"));
        return FALSE;
    }
 
    g_pBase->m_eProcessMode = PROC_MODE_SIMULATION_ONESIDE;
    m_eManualInspectSide = eDim;
 
    // Àӽ÷Π¸·À½
    //return TRUE;
 
    AfxBeginThread(ManualInspectProcess,this);
 
    return TRUE;
}
 
void CMainFrame::MLight_OnOff(int iCon,int iCh,BOOL bValue)
{
    //     if(IsScanNow())
    //     {
    //         g_pLog->DisplayMessage(_T("Doing Inspection"));
    //         return;
    //     }
 
    if(m_pLightManager == NULL)
        return;
 
    m_pLightManager->LampTurnOnOff(iCon, iCh, bValue);
}
 
BOOL CMainFrame::MLight_SetLightControlValue(int iCon,int iCh, int nValue, BOOL bRef, int nScanIdx, BOOL bAdjLight)
{
    //     if(IsScanNow())
    //     {
    //         g_pLog->DisplayMessage(_T("Doing Inspection"));
    //         return TRUE;
    //     }
 
    if(m_pLightManager == NULL)
        return FALSE;
 
    BOOL    bRet = m_pLightManager->SetLightControlValue(iCon, iCh, nValue);
 
    return bRet;
}
 
BOOL CMainFrame::IV2M_SetLiveGrabCommand(DimensionDir eDim,BOOL bStop)
{
    if (IsScanNow())
    {
        g_pLog->DisplayMessage(_T("Doing Inspection"));
        return TRUE;
    }
 
    // 4/13 MiniLED
    if(eDim < DIMENSION_A || eDim > DIMENSION_D)
        return FALSE;
 
    g_pLog->DisplayMessage(_T("Live Cam %d Start : Main"),(int)eDim);    
 
    BOOL bRet = SetLiveGrabCommand(eDim,bStop);
 
    g_pLog->DisplayMessage(_T("Live Cam %d End : Main"),(int)eDim);
 
    return bRet;
}
 
LPBYTE CMainFrame::IV2M_GetGrabBufferByDimension(DimensionDir eDim,int iVline)
{
    //     if(IsScanNow())
    //     {
    //         g_pLog->DisplayMessage(_T("Doing Inspection"));
    //         return NULL;
    //     }    
 
    if(eDim < DIMENSION_A || eDim > DIMENSION_D_DN)
        return NULL;
    if(iVline < 0)
        return NULL;
 
    return GetGrabBuffer(eDim,iVline);
}
 
void CMainFrame::IV2M_LoadImageFullFile(int iSide, CGlass_Data *pGlassData, std::function<void(BYTE)> _Func)
{
    if(IsScanNow())
    {
        g_pLog->DisplayMessage(_T("Doing Inspection"));
        return;
    }
 
    if(m_bManualProcessStart == TRUE)
    {
        g_pLog->DisplayMessage(_T("Doing Manual Process"));
        return;
    }
 
    m_bManualProcessStart = TRUE;
 
    CString strPath,strGlassID;
    TCHAR szFilter[] = _T("Image Files(*.bmp;,*.jpg) |*.bmp;*.jpg;|All File (*.*)| *.*||");
    CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter,AfxGetMainWnd());
 
    int nStartY = 0, nHeight = 0;
    if(dlg.DoModal() == IDOK)
    {
 
#ifndef _DEBUG
        SetSlashText(GLOBAL_DEFINE::emShow, _T(""), RGB(0,0,0));
#endif
 
        SetSlashText(GLOBAL_DEFINE::emText, _T("Image Loading Start"), RGB(0,0,0));
 
        if(iSide > -1)
        {
 
            CString strGlsID, strTmp , strExt;
 
            strExt     = dlg.GetFileExt();
            strGlsID = dlg.GetFileName();
            strGlsID = strGlsID.Left(strGlsID.Find(_T("__")));            
 
            g_pBase->m_strHPanelID = strGlsID;
            strTmp = dlg.GetPathName();
            strTmp = strTmp.Left( strTmp.ReverseFind(_T('\\')));
 
            char str_filename[200];
 
            for(int i = 0 ; i < 6 ; i++)
            {
                strPath.Format(_T("%s\\%s__%s_%d.%s"),strTmp,strGlsID,PANEL_SIDE[iSide],i,strExt);
                USES_CONVERSION;                    
                sprintf_s(str_filename, "%s", W2A(strPath));
                if(access(str_filename, 0) == 0)
                {
                    nHeight = LoadFullImage(strPath,iSide,nStartY);
                    if(nHeight == -1)
                        break;
                    nStartY += nHeight;
                }
                else
                    break;
            }
 
            if(pGlassData != NULL)
            {
                CSide_Data* pSideData = pGlassData->GetSideData((DimensionDir)iSide);
                if(pSideData != NULL)
                {
                    pSideData->m_nGlassStartLine = 0;
                    pSideData->m_nGlassEndLine = nStartY;
                }
 
            }
 
            if(_Func != nullptr)
            {
                _Func(iSide);
            }            
        }
        else
        {
 
            CString strGlsID, strTmp , strExt;
 
            strExt     = dlg.GetFileExt();
            strGlsID =dlg.GetFileName();
            strGlsID = strGlsID.Left(strGlsID.Find(_T("__")));
            g_pBase->m_strHPanelID = strGlsID;
 
            char str_filename[200];
            for(int i = 0; i < MAX_PANEL_SIDE * UPDN_TYPE; i++)
            {
                strTmp = dlg.GetPathName();
                strTmp = strTmp.Left( strTmp.ReverseFind(_T('\\')));
 
                nStartY = 0, nHeight = 0;
 
                for(int j = 0 ; j < 6 ; j++)
                {
                    strPath.Format(_T("%s\\%s__%s_%d.%s"),strTmp,strGlsID,PANEL_SIDE[i],j,strExt);
 
                    USES_CONVERSION;                    
                    sprintf_s(str_filename, "%s", W2A(strPath));
                    if(access(str_filename, 0) == 0)
                    {
                        nHeight = LoadFullImage(strPath,i,nStartY);
                        if(nHeight == -1)
                            break;
                        nStartY += nHeight;
                    }                    
                    else
                        break;
                }
 
                if(pGlassData != NULL)
                {
                    CSide_Data* pSideData = pGlassData->GetSideData((DimensionDir)i);
                    if(pSideData != NULL)
                    {
                        pSideData->m_nGlassStartLine = 0;
                        pSideData->m_nGlassEndLine = nStartY;
                    }
 
                }
                if(_Func != nullptr)
                {                    
                    _Func(i);
                }
            }
        }
        SetSlashText(GLOBAL_DEFINE::emHide, _T("Loading Full Image Completed"), RGB(0,0,0));
    }
 
    m_bManualProcessStart = FALSE;
    g_pLog->DisplayMessage(_T("Loading Full Image Completed"));    
}
 
void CMainFrame::DisplayMessage(TCHAR* str)
{
    WriteLogManager(str);
}