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 
canvasConfig(int index)48 canvasConfig::canvasConfig( int index )
49 {
50     configIndex = index;
51     canvas = NULL;
52     GroupID = 0;
53     iLat = 0.;
54     iLon = 0.;
55     iScale = .0003;        // decent initial value
56     iRotation = 0.;
57 }
58 
~canvasConfig()59 canvasConfig::~canvasConfig(){}
60 
61 
Reset(void)62 void canvasConfig::Reset( void){
63         bFollow = false;
64         bShowTides = false;
65         bShowCurrents = false;
66         bCourseUp = false;
67         bHeadUp = false;
68         bLookahead = false;
69         bShowAIS = true;
70         bAttenAIS = false;
71         bQuilt = true;
72         nENCDisplayCategory = (int)(enum _DisCat) STANDARD;
73 
74 }
75 
LoadFromLegacyConfig(wxFileConfig * conf)76 void canvasConfig::LoadFromLegacyConfig( wxFileConfig *conf )
77 {
78     if(!conf)
79         return;
80 
81     bFollow = false;
82     bShowAIS = true;
83 
84     //S52 stuff
85     conf->SetPath( _T ( "/Settings/GlobalState" ) );
86     conf->Read( _T ( "bShowS57Text" ), &bShowENCText, 1 );
87     conf->Read( _T ( "bShowLightDescription" ), &bShowENCLightDescriptions, 0 );
88     conf->Read( _T ( "nDisplayCategory" ), &nENCDisplayCategory, (enum _DisCat) STANDARD );
89     conf->Read( _T ( "bShowSoundg" ), &bShowENCDepths, 1 );
90     conf->Read( _T ( "bShowAtonText" ), &bShowENCBuoyLabels, 1 );
91     bShowENCLights = true;
92 
93     conf->SetPath( _T ( "/Settings/AIS" ) );
94     conf->Read( _T ( "bShowScaledTargets" ), &bAttenAIS, 0 );
95 
96     conf->SetPath( _T ( "/Settings" ) );
97     conf->Read( _T ( "ShowTide" ), &bShowTides, 0 );
98     conf->Read( _T ( "ShowCurrent" ), &bShowCurrents, 0 );
99     conf->Read( _T ( "CourseUpMode" ), &bCourseUp, 0 );
100     conf->Read( _T ( "HeadUpMode" ), &bHeadUp, 0 );
101     conf->Read( _T ( "LookAheadMode" ), &bLookahead, 0 );
102 
103     conf->Read( _T ( "ShowGrid" ), &bShowGrid, 0 );
104     conf->Read( _T ( "ShowChartOutlines" ), &bShowOutlines, 1 );
105     conf->Read( _T ( "ShowDepthUnits" ), &bShowDepthUnits, 1 );
106     conf->Read( _T ( "ChartQuilting" ), &bQuilt, 1 );
107 
108     conf->Read( _T ( "ActiveChartGroup" ), &GroupID, 0 );
109     conf->Read( _T ( "InitialdBIndex" ), &DBindex, -1 );
110 
111     conf->SetPath( _T ( "/Settings/GlobalState" ) );
112     wxString st;
113     double st_view_scale, st_rotation;
114     if( conf->Read( wxString( _T ( "VPScale" ) ), &st ) ) {
115         sscanf( st.mb_str( wxConvUTF8 ), "%lf", &st_view_scale );
116 //    Sanity check the scale
117         st_view_scale = fmax ( st_view_scale, .001/32 );
118         st_view_scale = fmin ( st_view_scale, 4 );
119         iScale = st_view_scale;
120     }
121 
122     if( conf->Read( wxString( _T ( "VPRotation" ) ), &st ) ) {
123         sscanf( st.mb_str( wxConvUTF8 ), "%lf", &st_rotation );
124 //    Sanity check the rotation
125         st_rotation = fmin ( st_rotation, 360 );
126         st_rotation = fmax ( st_rotation, 0 );
127         iRotation = st_rotation * PI / 180.;
128     }
129 
130     wxString sll;
131     double lat, lon;
132     if( conf->Read( _T ( "VPLatLon" ), &sll ) ) {
133         sscanf( sll.mb_str( wxConvUTF8 ), "%lf,%lf", &lat, &lon );
134 
135         //    Sanity check the lat/lon...both have to be reasonable.
136         if( fabs( lon ) < 360. ) {
137             while( lon < -180. )
138                 lon += 360.;
139 
140             while( lon > 180. )
141                 lon -= 360.;
142 
143             iLon = lon;
144         }
145 
146         if( fabs( lat ) < 90.0 )
147             iLat = lat;
148     }
149 
150 }
151 
152 
153 
154