Control_DrawDistrbutionImageAndBSE.cs 77 KB

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