Control_DrawDistrbutionImageAndBSE.cs 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239
  1. using NLog;
  2. using OTSCommon.Model;
  3. using OTSIncAReportApp;
  4. using OTSIncAReportApp._3_ServiceCenter;
  5. using OTSIncAReportApp.DataOperation.DataAccess;
  6. using OTSIncAReportApp.OTSSampleReportInfo;
  7. using OTSIncAReportApp.SysMgrTools;
  8. using OTSIncAReportGraph.Class;
  9. using OTSIncAReportGraph.OTSIncAReportGraphFuncation;
  10. using OTSIncAReportMailInterface;
  11. using OTSRptPeriodicTable;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Data;
  15. using System.Diagnostics;
  16. using System.Drawing;
  17. using System.Drawing.Drawing2D;
  18. using System.IO;
  19. using System.Linq;
  20. using System.Threading;
  21. using System.Windows.Forms;
  22. using System.Windows.Media.Imaging;
  23. using System.Xml;
  24. namespace OTSIncAReportGraph.Controls
  25. {
  26. public enum SelectedShape
  27. {
  28. Rectangle=0,
  29. Ellipse = 1
  30. }
  31. public struct SelectTool
  32. {
  33. public SelectedShape Shape;
  34. public Point StartPoint;
  35. public bool IsSelecting;
  36. //进行选择的矩形范围
  37. public RectangleF Rect ;
  38. }
  39. public struct ParticleSegmentation
  40. {
  41. public Point StartPoint;
  42. public bool IsParticleSegmentation;
  43. public Point EndPoint;
  44. public Particle ParticleData;
  45. public RectangleF Rectangle;
  46. }
  47. public enum RightButtonMenu
  48. {
  49. Include=0,
  50. MoveSEMToParticle=1,
  51. CopyImage=2,
  52. OriginalSplicing= 3,
  53. DeleteParticle=4,
  54. ParticleSegmentation=5,
  55. ImportSTDDb=6
  56. }
  57. /// <summary>
  58. /// 选择导出的图片是原图还是颗粒渲染后的图片
  59. /// </summary>
  60. public enum Outpic_enum
  61. {
  62. pic=0,
  63. Render_pic=1
  64. }
  65. public partial class Control_DrawDistrbutionImageAndBSE : UserControl
  66. {
  67. //缩放的增大缩小的增量
  68. private const float const_zoom_increment = 0.05f;
  69. //最大缩放倍数
  70. private const float m_f_zoom_max = 4f;
  71. //最小缩放倍数
  72. private float m_f_zoom_mix = 0.05f;
  73. //标尺原先大小的记录,参与计算
  74. private const float m_f_old_ruler_size = 100;
  75. double ls_d_cz_width;
  76. double ls_d_cz_height;
  77. #region 变量定义
  78. private SelectTool m_SelectTool;
  79. private ParticleSegmentation m_ParticleSegmentation;
  80. public bool isReView = false;
  81. public int reViewFieldId = 0;
  82. public int reViewParticleId = 0;
  83. //与原先缩放的记录数
  84. private float m_zoom_record = 1;
  85. //标尺的大小记录
  86. public float m_f_ruler_size = 100;
  87. public double m_pixelSize = 4.5f;
  88. //国际化存储信息
  89. System.Collections.Hashtable table;
  90. //包含particle的field的列表对象
  91. public List<DisplayField> m_list_allDfield = null;
  92. //这里要做成控件,不要是窗体
  93. public List<DisplayParticle> m_list_allDPart = null;
  94. //总背景矩形
  95. public RectangleF m_backRect = new RectangleF();
  96. //记录总物理矩形总大小
  97. public RectangleF m_back_wl_rectf = new RectangleF();
  98. //是否显示网格线
  99. private bool m_is_showgrid = false;
  100. //绘制的网格中,需要几条线,宽
  101. public double m_i_grid_showlinesnumber_width = 0;
  102. //绘制的网格中,需要几条线,高
  103. public double m_i_grid_showlinesnumber_height = 0;
  104. //是否拖动
  105. private bool m_isDrag = false;
  106. //拖动前的坐标记录
  107. private PointF m_beforedrag_pointf = new PointF();
  108. //提供鼠标在右下角显示的文本,左侧
  109. private string m_str_mouseshow_left = "";
  110. //提供鼠标在右下角显示的文本,右侧
  111. private string m_str_mouseshow_right = "";
  112. //整个背景矩形的背景色
  113. private Color m_backrangecolor = Color.White;
  114. OTSImageDisHelp m_disHelper = null;
  115. //当前鼠标的位置
  116. Point m_mouse_now_point = new Point();
  117. //记录当前鼠标位置对应SEM电镜的位置
  118. Point m_sem_mouse_now_point = new Point();
  119. //鼠标移动经过的颗粒对象,临时存放,用来记录是否要显示xray与隐藏xray
  120. DisplayParticle m_mouseOver_dparticle = null;
  121. //保存数据源名称
  122. private string m_showsourcename = "";
  123. //保存当前数据源的ID
  124. private int m_datasourceid = 0;
  125. //移动SEM到指定位置发生线程
  126. private Thread m_mythread;
  127. private Color m_ColorNotContent = Color.SkyBlue;
  128. //读取背景原图的名称和图片
  129. private Dictionary<string, Image> originalImages = new Dictionary<string, Image>();
  130. //背景使用原图
  131. private bool OriginalBackground = false;
  132. static System.Windows.Forms.Timer delaytimer = new System.Windows.Forms.Timer();
  133. Logger log;
  134. /// <summary>
  135. /// 当前正在显示的数据源名称,用来与框架调用条件判断使用
  136. /// </summary>
  137. public string ShowSourceName
  138. {
  139. set { m_showsourcename = value; }
  140. get { return m_showsourcename; }
  141. }
  142. /// <summary>
  143. /// 当前正在显示的数据源的ID
  144. /// </summary>
  145. public int DataSourceID
  146. {
  147. set { m_datasourceid = value; }
  148. get { return m_datasourceid; }
  149. }
  150. /// <summary>
  151. /// 背景矩形属性
  152. /// </summary>
  153. public RectangleF BackRectF
  154. {
  155. set { m_backRect = value; }
  156. get { return m_backRect; }
  157. }
  158. public OTSImageDisHelp imageDisHelper { get => m_disHelper; set => m_disHelper = value; }
  159. //测试用隐藏颗粒的id号,回头去掉
  160. public int test_hide_particle_tagid = 1000;
  161. //进度条窗体
  162. public Frm_UserProgress m_frm_userprogress;
  163. /// <summary>
  164. /// 是否显示过小颗粒
  165. /// </summary>
  166. public bool bShowSmallParticle = false;
  167. OTSIncAReportApp.frmReportApp m_ReportApp;
  168. ResultFile resultFile = null;
  169. #endregion
  170. #region 构造函数及窗体加载
  171. public Control_DrawDistrbutionImageAndBSE(OTSIncAReportApp.frmReportApp ReportApp)
  172. {
  173. log = NLog.LogManager.GetCurrentClassLogger();
  174. m_list_allDfield = new List<DisplayField>();
  175. m_list_allDPart = new List<DisplayParticle>();
  176. m_frm_userprogress = new Frm_UserProgress();
  177. //m_mythread_state = false;
  178. m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
  179. m_ReportApp = ReportApp;
  180. resultFile = m_ReportApp.m_rstDataMgr.CurResultFile;
  181. //初始化底层操作类
  182. imageDisHelper = new OTSImageDisHelp(resultFile);
  183. InitializeComponent();
  184. #region 国际化语言
  185. Language lan = new Language(this);
  186. table = lan.GetNameTable(this.Name);
  187. #endregion
  188. //load the userdefine control dynamically
  189. System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Control_DrawDistrbutionImageAndBSE));
  190. this.control_XRayTable1 = new Control_XRayTable();
  191. this.control_XRayTable1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
  192. this.control_XRayTable1.Dock = System.Windows.Forms.DockStyle.Bottom;
  193. this.control_XRayTable1.GBInfoStr = "";
  194. this.control_XRayTable1.GoodChineseName = "";
  195. this.control_XRayTable1.MaterialName = "";
  196. this.control_XRayTable1.List_ShowElementInfo = ((System.Collections.Generic.List<OTSIncAReportGraph.Controls.ShowElementInfo>)(resources.GetObject("control_XRayTable1.List_ShowElementInfo")));
  197. this.control_XRayTable1.Location = new System.Drawing.Point(0, 400);
  198. this.control_XRayTable1.Name = "control_XRayTable1";
  199. this.control_XRayTable1.ShowAnalysisXray = true;
  200. this.control_XRayTable1.ShowSearchXray = false;
  201. this.control_XRayTable1.Size = new System.Drawing.Size(1004, 200);
  202. this.control_XRayTable1.STDName = "";
  203. this.control_XRayTable1.TabIndex = 6;
  204. this.control_XRayTable1.Visible = false;
  205. //
  206. // control_Ruler1
  207. //
  208. this.control_Ruler1 = new Control_Ruler();
  209. this.control_Ruler1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(200)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
  210. this.control_Ruler1.Location = new System.Drawing.Point(3, 400);
  211. this.control_Ruler1.Name = "control_Ruler1";
  212. this.control_Ruler1.RulerWidth = 100;
  213. this.control_Ruler1.ShowString = "100um";
  214. this.control_Ruler1.Size = new System.Drawing.Size(120, 40);
  215. this.control_Ruler1.TabIndex = 8;
  216. this.control_Ruler1.Value = 0D;
  217. this.control_Ruler1.Visible = false;
  218. this.Controls.Add(this.control_XRayTable1);
  219. this.Controls.Add(this.control_Ruler1);
  220. }
  221. private void ProgressBarUpdate(int progress, string message)
  222. {
  223. //显示进度条,计算进度条应该显示的位置和宽度
  224. if (m_frm_userprogress.Visible == false)
  225. {
  226. Form ls_main_form = this.ParentForm.ParentForm;//取出父窗体
  227. m_frm_userprogress.Width = (int)(MyPrimaryScreen.DESKTOP.Width / MyPrimaryScreen.ScaleX * 0.9);
  228. m_frm_userprogress.Location = new Point(ls_main_form.Location.X + 80, ls_main_form.Location.Y + (int)(MyPrimaryScreen.DESKTOP.Height / MyPrimaryScreen.ScaleX) / 2);
  229. m_frm_userprogress.Show();
  230. }
  231. m_frm_userprogress.SetProgressValueAndText(progress, message);
  232. }
  233. private void Control_DrawDistrbutionImageAndBSE_Load(object sender, EventArgs e)
  234. {
  235. //设置双缓冲
  236. SetDoubleBufferByIsDraw();
  237. ProgressBarUpdate(0, table["str1"].ToString());
  238. //执行获取颗粒分布图数据,总过程函数
  239. GetDistrbutionImageAndBSE_Total();
  240. //设置标尺
  241. //根据f_onepixel_size计算出要显示出100um的实际宽度
  242. double d_onefixel_width = 100 / m_pixelSize;
  243. if (d_onefixel_width == 0)
  244. {
  245. this.control_Ruler1.Visible = false;
  246. }
  247. else
  248. {
  249. //将标尺定位到合理的位置上
  250. this.control_Ruler1.Location = new Point(10, MyPrimaryScreen.WorkingArea.Height - 300);
  251. this.control_Ruler1.Visible = true;
  252. this.control_Ruler1.SetValue(m_f_ruler_size, m_pixelSize);
  253. }
  254. ProgressBarUpdate(100, table["str2"].ToString());
  255. m_frm_userprogress.Visible = false;
  256. }
  257. /// <summary>
  258. /// 获取组整个获取分布图和排序图图像数据的底层数据组建方式,的总过程
  259. /// </summary>
  260. public void GetDistrbutionImageAndBSE_Total()
  261. {
  262. string str27 = "begin to loading data....";
  263. log.Info(str27);
  264. Application.DoEvents();
  265. ProgressBarUpdate(1, str27);
  266. List<Field> fieldlist = resultFile.List_OTSField;
  267. //防止有时底层返回的Field的List是0,直接返回
  268. if (fieldlist.Count == 0)
  269. {
  270. ProgressBarUpdate(100, "field number =0 !....");
  271. return;
  272. }
  273. string str29 = "begin to compose field picture....";
  274. log.Info(str29);
  275. Application.DoEvents();
  276. ProgressBarUpdate(15, str29);
  277. //第一次循环,用来计算单个Field的像素分辨率,和将所有的物理位置存放到List当中
  278. List<Point> list_point = new List<Point>();
  279. int fieldwidth = 0, fieldheight = 0;
  280. //获取到该field的分辨率大小,循环中都是一样的
  281. if (fieldlist.Count > 0)
  282. {
  283. Rectangle r = imageDisHelper.GetImageWidthAndHeight();
  284. fieldwidth = r.Width;
  285. fieldheight = r.Height;
  286. }
  287. for (int i = 0; i < fieldlist.Count(); i++)
  288. {
  289. //然后取出物理坐标,这个一会要与分辨率坐标进行变算一下
  290. Point ls_point = new Point() { X = fieldlist[i].FieldPosX, Y = fieldlist[i].FieldPosY };
  291. list_point.Add(ls_point);
  292. }
  293. //计算出整个绘制图像总Rectagnle的大小
  294. m_backRect = imageDisHelper. ConvertAndGetMaxRect(list_point, fieldwidth, fieldheight);
  295. ProgressBarUpdate(18, "calculate ruler....");
  296. #region //标尺相关------------------------------------------------------------------------------
  297. RectangleF ls_jsblrect = imageDisHelper.GetPhysicalFieldWidthAndHeight();
  298. //然后用宽度来除以i_field_width 获取单个的像素比例
  299. m_pixelSize = Convert.ToDouble(ls_jsblrect.Width) / Convert.ToDouble(fieldwidth);
  300. #endregion //---------------------------------------------------------------------------------------
  301. ProgressBarUpdate(20, "compose whole picture....");
  302. //70的进度条给到下面的循环中,计算进度条各分类进度分配
  303. float ls_int_progresscalc = 0;
  304. if (fieldlist.Count > 0)
  305. ls_int_progresscalc = (float)70 / (float)fieldlist.Count;
  306. string str32 = "finished ";
  307. string str33 = "total ";
  308. string str34 = "field...";
  309. var otsLeftBottomPoint = imageDisHelper.GetOTSCoordLeftBottomPoint(list_point);
  310. m_list_allDfield.Clear();
  311. m_list_allDPart.Clear();
  312. for (int i = 0; i < fieldlist.Count(); i++)
  313. {
  314. ProgressBarUpdate(20 + (int)(ls_int_progresscalc * (i + 1)), str32 + i.ToString() + str33 + resultFile.List_OTSField.Count.ToString() + str34);
  315. //取出该Field的物理坐标,将其转换成对应的屏幕像素坐标,屏幕左上角为原点(0,0)的偏移值,用于后面计算各Segment的位置使用
  316. Point thisfield_point = new Point() { X = fieldlist[i].FieldPosX, Y = fieldlist[i].FieldPosY };
  317. Point offset_point = imageDisHelper.ConvertOTSCoordToScreenCoord(otsLeftBottomPoint, m_pixelSize, thisfield_point, m_backRect, new RectangleF(0,0,fieldwidth,fieldheight));//the ots coordinate is always the up right positive.
  318. DisplayField df = new DisplayField(fieldlist[i],fieldwidth,fieldheight, offset_point);
  319. m_list_allDfield.Add(df);
  320. m_list_allDPart.AddRange(df.List_DParticle);
  321. }
  322. ProgressBarUpdate(90, "convert solution...");
  323. //然后这里还需要计算出,各field的宽和高,帧图边框分别需要显示多少个框
  324. if (fieldwidth != 0 && fieldheight != 0)
  325. {
  326. m_i_grid_showlinesnumber_width = Convert.ToInt32(BackRectF.Width / fieldwidth);
  327. m_i_grid_showlinesnumber_height = Convert.ToInt32(BackRectF.Height / fieldheight);
  328. }
  329. ProgressBarUpdate(95, "other work...");
  330. //相关计数
  331. imageDisHelper.m_field_count = fieldlist.Count;
  332. imageDisHelper.m_particle_count = m_list_allDPart.Count;
  333. }
  334. /// <summary>
  335. /// 分布图和BSE图中,从底层获取相关结果后,重新组织显示
  336. /// </summary>
  337. /// <param name="sourceGridData"></param>
  338. public void FilterParticleByOtherCondition(ReportCondition sourceGridData)
  339. {
  340. bool sizeconditionResult;
  341. bool stdIdconditionResult;
  342. string stdId = "";
  343. int stdIdIndex = 0;
  344. //find the stdId condition
  345. var STDIdItm = sourceGridData.ConditionItemList.Find(s => s.iItemId == OTS_REPORT_PROP_GRID_ITEMS.STD_ID);
  346. if (STDIdItm != null)
  347. {
  348. stdId = STDIdItm.itemDisplayVal.ToString();
  349. stdIdIndex = STDIdItm.comboDownList.IndexOf(stdId);
  350. }
  351. //find the size condition
  352. var size_cal_method_type = (SIZE_CAL_METHOD_TYPE)sourceGridData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE);
  353. var itm = sourceGridData.ConditionItemList.Find(s => s.iItemId == OTS_REPORT_PROP_GRID_ITEMS.GRAIN_SIZE_CLASS);
  354. string size = itm.itemDisplayVal.ToString();
  355. int index = itm.comboDownList.IndexOf(size);
  356. string min = "0";
  357. string max = "999";
  358. if (index > 0)
  359. {
  360. max = sourceGridData.ConditionItemList.Find(s => s.iItemId == OTS_REPORT_PROP_GRID_ITEMS.GRAIN_SIZE_MAX).itemDisplayVal.ToString();
  361. min = sourceGridData.ConditionItemList.Find(s => s.iItemId == OTS_REPORT_PROP_GRID_ITEMS.GRAIN_SIZE_MIN).itemDisplayVal.ToString();
  362. if (max.ToLower() == "max")
  363. {
  364. max = "999";
  365. }
  366. }
  367. double dia_min = Convert.ToDouble(min);
  368. double dia_max = Convert.ToDouble(max);
  369. foreach (DisplayParticle ls_dp in m_list_allDPart)
  370. {
  371. if (index > 0)
  372. {
  373. double diameter = 0;
  374. switch (size_cal_method_type)
  375. {
  376. case SIZE_CAL_METHOD_TYPE.DMAX:
  377. diameter = ls_dp.objParticleData.DMAX;
  378. break;
  379. case SIZE_CAL_METHOD_TYPE.DMIN:
  380. diameter = ls_dp.objParticleData.DMIN;
  381. break;
  382. case SIZE_CAL_METHOD_TYPE.CIRCLE:
  383. diameter = Math.Sqrt(ls_dp.objParticleData.Area / 3.14159f) * 2f;
  384. break;
  385. case SIZE_CAL_METHOD_TYPE.DFERET:
  386. diameter = ls_dp.objParticleData.DFERET;
  387. break;
  388. default:
  389. diameter = 0;
  390. break;
  391. }
  392. if (diameter >= dia_min && diameter <= dia_max)
  393. {
  394. sizeconditionResult = true;
  395. }
  396. else
  397. {
  398. sizeconditionResult = false;
  399. }
  400. }
  401. else
  402. {
  403. sizeconditionResult = true;
  404. }
  405. if (stdIdIndex > 0)// it's not "All"
  406. {
  407. if (ls_dp.objParticleData.TypeName != stdId)
  408. {
  409. stdIdconditionResult = false;
  410. }
  411. else
  412. {
  413. stdIdconditionResult = true;
  414. }
  415. }
  416. else
  417. {
  418. stdIdconditionResult = true;
  419. }
  420. if (stdIdconditionResult && sizeconditionResult)
  421. {
  422. ls_dp.SetDisplayState(DisplayState.DISPLAY);
  423. }
  424. else
  425. {
  426. ls_dp.SetDisplayState(DisplayState.NODISPLAY);
  427. }
  428. }
  429. }
  430. #endregion
  431. #region 设置双缓冲
  432. /// <summary>
  433. /// 设置双缓冲
  434. /// </summary>
  435. public void SetDoubleBufferByIsDraw()
  436. {
  437. SetStyle(ControlStyles.UserPaint, true); //没什么效果,开与关
  438. SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景,关了闪
  439. SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // 双缓冲,关了闪
  440. //上面是必须有的
  441. SetStyle(ControlStyles.UserMouse, true); //执行自己的鼠标行为,这个打开后,在win7下鼠标操作明显改善
  442. }
  443. #endregion
  444. #region 绘制函数
  445. protected override void OnPaint(PaintEventArgs e)//处理重绘情况
  446. {
  447. if (OriginalBackground)
  448. {
  449. GetPic(e);
  450. }
  451. else
  452. {
  453. #region //填充个背景色矩形-----------------------------------------------
  454. SolidBrush b = new SolidBrush(m_backrangecolor);
  455. e.Graphics.FillRectangle(b, m_backRect);
  456. #endregion
  457. }
  458. #region //计算并进行绘制部份------------------------------------
  459. foreach (DisplayParticle item in m_list_allDPart)
  460. {
  461. DisplayParticle dp =item;
  462. if (isReView)
  463. {
  464. if (dp.objParticleData.FieldId == reViewFieldId && dp.objParticleData.ParticleId == reViewParticleId)
  465. {
  466. dp.IsSelect = true;
  467. }
  468. }
  469. if (dp.GetPaintState() != PaintState.NOPAINT)
  470. {
  471. dp.OnPaint(e);
  472. }
  473. }
  474. #endregion
  475. #region //判断是否使用了矩形或圆形工具进行多选,是的话,那么这里就开始绘制------------------------
  476. if (m_SelectTool.IsSelecting)
  477. {
  478. if (m_SelectTool.Shape==SelectedShape.Rectangle && m_SelectTool.Rect.Width > 0 && m_SelectTool.Rect.Height > 0)
  479. {
  480. Graphics g = e.Graphics;
  481. //绘制矩形
  482. g.DrawRectangle(new Pen(Color.Blue), m_SelectTool.Rect.X, m_SelectTool.Rect.Y, m_SelectTool.Rect.Width, m_SelectTool.Rect.Height);
  483. //半透明画刷
  484. SolidBrush brush = new SolidBrush(Color.FromArgb(50, m_ColorNotContent));
  485. //填充选择矩形
  486. g.FillRectangle(brush, m_SelectTool.Rect.X, m_SelectTool.Rect.Y, m_SelectTool.Rect.Width, m_SelectTool.Rect.Height);
  487. }
  488. if (m_SelectTool.Shape == SelectedShape.Ellipse && m_SelectTool.Rect.Width > 0 && m_SelectTool.Rect.Height > 0)
  489. {
  490. Graphics g = e.Graphics;
  491. //绘制圆形
  492. g.DrawEllipse(new Pen(Color.Blue), m_SelectTool.Rect.X, m_SelectTool.Rect.Y, m_SelectTool.Rect.Width, m_SelectTool.Rect.Height);
  493. //半透明画刷
  494. SolidBrush brush = new SolidBrush(Color.FromArgb(50, m_ColorNotContent));
  495. //填充选择圆形
  496. g.FillEllipse(brush, m_SelectTool.Rect.X, m_SelectTool.Rect.Y, m_SelectTool.Rect.Width, m_SelectTool.Rect.Height);
  497. }
  498. }
  499. #endregion
  500. #region //判断是否使用颗粒分割,是的话,那么这里就开始绘制------------------------
  501. if (m_ParticleSegmentation.IsParticleSegmentation)
  502. {
  503. e.Graphics.DrawLine(new Pen(Color.Red), m_ParticleSegmentation.StartPoint.X, m_ParticleSegmentation.StartPoint.Y, m_ParticleSegmentation.EndPoint.X, m_ParticleSegmentation.EndPoint.Y);
  504. }
  505. #endregion
  506. #region 绘制网格线,帧图边框部份
  507. if (true == m_is_showgrid)
  508. {
  509. RectangleF ls_rect_gridline = Rectangle.Round(new RectangleF(m_backRect.X,
  510. m_backRect.Y,
  511. m_backRect.Width,
  512. m_backRect.Height));
  513. //共绘制外边框,和里面横竖,各4个线
  514. ControlPaint.DrawBorder(e.Graphics,
  515. Rectangle.Ceiling(ls_rect_gridline),
  516. Color.BurlyWood,
  517. 1,
  518. ButtonBorderStyle.Solid,
  519. Color.BurlyWood,
  520. 1,
  521. ButtonBorderStyle.Solid,
  522. Color.BurlyWood,
  523. 1,
  524. ButtonBorderStyle.Solid,
  525. Color.BurlyWood,
  526. 1,
  527. ButtonBorderStyle.Solid);
  528. //然后再把rectangle,横竖分成4块,画上4条横竖线
  529. //画横线
  530. for (int i = 1; i < m_i_grid_showlinesnumber_height; i++)
  531. {
  532. double y_zl = ls_rect_gridline.Height / m_i_grid_showlinesnumber_height;
  533. e.Graphics.DrawLine(new Pen(Color.BurlyWood),
  534. ls_rect_gridline.X,
  535. Convert.ToInt64(ls_rect_gridline.Y + y_zl * i),
  536. ls_rect_gridline.X + ls_rect_gridline.Width,
  537. Convert.ToInt64(ls_rect_gridline.Y + y_zl * i));
  538. }
  539. //画竖线
  540. for (int i = 1; i < m_i_grid_showlinesnumber_width; i++)
  541. {
  542. double x_zl = ls_rect_gridline.Width / m_i_grid_showlinesnumber_width;
  543. e.Graphics.DrawLine(new Pen(Color.BurlyWood),
  544. Convert.ToInt64(ls_rect_gridline.X + x_zl * i),
  545. ls_rect_gridline.Y,
  546. Convert.ToInt64(ls_rect_gridline.X + x_zl * i),
  547. ls_rect_gridline.Y + ls_rect_gridline.Height);
  548. }
  549. }
  550. #endregion
  551. #region 绘制鼠标跟踪线部份
  552. //XX虚线-----------------------------------------------
  553. Pen xxpen = new Pen(Color.GreenYellow, 1);
  554. xxpen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
  555. xxpen.DashPattern = new float[] { 5, 5 };
  556. //竖线
  557. e.Graphics.DrawLine(xxpen, 0, m_mouse_now_point.Y, m_mouse_now_point.X - 10, m_mouse_now_point.Y);
  558. e.Graphics.DrawLine(xxpen, m_mouse_now_point.X + 10, m_mouse_now_point.Y, this.Width, m_mouse_now_point.Y);
  559. //横线
  560. e.Graphics.DrawLine(xxpen, m_mouse_now_point.X, 0, m_mouse_now_point.X, m_mouse_now_point.Y - 10);
  561. e.Graphics.DrawLine(xxpen, m_mouse_now_point.X, m_mouse_now_point.Y + 10, m_mouse_now_point.X, this.Height);
  562. ////--------------------------------------------------------------------------------
  563. #endregion
  564. }
  565. #endregion
  566. #region 鼠标操作事件
  567. private void ImageZoom(float newZoom,PointF refPoint)
  568. {
  569. float zoomDelta = newZoom - m_zoom_record;
  570. if (zoomDelta == 0) return;
  571. m_backRect.Width += m_backRect.Width/m_zoom_record*zoomDelta;
  572. m_backRect.Height += m_backRect.Height / m_zoom_record*zoomDelta;
  573. //锚点缩放补差值计算,得出差值
  574. float xShiftOld = (m_backRect.X-refPoint.X );
  575. float yShiftOld = (m_backRect.Y-refPoint.Y );
  576. float xShift = m_backRect.X-refPoint.X + xShiftOld/m_zoom_record * zoomDelta;
  577. float yShift = m_backRect.Y-refPoint.Y + yShiftOld/m_zoom_record * zoomDelta;
  578. //对背景矩形与所有的segment进行修补差值
  579. m_backRect.X = refPoint.X + xShift;
  580. m_backRect.Y = refPoint.Y + yShift;
  581. for (int i = 0; i < m_list_allDPart.Count(); i++)
  582. {
  583. DisplayParticle dp = m_list_allDPart[i];
  584. dp.Zoom(zoomDelta, refPoint);
  585. PointF ct =dp. GetCenterPoint();
  586. if (ct.X < -100 || ct.X > this.Width + 100 || ct.Y < -100 || ct.Y > this.Height + 100)
  587. {
  588. dp.SetPaintState(PaintState.NOPAINT);//the particles which are out of screen don't display.to speed up the display efficient.
  589. }
  590. }
  591. if (m_list_allDfield != null)
  592. {
  593. if (m_list_allDfield.Count > 0)
  594. {
  595. for (int i = 0; i < m_list_allDfield.Count; i++)
  596. {
  597. DisplayField theField = m_list_allDfield[i];
  598. theField.Zoom(zoomDelta,refPoint);
  599. }
  600. }
  601. }
  602. #region 计算标尺尺寸部份-----放大------
  603. //计算标尺实际占用像素的宽度
  604. m_f_ruler_size = m_f_ruler_size + Convert.ToInt32(m_f_old_ruler_size * zoomDelta);//m_f_old_ruler_size
  605. control_Ruler1.SetValue(m_f_ruler_size, m_pixelSize);
  606. #endregion
  607. m_zoom_record = newZoom;
  608. if (m_zoom_record <= m_f_zoom_mix)
  609. {
  610. MoveImageToPoint(new PointF(0, 0));
  611. }
  612. }
  613. protected override void OnMouseWheel(MouseEventArgs e)
  614. {
  615. //float zoomDelta;
  616. float currentZoom;
  617. if (e.Delta > 0)
  618. {
  619. currentZoom=m_zoom_record + const_zoom_increment;
  620. }
  621. else
  622. {
  623. currentZoom=m_zoom_record - const_zoom_increment;
  624. }
  625. if (currentZoom > m_f_zoom_max) currentZoom = m_f_zoom_max;
  626. if(currentZoom < m_f_zoom_mix) currentZoom=m_f_zoom_mix;
  627. ImageZoom(currentZoom, new PointF(e.X, e.Y));
  628. Invalidate();
  629. }
  630. protected override void OnMouseDown(MouseEventArgs e)
  631. {
  632. if (e.Button == MouseButtons.Left)
  633. {
  634. this.Cursor = Cursors.Hand;
  635. isReView = false;
  636. if (m_SelectTool.IsSelecting)
  637. {
  638. m_SelectTool.StartPoint = e.Location;
  639. }
  640. else if (m_ParticleSegmentation.IsParticleSegmentation)
  641. {
  642. m_ParticleSegmentation.StartPoint= e.Location;
  643. }
  644. else
  645. {
  646. bool ifClickOnParticle=false;
  647. foreach (DisplayParticle item in m_list_allDPart)
  648. {
  649. var dp = item;
  650. if (imageDisHelper.WhetherInRange(dp, e.Location))
  651. {
  652. dp.IsSelect = !dp.IsSelect;
  653. ifClickOnParticle = true;
  654. break;
  655. }
  656. }
  657. if (ifClickOnParticle == false)
  658. {
  659. foreach (DisplayParticle item in m_list_allDPart)
  660. {
  661. var dp = item;
  662. PointF ct = dp.GetCenterPoint();
  663. if (ct.X > -100 && ct.X < this.Width + 100 && ct.Y > -100 && ct.Y < this.Height + 100)
  664. {
  665. item.IsDragging = true;
  666. }
  667. item.DraggingPoint = e.Location;
  668. if (OriginalBackground)
  669. {
  670. dp.SetPaintState(PaintState.NOPAINT);
  671. }
  672. }
  673. foreach (DisplayField item in m_list_allDfield)
  674. {
  675. item.IsDragging = true;
  676. item.DraggingPoint = e.Location;
  677. }
  678. m_isDrag = true;
  679. m_beforedrag_pointf = e.Location;
  680. }
  681. }
  682. }
  683. Invalidate();
  684. }
  685. protected override void OnMouseMove(MouseEventArgs e)
  686. {
  687. //当前鼠标的位置,用来绘制鼠标线用
  688. m_mouse_now_point = e.Location;
  689. if (m_ParticleSegmentation.IsParticleSegmentation)
  690. {
  691. if (e.Button == MouseButtons.Left)
  692. {
  693. m_ParticleSegmentation.EndPoint = e.Location;
  694. }
  695. }
  696. if (m_SelectTool.IsSelecting)
  697. {
  698. if (e.Button == MouseButtons.Left)
  699. {
  700. if (e.Location.X > m_SelectTool.StartPoint.X && e.Location.Y > m_SelectTool.StartPoint.Y)
  701. {
  702. //右下拖动
  703. m_SelectTool.Rect = new RectangleF(m_SelectTool.StartPoint, new SizeF(e.Location.X - m_SelectTool.StartPoint.X, e.Location.Y - m_SelectTool.StartPoint.Y));
  704. }
  705. if (e.Location.X < m_SelectTool.StartPoint.X && e.Location.Y < m_SelectTool.StartPoint.Y)
  706. {
  707. //左上拖动
  708. PointF lspointf = new PointF(e.Location.X, e.Location.Y);
  709. m_SelectTool.Rect = new RectangleF(lspointf, new SizeF(m_SelectTool.StartPoint.X - e.Location.X, m_SelectTool.StartPoint.Y - e.Location.Y));
  710. }
  711. if (e.Location.X > m_SelectTool.StartPoint.X && e.Location.Y < m_SelectTool.StartPoint.Y)
  712. {
  713. //右上,这种画法,需要将左下,右上两点转换成左上,右下
  714. PointF left_pointf = new PointF(m_SelectTool.StartPoint.X, e.Location.Y);
  715. PointF right_pointf = new PointF(e.Location.X, m_SelectTool.StartPoint.Y);
  716. m_SelectTool.Rect = new RectangleF(left_pointf, new SizeF(right_pointf.X - left_pointf.X, right_pointf.Y - left_pointf.Y));
  717. }
  718. if (e.Location.X < m_SelectTool.StartPoint.X && e.Location.Y > m_SelectTool.StartPoint.Y)
  719. {
  720. //左下,这种画法,需要将左下,右上两点转换成左上,右下
  721. PointF left_pointf = new PointF(e.Location.X, m_SelectTool.StartPoint.Y);
  722. PointF right_pointf = new PointF(m_SelectTool.StartPoint.X, e.Location.Y);
  723. m_SelectTool.Rect = new RectangleF(left_pointf, new SizeF(right_pointf.X - left_pointf.X, right_pointf.Y - left_pointf.Y));
  724. }
  725. }
  726. }
  727. else
  728. {
  729. if (m_isDrag)
  730. {
  731. foreach (DisplayParticle dp in m_list_allDPart)
  732. {
  733. if ( dp.IsDragging)
  734. {
  735. dp.DraggingMove(e.Location);
  736. PointF ct = dp.GetCenterPoint();
  737. if (ct.X < -100 || ct.X > this.Width + 100 || ct.Y < -100 || ct.Y > this.Height + 100)
  738. {
  739. dp.SetPaintState(PaintState.NOPAINT);//the particles which are out of screen don't display.to speed up the display efficient.
  740. }
  741. else
  742. {
  743. dp.SetPaintState(PaintState.PAINT);
  744. }
  745. }
  746. }
  747. foreach (var item in m_list_allDfield)
  748. {
  749. if ( item.IsDragging)
  750. {
  751. item.DraggingMove(e.Location);
  752. }
  753. }
  754. //同样重新计算backrectf的坐标
  755. m_backRect = new RectangleF(m_backRect.Location.X + e.X - m_beforedrag_pointf.X,
  756. m_backRect.Location.Y + e.Y - m_beforedrag_pointf.Y, m_backRect.Width, m_backRect.Height);
  757. m_beforedrag_pointf = e.Location;
  758. }
  759. else
  760. {
  761. foreach (DisplayParticle item in m_list_allDPart)
  762. {
  763. DisplayParticle dp = item;
  764. if (dp.GetPaintState() == PaintState.PAINT)
  765. {
  766. if (imageDisHelper.WhetherInRange(dp, e.Location))
  767. {
  768. dp.IsMouseOver = true;
  769. ShowParticleInfo(dp);
  770. m_ParticleSegmentation.Rectangle = dp.GetShowRect();
  771. }
  772. else
  773. {
  774. dp.IsMouseOver = false;
  775. HideParticleInfo(dp);
  776. }
  777. }
  778. }
  779. }
  780. }
  781. #region 向报告程序右下角,传送鼠标颗粒等相关信息
  782. //获取颜色方法1,使用API来获取当前鼠标指向位置的颜色值-----------------------------------------------------
  783. Color ls_c = GetColorByMousePoint(e.X, e.Y);
  784. m_str_mouseshow_right = "灰度#" + ls_c.R.ToString();
  785. m_ReportApp.mouseMatter.Text = m_str_mouseshow_right ;
  786. m_ReportApp.RSGrayVal.Text = m_str_mouseshow_left;
  787. #endregion
  788. Invalidate();
  789. }
  790. /// <summary>
  791. /// 计算颗粒中心的电镜坐标
  792. /// </summary>
  793. /// <param name="resultFile"></param>
  794. /// <param name="SEMPos"></param>
  795. /// <param name="ParticlePos"></param>
  796. /// <returns></returns>
  797. public static Point CalculateParticleCenterPosition(ResultFile resultFile, Point SEMPos, Point ParticlePos)
  798. {
  799. Point point = new Point();
  800. Dictionary<string, object> sampleMembers = ((Dictionary<string, object>)((Dictionary<string, object>)resultFile.ResultInfo["Sample"])["Members"]);
  801. Dictionary<string, object> imageScanParam = (Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)sampleMembers["MsrParams"])["Members"])["ImageScanParam"];
  802. Dictionary<string, object> SEMDataMsr = (Dictionary<string, object>)sampleMembers["SEMDataMsr"];
  803. Dictionary<string, object> SEMStageData = (Dictionary<string, object>)resultFile.ResultInfo["SEMStageData"];
  804. float ScanFieldSizeX = float.Parse(SEMDataMsr["ScanFieldSize"].ToString());
  805. string leftOrRight = SEMStageData["xAxisDir"].ToString().Split(':')[1];
  806. string downOrUp = SEMStageData["yAxisDir"].ToString().Split(':')[1];
  807. string ImageResolution = imageScanParam["ImageResolution"].ToString();
  808. int width = int.Parse(ImageResolution.Split('_')[1]);
  809. int height = int.Parse(ImageResolution.Split('_')[2]);
  810. float ScanFieldSizeY = ScanFieldSizeX * height / width;
  811. float m_pixelSize = ScanFieldSizeX / width;
  812. if (leftOrRight == "RIGHT_TOWARD")
  813. {
  814. point.X = (int)(SEMPos.X - ScanFieldSizeX / 2 + ParticlePos.X * m_pixelSize);
  815. }
  816. else
  817. {
  818. point.X = (int)(SEMPos.X + ScanFieldSizeX / 2 - ParticlePos.X * m_pixelSize);
  819. }
  820. if (downOrUp == "UP_TOWARD")
  821. {
  822. point.Y = (int)(SEMPos.Y + ScanFieldSizeY / 2 - ParticlePos.Y * m_pixelSize);
  823. }
  824. else
  825. {
  826. point.Y = (int)(SEMPos.Y - ScanFieldSizeY / 2 + ParticlePos.Y * m_pixelSize);
  827. }
  828. return point;
  829. }
  830. /// <summary>
  831. /// 获取鼠标所在位置的信息,显示在框架的右下角
  832. /// </summary>
  833. /// <param name="mouseshow_left"></param>
  834. /// <param name="mouseshow_rightb"></param>
  835. public void GetMouseLowerRightCornerText(out string mouseshow_left, out string mouseshow_rightb)
  836. {
  837. mouseshow_left = m_str_mouseshow_left;
  838. mouseshow_rightb = m_str_mouseshow_right;
  839. }
  840. /// <summary>
  841. /// 鼠标抬起事件
  842. /// </summary>
  843. /// <param name="e"></param>
  844. protected override void OnMouseUp(MouseEventArgs e)
  845. {
  846. if (e.Button == MouseButtons.Left)
  847. {
  848. this.Cursor = Cursors.Default;
  849. if (m_SelectTool.IsSelecting)
  850. {
  851. if (m_SelectTool.Rect.Width > 0 && m_SelectTool.Rect.Height > 0)
  852. {
  853. GraphicsPath ls_gpath = new GraphicsPath();
  854. switch (m_SelectTool.Shape)
  855. {
  856. case SelectedShape.Rectangle:
  857. ls_gpath.AddRectangle(m_SelectTool.Rect);
  858. break;
  859. case SelectedShape.Ellipse:
  860. ls_gpath.AddEllipse(m_SelectTool.Rect);
  861. break;
  862. default:
  863. break;
  864. }
  865. foreach (DisplayParticle dp in m_list_allDPart)
  866. {
  867. if (dp.GetPaintState() != PaintState.NOPAINT )
  868. {
  869. PointF[] lspointf = ls_gpath.PathPoints;
  870. if (true == imageDisHelper.WhetherInRange(m_SelectTool.Rect, lspointf,new Point((int)dp.GetShowRect().X,(int)dp.GetShowRect().Y)))
  871. {
  872. dp.IsSelect =!dp.IsSelect ;// set the particle to the oposite selected state
  873. }
  874. }
  875. }
  876. }
  877. m_SelectTool.IsSelecting = false;
  878. }
  879. else if(m_ParticleSegmentation.IsParticleSegmentation)
  880. {
  881. m_ParticleSegmentation.EndPoint = e.Location;
  882. DialogResult res = MessageBox.Show(table["str11"].ToString(), "", MessageBoxButtons.OKCancel);
  883. if (res == DialogResult.OK)
  884. {
  885. m_disHelper.m_ParticleSegmentation = m_ParticleSegmentation;
  886. bool isTrue = m_disHelper.isLineIntersectRectangle(m_ParticleSegmentation.StartPoint.X, m_ParticleSegmentation.StartPoint.Y, m_ParticleSegmentation.EndPoint.X, m_ParticleSegmentation.EndPoint.Y,
  887. m_ParticleSegmentation.Rectangle.Left, m_ParticleSegmentation.Rectangle.Top, m_ParticleSegmentation.Rectangle.Right, m_ParticleSegmentation.Rectangle.Bottom);
  888. if (isTrue)//判断绘制线段是否与颗粒外接矩形相交
  889. {
  890. List<Point> pointList = new List<Point>();
  891. if (m_disHelper.GetInterBetweenLinesAndRect(m_ParticleSegmentation.StartPoint, m_ParticleSegmentation.EndPoint, m_ParticleSegmentation.Rectangle, ref pointList))
  892. {
  893. if (pointList.Count != 2)
  894. {
  895. MessageBox.Show(table["str12"].ToString());
  896. }
  897. else
  898. {
  899. if (!m_disHelper.GetSplitPartFun(pointList[0], pointList[1]))
  900. {
  901. MessageBox.Show(table["str13"].ToString());
  902. }
  903. else
  904. {
  905. FieldData fieldData = new FieldData(resultFile.FilePath);
  906. List<Field> fieldlist = fieldData.GetFieldList();
  907. m_ReportApp.m_rstDataMgr.CurResultFile.List_OTSField = fieldlist;
  908. m_ReportApp.rbRenewFun(true, m_ParticleSegmentation.ParticleData.FieldId, m_ParticleSegmentation.ParticleData.ParticleId);
  909. }
  910. }
  911. }
  912. }
  913. else
  914. {
  915. MessageBox.Show(table["str14"].ToString());
  916. }
  917. }
  918. m_ParticleSegmentation.IsParticleSegmentation = false;
  919. }
  920. else
  921. {
  922. if (m_isDrag)
  923. {
  924. foreach (DisplayParticle dp in m_list_allDPart)
  925. {
  926. dp.DraggingMove(e.Location);
  927. dp.DraggingPoint = Point.Empty;
  928. dp.IsDragging = false;
  929. PointF ct = dp.GetCenterPoint();
  930. if (ct.X < -100 || ct.X > this.Width + 100 || ct.Y < -100 || ct.Y > this.Height + 100)
  931. {
  932. dp.SetPaintState(PaintState.NOPAINT);//the particles which are out of screen don't display.to speed up the display efficient.
  933. }
  934. else
  935. {
  936. dp.SetPaintState(PaintState.PAINT);
  937. }
  938. }
  939. m_isDrag = false;
  940. }
  941. }
  942. }
  943. if (e.Button == MouseButtons.Right)
  944. {
  945. bool ifClickOnParticle=false;
  946. bool ifThereIsSelectedParticle = false;
  947. foreach (DisplayParticle item in m_list_allDPart)
  948. {
  949. if (true == imageDisHelper.WhetherInRange(item, e.Location))
  950. {
  951. ifClickOnParticle = true;
  952. CMenuStrip.Items[(int)RightButtonMenu.Include].Visible = false;
  953. CMenuStrip.Items[(int)RightButtonMenu.CopyImage].Visible = false;
  954. CMenuStrip.Items[(int)RightButtonMenu.OriginalSplicing].Visible = false;
  955. CMenuStrip.Items[(int)RightButtonMenu.DeleteParticle].Visible = true;
  956. CMenuStrip.Items[(int)RightButtonMenu.MoveSEMToParticle].Visible = true;
  957. CMenuStrip.Items[(int)RightButtonMenu.MoveSEMToParticle].Tag = item;
  958. DisplayParticle dp = (DisplayParticle)item;
  959. CMenuStrip.Items[(int)RightButtonMenu.ImportSTDDb].Visible = true;
  960. CMenuStrip.Items[(int)RightButtonMenu.ParticleSegmentation].Visible = true;
  961. m_ParticleSegmentation.ParticleData = dp.objParticleData;
  962. }
  963. if (((DisplayParticle)item).IsSelect)
  964. {
  965. ifThereIsSelectedParticle = true;
  966. }
  967. }
  968. if (ifClickOnParticle == false)
  969. {
  970. if (ifThereIsSelectedParticle)
  971. {
  972. CMenuStrip.Items[(int)RightButtonMenu.Include].Visible = true;
  973. }
  974. else
  975. {
  976. CMenuStrip.Items[(int)RightButtonMenu.Include].Visible = false;
  977. }
  978. CMenuStrip.Items[(int)RightButtonMenu.DeleteParticle].Visible = false;
  979. CMenuStrip.Items[(int)RightButtonMenu.CopyImage].Visible = true;
  980. CMenuStrip.Items[(int)RightButtonMenu.OriginalSplicing].Visible = true;
  981. CMenuStrip.Items[(int)RightButtonMenu.MoveSEMToParticle].Visible = false;
  982. CMenuStrip.Items[(int)RightButtonMenu.ParticleSegmentation].Visible = false;
  983. CMenuStrip.Items[(int)RightButtonMenu.ImportSTDDb].Visible = false;
  984. }
  985. }
  986. Invalidate();
  987. }
  988. #endregion
  989. #region 鼠标右键菜单
  990. private void ToolStripMenuItem_id_Click(object sender, EventArgs e)
  991. {
  992. //ID
  993. //DisplayParticle dp = (DisplayParticle)CMenuStrip.Items[0].Tag;
  994. //MessageBox.Show(dp.guid.ToString());
  995. }
  996. //是否显示过小颗菜单
  997. private void ToolStripMenuItem_ShowSmallParticle_Click(object sender, EventArgs e)
  998. {
  999. }
  1000. private void ToolStripMenuItem_selected_Click(object sender, EventArgs e)
  1001. {
  1002. List<DisplayParticle> selectedParts = new List<DisplayParticle>();
  1003. List<Particle> Particles = new List<Particle>();
  1004. foreach (var dp in m_list_allDPart)
  1005. {
  1006. if (dp.IsSelect)
  1007. {
  1008. selectedParts.Add((DisplayParticle)dp);
  1009. Particle particle = new Particle();
  1010. particle.FieldId = ((OTSIncAReportGraph.DisplayParticle)dp).FieldId;
  1011. particle.ParticleId = ((OTSIncAReportGraph.DisplayParticle)dp).ParticleId;
  1012. Particles.Add(particle);
  1013. }
  1014. }
  1015. frmReportApp.selectedRegion = m_SelectTool.Rect;
  1016. SendSelectParticleListToReportFrame(selectedParts);
  1017. }
  1018. /// <summary>
  1019. /// 显示x-ray能谱图
  1020. /// </summary>
  1021. /// <param name="in_dparticle"></param>
  1022. private void ShowParticleInfo(DisplayParticle in_dparticle)
  1023. {
  1024. if (delaytimer.Enabled == false)
  1025. {
  1026. m_mouseOver_dparticle = in_dparticle;//将显示xray的dparticle记录给全局变量
  1027. delaytimer.Tick += Delaytimer_Tick;
  1028. delaytimer.Interval = 500;
  1029. delaytimer.Start();
  1030. }
  1031. }
  1032. private void Delaytimer_Tick(object sender, EventArgs e)
  1033. {
  1034. delaytimer.Enabled = false;
  1035. Point point = CalculateParticleCenterPosition(resultFile, new Point(m_mouseOver_dparticle.SEMPosX, m_mouseOver_dparticle.SEMPosY), new Point(m_mouseOver_dparticle.objParticleData.PosX, m_mouseOver_dparticle.objParticleData.PosY));
  1036. m_str_mouseshow_left = "颗粒SEM位置:" + point.X.ToString() + ":" + point.Y.ToString();
  1037. m_sem_mouse_now_point = point;
  1038. //显示xray相关信息
  1039. uint[] Search_xray = new uint[2000];
  1040. uint[] Analysis_xray = new uint[2000];
  1041. //
  1042. int i_xray_id = 0;
  1043. List<Element> list_celementchemistryclr = new List<Element>();
  1044. //获取Xray数据
  1045. imageDisHelper.GetXrayByParticleTagIDAndFieldID_ForDrawDistrbutionImageAndBSE(m_mouseOver_dparticle.ParticleId, m_mouseOver_dparticle.FieldId, out Search_xray, out Analysis_xray, out i_xray_id, out list_celementchemistryclr);
  1046. //get CElementChemistryClr list
  1047. List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
  1048. for (int i = 0; i < list_celementchemistryclr.Count; i++)
  1049. {
  1050. ShowElementInfo ls_sei = new ShowElementInfo();
  1051. ls_sei.ElementName = list_celementchemistryclr[i].Name;
  1052. ls_sei.Percentage = list_celementchemistryclr[i].Percentage;
  1053. ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByYsm(CListPeriodic.GetListPeriodic(), ls_sei.ElementName).SX1);
  1054. double de_sx2 = 0;
  1055. if (CListPeriodic.GetPeriodicByYsm(CListPeriodic.GetListPeriodic(), ls_sei.ElementName).SX2 == "" || CListPeriodic.GetPeriodicByYsm(CListPeriodic.GetListPeriodic(), ls_sei.ElementName).SX2 == "-")
  1056. {
  1057. de_sx2 = 0;
  1058. }
  1059. else
  1060. {
  1061. de_sx2 = Convert.ToDouble(CListPeriodic.GetPeriodicByYsm(CListPeriodic.GetListPeriodic(), ls_sei.ElementName).SX2);
  1062. }
  1063. ls_sei.dLF = de_sx2;
  1064. list_showelementinfo.Add(ls_sei);
  1065. }
  1066. //获取使用标准库的名称
  1067. string str_IncAName = "";
  1068. str_IncAName = m_mouseOver_dparticle.TypeName;
  1069. Particle particle = resultFile.List_OTSField.Find(x => x.FieldID == m_mouseOver_dparticle.FieldId).ParticleList.Find(x => x.ParticleId == m_mouseOver_dparticle.ParticleId);
  1070. control_XRayTable1.SetParticleInfo("Area:"+ Math.Round(particle.Area,2)+" "+"DELONG:"+ Math.Round(particle.DELONG,2)+" "+"DFERET:"+ Math.Round(particle.DFERET,2)+" "+"DINSCR:"+ Math.Round(particle.DINSCR,2)+" "+"DMAX:"+ Math.Round(particle.DMAX,2)+"\n"+"DMEAN:"+ Math.Round(particle.DMEAN,2)+" "+"DMIN:"+ Math.Round(particle.DMIN,2)+" "+"DPERP:"+ Math.Round(particle.DPERP,2)+" "+"ORIENTATION:"+ Math.Round(particle.ORIENTATION,2)+" "+"PERIMETER:"+ Math.Round(particle.PERIMETER,2));
  1071. //获取数据后,需要对xraytable设置
  1072. control_XRayTable1.Visible = true;
  1073. control_XRayTable1.SetXRayShowLineValue(Search_xray, Analysis_xray, list_showelementinfo);
  1074. //颗粒国标信息
  1075. control_XRayTable1.GBInfoStr = "";
  1076. control_XRayTable1.MaterialName = str_IncAName;//杂夹物
  1077. control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
  1078. Invalidate();
  1079. }
  1080. /// <summary>
  1081. /// 隐藏x-ray能谱图
  1082. /// </summary>
  1083. private void HideParticleInfo(DisplayParticle in_dparticle)
  1084. {
  1085. if (m_mouseOver_dparticle == null)
  1086. return;
  1087. if (m_mouseOver_dparticle.guid == in_dparticle.guid || m_mouseOver_dparticle.IsDeleted==true)
  1088. {
  1089. //如果是刚才移动过的颗粒的话,那么这里再对xray进行隐藏
  1090. control_XRayTable1.Visible = false;
  1091. delaytimer.Enabled = false;
  1092. }
  1093. }
  1094. /// <summary>
  1095. /// 根据传入的鼠标位置,来获取当前鼠标位置上的灰度值
  1096. /// </summary>
  1097. /// <param name="int_x"></param>
  1098. /// <param name="int_y"></param>
  1099. /// <returns></returns>
  1100. private Color GetColorByMousePoint(int int_x, int int_y)
  1101. {
  1102. Graphics g = Graphics.FromHwnd(this.Handle);
  1103. IntPtr hdc = g.GetHdc();
  1104. uint u_color = 0;
  1105. try
  1106. {
  1107. u_color = DrawFunction.GetPixel(hdc, int_x, int_y);
  1108. }
  1109. catch
  1110. { }
  1111. Color ls_c = Color.FromArgb
  1112. (
  1113. (int)(u_color << 24 >> 24),
  1114. (int)(u_color << 16 >> 24),
  1115. (int)(u_color << 8 >> 24)
  1116. );
  1117. return ls_c;
  1118. }
  1119. /// <summary>
  1120. /// 封装,将分布图中的颗粒list传送给报告项目框架中
  1121. /// </summary>
  1122. private void SendSelectParticleListToReportFrame(List<DisplayParticle> selectParts)
  1123. {
  1124. //先获取分布图中,有哪些颗粒已经被选择上了
  1125. foreach (var p in selectParts)
  1126. {
  1127. if (!frmReportApp.selectedParticles.ContainsKey(p.guid))
  1128. {
  1129. frmReportApp.selectedParticles.Add(p.guid, p);
  1130. }
  1131. }
  1132. }
  1133. /// <summary>
  1134. /// 设置当前对哪些颗粒进行设置为选择状态
  1135. /// </summary>
  1136. /// <param name="in_list_cotsparticleclr"></param>
  1137. public void SetSelectParticle(List<Particle> particles)
  1138. {
  1139. if (particles == null)
  1140. {
  1141. return;
  1142. }
  1143. if (particles.Count == 0)
  1144. {
  1145. return;
  1146. }
  1147. foreach (DisplayParticle ls_dp in m_list_allDPart)
  1148. {
  1149. if (ls_dp.GetPaintState() == PaintState.PAINT)
  1150. {
  1151. for (int i = 0; i < particles.Count; i++)
  1152. {
  1153. if (particles[i].ParticleId == ls_dp.ParticleId
  1154. && particles[i].FieldId == ls_dp.FieldId)
  1155. {
  1156. ls_dp.IsSelect=true;
  1157. }
  1158. }
  1159. }
  1160. }
  1161. }
  1162. private void ToolStripMenuItem_delete_Click(object sender, EventArgs e)
  1163. {
  1164. List<DisplayParticle> selectedParts = new List<DisplayParticle>();
  1165. foreach (var obj in m_list_allDPart)
  1166. {
  1167. var dp = (DisplayParticle)obj;
  1168. if (dp.IsSelect)
  1169. {
  1170. dp.IsDeleted = true;
  1171. }
  1172. else
  1173. {
  1174. selectedParts.Add(dp);
  1175. }
  1176. }
  1177. SendSelectParticleListToReportFrame(selectedParts);
  1178. }
  1179. //复制图像
  1180. private void toolStripMenuItem_copyimage_Click(object sender, EventArgs e)
  1181. {
  1182. SaveFileDialog sfd = new SaveFileDialog();
  1183. //|ALL Files(*.*)|*.*
  1184. //BMP Files(*.bmp)| *.bmp |
  1185. sfd.Filter = "png Files(*.png)| *.png |BMP Files(*.bmp)| *.bmp |JPG Files(*.jpg)|*.jpg;*.jpeg";
  1186. if (sfd.ShowDialog() == DialogResult.OK)
  1187. {
  1188. OutPIC outpic = new OutPIC();
  1189. outpic.m_list_allDfield = m_list_allDfield;
  1190. outpic.resultFile = resultFile;
  1191. outpic.sfd = sfd;
  1192. outpic.type = (int)Outpic_enum.pic;
  1193. Thread bThread = new Thread(new ThreadStart(outpic.opencv_outpic));
  1194. bThread.IsBackground = true;
  1195. bThread.Start();
  1196. }
  1197. }
  1198. private void ToolStripMenuItem_movesempoint_Click(object sender, EventArgs e)
  1199. {
  1200. //移动SEM到指定位置
  1201. if (m_mythread == null)
  1202. {
  1203. return;
  1204. }
  1205. if (m_mythread.ThreadState == System.Threading.ThreadState.Running || m_mythread.ThreadState == System.Threading.ThreadState.WaitSleepJoin)
  1206. {
  1207. return;
  1208. }
  1209. if (m_mythread.ThreadState == System.Threading.ThreadState.Stopped)
  1210. {
  1211. m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
  1212. }
  1213. //改为线程调用,先判断线程状态
  1214. m_mythread.Start(new Point(m_sem_mouse_now_point.X, m_sem_mouse_now_point.Y));
  1215. }
  1216. #endregion
  1217. #region 自定义功能函数
  1218. /// <summary>
  1219. /// 复制图像
  1220. /// </summary>
  1221. private void CopyImage()
  1222. {
  1223. int height, width;
  1224. width = this.Width;
  1225. height = this.Height;
  1226. Bitmap image = new Bitmap(width, height);
  1227. //this.BackgroundImage
  1228. this.DrawToBitmap(image, new Rectangle(0, 0, width, height));
  1229. Clipboard.SetImage(image);
  1230. }
  1231. /// <summary>
  1232. /// 移动SEM到指定位置线程函数
  1233. /// </summary>
  1234. private void Thread_GO(object in_obj)
  1235. {
  1236. Point sem_point = (Point)in_obj;
  1237. //第二步,移动到指定位置,先读取再设置
  1238. if (imageDisHelper.ConnectToIpcSvr())
  1239. {
  1240. imageDisHelper.MoveSemToPointXY(sem_point.X, sem_point.Y);
  1241. }
  1242. }
  1243. /// <summary>
  1244. /// 按框架传入的底层计算结果,重新对颗粒进行区分显示
  1245. /// </summary>
  1246. /// <param name="in_cgriddataclr"></param>
  1247. public void DrawDistrbutionImageAndBSE_ByQuery(ReportCondition in_griddata)
  1248. {
  1249. FilterParticleByOtherCondition(in_griddata);
  1250. Invalidate();
  1251. this.Refresh();
  1252. }
  1253. /// <summary>
  1254. /// 对分布图进行宽度匹配操作
  1255. /// </summary>
  1256. public void WidthMatch()
  1257. {
  1258. if (this.Width != m_backRect.Width)
  1259. {
  1260. float f_cz = 0;//进行调整的差值
  1261. f_cz = -((m_backRect.Width - this.Width) / m_backRect.Width);
  1262. var theZoom = m_zoom_record + m_zoom_record * f_cz;//更新上缩放值,与下面处理缩放对应上
  1263. ImageZoom(theZoom, new PointF(0, 0));
  1264. }
  1265. MoveImageToPoint(new PointF(0, 0));
  1266. }
  1267. /// <summary>
  1268. /// 对分布图进行高度匹配操作
  1269. /// </summary>
  1270. public void HeightMatch()
  1271. {
  1272. if (this.Height != m_backRect.Height)
  1273. {
  1274. float f_cz = 0;//进行调整的差值
  1275. f_cz = -((m_backRect.Height - this.Height) / m_backRect.Height);
  1276. var currentZoom = m_zoom_record + f_cz;//更新上缩放值,与下面处理缩放对应上
  1277. ImageZoom(currentZoom, new PointF( 0, 0));
  1278. }
  1279. //移动到,this.width - backrectf.width /2
  1280. int ls_x = (int)(this.Width - m_backRect.Width) / 2;
  1281. MoveImageToPoint(new PointF(ls_x, 0));
  1282. }
  1283. /// <summary>
  1284. /// 对分布图进行全图匹配操作
  1285. /// </summary>
  1286. public void FullGraphMatch()
  1287. {
  1288. //全图匹配,首先要判断出来是按宽度来计算缩放,还是按高度来计算缩放
  1289. double thiswidth = this.Width;
  1290. double thisheight = this.Height;
  1291. double imagewidth = m_backRect.Width;
  1292. double imageheight = m_backRect.Height;
  1293. //如果宽已相等rect在thisheight范围内,是宽度匹配已经达到目的,或是高已相等rect在thiswidth范围内,是高度匹配已经达到目的
  1294. if ((thiswidth == imagewidth && thisheight > imagewidth) || (thisheight == imageheight && thiswidth > imagewidth))
  1295. {
  1296. //已经达到目的不操作,返回
  1297. return;
  1298. }
  1299. //判断当前是否宽度匹配未达到全图匹配效果
  1300. if (thiswidth == imagewidth && thisheight < imageheight)
  1301. {
  1302. //说明目前已经达到了宽度匹配,但是未能显示完全整图需要高度匹配
  1303. HeightMatch();
  1304. m_f_zoom_mix = m_zoom_record;
  1305. return;
  1306. }
  1307. //判断当前是否高度匹配未达到全图匹配效果
  1308. if (thisheight == imageheight && thiswidth < imagewidth)
  1309. {
  1310. //说明目前已经达到了高度匹配,但是未能显示完全的整图需要宽度匹配
  1311. WidthMatch();
  1312. m_f_zoom_mix = m_zoom_record;
  1313. return;
  1314. }
  1315. ls_d_cz_width = Math.Abs(thiswidth / imagewidth);
  1316. ls_d_cz_height = Math.Abs(thisheight / imageheight);
  1317. //应该是看谁差的倍数大就按谁的进行调整,而不只能看高宽的差值
  1318. if ((1 - ls_d_cz_width) > (1 - ls_d_cz_height))
  1319. {
  1320. //宽差大,就调用WidthMate
  1321. WidthMatch();
  1322. }
  1323. else
  1324. {
  1325. //高差大,则调用HightMate
  1326. HeightMatch();
  1327. }
  1328. m_f_zoom_mix = m_zoom_record;
  1329. }
  1330. /// <summary>
  1331. /// 将整个图像的位置移动到指定的位置上
  1332. /// </summary>
  1333. private void MoveImageToPoint(PointF in_pointf)
  1334. {
  1335. SizeF offex_p = new SizeF(m_backRect.X - in_pointf.X, m_backRect.Y - in_pointf.Y);
  1336. //同样重新计算backrectf的坐标
  1337. m_backRect = new RectangleF(in_pointf.X, in_pointf.Y,
  1338. m_backRect.Width, m_backRect.Height);
  1339. for (int i = 0; i < m_list_allDPart.Count; i++)
  1340. {
  1341. DisplayParticle dp = m_list_allDPart[i];
  1342. dp.Move(offex_p);
  1343. PointF ct = dp.GetCenterPoint();
  1344. if (ct.X < -100 || ct.X > this.Width + 100 || ct.Y < -100 || ct.Y > this.Height + 100)
  1345. {
  1346. dp.SetPaintState(PaintState.NOPAINT);//the particles which are out of screen don't display.to speed up the display efficient.
  1347. }
  1348. else
  1349. {
  1350. dp.SetPaintState(PaintState.PAINT);
  1351. }
  1352. }
  1353. for (int i =0;i< m_list_allDfield.Count;i++)
  1354. {
  1355. var f = m_list_allDfield[i];
  1356. f.Move(offex_p);
  1357. }
  1358. Invalidate();
  1359. }
  1360. /// <summary>
  1361. /// 是否显示边框格线,自动切换显示与不显示
  1362. /// </summary>
  1363. /// <param name="b_show"></param>
  1364. public void ShowGridLine()
  1365. {
  1366. m_is_showgrid = !m_is_showgrid;
  1367. }
  1368. /// <summary>
  1369. /// 是否显示标尺控件
  1370. /// </summary>
  1371. /// <param name="b_show"></param>
  1372. public void ShowRulerControl()
  1373. {
  1374. control_Ruler1.Visible = !control_Ruler1.Visible;
  1375. }
  1376. /// <summary>
  1377. /// 是否显示边框格线,带参重载
  1378. /// </summary>
  1379. /// <param name="b_show"></param>
  1380. public void ShowGridLine(bool b_show)
  1381. {
  1382. m_is_showgrid = b_show;
  1383. }
  1384. /// <summary>
  1385. /// 是否显示标尺控件,带参重载
  1386. /// </summary>
  1387. /// <param name="b_show"></param>
  1388. public void ShowRulerControl(bool b_show)
  1389. {
  1390. control_Ruler1.Visible = b_show;
  1391. }
  1392. /// <summary>
  1393. /// 颗粒分割
  1394. /// </summary>
  1395. public void Particle_Segmentation()
  1396. {
  1397. m_ParticleSegmentation.IsParticleSegmentation = true;
  1398. m_ParticleSegmentation.StartPoint = new Point();
  1399. m_ParticleSegmentation.EndPoint = new Point();
  1400. }
  1401. /// <summary>
  1402. /// 是否进行矩形多选操作
  1403. /// </summary>
  1404. public void MultiSelect_Rectangle()
  1405. {
  1406. m_SelectTool.IsSelecting = true;
  1407. m_SelectTool.Shape = SelectedShape.Rectangle;
  1408. m_SelectTool.Rect = new RectangleF();
  1409. m_SelectTool.Rect.Width = 0;
  1410. m_SelectTool.Rect.Height = 0;
  1411. }
  1412. /// <summary>
  1413. /// 是否进行圆形多选操作
  1414. /// </summary>
  1415. public void MultiSelect_Ellipse()
  1416. {
  1417. m_SelectTool.IsSelecting = true;
  1418. m_SelectTool.Shape = SelectedShape.Ellipse;
  1419. m_SelectTool.Rect = new RectangleF();
  1420. m_SelectTool.Rect.Width = 0;
  1421. m_SelectTool.Rect.Height = 0;
  1422. }
  1423. /// <summary>
  1424. /// 对选择的多边形进行反选操作
  1425. /// </summary>
  1426. public void ReverseSelection()
  1427. {
  1428. foreach (DisplayParticle dp in m_list_allDPart)
  1429. {
  1430. if (dp.IsSelect)
  1431. {
  1432. dp.IsSelect = false;
  1433. }
  1434. else
  1435. {
  1436. dp.IsSelect = true;
  1437. }
  1438. }
  1439. //将排列图选择的颗粒传送给报告框架中
  1440. //SendSelectParticleListToReportFrame();
  1441. this.Invalidate();
  1442. }
  1443. /// <summary>
  1444. /// 取消所有的颗粒的选择状态
  1445. /// </summary>
  1446. public void DeselectAllParticle()
  1447. {
  1448. foreach (DisplayParticle dp in m_list_allDPart)
  1449. {
  1450. dp.IsSelect=false;
  1451. }
  1452. this.Invalidate();
  1453. }
  1454. /// <summary>
  1455. /// 将整个图像拷贝到内存中
  1456. /// </summary>
  1457. public void CopyToBitmap()
  1458. {
  1459. Bitmap bp = new Bitmap(this.Size.Width, this.Size.Height);
  1460. this.DrawToBitmap(bp, new Rectangle(0, 0, this.Size.Width, this.Size.Height));
  1461. Clipboard.SetImage(bp);
  1462. }
  1463. /// <summary>
  1464. /// 设置显示BSE原图,还是显示分布图带有标准库的
  1465. /// </summary>
  1466. public void ShowMode(IMAGE_TYPE a_type)
  1467. {
  1468. if (a_type == IMAGE_TYPE.BSE)
  1469. {
  1470. OriginalBackground = false;
  1471. //bse图时,显示背景图为白色
  1472. m_backrangecolor = Color.White;
  1473. foreach (DisplayParticle ls_dp in m_list_allDPart)
  1474. {
  1475. ls_dp.ShowMode = SegmentShowMode.DRAWPOINT;
  1476. }
  1477. }
  1478. else if (a_type == IMAGE_TYPE.CLASSIFIED)
  1479. {
  1480. m_backrangecolor = Color.Gainsboro;
  1481. OriginalBackground = false;
  1482. foreach (DisplayParticle ls_dp in m_list_allDPart)
  1483. {
  1484. ls_dp.ShowMode = SegmentShowMode.DRAWLINE;
  1485. }
  1486. }
  1487. else if (a_type== IMAGE_TYPE.ORIGINAl)
  1488. {
  1489. m_backrangecolor = Color.Gainsboro;
  1490. OriginalBackground = true;
  1491. foreach (DisplayParticle ls_dp in m_list_allDPart)
  1492. {
  1493. ls_dp.SetDisplayState(DisplayState.NODISPLAY);
  1494. }
  1495. }
  1496. else if(a_type== IMAGE_TYPE.ORIGINALCLASSIFIED)
  1497. {
  1498. m_backrangecolor = Color.Gainsboro;
  1499. OriginalBackground = true;
  1500. foreach (DisplayParticle ls_dp in m_list_allDPart)
  1501. {
  1502. ls_dp.ShowMode = SegmentShowMode.DRAWLINE;
  1503. }
  1504. }
  1505. this.Invalidate();
  1506. }
  1507. /// <summary>
  1508. /// 根据传入的颗粒状态,来获取所有该颗粒状态下的数据,用来测试统计使用
  1509. /// </summary>
  1510. /// <param name="str_particlestate"></param>
  1511. /// <returns></returns>
  1512. public int GetParticleNumberByState(PaintState in_ParticleState)
  1513. {
  1514. int icount = 0;
  1515. foreach (DisplayParticle ls_dp in m_list_allDPart)
  1516. {
  1517. if (ls_dp.GetPaintState() == in_ParticleState)
  1518. {
  1519. icount++;
  1520. }
  1521. }
  1522. return icount;
  1523. }
  1524. /// <summary>
  1525. /// 获取所有原图
  1526. /// </summary>
  1527. /// <param name="args"></param>
  1528. /// <returns></returns>
  1529. private void GetPic(PaintEventArgs args)
  1530. {
  1531. //outpic();
  1532. foreach (var f in m_list_allDfield)
  1533. {
  1534. var curfldrec = f.GetShowRect();
  1535. if (curfldrec.Left > -2000 && curfldrec.Right < this.Width + 2000 && curfldrec.Top > -2000 && curfldrec.Bottom < this.Height + 2000)
  1536. {
  1537. args.Graphics.DrawImage(f.OriginalImage, curfldrec.X, curfldrec.Y, curfldrec.Width, curfldrec.Height);
  1538. Graphics g = args.Graphics;
  1539. for (int i = 0; i < f.List_DParticle.Count; i++)
  1540. {
  1541. PointF xrayPos = new PointF(f.List_DParticle[i].objParticleData.PosX, f.List_DParticle[i].objParticleData.PosY);
  1542. PointF p = new PointF(xrayPos.X / f.OriginalImage.Width* curfldrec.Width+ curfldrec.X, xrayPos.Y / f.OriginalImage.Height* curfldrec.Height+ curfldrec.Y);
  1543. g.DrawString("+", new Font("黑体", 6), new SolidBrush(Color.Red), p);
  1544. }
  1545. }
  1546. }
  1547. }
  1548. #endregion
  1549. private static byte[] ImgtoByte(Image img)
  1550. {
  1551. MemoryStream ms = new MemoryStream();
  1552. byte[] imagedata = null;
  1553. img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
  1554. imagedata = ms.GetBuffer();
  1555. return imagedata;
  1556. }
  1557. private static Image BytesToImage(byte[] buffer)
  1558. {
  1559. MemoryStream ms = new MemoryStream(buffer);
  1560. Image image = System.Drawing.Image.FromStream(ms);
  1561. return image;
  1562. }
  1563. #region Debug下执行的辅助测试代码
  1564. private void Control_DrawDistrbutionImageAndBSE_MouseDoubleClick(object sender, MouseEventArgs e)
  1565. {
  1566. #if DEBUG
  1567. Screen[] screens = Screen.AllScreens;
  1568. string ls_str = "";
  1569. for (int i = 0; i < screens.Count(); i++)
  1570. {
  1571. ls_str = ls_str + "显示器" + (i + 1).ToString() + " 名称:" + screens[i].DeviceName + Environment.NewLine +
  1572. "显示器" + (i + 1).ToString() + " 是否主要显示器:" + screens[i].Primary + Environment.NewLine +
  1573. "显示器" + (i + 1).ToString() + " WorkingArea:" + screens[i].WorkingArea + Environment.NewLine +
  1574. "显示器" + (i + 1).ToString() + " Bounds:" + screens[i].Bounds + Environment.NewLine +
  1575. "显示器" + (i + 1).ToString() + " 色深:" + screens[i].BitsPerPixel + Environment.NewLine;
  1576. }
  1577. MessageBox.Show("------------------该段代码主要用来测试程序---------------------" + Environment.NewLine +
  1578. //"当前窗体X:" + this.ParentForm.Location.X.ToString() + " Y:" + this.ParentForm.Location.Y.ToString() + Environment.NewLine +
  1579. "显示器数量" + Screen.AllScreens.Count().ToString() + Environment.NewLine +
  1580. ls_str +
  1581. "DESKTOP.Width:" + MyPrimaryScreen.DESKTOP.Width + " DESKTOP.Height:" + MyPrimaryScreen.DESKTOP.Height + Environment.NewLine +
  1582. "DpiX:" + MyPrimaryScreen.DpiX + " DpiY:" + MyPrimaryScreen.DpiY + Environment.NewLine +
  1583. "ScaleX:" + MyPrimaryScreen.ScaleX + " ScaleY:" + MyPrimaryScreen.ScaleY + Environment.NewLine +
  1584. "WorkingArea.Width:" + MyPrimaryScreen.WorkingArea.Width + " WorkingArea.Height:" + MyPrimaryScreen.WorkingArea.Height + Environment.NewLine +
  1585. "this.Width:" + this.Width + " this.Height:" + this.Height + Environment.NewLine +
  1586. "单像素比:" + m_pixelSize.ToString() + Environment.NewLine +
  1587. "缩放倍数:" + m_zoom_record.ToString() + Environment.NewLine +
  1588. "屏幕像素backrectf x:" + m_backRect.X.ToString() + " y:" + m_backRect.Y.ToString() + " width:" + m_backRect.Width.ToString() + " height:" + m_backRect.Height.ToString() + Environment.NewLine +
  1589. //"屏幕像素oldbackrectf x:" + m_original_backRect.X.ToString() + " y:" + m_original_backRect.Y.ToString() + " width:" + m_original_backRect.Width.ToString() + " height:" + m_original_backRect.Height.ToString() + Environment.NewLine +
  1590. "物理像素back_wl_rectf x:" + m_back_wl_rectf.X.ToString() + " y:" + m_back_wl_rectf.Y.ToString() + " width:" + m_back_wl_rectf.Width.ToString() + " height:" + m_back_wl_rectf.Height.ToString() + Environment.NewLine +
  1591. //"单个Field视域屏幕像素宽:" + m_OneField_Screen_BackRectf.Width.ToString() + " 高:" + m_OneField_Screen_BackRectf.Height.ToString() + Environment.NewLine +
  1592. //"单个OTS视域屏幕像素宽:" + m_OneField_OTS_Rect.Width.ToString() + " 高:" + m_OneField_OTS_Rect.Height.ToString() + Environment.NewLine +
  1593. "屏幕像素backrectf x:" + m_backRect.X.ToString() + " y:" + m_backRect.Y.ToString() + " width:" + m_backRect.Width.ToString() + " height:" + m_backRect.Height.ToString() + Environment.NewLine +
  1594. "包含Field数量:" + imageDisHelper.m_field_count.ToString() + " Particle数量:" + imageDisHelper.m_particle_count.ToString() + Environment.NewLine +
  1595. "正常显示Paticle数量:" + GetParticleNumberByState(PaintState.PAINT).ToString() + " 不显示Particel数量:" + GetParticleNumberByState(PaintState.NOPAINT).ToString() + Environment.NewLine +
  1596. //"删除Particle数量:" + GetParticleNumberByState("删除").ToString() + " 选中Particle数量:" + GetParticleNumberByState("选择").ToString() + Environment.NewLine +
  1597. "加载底层数据用时:" + imageDisHelper.m_time_str + Environment.NewLine +
  1598. "组建并计算图像用时:" + imageDisHelper.m_time_str2 + Environment.NewLine +
  1599. "---------------------------END----------------------------------"
  1600. );
  1601. #endif
  1602. }
  1603. #endregion
  1604. private void ExportoriginalspliceToolStripMenuItem_Click(object sender, EventArgs e)
  1605. {
  1606. SaveFileDialog sfd = new SaveFileDialog();
  1607. //|ALL Files(*.*)|*.*
  1608. //BMP Files(*.bmp)| *.bmp |
  1609. sfd.Filter = "png Files(*.png)| *.png |BMP Files(*.bmp)| *.bmp |JPG Files(*.jpg)|*.jpg;*.jpeg";
  1610. if (sfd.ShowDialog() == DialogResult.OK)
  1611. {
  1612. OutPIC outpic = new OutPIC();
  1613. outpic.m_list_allDfield = m_list_allDfield;
  1614. outpic.resultFile = resultFile;
  1615. outpic.sfd = sfd;
  1616. outpic.type = (int)Outpic_enum.Render_pic;
  1617. Thread bThread = new Thread(new ThreadStart(outpic.opencv_outpic));
  1618. bThread.IsBackground = true;
  1619. bThread.Start();
  1620. }
  1621. }
  1622. private void ToolStripMenuItemDelete_Particle_Click(object sender, EventArgs e)
  1623. {
  1624. DialogResult dr = MessageBox.Show("Should I delete particles", "Tips", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  1625. if (dr== DialogResult.OK)
  1626. {
  1627. if (DeleteParticlesFromLibrary(m_mouseOver_dparticle.ParticleId, m_mouseOver_dparticle.FieldId))
  1628. {
  1629. MessageBox.Show("Deleted successfully");
  1630. m_mouseOver_dparticle.IsDeleted=true;
  1631. }
  1632. else
  1633. {
  1634. MessageBox.Show("Delete failed");
  1635. }
  1636. }
  1637. else
  1638. {
  1639. return;
  1640. }
  1641. }
  1642. private bool DeleteParticlesFromLibrary(int in_clr_tagid, int in_clr_fieldid)
  1643. {
  1644. bool DoesItExist = false;
  1645. for (int i = 1; i < 201; i++)
  1646. {
  1647. if (System.IO.Directory.Exists(resultFile.FilePath + "\\FIELD_FILES\\Backups" + i.ToString()))
  1648. {
  1649. DoesItExist = true;
  1650. break;
  1651. }
  1652. }
  1653. if (!DoesItExist)
  1654. {
  1655. //备份数据库
  1656. BackupDatabase();
  1657. }
  1658. DoesItExist = false;
  1659. //防止为空校验判断
  1660. if (resultFile.List_OTSField == null)
  1661. return false;
  1662. Particle particle = resultFile.List_OTSField.Find(x => x.FieldID == in_clr_fieldid).ParticleList.Find(x => x.ParticleId == in_clr_tagid);
  1663. if (new ParticleData(resultFile.FilePath).DeleteFromData(Convert.ToString(particle.FieldId), Convert.ToString(particle.XrayId)))
  1664. {
  1665. return true;
  1666. }
  1667. else
  1668. {
  1669. return false;
  1670. }
  1671. }
  1672. private bool BackupDatabase()
  1673. {
  1674. //创建备份数据库文件夹
  1675. string sourcePath = resultFile.FilePath + "\\FIELD_FILES\\Inclusion.db";//源文件路径
  1676. string sourceName = "Inclusion.db";//源文件名称
  1677. string folderPath = resultFile.FilePath + "\\FIELD_FILES\\Backups";//目标文件夹
  1678. string Fields = "";
  1679. for (int i = 1; i < 201; i++)
  1680. {
  1681. if (System.IO.Directory.Exists(folderPath + i.ToString()))
  1682. {
  1683. Fields = folderPath + i.ToString();
  1684. continue;
  1685. }
  1686. else
  1687. {
  1688. System.IO.Directory.CreateDirectory(folderPath + i.ToString());
  1689. Fields = folderPath + i.ToString();
  1690. break;
  1691. }
  1692. }
  1693. if (Fields == "")
  1694. {
  1695. return false;
  1696. }
  1697. //复制数据库文件
  1698. string targetPath = Path.Combine(Fields, sourceName);
  1699. FileInfo file = new FileInfo(sourcePath);
  1700. if (file.Exists)
  1701. {
  1702. file.CopyTo(targetPath, true);
  1703. }
  1704. return true;
  1705. }
  1706. int GetsIntersectionOfTheIntercepts(Point P1,Point P2,int y)
  1707. {
  1708. int x = (y - P1.Y * P2.X + P1.X * P2.Y) / (P2.Y - P1.Y);
  1709. return x;
  1710. }
  1711. //private void ParticleSegmentation_Click(object sender, EventArgs e)
  1712. //{
  1713. // Particle_Segmentation();
  1714. //}
  1715. private void 分割颗粒ToolStripMenuItem_Click(object sender, EventArgs e)
  1716. {
  1717. Particle_Segmentation();
  1718. }
  1719. private void ImportSTDDb_Click(object sender, EventArgs e)
  1720. {
  1721. Dictionary<string, object> sampleMembers = ((Dictionary<string, object>)((Dictionary<string, object>)resultFile.ResultInfo["Sample"])["Members"]);
  1722. string STDName = ((Dictionary<string, object>)sampleMembers["MsrParams"])["STDName"].ToString();
  1723. string ResultDbPath = resultFile.FilePath + "\\FIELD_FILES\\Inclusion.db";
  1724. if (STDName.ToLower().Split('.')[0] == "nostddb")
  1725. {
  1726. OpenFileDialog openFileDialog = new OpenFileDialog();
  1727. openFileDialog.Filter = "(*.db)|*.db";
  1728. openFileDialog.RestoreDirectory = true;
  1729. openFileDialog.FilterIndex = 1;
  1730. openFileDialog.Title = "Please choose a STD to add the rule!";
  1731. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1732. {
  1733. try
  1734. {
  1735. string arguments = openFileDialog.FileName;
  1736. foreach (DisplayParticle item in m_list_allDPart)
  1737. {
  1738. DisplayParticle dp = item;
  1739. if (imageDisHelper.WhetherInRange(dp, m_mouse_now_point))
  1740. {
  1741. arguments += " " + ResultDbPath + " " + dp.FieldId + " " + dp.ParticleId + " " + dp.XRayId;
  1742. break;
  1743. }
  1744. }
  1745. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSPartA_STDEditor.exe", arguments);
  1746. p.WaitForExit();
  1747. }
  1748. catch (Exception ex)
  1749. {
  1750. log.Error("OTSPartA_STDEditor:" + ex.ToString());
  1751. }
  1752. }
  1753. }
  1754. else
  1755. {
  1756. string arguments = ".\\Config\\SysData\\"+ STDName.Split('.')[0]+".db";
  1757. foreach (DisplayParticle item in m_list_allDPart)
  1758. {
  1759. DisplayParticle dp = item;
  1760. if (imageDisHelper.WhetherInRange(dp, m_mouse_now_point))
  1761. {
  1762. arguments += " " + ResultDbPath + " " + dp.FieldId + " " + dp.ParticleId + " " + dp.XRayId;
  1763. break;
  1764. }
  1765. }
  1766. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSPartA_STDEditor.exe", arguments);
  1767. p.WaitForExit();
  1768. }
  1769. }
  1770. }
  1771. }