]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/tracktype.h
Remove some unnecessary things
[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 "objecttype.h"
8 #include "trackpart.h"
9
10 namespace R2C2 {
11
12 class TrackAppearance;
13
14 class TrackType: public ObjectType
15 {
16 public:
17         struct Endpoint
18         {
19                 Vector pos;
20                 Angle dir;  // Direction outwards from the endpoint
21                 unsigned paths;
22
23                 Endpoint(float, float, const Angle &, unsigned);
24
25                 bool has_path(unsigned p) const { return paths&(1<<p); }
26                 bool has_common_paths(const Endpoint &e) const { return paths&e.paths; }
27         };
28
29         class Loader: public Msp::DataFile::DerivedObjectLoader<TrackType, ObjectType::Loader>
30         {
31         public:
32                 typedef Msp::DataFile::Collection Collection;
33
34         private:
35                 Collection &coll;
36                 bool state_bits_set;
37
38         public:
39                 Loader(TrackType &, Collection &);
40
41                 virtual Collection &get_collection() const { return coll; }
42         private:
43                 virtual void finish();
44                 void appearance(const std::string &);
45                 void part();
46                 void state_bits(unsigned);
47         };
48
49 private:
50         const TrackAppearance *appearance;
51         std::vector<TrackPart> parts;
52         std::vector<Endpoint> endpoints;
53         unsigned state_bits;
54         unsigned autofit_preference;
55         std::string object;
56
57 public:
58         TrackType();
59
60         const TrackAppearance &get_appearance() const;
61         float get_gauge() const;
62         float get_total_length() const;
63         float get_path_length(int) const;
64         unsigned get_paths() const;
65         unsigned get_n_paths() const;
66         unsigned coerce_path(unsigned, unsigned) const;
67         unsigned get_state_bits() const { return state_bits; }
68         bool is_turnout() const;
69         bool is_dead_end() const;
70         unsigned get_autofit_preference() const { return autofit_preference; }
71         const std::string &get_object() const { return object; }
72         const std::vector<TrackPart> &get_parts() const { return parts; }
73         const std::vector<Endpoint> &get_endpoints() const { return endpoints; }
74         const Endpoint &get_endpoint(unsigned) const;
75         OrientedPoint get_point(unsigned, unsigned, float) const;
76         OrientedPoint get_nearest_point(const Vector &) const;
77
78 private:
79         void collect_endpoints();
80 };
81
82 } // namespace R2C2
83
84 #endif