Skip to content

Commit

Permalink
Merge pull request #185 from asmithie13/Abby_Branch
Browse files Browse the repository at this point in the history
Abby branch
  • Loading branch information
asmithie13 authored Apr 1, 2024
2 parents 095abdc + bea7b29 commit 08f1aca
Show file tree
Hide file tree
Showing 8 changed files with 412 additions and 111 deletions.
8 changes: 4 additions & 4 deletions CTC/CTC_Maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion CTC/CTC_Testbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
281 changes: 211 additions & 70 deletions CTC/CTC_UI.py

Large diffs are not rendered by default.

76 changes: 56 additions & 20 deletions CTC/CTC_UI.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>981</width>
<height>695</height>
<width>1047</width>
<height>673</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -23,7 +23,7 @@
<item>
<layout class="QVBoxLayout" name="CTC_TabCol1" stretch="1,4">
<item>
<layout class="QHBoxLayout" name="TopCol1Layout">
<layout class="QHBoxLayout" name="TopCol1Layout" stretch="1,2">
<item>
<layout class="QVBoxLayout" name="ButtonLayout">
<item>
Expand Down Expand Up @@ -524,7 +524,7 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="TrainNameField"/>
<widget class="QComboBox" name="TrainNameSelect"/>
</item>
<item>
<widget class="QPushButton" name="AddTrainButton">
Expand All @@ -536,7 +536,7 @@
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="ManualDispatchRow2" stretch="1,2,2,2">
<layout class="QHBoxLayout" name="ManualDispatchRow2" stretch="1,2,1,1">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
Expand Down Expand Up @@ -614,6 +614,9 @@
<property name="text">
<string>Maintenance Mode</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
</widget>
</item>
<item>
Expand All @@ -622,15 +625,22 @@
</layout>
</item>
<item>
<widget class="QGroupBox" name="MaintenceBox">
<widget class="QGroupBox" name="MaintenanceBox">
<property name="title">
<string>Maintenance</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_6" stretch="1,1">
<item>
<layout class="QVBoxLayout" name="BlockClosureLayout">
<layout class="QVBoxLayout" name="BlockClosureLayout" stretch="0,0,0,0">
<item>
<widget class="QTableView" name="BlockClosureTable"/>
<widget class="QTableView" name="BlockClosureTable">
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="CloseBlockPromptLabel">
Expand All @@ -643,18 +653,33 @@
<widget class="QComboBox" name="CloseBlockSelect"/>
</item>
<item>
<widget class="QPushButton" name="CloseBlockButton">
<property name="text">
<string>Close Block</string>
</property>
</widget>
<layout class="QHBoxLayout" name="CloseBlockButtonLayout">
<item>
<widget class="QPushButton" name="CloseBlockButton">
<property name="text">
<string>Close Block</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="ReopenBlockButton">
<property name="text">
<string>Reopen Block</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="SwitchPositionLayout">
<layout class="QVBoxLayout" name="SwitchPositionLayout" stretch="1,1,1,1,1,4">
<item>
<widget class="QTableView" name="SwitchPositionTable"/>
<widget class="QTableView" name="SwitchPositionTable">
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="ChooseSwitchLabel">
Expand All @@ -677,11 +702,22 @@
<widget class="QComboBox" name="SwitchPositionSelect"/>
</item>
<item>
<widget class="QPushButton" name="SetSwitchPositionButton">
<property name="text">
<string>Set Switch Positon</string>
</property>
</widget>
<layout class="QHBoxLayout" name="SwitchButtonLayout">
<item>
<widget class="QPushButton" name="SetSwitchPositionButton">
<property name="text">
<string>Set Switch Positon</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="ReleaseSwitchButton">
<property name="text">
<string>Release Switch</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
Expand Down
148 changes: 133 additions & 15 deletions CTC/OccupiedBlocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,149 @@ 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 < 76):
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
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):
ID = self.searchPreviousBlock(BlockNum)
if ID != -1:
return ("T" + str(ID+1))

#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):
ID = self.searchBothDirections(BlockNum)
if ID != -1:
return ("T" + str(ID+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):
ID = self.searchPreviousBlock(BlockNum)
if ID != -1:
return ("T" + str(ID+1))

#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):
ID = self.searchPreviousBlock(BlockNum)
if ID != -1:
return ("T" + str(ID+1))

#Full n block, bidirectional
elif (BlockNum >= 77) and (BlockNum <= 84):
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:
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):
ID = self.searchPreviousBlock(BlockNum)
if ID != -1:
return ("T" + str(ID+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)):
ID = self.searchPreviousBlock(BlockNum)
if ID != -1:
return ("T" + str(ID+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 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
Expand Down
1 change: 1 addition & 0 deletions CTC/Schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 5 additions & 1 deletion MainSimulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions Main_UI.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(self):

#CTC UI Window
self.CTCwindow = CTC_UI()
self.CTCwindow.resize(900, 600) #width, height
self.CTC_tb = CTC_Testbench()
self.CTC_Button.clicked.connect(self.open_CTC_UI)

Expand Down

0 comments on commit 08f1aca

Please sign in to comment.