Control_DrawDistrbutionImageAndBSE.cs 85 KB

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