3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #ifndef LIBMARKLIN_TRAIN_H_
9 #define LIBMARKLIN_TRAIN_H_
11 #include <sigc++/signal.h>
12 #include <sigc++/trackable.h>
13 #include <msp/time/timestamp.h>
15 #include "blockiter.h"
16 #include "controller.h"
26 class Train: public sigc::trackable
29 class Loader: public Msp::DataFile::BasicLoader<Train>
38 virtual void finish();
40 void block_hint(unsigned);
41 void name(const std::string &);
42 void real_speed(unsigned, float, float);
43 void route(const std::string &);
45 void vehicle(ArticleNumber);
48 sigc::signal<void, const std::string &> signal_name_changed;
49 sigc::signal<void, const std::string &, float> signal_control_changed;
50 sigc::signal<void, unsigned, bool> signal_function_changed;
51 sigc::signal<void, const Route *> signal_route_changed;
52 sigc::signal<void> signal_arrived;
53 sigc::signal<void, const std::string &> signal_status_changed;
61 RouteRef(const Route *, unsigned = 0);
70 void add(float, float);
73 typedef std::list<BlockIter> BlockList;
76 const VehicleType &loco_type;
80 const Train *yielding_to;
81 std::vector<Vehicle *> vehicles;
83 BlockList::iterator cur_blocks_end;
84 BlockList::iterator clear_blocks_end;
88 Controller *controller;
91 unsigned current_speed;
94 Msp::Time::TimeStamp stop_timeout;
96 std::list<RouteRef> routes;
100 Msp::Time::TimeStamp last_entry_time;
103 std::vector<RealSpeed> real_speed;
104 bool accurate_position;
105 float overshoot_dist;
108 Train(Layout &, const VehicleType &, unsigned);
111 Layout &get_layout() const { return layout; }
112 const VehicleType &get_locomotive_type() const { return loco_type; }
113 unsigned get_address() const { return address; }
114 void set_name(const std::string &);
115 const std::string &get_name() const { return name; }
116 void set_priority(int);
117 void yield_to(const Train &);
118 int get_priority() const { return priority; }
119 Controller &get_controller() const { return *controller; }
121 void add_vehicle(const VehicleType &);
122 void remove_vehicle(unsigned);
123 unsigned get_n_vehicles() const;
124 Vehicle &get_vehicle(unsigned);
125 const Vehicle &get_vehicle(unsigned) const;
127 void set_control(const std::string &, float);
128 void set_active(bool);
129 void set_function(unsigned, bool);
130 float get_control(const std::string &) const;
131 float get_speed() const;
132 bool is_active() const { return active; }
133 bool get_function(unsigned) const;
134 unsigned get_functions() const { return functions; }
136 void set_timetable(Timetable *);
137 Timetable *get_timetable() { return timetable; }
139 bool set_route(const Route *);
141 bool divert(Track &);
142 const Route *get_route() const;
143 void place(Block &, unsigned);
145 bool is_placed() const { return !blocks.empty(); }
146 bool free_block(Block &);
147 void free_noncritical_blocks();
148 int get_entry_to_block(Block &) const;
149 float get_reserved_distance() const;
151 const std::string &get_status() const { return status; }
153 void tick(const Msp::Time::TimeStamp &, const Msp::Time::TimeDelta &);
155 void save(std::list<Msp::DataFile::Statement> &) const;
157 void control_changed(const Controller::Control &);
158 void loco_speed_event(unsigned, unsigned, bool);
159 void loco_func_event(unsigned, unsigned, bool);
160 void sensor_event(unsigned, bool);
161 void turnout_path_changed(Track &);
162 void halt_event(bool);
163 void block_reserved(const Block &, const Train *);
165 void check_turnout_paths(bool);
166 float get_reserved_distance_until(const Block *, bool) const;
167 float get_real_speed(unsigned) const;
168 unsigned find_speed(float) const;
169 float get_travel_speed() const;
170 void set_status(const std::string &);
171 void release_blocks();
172 void release_blocks(BlockList::iterator, BlockList::iterator);
173 void reverse_blocks(BlockList &) const;
174 bool advance_route(std::list<RouteRef>::iterator &, Track &);
175 Route *create_lead_route(Route *, const Route *);
176 bool is_valid_diversion(const Route &, const TrackIter &);
179 } // namespace Marklin