OTSIncAReportFun.cs 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461
  1. 
  2. using NSOTSController;
  3. using OTSIncAReportApp.DataOperation.DataAccess;
  4. using OTSIncAReportApp.DataOperation.Model;
  5. using OTSIncAReportApp.SysMgrTools;
  6. using OTSIncAReportGraph.Class;
  7. using OTSIncAReportGraph.Controls;
  8. using System;
  9. using System.Collections;
  10. using System.Collections.Generic;
  11. using System.Data;
  12. using System.Diagnostics;
  13. using System.Drawing;
  14. using System.Linq;
  15. namespace OTSIncAReportGraph.OTSIncAReportGraphFuncation
  16. {
  17. class OTSIncAReportFun
  18. {
  19. #region 枚举定义
  20. /// <summary>
  21. /// 样品台X轴方向
  22. /// </summary>
  23. enum OTS_X_AXIS_DIRECTION
  24. {
  25. LEFT_TOWARD = 0,
  26. RIGHT_TOWARD = 1
  27. }
  28. /// <summary>
  29. /// 样品台Y轴方向
  30. /// </summary>
  31. enum OTS_Y_AXIS_DIRECTION
  32. {
  33. UP_TOWARD = 0,
  34. DOWN_TOWARD = 1
  35. }
  36. #endregion
  37. #region 定义变量
  38. private ResultFile resultFile = null;
  39. //新版排序图窗体对象
  40. private Control_DrawDistrbutionSortImage m_Control_DrawdistrbutionsortImage = null;
  41. //新版分布图和BSE图整合对象
  42. private Control_DrawDistrbutionImageAndBSE m_Control_DrawDistrbutionImageAndBSE = null;
  43. //全局对象,为了能够快速的获取到xray数据,而做为一个临时变量进行保存,使用前应该判断是否为空
  44. public List<Field> m_list_COTSFieldMgrClr = null;
  45. NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
  46. //field的数量
  47. public int m_field_count = 0;
  48. //particle的数量
  49. public int m_particle_count = 0;
  50. //加载使用的时间
  51. public string m_time_str = "";
  52. //加载使用时间计算时间段2
  53. public string m_time_str2 = "";
  54. //防止segment过多的数量限制,先写300吧,过少也不好,过防止过多程序而卡死
  55. public int m_segment_overflownumber = 400;
  56. //电镜设置对象
  57. public NSOTSController.COTSControlFunExport m_cfun = null;
  58. //是否已经连接到了电镜
  59. public bool m_SEMConnectionState = false;
  60. //连接到电镜的ID号
  61. public int m_SEM_ID = 0;
  62. //国际化
  63. Language lan = new Language();
  64. Hashtable table;
  65. #endregion
  66. #region 构造函数
  67. /// <summary>
  68. /// 构造函数,接收新版分布图和排序图的构造函数
  69. /// </summary>
  70. /// <param name="in_Control_DrawDistrbutionImageAndBSE"></param>
  71. /// <param name="in_Cotsreportprojfilemgrclr"></param>
  72. public OTSIncAReportFun(Control_DrawDistrbutionImageAndBSE in_Control_DrawDistrbutionImageAndBSE, ResultFile result)
  73. {
  74. m_Control_DrawDistrbutionImageAndBSE = in_Control_DrawDistrbutionImageAndBSE;
  75. resultFile = result;
  76. m_cfun = new COTSControlFunExport();//重新new一下试试呢,不New并不好用 It's better to reinitialize, but it's not good to uninitialize
  77. table = lan.GetNameTable("OTSIncAReportFun");
  78. }
  79. /// <summary>
  80. /// 构造函数,接收新版颗粒排序图的构造
  81. /// </summary>
  82. /// <param name="in_Control_DrawDistrbutionSortimage"></param>
  83. /// <param name="in_Cotsreportprojfilemgrclr"></param>
  84. public OTSIncAReportFun(Control_DrawDistrbutionSortImage in_Control_DrawDistrbutionSortimage, ResultFile result)
  85. {
  86. m_Control_DrawdistrbutionsortImage = in_Control_DrawDistrbutionSortimage;
  87. resultFile = result;
  88. m_cfun = new COTSControlFunExport();//重新new一下试试呢,不New并不好用 It's better to reinitialize, but it's not good to uninitialize
  89. table = lan.GetNameTable("OTSIncAReportFun");
  90. }
  91. #endregion
  92. #region 封装自定义方法
  93. /// <summary>
  94. /// 根据颗粒排序图获取已经选择上的颗粒,返回被选择上的颗粒的列表
  95. /// </summary>
  96. /// <returns></returns>
  97. public List<Particle> GetSelectedParticleList_ForDrawDistrbutionImageAndBSE()
  98. {
  99. List<Particle> ls_list_cotsparticleclr = new List<Particle>();
  100. //防止为空校验判断
  101. if (m_list_COTSFieldMgrClr == null)
  102. return ls_list_cotsparticleclr;
  103. //先取出,所有被选择的dparticle列表的
  104. List<DParticle> ls_list_dp = new List<DParticle>();
  105. foreach (DParticle ls_dp in m_Control_DrawDistrbutionImageAndBSE.m_list_baseobject)
  106. {
  107. if (ls_dp.Operator == ParticleOperator.SELECTED)
  108. {
  109. ls_list_dp.Add(ls_dp);
  110. }
  111. }
  112. //并开始查找包含tagid和fieldid的cotsparticle的对象,保存到list当中
  113. for (int i = 0; i < ls_list_dp.Count(); i++)
  114. {
  115. for (int j = 0; j < m_list_COTSFieldMgrClr.Count(); j++)
  116. {
  117. //先获取该field中的所有particle
  118. List<Particle> list_cotsparticleclr = new List<Particle>();
  119. list_cotsparticleclr = m_list_COTSFieldMgrClr[j].ParticleList;
  120. for (int k = 0; k < list_cotsparticleclr.Count(); k++)
  121. {
  122. if (list_cotsparticleclr[k].ParticleId == ls_list_dp[i].CLRTagID
  123. && list_cotsparticleclr[k].FieldId == ls_list_dp[i].CLRFieldID)
  124. {
  125. ls_list_cotsparticleclr.Add(list_cotsparticleclr[k]);
  126. }
  127. }
  128. }
  129. }
  130. return ls_list_cotsparticleclr;
  131. }
  132. /// <summary>
  133. /// 计算像素总画面Image大小,及进行物理坐标与分辨率坐标的换算操作 传入物理坐标,及宽高,来
  134. /// </summary>
  135. /// <param name="in_list_point">传入的物理坐标数组</param>
  136. /// <param name="width">单个field宽</param>
  137. /// <param name="height">单个field高</param>
  138. /// <returns></returns>
  139. public Rectangle ConvertAndGetMaxRect(List<Point> in_list_point, int in_width, int in_height)
  140. {
  141. //首先要能确定下来,单个物理坐标的宽和高--------------------------------
  142. int i_wl_width = 0;
  143. int i_wl_height = 0;
  144. Rectangle ls_r = GetOneFieldWidthAndHeight(in_list_point);
  145. i_wl_width = ls_r.Width;
  146. i_wl_height = ls_r.Height;
  147. //-----------------------------------------------------------------------------
  148. int point_x_min = 10000000;
  149. int point_x_max = -10000000;
  150. int point_y_min = 10000000;
  151. int point_y_max = -10000000;
  152. for (int i = 0; i < in_list_point.Count(); i++)
  153. {
  154. Point ls_point = in_list_point[i];
  155. //取出正数最大x
  156. if (ls_point.X > point_x_max)
  157. point_x_max = ls_point.X;
  158. if (ls_point.Y > point_y_max)
  159. point_y_max = ls_point.Y;
  160. if (ls_point.X < point_x_min)
  161. point_x_min = ls_point.X;
  162. if (ls_point.Y < point_y_min)
  163. point_y_min = ls_point.Y;
  164. }
  165. //然后分别用最大值+abs(最小值),就是x,和y轴的总长值
  166. point_x_max = point_x_max - point_x_min;
  167. point_y_max = point_y_max - point_y_min;
  168. //该算法有个问题,就是不能直观的得到整个范围的大小,要除以倍数再补1能补充缺少的一个field视域**********
  169. point_x_max = ((point_x_max / i_wl_width) + 1) * i_wl_width;
  170. point_y_max = ((point_y_max / i_wl_height) + 1) * i_wl_height;
  171. //将物理宽高,变换成分辨率宽高
  172. if (i_wl_width != 0) point_x_max = (point_x_max / i_wl_width) * in_width; else point_x_max = 0;
  173. if (i_wl_height != 0) point_y_max = (point_y_max / i_wl_height) * in_height; else point_y_max = 0;
  174. Rectangle ret_rectangle = new Rectangle(0, 0, 0, 0);
  175. //判断一下防止出错,只有在有数据的情况下,进行赋值才行
  176. if (in_list_point.Count > 0)
  177. {
  178. ret_rectangle = new Rectangle(0, 0, point_x_max, point_y_max);
  179. }
  180. //这样返回是物理坐标的总大小,应该返回像素坐标大小才对
  181. return ret_rectangle;
  182. }
  183. /// <summary>
  184. /// 通过传入的各field物理坐标列表,和单个field的屏幕分辨率,及单个的field的物理坐标,来获取当前field在整个image中的屏幕像素坐标偏移,并且是OTS向上为正做了Y轴相反运算
  185. /// </summary>
  186. /// <param name="in_list_point"></param>
  187. /// <param name="in_screen_width"></param>
  188. /// <param name="in_screen_height"></param>
  189. /// <param name="in_physics_width"></param>
  190. /// <param name="in_physics_height"></param>
  191. /// <returns></returns>
  192. public Point GetFieldPhysicsConvertToScreen(List<Point> in_list_point, int in_screen_width, int in_screen_height, Point in_physics_point)
  193. {
  194. //先确定单个物理坐标的宽和高
  195. Rectangle rect_onefield_wl = GetOneFieldWidthAndHeight(in_list_point);
  196. //找出最小的x,y用来做偏移运算
  197. int i_offset_x = 1000000000;
  198. int i_offset_y = 1000000000;
  199. //先取出最小的x,y
  200. for (int i = 0; i < in_list_point.Count; i++)
  201. {
  202. if (i_offset_x > in_list_point[i].X)
  203. {
  204. i_offset_x = in_list_point[i].X;
  205. }
  206. if (i_offset_y > in_list_point[i].Y)
  207. {
  208. i_offset_y = in_list_point[i].Y;
  209. }
  210. }
  211. List<Point> list_point = new List<Point>();
  212. //将各Field的OTS坐标与屏幕左上角的坐标进行相减,取出与屏幕左上角的偏移量,也就是取出了屏幕坐标
  213. int index = 0;
  214. for (int i = 0; i < in_list_point.Count; i++)
  215. {
  216. list_point.Add(new Point(in_list_point[i].X - i_offset_x, in_list_point[i].Y - i_offset_y));
  217. //根据物理坐标的对应关系,找到了在数组中的位置,下面将用该位置对应得出像素坐标的位置,并进行返回
  218. if (in_list_point[i] == in_physics_point)
  219. {
  220. index = i;
  221. }
  222. }
  223. //再将物理像素list_point换算成像素list_point,再用index定位
  224. for (int i = 0; i < list_point.Count; i++)
  225. {
  226. //将单个物理像素变换成屏幕像素分辨率
  227. int i_bs_x = 0;
  228. int i_bs_y = 0;
  229. if (rect_onefield_wl.Width != 0)
  230. i_bs_x = list_point[i].X / rect_onefield_wl.Width;
  231. if (rect_onefield_wl.Height != 0)
  232. i_bs_y = list_point[i].Y / rect_onefield_wl.Height;
  233. //再将屏幕像素分辨率按倍数赋值给list_point
  234. //考虑到OTS坐标整体是Y轴向上为正,所以这里需要根据总高,减y轴就是向上为正
  235. list_point[i] = new Point(in_screen_width * i_bs_x, in_screen_height * i_bs_y);
  236. }
  237. #region Y轴向上为正转换---------------------------------------------------------------------------------------
  238. //但上面由于相减,会出现y轴为负的情况,所以这里要根据Y轴是否出现负值,再次做偏移运算
  239. //找到最小的y轴,也就是 [Y轴偏移量]
  240. int i_offset_y_second = 100000000;
  241. //找到最大的Y轴,用于做相反运算,Y轴向上
  242. int i_screen_y = -100000000;
  243. for (int i = 0; i < list_point.Count; i++)
  244. {
  245. if (i_offset_y_second > list_point[i].Y)
  246. {
  247. i_offset_y_second = list_point[i].Y;//这个偏移Y就是最小的Y,可能是负数,也可能是0
  248. }
  249. if (i_screen_y < list_point[i].Y)
  250. {
  251. i_screen_y = list_point[i].Y;
  252. }
  253. }
  254. //对Y轴进行反转,OTS坐标向屏幕坐标转换
  255. for (int i = 0; i < list_point.Count; i++)
  256. {
  257. list_point[i] = new Point(list_point[i].X, i_screen_y - list_point[i].Y);
  258. }
  259. //再将所有的Field与这个 [Y轴偏移量] 相加,防止OTS向上为正转换屏幕坐标,造成的Y轴为负的情况
  260. for (int i = 0; i < list_point.Count; i++)
  261. {
  262. list_point[i] = new Point(list_point[i].X, list_point[i].Y + Math.Abs(i_offset_y_second));
  263. }
  264. #endregion Y轴向上为正转换结束--------------------------------------------------------------------------
  265. return list_point[index];
  266. }
  267. /// <summary>
  268. /// 计算单个field的物理大小 传入field的list,还有测量结果管理类对象,在无法计算出单file的物理大小的情况下,到这里取再计算得出
  269. /// </summary>
  270. /// <returns></returns>
  271. public Rectangle GetOneFieldWidthAndHeight(List<Point> in_list_point)
  272. {
  273. int i_wl_width_max = -10000000;
  274. int i_wl_height_max = -10000000;
  275. int i_wl_width_max2 = -10000000;
  276. int i_wl_height_max2 = -10000000;
  277. //先找出最大的值,
  278. for (int i = 0; i < in_list_point.Count(); i++)
  279. {
  280. if (i_wl_width_max < in_list_point[i].X)
  281. i_wl_width_max = in_list_point[i].X;
  282. if (i_wl_height_max < in_list_point[i].Y)
  283. i_wl_height_max = in_list_point[i].Y;
  284. }
  285. //再找出第二大的值
  286. for (int i = 0; i < in_list_point.Count(); i++)
  287. {
  288. if (i_wl_width_max2 < in_list_point[i].X && i_wl_width_max != in_list_point[i].X)
  289. i_wl_width_max2 = in_list_point[i].X;
  290. if (i_wl_height_max2 < in_list_point[i].Y && i_wl_height_max != in_list_point[i].Y)
  291. i_wl_height_max2 = in_list_point[i].Y;
  292. }
  293. //需要针对第二大的值,获取时进行判断,感觉这里应该如果并未找到第二大的值的情况下,赋于0值,便于以后进行计算
  294. if (i_wl_width_max2 == -10000000)
  295. i_wl_width_max2 = 0;
  296. if (i_wl_height_max2 == -10000000)
  297. i_wl_height_max2 = 0;
  298. Rectangle ret_rect = new Rectangle(0, 0, i_wl_width_max - i_wl_width_max2, i_wl_height_max - i_wl_height_max2);
  299. //如果最后计算出的宽高有0则重新到测量数据中获取---------------------------------------
  300. if (ret_rect.Width == 0 || ret_rect.Height == 0)
  301. {
  302. //到参数中去取单个宽
  303. double d_onefilesize_width = Convert.ToDouble(((Dictionary<string, object>)resultFile.ResultInfo["SEMStageData"])["scanFieldSize"]);
  304. //然后再用单个宽去计算出高是多少
  305. double d_onefilesize_height = 0;
  306. if (d_onefilesize_width != 0)
  307. d_onefilesize_height = (d_onefilesize_width / 4) * 3;
  308. ret_rect.Width = (int)d_onefilesize_width;
  309. ret_rect.Height = (int)d_onefilesize_height;
  310. }
  311. ///-----------because all the fields 's height/width=0.75 so here we make an enforce. gsp add at 2019/10/31
  312. ///sometimes the gbfields are not conform to this for the cuting and merging operation.
  313. if (ret_rect.Height / ret_rect.Width != 0.75f)
  314. {
  315. ret_rect = new Rectangle(ret_rect.X, ret_rect.Y, ret_rect.Width, (int)(ret_rect.Width * 0.75f));
  316. }
  317. return ret_rect;
  318. }
  319. #endregion
  320. #region 电镜操作相关方法
  321. /// <summary>
  322. /// 连接电镜,分布图使用
  323. /// </summary>
  324. public void ConnectToSEM()
  325. {
  326. if (m_cfun == null)
  327. {
  328. m_cfun = new COTSControlFunExport();
  329. }
  330. log.Trace("(Connection_ForDrawDistrbutionImageAndBSE)" + "Connect to SEM");
  331. if (!m_SEMConnectionState)
  332. {
  333. //和电镜建立通讯连接
  334. m_SEMConnectionState = m_cfun.ConncetSem();
  335. log.Trace("(Connection_ForDrawDistrbutionImageAndBSE)" + "Connect to SEM" + ":--" + m_SEMConnectionState + "---");
  336. ///获取当前电镜的ID号
  337. m_SEM_ID = m_cfun.GetSemType();
  338. log.Trace("(Connection_ForDrawDistrbutionImageAndBSE)" + "ID:" + m_SEM_ID.ToString());
  339. }
  340. else
  341. {
  342. log.Trace("(Connection_ForDrawDistrbutionImageAndBSE)" + ":allready connected, state:" + m_SEMConnectionState);
  343. //断开电镜连接
  344. }
  345. }
  346. /// <summary>
  347. /// 移动电镜到指定的X,Y坐标上,R坐标使用原先的值进行移动
  348. /// </summary>
  349. /// <param name="PositionX"></param>
  350. /// <param name="PositionY"></param>
  351. public void MoveSemToPointXY(double in_PositionX, double in_PositionY)
  352. {
  353. log.Trace("Begin MoveSemToPointXY:(" +in_PositionX.ToString()+","+in_PositionY.ToString()+")");
  354. //首先获取电镜当前的位置,并记录原R值
  355. double ls_PositionX = 0;
  356. double ls_PositionY = 0;
  357. double ls_PositionR = 0;
  358. if (m_SEMConnectionState)
  359. {
  360. m_cfun.GetSemPositionXY(ref ls_PositionX, ref ls_PositionY, ref ls_PositionR);
  361. }
  362. else
  363. {
  364. log.Error("Failed to MoveSemToPointXY" );
  365. }
  366. if (m_SEMConnectionState)
  367. {
  368. m_cfun.MoveSEMToPoint(in_PositionX, in_PositionY, ls_PositionR);
  369. }
  370. }
  371. /// <summary>
  372. /// 断开电镜连接
  373. /// </summary>
  374. public void DisConnectSEM()
  375. {
  376. log.Trace("(DisConnectSEM_ForDrawDistrbutionImageAndBSE)" );
  377. m_cfun.DisconnectSem();
  378. /// <summary>
  379. m_SEMConnectionState = false;
  380. }
  381. #endregion
  382. #region //--------------------------------------颗粒分布图相关部份---------------------------------------------------------------------
  383. /// <summary>
  384. /// 传入颗粒的tagid和fieldid,来获取该颗粒下对应的xray数据
  385. /// </summary>
  386. /// <param name="in_clr_tagid"></param>
  387. /// <param name="in_clr_fieldid"></param>
  388. /// <param name="Search_xray"></param>
  389. /// <param name="Analysis_xray"></param>
  390. public void GetXrayByParticleTagIDAndFieldID_ForDrawDistrbutionImageAndBSE(int in_clr_tagid, int in_clr_fieldid, out uint[] Search_xray, out uint[] Analysis_xray, out int xray_id, out List<Element> list_celementchemistryclr)
  391. {
  392. Search_xray = new uint[2000];
  393. Analysis_xray = new uint[2000];
  394. xray_id = 0;
  395. list_celementchemistryclr = new List<Element>();
  396. //防止为空校验判断
  397. if (m_list_COTSFieldMgrClr == null)
  398. return;
  399. Particle particle = m_list_COTSFieldMgrClr.Find(x => x.FieldID == in_clr_fieldid).ParticleList.Find(x => x.ParticleId == in_clr_tagid);
  400. if (particle.XrayId > -1)
  401. {
  402. for (int i = 0; i < 2000; i++)
  403. {
  404. Analysis_xray[i] = BitConverter.ToUInt32(particle.XRayData, i * 4);
  405. }
  406. Search_xray = Analysis_xray;
  407. xray_id = particle.XrayId;
  408. list_celementchemistryclr = particle.ElementList;
  409. }
  410. }
  411. /// <summary>
  412. /// 传入所有的物理field坐标点,和单个物理field的宽高,返回所有field的左上角位置,和整个field组成的rect大小
  413. /// </summary>
  414. /// <param name="in_list_point"></param>
  415. /// <param name="in_width"></param>
  416. /// <param name="in_height"></param>
  417. /// <returns></returns>
  418. public Rectangle GetWlRectTopLeftAndRect(List<Point> in_list_point, int in_width, int in_height)
  419. {
  420. //分别获取整个rect的xy最小值和最大值
  421. int i_rect_x_min = 100000000;
  422. int i_rect_y_min = 100000000;
  423. int i_rect_x_max = -100000000;
  424. int i_rect_y_max = -100000000;
  425. for (int i = 0; i < in_list_point.Count; i++)
  426. {
  427. if (i_rect_x_min > in_list_point[i].X)
  428. i_rect_x_min = in_list_point[i].X;
  429. if (i_rect_y_min > in_list_point[i].Y)
  430. i_rect_y_min = in_list_point[i].Y;
  431. if (i_rect_x_max < in_list_point[i].X)
  432. i_rect_x_max = in_list_point[i].X;
  433. if (i_rect_y_max < in_list_point[i].Y)
  434. i_rect_y_max = in_list_point[i].Y;
  435. }
  436. Rectangle ret_rect = new Rectangle(i_rect_x_min, i_rect_y_min,
  437. i_rect_x_max - i_rect_x_min, i_rect_y_max - i_rect_y_min);
  438. return ret_rect;
  439. }
  440. /// <summary>
  441. /// 根据Field的ID,来获取Field列表中对应FIeld的OTS 坐标
  442. /// </summary>
  443. /// <param name="in_fieldid"></param>
  444. /// <returns></returns>
  445. public Point GetOTSPointByFieldID(List<DField> in_list_dfield, int in_fieldid)
  446. {
  447. Point ret_point = new Point(0, 0);
  448. for (int i = 0; i < in_list_dfield.Count; i++)
  449. {
  450. //这里TagID先代表的是底层返回的ID
  451. if (in_list_dfield[i].FieldID == in_fieldid.ToString())
  452. {
  453. ret_point = new Point(Convert.ToInt32(in_list_dfield[i].OTS_RECT.X), Convert.ToInt32(in_list_dfield[i].OTS_RECT.Y));
  454. }
  455. }
  456. return ret_point;
  457. }
  458. /// <summary>
  459. /// 将OTS坐标转换为Sem 坐标
  460. /// </summary>
  461. /// <param name="POTSCoord"></param>
  462. /// <returns></returns>
  463. public Point ChangeOTSToSemCoord(Point POTSCoord)
  464. {
  465. //first if m_semstagedata is null to get stage inforation
  466. Convert.ToDouble(((Dictionary<string, object>)resultFile.ResultInfo["SEMStageData"])["scanFieldSize"]);
  467. //after obtaining stage info,calc stage point data
  468. Point ret_SEM_point = new Point();
  469. // get center point, um
  470. long xStart = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)resultFile.ResultInfo["SEMStageData"])["Members"])["XAxis"])["start"]);
  471. long xEnd = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)resultFile.ResultInfo["SEMStageData"])["Members"])["XAxis"])["end"]);
  472. long xCenter = (xStart + xEnd) / 2;
  473. long yStart = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)resultFile.ResultInfo["SEMStageData"])["Members"])["YAxis"])["start"]);
  474. long yEnd = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)resultFile.ResultInfo["SEMStageData"])["Members"])["YAxis"])["end"]);
  475. long yCenter = (yStart + yEnd) / 2;
  476. // delte = SEM - OTSa
  477. long deltex = xCenter - 0;
  478. long deltey = yCenter - 0;
  479. int xdir = Convert.ToInt32(((Dictionary<string, object>)resultFile.ResultInfo["SEMStageData"])["xAxisDir"]);
  480. int ydir = Convert.ToInt32(((Dictionary<string, object>)resultFile.ResultInfo["SEMStageData"])["yAxisDir"]);
  481. if (xdir == (int)OTS_X_AXIS_DIRECTION.LEFT_TOWARD)
  482. {
  483. ret_SEM_point.X = -1 * (POTSCoord.X - Convert.ToInt32(deltex));
  484. }
  485. else if (xdir == (int)OTS_X_AXIS_DIRECTION.RIGHT_TOWARD)
  486. {
  487. ret_SEM_point.X = POTSCoord.X + Convert.ToInt32(deltex);
  488. }
  489. if (ydir == (int)OTS_Y_AXIS_DIRECTION.UP_TOWARD)
  490. {
  491. ret_SEM_point.Y = POTSCoord.Y + Convert.ToInt32(deltey);
  492. }
  493. else if (ydir == (int)OTS_Y_AXIS_DIRECTION.DOWN_TOWARD)
  494. {
  495. ret_SEM_point.Y = -1 * (POTSCoord.Y - Convert.ToInt32(deltey));
  496. }
  497. return ret_SEM_point;
  498. }
  499. /// <summary>
  500. /// 获取组整个获取分布图和排序图图像数据的底层数据组建方式,的总过程
  501. /// </summary>
  502. public void GetDistrbutionImageAndBSE_Total()
  503. {
  504. string str27 = "开始从底层加载数据....";
  505. str27 = table["str27"].ToString();
  506. m_Control_DrawDistrbutionImageAndBSE.m_frm_userprogress.SetProgressValueAndText(1, str27);
  507. //对底层加载速度进行计时
  508. Stopwatch stopwatch = new Stopwatch();
  509. stopwatch.Start();
  510. string path = resultFile.FilePath;
  511. FieldData fieldData = new FieldData(path);
  512. List<Field> fieldlist = fieldData.GetFieldList();
  513. //防止有时底层返回的Field的List是0,直接返回
  514. if (fieldlist.Count == 0)
  515. {
  516. string str28 = "底层返回视域数据数量为0....";
  517. str28 = table["str28"].ToString();
  518. m_Control_DrawDistrbutionImageAndBSE.m_frm_userprogress.SetProgressValueAndText(100, str28);
  519. return;
  520. }
  521. //底层加载field对象结束
  522. stopwatch.Stop();
  523. TimeSpan timespan = stopwatch.Elapsed;
  524. //重置计数器,对组建和计算图像进行计时
  525. stopwatch.Reset();
  526. stopwatch.Start();
  527. string str29 = "开始组建图像视域....";
  528. str29 = table["str29"].ToString();
  529. m_Control_DrawDistrbutionImageAndBSE.m_frm_userprogress.SetProgressValueAndText(15, str29);
  530. //将field的list对象给全局变量中,供后面获取xray使用,不需要再次重新加载数据,以提升速度
  531. m_list_COTSFieldMgrClr = fieldlist;
  532. //第一次循环,用来计算单个Field的像素分辨率,和将所有的物理位置存放到List当中
  533. List<Point> list_point = new List<Point>();
  534. int i_field_width = 0, i_field_height = 0;
  535. //获取到该field的分辨率大小,循环中都是一样的
  536. if (fieldlist.Count > 0)
  537. {
  538. Bitmap bitmp = DrawFuncation.ReadImageFile(fieldlist[0].FieldImage);
  539. i_field_width = bitmp.Width;
  540. i_field_height = bitmp.Height;
  541. }
  542. for (int i = 0; i < fieldlist.Count(); i++)
  543. {
  544. //然后取出物理坐标,这个一会要与分辨率坐标进行变算一下
  545. Point ls_point = new Point() { X = fieldlist[i].FieldPosX, Y = fieldlist[i].FieldPosY };
  546. list_point.Add(ls_point);
  547. }
  548. //对单个视域的屏幕像素宽高,进行记录
  549. m_Control_DrawDistrbutionImageAndBSE.m_OneField_Screen_BackRectf = new RectangleF(0, 0, i_field_width, i_field_height);
  550. //获取单个OTS视域像素宽高,并进行记录
  551. Rectangle OTS_FieldRect = GetOneFieldWidthAndHeight(list_point);
  552. m_Control_DrawDistrbutionImageAndBSE.m_OneField_OTS_Rectf = OTS_FieldRect;
  553. //计算出整个绘制图像总Rectagnle的大小
  554. m_Control_DrawDistrbutionImageAndBSE.m_backrectf = ConvertAndGetMaxRect(list_point, i_field_width, i_field_height);
  555. string str30 = "计算标尺....";
  556. str30 = table["str30"].ToString();
  557. //更新进度条提示
  558. m_Control_DrawDistrbutionImageAndBSE.m_frm_userprogress.SetProgressValueAndText(18, str30);
  559. #region //标尺相关------------------------------------------------------------------------------
  560. //在此处通过上面的i_field_width,ifield_height和list_point,来计算出个像素与实际物理值的比例
  561. Rectangle ls_jsblrect = GetOneFieldWidthAndHeight(list_point);
  562. //然后用宽度来除以i_field_width 获取单个的像素比例
  563. double d_onepixel_scale = Convert.ToDouble(ls_jsblrect.Width) / Convert.ToDouble(i_field_width);
  564. //再用该比例对标尺进行相应的赋值
  565. m_Control_DrawDistrbutionImageAndBSE.m_f_onepixel_size = (float)d_onepixel_scale;
  566. //对整个物理像素的范围进行获取与设置
  567. Rectangle ls_offsetandtopleftrect = GetWlRectTopLeftAndRect(list_point, ls_jsblrect.Width, ls_jsblrect.Height);
  568. m_Control_DrawDistrbutionImageAndBSE.m_back_wl_rectf = new RectangleF(ls_offsetandtopleftrect.X, ls_offsetandtopleftrect.Y
  569. , ls_offsetandtopleftrect.Width, ls_offsetandtopleftrect.Height);
  570. #endregion //---------------------------------------------------------------------------------------
  571. string str31 = "组建整图数据....";
  572. str31 = table["str31"].ToString();
  573. //更新进度条提示
  574. m_Control_DrawDistrbutionImageAndBSE.m_frm_userprogress.SetProgressValueAndText(20, str31);
  575. //70的进度条给到下面的循环中,计算进度条各分类进度分配
  576. float ls_int_progresscalc = 0;
  577. if (fieldlist.Count > 0)
  578. ls_int_progresscalc = (float)70 / (float)fieldlist.Count;
  579. string str32 = "已完成第";
  580. str32 = table["str32"].ToString();
  581. string str33 = "个视域数据组建,共";
  582. str33 = table["str33"].ToString();
  583. string str34 = "个视域...";
  584. str34 = table["str34"].ToString();
  585. //再通过Field取到对应的Particle,循环一次
  586. for (int i = 0; i < fieldlist.Count(); i++)
  587. {
  588. //更新进度条提示
  589. m_Control_DrawDistrbutionImageAndBSE.m_frm_userprogress.SetProgressValueAndText(20 + (int)(ls_int_progresscalc * (i + 1)), str32 + i.ToString() + str33 + m_list_COTSFieldMgrClr.Count.ToString() + str34);
  590. //先获取该Field中的所有Particle
  591. List<Particle> list_cotsparticleclr = new List<Particle>();
  592. list_cotsparticleclr = fieldlist[i].ParticleList;
  593. //取出该Field的物理坐标,将其转换成对应的屏幕像素坐标,屏幕左上角为原点(0,0)的偏移值,用于后面计算各Segment的位置使用
  594. //应该也就是这里根据OTS坐标转换到屏幕像素坐标,Y轴是反的,所以在这里对从OTS坐标转换成屏幕坐标的地方进行反转!
  595. Point thisfield_point = new Point() { X = fieldlist[i].FieldPosX, Y = fieldlist[i].FieldPosY };
  596. Point offset_point = GetFieldPhysicsConvertToScreen(list_point, i_field_width, i_field_height, thisfield_point);
  597. //保存该Field最终在屏幕上显示的位置及大小
  598. DField df = new DField();
  599. df.FieldID = fieldlist[i].FieldID.ToString();
  600. df.Show_Rect = new Rectangle(offset_point, new Size(i_field_width, i_field_height));
  601. df.Current_Rect = new Rectangle(offset_point, new Size(i_field_width, i_field_height));
  602. df.OTS_RECT = new RectangleF(thisfield_point.X, thisfield_point.Y, OTS_FieldRect.Width, OTS_FieldRect.Height);
  603. m_Control_DrawDistrbutionImageAndBSE.m_list_dfield.Add(df);
  604. //然后将取出的数据,转换成Bitmap对象
  605. Bitmap ls_bt = DrawFuncation.ReadImageFile(fieldlist[i].FieldImage);
  606. //再循环计算所有的Particle对象
  607. foreach (Particle ls_cotsparticleclr in list_cotsparticleclr)
  608. {
  609. //从Clr中获取所有的Segment的List对象
  610. List<Feature> list_cotssegmentclr = new List<Feature>();
  611. list_cotssegmentclr = ls_cotsparticleclr.FeatureList;
  612. //创建颗粒分布图对应的类对象
  613. List<DSegment> list_dsegment = new List<DSegment>();
  614. //创建DParticle颗粒,保存与之对应的颗粒tagid和particleid,为了后面取xray数据及多选时获取多选cotsparticleclr列表
  615. DParticle ls_dp = new DParticle();
  616. ls_dp.CLRTagID = ls_cotsparticleclr.ParticleId;
  617. ls_dp.CLRFieldID = ls_cotsparticleclr.FieldId;
  618. ls_dp.STDTypeID = ls_cotsparticleclr.TypeId;
  619. ls_dp.TypeId = ls_cotsparticleclr.TypeId;
  620. ls_dp.TypeName = ls_cotsparticleclr.TypeName;
  621. ls_dp.XRayId = ls_cotsparticleclr.XrayId;
  622. ls_dp.SEMPosX = ls_cotsparticleclr.SEMPosX;
  623. ls_dp.SEMPosY = ls_cotsparticleclr.SEMPosY;
  624. //获取该颗粒在STD标准库中已分析出化合物对应的颜色
  625. ls_dp.Color = GetColorBySTDTypeIDForBSEAndSorImage(ls_cotsparticleclr.TypeColor, ls_cotsparticleclr.TypeId);
  626. //防止超大颗粒,会让程序死掉
  627. if (list_cotssegmentclr.Count < m_segment_overflownumber)
  628. {
  629. //再循环取出里面所有的segment
  630. foreach (Feature ls_cotssegmentclr in list_cotssegmentclr)
  631. {
  632. #region 创建DSegment对象,并将STD分析出的化合物颜色保存到DSegment对象中
  633. //对Particle里的Segment进行偏移的计算等,创建了DSegment的大小
  634. DSegment ds = new DSegment();
  635. ds.Rect = new Rectangle(ls_cotssegmentclr.Start + offset_point.X,
  636. //i_field_height - ls_cotssegmentclr.GetHeight() + offset_point.Y,//这是让单个Field的图像按Y轴反过来
  637. ls_cotssegmentclr.Height + offset_point.Y,
  638. ls_cotssegmentclr.Length,
  639. 1);
  640. ds.Color = ls_dp.Color;//将线的颜色对应到颗粒的颜色
  641. #endregion
  642. #region //这里是在Field中,抠取出原BSE图像到DSegment中--------------------------------
  643. //ls_bt.RotateFlip(RotateFlipType.Rotate180FlipX);//使用系统带的图像处理方法,进行Y轴的翻转,与上面记录位置对应
  644. //合成图像完成,开始抠取像素-----------------------------------------------------------------
  645. int i_ls_length = ls_cotssegmentclr.Length;
  646. List<Color> ls_list_colors = new List<Color>();
  647. for (int m = 0; m < i_ls_length; m++)
  648. {
  649. //这里实现一下代码保护
  650. int lsjs_x = ls_cotssegmentclr.Start + m;
  651. //int lsjs_y = i_field_height - ls_cotssegmentclr.GetHeight();//这个反转要与上面对应
  652. int lsjs_y = ls_cotssegmentclr.Height;
  653. if (lsjs_x < 0)
  654. lsjs_x = 0;
  655. if (lsjs_x >= i_field_width)
  656. lsjs_x = i_field_width - 1;
  657. if (lsjs_y < 0)
  658. lsjs_y = 0;
  659. if (lsjs_y >= i_field_height)
  660. lsjs_y = i_field_height - 1;
  661. //按理说这里应该加上个横向抠取像素颜色,这里需要再处理一下
  662. ls_list_colors.Add(ls_bt.GetPixel(lsjs_x,
  663. lsjs_y));
  664. }
  665. //保存原BSE图中的颜色列表
  666. ds.List_Colors = ls_list_colors;
  667. #endregion //------------------------------------------------------------------------------
  668. list_dsegment.Add(ds);
  669. //ls_bt.Dispose();
  670. }
  671. }
  672. //设置Particle在0.5F倍数以上时才进行显示
  673. ls_dp.Zoom_DisPlayMultiplier = 0.5f;
  674. ls_dp.Zoom_DisPlay = true;
  675. //将segment对应的设置到particle中
  676. ls_dp.DSegments = list_dsegment;
  677. //并对DParticle相关信息进行计算
  678. ls_dp.Rect = ls_dp.GetRectFromDSegment();
  679. ls_dp.GPath = ls_dp.GetRegionFromDSegments();
  680. ls_dp.SmallRect = ls_dp.GetSmallRectangleFromRect();
  681. //将每个颗粒添加到颗粒分布图中的列表中
  682. m_Control_DrawDistrbutionImageAndBSE.m_list_baseobject.Add(ls_dp);
  683. if (ls_dp.XRayId > -1)
  684. {
  685. m_Control_DrawDistrbutionImageAndBSE.m_list_usebject.Add(ls_dp);
  686. }
  687. }
  688. }
  689. string str35 = "转换分辨率...";
  690. str35 = table["str35"].ToString();
  691. //更新进度条相关显示
  692. m_Control_DrawDistrbutionImageAndBSE.m_frm_userprogress.SetProgressValueAndText(90, str35);
  693. //然后这里还需要计算出,各field的宽和高,帧图边框分别需要显示多少个框
  694. if (i_field_width != 0 && i_field_height != 0)
  695. {
  696. m_Control_DrawDistrbutionImageAndBSE.m_i_grid_showlinesnumber_width = Convert.ToInt32(m_Control_DrawDistrbutionImageAndBSE.BackRectF.Width / i_field_width);
  697. m_Control_DrawDistrbutionImageAndBSE.m_i_grid_showlinesnumber_height = Convert.ToInt32(m_Control_DrawDistrbutionImageAndBSE.BackRectF.Height / i_field_height);
  698. }
  699. string str36 = "完成其它工作...";
  700. str36 = table["str36"].ToString();
  701. //结束组建计算图像计数
  702. stopwatch.Stop();
  703. TimeSpan timespan2 = stopwatch.Elapsed;
  704. m_Control_DrawDistrbutionImageAndBSE.m_frm_userprogress.SetProgressValueAndText(95, str36);
  705. string str37 = "分钟 ";
  706. str37 = table["str37"].ToString();
  707. string str38 = "秒 共(";
  708. str38 = table["str38"].ToString();
  709. string str39 = ")毫秒";
  710. str39 = table["str39"].ToString();
  711. //相关计数
  712. m_field_count = fieldlist.Count;
  713. m_particle_count = m_Control_DrawDistrbutionImageAndBSE.m_list_baseobject.Count;
  714. m_time_str = timespan.TotalMinutes.ToString("0.00") + str37 + timespan.TotalSeconds.ToString("0.00") + str38 + timespan.TotalMilliseconds.ToString() + str39;
  715. m_time_str2 = timespan2.TotalMinutes.ToString("0.00") + str37 + timespan2.TotalSeconds.ToString("0.00") + str38 + timespan2.TotalMilliseconds.ToString() + str39;
  716. }
  717. //读取进度条,虚拟读取,直接通过所有时域
  718. void setPr(float ls_int_progresscalc, string str32, string str33, string str34)
  719. {
  720. for (int i = 0; i < m_list_COTSFieldMgrClr.Count; i++)
  721. {
  722. m_Control_DrawDistrbutionImageAndBSE.m_frm_userprogress.SetProgressValueAndText(20 + (int)(ls_int_progresscalc * (i + 1)), str32 + i.ToString() + str33 + m_list_COTSFieldMgrClr.Count.ToString() + str34);
  723. }
  724. }
  725. /// <summary>
  726. /// 分布图和BSE图中,从底层获取相关结果后,重新组织显示
  727. /// </summary>
  728. /// <param name="ls_cgriddataclr"></param>
  729. public void GetDrawDistrbutionImageAndBSE_ByQuery(OTSIncAReportApp.OTSSampleReportInfo.OTSSampleMeaInfo sourceGridData)
  730. {
  731. var display = sourceGridData.SampleDataList.Find(s => Convert.ToInt32(s.iItemId) == 7);
  732. string display_type = display.itemVal.ToString();
  733. int disinde = display.comboDownList.IndexOf(display_type);
  734. var list = sourceGridData.SampleDataList.Find(s => Convert.ToInt32(s.iItemId) == 10);
  735. string size = list.itemVal.ToString();
  736. int inde = list.comboDownList.IndexOf(size);
  737. string size_cal_method_type = sourceGridData.SampleDataList.Find(s => Convert.ToInt32(s.iItemId) == 13).itemVal.ToString();
  738. string con = "";
  739. switch (size_cal_method_type)
  740. {
  741. case "DMAX":
  742. con = "DMAX";
  743. break;
  744. case "DMIN":
  745. con = "DMIN";
  746. break;
  747. case "Area":
  748. con = "Area";
  749. break;
  750. case "FERET":
  751. con = "DFERET";
  752. break;
  753. }
  754. string min = "0";
  755. string max = "999";
  756. if (inde != 0)
  757. {
  758. max = sourceGridData.SampleDataList.Find(s => Convert.ToInt32(s.iItemId) == 12).itemVal.ToString(); ;
  759. min = sourceGridData.SampleDataList.Find(s => Convert.ToInt32(s.iItemId) == 11).itemVal.ToString(); ;
  760. if (max.ToLower() == "max")
  761. {
  762. max = "999";
  763. }
  764. }
  765. string path = resultFile.FilePath;
  766. ParticleData particleData = new ParticleData(path);
  767. List<Particle> particles = particleData.GetParticleListByCon(con, max, min, disinde);
  768. foreach (DParticle ls_dp in m_Control_DrawDistrbutionImageAndBSE.m_list_baseobject)
  769. {
  770. int dis = 0;
  771. foreach (Particle particle in particles)
  772. {
  773. //找到对应的颗粒,将分类设置进去
  774. if (ls_dp.CLRTagID == particle.ParticleId && ls_dp.CLRFieldID == particle.FieldId)
  775. {
  776. //这里居然添加进来了7个,原来是这里,在底层直接取出了6个相同的颗粒到一起。
  777. ls_dp.ParticleFL = particle.TypeName;
  778. ls_dp.Operator = ParticleOperator.DISPLAY;
  779. dis = 1;
  780. break;
  781. }
  782. }
  783. if (dis == 0)
  784. {
  785. ls_dp.Operator = ParticleOperator.NODISPLAY;
  786. }
  787. }
  788. }
  789. #endregion
  790. #region //--------------------------------------颗粒排序图相关部份---------------------------------------------------------------------
  791. /// <summary>
  792. /// 根据颗粒排序图获取已经选择上的颗粒,返回被选择上的颗粒的列表
  793. /// </summary>
  794. /// <returns></returns>
  795. public List<Particle> GetSelectedParticleList_ForDrawDistrbutionSortImage()
  796. {
  797. List<Particle> ls_list_cotsparticleclr = new List<Particle>();
  798. //防止为空校验判断
  799. if (m_list_COTSFieldMgrClr == null)
  800. {
  801. return ls_list_cotsparticleclr;
  802. }
  803. //先取出,所有被选择的dparticle列表的
  804. List<DParticle> ls_list_dp = new List<DParticle>();
  805. foreach (SortParticleDistribution spd in m_Control_DrawdistrbutionsortImage.m_list_sortparticledistribution)
  806. {
  807. foreach (DParticle ls_dp in spd.List_DParticle)
  808. {
  809. if (ls_dp.Operator == ParticleOperator.SELECTED)
  810. {
  811. ls_list_dp.Add(ls_dp);
  812. }
  813. }
  814. }
  815. //并开始查找包含tagid和fieldid的cotsparticle的对象,保存到list当中
  816. for (int i = 0; i < ls_list_dp.Count(); i++)
  817. {
  818. for (int j = 0; j < m_list_COTSFieldMgrClr.Count(); j++)
  819. {
  820. //先获取该field中的所有particle
  821. List<Particle> list_cotsparticleclr = new List<Particle>();
  822. list_cotsparticleclr = m_list_COTSFieldMgrClr[j].ParticleList;
  823. for (int k = 0; k < list_cotsparticleclr.Count(); k++)
  824. {
  825. if (list_cotsparticleclr[k].ParticleId == ls_list_dp[i].CLRTagID
  826. && list_cotsparticleclr[k].FieldId == ls_list_dp[i].CLRFieldID)
  827. {
  828. //将cotsparticleclr保存到list当中
  829. ls_list_cotsparticleclr.Add(list_cotsparticleclr[k]);
  830. }
  831. }
  832. }
  833. }
  834. return ls_list_cotsparticleclr;
  835. }
  836. /// <summary>
  837. /// 根据传入的fieldid和tagid返回该颗粒的OTS坐标
  838. /// </summary>
  839. /// <param name="in_fieldid"></param>
  840. /// <param name="in_tagid"></param>
  841. /// <returns></returns>
  842. public Point GetOTSPointFromOld_list_sortparticledistribution(int in_fieldid, int in_tagid, Control_DrawDistrbutionSortImage in_control_drawdistrbutionsortimage)
  843. {
  844. Point ret_point = new Point(0, 0);
  845. if (m_list_COTSFieldMgrClr != null)
  846. {
  847. Field field = m_list_COTSFieldMgrClr.Find(x => x.FieldID == in_fieldid);
  848. ret_point = new Point() { X = field.FieldPosX, Y = field.FieldPosY };
  849. }
  850. return ret_point;
  851. }
  852. /// <summary>
  853. /// 排序图获取底层数据,组建整张排序图的总方法过程
  854. /// </summary>
  855. public void GetDistrbutionSortImage_Total()
  856. {
  857. string str48 = "开始从底层加载数据....";
  858. str48 = table["str48"].ToString();
  859. m_Control_DrawdistrbutionsortImage.m_frm_userprogress.SetProgressValueAndText(1, str48);
  860. string path = resultFile.FilePath;
  861. FieldData fieldData = new FieldData(path);
  862. List<Field> fieldlist = fieldData.GetFieldList();
  863. //将field的list对象给全局变量中,供后面获取xray使用
  864. m_list_COTSFieldMgrClr = fieldlist;
  865. string str49 = "开始组建图像资源....";
  866. str49 = table["str49"].ToString();
  867. m_Control_DrawdistrbutionsortImage.m_frm_userprogress.SetProgressValueAndText(15, str49);
  868. //第一次,用来计算,总大小等,获取Field的坐标,id,同时获取对应的ImgClr里的宽高,图像大小
  869. List<Point> list_point = new List<Point>();
  870. int i_field_width = 0, i_field_height = 0;
  871. //获取到该field的分辨率大小,循环中都是一样的
  872. if (fieldlist.Count > 0)
  873. {
  874. Bitmap bitmp = DrawFuncation.ReadImageFile(fieldlist[0].FieldImage);
  875. i_field_width = bitmp.Width;
  876. i_field_height = bitmp.Height;
  877. }
  878. for (int i = 0; i < fieldlist.Count(); i++)
  879. {
  880. //然后取出物理坐标,这个一会要与分辨率坐标进行变算一下
  881. Point ls_point = new Point() { X = fieldlist[i].FieldPosX, Y = fieldlist[i].FieldPosY };
  882. list_point.Add(ls_point);
  883. }
  884. //对单个Field视域的屏幕像素宽高,进行记录
  885. m_Control_DrawdistrbutionsortImage.m_OneField_Screen_BackRectf = new RectangleF(0, 0, i_field_width, i_field_height);
  886. //获取单个OTS视域像素宽高,并进行记录
  887. Rectangle OTS_FieldRect = GetOneFieldWidthAndHeight(list_point);
  888. m_Control_DrawdistrbutionsortImage.m_OneField_OTS_Rectf = OTS_FieldRect;
  889. string str50 = "计算标尺....";
  890. str50 = table["str50"].ToString();
  891. m_Control_DrawdistrbutionsortImage.m_frm_userprogress.SetProgressValueAndText(18, str50);
  892. #region //标尺相关------------------------------------------------------------------------------
  893. //在此处通过上面的i_field_width,ifield_height和list_point,来计算出个像素与实际物理值的比例
  894. Rectangle ls_jsblrect = GetOneFieldWidthAndHeight(list_point);
  895. //然后用宽度来除以i_field_width 获取单个的像素比例
  896. double d_onepixel_scale = Convert.ToDouble(ls_jsblrect.Width) / Convert.ToDouble(i_field_width);
  897. //再用该比例对标尺进行相应的赋值
  898. m_Control_DrawdistrbutionsortImage.m_f_onepixel_size = (float)d_onepixel_scale;
  899. #endregion //---------------------------------------------------------------------------------------
  900. string str51 = "组建整图数据....";
  901. str51 = table["str51"].ToString();
  902. m_Control_DrawdistrbutionsortImage.m_frm_userprogress.SetProgressValueAndText(20, str51);
  903. //70的进度条给到下面的循环中
  904. float ls_int_progresscalc = 0;
  905. if (fieldlist.Count > 0)
  906. ls_int_progresscalc = (float)80 / (float)fieldlist.Count;
  907. string str52 = "已完成第";
  908. str52 = table["str52"].ToString();
  909. string str53 = "个数据,共";
  910. str53 = table["str53"].ToString();
  911. string str54 = "个数据...";
  912. str54 = table["str54"].ToString();
  913. //第二次,再通过Field取到对应的Particle,循环一次
  914. for (int i = 0; i < fieldlist.Count(); i++)
  915. {
  916. m_Control_DrawdistrbutionsortImage.m_frm_userprogress.SetProgressValueAndText(20 + (int)(ls_int_progresscalc * (i + 1)), str52 + i.ToString() + str53 + m_list_COTSFieldMgrClr.Count.ToString() + str54);
  917. //先获取该field中的所有particle
  918. List<Particle> list_cotsparticleclr = new List<Particle>();
  919. list_cotsparticleclr = fieldlist[i].ParticleList;
  920. //取出该Field中,从物理坐标转换到像素坐标后.不知道该算法是否可靠,先进行测试判断
  921. Point offset_point = GetFieldPhysicsConvertToScreen(list_point, i_field_width, i_field_height, new Point() { X = fieldlist[i].FieldPosX, Y = fieldlist[i].FieldPosY });
  922. //然后将取出的数据,转换成Bitmap对象
  923. Bitmap ls_bt = DrawFuncation.ReadImageFile(fieldlist[i].FieldImage);
  924. //再循环取出所有的particle
  925. foreach (Particle ls_cotsparticleclr in list_cotsparticleclr)
  926. {
  927. List<Feature> list_cotssegmentclr = new List<Feature>();
  928. list_cotssegmentclr = ls_cotsparticleclr.FeatureList;
  929. //创建颗粒分布图对应的类对象
  930. List<DSegment> list_dsegment = new List<DSegment>();
  931. //定义particle颗粒,并获取该颗粒与标准库中对应的颜色
  932. DParticle ls_dp = new DParticle();
  933. //ls_dp.Color = DrawFuncation.colorHx16toRGB(GetSTDItemClrByTypeIndex_ForDistrbutionSortImage(ls_cotsparticleclr.GetType()).GetColor());
  934. ls_dp.CLRFieldID = ls_cotsparticleclr.FieldId; //为我封装的颗粒保存上,底层对应的FieldID
  935. ls_dp.CLRTagID = ls_cotsparticleclr.ParticleId; //为我封装的颗粒对象保存上,底层对应的TagID
  936. ls_dp.STDTypeID = ls_cotsparticleclr.TypeId; //为我封装的颗粒对象保存上,类型
  937. ls_dp.TypeId = ls_cotsparticleclr.TypeId;
  938. ls_dp.TypeName = ls_cotsparticleclr.TypeName;
  939. ls_dp.XRayId = ls_cotsparticleclr.XrayId;
  940. ls_dp.SEMPosX = ls_cotsparticleclr.SEMPosX;
  941. ls_dp.SEMPosY = ls_cotsparticleclr.SEMPosY;
  942. ls_dp.Color = GetColorBySTDTypeIDForBSEAndSorImage(ls_cotsparticleclr.TypeColor, ls_cotsparticleclr.TypeId);
  943. //防止segment过多造成程序卡死
  944. if (list_cotssegmentclr.Count < m_segment_overflownumber)
  945. //再循环取出里面所有的segment
  946. foreach (Feature ls_cotssegmentclr in list_cotssegmentclr)
  947. {
  948. //这里的坐标未转换
  949. DSegment ds = new DSegment();
  950. ds.Rect = new Rectangle(ls_cotssegmentclr.Start + offset_point.X,
  951. //i_field_height - ls_cotssegmentclr.GetHeight() + offset_point.Y,
  952. ls_cotssegmentclr.Height + offset_point.Y,
  953. ls_cotssegmentclr.Length,
  954. 1);
  955. //图像上下反了,翻转一下,上下翻转
  956. //ls_bt.RotateFlip(RotateFlipType.Rotate180FlipX);//使用系统带的图像处理方法,进行x轴的翻转
  957. //合成图像完成,开始抠取像素---------------------为显示BSE原图而用--------------------------------------------
  958. int i_ls_length = ls_cotssegmentclr.Length;
  959. List<Color> ls_list_colors = new List<Color>();
  960. for (int m = 0; m < i_ls_length; m++)
  961. {
  962. //这里实现一下代码保护
  963. int lsjs_x = ls_cotssegmentclr.Start + m;
  964. //int lsjs_y = i_field_height - ls_cotssegmentclr.GetHeight();
  965. int lsjs_y = ls_cotssegmentclr.Height;
  966. if (lsjs_x < 0)
  967. lsjs_x = 0;
  968. if (lsjs_x >= i_field_width)
  969. lsjs_x = i_field_width - 1;
  970. if (lsjs_y < 0)
  971. lsjs_y = 0;
  972. if (lsjs_y >= i_field_height)
  973. lsjs_y = i_field_height - 1;
  974. //按理说这里应该加上个横向抠取像素颜色,这里需要再处理一下
  975. ls_list_colors.Add(ls_bt.GetPixel(lsjs_x,
  976. lsjs_y));
  977. }
  978. //---------------------------------------------存入标准库相关的信息------------------------------------------------
  979. ds.Color = ls_dp.Color;//将线的颜色对应到颗粒的颜色
  980. //------------------------------------------------------------------------------------------------------
  981. ds.List_Colors = ls_list_colors;
  982. list_dsegment.Add(ds);
  983. //ls_bt.Dispose();
  984. }
  985. ls_dp.Zoom_DisPlayMultiplier = 0.5f;
  986. ls_dp.Zoom_DisPlay = true;
  987. ls_dp.DSegments = list_dsegment; //将segment对应的设置到particle中
  988. //并对DParticle相关信息进行计算
  989. ls_dp.Rect = ls_dp.GetRectFromDSegment();
  990. ls_dp.GPath = ls_dp.GetRegionFromDSegments();
  991. ls_dp.SmallRect = ls_dp.GetSmallRectangleFromRect();
  992. //将每个颗粒添加到颗粒分布图中的列表中
  993. m_Control_DrawdistrbutionsortImage.m_list_baseobject.Add(ls_dp);
  994. }
  995. }
  996. //--------------然后开始操作分布图定义的结构,接接所有的field,组成一个完整的image的rect大小,定义
  997. }
  998. /// <summary>
  999. /// 根据type,从三种分类的分析库中提取当前分析物的颜色
  1000. /// </summary>
  1001. /// <param name="in_cotssampleclr"></param>
  1002. /// <param name="in_stdtypeid"></param>
  1003. /// <returns></returns>
  1004. public Color GetColorBySTDTypeIDForBSEAndSorImage(string in_cotssampleclr, int in_stdtypeid)
  1005. {
  1006. Color ret_c = new Color();
  1007. if (in_stdtypeid < 1000)
  1008. {
  1009. OTSSysSTDMgrClass osc = new OTSSysSTDMgrClass();
  1010. //小于1000,使用系统默认分类
  1011. ret_c = osc.GetColorByEnum(in_stdtypeid);
  1012. }
  1013. else if (in_stdtypeid >= 1000)
  1014. {
  1015. //大于等于1000,并且小于10000时,使用用户标准库来分析夹杂物名称
  1016. if (!in_cotssampleclr.Contains("#"))
  1017. {
  1018. ret_c = DrawFuncation.colorHx16toRGB("#" + in_cotssampleclr);//接收必须是#000000的格式
  1019. }
  1020. else
  1021. {
  1022. ret_c = DrawFuncation.colorHx16toRGB(in_cotssampleclr);//接收必须是#000000的格式
  1023. }
  1024. }
  1025. return ret_c;
  1026. }
  1027. /// <summary>
  1028. /// 颗粒排序图中的颗粒,重新组织显示颗粒排序规则
  1029. /// </summary>
  1030. public void GetDistrbutionSortimage_ByQuery(OTSIncAReportApp.OTSSampleReportInfo.OTSSampleMeaInfo sourceGridData)
  1031. {
  1032. List<string> FLNameList = new List<string>();
  1033. //List<int> FLID = new List<int>() { -1,0, 1, 2, 4, 6, 7, 8, 9 };
  1034. List<int> FLID = new List<int>() { 0, 1, 2, 4, 6, 9, 10};
  1035. List<string> NameList = new List<string>();
  1036. int fltype = 0;
  1037. //先清除list
  1038. m_Control_DrawdistrbutionsortImage.m_list_sortparticledistribution.Clear();
  1039. m_Control_DrawdistrbutionsortImage.m_old_list_sortparticledistribution.Clear();
  1040. m_Control_DrawdistrbutionsortImage.m_f_zoom_record = 1;
  1041. //------------------------------------分解结果内容部份------------------------------------
  1042. string display_type = "";
  1043. string con = "";
  1044. var list = sourceGridData.SampleDataList.Find(s => Convert.ToInt32(s.iItemId) == 4);
  1045. string sort_type = list.itemVal.ToString();
  1046. int _type = list.comboDownList.IndexOf(sort_type);
  1047. switch (_type)
  1048. {
  1049. case 0:
  1050. fltype = 0;
  1051. break;
  1052. case 1:
  1053. fltype = 1;
  1054. break;
  1055. case 2:
  1056. fltype = 2;
  1057. display_type = sourceGridData.SampleDataList.Find(s => Convert.ToInt32(s.iItemId) == 13).itemVal.ToString();
  1058. switch (display_type)
  1059. {
  1060. case "DMAX":
  1061. con = "DMAX";
  1062. break;
  1063. case "DMIN":
  1064. con = "DMIN";
  1065. break;
  1066. case "Area":
  1067. con = "Area";
  1068. break;
  1069. case "FERET":
  1070. con = "DFERET";
  1071. break;
  1072. }
  1073. break;
  1074. }
  1075. string path = resultFile.FilePath;
  1076. ParticleData particleData = new ParticleData(path);
  1077. List<Particle> particles = particleData.GetParticleListByCon("", "", "", 0);
  1078. foreach (DParticle ls_dp in m_Control_DrawdistrbutionsortImage.m_list_baseobject)
  1079. {
  1080. int dis = 0;
  1081. foreach (Particle particle in particles)
  1082. {
  1083. //找到对应的颗粒,将分类设置进去
  1084. if (ls_dp.CLRTagID == particle.ParticleId && ls_dp.CLRFieldID == particle.FieldId)
  1085. {
  1086. if (!FLNameList.Contains(particle.TypeName) && particle.TypeName != "")
  1087. {
  1088. FLNameList.Add(particle.TypeName);
  1089. }
  1090. if (fltype == 0)
  1091. {
  1092. ls_dp.ParticleFL = particle.TypeId.ToString();
  1093. }
  1094. if (fltype == 1)
  1095. {
  1096. ls_dp.ParticleFL = particle.TypeName.ToString();
  1097. }
  1098. if (fltype == 2)
  1099. {
  1100. if (con == "DMAX")
  1101. ls_dp.ParticleFL = particle.DMAX.ToString();
  1102. if (con == "DMIN")
  1103. ls_dp.ParticleFL = particle.DMIN.ToString();
  1104. if (con == "Area")
  1105. ls_dp.ParticleFL = particle.Area.ToString();
  1106. if (con == "DFERET")
  1107. ls_dp.ParticleFL = particle.FERET.ToString();
  1108. }
  1109. ls_dp.Operator = ParticleOperator.DISPLAY;
  1110. dis = 1;
  1111. break;
  1112. }
  1113. }
  1114. if (dis == 0)
  1115. {
  1116. ls_dp.Operator = ParticleOperator.NODISPLAY;
  1117. }
  1118. }
  1119. if (fltype == 0)
  1120. {
  1121. //NameList = new List<string>() { table["partcletype0"].ToString(), table["partcletype1"].ToString(), table["partcletype2"].ToString(), table["partcletype4"].ToString(), table["partcletype6"].ToString(), table["partcletype7"].ToString(), table["partcletype8"].ToString(), table["partcletype9"].ToString(), table["partcletype10"].ToString() };
  1122. NameList = new List<string>() {table["partcletype9"].ToString(), table["partcletype10"].ToString() };
  1123. }
  1124. if (fltype == 1)
  1125. {
  1126. NameList = FLNameList;
  1127. }
  1128. if (fltype == 2)
  1129. {
  1130. //获取粒级表
  1131. string flpath = m_Control_DrawdistrbutionsortImage.m_ReportApp.m_RptConfigFile.FileFolderSize + m_Control_DrawdistrbutionsortImage.m_ReportApp.m_RptConfigFile.PartSizeFile;
  1132. DataSet ds = XMLoperate.GetXml(flpath);
  1133. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  1134. List<string> sizeList = new List<string>();
  1135. for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
  1136. {
  1137. if (sizestr.Split(',')[i].Length > 0)
  1138. {
  1139. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  1140. double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
  1141. sizeList.Add(d1.ToString() + "~" + d2.ToString());
  1142. }
  1143. }
  1144. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  1145. sizeList.Add(d.ToString() + "~MAX");
  1146. NameList = sizeList;
  1147. }
  1148. //为颗粒排序图,创建分栏grid
  1149. foreach (string name in NameList)
  1150. {
  1151. SortParticleDistribution sortparticledistribution = new SortParticleDistribution();
  1152. sortparticledistribution.RectF = new RectangleF(m_Control_DrawdistrbutionsortImage.ClientRectangle.X, m_Control_DrawdistrbutionsortImage.ClientRectangle.Y,
  1153. 800, m_Control_DrawdistrbutionsortImage.ClientRectangle.Height);
  1154. sortparticledistribution.ShowStr = name;//设置分类grid
  1155. m_Control_DrawdistrbutionsortImage.m_list_sortparticledistribution.Add(sortparticledistribution);
  1156. }
  1157. //然后再重新将list_baseobject中的颗粒,分别添加到对应的sortgrid中
  1158. foreach (DParticle ls_dp in m_Control_DrawdistrbutionsortImage.m_list_baseobject)
  1159. {
  1160. var sort = m_Control_DrawdistrbutionsortImage.m_list_sortparticledistribution;
  1161. for (int i = 0; i < sort.Count; i++)
  1162. {
  1163. if (fltype == 0)
  1164. {
  1165. if (ls_dp.STDTypeID == FLID[i])
  1166. {
  1167. //将对应的颗粒添加到分栏grid中
  1168. DParticle sort_dp = ls_dp.Clone() as DParticle;
  1169. sort_dp.Rect = sort_dp.GetRectFromDSegment();
  1170. sort[i].List_DParticle.Add(sort_dp);
  1171. break;
  1172. }
  1173. else if (ls_dp.STDTypeID > 10000)
  1174. {
  1175. //将对应的颗粒添加到分栏grid中
  1176. DParticle sort_dp = ls_dp.Clone() as DParticle;
  1177. sort_dp.Rect = sort_dp.GetRectFromDSegment();
  1178. sort[sort.Count - 1].List_DParticle.Add(sort_dp);
  1179. break;
  1180. }
  1181. }
  1182. else if (fltype == 1)
  1183. {
  1184. if (ls_dp.TypeName == NameList[i])
  1185. {
  1186. //将对应的颗粒添加到分栏grid中
  1187. DParticle sort_dp = ls_dp.Clone() as DParticle;
  1188. sort_dp.Rect = sort_dp.GetRectFromDSegment();
  1189. sort[i].List_DParticle.Add(sort_dp);
  1190. break;
  1191. }
  1192. }
  1193. else if (fltype == 2)
  1194. {
  1195. double min = Convert.ToDouble(NameList[i].Split('~')[0]);
  1196. double max = 0;
  1197. if (NameList[i].Split('~')[1].ToLower() != "max")
  1198. { max = Convert.ToDouble(NameList[i].Split('~')[1]); }
  1199. else
  1200. {
  1201. max = 999;
  1202. }
  1203. double size = Convert.ToDouble(ls_dp.ParticleFL);
  1204. if (size <= max && size >= min)
  1205. {
  1206. //将对应的颗粒添加到分栏grid中
  1207. DParticle sort_dp = ls_dp.Clone() as DParticle;
  1208. sort_dp.Rect = sort_dp.GetRectFromDSegment();
  1209. sort[i].List_DParticle.Add(sort_dp);
  1210. break;
  1211. }
  1212. }
  1213. }
  1214. }
  1215. //循环分栏grid,对各分栏grid进行摆放
  1216. for (int i = 0; i < m_Control_DrawdistrbutionsortImage.m_list_sortparticledistribution.Count(); i++)
  1217. {
  1218. //计算y轴,的增量
  1219. float ls_height = 0;
  1220. if (i == 0)
  1221. {
  1222. ls_height = 0;
  1223. }
  1224. else
  1225. {
  1226. ls_height = m_Control_DrawdistrbutionsortImage.m_list_sortparticledistribution[i - 1].RectF.Y +
  1227. m_Control_DrawdistrbutionsortImage.m_list_sortparticledistribution[i - 1].RectF.Height - 10;
  1228. }
  1229. m_Control_DrawdistrbutionsortImage.m_list_sortparticledistribution[i].RectF = new RectangleF(
  1230. m_Control_DrawdistrbutionsortImage.m_list_sortparticledistribution[i].RectF.X,
  1231. m_Control_DrawdistrbutionsortImage.m_list_sortparticledistribution[i].RectF.Y + ls_height,
  1232. m_Control_DrawdistrbutionsortImage.m_list_sortparticledistribution[i].RectF.Width,
  1233. m_Control_DrawdistrbutionsortImage.m_list_sortparticledistribution[i].GetSortGridHeight() + 50);//为每栏的高度增加了50补充,防止图像溢出
  1234. }
  1235. //然后再重新对分栏grid中的颗粒,重新进行摆放
  1236. foreach (SortParticleDistribution ls_spd in m_Control_DrawdistrbutionsortImage.m_list_sortparticledistribution)
  1237. {
  1238. ls_spd.SortDParticle(m_Control_DrawdistrbutionsortImage.FZOOMRecord);
  1239. }
  1240. //最后,将分栏grid,分别存放到old的分栏grid中
  1241. foreach (SortParticleDistribution ls_sortparticledistribution in m_Control_DrawdistrbutionsortImage.m_list_sortparticledistribution)
  1242. {
  1243. SortParticleDistribution old_sortparticledistribution = ls_sortparticledistribution.Clone() as SortParticleDistribution;
  1244. m_Control_DrawdistrbutionsortImage.m_old_list_sortparticledistribution.Add(old_sortparticledistribution);
  1245. foreach (DParticle ls_dp in old_sortparticledistribution.List_DParticle)
  1246. {
  1247. ls_dp.Rect = ls_dp.GetRectFromDSegment();
  1248. }
  1249. }
  1250. }
  1251. #endregion
  1252. }
  1253. }