Control_DrawDistrbutionImageAndBSE.cs 81 KB

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