-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNovacMasterProgramView.cpp
More file actions
1322 lines (1079 loc) · 39.1 KB
/
NovacMasterProgramView.cpp
File metadata and controls
1322 lines (1079 loc) · 39.1 KB
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
// NovacMasterProgramView.cpp : implementation of the CNovacMasterProgramView class
//
#include "stdafx.h"
#include "NovacMasterProgram.h"
#include "MainFrm.h"
#include "NovacMasterProgramDoc.h"
#include "NovacMasterProgramView.h"
#include "UserSettings.h"
#include "View_Scanner.h"
#include "Common/ReportWriter.h"
#include "Common/FluxLogFileHandler.h"
#include "Communication/LinkStatistics.h"
#include "Evaluation/ScanResult.h"
#include "Evaluation/EvaluationController.h"
#include "Geometry/GeometryResult.h"
#include "Configuration/ConfigurationFileHandler.h"
#include "PostFlux/PostFluxDlg.h"
#include "ReEvaluation/ReEvaluator.h"
#include "ReEvaluation/ReEvaluationDlg.h"
#include "ReEvaluation/ReEval_ScanDlg.h"
#include "ReEvaluation/ReEval_WindowDlg.h"
#include "ReEvaluation/ReEval_MiscSettingsDlg.h"
#include "ReEvaluation/ReEval_DoEvaluationDlg.h"
#include "Dialogs/ExportDlg.h"
#include "Dialogs/ExportSpectraDlg.h"
#include "Dialogs/ExportEvallogDlg.h"
#include "Dialogs/ManualWindDlg.h"
#include "Dialogs/ManualCompositionDlg.h"
#include "Dialogs/ImportSpectraDlg.h"
#include "Dialogs/FileTransferDlg.h"
#include "Dialogs/GeometryDlg.h"
#include "Dialogs/SplitPakFilesDlg.h"
#include "Dialogs/MergePakFilesDlg.h"
#include "Dialogs/DataBrowserDlg.h"
#include "Dialogs/PakFileInspector.h"
#include "Dialogs/SummarizeFluxDataDlg.h"
#include "WindMeasurement/PostWindDlg.h"
#include "WindMeasurement/WindSpeedResult.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
extern CMeteorologicalData g_metData;
extern CConfigurationSetting g_settings;
extern CUserSettings g_userSettings;
CFormView* pView;
// CNovacMasterProgramView
IMPLEMENT_DYNCREATE(CNovacMasterProgramView, CFormView)
BEGIN_MESSAGE_MAP(CNovacMasterProgramView, CFormView)
// Messages from other parts of the program
ON_MESSAGE(WM_STATUSMSG, OnShowStatus)
ON_MESSAGE(WM_UPDATE_MESSAGE, OnUpdateMessage)
ON_MESSAGE(WM_SHOW_MESSAGE, OnShowMessage)
ON_MESSAGE(WM_EVAL_SUCCESS, OnEvalSucess)
ON_MESSAGE(WM_EVAL_FAILURE, OnEvalFailure)
ON_MESSAGE(WM_CORR_SUCCESS, OnCorrelationSuccess)
ON_MESSAGE(WM_SCANNER_RUN, OnScannerRun)
ON_MESSAGE(WM_SCANNER_SLEEP, OnScannerSleep)
ON_MESSAGE(WM_SCANNER_NOT_CONNECT, OnScannerNotConnect)
ON_MESSAGE(WM_FINISH_DOWNLOAD, OnDownloadFinished)
ON_MESSAGE(WM_FINISH_UPLOAD, OnUploadFinished)
ON_MESSAGE(WM_WRITE_REPORT, OnWriteReport)
ON_MESSAGE(WM_PH_SUCCESS, OnPlumeHeightSuccess)
ON_MESSAGE(WM_NEW_WINDFIELD, OnNewWindField)
ON_MESSAGE(WM_REWRITE_CONFIGURATION, OnRewriteConfigurationXml)
// Commands from the user
ON_COMMAND(ID_SET_LANGUAGE_ENGLISH, OnMenuSetLanguageEnglish)
ON_COMMAND(ID_SET_LANGUAGE_ESPA, OnMenuSetLanguageSpanish)
ON_COMMAND(ID_CONTROL_START, OnMenuStartMasterController)
ON_COMMAND(ID_CONTROL_MAKEWINDMEASUREMENT, OnMenuMakeWindMeasurement)
ON_COMMAND(ID_CONTROL_MAKECOMPOSITIONMEASUREMENT, OnMenuMakeCompositionMeasurement)
ON_COMMAND(ID_ANALYSIS_FLUX, OnMenuAnalysisFlux)
ON_COMMAND(ID_ANALYSIS_REEVALUATE, OnMenuAnalysisReevaluate)
ON_COMMAND(ID_ANALYSIS_SETUP, OnMenuAnalysisSetup)
ON_COMMAND(ID_ANALYSIS_BROWSEMEASUREDDATA, OnMenuAnalysisBrowseData)
ON_COMMAND(ID_ANALYSIS_SUMMARIZEFLUXDATA, OnMenuAnalysisSummarizeFlux)
ON_COMMAND(ID_FILE_EXPORT, OnMenuFileExport)
ON_COMMAND(ID_FILE_IMPORT, OnMenuFileImport)
ON_COMMAND(ID_FILE_SPLITMERGE, OnMenuFileSplitMergePak)
ON_COMMAND(ID_FILE_CHECKPAKFILE, OnMenuFileCheckPakFile)
ON_COMMAND(ID_CONFIGURATION_FILETRANSFER, OnMenuConfigurationFileTransfer)
ON_COMMAND(ID_CONFIGURATION_CONFIGURATION, OnMenuShowConfigurationDialog)
ON_COMMAND(ID_MENU_VIEW_INSTRUMENTTAB, OnMenuViewInstrumentTab)
ON_COMMAND(ID_ANALYSIS_WIND, OnMenuAnalysisWind)
// Changing the units
ON_COMMAND(ID_UNITOFFLUX_KG, OnChangeUnitOfFluxToKgS)
ON_COMMAND(ID_UNITOFFLUX_TON, OnChangeUnitOfFluxToTonDay)
ON_COMMAND(ID_UNITOFCOLUMNS_PPMM, OnChangeUnitOfColumnToPPMM)
ON_COMMAND(ID_UNITOFCOLUMNS_MOLEC_CM2, OnChangeUnitOfColumnToMolecCm2)
// Updating the interface
ON_UPDATE_COMMAND_UI(ID_CONTROL_START, OnUpdateStart)
ON_UPDATE_COMMAND_UI(ID_CONFIGURATION_FILETRANSFER, OnUpdateFileTransfer)
ON_UPDATE_COMMAND_UI(ID_SET_LANGUAGE_ENGLISH, OnUpdateSetLanguageEnglish)
ON_UPDATE_COMMAND_UI(ID_SET_LANGUAGE_ESPA, OnUpdateSetLanguageSpanish)
ON_UPDATE_COMMAND_UI(ID_MENU_VIEW_INSTRUMENTTAB, OnUpdateMenuViewInstrumenttab)
ON_UPDATE_COMMAND_UI(ID_UNITOFFLUX_KG, OnUpdateChangeUnitOfFluxToKgS)
ON_UPDATE_COMMAND_UI(ID_UNITOFFLUX_TON, OnUpdateChangeUnitOfFluxToTonDay)
ON_UPDATE_COMMAND_UI(ID_UNITOFCOLUMNS_PPMM, OnUpdateChangeUnitOfColumnToPPMM)
ON_UPDATE_COMMAND_UI(ID_UNITOFCOLUMNS_MOLEC_CM2, OnUpdateChangeUnitOfColumnToMolecCm2)
ON_UPDATE_COMMAND_UI(ID_ANALYSIS_SUMMARIZEFLUXDATA, OnUpdateMenuSummarizeFluxData)
ON_UPDATE_COMMAND_UI(ID_CONTROL_MAKEWINDMEASUREMENT, OnUpdateMakeWindMeasurement)
ON_UPDATE_COMMAND_UI(ID_CONTROL_MAKECOMPOSITIONMEASUREMENT, OnUpdateMakeCompositionMeasurement)
// Windows messages
ON_WM_DESTROY()
ON_WM_SIZE()
END_MESSAGE_MAP()
// CNovacMasterProgramView construction/destruction
using namespace FileHandler;
CNovacMasterProgramView::CNovacMasterProgramView()
: CFormView(CNovacMasterProgramView::IDD)
{
pView = this;
m_evalDataStorage = new CEvaluatedDataStorage();
m_commDataStorage = new CCommunicationDataStorage();
m_overView = NULL;
m_windOverView = NULL;
m_instrumentView= NULL;
}
CNovacMasterProgramView::~CNovacMasterProgramView()
{
delete m_evalDataStorage;
delete m_commDataStorage;
delete m_overView;
delete m_windOverView;
delete m_instrumentView;
for(int i = 0; i < m_scannerPages.GetCount(); ++i){
CPropertyPage *page = m_scannerPages[i];
delete page;
}
m_scannerPages.RemoveAll();
}
void CNovacMasterProgramView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDbSpecView)
DDX_Control(pDX, IDC_STATUS_MESSAGE_LIST, m_statusListBox);
DDX_Control(pDX, IDC_MASTERFRAME, m_masterFrame);
DDX_Control(pDX, IDC_STATUS_STATIC, m_statusFrame);
//}}AFX_DATA_MAP
}
BOOL CNovacMasterProgramView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CNovacMasterProgramView::SetLayout(){
// Resize this window to the size of the main-window
int bottomMargin = 30;
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
CRect thisRect;
GetWindowRect(thisRect);
thisRect.right = thisRect.left + screenWidth;
thisRect.bottom = screenHeight - bottomMargin;
this->MoveWindow(thisRect);
// Put the status-list frame where it should be
CRect statusFrameRect, statusListRect, masterFrameRect;
m_statusFrame.GetWindowRect(statusFrameRect);
int height = statusFrameRect.Height();
statusFrameRect.right = thisRect.Width() - statusFrameRect.left;
statusFrameRect.top = thisRect.Height() - height - bottomMargin;
statusFrameRect.bottom= thisRect.Height() - bottomMargin;
m_statusFrame.MoveWindow(statusFrameRect);
// Put the status-list box where it should be
this->m_statusListBox.GetWindowRect(statusListRect);
statusListRect.left = statusFrameRect.left + 10;
statusListRect.top = statusFrameRect.top + 20;
statusListRect.right = statusFrameRect.right - 10;
statusListRect.bottom = statusFrameRect.bottom - 10;
m_statusListBox.MoveWindow(statusListRect);
// Put the master frame where it should be
this->m_masterFrame.GetWindowRect(masterFrameRect);
masterFrameRect.left = thisRect.left + 10;
masterFrameRect.top = 0;
masterFrameRect.right = thisRect.right - 10;
masterFrameRect.bottom = statusFrameRect.top - 10;
m_masterFrame.MoveWindow(masterFrameRect);
}
void CNovacMasterProgramView::OnInitialUpdate()
{
CString message;
CRect rect, rect2, tabRect;
CString fileName, windFieldFile, userSettingsFile;
CString path, serialNumber, dateStr;
FileHandler::CFluxLogFileHandler fluxLogReader;
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
m_common.GetExePath();
// Fix the layout of the main components to fit the screen
// SetLayout();
// Initialize the master-frame
m_sheet.Construct("", this);
// Read the configuration file
fileName.Format("%sconfiguration.xml", m_common.m_exePath);
FileHandler::CConfigurationFileHandler reader;
reader.ReadConfigurationFile(g_settings, &fileName);
// Read the user settings
userSettingsFile.Format("%s\\user.ini", m_common.m_exePath);
g_userSettings.ReadSettings(&userSettingsFile);
// If there's no output-directory specified
if(strlen(g_settings.outputDirectory) <= 2){
g_settings.outputDirectory.Format(m_common.m_exePath);
}
// Check if there's any flux-logs with data from earlier today
dateStr.Format("%04d.%02d.%02d", m_common.GetYear(), m_common.GetMonth(), m_common.GetDay());
for(unsigned int it = 0; it < g_settings.scannerNum; ++it){
serialNumber.Format(g_settings.scanner[it].spec[0].serialNumber);
path.Format("%sOutput\\%s\\%s\\FluxLog_%s_%s.txt", g_settings.outputDirectory, dateStr, serialNumber, serialNumber, dateStr);
m_evalDataStorage->AddData(serialNumber, NULL);
if(IsExistingFile(path)){
// Try to read the flux-log
fluxLogReader.m_fluxLog.Format(path);
if(FAIL == fluxLogReader.ReadFluxLog())
continue;
if(fluxLogReader.m_fluxesNum > 0){
// Copy the read-in data to the m_evalDataStorage
int fluxesNum = fluxLogReader.m_fluxesNum;
for(int it2 = 0; it2 < fluxesNum; ++it2){
Evaluation::CFluxResult &fl = fluxLogReader.m_fluxes[it2];
CSpectrumInfo &info = fluxLogReader.m_scanInfo[it2];
m_evalDataStorage->AppendFluxResult(it, fl.m_startTime, fl.m_flux, fl.m_fluxOk, info.m_batteryVoltage, info.m_temperature, info.m_exposureTime);
}
// Insert the last used wind-field for the current spectrometer
CWindField windField;
if(fluxLogReader.m_fluxes[fluxesNum-1].m_plumeHeight > 0 && fluxLogReader.m_fluxes[fluxesNum-1].m_plumeHeight < 5000){
windField.SetPlumeHeight(fluxLogReader.m_fluxes[fluxesNum-1].m_plumeHeight, fluxLogReader.m_fluxes[fluxesNum-1].m_plumeHeightSource);
}else{
windField.SetPlumeHeight(1000, MET_DEFAULT);
}
if(fluxLogReader.m_fluxes[fluxesNum-1].m_windDirection > -180 && fluxLogReader.m_fluxes[fluxesNum-1].m_windDirection <= 360){
windField.SetWindDirection(fluxLogReader.m_fluxes[fluxesNum-1].m_windDirection, fluxLogReader.m_fluxes[fluxesNum-1].m_windDirectionSource);
}else{
windField.SetWindDirection(0, MET_DEFAULT);
}
if(fluxLogReader.m_fluxes[fluxesNum-1].m_windSpeed > -1 && fluxLogReader.m_fluxes[fluxesNum-1].m_windSpeed <= 30){
windField.SetWindSpeed(fluxLogReader.m_fluxes[fluxesNum-1].m_windSpeed, fluxLogReader.m_fluxes[fluxesNum-1].m_windSpeedSource);
}else{
windField.SetWindSpeed(10, MET_DEFAULT);
}
g_metData.SetWindField(serialNumber, windField);
}
}
}
// Try to find and read in a wind-field file, if any can be found...
if(g_settings.windSourceSettings.windFieldFile.GetLength() > 0 && IsExistingFile(g_settings.windSourceSettings.windFieldFile)){
if(0 == g_metData.ReadWindFieldFromFile(g_settings.windSourceSettings.windFieldFile)){
ShowMessage("Successfully read in wind-field from file");
this->PostMessage(WM_NEW_WINDFIELD, NULL, NULL);
}
}
// Check if there is any old status-log file from which we can learn anything...
ScanStatusLogFile();
// Initialize the controls of the screen
InitializeControls();
// Enable the tool tips
if(!m_toolTip.Create(this)){
TRACE0("Failed to create tooltip control\n");
}
CTabCtrl *tabPtr = m_sheet.GetTabControl();
for(int i = 0; i < tabPtr->GetItemCount() - 1; ++i){
tabPtr->GetItemRect(i, &tabRect);
m_toolTip.AddTool(tabPtr, IDD_VIEW_SCANNERSTATUS, &tabRect, IDD_VIEW_SCANNERSTATUS);
}
tabPtr->GetItemRect(i, &tabRect);
m_toolTip.AddTool(tabPtr, IDD_VIEW_OVERVIEW, &tabRect, IDD_VIEW_OVERVIEW);
tabPtr->SetToolTips(&m_toolTip);
tabPtr->EnableToolTips(TRUE);
m_toolTip.SetMaxTipWidth(INT_MAX);
m_toolTip.Activate(TRUE);
// If the configuration says automatic startup then start up automatically
if(g_settings.startup == CConfigurationSetting::STARTUP_AUTOMATIC){
// start the master controller
message.Format("Program automatically started");
ShowMessage(message);
this->OnMenuStartMasterController();
}else{
message.Format("%s", m_common.GetString(MSG_PLEASE_PRESS_START));
ShowMessage(message);
}
// initialize the default wind field
g_metData.defaultWindField.SetPlumeHeight(1000, MET_DEFAULT);
g_metData.defaultWindField.SetWindDirection(0, MET_DEFAULT);
g_metData.defaultWindField.SetWindSpeed(10, MET_DEFAULT);
// update the window
UpdateData(FALSE);
}
// CNovacMasterProgramView diagnostics
#ifdef _DEBUG
void CNovacMasterProgramView::AssertValid() const
{
CFormView::AssertValid();
}
void CNovacMasterProgramView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CNovacMasterProgramDoc* CNovacMasterProgramView::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CNovacMasterProgramDoc)));
return (CNovacMasterProgramDoc*)m_pDocument;
}
#endif //_DEBUG
// CNovacMasterProgramView message handlers
// updates the status bar
LRESULT CNovacMasterProgramView::OnShowStatus(WPARAM wParam, LPARAM lParam){
// CString str = "status";
CString *msg;
//msg = &str;
msg = (CString *)wParam;
CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
pFrame->SetStatusBarText(*msg);
return 0;
}
//update the first message of list box
LRESULT CNovacMasterProgramView::OnUpdateMessage(WPARAM wParam,LPARAM lParam)
{
CString *msg = (CString *)wParam;
int topIndex = 0;
topIndex = m_statusListBox.GetTopIndex();
m_statusListBox.DeleteString(topIndex);
m_statusListBox.InsertString(0,*msg);
delete msg;
return 0;
}
LRESULT CNovacMasterProgramView::OnShowMessage(WPARAM wParam, LPARAM lParam){
CString *msg = (CString *)wParam;
CString logFile,dateStr,logPath;
if(msg == NULL)
return 0;
// add the message to the log file
m_common.GetDateText(dateStr);
logPath.Format("%sOutput\\%s", g_settings.outputDirectory,dateStr);
CreateDirectory(logPath,NULL);
logFile.Format("%s\\StatusLog.txt",logPath);
FILE *f = fopen(logFile, "a+");
if(f != NULL){
fprintf(f, "%s\n", *msg);
fclose(f);
}
// update the status message listbox
int nItems = m_statusListBox.GetCount();
if(nItems > 100){
m_statusListBox.DeleteString(100);
}
m_statusListBox.InsertString(0, *msg);
if(strlen(*msg) > 15){
// Find the longest string in the list box.
CString str;
CSize sz;
int dx = 0;
TEXTMETRIC tm;
CDC* pDC = m_statusListBox.GetDC();
CFont* pFont = m_statusListBox.GetFont();
// Select the listbox font, save the old font
CFont* pOldFont = pDC->SelectObject(pFont);
// Get the text metrics for avg char width
pDC->GetTextMetrics(&tm);
for (int i = 0; i < m_statusListBox.GetCount(); i++)
{
m_statusListBox.GetText(i, str);
sz = pDC->GetTextExtent(str);
// Add the avg width to prevent clipping
sz.cx += tm.tmAveCharWidth;
if (sz.cx > dx)
dx = sz.cx;
}
// Select the old font back into the DC
pDC->SelectObject(pOldFont);
m_statusListBox.ReleaseDC(pDC);
// Set the horizontal extent so every character of all strings can be scrolled to.
m_statusListBox.SetHorizontalExtent(dx);
}
delete msg;
return 0;
}
void CNovacMasterProgramView::ForwardMessage(int message, WPARAM wParam, LPARAM lParam){
unsigned int i;
// 1. forward the message to the flux-overview, if it is selected
if(m_overView->m_hWnd != NULL)
m_overView->PostMessage(message, wParam, lParam);
// 2. forward the message to the instrument-overview, if it is selected
if(m_instrumentView->m_hWnd != NULL)
m_instrumentView->PostMessage(message, wParam, lParam);
// 3. Find the scanner view to forward to...
if(wParam != NULL){
CString *serial = (CString *)wParam;
// 3a. look for the correct spectrometer
for(i = 0; i < g_settings.scannerNum; ++i){
if(Equals(*serial, g_settings.scanner[i].spec[0].serialNumber))
break;
}
if(i == g_settings.scannerNum)
return; // <-- nothing found.
// 3b. forward the message to the correct scanner view, if it is selected
if(m_scannerPages[i]->m_hWnd != NULL)
m_scannerPages[i]->PostMessage(message, wParam, lParam);
}else{
// if not to any specific scanner view then just forward to the one which is shown right now
for(i = 0; i < g_settings.scannerNum; ++i){
if(m_scannerPages[i]->m_hWnd != NULL){
m_scannerPages[i]->PostMessage(message, wParam, lParam);
break;
}
}
}
}
LRESULT CNovacMasterProgramView::OnScannerRun(WPARAM wParam, LPARAM lParam)
{
CString *serialID = (CString *)wParam;
m_commDataStorage->SetStatus(*serialID, COMM_STATUS_GREEN);
// forward the message to the correct scanner view
ForwardMessage(WM_SCANNER_RUN, wParam, lParam);
return 0;
}
LRESULT CNovacMasterProgramView::OnScannerSleep(WPARAM wParam, LPARAM lParam)
{
CString *serialID = (CString *)wParam;
m_commDataStorage->SetStatus(*serialID, COMM_STATUS_YELLOW);
// forward the message to the correct scanner view
ForwardMessage(WM_SCANNER_SLEEP, wParam, lParam);
return 0;
}
LRESULT CNovacMasterProgramView::OnScannerNotConnect(WPARAM wParam, LPARAM lParam)
{
CString *serialID = (CString *)wParam;
m_commDataStorage->SetStatus(*serialID, COMM_STATUS_RED);
// forward the message to the correct scanner view
ForwardMessage(WM_SCANNER_NOT_CONNECT, wParam, lParam);
return 0;
}
LRESULT CNovacMasterProgramView::OnNewWindField(WPARAM wParam, LPARAM lParam)
{
this->ForwardMessage(WM_NEW_WINDFIELD, wParam, lParam);
return 0;
}
LRESULT CNovacMasterProgramView::OnDownloadFinished(WPARAM wParam, LPARAM lParam)
{
CString *serialID = (CString *)wParam;
double *dataSpeed = (double *)lParam;
m_commDataStorage->AddDownloadData(*serialID, *dataSpeed);
return 0;
}
LRESULT CNovacMasterProgramView::OnUploadFinished(WPARAM wParam, LPARAM lParam)
{
double linkSpeed = (double)wParam;
m_commDataStorage->AddDownloadData("FTP", linkSpeed);
return 0;
}
LRESULT CNovacMasterProgramView::OnEvalSucess(WPARAM wParam, LPARAM lParam){
// the serial number of the spectrometer that has sucessfully evaluated one scan
CString *serial = (CString *)wParam;
Evaluation::CScanResult *result = (Evaluation::CScanResult *)lParam;
if(result->GetCorruptedNum() == 0)
m_evalDataStorage->SetStatus(*serial, STATUS_GREEN);
else if(result->GetCorruptedNum() < 5)
m_evalDataStorage->SetStatus(*serial, STATUS_YELLOW);
else
m_evalDataStorage->SetStatus(*serial, STATUS_RED);
m_evalDataStorage->AddData(*serial, result);
// forward the message to the correct scanner view
if(m_overView->m_hWnd != NULL){
m_overView->PostMessage(WM_EVAL_SUCCESS, wParam, NULL);
}
if(m_instrumentView->m_hWnd != NULL){
m_instrumentView->PostMessage(WM_EVAL_SUCCESS, wParam, NULL);
}
for(int i = 0; i < g_settings.scannerNum; ++i){
if(Equals(*serial, g_settings.scanner[i].spec[0].serialNumber)){
if(m_scannerPages[i]->m_hWnd != NULL){
Evaluation::CScanResult *copiedResult = new Evaluation::CScanResult();
*copiedResult = *result;
m_scannerPages[i]->PostMessage(WM_EVAL_SUCCESS, wParam, (LPARAM)copiedResult);
}
}
}
// See if we need to upload any auxilliary data to the FTP-server
UploadAuxData();
// clean up the results...
delete result;
return 0;
}
LRESULT CNovacMasterProgramView::OnEvalFailure(WPARAM wParam, LPARAM lParam){
// the serial number of the spectrometer that has failed to evaluate one scan
CString *serial = (CString *)wParam;
if(lParam != NULL){
Evaluation::CScanResult *result = (Evaluation::CScanResult *)lParam;
m_evalDataStorage->AddData(*serial, result);
}
m_evalDataStorage->SetStatus(*serial, STATUS_RED);
// forward the message to the correct scanner view
ForwardMessage(WM_EVAL_FAILURE, wParam, lParam);
return 0;
}
LRESULT CNovacMasterProgramView::OnCorrelationSuccess(WPARAM wParam, LPARAM lParam){
// the serial number of the spectrometer from which one wind-speed measurement has been done
WindSpeedMeasurement::CWindSpeedResult *result = (WindSpeedMeasurement::CWindSpeedResult *)wParam;
// Remember the result
m_evalDataStorage->AddWindData(result->m_serial, result);
// Tell the wind-measurement overview to update, if it is available and selected
if(m_showWindOverView == true && m_windOverView->m_hWnd != NULL)
m_windOverView->PostMessage(WM_CORR_SUCCESS, NULL, NULL);
// Finally, release the memory
delete result;
return 0;
}
LRESULT CNovacMasterProgramView::OnPlumeHeightSuccess(WPARAM wParam, LPARAM lParam){
// The result of the measurement...
Geometry::CGeometryResult *result = (Geometry::CGeometryResult *)wParam;
// Release the memory
delete result;
return 0;
}
LRESULT CNovacMasterProgramView::OnWriteReport(WPARAM wParam, LPARAM lParam){
FileHandler::CReportWriter::WriteReport(m_evalDataStorage, m_commDataStorage);
return 0;
}
void CNovacMasterProgramView::OnMenuSetLanguageEnglish()
{
g_userSettings.m_language = LANGUAGE_ENGLISH;
g_userSettings.WriteToFile();
::SetThreadLocale(MAKELCID(MAKELANGID(0x0409, SUBLANG_DEFAULT),SORT_DEFAULT));
primaryLanguage = 0x0409;
Common common;
MessageBox(common.GetString(MSG_YOU_HAVE_TO_RESTART), "Change of language", MB_OK);
}
void CNovacMasterProgramView::OnMenuSetLanguageSpanish()
{
g_userSettings.m_language = LANGUAGE_SPANISH;
g_userSettings.WriteToFile();
::SetThreadLocale(MAKELCID(MAKELANGID(0x0c0a, SUBLANG_DEFAULT),SORT_DEFAULT));
primaryLanguage = 0x0c0a;
Common common;
MessageBox(common.GetString(MSG_YOU_HAVE_TO_RESTART), "Change of language", MB_OK);
}
void CNovacMasterProgramView::OnUpdateSetLanguageEnglish(CCmdUI *pCmdUI)
{
if(primaryLanguage == 0x0c0a) // 0x0c0a == spanish...
pCmdUI->SetCheck(0);
else
pCmdUI->SetCheck(1);
}
void CNovacMasterProgramView::OnUpdateSetLanguageSpanish(CCmdUI *pCmdUI)
{
if(primaryLanguage == 0x0c0a)
pCmdUI->SetCheck(1);
else
pCmdUI->SetCheck(0);
}
void CNovacMasterProgramView::OnUpdateStart(CCmdUI *pCmdUI)
{
if(m_controller.m_fRunning){
pCmdUI->Enable(FALSE);
}else{
pCmdUI->Enable(TRUE);
}
}
void CNovacMasterProgramView::OnUpdateFileTransfer(CCmdUI *pCmdUI)
{
if(m_controller.m_fRunning){
pCmdUI->Enable(FALSE);
}else{
pCmdUI->Enable(TRUE);
}
}
void CNovacMasterProgramView::OnUpdateMakeWindMeasurement(CCmdUI *pCmdUI)
{
if(m_controller.m_fRunning){
pCmdUI->Enable(TRUE);
}else{
pCmdUI->Enable(FALSE);
}
}
void CNovacMasterProgramView::OnUpdateMakeCompositionMeasurement(CCmdUI *pCmdUI)
{
if(m_controller.m_fRunning){
pCmdUI->Enable(TRUE);
}else{
pCmdUI->Enable(FALSE);
}
}
void CNovacMasterProgramView::OnUpdateMenuSummarizeFluxData(CCmdUI *pCmdUI)
{
#ifndef _DEBUG
pCmdUI->Enable(FALSE);
#endif
}
void CNovacMasterProgramView::OnMenuShowConfigurationDialog()
{
ConfigurationDialog::CConfigurationDlg dlg;
INT_PTR ret = dlg.DoModal();
}
void CNovacMasterProgramView::OnMenuViewInstrumentTab(){
// m_instrumentView->SetActiveWindow();
if(m_instrumentViewVisible){
m_sheet.RemovePage(m_instrumentView);
m_instrumentViewVisible = false;
}else{
m_sheet.AddPage(m_instrumentView);
m_instrumentViewVisible = true;
}
}
void CNovacMasterProgramView::OnDestroy()
{
this->m_controller.Stop();
CFormView::OnDestroy();
}
/** Starting of the master controller */
void CNovacMasterProgramView::OnMenuStartMasterController(){
CString fileName, programName;
int pids[1024];
// Check if there's already a NovacProgram running!!
m_common.GetExePath();
programName.Format("%s", m_common.m_exeFileName);
if(1 != Common::GetAllProcessIDs(programName, pids)){
// There's more than just this instance of the program running - expect problems!
MessageBox("NovacProgram is already running!! \n Please close the other instances of the NovacProgram and restart.", "Error");
return;
}
// check if the controller is already running, if not then start it.
if(!m_controller.m_fRunning){
// (Re-) Read the configuration file
//g_settings.Clear();
//fileName.Format("%sconfiguration.xml", m_common.m_exePath);
//FileHandler::CConfigurationFileHandler reader;
//reader.ReadConfigurationFile(g_settings, &fileName);
//ShowMessage("Read configuration file - configuration.xml");
//InitializeControls(); // update the view
m_controller.Start();
}else{
ShowMessage(m_common.GetString(MSG_PROGRAM_ALREADY_RUNNING));
}
}
void CNovacMasterProgramView::OnMenuMakeWindMeasurement(){
Dialogs::CManualWindDlg windDlg;
windDlg.DoModal();
}
void CNovacMasterProgramView::OnMenuMakeCompositionMeasurement(){
Dialogs::CManualCompositionDlg compDlg;
compDlg.DoModal();
}
BOOL CNovacMasterProgramView::PreTranslateMessage(MSG* pMsg){
m_toolTip.RelayEvent(pMsg);
return CFormView::PreTranslateMessage(pMsg);
}
int CNovacMasterProgramView::InitializeControls(){
// Initialize the master frame
CRect rect, rect2;
CView_Scanner *page;
CString site;
unsigned int i;
TCITEM tcItem;
m_showWindOverView = false;
// Add the pages, one for every spectrometer configured
if(g_settings.scannerNum == 0){
page = new CView_Scanner();
page->Construct(IDD_VIEW_SCANNERSTATUS);
page->m_evalDataStorage = this->m_evalDataStorage;
page->m_commDataStorage = this->m_commDataStorage;
page->m_scannerIndex = 0;
page->m_serial.Format("unknown");
m_sheet.AddPage(page);
m_scannerPages.Add(page);
}else{
for(i = 0; i < g_settings.scannerNum; ++i){
page = new CView_Scanner();
page->Construct(IDD_VIEW_SCANNERSTATUS);
page->m_evalDataStorage = this->m_evalDataStorage;
page->m_commDataStorage = this->m_commDataStorage;
page->m_scannerIndex = i;
page->m_serial.Format("%s", g_settings.scanner[i].spec[0].serialNumber);
page->m_siteName.Format("%s", g_settings.scanner[i].site);
m_sheet.AddPage(page);
m_scannerPages.Add(page);
// if this system can make wind-measurements then show the wind-overView page
if(g_settings.scanner[i].spec[0].channelNum == 2 || g_settings.scanner[i].instrumentType == INSTR_HEIDELBERG){
m_showWindOverView = true;
}
}
}
// ...add the overview page...
m_overView = new CView_OverView();
m_overView->Construct(IDD_VIEW_OVERVIEW);
m_overView->m_evalDataStorage = this->m_evalDataStorage;
m_overView->m_commDataStorage = this->m_commDataStorage;
m_sheet.AddPage(m_overView);
// ...add the instrument overview page...
m_instrumentView = new CView_Instrument();
m_instrumentView->Construct(IDD_VIEW_INSTRUMENT_OVERVIEW);
m_instrumentView->m_evalDataStorage = this->m_evalDataStorage;
m_instrumentView->m_commDataStorage = this->m_commDataStorage;
m_sheet.AddPage(m_instrumentView);
m_instrumentViewVisible = true;
// At last, add the wind-measurements overview page,
// if there is at least one instrument which is capable of making wind-measurements
if(m_showWindOverView){
m_windOverView = new CView_WindMeasOverView();
m_windOverView->Construct(IDD_VIEW_WIND_OVERVIEW);
m_windOverView->m_evalDataStorage = this->m_evalDataStorage;
m_sheet.AddPage(m_windOverView);
}
// Create the sheet and move it to it's position on the screen
m_sheet.Create(this, WS_CHILD | WS_VISIBLE);
m_sheet.ModifyStyleEx(0, WS_EX_CONTROLPARENT);
// Move everything into place...
m_masterFrame.GetWindowRect(rect);
GetWindowRect(rect2);
m_sheet.MoveWindow(rect2.left, rect.top - rect2.top, rect2.Width(), rect.Height());
m_masterFrame.GetWindowRect(rect);
//for(i = 0; i < m_scannerPages.GetCount(); ++i){
// CPropertyPage *page = m_scannerPages.GetAt(i);
// page->GetWindowRect(rect2);
// rect2.right = rect.right - 10;
// rect2.top -= rect.top;
// rect2.bottom -= rect.top;
// page->MoveWindow(rect2);
//}
// Get the tab control and set the title of each tab to the serial number of the spectrometer
CTabCtrl *tabPtr = m_sheet.GetTabControl();
if(g_settings.scannerNum <= 0){
// Get the 'item' of the tab.
tcItem.mask = TCIF_TEXT;
// Set the text in the 'item'
site.Format("Unknown Scanner");
tcItem.pszText = site.GetBuffer(256);
// Update the tab with the updated 'item'
tabPtr->SetItem(0, &tcItem);
}else{
for(i = 0; i < g_settings.scannerNum; ++i){
tcItem.mask = TCIF_TEXT;
// Set the text in the 'item'. !!!! The serial-string is necessary
// otherwise this function changes the global object !!!!!!!!!!!
site.Format("%s", g_settings.scanner[i].site);
tcItem.pszText = site.GetBuffer(256);
// Update the tab with the updated 'item'
tabPtr->SetItem(i, &tcItem);
}
}
return 0;
}
void CNovacMasterProgramView::OnMenuAnalysisFlux()
{
CPostFluxDlg fluxDlg;
fluxDlg.DoModal();
}
void CNovacMasterProgramView::OnMenuAnalysisBrowseData(){
Dialogs::CDataBrowserDlg dlg;
dlg.DoModal();
}
void CNovacMasterProgramView::OnMenuAnalysisSummarizeFlux(){
#ifdef _DEBUG
Dialogs::CSummarizeFluxDataDlg dlg;
dlg.DoModal();
#endif
}
void CNovacMasterProgramView::OnMenuAnalysisReevaluate()
{
ReEvaluation::CReEvaluator *reeval = new ReEvaluation::CReEvaluator();
ReEvaluation::CReEvaluationDlg dlg;
dlg.Construct("ReEvaluation", this, 0);
// the scan file page
ReEvaluation::CReEval_ScanDlg page1;
page1.Construct(IDD_REEVAL_SCANFILES);
page1.m_reeval = reeval;
// the fit windows page
ReEvaluation::CReEval_WindowDlg page2;
page2.Construct(IDD_REEVAL_WINDOW);
page2.m_reeval = reeval;
// the 'misc settings' page
ReEvaluation::CReEval_MiscSettingsDlg page3;
page3.Construct(IDD_REEVAL_MISC);
page3.m_reeval = reeval;
// the 'do evaluation' page
ReEvaluation::CReEval_DoEvaluationDlg page4;
page4.Construct(IDD_REEVAL_FINAL);
page4.m_reeval = reeval;
// add the pages
dlg.AddPage(&page1);
dlg.AddPage(&page2);
dlg.AddPage(&page3);
dlg.AddPage(&page4);
// show the window
dlg.DoModal();
delete reeval;
}
void CNovacMasterProgramView::OnMenuFileExport()
{
Dialogs::CExportDlg dlg;
dlg.Construct("Export", this, 0);
// the spectrum page
Dialogs::CExportSpectraDlg page1;
page1.Construct(IDD_EXPORT_SPECTRA);
// the evaluation log page
Dialogs::CExportEvallogDlg page2;
page2.Construct(IDD_EXPORT_EVALLOG);
// add the pages
dlg.AddPage(&page1);
dlg.AddPage(&page2);
// show the window
dlg.DoModal();
}
void CNovacMasterProgramView::OnMenuFileImport()
{
Dialogs::CExportDlg dlg;
dlg.Construct("Import", this, 0);
// the spectrum page
Dialogs::CImportSpectraDlg page1;