sensor_id = i;
layout.create_blocks(*this);
- if(layout.has_driver() && sensor_id)
- layout.get_driver().add_sensor(sensor_id);
}
void Track::set_active_path(unsigned p)
layout.get_driver().set_turnout(turnout_id, p);
}
-TrackPoint Track::get_point(unsigned epi, unsigned path, float d) const
+float Track::get_path_length(int p) const
{
- TrackPoint p = type.get_point(epi, path, d);
+ if(p<0)
+ p = active_path;
+ return type.get_path_length(p);
+}
+
+OrientedPoint Track::get_point(unsigned epi, unsigned path, float d) const
+{
+ OrientedPoint p = type.get_point(epi, path, d);
- p.pos = position+rotated_vector(p.pos, rotation);
- p.dir += rotation;
+ p.position = position+rotated_vector(p.position, rotation);
+ p.rotation += rotation;
if(type.get_endpoints().size()==2)
{
- float grade = tan(tilt);
+ float dz = tan(tilt)*d;
if(epi==0)
{
- p.pos.z += grade*d;
- p.grade = grade;
+ p.position.z += dz;
+ p.tilt = tilt;
}
else
{
- p.pos.z += slope-grade*d;
- p.grade = -grade;
+ p.position.z += slope-dz;
+ p.tilt = -tilt;
}
}
return p;
}
-TrackPoint Track::get_point(unsigned epi, float d) const
+OrientedPoint Track::get_point(unsigned epi, float d) const
{
return get_point(epi, active_path, d);
}
{
Vector local = rotated_vector(sn.position-position, -rotation);
- TrackPoint tp = type.get_nearest_point(local);
- Vector span = local-tp.pos;
+ OrientedPoint np = type.get_nearest_point(local);
+ Vector span = local-np.position;
if(dot(span, span)<=limit*limit)
{
- sn.position = position+rotated_vector(tp.pos, rotation);
- sn.rotation = tp.dir+rotation;
+ sn.position = position+rotated_vector(np.position, rotation);
+ sn.rotation = np.rotation+rotation;
return true;
}
}
return false;
links[i] = 0;
- other->break_link(*this);
- // XXX Creates the blocks twice, because the other track calls this too
- layout.create_blocks(*this);
+ if(!other->break_link(*this))
+ {
+ /* If the call doesn't succeed, it means that the other track already
+ broke the link and is calling us right now. Recreate blocks in the inner
+ call so it occurs before any signals are emitted. */
+ layout.create_blocks(*this);
+ }
+
signal_link_changed.emit(i, 0);
return true;