2025-11-04 16:20:50 +08:00
|
|
|
from PySide6.QtCore import QTimer, Signal, QObject # 导入Qt核心类
|
|
|
|
|
from PySide6.QtWidgets import QApplication # 用于获取主线程
|
2025-11-01 18:52:19 +08:00
|
|
|
import threading
|
2025-11-04 16:20:50 +08:00
|
|
|
from view.main_window import MainWindow
|
2025-10-31 18:52:31 +08:00
|
|
|
from .camera_controller import CameraController
|
|
|
|
|
from .bottom_control_controller import BottomControlController
|
2025-11-06 10:55:29 +08:00
|
|
|
from .hopper_controller import HopperController
|
2025-11-04 16:20:50 +08:00
|
|
|
|
2025-11-13 09:37:41 +08:00
|
|
|
from service.msg_recorder import MessageRecorder
|
2025-11-17 00:05:40 +08:00
|
|
|
from config.settings import Settings
|
|
|
|
|
from core.system import FeedingControlSystem
|
|
|
|
|
from opc.opcua_server import SimpleOPCUAServer
|
2025-11-13 09:37:41 +08:00
|
|
|
|
2025-10-18 18:29:40 +08:00
|
|
|
class MainController:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
# 主界面
|
|
|
|
|
self.main_window = MainWindow()
|
2025-11-17 00:05:40 +08:00
|
|
|
self.settings = Settings()
|
|
|
|
|
self.system = FeedingControlSystem(self.settings)
|
|
|
|
|
self.system.initialize()
|
|
|
|
|
self.system.state.state_updated.connect(self.update_ui_notify)
|
|
|
|
|
self.opcua_server = SimpleOPCUAServer(self.system.state)
|
|
|
|
|
self.opcua_server.start()
|
2025-11-13 09:37:41 +08:00
|
|
|
self.msg_recorder = MessageRecorder()
|
|
|
|
|
self.msg_recorder.normal_record("开始自动智能浇筑系统")
|
2025-11-17 00:05:40 +08:00
|
|
|
|
2025-11-04 16:20:50 +08:00
|
|
|
# 初始化子界面和控制器
|
2025-10-18 18:29:40 +08:00
|
|
|
self._initSubViews()
|
2025-10-31 18:52:31 +08:00
|
|
|
self._initSubControllers()
|
2025-10-18 18:29:40 +08:00
|
|
|
|
2025-11-13 09:37:41 +08:00
|
|
|
# 连接信号
|
|
|
|
|
self.__connectSignals()
|
|
|
|
|
|
2025-10-18 18:29:40 +08:00
|
|
|
def showMainWindow(self):
|
2025-11-04 09:45:14 +08:00
|
|
|
self.main_window.showFullScreen()
|
2025-11-07 15:45:54 +08:00
|
|
|
# self.main_window.show()
|
2025-11-01 18:52:19 +08:00
|
|
|
self.main_window.dispatch_task_widget.set_task_time("task1","15:44 PM")
|
|
|
|
|
self.main_window.dispatch_task_widget.set_task_time("task2","17:37 PM")
|
|
|
|
|
self.main_window.segment_task_widget.set_task_time("task1","15:38 PM")
|
|
|
|
|
self.main_window.segment_task_widget.set_task_time("task2","17:24 PM")
|
2025-10-18 18:29:40 +08:00
|
|
|
|
2025-10-31 18:52:31 +08:00
|
|
|
def _initSubControllers(self):
|
2025-11-06 10:55:29 +08:00
|
|
|
# 右侧视频显示控制模块
|
2025-10-31 18:52:31 +08:00
|
|
|
self.camera_controller = CameraController(
|
|
|
|
|
video_view=self.main_window.vibration_video
|
|
|
|
|
)
|
2025-11-06 10:55:29 +08:00
|
|
|
|
|
|
|
|
# 底部按钮控制模块
|
2025-10-31 18:52:31 +08:00
|
|
|
self.bottom_control_controller = BottomControlController(
|
|
|
|
|
bottom_control_widget=self.main_window.bottom_control_widget,
|
|
|
|
|
main_window=self.main_window
|
|
|
|
|
)
|
|
|
|
|
|
2025-11-06 10:55:29 +08:00
|
|
|
# 料斗控制模块(包括 夹爪开合、拱等按钮)
|
|
|
|
|
self.hopper_controller = HopperController(
|
|
|
|
|
hopper_view = self.main_window.hopper_widget,
|
|
|
|
|
conveyor_view = self.main_window.conveyor_system_widget
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2025-10-18 18:29:40 +08:00
|
|
|
def _initSubViews(self):
|
2025-11-13 09:37:41 +08:00
|
|
|
pass
|
2025-11-17 00:05:40 +08:00
|
|
|
|
|
|
|
|
def update_ui_notify(self, prop:str,value):
|
|
|
|
|
"""更新UI状态"""
|
|
|
|
|
print(f"更新UI状态: {prop} = {value}")
|
2025-11-13 09:37:41 +08:00
|
|
|
|
2025-11-19 19:25:39 +08:00
|
|
|
if prop == "feed_status" and value == 4:
|
|
|
|
|
# 盖板到位的情况, 更新 管片任务 (目前)
|
|
|
|
|
self.main_window.update_segment_tasks()
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if prop == "mould_finish_weight":
|
|
|
|
|
# 模具车中料的重量
|
|
|
|
|
current_mould_weight = value
|
|
|
|
|
if self.system.state._mould_need_weight != 0:
|
|
|
|
|
# 计算 模具车 和 生产进度
|
|
|
|
|
progress = int((current_mould_weight / self.system.state._mould_need_weight) * 100) # 去掉百分号之后的整数
|
|
|
|
|
progress = min(progress, 100) # 限制为100
|
|
|
|
|
self.main_window.arc_progress.setProgress(progress)
|
|
|
|
|
self.main_window.production_progress.setProgress(progress)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if prop == "upper_volume":
|
|
|
|
|
# 上料斗方量
|
|
|
|
|
self.hopper_controller.onUpdateUpperHopperVolume(value)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if prop == "lower_weight":
|
|
|
|
|
# 低位料斗重量
|
|
|
|
|
self.hopper_controller.onUpdateLowerHopperWeight(value)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
2025-11-13 09:37:41 +08:00
|
|
|
def __connectSignals(self):
|
|
|
|
|
self.main_window.about_to_close.connect(self.handleMainWindowClose) # 处理主界面关闭
|
|
|
|
|
|
|
|
|
|
def handleMainWindowClose(self):
|
|
|
|
|
"""主界面关闭"""
|
|
|
|
|
self.msg_recorder.normal_record("关闭自动智能浇筑系统")
|
|
|
|
|
# 停止系统底部控制器中的线程
|
|
|
|
|
if hasattr(self, 'bottom_control_controller'):
|
|
|
|
|
self.bottom_control_controller.stop_threads()
|