Control_DrawDistrbutionImageAndBSE.cs 94 KB

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