-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_screen.py
146 lines (123 loc) · 4.93 KB
/
main_screen.py
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
from PyQt5.QtWidgets import QMainWindow, QErrorMessage
from ui.python.ui_main_screen import Ui_MainScreen
from PyQt5 import QtCore
from target import Target
from constant import R_MAX, CENTER_GROUND_RADIUS, TICK_INTERVAL
from option import Option
import traceback
class MainScreen(QMainWindow):
def __init__(self, navigator):
super().__init__()
self.navigator = navigator
# Setup UI
self.uic = Ui_MainScreen()
self.uic.setupUi(self)
self.uic.checkBox.stateChanged.connect(self.toggle_cfar)
self.uic.v_multiple.setValue(Option.v_multiple)
self.uic.v_multiple.valueChanged.connect(self.v_multiple_on_change)
self.uic.show_actual.stateChanged.connect(self.toggle_show_actual)
self.uic.show_observe.stateChanged.connect(self.toggle_show_observe)
self.uic.show_predict.stateChanged.connect(self.toggle_show_predict)
self.uic.pfa_slider.valueChanged.connect(self.pfa_on_change)
self.uic.plot_btn.clicked.connect(self.open_plot)
# Setup status UI
self.stui = [] # status ui
self.setup_stui()
# Init states
self.targets = [None, None, None, None]
self.tracking_target = None
# Timer
timer = QtCore.QTimer(self)
timer.setInterval(TICK_INTERVAL)
timer.timeout.connect(self.tick)
timer.start()
# Set default pfa
self.uic.pfa_slider.setValue(Option.pfa * 100000)
self.uic.pfa_tbx.setText(str(Option.pfa))
def setup_stui(self):
# status ui
self.stui = [
{
"r": self.uic.lineEdit_kc_1,
"a": self.uic.lineEdit_pv_1,
"dir": self.uic.lineEdit_hd_1,
"v": self.uic.lineEdit_vt_1,
"btn": self.uic.btn_create_1,
},
{
"r": self.uic.lineEdit_kc_2,
"a": self.uic.lineEdit_pv_2,
"dir": self.uic.lineEdit_hd_2,
"v": self.uic.lineEdit_vt_2,
"btn": self.uic.btn_create_2,
},
{
"r": self.uic.lineEdit_kc_3,
"a": self.uic.lineEdit_pv_3,
"dir": self.uic.lineEdit_hd_3,
"v": self.uic.lineEdit_vt_3,
"btn": self.uic.btn_create_3,
},
{
"r": self.uic.lineEdit_kc_4,
"a": self.uic.lineEdit_pv_4,
"dir": self.uic.lineEdit_hd_4,
"v": self.uic.lineEdit_vt_4,
"btn": self.uic.btn_create_4,
}
]
self.stui[0]["btn"].clicked.connect(self.onclick_btn_create_1)
self.stui[1]["btn"].clicked.connect(self.onclick_btn_create_2)
self.stui[2]["btn"].clicked.connect(self.onclick_btn_create_3)
self.stui[3]["btn"].clicked.connect(self.onclick_btn_create_4)
def tick(self):
self.uic.radar.tick()
self.uic.radar_2.tick()
def toggle_cfar(self, isCheck):
Option.enable_CFAR = not Option.enable_CFAR
def v_multiple_on_change(self, value):
print("Set v x", value)
Option.v_multiple = value
def onclick_btn_create(self, i):
try:
r = float(self.stui[i]["r"].text())
a = float(self.stui[i]["a"].text())
dir = float(self.stui[i]["dir"].text())
v = float(self.stui[i]["v"].text())
## Validate r, a, dir, v
# Validate r
if not (r > CENTER_GROUND_RADIUS and r < R_MAX):
raise Exception(f"Khoảng cách phải nằm trong khoảng ({CENTER_GROUND_RADIUS},{R_MAX})")
# Validate v
if v < 0:
raise Exception("Vận tốc không được âm")
self.targets[i] = Target(r, a, dir, v)
self.stui[i]["btn"].setDisabled(True)
except ValueError as e:
msg = QErrorMessage(self)
print(str(e))
msg.showMessage("Giá trị là số không hợp lệ")
except Exception as e:
msg = QErrorMessage(self)
print(traceback.format_exc())
msg.showMessage(str(e))
def onclick_btn_create_1(self):
self.onclick_btn_create(0)
def onclick_btn_create_2(self):
self.onclick_btn_create(1)
def onclick_btn_create_3(self):
self.onclick_btn_create(2)
def onclick_btn_create_4(self):
self.onclick_btn_create(3)
def pfa_on_change(self, value):
print("Change pfa=", value)
Option.pfa = value / 100000
self.uic.pfa_tbx.setText(str(Option.pfa))
def toggle_show_actual(self, check):
Option.show_actual = not Option.show_actual
def toggle_show_observe(self, check):
Option.show_observe = not Option.show_observe
def toggle_show_predict(self, check):
Option.show_predict = not Option.show_predict
def open_plot(self):
self.navigator.open_plot_screen()