/
GribUIDialog.cpp
1982 lines (1696 loc) · 78.5 KB
/
GribUIDialog.cpp
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
/******************************************************************************
*
* Project: OpenCPN
* Purpose: GRIB Object
* Author: David Register
*
***************************************************************************
* Copyright (C) 2010 by David S. Register *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************
*
*/
#include "wx/wx.h"
#include "wx/tokenzr.h"
#include "wx/datetime.h"
#include "wx/sound.h"
#include <wx/wfstream.h>
#include <wx/dir.h>
#include <wx/filename.h>
#include <wx/debug.h>
#include <wx/graphics.h>
#include <wx/stdpaths.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "grib_pi.h"
#include "GribTable.h"
#include "email.h"
#include "folder.xpm"
#include <wx/arrimpl.cpp>
#if defined (_WIN32)
int round (double x) {
int i = (int) x;
if (x >= 0.0) {
return ((x-i) >= 0.5) ? (i + 1) : (i);
} else {
return (-x+i >= 0.5) ? (i - 1) : (i);
}
}
#endif
WX_DEFINE_OBJARRAY( ArrayOfGribRecordSets );
enum { SAILDOCS,ZYGRIB };
enum { GFS,COAMPS,RTOFS };
// Sort compare function for File Modification Time
static int CompareFileStringTime( const wxString& first, const wxString& second )
{
wxFileName f( first );
wxFileName s( second );
wxTimeSpan sp = s.GetModificationTime() - f.GetModificationTime();
return sp.GetMinutes();
// return ::wxFileModificationTime(first) - ::wxFileModificationTime(second);
}
//date/time in the desired time zone format
static wxString TToString( const wxDateTime date_time, const int time_zone )
{
wxDateTime t( date_time );
t.MakeFromTimezone( wxDateTime::UTC );
if( t.IsDST() ) t.Subtract( wxTimeSpan( 1, 0, 0, 0 ) );
switch( time_zone ) {
case 0: return t.Format( _T(" %a %d-%b-%Y %H:%M "), wxDateTime::Local ) + _T("LOC");//:%S
case 1:
default: return t.Format( _T(" %a %d-%b-%Y %H:%M "), wxDateTime::UTC ) + _T("UTC");
}
}
wxString toMailFormat ( int NEflag, int a )
{
char c;
switch(NEflag) {
case 1:
c = 'N';
if ( a < 0.0 ) c = 'S';
break;
case 2:
c = 'E';
if ( a < 0.0 ) c = 'W';
}
wxString s;
s.Printf ( _T ( "%01d%c" ), abs(a), c );
return s;
}
#if !wxCHECK_VERSION(2,9,4) /* to work with wx 2.8 */
#define SetBitmap SetBitmapLabel
#endif
const wxString buttonText[] = {_("Moving Grib Disabled"), _("Moving Grib Enabled") };
//---------------------------------------------------------------------------------------
// GRIB Selector/Control Dialog Implementation
//---------------------------------------------------------------------------------------
/* interpolating constructor
as a possible optimization, write this function to also
take latitude longitude boundaries so the resulting record can be
a subset of the input, but also would need to be recomputed when panning the screen */
GribTimelineRecordSet::GribTimelineRecordSet(GribRecordSet &GRS1, GribRecordSet &GRS2, double interp_const)
{
for(int i=0; i<Idx_COUNT; i++) {
GribRecord *GR1 = GRS1.m_GribRecordPtrArray[i];
GribRecord *GR2 = GRS2.m_GribRecordPtrArray[i];
if(GR1 && GR2 && GR1->isOk() && GR2->isOk() &&
GR1->getDi() == GR2->getDi() && GR1->getDj() == GR2->getDj() &&
GR1->getLatMin() == GR2->getLatMin() && GR1->getLonMin() == GR2->getLonMin() &&
GR1->getLatMax() == GR2->getLatMax() && GR1->getLonMax() == GR2->getLonMax())
m_GribRecordPtrArray[i] = new GribRecord(*GR1, *GR2, interp_const);
else
m_GribRecordPtrArray[i] = NULL;
m_IsobarArray[i] = NULL;
}
m_Reference_Time = (1-interp_const)*GRS1.m_Reference_Time
+ interp_const*GRS2.m_Reference_Time;
}
GribTimelineRecordSet::~GribTimelineRecordSet()
{
for(int i=0; i<Idx_COUNT; i++)
delete m_GribRecordPtrArray[i]; /* delete these for timeline */
ClearCachedData();
}
void GRIBUIDialog::OpenFile(bool newestFile)
{
m_bpPlay->SetBitmap(*m_bPlay);
m_bpPlay->SetToolTip(_("Play"));
m_tPlayStop.Stop();
SetCanvasContextMenuItemViz( pPlugIn->m_MenuItem, false);
m_cRecordForecast->Clear();
pPlugIn->GetGRIBOverlayFactory()->SetAltitude( 0 );
delete m_bGRIBActiveFile;
m_pTimelineSet = NULL;
m_InterpolateMode = false;
m_pNowMode = false;
m_pMovingGrib = false;
//get more recent file in default directory if necessary
wxFileName f( m_file_name );
if( newestFile || f.GetFullName().IsEmpty() ) m_file_name = GetNewestFileInDirectory();
m_bGRIBActiveFile = new GRIBFile( m_file_name,
pPlugIn->GetCopyFirstCumRec(),
pPlugIn->GetCopyMissWaveRec() );
ArrayOfGribRecordSets *rsa = m_bGRIBActiveFile->GetRecordSetArrayPtr();
if(rsa->GetCount() < 2)
m_TimeLineHours = 0;
else {
GribRecordSet &first=rsa->Item(0), &second = rsa->Item(1), &last = rsa->Item(rsa->GetCount()-1);
//get file interval index
int halphintermin(wxTimeSpan(wxDateTime(second.m_Reference_Time) - wxDateTime(first.m_Reference_Time)).GetMinutes() / 2);
for( m_FileIntervalIndex=0;;m_FileIntervalIndex++){
if(m_OverlaySettings.GetMinFromIndex(m_FileIntervalIndex) > halphintermin) break;
}
m_FileIntervalIndex--;
if(m_OverlaySettings.m_SlicesPerUpdate > m_FileIntervalIndex) m_OverlaySettings.m_SlicesPerUpdate = m_FileIntervalIndex;
//search for a moving grib file
double wmin1,wmax1,hmin1,hmax1,wmin2,wmax2,hmin2,hmax2;
GetGribZoneLimits(GetTimeLineRecordSet(first.m_Reference_Time), &wmin1, &wmax1, &hmin1, &hmax1 );
GetGribZoneLimits(GetTimeLineRecordSet(last.m_Reference_Time), &wmin2, &wmax2, &hmin2, &hmax2 );
if( wmin1 != wmin2 || wmax1 != wmax2 || hmin1 != hmin2 || hmax1 != hmax2 )
m_pMovingGrib = true;
//
wxTimeSpan span = wxDateTime(last.m_Reference_Time) - wxDateTime(first.m_Reference_Time);
m_TimeLineHours = span.GetHours();
m_sTimeline->Enable();
}
m_sTimeline->SetValue(0);
wxFileName fn( m_file_name );
wxString title( fn.GetFullName() );
if( m_bGRIBActiveFile ) {
if( m_bGRIBActiveFile->IsOK() ) {
//there could be valid but empty file
if( rsa->GetCount() == 0 ) {
m_bGRIBActiveFile = NULL;
pPlugIn->GetGRIBOverlayFactory()->SetMessage( _("Error: No valid data in this file!") );
} else {
PopulateComboDataList();
title.append( _T("(") + TToString( m_bGRIBActiveFile->GetRefDateTime(), pPlugIn->GetTimeZone()) + _T(")"));
}
if( rsa->GetCount() > 1 )
SetCanvasContextMenuItemViz( pPlugIn->m_MenuItem, true);
} else {
if( fn.IsDir() ) {
pPlugIn->GetGRIBOverlayFactory()->SetMessage( _("Warning: Empty directory!") );
}
else
pPlugIn->GetGRIBOverlayFactory()->SetMessage( m_bGRIBActiveFile->GetLastMessage() );
}
this->SetTitle(title);
SetFactoryOptions();
if( pPlugIn->GetStartOptions() )
ComputeBestForecastForNow();
else
TimelineChanged();
PopulateTrackingControls();
}
if(m_pMovingGrib) {
wxMessageDialog mes(this, _("The Grib file you are opening contains a moving Grib Zone.\nInterpolation is not supported for this type of file"),
_("Warning!"), wxOK);
mes.ShowModal();
}
}
bool GRIBUIDialog::GetGribZoneLimits(GribTimelineRecordSet *timelineSet, double *latmin, double *latmax, double *lonmin, double *lonmax)
{
//calculate the largest overlay size
GribRecord **pGR = timelineSet->m_GribRecordPtrArray;
double ltmi = -GRIB_NOTDEF, ltma = GRIB_NOTDEF, lnmi = -GRIB_NOTDEF, lnma = GRIB_NOTDEF;
for( int i = 0; i<36; i++){
GribRecord *pGRA = pGR[i];
if(!pGRA) continue;
if(pGRA->getLatMin() < ltmi) ltmi = pGRA->getLatMin();
if(pGRA->getLatMax() > ltma) ltma = pGRA->getLatMax();
if(pGRA->getLonMin() < lnmi) lnmi = pGRA->getLonMin();
if(pGRA->getLonMax() > lnma) lnma = pGRA->getLonMax();
}
if( ltmi == -GRIB_NOTDEF || lnmi == -GRIB_NOTDEF ||
ltma == GRIB_NOTDEF || lnma == GRIB_NOTDEF)
return false;
if(latmin) *latmin = ltmi;
if(latmax) *latmax = ltma;
if(lonmin) *lonmin = lnmi;
if(lonmax) *lonmax = lnma;
return true;
}
wxString GRIBUIDialog::GetNewestFileInDirectory()
{
if( !wxDir::Exists( m_grib_dir ) ) {
wxStandardPathsBase& path = wxStandardPaths::Get();
m_grib_dir = path.GetDocumentsDir();
}
// Get an array of GRIB file names in the target directory, not descending into subdirs
wxArrayString file_array;
int m_n_files = 0;
m_n_files = wxDir::GetAllFiles( m_grib_dir, &file_array, _T ( "*.grb" ), wxDIR_FILES );
m_n_files += wxDir::GetAllFiles( m_grib_dir, &file_array, _T ( "*.bz2" ),
wxDIR_FILES );
if( m_n_files ) {
file_array.Sort( CompareFileStringTime ); //sort the files by File Modification Date
return file_array[0]; //return the first file (the more recent one)
} else {
wxFileName d(m_grib_dir);
return wxString( m_grib_dir.Append(d.GetPathSeparator()) ); //this directory is empty
}
}
void GribTimelineRecordSet::ClearCachedData()
{
for(int i=0; i<Idx_COUNT; i++) {
if(m_IsobarArray[i]) {
// Clear out the cached isobars
for( unsigned int j = 0; j < m_IsobarArray[i]->GetCount(); j++ ) {
IsoLine *piso = (IsoLine *) m_IsobarArray[i]->Item( j );
delete piso;
}
delete m_IsobarArray[i];
m_IsobarArray[i] = NULL;
}
}
}
GRIBUIDialog::GRIBUIDialog(wxWindow *parent, grib_pi *ppi)
: GRIBUIDialogBase(parent)
{
pParent = parent;
pPlugIn = ppi;
pReq_Dialog = NULL;
m_bGRIBActiveFile = NULL;
m_pTimelineSet = NULL;
wxFileConfig *pConf = GetOCPNConfigObject();
if(pConf) {
pConf->SetPath ( _T ( "/Settings/GRIB" ) );
bool value;
pConf->Read( _T ( "WindPlot" ), &value, true );
m_cbWind->SetValue(value);
pConf->Read( _T ( "WindGustPlot" ), &value, false );
m_cbWindGust->SetValue(value);
pConf->Read( _T ( "PressurePlot" ), &value, false );
m_cbPressure->SetValue(value);
pConf->Read( _T ( "WavePlot" ), &value, false );
m_cbWave->SetValue(value);
pConf->Read( _T ( "CurrentPlot" ), &value, false );
m_cbCurrent->SetValue(value);
pConf->Read( _T ( "PrecipitationPlot" ), &value, false );
m_cbPrecipitation->SetValue(value);
pConf->Read( _T ( "CloudPlot" ), &value, false );
m_cbCloud->SetValue(value);
pConf->Read( _T ( "AirTemperaturePlot" ), &value, false );
m_cbAirTemperature->SetValue(value);
pConf->Read( _T ( "SeaTemperaturePlot" ), &value, false );
m_cbSeaTemperature->SetValue(value);
pConf->Read( _T ( "CAPEPlot" ), &value, false );
m_cbCAPE->SetValue(value);
pConf->Read ( _T ( "lastdatatype" ), &m_lastdatatype, 0);
pConf->Read ( _T ( "Filename" ), &m_file_name );
wxStandardPathsBase& spath = wxStandardPaths::Get();
pConf->SetPath ( _T ( "/Directories" ) );
pConf->Read ( _T ( "GRIBDirectory" ), &m_grib_dir, spath.GetDocumentsDir() );
}
m_bpPrev->SetBitmap(wxBitmap( prev ));
m_bpNext->SetBitmap(wxBitmap( next ));
m_bpNow->SetBitmap(wxBitmap( now ));
m_bpZoomToCenter->SetBitmap(wxBitmap( zoomto ));
m_bPlay = new wxBitmap( play );
m_bpPlay->SetBitmap(*m_bPlay );
m_bpOpenFile->SetBitmap(wxBitmap( openfile ));
m_bpSettings->SetBitmap(wxBitmap( setting ));
m_bpRequest->SetBitmap(wxBitmap( request ));
//connect events have not been done in dialog base
this->Connect( wxEVT_MOVE, wxMoveEventHandler( GRIBUIDialog::OnMove ) );
m_tPlayStop.Connect(wxEVT_TIMER, wxTimerEventHandler( GRIBUIDialog::OnPlayStopTimer ), NULL, this);
m_OverlaySettings.Read();
DimeWindow( this );
m_pTimelineSet = NULL;
m_fgTrackingDisplay->Show(2,false); //Hide extra altitude data parameters
//is there a bug in wxWigget? m_fgTrackingControls->Clear() delete m_fcAltitude so it's necessary to detach it before
m_fgTrackingControls->Detach(m_fcAltitude);
m_fgTrackingControls->Clear();
Fit();
SetMinSize( GetBestSize() );
}
GRIBUIDialog::~GRIBUIDialog()
{
wxFileConfig *pConf = GetOCPNConfigObject();;
if(pConf) {
pConf->SetPath ( _T ( "/Settings/GRIB" ) );
pConf->Write( _T ( "WindPlot" ), m_cbWind->GetValue());
pConf->Write( _T ( "WindGustPlot" ), m_cbWindGust->GetValue());
pConf->Write( _T ( "PressurePlot" ), m_cbPressure->GetValue());
pConf->Write( _T ( "WavePlot" ), m_cbWave->GetValue());
pConf->Write( _T ( "CurrentPlot" ), m_cbCurrent->GetValue());
pConf->Write( _T ( "PrecipitationPlot" ), m_cbPrecipitation->GetValue());
pConf->Write( _T ( "CloudPlot" ), m_cbCloud->GetValue());
pConf->Write( _T ( "AirTemperaturePlot" ), m_cbAirTemperature->GetValue());
pConf->Write( _T ( "SeaTemperaturePlot" ), m_cbSeaTemperature->GetValue());
pConf->Write( _T ( "CAPEPlot" ), m_cbCAPE->GetValue());
pConf->Write( _T ( "lastdatatype" ), m_lastdatatype);
pConf->Write ( _T ( "Filename" ), m_file_name );
pConf->SetPath ( _T ( "/Directories" ) );
pConf->Write ( _T ( "GRIBDirectory" ), m_grib_dir );
}
delete m_pTimelineSet;
}
void GRIBUIDialog::SetCursorLatLon( double lat, double lon )
{
m_cursor_lon = lon;
m_cursor_lat = lat;
UpdateTrackingControls();
}
void GRIBUIDialog::ContextMenuItemCallback(int id)
{
wxFileConfig *pConf = GetOCPNConfigObject();
int x,y,w,h;
if(pConf) {
pConf->SetPath ( _T ( "/Settings/GRIB" ) );
pConf->Read( _T ( "GribDataTablePosition_x" ), &x, -1 );
pConf->Read( _T ( "GribDataTablePosition_y" ), &y, -1 );
pConf->Read( _T ( "GribDataTableWidth" ), &w, 900 );
pConf->Read( _T ( "GribDataTableHeight" ), &h, 350 );
}
//init centered position and default size if not set yet
if(x==-1 && y == -1) { x = (m_vp->pix_width - w) / 2; y = (m_vp->pix_height - h) /2; }
ArrayOfGribRecordSets *rsa = m_bGRIBActiveFile->GetRecordSetArrayPtr();
GRIBTable *table = new GRIBTable(*this);
table->InitGribTable( pPlugIn->GetTimeZone(), rsa );
table->m_pButtonTableOK->SetLabel(_("Close"));
//set dialog size and position
table->SetSize(w, h);
table->SetPosition(wxPoint(x, y));
table->ShowModal();
}
void GRIBUIDialog::SetViewPort( PlugIn_ViewPort *vp )
{
if(m_vp == vp) return;
m_vp = new PlugIn_ViewPort(*vp);
if(pReq_Dialog)
if(pReq_Dialog->IsShown()) pReq_Dialog->OnVpChange(vp);
}
void GRIBUIDialog::AddTrackingControl( wxControl *ctrl1, wxControl *ctrl2, wxControl *ctrl3, bool show, bool altitude )
{
if(show) {
if( altitude ){
m_fcAltitude->Add(ctrl1, 0, wxALL, 1);
ctrl1->Show();
m_cbAltitude->Show();
m_fgTrackingControls->Add( m_fcAltitude, 1, wxRIGHT|wxBOTTOM, 3 );
} else {
m_fgTrackingControls->Add(ctrl1, 0, wxALL, 1);
ctrl1->Show();
}
if(ctrl2) {
m_fgTrackingControls->Add(ctrl2, 0, wxALL, 1);
ctrl2->Show();
} else
m_fgTrackingControls->Add(0, 0, 1, wxEXPAND, 1); /* spacer */
if(ctrl3) {
m_fgTrackingControls->Add(ctrl3, 0, wxALL, 1);
ctrl3->Show();
} else
m_fgTrackingControls->Add(0, 0, 1, wxEXPAND, 1); /* spacer */
} else {
ctrl1->Hide();
if(ctrl2)
ctrl2->Hide();
if(ctrl3)
ctrl3->Hide();
}
}
void GRIBUIDialog::PopulateTrackingControls( void )
{
wxColour bgd1,bgd2;
GetGlobalColor( _T("DILG0"),&bgd1);
GetGlobalColor( _T("YELO1"),&bgd2);
m_tcWindSpeed->SetBackgroundColour(bgd1);
//fix crash with curious files with no record
if(m_pTimelineSet) {
m_bpSettings->Enable();
m_bpZoomToCenter->Enable();
} else {
m_bpSettings->Disable();
m_bpZoomToCenter->Disable();
}
if(m_pTimelineSet && m_TimeLineHours) {
m_sTimeline->Show();
m_bpPlay->Show();
m_bpPrev->Enable();
m_bpNext->Enable();
m_bpNow->Enable();
} else {
m_sTimeline->Hide();
m_bpPlay->Hide();
m_bpPrev->Disable();
m_bpNext->Disable();
m_bpNow->Disable();
}
//is there a bug in wxWigget? flexsizer->Clear() delete child if it's a flexsizer so it's necessary to detach it before
if(m_fgTrackingControls->GetItem(m_fcAltitude) != NULL) m_fgTrackingControls->Detach(m_fcAltitude);
m_fgTrackingControls->Clear();
m_fgTrackingControls->SetCols(9);
if(m_fcAltitude->GetItem(m_cbWind) != NULL) m_fcAltitude->Detach(m_cbWind);
m_cbAltitude->Hide();
this->Fit();
//populate and set altitude choice
m_cbAltitude->Clear();
for( int i = 0; i<5; i++) {
if( (( m_pTimelineSet && m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WIND_VX + i) != wxNOT_FOUND
&& m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WIND_VY + i) != wxNOT_FOUND )) || i == 0 )
m_cbAltitude->Append(m_OverlaySettings.GetAltitudeFromIndex( i , m_OverlaySettings.Settings[GribOverlaySettings::PRESSURE].m_Units));
}
AddTrackingControl(m_cbWind, m_tcWindSpeed, m_tcWindDirection,
m_pTimelineSet && m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WIND_VX) != wxNOT_FOUND
&& m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WIND_VY) != wxNOT_FOUND, m_cbAltitude->GetCount() > 1 );
AddTrackingControl(m_cbWindGust, m_tcWindGust, 0, m_pTimelineSet
&& m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WIND_GUST) != wxNOT_FOUND);
AddTrackingControl(m_cbPressure, m_tcPressure, 0, m_pTimelineSet
&& m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_PRESSURE) != wxNOT_FOUND);
/* tracking for wave is funky */
if(m_pTimelineSet && m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_HTSIGW) != wxNOT_FOUND) {
if(m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WVDIR) != wxNOT_FOUND)
AddTrackingControl(m_cbWave, m_tcWaveHeight, m_tcWaveDirection, true);
else {
AddTrackingControl(m_cbWave, m_tcWaveHeight, 0, true);
m_tcWaveDirection->Hide();
}
} else
if(m_pTimelineSet && m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WVDIR) != wxNOT_FOUND) {
AddTrackingControl(m_cbWave, 0, m_tcWaveDirection, true);
m_tcWaveHeight->Hide();
} else
AddTrackingControl(m_cbWave, m_tcWaveHeight, m_tcWaveDirection, false);
AddTrackingControl(m_cbCurrent, m_tcCurrentVelocity, m_tcCurrentDirection,
m_pTimelineSet && m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_SEACURRENT_VX) != wxNOT_FOUND
&& m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_SEACURRENT_VY) != wxNOT_FOUND);
AddTrackingControl(m_cbPrecipitation, m_tcPrecipitation, 0,
m_pTimelineSet && m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_PRECIP_TOT) != wxNOT_FOUND);
AddTrackingControl(m_cbCloud, m_tcCloud, 0,
m_pTimelineSet && m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_CLOUD_TOT) != wxNOT_FOUND);
AddTrackingControl(m_cbAirTemperature, m_tcAirTemperature, 0,
m_pTimelineSet && m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_AIR_TEMP) != wxNOT_FOUND);
AddTrackingControl(m_cbSeaTemperature, m_tcSeaTemperature, 0,
m_pTimelineSet && m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_SEA_TEMP) != wxNOT_FOUND);
AddTrackingControl(m_cbCAPE, m_tcCAPE, 0,
m_pTimelineSet && m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_CAPE) != wxNOT_FOUND);
m_cbAltitude->SetSelection( pPlugIn->GetGRIBOverlayFactory()->m_Altitude );
//
//init and show extra parameters for altitude tracking if necessary
if( pPlugIn->GetGRIBOverlayFactory()->m_Altitude ) {
if( (m_pTimelineSet && m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_AIR_TEMP
+ pPlugIn->GetGRIBOverlayFactory()->m_Altitude) != wxNOT_FOUND)
|| (m_pTimelineSet && m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_HUMID_RE
+ pPlugIn->GetGRIBOverlayFactory()->m_Altitude) != wxNOT_FOUND)
|| (m_pTimelineSet && m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_GEOP_HGT
+ pPlugIn->GetGRIBOverlayFactory()->m_Altitude) != wxNOT_FOUND) ) {
m_fgTrackingDisplay->Show(2, true);
m_tcAltitude->SetValue( _("N/A") );
m_tcTemp->SetValue( _("N/A") );
m_tcRelHumid->SetValue( _("N/A") );
m_tcWindSpeed->SetBackgroundColour(bgd2);
m_tcAltitude->SetBackgroundColour(bgd2);
m_tcTemp->SetBackgroundColour(bgd2);
m_tcRelHumid->SetBackgroundColour(bgd2);
}
m_stAltitudeText->SetLabel((m_OverlaySettings.GetAltitudeFromIndex(
pPlugIn->GetGRIBOverlayFactory()->m_Altitude, m_OverlaySettings.Settings[GribOverlaySettings::PRESSURE].m_Units))
.append(_T(" ")).Append( m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::PRESSURE) ) );
} else
m_fgTrackingDisplay->Show(2,false);
//
//Resize speed ctrl for single or double unit display
if(m_OverlaySettings.Settings[GribOverlaySettings::WIND].m_Units == GribOverlaySettings::BFS)
m_tcWindSpeed->SetMinSize(wxSize(70, -1));
else
m_tcWindSpeed->SetMinSize(wxSize(110, -1) );
//Resize wave height ctrl for single or double display
if(m_pTimelineSet && m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WVPER) == wxNOT_FOUND)
m_tcWaveHeight->SetMinSize(wxSize(70, -1));
else
m_tcWaveHeight->SetMinSize(wxSize(90, -1) );
Fit();
Refresh();
}
void GRIBUIDialog::UpdateTrackingControls( void )
{
if( !m_pTimelineSet )
return;
GribRecord **RecordArray = m_pTimelineSet->m_GribRecordPtrArray;
// Update the wind control
int altitude = pPlugIn->GetGRIBOverlayFactory()->m_Altitude;
if( RecordArray[Idx_WIND_VX + altitude] && RecordArray[Idx_WIND_VY + altitude] ) {
double vx = RecordArray[Idx_WIND_VX + altitude]->
getInterpolatedValue(m_cursor_lon, m_cursor_lat, true );
double vy = RecordArray[Idx_WIND_VY + altitude]->
getInterpolatedValue(m_cursor_lon, m_cursor_lat, true );
if( ( vx != GRIB_NOTDEF ) && ( vy != GRIB_NOTDEF ) ) {
/*in case of beaufort scale unit, it's better to calculate vkn before calibrate value to maintain precision*/
double vkn = sqrt( vx * vx + vy * vy ),vk;
vk = m_OverlaySettings.CalibrateValue(GribOverlaySettings::WIND, vkn);
m_tcWindSpeed->SetValue( wxString::Format( _T("%3d ") + m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::WIND) , (int)round( vk )) );
//wind is a special case: if current unit is not bf ==> double speed display (current unit + bf)
if(m_OverlaySettings.Settings[GribOverlaySettings::WIND].m_Units != GribOverlaySettings::BFS) {
vk = m_OverlaySettings.GetmstobfFactor(vkn)* vkn;
m_tcWindSpeed->SetValue(m_tcWindSpeed->GetValue().Append(_T(" - ")).
Append(wxString::Format( _T("%2d bf"), (int)round( vk ))));
}
//
double ang = 90. + ( atan2( vy, -vx ) * 180. / PI );
if( ang > 360. ) ang -= 360.;
if( ang < 0. ) ang += 360.;
m_tcWindDirection->SetValue( wxString::Format( _T("%03d\u00B0"), (int) ( ang ) ));
} else {
m_tcWindSpeed->SetValue( _("N/A") );
m_tcWindDirection->SetValue( _("N/A") );
}
}
// Update the Wind gusts control
if( RecordArray[Idx_WIND_GUST] ) {
double vkn = RecordArray[Idx_WIND_GUST]->
getInterpolatedValue(m_cursor_lon, m_cursor_lat, true );
if( vkn != GRIB_NOTDEF ) {
vkn = m_OverlaySettings.CalibrateValue(GribOverlaySettings::WIND_GUST, vkn);
m_tcWindGust->SetValue( wxString::Format(_T("%2d ") + m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::WIND_GUST), (int)round( vkn )) );
} else
m_tcWindGust->SetValue( _("N/A") );
}
// Update the Pressure control
if( RecordArray[Idx_PRESSURE] ) {
double press = RecordArray[Idx_PRESSURE]->
getInterpolatedValue(m_cursor_lon, m_cursor_lat, true );
if( press != GRIB_NOTDEF ) {
press = m_OverlaySettings.CalibrateValue(GribOverlaySettings::PRESSURE, press);
int p = (m_OverlaySettings.Settings[GribOverlaySettings::PRESSURE].m_Units == 2) ? 2 : 0; // if PRESSURE & inHG = two decimals
m_tcPressure->SetValue( wxString::Format(_T("%2.*f ") + m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::PRESSURE), p, ( press )) );
} else
m_tcPressure->SetValue( _("N/A") );
}
// Update the Sig Wave Height
if( RecordArray[Idx_HTSIGW] ) {
double height = RecordArray[Idx_HTSIGW]->
getInterpolatedValue(m_cursor_lon, m_cursor_lat, true );
if( height != GRIB_NOTDEF ) {
height = m_OverlaySettings.CalibrateValue(GribOverlaySettings::WAVE, height);
wxString w( wxString::Format( _T("%4.1f ") + m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::WAVE), height ));
if( RecordArray[Idx_WVPER] ) {
double period = RecordArray[Idx_WVPER]->
getInterpolatedValue(m_cursor_lon, m_cursor_lat, true );
if( period != GRIB_NOTDEF ) w.Append( wxString::Format( _T(" - %01ds") , (int) round(period) ));
}
m_tcWaveHeight->SetValue(w);
} else
m_tcWaveHeight->SetValue( _("N/A") );
}
// Update the Wave direction
if( RecordArray[Idx_WVDIR] ) {
double direction = RecordArray[Idx_WVDIR]->
getInterpolatedValue(m_cursor_lon, m_cursor_lat, true );
if( direction != GRIB_NOTDEF )
m_tcWaveDirection->SetValue( wxString::Format( _T("%03d\u00B0"), (int)direction ));
else
m_tcWaveDirection->SetValue( _("N/A") );
}
// Update the Current control
if( RecordArray[Idx_SEACURRENT_VX] && RecordArray[Idx_SEACURRENT_VY] ) {
double vx = RecordArray[Idx_SEACURRENT_VX]->
getInterpolatedValue(m_cursor_lon, m_cursor_lat, true );
double vy = RecordArray[Idx_SEACURRENT_VY]->
getInterpolatedValue(m_cursor_lon, m_cursor_lat, true );
if( ( vx != GRIB_NOTDEF ) && ( vy != GRIB_NOTDEF ) ) {
vx = m_OverlaySettings.CalibrateValue(GribOverlaySettings::CURRENT, vx);
vy = m_OverlaySettings.CalibrateValue(GribOverlaySettings::CURRENT, vy);
double vkn = sqrt( vx * vx + vy * vy );
m_tcCurrentVelocity->SetValue( wxString::Format( _T("%4.1f ") + m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::CURRENT), vkn ) );
double ang = 90. + ( atan2( -vy, vx ) * 180. / PI );
if( ang > 360. ) ang -= 360.;
if( ang < 0. ) ang += 360.;
m_tcCurrentDirection->SetValue( wxString::Format( _T("%03d\u00B0"), (int) ( ang ) ) );
} else {
m_tcCurrentVelocity->SetValue( _("N/A") );
m_tcCurrentDirection->SetValue( _("N/A") );
}
}
// Update total rainfall control
if( RecordArray[Idx_PRECIP_TOT] ) {
double precip = RecordArray[Idx_PRECIP_TOT]->
getInterpolatedValue( m_cursor_lon, m_cursor_lat, true );
if( precip != GRIB_NOTDEF ) {
precip = m_OverlaySettings.CalibrateValue(GribOverlaySettings::PRECIPITATION, precip);
int p = precip < 10. ? 2 : precip < 100. ? 1 : 0;
p += m_OverlaySettings.Settings[GribOverlaySettings::PRECIPITATION].m_Units == 1 ? 1 : 0 ; // if PRESSURE & in = one decimal more
m_tcPrecipitation->SetValue( wxString::Format( _T("%6.*f ") + m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::PRECIPITATION), p, precip ) );
} else
m_tcPrecipitation->SetValue( _("N/A") );
}
// Update total cloud control
if( RecordArray[Idx_CLOUD_TOT] ) {
double cloud = RecordArray[Idx_CLOUD_TOT]->
getInterpolatedValue( m_cursor_lon, m_cursor_lat, true );
if( cloud != GRIB_NOTDEF ) {
cloud = m_OverlaySettings.CalibrateValue(GribOverlaySettings::CLOUD, cloud);
wxString val( wxString::Format( _T("%5.0f "), cloud ) );
m_tcCloud->SetValue( val + m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::CLOUD) );
} else
m_tcCloud->SetValue( _("N/A") );
}
// Update the Air Temperature
if( RecordArray[Idx_AIR_TEMP] ) {
double temp = RecordArray[Idx_AIR_TEMP]->
getInterpolatedValue( m_cursor_lon, m_cursor_lat, true );
if( temp != GRIB_NOTDEF ) {
temp = m_OverlaySettings.CalibrateValue(GribOverlaySettings::AIR_TEMPERATURE, temp);
m_tcAirTemperature->SetValue( wxString::Format( _T("%5.1f ") + m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::AIR_TEMPERATURE), temp ) );
} else
m_tcAirTemperature->SetValue( _("N/A") );
}
// Update the Sea Surface Temperature
if( RecordArray[Idx_SEA_TEMP] ) {
double temp = RecordArray[Idx_SEA_TEMP]->
getInterpolatedValue( m_cursor_lon, m_cursor_lat, true );
if( temp != GRIB_NOTDEF ) {
temp = m_OverlaySettings.CalibrateValue(GribOverlaySettings::SEA_TEMPERATURE, temp);
m_tcSeaTemperature->SetValue( wxString::Format( _T("%5.1f ") + m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::SEA_TEMPERATURE), temp ) );
} else
m_tcSeaTemperature->SetValue( _("N/A") );
}
// Update the Convective Available Potential Energy (CAPE)
if( RecordArray[Idx_CAPE] ) {
double cape = RecordArray[Idx_CAPE]->
getInterpolatedValue( m_cursor_lon, m_cursor_lat, true );
if( cape != GRIB_NOTDEF ) {
cape = m_OverlaySettings.CalibrateValue(GribOverlaySettings::CAPE, cape);
m_tcCAPE->SetValue( wxString::Format( _T("%5.0f ") + m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::CAPE), cape ) );
} else
m_tcCAPE->SetValue( _("N/A") );
}
// Update extra data for altitude
// geopotential altitude
if( RecordArray[Idx_GEOP_HGT + altitude] ) {
double geop = RecordArray[Idx_GEOP_HGT + altitude]->
getInterpolatedValue( m_cursor_lon, m_cursor_lat, true );
if( geop != GRIB_NOTDEF ) {
geop = m_OverlaySettings.CalibrateValue(GribOverlaySettings::GEO_ALTITUDE, geop);
m_tcAltitude->SetValue( wxString::Format( _T("%5.0f "), geop ) + m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::GEO_ALTITUDE) );
} else
m_tcAltitude->SetValue( _("N/A") );
}
// temperature
if( RecordArray[Idx_AIR_TEMP + altitude] ) {
double temp = RecordArray[Idx_AIR_TEMP + altitude]->
getInterpolatedValue( m_cursor_lon, m_cursor_lat, true );
if( temp != GRIB_NOTDEF ) {
temp = m_OverlaySettings.CalibrateValue(GribOverlaySettings::AIR_TEMPERATURE, temp);
m_tcTemp->SetValue( wxString::Format( _T("%5.1f "), temp ) + m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::AIR_TEMPERATURE) );
} else
m_tcTemp->SetValue( _("N/A") );
}
// relative humidity
if( RecordArray[Idx_HUMID_RE + altitude] ) {
double humi = RecordArray[Idx_HUMID_RE + altitude]->
getInterpolatedValue( m_cursor_lon, m_cursor_lat, true );
if( humi != GRIB_NOTDEF ) {
humi = m_OverlaySettings.CalibrateValue(GribOverlaySettings::REL_HUMIDITY, humi);
m_tcRelHumid->SetValue( wxString::Format( _T("%5.0f "), humi ) + m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::REL_HUMIDITY) );
} else
m_tcRelHumid->SetValue( _("N/A") );
}
Fit();
}
void GRIBUIDialog::OnClose( wxCloseEvent& event )
{
pPlugIn->OnGribDialogClose();
}
void GRIBUIDialog::OnMove( wxMoveEvent& event )
{
// Record the dialog position
wxPoint p = GetPosition();
pPlugIn->SetGribDialogX( p.x );
pPlugIn->SetGribDialogY( p.y );
event.Skip();
}
void GRIBUIDialog::OnSize( wxSizeEvent& event )
{
// Record the dialog size
wxSize p = event.GetSize();
pPlugIn->SetGribDialogSizeX( p.x );
pPlugIn->SetGribDialogSizeY( p.y );
event.Skip();
}
void GRIBUIDialog::OnRequest( wxCommandEvent& event )
{
if(pReq_Dialog){ //there is one instance of the dialog
if(pReq_Dialog->IsShown()) return; //already visible
}
delete pReq_Dialog; //delete to be re-created
pReq_Dialog = new GribRequestSetting( this );
pReq_Dialog->SetVpSize(m_vp);
pReq_Dialog->InitRequestConfig();
pReq_Dialog->Show();
pReq_Dialog->Fit();
pReq_Dialog->Refresh();
}
void GRIBUIDialog::OnSettings( wxCommandEvent& event )
{
GribOverlaySettings initSettings = m_OverlaySettings;
GribSettingsDialog *dialog = new GribSettingsDialog( *this, m_OverlaySettings, m_lastdatatype, m_FileIntervalIndex);
if(dialog->ShowModal() == wxID_OK)
{
dialog->WriteSettings();
m_OverlaySettings.Write();
} else
m_OverlaySettings = initSettings;
SetFactoryOptions(true);
TimelineChanged();
PopulateTrackingControls();
}
void GRIBUIDialog::OnPlayStop( wxCommandEvent& event )
{
if( m_bPlay->IsSameAs( m_bpPlay->GetBitmapLabel()) ) {
m_bpPlay->SetBitmap(wxBitmap( stop ));
m_bpPlay->SetToolTip( _("Stop") );
m_tPlayStop.Start( 1000/m_OverlaySettings.m_UpdatesPerSecond, wxTIMER_CONTINUOUS );
} else
m_bpPlay->SetBitmap(*m_bPlay );
m_InterpolateMode = m_OverlaySettings.m_bInterpolate && !m_pMovingGrib;
}
void GRIBUIDialog::OnPlayStopTimer( wxTimerEvent & )
{
if( m_bPlay->IsSameAs( m_bpPlay->GetBitmapLabel()) ) {
m_bpPlay->SetToolTip( _("Play") );
m_tPlayStop.Stop();
return;
}
if(m_sTimeline->GetValue() >= m_sTimeline->GetMax()) {
if(m_OverlaySettings.m_bLoopMode) {
if(m_OverlaySettings.m_LoopStartPoint) {
ComputeBestForecastForNow();
if(m_sTimeline->GetValue() >= m_sTimeline->GetMax()) m_bpPlay->SetBitmap(*m_bPlay );; //will stop playback
return;
} else
m_sTimeline->SetValue(0);
} else
m_bpPlay->SetBitmap(*m_bPlay ); //will stop playback
} else {
int value = m_pNowMode ? m_OverlaySettings.m_bInterpolate && !m_pMovingGrib ?
GetNearestValue(GetNow(), 1) : GetNearestIndex(GetNow(), 2) : m_sTimeline->GetValue();
m_sTimeline->SetValue(value + 1);
}
m_pNowMode = false;
if(!m_InterpolateMode) m_cRecordForecast->SetSelection( m_sTimeline->GetValue() );
TimelineChanged();
}
void GRIBUIDialog::TimelineChanged()
{
if( !m_bGRIBActiveFile || (m_bGRIBActiveFile && !m_bGRIBActiveFile->IsOK()) ) {
pPlugIn->GetGRIBOverlayFactory()->SetGribTimelineRecordSet(NULL);
return;
}
wxDateTime time = TimelineTime();
SetGribTimelineRecordSet(GetTimeLineRecordSet(time));
if( !m_InterpolateMode ){
/* get closest value to update timeline */
double sel = (m_cRecordForecast->GetCurrentSelection());
m_sTimeline->SetValue(
(int) m_OverlaySettings.m_bInterpolate && !m_pMovingGrib ?
sel / (m_cRecordForecast->GetCount()-1) * m_sTimeline->GetMax() : sel
);
} else
m_cRecordForecast->SetValue( TToString( time, pPlugIn->GetTimeZone() ) );
UpdateTrackingControls();
pPlugIn->SendTimelineMessage(time);
RequestRefresh( pParent );
}
int GRIBUIDialog::GetNearestIndex(wxDateTime time, int model)
{
/* get closest index to update combo box */
size_t i;
ArrayOfGribRecordSets *rsa = m_bGRIBActiveFile->GetRecordSetArrayPtr();
wxDateTime itime, ip1time;
for(i=0; i<rsa->GetCount()-1; i++) {
itime = rsa->Item(i).m_Reference_Time;
ip1time = rsa->Item(i+1).m_Reference_Time;
if(ip1time >= time)
break;
}
if(!model) return (time - itime > (ip1time - time)*3) ? i+1 : i;
return model == 1 ? time == ip1time ? i : i+1 : time == ip1time ? i+1 : i;
}
int GRIBUIDialog::GetNearestValue(wxDateTime time, int model)
{
/* get closest value to update Time line */
if(m_TimeLineHours == 0) return 0;
wxDateTime itime, ip1time;
int stepmin = m_OverlaySettings.GetMinFromIndex(m_OverlaySettings.m_SlicesPerUpdate);
wxTimeSpan span = time - MinTime();
int t = span.GetMinutes()/stepmin;
itime = MinTime() + wxTimeSpan( t * stepmin / 60, (t * stepmin) % 60 ); //time at t
ip1time = itime + wxTimeSpan( stepmin / 60, stepmin % 60 ); //time at t+1
if(model == 1) return time == ip1time ? t+1 : t;
return (time - itime > (ip1time - time)*3) ? t+1 : t;
}
wxDateTime GRIBUIDialog::GetNow()
{
//wxDateTime::Now() is in local time and must be transslated to UTC to be compared to grib times
wxDateTime now = wxDateTime::Now().ToUTC(wxDateTime::Now().IsDST()==0).SetSecond(0);
if(now.IsDST()) now.Add(wxTimeSpan( 1,0,0,0)); //bug in wxWidgets ?
ArrayOfGribRecordSets *rsa = m_bGRIBActiveFile->GetRecordSetArrayPtr();
//verifie if we are outside of the file time range
now = (now > rsa->Item(rsa->GetCount()-1).m_Reference_Time) ? rsa->Item(rsa->GetCount()-1).m_Reference_Time :
(now < rsa->Item(0).m_Reference_Time) ? rsa->Item(0).m_Reference_Time : now;
return now;
}
wxDateTime GRIBUIDialog::TimelineTime()
{
if(m_InterpolateMode) {
int tl = (m_TimeLineHours == 0) ? 0 : m_sTimeline->GetValue();
int stepmin = m_OverlaySettings.GetMinFromIndex(m_OverlaySettings.m_SlicesPerUpdate);