From: Mikko Rasa Date: Fri, 4 Apr 2014 16:57:54 +0000 (+0300) Subject: Prefer is_turnout() when checking if a track is, in fact, a turnout X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=0d0b5fcbaf3e8eb1cbfd9764d19792c4383cce7b;p=r2c2.git Prefer is_turnout() when checking if a track is, in fact, a turnout --- diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index 3d068d0..4ad5274 100644 --- a/source/designer/designer.cpp +++ b/source/designer/designer.cpp @@ -537,8 +537,9 @@ void Designer::update_object_icon(Object &obj) overlay->add_graphic(obj3d, "trackcircuit"); overlay->set_label(obj3d, lexical_cast(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); } } diff --git a/source/engineer/engineer.cpp b/source/engineer/engineer.cpp index 19e515c..fb0502d 100644 --- a/source/engineer/engineer.cpp +++ b/source/engineer/engineer.cpp @@ -196,7 +196,7 @@ void Engineer::button_press(unsigned btn) Object *obj = pick_object(pointer); if(Track *track = dynamic_cast(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)) diff --git a/source/libr2c2/blockallocator.cpp b/source/libr2c2/blockallocator.cpp index 6e2a11c..5a410ff 100644 --- a/source/libr2c2/blockallocator.cpp +++ b/source/libr2c2/blockallocator.cpp @@ -42,7 +42,7 @@ BlockAllocator::BlockAllocator(Train &t): const set &tracks = layout.get_all(); for(set::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)))); diff --git a/source/libr2c2/layout.cpp b/source/libr2c2/layout.cpp index c7dc346..b4eb8fa 100644 --- a/source/libr2c2/layout.cpp +++ b/source/libr2c2/layout.cpp @@ -248,7 +248,7 @@ unsigned Layout::allocate_turnout_address() set used_addrs; const set &tracks = objects.get(); for(set::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 &tracks = objects.get(); for(set::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::const_iterator i=trains.begin(); i!=trains.end(); ++i) { diff --git a/source/libr2c2/route.cpp b/source/libr2c2/route.cpp index 5b37fcc..be4237d 100644 --- a/source/libr2c2/route.cpp +++ b/source/libr2c2/route.cpp @@ -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::const_iterator i = turnouts.find(taddr); + map::const_iterator i = turnouts.find(trk.get_turnout_address()); if(i!=turnouts.end()) return i->second; }