OTSIncAReportFun.cs 68 KB

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