OpenCPN Partial API docs
ConfigMgr.cpp
1 /***************************************************************************
2  *
3  * Project: OpenCPN
4  *
5  ***************************************************************************
6  * Copyright (C) 2018 by David S. Register *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
22  **************************************************************************/
23 
24 #ifdef __MINGW32__
25 #undef IPV6STRICT // mingw FTBS fix: missing struct ip_mreq
26 #include <windows.h>
27 #endif
28 
29 #include <wx/tokenzr.h>
30 
31 #include "config.h"
32 #include "model/config_vars.h"
33 #include "ConfigMgr.h"
34 
35 #include <wx/filename.h>
36 #include <wx/fileconf.h>
37 #include <wx/statline.h>
38 
39 #include "dychart.h"
40 
41 #include <stdlib.h>
42 //#include <math.h>
43 #include <time.h>
44 #include <locale>
45 #include <list>
46 
47 #include <wx/listimpl.cpp>
48 #include <wx/progdlg.h>
49 
50 #include "model/ais_decoder.h"
51 #include "model/ais_state_vars.h"
52 #include "model/cutil.h"
53 #include "model/geodesic.h"
54 #include "model/georef.h"
55 #include "model/multiplexer.h"
56 #include "model/nav_object_database.h"
57 #include "model/route.h"
58 #include "model/routeman.h"
59 #include "model/select.h"
60 #include "model/track.h"
61 
62 #include "ais.h"
63 #include "CanvasConfig.h"
64 #include "chartbase.h"
65 #include "chartdb.h"
66 #include "chcanv.h"
67 #include "cm93.h"
68 #include "FontMgr.h"
69 #include "Layer.h"
70 #include "navutil.h"
71 #include "nmea0183.h"
72 #include "NMEALogWindow.h"
73 #include "ocpndc.h"
74 #include "ocpn_frame.h"
75 #include "OCPNPlatform.h"
76 #include "s52plib.h"
77 #include "s52utils.h"
78 #include "styles.h"
79 
80 #ifdef ocpnUSE_GL
81 #include "glChartCanvas.h"
82 #endif
83 
84 // Global statics
85 // Statics
86 
87 extern OCPNPlatform *g_Platform;
88 extern MyFrame *gFrame;
89 
90 extern int g_restore_stackindex;
91 extern int g_restore_dbindex;
92 extern LayerList *pLayerList;
93 extern MyConfig *pConfig;
94 extern int g_nbrightness;
95 extern bool g_bShowStatusBar;
96 extern bool g_bUIexpert;
97 extern bool g_bFullscreen;
98 
99 extern wxString g_SENCPrefix;
100 extern wxString g_UserPresLibData;
101 
102 extern wxString *pInit_Chart_Dir;
103 extern wxString gWorldMapLocation;
104 extern wxString gWorldShapefileLocation;
105 
106 extern bool s_bSetSystemTime;
107 extern bool g_bDisplayGrid; // Flag indicating if grid is to be displayed
108 extern bool g_bPlayShipsBells;
109 extern int g_iSoundDeviceIndex;
110 extern bool g_bFullscreenToolbar;
111 extern bool g_bShowLayers;
112 extern bool g_bTransparentToolbar;
113 extern bool g_bPermanentMOBIcon;
114 
115 extern bool g_bShowDepthUnits;
116 extern bool g_bAutoAnchorMark;
117 extern bool g_bskew_comp;
118 extern bool g_bopengl;
119 extern bool g_bSoftwareGL;
120 extern bool g_bsmoothpanzoom;
121 
122 extern bool g_bShowOutlines;
123 extern bool g_bShowActiveRouteHighway;
124 extern bool g_bShowRouteTotal;
125 extern int g_nAWDefault;
126 extern int g_nAWMax;
127 
128 extern int g_nframewin_x;
129 extern int g_nframewin_y;
130 extern int g_nframewin_posx;
131 extern int g_nframewin_posy;
132 extern bool g_bframemax;
133 extern int g_route_prop_x, g_route_prop_y;
134 extern int g_route_prop_sx, g_route_prop_sy;
135 
136 extern wxString g_VisibleLayers;
137 extern wxString g_InvisibleLayers;
138 
139 // LIVE ETA OPTION
140 extern bool g_bShowLiveETA;
141 extern double g_defaultBoatSpeed;
142 
143 extern int g_S57_dialog_sx, g_S57_dialog_sy;
144 
145 extern int g_iNavAidRadarRingsNumberVisible;
146 extern bool g_bNavAidRadarRingsShown;
147 extern float g_fNavAidRadarRingsStep;
148 extern int g_pNavAidRadarRingsStepUnits;
149 extern int g_iWaypointRangeRingsNumber;
150 extern float g_fWaypointRangeRingsStep;
151 extern int g_iWaypointRangeRingsStepUnits;
152 extern wxColour g_colourWaypointRangeRingsColour;
153 extern bool g_bWayPointPreventDragging;
154 extern bool g_bConfirmObjectDelete;
155 extern wxColour g_colourOwnshipRangeRingsColour;
156 
157 extern bool g_bEnableZoomToCursor;
158 extern wxString g_toolbarConfig;
159 extern double g_TrackIntervalSeconds;
160 extern double g_TrackDeltaDistance;
161 
162 extern bool g_bGDAL_Debug;
163 extern bool g_bDebugCM93;
164 extern bool g_bDebugS57;
165 
166 extern double g_ownship_predictor_minutes;
167 extern double g_ownship_HDTpredictor_miles;
168 
169 extern bool g_own_ship_sog_cog_calc;
170 extern int g_own_ship_sog_cog_calc_damp_sec;
171 
172 extern s52plib *ps52plib;
173 
174 extern int g_cm93_zoom_factor;
175 extern bool g_b_legacy_input_filter_behaviour;
176 extern bool g_bShowDetailSlider;
177 extern int g_detailslider_dialog_x, g_detailslider_dialog_y;
178 
179 extern int g_OwnShipIconType;
180 extern double g_n_ownship_length_meters;
181 extern double g_n_ownship_beam_meters;
182 extern double g_n_gps_antenna_offset_y;
183 extern double g_n_gps_antenna_offset_x;
184 extern int g_n_ownship_min_mm;
185 
186 extern bool g_bPreserveScaleOnX;
187 extern bool g_bsimplifiedScalebar;
188 
189 extern bool g_bUseGLL;
190 
191 extern wxString g_locale;
192 extern wxString g_localeOverride;
193 
194 extern bool g_bCourseUp;
195 extern bool g_bLookAhead;
196 extern int g_COGAvgSec;
197 extern bool g_bShowChartBar;
198 
199 extern int g_MemFootMB;
200 
201 extern wxString g_AW1GUID;
202 extern wxString g_AW2GUID;
203 extern int g_BSBImgDebug;
204 
205 extern wxString g_config_version_string;
206 extern wxString g_config_version_string;
207 
208 extern bool g_bDebugGPSD;
209 
210 extern bool g_bfilter_cogsog;
211 extern int g_COGFilterSec;
212 
213 extern int g_navobjbackups;
214 
215 extern bool g_bQuiltEnable;
216 extern bool g_bFullScreenQuilt;
217 extern bool g_bQuiltStart;
218 
219 extern int g_SkewCompUpdatePeriod;
220 
221 extern int g_maintoolbar_x;
222 extern int g_maintoolbar_y;
223 extern long g_maintoolbar_orient;
224 
225 extern int g_lastClientRectx;
226 extern int g_lastClientRecty;
227 extern int g_lastClientRectw;
228 extern int g_lastClientRecth;
229 
230 extern bool g_bHighliteTracks;
231 extern int g_cog_predictor_width;
232 extern int g_ais_cog_predictor_width;
233 
234 extern wxColour g_colourTrackLineColour;
235 extern wxString g_default_wp_icon;
236 
237 extern ChartGroupArray *g_pGroupArray;
238 
239 extern bool g_bDebugOGL;
240 extern wxString g_uploadConnection;
241 
242 extern std::vector<std::string> TideCurrentDataSet;
243 extern wxString g_TCData_Dir;
244 
245 extern bool g_bresponsive;
246 
247 extern bool g_bGLexpert;
248 
249 extern int g_SENC_LOD_pixels;
250 extern ArrayOfMmsiProperties g_MMSI_Props_Array;
251 
252 extern int g_chart_zoom_modifier_raster;
253 extern int g_chart_zoom_modifier_vector;
254 
255 extern bool g_bAdvanceRouteWaypointOnArrivalOnly;
256 extern double g_display_size_mm;
257 extern std::vector<size_t> g_config_display_size_mm;
258 extern bool g_config_display_size_manual;
259 
260 extern bool g_benable_rotate;
261 extern bool g_bEmailCrashReport;
262 
263 extern int g_default_font_size;
264 
265 extern bool g_bAutoHideToolbar;
266 extern int g_nAutoHideToolbar;
267 extern int g_GUIScaleFactor;
268 extern int g_ChartScaleFactor;
269 extern int g_ShipScaleFactor;
270 
271 extern int g_iENCToolbarPosX;
272 extern int g_iENCToolbarPosY;
273 
274 extern bool g_bSpaceDropMark;
275 
276 extern bool g_bShowMenuBar;
277 extern bool g_bShowCompassWin;
278 
279 extern wxString g_uiStyle;
280 extern bool g_useMUI;
281 extern wxString g_gpx_path;
282 
283 extern unsigned int g_canvasConfig;
284 
285 #ifdef ocpnUSE_GL
286 extern ocpnGLOptions g_GLOptions;
287 #endif
288 
289 #if !defined(NAN)
290 static const long long lNaN = 0xfff8000000000000;
291 #define NAN (*(double *)&lNaN)
292 #endif
293 
294 ConfigMgr *ConfigMgr::instance = NULL;
295 
296 //--------------------------------------------------------------------------
297 //
298 // Utility functions
299 //
300 //--------------------------------------------------------------------------
301 int GetRandomNumber(int range_min, int range_max) {
302  long u = (long)wxRound(
303  ((double)rand() / ((double)(RAND_MAX) + 1) * (range_max - range_min)) +
304  range_min);
305  return (int)u;
306 }
307 
308 // Helper conditional file name dir slash
309 void appendOSDirSlash(wxString *pString);
310 
312 public:
314  ~OCPNConfigObject();
315 
316  OCPNConfigObject(int canvas_config);
317 
318  void Init();
319  wxPanel *GetSettingsPanel();
320 
321  int m_canvasConfig;
322  wxString m_GUID;
323  wxString templateFileName;
324  wxString m_title;
325  wxString m_description;
326 };
327 
328 OCPNConfigObject::OCPNConfigObject() { Init(); }
329 
330 OCPNConfigObject::OCPNConfigObject(int canvas_config) {
331  Init();
332  m_canvasConfig = canvas_config;
333 }
334 
335 OCPNConfigObject::~OCPNConfigObject() {}
336 
337 void OCPNConfigObject::Init() { m_canvasConfig = 0; }
338 
339 #include <wx/listimpl.cpp>
340 WX_DEFINE_LIST(ConfigObjectList);
341 
342 //--------------------------------------------------------------------
343 // Private ( XML encoded ) catalog of available configurations
344 //--------------------------------------------------------------------
345 
346 class OCPNConfigCatalog : public pugi::xml_document {
347 public:
350 
351  bool AddConfig(OCPNConfigObject *config, unsigned int flags);
352  bool RemoveConfig(wxString GUID);
353 
354  void SetRootConfigNode(void);
355  bool IsOpenCPN();
356  bool SaveFile(const wxString filename);
357  bool LoadFile(const wxString filename);
358 
359  pugi::xml_node m_config_root;
360 };
361 
362 OCPNConfigCatalog::OCPNConfigCatalog() : pugi::xml_document() {}
363 
364 OCPNConfigCatalog::~OCPNConfigCatalog() {}
365 
366 void OCPNConfigCatalog::SetRootConfigNode(void) {
367  if (!strlen(m_config_root.name())) {
368  m_config_root = append_child("configs");
369  m_config_root.append_attribute("version") = "1.0";
370  m_config_root.append_attribute("creator") = "OpenCPN";
371  m_config_root.append_attribute("xmlns:xsi") =
372  "http://www.w3.org/2001/XMLSchema-instance";
373  m_config_root.append_attribute("xmlns") =
374  "http://www.topografix.com/GPX/1/1";
375  m_config_root.append_attribute("xmlns:gpxx") =
376  "http://www.garmin.com/xmlschemas/GpxExtensions/v3";
377  m_config_root.append_attribute("xsi:schemaLocation") =
378  "http://www.topografix.com/GPX/1/1 "
379  "http://www.topografix.com/GPX/1/1/gpx.xsd";
380  m_config_root.append_attribute("xmlns:opencpn") = "http://www.opencpn.org";
381  }
382 }
383 
384 bool OCPNConfigCatalog::IsOpenCPN() {
385  for (pugi::xml_attribute attr = root().first_child().first_attribute(); attr;
386  attr = attr.next_attribute())
387  if (!strcmp(attr.name(), "creator") && !strcmp(attr.value(), "OpenCPN"))
388  return true;
389  return false;
390 }
391 
392 bool OCPNConfigCatalog::SaveFile(const wxString filename) {
393  save_file(filename.fn_str(), " ");
394  return true;
395 }
396 
397 bool OCPNConfigCatalog::LoadFile(const wxString filename) {
398  load_file(filename.fn_str());
399  m_config_root = this->child("configs");
400  return true;
401 }
402 
403 bool OCPNConfigCatalog::AddConfig(OCPNConfigObject *config,
404  unsigned int flags) {
405  pugi::xml_node node = m_config_root.append_child("config");
406 
407  node.append_attribute("GUID") = config->m_GUID.mb_str();
408 
409  // Handle non-ASCII characters as UTF8
410  wxCharBuffer abuf = config->m_title.ToUTF8();
411  if (abuf.data())
412  node.append_attribute("title") = abuf.data();
413  else
414  node.append_attribute("title") = _T("Substitute Title");
415 
416  abuf = config->m_description.ToUTF8();
417  if (abuf.data())
418  node.append_attribute("description") = abuf.data();
419  else
420  node.append_attribute("description") = _T("Substitute Description");
421 
422  node.append_attribute("templateFile") = config->templateFileName.mb_str();
423 
424  return true;
425 }
426 
427 bool OCPNConfigCatalog::RemoveConfig(wxString GUID) {
428  for (pugi::xml_node child = m_config_root.first_child(); child;) {
429  pugi::xml_node next = child.next_sibling();
430  const char *guid = child.attribute("GUID").value();
431 
432  if (!strcmp(guid, GUID.mb_str())) {
433  child.parent().remove_child(child);
434  return true;
435  }
436 
437  child = next;
438  }
439 
440  return false;
441 }
442 
443 //--------------------------------------------------------------------
444 // ConfigPanel implementation
445 //--------------------------------------------------------------------
446 
447 ConfigPanel::ConfigPanel(OCPNConfigObject *config, wxWindow *parent,
448  wxWindowID id, const wxPoint &pos, const wxSize &size)
449  : wxPanel(parent, id, pos, size, wxSIMPLE_BORDER)
450 
451 {
452  m_config = config;
453  wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
454  SetSizer(mainSizer);
455 
456  mainSizer->Add(new wxStaticText(this, wxID_ANY, _("Title")));
457  mainSizer->Add(new wxStaticText(this, wxID_ANY, config->m_title));
458 
459  mainSizer->Add(new wxStaticLine(this, wxID_ANY), 0, wxEXPAND | wxALL, 1);
460 
461  mainSizer->Add(new wxStaticText(this, wxID_ANY, _("Description")));
462  mainSizer->Add(new wxStaticText(this, wxID_ANY, config->m_description));
463 
464  SetMinSize(wxSize(-1, 6 * GetCharHeight()));
465 
466  SetBackgroundColour(wxSystemSettings::GetColour(wxSystemColour::wxSYS_COLOUR_WINDOW));
467  // Connect(wxEVT_LEFT_DOWN,
468  // wxMouseEventHandler(ConfigPanel::OnConfigPanelMouseSelected), NULL, this);
469 }
470 
471 ConfigPanel::~ConfigPanel() {}
472 
473 void ConfigPanel::OnConfigPanelMouseSelected(wxMouseEvent &event) {
474  // SetBackgroundColour(*wxRED);
475  // event.Skip();
476 }
477 
478 wxString ConfigPanel::GetConfigGUID() { return m_config->m_GUID; }
479 
480 //--------------------------------------------------------------------
481 // ConfigMgr implementation
482 // Singleton Pattern
483 //--------------------------------------------------------------------
484 
485 ConfigMgr &ConfigMgr::Get() {
486  if (!instance) instance = new ConfigMgr;
487  return *instance;
488 }
489 
490 void ConfigMgr::Shutdown() {
491  if (instance) {
492  delete instance;
493  instance = NULL;
494  }
495 }
496 
497 ConfigMgr::ConfigMgr() {
498  Init();
499 
500  // Load any existing configs from the catalog
501  LoadCatalog();
502 }
503 
504 ConfigMgr::~ConfigMgr() { configList->Clear(); delete configList; }
505 
506 void ConfigMgr::Init() {
507  m_configDir = g_Platform->GetPrivateDataDir();
508  appendOSDirSlash(&m_configDir);
509  m_configDir.append(_T("Configs"));
510  appendOSDirSlash(&m_configDir);
511  if (!wxFileName::DirExists(m_configDir)) {
512  wxFileName::Mkdir(m_configDir);
513  }
514 
515  m_configCatalogName = g_Platform->GetPrivateDataDir();
516  appendOSDirSlash(&m_configCatalogName);
517  m_configCatalogName.append(_T("Configs"));
518  appendOSDirSlash(&m_configCatalogName);
519  m_configCatalogName.append(_T("configs.xml"));
520 
521  // Create the catalog, if necessary
522  if (!wxFileExists(m_configCatalogName)) {
523  wxLogMessage(_T("Creating new Configs catalog: ") + m_configCatalogName);
524 
526  cat->SetRootConfigNode();
527  cat->SaveFile(m_configCatalogName);
528  delete cat;
529  }
530 
531  m_configCatalog = new OCPNConfigCatalog();
532 
533  configList = new ConfigObjectList;
534 
535  // Add the default "Recovery" template
536  wxString t_title = _("Recovery Template");
537  wxString t_desc =
538  _("Apply this template to return to a known safe configuration");
539  CreateNamedConfig(t_title, t_desc,
540  _T("11111111-1111-1111-1111-111111111111"));
541 }
542 
543 bool ConfigMgr::LoadCatalog() {
544  wxLogMessage(_T("Loading Configs catalog: ") + m_configCatalogName);
545  m_configCatalog->LoadFile(m_configCatalogName);
546 
547  // Parse the config catalog
548  pugi::xml_node objects = m_configCatalog->child("configs");
549 
550  // pugi::xml_node node = m_config_root.append_child("config");
551 
552  // node.append_attribute("GUID") = config->m_GUID.mb_str();
553  // node.append_attribute("title") = config->m_title.mb_str();
554  // node.append_attribute("description") = config->m_description.mb_str();
555  // node.append_attribute("templateFile") = config->templateFileName.mb_str();
556 
557  for (pugi::xml_node object = objects.first_child(); object;
558  object = object.next_sibling()) {
559  if (!strcmp(object.name(), "config")) {
560  // Check the GUID for duplicates
561  wxString testGUID =
562  wxString::FromUTF8(object.attribute("GUID").as_string());
563 
564  bool bFound = false;
565  for (ConfigObjectList::Node *node = configList->GetFirst(); node;
566  node = node->GetNext()) {
567  OCPNConfigObject *look = node->GetData();
568  if (look->m_GUID == testGUID) {
569  bFound = true;
570  break;
571  }
572  }
573 
574  if (!bFound) {
575  OCPNConfigObject *newConfig = new OCPNConfigObject;
576 
577  newConfig->m_GUID =
578  wxString::FromUTF8(object.attribute("GUID").as_string());
579  newConfig->m_title =
580  wxString::FromUTF8(object.attribute("title").as_string());
581  newConfig->m_description =
582  wxString::FromUTF8(object.attribute("description").as_string());
583  newConfig->templateFileName =
584  wxString::FromUTF8(object.attribute("templateFile").as_string());
585 
586  // Add to the class list of configs
587  configList->Append(newConfig);
588  }
589  }
590  }
591 
592  return true;
593 }
594 
595 bool ConfigMgr::SaveCatalog() {
596  m_configCatalog->SaveFile(m_configCatalogName);
597 
598  return true;
599 }
600 
601 wxString ConfigMgr::CreateNamedConfig(const wxString &title,
602  const wxString &description,
603  wxString UUID) {
604  wxString GUID;
605 
606  // Must have title
607  if (title.IsEmpty()) return GUID;
608 
609  OCPNConfigObject *pConfig = new OCPNConfigObject;
610 
611  // If no UUID is passed, then create a new GUID for this config
612  if (UUID.IsEmpty())
613  GUID = GetUUID();
614  else
615  GUID = UUID;
616 
617  pConfig->m_GUID = GUID;
618  pConfig->m_title = title;
619  pConfig->m_description = description;
620 
621  if (UUID.IsEmpty()) {
622  // create template file name
623  pConfig->templateFileName = _T("OCPNTemplate-") + GUID + _T(".conf");
624 
625  // Save the template contents
626  wxString templateFullFileName = GetConfigDir() + pConfig->templateFileName;
627  if (!SaveTemplate(templateFullFileName)) {
628  wxLogMessage(_T("Unable to save template titled: ") + title +
629  _T(" as file: ") + templateFullFileName);
630  delete pConfig;
631  return _T("");
632  }
633  }
634 
635  // Add this config to the catalog
636  if (!m_configCatalog->AddConfig(pConfig, 0)) {
637  wxLogMessage(_T("Unable to add config to catalog...Title: ") + title);
638  delete pConfig;
639  return _T("");
640  }
641 
642  // Add to the class list of configs
643  configList->Append(pConfig);
644 
645  if (UUID.IsEmpty()) SaveCatalog();
646 
647  return GUID;
648 }
649 
650 bool ConfigMgr::DeleteConfig(wxString GUID) {
651  OCPNConfigObject *cfg = GetConfig(GUID);
652  if (!cfg) return false;
653 
654  // Find and delete the template file
655  wxString templateFullFileName = GetConfigDir() + cfg->templateFileName;
656  if (wxFileExists(templateFullFileName)) wxRemoveFile(templateFullFileName);
657 
658  // Remove the config from the catalog
659  bool rv = m_configCatalog->RemoveConfig(GUID);
660 
661  if (rv) SaveCatalog();
662 
663  // Remove the config from the member list
664  bool bDel = configList->DeleteObject(cfg);
665  if (bDel) delete cfg;
666 
667  return rv;
668 }
669 
670 wxPanel *ConfigMgr::GetConfigPanel(wxWindow *parent, wxString GUID) {
671  wxPanel *retPanel = NULL;
672 
673  // Find the GUID-matching config in the member list
674  OCPNConfigObject *config = GetConfig(GUID);
675 
676  // Found it?
677  if (config) {
678  retPanel = new ConfigPanel(config, parent);
679  }
680 
681  return retPanel;
682 }
683 
684 OCPNConfigObject *ConfigMgr::GetConfig(wxString GUID) {
685  // Find the GUID-matching config in the member list
686  for (ConfigObjectList::Node *node = configList->GetFirst(); node;
687  node = node->GetNext()) {
688  OCPNConfigObject *look = node->GetData();
689  if (look->m_GUID == GUID) {
690  return look;
691  break;
692  }
693  }
694 
695  return NULL;
696 }
697 
698 wxString ConfigMgr::GetTemplateTitle(wxString GUID) {
699  for (ConfigObjectList::Node *node = configList->GetFirst(); node;
700  node = node->GetNext()) {
701  OCPNConfigObject *look = node->GetData();
702  if (look->m_GUID == GUID) {
703  return look->m_title;
704  break;
705  }
706  }
707 
708  return wxEmptyString;
709 }
710 
711 wxArrayString ConfigMgr::GetConfigGUIDArray() {
712  wxArrayString ret_val;
713 
714  for (ConfigObjectList::Node *node = configList->GetFirst(); node;
715  node = node->GetNext()) {
716  OCPNConfigObject *look = node->GetData();
717  ret_val.Add(look->m_GUID);
718  }
719 
720  return ret_val;
721 }
722 
723 bool ConfigMgr::ApplyConfigGUID(wxString GUID) {
724  // Find the GUID-matching config in the member list
725  OCPNConfigObject *config = GetConfig(GUID);
726 
727  // Found it?
728  if (config) {
729  wxString thisConfig = GetConfigDir() + config->templateFileName;
730 
731  // Special case for Recovery template
732  if (GUID.StartsWith(_T("11111111"))) {
733  thisConfig =
734  *GetpSharedDataLocation() + _T("configs/OCPNTemplate-Recovery.conf");
735  }
736 
737  MyConfig fconf(thisConfig);
738 
739  // Load the template contents, without resetting defaults
740  fconf.LoadMyConfigRaw(true);
741 
742  // Load Canvas configs, applying only the "templateable" items
743  fconf.LoadCanvasConfigs(true);
744 
745  if (ps52plib && ps52plib->m_bOK) fconf.LoadS57Config();
746 
747  return true;
748  }
749 
750  return false;
751 }
752 
753 // RFC4122 version 4 compliant random UUIDs generator.
754 wxString ConfigMgr::GetUUID(void) {
755  wxString str;
756  struct {
757  int time_low;
758  int time_mid;
759  int time_hi_and_version;
760  int clock_seq_hi_and_rsv;
761  int clock_seq_low;
762  int node_hi;
763  int node_low;
764  } uuid;
765 
766  uuid.time_low = GetRandomNumber(
767  0, 2147483647); // FIXME: the max should be set to something like
768  // MAXINT32, but it doesn't compile un gcc...
769  uuid.time_mid = GetRandomNumber(0, 65535);
770  uuid.time_hi_and_version = GetRandomNumber(0, 65535);
771  uuid.clock_seq_hi_and_rsv = GetRandomNumber(0, 255);
772  uuid.clock_seq_low = GetRandomNumber(0, 255);
773  uuid.node_hi = GetRandomNumber(0, 65535);
774  uuid.node_low = GetRandomNumber(0, 2147483647);
775 
776  /* Set the two most significant bits (bits 6 and 7) of the
777  * clock_seq_hi_and_rsv to zero and one, respectively. */
778  uuid.clock_seq_hi_and_rsv = (uuid.clock_seq_hi_and_rsv & 0x3F) | 0x80;
779 
780  /* Set the four most significant bits (bits 12 through 15) of the
781  * time_hi_and_version field to 4 */
782  uuid.time_hi_and_version = (uuid.time_hi_and_version & 0x0fff) | 0x4000;
783 
784  str.Printf(_T("%08x-%04x-%04x-%02x%02x-%04x%08x"), uuid.time_low,
785  uuid.time_mid, uuid.time_hi_and_version, uuid.clock_seq_hi_and_rsv,
786  uuid.clock_seq_low, uuid.node_hi, uuid.node_low);
787 
788  return str;
789 }
790 
791 bool ConfigMgr::SaveTemplate(wxString fileName) {
792  // Assuming the file exists, and is empty....
793 
794  // Create a private wxFileConfig object
795  MyConfig *conf = new MyConfig(fileName);
796 
797 // Write out all the elements of a config template....
798 
799 // Temporarily suppress logging of trivial non-fatal wxLogSysError() messages
800 // provoked by Android security...
801 #ifdef __ANDROID__
802  wxLogNull logNo;
803 #endif
804 
805  // Global options and settings
806  conf->SetPath(_T ( "/Settings" ));
807 
808  conf->Write(_T ( "InlandEcdis" ), g_bInlandEcdis);
809  conf->Write(_T ( "UIexpert" ), g_bUIexpert);
810  conf->Write(_T ( "SpaceDropMark" ), g_bSpaceDropMark);
811 
812  conf->Write(_T ( "ShowStatusBar" ), g_bShowStatusBar);
813 #ifndef __WXOSX__
814  conf->Write(_T ( "ShowMenuBar" ), g_bShowMenuBar);
815 #endif
816  conf->Write(_T ( "DefaultFontSize" ), g_default_font_size);
817 
818  conf->Write(_T ( "Fullscreen" ), g_bFullscreen);
819  conf->Write(_T ( "ShowCompassWindow" ), g_bShowCompassWin);
820  conf->Write(_T ( "SetSystemTime" ), s_bSetSystemTime);
821  conf->Write(_T ( "ShowGrid" ), g_bDisplayGrid);
822  conf->Write(_T ( "PlayShipsBells" ), g_bPlayShipsBells);
823  conf->Write(_T ( "SoundDeviceIndex" ), g_iSoundDeviceIndex);
824  conf->Write(_T ( "FullscreenToolbar" ), g_bFullscreenToolbar);
825  // conf->Write( _T ( "TransparentToolbar" ), g_bTransparentToolbar );
826  conf->Write(_T ( "PermanentMOBIcon" ), g_bPermanentMOBIcon);
827  conf->Write(_T ( "ShowLayers" ), g_bShowLayers);
828  conf->Write(_T ( "AutoAnchorDrop" ), g_bAutoAnchorMark);
829  conf->Write(_T ( "ShowChartOutlines" ), g_bShowOutlines);
830  conf->Write(_T ( "ShowActiveRouteTotal" ), g_bShowRouteTotal);
831  conf->Write(_T ( "ShowActiveRouteHighway" ), g_bShowActiveRouteHighway);
832  conf->Write(_T ( "SDMMFormat" ), g_iSDMMFormat);
833  conf->Write(_T ( "ShowChartBar" ), g_bShowChartBar);
834 
835  conf->Write(_T ( "GUIScaleFactor" ), g_GUIScaleFactor);
836  conf->Write(_T ( "ChartObjectScaleFactor" ), g_ChartScaleFactor);
837  conf->Write(_T ( "ShipScaleFactor" ), g_ShipScaleFactor);
838 
839  conf->Write(_T ( "ShowTrue" ), g_bShowTrue);
840  conf->Write(_T ( "ShowMag" ), g_bShowMag);
841  conf->Write(_T ( "UserMagVariation" ),
842  wxString::Format(_T("%.2f"), g_UserVar));
843 
844  conf->Write(_T ( "CM93DetailFactor" ), g_cm93_zoom_factor);
845  conf->Write(_T ( "CM93DetailZoomPosX" ), g_detailslider_dialog_x);
846  conf->Write(_T ( "CM93DetailZoomPosY" ), g_detailslider_dialog_y);
847  conf->Write(_T ( "ShowCM93DetailSlider" ), g_bShowDetailSlider);
848 
849  conf->Write(_T ( "SkewToNorthUp" ), g_bskew_comp);
850 
851  conf->Write(_T ( "ZoomDetailFactor" ), g_chart_zoom_modifier_raster);
852  conf->Write(_T ( "ZoomDetailFactorVector" ), g_chart_zoom_modifier_vector);
853 
854  conf->Write(_T ( "SmoothPanZoom" ), g_bsmoothpanzoom);
855 
856  conf->Write(_T ( "CourseUpMode" ), g_bCourseUp);
857  if (!g_bInlandEcdis) conf->Write(_T ( "LookAheadMode" ), g_bLookAhead);
858  conf->Write(_T ( "COGUPAvgSeconds" ), g_COGAvgSec);
859  conf->Write(_T ( "UseMagAPB" ), g_bMagneticAPB);
860 
861  conf->Write(_T ( "OwnshipCOGPredictorMinutes" ), g_ownship_predictor_minutes);
862  conf->Write(_T ( "OwnshipCOGPredictorWidth" ), g_cog_predictor_width);
863  conf->Write(_T ( "OwnshipHDTPredictorMiles" ), g_ownship_HDTpredictor_miles);
864  conf->Write(_T ( "OwnShipIconType" ), g_OwnShipIconType);
865  conf->Write(_T ( "OwnShipLength" ), g_n_ownship_length_meters);
866  conf->Write(_T ( "OwnShipWidth" ), g_n_ownship_beam_meters);
867  conf->Write(_T ( "OwnShipGPSOffsetX" ), g_n_gps_antenna_offset_x);
868  conf->Write(_T ( "OwnShipGPSOffsetY" ), g_n_gps_antenna_offset_y);
869  conf->Write(_T ( "OwnShipMinSize" ), g_n_ownship_min_mm);
870  conf->Write(_T ( "OwnShipSogCogCalc" ), g_own_ship_sog_cog_calc);
871  conf->Write(_T ( "OwnShipSogCogCalcDampSec"),
872  g_own_ship_sog_cog_calc_damp_sec);
873 
874  conf->Write(_T ( "RouteArrivalCircleRadius" ),
875  wxString::Format(_T("%.3f"), g_n_arrival_circle_radius));
876  conf->Write(_T ( "ChartQuilting" ), g_bQuiltEnable);
877 
878  conf->Write(_T ( "StartWithTrackActive" ), g_bTrackCarryOver);
879  conf->Write(_T ( "AutomaticDailyTracks" ), g_bTrackDaily);
880  conf->Write(_T ( "TrackRotateAt" ), g_track_rotate_time);
881  conf->Write(_T ( "TrackRotateTimeType" ), g_track_rotate_time_type);
882  conf->Write(_T ( "HighlightTracks" ), g_bHighliteTracks);
883 
884  conf->Write(_T ( "InitialStackIndex" ), g_restore_stackindex);
885  conf->Write(_T ( "InitialdBIndex" ), g_restore_dbindex);
886 
887  conf->Write(_T ( "AnchorWatch1GUID" ), g_AW1GUID);
888  conf->Write(_T ( "AnchorWatch2GUID" ), g_AW2GUID);
889 
890  conf->Write(_T ( "ToolbarX" ), g_maintoolbar_x);
891  conf->Write(_T ( "ToolbarY" ), g_maintoolbar_y);
892  conf->Write(_T ( "ToolbarOrient" ), g_maintoolbar_orient);
893 
894  conf->Write(_T ( "iENCToolbarX" ), g_iENCToolbarPosX);
895  conf->Write(_T ( "iENCToolbarY" ), g_iENCToolbarPosY);
896 
897  if (!g_bInlandEcdis) {
898  conf->Write(_T ( "GlobalToolbarConfig" ), g_toolbarConfig);
899  conf->Write(_T ( "DistanceFormat" ), g_iDistanceFormat);
900  conf->Write(_T ( "SpeedFormat" ), g_iSpeedFormat);
901  conf->Write(_T ( "WindSpeedFormat" ), g_iWindSpeedFormat);
902  conf->Write(_T ( "ShowDepthUnits" ), g_bShowDepthUnits);
903  }
904 
905  conf->Write(_T ( "MobileTouch" ), g_btouch);
906  conf->Write(_T ( "ResponsiveGraphics" ), g_bresponsive);
907 
908  conf->Write(_T ( "AutoHideToolbar" ), g_bAutoHideToolbar);
909  conf->Write(_T ( "AutoHideToolbarSecs" ), g_nAutoHideToolbar);
910 
911  wxString st0;
912  for (const auto &mm : g_config_display_size_mm) {
913  st0.Append(wxString::Format(_T ( "%zu," ), mm));
914  }
915  st0.RemoveLast(); //Strip last comma
916  conf->Write(_T ( "DisplaySizeMM" ), st0);
917  conf->Write(_T ( "DisplaySizeManual" ), g_config_display_size_manual);
918 
919  conf->Write(_T ( "PlanSpeed" ), wxString::Format(_T("%.2f"), g_PlanSpeed));
920 
921 #if 0
922  wxString vis, invis;
923  LayerList::iterator it;
924  int index = 0;
925  for( it = ( *pLayerList ).begin(); it != ( *pLayerList ).end(); ++it, ++index ) {
926  Layer *lay = (Layer *) ( *it );
927  if( lay->IsVisibleOnChart() ) vis += ( lay->m_LayerName ) + _T(";");
928  else
929  invis += ( lay->m_LayerName ) + _T(";");
930  }
931  conf->Write( _T ( "VisibleLayers" ), vis );
932  conf->Write( _T ( "InvisibleLayers" ), invis );
933 #endif
934 
935  conf->Write(_T ( "Locale" ), g_locale);
936  conf->Write(_T ( "LocaleOverride" ), g_localeOverride);
937 
938  // LIVE ETA OPTION
939  conf->Write(_T( "LiveETA" ), g_bShowLiveETA);
940  conf->Write(_T( "DefaultBoatSpeed" ), g_defaultBoatSpeed);
941 
942  // S57 Object Filter Settings
943  conf->SetPath(_T ( "/Settings/ObjectFilter" ));
944 
945  if (ps52plib) {
946  for (unsigned int iPtr = 0; iPtr < ps52plib->pOBJLArray->GetCount();
947  iPtr++) {
948  OBJLElement *pOLE = (OBJLElement *)(ps52plib->pOBJLArray->Item(iPtr));
949 
950  wxString st1(_T ( "viz" ));
951  char name[7];
952  strncpy(name, pOLE->OBJLName, 6);
953  name[6] = 0;
954  st1.Append(wxString(name, wxConvUTF8));
955  conf->Write(st1, pOLE->nViz);
956  }
957  }
958 
959  // Global State
960 
961  conf->SetPath(_T ( "/Settings/GlobalState" ));
962 
963  // Various Options
964  if (!g_bInlandEcdis)
965  conf->Write(_T ( "nColorScheme" ), (int)gFrame->GetColorScheme());
966 
967  // AIS
968  conf->SetPath(_T ( "/Settings/AIS" ));
969 
970  conf->Write(_T ( "bNoCPAMax" ), g_bCPAMax);
971  conf->Write(_T ( "NoCPAMaxNMi" ), g_CPAMax_NM);
972  conf->Write(_T ( "bCPAWarn" ), g_bCPAWarn);
973  conf->Write(_T ( "CPAWarnNMi" ), g_CPAWarn_NM);
974  conf->Write(_T ( "bTCPAMax" ), g_bTCPA_Max);
975  conf->Write(_T ( "TCPAMaxMinutes" ), g_TCPA_Max);
976  conf->Write(_T ( "bMarkLostTargets" ), g_bMarkLost);
977  conf->Write(_T ( "MarkLost_Minutes" ), g_MarkLost_Mins);
978  conf->Write(_T ( "bRemoveLostTargets" ), g_bRemoveLost);
979  conf->Write(_T ( "RemoveLost_Minutes" ), g_RemoveLost_Mins);
980  conf->Write(_T ( "bShowCOGArrows" ), g_bShowCOG);
981  conf->Write(_T ( "CogArrowMinutes" ), g_ShowCOG_Mins);
982  conf->Write(_T ( "bShowTargetTracks" ), g_bAISShowTracks);
983  conf->Write(_T ( "TargetTracksMinutes" ), g_AISShowTracks_Mins);
984 
985  conf->Write(_T ( "bHideMooredTargets" ), g_bHideMoored);
986  conf->Write(_T ( "MooredTargetMaxSpeedKnots" ), g_ShowMoored_Kts);
987 
988  conf->Write(_T ( "bAISAlertDialog" ), g_bAIS_CPA_Alert);
989  conf->Write(_T ( "bAISAlertAudio" ), g_bAIS_CPA_Alert_Audio);
990  conf->Write(_T ( "AISAlertAudioFile" ), g_sAIS_Alert_Sound_File);
991  conf->Write(_T ( "bAISAlertSuppressMoored" ),
992  g_bAIS_CPA_Alert_Suppress_Moored);
993  conf->Write(_T ( "bShowAreaNotices" ), g_bShowAreaNotices);
994  conf->Write(_T ( "bDrawAISSize" ), g_bDrawAISSize);
995  conf->Write(_T ( "bDrawAISRealtime" ), g_bDrawAISRealtime);
996  conf->Write(_T ( "AISRealtimeMinSpeedKnots" ), g_AIS_RealtPred_Kts);
997  conf->Write(_T ( "bShowAISName" ), g_bShowAISName);
998  conf->Write(_T ( "ShowAISTargetNameScale" ), g_Show_Target_Name_Scale);
999  conf->Write(_T ( "bWplIsAprsPositionReport" ), g_bWplUsePosition);
1000  conf->Write(_T ( "WplSelAction" ), g_WplAction);
1001  conf->Write(_T ( "AISCOGPredictorWidth" ), g_ais_cog_predictor_width);
1002  conf->Write(_T ( "bShowScaledTargets" ), g_bAllowShowScaled);
1003  conf->Write(_T ( "AISScaledNumber" ), g_ShowScaled_Num);
1004  conf->Write(_T ( "AISScaledNumberWeightSOG" ), g_ScaledNumWeightSOG);
1005  conf->Write(_T ( "AISScaledNumberWeightCPA" ), g_ScaledNumWeightCPA);
1006  conf->Write(_T ( "AISScaledNumberWeightTCPA" ), g_ScaledNumWeightTCPA);
1007  conf->Write(_T ( "AISScaledNumberWeightRange" ), g_ScaledNumWeightRange);
1008  conf->Write(_T ( "AISScaledNumberWeightSizeOfTarget" ),
1009  g_ScaledNumWeightSizeOfT);
1010  conf->Write(_T ( "AISScaledSizeMinimal" ), g_ScaledSizeMinimal);
1011  conf->Write(_T ( "AISShowScaled"), g_bShowScaled);
1012 
1013  conf->Write(_T ( "AlertDialogSizeX" ), g_ais_alert_dialog_sx);
1014  conf->Write(_T ( "AlertDialogSizeY" ), g_ais_alert_dialog_sy);
1015  conf->Write(_T ( "AlertDialogPosX" ), g_ais_alert_dialog_x);
1016  conf->Write(_T ( "AlertDialogPosY" ), g_ais_alert_dialog_y);
1017  conf->Write(_T ( "QueryDialogPosX" ), g_ais_query_dialog_x);
1018  conf->Write(_T ( "QueryDialogPosY" ), g_ais_query_dialog_y);
1019  conf->Write(_T ( "AISTargetListPerspective" ), g_AisTargetList_perspective);
1020  conf->Write(_T ( "AISTargetListRange" ), g_AisTargetList_range);
1021  conf->Write(_T ( "AISTargetListSortColumn" ), g_AisTargetList_sortColumn);
1022  conf->Write(_T ( "bAISTargetListSortReverse" ), g_bAisTargetList_sortReverse);
1023  conf->Write(_T ( "AISTargetListColumnSpec" ), g_AisTargetList_column_spec);
1024  conf->Write(_T ( "AISTargetListColumnOrder" ), g_AisTargetList_column_order);
1025  conf->Write(_T ( "S57QueryDialogSizeX" ), g_S57_dialog_sx);
1026  conf->Write(_T ( "S57QueryDialogSizeY" ), g_S57_dialog_sy);
1027  conf->Write(_T ( "bAISRolloverShowClass" ), g_bAISRolloverShowClass);
1028  conf->Write(_T ( "bAISRolloverShowCOG" ), g_bAISRolloverShowCOG);
1029  conf->Write(_T ( "bAISRolloverShowCPA" ), g_bAISRolloverShowCPA);
1030  conf->Write(_T ( "bAISAlertAckTimeout" ), g_bAIS_ACK_Timeout);
1031  conf->Write(_T ( "AlertAckTimeoutMinutes" ), g_AckTimeout_Mins);
1032 
1033  conf->SetPath(_T ( "/Settings/GlobalState" ));
1034  if (ps52plib) {
1035  conf->Write(_T ( "bShowS57Text" ), ps52plib->GetShowS57Text());
1036  conf->Write(_T ( "bShowS57ImportantTextOnly" ),
1037  ps52plib->GetShowS57ImportantTextOnly());
1038  if (!g_bInlandEcdis)
1039  conf->Write(_T ( "nDisplayCategory" ),
1040  (long)ps52plib->GetDisplayCategory());
1041  conf->Write(_T ( "nSymbolStyle" ), (int)ps52plib->m_nSymbolStyle);
1042  conf->Write(_T ( "nBoundaryStyle" ), (int)ps52plib->m_nBoundaryStyle);
1043 
1044  conf->Write(_T ( "bShowSoundg" ), ps52plib->m_bShowSoundg);
1045  conf->Write(_T ( "bShowMeta" ), ps52plib->m_bShowMeta);
1046  conf->Write(_T ( "bUseSCAMIN" ), ps52plib->m_bUseSCAMIN);
1047  conf->Write(_T ( "bUseSUPER_SCAMIN" ), ps52plib->m_bUseSUPER_SCAMIN);
1048  conf->Write(_T ( "bShowAtonText" ), ps52plib->m_bShowAtonText);
1049  conf->Write(_T ( "bShowLightDescription" ), ps52plib->m_bShowLdisText);
1050  conf->Write(_T ( "bExtendLightSectors" ), ps52plib->m_bExtendLightSectors);
1051  conf->Write(_T ( "bDeClutterText" ), ps52plib->m_bDeClutterText);
1052  conf->Write(_T ( "bShowNationalText" ), ps52plib->m_bShowNationalTexts);
1053 
1054  conf->Write(_T ( "S52_MAR_SAFETY_CONTOUR" ),
1055  S52_getMarinerParam(S52_MAR_SAFETY_CONTOUR));
1056  conf->Write(_T ( "S52_MAR_SHALLOW_CONTOUR" ),
1057  S52_getMarinerParam(S52_MAR_SHALLOW_CONTOUR));
1058  conf->Write(_T ( "S52_MAR_DEEP_CONTOUR" ),
1059  S52_getMarinerParam(S52_MAR_DEEP_CONTOUR));
1060  conf->Write(_T ( "S52_MAR_TWO_SHADES" ),
1061  S52_getMarinerParam(S52_MAR_TWO_SHADES));
1062  conf->Write(_T ( "S52_DEPTH_UNIT_SHOW" ), ps52plib->m_nDepthUnitDisplay);
1063  }
1064 
1065  conf->SetPath(_T ( "/Settings/Others" ));
1066 
1067  // Radar rings
1068  conf->Write(_T ( "ShowRadarRings" ), (bool)(g_iNavAidRadarRingsNumberVisible >
1069  0)); // 3.0.0 config support
1070  conf->Write(_T ( "RadarRingsNumberVisible" ),
1071  g_iNavAidRadarRingsNumberVisible);
1072  g_bNavAidRadarRingsShown = g_iNavAidRadarRingsNumberVisible > 0;
1073  conf->Write(_T ( "RadarRingsStep" ), g_fNavAidRadarRingsStep);
1074  conf->Write(_T ( "RadarRingsStepUnits" ), g_pNavAidRadarRingsStepUnits);
1075  conf->Write(_T ( "RadarRingsColour" ),
1076  g_colourOwnshipRangeRingsColour.GetAsString(wxC2S_HTML_SYNTAX));
1077 
1078  // Waypoint Radar rings
1079  conf->Write(_T ( "WaypointRangeRingsNumber" ), g_iWaypointRangeRingsNumber);
1080  conf->Write(_T ( "WaypointRangeRingsStep" ), g_fWaypointRangeRingsStep);
1081  conf->Write(_T ( "WaypointRangeRingsStepUnits" ),
1082  g_iWaypointRangeRingsStepUnits);
1083  conf->Write(_T ( "WaypointRangeRingsColour" ),
1084  g_colourWaypointRangeRingsColour.GetAsString(wxC2S_HTML_SYNTAX));
1085 
1086  conf->Write(_T ( "ConfirmObjectDeletion" ), g_bConfirmObjectDelete);
1087 
1088  // Waypoint dragging with mouse
1089  conf->Write(_T ( "WaypointPreventDragging" ), g_bWayPointPreventDragging);
1090 
1091  conf->Write(_T ( "EnableZoomToCursor" ), g_bEnableZoomToCursor);
1092 
1093  conf->Write(_T ( "TrackIntervalSeconds" ), g_TrackIntervalSeconds);
1094  conf->Write(_T ( "TrackDeltaDistance" ), g_TrackDeltaDistance);
1095  conf->Write(_T ( "TrackPrecision" ), g_nTrackPrecision);
1096 
1097  conf->Write(_T ( "RouteLineWidth" ), g_route_line_width);
1098  conf->Write(_T ( "TrackLineWidth" ), g_track_line_width);
1099  conf->Write(_T ( "TrackLineColour" ),
1100  g_colourTrackLineColour.GetAsString(wxC2S_HTML_SYNTAX));
1101  conf->Write(_T ( "DefaultWPIcon" ), g_default_wp_icon);
1102 
1103  // Fonts
1104 
1105  // Store the persistent Auxiliary Font descriptor Keys
1106  conf->SetPath(_T ( "/Settings/AuxFontKeys" ));
1107 
1108  wxArrayString keyArray = FontMgr::Get().GetAuxKeyArray();
1109  for (unsigned int i = 0; i < keyArray.GetCount(); i++) {
1110  wxString key;
1111  key.Printf(_T("Key%i"), i);
1112  wxString keyval = keyArray[i];
1113  conf->Write(key, keyval);
1114  }
1115 
1116  wxString font_path;
1117 #ifdef __WXX11__
1118  font_path = (_T ( "/Settings/X11Fonts" ));
1119 #endif
1120 
1121 #ifdef __WXGTK__
1122  font_path = (_T ( "/Settings/GTKFonts" ));
1123 #endif
1124 
1125 #ifdef __WXMSW__
1126  font_path = (_T ( "/Settings/MSWFonts" ));
1127 #endif
1128 
1129 #ifdef __WXMAC__
1130  font_path = (_T ( "/Settings/MacFonts" ));
1131 #endif
1132 
1133 #ifdef __WXQT__
1134  font_path = (_T ( "/Settings/QTFonts" ));
1135 #endif
1136 
1137  conf->DeleteGroup(font_path);
1138 
1139  conf->SetPath(font_path);
1140 
1141  int nFonts = FontMgr::Get().GetNumFonts();
1142 
1143  for (int i = 0; i < nFonts; i++) {
1144  wxString cfstring(FontMgr::Get().GetConfigString(i));
1145  wxString valstring = FontMgr::Get().GetFullConfigDesc(i);
1146  conf->Write(cfstring, valstring);
1147  }
1148 
1149  // Save the per-canvas config options
1150  conf->SaveCanvasConfigs();
1151 
1152  conf->Flush();
1153 
1154  delete conf;
1155 
1156  return true;
1157 }
1158 
1159 bool ConfigMgr::CheckTemplateGUID(wxString GUID) {
1160  bool rv = false;
1161 
1162  OCPNConfigObject *config = GetConfig(GUID);
1163  if (config) {
1164  rv = CheckTemplate(GetConfigDir() + config->templateFileName);
1165  }
1166 
1167  return rv;
1168 }
1169 
1170 #define CHECK_INT(s, t) \
1171  read_int = *t; \
1172  if (!conf.Read(s, &read_int)) wxLogMessage(s); \
1173  if ((int)*t != read_int) return false;
1174 
1175 #define CHECK_STR(s, t) \
1176  val = t; \
1177  conf.Read(s, &val); \
1178  if (!t.IsSameAs(val)) return false;
1179 
1180 #define CHECK_STRP(s, t) \
1181  conf.Read(s, &val); \
1182  if (!t->IsSameAs(val)) return false;
1183 
1184 #define CHECK_FLT(s, t, eps) \
1185  conf.Read(s, &val); \
1186  val.ToDouble(&dval); \
1187  if (fabs(dval - *t) > eps) return false;
1188 
1189 bool ConfigMgr::CheckTemplate(wxString fileName) {
1190  bool rv = true;
1191 
1192  int read_int;
1193  wxString val;
1194  double dval;
1195 
1196  MyConfig conf(fileName);
1197 
1198  // Global options and settings
1199  conf.SetPath(_T ( "/Settings" ));
1200 
1201  CHECK_INT(_T ( "UIexpert" ), &g_bUIexpert);
1202 
1204 
1205  CHECK_INT(_T ( "InlandEcdis" ), &g_bInlandEcdis);
1206 
1207  CHECK_INT(_T( "SpaceDropMark" ), &g_bSpaceDropMark);
1208 
1210 
1211 #if 0
1212  CHECK_INT( _T ( "DebugGDAL" ), &g_bGDAL_Debug );
1213  CHECK_INT( _T ( "DebugNMEA" ), &g_nNMEADebug );
1214  CHECK_INT( _T ( "DebugOpenGL" ), &g_bDebugOGL );
1218  CHECK_INT( _T ( "DebugCM93" ), &g_bDebugCM93 );
1219  CHECK_INT( _T ( "DebugS57" ), &g_bDebugS57 ); // Show LUP and Feature info in object query
1220  CHECK_INT( _T ( "DebugBSBImg" ), &g_BSBImgDebug );
1221  CHECK_INT( _T ( "DebugGPSD" ), &g_bDebugGPSD );
1222 #endif
1223 
1224  CHECK_INT(_T ( "DefaultFontSize"), &g_default_font_size);
1225 
1226  // Read( _T ( "GPSIdent" ), &g_GPS_Ident );
1227  CHECK_INT(_T ( "UseGarminHostUpload" ), &g_bGarminHostUpload);
1228 
1229  CHECK_INT(_T ( "UseNMEA_GLL" ), &g_bUseGLL);
1230 
1231  CHECK_INT(_T ( "AutoHideToolbar" ), &g_bAutoHideToolbar);
1232  CHECK_INT(_T ( "AutoHideToolbarSecs" ), &g_nAutoHideToolbar);
1233 
1234  CHECK_INT(_T ( "UseSimplifiedScalebar" ), &g_bsimplifiedScalebar);
1235 
1236  CHECK_INT(_T ( "DisplaySizeMM" ), &g_display_size_mm);
1237  CHECK_INT(_T ( "DisplaySizeManual" ), &g_config_display_size_manual);
1238 
1239  CHECK_INT(_T ( "GUIScaleFactor" ), &g_GUIScaleFactor);
1240 
1241  CHECK_INT(_T ( "ChartObjectScaleFactor" ), &g_ChartScaleFactor);
1242  CHECK_INT(_T ( "ShipScaleFactor" ), &g_ShipScaleFactor);
1243 
1244  CHECK_INT(_T ( "FilterNMEA_Avg" ), &g_bfilter_cogsog);
1245  CHECK_INT(_T ( "FilterNMEA_Sec" ), &g_COGFilterSec);
1246 
1247  CHECK_INT(_T ( "ShowTrue" ), &g_bShowTrue);
1248  CHECK_INT(_T ( "ShowMag" ), &g_bShowMag);
1249 
1250  CHECK_FLT(_T ( "UserMagVariation" ), &g_UserVar, 0.1)
1251 
1252  CHECK_INT(_T ( "UseMagAPB" ), &g_bMagneticAPB);
1253 
1254  CHECK_INT(_T ( "ScreenBrightness" ), &g_nbrightness);
1255 
1256  CHECK_INT(_T ( "MemFootprintTargetMB" ), &g_MemFootMB);
1257 
1258  CHECK_INT(_T ( "WindowsComPortMax" ), &g_nCOMPortCheck);
1259 
1260  CHECK_INT(_T ( "ChartQuilting" ), &g_bQuiltEnable);
1261  CHECK_INT(_T ( "ChartQuiltingInitial" ), &g_bQuiltStart);
1262 
1263  CHECK_INT(_T ( "CourseUpMode" ), &g_bCourseUp);
1264  CHECK_INT(_T ( "COGUPAvgSeconds" ), &g_COGAvgSec);
1265  // CHECK_INT( _T ( "LookAheadMode" ), &g_bLookAhead );
1266  // CHECK_INT( _T ( "SkewToNorthUp" ), &g_bskew_comp );
1267  CHECK_INT(_T ( "OpenGL" ), &g_bopengl);
1268  CHECK_INT(_T ( "SoftwareGL" ), &g_bSoftwareGL);
1269 
1270  CHECK_INT(_T( "NMEAAPBPrecision" ), &g_NMEAAPBPrecision);
1271 
1272  CHECK_STR(_T( "TalkerIdText" ), g_TalkerIdText);
1273  CHECK_INT(_T( "MaxWaypointNameLength" ), &g_maxWPNameLength);
1274  CHECK_INT(_T( "MbtilesMaxLayers" ), &g_mbtilesMaxLayers);
1275 
1276  /* opengl options */
1277 #ifdef ocpnUSE_GL
1278  CHECK_INT(_T ( "OpenGLExpert" ), &g_bGLexpert);
1279  CHECK_INT(_T ( "UseAcceleratedPanning" ),
1280  &g_GLOptions.m_bUseAcceleratedPanning);
1281  CHECK_INT(_T ( "GPUTextureCompression" ), &g_GLOptions.m_bTextureCompression);
1282  CHECK_INT(_T ( "GPUTextureCompressionCaching" ),
1283  &g_GLOptions.m_bTextureCompressionCaching);
1284  CHECK_INT(_T ( "PolygonSmoothing" ), &g_GLOptions.m_GLPolygonSmoothing);
1285  CHECK_INT(_T ( "LineSmoothing" ), &g_GLOptions.m_GLLineSmoothing);
1286  CHECK_INT(_T ( "GPUTextureDimension" ), &g_GLOptions.m_iTextureDimension);
1287  CHECK_INT(_T ( "GPUTextureMemSize" ), &g_GLOptions.m_iTextureMemorySize);
1288 
1289 #endif
1290  CHECK_INT(_T ( "SmoothPanZoom" ), &g_bsmoothpanzoom);
1291 
1292  CHECK_INT(_T ( "ToolbarX"), &g_maintoolbar_x);
1293  CHECK_INT(_T ( "ToolbarY" ), &g_maintoolbar_y);
1294  CHECK_INT(_T ( "ToolbarOrient" ), &g_maintoolbar_orient);
1295  CHECK_STR(_T ( "GlobalToolbarConfig" ), g_toolbarConfig);
1296 
1297  CHECK_INT(_T ( "iENCToolbarX"), &g_iENCToolbarPosX);
1298  CHECK_INT(_T ( "iENCToolbarY"), &g_iENCToolbarPosY);
1299 
1300  CHECK_STR(_T ( "AnchorWatch1GUID" ), g_AW1GUID);
1301  CHECK_STR(_T ( "AnchorWatch2GUID" ), g_AW2GUID);
1302 
1303  CHECK_INT(_T ( "MobileTouch" ), &g_btouch);
1304  CHECK_INT(_T ( "ResponsiveGraphics" ), &g_bresponsive);
1305 
1306  CHECK_INT(_T ( "ZoomDetailFactor" ), &g_chart_zoom_modifier_raster);
1307  CHECK_INT(_T ( "ZoomDetailFactorVector" ), &g_chart_zoom_modifier_vector);
1308 
1309  CHECK_INT(_T ( "CM93DetailFactor" ), &g_cm93_zoom_factor);
1310  CHECK_INT(_T ( "CM93DetailZoomPosX" ), &g_detailslider_dialog_x);
1311  CHECK_INT(_T ( "CM93DetailZoomPosY" ), &g_detailslider_dialog_y);
1312  CHECK_INT(_T ( "ShowCM93DetailSlider" ), &g_bShowDetailSlider);
1313 
1314  CHECK_INT(_T ( "SENC_LOD_Pixels" ), &g_SENC_LOD_pixels);
1315 
1316  CHECK_INT(_T ( "SkewCompUpdatePeriod" ), &g_SkewCompUpdatePeriod);
1317 
1318  CHECK_INT(_T ( "ShowStatusBar" ), &g_bShowStatusBar);
1319 #ifndef __WXOSX__
1320  CHECK_INT(_T ( "ShowMenuBar" ), &g_bShowMenuBar);
1321 #endif
1322  CHECK_INT(_T ( "Fullscreen" ), &g_bFullscreen);
1323  CHECK_INT(_T ( "ShowCompassWindow" ), &g_bShowCompassWin);
1324  CHECK_INT(_T ( "PlayShipsBells" ), &g_bPlayShipsBells);
1325  CHECK_INT(_T ( "SoundDeviceIndex" ), &g_iSoundDeviceIndex);
1326  CHECK_INT(_T ( "FullscreenToolbar" ), &g_bFullscreenToolbar);
1327  // CHECK_INT( _T ( "TransparentToolbar" ), &g_bTransparentToolbar );
1328  CHECK_INT(_T ( "PermanentMOBIcon" ), &g_bPermanentMOBIcon);
1329  CHECK_INT(_T ( "ShowLayers" ), &g_bShowLayers);
1330  CHECK_INT(_T ( "ShowDepthUnits" ), &g_bShowDepthUnits);
1331  CHECK_INT(_T ( "AutoAnchorDrop" ), &g_bAutoAnchorMark);
1332  CHECK_INT(_T ( "ShowActiveRouteHighway" ), &g_bShowActiveRouteHighway);
1333  CHECK_INT(_T ( "ShowActiveRouteTotal" ), &g_bShowRouteTotal);
1334  CHECK_STR(_T ( "MostRecentGPSUploadConnection" ), g_uploadConnection);
1335  CHECK_INT(_T ( "ShowChartBar" ), &g_bShowChartBar);
1336  CHECK_INT(_T ( "SDMMFormat" ),
1337  &g_iSDMMFormat); // 0 = "Degrees, Decimal minutes"), 1 = "Decimal
1338  // degrees", 2 = "Degrees,Minutes, Seconds"
1339 
1340  CHECK_INT(_T ( "DistanceFormat" ),
1341  &g_iDistanceFormat); // 0 = "Nautical miles"), 1 = "Statute miles",
1342  // 2 = "Kilometers", 3 = "Meters"
1343  CHECK_INT(_T ( "SpeedFormat" ),
1344  &g_iSpeedFormat); // 0 = "kts"), 1 = "mph", 2 = "km/h", 3 = "m/s"
1345  CHECK_INT(_T ( "WindSpeedFormat" ),
1346  &g_iWindSpeedFormat); // 0 = "knots"), 1 = "m/s", 2 = "Mph", 3 = "km/h"
1347 
1348  // LIVE ETA OPTION
1349  CHECK_INT(_T ( "LiveETA" ), &g_bShowLiveETA);
1350  CHECK_INT(_T ( "DefaultBoatSpeed" ), &g_defaultBoatSpeed);
1351 
1352  CHECK_INT(_T ( "OwnshipCOGPredictorMinutes" ), &g_ownship_predictor_minutes);
1353  CHECK_INT(_T ( "OwnshipCOGPredictorWidth" ), &g_cog_predictor_width);
1354  CHECK_INT(_T ( "OwnshipHDTPredictorMiles" ), &g_ownship_HDTpredictor_miles);
1355 
1356  CHECK_INT(_T ( "OwnShipIconType" ), &g_OwnShipIconType);
1357  CHECK_FLT(_T ( "OwnShipLength" ), &g_n_ownship_length_meters, 0.1);
1358  CHECK_FLT(_T ( "OwnShipWidth" ), &g_n_ownship_beam_meters, 0.1);
1359  CHECK_FLT(_T ( "OwnShipGPSOffsetX" ), &g_n_gps_antenna_offset_x, 0.1);
1360  CHECK_FLT(_T ( "OwnShipGPSOffsetY" ), &g_n_gps_antenna_offset_y, 0.1);
1361  CHECK_INT(_T ( "OwnShipMinSize" ), &g_n_ownship_min_mm);
1362  CHECK_INT(_T ( "OwnShipSogCogCalc" ), &g_own_ship_sog_cog_calc);
1363  CHECK_INT(_T ( "OwnShipSogCogCalcDampSec"),
1364  &g_own_ship_sog_cog_calc_damp_sec);
1365 
1366  CHECK_FLT(_T ( "RouteArrivalCircleRadius" ), &g_n_arrival_circle_radius, .01);
1367 
1368  CHECK_INT(_T ( "FullScreenQuilt" ), &g_bFullScreenQuilt);
1369 
1370  CHECK_INT(_T ( "StartWithTrackActive" ), &g_bTrackCarryOver);
1371  CHECK_INT(_T ( "AutomaticDailyTracks" ), &g_bTrackDaily);
1372  CHECK_INT(_T ( "TrackRotateAt" ), &g_track_rotate_time);
1373  CHECK_INT(_T ( "TrackRotateTimeType" ), &g_track_rotate_time_type);
1374  CHECK_INT(_T ( "HighlightTracks" ), &g_bHighliteTracks);
1375 
1376  CHECK_FLT(_T ( "PlanSpeed" ), &g_PlanSpeed, 0.1)
1377 
1378 
1380 
1381  CHECK_INT(_T ( "PreserveScaleOnX" ), &g_bPreserveScaleOnX);
1382 
1383  CHECK_STR(_T ( "Locale" ), g_locale);
1384  CHECK_STR(_T ( "LocaleOverride" ), g_localeOverride);
1385 
1386  // We allow 0-99 backups ov navobj.xml
1387  CHECK_INT(_T ( "KeepNavobjBackups" ), &g_navobjbackups);
1388 
1389  // NMEALogWindow::Get().SetSize(Read(_T("NMEALogWindowSizeX"), 600L),
1390  // Read(_T("NMEALogWindowSizeY"), 400L));
1391  // NMEALogWindow::Get().SetPos(Read(_T("NMEALogWindowPosX"), 10L),
1392  // Read(_T("NMEALogWindowPosY"), 10L));
1393  // NMEALogWindow::Get().CheckPos(display_width, display_height);
1394 
1395  // Boolean to cater for legacy Input COM Port filer behaviour, i.e. show msg
1396  // filtered but put msg on bus.
1397  CHECK_INT(_T ( "LegacyInputCOMPortFilterBehaviour" ),
1398  &g_b_legacy_input_filter_behaviour);
1399 
1400  CHECK_INT(_T( "AdvanceRouteWaypointOnArrivalOnly" ),
1401  &g_bAdvanceRouteWaypointOnArrivalOnly);
1402 
1403  CHECK_INT(_T ( "EnableRotateKeys" ), &g_benable_rotate);
1404  CHECK_INT(_T ( "EmailCrashReport" ), &g_bEmailCrashReport);
1405 
1406  CHECK_INT(_T ( "EnableAISNameCache" ), &g_benableAISNameCache);
1407 
1408  CHECK_INT(_T ( "EnableUDPNullHeader" ), &g_benableUDPNullHeader);
1409 
1410  conf.SetPath(_T ( "/Settings/GlobalState" ));
1411 
1412  CHECK_INT(_T ( "FrameWinX" ), &g_nframewin_x);
1413  CHECK_INT(_T ( "FrameWinY" ), &g_nframewin_y);
1414  CHECK_INT(_T ( "FrameWinPosX" ), &g_nframewin_posx);
1415  CHECK_INT(_T ( "FrameWinPosY" ), &g_nframewin_posy);
1416  CHECK_INT(_T ( "FrameMax" ), &g_bframemax);
1417 
1418  CHECK_INT(_T ( "ClientPosX" ), &g_lastClientRectx);
1419  CHECK_INT(_T ( "ClientPosY" ), &g_lastClientRecty);
1420  CHECK_INT(_T ( "ClientSzX" ), &g_lastClientRectw);
1421  CHECK_INT(_T ( "ClientSzY" ), &g_lastClientRecth);
1422 
1423  CHECK_INT(_T( "RoutePropSizeX" ), &g_route_prop_sx);
1424  CHECK_INT(_T( "RoutePropSizeY" ), &g_route_prop_sy);
1425  CHECK_INT(_T( "RoutePropPosX" ), &g_route_prop_x);
1426  CHECK_INT(_T( "RoutePropPosY" ), &g_route_prop_y);
1427 
1428  CHECK_INT(_T ( "S52_DEPTH_UNIT_SHOW" ),
1429  &g_nDepthUnitDisplay); // default is metres
1430 
1431  // AIS
1432  conf.SetPath(_T ( "/Settings/AIS" ));
1433  CHECK_INT(_T ( "bNoCPAMax" ), &g_bCPAMax);
1434  CHECK_FLT(_T ( "NoCPAMaxNMi" ), &g_CPAMax_NM, .01)
1435  CHECK_INT(_T ( "bCPAWarn" ), &g_bCPAWarn);
1436  CHECK_FLT(_T ( "CPAWarnNMi" ), &g_CPAWarn_NM, .01)
1437  CHECK_INT(_T ( "bTCPAMax" ), &g_bTCPA_Max);
1438  CHECK_FLT(_T ( "TCPAMaxMinutes" ), &g_TCPA_Max, 1)
1439  CHECK_INT(_T ( "bMarkLostTargets" ), &g_bMarkLost);
1440  CHECK_FLT(_T ( "MarkLost_Minutes" ), &g_MarkLost_Mins, 1)
1441  CHECK_INT(_T ( "bRemoveLostTargets" ), &g_bRemoveLost);
1442  CHECK_FLT(_T ( "RemoveLost_Minutes" ), &g_RemoveLost_Mins, 1)
1443  CHECK_INT(_T ( "bShowCOGArrows" ), &g_bShowCOG);
1444  CHECK_INT(_T ( "bSyncCogPredictors" ), &g_bSyncCogPredictors);
1445  CHECK_FLT(_T ( "CogArrowMinutes" ), &g_ShowCOG_Mins, 1);
1446  CHECK_INT(_T ( "bShowTargetTracks" ), &g_bAISShowTracks);
1447  CHECK_FLT(_T ( "TargetTracksMinutes" ), &g_AISShowTracks_Mins, 1)
1448  CHECK_FLT(_T ( "TargetTracksLimit" ), &g_AISShowTracks_Limit, 300)
1449  CHECK_INT(_T ( "bHideMooredTargets" ), &g_bHideMoored)
1450  CHECK_FLT(_T ( "MooredTargetMaxSpeedKnots" ), &g_ShowMoored_Kts, .1)
1451  CHECK_INT(_T ( "bShowScaledTargets"), &g_bAllowShowScaled);
1452  CHECK_INT(_T ( "AISScaledNumber" ), &g_ShowScaled_Num);
1453  CHECK_INT(_T ( "AISScaledNumberWeightSOG" ), &g_ScaledNumWeightSOG);
1454  CHECK_INT(_T ( "AISScaledNumberWeightCPA" ), &g_ScaledNumWeightCPA);
1455  CHECK_INT(_T ( "AISScaledNumberWeightTCPA" ), &g_ScaledNumWeightTCPA);
1456  CHECK_INT(_T ( "AISScaledNumberWeightRange" ), &g_ScaledNumWeightRange);
1457  CHECK_INT(_T ( "AISScaledNumberWeightSizeOfTarget" ),
1458  &g_ScaledNumWeightSizeOfT);
1459  CHECK_INT(_T ( "AISScaledSizeMinimal" ), &g_ScaledSizeMinimal);
1460  CHECK_INT(_T( "AISShowScaled"), &g_bShowScaled);
1461  CHECK_INT(_T ( "bShowAreaNotices" ), &g_bShowAreaNotices);
1462  CHECK_INT(_T ( "bDrawAISSize" ), &g_bDrawAISSize);
1463  CHECK_INT(_T ( "bDrawAISRealtime" ), &g_bDrawAISRealtime);
1464  CHECK_FLT(_T ( "AISRealtimeMinSpeedKnots" ), &g_AIS_RealtPred_Kts, .1);
1465  CHECK_INT(_T ( "bShowAISName" ), &g_bShowAISName);
1466  CHECK_INT(_T ( "bAISAlertDialog" ), &g_bAIS_CPA_Alert);
1467  CHECK_INT(_T ( "ShowAISTargetNameScale" ), &g_Show_Target_Name_Scale);
1468  CHECK_INT(_T ( "bWplIsAprsPositionReport" ), &g_bWplUsePosition);
1469  CHECK_INT(_T ( "WplSelAction" ), &g_WplAction);
1470  CHECK_INT(_T ( "AISCOGPredictorWidth" ), &g_ais_cog_predictor_width);
1471  CHECK_INT(_T ( "bAISAlertAudio" ), &g_bAIS_CPA_Alert_Audio);
1472  CHECK_STR(_T ( "AISAlertAudioFile" ), g_sAIS_Alert_Sound_File);
1473  CHECK_INT(_T ( "bAISAlertSuppressMoored" ),
1474  &g_bAIS_CPA_Alert_Suppress_Moored);
1475  CHECK_INT(_T ( "bAISAlertAckTimeout" ), &g_bAIS_ACK_Timeout);
1476  CHECK_FLT(_T ( "AlertAckTimeoutMinutes" ), &g_AckTimeout_Mins, 1)
1477  CHECK_STR(_T ( "AISTargetListPerspective" ), g_AisTargetList_perspective);
1478  CHECK_INT(_T ( "AISTargetListRange" ), &g_AisTargetList_range);
1479  CHECK_INT(_T ( "AISTargetListSortColumn" ), &g_AisTargetList_sortColumn);
1480  CHECK_INT(_T ( "bAISTargetListSortReverse" ), &g_bAisTargetList_sortReverse);
1481  CHECK_STR(_T ( "AISTargetListColumnSpec" ), g_AisTargetList_column_spec);
1482  CHECK_STR(_T ("AISTargetListColumnOrder"), g_AisTargetList_column_order);
1483  CHECK_INT(_T ( "bAISRolloverShowClass" ), &g_bAISRolloverShowClass);
1484  CHECK_INT(_T ( "bAISRolloverShowCOG" ), &g_bAISRolloverShowCOG);
1485  CHECK_INT(_T ( "bAISRolloverShowCPA" ), &g_bAISRolloverShowCPA);
1486 
1487  CHECK_INT(_T ( "S57QueryDialogSizeX" ), &g_S57_dialog_sx);
1488  CHECK_INT(_T ( "S57QueryDialogSizeY" ), &g_S57_dialog_sy);
1489  CHECK_INT(_T ( "AlertDialogSizeX" ), &g_ais_alert_dialog_sx);
1490  CHECK_INT(_T ( "AlertDialogSizeY" ), &g_ais_alert_dialog_sy);
1491  CHECK_INT(_T ( "AlertDialogPosX" ), &g_ais_alert_dialog_x);
1492  CHECK_INT(_T ( "AlertDialogPosY" ), &g_ais_alert_dialog_y);
1493  CHECK_INT(_T ( "QueryDialogPosX" ), &g_ais_query_dialog_x);
1494  CHECK_INT(_T ( "QueryDialogPosY" ), &g_ais_query_dialog_y);
1495 
1496  conf.SetPath(_T ( "/Directories" ));
1497  CHECK_STR(_T ( "PresentationLibraryData" ), g_UserPresLibData)
1499 
1500  CHECK_STR(_T ( "SENCFileLocation" ), g_SENCPrefix)
1501 
1502  CHECK_STR(_T ( "GPXIODir" ), g_gpx_path); // Get the Directory name
1503  CHECK_STR(_T ( "TCDataDir" ), g_TCData_Dir); // Get the Directory name
1504  CHECK_STR(_T ( "BasemapDir"), gWorldMapLocation);
1505  CHECK_STR(_T ( "BaseShapefileDir"), gWorldShapefileLocation);
1506 
1507  // Fonts
1508 
1509 #if 0
1510  // Load the persistent Auxiliary Font descriptor Keys
1511  conf.SetPath ( _T ( "/Settings/AuxFontKeys" ) );
1512 
1513  wxString strk;
1514  long dummyk;
1515  wxString kval;
1516  bool bContk = conf,GetFirstEntry( strk, dummyk );
1517  bool bNewKey = false;
1518  while( bContk ) {
1519  Read( strk, &kval );
1520  bNewKey = FontMgr::Get().AddAuxKey(kval);
1521  if(!bNewKey) {
1522  DeleteEntry( strk );
1523  dummyk--;
1524  }
1525  bContk = GetNextEntry( strk, dummyk );
1526  }
1527 #endif
1528 
1529 #ifdef __WXX11__
1530  conf.SetPath(_T ( "/Settings/X11Fonts" ));
1531 #endif
1532 
1533 #ifdef __WXGTK__
1534  conf.SetPath(_T ( "/Settings/GTKFonts" ));
1535 #endif
1536 
1537 #ifdef __WXMSW__
1538  conf.SetPath(_T ( "/Settings/MSWFonts" ));
1539 #endif
1540 
1541 #ifdef __WXMAC__
1542  conf.SetPath(_T ( "/Settings/MacFonts" ));
1543 #endif
1544 
1545 #ifdef __WXQT__
1546  conf.SetPath(_T ( "/Settings/QTFonts" ));
1547 #endif
1548 
1549  conf.SetPath(_T ( "/Settings/Others" ));
1550 
1551  // Radar rings
1552  CHECK_INT(_T ( "RadarRingsNumberVisible" ), &g_iNavAidRadarRingsNumberVisible)
1553  CHECK_INT(_T ( "RadarRingsStep" ), &g_fNavAidRadarRingsStep)
1554 
1555  CHECK_INT(_T ( "RadarRingsStepUnits" ), &g_pNavAidRadarRingsStepUnits);
1556 
1557  // wxString l_wxsOwnshipRangeRingsColour;
1558  // CHECK_STR( _T ( "RadarRingsColour" ), &l_wxsOwnshipRangeRingsColour );
1559  // if(l_wxsOwnshipRangeRingsColour.Length())
1560  // g_colourOwnshipRangeRingsColour.Set( l_wxsOwnshipRangeRingsColour );
1561 
1562  // Waypoint Radar rings
1563  CHECK_INT(_T ( "WaypointRangeRingsNumber" ), &g_iWaypointRangeRingsNumber)
1564 
1565  CHECK_FLT(_T ( "WaypointRangeRingsStep" ), &g_fWaypointRangeRingsStep, .1)
1566 
1567  CHECK_INT(_T ( "WaypointRangeRingsStepUnits" ),
1568  &g_iWaypointRangeRingsStepUnits);
1569 
1570  // wxString l_wxsWaypointRangeRingsColour;
1571  // CHECK_STR( _T( "WaypointRangeRingsColour" ),
1572  // &l_wxsWaypointRangeRingsColour ); g_colourWaypointRangeRingsColour.Set(
1573  // l_wxsWaypointRangeRingsColour );
1574 
1575  CHECK_INT(_T ( "ConfirmObjectDeletion" ), &g_bConfirmObjectDelete);
1576 
1577  // Waypoint dragging with mouse
1578  CHECK_INT(_T ( "WaypointPreventDragging" ), &g_bWayPointPreventDragging);
1579 
1580  CHECK_INT(_T ( "EnableZoomToCursor" ), &g_bEnableZoomToCursor);
1581 
1582  CHECK_FLT(_T ( "TrackIntervalSeconds" ), &g_TrackIntervalSeconds, 1)
1583 
1584  CHECK_FLT(_T ( "TrackDeltaDistance" ), &g_TrackDeltaDistance, .1)
1585 
1586  CHECK_INT(_T ( "TrackPrecision" ), &g_nTrackPrecision);
1587 
1588  // CHECK_STR( _T ( "NavObjectFileName" ), m_sNavObjSetFile );
1589 
1590  CHECK_INT(_T ( "RouteLineWidth" ), &g_route_line_width);
1591  CHECK_INT(_T ( "TrackLineWidth" ), &g_track_line_width);
1592 
1593  // wxString l_wxsTrackLineColour;
1594  // CHECK_STR( _T( "TrackLineColour" ), l_wxsTrackLineColour )
1595  // g_colourTrackLineColour.Set( l_wxsTrackLineColour );
1596 
1597  CHECK_STR(_T ( "DefaultWPIcon" ), g_default_wp_icon)
1598 
1599  // S57 template items
1600 
1601 #define CHECK_BFN(s, t) \
1602  conf.Read(s, &read_int); \
1603  bval = t; \
1604  bval0 = read_int != 0; \
1605  if (bval != bval0) return false;
1606 
1607 #define CHECK_IFN(s, t) \
1608  conf.Read(s, &read_int); \
1609  if (read_int != t) return false;
1610 
1611 #define CHECK_FFN(s, t) \
1612  conf.Read(s, &dval); \
1613  if (fabs(dval - t) > 0.1) return false;
1614 
1615  if (ps52plib) {
1616  int read_int;
1617  double dval;
1618  bool bval, bval0;
1619 
1620  conf.SetPath(_T ( "/Settings/GlobalState" ));
1621 
1622  CHECK_BFN(_T ( "bShowS57Text" ), ps52plib->GetShowS57Text());
1623 
1624  CHECK_BFN(_T ( "bShowS57ImportantTextOnly" ),
1625  ps52plib->GetShowS57ImportantTextOnly());
1626  CHECK_BFN(_T ( "bShowLightDescription" ), ps52plib->m_bShowLdisText);
1627  CHECK_BFN(_T ( "bExtendLightSectors" ), ps52plib->m_bExtendLightSectors);
1628  CHECK_BFN(_T ( "bShowSoundg" ), ps52plib->m_bShowSoundg);
1629  CHECK_BFN(_T ( "bShowMeta" ), ps52plib->m_bShowMeta);
1630  CHECK_BFN(_T ( "bUseSCAMIN" ), ps52plib->m_bUseSCAMIN);
1631  CHECK_BFN(_T ( "bUseSUPERSCAMIN" ), ps52plib->m_bUseSUPER_SCAMIN);
1632  CHECK_BFN(_T ( "bShowAtonText" ), ps52plib->m_bShowAtonText);
1633  CHECK_BFN(_T ( "bDeClutterText" ), ps52plib->m_bDeClutterText);
1634  CHECK_BFN(_T ( "bShowNationalText" ), ps52plib->m_bShowNationalTexts);
1635  CHECK_IFN(_T ( "nDisplayCategory" ), ps52plib->GetDisplayCategory());
1636  CHECK_IFN(_T ( "nSymbolStyle" ), ps52plib->m_nSymbolStyle);
1637  CHECK_IFN(_T ( "nBoundaryStyle" ), ps52plib->m_nBoundaryStyle);
1638  CHECK_FFN(_T ( "S52_MAR_SAFETY_CONTOUR" ),
1639  S52_getMarinerParam(S52_MAR_SAFETY_CONTOUR));
1640  CHECK_FFN(_T ( "S52_MAR_SHALLOW_CONTOUR" ),
1641  S52_getMarinerParam(S52_MAR_SHALLOW_CONTOUR));
1642  CHECK_FFN(_T ( "S52_MAR_DEEP_CONTOUR" ),
1643  S52_getMarinerParam(S52_MAR_DEEP_CONTOUR));
1644  CHECK_FFN(_T ( "S52_MAR_TWO_SHADES" ),
1645  S52_getMarinerParam(S52_MAR_TWO_SHADES));
1646  CHECK_INT(_T ( "S52_DEPTH_UNIT_SHOW" ), &g_nDepthUnitDisplay);
1647 
1648  // S57 Object Class Visibility
1649 
1650  OBJLElement *pOLE;
1651 
1652  conf.SetPath(_T ( "/Settings/ObjectFilter" ));
1653 
1654  unsigned int iOBJMax = conf.GetNumberOfEntries();
1655 
1656  if (iOBJMax != ps52plib->pOBJLArray->GetCount()) return false;
1657 
1658  if (iOBJMax) {
1659  wxString str, sObj;
1660  long val;
1661  long dummy;
1662 
1663  bool bCont = conf.GetFirstEntry(str, dummy);
1664  while (bCont) {
1665  conf.Read(str, &val); // Get an Object Viz
1666 
1667  // scan for the same key in the global list
1668  bool bfound = false;
1669  if (str.StartsWith(_T ( "viz" ), &sObj)) {
1670  for (unsigned int iPtr = 0; iPtr < ps52plib->pOBJLArray->GetCount();
1671  iPtr++) {
1672  pOLE = (OBJLElement *)(ps52plib->pOBJLArray->Item(iPtr));
1673  if (!strncmp(pOLE->OBJLName, sObj.mb_str(), 6)) {
1674  bfound = true;
1675  if (pOLE->nViz != val) {
1676  return false;
1677  }
1678  }
1679  }
1680 
1681  if (!bfound) return false;
1682  }
1683  bCont = conf.GetNextEntry(str, dummy);
1684  }
1685  }
1686  }
1687 
1688  conf.SetPath(_T ( "/MmsiProperties" ));
1689  int iPMax = conf.GetNumberOfEntries();
1690  if (iPMax) {
1691  wxString str, val;
1692  long dummy;
1693 
1694  bool bCont = conf.GetFirstEntry(str, dummy);
1695  while (bCont) {
1696  conf.Read(str, &val); // Get an entry
1697 
1698  bool bfound = false;
1699  for (unsigned int j = 0; j < g_MMSI_Props_Array.GetCount(); j++) {
1700  MmsiProperties *pProps = g_MMSI_Props_Array.Item(j);
1701  if (pProps->Serialize().IsSameAs(val)) {
1702  bfound = true;
1703  break;
1704  }
1705  }
1706  if (!bfound) return false;
1707 
1708  bCont = conf.GetNextEntry(str, dummy);
1709  }
1710  }
1711 
1712  return rv;
1713 }
Global state for AIS decoder.
wxString & GetPrivateDataDir()
Return dir path for opencpn.log, etc., respecting -c cli option.
Manages the user config matrix.
Definition: ConfigMgr.h:45
Definition: Layer.h:32