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 30 #include <wx/config.h> 31 #include <wx/confbase.h> 32 #include <wx/fileconf.h> 33 #include <wx/sound.h> 34 35 #ifdef __WXMSW__ 36 #include <wx/msw/regconf.h> 37 #include <wx/msw/iniconf.h> 38 #endif 39 40 #include "bbox.h" 41 //#include "chcanv.h" 42 #include "chartdbs.h" 43 //nclude "RoutePoint.h" 44 #include "vector2D.h" 45 #include "SelectItem.h" 46 #include "ocpndc.h" 47 48 enum 49 { 50 DISTANCE_NMI = 0, 51 DISTANCE_MI, 52 DISTANCE_KM, 53 DISTANCE_M, 54 DISTANCE_FT, 55 DISTANCE_FA, 56 DISTANCE_IN, 57 DISTANCE_CM 58 }; 59 60 enum 61 { 62 SPEED_KTS = 0, 63 SPEED_MPH, 64 SPEED_KMH, 65 SPEED_MS 66 }; 67 68 extern bool LogMessageOnce(const wxString &msg); 69 extern double toUsrDistance( double nm_distance, int unit = -1 ); 70 extern double fromUsrDistance( double usr_distance, int unit = -1 ); 71 extern double toUsrSpeed( double kts_speed, int unit = -1 ); 72 extern double fromUsrSpeed( double usr_speed, int unit = -1 ); 73 extern wxString getUsrDistanceUnit( int unit = -1 ); 74 extern wxString getUsrSpeedUnit( int unit = -1 ); 75 extern wxString toSDMM(int NEflag, double a, bool hi_precision = true); 76 extern wxString FormatDistanceAdaptive( double distance ); 77 extern wxString formatTimeDelta(wxTimeSpan span); 78 extern wxString formatTimeDelta(wxDateTime startTime, wxDateTime endTime); 79 extern wxString formatTimeDelta(wxLongLong secs); 80 extern wxString formatAngle(double angle); 81 82 extern void AlphaBlending( ocpnDC& dc, int x, int y, int size_x, int size_y, float radius, 83 wxColour color, unsigned char transparency ); 84 85 //Central dimmer... 86 void DimeControl(wxWindow* ctrl); 87 void DimeControl(wxWindow* ctrl, wxColour col, wxColour col1, wxColour back_color,wxColour text_color,wxColour uitext, wxColour udkrd, wxColour gridline); 88 89 extern double fromDMM(wxString sdms); 90 91 class Route; 92 class NavObjectCollection; 93 class wxGenericProgressDialog; 94 class ocpnDC; 95 class NavObjectCollection1; 96 class NavObjectChanges; 97 class TrackPoint; 98 class TrackList; 99 class RouteList; 100 class canvasConfig; 101 class RoutePointList; 102 class RoutePoint; 103 class Track; 104 105 //---------------------------------------------------------------------------- 106 // Static XML Helpers 107 //---------------------------------------------------------------------------- 108 109 //RoutePoint *LoadGPXWaypoint (GpxWptElement *wptnode, wxString def_symbol_name, bool b_fullviz = false ); 110 //Route *LoadGPXRoute (GpxRteElement *rtenode, int routenum, bool b_fullviz = false ); 111 //Route *LoadGPXTrack (GpxTrkElement *trknode, bool b_fullviz = false ); 112 //void GPXLoadTrack ( GpxTrkElement *trknode, bool b_fullviz = false ); 113 //void GPXLoadRoute ( GpxRteElement *rtenode, int routenum, bool b_fullviz = false ); 114 //void InsertRoute(Route *pTentRoute, int routenum); 115 //void UpdateRoute(Route *pTentRoute); 116 117 //GpxWptElement *CreateGPXWpt ( RoutePoint *pr, char * waypoint_type, bool b_props_explicit = false, bool b_props_minimal = false ); 118 //GpxRteElement *CreateGPXRte ( Route *pRoute ); 119 //GpxTrkElement *CreateGPXTrk ( Route *pRoute ); 120 121 bool WptIsInRouteList(RoutePoint *pr); 122 RoutePoint *WaypointExists( const wxString& name, double lat, double lon); 123 RoutePoint *WaypointExists( const wxString& guid); 124 Route *RouteExists( const wxString& guid); 125 Route *RouteExists( Route * pTentRoute ); 126 Track *TrackExists( const wxString& guid ); 127 const wxChar *ParseGPXDateTime( wxDateTime &dt, const wxChar *datetime ); 128 129 void ExportGPX(wxWindow* parent, bool bviz_only = false, bool blayer = false); 130 void UI_ImportGPX(wxWindow* parent, bool islayer = false, wxString dirpath = _T(""), bool isdirectory = true, bool isPersistent = false); 131 132 bool ExportGPXRoutes(wxWindow* parent, RouteList *pRoutes, const wxString suggestedName = _T("routes")); 133 bool ExportGPXTracks(wxWindow* parent, TrackList *pRoutes, const wxString suggestedName = _T("tracks")); 134 bool ExportGPXWaypoints(wxWindow* parent, RoutePointList *pRoutePoints, const wxString suggestedName = _T("waypoints")); 135 136 //---------------------------------------------------------------------------- 137 // Config 138 //---------------------------------------------------------------------------- 139 class MyConfig:public wxFileConfig 140 { 141 public: 142 143 MyConfig(const wxString &LocalFileName); 144 145 int LoadMyConfig(); 146 void LoadS57Config(); 147 void LoadNavObjects(); 148 virtual void AddNewRoute(Route *pr); 149 virtual void UpdateRoute(Route *pr); 150 virtual void DeleteConfigRoute(Route *pr); 151 152 virtual void AddNewTrack(Track *pt); 153 virtual void UpdateTrack(Track *pt); 154 virtual void DeleteConfigTrack(Track *pt); 155 156 virtual void AddNewWayPoint(RoutePoint *pWP, int ConfigRouteNum = -1); 157 virtual void UpdateWayPoint(RoutePoint *pWP); 158 virtual void DeleteWayPoint(RoutePoint *pWP); 159 virtual void AddNewTrackPoint( TrackPoint *pWP, const wxString& parent_GUID ); 160 161 virtual void CreateConfigGroups ( ChartGroupArray *pGroupArray ); 162 virtual void DestroyConfigGroups ( void ); 163 virtual void LoadConfigGroups ( ChartGroupArray *pGroupArray ); 164 165 virtual void LoadCanvasConfigs( bool bApplyAsTemplate = false ); 166 virtual void LoadConfigCanvas( canvasConfig *cConfig, bool bApplyAsTemplate ); 167 168 virtual void SaveCanvasConfigs( ); 169 virtual void SaveConfigCanvas( canvasConfig *cc ); 170 171 virtual bool UpdateChartDirs(ArrayOfCDI &dirarray); 172 virtual bool LoadChartDirArray(ArrayOfCDI &ChartDirArray); 173 virtual void UpdateSettings(); 174 virtual void UpdateNavObj(bool bRecreate = false); 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 bool m_bSkipChangeSetUpdate; 188 189 }; 190 191 void SwitchInlandEcdisMode( bool Switch ); 192 193 /* 194 * X11FontPicker DIALOG 195 */ 196 #include <wx/fontdlg.h> 197 198 class wxChoice; 199 class WXDLLEXPORT wxText; 200 class wxCheckBox; 201 class WXDLLEXPORT MyFontPreviewer; 202 203 /* 204 enum 205 { 206 wxID_FONT_UNDERLINE = 3000, 207 wxID_FONT_STYLE, 208 wxID_FONT_WEIGHT, 209 wxID_FONT_FAMILY, 210 wxID_FONT_COLOUR, 211 wxID_FONT_SIZE 212 }; 213 */ 214 215 class WXDLLEXPORT X11FontPicker : public wxFontDialogBase 216 { 217 public: X11FontPicker()218 X11FontPicker() { Init(); } X11FontPicker(wxWindow * parent,const wxFontData & data)219 X11FontPicker(wxWindow *parent, const wxFontData& data) : wxFontDialogBase(parent, data) { Init(); } 220 virtual ~X11FontPicker(); 221 222 virtual int ShowModal(); 223 224 225 // deprecated, for backwards compatibility only 226 // X11FontPicker(wxWindow *parent, const wxFontData *data) 227 // : wxFontDialogBase(parent, data) { Init(); } 228 229 // Internal functions 230 void OnCloseWindow(wxCloseEvent& event); 231 232 virtual void CreateWidgets(); 233 virtual void InitializeFont(); 234 235 void OnChangeFont(wxCommandEvent& event); 236 void OnChangeFace(wxCommandEvent& event); 237 238 protected: 239 // common part of all ctors 240 void Init(); 241 242 virtual bool DoCreate(wxWindow *parent); 243 void InitializeAllAvailableFonts(); 244 void SetChoiceOptionsFromFacename(const wxString &facename); 245 void DoFontChange(void); 246 247 wxFont dialogFont; 248 249 wxChoice *familyChoice; 250 wxChoice *styleChoice; 251 wxChoice *weightChoice; 252 wxChoice *colourChoice; 253 wxCheckBox *underLineCheckBox; 254 wxChoice *pointSizeChoice; 255 256 MyFontPreviewer *m_previewer; 257 bool m_useEvents; 258 259 wxArrayString *pFaceNameArray; 260 261 wxFont *pPreviewFont; 262 263 // static bool fontDialogCancelled; 264 DECLARE_EVENT_TABLE() 265 DECLARE_DYNAMIC_CLASS(X11FontPicker) 266 }; 267 268 269 class GpxDocument 270 { 271 public: 272 static wxString GetUUID(void); 273 static void SeedRandom(); 274 private: 275 static int GetRandomNumber(int min, int max); 276 }; 277 278 #endif 279