123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- 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
- {
- /// <summary>
- /// 构造波形图数据所需工具
- /// </summary>
- class WaveDataTools
- {
- /// <summary>
- /// 读取配置信息
- /// </summary>
- public static void ReadConfig(string jhorlgl, ref WaveInput list)
- {
- list.pzPath = ConfigurationManager.AppSettings["pzConfig"];
- list.jgtPath = ConfigurationManager.AppSettings["jgtpath"];
- }
- /// <summary>
- /// 构造WaveInput类数据
- /// </summary>
- public static void showBXT<T>(List<T> jhbx, string Xaxix, ref WaveInput pzmess,List<PZClass> pzlist)
- {
- Dictionary<string, CoorListClass> coorlist = new Dictionary<string, CoorListClass>();
- List<PZClass> pznewlist = new List<PZClass>();
- List<decimal> jgjlc = new List<decimal>();
- 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<PointF> pointlist = new List<PointF>();
- 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<T>(List<T> jhbx, List<T> jhbxold, string Xaxix, ref WaveInput pzmess, List<PZClass> pzlist)
- {
- Dictionary<string, CoorListClass> coorlist = new Dictionary<string, CoorListClass>();
- List<PZClass> pznewlist = new List<PZClass>();
- List<decimal> jgjlc = new List<decimal>();
- List<decimal> jgjlcold = new List<decimal>();
- 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<PointF> pointlist = new List<PointF>();
- List<PointF> pointlistold = new List<PointF>();
- 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();
- }
- }
- }
|