Driver/Volkslogger: eliminate class VLA_SYS
[xcsoar.git] / src / UtilsSettings.cpp
blobfe1d328352e44436264ce47b18745ce2971cf80e
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 "Computer/Settings.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/Ordered/OrderedTask.hpp"
53 #include "Engine/Task/TaskEvents.hpp"
54 #include "Waypoint/WaypointGlue.hpp"
55 #include "Computer/GlideComputer.hpp"
56 #include "Language/LanguageGlue.hpp"
57 #include "Units/Units.hpp"
58 #include "Formatter/UserGeoPointFormatter.hpp"
59 #include "InfoBoxes/InfoBoxManager.hpp"
60 #include "Audio/VarioGlue.hpp"
61 #include "PageActions.hpp"
63 #if defined(__BORLANDC__) // due to compiler bug
64 #include "Waypoint/Waypoints.hpp"
65 #endif
67 bool DevicePortChanged = false;
68 bool MapFileChanged = false;
69 bool AirspaceFileChanged = false;
70 bool AirfieldFileChanged = false;
71 bool WaypointFileChanged = false;
72 bool InputFileChanged = false;
73 bool LanguageChanged = false;
74 bool require_restart;
76 static void
77 SettingsEnter()
79 CommonInterface::main_window->SuspendThreads();
81 // This prevents the map and calculation threads from doing anything
82 // with shared data while it is being changed (also prevents drawing)
84 MapFileChanged = false;
85 AirspaceFileChanged = false;
86 AirfieldFileChanged = false;
87 WaypointFileChanged = false;
88 InputFileChanged = false;
89 DevicePortChanged = false;
90 LanguageChanged = false;
91 require_restart = false;
94 static void
95 SettingsLeave(const UISettings &old_ui_settings)
97 if (!global_running)
98 return;
100 SuspendAllThreads();
102 VerboseOperationEnvironment operation;
104 MainWindow &main_window = *CommonInterface::main_window;
106 if (LanguageChanged)
107 ReadLanguageFile();
109 bool TerrainFileChanged = false, TopographyFileChanged = false;
110 if (MapFileChanged) {
111 /* set these flags, because they may be loaded from the map
112 file */
113 AirspaceFileChanged = true;
114 AirfieldFileChanged = true;
115 WaypointFileChanged = true;
116 TerrainFileChanged = true;
117 TopographyFileChanged = true;
120 if (TerrainFileChanged) {
121 operation.SetText(_("Loading Terrain File..."));
123 /* just in case the bottom widget uses the old terrain object
124 (e.g. the cross section) */
125 main_window.SetBottomWidget(nullptr);
127 main_window.SetTerrain(NULL);
128 glide_computer->SetTerrain(NULL);
130 // re-load terrain
131 delete terrain;
132 terrain = RasterTerrain::OpenTerrain(file_cache, operation);
134 main_window.SetTerrain(terrain);
135 glide_computer->SetTerrain(terrain);
137 /* re-create the bottom widget if it was deleted here */
138 PageActions::Update();
141 if (WaypointFileChanged || AirfieldFileChanged) {
142 // re-load waypoints
143 WaypointGlue::LoadWaypoints(way_points, terrain, operation);
144 WaypointDetails::ReadFileFromProfile(way_points, operation);
147 if (WaypointFileChanged && protected_task_manager != NULL) {
148 ProtectedTaskManager::ExclusiveLease lease(*protected_task_manager);
149 OrderedTask *task = lease->Clone(CommonInterface::GetComputerSettings().task);
150 if (task) {
151 // this must be done in thread lock because it potentially changes the
152 // waypoints database
153 task->CheckDuplicateWaypoints(way_points);
155 /* XXX shall this task be committed if it has been modified? */
156 delete task;
158 way_points.Optimise();
160 lease->FillMatPoints(way_points);
164 if (WaypointFileChanged || TerrainFileChanged) {
165 // re-set home
166 WaypointGlue::SetHome(way_points, terrain,
167 CommonInterface::SetComputerSettings().poi,
168 CommonInterface::SetComputerSettings().team_code,
169 device_blackboard, WaypointFileChanged);
170 WaypointGlue::SaveHome(CommonInterface::GetComputerSettings().poi,
171 CommonInterface::GetComputerSettings().team_code);
174 if (TopographyFileChanged) {
175 main_window.SetTopography(NULL);
176 topography->Reset();
177 LoadConfiguredTopography(*topography, operation);
178 main_window.SetTopography(topography);
181 if (AirspaceFileChanged) {
182 if (glide_computer != NULL)
183 glide_computer->GetAirspaceWarnings().clear();
185 if (glide_computer != NULL)
186 glide_computer->ClearAirspaces();
188 airspace_database.clear();
189 ReadAirspace(airspace_database, terrain,
190 CommonInterface::GetComputerSettings().pressure,
191 operation);
194 if (DevicePortChanged)
195 devRestart();
197 const UISettings &ui_settings = CommonInterface::GetUISettings();
199 Units::SetConfig(ui_settings.units);
200 SetUserCoordinateFormat(ui_settings.coordinate_format);
202 const MapSettings &old_settings_map = old_ui_settings.map;
203 const MapSettings &settings_map = ui_settings.map;
205 if (settings_map.trail.type != old_settings_map.trail.type ||
206 settings_map.trail.scaling_enabled != old_settings_map.trail.scaling_enabled)
207 main_window.SetLook().map.trail.Initialise(settings_map.trail);
209 if (settings_map.waypoint.landable_style != old_settings_map.waypoint.landable_style)
210 main_window.SetLook().map.waypoint.Initialise(settings_map.waypoint);
212 ResumeAllThreads();
213 main_window.ResumeThreads();
214 // allow map and calculations threads to continue
216 ActionInterface::SendMapSettings(true);
218 AudioVarioGlue::Configure(CommonInterface::GetUISettings().sound.vario);
220 operation.Hide();
221 InfoBoxManager::SetDirty();
222 main_window.FullRedraw();
223 main_window.SetDefaultFocus();
226 void
227 SystemConfiguration()
229 const UISettings old_ui_settings = CommonInterface::GetUISettings();
231 SettingsEnter();
232 dlgConfigurationShowModal();
233 SettingsLeave(old_ui_settings);