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