]> git.tdb.fi Git - r2c2.git/commitdiff
Prefer is_turnout() when checking if a track is, in fact, a turnout
authorMikko Rasa <tdb@tdb.fi>
Fri, 4 Apr 2014 16:57:54 +0000 (19:57 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 4 Apr 2014 16:57:54 +0000 (19:57 +0300)
source/designer/designer.cpp
source/engineer/engineer.cpp
source/libr2c2/blockallocator.cpp
source/libr2c2/layout.cpp
source/libr2c2/route.cpp

index 3d068d0ad42d4252adb1561f45874e46bb6790ee..4ad5274e1cce7754c9742890b4b26607449f9ef6 100644 (file)
@@ -537,8 +537,9 @@ void Designer::update_object_icon(Object &obj)
                        overlay->add_graphic(obj3d, "trackcircuit");
                        overlay->set_label(obj3d, lexical_cast<string>(saddr));
                }
-               else if(unsigned taddr = track->get_turnout_address())
+               else if(track->get_type().is_turnout())
                {
+                       unsigned taddr = track->get_turnout_address();
                        if(taddr<0x800)
                        {
                                overlay->add_graphic(obj3d, "turnout");
@@ -595,7 +596,7 @@ string Designer::tooltip(int x, int y)
                {
                        if(mode!=CATALOGUE && abs(track->get_tilt()).radians()>1e-4)
                                info += format(" (slope %.1f%%)", abs(tan(track->get_tilt())*100));
-                       if(track->get_turnout_address())
+                       if(track->get_type().is_turnout())
                                info += format(" (turnout %d)", track->get_turnout_address());
                        else if(track->get_sensor_address())
                                info += format(" (sensor %d)", track->get_sensor_address());
@@ -623,8 +624,8 @@ void Designer::show_route(const Route &route)
                Track3D &t3d = layout_3d->get_3d(**i);
                Path3D *path = new Path3D(t3d);
                path->set_color(GL::Color(0.5, 0.8, 1.0));
-               if(unsigned taddr = (*i)->get_turnout_address())
-                       path->set_path(route.get_turnout(taddr));
+               if((*i)->get_type().is_turnout())
+                       path->set_path(route.get_turnout((*i)->get_turnout_address()));
                highlight_paths.push_back(path);
        }
 }
index 19e515c2d2074a291b0ec0cf731e30f5a7eb676b..fb0502dbfde6d7f4df131c368006b58967d027c7 100644 (file)
@@ -196,7 +196,7 @@ void Engineer::button_press(unsigned btn)
                Object *obj = pick_object(pointer);
                if(Track *track = dynamic_cast<Track *>(obj))
                {
-                       if(track->get_turnout_address())
+                       if(track->get_type().is_turnout())
                        {
                                Block &block = track->get_block();
                                if(block.get_train() && block.get_train()->is_block_critical(block))
index 6e2a11cde0bedf77295b089f97961d8467859c98..5a410ff20de0af908df94952d6d2bdb46348e14f 100644 (file)
@@ -42,7 +42,7 @@ BlockAllocator::BlockAllocator(Train &t):
 
        const set<Track *> &tracks = layout.get_all<Track>();
        for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
-               if((*i)->get_turnout_address())
+               if((*i)->get_type().is_turnout())
                {
                        (*i)->signal_path_changing.connect(sigc::hide(sigc::bind(sigc::mem_fun(this, &BlockAllocator::turnout_path_changing), sigc::ref(**i))));
                        (*i)->signal_path_changed.connect(sigc::hide(sigc::bind(sigc::mem_fun(this, &BlockAllocator::turnout_path_changed), sigc::ref(**i))));
index c7dc346d61db45c652c3f553fc438c92e9f8576f..b4eb8faacdbdb52d5d4786fe8495c747762c1c6a 100644 (file)
@@ -248,7 +248,7 @@ unsigned Layout::allocate_turnout_address()
        set<unsigned> used_addrs;
        const set<Track *> &tracks = objects.get<Track>();
        for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
-               if((*i)->get_turnout_address())
+               if((*i)->get_type().is_turnout())
                        used_addrs.insert((*i)->get_turnout_address());
 
        unsigned result = next_turnout_addr;
@@ -480,8 +480,8 @@ void Layout::save_dynamic(const string &fn) const
 
        const set<Track *> &tracks = objects.get<Track>();
        for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
-               if(unsigned taddr = (*i)->get_turnout_address())
-                       writer.write((DataFile::Statement("turnout"), taddr, (*i)->get_active_path()));
+               if((*i)->get_type().is_turnout())
+                       writer.write((DataFile::Statement("turnout"), (*i)->get_turnout_address(), (*i)->get_active_path()));
 
        for(map<unsigned, Train *>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
        {
index 5b37fcc06f3f7d381ec63309d9450ffde7f9e558..be4237d10bddb875f84d172a0a7f98cb1c3b8a55 100644 (file)
@@ -215,9 +215,9 @@ int Route::get_turnout(unsigned id) const
 
 unsigned Route::get_path(Track &trk) const
 {
-       if(unsigned taddr = trk.get_turnout_address())
+       if(trk.get_type().is_turnout())
        {
-               map<unsigned, int>::const_iterator i = turnouts.find(taddr);
+               map<unsigned, int>::const_iterator i = turnouts.find(trk.get_turnout_address());
                if(i!=turnouts.end())
                        return i->second;
        }