#include <algorithm>
+#include <msp/strings/format.h>
#include <msp/time/units.h>
#include "block.h"
-#include "driver.h"
#include "layout.h"
#include "route.h"
#include "trackcircuit.h"
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);
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;
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);
}