Added list of active throttles to world

Dieser Commit ist enthalten in:
Reinder Feenstra 2025-01-11 10:33:30 +01:00
Ursprung 78a8e17958
Commit b73ed8c0eb
6 geänderte Dateien mit 46 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -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<ThrottleListColumn, 3> throttleListColumnValues = {
constexpr std::array<ThrottleListColumn, 4> throttleListColumnValues = {
ThrottleListColumn::Id,
ThrottleListColumn::Name,
ThrottleListColumn::Train,
ThrottleListColumn::Interface,
};

Datei anzeigen

@ -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<const WebThrottle*>(&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);
}

Datei anzeigen

@ -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<Throttle>());
release();
IdObject::destroying();
}
void Throttle::addToWorld()
{
IdObject::addToWorld();
m_world.throttles->addObject(shared_ptr<Throttle>());
}
Throttle::AcquireResult Throttle::acquire(std::shared_ptr<Decoder> decoder, bool steal)
{
if(!decoder->acquire(*this, steal))

Datei anzeigen

@ -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> decoder, bool steal = false);

Datei anzeigen

@ -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<class T>
inline static void deleteAll(T& objectList)
@ -116,6 +118,7 @@ void World::init(World& world)
world.identifications.setValueInternal(std::make_shared<IdentificationList>(world, world.outputs.name(), identificationListColumns));
world.boards.setValueInternal(std::make_shared<BoardList>(world, world.boards.name()));
world.clock.setValueInternal(std::make_shared<Clock>(world, world.clock.name()));
world.throttles.setValueInternal(std::make_shared<ThrottleList>(world, world.throttles.name(), throttleListColumns));
world.trains.setValueInternal(std::make_shared<TrainList>(world, world.trains.name()));
world.railVehicles.setValueInternal(std::make_shared<RailVehicleList>(world, world.railVehicles.name()));
world.luaScripts.setValueInternal(std::make_shared<Lua::ScriptList>(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);

Datei anzeigen

@ -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<IdentificationList> identifications;
ObjectProperty<BoardList> boards;
ObjectProperty<Clock> clock;
ObjectProperty<ThrottleList> throttles;
ObjectProperty<TrainList> trains;
ObjectProperty<RailVehicleList> railVehicles;
ObjectProperty<Lua::ScriptList> luaScripts;