3 This file is part of R²C²
4 Copyright © 2006-2011 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #ifndef LIBR2C2_LAYOUT_H_
9 #define LIBR2C2_LAYOUT_H_
12 #include <sigc++/sigc++.h>
13 #include <msp/datafile/loader.h>
14 #include <msp/time/timestamp.h>
32 class Loader: public Msp::DataFile::BasicLoader<Layout>
40 virtual void finish();
42 void route(const std::string &);
44 void track(ArticleNumber);
45 void train(unsigned, unsigned, const std::string &);
46 void train(ArticleNumber, unsigned, const std::string &);
47 void turnout(unsigned, unsigned);
51 typedef std::set<Zone *> ZoneSet;
52 typedef std::vector<Zone *> ZoneArray;
54 sigc::signal<void, Track &> signal_track_added;
55 sigc::signal<void, Track &> signal_track_removed;
56 sigc::signal<void, Route &> signal_route_added;
57 sigc::signal<void, Route &> signal_route_removed;
58 sigc::signal<void, Zone &> signal_zone_added;
59 sigc::signal<void, Zone &> signal_zone_removed;
60 sigc::signal<void, Train &> signal_train_added;
61 sigc::signal<void, Train &> signal_train_removed;
62 sigc::signal<void, Vehicle &> signal_vehicle_added;
63 sigc::signal<void, Vehicle &> signal_vehicle_removed;
64 sigc::signal<void, Block &, Train *> signal_block_reserved;
65 sigc::signal<void, const std::string &> signal_emergency;
71 std::set<Track *> tracks;
72 std::set<Route *> routes;
74 std::set<Block *> blocks;
75 std::map<unsigned, Train *> trains;
76 std::set<Vehicle *> vehicles;
77 Msp::Time::TimeStamp last_tick;
78 unsigned next_turnout_id;
81 Layout(Catalogue &, Driver * = 0);
84 Catalogue &get_catalogue() const { return catalogue; }
85 bool has_driver() const { return driver; }
86 Driver &get_driver() const;
87 const std::string &get_base() const { return base; }
89 void add_track(Track &);
90 const std::set<Track *> &get_tracks() const { return tracks; }
91 Track *pick_track(const Vector &, const Vector &);
92 void remove_track(Track &);
93 unsigned allocate_turnout_id();
95 void add_block(Block &);
96 Block &get_block(unsigned) const;
97 const std::set<Block *> &get_blocks() const { return blocks; }
99 void create_blocks(Track &);
100 void remove_block(Block &);
102 void add_route(Route &);
103 const std::set<Route *> &get_routes() const { return routes; }
104 Route &get_route(const std::string &) const;
105 void update_routes();
106 void remove_route(Route &);
108 void add_zone(Zone &);
109 const ZoneSet &get_zones() const { return zones; }
110 ZoneArray get_zones(const std::string &) const;
111 Zone &get_zone(const std::string &, unsigned) const;
112 void remove_zone(Zone &);
114 void add_train(Train &);
115 Train &get_train(unsigned) const;
116 const std::map<unsigned, Train *> &get_trains() const { return trains; }
117 void remove_train(Train &);
119 void add_vehicle(Vehicle &);
120 void remove_vehicle(Vehicle &);
123 void emergency(const std::string &);
125 void save(const std::string &) const;
126 void save_dynamic(const std::string &) const;
128 void sensor_event(unsigned, bool);