OpenCPN Partial API docs
Loading...
Searching...
No Matches
grib_request_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
47#ifndef GRIBREQUESTDIALOG_H_
48#define GRIBREQUESTDIALOG_H_
49
50#ifndef WX_PRECOMP
51#include <wx/wx.h>
52#endif
53
54#include "grib_ui_dlg_base.h"
55#include "grib_ui_dlg.h"
56#include "jsonreader.h"
57#include "pi_ocpndc.h"
58
59#define XYGRIB_MAX_DOWNLOADABLE_GRIB_SIZE_MB 10
60
68
69const std::string CATALOG_URL =
70 "https://raw.githubusercontent.com/chartcatalogs/gribcatalog/main/"
71 "sources.json";
72
73const std::string WORLD_MODELS_URL = "https://grib.bosun.io/models";
74
79 RENDER_NONE = 0, // No selection zone to render
80 RENDER_COMPLETE = 1, // Selection is complete, render the final zone
81 RENDER_DRAWING = 2 // User is actively drawing the selection zone
82};
83
96public:
98
99 ~GribRequestSetting() override;
100
101 void OnClose(wxCloseEvent &event) override;
102 void SetVpSize(PlugIn_ViewPort *vp);
130 bool MouseEventHook(wxMouseEvent &event);
139 bool RenderZoneOverlay(wxDC &dc);
147 bool RenderGlZoneOverlay();
156 bool DoRenderZoneOverlay();
157 void SetRequestDialogSize();
158 void StopGraphicalZoneSelection();
159 void UpdateAreaSelectionState();
168 [[nodiscard]] double GetMinLat() const;
177 [[nodiscard]] double GetMaxLat() const;
186 [[nodiscard]] double GetMinLon() const;
195 [[nodiscard]] double GetMaxLon() const;
196
197 [[nodiscard]] int GetBoundingBoxCanvasIndex() const {
198 return m_boundingBoxCanvasIndex;
199 }
200
201 void Save() {
202 wxCommandEvent evt;
203 OnOK(evt);
204 }
205
206 wxString m_RequestConfigBase;
207 wxString m_MailToAddresses;
214
225
236 double m_Lat;
238 double m_Lon;
239
240protected:
241 void OnTopChange(wxCommandEvent &event) override;
242 void OnMovingClick(wxCommandEvent &event) override;
243 void OnAnyChange(wxCommandEvent &event) override;
244 void OnAnySpinChange(wxSpinEvent &event) override {
245 wxCommandEvent evt;
246 OnAnyChange(evt);
247 }
249 void OnNotebookPageChanged(wxNotebookEvent &event) override {
250 HighlightArea(0, 0, 0, 0);
251 }
252 void OnTimeRangeChange(wxCommandEvent &event) override;
253 void OnSendMaiL(wxCommandEvent &event) override;
254 void OnOK(wxCommandEvent &event) override;
255 void OnZoneSelectionModeChange(wxCommandEvent &event) override;
256 void OnCancel(wxCommandEvent &event) override {
257 wxCloseEvent evt;
258 OnClose(evt);
259 }
260 void OnWorldModelChoice(wxCommandEvent &event) override;
261 void OnUpdateWorldModels(wxCommandEvent &event) override;
262 void OnWorldDownload(wxCommandEvent &event) override;
263 void OnLocalTreeItemExpanded(wxTreeEvent &event) override { event.Skip(); }
264 void OnLocalTreeSelChanged(wxTreeEvent &event) override;
265 void OnUpdateLocalCatalog(wxCommandEvent &event) override;
266 // XyGrib GUI callbacks
267 void OnXyGribDownloadButton(wxCommandEvent &event) override;
268 void OnXyGribAtmModelChoice(wxCommandEvent &event) override;
269 void OnXyGribWaveModelChoice(wxCommandEvent &event) override;
270 void OnXyGribConfigChange(wxCommandEvent &event) override;
271 void OnDownloadLocal(wxCommandEvent &event) override;
272 void OnCoordinatesChange(wxSpinEvent &event) override;
273 void SaveConfig() override;
274
275private:
276 void HighlightArea(double latmax, double lonmax, double latmin,
277 double lonmin);
278 void ReadLocalCatalog();
279 void ReadWorldModels();
280 int FindWorldModel(const wxString &name);
281 wxJSONValue m_world_models;
282 void FillTreeCtrl(wxJSONValue &data);
283 void ApplyRequestConfig(unsigned rs, unsigned it, unsigned tr);
284 wxString WriteMail();
285 int EstimateFileSize(double *size);
286
287 template <typename T>
288 static std::string FormatPerLocale(T value);
289
290 static wxString GetDownloadProgressText(long bytesTransferred,
291 long bytesTotal);
294 void InitRequestConfig();
295 void OnExit(wxCommandEvent &event) {
296 wxCloseEvent evt;
297 OnClose(evt);
298 }
299
300 void OnMouseEventTimer(wxTimerEvent &event);
301 void SetCoordinatesText();
302
303 void onDLEvent(OCPN_downloadEvent &ev);
304 void EnableDownloadButtons();
305
306 // Xygrib internal methods
307 void InitializeXygribDialog();
308 wxString BuildXyGribUrl();
309 wxString BuildGribFileName();
310
311 // Manage XyGrib UI Configuration
312 void ApplyXyGribConfiguration();
313 void MemorizeXyGribConfiguration();
314 // Calculate estimated size of GRIB file
315 void UpdateGribSizeEstimate();
316
317 // Index of currently selected XyGrib atmospheric model
318 int m_selectedAtmModelIndex;
319 // Index of currently selected XyGrib wave model
320 int m_selectedWaveModelIndex;
321 // Last size estimation of the GRIB file
322 int m_gribSizeEstimate;
323
324 GRIBUICtrlBar &m_parent;
325
326 wxDC *m_pdc;
327 pi_ocpnDC *m_oDC; // Used for selection overlay on GL
328
329 wxTimer m_tMouseEventTimer;
330 wxTimer m_tMouseClickTimer;
331 wxMouseEvent m_SingleClickEvent;
332
333 bool IsZYGRIB;
334 bool IsGFS;
335 int m_MailError_Nb;
336 int m_SendMethod;
337 bool m_AllowSend;
338 bool m_IsMaxLong;
339 double m_displayScale;
340 bool m_connected;
341 bool m_downloading;
342 long m_download_handle;
343 bool m_bTransferSuccess;
344 bool m_canceled;
345 bool m_bLocal_source_selected;
346 GribDownloadType m_downloadType;
349 int m_boundingBoxCanvasIndex;
350};
351
352#endif // GRIBREQUESTDIALOG_H_
Class GribRequestSettingBase.
Manages GRIB file request configuration and downloads.
double m_StartLat
The latitude at the starting point of the bounding box.
void OnXyGribWaveModelChoice(wxCommandEvent &event) override
Handle action of changing wave model selection.
void OnSendMaiL(wxCommandEvent &event) override
Callback invoked when the user clicks the "Send" button in the "e-mail" tab.
double GetMinLat() const
Get the minimum latitude of the bounding box for the download request.
double GetMaxLat() const
Get the maximum latitude of the bounding box for the download request.
double m_Lat
The latitude at the mouse cursor while drawing a bounding box.
void OnCancel(wxCommandEvent &event) override
Callback invoked when the user clicks the "Cancel" button in the "download" dialog.
void OnVpUnderMouseChange(PlugIn_ViewPort *vp)
Callback invoked when the view port under mouse has changed.
bool RenderGlZoneOverlay()
Renders the GRIB area selection overlay using OpenGL.
bool RenderZoneOverlay(wxDC &dc)
Renders the GRIB area selection overlay using standard device context.
double m_Lon
The longitude at the mouse cursor while drawing a bounding box.
void OnXyGribAtmModelChoice(wxCommandEvent &event) override
Handle action of changing atmospheric model selection.
wxPoint m_StartPoint
Starting point of the bounding box in physical pixels.
bool DoRenderZoneOverlay()
Draws the GRIB area selection overlay on the chart.
void OnNotebookPageChanged(wxNotebookEvent &event) override
Save the "download" configuration to disk.
bool MouseEventHook(wxMouseEvent &event)
Intercepts mouse events to handle GRIB area selection.
void OnVpWithFocusChange(PlugIn_ViewPort *vp)
Callback invoked when the focused view port has changed, such as in multi-chart mode when user switch...
PlugIn_ViewPort * m_VpMouse
The viewport under the mouse.
ZoneSelectionRenderState m_RenderSelectionZoneState
Current state of the bounding box overlay rendering.
void OnXyGribConfigChange(wxCommandEvent &event) override
Handle action of changing a GRIB configuration parameter.
double GetMaxLon() const
Get the maximum longitude of the bounding box for the download request.
PlugIn_ViewPort * m_VpFocus
The viewport currently in focus.
double m_StartLon
The longitude at the starting point of the bounding box.
double GetMinLon() const
Get the minimum longitude of the bounding box for the download request.
void OnOK(wxCommandEvent &event) override
Callback invoked when the user clicks the "OK" button in the "download" dialog.
Contains view parameters and status information for a chart display viewport.
The JSON value class implementation.
Definition jsonval.h:79
ZoneSelectionRenderState
Enumeration defining the states of the GRIB zone selection overlay rendering.
GribDownloadType
@ WORLD
Global forecast downloads (e.g., GFS)
@ XYGRIB
Downloads from XyGrib service.
@ NONE
No download source selected.
@ LOCAL_CATALOG
Downloads from configured catalogs.
@ LOCAL
Downloads from local sources.
GRIB Weather Data Control Interface.
Base User Interface Components for GRIB Plugin.
Graphics abstraction layer on top of wxDC or OpenGL.