X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Ftrain.h;h=a13c422a9d8c2d35f989d2704e11447152d908f5;hb=975ea87cc7be179618b06291cb2506a2523cad1f;hp=5960c27d16b78164da022a40e0c79e7529647244;hpb=a9180bc4bb7ff4c403e206cc2c785ff32544a0d6;p=r2c2.git diff --git a/source/libmarklin/train.h b/source/libmarklin/train.h index 5960c27..a13c422 100644 --- a/source/libmarklin/train.h +++ b/source/libmarklin/train.h @@ -12,14 +12,16 @@ Distributed under the GPL #include #include #include "block.h" +#include "blockiter.h" +#include "controller.h" namespace Marklin { -class ControlModel; -class LocoType; +class ArticleNumber; class Route; class Timetable; class Vehicle; +class VehicleType; class Train: public sigc::trackable { @@ -28,16 +30,19 @@ public: { private: Block *prev_block; + bool blocks_valid; public: Loader(Train &); private: + virtual void finish(); void block(unsigned); void block_hint(unsigned); void name(const std::string &); void real_speed(unsigned, float, float); void route(const std::string &); void timetable(); + void vehicle(ArticleNumber); }; sigc::signal signal_name_changed; @@ -48,13 +53,12 @@ public: sigc::signal signal_status_changed; private: - struct BlockRef + struct RouteRef { - Block *block; - unsigned entry; + const Route *route; + unsigned diversion; - BlockRef(Block *, unsigned); - BlockRef next() const; + RouteRef(const Route *, unsigned = 0); }; struct RealSpeed @@ -66,24 +70,31 @@ private: void add(float, float); }; + typedef std::list BlockList; + Layout &layout; - const LocoType &loco_type; + const VehicleType &loco_type; unsigned address; + std::string protocol; std::string name; + int priority; + const Train *yielding_to; std::vector vehicles; - std::list cur_blocks; - std::list rsv_blocks; + BlockList blocks; + BlockList::iterator cur_blocks_end; + BlockList::iterator clear_blocks_end; Block *pending_block; - ControlModel *control; + bool reserving; + bool advancing; + Controller *controller; Timetable *timetable; bool active; - unsigned current_speed; + unsigned current_speed_step; bool speed_changing; bool reverse; Msp::Time::TimeStamp stop_timeout; unsigned functions; - const Route *route; - const Route *next_route; + std::list routes; bool end_of_route; std::string status; @@ -91,18 +102,27 @@ private: float travel_dist; bool pure_speed; std::vector real_speed; + bool accurate_position; + float overshoot_dist; public: - Train(Layout &, const LocoType &, unsigned); + Train(Layout &, const VehicleType &, unsigned, const std::string &); ~Train(); Layout &get_layout() const { return layout; } - const LocoType &get_locomotive_type() const { return loco_type; } + const VehicleType &get_locomotive_type() const { return loco_type; } unsigned get_address() const { return address; } + const std::string &get_protocol() const { return protocol; } void set_name(const std::string &); const std::string &get_name() const { return name; } - ControlModel &get_control() const { return *control; } - + void set_priority(int); + void yield_to(const Train &); + int get_priority() const { return priority; } + Controller &get_controller() const { return *controller; } + + void add_vehicle(const VehicleType &); + void remove_vehicle(unsigned); + unsigned get_n_vehicles() const; Vehicle &get_vehicle(unsigned); const Vehicle &get_vehicle(unsigned) const; @@ -110,16 +130,23 @@ public: void set_active(bool); void set_function(unsigned, bool); float get_control(const std::string &) const; + float get_speed() const; bool is_active() const { return active; } bool get_function(unsigned) const; unsigned get_functions() const { return functions; } - void set_route(const Route *); - void go_to(const Track &); - const Route *get_route() const { return route; } + void set_timetable(Timetable *); + Timetable *get_timetable() { return timetable; } + + bool set_route(const Route *); + bool go_to(Track &); + bool divert(Track &); + const Route *get_route() const; void place(Block &, unsigned); - bool is_placed() const { return !cur_blocks.empty(); } + void unplace(); + bool is_placed() const { return !blocks.empty(); } bool free_block(Block &); + void free_noncritical_blocks(); int get_entry_to_block(Block &) const; float get_reserved_distance() const; @@ -129,19 +156,26 @@ public: void save(std::list &) const; private: + void control_changed(const Controller::Control &); void loco_speed_event(unsigned, unsigned, bool); void loco_func_event(unsigned, unsigned, bool); void sensor_event(unsigned, bool); - void turnout_event(unsigned, bool); + void turnout_path_changed(Track &); + void halt_event(bool); void block_reserved(const Block &, const Train *); - unsigned reserve_more(); + void reserve_more(); + void check_turnout_paths(bool); + float get_reserved_distance_until(const Block *, bool) const; float get_real_speed(unsigned) const; - unsigned find_speed(float) const; + unsigned find_speed_step(float) const; float get_travel_speed() const; void set_status(const std::string &); - void release_blocks(std::list &); - void release_blocks(std::list &, std::list::iterator, std::list::iterator); - void reverse_blocks(std::list &) const; + void release_blocks(); + void release_blocks(BlockList::iterator, BlockList::iterator); + void reverse_blocks(BlockList &) const; + bool advance_route(std::list::iterator &, Track &); + Route *create_lead_route(Route *, const Route *); + bool is_valid_diversion(const Route &, const TrackIter &); }; } // namespace Marklin