SDC C-Project CF Review 프로그램
LYW
2021-09-14 ffe71aadfdcb4a9ea2ac4d8d320983d42ef3cad5
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
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
// DlgSelfDiagnosis_Flatness.cpp: 구현 파일
//
 
#include "stdafx.h"
#include "ReviewSystem.h"
#include "DlgSelfDiagnosis_Flatness.h"
#include "afxdialogex.h"
 
// CDlgSelfDiagnosis_Flatness 대화 상자
 
IMPLEMENT_DYNAMIC(CDlgSelfDiagnosis_Flatness, CDialogEx)
 
CDlgSelfDiagnosis_Flatness::CDlgSelfDiagnosis_Flatness(CDiagnosisManager* pDiagnosisManager, CWnd* pParent /*=nullptr*/)
    : CDialogEx(IDD_DLG_SELF_DIAGNOSIS_FLATNESS, pParent)
{
    m_bState = FALSE;
    m_prBtn = NULL;
    m_bUseRadioBtn = FALSE;
    m_pDiagnosisManager = pDiagnosisManager;
}
 
CDlgSelfDiagnosis_Flatness::~CDlgSelfDiagnosis_Flatness()
{
    KillProcess("wgnuplot.exe");
}
 
BOOL CDlgSelfDiagnosis_Flatness::ChangeRadioButton(int nIndex)
{
 
    const CDiagnosisInfo* pSettingInfo = m_pDiagnosisManager->GetDiagnosisInfo();
    if (pSettingInfo == NULL) return FALSE;
 
    int nRangeCount = pSettingInfo->GetRangeCount_Flatness();
 
    if (nIndex < nRangeCount)
    {
        m_prBtn[nIndex]->EnableWindow(TRUE);
        m_prBtn[nIndex]->SetCheck(TRUE);
 
        CDlgSelfDiagnosis_Flatness* pDlg = (CDlgSelfDiagnosis_Flatness*)AfxGetApp()->m_pMainWnd;
        pDlg->PostMessage(CUSTOM_UPDATEDATA, 0, 0);
    }
 
return TRUE;
}
 
BOOL CDlgSelfDiagnosis_Flatness::ChangeGridResultData()
{
    CDiagnosisInfo* pSettingInfo = m_pDiagnosisManager->GetDiagnosisInfo();
    if (pSettingInfo == NULL) return FALSE;
 
    CDiagnosisResult * pProcessResult = m_pDiagnosisManager->GetDiagnosisResult_Flatness();
    if (pProcessResult == NULL) return FALSE;
 
    SPositionData* pPositionData = pProcessResult->GetPositionData_Flatness(0);
    if (pPositionData == NULL) return FALSE;
 
    int nMode = pSettingInfo->GetFlatnessMode();
 
    SetGridResultData(nMode, pPositionData);
 
    CDlgSelfDiagnosis_Flatness* pDlg = (CDlgSelfDiagnosis_Flatness*)AfxGetApp()->m_pMainWnd;
    pDlg->PostMessage(CUSTOM_UPDATEDATA, 0, 0);
 
    return TRUE;
}
 
void CDlgSelfDiagnosis_Flatness::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_GRID_RESULT_DATA, m_ctrlResultData);
    DDX_Control(pDX, IDC_PICTURE_CONTROL, m_Plot);
    DDX_Control(pDX, IDC_LIST, m_ListBox);
    DDX_Control(pDX, IDC_BUTTON_SIMULATION, m_btnSimul);
    DDX_Control(pDX, IDC_COMBO_MODE, m_ComboMode);
    DDX_Control(pDX, IDC_STATIC_GLASSVIEW, m_staticGlassView);
    DDX_Control(pDX, IDC_EDIT_JUDGE_MOTOR_Z, m_EditJudgeRange);
    DDX_Control(pDX, IDC_EDIT_COUNT, m_EditRangeCount);
}
 
BEGIN_MESSAGE_MAP(CDlgSelfDiagnosis_Flatness, CDialogEx)
    ON_LBN_SELCHANGE(IDC_LIST, &CDlgSelfDiagnosis_Flatness::OnLbnSelchangeList)
    ON_BN_CLICKED(IDC_BUTTON_SIMULATION, &CDlgSelfDiagnosis_Flatness::OnBnClickedButtonSimulation)
    ON_WM_DESTROY()
    ON_CBN_SELCHANGE(IDC_COMBO_MODE, &CDlgSelfDiagnosis_Flatness::OnCbnSelchangeComboMode)
    ON_MESSAGE(CUSTOM_UPDATEDATA, OnUpdateDialog)
    ON_BN_CLICKED(IDC_BUTTON_MANUAL, &CDlgSelfDiagnosis_Flatness::OnBnClickedButtonManual)
END_MESSAGE_MAP()
void CDlgSelfDiagnosis_Flatness::InitGnuPlot()
{
    /*
    const char* text_char = "C:\\gnuplot426\\bin\\wgnuplot.exe";
    size_t length = strlen(text_char);
    wchar_t text_wchar[30];
    mbstowcs_s(&length, text_wchar, text_char, length);
    */
    m_Plot.init(_T("wgnuplot.exe"));
    //m_Plot1.cmd("plot sin(x)");
    //m_Plot1.cmd("replot cos(x)");
    //m_Plot1.cmd("replot tan(x)");
 
    //reset    # set 초기화
 
 
    m_Plot.cmd("set object 1 rectangle from screen 0,0 to screen 1,1 fillcolor rgb '#282d32'  behind"); //   # 바탕화면 색 지정
 
    m_Plot.cmd("set pm3d");
    m_Plot.cmd("set xtics textcolor rgb '#d5d5d5'");   // # x 축 색 지정
 
    m_Plot.cmd("set ytics textcolor rgb '#d5d5d5'"); //   # y 축 색 지정
 
    m_Plot.cmd("set ztics textcolor rgb '#d5d5d5'"); //   # z 축 색 지정
 
    m_Plot.cmd("set key textcolor  rgb '#d5d5d5'");  //  # 범례 텍스트 색지정  
    m_Plot.cmd("set border lc  rgb '#555555'");  //  # 범례 색 지정
 
    m_Plot.cmd("set palette rgbformulae 33,13,10");
    //m_Plot.cmd("set dgrid3d 10,10");  //  # Smooth 처리
    m_Plot.cmd("set dgrid3d 8,8");  //  # Smooth 처리
    m_Plot.cmd("splot 'c:\\temp\\image.txt' with lines");   //  # 그래프 출력
    //m_Plot.cmd("splot 'c:\\temp\\data3.txt' matrix w lines lc rgb '#FAED7D'");   //  # 그래프 출력
    //m_Plot.cmd("splot 'test.csv' using 1:2:3 '%lf,%lf,%lf,%lf' with linespoints pt 6 ps 2 lw 3 matrix w lines lc rgb '#FAED7D'");
 
 
 
    //m_Plot.cmd("splot -x*x with pm3d");
    
}
 
void CDlgSelfDiagnosis_Flatness::InitListCtrl()
{
    CString strExt = _T("\\*txt");
    CString strFilePath = REVIEW_AUTO_DIAGNOSIS_RESULT_FLATNESS_PATH + strExt;
 
    //검색 클래스
    CFileFind finder;
 
    //CFileFind는 파일, 디렉터리가 존재하면 TRUE 를 반환함
    BOOL bWorking = finder.FindFile(strFilePath); //
 
    CString fileName;
    CString DirName;
 
 
    m_ListBox.ResetContent();
    while (bWorking)
    {
        //다음 파일 / 폴더 가 존재하면다면 TRUE 반환
        bWorking = finder.FindNextFile();
        //파일 일때
        if (finder.IsArchived())
        {
            //파일의 경로
            CString _fileName = finder.GetFilePath();
 
            // 현재폴더 상위폴더 썸네일파일은 제외
            if (_fileName == _T(".") ||
                _fileName == _T("..") ||
                _fileName == _T("Thumbs.db")) continue;
 
            //읽어온 파일 경로를 리스트박스에 넣음
            m_ListBox.AddString(_fileName);
        }
        //// 디렉터리 일때
        //if (finder.IsDirectory())
        //{
        //    // 필요하면 여기서 처리
        //        DirName = finder.GetFileName();
        //}
    }
}
 
 
 
void CDlgSelfDiagnosis_Flatness::InitModeComboBox()
{
    //enum FlatnessMode { Mode_2x2, Mode_3x3, Mode_3x4, Mode_4x5, Mode_10x10, ModeCount };
    m_ComboMode.AddString("Mode_2x2");
    m_ComboMode.AddString("Mode_3x3");
    m_ComboMode.AddString("Mode_3x4");
    m_ComboMode.AddString("Mode_4x5");
    m_ComboMode.AddString("Mode_10x10");
}
 
void CDlgSelfDiagnosis_Flatness::InitRadioButton(int nMode)
{
 
    //enum FlatnessMode { Mode_2x2, Mode_3x3, Mode_3x4, Mode_4x5, Mode_10x10, ModeCount };
    //Mode_2x2     0 = 4ea
    //Mode_3x3     1 = 9ea
    //Mode_3x4     2 = 12ea
    //Mode_4x5     3 = 20ea
    //Mode_10x10 4 = 100ea
    int nbtncnt = 0;
    int nWidth, nHeight, nViewWidth, nViewHeight, nSx, nSy, nRows, nCols;
    int nbtnsize = 15;
    int nBtnidx = 0;
 
    CRect rt;
    m_staticGlassView.GetClientRect(rt);
 
    nSx = rt.Width();
    nSy = rt.Height() + 3;
    nViewWidth = rt.Width() - 20;
    nViewHeight = rt.Height() - 30;
    DeleteRadioButton();
    switch (nMode)
    {
    case Mode_2x2:
        nRows = 2;
        nCols = 2;
        break;
 
    case Mode_3x3:
        nRows = 3;
        nCols = 3;
        break;
 
    case Mode_3x4:
        nRows = 3;
        nCols = 4;
        break;
 
    case Mode_4x5:
        nRows = 4;
        nCols = 5;
        break;
 
    case Mode_10x10:
        nRows = 10;
        nCols = 10;
        break;
 
    }
    nbtncnt = nRows * nCols;
 
    nWidth = nViewWidth / (nRows - 1);
    nHeight = nViewHeight / (nCols - 1);
 
 
    m_prBtn = new CButton*[nbtncnt];
    for (int i = 0; i < nRows; i++)
    {
        if (i % 2 == 0)
        {
            for (int j = nCols - 1; j >= 0; j--)
            {
                m_prBtn[nBtnidx] = new CButton();
                m_prBtn[nBtnidx]->Create(_T(""), WS_CHILD | WS_VISIBLE |
                    BS_AUTORADIOBUTTON, CRect(nSx + nWidth * i, nSy + nHeight * j, nSx + nWidth * i + nbtnsize, nSy + nHeight * j + nbtnsize), this, BTN_ID_001);
 
                m_prBtn[nBtnidx]->EnableWindow(FALSE);
                m_prBtn[nBtnidx]->SetCheck(FALSE);
                nBtnidx++;
            }
        }
        else
        {
            for (int j = 0; j < nCols; j++)
            {
                m_prBtn[nBtnidx] = new CButton();
                m_prBtn[nBtnidx]->Create(_T(""), WS_CHILD | WS_VISIBLE |
                    BS_AUTORADIOBUTTON, CRect(nSx + nWidth * i, nSy + nHeight * j, nSx + nWidth * i + nbtnsize, nSy + nHeight * j + nbtnsize), this, BTN_ID_001);
 
                m_prBtn[nBtnidx]->EnableWindow(FALSE);
                m_prBtn[nBtnidx]->SetCheck(FALSE);
                nBtnidx++;
            }
        }
    }
 
    m_bUseRadioBtn = TRUE;
    m_nPrerbtnCnt = nbtncnt;
}
 
BOOL CDlgSelfDiagnosis_Flatness::InitDiagnosisSetiing()
{
    const CDiagnosisInfo* pSettingInfo = m_pDiagnosisManager->GetDiagnosisInfo();
    if (pSettingInfo == NULL) return 0;
 
    CString strTemp = _T("");
 
    strTemp.Format(_T("%d"), pSettingInfo->GetJudgeData_ZRange());
    m_EditJudgeRange.SetWindowTextA(strTemp);
    
    int nMode = pSettingInfo->GetFlatnessMode();
    int nRangeCount = pSettingInfo->GetRangeCount_Flatness();
    m_ComboMode.SetCurSel(nMode);
 
    if(nMode==0)
        strTemp = _T("Mode_2x2");
    else if (nMode == 1)
        strTemp = _T("Mode_3x3");
    else if (nMode == 2)
        strTemp = _T("Mode_3x4");
    else if (nMode == 3)
        strTemp = _T("Mode_4x5");
    else if (nMode == 4)
        strTemp = _T("Mode_10x10");
    m_ComboMode.SetWindowTextA(strTemp);
 
    strTemp.Format("%d", nRangeCount);
    m_EditRangeCount.SetWindowTextA(strTemp);
    SetRadioButton(nMode);
    InitRadioButton(nMode);
 
    return TRUE;
 
}
 
BOOL CDlgSelfDiagnosis_Flatness::SetGridResultData(int nMode, SPositionData* pPositionData)
{
    int nRowIdx, nColIdx, nRows, nCols, nFixRows, nFixCols;
    CString strTemp;
 
    int nGridWidth, nGridHeight;
    nGridWidth = 380;
    nGridHeight = 80;
 
    m_ctrlResultData.DeleteAllItems();
 
    switch (nMode)
    {
    case Mode_2x2:
        nCols = 2;
        nRows = 2;
        m_ctrlResultData.SetRowCount(nRows+1);
        m_ctrlResultData.SetColumnCount(nCols+1);
        m_ctrlResultData.SetColumnWidth(0, 130);
            //tmp_grid.SetItemBkColour(row, col, clr);
            //tmp_grid.SetItemFgColour(row, col, RGB(255, 0, 0));
        for (int i = 0; i < nRows +1; i++)
        {
            //m_ctrlResultData.SetRowHeight(i, nGridHeight/2);
        }
 
        for (int i = 0; i < nCols +1; i++)
        {
            //m_ctrlResultData.SetColumnWidth(i, nGridWidth/2);
        }
        break;
    case Mode_3x3:
        nCols = 3;
        nRows = 3;
        m_ctrlResultData.SetRowCount(nRows+1);
        m_ctrlResultData.SetColumnCount(nCols+1);
        for (int i = 0; i < nRows; i++)
        {
            //m_ctrlResultData.SetRowHeight(i, 31);
        }
 
        for (int i = 0; i < nCols; i++)
        {
            //m_ctrlResultData.SetColumnWidth(i, 171);
        }
        break;
    case Mode_3x4:
        nCols = 3;
        nRows = 4;
        m_ctrlResultData.SetRowCount(nRows+1);
        m_ctrlResultData.SetColumnCount(nCols+1);
        for (int i = 0; i < nRows; i++)
        {
            //m_ctrlResultData.SetRowHeight(i, 31);
        }
 
        for (int i = 0; i < nCols; i++)
        {
            //m_ctrlResultData.SetColumnWidth(i, 171);
        }
        break;
    case Mode_4x5:
 
        nCols = 4;
        nRows = 5;
        m_ctrlResultData.SetRowCount(nRows+1);
        m_ctrlResultData.SetColumnCount(nCols+1);
        for (int i = 0; i < nRows; i++)
        {
            //m_ctrlResultData.SetRowHeight(i, 31);
        }
 
        for (int i = 0; i < nCols; i++)
        {
            //m_ctrlResultData.SetColumnWidth(i, 171);
        }
        break;
    case Mode_10x10:
 
        nCols = 10;
        nRows = 10;
        m_ctrlResultData.SetRowCount(nRows+1);
        m_ctrlResultData.SetColumnCount(nCols+1);
        for (int i = 0; i < nRows; i++)
        {
            //m_ctrlResultData.SetRowHeight(i, 31);
        }
 
        for (int i = 0; i < nCols; i++)
        {
            //m_ctrlResultData.SetColumnWidth(i, 171);
        }
        break;
 
    }
 
    int nIndex = 0;
 
    nCols++;
    nRows++; 
    
 
    // 글라스 좌표 영역 색상
    for (int i = 0; i < nRows; i++)
    {
        m_ctrlResultData.SetItemBkColour(i, 0, RGB(128, 143, 175));
    }
 
    for (int i = 0; i < nCols; i++)
    {
        m_ctrlResultData.SetItemBkColour(0, i, RGB(128, 143, 175));
    }
 
 
    // 0,0 영역 색상 및 텍스트
 
    GV_ITEM Item;
    Item.mask = GVIF_TEXT | GVIF_FORMAT;
    Item.nFormat = DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX;
    strTemp.Format(_T("GlassPosY\GlassPosX(mm)"));
    m_ctrlResultData.SetColumnWidth(0, 171);
    Item.col = 0;
    Item.row = 0;
    Item.strText = strTemp;
    m_ctrlResultData.SetItem(&Item);
 
 
 
    // 값 입력
    for (int i = 1; i < nCols; i++)
    {
        if (i % 2 == 0)
        {
            for (int j = 1; j < nRows; j++)
            {
                Item.col = i;
                Item.row = j;
                strTemp.Format(_T("%lf"), pPositionData[nIndex].dPosZ);
                Item.strText = strTemp;
                m_ctrlResultData.SetItem(&Item);
 
                Item.col = i;
                Item.row = 0;
                strTemp.Format(_T("%.2lf"), pPositionData[nIndex].dPosX);
                Item.strText = _T("글라스좌표X");
                Item.strText = strTemp;
                m_ctrlResultData.SetItem(&Item);
 
                Item.col = 0;
                Item.row = j;
                strTemp.Format(_T("%.2lf"), pPositionData[nIndex].dPosY);
                Item.strText = _T("글라스좌표Y");
                Item.strText = strTemp;
                m_ctrlResultData.SetItem(&Item);
 
                nIndex++;
                
            }
        }
        else
        {
            for (int j = nRows - 1; j > 0; j--)
            {
                Item.col = i;
                Item.row = j;
                strTemp.Format(_T("%lf"), pPositionData[nIndex].dPosZ);
                Item.strText = strTemp;
                m_ctrlResultData.SetItem(&Item);
 
                Item.col = i;
                Item.row = 0;
                strTemp.Format(_T("%.2lf"), pPositionData[nIndex].dPosX);
                Item.strText = _T("글라스좌표X");
                Item.strText = strTemp;
                m_ctrlResultData.SetItem(&Item);
 
                Item.col = 0;
                Item.row = j;
                strTemp.Format(_T("%.2lf"), pPositionData[nIndex].dPosY);
                Item.strText = _T("글라스좌표Y");
                Item.strText = strTemp;
                m_ctrlResultData.SetItem(&Item);
                nIndex++;
            }
        }
    }
 
    m_ctrlResultData.SetEditable(FALSE);
 
    return TRUE;
}
 
void CDlgSelfDiagnosis_Flatness::SetListCtrl()
{
 
}
 
void CDlgSelfDiagnosis_Flatness::SetGnuPlot(CString strFilePath)
{
    CString strsplot, strtemp, strCmdMakeGraph;
 
    strsplot = _T("splot ");
    strtemp = _T(" with lines");
    strCmdMakeGraph = strsplot + _T("'") + strFilePath + _T("'") + strtemp;
 
    m_Plot.cmd("set dgrid3d 2,2");  //  # Smooth 처리
    m_Plot.cmd(strCmdMakeGraph);   //  # 그래프 출력
}
 
void CDlgSelfDiagnosis_Flatness::SetRadioButton(int nMode)
{
    //enum FlatnessMode { Mode_2x2, Mode_3x3, Mode_3x4, Mode_4x5, Mode_10x10, ModeCount };
    //Mode_2x2     0 = 4ea
    //Mode_3x3     1 = 9ea
    //Mode_3x4     2 = 12ea
    //Mode_4x5     3 = 20ea
    //Mode_10x10 4 = 100ea
    int nbtncnt = 0;
    int nWidth, nHeight, nViewWidth, nViewHeight, nSx, nSy, nRows, nCols;
    int nbtnsize = 15;
    int nBtnidx = 0;
 
    CRect rt;
    m_staticGlassView.GetClientRect(rt);
 
    nSx = rt.Width();
    nSy = rt.Height()+3;
    nViewWidth = rt.Width()-20;
    nViewHeight = rt.Height()-30;
    DeleteRadioButton();
    switch (nMode)
    {
    case Mode_2x2:
        nRows = 2;
        nCols = 2;
 
        nbtncnt = nRows * nCols;
 
        nWidth = nViewWidth / (nRows - 1);
        nHeight = nViewHeight / (nCols - 1);
 
 
        m_prBtn = new CButton*[nbtncnt];
        for (int i = 0; i < nRows; i++)
        {
            if (i % 2 == 0)
            {
                for (int j = 0; j < nCols; j++)
                {
                    m_prBtn[nBtnidx] = new CButton();
                    m_prBtn[nBtnidx]->Create(_T(""), WS_CHILD | WS_VISIBLE |
                        BS_AUTORADIOBUTTON, CRect(nSx + nWidth * i, nSy + nHeight * j, nSx + nWidth * i + nbtnsize, nSy + nHeight * j + nbtnsize), this, BTN_ID_001);
 
                    //m_prBtn[nBtnidx]->EnableWindow(FALSE);
                    m_prBtn[nBtnidx]->SetCheck(TRUE);
                    nBtnidx++;
                }
            }
            else
            {
                for (int j = nCols - 1; j >= 0; j--)
                {
                    m_prBtn[nBtnidx] = new CButton();
                    m_prBtn[nBtnidx]->Create(_T(""), WS_CHILD | WS_VISIBLE |
                        BS_AUTORADIOBUTTON, CRect(nSx + nWidth * i, nSy + nHeight * j, nSx + nWidth * i + nbtnsize, nSy + nHeight * j + nbtnsize), this, BTN_ID_001);
 
                    //m_prBtn[nBtnidx]->EnableWindow(FALSE);
                    m_prBtn[nBtnidx]->SetCheck(TRUE);
                    nBtnidx++;
                }
            }
        }
        break;
 
    case Mode_3x3:
        nRows = 3;
        nCols = 3;
 
        nbtncnt = nRows * nCols;
 
        nWidth = nViewWidth / (nRows - 1);
        nHeight = nViewHeight / (nCols - 1);
 
 
        m_prBtn = new CButton*[nbtncnt];
        for (int i = 0; i < nRows; i++)
        {
            if (i % 2 == 0)
            {
                for (int j = 0; j < nCols; j++)
                {
                    m_prBtn[nBtnidx] = new CButton();
                    m_prBtn[nBtnidx]->Create(_T(""), WS_CHILD | WS_VISIBLE |
                        BS_AUTORADIOBUTTON, CRect(nSx + nWidth * i, nSy + nHeight * j, nSx + nWidth * i + nbtnsize, nSy + nHeight * j + nbtnsize), this, BTN_ID_001);
 
                    //m_prBtn[nBtnidx]->EnableWindow(FALSE);
                    m_prBtn[nBtnidx]->SetCheck(TRUE);
                    nBtnidx++;
                }
            }
            else
            {
                for (int j = nCols - 1; j >= 0; j--)
                {
                    m_prBtn[nBtnidx] = new CButton();
                    m_prBtn[nBtnidx]->Create(_T(""), WS_CHILD | WS_VISIBLE |
                        BS_AUTORADIOBUTTON, CRect(nSx + nWidth * i, nSy + nHeight * j, nSx + nWidth * i + nbtnsize, nSy + nHeight * j + nbtnsize), this, BTN_ID_001);
 
                    //m_prBtn[nBtnidx]->EnableWindow(FALSE);
                    m_prBtn[nBtnidx]->SetCheck(TRUE);
                    nBtnidx++;
                }
            }
        }
        break;
 
    case Mode_3x4:
        nRows = 3;
        nCols = 4;
 
        nbtncnt = nRows * nCols;
 
        nWidth = nViewWidth / (nRows - 1);
        nHeight = nViewHeight / (nCols - 1);
 
 
        m_prBtn = new CButton*[nbtncnt];
        for (int i = 0; i < nRows; i++)
        {
 
            if (i % 2 == 0)
            {
                for (int j = 0; j < nCols; j++)
                {
                    m_prBtn[nBtnidx] = new CButton();
                    m_prBtn[nBtnidx]->Create(_T(""), WS_CHILD | WS_VISIBLE |
                        BS_AUTORADIOBUTTON, CRect(nSx + nWidth * i, nSy + nHeight * j, nSx + nWidth * i + nbtnsize, nSy + nHeight * j + nbtnsize), this, BTN_ID_001);
 
                    //m_prBtn[nBtnidx]->EnableWindow(FALSE);
                    m_prBtn[nBtnidx]->SetCheck(TRUE);
                    nBtnidx++;
                }
            }
            else
            {
                for (int j = nCols-1; j >= 0; j--)
                {
                    m_prBtn[nBtnidx] = new CButton();
                    m_prBtn[nBtnidx]->Create(_T(""), WS_CHILD | WS_VISIBLE |
                        BS_AUTORADIOBUTTON, CRect(nSx + nWidth * i, nSy + nHeight * j, nSx + nWidth * i + nbtnsize, nSy + nHeight * j + nbtnsize), this, BTN_ID_001);
 
                    //m_prBtn[nBtnidx]->EnableWindow(FALSE);
                    m_prBtn[nBtnidx]->SetCheck(TRUE);
                    nBtnidx++;
                }
            }
        }
        break;
 
    case Mode_4x5:
        nRows = 4;
        nCols = 5;
 
        nbtncnt = nRows * nCols;
 
        nWidth = nViewWidth / (nRows - 1);
        nHeight = nViewHeight / (nCols - 1);
 
 
        m_prBtn = new CButton*[nbtncnt];
        for (int i = 0; i < nRows; i++)
        {
            if (i % 2 == 0)
            {
                for (int j = 0; j < nCols; j++)
                {
                    m_prBtn[nBtnidx] = new CButton();
                    m_prBtn[nBtnidx]->Create(_T(""), WS_CHILD | WS_VISIBLE |
                        BS_AUTORADIOBUTTON, CRect(nSx + nWidth * i, nSy + nHeight * j, nSx + nWidth * i + nbtnsize, nSy + nHeight * j + nbtnsize), this, BTN_ID_001);
 
                    //m_prBtn[nBtnidx]->EnableWindow(FALSE);
                    m_prBtn[nBtnidx]->SetCheck(TRUE);
                    nBtnidx++;
                }
            }
            else
            {
                for (int j = nCols - 1; j >= 0; j--)
                {
                    m_prBtn[nBtnidx] = new CButton();
                    m_prBtn[nBtnidx]->Create(_T(""), WS_CHILD | WS_VISIBLE |
                        BS_AUTORADIOBUTTON, CRect(nSx + nWidth * i, nSy + nHeight * j, nSx + nWidth * i + nbtnsize, nSy + nHeight * j + nbtnsize), this, BTN_ID_001);
 
                    //m_prBtn[nBtnidx]->EnableWindow(FALSE);
                    m_prBtn[nBtnidx]->SetCheck(TRUE);
                    nBtnidx++;
                }
            }
        }
        break;
 
    case Mode_10x10:
        nRows = 10;
        nCols = 10;
 
        nbtncnt = nRows * nCols;
 
        nWidth = nViewWidth / (nRows - 1);
        nHeight = nViewHeight / (nCols - 1);
 
 
        m_prBtn = new CButton*[nbtncnt];
        for (int i = 0; i < nRows; i++)
        {
            if (i % 2 == 0)
            {
                for (int j = 0; j < nCols; j++)
                {
                    m_prBtn[nBtnidx] = new CButton();
                    m_prBtn[nBtnidx]->Create(_T(""), WS_CHILD | WS_VISIBLE |
                        BS_AUTORADIOBUTTON, CRect(nSx + nWidth * i, nSy + nHeight * j, nSx + nWidth * i + nbtnsize, nSy + nHeight * j + nbtnsize), this, BTN_ID_001);
 
                    //m_prBtn[nBtnidx]->EnableWindow(FALSE);
                    m_prBtn[nBtnidx]->SetCheck(TRUE);
                    nBtnidx++;
                }
            }
            else
            {
                for (int j = nCols - 1; j >= 0; j--)
                {
                    m_prBtn[nBtnidx] = new CButton();
                    m_prBtn[nBtnidx]->Create(_T(""), WS_CHILD | WS_VISIBLE |
                        BS_AUTORADIOBUTTON, CRect(nSx + nWidth * i, nSy + nHeight * j, nSx + nWidth * i + nbtnsize, nSy + nHeight * j + nbtnsize), this, BTN_ID_001);
 
                    //m_prBtn[nBtnidx]->EnableWindow(FALSE);
                    m_prBtn[nBtnidx]->SetCheck(TRUE);
                    nBtnidx++;
                }
            }
        }
        break;
 
    }
 
    m_bUseRadioBtn = TRUE;
    m_nPrerbtnCnt = nbtncnt;
 
}
BOOL CDlgSelfDiagnosis_Flatness::OnInitDialog()
{
    CDialogEx::OnInitDialog();
 
    InitDiagnosisSetiing();
    InitListCtrl();
    InitGnuPlot();
    InitModeComboBox();
 
    // TODO:  여기에 추가 초기화 작업을 추가합니다.
 
    return TRUE;  // return TRUE unless you set the focus to a control
                  // 예외: OCX 속성 페이지는 FALSE를 반환해야 합니다.
}
 
 
void CDlgSelfDiagnosis_Flatness::OnLbnSelchangeList()
{
    // TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
    int nCurrentSel;
    CString strFilePath = _T("");
 
 
    nCurrentSel = m_ListBox.GetCurSel();
    m_ListBox.GetText(nCurrentSel, strFilePath);
 
    //"c:\\temp\\2020-12-01_1_Flatness.txt" // 1_Flatness = Mode 1 = Mode_3x3;
    int nMode, nTemp;
    CString strMode;
    nTemp = strFilePath.Find(_T("."));
    nTemp -= 10; // "c:\\temp\\2020-12-01_1 <-1의 위치 찾기
 
    strMode = strFilePath.Mid(nTemp,1);
    nMode = _ttoi(strMode);
 
    // Mode로 RangeCount 찾아내기
    int nRangeCount;
    if (nMode == Mode_2x2) { nRangeCount        =4; }
    else if (nMode == Mode_3x3) { nRangeCount   = 9; }
    else if (nMode == Mode_3x4) { nRangeCount   = 12; }
    else if (nMode == Mode_4x5) { nRangeCount   = 20; }
    else if (nMode == Mode_10x10) { nRangeCount = 100; }
 
    // RangeCount만큼 SPositionData 생성
    SPositionData* pPositionData = new SPositionData[nRangeCount];
 
 
 
    SetGnuPlot(strFilePath);
    m_pDiagnosisManager->GetDiagnosis3DImageData_Flatness(strFilePath, pPositionData);
    SetGridResultData(nMode, pPositionData);
    SetRadioButton(nMode);
    m_ComboMode.SetCurSel(nMode);
 
 
    // 메모리 해제
    delete [] pPositionData;
}
 
 
void CDlgSelfDiagnosis_Flatness::MakeSimulationData()
{
    for (int i = 1; i <= 5; i++)
    {
        SPositionData data;
        data.dPosX = i * 1000;
        data.dPosY = i * 1000;
        data.dPosZ = i * 1000;
        data.nIndex = i;
    }
}
 
int CDlgSelfDiagnosis_Flatness::LoadResultData()
{
    CString strFilepath = _T("C:\\temp\\2018-12-01_0_Flatness.txt");
 
 
    CFile file;
    // 파일의 내용을 담는다.
    CString strFile;
    // 파일의 크기
    int nFileSize = 0;
    // 단어를 담을 스트링 배열
    // CString의 배열 보다 CStirng을 담을 수 있는 배열을 쓰는게 효율적이다.
    CStringArray strWordArray;
    // 하나의 단어를 담을 임시 변수
    CString strWord;
 
    float fGlassPosX, fGlassPosY, fMotorZ;
    enum { GlassPosX, GlassPosY, MotorZ };
    CString str = _T("\r\n");
    if (file.Open(strFilepath, CFile::modeRead))
    {
        // 파일의 크기를 구한다.
        nFileSize = (int)file.GetLength();
        // 파일의 크기 만큼 읽어 CString 변수에 담는다.
        file.Read(strFile.GetBuffer(nFileSize), nFileSize);
        strFile.ReleaseBuffer(nFileSize);
 
 
        int nIndex = -1;
 
        // 공백을 찾을 때 까지 루프를 돈다.
        while (strFile.Find(" ") != -1)
        {
 
            // 공백까지의 스트링을 가져온다.
            strWord = strFile.Left(strFile.Find(" "));
 
            // 단어를 담는다.
            if (strWord.Mid(0, 2) == str)
            {
                //strWordArray.Add(strWord.Mid(2, strWord.GetLength() - 2));
                strWord = strWord.Mid(2, strWord.GetLength() - 2);
                nIndex = 0;
            }
            else
            {
                nIndex++;
                //strWordArray.Add(strWord);
            }
 
            switch (nIndex)
            {
            case GlassPosX:
                fGlassPosX = _tstof(strWord);
                TRACE(_T("fGlassPosX = %f\r\n"), fGlassPosX);
                break;
            case GlassPosY:
                fGlassPosY = _tstof(strWord);
                TRACE(_T("fGlassPosY = %f\r\n"), fGlassPosY);
                break;
            case MotorZ:
                fMotorZ = _tstof(strWord);
                TRACE(_T("fMotorZ = %f\r\n"), fMotorZ);
                break;
            }
 
 
 
            // 단어 길이만큼 파일의 내용을 삭제한다.
            if(strFile.Mid(0,2)== str)
                strFile.Delete(0, strWord.GetLength()+3);
            else
                strFile.Delete(0, strWord.GetLength() + 1);
            
            
        }
        // 파일의 끝은 공백이 없으므로 마지막 단어가 하나 남는다.
        // 마지막 단어 하나를 추가해 준다.
        //strWordArray.Add(strFile);
        //if (strWord.Mid(0, 2) == str)
        //    strWordArray.Add(strWord.Mid(2, strWord.GetLength() - 2));
        //else
        //    strWordArray.Add(strWord);
 
        file.Close();
    }
 
 
    return TRUE;
}
 
 
int CDlgSelfDiagnosis_Flatness::SaveResultData(int nMode)
{
    /*
    CTime cTime = CTime::GetCurrentTime(); // 현재 시스템으로부터 날짜 및 시간을 얻어 온다.
    CString strFilename,strFilePath;
 
 
    //strFilename.Format(_T("c:\\temp\\2018_12_01_12_24_0_Flatness.txt"));
    strFilename.Format("%d-%2d-%2d-%2d-%2d-%d-Flatness.txt", cTime.GetYear(),cTime.GetMonth(),cTime.GetDay(), cTime.GetHour(), cTime.GetMinute(),nMode);
    strFilePath = _T("C:\\temp\\tempimage\\") + strFilename;
 
    FILE *fp = NULL;
    _tfopen_s(&fp, strFilePath, _T("w"));
    if (fp == NULL) return 0;
 
 
 
 
    _ftprintf_s(fp, _T("%d %d %.3lf \n"), 10, 10, 1.01);
    _ftprintf_s(fp, _T("%d %d %.3lf \n"), 10, 2290, 1.015);
    _ftprintf_s(fp, _T("%d %d %.3lf \n"), 2690, 2290, 1.07);
    _ftprintf_s(fp, _T("%d %d %.3lf \n"), 2690, 10, 1.031);
    
    int nIndex = 0;
    
    for (int i =0; i<5; i++)
    {
        //pDefectResult = static_cast<CDefectResult*>(*it);
        //
        //if (pDefectResult == NULL) continue;
 
        _ftprintf_s(fp, _T("%d %d %.3lf \n"), 10, 10, 1.01);
        _ftprintf_s(fp, _T("%d %d %.3lf \n"), 10, 2290, 1.015);
        _ftprintf_s(fp, _T("%d %d %.3lf \n"), 2690, 2290, 1.07);
        _ftprintf_s(fp, _T("%d %d %.3lf \n"), 2690, 10, 1.031);
    }
    
    fclose(fp);
    */
    return 1;
}
 
void CDlgSelfDiagnosis_Flatness::DeleteRadioButton()
{
    if (m_bUseRadioBtn == TRUE)
    {
        if (m_prBtn != NULL)
        {
            for (int i = 0; i < m_nPrerbtnCnt; i++)
            {
                delete m_prBtn[i];
                m_prBtn[i] = NULL;
            }
            delete[] m_prBtn;
        }
    }
}
 
void CDlgSelfDiagnosis_Flatness::OnBnClickedButtonSimulation()
{
    // TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
 
    //#3514_LYW_CF AOI Review 자가진단 기능 개선_START
    if (m_pDiagnosisManager->CheckManualMode() == FALSE)
    {
        CString strMessage;
        strMessage.Format(_T("Change Manual Mode!!"));
        if (IDOK == AfxMessageBox(strMessage, MB_OK | MB_ICONERROR))
        {
            g_pLog->DisplayMessage(_T("Manual Diagnosis Fail! Not Manual Mode"));
            return;
        }
    }
    //#3514_LYW_CF AOI Review 자가진단 기능 개선_END
 
    if (m_bState == FALSE)
    {
        m_bState = TRUE;
        m_btnSimul.SetWindowTextA("동작 중");
        m_pDiagnosisManager->RecvSignalToSignalControl(DiagnosisSignal_Auto, DiagnosisMode_Flatness,TRUE);
    }
    else
    {
        m_bState = FALSE;
        m_btnSimul.SetWindowTextA("종료 됨");
        m_pDiagnosisManager->RecvSignalToSignalControl(DiagnosisSignal_Auto, DiagnosisMode_Flatness,FALSE);
    }
}
 
 
void CDlgSelfDiagnosis_Flatness::OnBnClickedButtonManual()
{
    //#3514_LYW_CF AOI Review 자가진단 기능 개선_START
    if (m_pDiagnosisManager->CheckManualMode() == FALSE)
    {
        CString strMessage;
        strMessage.Format(_T("Change Manual Mode!!"));
        if (IDOK == AfxMessageBox(strMessage, MB_OK | MB_ICONERROR))
        {
            g_pLog->DisplayMessage(_T("Manual Diagnosis Fail! Not Manual Mode"));
            return;
        }
    }
    //#3514_LYW_CF AOI Review 자가진단 기능 개선_END
 
    m_pDiagnosisManager->ManualMeasure_Flatness();
}
 
 
void CDlgSelfDiagnosis_Flatness::OnDestroy()
{
    CDialogEx::OnDestroy();
 
    // TODO: 여기에 메시지 처리기 코드를 추가합니다.
}
 
 
void CDlgSelfDiagnosis_Flatness::OnCbnSelchangeComboMode()
{
    // TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
    int nMode = m_ComboMode.GetCurSel();
    SetRadioButton(nMode);
}
 
LRESULT CDlgSelfDiagnosis_Flatness::OnUpdateDialog(WPARAM wParam, LPARAM lParam)
{
    UpdateData(FALSE);
    return 0;
}