4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2012 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 "Interface.hpp"
25 #include "Thread/Mutex.hpp"
26 #include "MainWindow.hpp"
27 #include "MapWindow/GlueMapWindow.hpp"
28 #include "Language/Language.hpp"
29 #include "Dialogs/Message.hpp"
30 #include "StatusMessage.hpp"
31 #include "InfoBoxes/InfoBoxManager.hpp"
32 #include "InfoBoxes/InfoBoxLayout.hpp"
33 #include "Screen/Layout.hpp"
35 #include "Components.hpp"
36 #include "DrawThread.hpp"
37 #include "FLARM/Glue.hpp"
38 #include "Gauge/GlueGaugeVario.hpp"
39 #include "Gauge/GaugeFLARM.hpp"
40 #include "PeriodClock.hpp"
41 #include "LogFile.hpp"
42 #include "DeviceBlackboard.hpp"
43 #include "CalculationThread.hpp"
44 #include "Task/ProtectedTaskManager.hpp"
45 #include "Profile/Profile.hpp"
46 #include "UIState.hpp"
48 UIState
CommonInterface::ui_state
;
50 bool CommonInterface::movement_detected
= false;
52 bool ActionInterface::force_shutdown
= false;
54 InterfaceBlackboard
CommonInterface::blackboard
;
55 StatusMessageList
CommonInterface::status_messages
;
56 MainWindow
CommonInterface::main_window(status_messages
);
59 CommonInterface::IsPanning()
61 const GlueMapWindow
*map
= main_window
.GetMapIfActive();
62 return map
!= NULL
&& map
->IsPanning();
67 XCSoarInterface::ReceiveGPS()
70 ScopeLock
protect(device_blackboard
->mutex
);
72 ReadBlackboardBasic(device_blackboard
->Basic());
74 const NMEAInfo
&real
= device_blackboard
->RealState();
75 movement_detected
= real
.connected
&& real
.gps
.real
&&
76 real
.MovementDetected();
81 if (!Basic().flarm
.traffic
.empty())
82 /* auto-load FlarmNet when traffic is seen */
87 XCSoarInterface::ReceiveCalculated()
90 ScopeLock
protect(device_blackboard
->mutex
);
92 ReadBlackboardCalculated(device_blackboard
->Calculated());
93 device_blackboard
->ReadComputerSettings(GetComputerSettings());
96 BroadcastCalculatedUpdate();
100 XCSoarInterface::ExchangeBlackboard()
102 ExchangeDeviceBlackboard();
103 SendGetComputerSettings();
108 XCSoarInterface::ExchangeDeviceBlackboard()
110 ScopeLock
protect(device_blackboard
->mutex
);
112 device_blackboard
->ReadComputerSettings(GetComputerSettings());
116 ActionInterface::SendGetComputerSettings()
118 assert(calculation_thread
!= NULL
);
120 main_window
.SetComputerSettings(GetComputerSettings());
122 calculation_thread
->SetComputerSettings(GetComputerSettings());
123 calculation_thread
->SetScreenDistanceMeters(main_window
.GetProjection().GetScreenDistanceMeters());
127 ActionInterface::SetBallast(fixed ballast
, bool to_devices
)
129 // write ballast into settings
130 GlidePolar
&polar
= SetComputerSettings().polar
.glide_polar_task
;
131 polar
.SetBallast(ballast
);
133 // send to calculation thread and trigger recalculation
134 if (protected_task_manager
!= NULL
)
135 protected_task_manager
->SetGlidePolar(polar
);
137 if (calculation_thread
!= NULL
) {
138 calculation_thread
->SetComputerSettings(GetComputerSettings());
139 calculation_thread
->Trigger();
142 // send to external devices
144 device_blackboard
->SetBallast(ballast
);
148 ActionInterface::SetBugs(fixed bugs
, bool to_devices
)
150 // Write Bugs into settings
151 CommonInterface::SetComputerSettings().polar
.SetBugs(bugs
);
152 GlidePolar
&polar
= SetComputerSettings().polar
.glide_polar_task
;
154 // send to calculation thread and trigger recalculation
155 if (protected_task_manager
!= NULL
)
156 protected_task_manager
->SetGlidePolar(polar
);
158 if (calculation_thread
!= NULL
) {
159 calculation_thread
->SetComputerSettings(GetComputerSettings());
160 calculation_thread
->Trigger();
163 // send to external devices
165 device_blackboard
->SetBugs(bugs
);
169 ActionInterface::SetMacCready(fixed mc
, bool to_devices
)
171 // Repeated adjustment of MC with the +/- UI elements could result in
172 // an MC which is slightly larger than 0. Since the calculations
173 // fundamentally change depending on "MC == 0" or "MC <> 0" force
174 // a fixed_zero for small MC values.
175 if (mc
< fixed(0.01))
178 /* update interface settings */
180 GlidePolar
&polar
= SetComputerSettings().polar
.glide_polar_task
;
183 /* update InfoBoxes (that might show the MacCready setting) */
185 InfoBoxManager::SetDirty();
187 /* send to calculation thread and trigger recalculation */
189 if (protected_task_manager
!= NULL
)
190 protected_task_manager
->SetGlidePolar(polar
);
192 if (calculation_thread
!= NULL
) {
193 calculation_thread
->SetComputerSettings(GetComputerSettings());
194 calculation_thread
->Trigger();
197 /* send to external devices */
200 device_blackboard
->SetMC(mc
);
203 void ActionInterface::SetManualMacCready(fixed mc
, bool to_devices
)
205 TaskBehaviour
&task_behaviour
= CommonInterface::SetComputerSettings().task
;
206 if (task_behaviour
.auto_mc
) {
207 task_behaviour
.auto_mc
= false;
208 Profile::Set(szProfileAutoMc
, false);
211 SetMacCready(mc
, to_devices
);
215 ActionInterface::SendMapSettings(const bool trigger_draw
)
217 // trigger_draw: asks for an immediate exchange of blackboard data
218 // (via ProcessTimer()) rather than waiting for the idle timer every 500ms
222 InfoBoxManager::ProcessTimer();
225 main_window
.SetMapSettings(GetMapSettings());
228 main_window
.full_redraw();
229 BroadcastUISettingsUpdate();
232 // TODO: trigger refresh if the settings are changed
236 ActionInterface::SignalShutdown(bool force
)
238 force_shutdown
= force
;
239 main_window
.close(); // signals close
243 XCSoarInterface::CheckShutdown()
248 return MessageBoxX(_("Quit program?"), _T("XCSoar"),
249 MB_YESNO
| MB_ICONQUESTION
) == IDYES
;
253 ActionInterface::DisplayModes()
255 main_window
.UpdateGaugeVisibility();