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>
25 class Train: public sigc::trackable
28 class Loader: public Msp::DataFile::BasicLoader<Train>
37 virtual void finish();
39 void block_hint(unsigned);
40 void name(const std::string &);
41 void real_speed(unsigned, float, float);
42 void route(const std::string &);
44 void vehicle(unsigned);
47 sigc::signal<void, const std::string &> signal_name_changed;
48 sigc::signal<void, const std::string &, float> signal_control_changed;
49 sigc::signal<void, unsigned, bool> signal_function_changed;
50 sigc::signal<void, const Route *> signal_route_changed;
51 sigc::signal<void> signal_arrived;
52 sigc::signal<void, const std::string &> signal_status_changed;
60 BlockRef(Block *, unsigned);
61 BlockRef next() const;
70 void add(float, float);
74 const VehicleType &loco_type;
78 std::vector<Vehicle *> vehicles;
79 std::list<BlockRef> cur_blocks;
80 std::list<BlockRef> rsv_blocks;
82 ControlModel *control;
85 unsigned current_speed;
88 Msp::Time::TimeStamp stop_timeout;
91 const Route *next_route;
95 Msp::Time::TimeStamp last_entry_time;
98 std::vector<RealSpeed> real_speed;
99 bool accurate_position;
100 float overshoot_dist;
103 Train(Layout &, const VehicleType &, unsigned);
106 Layout &get_layout() const { return layout; }
107 const VehicleType &get_locomotive_type() const { return loco_type; }
108 unsigned get_address() const { return address; }
109 void set_name(const std::string &);
110 const std::string &get_name() const { return name; }
111 void set_priority(int);
112 int get_priority() const { return priority; }
113 ControlModel &get_control_model() const { return *control; }
115 void add_vehicle(const VehicleType &);
116 void remove_vehicle(unsigned);
117 unsigned get_n_vehicles() const;
118 Vehicle &get_vehicle(unsigned);
119 const Vehicle &get_vehicle(unsigned) const;
121 void set_control(const std::string &, float);
122 void set_active(bool);
123 void set_function(unsigned, bool);
124 float get_control(const std::string &) const;
125 float get_speed() const;
126 bool is_active() const { return active; }
127 bool get_function(unsigned) const;
128 unsigned get_functions() const { return functions; }
130 void set_timetable(Timetable *);
131 Timetable *get_timetable() { return timetable; }
133 void set_route(const Route *);
134 void go_to(const Track &);
135 const Route *get_route() const { return route; }
136 void place(Block &, unsigned);
137 bool is_placed() const { return !cur_blocks.empty(); }
138 bool free_block(Block &);
139 int get_entry_to_block(Block &) const;
140 float get_reserved_distance() const;
142 const std::string &get_status() const { return status; }
144 void tick(const Msp::Time::TimeStamp &, const Msp::Time::TimeDelta &);
146 void save(std::list<Msp::DataFile::Statement> &) const;
148 void control_changed(const TrainControl &);
149 void loco_speed_event(unsigned, unsigned, bool);
150 void loco_func_event(unsigned, unsigned, bool);
151 void sensor_event(unsigned, bool);
152 void turnout_event(unsigned, bool);
153 void halt_event(bool);
154 void block_reserved(const Block &, const Train *);
155 unsigned reserve_more();
156 float get_real_speed(unsigned) const;
157 unsigned find_speed(float) const;
158 float get_travel_speed() const;
159 void set_status(const std::string &);
160 void release_blocks(std::list<BlockRef> &);
161 void release_blocks(std::list<BlockRef> &, std::list<BlockRef>::iterator, std::list<BlockRef>::iterator);
162 void reverse_blocks(std::list<BlockRef> &) const;
165 } // namespace Marklin