Debian Codegraph @

Server/Web/WebClientRoute.cpp

raw symbols ◀ ▶ SCIP
2 Debian patches touch this file
1 /*
2 RailControl - Model Railway Control Software
3
4 Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org
5
6 RailControl is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
9 later version.
10
11 RailControl is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with RailControl; see the file LICENCE. If not see
18 <http://www.gnu.org/licenses/>.
19 */
20
21 #include <map>
22 #include <string>
23 #include <utility>
24 #include <vector>
25
26 #include "DataModel/DataModel.h"
27 #include "DataModel/ObjectIdentifier.h"
28 #include "Server/Web/HtmlTagButton.h"
29 #include "Server/Web/HtmlTagButtonCancel.h"
30 #include "Server/Web/HtmlTagButtonCommandWide.h"
31 #include "Server/Web/HtmlTagButtonOK.h"
32 #include "Server/Web/HtmlTagButtonPopupWide.h"
33 #include "Server/Web/HtmlTagButtonSwapRelation.h"
34 #include "Server/Web/HtmlTagInputCheckboxWithLabel.h"
35 #include "Server/Web/HtmlTagInputHidden.h"
36 #include "Server/Web/HtmlTagInputIntegerWithLabel.h"
37 #include "Server/Web/HtmlTagInputTextWithLabel.h"
38 #include "Server/Web/HtmlTagRoute.h"
39 #include "Server/Web/HtmlTagSelect.h"
40 #include "Server/Web/HtmlTagSelectMultipleWithLabel.h"
41 #include "Server/Web/HtmlTagSelectOrientation.h"
42 #include "Server/Web/HtmlTagSelectWithLabel.h"
43 #include "Server/Web/HtmlTagSpace.h"
44 #include "Server/Web/WebClient.h"
45 #include "Server/Web/WebClientRoute.h"
46 #include "Server/Web/WebClientStatic.h"
47 #include "Utils/Integer.h"
48
49 using namespace DataModel;
50 using LayoutPosition = DataModel::LayoutItem::LayoutPosition;
51 using LayoutItemSize = DataModel::LayoutItem::LayoutItemSize;
52 using LayoutRotation = DataModel::LayoutItem::LayoutRotation;
53 using Visible = DataModel::LayoutItem::Visible;
54 using std::map;
55 using std::pair;
56 using std::string;
57 using std::to_string;
58 using std::vector;
59
60 namespace Server { namespace Web
61 {
62 void WebClientRoute::HandleRouteGet(const map<string, string>& arguments)
63 {
64 RouteID routeID = Utils::Utils::GetIntegerMapEntry(arguments, "route");
65 const DataModel::Route* route = manager.GetRoute(routeID);
66 if (route == nullptr || route->GetVisible() == DataModel::LayoutItem::VisibleNo)
67 {
68 client.ReplyHtmlWithHeader(HtmlTag());
69 return;
70 }
71 client.ReplyHtmlWithHeader(HtmlTagRoute(route));
72 }
73
74 void WebClientRoute::HandleRouteEdit(const map<string, string>& arguments)
75 {
76 HtmlTag content;
•77 const RouteID routeID = Utils::Utils::GetIntegerMapEntry(arguments, "route", RouteNone);
78 string name = Languages::GetText(Languages::TextNew);
79 Delay delay = Route::DefaultDelay;
80 Route::PushpullType pushpull = Route::PushpullTypeBoth;
81 Propulsion propulsion = PropulsionAll;
82 TrainType trainType = TrainTypeAll;
83 Length minTrainLength = 0;
84 Length maxTrainLength = 0;
85 vector<Relation*> relationsAtLock;
86 vector<Relation*> relationsAtUnlock;
87 LayoutPosition posx = Utils::Utils::GetIntegerMapEntry(arguments, "posx", 0);
88 LayoutPosition posy = Utils::Utils::GetIntegerMapEntry(arguments, "posy", 0);
89 LayoutPosition posz = Utils::Utils::GetIntegerMapEntry(arguments, "posz", LayerUndeletable);
90 DataModel::LayoutItem::Visible visible = static_cast<Visible>(Utils::Utils::GetBoolMapEntry(arguments, "visible", routeID == RouteNone && ((posx || posy) && posz >= LayerUndeletable) ? DataModel::LayoutItem::VisibleYes : DataModel::LayoutItem::VisibleNo));
91 Automode automode = static_cast<Automode>(Utils::Utils::GetBoolMapEntry(arguments, "automode", AutomodeNo));
92 TrackID fromTrack = static_cast<TrackID>(Utils::Utils::GetIntegerMapEntry(arguments, "fromtrack", TrackNone));
93 Orientation fromOrientation = static_cast<Orientation>(Utils::Utils::GetBoolMapEntry(arguments, "fromorientation", OrientationRight));
94 TrackID toTrack = static_cast<TrackID>(Utils::Utils::GetIntegerMapEntry(arguments, "totrack", TrackNone));
95 Orientation toOrientation = static_cast<Orientation>(Utils::Utils::GetBoolMapEntry(arguments, "toorientation", OrientationRight));
96 Route::Speed speed = static_cast<Route::Speed>(Utils::Utils::GetIntegerMapEntry(arguments, "speed", Route::SpeedTravel));
97 FeedbackID feedbackIdReduced = Utils::Utils::GetIntegerMapEntry(arguments, "feedbackreduced", FeedbackNone);
98 Delay reducedDelay = Utils::Utils::GetIntegerMapEntry(arguments, "reduceddelay", 0);
99 FeedbackID feedbackIdCreep = Utils::Utils::GetIntegerMapEntry(arguments, "feedbackcreep", FeedbackNone);
100 Delay creepDelay = Utils::Utils::GetIntegerMapEntry(arguments, "creepdelay", 0);
101 FeedbackID feedbackIdStop = Utils::Utils::GetIntegerMapEntry(arguments, "feedbackstop", FeedbackNone);
102 Delay stopDelay = Utils::Utils::GetIntegerMapEntry(arguments, "stopdelay", 0);
103 FeedbackID feedbackIdOver = Utils::Utils::GetIntegerMapEntry(arguments, "feedbackover", FeedbackNone);
104 Pause waitAfterRelease = Utils::Utils::GetIntegerMapEntry(arguments, "waitafterrelease", 0);
105 RouteID followUpRoute = Utils::Utils::GetIntegerMapEntry(arguments, "followuproute", RouteNone);
106 if (routeID > RouteNone)
107 {
108 const DataModel::Route* route = manager.GetRoute(routeID);
109 if (route != nullptr)
110 {
111 name = route->GetName();
112 delay = route->GetDelay();
113 pushpull = route->GetPushpull();
114 propulsion = route->GetPropulsion();
115 trainType = route->GetTrainType();
116 minTrainLength = route->GetMinTrainLength();
117 maxTrainLength = route->GetMaxTrainLength();
118 relationsAtLock = route->GetRelationsAtLock();
119 relationsAtUnlock = route->GetRelationsAtUnlock();
120 visible = route->GetVisible();
121 posx = route->GetPosX();
122 posy = route->GetPosY();
123 posz = route->GetPosZ();
124 automode = route->GetAutomode();
125 fromTrack = route->GetFromTrack();
126 fromOrientation = route->GetFromOrientation();
127 toTrack = route->GetToTrack();
128 toOrientation = route->GetToOrientation();
129 speed = route->GetSpeed();
130 feedbackIdReduced = route->GetFeedbackIdReduced();
131 reducedDelay = route->GetReducedDelay();
132 feedbackIdCreep = route->GetFeedbackIdCreep();
133 creepDelay = route->GetCreepDelay();
134 feedbackIdStop = route->GetFeedbackIdStop();
135 stopDelay = route->GetStopDelay();
136 feedbackIdOver = route->GetFeedbackIdOver();
137 waitAfterRelease = route->GetWaitAfterRelease();
138 followUpRoute = route->GetFollowUpRoute();
139 }
140 }
141
142 content.AddChildTag(HtmlTag("h1").AddContent(name).AddId("popup_title"));
143 HtmlTag tabMenu("div");
144 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("basic", Languages::TextBasic, true));
145 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("relationatlock", Languages::TextAtLock));
146 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("relationatunlock", Languages::TextAtUnlock, false, !automode));
147 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("position", Languages::TextPosition));
148 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("automode", Languages::TextAutomode));
149 content.AddChildTag(tabMenu);
150
151 HtmlTag formContent("form");
152 formContent.AddId("editform");
153 formContent.AddChildTag(HtmlTagInputHidden("cmd", "routesave"));
154 formContent.AddChildTag(HtmlTagInputHidden("route", to_string(routeID)));
155
156 HtmlTag basicContent("div");
157 basicContent.AddId("tab_basic");
158 basicContent.AddClass("tab_content");
159 basicContent.AddChildTag(HtmlTagInputTextWithLabel("name", Languages::TextName, name).AddAttribute("onkeyup", "updateName();"));
160 basicContent.AddChildTag(HtmlTagInputIntegerWithLabel("delay", Languages::TextWaitingTimeBetweenMembers, delay, 1, USHRT_MAX));
161 formContent.AddChildTag(basicContent);
162
163 HtmlTag relationDivAtLock("div");
164 relationDivAtLock.AddId("relationatlock");
165 Priority priorityAtLock = 1;
166 for (auto relation : relationsAtLock)
167 {
168 relationDivAtLock.AddChildTag(HtmlTagRelation("atlock", relation->GetPriority(), relation->ObjectType2(), relation->ObjectID2(), relation->GetData()));
169 priorityAtLock = relation->GetPriority() + 1;
170 }
171 relationDivAtLock.AddChildTag(HtmlTagInputHidden("relationcounteratlock", to_string(priorityAtLock)));
172 relationDivAtLock.AddChildTag(HtmlTag("div").AddId("new_atlock_priority_" + to_string(priorityAtLock)));
173
174 HtmlTag relationContentAtLock("div");
175 relationContentAtLock.AddId("tab_relationatlock");
176 relationContentAtLock.AddClass("tab_content");
177 relationContentAtLock.AddClass("hidden");
178 relationContentAtLock.AddChildTag(relationDivAtLock);
179 HtmlTagButton newButtonAtLock(Languages::TextNew, "newrelationatlock");
180 newButtonAtLock.AddAttribute("onclick", "addRelation('atlock');return false;");
181 newButtonAtLock.AddClass("wide_button");
182 relationContentAtLock.AddChildTag(newButtonAtLock);
183 relationContentAtLock.AddChildTag(HtmlTag("br"));
184 formContent.AddChildTag(relationContentAtLock);
185
186 HtmlTag relationDivAtUnlock("div");
187 relationDivAtUnlock.AddId("relationatunlock");
188 Priority priorityAtUnlock = 1;
189 for (auto relation : relationsAtUnlock)
190 {
191 relationDivAtUnlock.AddChildTag(HtmlTagRelation("atunlock", relation->GetPriority(), relation->ObjectType2(), relation->ObjectID2(), relation->GetData()));
192 priorityAtUnlock = relation->GetPriority() + 1;
193 }
194 relationDivAtUnlock.AddChildTag(HtmlTagInputHidden("relationcounteratunlock", to_string(priorityAtUnlock)));
195 relationDivAtUnlock.AddChildTag(HtmlTag("div").AddId("new_atunlock_priority_" + to_string(priorityAtUnlock)));
196
197 HtmlTag relationContentAtUnlock("div");
198 relationContentAtUnlock.AddId("tab_relationatunlock");
199 relationContentAtUnlock.AddClass("tab_content");
200 relationContentAtUnlock.AddClass("hidden");
201 relationContentAtUnlock.AddChildTag(relationDivAtUnlock);
202 HtmlTagButton newButtonAtUnlock(Languages::TextNew, "newrelationatunlock");
203 newButtonAtUnlock.AddAttribute("onclick", "addRelation('atunlock');return false;");
204 newButtonAtUnlock.AddClass("wide_button");
205 relationContentAtUnlock.AddChildTag(newButtonAtUnlock);
206 relationContentAtUnlock.AddChildTag(HtmlTag("br"));
207 formContent.AddChildTag(relationContentAtUnlock);
208
209 formContent.AddChildTag(client.HtmlTagTabPosition(posx, posy, posz, visible));
210
211 HtmlTag automodeContent("div");
212 automodeContent.AddId("tab_automode");
213 automodeContent.AddClass("tab_content");
214 automodeContent.AddClass("hidden");
215
216 HtmlTagInputCheckboxWithLabel checkboxAutomode("automode", Languages::TextAutomode, "automode", static_cast<bool>(automode));
217 checkboxAutomode.AddId("automode");
218 checkboxAutomode.AddAttribute("onchange", "onChangeCheckboxShowHide('automode', 'tracks', 'tab_button_relationatunlock');");
219 automodeContent.AddChildTag(checkboxAutomode);
220
221 HtmlTag tracksDiv("div");
222 tracksDiv.AddId("tracks");
223 if (automode == AutomodeNo)
224 {
225 tracksDiv.AddAttribute("hidden");
226 }
227 tracksDiv.AddChildTag(HtmlTagSelectTrack("from", Languages::TextStartTrack, fromTrack, fromOrientation));
228 tracksDiv.AddChildTag(HtmlTagSelectTrack("to", Languages::TextDestinationTrack, toTrack, toOrientation, "updateFeedbacksOfTrack(); return false;"));
229
230 map<Route::Speed,Languages::TextSelector> speedOptions;
231 speedOptions[Route::SpeedTravel] = Languages::TextTravelSpeed;
232 speedOptions[Route::SpeedReduced] = Languages::TextReducedSpeed;
233 speedOptions[Route::SpeedCreeping] = Languages::TextCreepingSpeed;
234 tracksDiv.AddChildTag(HtmlTagSelectWithLabel("speed", Languages::TextSpeed, speedOptions, speed));
235 HtmlTag feedbackDiv("div");
236 feedbackDiv.AddId("feedbacks");
237 feedbackDiv.AddChildTag(HtmlTagSelectFeedbacksOfTrack(toTrack, followUpRoute, feedbackIdReduced, reducedDelay, feedbackIdCreep, creepDelay, feedbackIdStop, stopDelay, feedbackIdOver));
238 tracksDiv.AddChildTag(feedbackDiv);
239
240 map<Route::PushpullType,Languages::TextSelector> pushpullOptions;
241 pushpullOptions[Route::PushpullTypeNo] = Languages::TextNoPushPull;
242 pushpullOptions[Route::PushpullTypeBoth] = Languages::TextAllTrains;
243 pushpullOptions[Route::PushpullTypeOnly] = Languages::TextPushPullOnly;
244 tracksDiv.AddChildTag(HtmlTagSelectWithLabel("pushpull", Languages::TextAllowedPushPull, pushpullOptions, pushpull));
245
246 vector<pair<Propulsion,Languages::TextSelector>> propulsionOptions;
247 propulsionOptions.push_back(pair<Propulsion,Languages::TextSelector>(PropulsionAll,Languages::TextPropulsionAll));
248 propulsionOptions.push_back(pair<Propulsion,Languages::TextSelector>(PropulsionSteam,Languages::TextPropulsionSteam));
249 propulsionOptions.push_back(pair<Propulsion,Languages::TextSelector>(PropulsionDiesel,Languages::TextPropulsionDiesel));
250 propulsionOptions.push_back(pair<Propulsion,Languages::TextSelector>(PropulsionGas,Languages::TextPropulsionGas));
251 propulsionOptions.push_back(pair<Propulsion,Languages::TextSelector>(PropulsionElectric,Languages::TextPropulsionElectric));
252 propulsionOptions.push_back(pair<Propulsion,Languages::TextSelector>(PropulsionHydrogen,Languages::TextPropulsionHydrogen));
253 propulsionOptions.push_back(pair<Propulsion,Languages::TextSelector>(PropulsionAccu,Languages::TextPropulsionAccu));
254 propulsionOptions.push_back(pair<Propulsion,Languages::TextSelector>(PropulsionOther,Languages::TextPropulsionOther));
255 tracksDiv.AddChildTag(HtmlTagSelectMultipleWithLabel("propulsion", Languages::TextAllowedPropulsions, propulsionOptions, propulsion));
256
257 vector<pair<TrainType,Languages::TextSelector>> trainTypeOptions;
258 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeAll,Languages::TextTrainTypeAll));
259 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypePassenger,Languages::TextTrainTypePassenger));
260 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeInternationalHighSpeed,Languages::TextTrainTypeInternationalHighSpeed));
261 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeNationalHighSpeed,Languages::TextTrainTypeNationalHighSpeed));
262 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeInternationalLongDistance,Languages::TextTrainTypeInternationalLongDistance));
263 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeNationalLongDistance,Languages::TextTrainTypeNationalLongDistance));
264 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeInternationalNight,Languages::TextTrainTypeInternationalNight));
265 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeNationalNight,Languages::TextTrainTypeNationalNight));
266 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeLongDistanceFastLocal,Languages::TextTrainTypeLongDistanceFastLocal));
267 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeFastLocal,Languages::TextTrainTypeFastLocal));
268 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeLocal,Languages::TextTrainTypeLocal));
269 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeSuburban,Languages::TextTrainTypeSuburban));
270 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeUnderground,Languages::TextTrainTypeUnderground));
271 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeHistoric,Languages::TextTrainTypeHistoric));
272 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeExtra,Languages::TextTrainTypeExtra));
273 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypePassengerWithCargo,Languages::TextTrainTypePassengerWithCargo));
274 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeCargo,Languages::TextTrainTypeCargo));
275 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeCargoLongDistance,Languages::TextTrainTypeCargoLongDistance));
276 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeCargoLocal,Languages::TextTrainTypeCargoLocal));
277 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeCargoBlock,Languages::TextTrainTypeCargoBlock));
278 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeCargoTractor,Languages::TextTrainTypeCargoTractor));
279 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeCargoExpress,Languages::TextTrainTypeCargoExpress));
280 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeCargoWithPassenger,Languages::TextTrainTypeCargoWithPassenger));
281 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeRescue,Languages::TextTrainTypeRescue));
282 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeConstruction,Languages::TextTrainTypeConstruction));
283 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeEmpty,Languages::TextTrainTypeEmpty));
284 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeLoco,Languages::TextTrainTypeLoco));
285 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeCleaning,Languages::TextTrainTypeCleaning));
286 trainTypeOptions.push_back(pair<TrainType,Languages::TextSelector>(TrainTypeOther,Languages::TextTrainTypeOther));
287 tracksDiv.AddChildTag(HtmlTagSelectMultipleWithLabel("traintype", Languages::TextAllowedTrainTypes, trainTypeOptions, trainType));
288
289 tracksDiv.AddChildTag(HtmlTagInputIntegerWithLabel("mintrainlength", Languages::TextMinTrainLength, minTrainLength, 0, 99999));
290 tracksDiv.AddChildTag(HtmlTagInputIntegerWithLabel("maxtrainlength", Languages::TextMaxTrainLength, maxTrainLength, 0, 99999));
291 tracksDiv.AddChildTag(HtmlTagInputIntegerWithLabel("waitafterrelease", Languages::TextWaitAfterRelease, waitAfterRelease, 0, 300));
292
293 automodeContent.AddChildTag(tracksDiv);
294 formContent.AddChildTag(automodeContent);
295
296 content.AddChildTag(HtmlTag("div").AddClass("popup_content").AddChildTag(formContent));
297 content.AddChildTag(HtmlTagButtonCancel());
298 content.AddChildTag(HtmlTagButtonOK());
299 client.ReplyHtmlWithHeader(content);
300 }
301
302 void WebClientRoute::HandleRouteSave(const map<string, string>& arguments)
303 {
304 const RouteID routeID = Utils::Utils::GetIntegerMapEntry(arguments, "route", RouteNone);
305 const string name = Utils::Utils::GetStringMapEntry(arguments, "name");
306 const Delay delay = static_cast<Delay>(Utils::Utils::GetIntegerMapEntry(arguments, "delay"));
307 const Route::PushpullType pushpull = static_cast<Route::PushpullType>(Utils::Utils::GetIntegerMapEntry(arguments, "pushpull", Route::PushpullTypeBoth));
308 Propulsion propulsion = static_cast<Propulsion>(Utils::Utils::GetIntegerMapEntry(arguments, "propulsion", PropulsionAll));
309 if (propulsion == PropulsionUnknown)
310 {
311 propulsion = PropulsionAll;
312 }
313 TrainType trainType = static_cast<TrainType>(Utils::Utils::GetIntegerMapEntry(arguments, "traintype", TrainTypeAll));
314 if (trainType == TrainTypeUnknown)
315 {
316 trainType = TrainTypeAll;
317 }
318 const Length mintrainlength = static_cast<Length>(Utils::Utils::GetIntegerMapEntry(arguments, "mintrainlength", 0));
319 const Length maxtrainlength = static_cast<Length>(Utils::Utils::GetIntegerMapEntry(arguments, "maxtrainlength", 0));
320 const Visible visible = static_cast<Visible>(Utils::Utils::GetBoolMapEntry(arguments, "visible"));
321 const LayoutPosition posx = Utils::Utils::GetIntegerMapEntry(arguments, "posx", 0);
322 const LayoutPosition posy = Utils::Utils::GetIntegerMapEntry(arguments, "posy", 0);
323 const LayoutPosition posz = Utils::Utils::GetIntegerMapEntry(arguments, "posz", 0);
324 const Automode automode = static_cast<Automode>(Utils::Utils::GetBoolMapEntry(arguments, "automode"));
325 const TrackID fromTrack = static_cast<TrackID>(Utils::Utils::GetIntegerMapEntry(arguments, "fromtrack", TrackNone));
326 const Orientation fromOrientation = static_cast<Orientation>(Utils::Utils::GetBoolMapEntry(arguments, "fromorientation", OrientationRight));
327 const TrackID toTrack = static_cast<TrackID>(Utils::Utils::GetIntegerMapEntry(arguments, "totrack", TrackNone));
328 const Orientation toOrientation = static_cast<Orientation>(Utils::Utils::GetBoolMapEntry(arguments, "toorientation", OrientationRight));
329 const Route::Speed speed = static_cast<Route::Speed>(Utils::Utils::GetIntegerMapEntry(arguments, "speed", Route::SpeedTravel));
330 const FeedbackID feedbackIdReduced = Utils::Utils::GetIntegerMapEntry(arguments, "feedbackreduced", FeedbackNone);
331 const Delay reducedDelay = Utils::Utils::GetIntegerMapEntry(arguments, "reduceddelay", 0);
332 const FeedbackID feedbackIdCreep = Utils::Utils::GetIntegerMapEntry(arguments, "feedbackcreep", FeedbackNone);
333 const Delay creepDelay = Utils::Utils::GetIntegerMapEntry(arguments, "creepdelay", 0);
334 const FeedbackID feedbackIdStop = Utils::Utils::GetIntegerMapEntry(arguments, "feedbackstop", FeedbackNone);
335 const Delay stopDelay = Utils::Utils::GetIntegerMapEntry(arguments, "stopdelay", 0);
336 const FeedbackID feedbackIdOver = Utils::Utils::GetIntegerMapEntry(arguments, "feedbackover", FeedbackNone);
337 const Pause waitAfterRelease = Utils::Utils::GetIntegerMapEntry(arguments, "waitafterrelease", 0);
338 const RouteID followUpRoute = Utils::Utils::GetIntegerMapEntry(arguments, "followuproute", RouteNone);
339
340 Priority relationCountAtLock = Utils::Utils::GetIntegerMapEntry(arguments, "relationcounteratlock", 0);
341 Priority relationCountAtUnlock = Utils::Utils::GetIntegerMapEntry(arguments, "relationcounteratunlock", 0);
342
343 vector<Relation*> relationsAtLock;
344 Priority priorityAtLock = 1;
345 for (Priority relationId = 1; relationId <= relationCountAtLock; ++relationId)
346 {
347 string priorityString = to_string(relationId);
348 ObjectType objectType = static_cast<ObjectType>(Utils::Utils::GetIntegerMapEntry(arguments, "relation_atlock_" + priorityString + "_type"));
349 ObjectID objectId = Utils::Utils::GetIntegerMapEntry(arguments, "relation_atlock_" + priorityString + "_id", ObjectNone);
350 if (objectId == 0
351 && objectType != ObjectTypeLoco
352 && objectType != ObjectTypePause
353 && objectType != ObjectTypeMultipleUnit
354 && objectType != ObjectTypeBooster)
355 {
356 continue;
357 }
358 if (objectId == fromTrack && objectType == ObjectTypeTrack)
359 {
360 continue;
361 }
362 if (objectId == toTrack && objectType == ObjectTypeTrack)
363 {
364 continue;
365 }
366 unsigned short state = Utils::Utils::GetIntegerMapEntry(arguments, "relation_atlock_" + priorityString + "_state");
367 relationsAtLock.push_back(new Relation(&manager,
368 ObjectIdentifier(ObjectTypeRoute, routeID),
369 ObjectIdentifier(objectType, objectId),
370 Relation::RelationTypeRouteAtLock,
371 priorityAtLock,
372 state));
373 ++priorityAtLock;
374 }
375
376 vector<Relation*> relationsAtUnlock;
377 Priority priorityAtUnlock = 1;
378 for (Priority relationId = 1; relationId <= relationCountAtUnlock; ++relationId)
379 {
380 string priorityString = to_string(relationId);
381 ObjectType objectType = static_cast<ObjectType>(Utils::Utils::GetIntegerMapEntry(arguments, "relation_atunlock_" + priorityString + "_type"));
382 ObjectID objectId = Utils::Utils::GetIntegerMapEntry(arguments, "relation_atunlock_" + priorityString + "_id", ObjectNone);
383 if (objectId == 0
384 && objectType != ObjectTypeLoco
385 && objectType != ObjectTypePause
386 && objectType != ObjectTypeMultipleUnit
387 && objectType != ObjectTypeBooster)
388 {
389 continue;
390 }
391 if (objectId == fromTrack && objectType == ObjectTypeTrack)
392 {
393 continue;
394 }
395 if (objectId == toTrack && objectType == ObjectTypeTrack)
396 {
397 continue;
398 }
399 unsigned char state = Utils::Utils::GetIntegerMapEntry(arguments, "relation_atunlock_" + priorityString + "_state");
400 relationsAtUnlock.push_back(new Relation(&manager,
401 ObjectIdentifier(ObjectTypeRoute, routeID),
402 ObjectIdentifier(objectType, objectId),
403 Relation::RelationTypeRouteAtUnlock,
404 priorityAtUnlock,
405 state));
406 ++priorityAtUnlock;
407 }
408
409 string result;
410 if (!manager.RouteSave(routeID,
411 name,
412 delay,
413 pushpull,
414 propulsion,
415 trainType,
416 mintrainlength,
417 maxtrainlength,
418 relationsAtLock,
419 relationsAtUnlock,
420 visible,
421 posx,
422 posy,
423 posz,
424 automode,
425 fromTrack,
426 fromOrientation,
427 toTrack,
428 toOrientation,
429 speed,
430 feedbackIdReduced,
431 reducedDelay,
432 feedbackIdCreep,
433 creepDelay,
434 feedbackIdStop,
435 stopDelay,
436 feedbackIdOver,
437 waitAfterRelease,
438 followUpRoute,
439 result))
440 {
441 client.ReplyResponse(client.ResponseError, result);
442 return;
443 }
444 client.ReplyResponse(client.ResponseInfo, Languages::TextRouteSaved, name);
445 }
446
447 void WebClientRoute::HandleRouteAskDelete(const map<string, string>& arguments)
448 {
449 RouteID routeID = Utils::Utils::GetIntegerMapEntry(arguments, "route", RouteNone);
450
451 if (routeID == RouteNone)
452 {
453 client.ReplyHtmlWithHeaderAndParagraph(Languages::TextRouteDoesNotExist);
454 return;
455 }
456
457 const DataModel::Route* route = manager.GetRoute(routeID);
458 if (route == nullptr)
459 {
460 client.ReplyHtmlWithHeaderAndParagraph(Languages::TextRouteDoesNotExist);
461 return;
462 }
463
464 HtmlTag content;
465 const string& routeName = route->GetName();
466 content.AddContent(HtmlTag("h1").AddContent(Languages::TextDeleteRoute));
467 content.AddContent(HtmlTag("p").AddContent(Languages::TextAreYouSureToDelete, routeName));
468 content.AddContent(HtmlTag("form").AddId("editform")
469 .AddContent(HtmlTagInputHidden("cmd", "routedelete"))
470 .AddContent(HtmlTagInputHidden("route", to_string(routeID))
471 ));
472 content.AddContent(HtmlTagButtonCancel());
473 content.AddContent(HtmlTagButtonOK());
474 client.ReplyHtmlWithHeader(content);
475 }
476
477 void WebClientRoute::HandleRouteDelete(const map<string, string>& arguments)
478 {
479 RouteID routeID = Utils::Utils::GetIntegerMapEntry(arguments, "route", RouteNone);
480 const DataModel::Route* route = manager.GetRoute(routeID);
481 if (route == nullptr)
482 {
483 client.ReplyResponse(client.ResponseError, Languages::TextRouteDoesNotExist);
484 return;
485 }
486
487 string name = route->GetName();
488 string result;
489 if (!manager.RouteDelete(routeID, result))
490 {
491 client.ReplyResponse(client.ResponseError, result);
492 return;
493 }
494
495 client.ReplyResponse(client.ResponseInfo, Languages::TextRouteDeleted, name);
496 }
497
498 void WebClientRoute::HandleRouteList()
499 {
500 HtmlTag content;
501 content.AddChildTag(HtmlTag("h1").AddContent(Languages::TextRoutes));
502 HtmlTag table("table");
503 const map<string,DataModel::Route*> routeList = manager.RouteListByName();
504 map<string,string> routeArgument;
505 for (auto& route : routeList)
506 {
507 HtmlTag row("tr");
508 row.AddChildTag(HtmlTag("td").AddContent(route.first));
509 const string& routeIdString = to_string(route.second->GetID());
510 routeArgument["route"] = routeIdString;
511 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonPopupWide(Languages::TextEdit, "routeedit_list_" + routeIdString, routeArgument)));
512 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonPopupWide(Languages::TextDelete, "routeaskdelete_" + routeIdString, routeArgument)));
513 if (route.second->IsInUse())
514 {
515 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonCommandWide(Languages::TextRelease, "routerelease_" + routeIdString, routeArgument, "hideElement('b_routerelease_" + routeIdString + "');")));
516 }
517 table.AddChildTag(row);
518 }
519 content.AddChildTag(HtmlTag("div").AddClass("popup_content").AddChildTag(table));
520 content.AddChildTag(HtmlTagButtonCancel());
521 content.AddChildTag(HtmlTagButtonPopupWide(Languages::TextNew, "routeedit_0"));
522 client.ReplyHtmlWithHeader(content);
523 }
524
525 void WebClientRoute::HandleRouteExecute(const map<string, string>& arguments)
526 {
527 RouteID routeID = Utils::Utils::GetIntegerMapEntry(arguments, "route", RouteNone);
528 manager.RouteExecuteAsync(logger, routeID);
529 client.ReplyHtmlWithHeaderAndParagraph("Route executed");
530 }
531
532 void WebClientRoute::HandleRouteRelease(const map<string, string>& arguments)
533 {
534 RouteID routeID = Utils::Utils::GetIntegerMapEntry(arguments, "route");
535 bool ret = manager.RouteRelease(routeID);
536 client.ReplyHtmlWithHeaderAndParagraph(ret ? "Route released" : "Route not released");
537 }
538
539 void WebClientRoute::HandleRelationAdd(const map<string, string>& arguments)
540 {
541 string priorityString = Utils::Utils::GetStringMapEntry(arguments, "priority", "1");
542 string type = Utils::Utils::GetStringMapEntry(arguments, "type", "atunlock");
543 if (type.compare("atunlock") != 0)
544 {
545 type = "atlock";
546 }
547 Priority priority = Utils::Integer::StringToInteger(priorityString, 1);
548 HtmlTag container;
549 container.AddChildTag(HtmlTagRelation(type, priority));
550 container.AddChildTag(HtmlTag("div").AddId("new_" + type + "_priority_" + to_string(priority + 1)));
551 client.ReplyHtmlWithHeader(container);
552 }
553
554 void WebClientRoute::HandleRelationObject(const map<string, string>& arguments)
555 {
556 const string priority = Utils::Utils::GetStringMapEntry(arguments, "priority");
557 const string atlock = Utils::Utils::GetStringMapEntry(arguments, "atlock");
558 const ObjectType objectType = static_cast<ObjectType>(Utils::Utils::GetIntegerMapEntry(arguments, "objecttype"));
559 const ObjectID id = static_cast<ObjectID>(Utils::Utils::GetIntegerMapEntry(arguments, "id"));
560 const DataModel::Relation::Data state = static_cast<DataModel::Relation::Data>(Utils::Utils::GetIntegerMapEntry(arguments, "state"));
561 client.ReplyHtmlWithHeader(HtmlTagRelationObject(atlock, priority, objectType, id, state));
562 }
563
564 void WebClientRoute::HandleRelationSwitchStates(const map<string, string>& arguments)
565 {
566 const string name = Utils::Utils::GetStringMapEntry(arguments, "name");
567 const SwitchID switchId = static_cast<SwitchID>(Utils::Utils::GetIntegerMapEntry(arguments, "switch"));
568 client.ReplyHtmlWithHeader(HtmlTagRelationSwitchState(name, switchId));
569 }
570
571 HtmlTag WebClientRoute::HtmlTagRelation(const string& atlock,
572 const Priority priority,
573 const ObjectType objectType,
574 const ObjectID objectId,
575 const DataModel::Relation::Data state)
576 {
577 HtmlTag content("div");
578 string priorityString = to_string(priority);
579 string name = "relation_" + atlock + "_" + priorityString;
580 content.AddId(name);
581 HtmlTagButton deleteButton(Languages::TextDelete, "delete_" + name);
582 deleteButton.AddAttribute("onclick", "deleteElement('" + name + "');return false;");
583 deleteButton.AddClass("wide_button");
584 content.AddChildTag(deleteButton);
585
586 if (priority > 1)
587 {
588 content.AddChildTag(HtmlTagButtonSwapRelation(atlock, priorityString, true));
589 }
590 else
591 {
592 content.AddChildTag(HtmlTagSpace().AddClass("small_button").AddClass("button_replacement"));
593 }
594 content.AddChildTag(HtmlTagButtonSwapRelation(atlock, priorityString, false));
595
596 HtmlTag contentObject("div");
597 contentObject.AddId(name + "_object");
598 contentObject.AddClass("inline-block");
599 contentObject.AddChildTag(HtmlTagRelationObject(atlock, priorityString, objectType, objectId, state));
600 content.AddChildTag(contentObject);
601 return content;
602 }
603
604 HtmlTag WebClientRoute::HtmlTagRelationSwitchState(const string& name,
605 const SwitchID switchId,
606 const DataModel::Relation::Data data)
607 {
608 map<DataModel::AccessoryState,Languages::TextSelector> stateOptions;
609 Switch* mySwitch = manager.GetSwitch(switchId);
610 if (mySwitch != nullptr)
611 {
612 stateOptions = mySwitch->GetStateOptions();
613 }
614
615 return HtmlTagSelect(name + "_state", stateOptions, static_cast<DataModel::AccessoryState>(data)).AddClass("select_relation_state");
616 }
617
618 HtmlTag WebClientRoute::HtmlTagRelationObject(const string& atlock,
619 const string& priorityString,
620 const ObjectType objectType,
621 const ObjectID objectId,
622 const DataModel::Relation::Data state)
623 {
624 const string name = "relation_" + atlock + "_" + priorityString;
625 HtmlTag content;
626 map<ObjectType, Languages::TextSelector> objectTypeOptions;
627 objectTypeOptions[ObjectTypeAccessory] = Languages::TextAccessory;
628 objectTypeOptions[ObjectTypeSignal] = Languages::TextSignal;
629 objectTypeOptions[ObjectTypeSwitch] = Languages::TextSwitch;
630 objectTypeOptions[ObjectTypeTrack] = Languages::TextTrack;
631 objectTypeOptions[ObjectTypeRoute] = Languages::TextRoute;
632 objectTypeOptions[ObjectTypeLoco] = Languages::TextLoco;
633 objectTypeOptions[ObjectTypeMultipleUnit] = Languages::TextOrientation;
634 objectTypeOptions[ObjectTypePause] = Languages::TextPause;
635 objectTypeOptions[ObjectTypeBooster] = Languages::TextBooster;
•636 objectTypeOptions[ObjectTypeCounter] = Languages::TextCounter;
637 HtmlTagSelect select(name + "_type", objectTypeOptions, objectType);
638 select.AddClass("select_relation_objecttype");
639 select.AddAttribute("onchange", "loadRelationObject('" + atlock + "', '" + priorityString + "');return false;");
640 content.AddChildTag(select);
641
642 switch (objectType)
643 {
644 case ObjectTypeSwitch:
645 {
646 std::map<string, AccessoryConfig> switches = manager.SwitchConfigByName();
647 map<string, SwitchID> switchOptions;
648 for (auto& mySwitch : switches)
649 {
650 switchOptions[mySwitch.first] = mySwitch.second.GetObjectIdentifier().GetObjectID();
651 }
652 SwitchID switchId = objectId;
653 if (switchId == SwitchNone && switchOptions.size() > 0)
654 {
655 switchId = switchOptions.begin()->second;
656 }
657 HtmlTagSelect selectSwitch(name + "_id", switchOptions, switchId);
658 selectSwitch.AddClass("select_relation_id");
659 selectSwitch.AddAttribute("onchange", "loadRelationObjectStates('switch', '" + name + "', '" + to_string(switchId) + "');return false;");
660 content.AddChildTag(selectSwitch);
661
662 HtmlTag contentState("div");
663 contentState.AddId(name + "_state");
664 contentState.AddClass("inline-block");
665 contentState.AddChildTag(HtmlTagRelationSwitchState(name, switchId, state));
666 content.AddChildTag(contentState);
667 return content;
668 }
669
670 case ObjectTypeSignal:
671 {
672 std::map<string, AccessoryConfig> signals = manager.SignalConfigByName();
673 map<string, SignalID> signalOptions;
674 for (auto& signal : signals)
675 {
676 signalOptions[signal.first] = signal.second.GetObjectIdentifier().GetObjectID();
677 }
678 SignalID signalId = objectId;
679 if (signalId == SignalNone && signalOptions.size() > 0)
680 {
681 signalId = signalOptions.begin()->second;
682 }
683 HtmlTagSelect selectSignal(name + "_id", signalOptions, signalId);
684 selectSignal.AddClass("select_relation_id");
685 selectSignal.AddAttribute("onchange", "loadRelationObjectStates('signal', '" + name + "', '" + to_string(signalId) + "');return false;");
686 content.AddChildTag(selectSignal);
687
688 HtmlTag contentState("div");
689 contentState.AddId(name + "_state");
690 contentState.AddClass("inline-block");
691 contentState.AddChildTag(client.HtmlTagRelationSignalState(name, signalId, state));
692 content.AddChildTag(contentState);
693 return content;
694 }
695
696 case ObjectTypeAccessory:
697 {
698 std::map<string, AccessoryConfig> accessories = manager.AccessoryConfigByName();
699 map<string, AccessoryID> accessoryOptions;
700 for (auto& accessory : accessories)
701 {
702 accessoryOptions[accessory.first] = accessory.second.GetObjectIdentifier().GetObjectID();
703 }
704 content.AddChildTag(HtmlTagSelect(name + "_id", accessoryOptions, objectId).AddClass("select_relation_id"));
705
706 map<DataModel::AccessoryState,Languages::TextSelector> stateOptions;
707 stateOptions[DataModel::AccessoryStateOn] = Languages::TextOn;
708 stateOptions[DataModel::AccessoryStateOff] = Languages::TextOff;
709 content.AddChildTag(HtmlTagSelect(name + "_state", stateOptions, static_cast<DataModel::AccessoryState>(state)).AddClass("select_relation_state"));
710 return content;
711 }
712
713 case ObjectTypeTrack:
714 {
715 std::map<string, Track*> tracks = manager.TrackListMasterByName();
716 map<string, TrackID> trackOptions;
717 for (auto& track : tracks)
718 {
719 trackOptions[track.first] = track.second->GetID();
720 }
721 content.AddChildTag(HtmlTagSelect(name + "_id", trackOptions, objectId).AddClass("select_relation_id"));
722
723 content.AddChildTag(HtmlTagSelectOrientation(name + "_state", static_cast<Orientation>(state)).AddClass("select_relation_state"));
724 return content;
725 }
726
727 case ObjectTypeRoute:
728 {
729 std::map<string, Route*> routes = manager.RouteListByName();
730 map<string, RouteID> routeOptions;
•731 for (auto& route : routes)
732 {
•733 routeOptions[route.first] = route.second->GetID();
734 }
735 content.AddChildTag(HtmlTagSelect(name + "_id", routeOptions, objectId).AddClass("select_relation_id"));
736 return content;
737 }
738
739 case ObjectTypeLoco:
740 {
741 map<string,string> functionOptions;
742 for (DataModel::LocoFunctionNr function = 0; function < NumberOfLocoFunctions; ++function)
743 {
744 functionOptions[Utils::Utils::ToStringWithLeadingZeros(function, 3)] = "F" + to_string(function);
745 }
746
747 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconShuntingMode, 3)] = Languages::GetText(Languages::TextLocoFunctionIconShuntingMode);
748 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconInertia, 3)] = Languages::GetText(Languages::TextLocoFunctionIconInertia);
749 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconLight, 3)] = Languages::GetText(Languages::TextLocoFunctionIconLight);
750 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconHeadlightLowBeamForward, 3)] = Languages::GetText(Languages::TextLocoFunctionIconHeadlightLowBeamForward);
751 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconHeadlightLowBeamReverse, 3)] = Languages::GetText(Languages::TextLocoFunctionIconHeadlightLowBeamReverse);
752 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconHeadlightHighBeamForward, 3)] = Languages::GetText(Languages::TextLocoFunctionIconHeadlightHighBeamForward);
753 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconHeadlightHighBeamReverse, 3)] = Languages::GetText(Languages::TextLocoFunctionIconHeadlightHighBeamReverse);
754 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconBacklightForward, 3)] = Languages::GetText(Languages::TextLocoFunctionIconBacklightForward);
755 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconBacklightReverse, 3)] = Languages::GetText(Languages::TextLocoFunctionIconBacklightReverse);
756 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconShuntingLight, 3)] = Languages::GetText(Languages::TextLocoFunctionIconShuntingLight);
757 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconBlinkingLight, 3)] = Languages::GetText(Languages::TextLocoFunctionIconBlinkingLight);
758 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconInteriorLight1, 3)] = Languages::GetText(Languages::TextLocoFunctionIconInteriorLight1);
759 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconInteriorLight2, 3)] = Languages::GetText(Languages::TextLocoFunctionIconInteriorLight2);
760 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconTableLight1, 3)] = Languages::GetText(Languages::TextLocoFunctionIconTableLight1);
761 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconTableLight2, 3)] = Languages::GetText(Languages::TextLocoFunctionIconTableLight2);
762 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconTableLight3, 3)] = Languages::GetText(Languages::TextLocoFunctionIconTableLight3);
763 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconCabLight1, 3)] = Languages::GetText(Languages::TextLocoFunctionIconCabLight1);
764 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconCabLight2, 3)] = Languages::GetText(Languages::TextLocoFunctionIconCabLight2);
765 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconCabLight12, 3)] = Languages::GetText(Languages::TextLocoFunctionIconCabLight12);
766 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconDriversDeskLight, 3)] = Languages::GetText(Languages::TextLocoFunctionIconDriversDeskLight);
767 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconTrainDestinationIndicator, 3)] = Languages::GetText(Languages::TextLocoFunctionIconTrainDestinationIndicator);
768 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconLocomotiveNumberIndicator, 3)] = Languages::GetText(Languages::TextLocoFunctionIconLocomotiveNumberIndicator);
769 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconEngineLight, 3)] = Languages::GetText(Languages::TextLocoFunctionIconEngineLight);
770 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconFireBox, 3)] = Languages::GetText(Languages::TextLocoFunctionIconFireBox);
771 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconStairsLight, 3)] = Languages::GetText(Languages::TextLocoFunctionIconStairsLight);
772 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconSmokeGenerator, 3)] = Languages::GetText(Languages::TextLocoFunctionIconSmokeGenerator);
773 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconTelex1, 3)] = Languages::GetText(Languages::TextLocoFunctionIconTelex1);
774 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconTelex2, 3)] = Languages::GetText(Languages::TextLocoFunctionIconTelex2);
775 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconTelex12, 3)] = Languages::GetText(Languages::TextLocoFunctionIconTelex12);
776 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconPanto1, 3)] = Languages::GetText(Languages::TextLocoFunctionIconPanto1);
777 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconPanto2, 3)] = Languages::GetText(Languages::TextLocoFunctionIconPanto2);
778 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconPanto12, 3)] = Languages::GetText(Languages::TextLocoFunctionIconPanto12);
779 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconUp, 3)] = Languages::GetText(Languages::TextLocoFunctionIconUp);
780 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconDown, 3)] = Languages::GetText(Languages::TextLocoFunctionIconDown);
781 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconUpDown1, 3)] = Languages::GetText(Languages::TextLocoFunctionIconUpDown1);
782 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconUpDown2, 3)] = Languages::GetText(Languages::TextLocoFunctionIconUpDown2);
783 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconLeft, 3)] = Languages::GetText(Languages::TextLocoFunctionIconLeft);
784 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconRight, 3)] = Languages::GetText(Languages::TextLocoFunctionIconRight);
785 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconLeftRight, 3)] = Languages::GetText(Languages::TextLocoFunctionIconLeftRight);
786 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconTurnLeft, 3)] = Languages::GetText(Languages::TextLocoFunctionIconTurnLeft);
787 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconTurnRight, 3)] = Languages::GetText(Languages::TextLocoFunctionIconTurnRight);
788 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconTurn, 3)] = Languages::GetText(Languages::TextLocoFunctionIconTurn);
789 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconCrane, 3)] = Languages::GetText(Languages::TextLocoFunctionIconCrane);
790 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconMagnet, 3)] = Languages::GetText(Languages::TextLocoFunctionIconMagnet);
791 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconCraneHook, 3)] = Languages::GetText(Languages::TextLocoFunctionIconCraneHook);
792 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconFan, 3)] = Languages::GetText(Languages::TextLocoFunctionIconFan);
793 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconBreak, 3)] = Languages::GetText(Languages::TextLocoFunctionIconBreak);
794 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconNoSound, 3)] = Languages::GetText(Languages::TextLocoFunctionIconNoSound);
795 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconSoundGeneral, 3)] = Languages::GetText(Languages::TextLocoFunctionIconSoundGeneral);
796 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconRunning1, 3)] = Languages::GetText(Languages::TextLocoFunctionIconRunning1);
797 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconRunning2, 3)] = Languages::GetText(Languages::TextLocoFunctionIconRunning2);
798 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconEngine1, 3)] = Languages::GetText(Languages::TextLocoFunctionIconEngine1);
799 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconEngine2, 3)] = Languages::GetText(Languages::TextLocoFunctionIconEngine2);
800 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconBreak1, 3)] = Languages::GetText(Languages::TextLocoFunctionIconBreak1);
801 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconBreak2, 3)] = Languages::GetText(Languages::TextLocoFunctionIconBreak2);
802 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconCurve, 3)] = Languages::GetText(Languages::TextLocoFunctionIconCurve);
803 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconHorn1, 3)] = Languages::GetText(Languages::TextLocoFunctionIconHorn1);
804 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconHorn2, 3)] = Languages::GetText(Languages::TextLocoFunctionIconHorn2);
805 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconWhistle1, 3)] = Languages::GetText(Languages::TextLocoFunctionIconWhistle1);
806 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconWhistle2, 3)] = Languages::GetText(Languages::TextLocoFunctionIconWhistle2);
807 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconBell, 3)] = Languages::GetText(Languages::TextLocoFunctionIconBell);
808 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconStationAnnouncement1, 3)] = Languages::GetText(Languages::TextLocoFunctionIconStationAnnouncement1);
809 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconStationAnnouncement2, 3)] = Languages::GetText(Languages::TextLocoFunctionIconStationAnnouncement2);
810 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconStationAnnouncement3, 3)] = Languages::GetText(Languages::TextLocoFunctionIconStationAnnouncement3);
811 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconSpeak, 3)] = Languages::GetText(Languages::TextLocoFunctionIconSpeak);
812 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconRadio, 3)] = Languages::GetText(Languages::TextLocoFunctionIconRadio);
813 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconMusic1, 3)] = Languages::GetText(Languages::TextLocoFunctionIconMusic1);
814 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconMusic2, 3)] = Languages::GetText(Languages::TextLocoFunctionIconMusic2);
815 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconOpenDoor, 3)] = Languages::GetText(Languages::TextLocoFunctionIconOpenDoor);
816 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconCloseDoor, 3)] = Languages::GetText(Languages::TextLocoFunctionIconCloseDoor);
817 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconFan1, 3)] = Languages::GetText(Languages::TextLocoFunctionIconFan1);
818 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconFan2, 3)] = Languages::GetText(Languages::TextLocoFunctionIconFan2);
819 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconFan3, 3)] = Languages::GetText(Languages::TextLocoFunctionIconFan3);
820 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconShovelCoal, 3)] = Languages::GetText(Languages::TextLocoFunctionIconShovelCoal);
821 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconCompressedAir, 3)] = Languages::GetText(Languages::TextLocoFunctionIconCompressedAir);
822 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconReliefValve, 3)] = Languages::GetText(Languages::TextLocoFunctionIconReliefValve);
823 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconSteamBlowOut, 3)] = Languages::GetText(Languages::TextLocoFunctionIconSteamBlowOut);
824 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconSteamBlow, 3)] = Languages::GetText(Languages::TextLocoFunctionIconSteamBlow);
825 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconDrainValve, 3)] = Languages::GetText(Languages::TextLocoFunctionIconDrainValve);
826 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconShakingRust, 3)] = Languages::GetText(Languages::TextLocoFunctionIconShakingRust);
827 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconAirPump, 3)] = Languages::GetText(Languages::TextLocoFunctionIconAirPump);
828 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconWaterPump, 3)] = Languages::GetText(Languages::TextLocoFunctionIconWaterPump);
829 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconBufferPush, 3)] = Languages::GetText(Languages::TextLocoFunctionIconBufferPush);
830 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconGenerator, 3)] = Languages::GetText(Languages::TextLocoFunctionIconGenerator);
831 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconGearBox, 3)] = Languages::GetText(Languages::TextLocoFunctionIconGearBox);
832 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconGearUp, 3)] = Languages::GetText(Languages::TextLocoFunctionIconGearUp);
833 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconGearDown, 3)] = Languages::GetText(Languages::TextLocoFunctionIconGearDown);
834 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconFillWater, 3)] = Languages::GetText(Languages::TextLocoFunctionIconFillWater);
835 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconFillDiesel, 3)] = Languages::GetText(Languages::TextLocoFunctionIconFillDiesel);
836 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconFillGas, 3)] = Languages::GetText(Languages::TextLocoFunctionIconFillGas);
837 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconSand, 3)] = Languages::GetText(Languages::TextLocoFunctionIconSand);
838 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconRailJoint, 3)] = Languages::GetText(Languages::TextLocoFunctionIconRailJoint);
839 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconCoupler, 3)] = Languages::GetText(Languages::TextLocoFunctionIconCoupler);
840 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconPanto, 3)] = Languages::GetText(Languages::TextLocoFunctionIconPanto);
841 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconMainSwitch, 3)] = Languages::GetText(Languages::TextLocoFunctionIconMainSwitch);
842 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconSoundLouder, 3)] = Languages::GetText(Languages::TextLocoFunctionIconSoundLouder);
843 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconSoundLower, 3)] = Languages::GetText(Languages::TextLocoFunctionIconSoundLower);
844 functionOptions[Utils::Utils::ToStringWithLeadingZeros(256 + LocoFunctionIconNoBreak, 3)] = Languages::GetText(Languages::TextLocoFunctionIconNoBreak);
845
846 content.AddChildTag(HtmlTagSelect(name + "_id", functionOptions, Utils::Utils::ToStringWithLeadingZeros(objectId, 3)).AddClass("select_relation_id"));
847
848 // FIXME: load available functions of loco
849 map<DataModel::LocoFunctionState,string> stateOptions;
850 stateOptions[DataModel::LocoFunctionStateOff] = Languages::GetText(Languages::TextOff);
851 stateOptions[DataModel::LocoFunctionStateOn] = Languages::GetText(Languages::TextOn);
852 stateOptions[DataModel::LocoFunctionState0s5] = "0.5s";
853 stateOptions[DataModel::LocoFunctionState1s0] = "1s";
854 stateOptions[DataModel::LocoFunctionState1s5] = "1.5s";
855 stateOptions[DataModel::LocoFunctionState2s0] = "2s";
856 content.AddChildTag(HtmlTagSelect(name + "_state", stateOptions, static_cast<DataModel::LocoFunctionState>(state)).AddClass("select_relation_state"));
857 return content;
858 }
859
860 case ObjectTypePause:
861 {
862 map<unsigned int,string> time;
863 time[1u] = "0.1s";
864 time[2u] = "0.2s";
865 time[3u] = "0.3s";
866 time[4u] = "0.4s";
867 time[5u] = "0.5s";
868 time[6u] = "0.6s";
869 time[7u] = "0.7s";
870 time[8u] = "0.8s";
871 time[9u] = "0.9s";
872 time[10u] = "1s";
873 time[15u] = "1.5s";
874 time[20u] = "2s";
875 time[25u] = "2.5s";
876 time[30u] = "3s";
877 time[40u] = "4s";
878 time[50u] = "5s";
879 time[60u] = "6s";
880 time[70u] = "7s";
881 time[80u] = "8s";
882 time[90u] = "9s";
883 time[100u] = "10s";
884 content.AddChildTag(HtmlTagSelect(name + "_state", time, static_cast<unsigned int>(state)).AddClass("select_relation_state"));
885 return content;
886 }
887
888 case ObjectTypeMultipleUnit: // abused for loco orientation
889 {
890 map<unsigned int,string> orientation;
891 orientation[0] = Languages::Languages::GetText(Languages::Languages::TextLeft);
892 orientation[1u] = Languages::Languages::GetText(Languages::Languages::TextRight);
893 orientation[2u] = Languages::Languages::GetText(Languages::Languages::TextChange);;
894 content.AddChildTag(HtmlTagSelect(name + "_state", orientation, static_cast<unsigned int>(state)).AddClass("select_relation_state"));
895 return content;
896 }
897
898 case ObjectTypeBooster:
899 {
900 map<unsigned int,string> booster;
901 booster[0] = Languages::Languages::GetText(Languages::Languages::TextOff);
902 booster[1u] = Languages::Languages::GetText(Languages::Languages::TextOn);
903 content.AddChildTag(HtmlTagSelect(name + "_state", booster, static_cast<unsigned int>(state)).AddClass("select_relation_state"));
904 return content;
905 }
906
•907 case ObjectTypeCounter:
908 {
909 std::map<string, Counter*> counters = manager.CounterListByName();
910 map<string, CounterID> counterOptions;
911 for (auto& counter : counters)
912 {
913 counterOptions[counter.first] = counter.second->GetID();
914 }
915 CounterID counterId = objectId;
916 if ((counterId == CounterNone) && (counterOptions.size() > 0))
917 {
918 counterId = counterOptions.begin()->second;
919 }
920 HtmlTagSelect selectCounter(name + "_id", counterOptions, counterId);
921 selectCounter.AddClass("select_relation_id");
922 selectCounter.AddAttribute("onchange", "loadRelationObjectStates('counter', '" + name + "', '" + to_string(counterId) + "');return false;");
923 content.AddChildTag(selectCounter);
924
925 map<unsigned int,string> countOptions;
926 countOptions[0] = Languages::Languages::GetText(Languages::Languages::TextIncrement);
927 countOptions[1u] = Languages::Languages::GetText(Languages::Languages::TextDecrement);
928 content.AddChildTag(HtmlTagSelect(name + "_state", countOptions, static_cast<unsigned int>(state)).AddClass("select_relation_state"));
929 return content;
930 }
931
932 default:
933 {
934 content.AddContent(Languages::TextUnknownObjectType);
935 return content;
936 }
937 }
938 }
939
940 HtmlTag WebClientRoute::HtmlTagSelectTrack(const std::string& name,
941 const Languages::TextSelector label,
942 const TrackID trackID,
943 const Orientation orientation,
944 const string& onchange) const
945 {
946 HtmlTag tag;
947 map<string,TrackID> tracks = manager.TrackListIdByName();
948 HtmlTagSelectWithLabel selectTrack(name + "track", label, tracks, trackID);
949 selectTrack.AddClass("select_track");
950 if (onchange.size() > 0)
951 {
952 selectTrack.AddAttribute("onchange", onchange);
953 }
954 tag.AddChildTag(selectTrack);
955 tag.AddChildTag(HtmlTagSelectOrientation(name + "orientation", orientation).AddClass("select_orientation"));
956 return tag;
957 }
958
959 HtmlTag WebClientRoute::HtmlTagSelectFeedbacksOfTrack(const TrackID trackID,
960 const RouteID followUpRoute,
961 const FeedbackID feedbackIdReduced,
962 const Delay reducedDelay,
963 const FeedbackID feedbackIdCreep,
964 const Delay creepDelay,
965 const FeedbackID feedbackIdStop,
966 const Delay stopDelay,
967 const FeedbackID feedbackIdOver) const
968 {
969 HtmlTag tag;
970 map<RouteID,string> followUpRouteOptions = manager.RoutesOfTrack(trackID);
971 followUpRouteOptions[RouteStop] = Languages::Languages::GetText(Languages::TextNone);
972 followUpRouteOptions[RouteAuto] = Languages::Languages::GetText(Languages::TextSelectAutomatically);
973 tag.AddChildTag(HtmlTagSelectWithLabel("followuproute", Languages::TextFollowUpRoute, followUpRouteOptions, followUpRoute));
974
975 map<string,FeedbackID> feedbacks = manager.FeedbacksOfTrack(trackID);
976 map<string,FeedbackID> feedbacksWithNone = feedbacks;
977 feedbacksWithNone["-"] = FeedbackNone;
978 map<string,Delay> delayOptions;
979 delayOptions["0.0s"] = 0;
980 delayOptions["0.1s"] = 1;
981 delayOptions["0.2s"] = 2;
982 delayOptions["0.3s"] = 3;
983 delayOptions["0.4s"] = 4;
984 delayOptions["0.5s"] = 5;
985 delayOptions["0.6s"] = 6;
986 delayOptions["0.7s"] = 7;
987 delayOptions["0.8s"] = 8;
988 delayOptions["0.9s"] = 9;
989 delayOptions["1.0s"] = 10;
990 delayOptions["1.5s"] = 15;
991 delayOptions["2.0s"] = 20;
992 delayOptions["2.5s"] = 25;
993 delayOptions["3.0s"] = 30;
994 delayOptions["3.5s"] = 35;
995 delayOptions["4.0s"] = 40;
996 delayOptions["4.5s"] = 45;
997 delayOptions["5.0s"] = 50;
998 delayOptions["6.0s"] = 60;
999 delayOptions["7.0s"] = 70;
1000 delayOptions["8.0s"] = 80;
1001 delayOptions["9.0s"] = 90;
1002
1003 tag.AddChildTag(HtmlTagSelectWithLabel("feedbackreduced", Languages::TextReducedSpeedAt, feedbacksWithNone, feedbackIdReduced).AddClass("select_feedback"));
1004 tag.AddChildTag(HtmlTagSelect("reduceddelay", delayOptions, reducedDelay).AddClass("select_delay"));
1005 tag.AddChildTag(HtmlTagSelectWithLabel("feedbackcreep", Languages::TextCreepAt, feedbacksWithNone, feedbackIdCreep).AddClass("select_feedback"));
1006 tag.AddChildTag(HtmlTagSelect("creepdelay", delayOptions, creepDelay).AddClass("select_delay"));
1007 tag.AddChildTag(HtmlTagSelectWithLabel("feedbackstop", Languages::TextStopAt, feedbacks, feedbackIdStop).AddClass("select_feedback"));
1008 tag.AddChildTag(HtmlTagSelect("stopdelay", delayOptions, stopDelay).AddClass("select_delay"));
1009 tag.AddChildTag(HtmlTagSelectWithLabel("feedbackover", Languages::TextOverrunAt, feedbacksWithNone, feedbackIdOver).AddClass("select_feedback"));
1010 return tag;
1011 }
1012
1013 void WebClientRoute::HandleFeedbacksOfTrack(const map<string, string>& arguments)
1014 {
1015 const TrackID trackID = static_cast<TrackID>(Utils::Utils::GetIntegerMapEntry(arguments, "track", TrackNone));
1016 client.ReplyHtmlWithHeader(HtmlTagSelectFeedbacksOfTrack(trackID));
1017 }
1018 }} // namespace Server::Web