fix: 修复下游面板自动填充断裂的三处根因 + 清理过时 pipeline→panel 映射

This commit is contained in:
DXC
2026-06-18 10:28:14 +08:00
parent 2261b4b30e
commit 3f217e95b0
5 changed files with 46 additions and 75 deletions

View File

@ -150,7 +150,7 @@ PANEL_REGISTRY = [
'stage': '阶段四:预测与成果输出',
'display_name': '9. 机器学习预测',
'dependencies': {
'models_dir': ('step8_ml_train', 'Supervised_Model_Training', 'models_dir_widget'),
'models_dir': ('step8_ml_train', 'Supervised_Model_Training', 'models_dir_file'),
},
'constructor_kwargs': None,
},

View File

@ -43,23 +43,6 @@ from src.gui.core.pipeline_mode_dialog import PipelineModeDialog
from src.gui.dialogs import BandConfirmDialog
from src.core.pipeline.runner import PipelineHalt
# pipeline step_id → panel step_id 映射
PIPELINE_TO_PANEL_STEP = {
'step1': 'step1',
'step2': 'step2',
'step3': 'step3',
'step4': 'step5_clean',
'step5': 'step6_feature',
'step7': 'step7_index',
'step8': 'step8_ml_train',
'step9': 'step10_watercolor',
'step10': 'step4_sampling',
'step11_ml': 'step9_ml_predict',
'step11': 'step11_map',
'step14': 'step11_map',
}
class PipelineExecutor(QObject):
"""Pipeline 执行器 —— 纯逻辑层,零 UI 直接操作。"""

View File

@ -34,23 +34,6 @@ from PyQt5.QtWidgets import QMessageBox, QFileDialog
from src.gui.core.event_bus import global_event_bus
from src.core.workspace_manager import WorkspaceManager
# pipeline step_id → panel step_id 映射
PIPELINE_TO_PANEL_STEP = {
'step1': 'step1',
'step2': 'step2',
'step3': 'step3',
'step4': 'step5_clean',
'step5': 'step6_feature',
'step7': 'step7_index',
'step8': 'step8_ml_train',
'step9': 'step10_watercolor',
'step10': 'step4_sampling',
'step11_ml': 'step9_ml_predict',
'step11': 'step11_map',
'step14': 'step11_map',
}
class WorkspaceInitializer(QObject):
"""工作空间初始化器 —— 纯逻辑层,零 UI 直接操作。"""
@ -66,7 +49,10 @@ class WorkspaceInitializer(QObject):
# 工作空间管理器(文件扫描、路径发现)
self._workspace_manager = WorkspaceManager()
self._workspace_manager.set_step_id_mapping(PIPELINE_TO_PANEL_STEP)
# 全局输入缓存:{step_id: {output_type: path}}
# 存储非步骤产出但下游面板依赖的参数(如 Step1 的 reference_img
self._global_inputs = {}
# 订阅 StepCompleted 事件 → 自动扫描产物
global_event_bus.subscribe('StepCompleted', self._on_step_completed)
@ -89,6 +75,28 @@ class WorkspaceInitializer(QObject):
def workspace_manager(self) -> WorkspaceManager:
return self._workspace_manager
def cache_global_input(self, step_id: str, output_type: str, path: str):
"""缓存全局输入参数。
全局输入不是任何步骤的产出,但下游面板依赖它。
典型例子Step1 的 reference_img用户选择的输入影像
Step2/Step3 等下游面板需要它来预填"影像文件"字段。
Args:
step_id: 源步骤 ID'step1'
output_type: 输出类型标识(如 'reference_img'
path: 文件路径字符串
"""
if not path:
return
if step_id not in self._global_inputs:
self._global_inputs[step_id] = {}
self._global_inputs[step_id][output_type] = path
def get_global_inputs(self):
"""返回所有已缓存的全局输入 {step_id: {output_type: path}}。"""
return dict(self._global_inputs)
def run(self):
"""启动时工作目录选择对话框(由 QTimer.singleShot 延迟调用)。
@ -183,12 +191,23 @@ class WorkspaceInitializer(QObject):
if step1_panel and hasattr(step1_panel, 'img_file'):
ref_img = step1_panel.img_file.get_path()
if ref_img:
# 缓存到全局输入,供后续懒加载面板苏醒时回放
self.cache_global_input('step1', 'reference_img', ref_img)
global_event_bus.publish('OutputUpdated', {
'step_id': 'step1',
'output_type': 'reference_img',
'path': ref_img,
})
# 兜底:遍历已加载面板调用 update_from_config重建内存级参数和默认输出路径
for step_id, panel in self._panel_factory.get_loaded_panels().items():
if not hasattr(panel, 'update_from_config'):
continue
try:
panel.update_from_config(work_dir=work_dir, pipeline=None)
except Exception:
pass
global_event_bus.publish('LogMessage', {
'message': '✓ 工作目录扫描完成,事件总线已通知所有面板自动填充',
'level': 'info',

View File

@ -157,23 +157,6 @@ from src.gui.core.pipeline_mode_dialog import PipelineModeDialog
from src.gui.core.viz_thread import VisualizationWorkerThread, _viz_training_spectra_csv_path
from src.core.workspace_manager import WorkspaceManager
# pipeline step_id → panel step_id 映射pipeline 内部编号与 GUI 面板编号不同)
PIPELINE_TO_PANEL_STEP = {
'step1': 'step1',
'step2': 'step2',
'step3': 'step3',
'step4': 'step5_clean',
'step5': 'step6_feature',
'step7': 'step7_index',
'step8': 'step8_ml_train',
'step9': 'step10_watercolor',
'step10': 'step4_sampling',
'step11_ml': 'step9_ml_predict',
'step11': 'step11_map',
'step14': 'step11_map',
}
class WaterQualityGUI(QMainWindow):
"""水质参数反演分析系统主窗口"""
@ -199,7 +182,6 @@ class WaterQualityGUI(QMainWindow):
# 工作空间管理器(文件扫描、路径发现、配置裁剪)
self.workspace_manager = WorkspaceManager()
self.workspace_manager.set_step_id_mapping(PIPELINE_TO_PANEL_STEP)
# 面板实例字典step_id → panel instance由 create_content_area 填充
self._panels = {}