OpenCPN Partial API docs
Loading...
Searching...
No Matches
CanvasConfig.cpp
1/***************************************************************************
2 * Copyright (C) 2018 by David S. Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 **************************************************************************/
19
20#include <wx/wxprec.h>
21
22#ifndef WX_PRECOMP
23#include <wx/wx.h>
24#endif // precompiled headers
25
26#include <wx/fileconf.h>
27
28#include "CanvasConfig.h"
29#include "ocpn_plugin.h"
30
31//----------------------------------------------------------------------------
32// constants
33//----------------------------------------------------------------------------
34#ifndef PI
35#define PI 3.1415926535897931160E0 /* pi */
36#endif
37
38//------------------------------------------------------------------------------
39// canvasConfig Implementation
40//------------------------------------------------------------------------------
41
42canvasConfig::canvasConfig(int index) {
43 configIndex = index;
44 canvas = NULL;
45 GroupID = 0;
46 iLat = 0.;
47 iLon = 0.;
48 iScale = .0003; // decent initial value
49 iRotation = 0.;
50}
51
52canvasConfig::~canvasConfig() {}
53
55 bFollow = false;
56 bShowTides = false;
57 bShowCurrents = false;
58 bCourseUp = false;
59 bHeadUp = false;
60 bLookahead = false;
61 bShowAIS = true;
62 bAttenAIS = false;
63 bQuilt = true;
64 nENCDisplayCategory = (int)(enum _DisCat)OTHER;
65 bShowENCDataQuality = 0;
66 bShowENCBuoyLabels = 0;
67 bShowENCLightDescriptions = 1;
68}
69
70void canvasConfig::LoadFromLegacyConfig(wxFileConfig *conf) {
71 if (!conf) return;
72
73 bFollow = false;
74 bShowAIS = true;
75
76 // S52 stuff
77 conf->SetPath(_T ( "/Settings/GlobalState" ));
78 conf->Read(_T ( "bShowS57Text" ), &bShowENCText, 1);
79 conf->Read(_T ( "bShowLightDescription" ), &bShowENCLightDescriptions, 1);
80 conf->Read(_T ( "nDisplayCategory" ), &nENCDisplayCategory,
81 (enum _DisCat)OTHER);
82 conf->Read(_T ( "bShowSoundg" ), &bShowENCDepths, 1);
83 conf->Read(_T ( "bShowAtonText" ), &bShowENCBuoyLabels, 0);
84 bShowENCLights = true;
85 bShowENCVisibleSectorLights = false;
86 bShowENCAnchorInfo = false;
87 bShowENCDataQuality = false;
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}
double iLat
Latitude of the center of the chart, in degrees.
bool bShowOutlines
Display chart outlines.
void Reset()
Resets all configuration options to default values.
bool bShowDepthUnits
Display depth unit indicators.
double iLon
Longitude of the center of the chart, in degrees.
double iRotation
Initial rotation angle in radians.
bool bCourseUp
Orient display to course up.
bool bQuilt
Enable chart quilting.
bool bFollow
Enable vessel following mode.
double iScale
Initial chart scale factor.
bool bShowENCText
Display ENC text elements.
bool bShowAIS
Display AIS targets.
bool bShowGrid
Display coordinate grid.
ChartCanvas * canvas
Pointer to associated chart canvas.
bool bShowCurrents
Display current information.
bool bShowTides
Display tide information.
bool bLookahead
Enable lookahead mode.
bool bHeadUp
Orient display to heading up.
bool bAttenAIS
Enable AIS target attenuation.
PlugIn Object Definition/API.