Control_DrawDistrbutionImageAndBSE.cs 87 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497
  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 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. CopyImage = 0,
  47. OriginalSplicing = 1
  48. }
  49. /// <summary>
  50. /// 选择导出的图片是原图还是颗粒渲染后的图片
  51. /// </summary>
  52. public enum Outpic_enum
  53. {
  54. pic = 0,
  55. Render_pic = 1,
  56. noBackground_pic = 2,
  57. Combin,
  58. Render_Combin
  59. }
  60. public partial class Control_DrawDistrbutionImageAndBSE : UserControl
  61. {
  62. private OTSImageDisHelp imageDisHelper = null;
  63. //缩放的增大缩小的增量
  64. private const float const_zoom_increment = 0.05f;
  65. //最大缩放倍数
  66. private const float m_f_zoom_max = 4f;
  67. //最小缩放倍数
  68. private float m_f_zoom_mix = 0.05f;
  69. //标尺原先大小的记录,参与计算
  70. private float m_f_old_ruler_size = 100;
  71. double ls_d_cz_width;
  72. double ls_d_cz_height;
  73. #region 变量定义
  74. private SelectTool m_SelectTool;
  75. private ParticleSegmentation m_ParticleSegmentation;
  76. public bool isReView = false;
  77. public int reViewFieldId = 0;
  78. public int reViewParticleId = 0;
  79. //与原先缩放的记录数
  80. private float m_zoom_record = 1;
  81. //标尺的大小记录
  82. public float m_f_ruler_size = 100;
  83. public float m_pixelSize = 4.5f;
  84. //国际化存储信息
  85. System.Collections.Hashtable table;
  86. //包含particle的field的列表对象
  87. public List<DisplayField> m_list_allDfield = null;
  88. //这里要做成控件,不要是窗体
  89. public List<DisplayParticle> m_list_allDPart = null;
  90. public List<DisplayParticle> m_list_allDPart_original = null;
  91. public List<DisplayField> m_CurGBFields = new List<DisplayField>();
  92. //总背景矩形
  93. private RectangleF m_backRect = new RectangleF();
  94. private PointF m_ScaleRefPoint;
  95. //记录总物理矩形总大小
  96. public RectangleF m_back_wl_rectf = new RectangleF();
  97. //是否显示网格线
  98. private bool m_is_showgrid = false;
  99. //是否拖动
  100. private bool m_isDrag = false;
  101. //拖动前的坐标记录
  102. private PointF m_beforedrag_pointf = new PointF();
  103. //提供鼠标在右下角显示的文本,左侧
  104. private string m_str_mouseshow_left = "";
  105. //提供鼠标在右下角显示的文本,右侧
  106. private string m_str_mouseshow_right = "";
  107. //当前鼠标的位置
  108. Point m_mouse_now_point = new Point();
  109. Point m_currentMouseDownPoint;
  110. //记录当前鼠标位置对应SEM电镜的位置
  111. Point m_sem_mouse_now_point = new Point();
  112. //鼠标移动经过的颗粒对象,临时存放,用来记录是否要显示xray与隐藏xray
  113. DisplayParticle m_mouseOver_dparticle = null;
  114. //保存数据源名称
  115. private string m_showsourcename = "";
  116. //保存当前数据源的ID
  117. private int m_datasourceid = 0;
  118. //移动SEM到指定位置发生线程
  119. private Thread m_mythread;
  120. private Color m_ColorNotContent = Color.SkyBlue;
  121. //读取背景原图的名称和图片
  122. private Dictionary<string, Image> originalImages = new Dictionary<string, Image>();
  123. private DISTRIBUTION_IMAGE_SHOW_MODE showMode;
  124. static System.Windows.Forms.Timer delaytimer = new System.Windows.Forms.Timer();
  125. Logger log;
  126. public string ShowSourceName
  127. {
  128. set { m_showsourcename = value; }
  129. get { return m_showsourcename; }
  130. }
  131. /// <summary>
  132. /// 当前正在显示的数据源的ID
  133. /// </summary>
  134. public int DataSourceID
  135. {
  136. set { m_datasourceid = value; }
  137. get { return m_datasourceid; }
  138. }
  139. //进度条窗体
  140. public Frm_UserProgress m_frm_userprogress;
  141. OTSIncAReportApp.frmReportApp m_ReportApp;
  142. ResultFile resultFile = null;
  143. //private Cursor cursor1;
  144. #endregion
  145. #region 构造函数及窗体加载
  146. public Control_DrawDistrbutionImageAndBSE(OTSIncAReportApp.frmReportApp ReportApp)
  147. {
  148. log = NLog.LogManager.GetCurrentClassLogger();
  149. m_list_allDfield = new List<DisplayField>();
  150. m_list_allDPart = new List<DisplayParticle>();
  151. m_frm_userprogress = new Frm_UserProgress();
  152. //cursor1 = Cursor;
  153. m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
  154. m_ReportApp = ReportApp;
  155. resultFile = m_ReportApp.m_rstDataMgr.CurResultFile;
  156. InitializeComponent();
  157. #region 国际化语言
  158. Language lan = new Language(this);
  159. table = lan.GetNameTable(this.Name);
  160. #endregion
  161. //load the userdefine control dynamically
  162. System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Control_DrawDistrbutionImageAndBSE));
  163. this.control_XRayTable1 = new Control_XRayTable();
  164. this.control_XRayTable1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
  165. this.control_XRayTable1.Dock = System.Windows.Forms.DockStyle.Bottom;
  166. this.control_XRayTable1.GBInfoStr = "";
  167. this.control_XRayTable1.GoodChineseName = "";
  168. this.control_XRayTable1.MaterialName = "";
  169. this.control_XRayTable1.List_ShowElementInfo = ((System.Collections.Generic.List<OTSIncAReportGraph.Controls.ShowElementInfo>)(resources.GetObject("control_XRayTable1.List_ShowElementInfo")));
  170. this.control_XRayTable1.Location = new System.Drawing.Point(0, 400);
  171. this.control_XRayTable1.Name = "control_XRayTable1";
  172. this.control_XRayTable1.ShowAnalysisXray = true;
  173. this.control_XRayTable1.ShowSearchXray = false;
  174. this.control_XRayTable1.Size = new System.Drawing.Size(1004, 200);
  175. this.control_XRayTable1.STDName = "";
  176. this.control_XRayTable1.TabIndex = 6;
  177. this.control_XRayTable1.Visible = false;
  178. //
  179. // control_Ruler1
  180. //
  181. this.control_Ruler1 = new Control_Ruler();
  182. this.control_Ruler1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(200)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
  183. this.control_Ruler1.Location = new System.Drawing.Point(3, 400);
  184. this.control_Ruler1.Name = "control_Ruler1";
  185. this.control_Ruler1.RulerWidth = 100;
  186. this.control_Ruler1.ShowString = "100um";
  187. this.control_Ruler1.Size = new System.Drawing.Size(120, 40);
  188. this.control_Ruler1.TabIndex = 8;
  189. this.control_Ruler1.Value = 0D;
  190. this.control_Ruler1.Visible = false;
  191. this.Controls.Add(this.control_XRayTable1);
  192. this.Controls.Add(this.control_Ruler1);
  193. }
  194. private void ProgressBarUpdate(int progress, string message)
  195. {
  196. //显示进度条,计算进度条应该显示的位置和宽度
  197. if (m_frm_userprogress.Visible == false)
  198. {
  199. Form ls_main_form = this.ParentForm.ParentForm;//取出父窗体
  200. m_frm_userprogress.Width = (int)(MyPrimaryScreen.DESKTOP.Width / MyPrimaryScreen.ScaleX * 0.9);
  201. m_frm_userprogress.Location = new Point(ls_main_form.Location.X + 80, ls_main_form.Location.Y + (int)(MyPrimaryScreen.DESKTOP.Height / MyPrimaryScreen.ScaleX) / 2);
  202. m_frm_userprogress.Show();
  203. }
  204. m_frm_userprogress.SetProgressValueAndText(progress, message);
  205. }
  206. private void Control_DrawDistrbutionImageAndBSE_Load(object sender, EventArgs e)
  207. {
  208. //设置双缓冲
  209. SetDoubleBufferByIsDraw();
  210. ProgressBarUpdate(0, table["str1"].ToString());
  211. //初始化底层操作类
  212. imageDisHelper = new OTSImageDisHelp(resultFile);
  213. m_backRect = imageDisHelper.m_originalBackRect;
  214. string str29 = "begin to compose field picture....";
  215. log.Info(str29);
  216. ProgressBarUpdate(20, "compose whole picture....");
  217. List<Field> fieldlist = resultFile.List_OTSField;
  218. float ls_int_progresscalc = 0;
  219. if (fieldlist.Count > 0)
  220. ls_int_progresscalc = (float)70 / (float)fieldlist.Count;
  221. m_list_allDfield.Clear();
  222. m_list_allDPart.Clear();
  223. var fieldSize = imageDisHelper.GetFieldImageSize();
  224. for (int i = 0; i < fieldlist.Count(); i++)
  225. {
  226. ProgressBarUpdate(20 + (int)(ls_int_progresscalc * (i + 1)), "finished " + i.ToString() + "total " + resultFile.List_OTSField.Count.ToString() + "field...");
  227. Point thisfield_point = new Point() { X = fieldlist[i].FieldPosX, Y = fieldlist[i].FieldPosY };//get OTS coordination
  228. Point offset_point = imageDisHelper.ConvertOTSCoordToScreenCoord(thisfield_point);//the ots coordinate is always the up right positive.
  229. DisplayField df;
  230. try
  231. {
  232. df = new DisplayField(fieldlist[i], (int)fieldSize.Width, (int)fieldSize.Height, offset_point);
  233. df.ContentColor = Color.Black;
  234. m_list_allDfield.Add(df);
  235. m_list_allDPart.AddRange(df.List_DParticle);
  236. }
  237. catch (Exception ex)
  238. {
  239. NLog.LogManager.GetCurrentClassLogger().Info(ex.ToString());
  240. }
  241. }
  242. m_list_allDPart_original = new List<DisplayParticle>();
  243. foreach (var apart in m_ReportApp.im_Control_DrawDistrbutionImageAndBSE.m_list_allDPart)
  244. {
  245. m_list_allDPart_original.Add(apart.Clone() as DisplayParticle);
  246. }
  247. m_pixelSize = resultFile.GetPixelSize();
  248. //设置标尺
  249. //根据f_onepixel_size计算出要显示出100um的实际宽度
  250. float d_onefixel_width = 100 / m_pixelSize;
  251. if (d_onefixel_width == 0)
  252. {
  253. this.control_Ruler1.Visible = false;
  254. }
  255. else
  256. {
  257. m_f_ruler_size = d_onefixel_width;
  258. m_f_old_ruler_size = d_onefixel_width;
  259. //将标尺定位到合理的位置上
  260. this.control_Ruler1.Location = new Point(10, MyPrimaryScreen.WorkingArea.Height - 300);
  261. this.control_Ruler1.Visible = true;
  262. this.control_Ruler1.SetValue(m_f_ruler_size);
  263. this.control_Ruler1.ShowString = Convert.ToInt32(100).ToString() + "μm";
  264. }
  265. ProgressBarUpdate(100, table["str2"].ToString());
  266. m_frm_userprogress.Visible = false;
  267. if (m_ReportApp.im_ParticlesGridDevidePage != null)
  268. {
  269. m_ReportApp.im_ParticlesGridDevidePage.ToolStripMenuItem_Addparticlestotheselectparticleslist.Visible = true; //由于分布图和颗粒表数据来源相对独立,所以只能在这里激活颗粒表选择菜单,待日后修改数据源加载方式,此项需修改
  270. }
  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 + m_f_old_ruler_size * zoomDelta;//m_f_old_ruler_size
  542. control_Ruler1.SetValue(m_f_ruler_size);
  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. else
  625. {
  626. m_currentMouseDownPoint = e.Location;
  627. }
  628. Invalidate();
  629. }
  630. protected override void OnMouseMove(MouseEventArgs e)
  631. {
  632. //当前鼠标的位置,用来绘制鼠标线用
  633. m_mouse_now_point = e.Location;
  634. if (m_ParticleSegmentation.IsParticleSegmentation)
  635. {
  636. if (e.Button == MouseButtons.Left)
  637. {
  638. m_ParticleSegmentation.EndPoint = e.Location;
  639. }
  640. }
  641. if (m_SelectTool.IsSelecting)
  642. {
  643. if (e.Button == MouseButtons.Left)
  644. {
  645. if (e.Location.X > m_SelectTool.StartPoint.X && e.Location.Y > m_SelectTool.StartPoint.Y)
  646. {
  647. //右下拖动
  648. m_SelectTool.Rect = new RectangleF(m_SelectTool.StartPoint, new SizeF(e.Location.X - m_SelectTool.StartPoint.X, e.Location.Y - m_SelectTool.StartPoint.Y));
  649. }
  650. if (e.Location.X < m_SelectTool.StartPoint.X && e.Location.Y < m_SelectTool.StartPoint.Y)
  651. {
  652. //左上拖动
  653. PointF lspointf = new PointF(e.Location.X, e.Location.Y);
  654. m_SelectTool.Rect = new RectangleF(lspointf, new SizeF(m_SelectTool.StartPoint.X - e.Location.X, m_SelectTool.StartPoint.Y - e.Location.Y));
  655. }
  656. if (e.Location.X > m_SelectTool.StartPoint.X && e.Location.Y < m_SelectTool.StartPoint.Y)
  657. {
  658. //右上,这种画法,需要将左下,右上两点转换成左上,右下
  659. PointF left_pointf = new PointF(m_SelectTool.StartPoint.X, e.Location.Y);
  660. PointF right_pointf = new PointF(e.Location.X, m_SelectTool.StartPoint.Y);
  661. m_SelectTool.Rect = new RectangleF(left_pointf, new SizeF(right_pointf.X - left_pointf.X, right_pointf.Y - left_pointf.Y));
  662. }
  663. if (e.Location.X < m_SelectTool.StartPoint.X && e.Location.Y > m_SelectTool.StartPoint.Y)
  664. {
  665. //左下,这种画法,需要将左下,右上两点转换成左上,右下
  666. PointF left_pointf = new PointF(e.Location.X, m_SelectTool.StartPoint.Y);
  667. PointF right_pointf = new PointF(m_SelectTool.StartPoint.X, e.Location.Y);
  668. m_SelectTool.Rect = new RectangleF(left_pointf, new SizeF(right_pointf.X - left_pointf.X, right_pointf.Y - left_pointf.Y));
  669. }
  670. }
  671. }
  672. else
  673. {
  674. if (m_isDrag)
  675. {
  676. foreach (DisplayParticle dp in m_list_allDPart)
  677. {
  678. if (dp.IsDragging)
  679. {
  680. dp.DraggingMove(e.Location);
  681. }
  682. }
  683. foreach (var item in m_list_allDfield)
  684. {
  685. if (item.IsDragging)
  686. {
  687. item.DraggingMove(e.Location);
  688. }
  689. }
  690. foreach (var item in m_CurGBFields)
  691. {
  692. if (item.IsDragging)
  693. {
  694. item.DraggingMove(e.Location);
  695. }
  696. }
  697. //同样重新计算backrectf的坐标
  698. m_backRect = new RectangleF(m_backRect.Location.X + e.X - m_beforedrag_pointf.X,
  699. m_backRect.Location.Y + e.Y - m_beforedrag_pointf.Y, m_backRect.Width, m_backRect.Height);
  700. m_beforedrag_pointf = e.Location;
  701. }
  702. else
  703. {
  704. foreach (DisplayParticle item in m_list_allDPart)
  705. {
  706. DisplayParticle dp = item;
  707. if (dp.GetPaintState() == PaintState.PAINT)
  708. {
  709. if (imageDisHelper.WhetherInRange(dp, e.Location))
  710. {
  711. dp.IsMouseOver = true;
  712. ShowParticleInfo(dp);
  713. m_ParticleSegmentation.Rectangle = dp.GetShowRect();
  714. }
  715. else
  716. {
  717. dp.IsMouseOver = false;
  718. HideParticleInfo(dp);
  719. }
  720. }
  721. }
  722. }
  723. }
  724. #region 向报告程序右下角,传送鼠标颗粒等相关信息
  725. //获取颜色方法1,使用API来获取当前鼠标指向位置的颜色值-----------------------------------------------------
  726. Color ls_c = GetColorByMousePoint(e.X, e.Y);
  727. m_str_mouseshow_right = "灰度#" + ls_c.R.ToString();
  728. m_ReportApp.mouseMatter.Text = m_str_mouseshow_right;
  729. m_ReportApp.RSGrayVal.Text = m_str_mouseshow_left;
  730. #endregion
  731. Invalidate();
  732. }
  733. /// <summary>
  734. /// 计算颗粒中心的电镜坐标
  735. /// </summary>
  736. /// <param name="resultFile"></param>
  737. /// <param name="SEMPos"></param>
  738. /// <param name="ParticlePos"></param>
  739. /// <returns></returns>
  740. public static Point CalculateParticleCenterPosition(ResultFile resultFile, Point SEMPos, Point ParticlePos)
  741. {
  742. Point point = new Point();
  743. float ScanFieldSizeX = resultFile.GetScanFieldSizeX();
  744. string leftOrRight = resultFile.GetXAxisDir();
  745. string downOrUp = resultFile.GetYAxisDir();
  746. float ScanFieldSizeY = resultFile.GetScanFieldSizeY();
  747. float m_pixelSize = resultFile.GetPixelSize();
  748. if (leftOrRight == "RIGHT_TOWARD")
  749. {
  750. point.X = (int)(SEMPos.X - ScanFieldSizeX / 2 + ParticlePos.X * m_pixelSize);
  751. }
  752. else
  753. {
  754. point.X = (int)(SEMPos.X + ScanFieldSizeX / 2 - ParticlePos.X * m_pixelSize);
  755. }
  756. if (downOrUp == "UP_TOWARD")
  757. {
  758. point.Y = (int)(SEMPos.Y + ScanFieldSizeY / 2 - ParticlePos.Y * m_pixelSize);
  759. }
  760. else
  761. {
  762. point.Y = (int)(SEMPos.Y - ScanFieldSizeY / 2 + ParticlePos.Y * m_pixelSize);
  763. }
  764. return point;
  765. }
  766. /// <summary>
  767. /// 获取鼠标所在位置的信息,显示在框架的右下角
  768. /// </summary>
  769. /// <param name="mouseshow_left"></param>
  770. /// <param name="mouseshow_rightb"></param>
  771. public void GetMouseLowerRightCornerText(out string mouseshow_left, out string mouseshow_rightb)
  772. {
  773. mouseshow_left = m_str_mouseshow_left;
  774. mouseshow_rightb = m_str_mouseshow_right;
  775. }
  776. /// <summary>
  777. /// 鼠标抬起事件
  778. /// </summary>
  779. /// <param name="e"></param>
  780. protected override void OnMouseUp(MouseEventArgs e)
  781. {
  782. if (e.Button == MouseButtons.Left)
  783. {
  784. this.Cursor = Cursors.Default;
  785. if (m_SelectTool.IsSelecting)
  786. {
  787. if (m_SelectTool.Rect.Width > 0 && m_SelectTool.Rect.Height > 0)
  788. {
  789. GraphicsPath ls_gpath = new GraphicsPath();
  790. switch (m_SelectTool.Shape)
  791. {
  792. case SelectedShape.Rectangle:
  793. ls_gpath.AddRectangle(m_SelectTool.Rect);
  794. break;
  795. case SelectedShape.Ellipse:
  796. ls_gpath.AddEllipse(m_SelectTool.Rect);
  797. break;
  798. default:
  799. break;
  800. }
  801. foreach (DisplayParticle dp in m_list_allDPart)
  802. {
  803. if (dp.GetPaintState() != PaintState.NOPAINT)
  804. {
  805. PointF[] lspointf = ls_gpath.PathPoints;
  806. if (true == imageDisHelper.WhetherInRange(m_SelectTool.Rect, lspointf, new Point((int)dp.GetShowRect().X, (int)dp.GetShowRect().Y)))
  807. {
  808. //dp.IsSelect = !dp.IsSelect;// set the particle to the oposite selected state
  809. dp.IsSelect = true;//框选不应反选!
  810. }
  811. }
  812. }
  813. }
  814. m_SelectTool.IsSelecting = false;
  815. }
  816. else if (m_ParticleSegmentation.IsParticleSegmentation)
  817. {
  818. m_ParticleSegmentation.EndPoint = e.Location;
  819. DialogResult res = MessageBox.Show(table["str11"].ToString(), "", MessageBoxButtons.OKCancel);
  820. if (res == DialogResult.OK)
  821. {
  822. imageDisHelper.m_ParticleSegmentation = m_ParticleSegmentation;
  823. bool isTrue = imageDisHelper.isLineIntersectRectangle(m_ParticleSegmentation.StartPoint.X, m_ParticleSegmentation.StartPoint.Y, m_ParticleSegmentation.EndPoint.X, m_ParticleSegmentation.EndPoint.Y,
  824. m_ParticleSegmentation.Rectangle.Left, m_ParticleSegmentation.Rectangle.Top, m_ParticleSegmentation.Rectangle.Right, m_ParticleSegmentation.Rectangle.Bottom);
  825. if (isTrue)//判断绘制线段是否与颗粒外接矩形相交
  826. {
  827. List<Point> pointList = new List<Point>();
  828. if (imageDisHelper.GetInterBetweenLinesAndRect(m_ParticleSegmentation.StartPoint, m_ParticleSegmentation.EndPoint, m_ParticleSegmentation.Rectangle, ref pointList))
  829. {
  830. if (pointList.Count != 2)
  831. {
  832. MessageBox.Show(table["str12"].ToString());
  833. }
  834. else
  835. {
  836. if (!imageDisHelper.GetSplitPartFun(pointList[0], pointList[1], m_pixelSize))
  837. {
  838. MessageBox.Show(table["str13"].ToString());
  839. }
  840. else
  841. {
  842. FieldData fieldData = new FieldData(resultFile.FilePath);
  843. List<Field> fieldlist = fieldData.GetFieldList();
  844. m_ReportApp.m_rstDataMgr.CurResultFile.List_OTSField = fieldlist;
  845. m_ReportApp.rbRenewFun(true, m_ParticleSegmentation.ParticleData.FieldId, m_ParticleSegmentation.ParticleData.ParticleId);
  846. }
  847. }
  848. }
  849. }
  850. else
  851. {
  852. MessageBox.Show(table["str14"].ToString());
  853. }
  854. }
  855. m_ParticleSegmentation.IsParticleSegmentation = false;
  856. }
  857. else
  858. {
  859. if (m_isDrag)
  860. {
  861. foreach (DisplayParticle dp in m_list_allDPart)
  862. {
  863. dp.DraggingMove(e.Location);
  864. dp.DraggingPoint = Point.Empty;
  865. dp.IsDragging = false;
  866. PointF ct = dp.GetCenterPoint();
  867. if (ct.X < -100 || ct.X > this.Width + 100 || ct.Y < -100 || ct.Y > this.Height + 100)
  868. {
  869. dp.SetPaintState(PaintState.NOPAINT);//the particles which are out of screen don't display.to speed up the display efficient.
  870. }
  871. else
  872. {
  873. dp.SetPaintState(PaintState.PAINT);
  874. }
  875. }
  876. m_isDrag = false;
  877. }
  878. }
  879. SetParticlesSelected();
  880. }
  881. if (e.Button == MouseButtons.Right)
  882. {
  883. bool ifClickOnParticle = false;
  884. foreach (DisplayParticle item in m_list_allDPart)
  885. {
  886. if (true == imageDisHelper.WhetherInRange(item, e.Location))
  887. {
  888. ifClickOnParticle = true;
  889. CMenuStrip.Items[(int)RightButtonMenu.CopyImage].Visible = false;
  890. CMenuStrip.Items[(int)RightButtonMenu.OriginalSplicing].Visible = false;
  891. contextMenuStrip_Particle.Visible = true;
  892. contextMenuStrip_Particle.Show(this, e.Location);
  893. ToolStripMenuItem_movesempoint.Tag = item;
  894. DisplayParticle dp = (DisplayParticle)item;
  895. m_ParticleSegmentation.ParticleData = dp.objParticleData;
  896. }
  897. }
  898. if (ifClickOnParticle == false)
  899. {
  900. contextMenuStrip_Particle.Visible = false;
  901. CMenuStrip.Items[(int)RightButtonMenu.CopyImage].Visible = true;
  902. CMenuStrip.Items[(int)RightButtonMenu.OriginalSplicing].Visible = true;
  903. }
  904. var m_RptConfigFile = RptConfigFile.GetRptConfig(); //报表程序的配置文件
  905. if (m_RptConfigFile.Systype == OTS_SysType_ID.CleannessA)
  906. {
  907. 显示国标信息ToolStripMenuItem.Visible = false;
  908. }
  909. }
  910. Invalidate();
  911. }
  912. #endregion
  913. #region 鼠标右键菜单
  914. private void ToolStripMenuItem_id_Click(object sender, EventArgs e)
  915. {
  916. //ID
  917. //DisplayParticle dp = (DisplayParticle)CMenuStrip.Items[0].Tag;
  918. //MessageBox.Show(dp.guid.ToString());
  919. }
  920. //是否显示过小颗菜单
  921. private void ToolStripMenuItem_ShowSmallParticle_Click(object sender, EventArgs e)
  922. {
  923. }
  924. void SetParticlesSelected()
  925. {
  926. List<DisplayParticle> selectedParts = new List<DisplayParticle>();
  927. List<Particle> Particles = new List<Particle>();
  928. foreach (var dp in m_list_allDPart)
  929. {
  930. if (dp.IsSelect)
  931. {
  932. selectedParts.Add((DisplayParticle)dp);
  933. Particle particle = new Particle();
  934. particle.FieldId = ((OTSIncAReportGraph.DisplayParticle)dp).FieldId;
  935. particle.ParticleId = ((OTSIncAReportGraph.DisplayParticle)dp).ParticleId;
  936. Particles.Add(particle);
  937. }
  938. }
  939. SendSelectParticleListToReportFrame(selectedParts);
  940. }
  941. /// <summary>
  942. /// 显示x-ray能谱图
  943. /// </summary>
  944. /// <param name="in_dparticle"></param>
  945. private void ShowParticleInfo(DisplayParticle in_dparticle)
  946. {
  947. if (delaytimer.Enabled == false)
  948. {
  949. m_mouseOver_dparticle = in_dparticle;//将显示xray的dparticle记录给全局变量
  950. delaytimer.Tick += Delaytimer_Tick;
  951. delaytimer.Interval = 500;
  952. delaytimer.Start();
  953. }
  954. }
  955. private void Delaytimer_Tick(object sender, EventArgs e)
  956. {
  957. delaytimer.Enabled = false;
  958. 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));
  959. m_str_mouseshow_left = "颗粒SEM位置:" + point.X.ToString() + ":" + point.Y.ToString();
  960. m_sem_mouse_now_point = point;
  961. //显示xray相关信息
  962. uint[] Search_xray = new uint[2000];
  963. uint[] Analysis_xray = new uint[2000];
  964. //
  965. int i_xray_id = 0;
  966. List<Element> list_celementchemistryclr = new List<Element>();
  967. //获取Xray数据
  968. imageDisHelper.GetXrayByParticleTagIDAndFieldID_ForDrawDistrbutionImageAndBSE(m_mouseOver_dparticle.ParticleId, m_mouseOver_dparticle.FieldId, out Search_xray, out Analysis_xray, out i_xray_id, out list_celementchemistryclr);
  969. //get CElementChemistryClr list
  970. List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
  971. for (int i = 0; i < list_celementchemistryclr.Count; i++)
  972. {
  973. ShowElementInfo ls_sei = new ShowElementInfo();
  974. ls_sei.ElementName = list_celementchemistryclr[i].Name;
  975. ls_sei.Percentage = list_celementchemistryclr[i].Percentage;
  976. ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).K_Peak);
  977. double de_sx2 = 0;
  978. if (CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "" || CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "-")
  979. {
  980. de_sx2 = 0;
  981. }
  982. else
  983. {
  984. de_sx2 = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak);
  985. }
  986. ls_sei.dLF = de_sx2;
  987. list_showelementinfo.Add(ls_sei);
  988. }
  989. string str_IncAName = "";
  990. str_IncAName = m_mouseOver_dparticle.TypeName;
  991. Particle particle = resultFile.List_OTSField.Find(x => x.FieldID == m_mouseOver_dparticle.FieldId).ParticleList.Find(x => x.ParticleId == m_mouseOver_dparticle.ParticleId);
  992. 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));
  993. //获取数据后,需要对xraytable设置
  994. control_XRayTable1.Visible = true;
  995. control_XRayTable1.SetXRayShowLineValue(Search_xray, Analysis_xray, list_showelementinfo);
  996. //颗粒国标信息
  997. control_XRayTable1.GBInfoStr = "";
  998. control_XRayTable1.MaterialName = str_IncAName;//杂夹物
  999. control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
  1000. Invalidate();
  1001. }
  1002. /// <summary>
  1003. /// 隐藏x-ray能谱图
  1004. /// </summary>
  1005. private void HideParticleInfo(DisplayParticle in_dparticle)
  1006. {
  1007. if (m_mouseOver_dparticle == null)
  1008. return;
  1009. if (m_mouseOver_dparticle.guid == in_dparticle.guid || m_mouseOver_dparticle.IsDeleted == true)
  1010. {
  1011. //如果是刚才移动过的颗粒的话,那么这里再对xray进行隐藏
  1012. control_XRayTable1.Visible = false;
  1013. delaytimer.Enabled = false;
  1014. }
  1015. }
  1016. /// <summary>
  1017. /// 根据传入的鼠标位置,来获取当前鼠标位置上的灰度值
  1018. /// </summary>
  1019. /// <param name="int_x"></param>
  1020. /// <param name="int_y"></param>
  1021. /// <returns></returns>
  1022. private Color GetColorByMousePoint(int int_x, int int_y)
  1023. {
  1024. Graphics g = Graphics.FromHwnd(this.Handle);
  1025. IntPtr hdc = g.GetHdc();
  1026. uint u_color = 0;
  1027. try
  1028. {
  1029. u_color = DrawFunction.GetPixel(hdc, int_x, int_y);
  1030. }
  1031. catch
  1032. { }
  1033. Color ls_c = Color.FromArgb
  1034. (
  1035. (int)(u_color << 24 >> 24),
  1036. (int)(u_color << 16 >> 24),
  1037. (int)(u_color << 8 >> 24)
  1038. );
  1039. return ls_c;
  1040. }
  1041. /// <summary>
  1042. /// 封装,将分布图中的颗粒list传送给报告项目框架中
  1043. /// </summary>
  1044. private void SendSelectParticleListToReportFrame(List<DisplayParticle> selectParts)
  1045. {
  1046. frmReportApp.selectedParticles.Clear();
  1047. foreach (var p in selectParts)
  1048. {
  1049. frmReportApp.selectedParticles.Add(p.guid, p);
  1050. }
  1051. }
  1052. /// <summary>
  1053. /// 设置当前对哪些颗粒进行设置为选择状态
  1054. /// </summary>
  1055. /// <param name="in_list_cotsparticleclr"></param>
  1056. public void SetSelectParticle(List<Particle> particles)
  1057. {
  1058. if (particles == null)
  1059. {
  1060. return;
  1061. }
  1062. if (particles.Count == 0)
  1063. {
  1064. return;
  1065. }
  1066. foreach (DisplayParticle ls_dp in m_list_allDPart)
  1067. {
  1068. if (ls_dp.GetPaintState() == PaintState.PAINT)
  1069. {
  1070. for (int i = 0; i < particles.Count; i++)
  1071. {
  1072. if (particles[i].ParticleId == ls_dp.ParticleId
  1073. && particles[i].FieldId == ls_dp.FieldId)
  1074. {
  1075. ls_dp.IsSelect = true;
  1076. }
  1077. }
  1078. }
  1079. }
  1080. }
  1081. //复制图像
  1082. private void toolStripMenuItem_copyimage_Click(object sender, EventArgs e)
  1083. {
  1084. SaveFileDialog sfd = new SaveFileDialog();
  1085. sfd.Filter = "png Files(*.png)| *.png |BMP Files(*.bmp)| *.bmp |JPG Files(*.jpg)|*.jpg;*.jpeg";
  1086. if (sfd.ShowDialog() == DialogResult.OK)
  1087. {
  1088. this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
  1089. OutPIC outpic = new OutPIC();
  1090. outpic.m_list_allDfield = m_list_allDfield;
  1091. outpic.resultFile = resultFile;
  1092. outpic.sfd = sfd;
  1093. outpic.type = (int)Outpic_enum.pic;
  1094. outpic.m_ReportApp = m_ReportApp;
  1095. Thread bThread = new Thread(new ThreadStart(outpic.opencv_outpic));
  1096. bThread.IsBackground = true;
  1097. bThread.Start();
  1098. }
  1099. }
  1100. public void msgInform()
  1101. {
  1102. MessageBox.Show("Export completed!");
  1103. this.Cursor = System.Windows.Forms.Cursors.Default;
  1104. }
  1105. private void ToolStripMenuItem_movesempoint_Click(object sender, EventArgs e)
  1106. {
  1107. //移动SEM到指定位置
  1108. if (m_mythread == null)
  1109. {
  1110. return;
  1111. }
  1112. if (m_mythread.ThreadState == System.Threading.ThreadState.Running || m_mythread.ThreadState == System.Threading.ThreadState.WaitSleepJoin)
  1113. {
  1114. return;
  1115. }
  1116. if (m_mythread.ThreadState == System.Threading.ThreadState.Stopped)
  1117. {
  1118. m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
  1119. }
  1120. //改为线程调用,先判断线程状态
  1121. m_mythread.Start(new Point(m_sem_mouse_now_point.X, m_sem_mouse_now_point.Y));
  1122. }
  1123. #endregion
  1124. #region 自定义功能函数
  1125. /// <summary>
  1126. /// 复制图像
  1127. /// </summary>
  1128. private void CopyImage()
  1129. {
  1130. int height, width;
  1131. width = this.Width;
  1132. height = this.Height;
  1133. Bitmap image = new Bitmap(width, height);
  1134. //this.BackgroundImage
  1135. this.DrawToBitmap(image, new Rectangle(0, 0, width, height));
  1136. Clipboard.SetImage(image);
  1137. }
  1138. /// <summary>
  1139. /// 移动SEM到指定位置线程函数
  1140. /// </summary>
  1141. private void Thread_GO(object in_obj)
  1142. {
  1143. Point sem_point = (Point)in_obj;
  1144. //第二步,移动到指定位置,先读取再设置
  1145. if (imageDisHelper.ConnectToIpcSvr())
  1146. {
  1147. imageDisHelper.MoveSemToPointXY(sem_point.X, sem_point.Y);
  1148. }
  1149. }
  1150. /// <summary>
  1151. /// 按框架传入的底层计算结果,重新对颗粒进行区分显示
  1152. /// </summary>
  1153. /// <param name="in_cgriddataclr"></param>
  1154. public void DrawDistrbutionImageAndBSE_ByQuery(ReportCondition in_griddata)
  1155. {
  1156. FilterParticleByOtherCondition(in_griddata);
  1157. Invalidate();
  1158. this.Refresh();
  1159. }
  1160. /// <summary>
  1161. /// 对分布图进行宽度匹配操作
  1162. /// </summary>
  1163. public void WidthMatch()
  1164. {
  1165. if (this.Width != m_backRect.Width)
  1166. {
  1167. float f_cz = 0;//进行调整的差值
  1168. f_cz = -((m_backRect.Width - this.Width) / m_backRect.Width);
  1169. var theZoom = m_zoom_record + m_zoom_record * f_cz;//更新上缩放值,与下面处理缩放对应上
  1170. ImageZoom(theZoom, new PointF(0, 0));
  1171. }
  1172. MoveImageToPoint(new PointF(0, 0));
  1173. }
  1174. /// <summary>
  1175. /// 对分布图进行高度匹配操作
  1176. /// </summary>
  1177. public void HeightMatch()
  1178. {
  1179. if (this.Height != m_backRect.Height)
  1180. {
  1181. float f_cz = 0;//进行调整的差值
  1182. f_cz = -((m_backRect.Height - this.Height) / m_backRect.Height);
  1183. var currentZoom = m_zoom_record + f_cz;//更新上缩放值,与下面处理缩放对应上
  1184. ImageZoom(currentZoom, new PointF(0, 0));
  1185. }
  1186. //移动到,this.width - backrectf.width /2
  1187. int ls_x = (int)(this.Width - m_backRect.Width) / 2;
  1188. MoveImageToPoint(new PointF(ls_x, 0));
  1189. }
  1190. /// <summary>
  1191. /// 对分布图进行全图匹配操作
  1192. /// </summary>
  1193. public void FullGraphMatch()
  1194. {
  1195. //全图匹配,首先要判断出来是按宽度来计算缩放,还是按高度来计算缩放
  1196. double thiswidth = this.Width;
  1197. double thisheight = this.Height;
  1198. double imagewidth = m_backRect.Width;
  1199. double imageheight = m_backRect.Height;
  1200. //如果宽已相等rect在thisheight范围内,是宽度匹配已经达到目的,或是高已相等rect在thiswidth范围内,是高度匹配已经达到目的
  1201. if ((thiswidth == imagewidth && thisheight > imagewidth) || (thisheight == imageheight && thiswidth > imagewidth))
  1202. {
  1203. //已经达到目的不操作,返回
  1204. return;
  1205. }
  1206. //判断当前是否宽度匹配未达到全图匹配效果
  1207. if (thiswidth == imagewidth && thisheight < imageheight)
  1208. {
  1209. //说明目前已经达到了宽度匹配,但是未能显示完全整图需要高度匹配
  1210. HeightMatch();
  1211. m_f_zoom_mix = m_zoom_record;
  1212. return;
  1213. }
  1214. //判断当前是否高度匹配未达到全图匹配效果
  1215. if (thisheight == imageheight && thiswidth < imagewidth)
  1216. {
  1217. //说明目前已经达到了高度匹配,但是未能显示完全的整图需要宽度匹配
  1218. WidthMatch();
  1219. m_f_zoom_mix = m_zoom_record;
  1220. return;
  1221. }
  1222. ls_d_cz_width = Math.Abs(thiswidth / imagewidth);
  1223. ls_d_cz_height = Math.Abs(thisheight / imageheight);
  1224. //应该是看谁差的倍数大就按谁的进行调整,而不只能看高宽的差值
  1225. if ((1 - ls_d_cz_width) > (1 - ls_d_cz_height))
  1226. {
  1227. //宽差大,就调用WidthMate
  1228. WidthMatch();
  1229. }
  1230. else
  1231. {
  1232. //高差大,则调用HightMate
  1233. HeightMatch();
  1234. }
  1235. m_f_zoom_mix = m_zoom_record;
  1236. }
  1237. /// <summary>
  1238. /// 将整个图像的位置移动到指定的位置上
  1239. /// </summary>
  1240. private void MoveImageToPoint(PointF in_pointf)
  1241. {
  1242. SizeF offex_p = new SizeF(m_backRect.X - in_pointf.X, m_backRect.Y - in_pointf.Y);
  1243. //同样重新计算backrectf的坐标
  1244. m_backRect = new RectangleF(in_pointf.X, in_pointf.Y,
  1245. m_backRect.Width, m_backRect.Height);
  1246. for (int i = 0; i < m_list_allDPart.Count; i++)
  1247. {
  1248. DisplayParticle dp = m_list_allDPart[i];
  1249. dp.Move(offex_p);
  1250. PointF ct = dp.GetCenterPoint();
  1251. if (ct.X < -100 || ct.X > this.Width + 100 || ct.Y < -100 || ct.Y > this.Height + 100)
  1252. {
  1253. dp.SetPaintState(PaintState.NOPAINT);//the particles which are out of screen don't display.to speed up the display efficient.
  1254. }
  1255. else
  1256. {
  1257. dp.SetPaintState(PaintState.PAINT);
  1258. }
  1259. }
  1260. for (int i = 0; i < m_list_allDfield.Count; i++)
  1261. {
  1262. var f = m_list_allDfield[i];
  1263. f.Move(offex_p);
  1264. }
  1265. for (int i = 0; i < m_CurGBFields.Count; i++)
  1266. {
  1267. var f = m_CurGBFields[i];
  1268. f.Move(offex_p);
  1269. }
  1270. Invalidate();
  1271. }
  1272. /// <summary>
  1273. /// 是否显示边框格线,自动切换显示与不显示
  1274. /// </summary>
  1275. /// <param name="b_show"></param>
  1276. public void ShowGridLine()
  1277. {
  1278. m_is_showgrid = !m_is_showgrid;
  1279. }
  1280. /// <summary>
  1281. /// 是否显示标尺控件
  1282. /// </summary>
  1283. /// <param name="b_show"></param>
  1284. public void ShowRulerControl()
  1285. {
  1286. control_Ruler1.Visible = !control_Ruler1.Visible;
  1287. }
  1288. /// <summary>
  1289. /// 是否显示边框格线,带参重载
  1290. /// </summary>
  1291. /// <param name="b_show"></param>
  1292. public void ShowGridLine(bool b_show)
  1293. {
  1294. m_is_showgrid = b_show;
  1295. }
  1296. /// <summary>
  1297. /// 是否显示标尺控件,带参重载
  1298. /// </summary>
  1299. /// <param name="b_show"></param>
  1300. public void ShowRulerControl(bool b_show)
  1301. {
  1302. control_Ruler1.Visible = b_show;
  1303. }
  1304. /// <summary>
  1305. /// 颗粒分割
  1306. /// </summary>
  1307. public void Particle_Segmentation()
  1308. {
  1309. m_ParticleSegmentation.IsParticleSegmentation = true;
  1310. m_ParticleSegmentation.StartPoint = new Point();
  1311. m_ParticleSegmentation.EndPoint = new Point();
  1312. }
  1313. /// <summary>
  1314. /// 是否进行矩形多选操作
  1315. /// </summary>
  1316. public void MultiSelect_Rectangle()
  1317. {
  1318. m_SelectTool.IsSelecting = true;
  1319. m_SelectTool.Shape = SelectedShape.Rectangle;
  1320. m_SelectTool.Rect = new RectangleF();
  1321. m_SelectTool.Rect.Width = 0;
  1322. m_SelectTool.Rect.Height = 0;
  1323. }
  1324. /// <summary>
  1325. /// 是否进行圆形多选操作
  1326. /// </summary>
  1327. public void MultiSelect_Ellipse()
  1328. {
  1329. m_SelectTool.IsSelecting = true;
  1330. m_SelectTool.Shape = SelectedShape.Ellipse;
  1331. m_SelectTool.Rect = new RectangleF();
  1332. m_SelectTool.Rect.Width = 0;
  1333. m_SelectTool.Rect.Height = 0;
  1334. }
  1335. /// <summary>
  1336. /// 对选择的多边形进行反选操作
  1337. /// </summary>
  1338. public void ReverseSelection()
  1339. {
  1340. foreach (DisplayParticle dp in m_list_allDPart)
  1341. {
  1342. if (dp.IsSelect)
  1343. {
  1344. dp.IsSelect = false;
  1345. }
  1346. else
  1347. {
  1348. dp.IsSelect = true;
  1349. }
  1350. }
  1351. this.Invalidate();
  1352. }
  1353. /// <summary>
  1354. /// 取消所有的颗粒的选择状态
  1355. /// </summary>
  1356. public void DeselectAllParticle()
  1357. {
  1358. foreach (DisplayParticle dp in m_list_allDPart)
  1359. {
  1360. dp.IsSelect = false;
  1361. }
  1362. this.Invalidate();
  1363. }
  1364. /// <summary>
  1365. /// 将整个图像拷贝到内存中
  1366. /// </summary>
  1367. public void CopyToBitmap()
  1368. {
  1369. Bitmap bp = new Bitmap(this.Size.Width, this.Size.Height);
  1370. this.DrawToBitmap(bp, new Rectangle(0, 0, this.Size.Width, this.Size.Height));
  1371. Clipboard.SetImage(bp);
  1372. }
  1373. /// <summary>
  1374. /// 设置显示BSE原图,还是显示分布图带有标准库的
  1375. /// </summary>
  1376. public void SetShowMode(DISTRIBUTION_IMAGE_SHOW_MODE a_type)
  1377. {
  1378. showMode = a_type;
  1379. this.Invalidate();
  1380. }
  1381. /// <summary>
  1382. /// 根据传入的颗粒状态,来获取所有该颗粒状态下的数据,用来测试统计使用
  1383. /// </summary>
  1384. /// <param name="str_particlestate"></param>
  1385. /// <returns></returns>
  1386. public int GetParticleNumberByState(PaintState in_ParticleState)
  1387. {
  1388. int icount = 0;
  1389. foreach (DisplayParticle ls_dp in m_list_allDPart)
  1390. {
  1391. if (ls_dp.GetPaintState() == in_ParticleState)
  1392. {
  1393. icount++;
  1394. }
  1395. }
  1396. return icount;
  1397. }
  1398. /// <summary>
  1399. /// 获取所有原图
  1400. /// </summary>
  1401. /// <param name="args"></param>
  1402. /// <returns></returns>
  1403. private void DrawOriginalImageAsBackground(PaintEventArgs args)
  1404. {
  1405. foreach (var f in m_list_allDfield)
  1406. {
  1407. var curfldrec = f.GetShowRect();
  1408. if (curfldrec.Left > -2000 && curfldrec.Right < this.Width + 2000 && curfldrec.Top > -2000 && curfldrec.Bottom < this.Height + 2000)
  1409. {
  1410. args.Graphics.DrawImage(f.OriginalImage, curfldrec.X, curfldrec.Y, curfldrec.Width, curfldrec.Height);
  1411. if (curfldrec.Width > this.Width)// only when zoom to a certain magnification do we display the xray Positon point as "+"
  1412. {
  1413. Graphics g = args.Graphics;
  1414. for (int i = 0; i < f.List_DParticle.Count; i++)
  1415. {
  1416. PointF xrayPos = new PointF(f.List_DParticle[i].objParticleData.PosX, f.List_DParticle[i].objParticleData.PosY);
  1417. PointF p = new PointF(xrayPos.X / f.OriginalImage.Width * curfldrec.Width + curfldrec.X, xrayPos.Y / f.OriginalImage.Height * curfldrec.Height + curfldrec.Y);
  1418. g.DrawString("+", new Font("黑体", 6), new SolidBrush(Color.Red), p);
  1419. }
  1420. }
  1421. }
  1422. }
  1423. }
  1424. #endregion
  1425. private void ExportoriginalspliceToolStripMenuItem_Click(object sender, EventArgs e)
  1426. {
  1427. SaveFileDialog sfd = new SaveFileDialog();
  1428. var particledata = new ParticleData(resultFile.FilePath);
  1429. DataTable ParticleAll = particledata.GetParticleTypeInformation();
  1430. DataTable ParticleClass = particledata.GetParticleClassAll();
  1431. //|ALL Files(*.*)|*.*
  1432. //BMP Files(*.bmp)| *.bmp |
  1433. sfd.Filter = "png Files(*.png)| *.png |BMP Files(*.bmp)| *.bmp |JPG Files(*.jpg)|*.jpg;*.jpeg";
  1434. if (sfd.ShowDialog() == DialogResult.OK)
  1435. {
  1436. this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
  1437. OutPIC outpic = new OutPIC();
  1438. outpic.m_list_allDfield = m_list_allDfield;
  1439. outpic.resultFile = resultFile;
  1440. outpic.sfd = sfd;
  1441. outpic.type = (int)Outpic_enum.Render_pic;
  1442. outpic.ParticleData = ParticleAll.Copy();
  1443. outpic.ParticleClassData = ParticleClass.Copy();
  1444. outpic.m_ReportApp = m_ReportApp;
  1445. Thread bThread = new Thread(new ThreadStart(outpic.opencv_outpic));
  1446. bThread.IsBackground = true;
  1447. bThread.Start();
  1448. }
  1449. }
  1450. private void ToolStripMenuItemDelete_Particle_Click(object sender, EventArgs e)
  1451. {
  1452. DialogResult dr = MessageBox.Show("Remove all these particles permanently?", "Tips", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  1453. if (dr == DialogResult.OK)
  1454. {
  1455. foreach (var p in m_list_allDPart)
  1456. {
  1457. if (p.IsSelect)
  1458. {
  1459. DeleteParticlesFromLibrary(p.objParticleData.ParticleId, p.objParticleData.FieldId);
  1460. p.IsDeleted = true;
  1461. }
  1462. }
  1463. MessageBox.Show("Deleted successfully");
  1464. Invalidate();
  1465. }
  1466. else
  1467. {
  1468. return;
  1469. }
  1470. }
  1471. public void DeletesParticlesSynchronously(List<Particle> list_Part)
  1472. {
  1473. foreach (var p in m_list_allDPart)
  1474. {
  1475. foreach (var p_Selected in list_Part)
  1476. {
  1477. if (p.ParticleId == p_Selected.ParticleId && p.FieldId == p_Selected.FieldId)
  1478. {
  1479. p.IsDeleted = true;
  1480. break;
  1481. }
  1482. }
  1483. }
  1484. Invalidate();
  1485. }
  1486. private bool DeleteParticlesFromLibrary(int in_clr_tagid, int in_clr_fieldid)
  1487. {
  1488. bool DoesItExist = false;
  1489. for (int i = 1; i < 201; i++)
  1490. {
  1491. if (System.IO.Directory.Exists(resultFile.FilePath + "\\FIELD_FILES\\Backups" + i.ToString()))
  1492. {
  1493. DoesItExist = true;
  1494. break;
  1495. }
  1496. }
  1497. if (!DoesItExist)
  1498. {
  1499. //备份数据库 ,.
  1500. BackupDatabase();
  1501. }
  1502. DoesItExist = false;
  1503. //防止为空校验判断
  1504. if (resultFile.List_OTSField == null)
  1505. return false;
  1506. Particle particle = resultFile.List_OTSField.Find(x => x.FieldID == in_clr_fieldid).ParticleList.Find(x => x.ParticleId == in_clr_tagid);
  1507. if (new ParticleData(resultFile.FilePath).DeleteFromData(Convert.ToString(particle.FieldId), Convert.ToString(particle.XrayId)))
  1508. {
  1509. return true;
  1510. }
  1511. else
  1512. {
  1513. return false;
  1514. }
  1515. }
  1516. public bool WhetherThereAreDeleteParticles()
  1517. {
  1518. foreach (var p in m_list_allDPart)
  1519. {
  1520. if (p.IsDeleted)
  1521. {
  1522. return true;
  1523. }
  1524. }
  1525. return false;
  1526. }
  1527. private bool BackupDatabase()
  1528. {
  1529. //创建备份数据库文件夹
  1530. string sourcePath = resultFile.FilePath + "\\FIELD_FILES\\Inclusion.db";//源文件路径
  1531. string sourceName = "Inclusion.db";//源文件名称
  1532. string folderPath = resultFile.FilePath + "\\FIELD_FILES\\Backups";//目标文件夹
  1533. string Fields = "";
  1534. for (int i = 1; i < 201; i++)
  1535. {
  1536. if (System.IO.Directory.Exists(folderPath + i.ToString()))
  1537. {
  1538. Fields = folderPath + i.ToString();
  1539. continue;
  1540. }
  1541. else
  1542. {
  1543. System.IO.Directory.CreateDirectory(folderPath + i.ToString());
  1544. Fields = folderPath + i.ToString();
  1545. break;
  1546. }
  1547. }
  1548. if (Fields == "")
  1549. {
  1550. return false;
  1551. }
  1552. //复制数据库文件
  1553. string targetPath = Path.Combine(Fields, sourceName);
  1554. FileInfo file = new FileInfo(sourcePath);
  1555. if (file.Exists)
  1556. {
  1557. file.CopyTo(targetPath, true);
  1558. }
  1559. return true;
  1560. }
  1561. int GetsIntersectionOfTheIntercepts(Point P1, Point P2, int y)
  1562. {
  1563. int x = (y - P1.Y * P2.X + P1.X * P2.Y) / (P2.Y - P1.Y);
  1564. return x;
  1565. }
  1566. private void ImportSTDDb_Click(object sender, EventArgs e)
  1567. {
  1568. //Dictionary<string, object> sampleMembers = ((Dictionary<string, object>)((Dictionary<string, object>)resultFile.ResultInfo["Sample"])["Members"]);
  1569. string STDName = resultFile.GetSTDName();
  1570. string ResultDbPath = resultFile.GetResultDBPath();
  1571. if (STDName.ToLower().Split('.')[0] == "nostddb")
  1572. {
  1573. OpenFileDialog openFileDialog = new OpenFileDialog();
  1574. openFileDialog.Filter = "(*.db)|*.db";
  1575. openFileDialog.RestoreDirectory = true;
  1576. openFileDialog.FilterIndex = 1;
  1577. openFileDialog.Title = "Please choose a STD to add the rule!";
  1578. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1579. {
  1580. try
  1581. {
  1582. string arguments = openFileDialog.FileName;
  1583. foreach (DisplayParticle item in m_list_allDPart)
  1584. {
  1585. DisplayParticle dp = item;
  1586. if (imageDisHelper.WhetherInRange(dp, m_mouse_now_point))
  1587. {
  1588. arguments += " " + ResultDbPath + " " + dp.FieldId + " " + dp.ParticleId + " " + dp.XRayId;
  1589. break;
  1590. }
  1591. }
  1592. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSPartA_STDEditor.exe", arguments);
  1593. p.WaitForExit();
  1594. }
  1595. catch (Exception ex)
  1596. {
  1597. log.Error("OTSPartA_STDEditor:" + ex.ToString());
  1598. }
  1599. }
  1600. }
  1601. else
  1602. {
  1603. string arguments = ".\\Config\\SysData\\" + STDName.Split('.')[0] + ".db";
  1604. foreach (DisplayParticle item in m_list_allDPart)
  1605. {
  1606. DisplayParticle dp = item;
  1607. if (imageDisHelper.WhetherInRange(dp, m_mouse_now_point))
  1608. {
  1609. arguments += " " + ResultDbPath + " " + dp.FieldId + " " + dp.ParticleId + " " + dp.XRayId;
  1610. break;
  1611. }
  1612. }
  1613. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSPartA_STDEditor.exe", arguments);
  1614. p.WaitForExit();
  1615. }
  1616. }
  1617. private void 显示国标信息ToolStripMenuItem_Click(object sender, EventArgs e)
  1618. {
  1619. Cursor = Cursors.WaitCursor;
  1620. m_CurGBFields.Clear();
  1621. int index = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
  1622. for (int i = 0; i < m_ReportApp.m_rstDataMgr.ResultFilesList.Count; i++)
  1623. {
  1624. string anothername = m_ReportApp.m_rstDataMgr.ResultFilesList[i].anotherFileName.ToString();
  1625. string resultfile = m_ReportApp.m_rstDataMgr.ResultFilesList[i].FilePath.ToString() + "\\" + m_ReportApp.m_rstDataMgr.ResultFilesList[i].FileName_real.ToString();
  1626. m_ReportApp.m_rstDataMgr.m_ReportMgr.AddASmplMsrResultMgr(resultfile, anothername);
  1627. }
  1628. OTSCLRINTERFACE.CPropParamClr clr_prop = m_ReportApp.m_rstDataMgr.m_ReportMgr.GetPropertyParamTable();
  1629. List<string> datasourcelist = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListByItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
  1630. clr_prop.SetDataSourceList(datasourcelist);
  1631. clr_prop.SetDataSourceId(index);//
  1632. clr_prop.SetType((int)DisplayPicutureType.AnalyzeDataTable);//table
  1633. DataTable tbl;//
  1634. var menuItm = (ToolStripMenuItem)sender;
  1635. string tag = menuItm.Tag.ToString();
  1636. switch (tag)
  1637. {
  1638. case "All1":
  1639. clr_prop.SetCalTableType((int)CALCULATE_TABLE_TYPE.GB_Method1);
  1640. tbl = m_ReportApp.m_rstDataMgr.m_ReportMgr.GetAllGBFields(clr_prop);
  1641. break;
  1642. case "DS1":
  1643. clr_prop.SetCalTableType((int)CALCULATE_TABLE_TYPE.GB_Method1);
  1644. tbl = m_ReportApp.m_rstDataMgr.m_ReportMgr.GetGBDSParticles(clr_prop);
  1645. break;
  1646. case "All2":
  1647. clr_prop.SetCalTableType((int)CALCULATE_TABLE_TYPE.GB_Method2);
  1648. tbl = m_ReportApp.m_rstDataMgr.m_ReportMgr.GetAllGBFields(clr_prop);
  1649. break;
  1650. case "DS2":
  1651. clr_prop.SetCalTableType((int)CALCULATE_TABLE_TYPE.GB_Method2);
  1652. tbl = m_ReportApp.m_rstDataMgr.m_ReportMgr.GetGBDSParticles(clr_prop);
  1653. break;
  1654. case "ASTMAll":
  1655. clr_prop.SetCalTableType((int)CALCULATE_TABLE_TYPE.ASTM);
  1656. tbl = m_ReportApp.m_rstDataMgr.m_ReportMgr.GetAllGBFields(clr_prop);
  1657. break;
  1658. default:
  1659. tbl = new DataTable();
  1660. break;
  1661. }
  1662. if (tag == "All1" || tag == "All2" || tag == "ASTMAll")
  1663. {
  1664. if (tbl.Rows.Count > 0)
  1665. {
  1666. foreach (DataRow r in tbl.Rows)
  1667. {
  1668. Point p = new Point(Convert.ToInt32(r["fieldX"]), Convert.ToInt32(r["fieldY"]));
  1669. Point screenP = imageDisHelper.ConvertOTSCoordToScreenCoord(p);
  1670. int gbfldwidth = Convert.ToInt32(710.0 / imageDisHelper.m_pixelSize);
  1671. var df = new DisplayField(gbfldwidth, gbfldwidth, p, screenP);
  1672. df.Zoom(m_zoom_record - 1, new PointF(0, 0));
  1673. df.Move(new SizeF(-m_backRect.X, -m_backRect.Y));
  1674. int topgrade = Convert.ToInt32(r["topGrade"]);
  1675. switch (topgrade)
  1676. {
  1677. case 0:
  1678. df.ContentColor = Color.White;
  1679. break;
  1680. case 1:
  1681. df.ContentColor = Color.DarkGray;
  1682. break;
  1683. case 2:
  1684. df.ContentColor = Color.Purple;
  1685. break;
  1686. case 3:
  1687. df.ContentColor = Color.Blue;
  1688. break;
  1689. case 4:
  1690. df.ContentColor = Color.Red;
  1691. break;
  1692. case 5:
  1693. df.ContentColor = Color.Red;
  1694. break;
  1695. default:
  1696. df.ContentColor = Color.Red;
  1697. break;
  1698. }
  1699. string grade = r["gradeDetail"].ToString();
  1700. df.gradeString = grade;
  1701. m_CurGBFields.Add(df);
  1702. }
  1703. }
  1704. }
  1705. else if (tag == "DS1" || tag == "DS2")
  1706. {
  1707. if (tbl.Rows.Count > 0)
  1708. {
  1709. foreach (DataRow r in tbl.Rows)
  1710. {
  1711. int fid = Convert.ToInt32(r["fieldId"]);
  1712. int pid = Convert.ToInt32(r["particleId"]);
  1713. foreach (var p in m_list_allDPart)
  1714. {
  1715. if (p.objParticleData.FieldId == fid && p.objParticleData.ParticleId == pid)
  1716. {
  1717. p.IsSelect = true;
  1718. break;
  1719. }
  1720. }
  1721. }
  1722. }
  1723. }
  1724. Cursor = Cursors.Default;
  1725. Invalidate();
  1726. }
  1727. private void 清除ToolStripMenuItem_Click(object sender, EventArgs e)
  1728. {
  1729. m_CurGBFields.Clear();
  1730. Invalidate();
  1731. }
  1732. private void ToolStripMenuItem_ParticleSplicing_Click(object sender, EventArgs e)
  1733. {
  1734. SaveFileDialog sfd = new SaveFileDialog();
  1735. sfd.Filter = "png Files(*.png)| *.png |BMP Files(*.bmp)| *.bmp |JPG Files(*.jpg)|*.jpg;*.jpeg";
  1736. if (sfd.ShowDialog() == DialogResult.OK)
  1737. {
  1738. this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
  1739. OutPIC outpic = new OutPIC();
  1740. outpic.m_list_allDfield = m_list_allDfield;
  1741. outpic.resultFile = resultFile;
  1742. outpic.sfd = sfd;
  1743. outpic.type = (int)Outpic_enum.noBackground_pic;
  1744. outpic.m_ReportApp = m_ReportApp;
  1745. Thread bThread = new Thread(new ThreadStart(outpic.opencv_outpic));
  1746. bThread.IsBackground = true;
  1747. bThread.Start();
  1748. }
  1749. }
  1750. protected override bool ProcessDialogKey(Keys keyData)
  1751. {
  1752. if (keyData == Keys.Escape)
  1753. {
  1754. DeselectAllParticle();
  1755. frmReportApp.selectedParticles.Clear();
  1756. return false;
  1757. }
  1758. return base.ProcessDialogKey(keyData);
  1759. }
  1760. private void toolStripMenuItem_Segmentation_Click(object sender, EventArgs e)
  1761. {
  1762. Particle_Segmentation();
  1763. }
  1764. private void toolStripMenuItem_combinClass_Click(object sender, EventArgs e)
  1765. {
  1766. SaveFileDialog sfd = new SaveFileDialog();
  1767. //|ALL Files(*.*)|*.*
  1768. //BMP Files(*.bmp)| *.bmp |
  1769. sfd.Filter = "png Files(*.png)| *.png |BMP Files(*.bmp)| *.bmp |JPG Files(*.jpg)|*.jpg;*.jpeg";
  1770. if (sfd.ShowDialog() == DialogResult.OK)
  1771. {
  1772. OutPIC outpic = new OutPIC();
  1773. outpic.m_list_allDfield = m_list_allDfield;
  1774. outpic.resultFile = resultFile;
  1775. outpic.sfd = sfd;
  1776. outpic.type = (int)Outpic_enum.Render_Combin;
  1777. Thread bThread = new Thread(new ThreadStart(outpic.opencv_outpic2));
  1778. bThread.IsBackground = true;
  1779. bThread.Start();
  1780. }
  1781. }
  1782. private void toolStripMenuItem_combin_Click(object sender, EventArgs e)
  1783. {
  1784. SaveFileDialog sfd = new SaveFileDialog();
  1785. //|ALL Files(*.*)|*.*
  1786. //BMP Files(*.bmp)| *.bmp |
  1787. sfd.Filter = "png Files(*.png)| *.png |BMP Files(*.bmp)| *.bmp |JPG Files(*.jpg)|*.jpg;*.jpeg";
  1788. if (sfd.ShowDialog() == DialogResult.OK)
  1789. {
  1790. OutPIC outpic = new OutPIC();
  1791. outpic.m_list_allDfield = m_list_allDfield;
  1792. outpic.resultFile = resultFile;
  1793. outpic.sfd = sfd;
  1794. outpic.type = (int)Outpic_enum.Combin;
  1795. Thread bThread = new Thread(new ThreadStart(outpic.opencv_outpic2));
  1796. bThread.IsBackground = true;
  1797. bThread.Start();
  1798. }
  1799. }
  1800. private void 显示当前帧国标分类ToolStripMenuItem_Click(object sender, EventArgs e)
  1801. {
  1802. }
  1803. DataTable GetAllPartsOfCurrentGBField()
  1804. {
  1805. DataTable tbl;//
  1806. if (m_CurGBFields.Count == 0)
  1807. {
  1808. return new DataTable();
  1809. }
  1810. int index = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
  1811. OTSCLRINTERFACE.CPropParamClr clr_prop = m_ReportApp.m_rstDataMgr.m_ReportMgr.GetPropertyParamTable();
  1812. List<string> datasourcelist = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListByItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
  1813. clr_prop.SetDataSourceList(datasourcelist);
  1814. clr_prop.SetDataSourceId(index);//
  1815. clr_prop.SetType((int)DisplayPicutureType.AnalyzeDataTable);//table
  1816. DisplayField curfld = new DisplayField(1024,768,new Point(0,0),new Point(0,0));
  1817. foreach (var f in m_CurGBFields)
  1818. {
  1819. if (imageDisHelper.WhetherInRange(f, m_currentMouseDownPoint))
  1820. {
  1821. curfld = f;
  1822. }
  1823. }
  1824. clr_prop.SetCalTableType((int)CALCULATE_TABLE_TYPE.GB_Method1);
  1825. tbl = m_ReportApp.m_rstDataMgr.m_ReportMgr.GetAllParticlesOfOneGBField(clr_prop, curfld.OTSCoordinatePos.X, curfld.OTSCoordinatePos.Y);
  1826. return tbl;
  1827. }
  1828. private void 全部ToolStripMenuItem_Click(object sender, EventArgs e)
  1829. {
  1830. Cursor = Cursors.WaitCursor;
  1831. //m_CurGBFields.Clear();
  1832. var tbl = GetAllPartsOfCurrentGBField();
  1833. if (tbl.Rows.Count > 0)
  1834. {
  1835. foreach (DataRow r in tbl.Rows)
  1836. {
  1837. int fid = Convert.ToInt32(r["fieldId"]);
  1838. int pid = Convert.ToInt32(r["particleId"]);
  1839. foreach (var p in m_list_allDPart)
  1840. {
  1841. if (p.objParticleData.FieldId == fid && p.objParticleData.ParticleId == pid)
  1842. {
  1843. p.IsSelect = true;
  1844. break;
  1845. }
  1846. }
  1847. }
  1848. }
  1849. Cursor = Cursors.Default;
  1850. Invalidate();
  1851. }
  1852. private void aToolStripMenuItem_Click(object sender, EventArgs e)
  1853. {
  1854. Cursor = Cursors.WaitCursor;
  1855. var tbl = GetAllPartsOfCurrentGBField();
  1856. if (tbl.Rows.Count > 0)
  1857. {
  1858. foreach (DataRow r in tbl.Rows)
  1859. {
  1860. int fid = Convert.ToInt32(r["fieldId"]);
  1861. int pid = Convert.ToInt32(r["particleId"]);
  1862. var typestr =Convert.ToString( r["gbClassify"]);
  1863. if (typestr == "A")
  1864. {
  1865. foreach (var p in m_list_allDPart)
  1866. {
  1867. if (p.objParticleData.FieldId == fid && p.objParticleData.ParticleId == pid)
  1868. {
  1869. p.IsSelect = true;
  1870. break;
  1871. }
  1872. }
  1873. }
  1874. }
  1875. }
  1876. Cursor = Cursors.Default;
  1877. Invalidate();
  1878. }
  1879. private void bToolStripMenuItem_Click(object sender, EventArgs e)
  1880. {
  1881. Cursor = Cursors.WaitCursor;
  1882. var tbl = GetAllPartsOfCurrentGBField();
  1883. if (tbl.Rows.Count > 0)
  1884. {
  1885. foreach (DataRow r in tbl.Rows)
  1886. {
  1887. int fid = Convert.ToInt32(r["fieldId"]);
  1888. int pid = Convert.ToInt32(r["particleId"]);
  1889. var typestr = Convert.ToString(r["gbClassify"]);
  1890. if (typestr == "B")
  1891. {
  1892. foreach (var p in m_list_allDPart)
  1893. {
  1894. if (p.objParticleData.FieldId == fid && p.objParticleData.ParticleId == pid)
  1895. {
  1896. p.IsSelect = true;
  1897. break;
  1898. }
  1899. }
  1900. }
  1901. }
  1902. }
  1903. Cursor = Cursors.Default;
  1904. Invalidate();
  1905. }
  1906. private void cToolStripMenuItem_Click(object sender, EventArgs e)
  1907. {
  1908. Cursor = Cursors.WaitCursor;
  1909. var tbl = GetAllPartsOfCurrentGBField();
  1910. if (tbl.Rows.Count > 0)
  1911. {
  1912. foreach (DataRow r in tbl.Rows)
  1913. {
  1914. int fid = Convert.ToInt32(r["fieldId"]);
  1915. int pid = Convert.ToInt32(r["particleId"]);
  1916. var typestr = Convert.ToString(r["gbClassify"]);
  1917. if (typestr == "C")
  1918. {
  1919. foreach (var p in m_list_allDPart)
  1920. {
  1921. if (p.objParticleData.FieldId == fid && p.objParticleData.ParticleId == pid)
  1922. {
  1923. p.IsSelect = true;
  1924. break;
  1925. }
  1926. }
  1927. }
  1928. }
  1929. }
  1930. Cursor = Cursors.Default;
  1931. Invalidate();
  1932. }
  1933. private void dToolStripMenuItem_Click(object sender, EventArgs e)
  1934. {
  1935. Cursor = Cursors.WaitCursor;
  1936. var tbl = GetAllPartsOfCurrentGBField();
  1937. if (tbl.Rows.Count > 0)
  1938. {
  1939. foreach (DataRow r in tbl.Rows)
  1940. {
  1941. int fid = Convert.ToInt32(r["fieldId"]);
  1942. int pid = Convert.ToInt32(r["particleId"]);
  1943. var typestr = Convert.ToString(r["gbClassify"]);
  1944. if (typestr == "D")
  1945. {
  1946. foreach (var p in m_list_allDPart)
  1947. {
  1948. if (p.objParticleData.FieldId == fid && p.objParticleData.ParticleId == pid)
  1949. {
  1950. p.IsSelect = true;
  1951. break;
  1952. }
  1953. }
  1954. }
  1955. }
  1956. }
  1957. Cursor = Cursors.Default;
  1958. Invalidate();
  1959. }
  1960. }
  1961. }