]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/signal.h
67aa77ee73a0bfa758c26edf7d6a144ffde0d590
[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 "blockiter.h"
7 #include "geometry.h"
8 #include "signaltype.h"
9 #include "trackattachment.h"
10
11 namespace R2C2 {
12
13 class Layout;
14 class Train;
15
16 class Signal: public TrackAttachment
17 {
18 public:
19         class Loader: public Msp::DataFile::ObjectLoader<Signal>
20         {
21         public:
22                 Loader(Signal &);
23
24         private:
25                 void address(unsigned);
26                 void position(float, float, float);
27                 void rotation(float);
28         };
29
30 private:
31         const SignalType &type;
32         unsigned address;
33         BlockIter block;
34         Train *train;
35         sigc::connection train_conn;
36         bool check_allocated_blocks;
37         bool passing;
38
39 public:
40         Signal(Layout &, const SignalType &);
41         ~Signal();
42
43         virtual Signal *clone(Layout * = 0) const;
44         virtual const SignalType &get_type() const { return type; }
45
46         void set_address(unsigned);
47         unsigned get_address() const { return address; }
48         virtual void set_position(const Vector &);
49         virtual void set_rotation(const Angle &);
50         virtual void set_tilt(const Angle &) { }
51 private:
52         void update_attachment();
53 public:
54
55         virtual unsigned get_n_snap_nodes() const;
56         virtual Snap get_snap_node(unsigned) const;
57 private:
58         virtual SnapType get_default_snap_type_to(const Object &) const;
59
60 public:
61         void tick(const Msp::Time::TimeDelta &);
62
63 private:
64         void block_reserved(const Block &, Train *);
65         void train_advanced(Block &);
66         void reset();
67
68 public:
69         void save(std::list<Msp::DataFile::Statement> &) const;
70 };
71 } // namespace R2C2
72
73
74 #endif