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