]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/signal.h
Make use of the geometry part of libmspmath
[r2c2.git] / source / libr2c2 / signal.h
1 #ifndef LIBR2C2_SIGNAL_H_
2 #define LIBR2C2_SIGNAL_H_
3
4 #include <msp/datafile/objectloader.h>
5 #include <msp/time/timedelta.h>
6 #include "geometry.h"
7 #include "object.h"
8 #include "signaltype.h"
9 #include "track.h"
10
11 namespace R2C2 {
12
13 class Block;
14 class Layout;
15 class Train;
16
17 class Signal: public Object
18 {
19 public:
20         class Loader: public Msp::DataFile::ObjectLoader<Signal>
21         {
22         public:
23                 Loader(Signal &);
24
25         private:
26                 void address(unsigned);
27                 void position(float, float, float);
28                 void rotation(float);
29         };
30
31 private:
32         const SignalType &type;
33         unsigned address;
34         Track *track;
35         Block *block;
36         unsigned entry;
37         Train *train;
38         sigc::connection train_conn;
39         bool check_allocated_blocks;
40         bool passing;
41
42 public:
43         Signal(Layout &, const SignalType &);
44         ~Signal();
45
46         virtual Signal *clone(Layout * = 0) const;
47         virtual const SignalType &get_type() const { return type; }
48
49         void set_address(unsigned);
50         virtual void set_position(const Vector &);
51         virtual void set_rotation(const Angle &);
52 private:
53         void normalize_location();
54 public:
55         virtual Track *get_parent() const { return track; }
56
57         virtual unsigned get_n_snap_nodes() const;
58         virtual Snap get_snap_node(unsigned) const;
59 private:
60         virtual SnapType get_default_snap_type_to(const Object &) const;
61
62 public:
63         void tick(const Msp::Time::TimeDelta &);
64
65 private:
66         void block_reserved(const Block &, Train *);
67         void train_advanced(Block &);
68         void reset();
69
70 public:
71         void save(std::list<Msp::DataFile::Statement> &) const;
72 };
73 } // namespace R2C2
74
75
76 #endif