From 1c6e33c6c876993e84ba77098a272625455a2c89 Mon Sep 17 00:00:00 2001
From: xyy <544939200@qq.com>
Date: Mon, 25 May 2026 17:35:18 +0800
Subject: [PATCH]
---
头罩视野slove/头罩视野/Views/PageTest.xaml | 6 +-
头罩视野slove/头罩视野/Views/PageTest.xaml.cs | 68 +++++++++++++++----
2 files changed, 59 insertions(+), 15 deletions(-)
diff --git a/头罩视野slove/头罩视野/Views/PageTest.xaml b/头罩视野slove/头罩视野/Views/PageTest.xaml
index 8cab806..c439b56 100644
--- a/头罩视野slove/头罩视野/Views/PageTest.xaml
+++ b/头罩视野slove/头罩视野/Views/PageTest.xaml
@@ -300,9 +300,9 @@
-
-
-
+
+
+
\ No newline at end of file
diff --git a/头罩视野slove/头罩视野/Views/PageTest.xaml.cs b/头罩视野slove/头罩视野/Views/PageTest.xaml.cs
index 05e2bcc..274a3e3 100644
--- a/头罩视野slove/头罩视野/Views/PageTest.xaml.cs
+++ b/头罩视野slove/头罩视野/Views/PageTest.xaml.cs
@@ -58,6 +58,7 @@ namespace 头罩视野.Views
private double _lastAngle = -1;
+ private bool _fullTestCompleted = false; // 是否已完成一组完整测试(左右眼都测完)
private double _binocularTotalArea = 0; // 双目总视野面积
@@ -167,12 +168,24 @@ namespace 头罩视野.Views
ma.BtnClickFunction(Function.ButtonType.复归型, 103);
ButtonTest.Content = "测试";
_isTesting = false;
+ SetNavButtonsEnabled(true); // 启用导航栏
testTimer.Stop();
+
}
//测试按钮
private async void Button_Click_Test(object sender, RoutedEventArgs e)
{
+
+
+ if (_fullTestCompleted)
+ {
+ MessageBox.Show("请先点击“复位”按钮清除上次测试数据,再进行新测试!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+ return;
+ }
+
+
+
if (_isTesting)
{
// 停止测试
@@ -195,6 +208,10 @@ namespace 头罩视野.Views
ButtonTest.Content = "测试中...";
+
+
+ SetNavButtonsEnabled(false); // 禁用导航栏
+
// 在开始测试前清空当前眼的数据,保留另一眼的数据(如果有)
if (btnLeft.Content.ToString() == "左眼关" && btnRight.Content.ToString() == "右眼开")
{
@@ -257,6 +274,7 @@ namespace 头罩视野.Views
testTimer.Stop();
await _modbusMaster.WriteSingleCoilAsync(1, 102, false);
FinishTestAndCompute(); // 新方法
+ SetNavButtonsEnabled(true); // 启用导航栏
}
}
}
@@ -298,7 +316,7 @@ namespace 头罩视野.Views
System.Diagnostics.Debug.WriteLine($"右眼面积: {rightArea}");
System.Diagnostics.Debug.WriteLine($"总视野面积: {totalArea}");
System.Diagnostics.Debug.WriteLine($"双目视野面积: {biArea}");
-
+ _fullTestCompleted = true;
// 更新界面
Dispatcher.Invoke(() =>
{
@@ -357,7 +375,7 @@ namespace 头罩视野.Views
zsysaveSum.Text = totalRate.ToString("F2");
}
});
-
+ _fullTestCompleted = true; // 新增
ShowAreaData(); // 保存记录
}
@@ -522,7 +540,7 @@ namespace 头罩视野.Views
{
// 选中 → 试样测试
-
+ //_fullTestCompleted = false;
tbTest.Content = "空白测试";
GlobalData.CurrentMode = "空白测试";
@@ -533,7 +551,7 @@ namespace 头罩视野.Views
private async void TbTest_Checked(object sender, RoutedEventArgs e)
{
// 取消 → 空白测试
-
+ //_fullTestCompleted = false;
tbTest.Content = "试样测试";
GlobalData.CurrentMode = "试样测试";
tbTest.Background = System.Windows.Media.Brushes.LightGray;
@@ -700,14 +718,14 @@ namespace 头罩视野.Views
//btnRight.Content = "右眼开";
//LedOff(led1);
//LedOff(led0);
-
+ _fullTestCompleted = false;
_leftBoundaries = new List();
_rightBoundaries = new List();
_binocularTotalArea = 0;
maxBottomViewAngle = 0;
-
+ SetNavButtonsEnabled(true); // 启用导航栏
//初始化:全部设为0(灭)
_leftFinalData = Enumerable.Repeat(0, 240).ToList();
_rightFinalData = Enumerable.Repeat(0, 240).ToList();
@@ -851,12 +869,11 @@ namespace 头罩视野.Views
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
- // ===== 新增:恢复之前保存的状态 =====
+ // ===== 恢复之前保存的状态 =====
if (Application.Current.Properties["LeftBoundaries"] is List leftB)
_leftBoundaries = leftB;
if (Application.Current.Properties["RightBoundaries"] is List rightB)
_rightBoundaries = rightB;
- // 恢复左右眼独立的角度列表
if (Application.Current.Properties["LeftMeasuredAngles"] is List leftAngles)
_leftMeasuredAngles = leftAngles;
if (Application.Current.Properties["RightMeasuredAngles"] is List rightAngles)
@@ -877,12 +894,22 @@ namespace 头罩视野.Views
if (Application.Current.Properties["NextTargetAngle"] is double next)
_nextTargetAngle = next;
+ // 恢复界面显示值
+ if (Application.Current.Properties["Zmsyarea"] is string zmsy) zmsyarea.Text = zmsy;
+ if (Application.Current.Properties["Ymsyarea"] is string ymsy) ymsyarea.Text = ymsy;
+ if (Application.Current.Properties["Smsyarea"] is string smsy) smsyarea.Text = smsy;
+ if (Application.Current.Properties["ZsyareaNum"] is string zsya) zsyareaNum.Text = zsya;
+ if (Application.Current.Properties["Xfsyarea"] is string xfsy) xfsyarea.Text = xfsy;
+ if (Application.Current.Properties["Sybhl"] is string syb) sybhl.Text = syb;
+ if (Application.Current.Properties["ZsysaveSum"] is string zss) zsysaveSum.Text = zss;
+
// 如果之前正在测试,重新启动定时器
if (_isTesting)
{
testTimer.Start();
}
-
+ // 根据测试状态设置导航栏启用/禁用
+ SetNavButtonsEnabled(!_isTesting);
_timer.Start();
ma = new Function(_modbusMaster);
c = new DataChange();
@@ -896,10 +923,9 @@ namespace 头罩视野.Views
_cts = null;
_serialPort?.Close();
- // ===== 新增:保存状态到应用程序属性 =====
+ // ===== 保存状态到应用程序属性 =====
Application.Current.Properties["LeftBoundaries"] = _leftBoundaries?.ToList();
Application.Current.Properties["RightBoundaries"] = _rightBoundaries?.ToList();
- // 保存左右眼独立的角度列表
Application.Current.Properties["LeftMeasuredAngles"] = _leftMeasuredAngles?.ToList();
Application.Current.Properties["RightMeasuredAngles"] = _rightMeasuredAngles?.ToList();
@@ -910,10 +936,20 @@ namespace 头罩视野.Views
Application.Current.Properties["IsTesting"] = _isTesting;
Application.Current.Properties["StepAngle"] = _stepAngle;
Application.Current.Properties["NextTargetAngle"] = _nextTargetAngle;
+
+ // 保存界面显示值
+ Application.Current.Properties["Zmsyarea"] = zmsyarea.Text;
+ Application.Current.Properties["Ymsyarea"] = ymsyarea.Text;
+ Application.Current.Properties["Smsyarea"] = smsyarea.Text;
+ Application.Current.Properties["ZsyareaNum"] = zsyareaNum.Text;
+ Application.Current.Properties["Xfsyarea"] = xfsyarea.Text;
+ Application.Current.Properties["Sybhl"] = sybhl.Text;
+ Application.Current.Properties["ZsysaveSum"] = zsysaveSum.Text;
}
+
private IModbusMaster _serialMaster;
private SerialPort _serialPort; // 保存串口对象以便关闭
private bool _isSerialInitialized = false;
@@ -1032,7 +1068,15 @@ namespace 头罩视野.Views
}
}
-
+ ///
+ /// 设置底部导航按钮的启用/禁用状态
+ ///
+ private void SetNavButtonsEnabled(bool enabled)
+ {
+ btnNavHome.IsEnabled = enabled;
+ btnNavTest.IsEnabled = enabled;
+ btnNavRecord.IsEnabled = enabled;
+ }
}
}