页面逻辑调整
This commit is contained in:
@@ -181,7 +181,62 @@ namespace 头罩视野.Views
|
||||
ButtonTest.Content = "测试中....";
|
||||
testTimer.Start();
|
||||
|
||||
// 1. 读取输入框
|
||||
double stepAngle = double.Parse(fbspeed.Text); // 分辨角度 例:10
|
||||
//double speed = double.Parse(zdangle.Text); // 转动速度
|
||||
int[] lightData = DataList.Cast<int>().ToArray(); // 1. 把DataList(List<dynamic>)转成方法需要的int[]
|
||||
// 1. 定义总和变量,初始为0
|
||||
double totalArea = 0;//总面积
|
||||
double totalBottomViewAngle = 0;//总角度
|
||||
// 2. 从0转到180,每 stepAngle 执行一次
|
||||
for (double current = stepAngle; current <= 180; current += stepAngle)
|
||||
{
|
||||
_ = ReadLightBarData();
|
||||
|
||||
//开始计算视野面积
|
||||
//2. 调用CalculateEllipseArea,传入两个参数
|
||||
double area = GetArea.CalculateEllipseArea(lightData, _lightPositions);
|
||||
totalArea += area;
|
||||
double bottomViewAngle = GetArea.CalculateBottomViewAngle(lightData, _lightPositions);
|
||||
totalBottomViewAngle += bottomViewAngle;
|
||||
}
|
||||
UpdateVisionResults(totalArea, totalBottomViewAngle);
|
||||
}
|
||||
//页面渲染值
|
||||
|
||||
public void UpdateVisionResults(double area, double BotViAn)
|
||||
{
|
||||
// 2. 根据按钮状态,把当前面积更新到对应的文本框
|
||||
if (btnRight.Content.ToString() == "右眼开" && btnLeft.Content.ToString() == "左眼关")
|
||||
{
|
||||
zmsyarea.Text = area.ToString("0.00"); // 左目
|
||||
}
|
||||
else if (btnRight.Content.ToString() == "右眼关" && btnLeft.Content.ToString() == "左眼开")
|
||||
{
|
||||
ymsyarea.Text = area.ToString("0.00"); // 右目
|
||||
}
|
||||
else if (btnRight.Content.ToString() == "右眼关" && btnLeft.Content.ToString() == "左眼关")
|
||||
{
|
||||
smsyarea.Text = area.ToString("0.00"); // 双目
|
||||
}
|
||||
|
||||
// 3. 计算空白区视野面积(双目时才有效)
|
||||
if (double.TryParse(smsyarea.Text, out double binocularTotalArea))
|
||||
{
|
||||
double blankArea = GetArea.GetBlankViewArea(binocularTotalArea);
|
||||
kbsyarea.Text = blankArea.ToString("0.00"); // 空白视野面积
|
||||
}
|
||||
|
||||
//// 4. 计算下方视野面积
|
||||
int botViAnInt = (int)Math.Round(BotViAn);
|
||||
xfsyarea.Text = botViAnInt.ToString("0.0"); // 下方视野
|
||||
|
||||
// 5. 计算视野保存率(双目)
|
||||
if (double.TryParse(smsyarea.Text, out double totalAreaForRate))
|
||||
{
|
||||
double binocularRate = GetArea.CalcVisionRate(totalAreaForRate);
|
||||
sybhl.Text = binocularRate.ToString("0.00"); // 视野保存率
|
||||
}
|
||||
}
|
||||
//停止btn
|
||||
private void Button_Click_Stop(object sender, RoutedEventArgs e)
|
||||
@@ -305,46 +360,10 @@ namespace 头罩视野.Views
|
||||
//ReadAndUpdateFloatAsync(430 ,2, sybhl, "F2", " "),
|
||||
|
||||
//前1从站地址,后1是长度
|
||||
ReadLightBarData()
|
||||
|
||||
|
||||
};
|
||||
isFinished = _modbusMaster.ReadCoils(1, 102, 1)[0];
|
||||
if (isFinished)
|
||||
{
|
||||
Button_Click_Stop(null, null);
|
||||
//开始计算视野面积
|
||||
// 1. 把DataList(List<dynamic>)转成方法需要的int[]
|
||||
int[] lightData = DataList.Cast<int>().ToArray();
|
||||
|
||||
//2. 调用CalculateEllipseArea,传入两个参数
|
||||
double area = GetArea.CalculateEllipseArea(lightData, _lightPositions);
|
||||
|
||||
//值显示在页面,
|
||||
if (btnRight.Content.ToString() == "右眼开"&& btnLeft.Content.ToString() == "左眼关")
|
||||
{
|
||||
zmsyarea.Text = area.ToString("0.00");//左目
|
||||
}
|
||||
else if (btnRight.Content.ToString() == "右眼关" && btnLeft.Content.ToString() == "左眼开")
|
||||
{
|
||||
ymsyarea.Text = area.ToString("0.00"); //右目
|
||||
}
|
||||
else if(btnRight.Content.ToString() == "右眼关" && btnLeft.Content.ToString() == "左眼关")
|
||||
{
|
||||
smsyarea.Text = area.ToString("0.00"); // 双目
|
||||
}
|
||||
// 空白
|
||||
double binocularTotalArea = double.Parse(smsyarea.Text);
|
||||
double blankArea = GetArea.GetBlankViewArea(binocularTotalArea);
|
||||
kbsyarea.Text = blankArea.ToString("0.00"); // 保留2位小数
|
||||
|
||||
|
||||
double BottomViewAngle = GetArea.CalculateEllipseArea(lightData, _lightPositions);
|
||||
xfsyarea.Text = BottomViewAngle.ToString("0.00"); // 下方
|
||||
|
||||
|
||||
double binocularRate = GetArea.CalcVisionRate(binocularTotalArea);
|
||||
sybhl.Text = binocularRate.ToString("0.00"); // 视野保存率
|
||||
}
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -423,7 +442,6 @@ namespace 头罩视野.Views
|
||||
}
|
||||
|
||||
|
||||
|
||||
//写入
|
||||
private void fbspeed_GotFocus(object sender, RoutedEventArgs e)
|
||||
{
|
||||
@@ -484,6 +502,7 @@ namespace 头罩视野.Views
|
||||
|
||||
|
||||
|
||||
|
||||
//读取灯泡的数据
|
||||
|
||||
/// <summary>
|
||||
@@ -518,7 +537,7 @@ namespace 头罩视野.Views
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"灯条数据读取失败:{ex.Message}");
|
||||
DataList.Clear(); // 出错时清空数据
|
||||
//DataList.Clear(); // 出错时清空数据
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user