Control_XRayTable.cs 34 KB

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