]> git.tdb.fi Git - r2c2.git/commitdiff
Turnout handling fixes
authorMikko Rasa <tdb@tdb.fi>
Wed, 30 Oct 2013 22:19:40 +0000 (00:19 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 30 Oct 2013 22:19:40 +0000 (00:19 +0200)
Add the turnout to driver when acquiring automatic id to avoid a key_error
later when removing it.  Don't bother connecting to turnout_event signal
if the track is not actually a turnout.

source/libr2c2/track.cpp

index 5da34f692b370c9f5711536e2d0838da78e9f8cb..23f1b9e2b6da280d7179276de2d8e1d1afa1a112 100644 (file)
@@ -40,12 +40,19 @@ Track::Track(Layout &l, const TrackType &t):
        path_changing(false)
 {
        if(type.is_turnout())
+       {
                turnout_id = layout.allocate_turnout_id();
 
+               if(layout.has_driver())
+               {
+                       Driver &driver = layout.get_driver();
+                       driver.add_turnout(turnout_id, type);
+                       driver.signal_turnout.connect(sigc::mem_fun(this, &Track::turnout_event));
+               }
+       }
+
        layout.add(*this);
 
-       if(layout.has_driver())
-               layout.get_driver().signal_turnout.connect(sigc::mem_fun(this, &Track::turnout_event));
 
        for(unsigned paths = type.get_paths(); !(paths&1); ++active_path, paths>>=1) ;
 }
@@ -400,9 +407,6 @@ void Track::save(list<DataFile::Statement> &st) const
 
 void Track::turnout_event(unsigned addr, unsigned state)
 {
-       if(!turnout_id)
-               return;
-
        if(addr==turnout_id)
        {
                active_path = state;