WaveDataTools.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Drawing;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using Uninpho.Railway.Waveform;
  12. namespace Uninpho.Tools.components.DataManager
  13. {
  14. /// <summary>
  15. /// 构造波形图数据所需工具
  16. /// </summary>
  17. class WaveDataTools
  18. {
  19. /// <summary>
  20. /// 读取配置信息
  21. /// </summary>
  22. public static void ReadConfig(string jhorlgl, ref WaveInput list)
  23. {
  24. list.pzPath = ConfigurationManager.AppSettings["pzConfig"];
  25. list.jgtPath = ConfigurationManager.AppSettings["jgtpath"];
  26. }
  27. /// <summary>
  28. /// 构造WaveInput类数据
  29. /// </summary>
  30. public static void showBXT<T>(List<T> jhbx, string Xaxix, ref WaveInput pzmess,List<PZClass> pzlist)
  31. {
  32. Dictionary<string, CoorListClass> coorlist = new Dictionary<string, CoorListClass>();
  33. List<PZClass> pznewlist = new List<PZClass>();
  34. List<decimal> jgjlc = new List<decimal>();
  35. foreach (var item in jhbx.Select(p => p.GetType().GetProperty(Xaxix).GetValue(p)).ToList())
  36. {
  37. jgjlc.Add(Convert.ToDecimal(item));
  38. }
  39. PropertyInfo[] PropertyList = jhbx[0].GetType().GetProperties();
  40. foreach (PropertyInfo item in PropertyList)
  41. {
  42. string name = item.Name;
  43. if (item.PropertyType == typeof(decimal) && name != Xaxix)
  44. {
  45. var currdata = jhbx.Select(p => p.GetType().GetProperty(name).GetValue(p)).ToList();
  46. List<PointF> pointlist = new List<PointF>();
  47. for (int i = 0; i < currdata.Count; i++)
  48. {
  49. float x = (float)jgjlc[i];
  50. float y = (float)Convert.ToDecimal(currdata[i]);
  51. pointlist.Add(new PointF() { X = x, Y = y });
  52. }
  53. CoorListClass input = new CoorListClass();
  54. input.ListId = name;
  55. pzlist.Find(temp =>
  56. {
  57. if (temp.Id.First().ToString().ToUpper() + temp.Id.Substring(1) == name)
  58. {
  59. pznewlist.Add(new PZClass()
  60. {
  61. Id = temp.Id.First().ToString().ToUpper() + temp.Id.Substring(1),
  62. Name = temp.Name
  63. });
  64. input.ListName = temp.Name;
  65. return true;
  66. }
  67. else
  68. {
  69. input.ListName = name;
  70. return false;
  71. }
  72. });
  73. input.Scale = 1;
  74. input.Width = 5;
  75. input.Offset = 0.001;
  76. input.RGBA = new int[] { 0, 200, 255, 255 };
  77. input.CoorList = pointlist;
  78. coorlist.Add(name, input);
  79. }
  80. }
  81. pzmess.waveData = coorlist;
  82. pzmess.pzData = pznewlist;
  83. }
  84. public static void showBXT<T>(List<T> jhbx, List<T> jhbxold, string Xaxix, ref WaveInput pzmess, List<PZClass> pzlist)
  85. {
  86. Dictionary<string, CoorListClass> coorlist = new Dictionary<string, CoorListClass>();
  87. List<PZClass> pznewlist = new List<PZClass>();
  88. List<decimal> jgjlc = new List<decimal>();
  89. List<decimal> jgjlcold = new List<decimal>();
  90. foreach (var item in jhbx.Select(p => p.GetType().GetProperty(Xaxix).GetValue(p)).ToList())
  91. {
  92. jgjlc.Add(Convert.ToDecimal(item));
  93. }
  94. foreach (var item in jhbxold.Select(p => p.GetType().GetProperty(Xaxix).GetValue(p)).ToList())
  95. {
  96. jgjlcold.Add(Convert.ToDecimal(item));
  97. }
  98. PropertyInfo[] PropertyList = jhbx[0].GetType().GetProperties();
  99. foreach (PropertyInfo item in PropertyList)
  100. {
  101. string name = item.Name;
  102. if (item.PropertyType == typeof(decimal) && name != Xaxix)
  103. {
  104. var currdata = jhbx.Select(p => p.GetType().GetProperty(name).GetValue(p)).ToList();
  105. var currdataold = jhbxold.Select(p => p.GetType().GetProperty(name).GetValue(p)).ToList();
  106. List<PointF> pointlist = new List<PointF>();
  107. List<PointF> pointlistold = new List<PointF>();
  108. for (int i = 0; i < currdata.Count; i++)
  109. {
  110. float x = (float)jgjlc[i];
  111. float y = (float)Convert.ToDecimal(currdata[i]);
  112. pointlist.Add(new PointF() { X = x, Y = y });
  113. }
  114. for (int i = 0; i < currdataold.Count; i++)
  115. {
  116. float x = (float)jgjlcold[i];
  117. float y = (float)Convert.ToDecimal(currdataold[i]);
  118. pointlistold.Add(new PointF() { X = x, Y = y });
  119. }
  120. CoorListClass input = new CoorListClass();
  121. input.ListId = name;
  122. pzlist.Find(temp =>
  123. {
  124. if (temp.Id.First().ToString().ToUpper() + temp.Id.Substring(1) == name)
  125. {
  126. pznewlist.Add(new PZClass()
  127. {
  128. Id = temp.Id.First().ToString().ToUpper() + temp.Id.Substring(1),
  129. Name = temp.Name
  130. });
  131. input.ListName = temp.Name;
  132. return true;
  133. }
  134. else
  135. {
  136. input.ListName = name;
  137. return false;
  138. }
  139. });
  140. input.Scale = 1;
  141. input.Width = 5;
  142. input.Offset = 0.001;
  143. input.RGBA = new int[] { 0, 200, 255, 255 };
  144. input.CoorList = pointlist;
  145. input.CoorListOld = pointlistold;
  146. coorlist.Add(name, input);
  147. }
  148. }
  149. pzmess.waveData = coorlist;
  150. pzmess.pzData = pznewlist;
  151. }
  152. public static void initPZMessage(ref WaveInput pzmess)
  153. {
  154. StreamReader sr = new StreamReader(pzmess.pzPath);
  155. while (!sr.EndOfStream)
  156. {
  157. try
  158. {
  159. //id name scale offset linewidth r,g,b,a visible
  160. var strarr = sr.ReadLine().Split(' ');
  161. if (pzmess.waveData.ContainsKey(strarr[0]))
  162. {
  163. pzmess.waveData[strarr[0]].Scale = Convert.ToDouble(strarr[2]);
  164. pzmess.waveData[strarr[0]].Offset = Convert.ToDouble(strarr[3]);
  165. pzmess.waveData[strarr[0]].Width = Convert.ToInt32(strarr[4]);
  166. int[] color = strarr[5].Split(',').Select(int.Parse).ToArray();
  167. pzmess.waveData[strarr[0]].RGBA = color;
  168. pzmess.waveData[strarr[0]].Visible = strarr[6] == "True";
  169. }
  170. }
  171. catch (Exception ex)
  172. {
  173. continue;
  174. }
  175. }
  176. sr.Close();
  177. }
  178. }
  179. }