Control_DrawDistrbutionImageAndBSE.cs 82 KB

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