X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Fblock.cpp;h=289c4e54f6bd14de4107f1e4246144e8438c168b;hb=399b48a7a80dafde49e7530ff8dfd2820232a73f;hp=59ad3a3c990965ac67b9e0ccad5602aff5c35abb;hpb=b28062f2dc88e082ee5a28b2e1f7c4c8bd989023;p=r2c2.git diff --git a/source/libr2c2/block.cpp b/source/libr2c2/block.cpp index 59ad3a3..289c4e5 100644 --- a/source/libr2c2/block.cpp +++ b/source/libr2c2/block.cpp @@ -1,7 +1,8 @@ #include +#include +#include #include #include "block.h" -#include "driver.h" #include "layout.h" #include "route.h" #include "trackcircuit.h" @@ -74,6 +75,11 @@ Block::~Block() delete sensor; } +void Block::set_name(const string &) +{ + throw logic_error("Block names can't be set"); +} + void Block::on_track_added(Track &track) { track.set_block(this); @@ -165,7 +171,7 @@ bool Block::reserve(Train *t) if(!t || !train) { train = t; - signal_reserved.emit(train); + signal_reserved.emit(t); return true; } else @@ -174,10 +180,17 @@ bool Block::reserve(Train *t) void Block::determine_id() { + string n; if(sensor_addr) + { id = 0x1000|sensor_addr; + n = format("Sensor %d", sensor_addr); + } else if(turnout_addr) + { id = 0x2000|turnout_addr; + n = format("Turnout %d", turnout_addr); + } else if(endpoints.size()==2) { unsigned id1 = endpoints[0].link ? endpoints[0].link->get_id() : 1; @@ -191,6 +204,17 @@ void Block::determine_id() unsigned id1 = endpoints[0].link ? endpoints[0].link->get_id() : 1; id = 0x10000 | id1; } + + if(n.empty()) + n = format("Block %x", id); + + name = n; + signal_name_changed.emit(name); +} + +DataFile::Statement Block::save_reference() const +{ + return (DataFile::Statement("block"), id); }