/* RailControl - Model Railway Control Software Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org RailControl is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. RailControl is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with RailControl; see the file LICENCE. If not see . */ #include #include #include #include "DataModel/LocoFunctions.h" #include "Utils/Integer.h" #include "Utils/Utils.h" namespace DataModel { LocoFunctions::LocoFunctions() { for (LocoFunctionNr nr = 0; nr < NumberOfLocoFunctions; ++nr) { entries[nr].nr = nr; entries[nr].type = LocoFunctionTypeNone; entries[nr].icon = LocoFunctionIconNone; entries[nr].timer = 0; } } std::vector LocoFunctions::GetFunctionStates() const { std::vector out; for (LocoFunctionNr i = 0; i < NumberOfLocoFunctions; ++i) { if (entries[i].type == LocoFunctionTypeNone) { continue; } out.push_back(entries[i]); } return out; } void LocoFunctions::ConfigureFunctions(const std::vector& newEntries) { for (LocoFunctionNr nr = 0; nr < NumberOfLocoFunctions; ++nr) { entries[nr].type = LocoFunctionTypeNone; } for (const LocoFunctionEntry& newEntry : newEntries) { LocoFunctionNr nr = newEntry.nr; LocoFunctionState state = entries[nr].state; entries[nr] = newEntry; entries[nr].state = state; } } void LocoFunctions::SetFunctionStates(const std::vector& newEntries) { for (LocoFunctionNr nr = 0; nr < NumberOfLocoFunctions; ++nr) { entries[nr].type = LocoFunctionTypeNone; } for (const LocoFunctionEntry& newEntry : newEntries) { LocoFunctionNr nr = newEntry.nr; entries[nr] = newEntry; } } std::string LocoFunctions::Serialize() const { std::string out; for (LocoFunctionNr nr = 0; nr < NumberOfLocoFunctions; ++nr) { if (entries[nr].type == LocoFunctionTypeNone) { continue; } out += "f" + std::to_string(static_cast(nr)); out += ":" + std::to_string(static_cast(entries[nr].state)); out += ":" + std::to_string(static_cast(entries[nr].type)); out += ":" + std::to_string(static_cast(entries[nr].icon)); if (entries[nr].type != LocoFunctionTypeTimer) { continue; } out += ":" + std::to_string(static_cast(entries[nr].icon)); } return out; } void LocoFunctions::Deserialize(const std::string& serialized) { std::deque functionsSerialized; Utils::Utils::SplitString(serialized, "f", functionsSerialized); for (std::string& functionSerialized : functionsSerialized) { if (functionSerialized.size() == 0) { continue; } std::deque functionTexts; Utils::Utils::SplitString(functionSerialized, ":", functionTexts); const size_t nrOfTexts = functionTexts.size(); if (nrOfTexts != 4 && nrOfTexts != 5) { continue; } LocoFunctionNr nr = Utils::Integer::StringToInteger(functionTexts.front()); functionTexts.pop_front(); entries[nr].state = static_cast(Utils::Integer::StringToInteger(functionTexts.front(), LocoFunctionStateOff)); functionTexts.pop_front(); entries[nr].type = static_cast(Utils::Integer::StringToInteger(functionTexts.front(), LocoFunctionTypePermanent)); functionTexts.pop_front(); entries[nr].icon = static_cast(Utils::Integer::StringToInteger(functionTexts.front(), LocoFunctionIconDefault)); functionTexts.pop_front(); if (nrOfTexts == 4) { entries[nr].timer = 0; continue; } entries[nr].timer = static_cast(Utils::Integer::StringToInteger(functionTexts.front(), 0)); functionTexts.pop_front(); } } std::string LocoFunctions::GetLocoFunctionIcon(const LocoFunctionNr nr, const LocoFunctionIcon icon) { switch (icon) { case LocoFunctionIconNone: return ""; case LocoFunctionIconShuntingMode: return "" "" "" "" "" ""; case LocoFunctionIconInertia: return "" "" "" "kg" ""; case LocoFunctionIconLight: return "" "" "" "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconHeadlightLowBeamForward: return "" "" "" "" "" "" ""; case LocoFunctionIconHeadlightLowBeamReverse: return "" "" "" "" "" "" ""; case LocoFunctionIconHeadlightHighBeamForward: return "" "" "" "" "" "" "" ""; case LocoFunctionIconHeadlightHighBeamReverse: return "" "" "" "" "" "" "" ""; case LocoFunctionIconBacklightForward: return "" "" "" "" "" "" "" "" ""; case LocoFunctionIconBacklightReverse: return "" "" "" "" "" "" "" "" ""; case LocoFunctionIconShuntingLight: return "" "" "" "" "" "" "" ""; case LocoFunctionIconBlinkingLight: return "" "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconInteriorLight1: return "" "" "" "" "" "" "" "" "1" ""; case LocoFunctionIconInteriorLight2: return "" "" "" "" "" "" "" "" "2" ""; case LocoFunctionIconTableLight1: return "" "" "" "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconTableLight2: return "" "" "" "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconTableLight3: return "" "" "" "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconCabLight1: return "" "" "" "" "" "" "" "" ""; case LocoFunctionIconCabLight2: return "" "" "" "" "" "" "" "" ""; case LocoFunctionIconCabLight12: return "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconDriversDeskLight: return "" "" "" "" "" ""; case LocoFunctionIconTrainDestinationIndicator: return "" "" "Zürich" "" "" "" "" "" "" ""; case LocoFunctionIconLocomotiveNumberIndicator: return "" "" "X4014" "" "" "" "" "" "" ""; case LocoFunctionIconEngineLight: return "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconFireBox: return "" "" "" "" "" "" "" "" ""; case LocoFunctionIconStairsLight: return "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconSmokeGenerator: return "" "" "" "" ""; case LocoFunctionIconTelex1: return "" "" "" "" ""; case LocoFunctionIconTelex2: return "" "" "" "" ""; case LocoFunctionIconTelex12: return "" "" "" ""; case LocoFunctionIconPanto1: return "" "" "" "" "" "" ""; case LocoFunctionIconPanto2: return "" "" "" "" "" "" ""; case LocoFunctionIconPanto12: return "" "" "" "" "" ""; case LocoFunctionIconUp: return "" "" ""; case LocoFunctionIconDown: return "" "" ""; case LocoFunctionIconUpDown1: return "" "" ""; case LocoFunctionIconUpDown2: return "" "" ""; case LocoFunctionIconLeft: return "" "" ""; case LocoFunctionIconRight: return "" "" ""; case LocoFunctionIconLeftRight: return "" "" ""; case LocoFunctionIconTurnLeft: return "" "" ""; case LocoFunctionIconTurnRight: return "" "" ""; case LocoFunctionIconTurn: return "" "" ""; case LocoFunctionIconCrane: return "" "" "" "" ""; case LocoFunctionIconMagnet: return "" "" "" "" "" ""; case LocoFunctionIconCraneHook: return "" "" ""; case LocoFunctionIconFan: return "" "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconBreak: return "" "" "" "" "" "" ""; case LocoFunctionIconNoSound: return "" "" "" "" "" "" "" "" ""; case LocoFunctionIconSoundGeneral: return "" "" "" "" "" "" ""; case LocoFunctionIconRunning1: return "" "" "" "" "" "" "" "" "1" "" "" "" "" ""; case LocoFunctionIconRunning2: return "" "" "" "" "" "" "" "" "2" "" "" "" "" ""; case LocoFunctionIconEngine1: return "" "" "" "M" "" "" "" "" "1" ""; case LocoFunctionIconEngine2: return "" "" "" "M" "" "" "" "" "2" ""; case LocoFunctionIconBreak1: return "" "" "" "" "" "" "" "" "" "1" ""; case LocoFunctionIconBreak2: return "" "" "" "" "" "" "" "" "" "2" ""; case LocoFunctionIconCurve: return "" "" "" "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconHorn1: return "" "" "" "" "" "1" ""; case LocoFunctionIconHorn2: return "" "" "" "" "" "2" ""; case LocoFunctionIconWhistle1: return "" "" "" "" "" "" ""; case LocoFunctionIconWhistle2: return "" "" "" "" "" ""; case LocoFunctionIconBell: return "" "" "" "" "" "" "" ""; case LocoFunctionIconStationAnnouncement1: return "" "" "" "" "" "1" ""; case LocoFunctionIconStationAnnouncement2: return "" "" "" "" "" "2" ""; case LocoFunctionIconStationAnnouncement3: return "" "" "" "" "" "3" ""; case LocoFunctionIconSpeak: return "" "" ""; case LocoFunctionIconRadio: return "" "" "" "" "" "" ""; case LocoFunctionIconMusic1: return "" "" "" "" "" "" "" "" "1" ""; case LocoFunctionIconMusic2: return "" "" "" "" "" "" "" "" "2" ""; case LocoFunctionIconOpenDoor: return "" "" "" ""; case LocoFunctionIconCloseDoor: return "" "" "" ""; case LocoFunctionIconFan1: return "" "" "" "" "" "" "1" "" "" "" "" ""; case LocoFunctionIconFan2: return "" "" "" "" "" "" "2" "" "" "" "" ""; case LocoFunctionIconFan3: return "" "" "" "" "" "" "3" "" "" "" "" ""; case LocoFunctionIconShovelCoal: return "" "" "" "" "" "" ""; case LocoFunctionIconCompressedAir: return "" "" "" "" "" "" "" "" ""; case LocoFunctionIconReliefValve: return "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconSteamBlowOut: return "" "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconSteamBlow: return "" "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconDrainValve: return "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconShakingRust: return "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconAirPump: return "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconWaterPump: return "" "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconBufferPush: return "" "" "" "" "" "" "" "" ""; case LocoFunctionIconGenerator: return "" "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconGearBox: return "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconGearUp: return "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconGearDown: return "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconFillWater: return "" "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconFillDiesel: return "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconFillGas: return "" "" "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconSand: return "" "" "" "" "" "" "" "" ""; case LocoFunctionIconRailJoint: return "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""; case LocoFunctionIconCoupler: return "" "" "" "" "" "" ""; case LocoFunctionIconPanto: return "" "" "" "" "" "" "" ""; case LocoFunctionIconMainSwitch: return "" "" "" "" "" "" ""; case LocoFunctionIconSoundLouder: return "" "" "" "" "" ""; case LocoFunctionIconSoundLower: return "" "" "" "" ""; case LocoFunctionIconNoBreak: return "" "" "" "" "" "" "" "" "" "" "" ""; default: return "" "F" + std::to_string(nr) + "" ""; } } } // namespace DataModel