1 /******************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: GRIB table
5 * Author: David Register
6 *
7 ***************************************************************************
8 * Copyright (C) 2010 by David S. Register *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
24 ***************************************************************************
25 *
26 */
27
28 #include "wx/wxprec.h"
29
30 #ifndef WX_PRECOMP
31 #include "wx/wx.h"
32 #endif //precompiled headers
33
34 #include <wx/glcanvas.h>
35 #include <wx/graphics.h>
36 #include <wx/progdlg.h>
37 #include <wx/grid.h>
38 #include "GribTable.h"
39 #include "CustomGrid.h"
40 #include <wx/tokenzr.h>
41
42 extern double m_cursor_lat, m_cursor_lon;
43
44 //----------------------------------------------------------------------------------------------------------
45 // GRIB Table Implementation
46 //----------------------------------------------------------------------------------------------------------
47
GRIBTable(GRIBUICtrlBar & parent)48 GRIBTable::GRIBTable(GRIBUICtrlBar &parent)
49 : GRIBTableBase(&parent), m_pGDialog(&parent){}
50
InitGribTable(int zone,ArrayOfGribRecordSets * rsa,int NowIndex)51 void GRIBTable::InitGribTable( int zone, ArrayOfGribRecordSets *rsa, int NowIndex )
52 {
53 m_pGribTable->m_gParent = this;
54 m_pIndex = NowIndex;
55
56 //init row attr
57 wxGridCellAttr *datarow = new wxGridCellAttr();
58 datarow->SetFont(GetOCPNGUIScaledFont_PlugIn( _T("Dialog") ));
59 datarow->SetAlignment(wxALIGN_CENTRE, wxALIGN_CENTRE);
60
61 //populate "cursor position" display
62 wxString l;
63 l.Append(toSDMM_PlugIn(1, m_cursor_lat)).Append(_T(" "))
64 .Append(toSDMM_PlugIn(2, m_cursor_lon));
65 m_pCursorPosition->SetLabel(l);
66 m_pCursorPosition->SetFont(GetOCPNGUIScaledFont_PlugIn(_T("Dialog")).MakeBold());
67 m_pPositionText->SetFont(GetOCPNGUIScaledFont_PlugIn(_T("Dialog")).MakeBold());
68
69 //create as columns as necessary
70 m_pGribTable->AppendCols(rsa->GetCount());
71
72 //populate grid
73 wxDateTime time, day, ptime;
74 int nrows, wcols = 0;
75 for(unsigned i = 0; i < rsa->GetCount(); i++ ) {
76 //populate time labels
77 time = rsa->Item(i).m_Reference_Time;
78 m_pGribTable->SetColLabelValue(i ,GetTimeRowsStrings( time, zone , 1)
79 .Append( _T("\n"))
80 .Append( GetTimeRowsStrings( rsa->Item(i).m_Reference_Time, zone , 0))
81 );
82 nrows = -1;
83 GribTimelineRecordSet *pTimeset = m_pGDialog->GetTimeLineRecordSet(time);
84 if (pTimeset == 0)
85 continue;
86
87 GribRecord **RecordArray = pTimeset->m_GribRecordPtrArray;
88
89 /*create and polulate wind data row
90 wind is a special case:
91 1) if current unit is not bf ==> double speed display (current unit + bf)
92 2) create two lines for direction and speed and a third for gust if exists
93 3) these two or three lines will be part of the same block*/
94 if(m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WIND_VX) != wxNOT_FOUND &&
95 m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WIND_VY) != wxNOT_FOUND) {
96 nrows++;
97 AddDataRow( nrows, i, _("Wind,Dir"), datarow );
98 double wdir;
99 GetWind(RecordArray, 1, wdir); //this is a numerical row
100 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
101 m_pGribTable->SetNumericalRow( nrows, i, R_WIND, wdir );
102 nrows++;
103 AddDataRow( nrows, i, _("Wind,Speed"), datarow );
104 if(m_pGDialog->m_OverlaySettings.Settings[GribOverlaySettings::WIND].m_Units != GribOverlaySettings::BFS)
105 m_pGribTable->SetCellValue(nrows, i, GetWind(RecordArray, 2, wdir) );
106 else
107 m_pGribTable->SetCellValue(nrows, i, GetWind(RecordArray, 3, wdir));
108 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
109 if(m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WIND_GUST) != wxNOT_FOUND) {
110 nrows++;
111 AddDataRow( nrows, i, _("Wind,Gust"), datarow );
112 if(m_pGDialog->m_OverlaySettings.Settings[GribOverlaySettings::WIND].m_Units != GribOverlaySettings::BFS)
113 m_pGribTable->SetCellValue(nrows, i, GetWindGust(RecordArray, 1) );
114 else
115 m_pGribTable->SetCellValue(nrows, i, GetWindGust(RecordArray, 2));
116 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
117 }
118 }//wind
119
120 //create and polulate Pressure data rown
121 if(m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_PRESSURE) != wxNOT_FOUND) {
122 nrows++;
123 AddDataRow( nrows, i, _("Pressure"), datarow );
124 m_pGribTable->SetCellValue(nrows, i, GetPressure(RecordArray));
125 }//pressure
126
127 /*create and polulate Waves data rows
128 waves is another special case:
129 1) if significant height data exists then create a line for direction and height
130 then a third for periode if data exists
131 2) these two or three lines will be part of the same block*/
132 if(m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_HTSIGW) != wxNOT_FOUND) {
133 double wdir;
134 if(m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WVDIR) != wxNOT_FOUND) {
135 nrows++;
136 AddDataRow( nrows, i, _("Waves,Dir"), datarow );
137 GetWaves(RecordArray ,Idx_WVDIR, wdir); //this is a numerical row
138 m_pGribTable->SetNumericalRow( nrows, i, R_WAVES, wdir );
139 }
140 nrows++;
141 AddDataRow( nrows, i, _("Waves,Hsig"), datarow );
142 m_pGribTable->SetCellValue(nrows, i, GetWaves(RecordArray, Idx_HTSIGW, wdir));
143 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
144 if(m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WVPER) != wxNOT_FOUND) {
145 nrows++;
146 AddDataRow( nrows, i, _("Waves,Per"), datarow );
147 m_pGribTable->SetCellValue(nrows, i, GetWaves(RecordArray ,Idx_WVPER, wdir));
148 }
149 }//waves
150
151 //create and polulate total rainfall data row
152 if(m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_PRECIP_TOT) != wxNOT_FOUND) {
153 nrows++;
154 AddDataRow( nrows, i, _("Rainfall"), datarow );
155 m_pGribTable->SetCellValue(nrows, i, GetRainfall(RecordArray));
156 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
157 }//rainfall
158
159 //create and populate total cloud control
160 if(m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_CLOUD_TOT) != wxNOT_FOUND) {
161 nrows++;
162 AddDataRow( nrows, i, _("Cloud Cover"), datarow );
163 m_pGribTable->SetCellValue(nrows, i, GetCloudCover(RecordArray));
164 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
165 }//cloud
166
167 //create and polulate the Air Temperature data row
168 if(m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_AIR_TEMP) != wxNOT_FOUND) {
169 nrows++;
170 AddDataRow( nrows, i, _("Air Temp."), datarow );
171 m_pGribTable->SetCellValue(nrows, i, GetAirTemp(RecordArray));
172 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
173 }//air temp
174
175 //create and polulate the Sea Surface Temperature data row
176 if(m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_SEA_TEMP) != wxNOT_FOUND) {
177 nrows++;
178 AddDataRow( nrows, i, _("Sea Temp."), datarow );
179 m_pGribTable->SetCellValue(nrows, i, GetSeaTemp(RecordArray));
180 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
181 }//sea temp
182
183 //create and polulate the Convective Available Potential Energy (CAPE) data row
184 if(m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_CAPE) != wxNOT_FOUND) {
185 nrows++;
186 AddDataRow( nrows, i, _("CAPE"), datarow );
187 m_pGribTable->SetCellValue(nrows, i, GetCAPE(RecordArray));
188 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
189 }//cape
190
191 //create and polulate the Composite Reflectivity data row
192 if(m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_COMP_REFL) != wxNOT_FOUND) {
193 nrows++;
194 AddDataRow( nrows, i, _("C. Reflect."), datarow );
195 m_pGribTable->SetCellValue(nrows, i, GetCompRefl(RecordArray));
196 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
197 }//composite Reflectivity
198
199 /*create and populate the current data rows
200 1)create two lines for direstion and speed
201 2) these two or three lines will be part of the same block*/
202 if(m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_SEACURRENT_VX) != wxNOT_FOUND &&
203 m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_SEACURRENT_VY) != wxNOT_FOUND) {
204 double wdir;
205 nrows++;
206 AddDataRow( nrows, i, _("Current,Dir"), datarow );
207 GetCurrent(RecordArray, 1, wdir); //this is a numerical row
208 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
209 m_pGribTable->SetNumericalRow( nrows, i, R_CURRENT, wdir );
210
211 nrows++;
212 AddDataRow( nrows, i, _("Current,Speed"), datarow );
213 m_pGribTable->SetCellValue(nrows, i, GetCurrent(RecordArray, 2, wdir));
214 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
215 }//current // populate grid
216 delete pTimeset;
217 m_pGribTable->AutoSizeColumn(i, false);
218 wcols = wxMax(m_pGribTable->GetColSize(i), wcols);
219 }//populate grid
220 //put cursor outside the grid
221 m_pGribTable->SetGridCursor( m_pGribTable->GetNumberRows() -1, 0);
222 //set col size
223 m_pGribTable->SetDefaultColSize( wcols, true );
224 //set row size
225 AutoSizeDataRows();
226 //set label size
227 m_pGribTable->SetColLabelSize(wxGRID_AUTOSIZE);
228 //set scroll steps
229 m_pGribTable->SetScrollLineX( wcols );
230
231 datarow->DecRef(); // Give up pointer contrl to Grid
232
233 m_tScrollToNowTimer.Connect(wxEVT_TIMER, wxTimerEventHandler( GRIBTable::OnScrollToNowTimer ), NULL, this);
234 }
235
SetTableSizePosition(int vpWidth,int vpHeight)236 void GRIBTable::SetTableSizePosition(int vpWidth, int vpHeight)
237 {
238 //Get size & position previously saved
239 int x = -1, y = -1, w = -1, h = -1;
240 wxFileConfig *pConf = GetOCPNConfigObject();
241 if (pConf) {
242 pConf->SetPath(_T("/Settings/GRIB"));
243 pConf->Read(_T("GribDataTablePosition_x"), &x);
244 pConf->Read(_T("GribDataTablePosition_y"), &y);
245 pConf->Read(_T("GribDataTableWidth"), &w);
246 pConf->Read(_T("GribDataTableHeight"), &h);
247 }
248 wxPoint final_pos = GetOCPNCanvasWindow()->ClientToScreen(wxPoint(x, y));
249 //set a default size & position if saved values are outside of limits
250 bool refit = false;
251 wxSize scw = wxSize(vpWidth, (vpHeight - GetChartbarHeight()));
252 wxPoint pcw = GetOCPNCanvasWindow()->ClientToScreen(GetOCPNCanvasWindow()->GetPosition());
253 if( !(wxRect(pcw, scw).Contains(wxRect(final_pos, wxSize(w, h)))) )
254 refit = true;
255 if( w < (m_pGribTable->GetRowLabelSize() + (m_pGribTable->GetColSize(0))) || h < (m_pGribTable->GetColLabelSize() + (m_pGribTable->GetRowSize(0))) )
256 refit = true;
257 if( refit ){
258 w = (scw.GetWidth() / 10) * 9; //10% less than canvas
259 h = (scw.GetHeight() / 10) * 9;
260 x = (scw.GetWidth() / 20); //centered horizontally
261 y = (scw.GetHeight() / 50); //a bit out-centered toward the top
262 final_pos = GetOCPNCanvasWindow()->ClientToScreen(wxPoint(x, y));
263 }//
264 //in case client size toot large for the grib
265 int w1 = m_pGribTable->GetRowLabelSize() + (m_pGribTable->GetColSize(0) * m_pGribTable->GetNumberCols());
266 w = wxMin( w, w1 );
267 int h1 = m_pGribTable->GetColLabelSize() + (m_pGribTable->GetRowSize(0) * (m_pGribTable->GetNumberRows() + 4 ));
268 h = wxMin( h, h1 );
269
270 this->SetClientSize(w, h);
271 this->Move(final_pos);
272
273 //scroll to the end of time steps to prepare the next scroll to 'now'
274 m_pGribTable->MakeCellVisible(0, m_pGribTable->GetNumberCols() - 1);
275 //trigger scroll to 'now'(must be postpone after the dialog is shown)
276 m_tScrollToNowTimer.Start( 200, wxTIMER_ONE_SHOT );
277 }
278
OnScrollToNowTimer(wxTimerEvent & event)279 void GRIBTable::OnScrollToNowTimer( wxTimerEvent& event )
280 {
281 m_pGribTable->MakeCellVisible(0, m_pIndex);
282 }
283
OnClose(wxCloseEvent & event)284 void GRIBTable::OnClose( wxCloseEvent& event )
285 {
286 CloseDialog();
287 this->EndModal(wxID_OK);
288 }
289
OnOKButton(wxCommandEvent & event)290 void GRIBTable::OnOKButton( wxCommandEvent& event )
291 {
292 CloseDialog();
293 this->EndModal(wxID_OK);
294 }
295
CloseDialog()296 void GRIBTable::CloseDialog()
297 {
298 wxSize s = this->GetClientSize();
299 wxPoint p = GetOCPNCanvasWindow()->ScreenToClient( this->GetPosition() );
300
301 wxFileConfig *pConf = GetOCPNConfigObject();
302 if(pConf) {
303 pConf->SetPath ( _T ( "/Settings/GRIB" ) );
304
305 pConf->Write( _T ( "GribDataTablePosition_x" ), p.x );
306 pConf->Write( _T ( "GribDataTablePosition_y" ), p.y );
307 pConf->Write( _T ( "GribDataTableWidth" ), s.GetWidth() );
308 pConf->Write( _T ( "GribDataTableHeight" ), s.GetHeight() );
309 }//
310 }
311
AddDataRow(int num_rows,int num_cols,wxString label,wxGridCellAttr * row_attr)312 void GRIBTable::AddDataRow( int num_rows, int num_cols, wxString label, wxGridCellAttr *row_attr )
313 {
314 if(m_pGribTable->GetNumberRows() == num_rows) {
315 m_pGribTable->AppendRows(1);
316 m_pGribTable->SetRowLabelValue(num_rows, label);
317 row_attr->IncRef();
318 m_pGribTable->SetRowAttr(num_rows, row_attr);
319 }
320 m_pDataCellsColour = m_pGribTable->GetCellBackgroundColour(num_rows, num_cols); //set default colour
321 }
322
AutoSizeDataRows()323 void GRIBTable::AutoSizeDataRows()
324 {
325 int hrows = 0;
326 for( int i = 0; i < m_pGribTable->GetNumberRows(); i++ ) {
327 m_pGribTable->AutoSizeRow(i, false);
328 hrows = wxMax(m_pGribTable->GetRowHeight(i) + 3, hrows);
329 }
330 m_pGribTable->SetDefaultRowSize( hrows, true );
331 //set scroll steps
332 m_pGribTable->SetScrollLineY(hrows);
333 }
334
GetWind(GribRecord ** recordarray,int datatype,double & wdir)335 wxString GRIBTable::GetWind(GribRecord **recordarray, int datatype, double& wdir )
336 {
337 wxString skn(wxEmptyString);
338 int altitude = 0;
339 double vkn, ang;
340 wdir = GRIB_NOTDEF;
341 if(GribRecord::getInterpolatedValues(vkn, ang,
342 recordarray[Idx_WIND_VX + altitude],
343 recordarray[Idx_WIND_VY + altitude],
344 m_cursor_lon, m_cursor_lat)) {
345 if( datatype == 1 ){
346 wdir = ang;
347 return skn;
348 }
349 double cvkn = m_pGDialog->m_OverlaySettings.CalibrateValue(GribOverlaySettings::WIND, vkn);
350 m_pDataCellsColour = m_pGDialog->pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(GribOverlaySettings::WIND, cvkn);
351 skn.Printf( wxString::Format( _T("%2d bf"), (int)wxRound( m_pGDialog->m_OverlaySettings.GetmstobfFactor(vkn)* vkn )) );
352 if( datatype ==2 ) { //wind speed unit other than bf
353 skn.Prepend(wxString::Format( _T("%2d ") + m_pGDialog->m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::WIND) , (int) wxRound( cvkn )) + _T(" - "));
354 }
355 }
356 return skn;
357 }
358
GetWindGust(GribRecord ** recordarray,int datatype)359 wxString GRIBTable::GetWindGust(GribRecord **recordarray, int datatype )
360 {
361 wxString skn(wxEmptyString);
362 if( recordarray[Idx_WIND_GUST] ) {
363 double vkn = recordarray[Idx_WIND_GUST]->
364 getInterpolatedValue(m_cursor_lon, m_cursor_lat, true );
365 if( vkn != GRIB_NOTDEF ) {
366 double cvkn = m_pGDialog->m_OverlaySettings.CalibrateValue(GribOverlaySettings::WIND_GUST, vkn);
367 m_pDataCellsColour = m_pGDialog->pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(GribOverlaySettings::WIND_GUST, cvkn);
368
369 skn.Printf( wxString::Format( _T("%2d bf"), (int)wxRound( m_pGDialog->m_OverlaySettings.GetmstobfFactor(vkn)* vkn )) ); //wind gust unit bf
370 if( datatype == 1 ) { //wind gust unit other than bf
371 skn.Prepend( wxString::Format(_T("%2d ") + m_pGDialog->m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::WIND_GUST), (int) wxRound( cvkn)) + _T(" - " ) );
372 }
373 }
374 }
375 return skn;
376 }
377
GetPressure(GribRecord ** recordarray)378 wxString GRIBTable::GetPressure(GribRecord **recordarray)
379 {
380 wxString skn(wxEmptyString);
381 if( recordarray[Idx_PRESSURE] ) {
382 double press = recordarray[Idx_PRESSURE]->
383 getInterpolatedValue(m_cursor_lon, m_cursor_lat, true );
384
385 if( press != GRIB_NOTDEF ) {
386 press = m_pGDialog->m_OverlaySettings.CalibrateValue(GribOverlaySettings::PRESSURE, press);
387 int p = (m_pGDialog->m_OverlaySettings.Settings[GribOverlaySettings::PRESSURE].m_Units == 2) ? 2 : 0; // if PRESSURE & inHG = two decimals
388 skn.Printf( wxString::Format(_T("%2.*f ") + m_pGDialog->m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::PRESSURE), p, ( press )) );
389 }
390 }
391 return skn;
392 }
393
GetWaves(GribRecord ** recordarray,int datatype,double & wdir)394 wxString GRIBTable::GetWaves(GribRecord **recordarray, int datatype, double& wdir)
395 {
396 wxString skn(wxEmptyString);
397 wdir = GRIB_NOTDEF;
398 switch (datatype ) {
399 case Idx_HTSIGW:
400 if( recordarray[Idx_HTSIGW] ) {
401 double height = recordarray[Idx_HTSIGW]->
402 getInterpolatedValue(m_cursor_lon, m_cursor_lat, true );
403 if( height != GRIB_NOTDEF ) {
404 double cheight = m_pGDialog->m_OverlaySettings.CalibrateValue(GribOverlaySettings::WAVE, height);
405 skn.Printf( wxString::Format( _T("%4.1f ") + m_pGDialog->m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::WAVE), cheight ));
406 m_pDataCellsColour = m_pGDialog->pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(GribOverlaySettings::WAVE, cheight);
407 }
408 }
409 break;
410 case Idx_WVDIR:
411 if( recordarray[Idx_WVDIR] ) {
412 double direction = recordarray[Idx_WVDIR]->
413 getInterpolatedValue(m_cursor_lon, m_cursor_lat, true, true );
414 wdir = direction;
415 return skn;
416 }
417 break;
418 case Idx_WVPER:
419 if( recordarray[Idx_WVPER] ) {
420 double period = recordarray[Idx_WVPER]->
421 getInterpolatedValue(m_cursor_lon, m_cursor_lat, true );
422 if( period != GRIB_NOTDEF )
423 skn.Printf( wxString::Format( _T("%01ds") , (int) (period + 0.5)) );
424 }
425 }
426 return skn;
427 }
428
GetRainfall(GribRecord ** recordarray)429 wxString GRIBTable::GetRainfall(GribRecord **recordarray)
430 {
431 wxString skn(wxEmptyString);
432 if( recordarray[Idx_PRECIP_TOT] ) {
433 double precip = recordarray[Idx_PRECIP_TOT]->
434 getInterpolatedValue(m_cursor_lon, m_cursor_lat, true );
435
436 if( precip != GRIB_NOTDEF ) {
437 precip = m_pGDialog->m_OverlaySettings.CalibrateValue(GribOverlaySettings::PRECIPITATION, precip);
438 skn.Printf( _T("%6.2f ") + m_pGDialog->m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::PRECIPITATION), precip );
439 m_pDataCellsColour = m_pGDialog->pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(GribOverlaySettings::PRECIPITATION, precip);
440 }
441 }
442 return skn;
443 }
444
GetCloudCover(GribRecord ** recordarray)445 wxString GRIBTable::GetCloudCover(GribRecord **recordarray)
446 {
447 wxString skn(wxEmptyString);
448 if( recordarray[Idx_CLOUD_TOT] ) {
449 double cloud = recordarray[Idx_CLOUD_TOT]->
450 getInterpolatedValue(m_cursor_lon, m_cursor_lat, true );
451
452 if( cloud != GRIB_NOTDEF ) {
453 cloud = m_pGDialog->m_OverlaySettings.CalibrateValue(GribOverlaySettings::CLOUD, cloud);
454 skn.Printf( _T("%5.1f "), cloud );
455 skn.Append(m_pGDialog->m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::CLOUD));
456 m_pDataCellsColour = m_pGDialog->pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(GribOverlaySettings::CLOUD, cloud);
457 }
458 }
459 return skn;
460 }
461
GetAirTemp(GribRecord ** recordarray)462 wxString GRIBTable::GetAirTemp(GribRecord **recordarray)
463 {
464 wxString skn(wxEmptyString);
465 if( recordarray[Idx_AIR_TEMP] ) {
466 double temp = recordarray[Idx_AIR_TEMP]->
467 getInterpolatedValue(m_cursor_lon, m_cursor_lat, true );
468
469 if( temp != GRIB_NOTDEF ) {
470 temp = m_pGDialog->m_OverlaySettings.CalibrateValue(GribOverlaySettings::AIR_TEMPERATURE, temp);
471 skn.Printf( _T("%5.1f ") + m_pGDialog->m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::AIR_TEMPERATURE), temp );
472 m_pDataCellsColour = m_pGDialog->pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(GribOverlaySettings::AIR_TEMPERATURE, temp);
473 }
474 }
475 return skn;
476 }
477
GetSeaTemp(GribRecord ** recordarray)478 wxString GRIBTable::GetSeaTemp(GribRecord **recordarray)
479 {
480 wxString skn(wxEmptyString);
481 if( recordarray[Idx_SEA_TEMP] ) {
482 double temp = recordarray[Idx_SEA_TEMP]->
483 getInterpolatedValue(m_cursor_lon, m_cursor_lat, true );
484
485 if( temp != GRIB_NOTDEF ) {
486 temp = m_pGDialog->m_OverlaySettings.CalibrateValue(GribOverlaySettings::SEA_TEMPERATURE, temp);
487 skn.Printf( _T("%5.1f ") + m_pGDialog->m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::SEA_TEMPERATURE), temp );
488 m_pDataCellsColour = m_pGDialog->pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(GribOverlaySettings::SEA_TEMPERATURE, temp);
489 }
490 }
491 return skn;
492 }
493
GetCAPE(GribRecord ** recordarray)494 wxString GRIBTable::GetCAPE(GribRecord **recordarray)
495 {
496 wxString skn(wxEmptyString);
497 if( recordarray[Idx_CAPE] ) {
498 double cape = recordarray[Idx_CAPE]->
499 getInterpolatedValue(m_cursor_lon, m_cursor_lat, true );
500
501 if( cape != GRIB_NOTDEF ) {
502 cape = m_pGDialog->m_OverlaySettings.CalibrateValue(GribOverlaySettings::CAPE, cape);
503 skn.Printf( wxString::Format( _T("%5.0f ") + m_pGDialog->m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::CAPE), cape ) );
504 m_pDataCellsColour = m_pGDialog->pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(GribOverlaySettings::CAPE, cape);
505 }
506 }
507 return skn;
508 }
509
GetCompRefl(GribRecord ** recordarray)510 wxString GRIBTable::GetCompRefl(GribRecord **recordarray)
511 {
512 wxString skn(wxEmptyString);
513 if( recordarray[Idx_COMP_REFL] ) {
514 double refl = recordarray[Idx_COMP_REFL]->
515 getInterpolatedValue(m_cursor_lon, m_cursor_lat, true );
516
517 if( refl != GRIB_NOTDEF ) {
518 refl = m_pGDialog->m_OverlaySettings.CalibrateValue(GribOverlaySettings::COMP_REFL, refl);
519 skn.Printf( wxString::Format( _T("%5.0f ") + m_pGDialog->m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::COMP_REFL), refl ) );
520 m_pDataCellsColour = m_pGDialog->pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(GribOverlaySettings::COMP_REFL, refl);
521 }
522 }
523 return skn;
524 }
525
526
GetCurrent(GribRecord ** recordarray,int datatype,double & wdir)527 wxString GRIBTable::GetCurrent(GribRecord **recordarray, int datatype, double& wdir)
528 {
529 wxString skn(wxEmptyString);
530 double vkn, ang;
531 wdir = GRIB_NOTDEF;
532 if(GribRecord::getInterpolatedValues(vkn, ang,
533 recordarray[Idx_SEACURRENT_VX],
534 recordarray[Idx_SEACURRENT_VY],
535 m_cursor_lon, m_cursor_lat)) {
536
537 if( datatype == 1 ){
538 wdir = ang;
539 return skn;
540 }
541 vkn = m_pGDialog->m_OverlaySettings.CalibrateValue(GribOverlaySettings::CURRENT, vkn);
542 skn.Printf( wxString::Format( _T("%4.1f ") + m_pGDialog->m_OverlaySettings.GetUnitSymbol(GribOverlaySettings::CURRENT), vkn ) );
543 m_pDataCellsColour = m_pGDialog->pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(GribOverlaySettings::CURRENT, vkn);
544 }
545 return skn;
546 }
547
GetTimeRowsStrings(wxDateTime date_time,int time_zone,int type)548 wxString GRIBTable::GetTimeRowsStrings( wxDateTime date_time, int time_zone, int type )
549 {
550 wxDateTime t( date_time );
551 switch( time_zone ) {
552 case 0:
553 if( (wxDateTime::Now() == (wxDateTime::Now().ToGMT())) && t.IsDST() ) //bug in wxWingets 3.0 for UTC meridien ?
554 t.Add( wxTimeSpan( 1, 0, 0, 0 ) );
555 switch( type ){
556 case 0:
557 return t.Format( _T(" %H:%M "), wxDateTime::Local ) + _T("LOC");
558 case 1:
559 if(GetLocaleCanonicalName() == _T("en_US"))
560 return t.Format( _T(" %a-%m/%d/%y "), wxDateTime::Local);
561 else
562 return t.Format( _T(" %a-%d/%m/%y "), wxDateTime::Local);
563 }
564 case 1:
565 switch( type ){
566 case 0:
567 return t.Format( _T(" %H:%M "), wxDateTime::UTC ) + _T("UTC");
568 case 1:
569 if(GetLocaleCanonicalName() == _T("en_US"))
570 return t.Format( _T(" %a-%m/%d/%y "), wxDateTime::UTC );
571 else
572 return t.Format( _T(" %a-%d/%m/%y "), wxDateTime::UTC );
573 }
574 default:
575 return wxEmptyString;
576 }
577 }
578