Control_DrawDistrbutionImageAndBSE.cs 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265
  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 = new Thread(new ParameterizedThreadStart(Thread_GO));
  178. m_ReportApp = ReportApp;
  179. resultFile = m_ReportApp.m_rstDataMgr.CurResultFile;
  180. //初始化底层操作类
  181. imageDisHelper = new OTSImageDisHelp(resultFile);
  182. InitializeComponent();
  183. #region 国际化语言
  184. Language lan = new Language(this);
  185. table = lan.GetNameTable(this.Name);
  186. #endregion
  187. //load the userdefine control dynamically
  188. System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Control_DrawDistrbutionImageAndBSE));
  189. this.control_XRayTable1 = new Control_XRayTable();
  190. this.control_XRayTable1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
  191. this.control_XRayTable1.Dock = System.Windows.Forms.DockStyle.Bottom;
  192. this.control_XRayTable1.GBInfoStr = "";
  193. this.control_XRayTable1.GoodChineseName = "";
  194. this.control_XRayTable1.MaterialName = "";
  195. this.control_XRayTable1.List_ShowElementInfo = ((System.Collections.Generic.List<OTSIncAReportGraph.Controls.ShowElementInfo>)(resources.GetObject("control_XRayTable1.List_ShowElementInfo")));
  196. this.control_XRayTable1.Location = new System.Drawing.Point(0, 400);
  197. this.control_XRayTable1.Name = "control_XRayTable1";
  198. this.control_XRayTable1.ShowAnalysisXray = true;
  199. this.control_XRayTable1.ShowSearchXray = false;
  200. this.control_XRayTable1.Size = new System.Drawing.Size(1004, 200);
  201. this.control_XRayTable1.STDName = "";
  202. this.control_XRayTable1.TabIndex = 6;
  203. this.control_XRayTable1.Visible = false;
  204. //
  205. // control_Ruler1
  206. //
  207. this.control_Ruler1 = new Control_Ruler();
  208. this.control_Ruler1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(200)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
  209. this.control_Ruler1.Location = new System.Drawing.Point(3, 400);
  210. this.control_Ruler1.Name = "control_Ruler1";
  211. this.control_Ruler1.RulerWidth = 100;
  212. this.control_Ruler1.ShowString = "100um";
  213. this.control_Ruler1.Size = new System.Drawing.Size(120, 40);
  214. this.control_Ruler1.TabIndex = 8;
  215. this.control_Ruler1.Value = 0D;
  216. this.control_Ruler1.Visible = false;
  217. this.Controls.Add(this.control_XRayTable1);
  218. this.Controls.Add(this.control_Ruler1);
  219. }
  220. private void ProgressBarUpdate(int progress, string message)
  221. {
  222. //显示进度条,计算进度条应该显示的位置和宽度
  223. if (m_frm_userprogress.Visible == false)
  224. {
  225. Form ls_main_form = this.ParentForm.ParentForm;//取出父窗体
  226. m_frm_userprogress.Width = (int)(MyPrimaryScreen.DESKTOP.Width / MyPrimaryScreen.ScaleX * 0.9);
  227. m_frm_userprogress.Location = new Point(ls_main_form.Location.X + 80, ls_main_form.Location.Y + (int)(MyPrimaryScreen.DESKTOP.Height / MyPrimaryScreen.ScaleX) / 2);
  228. m_frm_userprogress.Show();
  229. }
  230. m_frm_userprogress.SetProgressValueAndText(progress, message);
  231. }
  232. private void Control_DrawDistrbutionImageAndBSE_Load(object sender, EventArgs e)
  233. {
  234. //设置双缓冲
  235. SetDoubleBufferByIsDraw();
  236. ProgressBarUpdate(0, table["str1"].ToString());
  237. //执行获取颗粒分布图数据,总过程函数
  238. GetDistrbutionImageAndBSE_Total();
  239. //设置标尺
  240. //根据f_onepixel_size计算出要显示出100um的实际宽度
  241. double d_onefixel_width = 100 / m_pixelSize;
  242. if (d_onefixel_width == 0)
  243. {
  244. this.control_Ruler1.Visible = false;
  245. }
  246. else
  247. {
  248. //将标尺定位到合理的位置上
  249. this.control_Ruler1.Location = new Point(10, MyPrimaryScreen.WorkingArea.Height - 300);
  250. this.control_Ruler1.Visible = true;
  251. this.control_Ruler1.SetValue(m_f_ruler_size, m_pixelSize);
  252. }
  253. ProgressBarUpdate(100, table["str2"].ToString());
  254. m_frm_userprogress.Visible = false;
  255. }
  256. /// <summary>
  257. /// 获取组整个获取分布图和排序图图像数据的底层数据组建方式,的总过程
  258. /// </summary>
  259. public void GetDistrbutionImageAndBSE_Total()
  260. {
  261. string str27 = "begin to loading data....";
  262. log.Info(str27);
  263. Application.DoEvents();
  264. ProgressBarUpdate(1, str27);
  265. List<Field> fieldlist = resultFile.List_OTSField;
  266. if (fieldlist.Count == 0)
  267. {
  268. ProgressBarUpdate(100, "field number =0 !....");
  269. return;
  270. }
  271. string str29 = "begin to compose field picture....";
  272. log.Info(str29);
  273. Application.DoEvents();
  274. ProgressBarUpdate(15, str29);
  275. List<Point> list_point = new List<Point>();
  276. int fieldwidth = 0, fieldheight = 0;
  277. //获取到该field的分辨率大小,循环中都是一样的
  278. if (fieldlist.Count > 0)
  279. {
  280. Rectangle r = imageDisHelper.GetImageWidthAndHeight();
  281. fieldwidth = r.Width;
  282. fieldheight = r.Height;
  283. }
  284. for (int i = 0; i < fieldlist.Count(); i++)
  285. {
  286. Point ls_point = new Point() { X = fieldlist[i].FieldPosX, Y = fieldlist[i].FieldPosY };
  287. list_point.Add(ls_point);
  288. }
  289. //计算出整个绘制图像总Rectagnle的大小
  290. m_backRect = imageDisHelper. ConvertAndGetMaxRect(list_point, fieldwidth, fieldheight);
  291. ProgressBarUpdate(18, "calculate ruler....");
  292. #region //标尺相关------------------------------------------------------------------------------
  293. RectangleF ls_jsblrect = imageDisHelper.GetPhysicalFieldWidthAndHeight();
  294. //然后用宽度来除以i_field_width 获取单个的像素比例
  295. m_pixelSize = Convert.ToDouble(ls_jsblrect.Width) / Convert.ToDouble(fieldwidth);
  296. #endregion //---------------------------------------------------------------------------------------
  297. ProgressBarUpdate(20, "compose whole picture....");
  298. //70的进度条给到下面的循环中,计算进度条各分类进度分配
  299. float ls_int_progresscalc = 0;
  300. if (fieldlist.Count > 0)
  301. ls_int_progresscalc = (float)70 / (float)fieldlist.Count;
  302. string str32 = "finished ";
  303. string str33 = "total ";
  304. string str34 = "field...";
  305. var otsLeftBottomPoint = imageDisHelper.GetOTSCoordLeftBottomPoint(list_point);
  306. m_list_allDfield.Clear();
  307. m_list_allDPart.Clear();
  308. for (int i = 0; i < fieldlist.Count(); i++)
  309. {
  310. ProgressBarUpdate(20 + (int)(ls_int_progresscalc * (i + 1)), str32 + i.ToString() + str33 + resultFile.List_OTSField.Count.ToString() + str34);
  311. //取出该Field的物理坐标,将其转换成对应的屏幕像素坐标,屏幕左上角为原点(0,0)的偏移值,用于后面计算各Segment的位置使用
  312. Point thisfield_point = new Point() { X = fieldlist[i].FieldPosX, Y = fieldlist[i].FieldPosY };
  313. 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.
  314. DisplayField df;
  315. try
  316. {
  317. df = new DisplayField(fieldlist[i], fieldwidth, fieldheight, offset_point);
  318. m_list_allDfield.Add(df);
  319. m_list_allDPart.AddRange(df.List_DParticle);
  320. }
  321. catch (Exception ex)
  322. {
  323. NLog.LogManager.GetCurrentClassLogger().Info(ex.ToString());
  324. }
  325. }
  326. ProgressBarUpdate(90, "convert solution...");
  327. //然后这里还需要计算出,各field的宽和高,帧图边框分别需要显示多少个框
  328. if (fieldwidth != 0 && fieldheight != 0)
  329. {
  330. m_i_grid_showlinesnumber_width = Convert.ToInt32(BackRectF.Width / fieldwidth);
  331. m_i_grid_showlinesnumber_height = Convert.ToInt32(BackRectF.Height / fieldheight);
  332. }
  333. ProgressBarUpdate(95, "other work...");
  334. //相关计数
  335. imageDisHelper.m_field_count = fieldlist.Count;
  336. imageDisHelper.m_particle_count = m_list_allDPart.Count;
  337. }
  338. /// <summary>
  339. /// 分布图和BSE图中,从底层获取相关结果后,重新组织显示
  340. /// </summary>
  341. /// <param name="sourceGridData"></param>
  342. public void FilterParticleByOtherCondition(ReportCondition sourceGridData)
  343. {
  344. bool sizeconditionResult;
  345. bool stdIdconditionResult;
  346. string stdId = "";
  347. int stdIdIndex = 0;
  348. //find the stdId condition
  349. var STDIdItm = sourceGridData.ConditionItemList.Find(s => s.iItemId == OTS_REPORT_PROP_GRID_ITEMS.STD_ID);
  350. if (STDIdItm != null)
  351. {
  352. stdId = STDIdItm.itemDisplayVal.ToString();
  353. stdIdIndex = STDIdItm.comboDownList.IndexOf(stdId);
  354. }
  355. //find the size condition
  356. var size_cal_method_type = (SIZE_CAL_METHOD_TYPE)sourceGridData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE);
  357. var itm = sourceGridData.ConditionItemList.Find(s => s.iItemId == OTS_REPORT_PROP_GRID_ITEMS.GRAIN_SIZE_CLASS);
  358. string size = itm.itemDisplayVal.ToString();
  359. int index = itm.comboDownList.IndexOf(size);
  360. string min = "0";
  361. string max = "999";
  362. if (index > 0)
  363. {
  364. max = sourceGridData.ConditionItemList.Find(s => s.iItemId == OTS_REPORT_PROP_GRID_ITEMS.GRAIN_SIZE_MAX).itemDisplayVal.ToString();
  365. min = sourceGridData.ConditionItemList.Find(s => s.iItemId == OTS_REPORT_PROP_GRID_ITEMS.GRAIN_SIZE_MIN).itemDisplayVal.ToString();
  366. if (max.ToLower() == "max")
  367. {
  368. max = "999";
  369. }
  370. }
  371. double dia_min = Convert.ToDouble(min);
  372. double dia_max = Convert.ToDouble(max);
  373. foreach (DisplayParticle ls_dp in m_list_allDPart)
  374. {
  375. if (index > 0)
  376. {
  377. double diameter = 0;
  378. switch (size_cal_method_type)
  379. {
  380. case SIZE_CAL_METHOD_TYPE.DMAX:
  381. diameter = ls_dp.objParticleData.DMAX;
  382. break;
  383. case SIZE_CAL_METHOD_TYPE.DMIN:
  384. diameter = ls_dp.objParticleData.DMIN;
  385. break;
  386. case SIZE_CAL_METHOD_TYPE.CIRCLE:
  387. diameter = Math.Sqrt(ls_dp.objParticleData.Area / 3.14159f) * 2f;
  388. break;
  389. case SIZE_CAL_METHOD_TYPE.DFERET:
  390. diameter = ls_dp.objParticleData.DFERET;
  391. break;
  392. default:
  393. diameter = 0;
  394. break;
  395. }
  396. if (diameter >= dia_min && diameter <= dia_max)
  397. {
  398. sizeconditionResult = true;
  399. }
  400. else
  401. {
  402. sizeconditionResult = false;
  403. }
  404. }
  405. else
  406. {
  407. sizeconditionResult = true;
  408. }
  409. if (stdIdIndex > 0)// it's not "All"
  410. {
  411. if (ls_dp.objParticleData.TypeName != stdId)
  412. {
  413. stdIdconditionResult = false;
  414. }
  415. else
  416. {
  417. stdIdconditionResult = true;
  418. }
  419. }
  420. else
  421. {
  422. stdIdconditionResult = true;
  423. }
  424. if (stdIdconditionResult && sizeconditionResult)
  425. {
  426. ls_dp.SetDisplayState(DisplayState.DISPLAY);
  427. }
  428. else
  429. {
  430. ls_dp.SetDisplayState(DisplayState.NODISPLAY);
  431. }
  432. }
  433. }
  434. #endregion
  435. #region 设置双缓冲
  436. /// <summary>
  437. /// 设置双缓冲
  438. /// </summary>
  439. public void SetDoubleBufferByIsDraw()
  440. {
  441. SetStyle(ControlStyles.UserPaint, true); //没什么效果,开与关
  442. SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景,关了闪
  443. SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // 双缓冲,关了闪
  444. //上面是必须有的
  445. SetStyle(ControlStyles.UserMouse, true); //执行自己的鼠标行为,这个打开后,在win7下鼠标操作明显改善
  446. }
  447. #endregion
  448. #region 绘制函数
  449. protected override void OnPaint(PaintEventArgs e)//处理重绘情况
  450. {
  451. if (OriginalBackground)
  452. {
  453. DrawOriginalImageAsBackground(e);
  454. }
  455. else
  456. {
  457. SolidBrush b = new SolidBrush(m_backrangecolor);
  458. e.Graphics.FillRectangle(b, m_backRect);
  459. }
  460. foreach (DisplayParticle item in m_list_allDPart)
  461. {
  462. DisplayParticle dp = item;
  463. if (isReView)
  464. {
  465. if (dp.objParticleData.FieldId == reViewFieldId && dp.objParticleData.ParticleId == reViewParticleId)
  466. {
  467. dp.IsSelect = true;
  468. }
  469. }
  470. if (dp.GetPaintState() != PaintState.NOPAINT)
  471. {
  472. dp.OnPaint(e);
  473. }
  474. }
  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. this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
  1183. SaveFileDialog sfd = new SaveFileDialog();
  1184. //|ALL Files(*.*)|*.*
  1185. //BMP Files(*.bmp)| *.bmp |
  1186. sfd.Filter = "png Files(*.png)| *.png |BMP Files(*.bmp)| *.bmp |JPG Files(*.jpg)|*.jpg;*.jpeg";
  1187. if (sfd.ShowDialog() == DialogResult.OK)
  1188. {
  1189. OutPIC outpic = new OutPIC();
  1190. outpic.m_list_allDfield = m_list_allDfield;
  1191. outpic.resultFile = resultFile;
  1192. outpic.sfd = sfd;
  1193. outpic.type = (int)Outpic_enum.pic;
  1194. Thread bThread = new Thread(new ThreadStart(outpic.opencv_outpic));
  1195. bThread.IsBackground = true;
  1196. bThread.Start();
  1197. }
  1198. this.Cursor = System.Windows.Forms.Cursors.Default;
  1199. }
  1200. private void ToolStripMenuItem_movesempoint_Click(object sender, EventArgs e)
  1201. {
  1202. //移动SEM到指定位置
  1203. if (m_mythread == null)
  1204. {
  1205. return;
  1206. }
  1207. if (m_mythread.ThreadState == System.Threading.ThreadState.Running || m_mythread.ThreadState == System.Threading.ThreadState.WaitSleepJoin)
  1208. {
  1209. return;
  1210. }
  1211. if (m_mythread.ThreadState == System.Threading.ThreadState.Stopped)
  1212. {
  1213. m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
  1214. }
  1215. //改为线程调用,先判断线程状态
  1216. m_mythread.Start(new Point(m_sem_mouse_now_point.X, m_sem_mouse_now_point.Y));
  1217. }
  1218. #endregion
  1219. #region 自定义功能函数
  1220. /// <summary>
  1221. /// 复制图像
  1222. /// </summary>
  1223. private void CopyImage()
  1224. {
  1225. int height, width;
  1226. width = this.Width;
  1227. height = this.Height;
  1228. Bitmap image = new Bitmap(width, height);
  1229. //this.BackgroundImage
  1230. this.DrawToBitmap(image, new Rectangle(0, 0, width, height));
  1231. Clipboard.SetImage(image);
  1232. }
  1233. /// <summary>
  1234. /// 移动SEM到指定位置线程函数
  1235. /// </summary>
  1236. private void Thread_GO(object in_obj)
  1237. {
  1238. Point sem_point = (Point)in_obj;
  1239. //第二步,移动到指定位置,先读取再设置
  1240. if (imageDisHelper.ConnectToIpcSvr())
  1241. {
  1242. imageDisHelper.MoveSemToPointXY(sem_point.X, sem_point.Y);
  1243. }
  1244. }
  1245. /// <summary>
  1246. /// 按框架传入的底层计算结果,重新对颗粒进行区分显示
  1247. /// </summary>
  1248. /// <param name="in_cgriddataclr"></param>
  1249. public void DrawDistrbutionImageAndBSE_ByQuery(ReportCondition in_griddata)
  1250. {
  1251. FilterParticleByOtherCondition(in_griddata);
  1252. Invalidate();
  1253. this.Refresh();
  1254. }
  1255. /// <summary>
  1256. /// 对分布图进行宽度匹配操作
  1257. /// </summary>
  1258. public void WidthMatch()
  1259. {
  1260. if (this.Width != m_backRect.Width)
  1261. {
  1262. float f_cz = 0;//进行调整的差值
  1263. f_cz = -((m_backRect.Width - this.Width) / m_backRect.Width);
  1264. var theZoom = m_zoom_record + m_zoom_record * f_cz;//更新上缩放值,与下面处理缩放对应上
  1265. ImageZoom(theZoom, new PointF(0, 0));
  1266. }
  1267. MoveImageToPoint(new PointF(0, 0));
  1268. }
  1269. /// <summary>
  1270. /// 对分布图进行高度匹配操作
  1271. /// </summary>
  1272. public void HeightMatch()
  1273. {
  1274. if (this.Height != m_backRect.Height)
  1275. {
  1276. float f_cz = 0;//进行调整的差值
  1277. f_cz = -((m_backRect.Height - this.Height) / m_backRect.Height);
  1278. var currentZoom = m_zoom_record + f_cz;//更新上缩放值,与下面处理缩放对应上
  1279. ImageZoom(currentZoom, new PointF( 0, 0));
  1280. }
  1281. //移动到,this.width - backrectf.width /2
  1282. int ls_x = (int)(this.Width - m_backRect.Width) / 2;
  1283. MoveImageToPoint(new PointF(ls_x, 0));
  1284. }
  1285. /// <summary>
  1286. /// 对分布图进行全图匹配操作
  1287. /// </summary>
  1288. public void FullGraphMatch()
  1289. {
  1290. //全图匹配,首先要判断出来是按宽度来计算缩放,还是按高度来计算缩放
  1291. double thiswidth = this.Width;
  1292. double thisheight = this.Height;
  1293. double imagewidth = m_backRect.Width;
  1294. double imageheight = m_backRect.Height;
  1295. //如果宽已相等rect在thisheight范围内,是宽度匹配已经达到目的,或是高已相等rect在thiswidth范围内,是高度匹配已经达到目的
  1296. if ((thiswidth == imagewidth && thisheight > imagewidth) || (thisheight == imageheight && thiswidth > imagewidth))
  1297. {
  1298. //已经达到目的不操作,返回
  1299. return;
  1300. }
  1301. //判断当前是否宽度匹配未达到全图匹配效果
  1302. if (thiswidth == imagewidth && thisheight < imageheight)
  1303. {
  1304. //说明目前已经达到了宽度匹配,但是未能显示完全整图需要高度匹配
  1305. HeightMatch();
  1306. m_f_zoom_mix = m_zoom_record;
  1307. return;
  1308. }
  1309. //判断当前是否高度匹配未达到全图匹配效果
  1310. if (thisheight == imageheight && thiswidth < imagewidth)
  1311. {
  1312. //说明目前已经达到了高度匹配,但是未能显示完全的整图需要宽度匹配
  1313. WidthMatch();
  1314. m_f_zoom_mix = m_zoom_record;
  1315. return;
  1316. }
  1317. ls_d_cz_width = Math.Abs(thiswidth / imagewidth);
  1318. ls_d_cz_height = Math.Abs(thisheight / imageheight);
  1319. //应该是看谁差的倍数大就按谁的进行调整,而不只能看高宽的差值
  1320. if ((1 - ls_d_cz_width) > (1 - ls_d_cz_height))
  1321. {
  1322. //宽差大,就调用WidthMate
  1323. WidthMatch();
  1324. }
  1325. else
  1326. {
  1327. //高差大,则调用HightMate
  1328. HeightMatch();
  1329. }
  1330. m_f_zoom_mix = m_zoom_record;
  1331. }
  1332. /// <summary>
  1333. /// 将整个图像的位置移动到指定的位置上
  1334. /// </summary>
  1335. private void MoveImageToPoint(PointF in_pointf)
  1336. {
  1337. SizeF offex_p = new SizeF(m_backRect.X - in_pointf.X, m_backRect.Y - in_pointf.Y);
  1338. //同样重新计算backrectf的坐标
  1339. m_backRect = new RectangleF(in_pointf.X, in_pointf.Y,
  1340. m_backRect.Width, m_backRect.Height);
  1341. for (int i = 0; i < m_list_allDPart.Count; i++)
  1342. {
  1343. DisplayParticle dp = m_list_allDPart[i];
  1344. dp.Move(offex_p);
  1345. PointF ct = dp.GetCenterPoint();
  1346. if (ct.X < -100 || ct.X > this.Width + 100 || ct.Y < -100 || ct.Y > this.Height + 100)
  1347. {
  1348. dp.SetPaintState(PaintState.NOPAINT);//the particles which are out of screen don't display.to speed up the display efficient.
  1349. }
  1350. else
  1351. {
  1352. dp.SetPaintState(PaintState.PAINT);
  1353. }
  1354. }
  1355. for (int i =0;i< m_list_allDfield.Count;i++)
  1356. {
  1357. var f = m_list_allDfield[i];
  1358. f.Move(offex_p);
  1359. }
  1360. Invalidate();
  1361. }
  1362. /// <summary>
  1363. /// 是否显示边框格线,自动切换显示与不显示
  1364. /// </summary>
  1365. /// <param name="b_show"></param>
  1366. public void ShowGridLine()
  1367. {
  1368. m_is_showgrid = !m_is_showgrid;
  1369. }
  1370. /// <summary>
  1371. /// 是否显示标尺控件
  1372. /// </summary>
  1373. /// <param name="b_show"></param>
  1374. public void ShowRulerControl()
  1375. {
  1376. control_Ruler1.Visible = !control_Ruler1.Visible;
  1377. }
  1378. /// <summary>
  1379. /// 是否显示边框格线,带参重载
  1380. /// </summary>
  1381. /// <param name="b_show"></param>
  1382. public void ShowGridLine(bool b_show)
  1383. {
  1384. m_is_showgrid = b_show;
  1385. }
  1386. /// <summary>
  1387. /// 是否显示标尺控件,带参重载
  1388. /// </summary>
  1389. /// <param name="b_show"></param>
  1390. public void ShowRulerControl(bool b_show)
  1391. {
  1392. control_Ruler1.Visible = b_show;
  1393. }
  1394. /// <summary>
  1395. /// 颗粒分割
  1396. /// </summary>
  1397. public void Particle_Segmentation()
  1398. {
  1399. m_ParticleSegmentation.IsParticleSegmentation = true;
  1400. m_ParticleSegmentation.StartPoint = new Point();
  1401. m_ParticleSegmentation.EndPoint = new Point();
  1402. }
  1403. /// <summary>
  1404. /// 是否进行矩形多选操作
  1405. /// </summary>
  1406. public void MultiSelect_Rectangle()
  1407. {
  1408. m_SelectTool.IsSelecting = true;
  1409. m_SelectTool.Shape = SelectedShape.Rectangle;
  1410. m_SelectTool.Rect = new RectangleF();
  1411. m_SelectTool.Rect.Width = 0;
  1412. m_SelectTool.Rect.Height = 0;
  1413. }
  1414. /// <summary>
  1415. /// 是否进行圆形多选操作
  1416. /// </summary>
  1417. public void MultiSelect_Ellipse()
  1418. {
  1419. m_SelectTool.IsSelecting = true;
  1420. m_SelectTool.Shape = SelectedShape.Ellipse;
  1421. m_SelectTool.Rect = new RectangleF();
  1422. m_SelectTool.Rect.Width = 0;
  1423. m_SelectTool.Rect.Height = 0;
  1424. }
  1425. /// <summary>
  1426. /// 对选择的多边形进行反选操作
  1427. /// </summary>
  1428. public void ReverseSelection()
  1429. {
  1430. foreach (DisplayParticle dp in m_list_allDPart)
  1431. {
  1432. if (dp.IsSelect)
  1433. {
  1434. dp.IsSelect = false;
  1435. }
  1436. else
  1437. {
  1438. dp.IsSelect = true;
  1439. }
  1440. }
  1441. //将排列图选择的颗粒传送给报告框架中
  1442. //SendSelectParticleListToReportFrame();
  1443. this.Invalidate();
  1444. }
  1445. /// <summary>
  1446. /// 取消所有的颗粒的选择状态
  1447. /// </summary>
  1448. public void DeselectAllParticle()
  1449. {
  1450. foreach (DisplayParticle dp in m_list_allDPart)
  1451. {
  1452. dp.IsSelect=false;
  1453. }
  1454. this.Invalidate();
  1455. }
  1456. /// <summary>
  1457. /// 将整个图像拷贝到内存中
  1458. /// </summary>
  1459. public void CopyToBitmap()
  1460. {
  1461. Bitmap bp = new Bitmap(this.Size.Width, this.Size.Height);
  1462. this.DrawToBitmap(bp, new Rectangle(0, 0, this.Size.Width, this.Size.Height));
  1463. Clipboard.SetImage(bp);
  1464. }
  1465. /// <summary>
  1466. /// 设置显示BSE原图,还是显示分布图带有标准库的
  1467. /// </summary>
  1468. public void SetShowMode(IMAGE_TYPE a_type)
  1469. {
  1470. if (a_type == IMAGE_TYPE.BSE)
  1471. {
  1472. OriginalBackground = false;
  1473. //bse图时,显示背景图为白色
  1474. m_backrangecolor = Color.White;
  1475. foreach (DisplayParticle ls_dp in m_list_allDPart)
  1476. {
  1477. ls_dp.SetDisplayState(DisplayState.DISPLAY);
  1478. ls_dp.ShowMode = SegmentShowMode.DRAWPOINT;
  1479. }
  1480. }
  1481. else if (a_type == IMAGE_TYPE.CLASSIFIED)
  1482. {
  1483. m_backrangecolor = Color.Gainsboro;
  1484. OriginalBackground = false;
  1485. foreach (DisplayParticle ls_dp in m_list_allDPart)
  1486. {
  1487. ls_dp.SetDisplayState(DisplayState.DISPLAY);
  1488. ls_dp.ShowMode = SegmentShowMode.DRAWLINE;
  1489. }
  1490. }
  1491. else if (a_type== IMAGE_TYPE.ORIGINAl)
  1492. {
  1493. m_backrangecolor = Color.Gainsboro;
  1494. OriginalBackground = true;
  1495. foreach (DisplayParticle ls_dp in m_list_allDPart)
  1496. {
  1497. ls_dp.SetDisplayState(DisplayState.NODISPLAY);
  1498. }
  1499. }
  1500. else if(a_type== IMAGE_TYPE.ORIGINALCLASSIFIED)
  1501. {
  1502. m_backrangecolor = Color.Gainsboro;
  1503. OriginalBackground = true;
  1504. foreach (DisplayParticle ls_dp in m_list_allDPart)
  1505. {
  1506. ls_dp.ShowMode = SegmentShowMode.DRAWLINE;
  1507. ls_dp.SetDisplayState(DisplayState.DISPLAY);
  1508. }
  1509. }
  1510. this.Invalidate();
  1511. }
  1512. /// <summary>
  1513. /// 根据传入的颗粒状态,来获取所有该颗粒状态下的数据,用来测试统计使用
  1514. /// </summary>
  1515. /// <param name="str_particlestate"></param>
  1516. /// <returns></returns>
  1517. public int GetParticleNumberByState(PaintState in_ParticleState)
  1518. {
  1519. int icount = 0;
  1520. foreach (DisplayParticle ls_dp in m_list_allDPart)
  1521. {
  1522. if (ls_dp.GetPaintState() == in_ParticleState)
  1523. {
  1524. icount++;
  1525. }
  1526. }
  1527. return icount;
  1528. }
  1529. /// <summary>
  1530. /// 获取所有原图
  1531. /// </summary>
  1532. /// <param name="args"></param>
  1533. /// <returns></returns>
  1534. private void DrawOriginalImageAsBackground(PaintEventArgs args)
  1535. {
  1536. foreach (var f in m_list_allDfield)
  1537. {
  1538. var curfldrec = f.GetShowRect();
  1539. if (curfldrec.Left > -2000 && curfldrec.Right < this.Width + 2000 && curfldrec.Top > -2000 && curfldrec.Bottom < this.Height + 2000)
  1540. {
  1541. args.Graphics.DrawImage(f.OriginalImage, curfldrec.X, curfldrec.Y, curfldrec.Width, curfldrec.Height);
  1542. Graphics g = args.Graphics;
  1543. for (int i = 0; i < f.List_DParticle.Count; i++)
  1544. {
  1545. PointF xrayPos = new PointF(f.List_DParticle[i].objParticleData.PosX, f.List_DParticle[i].objParticleData.PosY);
  1546. PointF p = new PointF(xrayPos.X / f.OriginalImage.Width* curfldrec.Width+ curfldrec.X, xrayPos.Y / f.OriginalImage.Height* curfldrec.Height+ curfldrec.Y);
  1547. g.DrawString("+", new Font("黑体", 6), new SolidBrush(Color.Red), p);
  1548. }
  1549. }
  1550. }
  1551. }
  1552. #endregion
  1553. private static byte[] ImgtoByte(Image img)
  1554. {
  1555. MemoryStream ms = new MemoryStream();
  1556. byte[] imagedata = null;
  1557. img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
  1558. imagedata = ms.GetBuffer();
  1559. return imagedata;
  1560. }
  1561. private static Image BytesToImage(byte[] buffer)
  1562. {
  1563. MemoryStream ms = new MemoryStream(buffer);
  1564. Image image = System.Drawing.Image.FromStream(ms);
  1565. return image;
  1566. }
  1567. #region Debug下执行的辅助测试代码
  1568. private void Control_DrawDistrbutionImageAndBSE_MouseDoubleClick(object sender, MouseEventArgs e)
  1569. {
  1570. #if DEBUG
  1571. Screen[] screens = Screen.AllScreens;
  1572. string ls_str = "";
  1573. for (int i = 0; i < screens.Count(); i++)
  1574. {
  1575. ls_str = ls_str + "显示器" + (i + 1).ToString() + " 名称:" + screens[i].DeviceName + Environment.NewLine +
  1576. "显示器" + (i + 1).ToString() + " 是否主要显示器:" + screens[i].Primary + Environment.NewLine +
  1577. "显示器" + (i + 1).ToString() + " WorkingArea:" + screens[i].WorkingArea + Environment.NewLine +
  1578. "显示器" + (i + 1).ToString() + " Bounds:" + screens[i].Bounds + Environment.NewLine +
  1579. "显示器" + (i + 1).ToString() + " 色深:" + screens[i].BitsPerPixel + Environment.NewLine;
  1580. }
  1581. MessageBox.Show("------------------该段代码主要用来测试程序---------------------" + Environment.NewLine +
  1582. //"当前窗体X:" + this.ParentForm.Location.X.ToString() + " Y:" + this.ParentForm.Location.Y.ToString() + Environment.NewLine +
  1583. "显示器数量" + Screen.AllScreens.Count().ToString() + Environment.NewLine +
  1584. ls_str +
  1585. "DESKTOP.Width:" + MyPrimaryScreen.DESKTOP.Width + " DESKTOP.Height:" + MyPrimaryScreen.DESKTOP.Height + Environment.NewLine +
  1586. "DpiX:" + MyPrimaryScreen.DpiX + " DpiY:" + MyPrimaryScreen.DpiY + Environment.NewLine +
  1587. "ScaleX:" + MyPrimaryScreen.ScaleX + " ScaleY:" + MyPrimaryScreen.ScaleY + Environment.NewLine +
  1588. "WorkingArea.Width:" + MyPrimaryScreen.WorkingArea.Width + " WorkingArea.Height:" + MyPrimaryScreen.WorkingArea.Height + Environment.NewLine +
  1589. "this.Width:" + this.Width + " this.Height:" + this.Height + Environment.NewLine +
  1590. "单像素比:" + m_pixelSize.ToString() + Environment.NewLine +
  1591. "缩放倍数:" + m_zoom_record.ToString() + Environment.NewLine +
  1592. "屏幕像素backrectf x:" + m_backRect.X.ToString() + " y:" + m_backRect.Y.ToString() + " width:" + m_backRect.Width.ToString() + " height:" + m_backRect.Height.ToString() + Environment.NewLine +
  1593. //"屏幕像素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 +
  1594. "物理像素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 +
  1595. //"单个Field视域屏幕像素宽:" + m_OneField_Screen_BackRectf.Width.ToString() + " 高:" + m_OneField_Screen_BackRectf.Height.ToString() + Environment.NewLine +
  1596. //"单个OTS视域屏幕像素宽:" + m_OneField_OTS_Rect.Width.ToString() + " 高:" + m_OneField_OTS_Rect.Height.ToString() + Environment.NewLine +
  1597. "屏幕像素backrectf x:" + m_backRect.X.ToString() + " y:" + m_backRect.Y.ToString() + " width:" + m_backRect.Width.ToString() + " height:" + m_backRect.Height.ToString() + Environment.NewLine +
  1598. "包含Field数量:" + imageDisHelper.m_field_count.ToString() + " Particle数量:" + imageDisHelper.m_particle_count.ToString() + Environment.NewLine +
  1599. "正常显示Paticle数量:" + GetParticleNumberByState(PaintState.PAINT).ToString() + " 不显示Particel数量:" + GetParticleNumberByState(PaintState.NOPAINT).ToString() + Environment.NewLine +
  1600. //"删除Particle数量:" + GetParticleNumberByState("删除").ToString() + " 选中Particle数量:" + GetParticleNumberByState("选择").ToString() + Environment.NewLine +
  1601. "加载底层数据用时:" + imageDisHelper.m_time_str + Environment.NewLine +
  1602. "组建并计算图像用时:" + imageDisHelper.m_time_str2 + Environment.NewLine +
  1603. "---------------------------END----------------------------------"
  1604. );
  1605. #endif
  1606. }
  1607. #endregion
  1608. private void ExportoriginalspliceToolStripMenuItem_Click(object sender, EventArgs e)
  1609. {
  1610. this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
  1611. SaveFileDialog sfd = new SaveFileDialog();
  1612. var particledata = new ParticleData(resultFile.FilePath);
  1613. DataTable ParticleAll = particledata.GetParticleTypeInformation();
  1614. DataTable ParticleClass = particledata.GetParticleClassAll();
  1615. //|ALL Files(*.*)|*.*
  1616. //BMP Files(*.bmp)| *.bmp |
  1617. sfd.Filter = "png Files(*.png)| *.png |BMP Files(*.bmp)| *.bmp |JPG Files(*.jpg)|*.jpg;*.jpeg";
  1618. if (sfd.ShowDialog() == DialogResult.OK)
  1619. {
  1620. OutPIC outpic = new OutPIC();
  1621. outpic.m_list_allDfield = m_list_allDfield;
  1622. outpic.resultFile = resultFile;
  1623. outpic.sfd = sfd;
  1624. outpic.type = (int)Outpic_enum.Render_pic;
  1625. outpic.ParticleData = ParticleAll.Copy();
  1626. outpic.ParticleClassData = ParticleClass.Copy();
  1627. Thread bThread = new Thread(new ThreadStart(outpic.opencv_outpic));
  1628. bThread.IsBackground = true;
  1629. bThread.Start();
  1630. }
  1631. this.Cursor = System.Windows.Forms.Cursors.Default;
  1632. }
  1633. private void ToolStripMenuItemDelete_Particle_Click(object sender, EventArgs e)
  1634. {
  1635. DialogResult dr = MessageBox.Show("Should I delete particles", "Tips", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  1636. if (dr== DialogResult.OK)
  1637. {
  1638. if (DeleteParticlesFromLibrary(m_mouseOver_dparticle.ParticleId, m_mouseOver_dparticle.FieldId))
  1639. {
  1640. MessageBox.Show("Deleted successfully");
  1641. m_mouseOver_dparticle.IsDeleted=true;
  1642. }
  1643. else
  1644. {
  1645. MessageBox.Show("Delete failed");
  1646. }
  1647. }
  1648. else
  1649. {
  1650. return;
  1651. }
  1652. }
  1653. private bool DeleteParticlesFromLibrary(int in_clr_tagid, int in_clr_fieldid)
  1654. {
  1655. bool DoesItExist = false;
  1656. for (int i = 1; i < 201; i++)
  1657. {
  1658. if (System.IO.Directory.Exists(resultFile.FilePath + "\\FIELD_FILES\\Backups" + i.ToString()))
  1659. {
  1660. DoesItExist = true;
  1661. break;
  1662. }
  1663. }
  1664. if (!DoesItExist)
  1665. {
  1666. //备份数据库
  1667. BackupDatabase();
  1668. }
  1669. DoesItExist = false;
  1670. //防止为空校验判断
  1671. if (resultFile.List_OTSField == null)
  1672. return false;
  1673. Particle particle = resultFile.List_OTSField.Find(x => x.FieldID == in_clr_fieldid).ParticleList.Find(x => x.ParticleId == in_clr_tagid);
  1674. if (new ParticleData(resultFile.FilePath).DeleteFromData(Convert.ToString(particle.FieldId), Convert.ToString(particle.XrayId)))
  1675. {
  1676. return true;
  1677. }
  1678. else
  1679. {
  1680. return false;
  1681. }
  1682. }
  1683. private bool BackupDatabase()
  1684. {
  1685. //创建备份数据库文件夹
  1686. string sourcePath = resultFile.FilePath + "\\FIELD_FILES\\Inclusion.db";//源文件路径
  1687. string sourceName = "Inclusion.db";//源文件名称
  1688. string folderPath = resultFile.FilePath + "\\FIELD_FILES\\Backups";//目标文件夹
  1689. string Fields = "";
  1690. for (int i = 1; i < 201; i++)
  1691. {
  1692. if (System.IO.Directory.Exists(folderPath + i.ToString()))
  1693. {
  1694. Fields = folderPath + i.ToString();
  1695. continue;
  1696. }
  1697. else
  1698. {
  1699. System.IO.Directory.CreateDirectory(folderPath + i.ToString());
  1700. Fields = folderPath + i.ToString();
  1701. break;
  1702. }
  1703. }
  1704. if (Fields == "")
  1705. {
  1706. return false;
  1707. }
  1708. //复制数据库文件
  1709. string targetPath = Path.Combine(Fields, sourceName);
  1710. FileInfo file = new FileInfo(sourcePath);
  1711. if (file.Exists)
  1712. {
  1713. file.CopyTo(targetPath, true);
  1714. }
  1715. return true;
  1716. }
  1717. int GetsIntersectionOfTheIntercepts(Point P1,Point P2,int y)
  1718. {
  1719. int x = (y - P1.Y * P2.X + P1.X * P2.Y) / (P2.Y - P1.Y);
  1720. return x;
  1721. }
  1722. //private void ParticleSegmentation_Click(object sender, EventArgs e)
  1723. //{
  1724. // Particle_Segmentation();
  1725. //}
  1726. private void 分割颗粒ToolStripMenuItem_Click(object sender, EventArgs e)
  1727. {
  1728. Particle_Segmentation();
  1729. }
  1730. private void ImportSTDDb_Click(object sender, EventArgs e)
  1731. {
  1732. Dictionary<string, object> sampleMembers = ((Dictionary<string, object>)((Dictionary<string, object>)resultFile.ResultInfo["Sample"])["Members"]);
  1733. string STDName = ((Dictionary<string, object>)sampleMembers["MsrParams"])["STDName"].ToString();
  1734. string ResultDbPath = resultFile.FilePath + "\\FIELD_FILES\\Inclusion.db";
  1735. if (STDName.ToLower().Split('.')[0] == "nostddb")
  1736. {
  1737. OpenFileDialog openFileDialog = new OpenFileDialog();
  1738. openFileDialog.Filter = "(*.db)|*.db";
  1739. openFileDialog.RestoreDirectory = true;
  1740. openFileDialog.FilterIndex = 1;
  1741. openFileDialog.Title = "Please choose a STD to add the rule!";
  1742. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1743. {
  1744. try
  1745. {
  1746. string arguments = openFileDialog.FileName;
  1747. foreach (DisplayParticle item in m_list_allDPart)
  1748. {
  1749. DisplayParticle dp = item;
  1750. if (imageDisHelper.WhetherInRange(dp, m_mouse_now_point))
  1751. {
  1752. arguments += " " + ResultDbPath + " " + dp.FieldId + " " + dp.ParticleId + " " + dp.XRayId;
  1753. break;
  1754. }
  1755. }
  1756. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSPartA_STDEditor.exe", arguments);
  1757. p.WaitForExit();
  1758. }
  1759. catch (Exception ex)
  1760. {
  1761. log.Error("OTSPartA_STDEditor:" + ex.ToString());
  1762. }
  1763. }
  1764. }
  1765. else
  1766. {
  1767. string arguments = ".\\Config\\SysData\\"+ STDName.Split('.')[0]+".db";
  1768. foreach (DisplayParticle item in m_list_allDPart)
  1769. {
  1770. DisplayParticle dp = item;
  1771. if (imageDisHelper.WhetherInRange(dp, m_mouse_now_point))
  1772. {
  1773. arguments += " " + ResultDbPath + " " + dp.FieldId + " " + dp.ParticleId + " " + dp.XRayId;
  1774. break;
  1775. }
  1776. }
  1777. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSPartA_STDEditor.exe", arguments);
  1778. p.WaitForExit();
  1779. }
  1780. }
  1781. }
  1782. }