They can now be positioned freely and will logically attach to a nearby
track.
#include "driver.h"
#include "layout.h"
#include "signal.h"
#include "driver.h"
#include "layout.h"
#include "signal.h"
}
void Signal::set_position(const Vector &p)
}
void Signal::set_position(const Vector &p)
+{
+ position = p;
+
+ update_location();
+}
+
+void Signal::update_location()
{
const set<Track *> &tracks = layout.get_tracks();
{
const set<Track *> &tracks = layout.get_tracks();
+ float limit = layout.get_catalogue().get_gauge()*2;
float dist = -1;
for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
if(!(*i)->get_type().is_turnout())
{
Snap sn;
float dist = -1;
for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
if(!(*i)->get_type().is_turnout())
{
Snap sn;
+ sn.position = position;
- (*i)->snap(sn, 1000, SNAP_SEGMENT);
- float d = distance(p, sn.position);
+ (*i)->snap(sn, limit, SNAP_SEGMENT);
+ float d = distance(position, sn.position);
- position = sn.position;
- rotation = sn.rotation;
track = *i;
dist = d;
}
}
track = *i;
dist = d;
}
}
- normalize_location();
-}
-void Signal::normalize_location()
-{
- block = &track->get_block();
unsigned n_endpoints = track->get_type().get_endpoints().size();
for(unsigned j=0; j<n_endpoints; ++j)
unsigned n_endpoints = track->get_type().get_endpoints().size();
for(unsigned j=0; j<n_endpoints; ++j)
if(a>=Angle::quarter_turn())
{
BlockIter biter = TrackIter(track, j).block_iter();
if(a>=Angle::quarter_turn())
{
BlockIter biter = TrackIter(track, j).block_iter();
+ if(biter)
+ {
+ block = &track->get_block();
+ entry = biter.entry();
+ }
}
}
}
void Signal::set_rotation(const Angle &r)
{
}
}
}
void Signal::set_rotation(const Angle &r)
{
- Angle a = wrap_with_base(rotation-r, -Angle::quarter_turn());
- if(a>=Angle::quarter_turn())
- rotation = wrap_positive(rotation+Angle::half_turn());
}
unsigned Signal::get_n_snap_nodes() const
}
unsigned Signal::get_n_snap_nodes() const
virtual void set_position(const Vector &);
virtual void set_rotation(const Angle &);
private:
virtual void set_position(const Vector &);
virtual void set_rotation(const Angle &);
private:
- void normalize_location();
+ void update_location();
public:
virtual Track *get_parent() const { return track; }
public:
virtual Track *get_parent() const { return track; }