Control_DrawDistrbutionImageAndBSE.cs 102 KB

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