Control_DrawDistrbutionImageAndBSE.cs 101 KB

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