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
63class MyConfig; // forward
64extern MyConfig *pConfig;
66class canvasConfig; // circular
67
68bool LogMessageOnce(const wxString &msg);
69double fromUsrSpeed(double usr_speed, int unit = -1);
70double fromUsrWindSpeed(double usr_wspeed, int unit = -1);
71double fromUsrTemp(double usr_temp, int unit = -1);
72wxString getUsrTempUnit();
73wxString formatAngle(double angle);
74wxString GetLayerName(int id);
75
76namespace navutil {
77
78extern wxArrayString *pMessageOnceArray;
79
80void InitGlobals();
81
82void DeinitGlobals();
83
84} // namespace navutil
85
101wxDateTime toUsrDateTime(const wxDateTime ts, const int format,
102 const double lon = INFINITY - INFINITY);
117wxDateTime fromUsrDateTime(const wxDateTime ts, const int format,
118 const double lon = INFINITY - INFINITY);
119
120extern void AlphaBlending(ocpnDC &dc, int x, int y, int size_x, int size_y,
121 float radius, wxColour color,
122 unsigned char transparency);
123
124// Central dimmer...
125void DimeControl(wxWindow *ctrl);
126void DimeControl(wxWindow *ctrl, wxColour col, wxColour col1,
127 wxColour back_color, wxColour text_color, wxColour uitext,
128 wxColour udkrd, wxColour gridline);
129
130bool WptIsInRouteList(RoutePoint *pr);
131RoutePoint *WaypointExists(const wxString &name, double lat, double lon);
132RoutePoint *WaypointExists(const wxString &guid);
133Route *RouteExists(const wxString &guid);
134Route *RouteExists(Route *pTentRoute);
135Track *TrackExists(const wxString &guid);
136int BackupDatabase(wxWindow *parent);
137void ExportGPX(wxWindow *parent, bool bviz_only = false, bool blayer = false);
138void UI_ImportGPX(wxWindow *parent, bool islayer = false, wxString dirpath = "",
139 bool isdirectory = true, bool isPersistent = false);
140
141bool ExportGPXRoutes(wxWindow *parent, RouteList *pRoutes,
142 const wxString suggestedName = "routes");
143bool ExportGPXTracks(wxWindow *parent, std::vector<Track *> *pRoutes,
144 const wxString suggestedName = "tracks");
145bool ExportGPXWaypoints(wxWindow *parent, RoutePointList *pRoutePoints,
146 const wxString suggestedName = "waypoints");
147void ImportFileArray(const wxArrayString &file_array, bool islayer,
148 bool isPersistent, wxString dirpath);
149
151public:
153 static double ui_to_config(int slider_pos) {
154 return (2.0 / 100) * static_cast<double>(slider_pos) + 1.02;
155 }
156
158 static int config_to_ui(double value) {
159 return std::round((100.0 * (static_cast<double>(value) - 1.02)) / 2.0);
160 }
161};
162
163//----------------------------------------------------------------------------
164// Config
165//----------------------------------------------------------------------------
166class MyConfig : public wxFileConfig {
167public:
168 MyConfig(const wxString &LocalFileName);
169 ~MyConfig();
170
171 int LoadMyConfig();
172 void LoadS57Config();
173
174 virtual void CreateConfigGroups(ChartGroupArray *pGroupArray);
175 virtual void DestroyConfigGroups(void);
176 virtual void LoadConfigGroups(ChartGroupArray *pGroupArray);
177
178 virtual void LoadCanvasConfigs(bool bApplyAsTemplate = false);
179 virtual void LoadConfigCanvas(canvasConfig *cConfig, bool bApplyAsTemplate);
180
181 virtual void SaveCanvasConfigs();
182 virtual void SaveConfigCanvas(canvasConfig *cc);
183
184 virtual bool UpdateChartDirs(ArrayOfCDI &dirarray);
185 virtual bool LoadChartDirArray(ArrayOfCDI &ChartDirArray);
186 virtual void UpdateSettings();
187
188 bool LoadLayers(wxString &path);
189 int LoadMyConfigRaw(bool bAsTemplate = false);
190
191private:
192};
193
194void SwitchInlandEcdisMode(bool Switch);
195
196#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:158
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:153
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:2869
MyConfig * pConfig
Global instance.
Definition navutil.cpp:110
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:2909
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.