using System;
using System.Collections.Generic;
using System.Configuration;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Uninpho.Railway.Waveform;
namespace Uninpho.Tools.components.DataManager
{
///
/// 构造波形图数据所需工具
///
class WaveDataTools
{
///
/// 读取配置信息
///
public static void ReadConfig(string jhorlgl, ref WaveInput list)
{
list.pzPath = ConfigurationManager.AppSettings["pzConfig"];
list.jgtPath = ConfigurationManager.AppSettings["jgtpath"];
}
///
/// 构造WaveInput类数据
///
public static void showBXT(List jhbx, string Xaxix, ref WaveInput pzmess,List pzlist)
{
Dictionary coorlist = new Dictionary();
List pznewlist = new List();
List jgjlc = new List();
foreach (var item in jhbx.Select(p => p.GetType().GetProperty(Xaxix).GetValue(p)).ToList())
{
jgjlc.Add(Convert.ToDecimal(item));
}
PropertyInfo[] PropertyList = jhbx[0].GetType().GetProperties();
foreach (PropertyInfo item in PropertyList)
{
string name = item.Name;
if (item.PropertyType == typeof(decimal) && name != Xaxix)
{
var currdata = jhbx.Select(p => p.GetType().GetProperty(name).GetValue(p)).ToList();
List pointlist = new List();
for (int i = 0; i < currdata.Count; i++)
{
float x = (float)jgjlc[i];
float y = (float)Convert.ToDecimal(currdata[i]);
pointlist.Add(new PointF() { X = x, Y = y });
}
CoorListClass input = new CoorListClass();
input.ListId = name;
pzlist.Find(temp =>
{
if (temp.Id.First().ToString().ToUpper() + temp.Id.Substring(1) == name)
{
pznewlist.Add(new PZClass()
{
Id = temp.Id.First().ToString().ToUpper() + temp.Id.Substring(1),
Name = temp.Name
});
input.ListName = temp.Name;
return true;
}
else
{
input.ListName = name;
return false;
}
});
input.Scale = 1;
input.Width = 5;
input.Offset = 0.001;
input.RGBA = new int[] { 0, 200, 255, 255 };
input.CoorList = pointlist;
coorlist.Add(name, input);
}
}
pzmess.waveData = coorlist;
pzmess.pzData = pznewlist;
}
public static void showBXT(List jhbx, List jhbxold, string Xaxix, ref WaveInput pzmess, List pzlist)
{
Dictionary coorlist = new Dictionary();
List pznewlist = new List();
List jgjlc = new List();
List jgjlcold = new List();
foreach (var item in jhbx.Select(p => p.GetType().GetProperty(Xaxix).GetValue(p)).ToList())
{
jgjlc.Add(Convert.ToDecimal(item));
}
foreach (var item in jhbxold.Select(p => p.GetType().GetProperty(Xaxix).GetValue(p)).ToList())
{
jgjlcold.Add(Convert.ToDecimal(item));
}
PropertyInfo[] PropertyList = jhbx[0].GetType().GetProperties();
foreach (PropertyInfo item in PropertyList)
{
string name = item.Name;
if (item.PropertyType == typeof(decimal) && name != Xaxix)
{
var currdata = jhbx.Select(p => p.GetType().GetProperty(name).GetValue(p)).ToList();
var currdataold = jhbxold.Select(p => p.GetType().GetProperty(name).GetValue(p)).ToList();
List pointlist = new List();
List pointlistold = new List();
for (int i = 0; i < currdata.Count; i++)
{
float x = (float)jgjlc[i];
float y = (float)Convert.ToDecimal(currdata[i]);
pointlist.Add(new PointF() { X = x, Y = y });
}
for (int i = 0; i < currdataold.Count; i++)
{
float x = (float)jgjlcold[i];
float y = (float)Convert.ToDecimal(currdataold[i]);
pointlistold.Add(new PointF() { X = x, Y = y });
}
CoorListClass input = new CoorListClass();
input.ListId = name;
pzlist.Find(temp =>
{
if (temp.Id.First().ToString().ToUpper() + temp.Id.Substring(1) == name)
{
pznewlist.Add(new PZClass()
{
Id = temp.Id.First().ToString().ToUpper() + temp.Id.Substring(1),
Name = temp.Name
});
input.ListName = temp.Name;
return true;
}
else
{
input.ListName = name;
return false;
}
});
input.Scale = 1;
input.Width = 5;
input.Offset = 0.001;
input.RGBA = new int[] { 0, 200, 255, 255 };
input.CoorList = pointlist;
input.CoorListOld = pointlistold;
coorlist.Add(name, input);
}
}
pzmess.waveData = coorlist;
pzmess.pzData = pznewlist;
}
public static void initPZMessage(ref WaveInput pzmess)
{
StreamReader sr = new StreamReader(pzmess.pzPath);
while (!sr.EndOfStream)
{
try
{
//id name scale offset linewidth r,g,b,a visible
var strarr = sr.ReadLine().Split(' ');
if (pzmess.waveData.ContainsKey(strarr[0]))
{
pzmess.waveData[strarr[0]].Scale = Convert.ToDouble(strarr[2]);
pzmess.waveData[strarr[0]].Offset = Convert.ToDouble(strarr[3]);
pzmess.waveData[strarr[0]].Width = Convert.ToInt32(strarr[4]);
int[] color = strarr[5].Split(',').Select(int.Parse).ToArray();
pzmess.waveData[strarr[0]].RGBA = color;
pzmess.waveData[strarr[0]].Visible = strarr[6] == "True";
}
}
catch (Exception ex)
{
continue;
}
}
sr.Close();
}
}
}