if(track.get_track().get_flex())
overlay->add_graphic(track, "flex");
- if(unsigned sid = track.get_track().get_sensor_id())
+ if(unsigned saddr = track.get_track().get_sensor_address())
{
overlay->add_graphic(track, "sensor");
- overlay->set_label(track, lexical_cast<string>(sid));
+ overlay->set_label(track, lexical_cast<string>(saddr));
}
- else if(unsigned tid = track.get_track().get_turnout_id())
+ else if(unsigned taddr = track.get_track().get_turnout_address())
{
- if(tid<0x800)
+ if(taddr<0x800)
{
overlay->add_graphic(track, "turnout");
- overlay->set_label(track, lexical_cast<string>(tid));
+ overlay->set_label(track, lexical_cast<string>(taddr));
}
}
}
{
if(mode!=CATALOGUE && abs(track->get_tilt()).radians()>1e-4)
info += format(" (slope %.1f%%)", abs(tan(track->get_tilt())*100));
- if(track->get_turnout_id())
- info += format(" (turnout %d)", track->get_turnout_id());
- else if(track->get_sensor_id())
- info += format(" (sensor %d)", track->get_sensor_id());
+ if(track->get_turnout_address())
+ info += format(" (turnout %d)", track->get_turnout_address());
+ else if(track->get_sensor_address())
+ info += format(" (sensor %d)", track->get_sensor_address());
}
return info;
}
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 tid = (*i)->get_turnout_id())
- path->set_path(route.get_turnout(tid));
+ if(unsigned taddr = (*i)->get_turnout_address())
+ path->set_path(route.get_turnout(taddr));
}
}
{
GLtk::Row row(*layout);
- add(*(lbl1 = new GLtk::Label("Turnout ID")));
- add(*(ent_turnout_id = new GLtk::Entry));
- ent_turnout_id->set_edit_size(5, 1);
+ add(*(lbl1 = new GLtk::Label("Turnout address")));
+ add(*(ent_turnout_addr = new GLtk::Entry));
+ ent_turnout_addr->set_edit_size(5, 1);
}
{
GLtk::Row row(*layout);
- add(*(lbl2 = new GLtk::Label("Sensor ID")));
+ add(*(lbl2 = new GLtk::Label("Sensor address")));
layout->add_constraint(*lbl1, GLtk::Layout::COPY_WIDTH, *lbl2);
- add(*(ent_sensor_id = new GLtk::Entry));
- ent_sensor_id->set_edit_size(5, 1);
+ add(*(ent_sensor_addr = new GLtk::Entry));
+ ent_sensor_addr->set_edit_size(5, 1);
}
GLtk::Button *btn;
if(selection.size()==1)
{
- if(unsigned tid = selection.get_object<Track>()->get_turnout_id())
- ent_turnout_id->set_text(lexical_cast<string>(tid));
+ if(unsigned taddr = selection.get_object<Track>()->get_turnout_address())
+ ent_turnout_addr->set_text(lexical_cast<string>(taddr));
}
const set<Track *> &tracks = selection.get_objects<Track>();
- int sensor_id = -1;
+ int sensor_addr = -1;
for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
{
- if(static_cast<int>((*i)->get_sensor_id())!=sensor_id)
+ if(static_cast<int>((*i)->get_sensor_address())!=sensor_addr)
{
- if(sensor_id==-1)
- sensor_id = (*i)->get_sensor_id();
+ if(sensor_addr==-1)
+ sensor_addr = (*i)->get_sensor_address();
else
- sensor_id = -2;
+ sensor_addr = -2;
}
}
- if(sensor_id>=0)
- ent_sensor_id->set_text(lexical_cast<string>(sensor_id));
+ if(sensor_addr>=0)
+ ent_sensor_addr->set_text(lexical_cast<string>(sensor_addr));
}
void TrackProperties::on_response(int code)
{
Track *track = selection.get_object<Track>();
if(track->get_type().is_turnout())
- track->set_turnout_id(lexical_cast<unsigned>(ent_turnout_id->get_text()));
+ track->set_turnout_address(lexical_cast<unsigned>(ent_turnout_addr->get_text()));
}
- string sensor_id_text = ent_sensor_id->get_text();
- if(!sensor_id_text.empty())
+ string sensor_addr_text = ent_sensor_addr->get_text();
+ if(!sensor_addr_text.empty())
{
- unsigned sensor_id = lexical_cast<unsigned>(sensor_id_text);
+ unsigned sensor_addr = lexical_cast<unsigned>(sensor_addr_text);
const set<Track *> &tracks = selection.get_objects<Track>();
for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
if(!(*i)->get_type().is_turnout())
- (*i)->set_sensor_id(sensor_id);
+ (*i)->set_sensor_address(sensor_addr);
}
}
}
{
private:
const Selection &selection;
- Msp::GLtk::Entry *ent_turnout_id;
- Msp::GLtk::Entry *ent_sensor_id;
+ Msp::GLtk::Entry *ent_turnout_addr;
+ Msp::GLtk::Entry *ent_sensor_addr;
public:
TrackProperties(const Selection &);
Object *obj = pick_object(pointer);
if(Track *track = dynamic_cast<Track *>(obj))
{
- if(track->get_turnout_id())
+ if(track->get_turnout_address())
{
Block &block = track->get_block();
if(block.get_train() && block.get_train()->is_block_critical(block))
++i;
}
track->set_active_path(i);
- set_status(format("Turnout %d", track->get_turnout_id()));
+ set_status(format("Turnout %d", track->get_turnout_address()));
}
}
- if(unsigned sid = track->get_sensor_id())
+ if(unsigned saddr = track->get_sensor_address())
{
if(options.simulate)
- layout.get_driver().set_sensor(sid, !layout.get_driver().get_sensor(sid));
- set_status(format("Sensor %d", sid));
+ layout.get_driver().set_sensor(saddr, !layout.get_driver().get_sensor(saddr));
+ set_status(format("Sensor %d", saddr));
}
}
else if(Vehicle *veh = dynamic_cast<Vehicle *>(obj))
Block::Block(Layout &l, Track &start):
TrackChain(l),
id(0),
- sensor_id(start.get_sensor_id()),
- turnout_id(start.get_turnout_id()),
+ sensor_addr(start.get_sensor_address()),
+ turnout_addr(start.get_turnout_address()),
conflict(false),
sensor(0),
train(0)
for(set<Block *>::const_iterator i=blocks.begin(); (!conflict && i!=blocks.end()); ++i)
conflict = (id==(*i)->get_id());
- if(!conflict && sensor_id)
+ if(!conflict && sensor_addr)
sensor = new TrackCircuit(layout, *this);
layout.add(*this);
TrackChain::Validity Block::check_validity(Track &track) const
{
- if(track.get_sensor_id()!=sensor_id || track.get_turnout_id()!=turnout_id)
+ if(track.get_sensor_address()!=sensor_addr || track.get_turnout_address()!=turnout_addr)
return INCOMPATIBLE;
return TrackChain::check_validity(track);
void Block::determine_id()
{
- if(sensor_id)
- id = 0x1000|sensor_id;
- else if(turnout_id)
- id = 0x2000|turnout_id;
+ if(sensor_addr)
+ id = 0x1000|sensor_addr;
+ else if(turnout_addr)
+ id = 0x2000|turnout_addr;
else if(endpoints.size()==2)
{
unsigned id1 = endpoints[0].link ? endpoints[0].link->get_id() : 1;
private:
unsigned id;
- unsigned sensor_id;
- unsigned turnout_id;
+ unsigned sensor_addr;
+ unsigned turnout_addr;
bool conflict;
TrackCircuit *sensor;
std::vector<Endpoint> endpoints;
public:
unsigned get_id() const { return id; }
- unsigned get_sensor_id() const { return sensor_id; }
- unsigned get_turnout_id() const { return turnout_id; }
+ unsigned get_sensor_address() const { return sensor_addr; }
+ unsigned get_turnout_address() const { return turnout_addr; }
TrackCircuit *get_sensor() const { return sensor; }
const std::vector<Endpoint> &get_endpoints() const { return endpoints; }
const Endpoint &get_endpoint(unsigned) const;
const set<Track *> &tracks = layout.get_all<Track>();
for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
- if((*i)->get_turnout_id())
+ if((*i)->get_turnout_address())
{
(*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))));
float dist = 0;
for(BlockList::const_iterator i=cur_blocks_end; i!=blocks.end(); ++i)
{
- if((*i)->get_sensor_id())
+ if((*i)->get_sensor_address())
++nsens;
if(nsens>0)
dist += (*i)->get_path_length(i->entry());
// The track ends here
break;
- if(block->get_turnout_id() && !prev->get_turnout_id())
+ if(block->get_turnout_address() && !prev->get_turnout_address())
{
/* We are arriving at a turnout. See if we have enough blocks and
distance reserved. */
if(&*block==stop_at_block)
break;
- if(block->get_sensor_id())
+ if(block->get_sensor_address())
++nsens;
if(nsens>0)
dist += block->get_path_length(block.entry());
obj.blocks.push_back(BlockIter(blk, entry));
blk->reserve(&obj.train);
- if(blk->get_sensor_id())
- obj.train.get_layout().get_driver().set_sensor(blk->get_sensor_id(), true);
+ if(blk->get_sensor_address())
+ obj.train.get_layout().get_driver().set_sensor(blk->get_sensor_address(), true);
prev_block = blk;
}
int BlockIter::get_exit(const Route *route) const
{
const vector<Block::Endpoint> &eps = _block->get_endpoints();
- if(_block->get_turnout_id())
+ if(_block->get_turnout_address())
{
/* The endpoints of a turnout block exactly correspond to the endpoints
of the track. */
Layout::Layout(Catalogue &c, Driver *d):
catalogue(c),
driver(d),
- next_turnout_id(0x800)
+ next_turnout_addr(0x800)
{
clock.set_rate(60);
}
remove(static_cast<Sensor &>(g));
}
-unsigned Layout::allocate_turnout_id()
+unsigned Layout::allocate_turnout_address()
{
- set<unsigned> used_ids;
+ 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_id())
- used_ids.insert((*i)->get_turnout_id());
+ if((*i)->get_turnout_address())
+ used_addrs.insert((*i)->get_turnout_address());
- unsigned result = next_turnout_id;
- while(used_ids.count(result))
+ unsigned result = next_turnout_addr;
+ while(used_addrs.count(result))
++result;
- next_turnout_id = result+1;
+ next_turnout_addr = result+1;
return result;
}
const set<Track *> &tracks = objects.get<Track>();
for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
- if(unsigned tid = (*i)->get_turnout_id())
- writer.write((DataFile::Statement("turnout"), tid, (*i)->get_active_path()));
+ if(unsigned taddr = (*i)->get_turnout_address())
+ writer.write((DataFile::Statement("turnout"), taddr, (*i)->get_active_path()));
for(map<unsigned, Train *>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
{
Storage<Sensor> sensors;
std::map<unsigned, Train *> trains;
Msp::Time::TimeStamp last_tick;
- unsigned next_turnout_id;
+ unsigned next_turnout_addr;
public:
Layout(Catalogue &, Driver * = 0);
void remove(Sensor &);
void remove(BeamGate &);
- unsigned allocate_turnout_id();
+ unsigned allocate_turnout_address();
Block &get_block(unsigned) const;
void create_blocks();
for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
if((*i)->get_type().is_turnout())
{
- found.insert((*i)->get_turnout_id());
+ found.insert((*i)->get_turnout_address());
update_turnout(**i);
}
if(link->get_type().is_turnout())
{
const TrackType::Endpoint &link_ep = link->get_type().get_endpoint(link->get_link_slot(track));
- int p = get_turnout(link->get_turnout_id());
+ int p = get_turnout(link->get_turnout_address());
if(p>=0 && !link_ep.has_path(p))
// The linked track is a turnout and has a path which is incompatible with this endpoint
ep_mask = ~ep_mask;
mask &= ep_mask;
}
- unsigned tid = track.get_turnout_id();
+ unsigned taddr = track.get_turnout_address();
if(mask && !(mask&(mask-1)))
{
// Exactly one possible choice, set the path accordingly
unsigned path = 0;
for(; (mask && !(mask&1)); mask>>=1, ++path) ;
- turnouts[tid] = path;
+ turnouts[taddr] = path;
}
- else if(!turnouts.count(tid))
+ else if(!turnouts.count(taddr))
// More than one possible choice, and no existing entry - set as undecided
- turnouts[tid] = -1;
+ turnouts[taddr] = -1;
}
int Route::get_turnout(unsigned id) const
unsigned Route::get_path(Track &trk) const
{
- if(unsigned tid = trk.get_turnout_id())
+ if(unsigned taddr = trk.get_turnout_address())
{
- map<unsigned, int>::const_iterator i = turnouts.find(tid);
+ map<unsigned, int>::const_iterator i = turnouts.find(taddr);
if(i!=turnouts.end())
return i->second;
}
for(set<Track *>::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
if((*i)->get_type().is_turnout())
{
- TurnoutMap::iterator j = turnouts.find((*i)->get_turnout_id());
+ TurnoutMap::iterator j = turnouts.find((*i)->get_turnout_address());
if(j!=turnouts.end())
turnout_tracks[*i] = j->second;
}
BlockIter iter = block.next();
while(iter && iter->get_train()==train)
{
- if(iter->get_sensor_id())
+ if(iter->get_sensor_address())
++n_blocks;
iter=iter.next();
}
{
if(&b==block.block())
passing = true;
- else if(passing && b.get_sensor_id())
+ else if(passing && b.get_sensor_address())
{
layout.get_driver().set_signal(address, type.get_indications().back().aspect);
reset();
block(0),
slope(0),
flex(false),
- turnout_id(0),
- sensor_id(0),
+ turnout_addr(0),
+ sensor_addr(0),
links(type.get_endpoints().size()),
active_path(0),
path_changing(false)
{
if(type.is_turnout())
{
- turnout_id = layout.allocate_turnout_id();
+ turnout_addr = layout.allocate_turnout_address();
if(layout.has_driver())
{
Driver &driver = layout.get_driver();
- driver.add_turnout(turnout_id, type);
+ driver.add_turnout(turnout_addr, type);
driver.signal_turnout.connect(sigc::mem_fun(this, &Track::turnout_event));
}
}
Track::~Track()
{
break_links();
- if(layout.has_driver() && turnout_id)
- layout.get_driver().remove_turnout(turnout_id);
+ if(layout.has_driver() && turnout_addr)
+ layout.get_driver().remove_turnout(turnout_addr);
layout.remove(*this);
}
signal_moved.emit();
}
-void Track::set_turnout_id(unsigned i)
+void Track::set_turnout_address(unsigned a)
{
if(!type.is_turnout())
throw logic_error("not a turnout");
- if(!i)
+ if(!a)
throw invalid_argument("Track::set_turnout_id");
Driver *driver = (layout.has_driver() ? &layout.get_driver() : 0);
- if(driver && turnout_id)
- driver->remove_turnout(turnout_id);
- turnout_id = i;
+ if(driver && turnout_addr)
+ driver->remove_turnout(turnout_addr);
+ turnout_addr = a;
layout.create_blocks(*this);
layout.update_routes();
- if(driver && turnout_id)
- driver->add_turnout(turnout_id, type);
+ if(driver && turnout_addr)
+ driver->add_turnout(turnout_addr, type);
}
-void Track::set_sensor_id(unsigned i)
+void Track::set_sensor_address(unsigned a)
{
if(type.is_turnout())
throw logic_error("is a turnout");
- sensor_id = i;
+ sensor_addr = a;
layout.create_blocks(*this);
}
void Track::set_active_path(unsigned p)
{
- if(!turnout_id)
+ if(!turnout_addr)
throw logic_error("not a turnout");
if(!(type.get_paths()&(1<<p)))
throw invalid_argument("Track::set_active_path");
signal_path_changing(p);
path_changing = true;
- layout.get_driver().set_turnout(turnout_id, p);
+ layout.get_driver().set_turnout(turnout_addr, p);
}
float Track::get_path_length(int p) const
st.push_back((DataFile::Statement("position"), position.x, position.y, position.z));
st.push_back((DataFile::Statement("rotation"), rotation.radians()));
st.push_back((DataFile::Statement("tilt"), tilt.radians()));
- if(turnout_id)
- st.push_back((DataFile::Statement("turnout_id"), turnout_id));
- if(sensor_id)
- st.push_back((DataFile::Statement("sensor_id"), sensor_id));
+ if(turnout_addr)
+ st.push_back((DataFile::Statement("turnout_address"), turnout_addr));
+ if(sensor_addr)
+ st.push_back((DataFile::Statement("sensor_address"), sensor_addr));
if(flex)
st.push_back((DataFile::Statement("flex"), true));
}
void Track::turnout_event(unsigned addr, unsigned state)
{
- if(addr==turnout_id)
+ if(addr==turnout_addr)
{
active_path = state;
path_changing = false;
add("position", &Loader::position);
add("rotation", &Loader::rotation);
add("tilt", &Loader::tilt);
- add("turnout_id", &Loader::turnout_id);
- add("sensor_id", &Loader::sensor_id);
+ add("turnout_id", &Loader::turnout_address);
+ add("turnout_address", &Loader::turnout_address);
+ add("sensor_id", &Loader::sensor_address);
+ add("sensor_address", &Loader::sensor_address);
add("flex", &Track::flex);
// deprecated
obj.set_rotation(Angle::from_radians(r));
}
-void Track::Loader::sensor_id(unsigned id)
+void Track::Loader::sensor_address(unsigned addr)
{
- obj.set_sensor_id(id);
+ obj.set_sensor_address(addr);
}
void Track::Loader::slope(float s)
obj.set_tilt(Angle::from_radians(t));
}
-void Track::Loader::turnout_id(unsigned id)
+void Track::Loader::turnout_address(unsigned addr)
{
- obj.set_turnout_id(id);
+ obj.set_turnout_address(addr);
}
} // namespace R2C2
private:
void position(float, float, float);
void rotation(float);
- void sensor_id(unsigned);
+ void sensor_address(unsigned);
void slope(float);
void tilt(float);
- void turnout_id(unsigned);
+ void turnout_address(unsigned);
};
typedef std::list<TrackAttachment *> AttachmentList;
Block *block;
float slope;
bool flex;
- unsigned turnout_id;
- unsigned sensor_id;
+ unsigned turnout_addr;
+ unsigned sensor_addr;
std::vector<Track *> links;
unsigned active_path;
bool path_changing;
void check_slope();
public:
- void set_turnout_id(unsigned);
- void set_sensor_id(unsigned);
- unsigned get_turnout_id() const { return turnout_id; }
- unsigned get_sensor_id() const { return sensor_id; }
+ void set_turnout_address(unsigned);
+ void set_sensor_address(unsigned);
+ unsigned get_turnout_address() const { return turnout_addr; }
+ unsigned get_sensor_address() const { return sensor_addr; }
void set_active_path(unsigned);
unsigned get_active_path() const { return active_path; }
bool is_path_changing() const { return path_changing; }
Sensor(l),
block(b)
{
- Sensor::set_address(block.get_sensor_id());
+ Sensor::set_address(block.get_sensor_address());
}
void TrackCircuit::set_address(unsigned)
dist += i->get_path_length(i.entry());
- if(i->get_sensor_id())
+ if(i->get_sensor_address())
sensor_seen = true;
}
if(last_entry_block && &*last_entry_block!=block)
{
for(BlockIter i=last_entry_block.next(); (i && &*i!=block); i=i.next())
- if(i->get_train()!=this || i->get_sensor_id())
+ if(i->get_train()!=this || i->get_sensor_address())
return;
}
if(advance_route(route, block))
{
// Check if the block is a turnout and set it to proper path
- if(unsigned tid = block.get_turnout_id())
+ if(unsigned taddr = block.get_turnout_address())
{
- int path = (*route)->get_turnout(tid);
+ int path = (*route)->get_turnout(taddr);
if(path>=0)
b_iter.track_iter()->set_active_path(path);
}
void Vehicle::check_sensor(const TrackOffsetIter &t, unsigned &sensor, bool release)
{
- unsigned s = t->get_sensor_id();
+ unsigned s = t->get_sensor_address();
if(s!=sensor)
{
unsigned old = sensor;