]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/tracktype.h
Add a feature to autofit straight runs of track
[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 "geometry.h"
13 #include "trackpart.h"
14
15 namespace Marklin {
16
17 class TrackType
18 {
19 public:
20         struct Endpoint
21         {
22                 Point pos;
23                 float dir;  // Direction outwards from the endpoint
24                 unsigned paths;
25
26                 Endpoint(float, float, float, unsigned);
27         };
28
29         class Loader: public Msp::DataFile::BasicLoader<TrackType>
30         {
31         public:
32                 Loader(TrackType &);
33         private:
34                 virtual void finish();
35                 void part();
36                 void position(float, float, float);
37         };
38
39 private:
40         unsigned art_nr;
41         std::string description;
42         std::vector<TrackPart> parts;
43         std::vector<Endpoint> endpoints;
44         bool double_address;
45         unsigned autofit_preference;
46
47 public:
48         TrackType(unsigned);
49
50         unsigned get_article_number() const { return art_nr; }
51         const std::string &get_description() const { return description; }
52         float get_total_length() const;
53         float get_path_length(int) const;
54         unsigned get_paths() const;
55         unsigned get_n_paths() const;
56         bool is_turnout() const;
57         bool is_dead_end() const;
58         bool is_double_address() const { return double_address; }
59         unsigned get_autofit_preference() const { return autofit_preference; }
60         const std::vector<TrackPart> &get_parts() const { return parts; }
61         const std::vector<Endpoint> &get_endpoints() const { return endpoints; }
62         TrackPoint get_point(unsigned, unsigned, float) const;
63
64 private:
65         void collect_endpoints();
66 };
67
68 } // namespace Marklin
69
70 #endif