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 "controller.h"
24 class Train: public sigc::trackable
27 class Loader: public Msp::DataFile::BasicLoader<Train>
36 virtual void finish();
38 void block_hint(unsigned);
39 void name(const std::string &);
40 void real_speed(unsigned, float, float);
41 void route(const std::string &);
43 void vehicle(unsigned);
46 sigc::signal<void, const std::string &> signal_name_changed;
47 sigc::signal<void, const std::string &, float> signal_control_changed;
48 sigc::signal<void, unsigned, bool> signal_function_changed;
49 sigc::signal<void, const Route *> signal_route_changed;
50 sigc::signal<void> signal_arrived;
51 sigc::signal<void, const std::string &> signal_status_changed;
59 BlockRef(Block *, unsigned);
60 BlockRef next() const;
69 void add(float, float);
73 const VehicleType &loco_type;
77 std::vector<Vehicle *> vehicles;
78 std::list<BlockRef> cur_blocks;
79 std::list<BlockRef> rsv_blocks;
81 Controller *controller;
84 unsigned current_speed;
87 Msp::Time::TimeStamp stop_timeout;
90 const Route *next_route;
94 Msp::Time::TimeStamp last_entry_time;
97 std::vector<RealSpeed> real_speed;
98 bool accurate_position;
102 Train(Layout &, const VehicleType &, unsigned);
105 Layout &get_layout() const { return layout; }
106 const VehicleType &get_locomotive_type() const { return loco_type; }
107 unsigned get_address() const { return address; }
108 void set_name(const std::string &);
109 const std::string &get_name() const { return name; }
110 void set_priority(int);
111 int get_priority() const { return priority; }
112 Controller &get_controller() const { return *controller; }
114 void add_vehicle(const VehicleType &);
115 void remove_vehicle(unsigned);
116 unsigned get_n_vehicles() const;
117 Vehicle &get_vehicle(unsigned);
118 const Vehicle &get_vehicle(unsigned) const;
120 void set_control(const std::string &, float);
121 void set_active(bool);
122 void set_function(unsigned, bool);
123 float get_control(const std::string &) const;
124 float get_speed() const;
125 bool is_active() const { return active; }
126 bool get_function(unsigned) const;
127 unsigned get_functions() const { return functions; }
129 void set_timetable(Timetable *);
130 Timetable *get_timetable() { return timetable; }
132 void set_route(const Route *);
133 void go_to(const Track &);
134 const Route *get_route() const { return route; }
135 void place(Block &, unsigned);
136 bool is_placed() const { return !cur_blocks.empty(); }
137 bool free_block(Block &);
138 int get_entry_to_block(Block &) const;
139 float get_reserved_distance() const;
141 const std::string &get_status() const { return status; }
143 void tick(const Msp::Time::TimeStamp &, const Msp::Time::TimeDelta &);
145 void save(std::list<Msp::DataFile::Statement> &) const;
147 void control_changed(const Controller::Control &);
148 void loco_speed_event(unsigned, unsigned, bool);
149 void loco_func_event(unsigned, unsigned, bool);
150 void sensor_event(unsigned, bool);
151 void turnout_event(unsigned, bool);
152 void halt_event(bool);
153 void block_reserved(const Block &, const Train *);
154 unsigned reserve_more();
155 float get_real_speed(unsigned) const;
156 unsigned find_speed(float) const;
157 float get_travel_speed() const;
158 void set_status(const std::string &);
159 void release_blocks(std::list<BlockRef> &);
160 void release_blocks(std::list<BlockRef> &, std::list<BlockRef>::iterator, std::list<BlockRef>::iterator);
161 void reverse_blocks(std::list<BlockRef> &) const;
164 } // namespace Marklin