Control_XRayTable.cs 34 KB

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