const set<Track *> &tracks = objects.get<Track>();
for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
if((*i)->get_type().is_turnout())
- writer.write((DataFile::Statement("turnout"), (*i)->get_turnout_address(), (*i)->get_active_path()));
+ {
+ DataFile::Statement st("turnout");
+ st.append((*i)->get_turnout_address());
+ (*i)->save_dynamic(st.sub);
+ writer.write(st);
+ }
for(map<unsigned, Train *>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
{
add("train", &Loader::train);
add("turnout", &Loader::turnout);
add("zone", &Loader::zone);
+
+ // Deprecated
+ add("turnout", &Loader::turnout2);
}
void Layout::Loader::beamgate()
load_sub(*trn);
}
-void Layout::Loader::turnout(unsigned addr, unsigned path)
+void Layout::Loader::turnout(unsigned addr)
+{
+ /* Kinda slow, but maintaining a map of turnouts seems more trouble than
+ it's worth at this point. */
+ const set<Track *> &tracks = obj.objects.get<Track>();
+ for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
+ if((*i)->get_turnout_address()==addr)
+ {
+ load_sub(**i);
+ return;
+ }
+
+ throw key_error(addr);
+}
+
+void Layout::Loader::turnout2(unsigned addr, unsigned path)
{
+ // XXX Discrepancy between ids and addresses
if(obj.driver)
obj.driver->set_turnout(addr, path);
}
void terrain(const std::string &);
void track(const std::string &);
void train(const std::string &, unsigned, const std::string &);
- void turnout(unsigned, unsigned);
+ void turnout(unsigned);
+ void turnout2(unsigned, unsigned);
void zone();
};
st.push_back((DataFile::Statement("flex"), true));
}
+void Track::save_dynamic(list<DataFile::Statement> &st) const
+{
+ if(turnout_addr)
+ st.push_back((DataFile::Statement("path"), active_path));
+}
+
void Track::turnout_event(unsigned id, unsigned state)
{
if(id==turnout_id)
Track::Loader::Loader(Track &t):
DataFile::ObjectLoader<Track>(t)
{
+ add("path", &Loader::path);
add("position", &Loader::position);
add("rotation", &Loader::rotation);
add("tilt", &Loader::tilt);
add("slope", &Loader::slope);
}
+void Track::Loader::path(unsigned p)
+{
+ obj.set_active_path(p);
+ if(obj.path_changing)
+ {
+ obj.active_path = p;
+ obj.signal_path_changed.emit(p);
+ }
+}
+
void Track::Loader::position(float x, float y, float z)
{
obj.set_position(Vector(x, y, z));
public:
Loader(Track &);
private:
+ void path(unsigned);
void position(float, float, float);
void rotation(float);
void sensor_address(unsigned);
AttachmentList get_attachments_ordered(unsigned) const;
void save(std::list<Msp::DataFile::Statement> &) const;
+ void save_dynamic(std::list<Msp::DataFile::Statement> &) const;
private:
void turnout_event(unsigned, unsigned);
void turnout_failed(unsigned);