OpenCPN Partial API docs
Loading...
Searching...
No Matches
navutil.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
24#ifndef __NAVUTIL__
25#define __NAVUTIL__
26
27#include <cmath>
28#include <vector>
29
30#include <wx/colour.h>
31#include <wx/config.h>
32#include <wx/confbase.h>
33#include <wx/datetime.h>
34#include <wx/fileconf.h>
35#include <wx/progdlg.h>
36#include <wx/sound.h>
37#include <wx/string.h>
38
39#ifdef __WXMSW__
40#include <wx/msw/regconf.h>
41#include <wx/msw/iniconf.h>
42#endif
43
44#include "model/navutil_base.h"
45#include "model/nav_object_database.h"
46#include "model/select_item.h"
47#include "model/route.h"
48#include "model/route_point.h"
49#include "model/track.h"
50
51#include "bbox.h"
52#include "canvas_config.h"
53#include "chartdbs.h"
54#include "ocpndc.h"
55#include "vector2D.h"
56
57// User date formats
58#define UTCINPUT 0
59#define LTINPUT 1
60#define LMTINPUT 2
61#define GLOBAL_SETTINGS_INPUT 3
62
63constexpr int kMaxCogsogFilterSeconds = 60;
64constexpr int kMaxCogAverageSeconds = 60;
65
66class MyConfig; // forward
67extern MyConfig *pConfig;
69class canvasConfig; // circular
70
71bool LogMessageOnce(const wxString &msg);
72double fromUsrSpeed(double usr_speed, int unit = -1);
73double fromUsrWindSpeed(double usr_wspeed, int unit = -1);
74double fromUsrTemp(double usr_temp, int unit = -1);
75wxString getUsrTempUnit();
76wxString formatAngle(double angle);
77wxString GetLayerName(int id);
78
79namespace navutil {
80
81extern wxArrayString *pMessageOnceArray;
82
83void InitGlobals();
84
85void DeinitGlobals();
86
87} // namespace navutil
88
104wxDateTime toUsrDateTime(const wxDateTime ts, const int format,
105 const double lon = INFINITY - INFINITY);
120wxDateTime fromUsrDateTime(const wxDateTime ts, const int format,
121 const double lon = INFINITY - INFINITY);
122
123extern void AlphaBlending(ocpnDC &dc, int x, int y, int size_x, int size_y,
124 float radius, wxColour color,
125 unsigned char transparency);
126
127// Central dimmer...
128void DimeControl(wxWindow *ctrl);
129void DimeControl(wxWindow *ctrl, wxColour col, wxColour col1,
130 wxColour back_color, wxColour text_color, wxColour uitext,
131 wxColour udkrd, wxColour gridline);
132
133bool WptIsInRouteList(RoutePoint *pr);
134RoutePoint *WaypointExistsByNamePosition(const wxString &name, double lat,
135 double lon);
136RoutePoint *WaypointExistsByGUID(const wxString &guid);
137Route *RouteExists(const wxString &guid);
138Route *RouteExists(Route *pTentRoute);
139Track *TrackExists(const wxString &guid);
140int BackupDatabase(wxWindow *parent);
141void ExportGPX(wxWindow *parent, bool bviz_only = false, bool blayer = false);
142void UI_ImportGPX(wxWindow *parent, bool islayer = false, wxString dirpath = "",
143 bool isdirectory = true, bool isPersistent = false);
144
145bool ExportGPXRoutes(wxWindow *parent, RouteList *pRoutes,
146 const wxString suggestedName = "routes");
147bool ExportGPXTracks(wxWindow *parent, std::vector<Track *> *pRoutes,
148 const wxString suggestedName = "tracks");
149bool ExportGPXWaypoints(wxWindow *parent, RoutePointList *pRoutePoints,
150 const wxString suggestedName = "waypoints");
151void ImportFileArray(const wxArrayString &file_array, bool islayer,
152 bool isPersistent, wxString dirpath);
153
155public:
157 static double ui_to_config(int slider_pos) {
158 return (2.0 / 100) * static_cast<double>(slider_pos) + 1.02;
159 }
160
162 static int config_to_ui(double value) {
163 return std::round((100.0 * (static_cast<double>(value) - 1.02)) / 2.0);
164 }
165};
166
167//----------------------------------------------------------------------------
168// Config
169//----------------------------------------------------------------------------
170class MyConfig : public wxFileConfig {
171public:
172 MyConfig(const wxString &LocalFileName);
173 ~MyConfig();
174
175 int LoadMyConfig();
176 void LoadS57Config();
177
178 virtual void CreateConfigGroups(ChartGroupArray *pGroupArray);
179 virtual void DestroyConfigGroups(void);
180 virtual void LoadConfigGroups(ChartGroupArray *pGroupArray);
181
182 virtual void LoadCanvasConfigs(bool bApplyAsTemplate = false);
183 virtual void LoadConfigCanvas(canvasConfig *cConfig, bool bApplyAsTemplate);
184
185 virtual void SaveCanvasConfigs();
186 virtual void SaveConfigCanvas(canvasConfig *cc);
187
188 virtual bool UpdateChartDirs(ArrayOfCDI &dirarray);
189 virtual bool LoadChartDirArray(ArrayOfCDI &ChartDirArray);
190 virtual void UpdateSettings();
191
192 bool LoadLayers(wxString &path);
193 int LoadMyConfigRaw(bool bAsTemplate = false);
194
195private:
196 unsigned ReadUnsigned(const wxString &key, unsigned default_val);
197};
198
199void SwitchInlandEcdisMode(bool Switch);
200
201#endif
Chart canvas configuration state
Basic chart info storage.
static int config_to_ui(double value)
Convert configuration 1.02..3.0 value to slider scale 1..100.
Definition navutil.h:162
static double ui_to_config(int slider_pos)
Convert a slider scale 1-100 value to configuration value 1.02..3.0.
Definition navutil.h:157
Represents a waypoint or mark within the navigation system.
Definition route_point.h:71
Represents a navigational route in the navigation system.
Definition route.h:99
Represents a track, which is a series of connected track points.
Definition track.h:117
Encapsulates persistent canvas configuration.
Device context class that can use either wxDC or OpenGL for drawing.
Definition ocpndc.h:60
wxDateTime toUsrDateTime(const wxDateTime ts, const int format, const double lon=INFINITY - INFINITY)
Converts a timestamp from UTC to the user's preferred time format.
Definition navutil.cpp:2903
MyConfig * pConfig
Global instance.
Definition navutil.cpp:118
wxDateTime fromUsrDateTime(const wxDateTime ts, const int format, const double lon=INFINITY - INFINITY)
Converts a timestamp from a user's preferred time format to UTC.
Definition navutil.cpp:2943
Navigation Utility Functions without GUI dependencies.
Layer to use wxDC or opengl.
Route abstraction.
Waypoint or mark abstraction.
A single, selected generic item.
Recorded track abstraction.