]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/tracktype.h
Allow custom objects for tracks
[r2c2.git] / source / libr2c2 / tracktype.h
1 /* $Id$
2
3 This file is part of R²C²
4 Copyright © 2006-2010  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef LIBR2C2_TRACKTYPE_H_
9 #define LIBR2C2_TRACKTYPE_H_
10
11 #include <msp/datafile/loader.h>
12 #include "articlenumber.h"
13 #include "geometry.h"
14 #include "trackpart.h"
15
16 namespace R2C2 {
17
18 class TrackType
19 {
20 public:
21         struct Endpoint
22         {
23                 Point pos;
24                 float dir;  // Direction outwards from the endpoint
25                 unsigned paths;
26
27                 Endpoint(float, float, float, unsigned);
28         };
29
30         class Loader: public Msp::DataFile::BasicLoader<TrackType>
31         {
32         private:
33                 bool state_bits_set;
34
35         public:
36                 Loader(TrackType &);
37         private:
38                 virtual void finish();
39                 void part();
40                 void position(float, float, float);
41                 void state_bits(unsigned);
42         };
43
44 private:
45         ArticleNumber art_nr;
46         std::string description;
47         std::vector<TrackPart> parts;
48         std::vector<Endpoint> endpoints;
49         unsigned state_bits;
50         unsigned autofit_preference;
51         std::string object;
52
53 public:
54         TrackType(const ArticleNumber &);
55
56         const ArticleNumber &get_article_number() const { return art_nr; }
57         const std::string &get_description() const { return description; }
58         float get_total_length() const;
59         float get_path_length(int) const;
60         unsigned get_paths() const;
61         unsigned get_n_paths() const;
62         unsigned get_state_bits() const { return state_bits; }
63         bool is_turnout() const;
64         bool is_dead_end() const;
65         unsigned get_autofit_preference() const { return autofit_preference; }
66         const std::string &get_object() const { return object; }
67         const std::vector<TrackPart> &get_parts() const { return parts; }
68         const std::vector<Endpoint> &get_endpoints() const { return endpoints; }
69         const Endpoint &get_endpoint(unsigned) const;
70         TrackPoint get_point(unsigned, unsigned, float) const;
71
72 private:
73         void collect_endpoints();
74 };
75
76 } // namespace R2C2
77
78 #endif