Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anh branch #138

Merged
merged 5 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified CTC/__pycache__/CTC_Maintenance.cpython-39.pyc
Binary file not shown.
Binary file modified CTC/__pycache__/CTC_Testbench.cpython-39.pyc
Binary file not shown.
Binary file modified CTC/__pycache__/CTC_UI.cpython-39.pyc
Binary file not shown.
Binary file modified CTC/__pycache__/OccupiedBlocks.cpython-39.pyc
Binary file not shown.
Binary file modified CTC/__pycache__/Schedule.cpython-39.pyc
Binary file not shown.
Binary file modified CTC/__pycache__/TempData.cpython-39.pyc
Binary file not shown.
Binary file modified CTC/__pycache__/Throughput.cpython-39.pyc
Binary file not shown.
6 changes: 5 additions & 1 deletion MainSimulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import Track_Model
from Track_Model.TrackModel import *


#Utility function to initialize clock
def clock():
global time
Expand Down Expand Up @@ -62,6 +61,10 @@ def clock():

#Wayside to Track Model

"""Track Model Signals"""

#Track Model to CTC
MainWindow.TrackModelWindow.SendTicketsales.connect(MainWindow.CTCwindow.recieveTicketSales)

"""Clock Initialization"""
#Initializing Qtimer for clock
Expand All @@ -70,6 +73,7 @@ def clock():
timer0.setInterval(100) #Interval in ms
timer0.timeout.connect(clock)
timer0.start()
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)


sys.exit(UI_window.exec_())
6 changes: 3 additions & 3 deletions MainUI.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>386</width>
<height>384</height>
<width>400</width>
<height>394</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -133,7 +133,7 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="">
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>110</x>
Expand Down
2 changes: 2 additions & 0 deletions Main_UI.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import Track_Model
from Track_Model.TrackModel import *



class Main_UI(QtWidgets.QMainWindow):
def __init__(self):
super(Main_UI, self).__init__()
Expand Down
Binary file modified PLC_Files/__pycache__/Parser.cpython-39.pyc
Binary file not shown.
Binary file modified PLC_Files/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
30 changes: 0 additions & 30 deletions Track_Model/Track Layout.tmx

This file was deleted.

4 changes: 0 additions & 4 deletions Track_Model/Track.tsx

This file was deleted.

165 changes: 44 additions & 121 deletions Track_Model/TrackModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
sys.path.append(project_root)

# import libraries
from PyQt5.QtWidgets import QApplication, QLCDNumber, QMainWindow, QFileDialog, QVBoxLayout, QComboBox, QHBoxLayout, QWidget, QLabel, QPushButton, QSizePolicy
from PyQt5 import uic
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication,QLCDNumber, QGroupBox,QMainWindow, QFileDialog, QVBoxLayout, QComboBox, QHBoxLayout, QWidget, QLabel, QPushButton, QSizePolicy
from PyQt5 import uic,QtCore
from PyQt5.QtCore import Qt,QAbstractTableModel
from PyQt5.QtCore import QTimer, QTime
from Track_Resources.Block import Block
from PyQt5 import QtCore as qtc
Expand All @@ -29,21 +29,22 @@ class TrackModelMain(QMainWindow):
# Define a signal to emit the grade to testBench UI
grade_signal = pyqtSignal(float)
#Adding a signal to update information based on block selection:
block_selected_signal = pyqtSignal(str) # Add this at the beginning of the class
block_selected_signal = pyqtSignal(str)

getSpecialBlocks = pyqtSignal(list)
#sendOccupancies = pyqtSignal(list)

#send ticket sales to ctc
SendTicketsales = pyqtSignal(list)

def __init__(self):
super().__init__()
self.blockStates = {}


# Load the track model straight from the UI file using uic
uic.loadUi("Track_Model/Track_Model.ui", self)
self.clock_in.display("09:22")


# Connect Upload Track Layout button to make upload file
self.pushButton.clicked.connect(self.upload_track_layout)

Expand All @@ -52,42 +53,37 @@ def __init__(self):
self.block_in_2.setEnabled(False)


#self.generateTickets()

# Connect button to method
# If clicked, then connect to UI
self.offButton_1.clicked.connect(self.toggle_button_state)
self.offButton_2.clicked.connect(self.toggle_button_state_2)
self.offButton_3.clicked.connect(self.toggle_button_state_3)

# Set default state for toggle button (default color should be red and "OFF") on all 3 buttons
self.offButton_1.setText("OFF")
self.offButton_1.setStyleSheet("background-color: rgb(195, 16, 40);")

self.offButton_2.setText("OFF")
self.offButton_2.setStyleSheet("background-color: rgb(195, 16, 40);")

self.offButton_3.setText("OFF")
self.offButton_3.setStyleSheet("background-color: rgb(195, 16, 40);")
self.generateTickets()

# Instantiate the Data class
self.data = Data()

# Connect the comboBox to the function
self.green_line.hide()
self.green_fault.hide()
#self.red_line.hide()
self.line_select.currentIndexChanged.connect(self.on_line_select_changed)

def on_line_select_changed(self):
# Check the selected option and show the corresponding group box
selected_option = self.line_select.currentText()
if selected_option == "Green Line":
self.green_line.show()
self.green_fault.show()
elif selected_option == "Select Line":
self.green_line.hide()
# elif selected_option == "Red Line":
# self.red_line.show()
# self.green.hide()


def generateTickets(self):
# Generate a random number between 1 and 74 for ticket sales
random_number = random.randint(1, 74)
#Output the random numberto ticket sales block info
self.ticket_out.setText(str(random_number))
self.SendTicketsales.emit(random_number)



#send to CTC
def send_tickets(self):
pass

def send_boarding(self):
pass
self.SendTicketsales.emit([random_number])


#set temperature
def set_temp(self, temp):
Expand Down Expand Up @@ -132,61 +128,6 @@ def update_main_dropdown(self, selected_text):
# update the dropdown in your main UI
self.block_in_1.setCurrentText(selected_text)

#This toggles the button of the failures
def toggle_button_state(self):
# Toggle button state and color button for broken rail
if self.offButton_1.text() == "OFF":
self.offButton_1.setText("ON")
self.offButton_1.setStyleSheet("background-color: green;")
else:
self.offButton_1.setText("OFF")
self.offButton_1.setStyleSheet("background-color: rgb(195, 16, 40);")

def toggle_button_state_tb(self, bool1):
# Toggle button state and color button for block broken rail but used from tb to main
if bool1.lower() in ["yes", "true", "on", "1"]:
self.offButton_1.setText("ON")
self.offButton_1.setStyleSheet("background-color: green;")
elif bool1.lower() in ["no", "false", "off", "0"]:
self.offButton_1.setText("OFF")
self.offButton_1.setStyleSheet("background-color: rgb(195, 16, 40);")

def toggle_button_state_2(self):
# Toggle button state and color button for track circuit failure
if self.offButton_2.text() == "OFF":
self.offButton_2.setText("ON")
self.offButton_2.setStyleSheet("background-color: green;")
else:
self.offButton_2.setText("OFF")
self.offButton_2.setStyleSheet("background-color: rgb(195, 16, 40);")

def toggle_button_state_2_tb(self, bool1):
# Toggle button state and color button for block track circuit failure but used from tb to main
if bool1.lower() in ["yes", "true", "on", "1"]:
self.offButton_2.setText("ON")
self.offButton_2.setStyleSheet("background-color: green;")
elif bool1.lower() in ["no", "false", "off", "0"]:
self.offButton_2.setText("OFF")
self.offButton_2.setStyleSheet("background-color: rgb(195, 16, 40);")

def toggle_button_state_3(self):
# toggle button state and color button for power failure
if self.offButton_3.text() == "OFF":
self.offButton_3.setText("ON")
self.offButton_3.setStyleSheet("background-color: green;")
else:
self.offButton_3.setText("OFF")
self.offButton_3.setStyleSheet("background-color: rgb(195, 16, 40);")

def toggle_button_state_3_tb(self, bool1):
# Toggle button state and color button for power_failure but used from tb to main
if bool1.lower() in ["yes", "true", "on", "1"]:
self.offButton_3.setText("ON")
self.offButton_3.setStyleSheet("background-color: green;")
elif bool1.lower() in ["no", "false", "off", "0"]:
self.offButton_3.setText("OFF")
self.offButton_3.setStyleSheet("background-color: rgb(195, 16, 40);")

def toggle_light_state_tb(self, bool1):
# Toggle the state and color of the light button
if bool1.lower() == "green":
Expand Down Expand Up @@ -271,9 +212,6 @@ def update_block_info(self, block_text):

# Emit screen change based on block selection
self.block_selected_signal.emit(block_text)

# After updating the UI, restore the state of toggle buttons for the selected block
#self.restore_block_state(block_text)

#Updates block in failure based on block selection
def update_block_in_2_based_on_block_in_1(self):
Expand Down Expand Up @@ -312,6 +250,10 @@ class TrackModel_tb(QMainWindow):

# Change signal to emit an int for ticket sales
ticket_sales_signal = pyqtSignal(int)

#signal to from get speed
Wayside_speed = pyqtSignal(Block)
Wayside_authority = pyqtSignal(Block)

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -472,20 +414,14 @@ def __init__(self):
self.infra = None
self.cumm_elevation = None

def set_heater(self):
def set_heater(self): #based on set temp
pass

# read Excel files from DataFrame
def read_excel(self, filename):

#current_selection = self.line_select.currentText()
# Use an if statement to check the current selection and set the filename accordingly
#if num == 1:
self.df = pd.read_excel("Track_Resources/Blue_Line_Block_Info.xlsx")
#elif num == 2:
# self.df = pd.read_excel("Track_Resources/red_line.xlsx")
#else:
# pass
self.df = pd.read_csv("Track_Resources/Blue_Line_Block_Info.csv")

#extract data from DataFrame of the Excel and assign to variables
self.elevation_data = self.df.set_index('Block Number')['ELEVATION (M)'].to_dict()
Expand Down Expand Up @@ -612,31 +548,22 @@ def set_occupancies(self):
def send_occupancies(self):
pass


# class Communicate(QObject):
# #object signals (mainly for failures inputs button)
# broken_rail_input_signal = pyqtSignal(str)
# track_input_signal = pyqtSignal(str)
# power_input_signal = pyqtSignal(str)
# ticket_sales_signal = pyqtSignal(int)
# light_input_signal = pyqtSignal(str)
# switch_input_signal = pyqtSignal(str)
# cross_input_signal = pyqtSignal(str)
# dropdown_broken_signal = pyqtSignal(str)
# class for fault table per block
class TrackFaultTable(QAbstractTableModel):
def __init__(self, data=None):
super().__init__()
self._data = []



# Call Main window
if __name__ == "__main__":

app = QApplication(sys.argv)

window = TrackModelMain()
window_2 = TrackModel_tb()

#Create an instance of Communicate
#communicator = Communicate()

# connect the signal from window_2 to the slot in window
window_2.broken_rail_input_signal.connect(window.toggle_button_state_tb)
window_2.track_input_signal.connect(window.toggle_button_state_2_tb)
window_2.power_input_signal.connect(window.toggle_button_state_3_tb)

window_2.dropdown_broken_signal.connect(window.update_main_dropdown)

Expand All @@ -649,10 +576,6 @@ def send_occupancies(self):
# Connect TrackModelMain's method to emit the grade to TestBench's slot to update the grade label
window.grade_signal.connect(window_2.update_grade_label)

#window.SendTicketsales.connect("CTC/CTC_UI.py".MainWindow.update_grade_label)



window.block_selected_signal.connect(window_2.update_on_block_selection)
window.show()
window_2.show()
Expand Down
Loading