3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2009 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 real_speed(unsigned, float, float);
38 void route(const std::string &);
41 sigc::signal<void, const std::string &> signal_name_changed;
42 sigc::signal<void, unsigned> signal_target_speed_changed;
43 sigc::signal<void, const Route *> signal_route_changed;
44 sigc::signal<void, const std::string &> signal_status_changed;
52 BlockRef(Block *s, unsigned e): block(s), entry(e) { }
61 void add(float, float);
64 TrafficManager &trfc_mgr;
67 std::list<BlockRef> cur_blocks;
68 std::list<BlockRef> rsv_blocks;
70 unsigned target_speed;
72 Msp::Time::TimeStamp try_reserve;
75 Msp::Time::TimeStamp last_entry_time;
77 unsigned travel_speed;
79 std::vector<RealSpeed> real_speed;
82 unsigned cur_track_ep;
87 Train(TrafficManager &, Locomotive &);
89 void set_name(const std::string &);
90 void set_speed(unsigned);
91 void set_reverse(bool);
92 void set_route(const Route *);
93 const std::string &get_name() const { return name; }
94 Locomotive &get_locomotive() const { return loco; }
95 unsigned get_target_speed() const { return target_speed; }
96 const Route *get_route() const { return route; }
97 const std::string &get_status() const { return status; }
98 const Point &get_position() const { return pos; }
99 void place(Block &, unsigned);
100 bool is_placed() const { return !cur_blocks.empty(); }
101 bool free_block(Block &);
102 int get_entry_to_block(Block &) const;
103 void tick(const Msp::Time::TimeStamp &, const Msp::Time::TimeDelta &);
104 void save(std::list<Msp::DataFile::Statement> &) const;
106 void locomotive_reverse_changed(bool);
107 void sensor_event(bool, Sensor *);
108 void turnout_path_changing(unsigned, Turnout *);
109 void turnout_path_changed(unsigned, Turnout *);
110 unsigned reserve_more();
112 float get_real_speed(unsigned) const;
113 unsigned find_speed(float) const;
114 void set_status(const std::string &);
115 void set_position(const Block::Endpoint &);
116 void release_blocks(std::list<BlockRef> &);
117 void reverse_blocks(std::list<BlockRef> &) const;
120 } // namespace Marklin