refactor: Step1Panel UI 联动逻辑深度优化
This commit is contained in:
@ -1071,21 +1071,26 @@ class Step1Panel(QWidget):
|
||||
|
||||
# 动态显示/隐藏组件
|
||||
if use_ndwi:
|
||||
# 使用NDWI模式:隐藏掩膜文件,显示NDWI参数
|
||||
# 使用NDWI模式:隐藏掩膜文件,显示NDWI参数和输出掩膜
|
||||
self.mask_file.setVisible(False)
|
||||
self.ndwi_group.setVisible(True)
|
||||
self.output_file.setVisible(True) # 显示输出掩膜路径
|
||||
|
||||
# 当切换到NDWI模式时,如果工作目录已设置,自动填充输出路径
|
||||
if hasattr(self, 'work_dir') and self.work_dir:
|
||||
self._auto_fill_output_path()
|
||||
else:
|
||||
# 使用现有掩膜模式:显示掩膜文件,隐藏NDWI参数
|
||||
# 使用现有掩膜模式:显示掩膜文件,隐藏NDWI参数和输出掩膜
|
||||
self.mask_file.setVisible(True)
|
||||
self.ndwi_group.setVisible(False)
|
||||
self.output_file.setVisible(False) # 隐藏输出掩膜路径
|
||||
|
||||
# 参考影像和输出掩膜在两种模式下都显示
|
||||
# 参考影像在两种模式下都显示
|
||||
self.img_file.setVisible(True)
|
||||
self.output_file.setVisible(True)
|
||||
|
||||
def update_work_directory(self, work_dir):
|
||||
"""
|
||||
接收主窗口传来的工作目录,自动填充输出路径
|
||||
保存工作目录引用,用于后续自动填充路径
|
||||
|
||||
Args:
|
||||
work_dir: 工作目录路径
|
||||
@ -1093,26 +1098,53 @@ class Step1Panel(QWidget):
|
||||
if not work_dir:
|
||||
return
|
||||
|
||||
# 自动生成输出掩膜的完整路径
|
||||
output_dir = os.path.join(work_dir, "1_water_mask")
|
||||
# 保存工作目录引用
|
||||
self.work_dir = work_dir
|
||||
|
||||
# 如果当前选中的是NDWI模式,立即填充输出路径
|
||||
if self.use_ndwi_radio.isChecked():
|
||||
self._auto_fill_output_path()
|
||||
|
||||
def _auto_fill_output_path(self):
|
||||
"""
|
||||
自动填充输出掩膜路径(仅在NDWI模式下)
|
||||
确保路径使用正斜杠,避免斜杠混用
|
||||
"""
|
||||
if not hasattr(self, 'work_dir') or not self.work_dir:
|
||||
return
|
||||
|
||||
# 生成输出掩膜的完整路径
|
||||
output_dir = os.path.join(self.work_dir, "1_water_mask")
|
||||
os.makedirs(output_dir, exist_ok=True) # 确保目录存在
|
||||
|
||||
default_output_path = os.path.join(output_dir, "water_mask_out.dat")
|
||||
# 统一使用正斜杠,避免 \ 和 / 混用
|
||||
default_output_path = os.path.join(output_dir, "water_mask_out.dat").replace('\\', '/')
|
||||
self.output_file.set_path(default_output_path)
|
||||
|
||||
def get_config(self):
|
||||
"""获取配置"""
|
||||
use_ndwi = self.use_ndwi_radio.isChecked()
|
||||
|
||||
config = {
|
||||
'mask_path': None if self.use_ndwi_radio.isChecked() else self.mask_file.get_path(),
|
||||
'use_ndwi': self.use_ndwi_radio.isChecked(),
|
||||
'mask_path': None if use_ndwi else self.mask_file.get_path(),
|
||||
'use_ndwi': use_ndwi,
|
||||
'ndwi_threshold': self.ndwi_threshold.value()
|
||||
}
|
||||
|
||||
# 参考影像路径(两种模式都可能需要)
|
||||
img_path = self.img_file.get_path()
|
||||
if img_path:
|
||||
config['img_path'] = img_path
|
||||
output_path = self.output_file.get_path()
|
||||
if output_path:
|
||||
config['output_path'] = output_path
|
||||
|
||||
# 输出路径:仅在NDWI模式下有效
|
||||
if use_ndwi:
|
||||
output_path = self.output_file.get_path()
|
||||
if output_path:
|
||||
config['output_path'] = output_path
|
||||
else:
|
||||
# 使用现有掩膜时,不传递output_path,避免底层错误尝试保存文件
|
||||
config['output_path'] = None
|
||||
|
||||
return config
|
||||
|
||||
def set_config(self, config):
|
||||
@ -5668,14 +5700,14 @@ class WaterQualityGUI(QMainWindow):
|
||||
def _auto_fill_output_paths(self):
|
||||
"""
|
||||
根据工作目录自动填充各步骤的输出路径
|
||||
注意:Step1 的输出路径由 update_work_directory() 根据模式自动控制
|
||||
"""
|
||||
if not self.work_dir:
|
||||
return
|
||||
|
||||
# Step1: 输出掩膜路径
|
||||
if hasattr(self, 'step1_panel') and hasattr(self.step1_panel, 'output_file'):
|
||||
default_mask_path = os.path.join(self.work_dir, "1_water_mask", "water_mask_out.dat")
|
||||
self.step1_panel.output_file.set_path(default_mask_path)
|
||||
|
||||
# Step1: 只传递工作目录引用,不直接填充路径
|
||||
# 路径填充由 Step1Panel 根据单选按钮状态自动控制
|
||||
if hasattr(self, 'step1_panel'):
|
||||
self.step1_panel.update_work_directory(self.work_dir)
|
||||
|
||||
def init_ui(self):
|
||||
|
||||
Reference in New Issue
Block a user