Control_XRayTable.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. using OTSPeriodicTable;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace OTSSysMgrApp
  10. {
  11. /// <summary>
  12. /// 能谱图类
  13. /// </summary>
  14. public partial class Control_XRayTable : UserControl
  15. {
  16. #region 变量定义
  17. //定义两个能量值线,用来显示使用
  18. float[] m_f_show2 = new float[2000];
  19. //用来保存实际传入的xray值数,用该数据转换成显示的值
  20. uint[] m_analysis_xray = new uint[2000];
  21. List<TwoPoint> m_list_twopoint1 = new List<TwoPoint>();
  22. List<TwoPoint> m_list_twopoint2 = new List<TwoPoint>();
  23. //记录鼠标所在位置
  24. Point m_mouse_point = new Point();
  25. //字体
  26. Font m_thisfont = new Font("微软雅黑", 8, FontStyle.Regular);
  27. Font m_thisfont_bold = new Font("微软雅黑", 8, FontStyle.Bold);
  28. //下标尺分界位置
  29. float m_f_rulerX_location = 160;
  30. //下坐标尺设定参数
  31. float m_i_smalkd = 5; //5像素一个小刻度
  32. float m_i_bigkd = 25; //25像素一个大刻度
  33. float m_i_smallkd_number = 200; //小刻度的个数
  34. float m_i_bigkd_number = 40; //大刻度的个数
  35. float m_i_draw_start = 40; //整个界面绘制的起始点
  36. float m_i_draw_end = 1004; //整个界面绘制的边界
  37. float m_Y_draw_end = 175; //整个界面绘制的边界高
  38. float m_Y_draw_TopDiff = 15; //Y轴距离顶部距离
  39. float m_Y_MaxValue = 0; //Y轴显示的最大刻度长度
  40. uint m_Y_Value = 50; //Y轴大刻度包含像素数
  41. float m_i_rightdrawlabellocation_x = 850; //右上角要显示文字的位置
  42. float m_i_rightdrawlabellocation_y = 5; //右上角要显示文字的位置
  43. SolidBrush m_this_sb = new SolidBrush(Color.Black); //画刷
  44. SolidBrush m_this_sb_blue = new SolidBrush(Color.Blue); //
  45. Pen m_this_p = new Pen(Color.Black, 0.5f); //画笔的颜色
  46. Pen m_this_p_blue = new Pen(Color.DimGray, 0.5f); //画笔的颜色 , 分析xray的颜色
  47. Pen m_mousemove_p = new Pen(Color.PowderBlue, 0.1f); //鼠标移动画的竖线的画笔颜色
  48. float m_kml_fz_top = 0; //计算KML峰值记录最高点变量
  49. float m_xraytopixel_multiple = 40; //比如,从xray0-6000的值,转到显示像素中0-150的比例倍数
  50. float m_xraysum2 = 0; //xray计数总和2
  51. List<Periodic> m_list_periodic; //元素周期表,相关数据,窗体加载时初始化,然后用来计算使用
  52. List<KMLFPoint> m_list_kmlfpoint; //KML峰值,对应的位置和元素名
  53. //属性相关变量,用来显示使用
  54. private bool m_b_show_analysisxray = true; //设置是否绘制分析xray线
  55. private List<ShowElementInfo> m_list_showelementinfo = null; //需要显示的元素信息列表
  56. float m_f_zl = 0.5f; //2000个数据放到1000个像素中计算出的增量
  57. float m_f_kmlfzpd_max = 30; //KML峰值上界限,进行记数的值,峰值判断的界限,需要按峰值最高值,和
  58. float m_f_kmlfzpd_mix = 5; //KML峰值下界限
  59. string m_ParticleInfo = ""; //颗粒相关信息
  60. #endregion
  61. #region 属性相关
  62. /// <summary>
  63. /// 显示元素列表相关信息
  64. /// </summary>
  65. public List<ShowElementInfo> List_ShowElementInfo
  66. {
  67. get { return m_list_showelementinfo; }
  68. set { m_list_showelementinfo = value; }
  69. }
  70. /// <summary>
  71. /// 设置是否绘制分析Xray,默认为显示
  72. /// </summary>
  73. public bool ShowAnalysisXray
  74. {
  75. get { return m_b_show_analysisxray; }
  76. set { m_b_show_analysisxray = value; }
  77. }
  78. /// <summary>
  79. /// 显示颗粒相关信息
  80. /// </summary>
  81. public string ParticleInfo
  82. {
  83. get { return m_ParticleInfo; }
  84. set { m_ParticleInfo = value; }
  85. }
  86. #endregion
  87. #region 构造函数
  88. public Control_XRayTable()
  89. {
  90. InitializeComponent();
  91. }
  92. /// <summary>
  93. /// 需要确定下来倍数后,从xray最大值6000,转换成显示最大值150的比例转换
  94. /// </summary>
  95. /// <param name="in_value"></param>
  96. /// <returns></returns>
  97. private float GetValueByRatio(uint in_value)
  98. {
  99. return in_value / m_xraytopixel_multiple;
  100. }
  101. public void SetParticleInfo(string a_ParticleInfo)
  102. {
  103. m_ParticleInfo = a_ParticleInfo;
  104. }
  105. /// <summary>
  106. /// 设置搜索xray和分析xray值到,记录变量中,及转换成显示变量中,用来供XrayTable显示及计算使用
  107. /// </summary>
  108. /// <param name="search_xray"></param>
  109. /// <param name="analysis_xray"></param>
  110. public void SetXRayShowLineValue(uint[] analysis_xray, List<ShowElementInfo> in_list_showelementinfo)
  111. {
  112. //重新加载时,对当前的宽度等重新加载并计算
  113. m_i_draw_end = this.Width-20;
  114. m_Y_draw_end = this.Height-20;
  115. m_f_rulerX_location = m_Y_draw_end-75;
  116. m_i_smalkd = (m_i_draw_end- m_i_draw_start - 4) / m_i_smallkd_number;//按宽度重新计算小刻度的长度 -4是有4像素的边框差
  117. m_i_bigkd = (m_i_draw_end- m_i_draw_start - 4) / m_i_bigkd_number; //按宽度重新计算大刻度的长度
  118. #region 重新初始化相关全局变量
  119. m_list_periodic = CListPeriodic.GetListPeriodic();
  120. m_list_kmlfpoint = new List<KMLFPoint>();
  121. m_f_show2 = new float[2000];
  122. //用来保存实际传入的xray值数,用该数据转换成显示的值
  123. m_analysis_xray = new uint[2000];
  124. m_list_twopoint1 = new List<TwoPoint>();
  125. m_list_twopoint2 = new List<TwoPoint>();
  126. m_list_showelementinfo = new List<ShowElementInfo>();
  127. //初始化xray之和为0,之后开始进行求和计算
  128. m_xraysum2 = 0;
  129. //重新初始化高度比例尺
  130. m_xraytopixel_multiple = 0;
  131. #endregion
  132. //校验数据错误,防止空数据
  133. if (analysis_xray.Count() == 0)
  134. {
  135. return;
  136. }
  137. //再防止全数据为0
  138. uint ls_u_jcwl = 0;
  139. for (int i = 0; i < analysis_xray.Count(); i++)
  140. {
  141. if (analysis_xray[i] > ls_u_jcwl)
  142. ls_u_jcwl = analysis_xray[i];
  143. }
  144. if (ls_u_jcwl == 0)
  145. {
  146. return;
  147. }
  148. //比例尺,要根据传入的数据,自动进行计算的
  149. //逻辑那就应该是取最大的xray得到的值,加一点,然后除以我可以显示的像素分辨率,得到的倍数,后面都用这个倍数进行计算
  150. //取出最大的xray值,计算倍数---------------------------------------------------
  151. uint max_xra = 0;
  152. for (int i = 0; i < analysis_xray.Length; i++)
  153. {
  154. if (max_xra < analysis_xray[i])
  155. {
  156. max_xra = analysis_xray[i];
  157. }
  158. }
  159. //用最大的值除以可用来显示的像素,得到倍数
  160. m_xraytopixel_multiple = (float)(Convert.ToDouble(max_xra) / Convert.ToDouble(m_f_rulerX_location- m_Y_draw_TopDiff-20));
  161. //如果长度不是2000的话,不操作
  162. if (analysis_xray.Length == 2000)
  163. {
  164. //保存实际传入的值
  165. m_analysis_xray = analysis_xray;
  166. for (int i = 0; i < analysis_xray.Length; i++)
  167. {
  168. //这里按比例进行转换
  169. m_f_show2[i] = GetValueByRatio(analysis_xray[i]);
  170. m_xraysum2 = m_xraysum2 + analysis_xray[i];
  171. }
  172. }
  173. //生成xray对应的绘制线段
  174. float old_value = m_f_rulerX_location - 2;//从基础线-2的位置上进行绘制
  175. //float f_zl = 0.5f;//坐标值的增量,以小数做为增量的值,,,,这个坐标的增量应该根据实际的显示长度进行修改
  176. //当1000个像素时显示2000个数据,需要2000/1000=0.5f
  177. //0.5f就是2000个数据需要放到1000个像素中的计算系数
  178. double ls_width = m_i_draw_end;//改成固定值,整个绘制浪线的总长
  179. double ls_cs = 2000;
  180. m_f_zl = (float)((ls_width- m_i_draw_start - 4) / ls_cs);
  181. //计算KML峰值判定的上标值与下标值
  182. GetKMLFPD_MAXANDMIN(m_analysis_xray);
  183. for (int i = 0; i < m_f_show2.Length; i++)
  184. {
  185. TwoPoint tp = new TwoPoint();
  186. tp.pf1.X = i * m_f_zl;
  187. tp.pf1.Y = old_value;
  188. tp.pf2.X = i * m_f_zl + m_f_zl;
  189. tp.pf2.Y = m_f_rulerX_location - 2 - m_f_show2[i];
  190. tp.value = m_analysis_xray[i];
  191. tp.kmlf_value = (float)(Convert.ToDouble(i) / Convert.ToDouble(100));
  192. //重新实现计算峰值上显示元素的计算方法
  193. //CalcKMLFPoint(tp);
  194. old_value = m_f_rulerX_location - 2 - m_f_show2[i];
  195. m_list_twopoint2.Add(tp);
  196. }
  197. List<ShowElementInfo> in_list_showelementinfo2 = new List<ShowElementInfo>();
  198. if (in_list_showelementinfo != null)
  199. {
  200. if (in_list_showelementinfo.Count > 10) in_list_showelementinfo2 = in_list_showelementinfo.GetRange(0, 10);
  201. else in_list_showelementinfo2 = in_list_showelementinfo;
  202. //重新实现的计算峰值上显示元素的计算方法
  203. CalcKMLFPoint(in_list_showelementinfo2);
  204. m_list_showelementinfo = in_list_showelementinfo2;
  205. }
  206. this.Invalidate();
  207. }
  208. /// <summary>
  209. /// 根据传入的2000个峰值点,计算出有效参与计算的峰值判定高点,和低点,两个点
  210. /// </summary>
  211. /// <param name="in_xray"></param>
  212. /// <returns></returns>
  213. private void GetKMLFPD_MAXANDMIN(uint[] in_xray)
  214. {
  215. float f_lsmax = 0;
  216. //方法是,按50%为高点,10%为低点
  217. for (int i = 0; i < in_xray.Count(); i++)
  218. {
  219. if (f_lsmax < in_xray[i])
  220. {
  221. f_lsmax = in_xray[i];
  222. }
  223. }
  224. m_f_kmlfzpd_max = (float)(f_lsmax * 0.3);//最顶点的峰
  225. m_f_kmlfzpd_mix = (float)(f_lsmax * 0.1);
  226. return;
  227. }
  228. /// <summary>
  229. /// 根据传入的值,及获取的范围,来判断,该值大概为是什么元素的
  230. /// </summary>
  231. /// <param name="kml_value">传入的峰值</param>
  232. /// <param name="f_rect">范围</param>
  233. /// <returns></returns>
  234. private string GetElementNameByKMLRange(float kml_value, float f_rect)
  235. {
  236. string str_ret = "";
  237. float ls_f_sx1 = 0;
  238. float ls_f_sx2 = 0;
  239. float ls_f_sx3 = 0;
  240. for (int i = 0; i < m_list_periodic.Count(); i++)
  241. {
  242. //先对三个值进行转换,转出应有的值
  243. if (m_list_periodic[i].K_Peak != "" && m_list_periodic[i].K_Peak != "-")
  244. {
  245. ls_f_sx1 = (float)Convert.ToDouble(m_list_periodic[i].K_Peak);
  246. }
  247. if (m_list_periodic[i].L_Peak != "" && m_list_periodic[i].L_Peak != "-")
  248. {
  249. ls_f_sx2 = (float)Convert.ToDouble(m_list_periodic[i].L_Peak);
  250. }
  251. if (m_list_periodic[i].M_Peak != "" && m_list_periodic[i].M_Peak != "-")
  252. {
  253. ls_f_sx3 = (float)Convert.ToDouble(m_list_periodic[i].M_Peak);
  254. }
  255. //然后再对该值进行判断,如果在范围内,则判断为该元素
  256. if (kml_value >= (ls_f_sx1 - f_rect) && kml_value < (ls_f_sx1 + f_rect))
  257. {
  258. str_ret = m_list_periodic[i].Symbol;
  259. break;
  260. }
  261. if (kml_value >= (ls_f_sx2 - f_rect) && kml_value < (ls_f_sx2 + f_rect))
  262. {
  263. str_ret = m_list_periodic[i].Symbol;
  264. break;
  265. }
  266. if (kml_value >= (ls_f_sx3 - f_rect) && kml_value < (ls_f_sx3 + f_rect))
  267. {
  268. str_ret = m_list_periodic[i].Symbol;
  269. break;
  270. }
  271. }
  272. return str_ret;
  273. }
  274. /// <summary>
  275. /// 在循环遍历中,计算KML峰值中心点
  276. /// </summary>
  277. /// <param name="tp"></param>
  278. private void CalcKMLFPoint(TwoPoint tp)
  279. {
  280. //大于平均点值 max时,开始记录,2018-10-23重新实现
  281. if (tp.value > m_f_kmlfzpd_max)
  282. {
  283. m_kml_fz_top = tp.kmlf_value;
  284. }
  285. else if (tp.value < m_f_kmlfzpd_mix && m_kml_fz_top != 0)//平均小于平均峰值 min时,结束记录,并将峰值保存,记录峰值元素
  286. {
  287. //构造KML峰值list对象
  288. KMLFPoint ls_lkmfpoint = new KMLFPoint();
  289. ls_lkmfpoint.kml_x = m_kml_fz_top;
  290. //查找出该峰值是什么元素的, 待完成
  291. ls_lkmfpoint.ysm = GetElementNameByKMLRange(m_kml_fz_top, 0.2f);
  292. //将该峰值保存到峰值上
  293. m_list_kmlfpoint.Add(ls_lkmfpoint);
  294. m_Y_MaxValue = m_kml_fz_top;
  295. m_kml_fz_top = 0;
  296. }
  297. }
  298. private void CalcKMLFPoint(List<ShowElementInfo> in_list_showelementinfo)
  299. {
  300. for (int i = 0; i < in_list_showelementinfo.Count; i++)
  301. {
  302. KMLFPoint ls_lkmfpoint = new KMLFPoint();
  303. ls_lkmfpoint.ysm = in_list_showelementinfo[i].ElementName;
  304. ls_lkmfpoint.kml_x = (float)in_list_showelementinfo[i].dKF;
  305. ls_lkmfpoint.lml_x = (float)in_list_showelementinfo[i].dLF;
  306. //将该峰值保存到峰值上
  307. m_list_kmlfpoint.Add(ls_lkmfpoint);
  308. }
  309. }
  310. private void Control_XRayTable_Load(object sender, EventArgs e)
  311. {
  312. #region 设置背景透明及开启双缓冲
  313. //设置Style支持透明背景色
  314. this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  315. SetStyle(ControlStyles.UserPaint, true);
  316. SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
  317. this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // 双缓冲
  318. this.BackColor = Color.FromArgb(180, 255, 255, 255);
  319. #endregion
  320. //初始化变量,如果不初始化会在设计模式下报错
  321. m_list_showelementinfo = new List<ShowElementInfo>();
  322. }
  323. #endregion
  324. #region 绘制事件
  325. protected override void OnPaint(PaintEventArgs e)
  326. {
  327. Graphics g = e.Graphics;
  328. DrawXrayImage(g);
  329. }
  330. /// <summary>
  331. /// 封装绘制能谱数据方法
  332. /// </summary>
  333. /// <param name="g"></param>
  334. protected void DrawXrayImage(Graphics g)
  335. {
  336. #region //绘制标尺表盘部份----------------------------------------------------------------------------------------------
  337. //宽度比的缩放基数
  338. float f_js_width = 1;//经过考虑,先定为1,为固定的像素进行绘制
  339. #region 绘制下面的标尺
  340. //x轴标尺的线
  341. g.DrawLine(m_this_p, m_i_draw_start, m_f_rulerX_location, m_i_draw_end * f_js_width, m_f_rulerX_location);
  342. //y轴标尺的线
  343. g.DrawLine(m_this_p, m_i_draw_start, m_f_rulerX_location, m_i_draw_start, m_Y_draw_TopDiff);
  344. ////200个小刻度
  345. //for (int i = 0; i < m_i_smallkd_number; i++)
  346. //{
  347. // g.DrawLine(m_this_p, m_i_draw_start + (i * m_i_smalkd * f_js_width), m_f_rulerX_location, m_i_draw_start + (i * m_i_smalkd * f_js_width), m_f_rulerX_location + 5);
  348. //}
  349. int i_count = 0;
  350. //40个大刻度
  351. for (int i = 0; i < m_i_bigkd_number; i++)
  352. {
  353. g.DrawLine(m_this_p, m_i_draw_start + (i * m_i_bigkd * f_js_width), m_f_rulerX_location, m_i_draw_start + (i * m_i_bigkd * f_js_width), m_f_rulerX_location + 10);
  354. //每隔两刻度增长写字
  355. if (i % 2 == 0)
  356. {
  357. i_count++;
  358. g.DrawString((i_count - 1).ToString(), m_thisfont_bold, m_this_sb, m_i_draw_start + (i * m_i_bigkd * f_js_width) , m_f_rulerX_location + 10);
  359. }
  360. }
  361. float max_xra = 0;
  362. for (int i = 0; i < m_f_show2.Length; i++)
  363. {
  364. if (max_xra < m_f_show2[i])
  365. {
  366. max_xra = m_f_show2[i];
  367. }
  368. }
  369. int m_Y_Value_Count = (int)Math.Floor(max_xra / 25);
  370. m_Y_Value = (uint)(m_Y_Value_Count/4) * 25;
  371. if(m_Y_Value==0)
  372. {
  373. m_Y_Value = (uint)Math.Floor(max_xra / 2);
  374. }
  375. if (m_xraytopixel_multiple != 0)
  376. {
  377. //纵坐标
  378. for (int i = 0; i < 30; i++)
  379. {
  380. if (i * m_Y_Value <= max_xra)
  381. {
  382. g.DrawLine(m_this_p, m_i_draw_start, m_f_rulerX_location - (i * m_Y_Value * f_js_width), m_i_draw_start + 3, m_f_rulerX_location - (i * m_Y_Value * f_js_width));
  383. int aa = i * Convert.ToInt16(m_Y_Value);
  384. g.DrawString(aa.ToString(), m_thisfont_bold, m_this_sb, m_i_draw_start - 10 - ((aa.ToString().Length - 1) * 6), m_f_rulerX_location - (i * m_Y_Value * f_js_width) - 7);
  385. }
  386. }
  387. }
  388. //补充输入文字,为了美观
  389. //g.DrawString("kv", m_thisfont_bold, m_this_sb, 8, m_f_rulerX_location + 10);
  390. Font m_thisfont_bold2 = new Font("微软雅黑", 11, FontStyle.Bold);
  391. g.DrawString("Kev", m_thisfont_bold2, m_this_sb, (m_i_draw_end- m_i_draw_start) / 2+m_i_draw_start, m_f_rulerX_location + 23);
  392. g.TranslateTransform(m_i_draw_start-45, m_f_rulerX_location-25); // 移动到绘图起始点
  393. g.RotateTransform(-90); // 逆时针旋转90度
  394. g.DrawString("Counts", m_thisfont_bold2, m_this_sb, 0,0);
  395. g.ResetTransform();
  396. #endregion
  397. #region 绘制x-ray线的边框
  398. //x-ray画线的左边线
  399. g.DrawLine(m_this_p, m_i_draw_start, m_i_draw_start + m_Y_draw_TopDiff, m_i_draw_start * f_js_width, m_f_rulerX_location - 2);
  400. //x-ray画线的底盘
  401. //g.DrawLine(m_this_p, m_i_draw_start, m_f_rulerX_location - 2, m_i_draw_end* f_js_width, m_f_rulerX_location - 2);
  402. #endregion
  403. #endregion //--------------------------------------------------------------------------------------------------------
  404. #region 绘制波浪线及线上文字--------------------------------------------------------------------------------------
  405. if (m_b_show_analysisxray == true)
  406. {
  407. //画波浪线----第二条线
  408. for (int i = 0; i < m_list_twopoint2.Count(); i++)
  409. {
  410. PointF ls_pf1_2 = m_list_twopoint2[i].pf1;
  411. ls_pf1_2.X = (ls_pf1_2.X) * f_js_width+ m_i_draw_start ;
  412. PointF ls_pf2_2 = m_list_twopoint2[i].pf2;
  413. ls_pf2_2.X = (ls_pf2_2.X) * f_js_width+ m_i_draw_start ;
  414. g.DrawLine(m_this_p_blue, ls_pf1_2, ls_pf2_2);
  415. //找到最高值再输出的方式
  416. //if (list_twopoint2[i].pf2.Y < 60)
  417. //{
  418. // g.DrawString(list_twopoint2[i].value.ToString() + "@ev", thisfont_bold, this_sb_blue, list_twopoint2[i].pf2.X + 3, list_twopoint2[i].pf2.Y);
  419. //}
  420. }
  421. }
  422. #endregion //----------------------------------------------------------------------------------------------------------------
  423. #region //绘制峰值上的线-----------------------------------------------------------------------------------------------
  424. if (m_list_kmlfpoint != null)
  425. {
  426. for (int i = 0; i < m_list_kmlfpoint.Count(); i++)
  427. {
  428. //为了让元素标签不在同一高度显示,为了美观,也是防止会重叠,所以这里计算一下
  429. int i_py = 0;//设置元素标签的偏移
  430. if (i % 2 == 1)
  431. i_py = 0;
  432. else
  433. i_py = 20;
  434. //绘制竖线
  435. g.DrawLine(new Pen(Color.Wheat, 0.5f), f_js_width * (m_list_kmlfpoint[i].kml_x * ((m_i_draw_end- m_i_draw_start - 4) / 20)) + m_i_draw_start, m_f_rulerX_location / 3 + i_py, f_js_width * (m_list_kmlfpoint[i].kml_x * ((m_i_draw_end - m_i_draw_start - 4) / 20) + m_i_draw_start), m_f_rulerX_location - 3);
  436. //输出文字,并将字输出到线的上面
  437. SizeF out_testsizef = g.MeasureString(m_list_kmlfpoint[i].ysm, m_thisfont);
  438. PointF ut_test_pointF = new PointF(m_mouse_point.X - (out_testsizef.Width / 2), 2);
  439. g.FillRectangle(Brushes.Goldenrod, new RectangleF(new PointF(f_js_width * ((m_list_kmlfpoint[i].kml_x * ((m_i_draw_end - m_i_draw_start - 4) / 20)) + m_i_draw_start - out_testsizef.Width / 2), m_f_rulerX_location / 3 - 20 + i_py), out_testsizef));
  440. g.DrawString(m_list_kmlfpoint[i].ysm,
  441. m_thisfont_bold,
  442. m_this_sb,
  443. new PointF(f_js_width * ((m_list_kmlfpoint[i].kml_x * ((m_i_draw_end - m_i_draw_start - 4) / 20)) + m_i_draw_start - out_testsizef.Width / 2), m_f_rulerX_location / 3 - 20 + i_py));
  444. if (m_list_kmlfpoint[i].lml_x != 0)
  445. {
  446. //绘制竖线
  447. g.DrawLine(new Pen(Color.Wheat, 0.5f), f_js_width * (m_list_kmlfpoint[i].lml_x * ((m_i_draw_end - m_i_draw_start - 4) / 20)) + m_i_draw_start, m_f_rulerX_location / 3 + i_py, f_js_width * (m_list_kmlfpoint[i].lml_x * ((m_i_draw_end - m_i_draw_start - 4) / 20) + m_i_draw_start), m_f_rulerX_location - 3);
  448. //输出文字,并将字输出到线的上面
  449. SizeF out_testsizef2 = g.MeasureString(m_list_kmlfpoint[i].ysm, m_thisfont);
  450. PointF ut_test_pointF2 = new PointF(m_mouse_point.X - (out_testsizef.Width / 2), 2);
  451. g.FillRectangle(Brushes.Goldenrod, new RectangleF(new PointF(f_js_width * ((m_list_kmlfpoint[i].lml_x * ((m_i_draw_end - m_i_draw_start - 4) / 20))+ m_i_draw_start - out_testsizef.Width / 2), m_f_rulerX_location / 3 - 20 + i_py), out_testsizef));
  452. g.DrawString(m_list_kmlfpoint[i].ysm,
  453. m_thisfont_bold,
  454. m_this_sb,
  455. new PointF(f_js_width * ((m_list_kmlfpoint[i].lml_x * ((m_i_draw_end - m_i_draw_start - 4) / 20)) + m_i_draw_start - out_testsizef.Width / 2), m_f_rulerX_location / 3 - 20 + i_py));
  456. }
  457. }
  458. }
  459. #endregion
  460. #region 绘制鼠标移动显示的线及线上文字---------------------------------------------------------------------------------------
  461. //再绘制鼠标所在位置的竖线---------------------第一条线
  462. g.DrawLine(m_mousemove_p, m_mouse_point.X, m_i_draw_start, m_mouse_point.X, m_f_rulerX_location - 3);
  463. string ls_label_str = "";
  464. for (int i = 0; i < m_list_twopoint2.Count(); i++)
  465. {
  466. //判断要按条件进行显示,值大于200才进行显示,用循环i的位置进行判断,在不变动这些数组时,这种写法是正确的
  467. if (m_analysis_xray[i] > m_f_kmlfzpd_mix)
  468. {
  469. //用绘线线段,的起始点与鼠标当前位置进行对应上的话,那么就进行取kmlf值,进行显示
  470. if (Convert.ToInt32(m_list_twopoint2[i].pf1.X * f_js_width) == m_mouse_point.X+ m_i_draw_start)
  471. {
  472. ls_label_str = m_list_twopoint2[i].kmlf_value.ToString();
  473. }
  474. if (Convert.ToInt32(m_list_twopoint2[i].pf2.X * f_js_width) == m_mouse_point.X + m_i_draw_start)
  475. {
  476. ls_label_str = m_list_twopoint2[i].kmlf_value.ToString();
  477. }
  478. }
  479. }
  480. if (ls_label_str != "")
  481. ls_label_str = Convert.ToDouble(ls_label_str).ToString("0.000");//显示浮点数,为了美观
  482. //绘制鼠标竖线上的定位文字
  483. SizeF sizeF = g.MeasureString(ls_label_str, m_thisfont);
  484. PointF pointF = new PointF(m_mouse_point.X - (sizeF.Width / 2), 2);
  485. g.FillRectangle(Brushes.SkyBlue, new RectangleF(pointF, sizeF));
  486. g.DrawString(ls_label_str, m_thisfont_bold, m_this_sb, pointF);
  487. #endregion
  488. #region //右上角输出文字设置-------------------------------------------------------------------------------------------------
  489. m_i_rightdrawlabellocation_x = m_i_draw_end * f_js_width - 260;
  490. //国际化
  491. Language lan = new Language();
  492. Hashtable table = lan.GetNameTable("Control_XRayTable");
  493. string str1 = table["str1"].ToString();
  494. string str2 = table["str2"].ToString();
  495. g.DrawString(str1, m_thisfont, m_this_sb, new PointF(m_i_rightdrawlabellocation_x, m_i_rightdrawlabellocation_y + 20));
  496. //g.DrawString("高度比例尺:", m_thisfont, m_this_sb, new PointF(m_i_rightdrawlabellocation_x, m_i_rightdrawlabellocation_y + 20));
  497. g.DrawString(str2, m_thisfont, m_this_sb, new PointF(m_i_rightdrawlabellocation_x, m_i_rightdrawlabellocation_y + 40));
  498. //计算值显示,计数率
  499. g.DrawString(m_xraysum2.ToString(), m_thisfont_bold, m_this_sb, new PointF(m_i_rightdrawlabellocation_x + 50, m_i_rightdrawlabellocation_y + 20));
  500. //高度比例尺值显示
  501. //g.DrawString(m_xraytopixel_multiple.ToString("0.0"), m_thisfont_bold, m_this_sb, new PointF(m_i_rightdrawlabellocation_x + 50, m_i_rightdrawlabellocation_y + 20));
  502. //show element list information,using the elementlist number to make sure width,number take width 25 growth
  503. if (m_list_showelementinfo != null)
  504. {
  505. //make it 100%
  506. double sumpercentage = 0;
  507. for (int i = 0; i < m_list_showelementinfo.Count; i++)
  508. {
  509. sumpercentage += m_list_showelementinfo[i].Percentage;
  510. }
  511. for (int i = 0; i < m_list_showelementinfo.Count; i++)
  512. {
  513. m_list_showelementinfo[i].percentageIn100 = m_list_showelementinfo[i].Percentage / sumpercentage * 100;
  514. }
  515. StringBuilder sb = new StringBuilder();
  516. for (int i = 0; i < m_list_showelementinfo.Count; i++)
  517. {
  518. if (i > 6&& m_list_showelementinfo[i].Percentage<0.1) break;
  519. sb.Append(m_list_showelementinfo[i].ElementName);
  520. sb.Append("(");
  521. sb.Append(m_list_showelementinfo[i].Percentage.ToString("0.00) "));
  522. }
  523. sb.Append("\n");
  524. sb.Append(m_ParticleInfo);
  525. string str_element = sb.ToString();
  526. SizeF out_testsizef = g.MeasureString(str_element, m_thisfont);
  527. PointF ls_pt = new PointF(m_i_rightdrawlabellocation_x , m_i_rightdrawlabellocation_y + 42);
  528. ls_pt.X = m_i_rightdrawlabellocation_x + 50;
  529. g.DrawString(str_element, m_thisfont_bold, new SolidBrush(Color.Black), ls_pt);
  530. }
  531. #endregion //------------------------------------------------------------------------------------------------------------------
  532. }
  533. #endregion
  534. #region 鼠标移动事件
  535. protected override void OnMouseMove(MouseEventArgs e)
  536. {
  537. //记录鼠标移动到的点,用来绘制用
  538. m_mouse_point = new Point(e.X, e.Y);
  539. this.Invalidate();
  540. }
  541. #endregion
  542. private void label_close_Click(object sender, EventArgs e)
  543. {
  544. this.Visible = false;
  545. }
  546. }
  547. #region 用来显示连接线封装的类
  548. /// <summary>
  549. /// 封装两个点的一个类
  550. /// </summary>
  551. [Serializable]
  552. public class TwoPoint
  553. {
  554. public PointF pf1;
  555. public PointF pf2;
  556. public float value;
  557. public float kmlf_value;
  558. }
  559. /// <summary>
  560. /// 记录显示的KML峰值类,分别记录kml峰值的x坐标,和峰值对应的一左一右的元素名
  561. /// </summary>
  562. [Serializable]
  563. public class KMLFPoint
  564. {
  565. public float kml_x;
  566. public float lml_x;
  567. public string ysm;
  568. }
  569. /// <summary>
  570. /// show x-ray info with element list,the element information class
  571. /// </summary>
  572. [Serializable]
  573. public class ShowElementInfo
  574. {
  575. public string ElementName;
  576. public double Percentage;//实际能谱返回的质量百分比
  577. public double dKF;//K峰,元素周期表中固定值
  578. public double dLF;//L峰
  579. public double percentageIn100;//归一化后的百分比
  580. }
  581. #endregion
  582. }