添加两种不同种类的3D线条显示效果+解决界面bug
This commit is contained in:
78
UI/test.py
78
UI/test.py
@ -19,7 +19,6 @@ from ui_3d import Target3DWidgetA, Target3DWidgetB
|
||||
|
||||
class LengthMotorController(QMainWindow):
|
||||
"""线条长度标记与电机位置控制系统主界面"""
|
||||
update_time_signal = Signal(str)
|
||||
record_data_signal = Signal(float, float, float, float)
|
||||
line_select_signal = Signal(str, float, float, float, float)
|
||||
|
||||
@ -241,6 +240,7 @@ class LengthMotorController(QMainWindow):
|
||||
self.time_label = QLabel()
|
||||
self.time_label.setAlignment(Qt.AlignCenter)
|
||||
self.time_label.setFont(QFont("Microsoft YaHei", 14, QFont.Bold))
|
||||
self._update_current_time() # 手动触发一次,避免延迟
|
||||
time_layout.addWidget(self.time_label)
|
||||
right_v_layout.addWidget(time_group)
|
||||
|
||||
@ -390,39 +390,56 @@ class LengthMotorController(QMainWindow):
|
||||
display_layout = QVBoxLayout(display_group)
|
||||
display_layout.setContentsMargins(20, 20, 20, 20)
|
||||
|
||||
# 实例化ui_3d.py中的Target3DWidget
|
||||
self.ui_3d_widget = Target3DWidgetA() # 创建3D绘图控件实例
|
||||
self.ui_3d_widget.setMaximumSize(500, 330)
|
||||
# 创建3D控件的容器
|
||||
self.ui_3d_container = QWidget() # 空容器,专门放3D控件
|
||||
self.ui_3d_container_layout = QVBoxLayout(self.ui_3d_container)
|
||||
self.ui_3d_container_layout.setContentsMargins(0, 0, 0, 0)
|
||||
self.ui_3d_container.setFixedSize(500, 330)
|
||||
|
||||
test_btn = QPushButton("测试参数传递")
|
||||
test_btn.setFont(self.font2)
|
||||
test_btn.setFixedWidth(150)
|
||||
test_btn.clicked.connect(self._test_3d_param_pass)
|
||||
# 初始化默认显示A控件
|
||||
self.current_3d_widget = Target3DWidgetA()
|
||||
self.ui_3d_container_layout.addWidget(self.current_3d_widget)
|
||||
|
||||
display_layout.addWidget(self.ui_3d_widget)
|
||||
display_layout.addWidget(test_btn, alignment=Qt.AlignCenter)
|
||||
display_layout.addWidget(self.ui_3d_container)
|
||||
parent_layout.addWidget(display_group)
|
||||
|
||||
def _switch_3d_widget(self, widget_type):
|
||||
"""
|
||||
动态切换3D控件
|
||||
:param widget_type: "A"或"B"
|
||||
"""
|
||||
# 移除旧的3D控件
|
||||
if self.current_3d_widget:
|
||||
self.current_3d_widget.setParent(None) # 从布局中移除
|
||||
self.current_3d_widget.deleteLater() # 释放资源
|
||||
|
||||
# 创建新的3D控件
|
||||
if widget_type == "A":
|
||||
self.current_3d_widget = Target3DWidgetA()
|
||||
else:
|
||||
self.current_3d_widget = Target3DWidgetB()
|
||||
|
||||
# 添加新控件到容器
|
||||
self.ui_3d_container_layout.addWidget(self.current_3d_widget)
|
||||
|
||||
def _init_timer(self):
|
||||
"""初始化定时器"""
|
||||
self.timer = QTimer(self)
|
||||
self.timer.timeout.connect(self._update_current_time)
|
||||
self.timer.start(1000)
|
||||
self._update_current_time()
|
||||
|
||||
def _connect_signals(self):
|
||||
"""连接信号与槽函数"""
|
||||
self.save_btn.clicked.connect(self._save_settings)
|
||||
self.clear_btn.clicked.connect(self._clear_inputs)
|
||||
self.export_btn.clicked.connect(self._export_records)
|
||||
self.update_time_signal.connect(self.time_label.setText)
|
||||
self.record_data_signal.connect(self._log_param_change)
|
||||
self.line_select_signal.connect(self._set_line_params)
|
||||
|
||||
def _update_current_time(self):
|
||||
"""更新当前时间"""
|
||||
current_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
||||
self.update_time_signal.emit(current_time)
|
||||
self.time_label.setText(current_time)
|
||||
|
||||
@Slot(str)
|
||||
def _import_line_param(self, line_type):
|
||||
@ -431,13 +448,17 @@ class LengthMotorController(QMainWindow):
|
||||
selected_type = self.selected_line_a
|
||||
params = self.line_a_params[selected_type]
|
||||
line_name = f"线条A-{selected_type}"
|
||||
# 切换为A控件
|
||||
self._switch_3d_widget("A")
|
||||
else:
|
||||
selected_type = self.selected_line_b
|
||||
params = self.line_b_params[selected_type]
|
||||
line_name = f"线条B-{selected_type}"
|
||||
# 切换为B控件
|
||||
self._switch_3d_widget("B")
|
||||
|
||||
self.line_select_signal.emit(line_name, *params)
|
||||
QMessageBox.information(self, "导入成功", f"已导入{line_name}的参数")
|
||||
QMessageBox.information(self, "导入成功", f"已导入{line_name}的参数\n3D视图已切换为{line_type}类型")
|
||||
|
||||
@Slot(str, float, float, float, float)
|
||||
def _set_line_params(self, line_name, a, b, c, d):
|
||||
@ -449,10 +470,10 @@ class LengthMotorController(QMainWindow):
|
||||
d_str = f"{d:.0f}" # 参数d是整数(25/26/28等)
|
||||
|
||||
"""设置参数到下拉框"""
|
||||
self.combo_a.setCurrentText(str(a))
|
||||
self.combo_b.setCurrentText(str(b))
|
||||
self.combo_c.setCurrentText(str(c))
|
||||
self.combo_d.setCurrentText(str(d))
|
||||
self.combo_a.setCurrentText(a_str)
|
||||
self.combo_b.setCurrentText(b_str)
|
||||
self.combo_c.setCurrentText(c_str)
|
||||
self.combo_d.setCurrentText(d_str)
|
||||
|
||||
@Slot()
|
||||
def _save_settings(self):
|
||||
@ -482,27 +503,6 @@ class LengthMotorController(QMainWindow):
|
||||
"time": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
||||
})
|
||||
|
||||
@Slot()
|
||||
def _test_3d_param_pass(self):
|
||||
"""测试参数传递"""
|
||||
try:
|
||||
param_a = float(self.combo_a.currentText())
|
||||
param_b = float(self.combo_b.currentText())
|
||||
param_c = float(self.combo_c.currentText())
|
||||
param_d = float(self.combo_d.currentText())
|
||||
except ValueError:
|
||||
QMessageBox.critical(self, "测试失败", "当前参数格式无效!")
|
||||
return
|
||||
|
||||
QMessageBox.information(
|
||||
self, "参数传递测试成功",
|
||||
f"当前参数已准备好传递给3D模块:\n"
|
||||
f"参数a(半径):{param_a}\n"
|
||||
f"参数b(长度):{param_b}\n"
|
||||
f"参数c(颜色通道1):{param_c}\n"
|
||||
f"参数d(颜色通道2):{param_d}"
|
||||
)
|
||||
|
||||
@Slot()
|
||||
def _clear_inputs(self):
|
||||
"""清空所有选择"""
|
||||
|
||||
Reference in New Issue
Block a user