}
}
+ {
+ GLtk::Row row(*layout);
+ add(*(lbl1 = new GLtk::Label("Direction")));
+ layout->add_constraint(*lbl1, GLtk::Layout::COPY_WIDTH, *lbl2);
+
+ add(*(drp_preferred_dir = new GLtk::Dropdown));
+ GLtk::ListDataStore<string> &data = dynamic_cast<GLtk::ListDataStore<string> &>(drp_preferred_dir->get_data());
+ const char *directions[] = { "either", "up", "down", 0 };
+ for(unsigned i=0; directions[i]; ++i)
+ {
+ data.append(directions[i]);
+ if(zone.get_preferred_direction()==i)
+ drp_preferred_dir->set_selected_index(i);
+ }
+ }
+
GLtk::Button *btn;
{
zone.clear_direction();
else
zone.set_direction_towards(*up_directions.get(sel), TrackChain::UP);
+
+ if(zone.has_direction())
+ {
+ sel = drp_preferred_dir->get_selected_index();
+ zone.set_preferred_direction(static_cast<TrackChain::Direction>(sel));
+ }
}
}
Msp::GLtk::Entry *ent_number;
Msp::GLtk::FunctionListData<R2C2::Track *> up_directions;
Msp::GLtk::Dropdown *drp_up_direction;
+ Msp::GLtk::Dropdown *drp_preferred_dir;
public:
ZoneProperties(R2C2::Zone &);
sensor_addr(0),
links(type.get_endpoints().size()),
active_path(0),
- path_changing(false)
+ path_changing(false),
+ preferred_exit(-1)
{
if(type.is_turnout())
{
layout.create_blocks(*this);
}
+void Track::set_preferred_exit(int e)
+{
+ preferred_exit = e;
+}
+
void Track::set_active_path(unsigned p)
{
if(!type.is_turnout())
unsigned active_path;
bool path_changing;
AttachmentList attachments;
+ int preferred_exit;
Track(const Track &);
Track &operator=(const Track &);
void set_sensor_address(unsigned);
unsigned get_turnout_address() const { return turnout_addr; }
unsigned get_sensor_address() const { return sensor_addr; }
+ void set_preferred_exit(int);
+ int get_preferred_exit() const { return preferred_exit; }
void set_active_path(unsigned);
unsigned get_active_path() const { return active_path; }
bool is_path_changing() const { return path_changing; }
Zone::Zone(Layout &l):
TrackChain(l),
number(0),
- up_end(-1)
+ up_end(-1),
+ preferred_dir(UNSPECIFIED)
{
layout.add(*this);
}
TrackChain::set_name(full_name);
}
+void Zone::on_track_added(Track &track)
+{
+ if(preferred_dir)
+ {
+ TrackIter iter = iter_for(track, preferred_dir==UP ? DOWN : UP);
+ track.set_preferred_exit(iter.entry());
+ }
+}
+
void Zone::set_direction_towards(Track &track, Direction dir)
{
if(dir==UNSPECIFIED)
throw logic_error("internal error (valid track not linked to ends)");
}
+void Zone::set_preferred_direction(Direction d)
+{
+ if(up_end<0)
+ throw logic_error("no direction");
+
+ preferred_dir = d;
+
+ if(preferred_dir)
+ {
+ TrackIter iter = get_end(preferred_dir).reverse();
+ while(iter && tracks.count(iter.track()))
+ {
+ iter->set_preferred_exit(iter.entry());
+ iter = next_iter(iter);
+ }
+ }
+ else
+ {
+ for(TrackSet::iterator i=tracks.begin(); i!=tracks.end(); ++i)
+ (*i)->set_preferred_exit(-1);
+ }
+}
+
void Zone::clear_direction()
{
up_end = -1;
+ preferred_dir = UNSPECIFIED;
}
TrackIter Zone::iter_for(Track &track, Direction dir) const
break;
}
}
+
+ if(preferred_dir)
+ st.push_back((DataFile::Statement("preferred_direction"), preferred_dir));
}
}
add("direction_hint", &Loader::direction_hint);
add("group", &Zone::group);
add("number", &Zone::number);
+ add("preferred_direction", &Loader::preferred_direction);
add("qualifier", &Zone::qualifier);
}
throw invalid_argument("Zone::Loader::direction_hint");
}
+void Zone::Loader::preferred_direction(Direction d)
+{
+ obj.set_preferred_direction(d);
+}
+
} // namespace R2C2
virtual void finish();
void block(unsigned);
void direction_hint(unsigned, Direction);
+ void preferred_direction(Direction);
};
private:
std::string qualifier;
unsigned number;
int up_end;
+ Direction preferred_dir;
public:
Zone(Layout &);
const std::string &get_qualifier() const { return qualifier; }
unsigned get_number() const { return number; }
+private:
+ virtual void on_track_added(Track &);
+
+public:
void set_direction_towards(Track &, Direction);
+ bool has_direction() const { return up_end>=0; }
+ void set_preferred_direction(Direction);
+ Direction get_preferred_direction() const { return preferred_dir; }
void clear_direction();
virtual TrackIter iter_for(Track &, Direction) const;
private: