]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/tracktype.h
d13ea28c98354785075e08177ae514b985b92bf5
[r2c2.git] / source / libmarklin / tracktype.h
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2010  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef LIBMARKLIN_TRACKTYPE_H_
9 #define LIBMARKLIN_TRACKTYPE_H_
10
11 #include <msp/datafile/loader.h>
12 #include "articlenumber.h"
13 #include "geometry.h"
14 #include "trackpart.h"
15
16 namespace Marklin {
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         public:
33                 Loader(TrackType &);
34         private:
35                 virtual void finish();
36                 void part();
37                 void position(float, float, float);
38         };
39
40 private:
41         ArticleNumber art_nr;
42         std::string description;
43         std::vector<TrackPart> parts;
44         std::vector<Endpoint> endpoints;
45         bool double_address;
46         unsigned autofit_preference;
47
48 public:
49         TrackType(const ArticleNumber &);
50
51         const ArticleNumber &get_article_number() const { return art_nr; }
52         const std::string &get_description() const { return description; }
53         float get_total_length() const;
54         float get_path_length(int) const;
55         unsigned get_paths() const;
56         unsigned get_n_paths() const;
57         bool is_turnout() const;
58         bool is_dead_end() const;
59         bool is_double_address() const { return double_address; }
60         unsigned get_autofit_preference() const { return autofit_preference; }
61         const std::vector<TrackPart> &get_parts() const { return parts; }
62         const std::vector<Endpoint> &get_endpoints() const { return endpoints; }
63         const Endpoint &get_endpoint(unsigned) const;
64         TrackPoint get_point(unsigned, unsigned, float) const;
65
66 private:
67         void collect_endpoints();
68 };
69
70 } // namespace Marklin
71
72 #endif