-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWSignal.cpp
548 lines (524 loc) · 24 KB
/
WSignal.cpp
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
/*
* shunt signal [- WSIGNAL.CXX -]
**************************************************************************
*/
#include "WSignal.h"
#include <QDebug>
#include <QMenu>
void WSignal::setV_id( int name ){
QString suffix = QString::number( name ); //name convert to QString
if( name >0 && name <1000){
if( name < 10 ){
v_id = "W00" + suffix;
}
if( name < 100 && name > 9){
v_id = "W0" + suffix;
}
if( name < 1000 && name > 99){
v_id = "W" + suffix;
}
}
else qWarning()<<"__WSignal__: Falsche Benennung. Die Zahl muss dreistellig sein.";
}
void WSignal::setFahrt( WSignal *toZiel ){
//
//different bools to check, if route can be set
bool blockfreigabe = true; //locked would be false-->search as long as there are unlocked segments
bool blockkontrolle = true; //occupied would be false-->search as long as there are unoccupied segments
bool weichenverr = false; //locked would be true-->search as long as there are unlocked turnouts
bool weichenkontrolle = true; //occupied would be false-->search as long as there are unoccupied turnouts
if( getV_id().compare(toZiel->getV_id() ) != 0 && isNachbar(toZiel) ){ //prüfe, ob Zielsignal Nachbar ist und ob Zielsignal nicht das selbe Signal ist wie das Startsignal
//::::Blockstatus ==========================
for( int i = 0 ; i < block.size() ; i++ ){ //loop over segments
if( block.at(i).first.compare( toZiel->getV_id() ) == 0 ){
for( int j = 0 ; j < block.at(i).second.size() ; j++ ){
if( !block.at(i).second.at(j)->getB_status() ){ //look at occupied segments [if occupied]
blockkontrolle = false; //change flag to false
break;
}
if( !block.at(i).second.at(j)->getFreigabe() ){ //look at locked segments[if locked]
blockfreigabe = false; //change flag to false
break;
}
//
//loop finished and permission is possible
}
}
}
//::::Weichenstatus ========================
for( int k = 0 ; k < weichenstatus.size() ; k++ ){ //loop over turnouts
if( weichenstatus.at(k).first.compare( toZiel->getV_id() ) == 0 ){
for( int l = 0 ; l < weichenstatus.at(k).second.size() ; l++ ){
if( !weichenstatus.at(k).second.at(l).first->getBelegung() ){ //look at turnout occupation [if occupied]
weichenkontrolle = false; //change flag to false
break;
}
//if( weichenstatus.at(k).second.at(l).first->getVerriegelung() ){//look at turnout lock status[if locked = true]
// weichenverr = true; //change flag to true
//break;
//}// deprecated: hardware issue
}
//
//after the whole loop is finished, possibile permission exists
}
}
//::::Erlaubnisabgleich =======================
bool blockgeschichte = false; //complete permission segments?
bool weichengeschichte = false; //complete permission turnouts?
blockgeschichte = blockkontrolle && blockfreigabe;
weichengeschichte = weichenkontrolle && !weichenverr;
//::::Das eigentliche Stellen =================
if( blockgeschichte && weichengeschichte ){ //permission granted
//BLOCK
for( int m = 0 ; m < block.size() ; m++ ){ //loop over segments
if( block.at(m).first.compare( toZiel->getV_id() ) == 0 ){
for( int n = 0 ; n < block.at(m).second.size() ; n++ ){
block.at(m).second.at(n)->setFreigabe( false ); //lock segments
//
//no every segment in the route is locked
}
}
}
//WEICHEN
for( int o = 0 ; o < weichenstatus.size() ; o++ ){ //loop over turnouts
if( weichenstatus.at(o).first.compare( toZiel->getV_id() ) == 0 ){
for( int p = 0 ; p < weichenstatus.at(o).second.size() ; p++ ){
weichenstatus.at(o).second.at(p).first->setW_status(weichenstatus.at(o).second.at(p).second); //change turnouts to the needed direction
//weichenstatus.at(o).second.at(p).first->setVerriegelung( true ); //lock turnouts // deprecated: hardware issue
}
//
//every turnout is locked now
}
}
//WSIGNAL change shunt signal to "go"
setZiel( toZiel->getV_id() );
v_status = true;
hasWSZiel = true;
changeColor();
emit refreshStellwerkstechnikW(getV_id(), true);
//////
}
}
}
void WSignal::setFahrt(QString toZiel) // WS to HS
{
//different bools to check permission for route
bool blockfreigabe = true; //locked would be false-->search as long as there are unlocked segments
bool blockkontrolle = true; //occupied would be false-->search as long as there are unoccupied segments
bool weichenverr = false; //locked would be true-->search as long as there are unlocked turnouts
bool weichenkontrolle = true; //occupied would be false-->search as long as there are unoccupied turnouts
if( getV_id().compare(toZiel ) != 0 && isNachbar(toZiel) ){ //is signal neighbour
//::::Blockstatus ==========================
for( int i = 0 ; i < blockZuH.size() ; i++ ){ //loop over segments
if( blockZuH.at(i).first.compare( toZiel ) == 0 ){
for( int j = 0 ; j < blockZuH.at(i).second.size() ; j++ ){
if( !blockZuH.at(i).second.at(j)->getB_status() ){ //look at occupied segments [if occupied]
blockkontrolle = false; //change flag to false
break;
}
if( !blockZuH.at(i).second.at(j)->getFreigabe() ){ //look at the occupation status [if occupied]
blockfreigabe = false; //change flag to false
break;
}
//
//whole loop is finished, blockfreigabe und blockkontrolle auf = true -->possible permission
}
}
}
//::::Weichenstatus ========================
for( int k = 0 ; k < weichenstatusZuH.size() ; k++ ){ //loop over turnouts
if( weichenstatusZuH.at(k).first.compare( toZiel ) == 0 ){
for( int l = 0 ; l < weichenstatusZuH.at(k).second.size() ; l++ ){
if( !weichenstatusZuH.at(k).second.at(l).first->getBelegung() ){ //look at occupation status turnouts [if occupied]
weichenkontrolle = false; //change flag to
break;
}
//if( weichenstatusZuH.at(k).second.at(l).first->getVerriegelung() ){//look at turnout status [if locked =true]
// weichenverr = true; //change flag to true
// break;
//}//deprecated: hardware issue
}
//
//loop finished now possible route permission
}
}
//::::summarize permission =======================
bool blockgeschichte = false; //complete segment permission?
bool weichengeschichte = false; //complete turnout permission?
blockgeschichte = blockkontrolle && blockfreigabe;
weichengeschichte = weichenkontrolle && !weichenverr;
//::::Das eigentliche Stellen =================
if( blockgeschichte && weichengeschichte ){ //permission granted
//BLOCK
for( int m = 0 ; m < blockZuH.size() ; m++ ){ //loop over segments
if( blockZuH.at(m).first.compare( toZiel ) == 0 ){
for( int n = 0 ; n < blockZuH.at(m).second.size() ; n++ ){
blockZuH.at(m).second.at(n)->setFreigabe( false ); //lock segments
//
//every segment in the route is now locked
}
}
}
//WEICHEN
for( int o = 0 ; o < weichenstatusZuH.size() ; o++ ){ //loop over turnouts
if( weichenstatusZuH.at(o).first.compare( toZiel ) == 0 ){
for( int p = 0 ; p < weichenstatusZuH.at(o).second.size() ; p++ ){
weichenstatusZuH.at(o).second.at(p).first->setW_status(weichenstatusZuH.at(o).second.at(p).second);//change turnouts according to the route needs
//weichenstatusZuH.at(o).second.at(p).first->setVerriegelung( true );//lock turnouts //deprecated: hardware issue
}
//
//turnouts now locked
}
}
//WSIGNAL change shunt signal status to "go"
v_status = true;
setZiel(toZiel);
hasHSZiel = true;
changeColor();
emit refreshStellwerkstechnikW(getV_id(),true);
//////
}
}
}
void WSignal::deleteFS(){
//
//different bools to check, if route can be deleted
bool blockfreigabe = false; //unlocked would be true-->search as long as there are locked segments
bool blockkontrolle = true; //occupied would be 1false-->search as long as there are unoccupied segments
bool weichenverr = true; //unlocked would be false-->search as long as there are locked turnouts
bool weichenkontrolle = true; //occupied would be false-->search as long as there are unoccupied turnouts
//differentiation between delete FS for routes WS->WS or WS->HS
//##########################################################################
if(hasWSZiel){
//::::Blockgeschichte ==========================
for( int i = 0 ; i < block.size() ; i++ ){ //loop over segments
if( block.at(i).first.compare( getZiel() ) == 0 ){
for( int j = 0 ; j < block.at(i).second.size() ; j++ ){
if( !block.at(i).second.at(j)->getB_status() ){ // look at segment occupation [if occupied]
blockkontrolle = false; //change flag to false
break;
}
if( block.at(i).second.at(j)->getFreigabe() ){ //look segment status[if unlocked]
blockfreigabe = true; //change flag to true
break;
}
//
//finsihed loop, possible permission
}
}
}
//::::Weichengeschichte ========================
for( int k = 0 ; k < weichenstatus.size() ; k++ ){ //loop over turnouts
if( weichenstatus.at(k).first.compare( getZiel() ) == 0 ){
for( int l = 0 ; l < weichenstatus.at(k).second.size() ; l++ ){
if( !weichenstatus.at(k).second.at(l).first->getBelegung() ){ //look at occupation status [if occupied]
weichenkontrolle = false; //change flag to false
break;
}
//if( !weichenstatus.at(k).second.at(l).first->getVerriegelung() ){ //look betrachte Verriegelung [falls entriegelt = false]
// weichenverr = false; //change flag to false
// break;
//}// deprecated: hardware issue
}
//
//complete loop finshed and possible permission
}
}
//:::summarize permissions to delete route ============
bool blockgeschichte = false; //complete segment permission?
bool weichengeschichte = false; //complete turnout permission?
blockgeschichte = blockkontrolle && !blockfreigabe;
weichengeschichte = weichenkontrolle && weichenverr;
//:::Das eigentliche Löschen ===========
if( blockgeschichte && weichengeschichte ){ //permission granted
//BLOCK
for( int m = 0 ; m < block.size() ; m++ ){ //loop over segments
if( block.at(m).first.compare( getZiel() ) == 0 ){
for( int n = 0 ; n < block.at(m).second.size() ; n++ ){
block.at(m).second.at(n)->setFreigabe( true ); //unlock segments
//
//now segments are unlocked
}
}
}
//WEICHEN
//for( int o = 0 ; o < weichenstatus.size() ; o++ ){ //loop over turnouts
// if( weichenstatus.at(o).first.compare( getZiel() ) == 0 ){
// for( int p = 0 ; p < weichenstatus.at(o).second.size() ; p++ ){
// weichenstatus.at(o).second.at(p).first->setVerriegelung( false ); //unlock turnouts
// }
//
//at the end of the loop: turnouts unlocked
//}
//}//...deprecated: hardware issue
//WSIGNAL status changed to "stop"
//end signal is not up to date now
v_status = false;
hasWSZiel = false;
changeColor();
emit refreshStellwerkstechnikW(getV_id(), false);
//////
}
}
if(hasHSZiel){
//::::Blockstatus ==========================
for( int i = 0 ; i < blockZuH.size() ; i++ ){ //loop over segments
if( blockZuH.at(i).first.compare( getZiel() ) == 0 ){
for( int j = 0 ; j < blockZuH.at(i).second.size() ; j++ ){
if( !blockZuH.at(i).second.at(j)->getB_status() ){ //look at segment occupation status [if unoccupied]
blockkontrolle = false; //change flag to false
break;
}
if( blockZuH.at(i).second.at(j)->getFreigabe() ){ //look at segment status [if unlocked]
blockfreigabe = true; //change flag to true
break;
}
//complete loop finished, possible permission
}
}
}
//::::Weichenstatus ========================
for( int k = 0 ; k < weichenstatusZuH.size() ; k++ ){ //loop over turnouts
if( weichenstatusZuH.at(k).first.compare( getZiel() ) == 0 ){
for( int l = 0 ; l < weichenstatusZuH.at(k).second.size() ; l++ ){
if( !weichenstatusZuH.at(k).second.at(l).first->getBelegung() ){ //look at all turnout occupation [if occupied]
weichenkontrolle = false; //change flag to false
break;
}
//if( !weichenstatusZuH.at(k).second.at(l).first->getVerriegelung() ){ //look at lock status [if unlocked = false]
// weichenverr = false; //change flag to false
// break;
//}//deprecated: hardware issue
}
//all turnouts unlocked and permission is possible
}
}
//:::summarize permission ============
bool blockgeschichte = false; //complete permission segments
bool weichengeschichte = false; //complete permission turnouts
blockgeschichte = blockkontrolle && !blockfreigabe;
weichengeschichte = weichenkontrolle && weichenverr;
//:::deleting now... ===========
if( blockgeschichte && weichengeschichte ){ //permission to delete granted
//BLOCK
for( int m = 0 ; m < blockZuH.size() ; m++ ){ //loop over segments
if( blockZuH.at(m).first.compare( getZiel() ) == 0 ){
for( int n = 0 ; n < blockZuH.at(m).second.size() ; n++ ){
blockZuH.at(m).second.at(n)->setFreigabe( true ); //unlock segments
//
//all segments are now unlocked
}
}
//Die Schleife für die Namensuche läuft noch fertig
}
//WEICHEN
//for( int o = 0 ; o < weichenstatusZuH.size() ; o++ ){ //loop over turnouts
// if( weichenstatusZuH.at(o).first.compare( getZiel() ) == 0 ){
// for( int p = 0 ; p < weichenstatusZuH.at(o).second.size() ; p++ ){
// weichenstatusZuH.at(o).second.at(p).first->setVerriegelung( false ); //unlocking turnouts
// }
//
//all turnouts are now unlocked
//}
//}//...deprecated: hardware issue
//WSIGNAL- change status to "stop"
//end signal is not up to date now
v_status = false;
hasWSZiel = false;
changeColor();
emit refreshStellwerkstechnikW(getV_id(), false);
//////
}
}
}
void WSignal::addWeichenstatus( WSignal *toZiel , QList<QPair<Weiche* , bool>> weichenpair ){
QPair<QString, QList<QPair<Weiche* , bool>> > hilfspair( toZiel->getV_id() , weichenpair );
weichenstatus.push_back(hilfspair);
}
void WSignal::addWeichenstatusZuH( QString toZiel , QList<QPair<Weiche* , bool>> weichenpair ){
QPair<QString, QList<QPair<Weiche* , bool>> > hilfspair( toZiel , weichenpair );
weichenstatusZuH.push_back(hilfspair);
}
void WSignal::showWeichenstatusALL(){
QString message = "************************************************************\n";
qInfo()<<"************************************************************";
qInfo()<<"*** Dies ist der Weichenstatus für Rangiersignal"<<getV_id()<<" ***";
message += " Dies ist der Weichenstatus für Rangiersignal" + getV_id() + "\n";
for( int i = 0 ; i < weichenstatus.size() ; i++){
qInfo()<<"*** "<<weichenstatus.at(i).first<<" : ***";
message += " " + weichenstatus.at(i).first + "\n";
for( int j = 0 ; j < weichenstatus.at(i).second.size() ; j++ ){
qInfo()<<"*** "<<weichenstatus.at(i).second.at(j).first->getW_id()<<" --> "<<weichenstatus.at(i).second.at(j).second<<" ***";
message += " " + weichenstatus.at(i).second.at(j).first->getW_id() + " --> " + QString::number(weichenstatus.at(i).second.at(j).second) + "\n";
}
}
qInfo()<<"************************************************************";
message += "************************************************************\n";
qInfo()<<"";
this->showBox->setText(message);
this->showBox->open();
}
void WSignal::showWeichenstatus( WSignal *whichZiel ){
for( int i = 0 ; i < weichenstatus.size() ; i++){
if( weichenstatus.at(i).first.compare( whichZiel->getV_id() ) == 0 ){
qInfo()<<"";
qInfo()<<"************************************************************";
qInfo()<<"*** Dies ist der Weichenstatus für Rangiersignal"<<getV_id()<<" ***";
qInfo()<<"*** "<<weichenstatus.at(i).first<<" : ***";
for( int j = 0 ; j < weichenstatus.at(i).second.size() ; j++ ){
qInfo()<<"*** "<<weichenstatus.at(i).second.at(j).first->getW_id()<<" --> "<<weichenstatus.at(i).second.at(j).second<<" ***";
}
qInfo()<<"************************************************************";
qInfo()<<"";
}
}
}
void WSignal::addBlock( WSignal *toZiel , QList<Block*> inputBlock ){
QPair<QString , QList<Block*>> hilfspair(toZiel->getV_id(), inputBlock);
block.push_back(hilfspair);
}
void WSignal::addBlockZuH(QString toZiel, QList<Block *> inputBlock)
{
QPair<QString , QList<Block*>> hilfspair(toZiel, inputBlock);
blockZuH.push_back(hilfspair);
}
void WSignal::showBlock( WSignal *whichZiel ){
for( int i = 0 ; i < block.size() ; i++){
if( block.at(i).first.compare( whichZiel->getV_id() ) == 0){
qInfo()<<"";
qInfo()<<"************************************************************";
qInfo()<<"*** Dies sind die Blöcke für Hauptsignal "<<getV_id()<<" ***";
qInfo()<<"*** "<<block.at(i).first<<" : ***";
for( int j = 0 ; j < block.at(i).second.size() ; j++ ){//hier sind die Blöcke
qInfo()<<"*** "<<block.at(i).second.at(j)->getName()<<" ***";
}
qInfo()<<"************************************************************";
qInfo()<<"";
}
}
}
void WSignal::showBlockALL(){
QString message = "************************************************************\n";
message += " Dies sind die Blöcke für Hauptsignal "+ getV_id() + "\n";
qInfo()<<"************************************************************";
qInfo()<<"*** Dies sind die Blöcke für Hauptsignal "<<getV_id()<<" ***";
for( int i = 0 ; i < block.size() ; i++){
message += " " + block.at(i).first + "\n";
qInfo()<<"*** "<<block.at(i).first<<" : ***";
for( int j = 0 ; j < block.at(i).second.size() ; j++ ){
message += " " + block.at(i).second.at(j)->getName() + "\n";
qInfo()<<"*** "<<block.at(i).second.at(j)->getName()<<" ***";
}
}
message += "************************************************************\n";
qInfo()<<"************************************************************";
qInfo()<<"";
this->showBox->setText(message);
this->showBox->open();
}
bool WSignal::isNachbar(WSignal *toZiel){
bool giveback = false;
for( int i = 0; i < block.size(); i++){
if(block.at(i).first.compare( toZiel->getV_id() ) == 0){
giveback = true;
}
}
return giveback;
}
bool WSignal::isNachbar(QString toZiel){
bool giveback = false;
if(!blockZuH.isEmpty()){
for( int i = 0; i < blockZuH.size(); i++){
if(blockZuH.at(i).first.compare( toZiel ) == 0){
giveback = true;
}
}
}
else giveback = true; //it is empty, but this can happen (Schattenbahnhof)
return giveback;
}
void WSignal::deleteNachbar( WSignal *todelete ){
//
//delete means: in weichenstatus and blockstatus
//Weichenstatus:
int remember = -1;
for( int i = 0 ; i < weichenstatus.size() ; i++ ){
if( weichenstatus.at(i).first.compare( todelete->getV_id() ) == 0 ){//found
remember = i;
}
}
if( remember >= 0 ){ //only when the to delete signal is existent
weichenstatus.erase( weichenstatus.begin() + remember ); //delete i-th position
}
remember = -1;
//Block:
for( int j = 0 ; j < block.size() ; j++ ){
if( block.at(j).first.compare( todelete->getV_id() ) == 0 ){//found
remember = j;
}
}
if(remember >= 0 ){
block.erase( block.begin() + remember); //delete i-th position
}
}
void WSignal::addButtonAndLabel(QLabel *lab, WSignalQPushButton *but){
//Label
beschriftung = lab;
QString qname = v_id;
beschriftung->setText(qname);
QFont f( "Arial", 10, QFont::Bold);
beschriftung->setFont(f);
//and PushButton
push = but;
but->setFixedHeight(20);
but->setFixedWidth(20);
but->setStyleSheet("background-color: blue");
QObject::connect(push,&WSignalQPushButton::clicked,this,&WSignal::listenToFS);
QObject::connect(push,&WSignalQPushButton::rightClicked,this,&WSignal::showShowContexts);
QObject::connect(push->sato,&QAction::triggered,this,&WSignal::showWeichenstatusALL);
QObject::connect(push->sas,&QAction::triggered,this,&WSignal::showBlockALL);
}
void WSignal::listenToFS(){
//
//connected to clickmanager
emit listened(this);
}
void WSignal::zugpassiertW(QString addressedSignal){
if(this->getV_id() == addressedSignal){
v_status = false;
hasWSZiel = false;
hasHSZiel = false;
changeColor();
emit refreshStellwerkstechnikW(getV_id(),false);
}
}
void WSignal::changeColor(){
//possible groups basic_sh0, basic_sh1, minimialistic_sh0, minimalistic_sh1
QString mode = svgItem->objectName().split("_").at(0);
if(v_status){
svgItem->setElementId(mode + "_sh1");
svgItem->setObjectName(mode + "_sh1");
}
if(!v_status){
svgItem->setElementId(mode + "_sh0");
svgItem->setObjectName(mode + "_sh0");
}
}
void WSignal::setZiel(QString zziel){
if(zziel.at(0) == 'S'){ //HS
hasHSZiel = true;
ziel = zziel;
}
if(zziel.at(0) == 'W'){ //WS
hasWSZiel = true;
ziel = zziel;
}
}
void WSignal::showShowContexts(){
this->push->getMenu()->popup(QCursor::pos());
this->push->raise();
}
WSignal::~WSignal(){
delete beschriftung;
delete push;
}