]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/train.h
Make LCD output selectable at runtime through an extra I/O pin
[r2c2.git] / source / libmarklin / train.h
index 90627ae4561d021dc372ac8fe3090a1a94794677..a13c422a9d8c2d35f989d2704e11447152d908f5 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of the MSP Märklin suite
-Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-2010  Mikkosoft Productions, Mikko Rasa
 Distributed under the GPL
 */
 
@@ -12,38 +12,53 @@ Distributed under the GPL
 #include <sigc++/trackable.h>
 #include <msp/time/timestamp.h>
 #include "block.h"
+#include "blockiter.h"
+#include "controller.h"
 
 namespace Marklin {
 
-class Locomotive;
+class ArticleNumber;
 class Route;
-class Sensor;
-class TrafficManager;
-class Turnout;
+class Timetable;
+class Vehicle;
+class VehicleType;
 
 class Train: public sigc::trackable
 {
 public:
        class Loader: public Msp::DataFile::BasicLoader<Train>
        {
+       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<void, const std::string &> signal_name_changed;
-       sigc::signal<void, unsigned> signal_target_speed_changed;
+       sigc::signal<void, const std::string &, float> signal_control_changed;
+       sigc::signal<void, unsigned, bool> signal_function_changed;
        sigc::signal<void, const Route *> signal_route_changed;
+       sigc::signal<void> signal_arrived;
        sigc::signal<void, const std::string &> signal_status_changed;
 
 private:
-       struct BlockRef
+       struct RouteRef
        {
-               Block *block;
-               unsigned entry;
+               const Route *route;
+               unsigned diversion;
 
-               BlockRef(Block *s, unsigned e): block(s), entry(e) { }
+               RouteRef(const Route *, unsigned = 0);
        };
 
        struct RealSpeed
@@ -55,56 +70,112 @@ private:
                void add(float, float);
        };
 
-       TrafficManager &trfc_mgr;
+       typedef std::list<BlockIter> BlockList;
+
+       Layout &layout;
+       const VehicleType &loco_type;
+       unsigned address;
+       std::string protocol;
        std::string name;
-       Locomotive &loco;
-       std::list<BlockRef> cur_blocks;
-       std::list<BlockRef> rsv_blocks;
-       unsigned target_speed;
-       const Route *route;
-       Msp::Time::TimeStamp try_reserve;
+       int priority;
+       const Train *yielding_to;
+       std::vector<Vehicle *> vehicles;
+       BlockList blocks;
+       BlockList::iterator cur_blocks_end;
+       BlockList::iterator clear_blocks_end;
+       Block *pending_block;
+       bool reserving;
+       bool advancing;
+       Controller *controller;
+       Timetable *timetable;
+       bool active;
+       unsigned current_speed_step;
+       bool speed_changing;
+       bool reverse;
+       Msp::Time::TimeStamp stop_timeout;
+       unsigned functions;
+       std::list<RouteRef> routes;
+       bool end_of_route;
        std::string status;
 
        Msp::Time::TimeStamp last_entry_time;
        float travel_dist;
-       unsigned travel_speed;
        bool pure_speed;
        std::vector<RealSpeed> real_speed;
-
-       Track *cur_track;
-       unsigned cur_track_ep;
-       float offset;
-       Point pos;
+       bool accurate_position;
+       float overshoot_dist;
 
 public:
-       Train(TrafficManager &, Locomotive &);
+       Train(Layout &, const VehicleType &, unsigned, const std::string &);
+       ~Train();
 
+       Layout &get_layout() const { return layout; }
+       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 &);
-       void set_speed(unsigned);
-       void set_reverse(bool);
-       void set_route(const Route *);
        const std::string &get_name() const { return name; }
-       Locomotive &get_locomotive() const { return loco; }
-       unsigned get_target_speed() const { return target_speed; }
-       const Route *get_route() const { return route; }
+       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;
+
+       void set_control(const std::string &, float);
+       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_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);
+       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;
+
        const std::string &get_status() const { return status; }
-       const Point &get_position() const { return pos; }
-       void place(Block *, unsigned);
-       bool free_block(Block *);
+
        void tick(const Msp::Time::TimeStamp &, const Msp::Time::TimeDelta &);
+
        void save(std::list<Msp::DataFile::Statement> &) const;
 private:
-       void locomotive_reverse_changed(bool);
-       void sensor_event(bool, Sensor *);
-       void turnout_path_changing(unsigned, Turnout *);
-       void turnout_path_changed(unsigned, Turnout *);
-       unsigned reserve_more();
-       void update_speed();
+       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_path_changed(Track &);
+       void halt_event(bool);
+       void block_reserved(const Block &, const Train *);
+       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 set_position(const Block::Endpoint &);
-       void release_reserved_blocks();
+       void release_blocks();
+       void release_blocks(BlockList::iterator, BlockList::iterator);
+       void reverse_blocks(BlockList &) const;
+       bool advance_route(std::list<RouteRef>::iterator &, Track &);
+       Route *create_lead_route(Route *, const Route *);
+       bool is_valid_diversion(const Route &, const TrackIter &);
 };
 
 } // namespace Marklin