Projection: make invalid by default, add IsValid()
[xcsoar.git] / src / UtilsSettings.cpp
blob11ab83b4018cffb5c286f40f90e2971831fe2680
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "UtilsSettings.hpp"
25 #include "Protection.hpp"
26 #include "Look/Look.hpp"
27 #include "MainWindow.hpp"
28 #include "MapWindow/GlueMapWindow.hpp"
29 #include "ComputerSettings.hpp"
30 #include "MapSettings.hpp"
31 #include "Terrain/RasterTerrain.hpp"
32 #include "Waypoint/WaypointDetailsReader.hpp"
33 #include "Topography/TopographyStore.hpp"
34 #include "Topography/TopographyGlue.hpp"
35 #include "Dialogs/Dialogs.h"
36 #include "Device/device.hpp"
37 #include "Message.hpp"
38 #include "Polar/PolarGlue.hpp"
39 #include "Components.hpp"
40 #include "Interface.hpp"
41 #include "ActionInterface.hpp"
42 #include "Language/Language.hpp"
43 #include "LogFile.hpp"
44 #include "Simulator.hpp"
45 #include "DrawThread.hpp"
46 #include "Airspace/AirspaceGlue.hpp"
47 #include "Airspace/ProtectedAirspaceWarningManager.hpp"
48 #include "Engine/Airspace/Airspaces.hpp"
49 #include "Engine/Waypoint/Waypoints.hpp"
50 #include "Operation/VerboseOperationEnvironment.hpp"
51 #include "Task/ProtectedTaskManager.hpp"
52 #include "Engine/Task/TaskEvents.hpp"
53 #include "Waypoint/WaypointGlue.hpp"
54 #include "Computer/GlideComputer.hpp"
55 #include "Language/LanguageGlue.hpp"
56 #include "Units/Units.hpp"
57 #include "Formatter/UserGeoPointFormatter.hpp"
58 #include "InfoBoxes/InfoBoxManager.hpp"
59 #include "Audio/VarioGlue.hpp"
60 #include "PageActions.hpp"
62 #if defined(__BORLANDC__) // due to compiler bug
63 #include "Waypoint/Waypoints.hpp"
64 #endif
66 bool DevicePortChanged = false;
67 bool MapFileChanged = false;
68 bool AirspaceFileChanged = false;
69 bool AirfieldFileChanged = false;
70 bool WaypointFileChanged = false;
71 bool InputFileChanged = false;
72 bool LanguageChanged = false;
74 static void
75 SettingsEnter()
77 CommonInterface::main_window->SuspendThreads();
79 // This prevents the map and calculation threads from doing anything
80 // with shared data while it is being changed (also prevents drawing)
82 MapFileChanged = false;
83 AirspaceFileChanged = false;
84 AirfieldFileChanged = false;
85 WaypointFileChanged = false;
86 InputFileChanged = false;
87 DevicePortChanged = false;
88 LanguageChanged = false;
91 static void
92 SettingsLeave(const UISettings &old_ui_settings)
94 if (!global_running)
95 return;
97 SuspendAllThreads();
99 VerboseOperationEnvironment operation;
101 MainWindow &main_window = *CommonInterface::main_window;
103 if (LanguageChanged)
104 ReadLanguageFile();
106 bool TerrainFileChanged = false, TopographyFileChanged = false;
107 if (MapFileChanged) {
108 /* set these flags, because they may be loaded from the map
109 file */
110 AirspaceFileChanged = true;
111 AirfieldFileChanged = true;
112 WaypointFileChanged = true;
113 TerrainFileChanged = true;
114 TopographyFileChanged = true;
117 if (TerrainFileChanged) {
118 operation.SetText(_("Loading Terrain File..."));
120 /* just in case the bottom widget uses the old terrain object
121 (e.g. the cross section) */
122 main_window.SetBottomWidget(nullptr);
124 main_window.SetTerrain(NULL);
125 glide_computer->SetTerrain(NULL);
127 // re-load terrain
128 delete terrain;
129 terrain = RasterTerrain::OpenTerrain(file_cache, operation);
131 main_window.SetTerrain(terrain);
132 glide_computer->SetTerrain(terrain);
134 /* re-create the bottom widget if it was deleted here */
135 PageActions::Update();
138 if (WaypointFileChanged || AirfieldFileChanged) {
139 // re-load waypoints
140 WaypointGlue::LoadWaypoints(way_points, terrain, operation);
141 WaypointDetails::ReadFileFromProfile(way_points, operation);
144 if (WaypointFileChanged && protected_task_manager != NULL) {
145 ProtectedTaskManager::ExclusiveLease lease(*protected_task_manager);
146 OrderedTask *task = lease->Clone(CommonInterface::GetComputerSettings().task);
147 if (task) {
148 // this must be done in thread lock because it potentially changes the
149 // waypoints database
150 task->CheckDuplicateWaypoints(way_points);
152 /* XXX shall this task be committed if it has been modified? */
153 delete task;
155 way_points.Optimise();
159 if (WaypointFileChanged || TerrainFileChanged) {
160 // re-set home
161 WaypointGlue::SetHome(way_points, terrain,
162 CommonInterface::SetComputerSettings().poi,
163 CommonInterface::SetComputerSettings().team_code,
164 device_blackboard, WaypointFileChanged);
165 WaypointGlue::SaveHome(CommonInterface::GetComputerSettings().poi,
166 CommonInterface::GetComputerSettings().team_code);
169 if (TopographyFileChanged) {
170 main_window.SetTopography(NULL);
171 topography->Reset();
172 LoadConfiguredTopography(*topography, operation);
173 main_window.SetTopography(topography);
176 if (AirspaceFileChanged) {
177 if (glide_computer != NULL)
178 glide_computer->GetAirspaceWarnings().clear();
180 if (glide_computer != NULL)
181 glide_computer->ClearAirspaces();
183 airspace_database.clear();
184 ReadAirspace(airspace_database, terrain,
185 CommonInterface::GetComputerSettings().pressure,
186 operation);
189 if (DevicePortChanged)
190 devRestart();
192 const UISettings &ui_settings = CommonInterface::GetUISettings();
194 Units::SetConfig(ui_settings.units);
195 SetUserCoordinateFormat(ui_settings.coordinate_format);
197 const MapSettings &old_settings_map = old_ui_settings.map;
198 const MapSettings &settings_map = ui_settings.map;
200 if (settings_map.trail.type != old_settings_map.trail.type ||
201 settings_map.trail.scaling_enabled != old_settings_map.trail.scaling_enabled)
202 main_window.SetLook().map.trail.Initialise(settings_map.trail);
204 if (settings_map.waypoint.landable_style != old_settings_map.waypoint.landable_style)
205 main_window.SetLook().map.waypoint.Initialise(settings_map.waypoint);
207 ResumeAllThreads();
208 main_window.ResumeThreads();
209 // allow map and calculations threads to continue
211 ActionInterface::SendMapSettings(true);
213 AudioVarioGlue::Configure(CommonInterface::GetUISettings().sound.vario);
215 operation.Hide();
216 InfoBoxManager::SetDirty();
217 main_window.FullRedraw();
218 main_window.SetDefaultFocus();
221 void
222 SystemConfiguration()
224 const UISettings old_ui_settings = CommonInterface::GetUISettings();
226 SettingsEnter();
227 dlgConfigurationShowModal();
228 SettingsLeave(old_ui_settings);