| 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 <algorithm> |
| 22 | |
| 23 | #include "DataModel/DataModel.h" |
| 24 | #include "DataModel/LocoConfig.h" |
| 25 | #include "Hardware/HardwareHandler.h" |
| 26 | #include "Utils/Integer.h" |
| 27 | #include "Server/Web/HtmlTagButton.h" |
| 28 | #include "Server/Web/HtmlTagInputCheckboxWithLabel.h" |
| 29 | #include "Server/Web/HtmlTagInputHidden.h" |
| 30 | #include "Server/Web/HtmlTagInputIntegerWithLabel.h" |
| 31 | #include "Server/Web/HtmlTagInputTextWithLabel.h" |
| 32 | #include "Server/Web/WebClientStatic.h" |
| 33 | |
| 34 | using namespace DataModel; |
| 35 | using LayoutRotation = DataModel::LayoutItem::LayoutRotation; |
| 36 | using std::map; |
| 37 | using std::string; |
| 38 | using std::to_string; |
| 39 | using std::vector; |
| 40 | |
| 41 | namespace Server { namespace Web |
| 42 | { |
| 43 | HtmlTag WebClientStatic::HtmlTagControlArgument(const unsigned char argNr, const ArgumentType type, const string& value) |
| 44 | { |
| 45 | Languages::TextSelector argumentName; |
| 46 | string argumentNumber = "arg" + to_string(argNr); |
| 47 | switch (type) |
| 48 | { |
| 49 | case ArgumentTypeIpAddress: |
| 50 | argumentName = Languages::TextIPAddress; |
| 51 | break; |
| 52 | |
| 53 | case ArgumentTypeSerialPort: |
| 54 | { |
| 55 | argumentName = Languages::TextSerialPort; |
| 56 | #ifdef __CYGWIN__ |
| 57 | vector<unsigned char> comPorts; |
| 58 | bool ret = Utils::Utils::GetComPorts(comPorts); |
| 59 | if (ret == false || comPorts.size() == 0) |
| 60 | { |
| 61 | break; |
| 62 | } |
| 63 | map<string,string> comPortOptions; |
| 64 | for (auto comPort : comPorts) |
| 65 | { |
| 66 | comPortOptions["/dev/ttyS" + to_string(comPort)] = "COM" + to_string(comPort + 1); |
| 67 | } |
| 68 | return HtmlTagSelectWithLabel(argumentNumber, argumentName, comPortOptions, value); |
| 69 | #else |
| 70 | break; |
| 71 | #endif |
| 72 | } |
| 73 | |
| 74 | case ArgumentTypeS88Modules: |
| 75 | { |
| 76 | argumentName = Languages::TextNrOfS88Modules; |
| 77 | const int valueInteger = Utils::Integer::StringToInteger(value, 0, 62); |
| 78 | return HtmlTagInputIntegerWithLabel(argumentNumber, argumentName, valueInteger, 0, 62); |
| 79 | } |
| 80 | |
| 81 | case ArgumentTypeMainSecundary: |
| 82 | { |
| 83 | argumentName = Languages::TextDeviceType; |
| 84 | map<string,string> mainSecondaryOptions; |
| 85 | mainSecondaryOptions["1"] = Languages::Languages::GetText(Languages::Languages::TextSecondaryDevice); |
| 86 | mainSecondaryOptions["0"] = Languages::Languages::GetText(Languages::Languages::TextMainDevice); |
| 87 | return HtmlTagSelectWithLabel(argumentNumber, argumentName, mainSecondaryOptions, value); |
| 88 | } |
| 89 | |
| 90 | default: |
| 91 | return HtmlTag(); |
| 92 | } |
| 93 | return HtmlTagInputTextWithLabel(argumentNumber, argumentName, value); |
| 94 | } |
| 95 | |
| 96 | HtmlTag WebClientStatic::HtmlTagControlArguments(const HardwareType hardwareType, const string& arg1, const string& arg2, const string& arg3, const string& arg4, const string& arg5) |
| 97 | { |
| 98 | HtmlTag div; |
| 99 | std::map<unsigned char,ArgumentType> argumentTypes; |
| 100 | std::string hint; |
| 101 | Hardware::HardwareHandler::ArgumentTypesOfHardwareTypeAndHint(hardwareType, argumentTypes, hint); |
| 102 | if (argumentTypes.count(1) == 1) |
| 103 | { |
| 104 | div.AddChildTag(HtmlTagControlArgument(1, argumentTypes.at(1), arg1)); |
| 105 | } |
| 106 | if (argumentTypes.count(2) == 1) |
| 107 | { |
| 108 | div.AddChildTag(HtmlTagControlArgument(2, argumentTypes.at(2), arg2)); |
| 109 | } |
| 110 | if (argumentTypes.count(3) == 1) |
| 111 | { |
| 112 | div.AddChildTag(HtmlTagControlArgument(3, argumentTypes.at(3), arg3)); |
| 113 | } |
| 114 | if (argumentTypes.count(4) == 1) |
| 115 | { |
| 116 | div.AddChildTag(HtmlTagControlArgument(4, argumentTypes.at(4), arg4)); |
| 117 | } |
| 118 | if (argumentTypes.count(5) == 1) |
| 119 | { |
| 120 | div.AddChildTag(HtmlTagControlArgument(5, argumentTypes.at(5), arg5)); |
| 121 | } |
| 122 | if (hint.size() > 0) |
| 123 | { |
| 124 | div.AddChildTag(HtmlTag("div").AddContent(Languages::GetText(Languages::TextHint)).AddContent(HtmlTag("br")).AddContent(hint)); |
| 125 | } |
| 126 | return div; |
| 127 | } |
| 128 | |
| 129 | const std::map<string,HardwareType> WebClientStatic::ListHardwareNames() |
| 130 | { |
| 131 | std::map<string,HardwareType> hardwareList; |
| 132 | // Keys should not contain more then 30 characters |
| 133 | hardwareList["CAN-Digital-Bahn CC-Schnitte"] = HardwareTypeCcSchnitte; |
| 134 | hardwareList["Digikeijs DR5000"] = HardwareTypeDR5000; |
| 135 | hardwareList["DCC-EX Serial"] = HardwareTypeDccPpExSerial; |
| 136 | hardwareList["DCC-EX TCP"] = HardwareTypeDccPpExTcp; |
| 137 | hardwareList["ESU Ecos (beta)"] = HardwareTypeEcos; |
| 138 | hardwareList["Fleischmann TwinCenter"] = HardwareTypeTwinCenter; |
| 139 | hardwareList["KM1 System Control 7"] = HardwareTypeSystemControl7; |
| 140 | hardwareList["LDT HSI-88 RS-232"] = HardwareTypeHsi88; |
| 141 | hardwareList["LokStoreDigital LoDi-Rektor (beta)"] = HardwareTypeRektor; |
| 142 | hardwareList["Märklin Central Station 1 (beta)"] = HardwareTypeCS1; |
| 143 | hardwareList["Märklin Central Station 2/3 TCP"] = HardwareTypeCS2Tcp; |
| 144 | hardwareList["Märklin Central Station 2/3 UDP"] = HardwareTypeCS2Udp; |
| 145 | hardwareList["Märklin Interface 6050/6051"] = HardwareTypeM6051; |
| 146 | hardwareList["OpenDCC Z1"] = HardwareTypeOpenDcc; |
| 147 | hardwareList["Roco Z21"] = HardwareTypeZ21; |
| 148 | hardwareList["Tams MasterControl"] = HardwareTypeMasterControl; |
| 149 | hardwareList["Tams MasterControl 2"] = HardwareTypeMasterControl2; |
| 150 | hardwareList["Tams RedBox"] = HardwareTypeRedBox; |
| 151 | hardwareList["Uhlenbrock Adapter 63120"] = HardwareTypeLocoNetAdapter63120; |
| 152 | hardwareList["Uhlenbrock Adapter 63820"] = HardwareTypeLocoNetAdapter63820; |
| 153 | hardwareList["Uhlenbrock Intellibox"] = HardwareTypeIntellibox; |
| 154 | hardwareList["Uhlenbrock Intellibox II"] = HardwareTypeIntellibox2; |
| 155 | hardwareList["Virtual Command Station"] = HardwareTypeVirtual; |
| 156 | return hardwareList; |
| 157 | } |
| 158 | |
| 159 | HtmlTag WebClientStatic::HtmlTagProtocol(const map<string,Protocol>& protocolMap, const Protocol selectedProtocol) |
| 160 | { |
| 161 | size_t mapSize = protocolMap.size(); |
| 162 | switch (mapSize) |
| 163 | { |
| 164 | case 0: |
| 165 | return HtmlTagInputHidden("protocol", std::to_string(ProtocolNone)); |
| 166 | |
| 167 | case 1: |
| 168 | return HtmlTagInputHidden("protocol", std::to_string(protocolMap.begin()->second)); |
| 169 | |
| 170 | default: |
| 171 | HtmlTag content; |
| 172 | content.AddChildTag(HtmlTagLabel(Languages::TextProtocol, "protocol")); |
| 173 | content.AddChildTag(HtmlTagSelect("protocol", protocolMap, selectedProtocol)); |
| 174 | return content; |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | HtmlTag WebClientStatic::HtmlTagAccessoryAddress(const AccessoryType type, |
| 179 | const Address address, |
| 180 | const AddressPort port) |
| 181 | { |
| 182 | HtmlTag content; |
| 183 | content.AddChildTag(HtmlTagInputIntegerWithLabel("address", Languages::TextAddress, address, 1, 2044)); |
| 184 | switch (type & DataModel::AccessoryTypeConnectionMask) |
| 185 | { |
| 186 | case DataModel::AccessoryTypeOnPush: |
| 187 | case DataModel::AccessoryTypeOnOff: |
| 188 | { |
| 189 | map<AddressPort,Languages::TextSelector> portMap; |
| 190 | portMap[AddressPortRed] = Languages::TextRed; |
| 191 | portMap[AddressPortGreen] = Languages::TextGreen; |
| 192 | content.AddChildTag(HtmlTagSelect("port", portMap, port).AddClass("select_port")); |
| 193 | break; |
| 194 | } |
| 195 | |
| 196 | case DataModel::AccessoryTypeOnOn: |
| 197 | default: |
| 198 | content.AddChildTag(HtmlTagInputHidden("port", std::to_string(port))); |
| 199 | break; |
| 200 | } |
| 201 | return content; |
| 202 | } |
| 203 | |
| 204 | HtmlTag WebClientStatic::HtmlTagDuration(const DataModel::AccessoryPulseDuration duration, const Languages::TextSelector label) |
| 205 | { |
| 206 | std::map<string,string> durationOptions; |
| 207 | durationOptions["0000"] = "0"; |
| 208 | durationOptions["0100"] = "100"; |
| 209 | durationOptions["0250"] = "250"; |
| 210 | durationOptions["0500"] = "500"; |
| 211 | durationOptions["1000"] = "1000"; |
| 212 | durationOptions["1500"] = "1500"; |
| 213 | durationOptions["2000"] = "2000"; |
| 214 | durationOptions["3000"] = "3000"; |
| 215 | durationOptions["4000"] = "4000"; |
| 216 | durationOptions["5000"] = "5000"; |
| 217 | return HtmlTagSelectWithLabel("duration", label, durationOptions, Utils::Utils::ToStringWithLeadingZeros(duration, 4)); |
| 218 | } |
| 219 | |
| 220 | HtmlTag WebClientStatic::HtmlTagSlaveEntry(const string& prefix, |
| 221 | const string& priority, |
| 222 | const ObjectID objectId, |
| 223 | const map<string,ObjectID>& options) |
| 224 | { |
| 225 | HtmlTag content("div"); |
| 226 | content.AddId(prefix + "_priority_" + priority); |
| 227 | HtmlTagButton deleteButton(Languages::TextDelete, prefix + "_delete_" + priority); |
| 228 | deleteButton.AddAttribute("onclick", "deleteElement('" + prefix + "_priority_" + priority + "');return false;"); |
| 229 | deleteButton.AddClass("wide_button"); |
| 230 | content.AddChildTag(deleteButton); |
| 231 | |
| 232 | HtmlTag contentObject("div"); |
| 233 | contentObject.AddId(prefix + "_object_" + priority); |
| 234 | contentObject.AddClass("inline-block"); |
| 235 | |
| 236 | contentObject.AddChildTag(HtmlTagSelect(prefix + "_id_" + priority, options, objectId).AddClass("select_slave_id")); |
| 237 | content.AddChildTag(contentObject); |
| 238 | return content; |
| 239 | } |
| 240 | |
| 241 | HtmlTag WebClientStatic::HtmlTagRotation(const LayoutRotation rotation) |
| 242 | { |
| 243 | HtmlTag content; |
| 244 | std::map<LayoutRotation, Languages::TextSelector> rotationOptions; |
| 245 | rotationOptions[DataModel::LayoutItem::Rotation0] = Languages::TextNoRotation; |
| 246 | rotationOptions[DataModel::LayoutItem::Rotation90] = Languages::Text90DegClockwise; |
| 247 | rotationOptions[DataModel::LayoutItem::Rotation180] = Languages::Text180Deg; |
| 248 | rotationOptions[DataModel::LayoutItem::Rotation270] = Languages::Text90DegAntiClockwise; |
| 249 | content.AddChildTag(HtmlTagSelectWithLabel("rotation", Languages::TextRotation, Languages::TextHintPositionRotate, rotationOptions, rotation)); |
| 250 | return content; |
| 251 | } |
| 252 | |
| 253 | HtmlTag WebClientStatic::HtmlTagSelectExecuteAccessory(const bool executeAccessory) |
| 254 | { |
| 255 | map<unsigned char,Languages::TextSelector> options; |
| 256 | options[0] = Languages::TextWhenWrongPosition; |
| 257 | options[1] = Languages::TextAlways; |
| 258 | return HtmlTagSelectWithLabel("executeaccessory", Languages::TextExecuteAccessory, options, static_cast<unsigned char>(executeAccessory)); |
| 259 | } |
| 260 | |
| 261 | HtmlTag WebClientStatic::HtmlTagSelectSelectRouteApproach(const DataModel::SelectRouteApproach selectRouteApproach, const bool addDefault) |
| 262 | { |
| 263 | map<DataModel::SelectRouteApproach,Languages::TextSelector> options; |
| 264 | if (addDefault) |
| 265 | { |
| 266 | options[DataModel::SelectRouteSystemDefault] = Languages::TextSystemDefault; |
| 267 | } |
| 268 | options[DataModel::SelectRouteDoNotCare] = Languages::TextDoNotCare; |
| 269 | options[DataModel::SelectRouteRandom] = Languages::TextRandom; |
| 270 | options[DataModel::SelectRouteMinTrackLength] = Languages::TextMinTrackLength; |
| 271 | options[DataModel::SelectRouteLongestUnused] = Languages::TextLongestUnused; |
| 272 | return HtmlTagSelectWithLabel("selectrouteapproach", Languages::TextSelectRouteBy, options, selectRouteApproach); |
| 273 | } |
| 274 | |
| 275 | HtmlTag WebClientStatic::HtmlTagNrOfTracksToReserve(const DataModel::Loco::NrOfTracksToReserve nrOfTracksToReserve) |
| 276 | { |
| 277 | map<DataModel::Loco::NrOfTracksToReserve,string> options; |
| 278 | options[DataModel::Loco::ReserveOne] = "1"; |
| 279 | options[DataModel::Loco::ReserveTwo] = "2"; |
| 280 | return HtmlTagSelectWithLabel("nroftrackstoreserve", Languages::TextNrOfTracksToReserve, options, nrOfTracksToReserve); |
| 281 | } |
| 282 | |
| 283 | HtmlTag WebClientStatic::HtmlTagLogLevel() |
| 284 | { |
| 285 | map<Logger::Logger::Level,Languages::TextSelector> options; |
| 286 | options[Logger::Logger::LevelOff] = Languages::TextOff; |
| 287 | options[Logger::Logger::LevelError] = Languages::TextError; |
| 288 | options[Logger::Logger::LevelWarning] = Languages::TextWarning; |
| 289 | options[Logger::Logger::LevelInfo] = Languages::TextInfo; |
| 290 | options[Logger::Logger::LevelDebug] = Languages::TextDebug; |
| 291 | return HtmlTagSelectWithLabel("loglevel", Languages::TextLogLevel, options, Logger::Logger::GetLogLevel()); |
| 292 | } |
| 293 | |
| 294 | HtmlTag WebClientStatic::HtmlTagLanguage() |
| 295 | { |
| 296 | map<Languages::Language,Languages::TextSelector> options; |
| 297 | options[Languages::EN] = Languages::TextEnglish; |
| 298 | options[Languages::DE] = Languages::TextGerman; |
| 299 | options[Languages::ES] = Languages::TextSpanish; |
| 300 | return HtmlTagSelectWithLabel("language", Languages::TextLanguage, options, Languages::GetDefaultLanguage()); |
| 301 | } |
| 302 | |
| 303 | HtmlTag WebClientStatic::HtmlTagStartupLocos(const StartupInitLocos startupInitLocos) |
| 304 | { |
| 305 | map<StartupInitLocos,Languages::TextSelector> options; |
| 306 | options[StartupInitLocosNone] = Languages::TextStartupInitLocosNone; |
| 307 | options[StartupInitLocosSpeed] = Languages::TextStartupInitLocosSpeed; |
| 308 | options[StartupInitLocosAll] = Languages::TextStartupInitLocosAll; |
| 309 | return HtmlTagSelectWithLabel("startupinitlocos", Languages::TextStartupInitLocos, options, startupInitLocos); |
| 310 | } |
| 311 | |
| 312 | HtmlTag WebClientStatic::HtmlTagControl(const std::map<ControlID,string>& controls, ControlID& controlId, const string& objectType, const ObjectID objectID) |
| 313 | { |
| 314 | if (controls.size() == 0) |
| 315 | { |
| 316 | return HtmlTagInputTextWithLabel("control", Languages::TextControl, Languages::GetText(Languages::TextConfigureControlFirst)); |
| 317 | } |
| 318 | bool controlIdValid = false; |
| 319 | if (controlId != ControlIdNone) |
| 320 | { |
| 321 | for (auto& control : controls) |
| 322 | { |
| 323 | if (control.first != controlId) |
| 324 | { |
| 325 | continue; |
| 326 | } |
| 327 | controlIdValid = true; |
| 328 | break; |
| 329 | } |
| 330 | } |
| 331 | if (!controlIdValid) |
| 332 | { |
| 333 | controlId = controls.begin()->first; |
| 334 | } |
| 335 | if (controls.size() == 1) |
| 336 | { |
| 337 | return HtmlTagInputHidden("control", to_string(controlId)); |
| 338 | } |
| 339 | std::map<string, string> controlOptions; |
| 340 | for (auto& control : controls) |
| 341 | { |
| 342 | controlOptions[to_string(control.first)] = control.second; |
| 343 | } |
| 344 | return HtmlTagSelectWithLabel("control", Languages::TextControl, controlOptions, to_string(controlId)).AddAttribute("onchange", "loadProtocol('" + objectType + "', " + to_string(objectID) + ")"); |
| 345 | } |
| 346 | |
| 347 | HtmlTag WebClientStatic::HtmlTagControl(const string& name, const std::map<ControlID,string>& controls) |
| 348 | { |
| 349 | ControlID controlIdFirst = controls.begin()->first; |
| 350 | if (controls.size() == 1) |
| 351 | { |
| 352 | return HtmlTagInputHidden("s_" + name, to_string(controlIdFirst)); |
| 353 | } |
| 354 | return HtmlTagSelectWithLabel(name, Languages::TextControl, controls, controlIdFirst).AddAttribute("onchange", "loadProgramModeSelector();"); |
| 355 | } |
| 356 | |
| 357 | vector<ObjectID> WebClientStatic::InterpretSlaveData(const string& prefix, const map<string, string>& arguments) |
| 358 | { |
| 359 | vector<ObjectID> ids; |
| 360 | const unsigned int count = Utils::Utils::GetIntegerMapEntry(arguments, prefix + "counter", 0); |
| 361 | for (unsigned int index = 1; index <= count; ++index) |
| 362 | { |
| 363 | const string indexAsString = to_string(index); |
| 364 | const ObjectID id = Utils::Utils::GetIntegerMapEntry(arguments, prefix + "_id_" + indexAsString, ObjectNone); |
| 365 | if (id == ObjectNone) |
| 366 | { |
| 367 | continue; |
| 368 | } |
| 369 | ids.push_back(id); |
| 370 | } |
| 371 | |
| 372 | std::sort(ids.begin(), ids.end()); |
| 373 | ids.erase(std::unique(ids.begin(), ids.end()), ids.end()); |
| 374 | return ids; |
| 375 | } |
| 376 | |
| 377 | HtmlTag WebClientStatic::HtmlTagTabMenuItem(const std::string& tabName, |
| 378 | const Languages::TextSelector buttonValue, |
| 379 | const bool selected, |
| 380 | const bool hidden) |
| 381 | { |
| 382 | HtmlTag button("button"); |
| 383 | button.AddClass("tab_button"); |
| 384 | button.AddId("tab_button_" + tabName); |
| 385 | button.AddAttribute("onclick", "ShowTab('" + tabName + "');"); |
| 386 | button.AddContent(buttonValue); |
| 387 | if (selected) |
| 388 | { |
| 389 | button.AddClass("tab_button_selected"); |
| 390 | } |
| 391 | if (hidden) |
| 392 | { |
| 393 | button.AddClass("hidden"); |
| 394 | } |
| 395 | return button; |
| 396 | } |
| 397 | |
| 398 | HtmlTag WebClientStatic::HtmlTagSelectPropulsion(const Propulsion propulsion) |
| 399 | { |
| 400 | map<Propulsion,Languages::TextSelector> propulsions; |
| 401 | propulsions[PropulsionUnknown] = Languages::TextPropulsionUnknown; |
| 402 | propulsions[PropulsionSteam] = Languages::TextPropulsionSteam; |
| 403 | propulsions[PropulsionDiesel] = Languages::TextPropulsionDiesel; |
| 404 | propulsions[PropulsionGas] = Languages::TextPropulsionGas; |
| 405 | propulsions[PropulsionElectric] = Languages::TextPropulsionElectric; |
| 406 | propulsions[PropulsionHydrogen] = Languages::TextPropulsionHydrogen; |
| 407 | propulsions[PropulsionAccu] = Languages::TextPropulsionAccu; |
| 408 | propulsions[PropulsionOther] = Languages::TextPropulsionOther; |
| 409 | return HtmlTagSelectWithLabel("propulsion", Languages::TextPropulsion, propulsions, propulsion); |
| 410 | } |
| 411 | |
| 412 | HtmlTag WebClientStatic::HtmlTagSelectTrainType(const TrainType trainType) |
| 413 | { |
| 414 | map<TrainType,Languages::TextSelector> trainTypes; |
| 415 | trainTypes[TrainTypeUnknown] = Languages::TextTrainTypeUnknown; |
| 416 | trainTypes[TrainTypeInternationalHighSpeed] = Languages::TextTrainTypeInternationalHighSpeed; |
| 417 | trainTypes[TrainTypeNationalHighSpeed] = Languages::TextTrainTypeNationalHighSpeed; |
| 418 | trainTypes[TrainTypeInternationalLongDistance] = Languages::TextTrainTypeInternationalLongDistance; |
| 419 | trainTypes[TrainTypeNationalLongDistance] = Languages::TextTrainTypeNationalLongDistance; |
| 420 | trainTypes[TrainTypeInternationalNight] = Languages::TextTrainTypeInternationalNight; |
| 421 | trainTypes[TrainTypeNationalNight] = Languages::TextTrainTypeNationalNight; |
| 422 | trainTypes[TrainTypeLongDistanceFastLocal] = Languages::TextTrainTypeLongDistanceFastLocal; |
| 423 | trainTypes[TrainTypeFastLocal] = Languages::TextTrainTypeFastLocal; |
| 424 | trainTypes[TrainTypeLocal] = Languages::TextTrainTypeLocal; |
| 425 | trainTypes[TrainTypeSuburban] = Languages::TextTrainTypeSuburban; |
| 426 | trainTypes[TrainTypeUnderground] = Languages::TextTrainTypeUnderground; |
| 427 | trainTypes[TrainTypeHistoric] = Languages::TextTrainTypeHistoric; |
| 428 | trainTypes[TrainTypeExtra] = Languages::TextTrainTypeExtra; |
| 429 | trainTypes[TrainTypePassengerWithCargo] = Languages::TextTrainTypePassengerWithCargo; |
| 430 | trainTypes[TrainTypeCargoLongDistance] = Languages::TextTrainTypeCargoLongDistance; |
| 431 | trainTypes[TrainTypeCargoLocal] = Languages::TextTrainTypeCargoLocal; |
| 432 | trainTypes[TrainTypeCargoBlock] = Languages::TextTrainTypeCargoBlock; |
| 433 | trainTypes[TrainTypeCargoTractor] = Languages::TextTrainTypeCargoTractor; |
| 434 | trainTypes[TrainTypeCargoExpress] = Languages::TextTrainTypeCargoExpress; |
| 435 | trainTypes[TrainTypeCargoWithPassenger] = Languages::TextTrainTypeCargoWithPassenger; |
| 436 | trainTypes[TrainTypeRescue] = Languages::TextTrainTypeRescue; |
| 437 | trainTypes[TrainTypeConstruction] = Languages::TextTrainTypeConstruction; |
| 438 | trainTypes[TrainTypeEmpty] = Languages::TextTrainTypeEmpty; |
| 439 | trainTypes[TrainTypeLoco] = Languages::TextTrainTypeLoco; |
| 440 | trainTypes[TrainTypeCleaning] = Languages::TextTrainTypeCleaning; |
| 441 | trainTypes[TrainTypeOther] = Languages::TextTrainTypeOther; |
| 442 | return HtmlTagSelectWithLabel("type", Languages::TextTrainType, trainTypes, trainType); |
| 443 | } |
| 444 | |
| 445 | HtmlTag WebClientStatic::HtmlTagTabFunctions(const LocoFunctionEntry* locoFunctions) |
| 446 | { |
| 447 | HtmlTag functionsContent("div"); |
| 448 | functionsContent.AddId("tab_functions"); |
| 449 | functionsContent.AddClass("tab_content"); |
| 450 | functionsContent.AddClass("hidden"); |
| 451 | map<DataModel::LocoFunctionType,Languages::TextSelector> functionTypes; |
| 452 | functionTypes[DataModel::LocoFunctionTypeNone] = Languages::TextLocoFunctionTypeNone; |
| 453 | functionTypes[DataModel::LocoFunctionTypePermanent] = Languages::TextLocoFunctionTypePermanent; |
| 454 | functionTypes[DataModel::LocoFunctionTypeMoment] = Languages::TextLocoFunctionTypeMoment; |
| 455 | // functionTypes[DataModel::LocoFunctionTypeFlashing] = Languages::TextLocoFunctionTypeFlashing; |
| 456 | // functionTypes[DataModel::LocoFunctionTypeTimer] = Languages::TextLocoFunctionTypeTimer; |
| 457 | |
| 458 | map<DataModel::LocoFunctionIcon,Languages::TextSelector> functionIcons; |
| 459 | functionIcons[DataModel::LocoFunctionIconDefault] = Languages::TextLocoFunctionIconDefault; |
| 460 | functionIcons[DataModel::LocoFunctionIconShuntingMode] = Languages::TextLocoFunctionIconShuntingMode; |
| 461 | functionIcons[DataModel::LocoFunctionIconInertia] = Languages::TextLocoFunctionIconInertia; |
| 462 | functionIcons[DataModel::LocoFunctionIconLight] = Languages::TextLocoFunctionIconLight; |
| 463 | functionIcons[DataModel::LocoFunctionIconHeadlightLowBeamForward] = Languages::TextLocoFunctionIconHeadlightLowBeamForward; |
| 464 | functionIcons[DataModel::LocoFunctionIconHeadlightLowBeamReverse] = Languages::TextLocoFunctionIconHeadlightLowBeamReverse; |
| 465 | functionIcons[DataModel::LocoFunctionIconHeadlightHighBeamForward] = Languages::TextLocoFunctionIconHeadlightHighBeamForward; |
| 466 | functionIcons[DataModel::LocoFunctionIconHeadlightHighBeamReverse] = Languages::TextLocoFunctionIconHeadlightHighBeamReverse; |
| 467 | functionIcons[DataModel::LocoFunctionIconBacklightForward] = Languages::TextLocoFunctionIconBacklightForward; |
| 468 | functionIcons[DataModel::LocoFunctionIconBacklightReverse] = Languages::TextLocoFunctionIconBacklightReverse; |
| 469 | functionIcons[DataModel::LocoFunctionIconShuntingLight] = Languages::TextLocoFunctionIconShuntingLight; |
| 470 | functionIcons[DataModel::LocoFunctionIconBlinkingLight] = Languages::TextLocoFunctionIconBlinkingLight; |
| 471 | functionIcons[DataModel::LocoFunctionIconInteriorLight1] = Languages::TextLocoFunctionIconInteriorLight1; |
| 472 | functionIcons[DataModel::LocoFunctionIconInteriorLight2] = Languages::TextLocoFunctionIconInteriorLight2; |
| 473 | functionIcons[DataModel::LocoFunctionIconTableLight1] = Languages::TextLocoFunctionIconTableLight1; |
| 474 | functionIcons[DataModel::LocoFunctionIconTableLight2] = Languages::TextLocoFunctionIconTableLight2; |
| 475 | functionIcons[DataModel::LocoFunctionIconTableLight3] = Languages::TextLocoFunctionIconTableLight3; |
| 476 | functionIcons[DataModel::LocoFunctionIconCabLight1] = Languages::TextLocoFunctionIconCabLight1; |
| 477 | functionIcons[DataModel::LocoFunctionIconCabLight2] = Languages::TextLocoFunctionIconCabLight2; |
| 478 | functionIcons[DataModel::LocoFunctionIconCabLight12] = Languages::TextLocoFunctionIconCabLight12; |
| 479 | functionIcons[DataModel::LocoFunctionIconDriversDeskLight] = Languages::TextLocoFunctionIconDriversDeskLight; |
| 480 | functionIcons[DataModel::LocoFunctionIconTrainDestinationIndicator] = Languages::TextLocoFunctionIconTrainDestinationIndicator; |
| 481 | functionIcons[DataModel::LocoFunctionIconLocomotiveNumberIndicator] = Languages::TextLocoFunctionIconLocomotiveNumberIndicator; |
| 482 | functionIcons[DataModel::LocoFunctionIconEngineLight] = Languages::TextLocoFunctionIconEngineLight; |
| 483 | functionIcons[DataModel::LocoFunctionIconFireBox] = Languages::TextLocoFunctionIconFireBox; |
| 484 | functionIcons[DataModel::LocoFunctionIconStairsLight] = Languages::TextLocoFunctionIconStairsLight; |
| 485 | functionIcons[DataModel::LocoFunctionIconSmokeGenerator] = Languages::TextLocoFunctionIconSmokeGenerator; |
| 486 | functionIcons[DataModel::LocoFunctionIconTelex1] = Languages::TextLocoFunctionIconTelex1; |
| 487 | functionIcons[DataModel::LocoFunctionIconTelex2] = Languages::TextLocoFunctionIconTelex2; |
| 488 | functionIcons[DataModel::LocoFunctionIconTelex12] = Languages::TextLocoFunctionIconTelex12; |
| 489 | functionIcons[DataModel::LocoFunctionIconPanto1] = Languages::TextLocoFunctionIconPanto1; |
| 490 | functionIcons[DataModel::LocoFunctionIconPanto2] = Languages::TextLocoFunctionIconPanto2; |
| 491 | functionIcons[DataModel::LocoFunctionIconPanto12] = Languages::TextLocoFunctionIconPanto12; |
| 492 | functionIcons[DataModel::LocoFunctionIconUp] = Languages::TextLocoFunctionIconUp; |
| 493 | functionIcons[DataModel::LocoFunctionIconDown] = Languages::TextLocoFunctionIconDown; |
| 494 | functionIcons[DataModel::LocoFunctionIconUpDown1] = Languages::TextLocoFunctionIconUpDown1; |
| 495 | functionIcons[DataModel::LocoFunctionIconUpDown2] = Languages::TextLocoFunctionIconUpDown2; |
| 496 | functionIcons[DataModel::LocoFunctionIconLeft] = Languages::TextLocoFunctionIconLeft; |
| 497 | functionIcons[DataModel::LocoFunctionIconRight] = Languages::TextLocoFunctionIconRight; |
| 498 | functionIcons[DataModel::LocoFunctionIconLeftRight] = Languages::TextLocoFunctionIconLeftRight; |
| 499 | functionIcons[DataModel::LocoFunctionIconTurnLeft] = Languages::TextLocoFunctionIconTurnLeft; |
| 500 | functionIcons[DataModel::LocoFunctionIconTurnRight] = Languages::TextLocoFunctionIconTurnRight; |
| 501 | functionIcons[DataModel::LocoFunctionIconTurn] = Languages::TextLocoFunctionIconTurn; |
| 502 | functionIcons[DataModel::LocoFunctionIconCrane] = Languages::TextLocoFunctionIconCrane; |
| 503 | functionIcons[DataModel::LocoFunctionIconMagnet] = Languages::TextLocoFunctionIconMagnet; |
| 504 | functionIcons[DataModel::LocoFunctionIconCraneHook] = Languages::TextLocoFunctionIconCraneHook; |
| 505 | functionIcons[DataModel::LocoFunctionIconFan] = Languages::TextLocoFunctionIconFan; |
| 506 | functionIcons[DataModel::LocoFunctionIconBreak] = Languages::TextLocoFunctionIconBreak; |
| 507 | functionIcons[DataModel::LocoFunctionIconNoSound] = Languages::TextLocoFunctionIconNoSound; |
| 508 | functionIcons[DataModel::LocoFunctionIconSoundGeneral] = Languages::TextLocoFunctionIconSoundGeneral; |
| 509 | functionIcons[DataModel::LocoFunctionIconRunning1] = Languages::TextLocoFunctionIconRunning1; |
| 510 | functionIcons[DataModel::LocoFunctionIconRunning2] = Languages::TextLocoFunctionIconRunning2; |
| 511 | functionIcons[DataModel::LocoFunctionIconEngine1] = Languages::TextLocoFunctionIconEngine1; |
| 512 | functionIcons[DataModel::LocoFunctionIconEngine2] = Languages::TextLocoFunctionIconEngine2; |
| 513 | functionIcons[DataModel::LocoFunctionIconBreak1] = Languages::TextLocoFunctionIconBreak1; |
| 514 | functionIcons[DataModel::LocoFunctionIconBreak2] = Languages::TextLocoFunctionIconBreak2; |
| 515 | functionIcons[DataModel::LocoFunctionIconCurve] = Languages::TextLocoFunctionIconCurve; |
| 516 | functionIcons[DataModel::LocoFunctionIconHorn1] = Languages::TextLocoFunctionIconHorn1; |
| 517 | functionIcons[DataModel::LocoFunctionIconHorn2] = Languages::TextLocoFunctionIconHorn2; |
| 518 | functionIcons[DataModel::LocoFunctionIconWhistle1] = Languages::TextLocoFunctionIconWhistle1; |
| 519 | functionIcons[DataModel::LocoFunctionIconWhistle2] = Languages::TextLocoFunctionIconWhistle2; |
| 520 | functionIcons[DataModel::LocoFunctionIconBell] = Languages::TextLocoFunctionIconBell; |
| 521 | functionIcons[DataModel::LocoFunctionIconStationAnnouncement1] = Languages::TextLocoFunctionIconStationAnnouncement1; |
| 522 | functionIcons[DataModel::LocoFunctionIconStationAnnouncement2] = Languages::TextLocoFunctionIconStationAnnouncement2; |
| 523 | functionIcons[DataModel::LocoFunctionIconStationAnnouncement3] = Languages::TextLocoFunctionIconStationAnnouncement3; |
| 524 | functionIcons[DataModel::LocoFunctionIconSpeak] = Languages::TextLocoFunctionIconSpeak; |
| 525 | functionIcons[DataModel::LocoFunctionIconRadio] = Languages::TextLocoFunctionIconRadio; |
| 526 | functionIcons[DataModel::LocoFunctionIconMusic1] = Languages::TextLocoFunctionIconMusic1; |
| 527 | functionIcons[DataModel::LocoFunctionIconMusic2] = Languages::TextLocoFunctionIconMusic2; |
| 528 | functionIcons[DataModel::LocoFunctionIconOpenDoor] = Languages::TextLocoFunctionIconOpenDoor; |
| 529 | functionIcons[DataModel::LocoFunctionIconCloseDoor] = Languages::TextLocoFunctionIconCloseDoor; |
| 530 | functionIcons[DataModel::LocoFunctionIconFan1] = Languages::TextLocoFunctionIconFan1; |
| 531 | functionIcons[DataModel::LocoFunctionIconFan2] = Languages::TextLocoFunctionIconFan2; |
| 532 | functionIcons[DataModel::LocoFunctionIconFan3] = Languages::TextLocoFunctionIconFan3; |
| 533 | functionIcons[DataModel::LocoFunctionIconShovelCoal] = Languages::TextLocoFunctionIconShovelCoal; |
| 534 | functionIcons[DataModel::LocoFunctionIconCompressedAir] = Languages::TextLocoFunctionIconCompressedAir; |
| 535 | functionIcons[DataModel::LocoFunctionIconReliefValve] = Languages::TextLocoFunctionIconReliefValve; |
| 536 | functionIcons[DataModel::LocoFunctionIconSteamBlowOut] = Languages::TextLocoFunctionIconSteamBlowOut; |
| 537 | functionIcons[DataModel::LocoFunctionIconSteamBlow] = Languages::TextLocoFunctionIconSteamBlow; |
| 538 | functionIcons[DataModel::LocoFunctionIconDrainValve] = Languages::TextLocoFunctionIconDrainValve; |
| 539 | functionIcons[DataModel::LocoFunctionIconShakingRust] = Languages::TextLocoFunctionIconShakingRust; |
| 540 | functionIcons[DataModel::LocoFunctionIconAirPump] = Languages::TextLocoFunctionIconAirPump; |
| 541 | functionIcons[DataModel::LocoFunctionIconWaterPump] = Languages::TextLocoFunctionIconWaterPump; |
| 542 | functionIcons[DataModel::LocoFunctionIconBufferPush] = Languages::TextLocoFunctionIconBufferPush; |
| 543 | functionIcons[DataModel::LocoFunctionIconGenerator] = Languages::TextLocoFunctionIconGenerator; |
| 544 | functionIcons[DataModel::LocoFunctionIconGearBox] = Languages::TextLocoFunctionIconGearBox; |
| 545 | functionIcons[DataModel::LocoFunctionIconGearUp] = Languages::TextLocoFunctionIconGearUp; |
| 546 | functionIcons[DataModel::LocoFunctionIconGearDown] = Languages::TextLocoFunctionIconGearDown; |
| 547 | functionIcons[DataModel::LocoFunctionIconFillWater] = Languages::TextLocoFunctionIconFillWater; |
| 548 | functionIcons[DataModel::LocoFunctionIconFillDiesel] = Languages::TextLocoFunctionIconFillDiesel; |
| 549 | functionIcons[DataModel::LocoFunctionIconFillGas] = Languages::TextLocoFunctionIconFillGas; |
| 550 | functionIcons[DataModel::LocoFunctionIconSand] = Languages::TextLocoFunctionIconSand; |
| 551 | functionIcons[DataModel::LocoFunctionIconRailJoint] = Languages::TextLocoFunctionIconRailJoint; |
| 552 | functionIcons[DataModel::LocoFunctionIconCoupler] = Languages::TextLocoFunctionIconCoupler; |
| 553 | functionIcons[DataModel::LocoFunctionIconPanto] = Languages::TextLocoFunctionIconPanto; |
| 554 | functionIcons[DataModel::LocoFunctionIconMainSwitch] = Languages::TextLocoFunctionIconMainSwitch; |
| 555 | functionIcons[DataModel::LocoFunctionIconSoundLouder] = Languages::TextLocoFunctionIconSoundLouder; |
| 556 | functionIcons[DataModel::LocoFunctionIconSoundLower] = Languages::TextLocoFunctionIconSoundLower; |
| 557 | functionIcons[DataModel::LocoFunctionIconNoBreak] = Languages::TextLocoFunctionIconNoBreak; |
| 558 | for (unsigned int nr = 0; nr < NumberOfLocoFunctions; ++nr) |
| 559 | { |
| 560 | HtmlTag fDiv("div"); |
| 561 | fDiv.AddClass("function_line"); |
| 562 | string nrString = to_string(nr); |
| 563 | string fNrString = "f" + nrString; |
| 564 | fDiv.AddChildTag(HtmlTagLabel("F" + nrString, fNrString + "_type")); |
| 565 | |
| 566 | const DataModel::LocoFunctionType functionType = locoFunctions[nr].type; |
| 567 | DataModel::LocoFunctionIcon icon = locoFunctions[nr].icon; |
| 568 | DataModel::LocoFunctionTimer timer = locoFunctions[nr].timer; |
| 569 | |
| 570 | fDiv.AddChildTag(HtmlTagSelect(fNrString + "_type", functionTypes, functionType).AddAttribute("onchange", "onChangeLocoFunctionType(" + nrString + ");return false;")); |
| 571 | HtmlTagSelect selectIcon(fNrString + "_icon", functionIcons, icon); |
| 572 | HtmlTagInputInteger inputTimer(fNrString + "_timer", timer, 1, 255); |
| 573 | if (functionType == LocoFunctionTypeNone) |
| 574 | { |
| 575 | selectIcon.AddClass("hidden"); |
| 576 | } |
| 577 | if (functionType != LocoFunctionTypeTimer) |
| 578 | { |
| 579 | inputTimer.AddClass("hidden"); |
| 580 | } |
| 581 | inputTimer.AddClass("function_line_integer"); |
| 582 | |
| 583 | fDiv.AddChildTag(selectIcon); |
| 584 | fDiv.AddChildTag(inputTimer); |
| 585 | functionsContent.AddChildTag(fDiv); |
| 586 | } |
| 587 | return functionsContent; |
| 588 | } |
| 589 | |
| 590 | HtmlTag WebClientStatic::HtmlTagTabAutomode(const bool pushpull, |
| 591 | const Speed maxSpeed, |
| 592 | const Speed travelSpeed, |
| 593 | const Speed reducedSpeed, |
| 594 | const Speed creepingSpeed) |
| 595 | { |
| 596 | HtmlTag automodeContent("div"); |
| 597 | automodeContent.AddId("tab_automode"); |
| 598 | automodeContent.AddClass("tab_content"); |
| 599 | automodeContent.AddClass("hidden"); |
| 600 | automodeContent.AddChildTag(HtmlTagInputCheckboxWithLabel("pushpull", Languages::TextPushPullTrain, "pushpull", pushpull)); |
| 601 | automodeContent.AddChildTag(HtmlTagInputIntegerWithLabel("maxspeed", Languages::TextMaxSpeed, maxSpeed, 0, MaxSpeed)); |
| 602 | automodeContent.AddChildTag(HtmlTagInputIntegerWithLabel("travelspeed", Languages::TextTravelSpeed, travelSpeed, 0, MaxSpeed)); |
| 603 | automodeContent.AddChildTag(HtmlTagInputIntegerWithLabel("reducedspeed", Languages::TextReducedSpeed, reducedSpeed, 0, MaxSpeed)); |
| 604 | automodeContent.AddChildTag(HtmlTagInputIntegerWithLabel("creepingspeed", Languages::TextCreepingSpeed, creepingSpeed, 0, MaxSpeed)); |
| 605 | return automodeContent; |
| 606 | } |
| 607 | |
| 608 | vector<DataModel::Relation*> WebClientStatic::ConvertSlaveIDVectorToRelation(Manager& manager, |
| 609 | const MultipleUnitID multipleUnitID, |
| 610 | const vector<LocoID>& slaveIDs) |
| 611 | { |
| 612 | vector<DataModel::Relation*> slaves; |
| 613 | for (auto const & slaveID : slaveIDs) |
| 614 | { |
| 615 | slaves.push_back(new Relation(&manager, |
| 616 | ObjectIdentifier(ObjectTypeMultipleUnit, multipleUnitID), |
| 617 | ObjectIdentifier(ObjectTypeLoco, slaveID), |
| 618 | Relation::RelationTypeMultipleUnitLoco)); |
| 619 | } |
| 620 | return slaves; |
| 621 | } |
| 622 | }} // namespace Server::Web |