OpenCPN Partial API docs
Loading...
Searching...
No Matches
grib_table.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2010 by David S. Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 ***************************************************************************/
17
24#include "wx/wxprec.h"
25
26#ifndef WX_PRECOMP
27#include "wx/wx.h"
28#endif // precompiled headers
29
30#include "pi_gl.h"
31
32#include <wx/glcanvas.h>
33#include <wx/graphics.h>
34#include <wx/progdlg.h>
35#include <wx/grid.h>
36#include "grib_table.h"
37#include "custom_grid.h"
38#include <wx/tokenzr.h>
39
40extern double m_cursor_lat, m_cursor_lon;
41
42GRIBTable::GRIBTable(GRIBUICtrlBar &parent)
43 : GRIBTableBase(&parent), m_pGDialog(&parent) {}
44
45void GRIBTable::InitGribTable(ArrayOfGribRecordSets *rsa, int NowIndex) {
46 m_pGribTable->m_gParent = this;
47 m_pIndex = NowIndex;
48
49 // init row attr
50 wxGridCellAttr *datarow = new wxGridCellAttr();
51 datarow->SetFont(GetOCPNGUIScaledFont_PlugIn(_("Dialog")));
52 datarow->SetAlignment(wxALIGN_CENTRE, wxALIGN_CENTRE);
53
54 // populate "cursor position" display
55 wxString l;
56 l.Append(toSDMM_PlugIn(1, m_cursor_lat))
57 .Append(" ")
58 .Append(toSDMM_PlugIn(2, m_cursor_lon));
59 m_pCursorPosition->SetLabel(l);
60 m_pCursorPosition->SetFont(
61 GetOCPNGUIScaledFont_PlugIn(_("Dialog")).MakeBold());
62 m_pPositionText->SetFont(GetOCPNGUIScaledFont_PlugIn(_("Dialog")).MakeBold());
63
64 // create as columns as necessary
65 m_pGribTable->AppendCols(rsa->GetCount());
66
67 // populate grid
68 wxDateTime time;
69 int nrows, wcols = 0;
70 for (unsigned i = 0; i < rsa->GetCount(); i++) {
71 // populate time labels
72 time = rsa->Item(i).m_Reference_Time;
74 "$weekday_short_date\n$hour_minutes");
75 m_pGribTable->SetColLabelValue(
76 i, toUsrDateTimeFormat_Plugin(wxDateTime(time), opts));
77 nrows = -1;
78 GribTimelineRecordSet *pTimeset = m_pGDialog->GetTimeLineRecordSet(time);
79 if (!pTimeset) continue;
80
81 GribRecord **RecordArray = pTimeset->m_GribRecordPtrArray;
82
83 /*create and populate wind data row
84 wind is a special case:
85 1) if current unit is not bf ==> double speed display (current unit +
86 bf) 2) create two lines for direction and speed and a third for gust if
87 exists 3) these two or three lines will be part of the same block*/
88 if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WIND_VX) !=
89 wxNOT_FOUND &&
90 m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WIND_VY) !=
91 wxNOT_FOUND) {
92 nrows++;
93 AddDataRow(nrows, i, _("Wind,Dir"), datarow);
94 double wdir;
95 GetWind(RecordArray, 1, wdir); // this is a numerical row
96 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
97 m_pGribTable->SetNumericalRow(nrows, i, R_WIND, wdir);
98 nrows++;
99 AddDataRow(nrows, i, _("Wind,Speed"), datarow);
100 if (m_pGDialog->m_OverlaySettings.Settings[GribOverlaySettings::WIND]
101 .m_Units != GribOverlaySettings::BFS)
102 m_pGribTable->SetCellValue(nrows, i, GetWind(RecordArray, 2, wdir));
103 else
104 m_pGribTable->SetCellValue(nrows, i, GetWind(RecordArray, 3, wdir));
105 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
106 if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WIND_GUST) !=
107 wxNOT_FOUND) {
108 nrows++;
109 AddDataRow(nrows, i, _("Wind,Gust"), datarow);
110 if (m_pGDialog->m_OverlaySettings.Settings[GribOverlaySettings::WIND]
111 .m_Units != GribOverlaySettings::BFS)
112 m_pGribTable->SetCellValue(nrows, i, GetWindGust(RecordArray, 1));
113 else
114 m_pGribTable->SetCellValue(nrows, i, GetWindGust(RecordArray, 2));
115 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
116 }
117 } // wind
118
119 // create and populate Pressure data rown
120 if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_PRESSURE) !=
121 wxNOT_FOUND) {
122 nrows++;
123 AddDataRow(nrows, i, _("Pressure"), datarow);
124 m_pGribTable->SetCellValue(nrows, i, GetPressure(RecordArray));
125 } // pressure
126
127 /*create and populate Waves data rows
128 waves is another special case:
129 1) if significant height data exists then create a line for direction
130 and height 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) !=
133 wxNOT_FOUND) {
134 double wdir;
135 if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WVDIR) !=
136 wxNOT_FOUND) {
137 nrows++;
138 AddDataRow(nrows, i, _("Waves,Dir"), datarow);
139 GetWaves(RecordArray, Idx_WVDIR, wdir); // this is a numerical row
140 m_pGribTable->SetNumericalRow(nrows, i, R_WAVES, wdir);
141 }
142 nrows++;
143 AddDataRow(nrows, i, _("Waves,Hsig"), datarow);
144 m_pGribTable->SetCellValue(nrows, i,
145 GetWaves(RecordArray, Idx_HTSIGW, wdir));
146 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
147 if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WVPER) !=
148 wxNOT_FOUND) {
149 nrows++;
150 AddDataRow(nrows, i, _("Waves,Per"), datarow);
151 m_pGribTable->SetCellValue(nrows, i,
152 GetWaves(RecordArray, Idx_WVPER, wdir));
153 }
154 } // waves
155
156 // create and populate total rainfall data row
157 if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_PRECIP_TOT) !=
158 wxNOT_FOUND) {
159 nrows++;
160 AddDataRow(nrows, i, _("Rainfall"), datarow);
161 m_pGribTable->SetCellValue(nrows, i, GetRainfall(RecordArray));
162 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
163 } // rainfall
164
165 // create and populate total cloud control
166 if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_CLOUD_TOT) !=
167 wxNOT_FOUND) {
168 nrows++;
169 AddDataRow(nrows, i, _("Cloud Cover"), datarow);
170 m_pGribTable->SetCellValue(nrows, i, GetCloudCover(RecordArray));
171 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
172 } // cloud
173
174 // create and populate the Air Temperature data row
175 if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_AIR_TEMP) !=
176 wxNOT_FOUND) {
177 nrows++;
178 AddDataRow(nrows, i, _("Air Temp."), datarow);
179 m_pGribTable->SetCellValue(nrows, i, GetAirTemp(RecordArray));
180 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
181 } // air temp
182
183 // create and populate the Sea Surface Temperature data row
184 if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_SEA_TEMP) !=
185 wxNOT_FOUND) {
186 nrows++;
187 AddDataRow(nrows, i, _("Sea Temp."), datarow);
188 m_pGribTable->SetCellValue(nrows, i, GetSeaTemp(RecordArray));
189 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
190 } // sea temp
191
192 // create and populate the Convective Available Potential Energy (CAPE) data
193 // row
194 if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_CAPE) !=
195 wxNOT_FOUND) {
196 nrows++;
197 AddDataRow(nrows, i, _("CAPE"), datarow);
198 m_pGribTable->SetCellValue(nrows, i, GetCAPE(RecordArray));
199 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
200 } // cape
201
202 // create and populate the Composite Reflectivity data row
203 if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_COMP_REFL) !=
204 wxNOT_FOUND) {
205 nrows++;
206 AddDataRow(nrows, i, _("C. Reflect."), datarow);
207 m_pGribTable->SetCellValue(nrows, i, GetCompRefl(RecordArray));
208 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
209 } // composite Reflectivity
210
211 /*create and populate the current data rows
212 1)create two lines for direction and speed
213 2) these two or three lines will be part of the same block*/
214 if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(
215 Idx_SEACURRENT_VX) != wxNOT_FOUND &&
216 m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(
217 Idx_SEACURRENT_VY) != wxNOT_FOUND) {
218 double wdir;
219 nrows++;
220 AddDataRow(nrows, i, _("Current,Dir"), datarow);
221 GetCurrent(RecordArray, 1, wdir); // this is a numerical row
222 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
223 m_pGribTable->SetNumericalRow(nrows, i, R_CURRENT, wdir);
224
225 nrows++;
226 AddDataRow(nrows, i, _("Current,Speed"), datarow);
227 m_pGribTable->SetCellValue(nrows, i, GetCurrent(RecordArray, 2, wdir));
228 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
229 } // current // populate grid
230 delete pTimeset;
231 m_pGribTable->AutoSizeColumn(i, false);
232 wcols = wxMax(m_pGribTable->GetColSize(i), wcols);
233 } // populate grid
234 // put cursor outside the grid
235 m_pGribTable->SetGridCursor(m_pGribTable->GetNumberRows() - 1, 0);
236 // set col size
237 m_pGribTable->SetDefaultColSize(wcols, true);
238 // set row size
239 AutoSizeDataRows();
240 // set label size
241 m_pGribTable->SetColLabelSize(wxGRID_AUTOSIZE);
242 // set scroll steps
243 m_pGribTable->SetScrollLineX(wcols);
244
245 datarow->DecRef(); // Give up pointer contrl to Grid
246
247 m_tScrollToNowTimer.Connect(
248 wxEVT_TIMER, wxTimerEventHandler(GRIBTable::OnScrollToNowTimer), nullptr,
249 this);
250}
251
252void GRIBTable::SetTableSizePosition(int vpWidth, int vpHeight) {
253 // Get size & position previously saved
254 int x = -1, y = -1, w = -1, h = -1;
255 wxFileConfig *pConf = GetOCPNConfigObject();
256 if (pConf) {
257 pConf->SetPath("/Settings/GRIB");
258 pConf->Read("GribDataTablePosition_x", &x);
259 pConf->Read("GribDataTablePosition_y", &y);
260 pConf->Read("GribDataTableWidth", &w);
261 pConf->Read("GribDataTableHeight", &h);
262 }
263 wxPoint final_pos = GetOCPNCanvasWindow()->ClientToScreen(wxPoint(x, y));
264 // set a default size & position if saved values are outside of limits
265 bool refit = false;
266 wxSize scw = wxSize(vpWidth, (vpHeight - GetChartbarHeight()));
267 wxPoint pcw = GetOCPNCanvasWindow()->ClientToScreen(
268 GetOCPNCanvasWindow()->GetPosition());
269 if (!(wxRect(pcw, scw).Contains(wxRect(final_pos, wxSize(w, h)))))
270 refit = true;
271 if (w < (m_pGribTable->GetRowLabelSize() + (m_pGribTable->GetColSize(0))) ||
272 h < (m_pGribTable->GetColLabelSize() + (m_pGribTable->GetRowSize(0))))
273 refit = true;
274
275#ifdef __ANDROID__
276 refit = true;
277#endif
278 if (refit) {
279 w = (scw.GetWidth() / 10) * 9; // 10% less than canvas
280 h = (scw.GetHeight() / 10) * 9;
281 x = (scw.GetWidth() / 20); // centered horizontally
282 y = (scw.GetHeight() / 50); // a bit out-centered toward the top
283#ifdef __ANDROID__
284 // Position directly below GRIB control dialog
285 y = m_pGDialog->GetSize().GetHeight() * 11 / 10;
286 h = scw.GetHeight() - m_pGDialog->GetSize().GetHeight();
287#endif
288 final_pos = GetOCPNCanvasWindow()->ClientToScreen(wxPoint(x, y));
289 } //
290 // in case client size too large for the grib
291 int w1 = m_pGribTable->GetRowLabelSize() +
292 (m_pGribTable->GetColSize(0) * m_pGribTable->GetNumberCols());
293 w = wxMin(w, w1);
294 int h1 = m_pGribTable->GetColLabelSize() +
295 (m_pGribTable->GetRowSize(0) * (m_pGribTable->GetNumberRows() + 4));
296 h = wxMin(h, h1);
297
298 this->SetClientSize(w, h);
299 this->Move(final_pos);
300
301 // scroll to the end of time steps to prepare the next scroll to 'now'
302 m_pGribTable->MakeCellVisible(0, m_pGribTable->GetNumberCols() - 1);
303 // trigger scroll to 'now'(must be postpone after the dialog is shown)
304 m_tScrollToNowTimer.Start(200, wxTIMER_ONE_SHOT);
305}
306
307void GRIBTable::OnScrollToNowTimer(wxTimerEvent &event) {
308 m_pGribTable->MakeCellVisible(0, m_pIndex);
309}
310
311void GRIBTable::OnClose(wxCloseEvent &event) {
312 CloseDialog();
313 this->EndModal(wxID_OK);
314}
315
316void GRIBTable::OnOKButton(wxCommandEvent &event) {
317 CloseDialog();
318 this->EndModal(wxID_OK);
319}
320
321void GRIBTable::CloseDialog() {
322 wxSize s = this->GetClientSize();
323 wxPoint p = GetOCPNCanvasWindow()->ScreenToClient(this->GetPosition());
324
325 wxFileConfig *pConf = GetOCPNConfigObject();
326 if (pConf) {
327 pConf->SetPath("/Settings/GRIB");
328
329 pConf->Write("GribDataTablePosition_x", p.x);
330 pConf->Write("GribDataTablePosition_y", p.y);
331 pConf->Write("GribDataTableWidth", s.GetWidth());
332 pConf->Write("GribDataTableHeight", s.GetHeight());
333 } //
334}
335
336void GRIBTable::AddDataRow(int num_rows, int num_cols, wxString label,
337 wxGridCellAttr *row_attr) {
338 if (m_pGribTable->GetNumberRows() == num_rows) {
339 m_pGribTable->AppendRows(1);
340 m_pGribTable->SetRowLabelValue(num_rows, label);
341 row_attr->IncRef();
342 m_pGribTable->SetRowAttr(num_rows, row_attr);
343 }
344 m_pDataCellsColour = m_pGribTable->GetCellBackgroundColour(
345 num_rows, num_cols); // set default colour
346}
347
348void GRIBTable::AutoSizeDataRows() {
349 int hrows = 0;
350 for (int i = 0; i < m_pGribTable->GetNumberRows(); i++) {
351 m_pGribTable->AutoSizeRow(i, false);
352 hrows = wxMax(m_pGribTable->GetRowHeight(i) + 3, hrows);
353 }
354 m_pGribTable->SetDefaultRowSize(hrows, true);
355 // set scroll steps
356 m_pGribTable->SetScrollLineY(hrows);
357}
358
359wxString GRIBTable::GetWind(GribRecord **recordarray, int datatype,
360 double &wdir) {
361 wxString skn(wxEmptyString);
362 int altitude = 0;
363 double vkn, ang;
364 wdir = GRIB_NOTDEF;
366 vkn, ang, recordarray[Idx_WIND_VX + altitude],
367 recordarray[Idx_WIND_VY + altitude], m_cursor_lon, m_cursor_lat)) {
368 if (datatype == 1) {
369 wdir = ang;
370 return skn;
371 }
372 double cvkn = m_pGDialog->m_OverlaySettings.CalibrateValue(
373 GribOverlaySettings::WIND, vkn);
374 m_pDataCellsColour =
375 m_pGDialog->pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(
376 GribOverlaySettings::WIND, cvkn);
377 skn.Printf(wxString::Format(
378 "%2d bf",
379 (int)wxRound(m_pGDialog->m_OverlaySettings.GetmstobfFactor(vkn) *
380 vkn)));
381 if (datatype == 2) { // wind speed unit other than bf
382 skn.Prepend(
383 wxString::Format("%2d " + m_pGDialog->m_OverlaySettings.GetUnitSymbol(
384 GribOverlaySettings::WIND),
385 (int)wxRound(cvkn)) +
386 " - ");
387 }
388 }
389 return skn;
390}
391
392wxString GRIBTable::GetWindGust(GribRecord **recordarray, int datatype) {
393 wxString skn(wxEmptyString);
394 if (recordarray[Idx_WIND_GUST]) {
395 double vkn = recordarray[Idx_WIND_GUST]->GetInterpolatedValue(
396 m_cursor_lon, m_cursor_lat, true);
397 if (vkn != GRIB_NOTDEF) {
398 double cvkn = m_pGDialog->m_OverlaySettings.CalibrateValue(
399 GribOverlaySettings::WIND_GUST, vkn);
400 m_pDataCellsColour =
401 m_pGDialog->pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(
402 GribOverlaySettings::WIND_GUST, cvkn);
403
404 skn.Printf(wxString::Format(
405 "%2d bf",
406 (int)wxRound(m_pGDialog->m_OverlaySettings.GetmstobfFactor(vkn) *
407 vkn))); // wind gust unit bf
408 if (datatype == 1) { // wind gust unit other than bf
409 skn.Prepend(wxString::Format(
410 "%2d " + m_pGDialog->m_OverlaySettings.GetUnitSymbol(
411 GribOverlaySettings::WIND_GUST),
412 (int)wxRound(cvkn)) +
413 " - ");
414 }
415 }
416 }
417 return skn;
418}
419
420wxString GRIBTable::GetPressure(GribRecord **recordarray) {
421 wxString skn(wxEmptyString);
422 if (recordarray[Idx_PRESSURE]) {
423 double press = recordarray[Idx_PRESSURE]->GetInterpolatedValue(
424 m_cursor_lon, m_cursor_lat, true);
425
426 if (press != GRIB_NOTDEF) {
427 press = m_pGDialog->m_OverlaySettings.CalibrateValue(
428 GribOverlaySettings::PRESSURE, press);
429 int p =
430 (m_pGDialog->m_OverlaySettings.Settings[GribOverlaySettings::PRESSURE]
431 .m_Units == 2)
432 ? 2
433 : 0; // if PRESSURE & inHG = two decimals
434 skn.Printf(wxString::Format(
435 "%2.*f " + m_pGDialog->m_OverlaySettings.GetUnitSymbol(
436 GribOverlaySettings::PRESSURE),
437 p, (press)));
438 }
439 }
440 return skn;
441}
442
443wxString GRIBTable::GetWaves(GribRecord **recordarray, int datatype,
444 double &wdir) {
445 wxString skn(wxEmptyString);
446 wdir = GRIB_NOTDEF;
447 switch (datatype) {
448 case Idx_HTSIGW:
449 if (recordarray[Idx_HTSIGW]) {
450 double height = recordarray[Idx_HTSIGW]->GetInterpolatedValue(
451 m_cursor_lon, m_cursor_lat, true);
452 if (height != GRIB_NOTDEF) {
453 double cheight = m_pGDialog->m_OverlaySettings.CalibrateValue(
454 GribOverlaySettings::WAVE, height);
455 skn.Printf(wxString::Format(
456 "%4.1f " + m_pGDialog->m_OverlaySettings.GetUnitSymbol(
457 GribOverlaySettings::WAVE),
458 cheight));
459 m_pDataCellsColour =
460 m_pGDialog->pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(
461 GribOverlaySettings::WAVE, cheight);
462 }
463 }
464 break;
465 case Idx_WVDIR:
466 if (recordarray[Idx_WVDIR]) {
467 double direction = recordarray[Idx_WVDIR]->GetInterpolatedValue(
468 m_cursor_lon, m_cursor_lat, true, true);
469 wdir = direction;
470 return skn;
471 }
472 break;
473 case Idx_WVPER:
474 if (recordarray[Idx_WVPER]) {
475 double period = recordarray[Idx_WVPER]->GetInterpolatedValue(
476 m_cursor_lon, m_cursor_lat, true);
477 if (period != GRIB_NOTDEF)
478 skn.Printf(wxString::Format("%01ds", (int)(period + 0.5)));
479 }
480 }
481 return skn;
482}
483
484wxString GRIBTable::GetRainfall(GribRecord **recordarray) {
485 wxString skn(wxEmptyString);
486 if (recordarray[Idx_PRECIP_TOT]) {
487 double precip = recordarray[Idx_PRECIP_TOT]->GetInterpolatedValue(
488 m_cursor_lon, m_cursor_lat, true);
489
490 if (precip != GRIB_NOTDEF) {
491 precip = m_pGDialog->m_OverlaySettings.CalibrateValue(
492 GribOverlaySettings::PRECIPITATION, precip);
493 skn.Printf("%6.2f " + m_pGDialog->m_OverlaySettings.GetUnitSymbol(
494 GribOverlaySettings::PRECIPITATION),
495 precip);
496 m_pDataCellsColour =
497 m_pGDialog->pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(
498 GribOverlaySettings::PRECIPITATION, precip);
499 }
500 }
501 return skn;
502}
503
504wxString GRIBTable::GetCloudCover(GribRecord **recordarray) {
505 wxString skn(wxEmptyString);
506 if (recordarray[Idx_CLOUD_TOT]) {
507 double cloud = recordarray[Idx_CLOUD_TOT]->GetInterpolatedValue(
508 m_cursor_lon, m_cursor_lat, true);
509
510 if (cloud != GRIB_NOTDEF) {
511 cloud = m_pGDialog->m_OverlaySettings.CalibrateValue(
512 GribOverlaySettings::CLOUD, cloud);
513 skn.Printf("%5.1f ", cloud);
514 skn.Append(m_pGDialog->m_OverlaySettings.GetUnitSymbol(
515 GribOverlaySettings::CLOUD));
516 m_pDataCellsColour =
517 m_pGDialog->pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(
518 GribOverlaySettings::CLOUD, cloud);
519 }
520 }
521 return skn;
522}
523
524wxString GRIBTable::GetAirTemp(GribRecord **recordarray) {
525 wxString skn(wxEmptyString);
526 if (recordarray[Idx_AIR_TEMP]) {
527 double temp = recordarray[Idx_AIR_TEMP]->GetInterpolatedValue(
528 m_cursor_lon, m_cursor_lat, true);
529
530 if (temp != GRIB_NOTDEF) {
531 temp = m_pGDialog->m_OverlaySettings.CalibrateValue(
532 GribOverlaySettings::AIR_TEMPERATURE, temp);
533 skn.Printf("%5.1f " + m_pGDialog->m_OverlaySettings.GetUnitSymbol(
534 GribOverlaySettings::AIR_TEMPERATURE),
535 temp);
536 m_pDataCellsColour =
537 m_pGDialog->pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(
538 GribOverlaySettings::AIR_TEMPERATURE, temp);
539 }
540 }
541 return skn;
542}
543
544wxString GRIBTable::GetSeaTemp(GribRecord **recordarray) {
545 wxString skn(wxEmptyString);
546 if (recordarray[Idx_SEA_TEMP]) {
547 double temp = recordarray[Idx_SEA_TEMP]->GetInterpolatedValue(
548 m_cursor_lon, m_cursor_lat, true);
549
550 if (temp != GRIB_NOTDEF) {
551 temp = m_pGDialog->m_OverlaySettings.CalibrateValue(
552 GribOverlaySettings::SEA_TEMPERATURE, temp);
553 skn.Printf("%5.1f " + m_pGDialog->m_OverlaySettings.GetUnitSymbol(
554 GribOverlaySettings::SEA_TEMPERATURE),
555 temp);
556 m_pDataCellsColour =
557 m_pGDialog->pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(
558 GribOverlaySettings::SEA_TEMPERATURE, temp);
559 }
560 }
561 return skn;
562}
563
564wxString GRIBTable::GetCAPE(GribRecord **recordarray) {
565 wxString skn(wxEmptyString);
566 if (recordarray[Idx_CAPE]) {
567 double cape = recordarray[Idx_CAPE]->GetInterpolatedValue(
568 m_cursor_lon, m_cursor_lat, true);
569
570 if (cape != GRIB_NOTDEF) {
571 cape = m_pGDialog->m_OverlaySettings.CalibrateValue(
572 GribOverlaySettings::CAPE, cape);
573 skn.Printf(wxString::Format(
574 "%5.0f " + m_pGDialog->m_OverlaySettings.GetUnitSymbol(
575 GribOverlaySettings::CAPE),
576 cape));
577 m_pDataCellsColour =
578 m_pGDialog->pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(
579 GribOverlaySettings::CAPE, cape);
580 }
581 }
582 return skn;
583}
584
585wxString GRIBTable::GetCompRefl(GribRecord **recordarray) {
586 wxString skn(wxEmptyString);
587 if (recordarray[Idx_COMP_REFL]) {
588 double refl = recordarray[Idx_COMP_REFL]->GetInterpolatedValue(
589 m_cursor_lon, m_cursor_lat, true);
590
591 if (refl != GRIB_NOTDEF) {
592 refl = m_pGDialog->m_OverlaySettings.CalibrateValue(
593 GribOverlaySettings::COMP_REFL, refl);
594 skn.Printf(wxString::Format(
595 "%5.0f " + m_pGDialog->m_OverlaySettings.GetUnitSymbol(
596 GribOverlaySettings::COMP_REFL),
597 refl));
598 m_pDataCellsColour =
599 m_pGDialog->pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(
600 GribOverlaySettings::COMP_REFL, refl);
601 }
602 }
603 return skn;
604}
605
606wxString GRIBTable::GetCurrent(GribRecord **recordarray, int datatype,
607 double &wdir) {
608 wxString skn(wxEmptyString);
609 double vkn, ang;
610 wdir = GRIB_NOTDEF;
612 vkn, ang, recordarray[Idx_SEACURRENT_VX],
613 recordarray[Idx_SEACURRENT_VY], m_cursor_lon, m_cursor_lat)) {
614 if (datatype == 1) {
615 wdir = ang;
616 return skn;
617 }
618 vkn = m_pGDialog->m_OverlaySettings.CalibrateValue(
619 GribOverlaySettings::CURRENT, vkn);
620 skn.Printf(
621 wxString::Format("%4.1f " + m_pGDialog->m_OverlaySettings.GetUnitSymbol(
622 GribOverlaySettings::CURRENT),
623 vkn));
624 m_pDataCellsColour =
625 m_pGDialog->pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(
626 GribOverlaySettings::CURRENT, vkn);
627 }
628 return skn;
629}
Class GRIBTableBase.
void SetTableSizePosition(int vpWidth, int vpHeight)
Set the table size and position relative to viewport.
void InitGribTable(ArrayOfGribRecordSets *rsa)
Initialize the GRIB data table.
GribOverlaySettings m_OverlaySettings
Settings that control how GRIB data is displayed and overlaid.
GribPi * pPlugIn
Plugin instance that owns this control bar.
GRIBFile * m_bGRIBActiveFile
Currently active GRIB file being displayed.
GribTimelineRecordSet * GetTimeLineRecordSet(wxDateTime time)
Retrieves or creates a temporally interpolated GRIB record set for a specific timestamp.
GribRecord * m_GribRecordPtrArray[Idx_COUNT]
Array of pointers to GRIB records representing different meteorological parameters.
A meteorological data grid from a GRIB (Gridded Binary) file.
static bool GetInterpolatedValues(double &M, double &A, const GribRecord *GRX, const GribRecord *GRY, double px, double py, bool numericalInterpolation=true)
Gets spatially interpolated wind or current vector values at a specific latitude/longitude point.
double GetInterpolatedValue(double px, double py, bool numericalInterpolation=true, bool dir=false) const
Get spatially interpolated value at exact lat/lon position.
A specialized GribRecordSet that represents temporally interpolated weather data with isobar renderin...
Specialized Grid Control for GRIB Data Display.
@ Idx_COMP_REFL
Composite radar reflectivity in dBZ (decibel relative to Z)
@ Idx_PRECIP_TOT
Precipitation data in millimeters per hour.
@ Idx_AIR_TEMP
Air temperature at 2m in Kelvin (K)
@ Idx_PRESSURE
Surface pressure in Pascal (Pa)
@ Idx_WVDIR
Wave direction.
@ Idx_CLOUD_TOT
Total cloud cover in % (percent, range 0-100%)
@ Idx_WIND_GUST
Wind gust speed at surface in m/s.
@ Idx_WIND_VX
Surface wind velocity X component in m/s.
@ Idx_WVPER
Wave period.
@ Idx_HTSIGW
Significant wave height in meters.
@ Idx_SEACURRENT_VY
Sea current velocity Y component in m/s.
@ Idx_SEA_TEMP
Sea surface temperature in Kelvin (K)
@ Idx_WIND_VY
Surface wind velocity Y component in m/s.
@ Idx_SEACURRENT_VX
Sea current velocity X component in m/s.
@ Idx_CAPE
Convective Available Potential Energy in J/kg (Joules per kilogram)
GRIB Data Table View and Export Interface.
wxWindow * GetOCPNCanvasWindow()
Gets OpenCPN's main canvas window.
wxFileConfig * GetOCPNConfigObject()
Gets OpenCPN's configuration object.
wxFont GetOCPNGUIScaledFont_PlugIn(wxString item)
Gets a uniquely scaled font copy for responsive UI elements.
int GetChartbarHeight()
Gets height of chart bar in pixels.
OpenGL Platform Abstraction Layer.
wxString toSDMM_PlugIn(int NEflag, double a, bool hi_precision)
Convert decimal degrees to a formatted string.
wxString toUsrDateTimeFormat_Plugin(const wxDateTime date_time, const DateTimeFormatOptions &options)
Format a date/time to a localized string representation, conforming to the global date/time format an...
Configuration options for date and time formatting.
DateTimeFormatOptions & SetFormatString(const wxString &fmt)
Sets the date/time format pattern string.