32#include <wx/glcanvas.h>
33#include <wx/graphics.h>
34#include <wx/progdlg.h>
38#include <wx/tokenzr.h>
40extern double m_cursor_lat, m_cursor_lon;
46 m_pGribTable->m_gParent =
this;
50 wxGridCellAttr *datarow =
new wxGridCellAttr();
52 datarow->SetAlignment(wxALIGN_CENTRE, wxALIGN_CENTRE);
59 m_pCursorPosition->SetLabel(l);
60 m_pCursorPosition->SetFont(
65 m_pGribTable->AppendCols(rsa->GetCount());
70 for (
unsigned i = 0; i < rsa->GetCount(); i++) {
72 time = rsa->Item(i).m_Reference_Time;
74 "$weekday_short_date\n$hour_minutes");
75 m_pGribTable->SetColLabelValue(
79 if (!pTimeset)
continue;
93 AddDataRow(nrows, i, _(
"Wind,Dir"), datarow);
95 GetWind(RecordArray, 1, wdir);
96 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
97 m_pGribTable->SetNumericalRow(nrows, i, R_WIND, wdir);
99 AddDataRow(nrows, i, _(
"Wind,Speed"), datarow);
101 .m_Units != GribOverlaySettings::BFS)
102 m_pGribTable->SetCellValue(nrows, i, GetWind(RecordArray, 2, wdir));
104 m_pGribTable->SetCellValue(nrows, i, GetWind(RecordArray, 3, wdir));
105 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
109 AddDataRow(nrows, i, _(
"Wind,Gust"), datarow);
111 .m_Units != GribOverlaySettings::BFS)
112 m_pGribTable->SetCellValue(nrows, i, GetWindGust(RecordArray, 1));
114 m_pGribTable->SetCellValue(nrows, i, GetWindGust(RecordArray, 2));
115 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
123 AddDataRow(nrows, i, _(
"Pressure"), datarow);
124 m_pGribTable->SetCellValue(nrows, i, GetPressure(RecordArray));
138 AddDataRow(nrows, i, _(
"Waves,Dir"), datarow);
140 m_pGribTable->SetNumericalRow(nrows, i, R_WAVES, wdir);
143 AddDataRow(nrows, i, _(
"Waves,Hsig"), datarow);
144 m_pGribTable->SetCellValue(nrows, i,
146 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
150 AddDataRow(nrows, i, _(
"Waves,Per"), datarow);
151 m_pGribTable->SetCellValue(nrows, i,
160 AddDataRow(nrows, i, _(
"Rainfall"), datarow);
161 m_pGribTable->SetCellValue(nrows, i, GetRainfall(RecordArray));
162 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
169 AddDataRow(nrows, i, _(
"Cloud Cover"), datarow);
170 m_pGribTable->SetCellValue(nrows, i, GetCloudCover(RecordArray));
171 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
178 AddDataRow(nrows, i, _(
"Air Temp."), datarow);
179 m_pGribTable->SetCellValue(nrows, i, GetAirTemp(RecordArray));
180 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
187 AddDataRow(nrows, i, _(
"Sea Temp."), datarow);
188 m_pGribTable->SetCellValue(nrows, i, GetSeaTemp(RecordArray));
189 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
197 AddDataRow(nrows, i, _(
"CAPE"), datarow);
198 m_pGribTable->SetCellValue(nrows, i, GetCAPE(RecordArray));
199 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
206 AddDataRow(nrows, i, _(
"C. Reflect."), datarow);
207 m_pGribTable->SetCellValue(nrows, i, GetCompRefl(RecordArray));
208 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
220 AddDataRow(nrows, i, _(
"Current,Dir"), datarow);
221 GetCurrent(RecordArray, 1, wdir);
222 m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
223 m_pGribTable->SetNumericalRow(nrows, i, R_CURRENT, wdir);
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);
231 m_pGribTable->AutoSizeColumn(i,
false);
232 wcols = wxMax(m_pGribTable->GetColSize(i), wcols);
235 m_pGribTable->SetGridCursor(m_pGribTable->GetNumberRows() - 1, 0);
237 m_pGribTable->SetDefaultColSize(wcols,
true);
241 m_pGribTable->SetColLabelSize(wxGRID_AUTOSIZE);
243 m_pGribTable->SetScrollLineX(wcols);
247 m_tScrollToNowTimer.Connect(
248 wxEVT_TIMER, wxTimerEventHandler(GRIBTable::OnScrollToNowTimer),
nullptr,
254 int x = -1, y = -1, w = -1, h = -1;
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);
269 if (!(wxRect(pcw, scw).Contains(wxRect(final_pos, wxSize(w, h)))))
271 if (w < (m_pGribTable->GetRowLabelSize() + (m_pGribTable->GetColSize(0))) ||
272 h < (m_pGribTable->GetColLabelSize() + (m_pGribTable->GetRowSize(0))))
279 w = (scw.GetWidth() / 10) * 9;
280 h = (scw.GetHeight() / 10) * 9;
281 x = (scw.GetWidth() / 20);
282 y = (scw.GetHeight() / 50);
285 y = m_pGDialog->GetSize().GetHeight() * 11 / 10;
286 h = scw.GetHeight() - m_pGDialog->GetSize().GetHeight();
291 int w1 = m_pGribTable->GetRowLabelSize() +
292 (m_pGribTable->GetColSize(0) * m_pGribTable->GetNumberCols());
294 int h1 = m_pGribTable->GetColLabelSize() +
295 (m_pGribTable->GetRowSize(0) * (m_pGribTable->GetNumberRows() + 4));
298 this->SetClientSize(w, h);
299 this->Move(final_pos);
302 m_pGribTable->MakeCellVisible(0, m_pGribTable->GetNumberCols() - 1);
304 m_tScrollToNowTimer.Start(200, wxTIMER_ONE_SHOT);
307void GRIBTable::OnScrollToNowTimer(wxTimerEvent &event) {
308 m_pGribTable->MakeCellVisible(0, m_pIndex);
311void GRIBTable::OnClose(wxCloseEvent &event) {
313 this->EndModal(wxID_OK);
316void GRIBTable::OnOKButton(wxCommandEvent &event) {
318 this->EndModal(wxID_OK);
321void GRIBTable::CloseDialog() {
322 wxSize s = this->GetClientSize();
327 pConf->SetPath(
"/Settings/GRIB");
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());
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);
342 m_pGribTable->SetRowAttr(num_rows, row_attr);
344 m_pDataCellsColour = m_pGribTable->GetCellBackgroundColour(
348void GRIBTable::AutoSizeDataRows() {
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);
354 m_pGribTable->SetDefaultRowSize(hrows,
true);
356 m_pGribTable->SetScrollLineY(hrows);
359wxString GRIBTable::GetWind(
GribRecord **recordarray,
int datatype,
361 wxString skn(wxEmptyString);
367 recordarray[
Idx_WIND_VY + altitude], m_cursor_lon, m_cursor_lat)) {
373 GribOverlaySettings::WIND, vkn);
375 m_pGDialog->
pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(
376 GribOverlaySettings::WIND, cvkn);
377 skn.Printf(wxString::Format(
384 GribOverlaySettings::WIND),
385 (
int)wxRound(cvkn)) +
392wxString GRIBTable::GetWindGust(
GribRecord **recordarray,
int datatype) {
393 wxString skn(wxEmptyString);
396 m_cursor_lon, m_cursor_lat,
true);
397 if (vkn != GRIB_NOTDEF) {
399 GribOverlaySettings::WIND_GUST, vkn);
401 m_pGDialog->
pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(
402 GribOverlaySettings::WIND_GUST, cvkn);
404 skn.Printf(wxString::Format(
409 skn.Prepend(wxString::Format(
411 GribOverlaySettings::WIND_GUST),
412 (
int)wxRound(cvkn)) +
420wxString GRIBTable::GetPressure(
GribRecord **recordarray) {
421 wxString skn(wxEmptyString);
424 m_cursor_lon, m_cursor_lat,
true);
426 if (press != GRIB_NOTDEF) {
428 GribOverlaySettings::PRESSURE, press);
434 skn.Printf(wxString::Format(
436 GribOverlaySettings::PRESSURE),
443wxString GRIBTable::GetWaves(
GribRecord **recordarray,
int datatype,
445 wxString skn(wxEmptyString);
451 m_cursor_lon, m_cursor_lat,
true);
452 if (height != GRIB_NOTDEF) {
454 GribOverlaySettings::WAVE, height);
455 skn.Printf(wxString::Format(
457 GribOverlaySettings::WAVE),
460 m_pGDialog->
pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(
461 GribOverlaySettings::WAVE, cheight);
468 m_cursor_lon, m_cursor_lat,
true,
true);
476 m_cursor_lon, m_cursor_lat,
true);
477 if (period != GRIB_NOTDEF)
478 skn.Printf(wxString::Format(
"%01ds", (
int)(period + 0.5)));
484wxString GRIBTable::GetRainfall(
GribRecord **recordarray) {
485 wxString skn(wxEmptyString);
488 m_cursor_lon, m_cursor_lat,
true);
490 if (precip != GRIB_NOTDEF) {
492 GribOverlaySettings::PRECIPITATION, precip);
494 GribOverlaySettings::PRECIPITATION),
497 m_pGDialog->
pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(
498 GribOverlaySettings::PRECIPITATION, precip);
504wxString GRIBTable::GetCloudCover(
GribRecord **recordarray) {
505 wxString skn(wxEmptyString);
508 m_cursor_lon, m_cursor_lat,
true);
510 if (cloud != GRIB_NOTDEF) {
512 GribOverlaySettings::CLOUD, cloud);
513 skn.Printf(
"%5.1f ", cloud);
515 GribOverlaySettings::CLOUD));
517 m_pGDialog->
pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(
518 GribOverlaySettings::CLOUD, cloud);
524wxString GRIBTable::GetAirTemp(
GribRecord **recordarray) {
525 wxString skn(wxEmptyString);
528 m_cursor_lon, m_cursor_lat,
true);
530 if (temp != GRIB_NOTDEF) {
532 GribOverlaySettings::AIR_TEMPERATURE, temp);
534 GribOverlaySettings::AIR_TEMPERATURE),
537 m_pGDialog->
pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(
538 GribOverlaySettings::AIR_TEMPERATURE, temp);
544wxString GRIBTable::GetSeaTemp(
GribRecord **recordarray) {
545 wxString skn(wxEmptyString);
548 m_cursor_lon, m_cursor_lat,
true);
550 if (temp != GRIB_NOTDEF) {
552 GribOverlaySettings::SEA_TEMPERATURE, temp);
554 GribOverlaySettings::SEA_TEMPERATURE),
557 m_pGDialog->
pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(
558 GribOverlaySettings::SEA_TEMPERATURE, temp);
564wxString GRIBTable::GetCAPE(
GribRecord **recordarray) {
565 wxString skn(wxEmptyString);
568 m_cursor_lon, m_cursor_lat,
true);
570 if (cape != GRIB_NOTDEF) {
572 GribOverlaySettings::CAPE, cape);
573 skn.Printf(wxString::Format(
575 GribOverlaySettings::CAPE),
578 m_pGDialog->
pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(
579 GribOverlaySettings::CAPE, cape);
585wxString GRIBTable::GetCompRefl(
GribRecord **recordarray) {
586 wxString skn(wxEmptyString);
589 m_cursor_lon, m_cursor_lat,
true);
591 if (refl != GRIB_NOTDEF) {
593 GribOverlaySettings::COMP_REFL, refl);
594 skn.Printf(wxString::Format(
596 GribOverlaySettings::COMP_REFL),
599 m_pGDialog->
pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(
600 GribOverlaySettings::COMP_REFL, refl);
606wxString GRIBTable::GetCurrent(
GribRecord **recordarray,
int datatype,
608 wxString skn(wxEmptyString);
619 GribOverlaySettings::CURRENT, vkn);
622 GribOverlaySettings::CURRENT),
625 m_pGDialog->
pPlugIn->m_pGRIBOverlayFactory->GetGraphicColor(
626 GribOverlaySettings::CURRENT, vkn);
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_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...