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>
21 class Train: public sigc::trackable
24 class Loader: public Msp::DataFile::BasicLoader<Train>
33 void block_hint(unsigned);
34 void name(const std::string &);
35 void real_speed(unsigned, float, float);
36 void route(const std::string &);
39 sigc::signal<void, const std::string &> signal_name_changed;
40 sigc::signal<void, unsigned> signal_target_speed_changed;
41 sigc::signal<void, unsigned> signal_speed_changed;
42 sigc::signal<void, bool> signal_reverse_changed;
43 sigc::signal<void, unsigned, bool> signal_function_changed;
44 sigc::signal<void, const Route *> signal_route_changed;
45 sigc::signal<void, const std::string &> signal_status_changed;
53 BlockRef(Block *s, unsigned e): block(s), entry(e) { }
62 void add(float, float);
66 const LocoType &loco_type;
69 std::list<BlockRef> cur_blocks;
70 std::list<BlockRef> rsv_blocks;
72 unsigned target_speed;
73 unsigned current_speed;
75 Msp::Time::TimeStamp stop_timeout;
81 Msp::Time::TimeStamp last_entry_time;
83 unsigned travel_speed;
85 std::vector<RealSpeed> real_speed;
88 unsigned cur_track_ep;
93 Train(Layout &, const LocoType &, unsigned);
96 const LocoType &get_locomotive_type() const { return loco_type; }
97 unsigned get_address() const { return address; }
98 void set_name(const std::string &);
99 const std::string &get_name() const { return name; }
101 void set_speed(unsigned);
102 void set_reverse(bool);
103 void set_function(unsigned, bool);
104 unsigned get_target_speed() const { return target_speed; }
105 unsigned get_speed() const { return current_speed; }
106 bool get_reverse() const { return reverse; }
107 bool get_function(unsigned) const;
108 unsigned get_functions() const { return functions; }
110 void set_route(const Route *);
111 void go_to(const Track &);
112 const Route *get_route() const { return route; }
113 void place(Block &, unsigned);
114 bool is_placed() const { return !cur_blocks.empty(); }
115 bool free_block(Block &);
116 int get_entry_to_block(Block &) const;
118 const std::string &get_status() const { return status; }
119 const Point &get_position() const { return pos; }
121 void tick(const Msp::Time::TimeStamp &, const Msp::Time::TimeDelta &);
123 void save(std::list<Msp::DataFile::Statement> &) const;
125 void loco_speed_event(unsigned, unsigned, bool);
126 void loco_func_event(unsigned, unsigned, bool);
127 void sensor_event(unsigned, bool);
128 void turnout_event(unsigned, bool);
129 void block_reserved(const Block &, const Train *);
130 unsigned reserve_more();
132 float get_real_speed(unsigned) const;
133 unsigned find_speed(float) const;
134 void set_status(const std::string &);
135 void set_position(const Block::Endpoint &);
136 void release_blocks(std::list<BlockRef> &);
137 void release_blocks(std::list<BlockRef> &, std::list<BlockRef>::iterator, std::list<BlockRef>::iterator);
138 void reverse_blocks(std::list<BlockRef> &) const;
141 } // namespace Marklin