]> git.tdb.fi Git - r2c2.git/commitdiff
Detect curved turnouts and assign appropriate symbols to them
authorMikko Rasa <tdb@tdb.fi>
Mon, 21 Jan 2013 19:16:00 +0000 (21:16 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 21 Jan 2013 19:16:00 +0000 (21:16 +0200)
source/libr2c2/centralstation.cpp
source/libr2c2/centralstation.h

index 979749e401a446469b506638a08ac716cc639978..3a9624af1ba17b0049b17a832e317ecb055bb4dc 100644 (file)
@@ -142,6 +142,7 @@ void CentralStation::set_loco_function(unsigned addr, unsigned func, bool state)
 
 void CentralStation::add_turnout(unsigned addr, const TrackType &type)
 {
+       unsigned straight = type.get_paths();
        bool left = false;
        bool right = false;
        bool cross = false;
@@ -151,10 +152,11 @@ void CentralStation::add_turnout(unsigned addr, const TrackType &type)
        {
                TrackPoint start = i->get_point(0);
                TrackPoint end = i->get_point(i->get_length());
-               if(end.dir>start.dir+0.01)
-                       left = true;
-               else if(end.dir<start.dir-0.01)
-                       right = true;
+               if(end.dir>start.dir+0.01 || end.dir<start.dir-0.01)
+               {
+                       (end.dir>start.dir ? left : right) = true;
+                       straight &= ~(1<<i->get_path());
+               }
                else if(start.dir<-0.01 || start.dir>0.01)
                        cross = true;
        }
@@ -165,9 +167,9 @@ void CentralStation::add_turnout(unsigned addr, const TrackType &type)
        else if(left && right)
                symbol = Turnout::THREEWAY;
        else if(left)
-               symbol = Turnout::LEFT;
+               symbol = (straight ? Turnout::LEFT : Turnout::CURVED_LEFT);
        else if(right)
-               symbol = Turnout::RIGHT;
+               symbol = (straight ? Turnout::RIGHT : Turnout::CURVED_RIGHT);
 
        unsigned id = map_address(turnouts, turnout_addr, addr);
        if(!id)
index 4554d147b91382242422f729f8aade4d6c8521af..4539e0b10d00f56db768b9c416b5d138e87ab546 100644 (file)
@@ -72,10 +72,12 @@ private:
        {
                enum Symbol
                {
-                       LEFT,
-                       RIGHT,
-                       THREEWAY,
-                       DOUBLESLIP
+                       LEFT = 0,
+                       RIGHT = 1,
+                       THREEWAY = 2,
+                       DOUBLESLIP = 3,
+                       CURVED_LEFT = 21,
+                       CURVED_RIGHT = 22
                };
 
                unsigned address;