OpenCPN Partial API docs
Loading...
Searching...
No Matches
grib_ui_dlg.h
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
40#ifndef GRIBUICTRLBAR_H_
41#define GRIBUICTRLBAR_H_
42
43#include <wx/wxprec.h>
44
45#ifndef WX_PRECOMP
46#include <wx/wx.h>
47#endif
48#include <wx/glcanvas.h>
49
50#include "cursor_data.h"
51#include "grabber_win.h"
52#include "grib_reader.h"
53#include "grib_record_set.h"
54#include "grib_request_dlg.h"
55#include "grib_settings_dlg.h"
56#include "grib_ui_dlg_base.h"
57#include "iso_line.h"
58
59#ifndef PI
60#define PI 3.1415926535897931160E0 /* pi */
61#endif
62
63extern double m_cursor_lat, m_cursor_lon;
64
65class GRIBUICtrlBar;
66class GRIBUICData;
67class GRIBFile;
68class GRIBRecord;
69class GribRecordTree;
71class GribRecordSet;
73class GribGrabberWin;
74class GribSpacerWin;
75
76class wxFileConfig;
77class GribPi;
78class wxGraphicsContext;
79
80WX_DECLARE_OBJARRAY(GribRecordSet, ArrayOfGribRecordSets);
81
108
112typedef struct {
113 int atmModelIndex;
114 int waveModelIndex;
115 int resolutionIndex;
116 int durationIndex;
117 int runIndex;
118 int intervalIndex;
119 bool wind;
120 bool gust;
121 bool pressure;
122 bool temperature;
123 bool cape;
124 bool reflectivity;
125 bool cloudCover;
126 bool precipitation;
127 bool waveHeight;
128 bool windWaves;
130
150public:
160 GribTimelineRecordSet(unsigned int cnt);
161 // GribTimelineRecordSet(GribRecordSet &GRS1, GribRecordSet &GRS2, double
162 // interp_const);
163 ~GribTimelineRecordSet() override;
164
165 void ClearCachedData();
166
174 wxArrayPtrVoid *m_IsobarArray[Idx_COUNT];
175};
176
177//----------------------------------------------------------------------------------------------------------
178// GRIB CtrlBar Specification
179//----------------------------------------------------------------------------------------------------------
181 friend class GribRequestSetting;
182
183public:
184 GRIBUICtrlBar(wxWindow *parent, wxWindowID id, const wxString &title,
185 const wxPoint &pos, const wxSize &size, long style, GribPi *ppi,
186 double scale_factor);
187 ~GRIBUICtrlBar() override;
188
189 void OpenFile(bool newestFile = false);
190
191 void ContextMenuItemCallback(int id);
192 void SetFactoryOptions();
193
195 wxDateTime TimelineTime();
221 void StopPlayBack();
222 void TimelineChanged();
223 void CreateActiveFileFromNames(const wxArrayString &filenames);
224 void PopulateComboDataList();
225 void ComputeBestForecastForNow();
230 void SetTimeLineMax(bool SetValue);
231 void SetCursorLatLon(double lat, double lon);
244 void SetDialogsStyleSizePosition(bool force_recompute = false);
246 void SetRequestButtonBitmap(int type);
247 GRIBUICData *GetCDataDialog() { return m_gGRIBUICData; }
248 bool InDataPlot(int id) {
249 return id > wxID_ANY && id < (int)GribOverlaySettings::GEO_ALTITUDE;
250 }
251 void SetScaledBitmap(double factor);
252 void OpenFileFromJSON(wxString json);
253
254 //
255 double getTimeInterpolatedValue(int idx, double lon, double lat,
256 wxDateTime t);
257 bool getTimeInterpolatedValues(double &M, double &A, int idx1, int idx2,
258 double lon, double lat, wxDateTime t);
259
260 wxWindow *pParent;
265
267 wxTimer m_tPlayStop;
270 GribRequestSetting *pReq_Dialog;
273 bool m_bDataPlot[GribOverlaySettings::GEO_ALTITUDE]; // only for no altitude
274 // parameters
275 bool m_CDataIsShown;
276 int m_ZoneSelAllowed;
277 int m_old_DialogStyle;
278 void DoZoomToCenter();
279 wxString GetGribDir() {
280 if (m_grib_dir.IsEmpty() || !wxDirExists(m_grib_dir)) {
282 ->Append(wxFileName::GetPathSeparator())
283 .Append("grib");
284
285 if (!wxDirExists(m_grib_dir)) wxMkdir(m_grib_dir);
286
287 wxString dir_spec;
288 int response = PlatformDirSelectorDialog(
289 this, &dir_spec, _("Choose GRIB File Directory"), m_grib_dir);
290
291 if (response == wxID_OK) {
292 m_grib_dir = (dir_spec);
293 }
294 }
295 return m_grib_dir;
296 }
297
315 void GetProjectedLatLon(int &x, int &y, PlugIn_ViewPort *vp);
316 bool ProjectionEnabled() {
317 if (m_ProjectBoatPanel)
318 return m_ProjectBoatPanel->ProjectionEnabled();
319 else
320 return false;
321 }
322 double m_highlight_latmax;
323 double m_highlight_lonmax;
324 double m_highlight_latmin;
325 double m_highlight_lonmin;
327 wxString m_grib_dir;
329 wxArrayString m_file_names;
330 void DoOnMouseEvent(wxMouseEvent &event) { OnMouseEvent(event); }
331
332protected:
333 void OnClose(wxCloseEvent &event) override;
334 void OnSize(wxSizeEvent &event) override;
335 void OnPaint(wxPaintEvent &event) override;
336 void OnSettings(wxCommandEvent &event) override;
337 void OnPlayStop(wxCommandEvent &event) override;
338 void OnZoomToCenterClick(wxCommandEvent &event) override;
339 void OnPrev(wxCommandEvent &event) override;
340 void OnMouseEvent(wxMouseEvent &event) override;
341 void OnRecordForecast(wxCommandEvent &event) override {
342 StopPlayBack();
343 m_InterpolateMode = false;
344 m_pNowMode = false;
345 TimelineChanged();
346 }
347 void OnNext(wxCommandEvent &event) override;
348 void OnNow(wxCommandEvent &event) override {
349 StopPlayBack();
350 ComputeBestForecastForNow();
351 }
352 void OnAltitude(wxCommandEvent &event) override;
353 void OnOpenFile(wxCommandEvent &event) override;
355 void OnRequestForecastData(wxCommandEvent &event) override;
356 void OnCompositeDialog(wxCommandEvent &event) override;
357
358 void OnTimeline(wxScrollEvent &event) override;
359 void OnShowCursorData(wxCommandEvent &event) override;
360
361private:
362 void OnPlayStopTimer(wxTimerEvent &event);
363 void OnMove(wxMoveEvent &event);
364 void OnMenuEvent(wxMenuEvent &event);
365 void MenuAppend(wxMenu *menu, int id, wxString label, wxItemKind kind,
366 wxBitmap bitmap = wxNullBitmap, wxMenu *submenu = nullptr);
367
368 void createRequestDialog();
369
370 wxDateTime MinTime();
371 wxArrayString GetFilesInDirectory();
372 void SetGribTimelineRecordSet(GribTimelineRecordSet *pTimelineSet);
373 int GetNearestIndex(wxDateTime time, int model);
374 int GetNearestValue(wxDateTime time, int model);
375 bool GetGribZoneLimits(GribTimelineRecordSet *timelineSet, double *latmin,
376 double *latmax, double *lonmin, double *lonmax);
377 wxDateTime GetNow();
378 void RestaureSelectionString();
379 void SaveSelectionString() {
380 m_SelectionIsSaved = true;
381 m_Selection_index = m_cRecordForecast->GetSelection();
382 m_Selection_label = m_cRecordForecast->GetString(m_Selection_index);
383 }
384
385 // Data
386 CursorData *m_gCursorData;
387 GribGrabberWin *m_gGrabber;
388 GRIBUICData *m_gGRIBUICData;
390 PlugIn_ViewPort *m_vpMouse;
391 int m_lastdatatype;
392
393 int m_TimeLineHours;
394 int m_FileIntervalIndex;
395 bool m_InterpolateMode;
396 bool m_pNowMode;
397 bool m_HasAltitude;
398
399 bool m_SelectionIsSaved;
400 int m_Selection_index;
401 wxString m_Selection_label;
402 wxSize m_DialogsOffset;
403 double m_projected_lat;
404 double m_projected_lon;
405 // XyGrib panel configuration
406 XyGribConfig_t xyGribConfig;
407 bool m_gtk_started;
408
409 wxTimer m_tFormatRefresh;
410 wxString m_sLastTimeFormat; // Used to detect time format changes
411
412 void OnFormatRefreshTimer(wxTimerEvent &event);
413};
414
431class GRIBFile {
432public:
445 GRIBFile(const wxArrayString &file_names, bool CumRec, bool WaveRec,
446 bool newestFile = false);
447 ~GRIBFile();
448
453 [[nodiscard]] bool IsOK() const { return m_bOK; }
459 wxArrayString &GetFileNames() { return m_FileNames; }
463 wxString GetLastMessage() { return m_last_message; }
469 ArrayOfGribRecordSets *GetRecordSetArrayPtr() {
470 return &m_GribRecordSetArray;
471 }
481 [[nodiscard]] time_t GetRefDateTime() const { return m_pRefDateTime; }
482
483 [[nodiscard]] unsigned int GetCounter() const { return m_counter; }
484
485 WX_DEFINE_ARRAY_INT(int, GribIdxArray);
486 GribIdxArray m_GribIdxArray;
487
488private:
489 static unsigned int ID;
490
491 const unsigned int m_counter;
492 bool m_bOK;
493 wxString m_last_message;
494 wxArrayString m_FileNames;
495 GribReader *m_pGribReader;
496 time_t m_pRefDateTime;
497
499 ArrayOfGribRecordSets m_GribRecordSetArray;
500
501 int m_nGribRecords;
502};
503
504//---------------------------------------------------------------------
505// GRIB CursorData Dialog Specification
506//--------------------------------------------------------------------
508public:
509 GRIBUICData(GRIBUICtrlBar &parent);
510 ~GRIBUICData() override = default;
511
512 // GribGrabberWin *m_gGrabber;
513 GRIBUICtrlBar &m_gpparent;
514 CursorData *m_gCursorData;
515
516private:
517 void OnMove(wxMoveEvent &event);
518};
519
520#endif // GRIBUICTRLBAR_H_
Tracks and displays GRIB meteorological data at cursor position.
Definition cursor_data.h:52
Manages multiple GRIB record sets from one or more GRIB files.
bool IsOK() const
Checks if file loading and parsing was successful.
wxArrayString & GetFileNames()
Gets the list of source filenames being used.
wxString GetLastMessage()
Gets the last error message if file loading failed.
ArrayOfGribRecordSets * GetRecordSetArrayPtr()
Gets pointer to array of record sets organized by timestamp.
time_t GetRefDateTime() const
Returns the reference datetime of the GRIB data, as the number of seconds since the epoch.
Factory class for creating and managing GRIB data visualizations.
Class GRIBUICDataBase.
Class GRIBUICtrlBarBase.
void SetViewPortWithFocus(PlugIn_ViewPort *vp)
Set the ViewPort that has the focus.
void GetProjectedLatLon(int &x, int &y, PlugIn_ViewPort *vp)
Gets the projected position of vessel based on current course, speed and forecast time.
GribOverlaySettings m_OverlaySettings
Settings that control how GRIB data is displayed and overlaid.
void SetRequestButtonBitmap(int type)
Set the icon and tooltip for the download request button.
wxTimer m_tPlayStop
Timer for controlling GRIB animation playback.
void SetViewPortUnderMouse(PlugIn_ViewPort *vp)
Set the ViewPort under the mouse.
GribPi * pPlugIn
Plugin instance that owns this control bar.
wxString m_grib_dir
Directory containing GRIB files.
GRIBFile * m_bGRIBActiveFile
Currently active GRIB file being displayed.
wxDateTime TimelineTime()
Returns the selected time in the GRIB timeline widget.
void UpdateTrackingControl()
Schedules an update of the GRIB data values display at current cursor position.
GribTimelineRecordSet * m_pTimelineSet
Current set of GRIB records for timeline playback.
void OnRequestForecastData(wxCommandEvent &event) override
Callback invoked when user clicks download/request forecast data.
wxArrayString m_file_names
List of GRIB filenames being displayed.
GribTimelineRecordSet * GetTimeLineRecordSet(wxDateTime time)
Retrieves or creates a temporally interpolated GRIB record set for a specific timestamp.
Manages a collection of GribRecord objects representing multiple meteorological parameters at a singl...
Manages GRIB file request configuration and downloads.
A specialized GribRecordSet that represents temporally interpolated weather data with isobar renderin...
wxArrayPtrVoid * m_IsobarArray[Idx_COUNT]
Array of cached isobar calculations for each data type (wind, pressure, etc).
Contains view parameters and status information for a chart display viewport.
GRIB Cursor Data Tracking and Display.
GRIB Dialog Grabber Control Interface.
GRIB (GRIdded Binary) file reader and parser.
GRIB Record Set Management.
@ Idx_COUNT
Number of supported GRIB record types.
GRIB Weather Data Request and Download Management.
GRIB Display Settings Configuration Interface.
ZoneSelection
Defines the possible states for GRIB area selection.
Definition grib_ui_dlg.h:86
@ AUTO_SELECTION
Area automatically set from current viewport bounds.
Definition grib_ui_dlg.h:87
@ DRAW_SELECTION
Manual mode has been selected.
@ START_SELECTION
User has clicked Shift + Left click and is drawing the bounding box by dragging the mouse.
Definition grib_ui_dlg.h:93
@ COMPLETE_SELECTION
Selection box completed in manual mode, coordinates have been captured after the user has released th...
@ SAVED_SELECTION
Area loaded from previously saved coordinates.
Definition grib_ui_dlg.h:88
Base User Interface Components for GRIB Plugin.
GRIB Isobar and Isoline Generation System.
int PlatformDirSelectorDialog(wxWindow *parent, wxString *file_spec, wxString Title, wxString initDir)
Shows platform-optimized directory selector dialog.
wxString * GetpPrivateApplicationDataLocation()
Gets private application data directory.
Structure used to store XyGrib configuration.