OpenCPN Partial API docs
Loading...
Searching...
No Matches
CanvasConfig.cpp
1/***************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: Canvas Configuration
5 * Author: David Register
6 *
7 ***************************************************************************
8 * Copyright (C) 2018 by David S. Register *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
24 **************************************************************************/
25
26#include <wx/wxprec.h>
27
28#ifndef WX_PRECOMP
29#include <wx/wx.h>
30#endif // precompiled headers
31
32#include <wx/fileconf.h>
33
34#include "CanvasConfig.h"
35#include "ocpn_plugin.h"
36
37//----------------------------------------------------------------------------
38// constants
39//----------------------------------------------------------------------------
40#ifndef PI
41#define PI 3.1415926535897931160E0 /* pi */
42#endif
43
44//------------------------------------------------------------------------------
45// canvasConfig Implementation
46//------------------------------------------------------------------------------
47
48canvasConfig::canvasConfig(int index) {
49 configIndex = index;
50 canvas = NULL;
51 GroupID = 0;
52 iLat = 0.;
53 iLon = 0.;
54 iScale = .0003; // decent initial value
55 iRotation = 0.;
56}
57
58canvasConfig::~canvasConfig() {}
59
60void canvasConfig::Reset(void) {
61 bFollow = false;
62 bShowTides = false;
63 bShowCurrents = false;
64 bCourseUp = false;
65 bHeadUp = false;
66 bLookahead = false;
67 bShowAIS = true;
68 bAttenAIS = false;
69 bQuilt = true;
70 nENCDisplayCategory = (int)(enum _DisCat)STANDARD;
71}
72
73void canvasConfig::LoadFromLegacyConfig(wxFileConfig *conf) {
74 if (!conf) return;
75
76 bFollow = false;
77 bShowAIS = true;
78
79 // S52 stuff
80 conf->SetPath(_T ( "/Settings/GlobalState" ));
81 conf->Read(_T ( "bShowS57Text" ), &bShowENCText, 1);
82 conf->Read(_T ( "bShowLightDescription" ), &bShowENCLightDescriptions, 0);
83 conf->Read(_T ( "nDisplayCategory" ), &nENCDisplayCategory,
84 (enum _DisCat)STANDARD);
85 conf->Read(_T ( "bShowSoundg" ), &bShowENCDepths, 1);
86 conf->Read(_T ( "bShowAtonText" ), &bShowENCBuoyLabels, 1);
87 bShowENCLights = true;
88
89 conf->SetPath(_T ( "/Settings/AIS" ));
90 conf->Read(_T ( "bShowScaledTargets" ), &bAttenAIS, 0);
91
92 conf->SetPath(_T ( "/Settings" ));
93 conf->Read(_T ( "ShowTide" ), &bShowTides, 0);
94 conf->Read(_T ( "ShowCurrent" ), &bShowCurrents, 0);
95 conf->Read(_T ( "CourseUpMode" ), &bCourseUp, 0);
96 conf->Read(_T ( "HeadUpMode" ), &bHeadUp, 0);
97 conf->Read(_T ( "LookAheadMode" ), &bLookahead, 0);
98
99 conf->Read(_T ( "ShowGrid" ), &bShowGrid, 0);
100 conf->Read(_T ( "ShowChartOutlines" ), &bShowOutlines, 1);
101 conf->Read(_T ( "ShowDepthUnits" ), &bShowDepthUnits, 1);
102 conf->Read(_T ( "ChartQuilting" ), &bQuilt, 1);
103
104 conf->Read(_T ( "ActiveChartGroup" ), &GroupID, 0);
105 conf->Read(_T ( "InitialdBIndex" ), &DBindex, -1);
106
107 conf->SetPath(_T ( "/Settings/GlobalState" ));
108 wxString st;
109 double st_view_scale, st_rotation;
110 if (conf->Read(wxString(_T ( "VPScale" )), &st)) {
111 sscanf(st.mb_str(wxConvUTF8), "%lf", &st_view_scale);
112 // Sanity check the scale
113 st_view_scale = fmax(st_view_scale, .001 / 32);
114 st_view_scale = fmin(st_view_scale, 4);
115 iScale = st_view_scale;
116 }
117
118 if (conf->Read(wxString(_T ( "VPRotation" )), &st)) {
119 sscanf(st.mb_str(wxConvUTF8), "%lf", &st_rotation);
120 // Sanity check the rotation
121 st_rotation = fmin(st_rotation, 360);
122 st_rotation = fmax(st_rotation, 0);
123 iRotation = st_rotation * PI / 180.;
124 }
125
126 wxString sll;
127 double lat, lon;
128 if (conf->Read(_T ( "VPLatLon" ), &sll)) {
129 sscanf(sll.mb_str(wxConvUTF8), "%lf,%lf", &lat, &lon);
130
131 // Sanity check the lat/lon...both have to be reasonable.
132 if (fabs(lon) < 360.) {
133 while (lon < -180.) lon += 360.;
134
135 while (lon > 180.) lon -= 360.;
136
137 iLon = lon;
138 }
139
140 if (fabs(lat) < 90.0) iLat = lat;
141 }
142}