Control_DrawDistrbutionImageAndBSE.cs 102 KB

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