示波器图片展示
This commit is contained in:
@@ -57,15 +57,15 @@ namespace PowerAdaptabilityModule.ViewModels
|
||||
public string ScopeImageDir { get => _scopeImageDir; set => SetProperty(ref _scopeImageDir, value); }
|
||||
|
||||
private BitmapImage? _scopeImage;
|
||||
/// <summary>最近一次抓取的示波器屏幕图片(供界面 Image 控件显示)</summary>
|
||||
/// <summary>当前显示的波形截图(由 LIST / SYNTHESIS 按钮按配置文件同名规则加载)</summary>
|
||||
public BitmapImage? ScopeImage { get => _scopeImage; set => SetProperty(ref _scopeImage, value); }
|
||||
|
||||
private bool _hasScopeImage;
|
||||
/// <summary>是否已有截图(控制图片区占位提示的显隐)</summary>
|
||||
/// <summary>是否已加载波形截图(控制图片区占位提示的显隐)</summary>
|
||||
public bool HasScopeImage { get => _hasScopeImage; set => SetProperty(ref _hasScopeImage, value); }
|
||||
|
||||
private string _scopeImageHint = "";
|
||||
/// <summary>最近抓取的图片文件提示</summary>
|
||||
/// <summary>波形截图查找/加载结果提示</summary>
|
||||
public string ScopeImageHint { get => _scopeImageHint; set => SetProperty(ref _scopeImageHint, value); }
|
||||
#endregion
|
||||
|
||||
@@ -447,6 +447,8 @@ public ICommand CopySynthPhaseToThreeCommand { get; }
|
||||
public ICommand DeleteSynthPresetCommand { get; }
|
||||
public ICommand CaptureScopeImageCommand { get; }
|
||||
public ICommand BrowseScopeImageDirCommand { get; }
|
||||
public ICommand ShowListWaveImageCommand { get; }
|
||||
public ICommand ShowSynthWaveImageCommand { get; }
|
||||
public ICommand ScopeAcquireRunCommand { get; }
|
||||
public ICommand ScopeAcquireStopCommand { get; }
|
||||
public ICommand QueryAcquireStateCommand { get; }
|
||||
@@ -713,7 +715,7 @@ public ICommand CopySynthPhaseToThreeCommand { get; }
|
||||
SaveSynthPresetAsCommand = new DelegateCommand(SaveCurrentSynthPresetAs);
|
||||
DeleteSynthPresetCommand = new DelegateCommand(DeleteCurrentSynthPreset);
|
||||
|
||||
// 示波器抓图:抓取当前屏幕保存为 PNG 到存储位置,成功后自动加载显示
|
||||
// 示波器抓图:抓取当前屏幕保存为 PNG 到存储位置(图片区不自动显示,改由 LIST / SYNTHESIS 按钮按配置文件名加载)
|
||||
CaptureScopeImageCommand = new DelegateCommand(async () => await ExecScope(async () =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(ScopeImageDir))
|
||||
@@ -728,7 +730,6 @@ public ICommand CopySynthPhaseToThreeCommand { get; }
|
||||
|
||||
await _scope!.保存屏幕截图(file, Ct()); // SAVe:IMAGe → *OPC? → READFile → 写盘
|
||||
|
||||
LoadScopeImage(file);
|
||||
Log($"示波器屏幕图片已抓取:{file}");
|
||||
}));
|
||||
|
||||
@@ -747,6 +748,11 @@ public ICommand CopySynthPhaseToThreeCommand { get; }
|
||||
Log($"波形图片存储位置已设置:{ScopeImageDir}");
|
||||
});
|
||||
|
||||
// 按当前载入的配置文件查看对应波形截图:
|
||||
// LIST → {当前测试项文件名}.png;SYNTHESIS → {当前波形文件名}.png;找不到则清空图片区
|
||||
ShowListWaveImageCommand = new DelegateCommand(() => ShowWaveImage(_currentPresetPath, "LIST"));
|
||||
ShowSynthWaveImageCommand = new DelegateCommand(() => ShowWaveImage(_currentSynthPath, "SYNTHESIS"));
|
||||
|
||||
// —— 采集控制 ——
|
||||
ScopeAcquireRunCommand = new DelegateCommand(async () =>
|
||||
await ExecScope(async () => { await _scope!.设置采集状态(true, Ct()); Log("示波器采集已启动 (RUN)"); }));
|
||||
@@ -1382,10 +1388,11 @@ public ICommand CopySynthPhaseToThreeCommand { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 把抓取到的 PNG 加载为 BitmapImage 并刷新界面显示。
|
||||
/// 把指定的 PNG 加载为 BitmapImage 并刷新界面显示。
|
||||
/// <para>BitmapCacheOption.OnLoad 读完即释放文件句柄,不占用图片文件;Freeze 后跨线程安全。</para>
|
||||
/// </summary>
|
||||
private void LoadScopeImage(string file)
|
||||
/// <returns>加载成功返回 true;文件缺失/损坏返回 false(提示由调用方给)。</returns>
|
||||
private bool LoadScopeImage(string file)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -1398,11 +1405,65 @@ public ICommand CopySynthPhaseToThreeCommand { get; }
|
||||
|
||||
ScopeImage = bmp;
|
||||
HasScopeImage = true;
|
||||
ScopeImageHint = $"最近抓取:{Path.GetFileName(file)}";
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"加载截图失败:{ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>清空图片区(没有对应波形截图时不显示任何图片)。</summary>
|
||||
private void ClearScopeImage()
|
||||
{
|
||||
ScopeImage = null;
|
||||
HasScopeImage = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 按“当前模式已载入配置文件的文件名(去扩展名)+ .png”在波形图片存储位置查找截图并显示。
|
||||
/// <para>LIST 模式取当前打开的测试项文件,SYNTHESIS 模式取当前打开的波形文件;
|
||||
/// 未载入配置或图片不存在时清空图片区,不显示任何图片。</para>
|
||||
/// </summary>
|
||||
private void ShowWaveImage(string? configPath, string mode)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(ScopeImageDir))
|
||||
{
|
||||
ClearScopeImage();
|
||||
ScopeImageHint = "请先设置波形图片存储位置";
|
||||
Log("请先设置波形图片存储位置");
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(configPath))
|
||||
{
|
||||
ClearScopeImage();
|
||||
ScopeImageHint = $"请先载入 {mode} 配置文件,再查看对应波形图片";
|
||||
Log($"请先载入 {mode} 配置文件");
|
||||
return;
|
||||
}
|
||||
|
||||
string stem = Path.GetFileNameWithoutExtension(configPath); // 配置文件名去掉 .json 后缀
|
||||
string file = Path.Combine(ScopeImageDir, stem + ".png");
|
||||
|
||||
if (!File.Exists(file))
|
||||
{
|
||||
ClearScopeImage();
|
||||
ScopeImageHint = $"未找到波形图片:{stem}.png";
|
||||
Log($"[{mode}] 未找到波形图片:{file}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (LoadScopeImage(file))
|
||||
{
|
||||
ScopeImageHint = $"{mode} 波形图片:{stem}.png";
|
||||
Log($"[{mode}] 已显示波形图片:{file}");
|
||||
}
|
||||
else
|
||||
{
|
||||
ClearScopeImage();
|
||||
ScopeImageHint = $"波形图片加载失败:{stem}.png";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -497,7 +497,18 @@
|
||||
Style="{StaticResource CmdBtn}"
|
||||
Background="#388E3C" Foreground="White"
|
||||
HorizontalAlignment="Left" Margin="0,4"
|
||||
ToolTip="抓取示波器当前屏幕保存为 PNG(SAVe:IMAGe),成功后自动加载显示" />
|
||||
ToolTip="抓取示波器当前屏幕保存为 PNG(SAVe:IMAGe),仅保存文件;查看波形图请点下方 LIST / SYNTHESIS" />
|
||||
|
||||
<!-- 波形截图:按当前载入配置文件的文件名(去 .json 后缀)查找同名 .png -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4,0,0">
|
||||
<TextBlock Text="波形图" Style="{StaticResource ParamLabel}" />
|
||||
<Button Content="LIST" Command="{Binding ShowListWaveImageCommand}"
|
||||
Style="{StaticResource CmdBtn}"
|
||||
ToolTip="取当前载入的 LIST 测试项文件名(去 .json 后缀),在波形图片存储位置查找同名 .png 并显示;找不到不显示图片" />
|
||||
<Button Content="SYNTHESIS" Command="{Binding ShowSynthWaveImageCommand}"
|
||||
Style="{StaticResource CmdBtn}"
|
||||
ToolTip="取当前载入的 SYNTHESIS 波形文件名(去 .json 后缀),在波形图片存储位置查找同名 .png 并显示;找不到不显示图片" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- 波形图片显示 -->
|
||||
<Border BorderBrush="#DDDDDD" BorderThickness="1"
|
||||
@@ -505,7 +516,7 @@
|
||||
<Grid Height="230">
|
||||
<Image Source="{Binding ScopeImage}" Stretch="Uniform" Margin="4"
|
||||
Visibility="{Binding HasScopeImage, Converter={StaticResource BoolToVis}}" />
|
||||
<TextBlock Text="暂无波形图片
抓取成功后自动显示"
|
||||
<TextBlock Text="暂无波形图片
点 LIST / SYNTHESIS 查看对应波形图"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
Foreground="#BDBDBD" FontSize="13" TextAlignment="Center">
|
||||
<TextBlock.Style>
|
||||
|
||||
Reference in New Issue
Block a user