diff --git a/server/src/hardware/throttle/list/throttlelistcolumn.hpp b/server/src/hardware/throttle/list/throttlelistcolumn.hpp index 46f006de..dfe44b96 100644 --- a/server/src/hardware/throttle/list/throttlelistcolumn.hpp +++ b/server/src/hardware/throttle/list/throttlelistcolumn.hpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2022 Reinder Feenstra + * Copyright (C) 2022,2025 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -29,12 +29,14 @@ enum class ThrottleListColumn { Id = 1 << 0, Name = 1 << 1, - Interface = 1 << 2, + Train = 1 << 2, + Interface = 1 << 3, }; -constexpr std::array throttleListColumnValues = { +constexpr std::array throttleListColumnValues = { ThrottleListColumn::Id, ThrottleListColumn::Name, + ThrottleListColumn::Train, ThrottleListColumn::Interface, }; diff --git a/server/src/hardware/throttle/list/throttlelisttablemodel.cpp b/server/src/hardware/throttle/list/throttlelisttablemodel.cpp index 7fed16a7..497555bf 100644 --- a/server/src/hardware/throttle/list/throttlelisttablemodel.cpp +++ b/server/src/hardware/throttle/list/throttlelisttablemodel.cpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2022 Reinder Feenstra + * Copyright (C) 2022,2025 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -22,6 +22,9 @@ #include "throttlelisttablemodel.hpp" #include "throttlelist.hpp" +#include "../webthrottle.hpp" +#include "../../../core/objectproperty.tpp" +#include "../../../train/train.hpp" #include "../../../utils/displayname.hpp" bool ThrottleListTableModel::isListedProperty(std::string_view name) @@ -29,6 +32,7 @@ bool ThrottleListTableModel::isListedProperty(std::string_view name) return name == "id" || name == "name" || + name == "train" || name == "interface"; } @@ -42,6 +46,9 @@ static std::string_view displayName(ThrottleListColumn column) case ThrottleListColumn::Name: return DisplayName::Object::name; + case ThrottleListColumn::Train: + return DisplayName::Vehicle::Rail::train; + case ThrottleListColumn::Interface: return DisplayName::Hardware::interface; } @@ -81,6 +88,13 @@ std::string ThrottleListTableModel::getText(uint32_t column, uint32_t row) const case ThrottleListColumn::Name: return throttle.name; + case ThrottleListColumn::Train: + if(throttle.train) + { + return throttle.train->name; + } + return {}; + case ThrottleListColumn::Interface: if(const auto* interfaceProperty = throttle.getObjectProperty("interface"); interfaceProperty) { @@ -92,6 +106,10 @@ std::string ThrottleListTableModel::getText(uint32_t column, uint32_t row) const return interface->getObjectId(); } } + else if(dynamic_cast(&throttle)) + { + return "WebThrottle"; + } return ""; } assert(false); @@ -108,6 +126,8 @@ void ThrottleListTableModel::propertyChanged(BaseProperty& property, uint32_t ro changed(row, ThrottleListColumn::Id); else if(name == "name") changed(row, ThrottleListColumn::Name); + else if(name == "train") + changed(row, ThrottleListColumn::Train); else if(name == "interface") changed(row, ThrottleListColumn::Interface); } diff --git a/server/src/hardware/throttle/throttle.cpp b/server/src/hardware/throttle/throttle.cpp index 5abf85fc..7a19f3f2 100644 --- a/server/src/hardware/throttle/throttle.cpp +++ b/server/src/hardware/throttle/throttle.cpp @@ -21,6 +21,8 @@ */ #include "throttle.hpp" +#include "list/throttlelist.hpp" +#include "list/throttlelisttablemodel.hpp" #include "../../core/attributes.hpp" #include "../../core/method.tpp" #include "../../core/objectproperty.tpp" @@ -256,10 +258,17 @@ void Throttle::release(bool stopIt) void Throttle::destroying() { + m_world.throttles->removeObject(shared_ptr()); release(); IdObject::destroying(); } +void Throttle::addToWorld() +{ + IdObject::addToWorld(); + m_world.throttles->addObject(shared_ptr()); +} + Throttle::AcquireResult Throttle::acquire(std::shared_ptr decoder, bool steal) { if(!decoder->acquire(*this, steal)) diff --git a/server/src/hardware/throttle/throttle.hpp b/server/src/hardware/throttle/throttle.hpp index 18f514c0..661c5f9b 100644 --- a/server/src/hardware/throttle/throttle.hpp +++ b/server/src/hardware/throttle/throttle.hpp @@ -57,6 +57,7 @@ class Throttle : public IdObject Throttle(World& world, std::string_view _id); void destroying() override; + void addToWorld() override; AcquireResult acquire(std::shared_ptr decoder, bool steal = false); diff --git a/server/src/world/world.cpp b/server/src/world/world.cpp index 3d079f44..c0989ebb 100644 --- a/server/src/world/world.cpp +++ b/server/src/world/world.cpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2019-2024 Reinder Feenstra + * Copyright (C) 2019-2025 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -63,6 +63,7 @@ #include "../board/nx/nxmanager.hpp" #include "../board/tile/rail/nxbuttonrailtile.hpp" +#include "../hardware/throttle/list/throttlelist.hpp" #include "../train/train.hpp" #include "../train/trainlist.hpp" #include "../vehicle/rail/railvehiclelist.hpp" @@ -76,6 +77,7 @@ constexpr auto decoderListColumns = DecoderListColumn::Id | DecoderListColumn::N constexpr auto inputListColumns = InputListColumn::Id | InputListColumn::Name | InputListColumn::Interface | InputListColumn::Channel | InputListColumn::Address; constexpr auto outputListColumns = OutputListColumn::Interface | OutputListColumn::Channel | OutputListColumn::Address; constexpr auto identificationListColumns = IdentificationListColumn::Id | IdentificationListColumn::Name | IdentificationListColumn::Interface /*| IdentificationListColumn::Channel*/ | IdentificationListColumn::Address; +constexpr auto throttleListColumns = ThrottleListColumn::Id | ThrottleListColumn::Name | ThrottleListColumn::Train | ThrottleListColumn::Interface; template inline static void deleteAll(T& objectList) @@ -116,6 +118,7 @@ void World::init(World& world) world.identifications.setValueInternal(std::make_shared(world, world.outputs.name(), identificationListColumns)); world.boards.setValueInternal(std::make_shared(world, world.boards.name())); world.clock.setValueInternal(std::make_shared(world, world.clock.name())); + world.throttles.setValueInternal(std::make_shared(world, world.throttles.name(), throttleListColumns)); world.trains.setValueInternal(std::make_shared(world, world.trains.name())); world.railVehicles.setValueInternal(std::make_shared(world, world.railVehicles.name())); world.luaScripts.setValueInternal(std::make_shared(world, world.luaScripts.name())); @@ -163,6 +166,7 @@ World::World(Private /*unused*/) : identifications{this, "identifications", nullptr, PropertyFlags::ReadOnly | PropertyFlags::SubObject | PropertyFlags::NoStore}, boards{this, "boards", nullptr, PropertyFlags::ReadOnly | PropertyFlags::SubObject | PropertyFlags::NoStore | PropertyFlags::ScriptReadOnly}, clock{this, "clock", nullptr, PropertyFlags::ReadOnly | PropertyFlags::SubObject | PropertyFlags::Store | PropertyFlags::ScriptReadOnly}, + throttles{this, "throttles", nullptr, PropertyFlags::ReadOnly | PropertyFlags::SubObject | PropertyFlags::NoStore}, trains{this, "trains", nullptr, PropertyFlags::ReadOnly | PropertyFlags::SubObject | PropertyFlags::NoStore | PropertyFlags::ScriptReadOnly}, railVehicles{this, "rail_vehicles", nullptr, PropertyFlags::ReadOnly | PropertyFlags::SubObject | PropertyFlags::NoStore | PropertyFlags::ScriptReadOnly}, luaScripts{this, "lua_scripts", nullptr, PropertyFlags::ReadOnly | PropertyFlags::SubObject | PropertyFlags::NoStore}, @@ -360,6 +364,8 @@ World::World(Private /*unused*/) : m_interfaceItems.add(outputs); Attributes::addObjectEditor(identifications, false); m_interfaceItems.add(identifications); + Attributes::addObjectEditor(throttles, false); + m_interfaceItems.add(throttles); Attributes::addObjectEditor(boards, false); m_interfaceItems.add(boards); Attributes::addObjectEditor(clock, false); diff --git a/server/src/world/world.hpp b/server/src/world/world.hpp index b1a77dfb..62a63ad3 100644 --- a/server/src/world/world.hpp +++ b/server/src/world/world.hpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2019-2024 Reinder Feenstra + * Copyright (C) 2019-2025 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -53,6 +53,7 @@ class BoardList; class LinkRailTileList; class NXManager; class Clock; +class ThrottleList; class TrainList; class RailVehicleList; class SimulationStatus; @@ -122,6 +123,7 @@ class World : public Object ObjectProperty identifications; ObjectProperty boards; ObjectProperty clock; + ObjectProperty throttles; ObjectProperty trains; ObjectProperty railVehicles; ObjectProperty luaScripts;