Control_DrawDistrbutionImageAndBSE.cs 101 KB

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