-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignalindicator.hxx
137 lines (124 loc) · 6.4 KB
/
signalindicator.hxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#ifndef SignalIndicator_HXX
#define SignalIndicator_HXX
#include "signal.hxx"
#include "blocksection.hxx"
#include "scaling.hxx"
#include <QMap>
#include <QSvgWidget>
#include <QDebug>
#include <QGuiApplication>
#include <QScreen>
namespace EWRB
{
class SignalMapIndicator
{
private:
QMap<EWRB::SignalState, QSvgWidget*> _svgs;
int _position[2] = {0, 0};
QMap<EWRB::SignalState, BlockSection*> _entry_blocks;
QWidget* _parent = nullptr;
public:
SignalMapIndicator(QWidget* parent, BlockSection* valid_block, double angle=90) :
_parent(parent)
{
const Scaler* scaler_ = new Scaler;
_entry_blocks[EWRB::SignalState::Off] = valid_block;
_svgs[EWRB::SignalState::Off] = new QSvgWidget(":/svgs/svgs/AT2_Clear_"+QString::number(angle).replace(".","_")+".svg", _parent);
_svgs[EWRB::SignalState::Off]->setFixedSize(scaler_->scale_width(20), scaler_->scale_height(20));
_svgs[EWRB::SignalState::Off]->hide();
_svgs[EWRB::SignalState::On] = new QSvgWidget(":/svgs/svgs/AT2_Stop_"+QString::number(angle).replace(".","_")+".svg", _parent);
_svgs[EWRB::SignalState::On]->setFixedSize(scaler_->scale_width(20), scaler_->scale_height(20));
}
void PlaceAt(const int& x, const int& y);
void setSVG(EWRB::SignalState state, QString image, int w, int h)
{
if(_svgs.keys().contains(state)) delete _svgs[state];
_svgs[state] = new QSvgWidget(image, _parent);
_svgs[state]->setFixedSize(w, h);
if(state != EWRB::SignalState::On) _svgs[state]->hide();
}
void addValidBlocks(EWRB::SignalState state, BlockSection* block)
{
_entry_blocks[state] = block;
}
void update();
Signal* getMirroredSignal() const {return _entry_blocks[EWRB::SignalState::Off]->getBlockSignal();}
};
class ShuntMapIndicator : public SignalMapIndicator
{
public:
ShuntMapIndicator(QWidget* parent, BlockSection* valid_block, double angle=90) :
SignalMapIndicator(parent, valid_block, angle)
{
const Scaler* scaler_ = new Scaler;
setSVG(EWRB::SignalState::Off, ":/svgs/svgs/Disc_Clear_"+QString::number(angle).replace(".","_")+".svg", scaler_->scale_width(10), scaler_->scale_height(10));
setSVG(EWRB::SignalState::On, ":/svgs/svgs/Disc_Stop_"+QString::number(angle).replace(".","_")+".svg", scaler_->scale_width(10), scaler_->scale_height(10));
}
};
class EWREastSignalIndicator : public SignalMapIndicator
{
public:
EWREastSignalIndicator(QWidget* parent, QList<BlockSection*> valid_blocks) :
SignalMapIndicator(parent, valid_blocks[0])
{
const Scaler* scaler_ = new Scaler;
setSVG(EWRB::SignalState::Off, ":/svgs/svgs/AT2EWEast_Clear_90.svg", scaler_->scale_width(30), scaler_->scale_height(20));
setSVG(EWRB::SignalState::On, ":/svgs/svgs/AT2EWEast_Stop_90.svg", scaler_->scale_width(30), scaler_->scale_height(20));
setSVG(EWRB::SignalState::OffJctLeft, ":/svgs/svgs/AT2EWEast_JctLeft_90.svg", scaler_->scale_width(30), scaler_->scale_height(20));
addValidBlocks(EWRB::SignalState::OffJctLeft, valid_blocks[1]);
}
};
class EWRWestSignalIndicator : public SignalMapIndicator
{
public:
EWRWestSignalIndicator(QWidget* parent, QList<BlockSection*> valid_blocks) :
SignalMapIndicator(parent, valid_blocks[0])
{
const Scaler* scaler_ = new Scaler;
setSVG(EWRB::SignalState::Off, ":/svgs/svgs/AT2EWWest_Clear_270.svg", scaler_->scale_width(30), scaler_->scale_height(20));
setSVG(EWRB::SignalState::On, ":/svgs/svgs/AT2EWWest_Stop_270.svg", scaler_->scale_width(30), scaler_->scale_height(20));
setSVG(EWRB::SignalState::OffJctLeft, ":/svgs/svgs/AT2EWWest_JctLeft_270.svg", scaler_->scale_width(30), scaler_->scale_height(20));
setSVG(EWRB::SignalState::OffJctRight, ":/svgs/svgs/AT2EWWest_JctRight_270.svg", scaler_->scale_width(30), scaler_->scale_height(20));
addValidBlocks(EWRB::SignalState::OffJctLeft, valid_blocks[1]);
addValidBlocks(EWRB::SignalState::OffJctRight, valid_blocks[2]);
}
};
class PraedStJctSignalIndicator : public SignalMapIndicator
{
public:
PraedStJctSignalIndicator(QWidget* parent, QList<BlockSection*> valid_blocks) :
SignalMapIndicator(parent, valid_blocks[0])
{
const Scaler* scaler_ = new Scaler;
setSVG(EWRB::SignalState::Off, ":/svgs/svgs/AT2EWPraedJct_Clear_90.svg", scaler_->scale_width(30), scaler_->scale_height(20));
setSVG(EWRB::SignalState::On, ":/svgs/svgs/AT2EWPraedJct_Stop_90.svg", scaler_->scale_width(30), scaler_->scale_height(20));
setSVG(EWRB::SignalState::OffJctRight, ":/svgs/svgs/AT2EWPraedJct_JctRight_90.svg", scaler_->scale_width(30), scaler_->scale_height(20));
addValidBlocks(EWRB::SignalState::OffJctRight, valid_blocks[1]);
}
};
class SignalPanelIndicator
{
private:
QWidget* _parent = nullptr;
QMap<bool, QSvgWidget*> _svgs;
BlockSection* _entry_block = nullptr;
int _location[2] = {0, 0};
int _id = -1;
public:
SignalPanelIndicator(QWidget* parent, BlockSection* valid_block, const int indicator_id) :
_parent(parent), _entry_block(valid_block), _id(indicator_id)
{
const Scaler* scaler_ = new Scaler;
qDebug() << "Connecting to Block " << valid_block->id() << "\n";
_svgs[false] = new QSvgWidget(QString(":/svgs/svgs/PanelSigIndOff.svg"), _parent);
_svgs[false]->setFixedSize(scaler_->scale_width(20), scaler_->scale_height(20));
_svgs[true] = new QSvgWidget(QString(":/svgs/svgs/PanelSigIndOn.svg"), _parent);
_svgs[true]->setFixedSize(scaler_->scale_width(20), scaler_->scale_height(20));
_svgs[true]->hide();
}
void PlaceAt(const int& x, const int& y);
void update();
int getID() const {return _id;}
};
};
#endif // SignalIndicator_HXX