OpenCPN Partial API docs
navutil.h
1 /***************************************************************************
2  *
3  * Project: OpenCPN
4  * Purpose: Navigation Utility Functions
5  * Author: David Register
6  *
7  ***************************************************************************
8  * Copyright (C) 2010 by David S. Register *
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  * This program is distributed in the hope that it will be useful, *
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18  * GNU General Public License for more details. *
19  * *
20  * You should have received a copy of the GNU General Public License *
21  * along with this program; if not, write to the *
22  * Free Software Foundation, Inc., *
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
24  **************************************************************************/
25 
26 #ifndef __NAVUTIL__
27 #define __NAVUTIL__
28 
29 #include <wx/config.h>
30 #include <wx/confbase.h>
31 #include <wx/fileconf.h>
32 #include <wx/sound.h>
33 
34 #ifdef __WXMSW__
35 #include <wx/msw/regconf.h>
36 #include <wx/msw/iniconf.h>
37 #endif
38 
39 #include "bbox.h"
40 //#include "chcanv.h"
41 #include "chartdbs.h"
42 // nclude "RoutePoint.h"
43 #include "vector2D.h"
44 #include "model/select_item.h"
45 #include "ocpndc.h"
46 #include "model/navutil_base.h"
47 
48 
49 extern bool LogMessageOnce(const wxString &msg);
50 extern double fromUsrDistance(double usr_distance, int unit = -1);
51 extern double fromUsrSpeed(double usr_speed, int unit = -1);
52 extern double fromUsrWindSpeed(double usr_wspeed, int unit = -1);
53 extern double fromUsrTemp(double usr_temp, int unit = -1);
54 extern wxString getUsrTempUnit();
55 extern wxString formatAngle(double angle);
56 
57 extern void AlphaBlending(ocpnDC &dc, int x, int y, int size_x, int size_y,
58  float radius, wxColour color,
59  unsigned char transparency);
60 
61 // Central dimmer...
62 void DimeControl(wxWindow *ctrl);
63 void DimeControl(wxWindow *ctrl, wxColour col, wxColour col1,
64  wxColour back_color, wxColour text_color, wxColour uitext,
65  wxColour udkrd, wxColour gridline);
66 wxColor GetDimedColor(const wxColor& c);
67 
68 
69 class Route;
70 class NavObjectCollection;
71 class wxGenericProgressDialog;
72 class ocpnDC;
74 class NavObjectChanges;
75 class TrackPoint;
76 class RouteList;
77 class canvasConfig;
78 class RoutePointList;
79 class RoutePoint;
80 class Track;
81 
82 //----------------------------------------------------------------------------
83 // Static XML Helpers
84 //----------------------------------------------------------------------------
85 
86 // RoutePoint *LoadGPXWaypoint (GpxWptElement *wptnode, wxString
87 // def_symbol_name, bool b_fullviz = false ); Route *LoadGPXRoute (GpxRteElement
88 // *rtenode, int routenum, bool b_fullviz = false ); Route *LoadGPXTrack
89 // (GpxTrkElement *trknode, bool b_fullviz = false ); void GPXLoadTrack (
90 // GpxTrkElement *trknode, bool b_fullviz = false ); void GPXLoadRoute (
91 // GpxRteElement *rtenode, int routenum, bool b_fullviz = false ); void
92 // InsertRoute(Route *pTentRoute, int routenum); void UpdateRoute(Route
93 // *pTentRoute);
94 
95 // GpxWptElement *CreateGPXWpt ( RoutePoint *pr, char * waypoint_type, bool
96 // b_props_explicit = false, bool b_props_minimal = false ); GpxRteElement
97 // *CreateGPXRte ( Route *pRoute ); GpxTrkElement *CreateGPXTrk ( Route *pRoute
98 // );
99 
100 bool WptIsInRouteList(RoutePoint *pr);
101 RoutePoint *WaypointExists(const wxString &name, double lat, double lon);
102 RoutePoint *WaypointExists(const wxString &guid);
103 Route *RouteExists(const wxString &guid);
104 Route *RouteExists(Route *pTentRoute);
105 Track *TrackExists(const wxString &guid);
106 
107 void ExportGPX(wxWindow *parent, bool bviz_only = false, bool blayer = false);
108 void UI_ImportGPX(wxWindow *parent, bool islayer = false,
109  wxString dirpath = _T(""), bool isdirectory = true,
110  bool isPersistent = false);
111 
112 bool ExportGPXRoutes(wxWindow *parent, RouteList *pRoutes,
113  const wxString suggestedName = _T("routes"));
114 bool ExportGPXTracks(wxWindow *parent, std::vector<Track*> *pRoutes,
115  const wxString suggestedName = _T("tracks"));
116 bool ExportGPXWaypoints(wxWindow *parent, RoutePointList *pRoutePoints,
117  const wxString suggestedName = _T("waypoints"));
118 
119 
120 class MouseZoom {
121 public:
122 
124  static double ui_to_config(int slider_pos) {
125  return (2.0/100) * static_cast<double>(slider_pos) + 1.02;
126  }
127 
129  static int config_to_ui(double value) {
130  return std::round((100.0 * (static_cast<double>(value) - 1.02)) / 2.0);
131  }
132 };
133 
134 
135 //----------------------------------------------------------------------------
136 // Config
137 //----------------------------------------------------------------------------
138 class MyConfig : public wxFileConfig {
139 public:
140  MyConfig(const wxString &LocalFileName);
141  ~MyConfig();
142 
143  int LoadMyConfig();
144  void LoadS57Config();
145  wxString FindNewestUsableBackup() const;
146  void LoadNavObjects();
147  virtual void AddNewRoute(Route *pr);
148  virtual void UpdateRoute(Route *pr);
149  virtual void DeleteConfigRoute(Route *pr);
150 
151  virtual void AddNewTrack(Track *pt);
152  virtual void UpdateTrack(Track *pt);
153  virtual void DeleteConfigTrack(Track *pt);
154 
155  virtual void AddNewWayPoint(RoutePoint *pWP, int ConfigRouteNum = -1);
156  virtual void UpdateWayPoint(RoutePoint *pWP);
157  virtual void DeleteWayPoint(RoutePoint *pWP);
158  virtual void AddNewTrackPoint(TrackPoint *pWP, const wxString &parent_GUID);
159 
160  virtual void CreateConfigGroups(ChartGroupArray *pGroupArray);
161  virtual void DestroyConfigGroups(void);
162  virtual void LoadConfigGroups(ChartGroupArray *pGroupArray);
163 
164  virtual void LoadCanvasConfigs(bool bApplyAsTemplate = false);
165  virtual void LoadConfigCanvas(canvasConfig *cConfig, bool bApplyAsTemplate);
166 
167  virtual void SaveCanvasConfigs();
168  virtual void SaveConfigCanvas(canvasConfig *cc);
169 
170  virtual bool UpdateChartDirs(ArrayOfCDI &dirarray);
171  virtual bool LoadChartDirArray(ArrayOfCDI &ChartDirArray);
172  virtual void UpdateSettings();
173  virtual void UpdateNavObj(bool bRecreate = false);
174  virtual void UpdateNavObjOnly();
175  virtual bool IsChangesFileDirty();
176 
177  bool LoadLayers(wxString &path);
178  int LoadMyConfigRaw(bool bAsTemplate = false);
179 
180  void CreateRotatingNavObjBackup();
181 
182  wxString m_sNavObjSetFile;
183  wxString m_sNavObjSetChangesFile;
184 
185  NavObjectChanges *m_pNavObjectChangesSet;
186  NavObjectCollection1 *m_pNavObjectInputSet;
187 };
188 
189 void SwitchInlandEcdisMode(bool Switch);
190 
191 
192 #endif
static int config_to_ui(double value)
Convert configuration 1.02..3.0 value to slider scale 1..100.
Definition: navutil.h:129
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:124
Definition: route.h:75
Definition: track.h:78
Definition: ocpndc.h:58