using Bro.Common.Helper;
|
using Bro.UI.Model.Winform;
|
using MathNet.Numerics.Interpolation;
|
using NPOI.SS.Formula.Functions;
|
using ScottPlot;
|
using ScottPlot.Drawing.Colormaps;
|
using ScottPlot.Plottable;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Drawing;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Windows.Forms;
|
using Windows.Networking.Proximity;
|
|
namespace Bro.M141.Process.UI
|
{
|
//[MenuNode("点数据折线图", "点数据折线图", 7, EnumHelper.TopMenu.SystemInfo, MenuNodeType.Form)]
|
public partial class FrmPointLinec : MenuFormBase
|
{
|
M141Process prM141Process => Process as M141Process;
|
M141Config M141Config => Process.IConfig as M141Config;
|
|
|
public FrmPointLinec()
|
{
|
InitializeComponent();
|
|
formsPlot1.MouseMove += formsPlot1_MouseMove;
|
formsPlot1.MouseLeave += formsPlot1_MouseLeave;
|
formsPlot1.MouseEnter += formsPlot1_MouseEnter;
|
}
|
|
|
List<string> codes = new List<string>();
|
List<string> Points = new List<string>();
|
public override void OnProcessUpdated()
|
{
|
base.OnProcessUpdated();
|
//comboBox1.Text = M141Config.MeasurePointCollection.Count == 0 ? "" : M141Config.MeasurePointCollection[0].Name;
|
|
Points = M141Config.MeasurePointCollection.Select(u => u.Name).ToList();
|
codes = M141Config.GetSpecList().Select(u => u.Code).ToList();
|
codes.RemoveAll(u => !u.ToUpper().Contains("FAI"));
|
List<string> tem = new List<string>();
|
tem.AddRange(Points);
|
tem.AddRange(codes);
|
tem = tem.OrderBy(u => u).ToList();
|
|
comboBox1.Items.AddRange(tem.ToArray());
|
|
comboBox1.Text = tem.Count == 0 ? "" : tem[0];
|
|
comboBox1.TextChanged += comboBox1_TextChanged;
|
comboBox2.TextChanged += comboBox1_TextChanged;
|
comboBox3.TextChanged += comboBox1_TextChanged;
|
btnStart.Click += comboBox1_TextChanged;
|
prM141Process.PointRefresh += RefreshUI;
|
RefreshUI();
|
}
|
|
public override void OnCustomizedDispose()
|
{
|
base.OnCustomizedDispose();
|
|
if (prM141Process != null)
|
{
|
prM141Process.PointRefresh -= RefreshUI;
|
}
|
}
|
|
Dictionary<int, double> dicPoint = new Dictionary<int, double>();
|
public void RefreshUI()
|
{
|
//for (int s = 0; s < 500; s++)
|
//{
|
// Random random = new Random();
|
// prM141Process.M141Pointlist.Add(new List<Pointdata>
|
//{
|
// new Pointdata()
|
// {
|
// Code="FAI3_B1",
|
// ValueX=random.NextDouble()*14
|
// },
|
// new Pointdata()
|
// {
|
// Code="FAI3",
|
// Value=random.NextDouble()*14,
|
// Stand=5,
|
// Max=15,
|
// Min=0
|
// }
|
//});
|
|
// prM141Process.M141Codelist.Add(new List<Pointdata>
|
//{
|
// new Pointdata()
|
// {
|
// Code="FAI3_B1",
|
// ValueX=random.NextDouble()*14
|
// },
|
// new Pointdata()
|
// {
|
// Code="FAI 3",
|
// Value=random.NextDouble()*14,
|
// Stand=5,
|
// Max=15,
|
// Min=0
|
// }
|
//});
|
//}
|
|
|
|
dicPoint.Clear();
|
if (prM141Process.M141Pointlist == null || prM141Process.M141Pointlist.Count == 0)
|
{
|
return;
|
}
|
int total = Convert.ToInt32(comboBox2.Text);
|
string code = comboBox1.Text;
|
|
List<double> dataX = new List<double>();
|
List<double> dataY = new List<double>();
|
|
double max = 0;
|
double min = 0;
|
double stand = 0;
|
bool ispoint = Points.Contains(code);
|
|
|
if (ispoint)
|
{
|
if (prM141Process.M141Pointlist.Count >= total)
|
{
|
for (int i = 0; i < total; i++)
|
{
|
var tem = prM141Process.M141Pointlist[prM141Process.M141Pointlist.Count - total + i].FirstOrDefault(u => u.Code == code);
|
if (comboBox3.Text == "X")
|
{
|
dataY.Add(tem == null ? 0 : tem.ValueX);
|
dicPoint[i + 1] = tem == null ? 0 : tem.ValueX;
|
}
|
else
|
{
|
dataY.Add(tem == null ? 0 : tem.ValueY);
|
dicPoint[i + 1] = tem == null ? 0 : tem.ValueY;
|
}
|
|
dataX.Add(i + 1);
|
}
|
}
|
else
|
{
|
for (int i = 0; i < prM141Process.M141Pointlist.Count; i++)
|
{
|
var tem = prM141Process.M141Pointlist[i].FirstOrDefault(u => u.Code == code);
|
if (comboBox3.Text == "X")
|
{
|
dataY.Add(tem == null ? -999 : tem.ValueX);
|
dicPoint[i + 1] = tem == null ? 0 : tem.ValueX;
|
}
|
else
|
{
|
dataY.Add(tem == null ? -999 : tem.ValueY);
|
dicPoint[i + 1] = tem == null ? 0 : tem.ValueY;
|
}
|
dataX.Add(i + 1);
|
}
|
}
|
}
|
else
|
{
|
if (prM141Process.M141Codelist.Count >= total)
|
{
|
for (int i = 0; i < total; i++)
|
{
|
var tem = prM141Process.M141Codelist[prM141Process.M141Codelist.Count - total + i].FirstOrDefault(u => u.Code == code);
|
max = (tem == null ? 0 : tem.Max);
|
min = (tem == null ? 0 : tem.Min);
|
stand = (tem == null ? 0 : tem.Stand);
|
dataY.Add(tem == null ? 0 : tem.Value);
|
dicPoint[i + 1] = tem == null ? 0 : tem.Value;
|
dataX.Add(i + 1);
|
}
|
}
|
else
|
{
|
for (int i = 0; i < prM141Process.M141Codelist.Count; i++)
|
{
|
var tem = prM141Process.M141Codelist[i].FirstOrDefault(u => u.Code == code);
|
max = (tem == null ? 0 : tem.Max);
|
min = (tem == null ? 0 : tem.Min);
|
stand = (tem == null ? 0 : tem.Stand);
|
dataY.Add(tem == null ? 0 : tem.Value);
|
dicPoint[i + 1] = tem == null ? 0 : tem.Value;
|
dataX.Add(i + 1);
|
}
|
}
|
}
|
|
|
|
this.Invoke(new Action(() =>
|
{
|
formsPlot1.Plot.Clear();
|
|
// 添加折线图
|
if (!ispoint)
|
{
|
VSpan vspa =formsPlot1.Plot.AddVerticalSpan(min, max, Color.FromArgb(231, 244, 217));
|
//vspa.BorderLineStyle = LineStyle.Solid;
|
vspa.IsVisible = true;
|
|
var hl = formsPlot1.Plot.AddHorizontalLine(stand);
|
hl.LineColor = Color.Blue;
|
hl.LineStyle = LineStyle.DashDot;
|
|
hl.IsVisible = true;
|
hl.Label = stand.ToString();
|
}
|
|
formsPlot1.Plot.AddScatter(dataX.ToArray(), dataY.ToArray());
|
if (dataX.Count>0)
|
{
|
Crosshair1 = formsPlot1.Plot.AddCrosshair(dataX[0], dataY[0]);
|
Crosshair1.VerticalLine.IsVisible = false;
|
Crosshair1.HorizontalLine.IsVisible = false;
|
}
|
// 强制立即绘制
|
formsPlot1.Refresh();
|
}));
|
}
|
|
|
|
|
private void comboBox1_TextChanged(object sender, EventArgs e)
|
{
|
RefreshUI();
|
}
|
|
|
Crosshair Crosshair1;
|
private void formsPlot1_MouseMove(object sender, MouseEventArgs e)
|
{
|
if (Crosshair1 != null)
|
{
|
var mouseCoordinates = formsPlot1.GetMouseCoordinates(0, 0);
|
Crosshair1.X = (int)mouseCoordinates.Item1;
|
Crosshair1.Y = dicPoint.ContainsKey((int)mouseCoordinates.Item1) ? dicPoint[(int)mouseCoordinates.Item1] : 0;
|
formsPlot1.Refresh(false, true);
|
}
|
}
|
|
private void formsPlot1_MouseLeave(object sender, EventArgs e)
|
{
|
if (Crosshair1 != null)
|
{
|
Crosshair1.VerticalLine.IsVisible = false;
|
Crosshair1.HorizontalLine.IsVisible = false;
|
formsPlot1.Refresh(false, false);
|
}
|
}
|
|
private void formsPlot1_MouseEnter(object sender, EventArgs e)
|
{
|
if (Crosshair1 != null)
|
{
|
Crosshair1.VerticalLine.IsVisible = true;
|
Crosshair1.HorizontalLine.IsVisible = true;
|
formsPlot1.Refresh(false, false);
|
}
|
}
|
|
|
}
|
}
|