InputEventsTask: translate task start message
[xcsoar.git] / src / Input / InputEventsTask.cpp
blobe7a70d7b8be3c2d6ed7bb816692da893b50e8fff
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 "InputEvents.hpp"
25 #include "Util/Macros.hpp"
26 #include "Language/Language.hpp"
27 #include "Message.hpp"
28 #include "Components.hpp"
29 #include "Interface.hpp"
30 #include "ActionInterface.hpp"
31 #include "Protection.hpp"
32 #include "Formatter/UserUnits.hpp"
33 #include "Formatter/LocalTimeFormatter.hpp"
34 #include "Units/Units.hpp"
35 #include "Profile/Profile.hpp"
36 #include "Profile/ProfileKeys.hpp"
37 #include "LocalPath.hpp"
38 #include "UIGlobals.hpp"
39 #include "Dialogs/Task/TaskDialogs.hpp"
40 #include "Dialogs/Waypoint/WaypointDialogs.hpp"
41 #include "Task/ProtectedTaskManager.hpp"
42 #include "Task/TaskFile.hpp"
43 #include "Engine/Task/Ordered/OrderedTask.hpp"
44 #include "Engine/Waypoint/Waypoints.hpp"
45 #include "Engine/Navigation/Aircraft.hpp"
47 #include <windef.h> /* for MAX_PATH */
49 static void
50 trigger_redraw()
52 if (!CommonInterface::Basic().location_available)
53 ForceCalculation();
54 TriggerMapUpdate();
57 // ArmAdvance
58 // Controls waypoint advance trigger:
59 // on: Arms the advance trigger
60 // off: Disarms the advance trigger
61 // toggle: Toggles between armed and disarmed.
62 // show: Shows current armed state
63 void
64 InputEvents::eventArmAdvance(const TCHAR *misc)
66 if (protected_task_manager == NULL)
67 return;
69 ProtectedTaskManager::ExclusiveLease task_manager(*protected_task_manager);
70 TaskAdvance &advance = task_manager->SetTaskAdvance();
72 if (StringIsEqual(misc, _T("on"))) {
73 advance.SetArmed(true);
74 } else if (StringIsEqual(misc, _T("off"))) {
75 advance.SetArmed(false);
76 } else if (StringIsEqual(misc, _T("toggle"))) {
77 advance.ToggleArmed();
78 } else if (StringIsEqual(misc, _T("show"))) {
79 switch (advance.GetState()) {
80 case TaskAdvance::MANUAL:
81 Message::AddMessage(_("Advance manually"));
82 break;
83 case TaskAdvance::AUTO:
84 Message::AddMessage(_("Advance automatically"));
85 break;
86 case TaskAdvance::START_ARMED:
87 Message::AddMessage(_("Ready to start"));
88 break;
89 case TaskAdvance::START_DISARMED:
90 Message::AddMessage(_("Hold start"));
91 break;
92 case TaskAdvance::TURN_ARMED:
93 Message::AddMessage(_("Ready to turn"));
94 break;
95 case TaskAdvance::TURN_DISARMED:
96 Message::AddMessage(_("Hold turn"));
97 break;
101 /* quickly propagate the updated values from the TaskManager to the
102 InterfaceBlackboard, so they are available immediately */
103 task_manager->UpdateCommonStatsTask();
104 CommonInterface::ReadCommonStats(task_manager->GetCommonStats());
107 void
108 InputEvents::eventCalculator(gcc_unused const TCHAR *misc)
110 dlgTaskManagerShowModal(UIGlobals::GetMainWindow());
112 trigger_redraw();
115 void
116 InputEvents::eventGotoLookup(gcc_unused const TCHAR *misc)
118 const NMEAInfo &basic = CommonInterface::Basic();
120 if (protected_task_manager == NULL)
121 return;
123 const Waypoint* wp = ShowWaypointListDialog(basic.location);
124 if (wp != NULL) {
125 protected_task_manager->DoGoto(*wp);
126 trigger_redraw();
130 // MacCready
131 // Adjusts MacCready settings
132 // up, down, auto on, auto off, auto toggle, auto show
133 void
134 InputEvents::eventMacCready(const TCHAR *misc)
136 if (protected_task_manager == NULL)
137 return;
139 const GlidePolar &polar =
140 CommonInterface::GetComputerSettings().polar.glide_polar_task;
141 fixed mc = polar.GetMC();
143 TaskBehaviour &task_behaviour = CommonInterface::SetComputerSettings().task;
145 if (StringIsEqual(misc, _T("up"))) {
146 const fixed step = Units::ToSysVSpeed(GetUserVerticalSpeedStep());
147 ActionInterface::OffsetManualMacCready(step);
148 } else if (StringIsEqual(misc, _T("down"))) {
149 const fixed step = Units::ToSysVSpeed(GetUserVerticalSpeedStep());
150 ActionInterface::OffsetManualMacCready(-step);
151 } else if (StringIsEqual(misc, _T("auto toggle"))) {
152 task_behaviour.auto_mc = !task_behaviour.auto_mc;
153 Profile::Set(ProfileKeys::AutoMc, task_behaviour.auto_mc);
154 } else if (StringIsEqual(misc, _T("auto on"))) {
155 task_behaviour.auto_mc = true;
156 Profile::Set(ProfileKeys::AutoMc, true);
157 } else if (StringIsEqual(misc, _T("auto off"))) {
158 task_behaviour.auto_mc = false;
159 Profile::Set(ProfileKeys::AutoMc, false);
160 } else if (StringIsEqual(misc, _T("auto show"))) {
161 if (task_behaviour.auto_mc) {
162 Message::AddMessage(_("Auto. MacCready on"));
163 } else {
164 Message::AddMessage(_("Auto. MacCready off"));
166 } else if (StringIsEqual(misc, _T("show"))) {
167 TCHAR Temp[100];
168 FormatUserVerticalSpeed(mc, Temp, false);
169 Message::AddMessage(_("MacCready "), Temp);
173 // AdjustWaypoint
174 // Adjusts the active waypoint of the task
175 // next: selects the next waypoint, stops at final waypoint
176 // previous: selects the previous waypoint, stops at start waypoint
177 // nextwrap: selects the next waypoint, wrapping back to start after final
178 // previouswrap: selects the previous waypoint, wrapping to final after start
179 void
180 InputEvents::eventAdjustWaypoint(const TCHAR *misc)
182 if (protected_task_manager == NULL)
183 return;
185 if (StringIsEqual(misc, _T("next")))
186 protected_task_manager->IncrementActiveTaskPoint(1); // next
187 else if (StringIsEqual(misc, _T("nextwrap")))
188 protected_task_manager->IncrementActiveTaskPoint(1); // next - with wrap
189 else if (StringIsEqual(misc, _T("previous")))
190 protected_task_manager->IncrementActiveTaskPoint(-1); // previous
191 else if (StringIsEqual(misc, _T("previouswrap")))
192 protected_task_manager->IncrementActiveTaskPoint(-1); // previous with wrap
193 else if (StringIsEqual(misc, _T("nextarm")))
194 protected_task_manager->IncrementActiveTaskPointArm(1); // arm sensitive next
195 else if (StringIsEqual(misc, _T("previousarm")))
196 protected_task_manager->IncrementActiveTaskPointArm(-1); // arm sensitive previous
199 /* quickly propagate the updated values from the TaskManager to
200 the InterfaceBlackboard, so they are available immediately */
201 ProtectedTaskManager::ExclusiveLease tm(*protected_task_manager);
202 tm->UpdateCommonStatsTask();
203 CommonInterface::ReadCommonStats(tm->GetCommonStats());
206 trigger_redraw();
209 // AbortTask
210 // Allows aborting and resuming of tasks
211 // abort: aborts the task if active
212 // resume: resumes the task if aborted
213 // toggle: toggles between abort and resume
214 // show: displays a status message showing the task abort status
215 void
216 InputEvents::eventAbortTask(const TCHAR *misc)
218 if (protected_task_manager == NULL)
219 return;
221 ProtectedTaskManager::ExclusiveLease task_manager(*protected_task_manager);
223 if (StringIsEqual(misc, _T("abort")))
224 task_manager->Abort();
225 else if (StringIsEqual(misc, _T("resume")))
226 task_manager->Resume();
227 else if (StringIsEqual(misc, _T("show"))) {
228 switch (task_manager->GetMode()) {
229 case TaskType::ABORT:
230 Message::AddMessage(_("Task aborted"));
231 break;
232 case TaskType::GOTO:
233 Message::AddMessage(_("Go to target"));
234 break;
235 case TaskType::ORDERED:
236 Message::AddMessage(_("Ordered task"));
237 break;
238 default:
239 Message::AddMessage(_("No task"));
241 } else {
242 // toggle
243 switch (task_manager->GetMode()) {
244 case TaskType::NONE:
245 case TaskType::ORDERED:
246 task_manager->Abort();
247 break;
248 case TaskType::GOTO:
249 if (task_manager->CheckOrderedTask()) {
250 task_manager->Resume();
251 } else {
252 task_manager->Abort();
254 break;
255 case TaskType::ABORT:
256 task_manager->Resume();
257 break;
261 /* quickly propagate the updated values from the TaskManager to the
262 InterfaceBlackboard, so they are available immediately */
263 task_manager->UpdateCommonStatsTask();
264 CommonInterface::ReadCommonStats(task_manager->GetCommonStats());
266 trigger_redraw();
269 // TaskLoad
270 // Loads the task of the specified filename
271 void
272 InputEvents::eventTaskLoad(const TCHAR *misc)
274 if (protected_task_manager == NULL)
275 return;
277 if (!StringIsEmpty(misc)) {
278 TCHAR buffer[MAX_PATH];
279 LocalPath(buffer, misc);
281 OrderedTask *task = TaskFile::GetTask(buffer,
282 CommonInterface::GetComputerSettings().task,
283 &way_points, 0);
284 if (task) {
286 ScopeSuspendAllThreads suspend;
287 task->CheckDuplicateWaypoints(way_points);
288 way_points.Optimise();
291 task->FillMatPoints(way_points);
292 protected_task_manager->TaskCommit(*task);
293 delete task;
297 trigger_redraw();
300 // TaskSave
301 // Saves the task to the specified filename
302 void
303 InputEvents::eventTaskSave(const TCHAR *misc)
305 if (protected_task_manager == NULL)
306 return;
308 if (!StringIsEmpty(misc)) {
309 TCHAR buffer[MAX_PATH];
310 LocalPath(buffer, misc);
311 protected_task_manager->TaskSave(buffer);
315 void
316 InputEvents::eventTaskTransition(const TCHAR *misc)
318 if (protected_task_manager == NULL)
319 return;
321 if (StringIsEqual(misc, _T("start"))) {
322 AircraftState start_state = protected_task_manager->GetStartState();
324 TCHAR TempTime[40];
325 TCHAR TempAlt[40];
326 TCHAR TempSpeed[40];
328 FormatLocalTimeHHMM(TempTime, (int)start_state.time,
329 CommonInterface::GetComputerSettings().utc_offset);
330 FormatUserAltitude(start_state.altitude, TempAlt, true);
331 FormatUserSpeed(start_state.ground_speed,TempSpeed, true);
333 TCHAR TempAll[120];
334 _stprintf(TempAll, _T("\r\n%s: %s\r\n%s:%s\r\n%s: %s"),
335 _("Altitude"), TempAlt,
336 _("Speed"), TempSpeed,
337 _("Time"), TempTime);
338 Message::AddMessage(_("Task start"), TempAll);
339 } else if (StringIsEqual(misc, _T("tp"))) {
340 Message::AddMessage(_("Next turnpoint"));
341 } else if (StringIsEqual(misc, _T("finish"))) {
342 Message::AddMessage(_("Task finished"));
343 } else if (StringIsEqual(misc, _T("ready"))) {
344 Message::AddMessage(_("In sector, arm advance when ready"));