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>
24 class Train: public sigc::trackable
27 class Loader: public Msp::DataFile::BasicLoader<Train>
36 void block_hint(unsigned);
37 void name(const std::string &);
38 void real_speed(unsigned, float, float);
39 void route(const std::string &);
41 void vehicle(unsigned);
44 sigc::signal<void, const std::string &> signal_name_changed;
45 sigc::signal<void, const std::string &, float> signal_control_changed;
46 sigc::signal<void, unsigned, bool> signal_function_changed;
47 sigc::signal<void, const Route *> signal_route_changed;
48 sigc::signal<void> signal_arrived;
49 sigc::signal<void, const std::string &> signal_status_changed;
57 BlockRef(Block *, unsigned);
58 BlockRef next() const;
67 void add(float, float);
71 const LocoType &loco_type;
75 std::vector<Vehicle *> vehicles;
76 std::list<BlockRef> cur_blocks;
77 std::list<BlockRef> rsv_blocks;
79 ControlModel *control;
82 unsigned current_speed;
85 Msp::Time::TimeStamp stop_timeout;
88 const Route *next_route;
92 Msp::Time::TimeStamp last_entry_time;
95 std::vector<RealSpeed> real_speed;
96 bool accurate_position;
100 Train(Layout &, const LocoType &, unsigned);
103 Layout &get_layout() const { return layout; }
104 const LocoType &get_locomotive_type() const { return loco_type; }
105 unsigned get_address() const { return address; }
106 void set_name(const std::string &);
107 const std::string &get_name() const { return name; }
108 void set_priority(int);
109 int get_priority() const { return priority; }
110 ControlModel &get_control() const { return *control; }
112 Vehicle &get_vehicle(unsigned);
113 const Vehicle &get_vehicle(unsigned) const;
115 void set_control(const std::string &, float);
116 void set_active(bool);
117 void set_function(unsigned, bool);
118 float get_control(const std::string &) const;
119 bool is_active() const { return active; }
120 bool get_function(unsigned) const;
121 unsigned get_functions() const { return functions; }
123 void set_route(const Route *);
124 void go_to(const Track &);
125 const Route *get_route() const { return route; }
126 void place(Block &, unsigned);
127 bool is_placed() const { return !cur_blocks.empty(); }
128 bool free_block(Block &);
129 int get_entry_to_block(Block &) const;
130 float get_reserved_distance() const;
132 const std::string &get_status() const { return status; }
134 void tick(const Msp::Time::TimeStamp &, const Msp::Time::TimeDelta &);
136 void save(std::list<Msp::DataFile::Statement> &) const;
138 void loco_speed_event(unsigned, unsigned, bool);
139 void loco_func_event(unsigned, unsigned, bool);
140 void sensor_event(unsigned, bool);
141 void turnout_event(unsigned, bool);
142 void halt_event(bool);
143 void block_reserved(const Block &, const Train *);
144 unsigned reserve_more();
145 float get_real_speed(unsigned) const;
146 unsigned find_speed(float) const;
147 float get_travel_speed() const;
148 void set_status(const std::string &);
149 void release_blocks(std::list<BlockRef> &);
150 void release_blocks(std::list<BlockRef> &, std::list<BlockRef>::iterator, std::list<BlockRef>::iterator);
151 void reverse_blocks(std::list<BlockRef> &) const;
154 } // namespace Marklin