]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/tracktype.h
Add utility functions to make endpoint path mask operations clearer
[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                 bool has_path(unsigned p) const { return paths&(1<<p); }
23                 bool has_common_paths(const Endpoint &e) const { return paths&e.paths; }
24         };
25
26         class Loader: public Msp::DataFile::ObjectLoader<TrackType>
27         {
28         private:
29                 bool state_bits_set;
30
31         public:
32                 Loader(TrackType &);
33         private:
34                 virtual void finish();
35                 void part();
36                 void position(float, float, float);
37                 void state_bits(unsigned);
38         };
39
40 private:
41         ArticleNumber art_nr;
42         std::string description;
43         std::vector<TrackPart> parts;
44         std::vector<Endpoint> endpoints;
45         unsigned state_bits;
46         unsigned autofit_preference;
47         std::string object;
48
49 public:
50         TrackType(const ArticleNumber &);
51
52         const ArticleNumber &get_article_number() const { return art_nr; }
53         const std::string &get_description() const { return description; }
54         float get_total_length() const;
55         float get_path_length(int) const;
56         unsigned get_paths() const;
57         unsigned get_n_paths() const;
58         unsigned get_state_bits() const { return state_bits; }
59         bool is_turnout() const;
60         bool is_dead_end() const;
61         unsigned get_autofit_preference() const { return autofit_preference; }
62         const std::string &get_object() const { return object; }
63         const std::vector<TrackPart> &get_parts() const { return parts; }
64         const std::vector<Endpoint> &get_endpoints() const { return endpoints; }
65         const Endpoint &get_endpoint(unsigned) const;
66         TrackPoint get_point(unsigned, unsigned, float) const;
67         TrackPoint get_nearest_point(const Vector &) const;
68         bool collide_ray(const Vector &, const Vector &, float) const;
69
70 private:
71         void collect_endpoints();
72 };
73
74 } // namespace R2C2
75
76 #endif