From f354bb05056af84e071384422acee37ba78528ed Mon Sep 17 00:00:00 2001 From: Abby Date: Sat, 30 Mar 2024 15:03:25 -0400 Subject: [PATCH 01/19] Small edits to block occupancies --- CTC/CTC_UI.py | 9 +++++---- CTC/OccupiedBlocks.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CTC/CTC_UI.py b/CTC/CTC_UI.py index 6ed2a976..ebc17b08 100644 --- a/CTC/CTC_UI.py +++ b/CTC/CTC_UI.py @@ -368,11 +368,12 @@ def updateOccupiedBlocks(self, arr): self.occupiedBlocks.BlockDataNew = [] #Adding TrainID, Block ID, and line color to an array - for i in arr: - TrainID = self.occupiedBlocks.matchOccupanciesToTrains(i[0], i[1]) - self.occupiedBlocks.BlockDataNew.append([TrainID, i[0], i[1]]) + for block in arr: + TrainID = self.occupiedBlocks.matchOccupanciesToTrains(block[0], block[1]) + self.occupiedBlocks.BlockDataNew.append([TrainID, block[0], block[1]]) + if TrainID != 'X': - self.occupiedBlocks.currentTrains[int(TrainID[1:]) - 1].append(i[0]) + self.occupiedBlocks.currentTrains[int(TrainID[1:]) - 1].append(block[0]) #print(self.occupiedBlocks.currentTrains) diff --git a/CTC/OccupiedBlocks.py b/CTC/OccupiedBlocks.py index 176509b0..151c9720 100644 --- a/CTC/OccupiedBlocks.py +++ b/CTC/OccupiedBlocks.py @@ -44,7 +44,7 @@ def matchOccupanciesToTrains(self, BlockID, line): for i in self.currentTrains: if i[1] == 'K63': return i[0] - elif (line == 'green') and (BlockNum > 63) and (BlockNum < 76): + elif (line == 'green') and (BlockNum > 63) and (BlockNum < 100): for i in self.currentTrains: if int(i[1][1:]) == (BlockNum - 1): #Update Train Movement From 9cf2c4dfa1c7ec3cb406ecafc49a614d9cf8b531 Mon Sep 17 00:00:00 2001 From: Abby Date: Sat, 30 Mar 2024 15:07:02 -0400 Subject: [PATCH 02/19] Fixing CTC to Wayside HW signals --- MainSimulation.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/MainSimulation.py b/MainSimulation.py index 66b40295..dc9fb97b 100644 --- a/MainSimulation.py +++ b/MainSimulation.py @@ -76,9 +76,13 @@ def pauseSim(): MainWindow.CTC_tb.sendTicketSales.connect(MainWindow.CTCwindow.updateTicketSales) MainWindow.CTCwindow.sendDispatchInfo.connect(MainWindow.CTC_tb.showDispatchInfo) -#CTC to Wayside +#CTC to Wayside SW MainWindow.CTCwindow.sendDispatchInfo.connect(MainWindow.WaysideSWwindow.receiveSpeedAuth) +#CTC to Wayside HW +MainWindow.CTCwindow.sendBlockClosures.connect(MainWindow.WaysideHWwindow.getClosedBlocks) +MainWindow.CTCwindow.sendDispatchInfo.connect(MainWindow.WaysideHWwindow.handleSpeedAuthority) + #CTC to MainWindow MainWindow.CTCwindow.create_a_train.connect(MainWindow.create_new_train) From 14e00cd933f97f51769eeb8f626e3d6fb5b22cc3 Mon Sep 17 00:00:00 2001 From: Abby Date: Sat, 30 Mar 2024 17:35:17 -0400 Subject: [PATCH 03/19] CTC occupied blocks update on tracking trains --- .gitignore | 1 + CTC/CTC_Testbench.py | 2 +- CTC/CTC_UI.py | 27 ++++++++++++--------------- CTC/OccupiedBlocks.py | 37 ++++++++++++++++++++++++------------- 4 files changed, 38 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index 9601a39a..401851d6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +__pycache__/ __pycache__/Main_UI.cpython-312.pyc CTC/__pycache__/CTC_Maintenance.cpython-312.pyc CTC/__pycache__/CTC_Testbench.cpython-312.pyc diff --git a/CTC/CTC_Testbench.py b/CTC/CTC_Testbench.py index c76304c6..65e85c84 100644 --- a/CTC/CTC_Testbench.py +++ b/CTC/CTC_Testbench.py @@ -42,7 +42,7 @@ def updateBlocks_button(self): for i in range(len(UpdatedBlocks)): temp = [] temp.append(UpdatedBlocks[i]) - temp.append('green') + temp.append('Green') BlocksWithLineColor.append(temp) self.sendOccupiedBlocks.emit(BlocksWithLineColor) diff --git a/CTC/CTC_UI.py b/CTC/CTC_UI.py index ebc17b08..387a53ca 100644 --- a/CTC/CTC_UI.py +++ b/CTC/CTC_UI.py @@ -210,7 +210,6 @@ def addTrain_button(self): #Calculatig the Departure Station and time Departure = [] - print(type(ArrivalTime)) self.trainSchedule.calculateDeparture(Destination, ArrivalTime, Departure) #Adding the train to the schedule @@ -315,9 +314,9 @@ def displayClock(self, time): #Initializing where the train starts if i[0] == 'green': - self.occupiedBlocks.currentTrains.append([i[1], 'K63']) + self.occupiedBlocks.currentTrains.append(['K63']) elif i[0] == 'red': - self.occupiedBlocks.currentTrains.append([i[1], 'D10']) + self.occupiedBlocks.currentTrains.append(['D10']) #Define functionality for Upload File Button @@ -366,27 +365,25 @@ def exitMaintenanceMode(self): def updateOccupiedBlocks(self, arr): #Clear temp new block layout array self.occupiedBlocks.BlockDataNew = [] + #clear new train matrix, and initialize the correct number of row + self.occupiedBlocks.newTrains = [] + for i in range(len(self.occupiedBlocks.currentTrains)): + self.occupiedBlocks.newTrains.append([]) #Adding TrainID, Block ID, and line color to an array for block in arr: + #Getting train ID TrainID = self.occupiedBlocks.matchOccupanciesToTrains(block[0], block[1]) self.occupiedBlocks.BlockDataNew.append([TrainID, block[0], block[1]]) + #If it's a train, add to updated train list if TrainID != 'X': - self.occupiedBlocks.currentTrains[int(TrainID[1:]) - 1].append(block[0]) - - #print(self.occupiedBlocks.currentTrains) - - """ - for i in self.occupiedBlocks.currentTrains[:]: - for j in i[1:]: - if j not in arr: - print(arr) - i.remove(j) - """ - #print(self.occupiedBlocks.currentTrains) + self.occupiedBlocks.newTrains[int(TrainID[1:]) - 1].append(block[0]) + #update the current variable to be the newly calculated ones + self.occupiedBlocks.currentTrains = self.occupiedBlocks.newTrains self.occupiedBlocks.BlockDataCurrent = self.occupiedBlocks.BlockDataNew + self.OccupiedBlockTable.setModel(BlocksTableModel(self.occupiedBlocks.BlockDataCurrent)) diff --git a/CTC/OccupiedBlocks.py b/CTC/OccupiedBlocks.py index 151c9720..01c46b16 100644 --- a/CTC/OccupiedBlocks.py +++ b/CTC/OccupiedBlocks.py @@ -28,27 +28,38 @@ def __init__(self): #Holds train and block num #Based on current Trains self.currentTrains = [] + self.newTrains = [] def addBlockOccupancy(self, TrainName, BlockNum): newBlockOccupancy = [TrainName, BlockNum] self.BlockDataNew.append(newBlockOccupancy) def matchOccupanciesToTrains(self, BlockID, line): + #Get block number from ID BlockNum = int(BlockID[1:]) - if (BlockNum == 63) and (line == 'green'): - for i in self.currentTrains: - if i[1] == 'K63': - return i[0] - elif (BlockNum == 10) and (line == 'red'): - for i in self.currentTrains: - if i[1] == 'K63': - return i[0] - elif (line == 'green') and (BlockNum > 63) and (BlockNum < 100): - for i in self.currentTrains: - if int(i[1][1:]) == (BlockNum - 1): - #Update Train Movement - return i[0] + #Check to see if the block was occupied already + for i in self.BlockDataCurrent: + if i[1] == BlockID: + return i[0] + + #Begin logic to see if the block is occupied by a train + #Green line train dipatch case + if (BlockNum == 63) and (line == 'Green'): + for i in range(len(self.currentTrains)): + if self.currentTrains[i][0] == 'K63': + return ("T" + str(i+1)) + #Red line train dispatch case + elif (BlockNum == 10) and (line == 'Red'): + for i in range(len(self.currentTrains)): + if self.currentTrains[i][0] == 'D10': + return ("T" + str(i+1)) + elif (line == 'Green') and (BlockNum > 63) and (BlockNum < 100): + for i in range(len(self.currentTrains)): + for j in self.currentTrains[i]: + if int(j[1:]) == (BlockNum - 1): + #Update Train Movement + return ("T" + str(i+1)) return 'X' From 198c50b972108bcf98a7b70950c0bacc424fbdf1 Mon Sep 17 00:00:00 2001 From: Abby Date: Sat, 30 Mar 2024 17:35:47 -0400 Subject: [PATCH 04/19] gitignore test --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 401851d6..279a847f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -__pycache__/ +__pycache__\ __pycache__/Main_UI.cpython-312.pyc CTC/__pycache__/CTC_Maintenance.cpython-312.pyc CTC/__pycache__/CTC_Testbench.cpython-312.pyc From 24065abd4c7e3b5f0378ea3cc28a1765b52a08ad Mon Sep 17 00:00:00 2001 From: Abby Date: Sat, 30 Mar 2024 17:40:50 -0400 Subject: [PATCH 05/19] messing with git ignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 279a847f..9601a39a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -__pycache__\ __pycache__/Main_UI.cpython-312.pyc CTC/__pycache__/CTC_Maintenance.cpython-312.pyc CTC/__pycache__/CTC_Testbench.cpython-312.pyc From fc1be88cc95651056e746619b6f85ebd4aa6642a Mon Sep 17 00:00:00 2001 From: Abby Date: Sat, 30 Mar 2024 19:01:57 -0400 Subject: [PATCH 06/19] Tentative green line occupied blocks train tracking --- CTC/OccupiedBlocks.py | 128 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 114 insertions(+), 14 deletions(-) diff --git a/CTC/OccupiedBlocks.py b/CTC/OccupiedBlocks.py index 01c46b16..0f76f102 100644 --- a/CTC/OccupiedBlocks.py +++ b/CTC/OccupiedBlocks.py @@ -44,26 +44,126 @@ def matchOccupanciesToTrains(self, BlockID, line): return i[0] #Begin logic to see if the block is occupied by a train - #Green line train dipatch case - if (BlockNum == 63) and (line == 'Green'): - for i in range(len(self.currentTrains)): - if self.currentTrains[i][0] == 'K63': + #Green Line + if line == 'Green': + #A-C blocks, train can only come from its previous blocks, but they are in reverse number order + if (BlockNum >= 1) and (BlockNum <= 12): + if self.searchPreviousBlockR(BlockNum): return ("T" + str(i+1)) - #Red line train dispatch case - elif (BlockNum == 10) and (line == 'Red'): - for i in range(len(self.currentTrains)): - if self.currentTrains[i][0] == 'D10': + + #D13 switch block + elif BlockNum == 13: + for i in range(len(self.currentTrains)): + for j in self.currentTrains[i]: + if int(j[1:]) == 1: + return ("T" + str(i+1)) + if int(j[1:]) == 14: + return ("T" + str(i+1)) + + #D,E,F blocks (without the switches), bidirectional + elif (BlockNum >= 14) and (BlockNum <= 27): + if self.searchBothDirections(BlockNum): + return ("T" + str(i+1)) + + #F28 switch block + elif BlockNum == 28: + for i in range(len(self.currentTrains)): + for j in self.currentTrains[i]: + if int(j[1:]) == 27: + return ("T" + str(i+1)) + if int(j[1:]) == 150: + return ("T" + str(i+1)) + + #G-I blocks, train can only come from its previous blocks + elif (BlockNum >= 29) and (BlockNum <= 57): + if self.searchPreviousBlock(BlockNum): return ("T" + str(i+1)) - elif (line == 'Green') and (BlockNum > 63) and (BlockNum < 100): - for i in range(len(self.currentTrains)): - for j in self.currentTrains[i]: - if int(j[1:]) == (BlockNum - 1): - #Update Train Movement + + #J Blocks are the ones we skip near the yard + + #Green line train dipatch case + elif BlockNum == 63: + #for each train + for i in range(len(self.currentTrains)): + #for each block the train occupies + if self.currentTrains[i][0] == 'K63': + #return the current train if conditions are meet return ("T" + str(i+1)) + + #K-M blocks, train can only come from its previous blocks + elif (BlockNum >= 64) and (BlockNum <= 76): + if self.searchPreviousBlock(BlockNum): + return ("T" + str(i+1)) + + #Full n block, bidirectional + elif (BlockNum >= 77) and (BlockNum <= 84): + if self.searchBothDirections(BlockNum): + return ("T" + str(i+1)) + + #n switch on block 85, can come from N84 or Q100 + elif BlockNum == 85: + for i in range(len(self.currentTrains)): + for j in self.currentTrains[i]: + if int(j[1:]) == 84: + return ("T" + str(i+1)) + elif int(j[1:]) == 100: + return ("T" + str(i+1)) + + #O-Q blocks, train can only come from its previous blocks + elif (BlockNum >= 86) and (BlockNum <= 100): + if self.searchPreviousBlock(BlockNum): + return ("T" + str(i+1)) + #R101 block, comes from n track + elif BlockNum == 101: + for i in range(len(self.currentTrains)): + for j in self.currentTrains[i]: + if int(j[1:]) == 77: + return ("T" + str(i+1)) + + #S-Z blocks, train can only come from its previous blocks + elif ((BlockNum >= 102) and (BlockNum <= 150)): + if self.searchPreviousBlock(BlockNum): + return ("T" + str(i+1)) + + #Red Line + if line == "Red": + #Red line train dispatch case + if (BlockNum == 10): + for i in range(len(self.currentTrains)): + if self.currentTrains[i][0] == 'D10': + return ("T" + str(i+1)) + return 'X' - +#Internal function that searches if the current occupancy coresponds to train from a previous block +def searchPreviousBlock(self, BlockNum): + for i in range(len(self.currentTrains)): + for j in self.currentTrains[i]: + if int(j[1:]) == (BlockNum - 1): + return True + + return False + +#Internal function that searches if the current occupancy coresponds to train from a previous block, in reverse order +def searchPreviousBlockR(self, BlockNum): + for i in range(len(self.currentTrains)): + for j in self.currentTrains[i]: + if int(j[1:]) == (BlockNum + 1): + return True + + return False + +#Internal function that searches if the current occupancy coresponds to train from a previous block, iin both direction +def searchBothDirections(self, BlockNum): + for i in range(len(self.currentTrains)): + for j in self.currentTrains[i]: + if int(j[1:]) == (BlockNum - 1): + return True + if int(j[1:]) == (BlockNum + 1): + return True + + return False #Table class to initialize a Pyqt5 table object that will display the list of block occupancies From 4cbfbe85024d7e2d25cbb132fe18b6284e802dd0 Mon Sep 17 00:00:00 2001 From: Abby Date: Sat, 30 Mar 2024 19:25:27 -0400 Subject: [PATCH 07/19] Testing on green line train tracking adjustments --- CTC/OccupiedBlocks.py | 91 +++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 42 deletions(-) diff --git a/CTC/OccupiedBlocks.py b/CTC/OccupiedBlocks.py index 0f76f102..2486b0d0 100644 --- a/CTC/OccupiedBlocks.py +++ b/CTC/OccupiedBlocks.py @@ -48,8 +48,9 @@ def matchOccupanciesToTrains(self, BlockID, line): if line == 'Green': #A-C blocks, train can only come from its previous blocks, but they are in reverse number order if (BlockNum >= 1) and (BlockNum <= 12): - if self.searchPreviousBlockR(BlockNum): - return ("T" + str(i+1)) + ID = self.searchPreviousBlock(BlockNum) + if ID != -1: + return ("T" + str(ID+1)) #D13 switch block elif BlockNum == 13: @@ -62,8 +63,9 @@ def matchOccupanciesToTrains(self, BlockID, line): #D,E,F blocks (without the switches), bidirectional elif (BlockNum >= 14) and (BlockNum <= 27): - if self.searchBothDirections(BlockNum): - return ("T" + str(i+1)) + ID = self.searchBothDirections(BlockNum) + if ID != -1: + return ("T" + str(ID+1)) #F28 switch block elif BlockNum == 28: @@ -76,8 +78,9 @@ def matchOccupanciesToTrains(self, BlockID, line): #G-I blocks, train can only come from its previous blocks elif (BlockNum >= 29) and (BlockNum <= 57): - if self.searchPreviousBlock(BlockNum): - return ("T" + str(i+1)) + ID = self.searchPreviousBlock(BlockNum) + if ID != -1: + return ("T" + str(ID+1)) #J Blocks are the ones we skip near the yard @@ -92,13 +95,15 @@ def matchOccupanciesToTrains(self, BlockID, line): #K-M blocks, train can only come from its previous blocks elif (BlockNum >= 64) and (BlockNum <= 76): - if self.searchPreviousBlock(BlockNum): - return ("T" + str(i+1)) + ID = self.searchPreviousBlock(BlockNum) + if ID != -1: + return ("T" + str(ID+1)) #Full n block, bidirectional elif (BlockNum >= 77) and (BlockNum <= 84): - if self.searchBothDirections(BlockNum): - return ("T" + str(i+1)) + ID = self.searchBothDirections(BlockNum) + if ID != -1: + return ("T" + str(ID+1)) #n switch on block 85, can come from N84 or Q100 elif BlockNum == 85: @@ -111,8 +116,9 @@ def matchOccupanciesToTrains(self, BlockID, line): #O-Q blocks, train can only come from its previous blocks elif (BlockNum >= 86) and (BlockNum <= 100): - if self.searchPreviousBlock(BlockNum): - return ("T" + str(i+1)) + ID = self.searchPreviousBlock(BlockNum) + if ID != -1: + return ("T" + str(ID+1)) #R101 block, comes from n track elif BlockNum == 101: @@ -123,8 +129,9 @@ def matchOccupanciesToTrains(self, BlockID, line): #S-Z blocks, train can only come from its previous blocks elif ((BlockNum >= 102) and (BlockNum <= 150)): - if self.searchPreviousBlock(BlockNum): - return ("T" + str(i+1)) + ID = self.searchPreviousBlock(BlockNum) + if ID != -1: + return ("T" + str(ID+1)) #Red Line if line == "Red": @@ -136,34 +143,34 @@ def matchOccupanciesToTrains(self, BlockID, line): return 'X' -#Internal function that searches if the current occupancy coresponds to train from a previous block -def searchPreviousBlock(self, BlockNum): - for i in range(len(self.currentTrains)): - for j in self.currentTrains[i]: - if int(j[1:]) == (BlockNum - 1): - return True - - return False - -#Internal function that searches if the current occupancy coresponds to train from a previous block, in reverse order -def searchPreviousBlockR(self, BlockNum): - for i in range(len(self.currentTrains)): - for j in self.currentTrains[i]: - if int(j[1:]) == (BlockNum + 1): - return True - - return False - -#Internal function that searches if the current occupancy coresponds to train from a previous block, iin both direction -def searchBothDirections(self, BlockNum): - for i in range(len(self.currentTrains)): - for j in self.currentTrains[i]: - if int(j[1:]) == (BlockNum - 1): - return True - if int(j[1:]) == (BlockNum + 1): - return True - - return False + #Internal function that searches if the current occupancy coresponds to train from a previous block + def searchPreviousBlock(self, BlockNum): + for i in range(len(self.currentTrains)): + for j in self.currentTrains[i]: + if int(j[1:]) == (BlockNum - 1): + return i + + return -1 + + #Internal function that searches if the current occupancy coresponds to train from a previous block, in reverse order + def searchPreviousBlockR(self, BlockNum): + for i in range(len(self.currentTrains)): + for j in self.currentTrains[i]: + if int(j[1:]) == (BlockNum + 1): + return i + + return -1 + + #Internal function that searches if the current occupancy coresponds to train from a previous block, iin both direction + def searchBothDirections(self, BlockNum): + for i in range(len(self.currentTrains)): + for j in self.currentTrains[i]: + if int(j[1:]) == (BlockNum - 1): + return i + if int(j[1:]) == (BlockNum + 1): + return i + + return -1 #Table class to initialize a Pyqt5 table object that will display the list of block occupancies From 34f062ce145f5c23a5fa79011e0b325d7558b6e5 Mon Sep 17 00:00:00 2001 From: Abby Date: Sat, 30 Mar 2024 20:00:48 -0400 Subject: [PATCH 08/19] Added buttons for reopening blocks and releasing switches --- CTC/CTC_UI.ui | 59 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/CTC/CTC_UI.ui b/CTC/CTC_UI.ui index f094195f..e7e489e5 100644 --- a/CTC/CTC_UI.ui +++ b/CTC/CTC_UI.ui @@ -6,8 +6,8 @@ 0 0 - 981 - 695 + 1037 + 677 @@ -628,9 +628,16 @@ - + - + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + @@ -643,16 +650,27 @@ - - - Close Block - - + + + + + Close Block + + + + + + + Reopen Block + + + + - + @@ -677,11 +695,22 @@ - - - Set Switch Positon - - + + + + + Set Switch Positon + + + + + + + Release Switch + + + + From bf58a04ede67aca45714b6705ac2c26b907b554f Mon Sep 17 00:00:00 2001 From: Abby Date: Sat, 30 Mar 2024 20:01:39 -0400 Subject: [PATCH 09/19] Added resizing of CTC window and table columns --- CTC/CTC_UI.py | 9 ++++++++- Main_UI.py | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CTC/CTC_UI.py b/CTC/CTC_UI.py index 387a53ca..34662532 100644 --- a/CTC/CTC_UI.py +++ b/CTC/CTC_UI.py @@ -66,6 +66,8 @@ def __init__(self): #Initializing Schedule self.trainSchedule = Schedule() self.ScheduleTable.setModel(ScheduleTableModel(self.trainSchedule.Scheduledata)) + ScheduleHeader = self.ScheduleTable.horizontalHeader() + ScheduleHeader.setSectionResizeMode(QHeaderView.ResizeToContents) #Initializing Manual Mode Functions before Manual Mode has been selected self.TrainNameField.clear() @@ -105,7 +107,12 @@ def __init__(self): #Initializing Maintance Tables self.Maintence = CTC_Maintenance() self.BlockClosureTable.setModel(ClosedBlocksTableModel(self.Maintence.BlocksClosed)) + BCHeader = self.BlockClosureTable.horizontalHeader() + BCHeader.setSectionResizeMode(QHeaderView.ResizeToContents) + self.SwitchPositionTable.setModel(SwitchPositionTableModel(self.Maintence.BlocksClosed)) + SPHeader = self.SwitchPositionTable.horizontalHeader() + SPHeader.setSectionResizeMode(QHeaderView.ResizeToContents) #Initializing Throughput self.ThroughputGraph = Throughput() @@ -383,7 +390,7 @@ def updateOccupiedBlocks(self, arr): #update the current variable to be the newly calculated ones self.occupiedBlocks.currentTrains = self.occupiedBlocks.newTrains self.occupiedBlocks.BlockDataCurrent = self.occupiedBlocks.BlockDataNew - + self.OccupiedBlockTable.setModel(BlocksTableModel(self.occupiedBlocks.BlockDataCurrent)) diff --git a/Main_UI.py b/Main_UI.py index 6a05968b..1bc54d8c 100644 --- a/Main_UI.py +++ b/Main_UI.py @@ -39,6 +39,7 @@ def __init__(self): #CTC UI Window self.CTCwindow = CTC_UI() + self.CTCwindow.resize(800, 600) #width, height self.CTC_tb = CTC_Testbench() self.CTC_Button.clicked.connect(self.open_CTC_UI) From a0812210ea46f2545d67406c8214d267a29da74f Mon Sep 17 00:00:00 2001 From: Abby Date: Sat, 30 Mar 2024 20:03:58 -0400 Subject: [PATCH 10/19] Renames buttons on UI --- CTC/CTC_UI.ui | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CTC/CTC_UI.ui b/CTC/CTC_UI.ui index e7e489e5..7a84aae7 100644 --- a/CTC/CTC_UI.ui +++ b/CTC/CTC_UI.ui @@ -7,7 +7,7 @@ 0 0 1037 - 677 + 673 @@ -650,7 +650,7 @@ - + @@ -659,7 +659,7 @@ - + Reopen Block @@ -695,7 +695,7 @@ - + @@ -704,7 +704,7 @@ - + Release Switch From 07f723701f8879a688bba24cf359bbc88c688171 Mon Sep 17 00:00:00 2001 From: Abby Date: Sat, 30 Mar 2024 20:12:39 -0400 Subject: [PATCH 11/19] Formatting of buttons for releasing things in maintenance --- CTC/CTC_UI.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/CTC/CTC_UI.py b/CTC/CTC_UI.py index 34662532..41bb8d50 100644 --- a/CTC/CTC_UI.py +++ b/CTC/CTC_UI.py @@ -40,13 +40,17 @@ def __init__(self): self.AddTrainButton.clicked.connect(self.addTrain_button) self.MaintenanceModeButton.clicked.connect(self.enterMaintenanceMode) self.CloseBlockButton.clicked.connect(self.closeBlock_button) + self.ReopenBlockButto.clicked.connect(self.reopenBlock_button) self.SetSwitchPositionButton.clicked.connect(self.setSwitch_button) + self.ReleaseSwitchButton.clicked.connect(self.releaseSwitch_button) #Changing Button Colors - self.AddTrainButton.setStyleSheet("background-color : rgb(38, 207, 4)") #Green - self.UploadButton.setStyleSheet("background-color : rgb(38, 207, 4)") #Green - self.CloseBlockButton.setStyleSheet("background-color: rgb(195, 16, 40)") #Red - self.SetSwitchPositionButton.setStyleSheet("background-color: rgb(195, 16, 40)") #Red + self.AddTrainButton.setStyleSheet("background-color : rgb(38, 207, 4)") #Green + self.UploadButton.setStyleSheet("background-color : rgb(38, 207, 4)") #Green + self.CloseBlockButton.setStyleSheet("background-color: rgb(195, 16, 40)") #Red + self.ReopenBlockButton.setStyleSheet("background-color : rgb(38, 207, 4)") #Green + self.SetSwitchPositionButton.setStyleSheet("background-color: rgb(195, 16, 40)") #Red + self.ReleaseSwitchButton.setStyleSheet("background-color : rgb(38, 207, 4)") #Green #Changing Background colors to section off UI, all light blue self.MaualDispatchBox.setStyleSheet("background-color : rgb(233, 247, 255);") @@ -91,7 +95,9 @@ def __init__(self): self.CloseBlockButton.setEnabled(False) self.ChooseSwitchSelect.setEnabled(False) self.SwitchPositionSelect.setEnabled(False) + self.ReopenBlockButton.setEnables(False) self.SetSwitchPositionButton.setEnabled(False) + self.ReleaseSwitchButton.setEnable(False) #Setting text to gray self.CloseBlockPromptLabel.setStyleSheet("color: rgb(120, 120, 120);") self.ChooseSwitchLabel.setStyleSheet("color: rgb(120, 120, 120);") @@ -438,6 +444,10 @@ def closeBlock_button(self): #Send to wayside self.sendBlockClosures.emit(self.Maintence.BlocksClosed) + + #Function to reopen a block closure when in maintence mode + def reopenBlock_button(self): + print("to be written") #Function to set switch positons when in maintenance mode def setSwitch_button(self): @@ -470,6 +480,10 @@ def setSwitch_button(self): self.Maintence.SwitchesSet.append(temp) + #Function to release a set switch positons when in maintenance mode + def releaseSwitch_button(self): + print("TBD") + #Funciton to sync switch position options to current selected switch def newSwitchSelected(self, index): self.SwitchPositionSelect.clear() From 948b27de53935f96af2506f578389b4568a8221c Mon Sep 17 00:00:00 2001 From: Abby Date: Sat, 30 Mar 2024 20:52:52 -0400 Subject: [PATCH 12/19] progress on reopening blocks in maintenance mode --- CTC/CTC_UI.py | 58 +++++++++++++++++++++++++++++++++++++++------------ CTC/CTC_UI.ui | 8 +++++-- 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/CTC/CTC_UI.py b/CTC/CTC_UI.py index 41bb8d50..b477f452 100644 --- a/CTC/CTC_UI.py +++ b/CTC/CTC_UI.py @@ -40,7 +40,7 @@ def __init__(self): self.AddTrainButton.clicked.connect(self.addTrain_button) self.MaintenanceModeButton.clicked.connect(self.enterMaintenanceMode) self.CloseBlockButton.clicked.connect(self.closeBlock_button) - self.ReopenBlockButto.clicked.connect(self.reopenBlock_button) + self.ReopenBlockButton.clicked.connect(self.reopenBlock_button) self.SetSwitchPositionButton.clicked.connect(self.setSwitch_button) self.ReleaseSwitchButton.clicked.connect(self.releaseSwitch_button) @@ -95,9 +95,9 @@ def __init__(self): self.CloseBlockButton.setEnabled(False) self.ChooseSwitchSelect.setEnabled(False) self.SwitchPositionSelect.setEnabled(False) - self.ReopenBlockButton.setEnables(False) + self.ReopenBlockButton.setEnabled(False) self.SetSwitchPositionButton.setEnabled(False) - self.ReleaseSwitchButton.setEnable(False) + self.ReleaseSwitchButton.setEnabled(False) #Setting text to gray self.CloseBlockPromptLabel.setStyleSheet("color: rgb(120, 120, 120);") self.ChooseSwitchLabel.setStyleSheet("color: rgb(120, 120, 120);") @@ -276,7 +276,7 @@ def selectAutoMode_button(self): #Sets drop down options if green line is selected def greenLine_button(self): - self.currentLine = 'green' + self.currentLine = 'Green' #Highlight green line button self.GreenLineButton.setStyleSheet("background-color : rgb(38, 207, 4)") #Green @@ -295,7 +295,7 @@ def greenLine_button(self): self.newSwitchSelected(0) def redLine_button(self): - self.currentLine = 'red' + self.currentLine = 'Red' #Highlight red line button self.RedLineButton.setStyleSheet("background-color: rgb(195, 16, 40)") #Red @@ -326,9 +326,9 @@ def displayClock(self, time): print(i[1], "Dispatched") #Initializing where the train starts - if i[0] == 'green': + if i[0] == 'Green': self.occupiedBlocks.currentTrains.append(['K63']) - elif i[0] == 'red': + elif i[0] == 'Red': self.occupiedBlocks.currentTrains.append(['D10']) @@ -357,9 +357,11 @@ def enterMaintenanceMode(self): #Enable Maintenance Mode functions self.CloseBlockSelect.setEnabled(True) self.CloseBlockButton.setEnabled(True) + self.ReopenBlockButton.setEnabled(True) self.ChooseSwitchSelect.setEnabled(True) self.SwitchPositionSelect.setEnabled(True) self.SetSwitchPositionButton.setEnabled(True) + self.ReleaseSwitchButton.setEnabled(True) #Setting text to gray self.CloseBlockPromptLabel.setStyleSheet("color: black;") self.ChooseSwitchLabel.setStyleSheet("color: black;") @@ -425,7 +427,7 @@ def closeBlock_button(self): BlockToClose = self.CloseBlockSelect.currentText() #if green line blocks are being shown, find corresponding green line block - if self.currentLine == 'green': + if self.currentLine == 'Green': for i in self.TrackData.GreenBlocks: if i.ID == BlockToClose: temp = i @@ -447,7 +449,36 @@ def closeBlock_button(self): #Function to reopen a block closure when in maintence mode def reopenBlock_button(self): - print("to be written") + #Read block selection from UI drop down + BlockToOpen = [] + BlockToOpen.append(self.CloseBlockSelect.currentText()) + BlockToOpen.append(self.currentLine) + + for i in range(len(self.Maintence.BlocksClosedIDs)): + if BlockToOpen == self.Maintence.BlocksClosedIDs[i]: + #Reset block + self.Maintence.BlocksClosed[i].occupied = 0 + self.Maintence.BlocksClosed[i].maintenance = 0 + + #Send to wayside + self.sendBlockClosures.emit(self.Maintence.BlocksClosed) + + #Remove from maintenence list and update table + self.Maintence.BlocksClosed.pop(i) + self.Maintence.BlocksClosedIDs.pop(i) + self.BlockClosureTable.setModel(ClosedBlocksTableModel(self.Maintence.BlocksClosedIDs)) + + return + + """ + #Attempt to popup a message if the user enters a block that isn't closed + error_msg = QMessageBox() + error_msg.setWindowTitle("Selection Error") + error_msg.setText("Selected block was not closed") + error_msg.setIcon(QMessageBox.Critical) + + error_msg.show() + """ #Function to set switch positons when in maintenance mode def setSwitch_button(self): @@ -457,7 +488,7 @@ def setSwitch_button(self): positionIndex = self.SwitchPositionSelect.currentIndex() #if green line blocks are being shown, find corresponding green line block - if self.currentLine == 'green': + if self.currentLine == 'Green': for i in self.TrackData.GreenBlocks: if i.blockNum == switchToSet: temp = i @@ -482,16 +513,17 @@ def setSwitch_button(self): #Function to release a set switch positons when in maintenance mode def releaseSwitch_button(self): - print("TBD") + test = self.SwitchPositionTable.QItemSelectionModel() + print(test) #Funciton to sync switch position options to current selected switch def newSwitchSelected(self, index): self.SwitchPositionSelect.clear() - if self.currentLine == 'green': + if self.currentLine == 'Green': self.SwitchPositionSelect.addItem(self.TrackData.GreenSwitches[index][1]) self.SwitchPositionSelect.addItem(self.TrackData.GreenSwitches[index][2]) - if self.currentLine == 'red': + if self.currentLine == 'Red': self.SwitchPositionSelect.addItem(self.TrackData.RedSwitches[index][1]) self.SwitchPositionSelect.addItem(self.TrackData.RedSwitches[index][2]) diff --git a/CTC/CTC_UI.ui b/CTC/CTC_UI.ui index 7a84aae7..f16c6e25 100644 --- a/CTC/CTC_UI.ui +++ b/CTC/CTC_UI.ui @@ -632,7 +632,7 @@ - QAbstractItemView::SingleSelection + QAbstractItemView::NoSelection QAbstractItemView::SelectRows @@ -672,7 +672,11 @@ - + + + QAbstractItemView::NoSelection + + From 0c055b627c82a8818e1253c4fe33a714d61ba1d8 Mon Sep 17 00:00:00 2001 From: Abby Date: Sun, 31 Mar 2024 10:10:16 -0400 Subject: [PATCH 13/19] Abby can't spell maintenance --- CTC/CTC_UI.py | 44 ++++++++++++++++++++++---------------------- CTC/CTC_UI.ui | 2 +- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/CTC/CTC_UI.py b/CTC/CTC_UI.py index b477f452..6ca3336b 100644 --- a/CTC/CTC_UI.py +++ b/CTC/CTC_UI.py @@ -56,7 +56,7 @@ def __init__(self): self.MaualDispatchBox.setStyleSheet("background-color : rgb(233, 247, 255);") self.ScheduleBox.setStyleSheet("background-color : rgb(233, 247, 255);") self.OccupiedBlocksBox.setStyleSheet("background-color : rgb(233, 247, 255);") - self.MaintenceBox.setStyleSheet("background-color : rgb(233, 247, 255);") + self.MaintenanceBox.setStyleSheet("background-color : rgb(233, 247, 255);") #Manual Dispatch Formatting self.ArrivalTimeEdit.setDisplayFormat("hh:mm") @@ -102,7 +102,7 @@ def __init__(self): self.CloseBlockPromptLabel.setStyleSheet("color: rgb(120, 120, 120);") self.ChooseSwitchLabel.setStyleSheet("color: rgb(120, 120, 120);") self.SwitchPositionLabel.setStyleSheet("color: rgb(120, 120, 120);") - self.MaintenceBox.setStyleSheet("color: rgb(120, 120, 120);") + self.MaintenanceBox.setStyleSheet("color: rgb(120, 120, 120);") #Seting the Swith Position Drop Down self.ChooseSwitchSelect.currentIndexChanged.connect(self.newSwitchSelected) @@ -111,12 +111,12 @@ def __init__(self): self.OccupiedBlockTable.setModel(BlocksTableModel(self.occupiedBlocks.BlockDataCurrent)) #Initializing Maintance Tables - self.Maintence = CTC_Maintenance() - self.BlockClosureTable.setModel(ClosedBlocksTableModel(self.Maintence.BlocksClosed)) + self.Maintenance = CTC_Maintenance() + self.BlockClosureTable.setModel(ClosedBlocksTableModel(self.Maintenance.BlocksClosed)) BCHeader = self.BlockClosureTable.horizontalHeader() BCHeader.setSectionResizeMode(QHeaderView.ResizeToContents) - self.SwitchPositionTable.setModel(SwitchPositionTableModel(self.Maintence.BlocksClosed)) + self.SwitchPositionTable.setModel(SwitchPositionTableModel(self.Maintenance.BlocksClosed)) SPHeader = self.SwitchPositionTable.horizontalHeader() SPHeader.setSectionResizeMode(QHeaderView.ResizeToContents) @@ -322,7 +322,7 @@ def displayClock(self, time): self.create_a_train.emit(i[1]) #Train ID, speed, Authority - self.sendDispatchInfo.emit([i[1], 70, self.trainSchedule.AuthorityInfo[int(i[1][1:]) - 1]]) + self.sendDispatchInfo.emit([i[1], 40, self.trainSchedule.AuthorityInfo[int(i[1][1:]) - 1]]) print(i[1], "Dispatched") #Initializing where the train starts @@ -366,7 +366,7 @@ def enterMaintenanceMode(self): self.CloseBlockPromptLabel.setStyleSheet("color: black;") self.ChooseSwitchLabel.setStyleSheet("color: black;") self.SwitchPositionLabel.setStyleSheet("color: black;") - self.MaintenceBox.setStyleSheet("color: black;") + self.MaintenanceBox.setStyleSheet("color: black;") #Will indicate that the system is no longer in maintenance mode @@ -437,15 +437,15 @@ def closeBlock_button(self): temp = i #Add to list of strings for diplaying on CTC UI - self.Maintence.BlocksClosedIDs.append([BlockToClose, temp.lineColor]) - self.BlockClosureTable.setModel(ClosedBlocksTableModel(self.Maintence.BlocksClosedIDs)) + self.Maintenance.BlocksClosedIDs.append([BlockToClose, temp.lineColor]) + self.BlockClosureTable.setModel(ClosedBlocksTableModel(self.Maintenance.BlocksClosedIDs)) #Add to list of block objects for sending to wayside temp.occupied = 1 temp.maintenance = 1 - self.Maintence.BlocksClosed.append(temp) + self.Maintenance.BlocksClosed.append(temp) #Send to wayside - self.sendBlockClosures.emit(self.Maintence.BlocksClosed) + self.sendBlockClosures.emit(self.Maintenance.BlocksClosed) #Function to reopen a block closure when in maintence mode def reopenBlock_button(self): @@ -454,19 +454,19 @@ def reopenBlock_button(self): BlockToOpen.append(self.CloseBlockSelect.currentText()) BlockToOpen.append(self.currentLine) - for i in range(len(self.Maintence.BlocksClosedIDs)): - if BlockToOpen == self.Maintence.BlocksClosedIDs[i]: + for i in range(len(self.Maintenance.BlocksClosedIDs)): + if BlockToOpen == self.Maintenance.BlocksClosedIDs[i]: #Reset block - self.Maintence.BlocksClosed[i].occupied = 0 - self.Maintence.BlocksClosed[i].maintenance = 0 + self.Maintenance.BlocksClosed[i].occupied = 0 + self.Maintenance.BlocksClosed[i].maintenance = 0 #Send to wayside - self.sendBlockClosures.emit(self.Maintence.BlocksClosed) + self.sendBlockClosures.emit(self.Maintenance.BlocksClosed) #Remove from maintenence list and update table - self.Maintence.BlocksClosed.pop(i) - self.Maintence.BlocksClosedIDs.pop(i) - self.BlockClosureTable.setModel(ClosedBlocksTableModel(self.Maintence.BlocksClosedIDs)) + self.Maintenance.BlocksClosed.pop(i) + self.Maintenance.BlocksClosedIDs.pop(i) + self.BlockClosureTable.setModel(ClosedBlocksTableModel(self.Maintenance.BlocksClosedIDs)) return @@ -498,8 +498,8 @@ def setSwitch_button(self): temp = i #Add to list of strings for displaying on CTC UI - self.Maintence.SwitchText.append([switchToSet, positionToSet, temp.lineColor]) - self.SwitchPositionTable.setModel(SwitchPositionTableModel(self.Maintence.SwitchText)) + self.Maintenance.SwitchText.append([switchToSet, positionToSet, temp.lineColor]) + self.SwitchPositionTable.setModel(SwitchPositionTableModel(self.Maintenance.SwitchText)) #Add to list of block objects for sending to wayside #If the position is the first one, switch state is left = true if positionIndex == 0: @@ -509,7 +509,7 @@ def setSwitch_button(self): temp.maintenance = 1 - self.Maintence.SwitchesSet.append(temp) + self.Maintenance.SwitchesSet.append(temp) #Function to release a set switch positons when in maintenance mode def releaseSwitch_button(self): diff --git a/CTC/CTC_UI.ui b/CTC/CTC_UI.ui index f16c6e25..d7e6feee 100644 --- a/CTC/CTC_UI.ui +++ b/CTC/CTC_UI.ui @@ -622,7 +622,7 @@ - + Maintenance From 2f6038b9f2420f117a7426c07abb0d77a0822968 Mon Sep 17 00:00:00 2001 From: Abby Date: Sun, 31 Mar 2024 11:16:50 -0400 Subject: [PATCH 14/19] Update train ID input, so the user has to follow the convention --- CTC/CTC_UI.py | 46 ++++++++++++++++++++++------------------------ CTC/CTC_UI.ui | 6 +++--- CTC/Schedule.py | 1 + Main_UI.py | 2 +- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/CTC/CTC_UI.py b/CTC/CTC_UI.py index 6ca3336b..210995d3 100644 --- a/CTC/CTC_UI.py +++ b/CTC/CTC_UI.py @@ -72,10 +72,11 @@ def __init__(self): self.ScheduleTable.setModel(ScheduleTableModel(self.trainSchedule.Scheduledata)) ScheduleHeader = self.ScheduleTable.horizontalHeader() ScheduleHeader.setSectionResizeMode(QHeaderView.ResizeToContents) + #ScheduleHeader.setSectionResizeMode(QHeaderView.Fixed) #Initializing Manual Mode Functions before Manual Mode has been selected - self.TrainNameField.clear() - self.TrainNameField.setEnabled(False) + self.TrainNameSelect.clear() + self.TrainNameSelect.setEnabled(False) self.DestinationSelect.setEnabled(False) self.ArrivalTimeEdit.setEnabled(False) #Disable the add train button @@ -114,11 +115,11 @@ def __init__(self): self.Maintenance = CTC_Maintenance() self.BlockClosureTable.setModel(ClosedBlocksTableModel(self.Maintenance.BlocksClosed)) BCHeader = self.BlockClosureTable.horizontalHeader() - BCHeader.setSectionResizeMode(QHeaderView.ResizeToContents) + BCHeader.setSectionResizeMode(QHeaderView.Stretch) self.SwitchPositionTable.setModel(SwitchPositionTableModel(self.Maintenance.BlocksClosed)) SPHeader = self.SwitchPositionTable.horizontalHeader() - SPHeader.setSectionResizeMode(QHeaderView.ResizeToContents) + SPHeader.setSectionResizeMode(QHeaderView.Stretch) #Initializing Throughput self.ThroughputGraph = Throughput() @@ -214,29 +215,15 @@ def recieveTicketSales(self, TicketSales): self.updateTicketSales(AverageSales) """Function to Define Behavior of CTC UI""" - #defining manual mode add train button functionality - def addTrain_button(self): - #Grabbing values from the UI - TrainID = self.TrainNameField.text() - Destination = self.DestinationSelect.currentText() - ArrivalTime = self.ArrivalTimeEdit.time() - - #Calculatig the Departure Station and time - Departure = [] - self.trainSchedule.calculateDeparture(Destination, ArrivalTime, Departure) - - #Adding the train to the schedule - self.trainSchedule.addTrain(TrainID, Destination, ArrivalTime, Departure[0], Departure[1]) - self.ScheduleTable.setModel(ScheduleTableModel(self.trainSchedule.Scheduledata)) - - #Define mutually exclisive auto/manual mode when manual mode is selected def selectManualMode_button(self): #Disable Manual Mode button because there's no need to select it twice self.ManualModeButton.setEnabled(False) self.ManualModeButton.setStyleSheet("background-color : blue; color: black;") - self.TrainNameField.setEnabled(True) + self.TrainNameSelect.setEnabled(True) + self.TrainNameSelect.clear() + self.TrainNameSelect.addItems(self.trainSchedule.TrainNames) self.DestinationSelect.setEnabled(True) self.ArrivalTimeEdit.setEnabled(True) #Disable the add train button @@ -254,8 +241,8 @@ def selectAutoMode_button(self): self.UploadButton.setStyleSheet("background-color : rgb(38, 207, 4)") #Green #Disable Manual Mode Functions - self.TrainNameField.clear() - self.TrainNameField.setEnabled(False) + self.TrainNameSelect.clear() + self.TrainNameSelect.setEnabled(False) self.DestinationSelect.setEnabled(False) self.ArrivalTimeEdit.setEnabled(False) #Disable the add train button @@ -405,10 +392,21 @@ def updateOccupiedBlocks(self, arr): #defining manual mode add train button functionality def addTrain_button(self): #Getting User entered Info - TrainID = self.TrainNameField.text() + TrainID = self.TrainNameSelect.currentText() Destination = self.DestinationSelect.currentText() ArrivalTime = self.ArrivalTimeEdit.time() + #Add a new train name option if required + if TrainID == self.trainSchedule.TrainNames[0]: + TrainID = self.trainSchedule.TrainNames[0][1:] + self.trainSchedule.TrainNames[0] = TrainID + newID = "*T" + str(int(self.trainSchedule.TrainNames[0][1:]) + 1) + self.trainSchedule.TrainNames.insert(0,newID) + + #reset train name options + self.TrainNameSelect.clear() + self.TrainNameSelect.addItems(self.trainSchedule.TrainNames) + #Calculating Departure Info Departure = [] self.trainSchedule.calculateDeparture(Destination, ArrivalTime, Departure, self.currentLine) diff --git a/CTC/CTC_UI.ui b/CTC/CTC_UI.ui index d7e6feee..4a50ce24 100644 --- a/CTC/CTC_UI.ui +++ b/CTC/CTC_UI.ui @@ -23,7 +23,7 @@ - + @@ -524,7 +524,7 @@ - + @@ -536,7 +536,7 @@ - + QLayout::SetFixedSize diff --git a/CTC/Schedule.py b/CTC/Schedule.py index 56f83f2d..c8efee06 100644 --- a/CTC/Schedule.py +++ b/CTC/Schedule.py @@ -17,6 +17,7 @@ def __init__(self): self.Scheduledata = [] self.AuthorityInfo = [] self.TrackData = TempData() + self.TrainNames = ["*T1"] #Function to add a single train to the schedule def addTrain(self, line, TrainID, Destination, ArrivalTime, Departure, DepartureTime): diff --git a/Main_UI.py b/Main_UI.py index 1bc54d8c..137dfd6a 100644 --- a/Main_UI.py +++ b/Main_UI.py @@ -39,7 +39,7 @@ def __init__(self): #CTC UI Window self.CTCwindow = CTC_UI() - self.CTCwindow.resize(800, 600) #width, height + self.CTCwindow.resize(900, 600) #width, height self.CTC_tb = CTC_Testbench() self.CTC_Button.clicked.connect(self.open_CTC_UI) From da2d49702865d7af3839216aad6f2dda4fc81448 Mon Sep 17 00:00:00 2001 From: Abby Date: Sun, 31 Mar 2024 11:51:22 -0400 Subject: [PATCH 15/19] Release switch functionality --- CTC/CTC_Maintenance.py | 8 ++++---- CTC/CTC_UI.py | 34 ++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/CTC/CTC_Maintenance.py b/CTC/CTC_Maintenance.py index 06471233..ff34ccb8 100644 --- a/CTC/CTC_Maintenance.py +++ b/CTC/CTC_Maintenance.py @@ -12,10 +12,10 @@ #Class to manage maintenece mode for CTC class CTC_Maintenance(): def __init__(self): - self.BlocksClosed = [] - self.BlocksClosedIDs = [] - self.SwitchText = [] - self.SwitchesSet = [] + self.BlocksClosed = [] #Block class object + self.BlocksClosedIDs = [] #List of lists: Line, BlockID + self.SwitchText = [] #Block class objects + self.SwitchesSet = [] #List of lists: Line, Switch, Position def addBlockClosure(self, BlockID): newBlockClosure = [BlockID] diff --git a/CTC/CTC_UI.py b/CTC/CTC_UI.py index 210995d3..124d1fb4 100644 --- a/CTC/CTC_UI.py +++ b/CTC/CTC_UI.py @@ -468,15 +468,13 @@ def reopenBlock_button(self): return - """ - #Attempt to popup a message if the user enters a block that isn't closed + #Popup a message if the user enters a block that isn't closed error_msg = QMessageBox() error_msg.setWindowTitle("Selection Error") error_msg.setText("Selected block was not closed") error_msg.setIcon(QMessageBox.Critical) - error_msg.show() - """ + error_msg.exec_() #Function to set switch positons when in maintenance mode def setSwitch_button(self): @@ -511,8 +509,32 @@ def setSwitch_button(self): #Function to release a set switch positons when in maintenance mode def releaseSwitch_button(self): - test = self.SwitchPositionTable.QItemSelectionModel() - print(test) + #Read the current switch selected + switchToRelease = self.ChooseSwitchSelect.currentText() + + for i in range(len(self.Maintenance.SwitchText)): + if (switchToRelease == self.Maintenance.SwitchText[i][0]) and (self.currentLine == self.Maintenance.SwitchText[i][2]): + #Reset block + self.Maintenance.SwitchesSet[i].maintenance = 0 + + #Send to wayside + self.sendSwitchPositions.emit(self.Maintenance.SwitchesSet) + + #Remove from maintenence list and update table + self.Maintenance.SwitchText.pop(i) + self.Maintenance.SwitchesSet.pop(i) + self.SwitchPositionTable.setModel(SwitchPositionTableModel(self.Maintenance.SwitchText)) + + return + + #Popup a message if the user enters a block that isn't closed + error_msg = QMessageBox() + error_msg.setWindowTitle("Selection Error") + error_msg.setText("Selected switch was not under maintenance") + error_msg.setIcon(QMessageBox.Critical) + + error_msg.exec_() + #Funciton to sync switch position options to current selected switch def newSwitchSelected(self, index): From ff6319dedb1aa35c0e5efa3d946aa89f606aeb4e Mon Sep 17 00:00:00 2001 From: Abby Date: Sun, 31 Mar 2024 12:32:11 -0400 Subject: [PATCH 16/19] Beginning of being able to enter and exit maintenance mode --- CTC/CTC_UI.py | 10 ++++++++-- CTC/CTC_UI.ui | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CTC/CTC_UI.py b/CTC/CTC_UI.py index 124d1fb4..cd8c0a40 100644 --- a/CTC/CTC_UI.py +++ b/CTC/CTC_UI.py @@ -38,7 +38,7 @@ def __init__(self): self.RedLineButton.clicked.connect(self.redLine_button) self.UploadButton.clicked.connect(self.selectScheduleFile) self.AddTrainButton.clicked.connect(self.addTrain_button) - self.MaintenanceModeButton.clicked.connect(self.enterMaintenanceMode) + self.MaintenanceModeButton.clicked.connect(self.maintenanceMode_button) self.CloseBlockButton.clicked.connect(self.closeBlock_button) self.ReopenBlockButton.clicked.connect(self.reopenBlock_button) self.SetSwitchPositionButton.clicked.connect(self.setSwitch_button) @@ -333,7 +333,13 @@ def selectScheduleFile(self): #Disable Manual Mode and upload button self.UploadButton.setEnabled(False) self.UploadButton.setStyleSheet("background-color : rgb(240, 240, 240); color: rgb(120, 120, 120);") - + + #Function to determine if the system is entering or exitting maintenance mode + def maintenanceMode_button(self): + if self.MaintenanceModeButton.isChecked(): + self.enterMaintenanceMode() + else: + self.exitMaintenanceMode() #Indication that the system is in maintenance mode #Same behavior will occur if a block is closed or a switch is sets diff --git a/CTC/CTC_UI.ui b/CTC/CTC_UI.ui index 4a50ce24..95b5a3db 100644 --- a/CTC/CTC_UI.ui +++ b/CTC/CTC_UI.ui @@ -614,6 +614,9 @@ Maintenance Mode + + true + From 5cb78e992f945257b667985be5ccf5059d36b968 Mon Sep 17 00:00:00 2001 From: Abby Date: Mon, 1 Apr 2024 14:27:55 -0400 Subject: [PATCH 17/19] Progress on exiting maintenance mode and warning user that blocks/switches will reopen when exited --- CTC/CTC_UI.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++--- CTC/CTC_UI.ui | 4 ++-- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/CTC/CTC_UI.py b/CTC/CTC_UI.py index cd8c0a40..8e8a3fd7 100644 --- a/CTC/CTC_UI.py +++ b/CTC/CTC_UI.py @@ -92,6 +92,7 @@ def __init__(self): self.UploadButton.setStyleSheet("background-color : rgb(240, 240, 240); color: rgb(120, 120, 120);") #Initializing Maintenance Mode functions before Mainenance Mode has been selected + self.inMaintenance = False self.CloseBlockSelect.setEnabled(False) self.CloseBlockButton.setEnabled(False) self.ChooseSwitchSelect.setEnabled(False) @@ -336,7 +337,7 @@ def selectScheduleFile(self): #Function to determine if the system is entering or exitting maintenance mode def maintenanceMode_button(self): - if self.MaintenanceModeButton.isChecked(): + if self.inMaintenance == False: self.enterMaintenanceMode() else: self.exitMaintenanceMode() @@ -344,6 +345,8 @@ def maintenanceMode_button(self): #Indication that the system is in maintenance mode #Same behavior will occur if a block is closed or a switch is sets def enterMaintenanceMode(self): + self.inMaintenance = True + #Set button color to blue to indicate selection self.MaintenanceModeButton.setStyleSheet("background-color : blue; color: black;") @@ -355,7 +358,7 @@ def enterMaintenanceMode(self): self.SwitchPositionSelect.setEnabled(True) self.SetSwitchPositionButton.setEnabled(True) self.ReleaseSwitchButton.setEnabled(True) - #Setting text to gray + #Setting text to black self.CloseBlockPromptLabel.setStyleSheet("color: black;") self.ChooseSwitchLabel.setStyleSheet("color: black;") self.SwitchPositionLabel.setStyleSheet("color: black;") @@ -366,7 +369,49 @@ def enterMaintenanceMode(self): #Should work on the double press of the button #or if the block closures/switch position are empty def exitMaintenanceMode(self): - print("You still need to write this") + #If there are closures/switches set ask the user if they want to reopen all of them + if (len(self.Maintenance.BlocksClosed) > 0) or (len(self.Maintenance.SwitchesSet) > 0): + #Popup a message if the user enters a block that isn't closed + error_msg = QMessageBox() + error_msg.setWindowTitle("Confirmation") + error_msg.setText("Exiting Maintenance Mode will reopen all blocks and release all switches") + error_msg.setIcon(QMessageBox.Warning) + error_msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) + #error_msg.buttonClicked.connect(self.msgbtn) + + exitMode = error_msg.exec_() + else: + exitMode = QMessageBox.Ok + + #If we are exiting Maintenance Mode + if exitMode == QMessageBox.Ok: + self.inMaintenance = False + self.MaintenanceModeButton.setStyleSheet("background-color : white") + + self.CloseBlockSelect.setEnabled(False) + self.CloseBlockButton.setEnabled(False) + self.ChooseSwitchSelect.setEnabled(False) + self.SwitchPositionSelect.setEnabled(False) + self.ReopenBlockButton.setEnabled(False) + self.SetSwitchPositionButton.setEnabled(False) + self.ReleaseSwitchButton.setEnabled(False) + #Setting text to gray + self.CloseBlockPromptLabel.setStyleSheet("color: rgb(120, 120, 120);") + self.ChooseSwitchLabel.setStyleSheet("color: rgb(120, 120, 120);") + self.SwitchPositionLabel.setStyleSheet("color: rgb(120, 120, 120);") + self.MaintenanceBox.setStyleSheet("color: rgb(120, 120, 120);") + + #Reopen all blocks if there are any + if len(self.Maintenance.BlocksClosed) > 0: + for block in range(len(self.Maintenance.BlocksClosed)): + #Reset block + self.Maintenance.BlocksClosed[i].occupied = 0 + self.Maintenance.BlocksClosed[i].maintenance = 0 + + + #Send to wayside + self.sendBlockClosures.emit(self.Maintenance.BlocksClosed) + #function to update block occupied table based on input from Wayside diff --git a/CTC/CTC_UI.ui b/CTC/CTC_UI.ui index 95b5a3db..71d217fa 100644 --- a/CTC/CTC_UI.ui +++ b/CTC/CTC_UI.ui @@ -6,7 +6,7 @@ 0 0 - 1037 + 1047 673 @@ -615,7 +615,7 @@ Maintenance Mode - true + false From f9f21a27becdca2e4022dd23da67c80325753d05 Mon Sep 17 00:00:00 2001 From: Abby Date: Mon, 1 Apr 2024 14:38:26 -0400 Subject: [PATCH 18/19] Choosing to exit maintence mode with blocks closed or switches set now reopens everything --- CTC/CTC_UI.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/CTC/CTC_UI.py b/CTC/CTC_UI.py index 8e8a3fd7..5398a50c 100644 --- a/CTC/CTC_UI.py +++ b/CTC/CTC_UI.py @@ -385,9 +385,10 @@ def exitMaintenanceMode(self): #If we are exiting Maintenance Mode if exitMode == QMessageBox.Ok: + #Set button color self.inMaintenance = False self.MaintenanceModeButton.setStyleSheet("background-color : white") - + #Disable all button/maintenace functions self.CloseBlockSelect.setEnabled(False) self.CloseBlockButton.setEnabled(False) self.ChooseSwitchSelect.setEnabled(False) @@ -405,13 +406,31 @@ def exitMaintenanceMode(self): if len(self.Maintenance.BlocksClosed) > 0: for block in range(len(self.Maintenance.BlocksClosed)): #Reset block - self.Maintenance.BlocksClosed[i].occupied = 0 - self.Maintenance.BlocksClosed[i].maintenance = 0 + self.Maintenance.BlocksClosed[block].occupied = 0 + self.Maintenance.BlocksClosed[block].maintenance = 0 #Send to wayside self.sendBlockClosures.emit(self.Maintenance.BlocksClosed) + #Update Table + self.Maintenance.BlocksClosed.clear() + self.Maintenance.BlocksClosedIDs.clear() + self.BlockClosureTable.setModel(ClosedBlocksTableModel(self.Maintenance.BlocksClosedIDs)) + + #Release all switches if any are set + if len(self.Maintenance.SwitchesSet) > 0: + for switch in range(len(self.Maintenance.SwitchesSet)): + #Reset block + self.Maintenance.SwitchesSet[switch].maintenance = 0 + + #Send to wayside + self.sendSwitchPositions.emit(self.Maintenance.SwitchesSet) + + #Update Table + self.Maintenance.SwitchesSet.clear() + self.Maintenance.SwitchText.clear() + self.SwitchPositionTable.setModel(SwitchPositionTableModel(self.Maintenance.SwitchText)) #function to update block occupied table based on input from Wayside From bea7b299073f0625a93c9dfc064f565f1641a7d1 Mon Sep 17 00:00:00 2001 From: Abby Date: Mon, 1 Apr 2024 14:40:35 -0400 Subject: [PATCH 19/19] Small typo with switch/block maintenance tables --- CTC/CTC_UI.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CTC/CTC_UI.py b/CTC/CTC_UI.py index 5398a50c..6d3c4275 100644 --- a/CTC/CTC_UI.py +++ b/CTC/CTC_UI.py @@ -118,7 +118,7 @@ def __init__(self): BCHeader = self.BlockClosureTable.horizontalHeader() BCHeader.setSectionResizeMode(QHeaderView.Stretch) - self.SwitchPositionTable.setModel(SwitchPositionTableModel(self.Maintenance.BlocksClosed)) + self.SwitchPositionTable.setModel(SwitchPositionTableModel(self.Maintenance.SwitchText)) SPHeader = self.SwitchPositionTable.horizontalHeader() SPHeader.setSectionResizeMode(QHeaderView.Stretch)