]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/route.h
Add framework for generating simple meshes for vehicles
[r2c2.git] / source / libmarklin / route.h
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2007-2010  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef LIBMARKLIN_ROUTE_H_
9 #define LIBMARKLIN_ROUTE_H_
10
11 #include <map>
12 #include <set>
13 #include <string>
14 #include <sigc++/trackable.h>
15 #include <msp/datafile/loader.h>
16
17 namespace Marklin {
18
19 class Layout;
20 class Track;
21 class TrackIter;
22
23 class Route: public sigc::trackable
24 {
25 public:
26         typedef std::map<unsigned, int> TurnoutMap;
27
28         class Loader: public Msp::DataFile::BasicLoader<Route>
29         {
30         private:
31                 TurnoutMap turnouts;
32
33         public:
34                 Loader(Route &);
35         private:
36                 virtual void finish();
37                 void turnout(unsigned, unsigned);
38         };
39
40         sigc::signal<void, const std::string &> signal_name_changed;
41
42 private:
43         Layout &layout;
44         std::string name;
45         bool temporary;
46         std::set<Track *> tracks;
47         TurnoutMap turnouts;
48
49 public:
50         Route(Layout &);
51         ~Route();
52
53         void set_name(const std::string &);
54         const std::string &get_name() const { return name; }
55         void set_temporary(bool);
56         bool is_temporary() const { return temporary; }
57         void set_turnout(unsigned, unsigned);
58         void update_turnouts();
59         int get_turnout(unsigned) const;
60         unsigned get_path(Track &) const;
61         const std::map<unsigned, int> &get_turnouts() const { return turnouts; }
62         void add_track(Track &);
63         void add_tracks(const std::set<Track *> &);
64         void add_track_chain(Track &, unsigned, const TurnoutMap &);
65         const std::set<Track *> &get_tracks() const { return tracks; }
66         bool has_track(Track &) const;
67         void save(std::list<Msp::DataFile::Statement> &) const;
68 private:
69         unsigned check_validity(Track &) const;
70         void track_removed(Track &);
71
72 public:
73         static Route *find(const TrackIter &, Track &);
74         static Route *find(const TrackIter &, const Route &);
75         static Route *find(const TrackIter &, const std::set<Track *> &);
76 };
77
78 } // namespace Marklin
79
80 #endif