outputmap: added parent property for client, so it can access the object the outputmap belongs to.

Dieser Commit ist enthalten in:
Reinder Feenstra 2024-07-08 23:11:09 +02:00
Ursprung 4d76dc8891
Commit 80b08cb02a
10 geänderte Dateien mit 32 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -89,6 +89,12 @@ SwitchTile::SwitchTile(World& world, std::string_view _id)
m_interfaceItems.add(onValueChanged); m_interfaceItems.add(onValueChanged);
} }
void SwitchTile::addToWorld()
{
outputMap->parentObject.setValueInternal(shared_from_this());
Tile::addToWorld();
}
void SwitchTile::worldEvent(WorldState worldState, WorldEvent worldEvent) void SwitchTile::worldEvent(WorldState worldState, WorldEvent worldEvent)
{ {
Tile::worldEvent(worldState, worldEvent); Tile::worldEvent(worldState, worldEvent);

Datei anzeigen

@ -38,6 +38,7 @@ class SwitchTile : public Tile
CREATE_DEF(SwitchTile) CREATE_DEF(SwitchTile)
protected: protected:
void addToWorld() final;
void worldEvent(WorldState worldState, WorldEvent worldEvent) final; void worldEvent(WorldState worldState, WorldEvent worldEvent) final;
public: public:

Datei anzeigen

@ -74,6 +74,12 @@ DecouplerRailTile::DecouplerRailTile(World& world, std::string_view _id)
}); });
} }
void DecouplerRailTile::addToWorld()
{
outputMap->parentObject.setValueInternal(shared_from_this());
StraightRailTile::addToWorld();
}
void DecouplerRailTile::worldEvent(WorldState worldState, WorldEvent worldEvent) void DecouplerRailTile::worldEvent(WorldState worldState, WorldEvent worldEvent)
{ {
StraightRailTile::worldEvent(worldState, worldEvent); StraightRailTile::worldEvent(worldState, worldEvent);

Datei anzeigen

@ -40,6 +40,7 @@ class DecouplerRailTile final : public StraightRailTile
void setState(DecouplerState value, bool skipAction = false); void setState(DecouplerState value, bool skipAction = false);
protected: protected:
void addToWorld() final;
void worldEvent(WorldState worldState, WorldEvent worldEvent) final; void worldEvent(WorldState worldState, WorldEvent worldEvent) final;
public: public:

Datei anzeigen

@ -133,6 +133,12 @@ bool SignalRailTile::reserve(const std::shared_ptr<BlockPath>& blockPath, bool d
return true; return true;
} }
void SignalRailTile::addToWorld()
{
outputMap->parentObject.setValueInternal(shared_from_this());
StraightRailTile::addToWorld();
}
void SignalRailTile::worldEvent(WorldState state, WorldEvent event) void SignalRailTile::worldEvent(WorldState state, WorldEvent event)
{ {
StraightRailTile::worldEvent(state, event); StraightRailTile::worldEvent(state, event);

Datei anzeigen

@ -46,6 +46,7 @@ class SignalRailTile : public StraightRailTile
SignalRailTile(World& world, std::string_view _id, TileId tileId_); SignalRailTile(World& world, std::string_view _id, TileId tileId_);
void addToWorld() override;
void worldEvent(WorldState state, WorldEvent event) override; void worldEvent(WorldState state, WorldEvent event) override;
void boardModified() override; void boardModified() override;

Datei anzeigen

@ -83,6 +83,12 @@ bool TurnoutRailTile::release(bool dryRun)
return true; return true;
} }
void TurnoutRailTile::addToWorld()
{
outputMap->parentObject.setValueInternal(shared_from_this());
RailTile::addToWorld();
}
void TurnoutRailTile::worldEvent(WorldState state, WorldEvent event) void TurnoutRailTile::worldEvent(WorldState state, WorldEvent event)
{ {
RailTile::worldEvent(state, event); RailTile::worldEvent(state, event);

Datei anzeigen

@ -40,6 +40,7 @@ class TurnoutRailTile : public RailTile
protected: protected:
TurnoutRailTile(World& world, std::string_view _id, TileId tileId_, size_t connectors); TurnoutRailTile(World& world, std::string_view _id, TileId tileId_, size_t connectors);
void addToWorld() override;
void worldEvent(WorldState state, WorldEvent event) override; void worldEvent(WorldState state, WorldEvent event) override;
bool isValidPosition(TurnoutPosition value); bool isValidPosition(TurnoutPosition value);

Datei anzeigen

@ -41,6 +41,7 @@
OutputMap::OutputMap(Object& _parent, std::string_view parentPropertyName) OutputMap::OutputMap(Object& _parent, std::string_view parentPropertyName)
: SubObject(_parent, parentPropertyName) : SubObject(_parent, parentPropertyName)
, parentObject{this, "parent", nullptr, PropertyFlags::Constant | PropertyFlags::NoStore | PropertyFlags::NoScript}
, interface{this, "interface", nullptr, PropertyFlags::ReadWrite | PropertyFlags::Store | PropertyFlags::NoScript, , interface{this, "interface", nullptr, PropertyFlags::ReadWrite | PropertyFlags::Store | PropertyFlags::NoScript,
[this](const std::shared_ptr<OutputController>& /*newValue*/) [this](const std::shared_ptr<OutputController>& /*newValue*/)
{ {
@ -287,6 +288,8 @@ OutputMap::OutputMap(Object& _parent, std::string_view parentPropertyName)
auto& world = getWorld(&_parent); auto& world = getWorld(&_parent);
const bool editable = contains(world.state.value(), WorldState::Edit); const bool editable = contains(world.state.value(), WorldState::Edit);
m_interfaceItems.add(parentObject);
Attributes::addDisplayName(interface, DisplayName::Hardware::interface); Attributes::addDisplayName(interface, DisplayName::Hardware::interface);
Attributes::addEnabled(interface, editable); Attributes::addEnabled(interface, editable);
Attributes::addObjectList(interface, world.outputControllers); Attributes::addObjectList(interface, world.outputControllers);

Datei anzeigen

@ -82,6 +82,7 @@ class OutputMap : public SubObject
virtual void updateStateFromOutput(); virtual void updateStateFromOutput();
public: public:
ObjectProperty<Object> parentObject; // UI needs access to parent object
ObjectProperty<OutputController> interface; ObjectProperty<OutputController> interface;
Property<OutputChannel> channel; Property<OutputChannel> channel;
VectorProperty<uint32_t> addresses; VectorProperty<uint32_t> addresses;