Control_DrawDistrbutionImageAndBSE.cs 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083
  1. using NLog;
  2. using OTSIncAReportApp;
  3. using OTSIncAReportApp._3_ServiceCenter;
  4. using OTSIncAReportApp.DataOperation.DataAccess;
  5. using OTSIncAReportApp.DataOperation.Model;
  6. using OTSIncAReportApp.OTSSampleReportInfo;
  7. using OTSIncAReportApp.SysMgrTools;
  8. using OTSIncAReportGraph.Class;
  9. using OTSIncAReportGraph.OTSIncAReportGraphFuncation;
  10. using OTSIncAReportMailInterface;
  11. using OTSRptPeriodicTable;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Data;
  15. using System.Diagnostics;
  16. using System.Drawing;
  17. using System.Drawing.Drawing2D;
  18. using System.IO;
  19. using System.Linq;
  20. using System.Threading;
  21. using System.Windows.Forms;
  22. using System.Windows.Media.Imaging;
  23. using System.Xml;
  24. namespace OTSIncAReportGraph.Controls
  25. {
  26. public enum SelectedShape
  27. {
  28. Rectangle=0,
  29. Ellipse = 1
  30. }
  31. public struct SelectTool
  32. {
  33. public SelectedShape Shape;
  34. public Point StartPoint;
  35. public bool IsSelecting;
  36. //进行选择的矩形范围
  37. public RectangleF Rect ;
  38. }
  39. public enum RightButtonMenu
  40. {
  41. Include=0,
  42. MoveSEMToParticle=1,
  43. CopyImage=2,
  44. OriginalSplicing= 3,
  45. DeleteParticle=4,
  46. CopyDatabase=5
  47. }
  48. /// <summary>
  49. /// 选择导出的图片是原图还是颗粒渲染后的图片
  50. /// </summary>
  51. public enum Outpic_enum
  52. {
  53. pic=0,
  54. Render_pic=1
  55. }
  56. public partial class Control_DrawDistrbutionImageAndBSE : UserControl
  57. {
  58. //缩放的增大缩小的增量
  59. private const float const_zoom_increment = 0.05f;
  60. //最大缩放倍数
  61. private const float m_f_zoom_max = 4f;
  62. //最小缩放倍数
  63. private float m_f_zoom_mix = 0.05f;
  64. //标尺原先大小的记录,参与计算
  65. private const float m_f_old_ruler_size = 100;
  66. //int m_operator_currentid;
  67. double ls_d_cz_width;
  68. double ls_d_cz_height;
  69. #region 变量定义
  70. private SelectTool m_SelectTool;
  71. //缩放的基数,临时变量
  72. private float m_Zoom_Base = 0;
  73. //与原先缩放的记录数
  74. private float m_zoom_record = 1;
  75. //标尺的大小记录
  76. public float m_f_ruler_size = 100;
  77. //每像素代表的尺寸大小,还不知道在哪里进行计算
  78. public float m_pixelSize = 4.5f;
  79. //国际化存储信息
  80. System.Collections.Hashtable table;
  81. //包含particle的field的列表对象
  82. public List<DisplayField> m_list_allDfield = null;
  83. //这里要做成控件,不要是窗体
  84. public List<BaseObject> m_list_allDPart = null;
  85. //总背景矩形
  86. public RectangleF m_backRect = new RectangleF();
  87. //记录原值,总背景矩形
  88. public RectangleF m_old_backRect = new RectangleF();
  89. //记录总物理矩形总大小
  90. public RectangleF m_back_wl_rectf = new RectangleF();
  91. //是否显示网格线
  92. private bool m_is_showgrid = false;
  93. //绘制的网格中,需要几条线,宽
  94. public double m_i_grid_showlinesnumber_width = 0;
  95. //绘制的网格中,需要几条线,高
  96. public double m_i_grid_showlinesnumber_height = 0;
  97. //是否拖动
  98. private bool m_isDrag = false;
  99. //拖动前的坐标记录
  100. private PointF m_beforedrag_pointf = new PointF();
  101. //提供鼠标在右下角显示的文本,左侧
  102. private string m_str_mouseshow_left = "";
  103. //提供鼠标在右下角显示的文本,右侧
  104. private string m_str_mouseshow_right = "";
  105. //整个背景矩形的背景色
  106. private Color m_backrangecolor = Color.White;
  107. OTSImageDisHelp m_ReportFun = null;
  108. //当前鼠标的位置
  109. Point m_mouse_now_point = new Point();
  110. //记录当前鼠标位置对应SEM电镜的位置
  111. Point m_sem_mouse_now_point = new Point();
  112. //鼠标移动经过的颗粒对象,临时存放,用来记录是否要显示xray与隐藏xray
  113. DisplayParticle m_mouseOver_dparticle = null;
  114. //保存数据源名称
  115. private string m_showsourcename = "";
  116. //保存当前数据源的ID
  117. private int m_datasourceid = 0;
  118. //移动SEM到指定位置发生线程
  119. private Thread m_mythread;
  120. //记录线程是否已经运行完成的状态
  121. //private bool m_mythread_state = false;
  122. private Color m_ColorNotContent = Color.SkyBlue;
  123. //读取背景原图的名称和图片
  124. private Dictionary<string, Image> originalImages = new Dictionary<string, Image>();
  125. //private List<string> originalImageNames = new List<string>();
  126. //背景使用原图
  127. private bool OriginalBackground = false;
  128. static System.Windows.Forms.Timer delaytimer = new System.Windows.Forms.Timer();
  129. Logger log;
  130. /// <summary>
  131. /// 当前正在显示的数据源名称,用来与框架调用条件判断使用
  132. /// </summary>
  133. public string ShowSourceName
  134. {
  135. set { m_showsourcename = value; }
  136. get { return m_showsourcename; }
  137. }
  138. /// <summary>
  139. /// 当前正在显示的数据源的ID
  140. /// </summary>
  141. public int DataSourceID
  142. {
  143. set { m_datasourceid = value; }
  144. get { return m_datasourceid; }
  145. }
  146. /// <summary>
  147. /// 背景矩形属性
  148. /// </summary>
  149. public RectangleF BackRectF
  150. {
  151. set { m_backRect = value; }
  152. get { return m_backRect; }
  153. }
  154. public OTSImageDisHelp ReportFun { get => m_ReportFun; set => m_ReportFun = value; }
  155. //测试用隐藏颗粒的id号,回头去掉
  156. public int test_hide_particle_tagid = 1000;
  157. //进度条窗体
  158. public Frm_UserProgress m_frm_userprogress;
  159. /// <summary>
  160. /// 是否显示过小颗粒
  161. /// </summary>
  162. public bool bShowSmallParticle = false;
  163. OTSIncAReportApp.frmReportApp m_ReportApp;
  164. ResultFile resultFile = null;
  165. #endregion
  166. #region 构造函数及窗体加载
  167. public Control_DrawDistrbutionImageAndBSE(OTSIncAReportApp.frmReportApp ReportApp)
  168. {
  169. log = NLog.LogManager.GetCurrentClassLogger();
  170. m_list_allDfield = new List<DisplayField>();
  171. m_list_allDPart = new List<BaseObject>();
  172. m_frm_userprogress = new Frm_UserProgress();
  173. //m_mythread_state = false;
  174. m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
  175. m_ReportApp = ReportApp;
  176. resultFile = m_ReportApp.m_rstDataMgr.CurResultFile;
  177. //初始化底层操作类
  178. ReportFun = new OTSImageDisHelp(resultFile);
  179. InitializeComponent();
  180. #region 国际化语言
  181. Language lan = new Language(this);
  182. table = lan.GetNameTable(this.Name);
  183. #endregion
  184. //load the userdefine control dynamically
  185. System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Control_DrawDistrbutionImageAndBSE));
  186. this.control_XRayTable1 = new Control_XRayTable();
  187. this.control_XRayTable1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
  188. this.control_XRayTable1.Dock = System.Windows.Forms.DockStyle.Bottom;
  189. this.control_XRayTable1.GBInfoStr = "";
  190. this.control_XRayTable1.GoodChineseName = "";
  191. this.control_XRayTable1.MaterialName = "";
  192. this.control_XRayTable1.List_ShowElementInfo = ((System.Collections.Generic.List<OTSIncAReportGraph.Controls.ShowElementInfo>)(resources.GetObject("control_XRayTable1.List_ShowElementInfo")));
  193. this.control_XRayTable1.Location = new System.Drawing.Point(0, 400);
  194. this.control_XRayTable1.Name = "control_XRayTable1";
  195. this.control_XRayTable1.ShowAnalysisXray = true;
  196. this.control_XRayTable1.ShowSearchXray = false;
  197. this.control_XRayTable1.Size = new System.Drawing.Size(1004, 200);
  198. this.control_XRayTable1.STDName = "";
  199. this.control_XRayTable1.TabIndex = 6;
  200. this.control_XRayTable1.Visible = false;
  201. //
  202. // control_Ruler1
  203. //
  204. this.control_Ruler1 = new Control_Ruler();
  205. this.control_Ruler1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(200)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
  206. this.control_Ruler1.Location = new System.Drawing.Point(3, 400);
  207. this.control_Ruler1.Name = "control_Ruler1";
  208. this.control_Ruler1.RulerWidth = 100;
  209. this.control_Ruler1.ShowString = "100um";
  210. this.control_Ruler1.Size = new System.Drawing.Size(120, 40);
  211. this.control_Ruler1.TabIndex = 8;
  212. this.control_Ruler1.Value = 0D;
  213. this.control_Ruler1.Visible = false;
  214. this.Controls.Add(this.control_XRayTable1);
  215. this.Controls.Add(this.control_Ruler1);
  216. }
  217. private void ProgressBarUpdate(int progress, string message)
  218. {
  219. //显示进度条,计算进度条应该显示的位置和宽度
  220. if (m_frm_userprogress.Visible == false)
  221. {
  222. Form ls_main_form = this.ParentForm.ParentForm;//取出父窗体
  223. m_frm_userprogress.Width = (int)(MyPrimaryScreen.DESKTOP.Width / MyPrimaryScreen.ScaleX * 0.9);
  224. m_frm_userprogress.Location = new Point(ls_main_form.Location.X + 80, ls_main_form.Location.Y + (int)(MyPrimaryScreen.DESKTOP.Height / MyPrimaryScreen.ScaleX) / 2);
  225. m_frm_userprogress.Show();
  226. }
  227. m_frm_userprogress.SetProgressValueAndText(progress, message);
  228. }
  229. private void LoadUpdateDisplay()
  230. {
  231. ProgressBarUpdate(0, table["str1"].ToString());
  232. //执行获取颗粒分布图数据,总过程函数
  233. GetDistrbutionImageAndBSE_Total();
  234. //设置双缓冲
  235. SetDoubleBufferByIsDraw();
  236. //设置标尺
  237. //根据f_onepixel_size计算出要显示出100um的实际宽度
  238. double d_onefixel_width = 100 / m_pixelSize;
  239. if (d_onefixel_width == 0)
  240. {
  241. this.control_Ruler1.Visible = false;
  242. }
  243. else
  244. {
  245. //将标尺定位到合理的位置上
  246. this.control_Ruler1.Location = new Point(10, MyPrimaryScreen.WorkingArea.Height - 300);
  247. this.control_Ruler1.Visible = true;
  248. this.control_Ruler1.SetValue(m_f_ruler_size, m_pixelSize);
  249. }
  250. ReportFun.m_original_list_baseobject.Clear();
  251. //记录原值,用于缩放计算操作 ,此处要用克隆 ,原particle颗粒的值,在底层调用时已经赋值过了
  252. foreach (DisplayParticle ls_dp in m_list_allDPart)
  253. {
  254. ls_dp.SetPaintState(PaintState.NORMALPAINT);
  255. DisplayParticle old_dp = ls_dp.Clone() as DisplayParticle;
  256. ReportFun.m_original_list_baseobject.Add(old_dp);
  257. }
  258. //加载时将背景rect设置与整个窗体一边大小
  259. m_old_backRect = m_backRect;
  260. ReportFun.m_original_list_dfield.Clear();
  261. ////赋值给old保存原值
  262. for (int i = 0; i < m_list_allDfield.Count; i++)
  263. {
  264. DisplayField df = new DisplayField(m_list_allDfield[i].List_DParticle);
  265. df.Show_Rect = new RectangleF(m_list_allDfield[i].Show_Rect.X,
  266. m_list_allDfield[i].Show_Rect.Y,
  267. m_list_allDfield[i].Show_Rect.Width,
  268. m_list_allDfield[i].Show_Rect.Height);
  269. ReportFun.m_original_list_dfield.Add(df);
  270. }
  271. ProgressBarUpdate(100, table["str2"].ToString());
  272. //加载完成,关闭进度条
  273. m_frm_userprogress.Visible = false;
  274. //m_frm_userprogress.Close();
  275. }
  276. private void Control_DrawDistrbutionImageAndBSE_Load(object sender, EventArgs e)
  277. {
  278. LoadUpdateDisplay();
  279. }
  280. /// <summary>
  281. /// 获取组整个获取分布图和排序图图像数据的底层数据组建方式,的总过程
  282. /// </summary>
  283. public void GetDistrbutionImageAndBSE_Total()
  284. {
  285. string str27 = "begin to loading data....";
  286. log.Info(str27);
  287. Application.DoEvents();
  288. ProgressBarUpdate(1, str27);
  289. List<Field> fieldlist = resultFile.List_OTSField;
  290. //防止有时底层返回的Field的List是0,直接返回
  291. if (fieldlist.Count == 0)
  292. {
  293. ProgressBarUpdate(100, "field number =0 !....");
  294. return;
  295. }
  296. string str29 = "begin to composit field picture....";
  297. log.Info(str29);
  298. Application.DoEvents();
  299. ProgressBarUpdate(15, str29);
  300. //第一次循环,用来计算单个Field的像素分辨率,和将所有的物理位置存放到List当中
  301. List<Point> list_point = new List<Point>();
  302. int fieldwidth = 0, fieldheight = 0;
  303. //获取到该field的分辨率大小,循环中都是一样的
  304. if (fieldlist.Count > 0)
  305. {
  306. Bitmap bitmp = DrawFunction.ReadImageFile(fieldlist[0].FieldImage);
  307. fieldwidth = bitmp.Width;
  308. fieldheight = bitmp.Height;
  309. }
  310. for (int i = 0; i < fieldlist.Count(); i++)
  311. {
  312. //然后取出物理坐标,这个一会要与分辨率坐标进行变算一下
  313. Point ls_point = new Point() { X = fieldlist[i].FieldPosX, Y = fieldlist[i].FieldPosY };
  314. list_point.Add(ls_point);
  315. }
  316. //计算出整个绘制图像总Rectagnle的大小
  317. m_backRect = ReportFun. ConvertAndGetMaxRect(list_point, fieldwidth, fieldheight);
  318. ProgressBarUpdate(18, "calculate ruler....");
  319. #region //标尺相关------------------------------------------------------------------------------
  320. RectangleF ls_jsblrect = ReportFun.GetPhysicalFieldWidthAndHeight(list_point,fieldwidth,fieldheight);
  321. //然后用宽度来除以i_field_width 获取单个的像素比例
  322. double d_onepixel_scale = Convert.ToDouble(ls_jsblrect.Width) / Convert.ToDouble(fieldwidth);
  323. //再用该比例对标尺进行相应的赋值
  324. m_pixelSize = (float)d_onepixel_scale;
  325. #endregion //---------------------------------------------------------------------------------------
  326. ProgressBarUpdate(20, "composit whole picture....");
  327. //70的进度条给到下面的循环中,计算进度条各分类进度分配
  328. float ls_int_progresscalc = 0;
  329. if (fieldlist.Count > 0)
  330. ls_int_progresscalc = (float)70 / (float)fieldlist.Count;
  331. string str32 = "finished ";
  332. string str33 = "total ";
  333. string str34 = "field...";
  334. var otsLeftBottomPoint = ReportFun.GetOTSCoordLeftBottomPoint(list_point);
  335. m_list_allDfield.Clear();
  336. m_list_allDPart.Clear();
  337. for (int i = 0; i < fieldlist.Count(); i++)
  338. {
  339. ProgressBarUpdate(20 + (int)(ls_int_progresscalc * (i + 1)), str32 + i.ToString() + str33 + resultFile.List_OTSField.Count.ToString() + str34);
  340. //取出该Field的物理坐标,将其转换成对应的屏幕像素坐标,屏幕左上角为原点(0,0)的偏移值,用于后面计算各Segment的位置使用
  341. Point thisfield_point = new Point() { X = fieldlist[i].FieldPosX, Y = fieldlist[i].FieldPosY };
  342. Point offset_point = ReportFun.ConvertOTSCoordinateToScreenCoord(otsLeftBottomPoint, m_pixelSize, thisfield_point, m_backRect, new RectangleF(0,0,fieldwidth,fieldheight));//the ots coordinate is always the up right positive.
  343. DisplayField df = new DisplayField(fieldlist[i],fieldwidth,fieldheight, offset_point);
  344. m_list_allDfield.Add(df);
  345. m_list_allDPart.AddRange(df.List_DParticle);
  346. }
  347. ProgressBarUpdate(90, "convert solution...");
  348. //然后这里还需要计算出,各field的宽和高,帧图边框分别需要显示多少个框
  349. if (fieldwidth != 0 && fieldheight != 0)
  350. {
  351. m_i_grid_showlinesnumber_width = Convert.ToInt32(BackRectF.Width / fieldwidth);
  352. m_i_grid_showlinesnumber_height = Convert.ToInt32(BackRectF.Height / fieldheight);
  353. }
  354. ProgressBarUpdate(95, "other work...");
  355. //相关计数
  356. ReportFun.m_field_count = fieldlist.Count;
  357. ReportFun.m_particle_count = m_list_allDPart.Count;
  358. }
  359. /// <summary>
  360. /// 分布图和BSE图中,从底层获取相关结果后,重新组织显示
  361. /// </summary>
  362. /// <param name="sourceGridData"></param>
  363. public void FilterParticleByOtherCondition(ReportCondition sourceGridData)
  364. {
  365. bool sizeconditionResult;
  366. bool stdIdconditionResult;
  367. string stdId = "";
  368. int stdIdIndex = 0;
  369. //find the stdId condition
  370. var STDIdItm = sourceGridData.ConditionItemList.Find(s => s.iItemId == OTS_REPORT_PROP_GRID_ITEMS.STD_ID);
  371. if (STDIdItm != null)
  372. {
  373. stdId = STDIdItm.itemDisplayVal.ToString();
  374. stdIdIndex = STDIdItm.comboDownList.IndexOf(stdId);
  375. }
  376. //find the size condition
  377. var size_cal_method_type = (SIZE_CAL_METHOD_TYPE)sourceGridData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE);
  378. var itm = sourceGridData.ConditionItemList.Find(s => s.iItemId == OTS_REPORT_PROP_GRID_ITEMS.GRAIN_SIZE_CLASS);
  379. string size = itm.itemDisplayVal.ToString();
  380. int index = itm.comboDownList.IndexOf(size);
  381. string min = "0";
  382. string max = "999";
  383. if (index > 0)
  384. {
  385. max = sourceGridData.ConditionItemList.Find(s => s.iItemId == OTS_REPORT_PROP_GRID_ITEMS.GRAIN_SIZE_MAX).itemDisplayVal.ToString();
  386. min = sourceGridData.ConditionItemList.Find(s => s.iItemId == OTS_REPORT_PROP_GRID_ITEMS.GRAIN_SIZE_MIN).itemDisplayVal.ToString();
  387. if (max.ToLower() == "max")
  388. {
  389. max = "999";
  390. }
  391. }
  392. double dia_min = Convert.ToDouble(min);
  393. double dia_max = Convert.ToDouble(max);
  394. foreach (DisplayParticle ls_dp in m_list_allDPart)
  395. {
  396. if (index > 0)
  397. {
  398. double diameter = 0;
  399. switch (size_cal_method_type)
  400. {
  401. case SIZE_CAL_METHOD_TYPE.DMAX:
  402. diameter = ls_dp.objParticleData.DMAX;
  403. break;
  404. case SIZE_CAL_METHOD_TYPE.DMIN:
  405. diameter = ls_dp.objParticleData.DMIN;
  406. break;
  407. case SIZE_CAL_METHOD_TYPE.CIRCLE:
  408. diameter = Math.Sqrt(ls_dp.objParticleData.Area / 3.14159f) * 2f;
  409. break;
  410. case SIZE_CAL_METHOD_TYPE.DFERET:
  411. diameter = ls_dp.objParticleData.DFERET;
  412. break;
  413. default:
  414. diameter = 0;
  415. break;
  416. }
  417. if (diameter >= dia_min && diameter <= dia_max)
  418. {
  419. sizeconditionResult = true;
  420. }
  421. else
  422. {
  423. sizeconditionResult = false;
  424. }
  425. }
  426. else
  427. {
  428. sizeconditionResult = true;
  429. }
  430. if (stdIdIndex > 0)// it's not "All"
  431. {
  432. if (ls_dp.objParticleData.TypeName != stdId)
  433. {
  434. stdIdconditionResult = false;
  435. }
  436. else
  437. {
  438. stdIdconditionResult = true;
  439. }
  440. }
  441. else
  442. {
  443. stdIdconditionResult = true;
  444. }
  445. if (stdIdconditionResult && sizeconditionResult)
  446. {
  447. ls_dp.SetDisplayState(DisplayState.DISPLAY);
  448. }
  449. else
  450. {
  451. ls_dp.SetDisplayState(DisplayState.NODISPLAY);
  452. }
  453. }
  454. }
  455. #endregion
  456. #region 设置双缓冲
  457. /// <summary>
  458. /// 设置双缓冲
  459. /// </summary>
  460. public void SetDoubleBufferByIsDraw()
  461. {
  462. SetStyle(ControlStyles.UserPaint, true); //没什么效果,开与关
  463. SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景,关了闪
  464. SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // 双缓冲,关了闪
  465. //上面是必须有的
  466. SetStyle(ControlStyles.UserMouse, true); //执行自己的鼠标行为,这个打开后,在win7下鼠标操作明显改善
  467. }
  468. #endregion
  469. #region 绘制函数
  470. protected override void OnPaint(PaintEventArgs e)//处理重绘情况
  471. {
  472. if (OriginalBackground)
  473. {
  474. GetPic(e);
  475. }
  476. else
  477. {
  478. #region //填充个背景色矩形-----------------------------------------------
  479. SolidBrush b = new SolidBrush(m_backrangecolor);
  480. e.Graphics.FillRectangle(b, m_backRect);
  481. #endregion
  482. }
  483. #region //计算并进行绘制部份------------------------------------
  484. //log.Info(" m_f_widthAndheight_js=" +m_Zoom_Base.ToString());
  485. foreach (BaseObject item in m_list_allDPart)
  486. {
  487. DisplayParticle dp = (DisplayParticle)item;
  488. if (dp.GetPaintState() != PaintState.NOPAINT)
  489. {
  490. dp.OnPaint(e);
  491. }
  492. }
  493. #endregion
  494. #region //判断是否使用了矩形或圆形工具进行多选,是的话,那么这里就开始绘制------------------------
  495. if (m_SelectTool.IsSelecting)
  496. {
  497. if (m_SelectTool.Shape==SelectedShape.Rectangle && m_SelectTool.Rect.Width > 0 && m_SelectTool.Rect.Height > 0)
  498. {
  499. Graphics g = e.Graphics;
  500. //绘制矩形
  501. g.DrawRectangle(new Pen(Color.Blue), m_SelectTool.Rect.X, m_SelectTool.Rect.Y, m_SelectTool.Rect.Width, m_SelectTool.Rect.Height);
  502. //半透明画刷
  503. SolidBrush brush = new SolidBrush(Color.FromArgb(50, m_ColorNotContent));
  504. //填充选择矩形
  505. g.FillRectangle(brush, m_SelectTool.Rect.X, m_SelectTool.Rect.Y, m_SelectTool.Rect.Width, m_SelectTool.Rect.Height);
  506. }
  507. if (m_SelectTool.Shape == SelectedShape.Ellipse && m_SelectTool.Rect.Width > 0 && m_SelectTool.Rect.Height > 0)
  508. {
  509. Graphics g = e.Graphics;
  510. //绘制圆形
  511. g.DrawEllipse(new Pen(Color.Blue), m_SelectTool.Rect.X, m_SelectTool.Rect.Y, m_SelectTool.Rect.Width, m_SelectTool.Rect.Height);
  512. //半透明画刷
  513. SolidBrush brush = new SolidBrush(Color.FromArgb(50, m_ColorNotContent));
  514. //填充选择圆形
  515. g.FillEllipse(brush, m_SelectTool.Rect.X, m_SelectTool.Rect.Y, m_SelectTool.Rect.Width, m_SelectTool.Rect.Height);
  516. }
  517. }
  518. #endregion
  519. #region 绘制网格线,帧图边框部份
  520. if (true == m_is_showgrid)
  521. {
  522. RectangleF ls_rect_gridline = Rectangle.Round(new RectangleF(m_backRect.X,
  523. m_backRect.Y,
  524. m_backRect.Width,
  525. m_backRect.Height));
  526. //共绘制外边框,和里面横竖,各4个线
  527. ControlPaint.DrawBorder(e.Graphics,
  528. Rectangle.Ceiling(ls_rect_gridline),
  529. Color.BurlyWood,
  530. 1,
  531. ButtonBorderStyle.Solid,
  532. Color.BurlyWood,
  533. 1,
  534. ButtonBorderStyle.Solid,
  535. Color.BurlyWood,
  536. 1,
  537. ButtonBorderStyle.Solid,
  538. Color.BurlyWood,
  539. 1,
  540. ButtonBorderStyle.Solid);
  541. //然后再把rectangle,横竖分成4块,画上4条横竖线
  542. //画横线
  543. for (int i = 1; i < m_i_grid_showlinesnumber_height; i++)
  544. {
  545. double y_zl = ls_rect_gridline.Height / m_i_grid_showlinesnumber_height;
  546. e.Graphics.DrawLine(new Pen(Color.BurlyWood),
  547. ls_rect_gridline.X,
  548. Convert.ToInt64(ls_rect_gridline.Y + y_zl * i),
  549. ls_rect_gridline.X + ls_rect_gridline.Width,
  550. Convert.ToInt64(ls_rect_gridline.Y + y_zl * i));
  551. }
  552. //画竖线
  553. for (int i = 1; i < m_i_grid_showlinesnumber_width; i++)
  554. {
  555. double x_zl = ls_rect_gridline.Width / m_i_grid_showlinesnumber_width;
  556. e.Graphics.DrawLine(new Pen(Color.BurlyWood),
  557. Convert.ToInt64(ls_rect_gridline.X + x_zl * i),
  558. ls_rect_gridline.Y,
  559. Convert.ToInt64(ls_rect_gridline.X + x_zl * i),
  560. ls_rect_gridline.Y + ls_rect_gridline.Height);
  561. }
  562. }
  563. #endregion
  564. #region 绘制鼠标跟踪线部份
  565. //XX虚线-----------------------------------------------
  566. Pen xxpen = new Pen(Color.GreenYellow, 1);
  567. xxpen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
  568. xxpen.DashPattern = new float[] { 5, 5 };
  569. //竖线
  570. e.Graphics.DrawLine(xxpen, 0, m_mouse_now_point.Y, m_mouse_now_point.X - 10, m_mouse_now_point.Y);
  571. e.Graphics.DrawLine(xxpen, m_mouse_now_point.X + 10, m_mouse_now_point.Y, this.Width, m_mouse_now_point.Y);
  572. //横线
  573. e.Graphics.DrawLine(xxpen, m_mouse_now_point.X, 0, m_mouse_now_point.X, m_mouse_now_point.Y - 10);
  574. e.Graphics.DrawLine(xxpen, m_mouse_now_point.X, m_mouse_now_point.Y + 10, m_mouse_now_point.X, this.Height);
  575. ////--------------------------------------------------------------------------------
  576. #endregion
  577. }
  578. #endregion
  579. #region 鼠标操作事件
  580. /// <summary>
  581. /// 按指定的增量刻度对整个图像进行缩放,x,y为手动缩放时当前鼠标所在的位置,如果在其它地方调用则传入0在计算过程中,不会影响
  582. /// </summary>
  583. /// <param name="zoom"></param>
  584. private void ImageZoomByIncrement(float zoom, float in_mouse_x, float in_mouse_y)
  585. {
  586. //先计算鼠标的位置与背景rect的位置的差值
  587. //用于存储锚点缩放记录原backrectf值的,一用来于计算差值
  588. float oldwidth = m_backRect.Width;
  589. float oldheight = m_backRect.Height;
  590. m_backRect.Width = (float)(m_backRect.Width + Convert.ToDouble(m_old_backRect.Width * zoom));
  591. m_backRect.Height = (float)(m_backRect.Height + Convert.ToDouble(m_old_backRect.Height * zoom));
  592. //锚点缩放补差值计算,得出差值
  593. float f_czx = (in_mouse_x - m_backRect.X) * ((oldwidth - m_backRect.Width) / oldwidth);
  594. float f_czy = (in_mouse_y - m_backRect.Y) * ((oldheight - m_backRect.Height) / oldheight);
  595. //对背景矩形与所有的segment进行修补差值
  596. m_backRect.X = m_backRect.X + f_czx;
  597. m_backRect.Y = m_backRect.Y + f_czy;
  598. for (int i = 0; i < m_list_allDPart.Count(); i++)
  599. {
  600. DisplayParticle dp = (DisplayParticle)m_list_allDPart[i];
  601. //dp.displayState = DisplayState.NORMALDISPLAY;
  602. for (int y = 0; y < dp.DSegments.Count(); y++)
  603. {
  604. //这里重新设置每条线的高度,和x,y坐标
  605. DisplaySegment ds = dp.DSegments[y];
  606. DisplaySegment old_ds = ((DisplayParticle)ReportFun.m_original_list_baseobject[i]).DSegments[y];
  607. ds.PenWidthAndHeight = ds.PenWidthAndHeight + old_ds.PenWidthAndHeight
  608. * zoom;
  609. ds.Rect = new RectangleF(ds.Rect.X + old_ds.Rect.X * zoom + f_czx, ds.Rect.Y + old_ds.Rect.Y * zoom + f_czy,
  610. ds.Rect.Width + old_ds.Rect.Width * zoom, ds.Rect.Height + old_ds.Rect.Height * zoom);
  611. }
  612. //获取矩形的rectangle
  613. dp.Rect = dp.GetRectFromDSegment();
  614. //重新计算小矩形边框
  615. dp.SmallRect = dp.GetSmallRectangleFromRect();
  616. //设置缩放到多少倍时进行显示
  617. if (m_zoom_record >= dp.Zoom_DisPlayThreshold)
  618. {
  619. dp.SetPaintState(PaintState.NORMALPAINT);
  620. }
  621. else
  622. {
  623. dp.SetPaintState(PaintState.CONCISEPAINT);
  624. }
  625. if (dp.Rect.Left < -120 || dp.Rect.Right > this.Width+120 || dp.Rect.Top < -120 || dp.Rect.Bottom > this.Height+120)
  626. {
  627. dp.SetPaintState(PaintState.NOPAINT);//the particles which are out of screen don't display.to speed up the display efficient.
  628. }
  629. }
  630. if (m_list_allDfield != null)
  631. {
  632. if (m_list_allDfield.Count > 0)
  633. {
  634. for (int i = 0; i < m_list_allDfield.Count; i++)
  635. {
  636. DisplayField theField = m_list_allDfield[i];
  637. theField.Current_Rect = new RectangleF(theField.Current_Rect.X + theField.Show_Rect.X * zoom + f_czx,
  638. theField.Current_Rect.Y + theField.Show_Rect.Y * zoom + f_czy,
  639. theField.Current_Rect.Width + theField.Show_Rect.Width * zoom,
  640. theField.Current_Rect.Height + theField.Show_Rect.Height * zoom);
  641. }
  642. }
  643. }
  644. #region 计算标尺尺寸部份-----放大------
  645. //计算标尺实际占用像素的宽度
  646. m_f_ruler_size = m_f_ruler_size + Convert.ToInt32(m_f_old_ruler_size * zoom);
  647. control_Ruler1.SetValue(m_f_ruler_size, m_pixelSize);
  648. #endregion
  649. }
  650. protected override void OnMouseWheel(MouseEventArgs e)
  651. {
  652. if (e.Delta > 0)
  653. {
  654. if (m_zoom_record < m_f_zoom_max)
  655. {
  656. //图形缩放计算部份-------放大------------//是放大 一个刻度
  657. m_Zoom_Base = const_zoom_increment;
  658. }
  659. else return;
  660. }
  661. else
  662. {
  663. if (m_zoom_record > m_f_zoom_mix)
  664. {
  665. //图形缩放计算部份------缩小--------------//是缩小 一个刻度
  666. m_Zoom_Base = -const_zoom_increment;
  667. }
  668. else return;
  669. }
  670. m_zoom_record = m_zoom_record + m_Zoom_Base;
  671. //这里对缩放的总记录进行校验
  672. if (m_zoom_record < m_f_zoom_mix)
  673. {
  674. m_zoom_record = m_f_zoom_mix;
  675. return;
  676. }
  677. //传入增减缩放的刻度,进行缩放
  678. ImageZoomByIncrement(m_Zoom_Base, e.X, e.Y);
  679. Invalidate();
  680. }
  681. protected override void OnMouseDown(MouseEventArgs e)
  682. {
  683. if (e.Button == MouseButtons.Left)
  684. {
  685. this.Cursor = Cursors.Hand;
  686. if (m_SelectTool.IsSelecting)
  687. {
  688. m_SelectTool.StartPoint = e.Location;
  689. }
  690. else
  691. {
  692. bool ifClickOnParticle=false;
  693. foreach (BaseObject item in m_list_allDPart)
  694. {
  695. var dp = (DisplayParticle)item;
  696. if (ReportFun.WhetherInRange(dp, e.Location))
  697. {
  698. dp.IsSelect = !dp.IsSelect;
  699. ifClickOnParticle = true;
  700. break;
  701. }
  702. }
  703. if (ifClickOnParticle == false)
  704. {
  705. foreach (BaseObject item in m_list_allDPart)
  706. {
  707. var dp = (DisplayParticle)item;
  708. if (dp.Rect.Left > -120 && dp.Rect.Right < this.Width + 120 && dp.Rect.Top > -120 && dp.Rect.Bottom < this.Height + 120)
  709. {
  710. item.IsDragging = true;
  711. }
  712. item.DraggingPoint = e.Location;
  713. if (OriginalBackground)
  714. {
  715. dp.SetPaintState(PaintState.NOPAINT);
  716. }
  717. }
  718. foreach (DisplayField item in m_list_allDfield)
  719. {
  720. item.IsDragging = true;
  721. item.DraggingPoint = e.Location;
  722. }
  723. m_isDrag = true;
  724. m_beforedrag_pointf = e.Location;
  725. }
  726. }
  727. }
  728. Invalidate();
  729. }
  730. protected override void OnMouseMove(MouseEventArgs e)
  731. {
  732. //当前鼠标的位置,用来绘制鼠标线用
  733. m_mouse_now_point = e.Location;
  734. if (m_SelectTool.IsSelecting)
  735. {
  736. if (e.Button == MouseButtons.Left)
  737. {
  738. if (e.Location.X > m_SelectTool.StartPoint.X && e.Location.Y > m_SelectTool.StartPoint.Y)
  739. {
  740. //右下拖动
  741. m_SelectTool.Rect = new RectangleF(m_SelectTool.StartPoint, new SizeF(e.Location.X - m_SelectTool.StartPoint.X, e.Location.Y - m_SelectTool.StartPoint.Y));
  742. }
  743. if (e.Location.X < m_SelectTool.StartPoint.X && e.Location.Y < m_SelectTool.StartPoint.Y)
  744. {
  745. //左上拖动
  746. PointF lspointf = new PointF(e.Location.X, e.Location.Y);
  747. m_SelectTool.Rect = new RectangleF(lspointf, new SizeF(m_SelectTool.StartPoint.X - e.Location.X, m_SelectTool.StartPoint.Y - e.Location.Y));
  748. }
  749. if (e.Location.X > m_SelectTool.StartPoint.X && e.Location.Y < m_SelectTool.StartPoint.Y)
  750. {
  751. //右上,这种画法,需要将左下,右上两点转换成左上,右下
  752. PointF left_pointf = new PointF(m_SelectTool.StartPoint.X, e.Location.Y);
  753. PointF right_pointf = new PointF(e.Location.X, m_SelectTool.StartPoint.Y);
  754. m_SelectTool.Rect = new RectangleF(left_pointf, new SizeF(right_pointf.X - left_pointf.X, right_pointf.Y - left_pointf.Y));
  755. }
  756. if (e.Location.X < m_SelectTool.StartPoint.X && e.Location.Y > m_SelectTool.StartPoint.Y)
  757. {
  758. //左下,这种画法,需要将左下,右上两点转换成左上,右下
  759. PointF left_pointf = new PointF(e.Location.X, m_SelectTool.StartPoint.Y);
  760. PointF right_pointf = new PointF(m_SelectTool.StartPoint.X, e.Location.Y);
  761. m_SelectTool.Rect = new RectangleF(left_pointf, new SizeF(right_pointf.X - left_pointf.X, right_pointf.Y - left_pointf.Y));
  762. }
  763. }
  764. }
  765. else
  766. {
  767. if (m_isDrag)
  768. {
  769. foreach (BaseObject item in m_list_allDPart)
  770. {
  771. DisplayParticle dp = (DisplayParticle)item;
  772. if (true == item.IsDragging)
  773. {
  774. foreach (DisplaySegment ds in dp.DSegments)
  775. {
  776. var rec = ds.Rect;
  777. rec.X = ds.Rect.X + e.X - item.DraggingPoint.X; //获取到原先点与移动点的增减量,+原先的x坐标,就是新的坐标
  778. rec.Y = ds.Rect.Y + e.Y - item.DraggingPoint.Y;
  779. ds.Rect = rec;
  780. ds.DraggingPoint = e.Location;
  781. }
  782. item.DraggingPoint = e.Location;
  783. //获取矩形的rectangle
  784. dp.Rect = dp.GetRectFromDSegment();
  785. //重新计算小矩形边框
  786. dp.SmallRect = dp.GetSmallRectangleFromRect();
  787. if (m_zoom_record >= dp.Zoom_DisPlayThreshold)
  788. {
  789. dp.SetPaintState(PaintState.NORMALPAINT);
  790. }
  791. else
  792. {
  793. dp.SetPaintState(PaintState.CONCISEPAINT);
  794. }
  795. if (dp.Rect.Left < -120 || dp.Rect.Right > this.Width + 120 || dp.Rect.Top < -120 || dp.Rect.Bottom > this.Height + 120)
  796. {
  797. dp.SetPaintState(PaintState.NOPAINT);
  798. }
  799. }
  800. }
  801. foreach (var item in m_list_allDfield)
  802. {
  803. if (true == item.IsDragging)
  804. {
  805. item.Current_Rect = new RectangleF(
  806. item.Current_Rect.Left + Convert.ToSingle((e.X - item.DraggingPoint.X)),
  807. item.Current_Rect.Top + Convert.ToSingle((e.Y - item.DraggingPoint.Y)),
  808. item.Current_Rect.Width,
  809. item.Current_Rect.Height);
  810. item.DraggingPoint = e.Location;
  811. }
  812. }
  813. //同样重新计算backrectf的坐标
  814. m_backRect = new RectangleF(m_backRect.Location.X + e.X - m_beforedrag_pointf.X,
  815. m_backRect.Location.Y + e.Y - m_beforedrag_pointf.Y, m_backRect.Width, m_backRect.Height);
  816. m_beforedrag_pointf = e.Location;
  817. }
  818. else
  819. {
  820. foreach (BaseObject item in m_list_allDPart)
  821. {
  822. DisplayParticle dp = (DisplayParticle)item;
  823. if (dp.GetPaintState() == PaintState.NORMALPAINT)
  824. {
  825. if (ReportFun.WhetherInRange(dp, e.Location))
  826. {
  827. dp.IsMouseOver = true;
  828. //显示x-ray能谱图
  829. if (control_XRayTable1.Visible == false)
  830. ShowXRay(dp);
  831. //m_sem_mouse_now_point = new Point(dp.SEMPosX, dp.SEMPosY);
  832. m_str_mouseshow_left = "颗粒SEM位置:" + dp.SEMPosX.ToString() + ":" + dp.SEMPosY.ToString();
  833. m_sem_mouse_now_point = new Point(dp.SEMPosX, dp.SEMPosY);
  834. }
  835. else
  836. {
  837. dp.IsMouseOver = false;
  838. //移动在颗粒外面时,要判断,Operator_ShowXray不为选下显示XRAY时,才对XRay进行隐藏
  839. if (dp.Operator_ShowXRay != ParticleShowXray.SELECTANDDISPLAYXRAY)
  840. {
  841. //隐藏x-ray能谱图
  842. HideXRay(dp);
  843. }
  844. }
  845. }
  846. }
  847. }
  848. }
  849. #region 向报告程序右下角,传送鼠标颗粒等相关信息
  850. //获取颜色方法1,使用API来获取当前鼠标指向位置的颜色值-----------------------------------------------------
  851. Color ls_c = GetColorByMousePoint(e.X, e.Y);
  852. m_str_mouseshow_right = "灰度#" + ls_c.R.ToString();
  853. m_ReportApp.mouseMatter.Text = m_str_mouseshow_right ;
  854. m_ReportApp.RSGrayVal.Text = m_str_mouseshow_left;
  855. #endregion
  856. Invalidate();
  857. }
  858. /// <summary>
  859. /// 获取鼠标所在位置的信息,显示在框架的右下角
  860. /// </summary>
  861. /// <param name="mouseshow_left"></param>
  862. /// <param name="mouseshow_rightb"></param>
  863. public void GetMouseLowerRightCornerText(out string mouseshow_left, out string mouseshow_rightb)
  864. {
  865. mouseshow_left = m_str_mouseshow_left;
  866. mouseshow_rightb = m_str_mouseshow_right;
  867. }
  868. /// <summary>
  869. /// 鼠标抬起事件
  870. /// </summary>
  871. /// <param name="e"></param>
  872. protected override void OnMouseUp(MouseEventArgs e)
  873. {
  874. if (e.Button == MouseButtons.Left)
  875. {
  876. this.Cursor = Cursors.Default;
  877. if (m_SelectTool.IsSelecting)
  878. {
  879. if (m_SelectTool.Rect.Width > 0 && m_SelectTool.Rect.Height > 0)
  880. {
  881. GraphicsPath ls_gpath = new GraphicsPath();
  882. switch (m_SelectTool.Shape)
  883. {
  884. case SelectedShape.Rectangle:
  885. ls_gpath.AddRectangle(m_SelectTool.Rect);
  886. break;
  887. case SelectedShape.Ellipse:
  888. ls_gpath.AddEllipse(m_SelectTool.Rect);
  889. break;
  890. default:
  891. break;
  892. }
  893. foreach (DisplayParticle dp in m_list_allDPart)
  894. {
  895. if (dp.GetPaintState() != PaintState.NOPAINT )
  896. {
  897. PointF[] lspointf = ls_gpath.PathPoints;
  898. if (true == ReportFun.WhetherInRange(m_SelectTool.Rect, lspointf,new Point((int)dp.Rect.X,(int)dp.Rect.Y)))
  899. {
  900. dp.IsSelect =!dp.IsSelect ;// set the particle to the opsite selected state
  901. }
  902. }
  903. }
  904. }
  905. m_SelectTool.IsSelecting = false;
  906. }
  907. else
  908. {
  909. if (m_isDrag)
  910. {
  911. foreach (BaseObject item in m_list_allDPart)
  912. {
  913. DisplayParticle dp = (DisplayParticle)item;
  914. foreach (DisplaySegment ds in dp.DSegments)
  915. {
  916. var rec = ds.Rect;
  917. rec.X = ds.Rect.X + e.X - item.DraggingPoint.X; //获取到原先点与移动点的增减量,+原先的x坐标,就是新的坐标
  918. rec.Y = ds.Rect.Y + e.Y - item.DraggingPoint.Y;
  919. ds.Rect = rec;
  920. ds.DraggingPoint = Point.Empty;
  921. ds.IsDragging = false;
  922. }
  923. item.DraggingPoint = Point.Empty;
  924. item.IsDragging = false;
  925. //获取矩形的rectangle
  926. dp.Rect = dp.GetRectFromDSegment();
  927. //重新计算小矩形边框
  928. dp.SmallRect = dp.GetSmallRectangleFromRect();
  929. if (m_zoom_record >= dp.Zoom_DisPlayThreshold)
  930. {
  931. dp.SetPaintState(PaintState.NORMALPAINT);
  932. }
  933. else
  934. {
  935. dp.SetPaintState(PaintState.CONCISEPAINT);
  936. }
  937. if (dp.Rect.Left < -120 || dp.Rect.Right > this.Width + 120 || dp.Rect.Top < -120 || dp.Rect.Bottom > this.Height + 120)
  938. {
  939. dp.SetPaintState(PaintState.NOPAINT);
  940. }
  941. }
  942. m_isDrag = false;
  943. }
  944. }
  945. }
  946. if (e.Button == MouseButtons.Right)
  947. {
  948. bool ifClickOnParticle=false;
  949. bool ifThereIsSelectedParticle = false;
  950. foreach (BaseObject item in m_list_allDPart)
  951. {
  952. if (true == ReportFun.WhetherInRange((DisplayParticle)item, e.Location))
  953. {
  954. ifClickOnParticle = true;
  955. CMenuStrip.Items[(int)RightButtonMenu.Include].Visible = false;
  956. CMenuStrip.Items[(int)RightButtonMenu.CopyImage].Visible = false;
  957. CMenuStrip.Items[(int)RightButtonMenu.OriginalSplicing].Visible = false;
  958. CMenuStrip.Items[(int)RightButtonMenu.DeleteParticle].Visible = true;
  959. //CMenuStrip.Items[(int)RightButtonMenu.CopyDatabase].Visible = true;
  960. CMenuStrip.Items[(int)RightButtonMenu.MoveSEMToParticle].Visible = true;
  961. CMenuStrip.Items[(int)RightButtonMenu.MoveSEMToParticle].Tag = item;
  962. }
  963. if (((DisplayParticle)item).IsSelect)
  964. {
  965. ifThereIsSelectedParticle = true;
  966. }
  967. }
  968. if (ifClickOnParticle == false)
  969. {
  970. if (ifThereIsSelectedParticle)
  971. {
  972. CMenuStrip.Items[(int)RightButtonMenu.Include].Visible = true;
  973. }
  974. else
  975. {
  976. CMenuStrip.Items[(int)RightButtonMenu.Include].Visible = false;
  977. }
  978. CMenuStrip.Items[(int)RightButtonMenu.DeleteParticle].Visible = false;
  979. //CMenuStrip.Items[(int)RightButtonMenu.CopyDatabase].Visible = false;
  980. CMenuStrip.Items[(int)RightButtonMenu.CopyImage].Visible = true;
  981. CMenuStrip.Items[(int)RightButtonMenu.OriginalSplicing].Visible = true;
  982. CMenuStrip.Items[(int)RightButtonMenu.MoveSEMToParticle].Visible = false;
  983. }
  984. }
  985. Invalidate();
  986. }
  987. #endregion
  988. #region 鼠标右键菜单
  989. private void ToolStripMenuItem_id_Click(object sender, EventArgs e)
  990. {
  991. //ID
  992. //DisplayParticle dp = (DisplayParticle)CMenuStrip.Items[0].Tag;
  993. //MessageBox.Show(dp.guid.ToString());
  994. }
  995. //是否显示过小颗菜单
  996. private void ToolStripMenuItem_ShowSmallParticle_Click(object sender, EventArgs e)
  997. {
  998. }
  999. private void ToolStripMenuItem_selected_Click(object sender, EventArgs e)
  1000. {
  1001. List<DisplayParticle> selectedParts = new List<DisplayParticle>();
  1002. List<Particle> Particles = new List<Particle>();
  1003. foreach (var dp in m_list_allDPart)
  1004. {
  1005. if (dp.IsSelect)
  1006. {
  1007. selectedParts.Add((DisplayParticle)dp);
  1008. Particle particle = new Particle();
  1009. particle.FieldId = ((OTSIncAReportGraph.DisplayParticle)dp).FieldId;
  1010. particle.ParticleId = ((OTSIncAReportGraph.DisplayParticle)dp).ParticleId;
  1011. Particles.Add(particle);
  1012. }
  1013. }
  1014. frmReportApp.selectedRegion = m_SelectTool.Rect;
  1015. SendSelectParticleListToReportFrame(selectedParts);
  1016. }
  1017. /// <summary>
  1018. /// 显示x-ray能谱图
  1019. /// </summary>
  1020. /// <param name="in_dparticle"></param>
  1021. private void ShowXRay(DisplayParticle in_dparticle)
  1022. {
  1023. m_mouseOver_dparticle = in_dparticle;//将显示xray的dparticle记录给全局变量
  1024. if (delaytimer.Enabled == false)
  1025. {
  1026. delaytimer.Tick += Delaytimer_Tick;
  1027. delaytimer.Interval = 500;
  1028. delaytimer.Start();
  1029. }
  1030. }
  1031. private void Delaytimer_Tick(object sender, EventArgs e)
  1032. {
  1033. delaytimer.Enabled = false;
  1034. //显示xray相关信息
  1035. uint[] Search_xray = new uint[2000];
  1036. uint[] Analysis_xray = new uint[2000];
  1037. //
  1038. int i_xray_id = 0;
  1039. List<Element> list_celementchemistryclr = new List<Element>();
  1040. //获取Xray数据
  1041. ReportFun.GetXrayByParticleTagIDAndFieldID_ForDrawDistrbutionImageAndBSE(m_mouseOver_dparticle.ParticleId, m_mouseOver_dparticle.FieldId, out Search_xray, out Analysis_xray, out i_xray_id, out list_celementchemistryclr);
  1042. //get CElementChemistryClr list
  1043. List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
  1044. for (int i = 0; i < list_celementchemistryclr.Count; i++)
  1045. {
  1046. ShowElementInfo ls_sei = new ShowElementInfo();
  1047. ls_sei.ElementName = list_celementchemistryclr[i].Name;
  1048. ls_sei.Percentage = list_celementchemistryclr[i].Percentage;
  1049. ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByYsm(CListPeriodic.GetListPeriodic(), ls_sei.ElementName).SX1);
  1050. double de_sx2 = 0;
  1051. if (CListPeriodic.GetPeriodicByYsm(CListPeriodic.GetListPeriodic(), ls_sei.ElementName).SX2 == "" || CListPeriodic.GetPeriodicByYsm(CListPeriodic.GetListPeriodic(), ls_sei.ElementName).SX2 == "-")
  1052. {
  1053. de_sx2 = 0;
  1054. }
  1055. else
  1056. {
  1057. de_sx2 = Convert.ToDouble(CListPeriodic.GetPeriodicByYsm(CListPeriodic.GetListPeriodic(), ls_sei.ElementName).SX2);
  1058. }
  1059. ls_sei.dLF = de_sx2;
  1060. list_showelementinfo.Add(ls_sei);
  1061. }
  1062. //获取使用标准库的名称
  1063. string str_IncAName = "";
  1064. str_IncAName = m_mouseOver_dparticle.TypeName;
  1065. //获取数据后,需要对xraytable设置
  1066. control_XRayTable1.Visible = false;
  1067. control_XRayTable1.SetXRayShowLineValue(Search_xray, Analysis_xray, list_showelementinfo);
  1068. //颗粒国标信息
  1069. control_XRayTable1.GBInfoStr = "";
  1070. control_XRayTable1.MaterialName = str_IncAName;//杂夹物
  1071. control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
  1072. control_XRayTable1.Visible = true;
  1073. this.Refresh();
  1074. }
  1075. /// <summary>
  1076. /// 隐藏x-ray能谱图
  1077. /// </summary>
  1078. private void HideXRay(DisplayParticle in_dparticle)
  1079. {
  1080. if (m_mouseOver_dparticle == null)
  1081. return;
  1082. if (m_mouseOver_dparticle.guid == in_dparticle.guid || m_mouseOver_dparticle.IsDeleted==true)
  1083. {
  1084. //如果是刚才移动过的颗粒的话,那么这里再对xray进行隐藏
  1085. control_XRayTable1.Visible = false;
  1086. delaytimer.Enabled = false;
  1087. }
  1088. }
  1089. /// <summary>
  1090. /// 根据传入的鼠标位置,来获取当前鼠标位置上的灰度值
  1091. /// </summary>
  1092. /// <param name="int_x"></param>
  1093. /// <param name="int_y"></param>
  1094. /// <returns></returns>
  1095. private Color GetColorByMousePoint(int int_x, int int_y)
  1096. {
  1097. Graphics g = Graphics.FromHwnd(this.Handle);
  1098. IntPtr hdc = g.GetHdc();
  1099. uint u_color = 0;
  1100. try
  1101. {
  1102. u_color = DrawFunction.GetPixel(hdc, int_x, int_y);
  1103. }
  1104. catch
  1105. { }
  1106. Color ls_c = Color.FromArgb
  1107. (
  1108. (int)(u_color << 24 >> 24),
  1109. (int)(u_color << 16 >> 24),
  1110. (int)(u_color << 8 >> 24)
  1111. );
  1112. return ls_c;
  1113. }
  1114. /// <summary>
  1115. /// 封装,将分布图中的颗粒list传送给报告项目框架中
  1116. /// </summary>
  1117. private void SendSelectParticleListToReportFrame(List<DisplayParticle> selectParts)
  1118. {
  1119. //先获取分布图中,有哪些颗粒已经被选择上了
  1120. foreach (var p in selectParts)
  1121. {
  1122. if (!frmReportApp.selectedParticles.ContainsKey(p.guid))
  1123. {
  1124. frmReportApp.selectedParticles.Add(p.guid, p);
  1125. }
  1126. }
  1127. }
  1128. /// <summary>
  1129. /// 设置当前对哪些颗粒进行设置为选择状态
  1130. /// </summary>
  1131. /// <param name="in_list_cotsparticleclr"></param>
  1132. public void SetSelectParticle(List<Particle> particles)
  1133. {
  1134. if (particles == null)
  1135. {
  1136. return;
  1137. }
  1138. if (particles.Count == 0)
  1139. {
  1140. return;
  1141. }
  1142. foreach (DisplayParticle ls_dp in m_list_allDPart)
  1143. {
  1144. if (ls_dp.GetPaintState() == PaintState.NORMALPAINT)
  1145. {
  1146. for (int i = 0; i < particles.Count; i++)
  1147. {
  1148. if (particles[i].ParticleId == ls_dp.ParticleId
  1149. && particles[i].FieldId == ls_dp.FieldId)
  1150. {
  1151. ls_dp.IsSelect=true;
  1152. }
  1153. }
  1154. }
  1155. }
  1156. }
  1157. private void ToolStripMenuItem_delete_Click(object sender, EventArgs e)
  1158. {
  1159. List<DisplayParticle> selectedParts = new List<DisplayParticle>();
  1160. foreach (var obj in m_list_allDPart)
  1161. {
  1162. var dp = (DisplayParticle)obj;
  1163. if (dp.IsSelect)
  1164. {
  1165. dp.IsDeleted = true;
  1166. }
  1167. else
  1168. {
  1169. selectedParts.Add(dp);
  1170. }
  1171. }
  1172. SendSelectParticleListToReportFrame(selectedParts);
  1173. }
  1174. //复制图像
  1175. private void toolStripMenuItem_copyimage_Click(object sender, EventArgs e)
  1176. {
  1177. SaveFileDialog sfd = new SaveFileDialog();
  1178. //|ALL Files(*.*)|*.*
  1179. //BMP Files(*.bmp)| *.bmp |
  1180. sfd.Filter = "png Files(*.png)| *.png |BMP Files(*.bmp)| *.bmp |JPG Files(*.jpg)|*.jpg;*.jpeg";
  1181. if (sfd.ShowDialog() == DialogResult.OK)
  1182. {
  1183. OutPIC outpic = new OutPIC();
  1184. outpic.m_list_allDfield = m_list_allDfield;
  1185. outpic.resultFile = resultFile;
  1186. outpic.sfd = sfd;
  1187. outpic.type = (int)Outpic_enum.pic;
  1188. Thread bThread = new Thread(new ThreadStart(outpic.opencv_outpic));
  1189. bThread.IsBackground = true;
  1190. bThread.Start();
  1191. }
  1192. }
  1193. private void ToolStripMenuItem_movesempoint_Click(object sender, EventArgs e)
  1194. {
  1195. //移动SEM到指定位置
  1196. if (m_mythread == null)
  1197. {
  1198. return;
  1199. }
  1200. if (m_mythread.ThreadState == System.Threading.ThreadState.Running || m_mythread.ThreadState == System.Threading.ThreadState.WaitSleepJoin)
  1201. {
  1202. return;
  1203. }
  1204. if (m_mythread.ThreadState == System.Threading.ThreadState.Stopped)
  1205. {
  1206. m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
  1207. }
  1208. //改为线程调用,先判断线程状态
  1209. m_mythread.Start(new Point(m_sem_mouse_now_point.X, m_sem_mouse_now_point.Y));
  1210. }
  1211. #endregion
  1212. #region 自定义功能函数
  1213. /// <summary>
  1214. /// 复制图像
  1215. /// </summary>
  1216. private void CopyImage()
  1217. {
  1218. int height, width;
  1219. width = this.Width;
  1220. height = this.Height;
  1221. Bitmap image = new Bitmap(width, height);
  1222. //this.BackgroundImage
  1223. this.DrawToBitmap(image, new Rectangle(0, 0, width, height));
  1224. Clipboard.SetImage(image);
  1225. }
  1226. /// <summary>
  1227. /// 移动SEM到指定位置线程函数
  1228. /// </summary>
  1229. private void Thread_GO(object in_obj)
  1230. {
  1231. Point sem_point = (Point)in_obj;
  1232. //第一步,连接电镜
  1233. ReportFun.ConnectToSEM();
  1234. Thread.Sleep(500);
  1235. //第二步,移动到指定位置,先读取再设置
  1236. if (ReportFun.m_SEMConnectionState == true)
  1237. {
  1238. ReportFun.MoveSemToPointXY(sem_point.X, sem_point.Y);
  1239. }
  1240. Thread.Sleep(1500);
  1241. //第三步,断开电镜连接
  1242. ReportFun.DisConnectSEM();
  1243. }
  1244. /// <summary>
  1245. /// 按框架传入的底层计算结果,重新对颗粒进行区分显示
  1246. /// </summary>
  1247. /// <param name="in_cgriddataclr"></param>
  1248. public void DrawDistrbutionImageAndBSE_ByQuery(OTSIncAReportApp.OTSSampleReportInfo.ReportCondition in_griddata)
  1249. {
  1250. FilterParticleByOtherCondition(in_griddata);
  1251. Invalidate();
  1252. this.Refresh();
  1253. }
  1254. /// <summary>
  1255. /// 对分布图进行宽度匹配操作
  1256. /// </summary>
  1257. public void WidthMatch()
  1258. {
  1259. if (this.Width != m_backRect.Width)
  1260. {
  1261. float f_cz = 0;//进行调整的差值
  1262. f_cz = -((m_backRect.Width - this.Width) / m_old_backRect.Width);
  1263. m_zoom_record = m_zoom_record + f_cz;//更新上缩放值,与下面处理缩放对应上
  1264. ImageZoomByIncrement(f_cz, 0, 0);
  1265. }
  1266. MoveImageToPoint(new PointF(0, 0));
  1267. }
  1268. /// <summary>
  1269. /// 对分布图进行高度匹配操作
  1270. /// </summary>
  1271. public void HeightMatch()
  1272. {
  1273. if (this.Height != m_backRect.Height)
  1274. {
  1275. float f_cz = 0;//进行调整的差值
  1276. f_cz = -((m_backRect.Height - this.Height) / m_old_backRect.Height);
  1277. m_zoom_record = m_zoom_record + f_cz;//更新上缩放值,与下面处理缩放对应上
  1278. ImageZoomByIncrement(f_cz, 0, 0);
  1279. }
  1280. //移动到,this.width - backrectf.width /2
  1281. int ls_x = (int)(this.Width - m_backRect.Width) / 2;
  1282. MoveImageToPoint(new PointF(ls_x, 0));
  1283. }
  1284. /// <summary>
  1285. /// 对分布图进行全图匹配操作
  1286. /// </summary>
  1287. public void FullGraphMatch()
  1288. {
  1289. //全图匹配,首先要判断出来是按宽度来计算缩放,还是按高度来计算缩放
  1290. double thiswidth = this.Width;
  1291. double thisheight = this.Height;
  1292. double imagewidth = m_backRect.Width;
  1293. double imageheight = m_backRect.Height;
  1294. //如果宽已相等rect在thisheight范围内,是宽度匹配已经达到目的,或是高已相等rect在thiswidth范围内,是高度匹配已经达到目的
  1295. if ((thiswidth == imagewidth && thisheight > imagewidth) || (thisheight == imageheight && thiswidth > imagewidth))
  1296. {
  1297. //已经达到目的不操作,返回
  1298. return;
  1299. }
  1300. //判断当前是否宽度匹配未达到全图匹配效果
  1301. if (thiswidth == imagewidth && thisheight < imageheight)
  1302. {
  1303. //说明目前已经达到了宽度匹配,但是未能显示完全整图需要高度匹配
  1304. HeightMatch();
  1305. return;
  1306. }
  1307. //判断当前是否高度匹配未达到全图匹配效果
  1308. if (thisheight == imageheight && thiswidth < imagewidth)
  1309. {
  1310. //说明目前已经达到了高度匹配,但是未能显示完全的整图需要宽度匹配
  1311. WidthMatch();
  1312. return;
  1313. }
  1314. ls_d_cz_width = Math.Abs(thiswidth / imagewidth);
  1315. ls_d_cz_height = Math.Abs(thisheight / imageheight);
  1316. //应该是看谁差的倍数大就按谁的进行调整,而不只能看高宽的差值
  1317. if ((1 - ls_d_cz_width) > (1 - ls_d_cz_height))
  1318. {
  1319. //宽差大,就调用WidthMate
  1320. WidthMatch();
  1321. }
  1322. else
  1323. {
  1324. //高差大,则调用HightMate
  1325. HeightMatch();
  1326. }
  1327. m_f_zoom_mix = m_zoom_record;
  1328. }
  1329. /// <summary>
  1330. /// 将整个图像的位置移动到指定的位置上
  1331. /// </summary>
  1332. private void MoveImageToPoint(PointF in_pointf)
  1333. {
  1334. //先计算,当前所在的位置,和需要移动的位置之间的差
  1335. //想复杂了,其实就是当前backrectf的x,y与in_pointf的差就完了呗
  1336. PointF offex_p = new PointF(m_backRect.X - in_pointf.X, m_backRect.Y - in_pointf.Y);
  1337. for (int i = 0; i < m_list_allDPart.Count; i++)
  1338. {
  1339. DisplayParticle dp = (DisplayParticle)m_list_allDPart[i];
  1340. for (int k = 0; k < dp.DSegments.Count; k++)
  1341. {
  1342. dp.DSegments[k].Rect = new RectangleF(
  1343. dp.DSegments[k].Rect.X - offex_p.X,
  1344. dp.DSegments[k].Rect.Y - offex_p.Y,
  1345. dp.DSegments[k].Rect.Width,
  1346. dp.DSegments[k].Rect.Height);
  1347. }
  1348. //获取矩形的rectangle
  1349. dp.Rect = dp.GetRectFromDSegment();
  1350. //通过line获取路径边缘
  1351. dp.GPath = dp.GetRegionFromDSegments();
  1352. //重新计算小矩形边框
  1353. dp.SmallRect = dp.GetSmallRectangleFromRect();
  1354. if (dp.Rect.Left < -120 || dp.Rect.Right > this.Width + 120 || dp.Rect.Top < -120 || dp.Rect.Bottom > this.Height + 120)
  1355. {
  1356. dp.SetPaintState(PaintState.NOPAINT);
  1357. }
  1358. }
  1359. //同样重新计算backrectf的坐标
  1360. m_backRect = new RectangleF(m_backRect.X - offex_p.X, m_backRect.Y - offex_p.Y,
  1361. m_backRect.Width, m_backRect.Height);
  1362. for (int i =0;i< m_list_allDfield.Count;i++)
  1363. {
  1364. RectangleF dField = m_list_allDfield[i].Current_Rect;
  1365. dField.X = dField.X-offex_p.X;
  1366. dField.Y = dField.Y - offex_p.Y;
  1367. m_list_allDfield[i].Current_Rect = dField;
  1368. }
  1369. Invalidate();
  1370. }
  1371. /// <summary>
  1372. /// 是否显示边框格线,自动切换显示与不显示
  1373. /// </summary>
  1374. /// <param name="b_show"></param>
  1375. public void ShowGridLine()
  1376. {
  1377. m_is_showgrid = !m_is_showgrid;
  1378. }
  1379. /// <summary>
  1380. /// 是否显示标尺控件
  1381. /// </summary>
  1382. /// <param name="b_show"></param>
  1383. public void ShowRulerControl()
  1384. {
  1385. control_Ruler1.Visible = !control_Ruler1.Visible;
  1386. }
  1387. /// <summary>
  1388. /// 是否显示边框格线,带参重载
  1389. /// </summary>
  1390. /// <param name="b_show"></param>
  1391. public void ShowGridLine(bool b_show)
  1392. {
  1393. m_is_showgrid = b_show;
  1394. }
  1395. /// <summary>
  1396. /// 是否显示标尺控件,带参重载
  1397. /// </summary>
  1398. /// <param name="b_show"></param>
  1399. public void ShowRulerControl(bool b_show)
  1400. {
  1401. control_Ruler1.Visible = b_show;
  1402. }
  1403. /// <summary>
  1404. /// 是否进行矩形多选操作
  1405. /// </summary>
  1406. public void MultiSelect_Rectangle()
  1407. {
  1408. m_SelectTool.IsSelecting = true;
  1409. m_SelectTool.Shape = SelectedShape.Rectangle;
  1410. m_SelectTool.Rect = new RectangleF();
  1411. m_SelectTool.Rect.Width = 0;
  1412. m_SelectTool.Rect.Height = 0;
  1413. }
  1414. /// <summary>
  1415. /// 是否进行圆形多选操作
  1416. /// </summary>
  1417. public void MultiSelect_Ellipse()
  1418. {
  1419. m_SelectTool.IsSelecting = true;
  1420. m_SelectTool.Shape = SelectedShape.Ellipse;
  1421. m_SelectTool.Rect = new RectangleF();
  1422. m_SelectTool.Rect.Width = 0;
  1423. m_SelectTool.Rect.Height = 0;
  1424. }
  1425. /// <summary>
  1426. /// 对选择的多边形进行反选操作
  1427. /// </summary>
  1428. public void ReverseSelection()
  1429. {
  1430. foreach (DisplayParticle dp in m_list_allDPart)
  1431. {
  1432. if (dp.IsSelect)
  1433. {
  1434. dp.IsSelect = false;
  1435. }
  1436. else
  1437. {
  1438. dp.IsSelect = true;
  1439. }
  1440. }
  1441. //将排列图选择的颗粒传送给报告框架中
  1442. //SendSelectParticleListToReportFrame();
  1443. this.Invalidate();
  1444. }
  1445. /// <summary>
  1446. /// 取消所有的颗粒的选择状态
  1447. /// </summary>
  1448. public void DeselectAllParticle()
  1449. {
  1450. foreach (DisplayParticle dp in m_list_allDPart)
  1451. {
  1452. dp.IsSelect=false;
  1453. }
  1454. this.Invalidate();
  1455. }
  1456. /// <summary>
  1457. /// 将整个图像拷贝到内存中
  1458. /// </summary>
  1459. public void CopyToBitmap()
  1460. {
  1461. Bitmap bp = new Bitmap(this.Size.Width, this.Size.Height);
  1462. this.DrawToBitmap(bp, new Rectangle(0, 0, this.Size.Width, this.Size.Height));
  1463. Clipboard.SetImage(bp);
  1464. }
  1465. /// <summary>
  1466. /// 设置显示BSE原图,还是显示分布图带有标准库的
  1467. /// </summary>
  1468. public void ShowMode(IMAGE_TYPE a_type)
  1469. {
  1470. if (a_type == IMAGE_TYPE.BSE)
  1471. {
  1472. OriginalBackground = false;
  1473. //bse图时,显示背景图为白色
  1474. m_backrangecolor = Color.White;
  1475. foreach (DisplayParticle ls_dp in m_list_allDPart)
  1476. {
  1477. foreach (DisplaySegment ls_ds in ls_dp.DSegments)
  1478. {
  1479. ls_ds.ShowMode = SegmentShowMode.DRAWPOINT;
  1480. }
  1481. }
  1482. FullGraphMatch();
  1483. }
  1484. else if (a_type == IMAGE_TYPE.CLASSIFIED)
  1485. {
  1486. m_backrangecolor = Color.Gainsboro;
  1487. OriginalBackground = false;
  1488. foreach (DisplayParticle ls_dp in m_list_allDPart)
  1489. {
  1490. //ls_dp.DisplayState = DisplayState.DISPLAY;
  1491. foreach (DisplaySegment ls_ds in ls_dp.DSegments)
  1492. {
  1493. ls_ds.ShowMode = SegmentShowMode.DRAWLINE;
  1494. }
  1495. }
  1496. FullGraphMatch();
  1497. }
  1498. else if (a_type== IMAGE_TYPE.ORIGINAl)
  1499. {
  1500. m_backrangecolor = Color.Gainsboro;
  1501. OriginalBackground = true;
  1502. foreach (DisplayParticle ls_dp in m_list_allDPart)
  1503. {
  1504. ls_dp.SetDisplayState(DisplayState.NODISPLAY);
  1505. }
  1506. FullGraphMatch();
  1507. }
  1508. else if(a_type== IMAGE_TYPE.ORIGINALCLASSIFIED)
  1509. {
  1510. m_backrangecolor = Color.Gainsboro;
  1511. OriginalBackground = true;
  1512. foreach (DisplayParticle ls_dp in m_list_allDPart)
  1513. {
  1514. //ls_dp.DisplayState = DisplayState.DISPLAY;
  1515. foreach (DisplaySegment ls_ds in ls_dp.DSegments)
  1516. {
  1517. ls_ds.ShowMode = SegmentShowMode.DRAWLINE;
  1518. }
  1519. }
  1520. FullGraphMatch();
  1521. }
  1522. this.Invalidate();
  1523. }
  1524. /// <summary>
  1525. /// 根据传入的颗粒状态,来获取所有该颗粒状态下的数据,用来测试统计使用
  1526. /// </summary>
  1527. /// <param name="str_particlestate"></param>
  1528. /// <returns></returns>
  1529. public int GetParticleNumberByState(PaintState in_ParticleState)
  1530. {
  1531. int icount = 0;
  1532. foreach (DisplayParticle ls_dp in m_list_allDPart)
  1533. {
  1534. if (ls_dp.GetPaintState() == in_ParticleState)
  1535. {
  1536. icount++;
  1537. }
  1538. }
  1539. return icount;
  1540. }
  1541. /// <summary>
  1542. /// 获取所有原图
  1543. /// </summary>
  1544. /// <param name="args"></param>
  1545. /// <returns></returns>
  1546. private void GetPic(PaintEventArgs args)
  1547. {
  1548. //outpic();
  1549. foreach (var f in m_list_allDfield)
  1550. {
  1551. var curfldrec = f.Current_Rect;
  1552. if (curfldrec.Left > -1000 && curfldrec.Right < this.Width + 1000 && curfldrec.Top > -1000 && curfldrec.Bottom < this.Height + 1000)
  1553. {
  1554. args.Graphics.DrawImage(f.OriginalImage, f.Current_Rect.X, f.Current_Rect.Y, f.Current_Rect.Width, f.Current_Rect.Height);
  1555. Graphics g = args.Graphics;
  1556. for (int i = 0; i < f.List_DParticle.Count; i++)
  1557. {
  1558. PointF xrayPos = new PointF(f.List_DParticle[i].objParticleData.PosX, f.List_DParticle[i].objParticleData.PosY);
  1559. PointF p = new PointF(xrayPos.X / f.OriginalImage.Width*f.Current_Rect.Width+f.Current_Rect.X, xrayPos.Y / f.OriginalImage.Height* f.Current_Rect.Height+f.Current_Rect.Y);
  1560. g.DrawString("+", new Font("黑体", 6), new SolidBrush(Color.Red), p);
  1561. }
  1562. }
  1563. }
  1564. }
  1565. #endregion
  1566. private static byte[] ImgtoByte(Image img)
  1567. {
  1568. MemoryStream ms = new MemoryStream();
  1569. byte[] imagedata = null;
  1570. img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
  1571. imagedata = ms.GetBuffer();
  1572. return imagedata;
  1573. }
  1574. private static Image BytesToImage(byte[] buffer)
  1575. {
  1576. MemoryStream ms = new MemoryStream(buffer);
  1577. Image image = System.Drawing.Image.FromStream(ms);
  1578. return image;
  1579. }
  1580. #region Debug下执行的辅助测试代码
  1581. private void Control_DrawDistrbutionImageAndBSE_MouseDoubleClick(object sender, MouseEventArgs e)
  1582. {
  1583. #if DEBUG
  1584. Screen[] screens = Screen.AllScreens;
  1585. string ls_str = "";
  1586. for (int i = 0; i < screens.Count(); i++)
  1587. {
  1588. ls_str = ls_str + "显示器" + (i + 1).ToString() + " 名称:" + screens[i].DeviceName + Environment.NewLine +
  1589. "显示器" + (i + 1).ToString() + " 是否主要显示器:" + screens[i].Primary + Environment.NewLine +
  1590. "显示器" + (i + 1).ToString() + " WorkingArea:" + screens[i].WorkingArea + Environment.NewLine +
  1591. "显示器" + (i + 1).ToString() + " Bounds:" + screens[i].Bounds + Environment.NewLine +
  1592. "显示器" + (i + 1).ToString() + " 色深:" + screens[i].BitsPerPixel + Environment.NewLine;
  1593. }
  1594. MessageBox.Show("------------------该段代码主要用来测试程序---------------------" + Environment.NewLine +
  1595. //"当前窗体X:" + this.ParentForm.Location.X.ToString() + " Y:" + this.ParentForm.Location.Y.ToString() + Environment.NewLine +
  1596. "显示器数量" + Screen.AllScreens.Count().ToString() + Environment.NewLine +
  1597. ls_str +
  1598. "DESKTOP.Width:" + MyPrimaryScreen.DESKTOP.Width + " DESKTOP.Height:" + MyPrimaryScreen.DESKTOP.Height + Environment.NewLine +
  1599. "DpiX:" + MyPrimaryScreen.DpiX + " DpiY:" + MyPrimaryScreen.DpiY + Environment.NewLine +
  1600. "ScaleX:" + MyPrimaryScreen.ScaleX + " ScaleY:" + MyPrimaryScreen.ScaleY + Environment.NewLine +
  1601. "WorkingArea.Width:" + MyPrimaryScreen.WorkingArea.Width + " WorkingArea.Height:" + MyPrimaryScreen.WorkingArea.Height + Environment.NewLine +
  1602. "this.Width:" + this.Width + " this.Height:" + this.Height + Environment.NewLine +
  1603. "单像素比:" + m_pixelSize.ToString() + Environment.NewLine +
  1604. "缩放倍数:" + m_zoom_record.ToString() + Environment.NewLine +
  1605. "屏幕像素backrectf x:" + m_backRect.X.ToString() + " y:" + m_backRect.Y.ToString() + " width:" + m_backRect.Width.ToString() + " height:" + m_backRect.Height.ToString() + Environment.NewLine +
  1606. "屏幕像素oldbackrectf x:" + m_old_backRect.X.ToString() + " y:" + m_old_backRect.Y.ToString() + " width:" + m_old_backRect.Width.ToString() + " height:" + m_old_backRect.Height.ToString() + Environment.NewLine +
  1607. "物理像素back_wl_rectf x:" + m_back_wl_rectf.X.ToString() + " y:" + m_back_wl_rectf.Y.ToString() + " width:" + m_back_wl_rectf.Width.ToString() + " height:" + m_back_wl_rectf.Height.ToString() + Environment.NewLine +
  1608. //"单个Field视域屏幕像素宽:" + m_OneField_Screen_BackRectf.Width.ToString() + " 高:" + m_OneField_Screen_BackRectf.Height.ToString() + Environment.NewLine +
  1609. //"单个OTS视域屏幕像素宽:" + m_OneField_OTS_Rect.Width.ToString() + " 高:" + m_OneField_OTS_Rect.Height.ToString() + Environment.NewLine +
  1610. "屏幕像素backrectf x:" + m_backRect.X.ToString() + " y:" + m_backRect.Y.ToString() + " width:" + m_backRect.Width.ToString() + " height:" + m_backRect.Height.ToString() + Environment.NewLine +
  1611. "包含Field数量:" + ReportFun.m_field_count.ToString() + " Particle数量:" + ReportFun.m_particle_count.ToString() + Environment.NewLine +
  1612. "正常显示Paticle数量:" + GetParticleNumberByState(PaintState.NORMALPAINT).ToString() + " 不显示Particel数量:" + GetParticleNumberByState(PaintState.NOPAINT).ToString() + Environment.NewLine +
  1613. //"删除Particle数量:" + GetParticleNumberByState("删除").ToString() + " 选中Particle数量:" + GetParticleNumberByState("选择").ToString() + Environment.NewLine +
  1614. "加载底层数据用时:" + ReportFun.m_time_str + Environment.NewLine +
  1615. "组建并计算图像用时:" + ReportFun.m_time_str2 + Environment.NewLine +
  1616. "---------------------------END----------------------------------"
  1617. );
  1618. #endif
  1619. }
  1620. #endregion
  1621. private void ExportoriginalspliceToolStripMenuItem_Click(object sender, EventArgs e)
  1622. {
  1623. SaveFileDialog sfd = new SaveFileDialog();
  1624. //|ALL Files(*.*)|*.*
  1625. //BMP Files(*.bmp)| *.bmp |
  1626. sfd.Filter = "png Files(*.png)| *.png |BMP Files(*.bmp)| *.bmp |JPG Files(*.jpg)|*.jpg;*.jpeg";
  1627. if (sfd.ShowDialog() == DialogResult.OK)
  1628. {
  1629. OutPIC outpic = new OutPIC();
  1630. outpic.m_list_allDfield = m_list_allDfield;
  1631. outpic.resultFile = resultFile;
  1632. outpic.sfd = sfd;
  1633. outpic.type = (int)Outpic_enum.Render_pic;
  1634. Thread bThread = new Thread(new ThreadStart(outpic.opencv_outpic));
  1635. bThread.IsBackground = true;
  1636. bThread.Start();
  1637. }
  1638. }
  1639. private void ToolStripMenuItemDelete_Particle_Click(object sender, EventArgs e)
  1640. {
  1641. DialogResult dr = MessageBox.Show("Should I delete particles", "Tips", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  1642. if (dr== DialogResult.OK)
  1643. {
  1644. if (ReportFun.DeleteParticlesFromLibrary(m_mouseOver_dparticle.ParticleId, m_mouseOver_dparticle.FieldId))
  1645. {
  1646. MessageBox.Show("Deleted successfully");
  1647. m_mouseOver_dparticle.IsDeleted=true;
  1648. //FieldData fieldData = new FieldData(resultFile.FilePath);
  1649. //List<Field> fieldlist = fieldData.GetFieldList();
  1650. //m_ReportApp.m_rstDataMgr.CurResultFile.List_OTSField = fieldlist;
  1651. //LoadUpdateDisplay();
  1652. }
  1653. else
  1654. {
  1655. MessageBox.Show("Delete failed");
  1656. }
  1657. }
  1658. else
  1659. {
  1660. return;
  1661. }
  1662. }
  1663. }
  1664. }