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 *WaypointExists(const wxString &name, double lat, double lon);
135RoutePoint *WaypointExists(const wxString &guid);
136Route *RouteExists(const wxString &guid);
137Route *RouteExists(Route *pTentRoute);
138Track *TrackExists(const wxString &guid);
139int BackupDatabase(wxWindow *parent);
140void ExportGPX(wxWindow *parent, bool bviz_only = false, bool blayer = false);
141void UI_ImportGPX(wxWindow *parent, bool islayer = false, wxString dirpath = "",
142 bool isdirectory = true, bool isPersistent = false);
143
144bool ExportGPXRoutes(wxWindow *parent, RouteList *pRoutes,
145 const wxString suggestedName = "routes");
146bool ExportGPXTracks(wxWindow *parent, std::vector<Track *> *pRoutes,
147 const wxString suggestedName = "tracks");
148bool ExportGPXWaypoints(wxWindow *parent, RoutePointList *pRoutePoints,
149 const wxString suggestedName = "waypoints");
150void ImportFileArray(const wxArrayString &file_array, bool islayer,
151 bool isPersistent, wxString dirpath);
152
154public:
156 static double ui_to_config(int slider_pos) {
157 return (2.0 / 100) * static_cast<double>(slider_pos) + 1.02;
158 }
159
161 static int config_to_ui(double value) {
162 return std::round((100.0 * (static_cast<double>(value) - 1.02)) / 2.0);
163 }
164};
165
166//----------------------------------------------------------------------------
167// Config
168//----------------------------------------------------------------------------
169class MyConfig : public wxFileConfig {
170public:
171 MyConfig(const wxString &LocalFileName);
172 ~MyConfig();
173
174 int LoadMyConfig();
175 void LoadS57Config();
176
177 virtual void CreateConfigGroups(ChartGroupArray *pGroupArray);
178 virtual void DestroyConfigGroups(void);
179 virtual void LoadConfigGroups(ChartGroupArray *pGroupArray);
180
181 virtual void LoadCanvasConfigs(bool bApplyAsTemplate = false);
182 virtual void LoadConfigCanvas(canvasConfig *cConfig, bool bApplyAsTemplate);
183
184 virtual void SaveCanvasConfigs();
185 virtual void SaveConfigCanvas(canvasConfig *cc);
186
187 virtual bool UpdateChartDirs(ArrayOfCDI &dirarray);
188 virtual bool LoadChartDirArray(ArrayOfCDI &ChartDirArray);
189 virtual void UpdateSettings();
190
191 bool LoadLayers(wxString &path);
192 int LoadMyConfigRaw(bool bAsTemplate = false);
193
194private:
195 unsigned ReadUnsigned(const wxString &key, unsigned default_val);
196};
197
198void SwitchInlandEcdisMode(bool Switch);
199
200#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:161
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:156
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:2923
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:2963
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.