X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Flayout.cpp;h=af88d7d8fd2e35f3a44af86ff24640c85c003d1d;hb=a4566a4a23ff676f11a90615e8e468ef50107946;hp=c0930352fb7d2b171f7279a55c0dd1fddffc454b;hpb=651698847d5293cfb15b6fb23a394701388c0151;p=r2c2.git diff --git a/source/libmarklin/layout.cpp b/source/libmarklin/layout.cpp index c093035..af88d7d 100644 --- a/source/libmarklin/layout.cpp +++ b/source/libmarklin/layout.cpp @@ -28,7 +28,10 @@ namespace Marklin { Layout::Layout(Catalogue &c, Driver *d): catalogue(c), driver(d) -{ } +{ + if(driver) + driver->signal_sensor.connect(sigc::mem_fun(this, &Layout::sensor_event)); +} Layout::~Layout() { @@ -182,6 +185,18 @@ void Layout::remove_train(Train &t) signal_train_removed.emit(t); } +void Layout::add_vehicle(Vehicle &v) +{ + if(vehicles.insert(&v).second) + signal_vehicle_added.emit(v); +} + +void Layout::remove_vehicle(Vehicle &v) +{ + if(vehicles.erase(&v)) + signal_vehicle_removed.emit(v); +} + void Layout::tick() { if(driver) @@ -197,6 +212,13 @@ void Layout::tick() i->second->tick(t, dt); } +void Layout::emergency(const string &msg) +{ + if(driver) + driver->halt(true); + signal_emergency.emit(msg); +} + void Layout::save(const string &fn) { IO::BufferedFile out(fn, IO::M_WRITE); @@ -332,6 +354,20 @@ void Layout::check_routes() } } +void Layout::sensor_event(unsigned addr, bool state) +{ + if(state) + { + for(set::iterator i=blocks.begin(); i!=blocks.end(); ++i) + if((*i)->get_sensor_id()==addr) + { + if(!(*i)->get_train()) + emergency("Unreserved sensor triggered"); + break; + } + } +} + Layout::Loader::Loader(Layout &l): DataFile::BasicLoader(l),