Control_DrawDistrbutionSortImage.cs 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107
  1. using OTSIncAReportApp.DataOperation.DataAccess;
  2. using OTSIncAReportApp.DataOperation.Model;
  3. using OTSIncAReportApp.OTSSampleReportInfo;
  4. using OTSIncAReportApp.SysMgrTools;
  5. using OTSIncAReportGraph.Class;
  6. using OTSIncAReportGraph.OTSIncAReportGraphFuncation;
  7. using OTSIncAReportMailInterface;
  8. using OTSPeriodicTable;
  9. using System;
  10. using System.Collections;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Drawing;
  14. using System.Drawing.Drawing2D;
  15. using System.Linq;
  16. using System.Threading;
  17. using System.Windows.Forms;
  18. namespace OTSIncAReportGraph.Controls
  19. {
  20. public enum ParticleClassifyType
  21. {
  22. MaterialType=0,
  23. SizeType=1
  24. }
  25. public partial class Control_DrawDistrbutionSortImage : UserControl
  26. {
  27. #region 变量定义
  28. //这里要做成控件,不要是窗体
  29. public List<BaseObject> m_list_baseobject = null;
  30. //多边形的分栏,list
  31. public List<SortParticleDistribution> m_list_sortparticledistribution = null;
  32. //多边形的分栏list,的原先值,用于缩放拖动等计算使用
  33. public List<SortParticleDistribution> m_old_list_sortparticledistribution = null;
  34. //记录操作记录类
  35. List<HistoryApolygon> m_list_historyapolygon = null;
  36. //操作历史类,当前操作到的id
  37. private int m_operator_currentid = 0;
  38. //背景矩形
  39. private RectangleF m_backrectf = new RectangleF();
  40. //记录原值,背景矩形
  41. private RectangleF m_old_backrectf = new RectangleF();
  42. //单一Field视域,屏幕像素的宽高
  43. public RectangleF m_OneField_Screen_BackRectf = new RectangleF();
  44. //单一Field视域,OTS物理像素的宽高
  45. public RectangleF m_OneField_OTS_Rectf = new RectangleF();
  46. //是否使用矩形进行多选操作
  47. private bool m_is_multiselect_rectangle = false;
  48. //是否使用圆形进行多选操作
  49. private bool m_is_multiselect_ellipse = false;
  50. //是否可以进行绘制,提供给矩形多选与圆形多选使用的临时变量
  51. private bool m_is_multiselect_onpaint = false;
  52. //进行选择的矩形范围
  53. private RectangleF m_multiselect_rect = new RectangleF();
  54. //在进行拖选前鼠标记录的点
  55. private PointF m_beforemultiselect_point = new PointF();
  56. //是否拖动
  57. private bool m_isDrag = false;
  58. //拖动前的坐标记录
  59. private PointF m_beforedrag_pointf = new PointF();
  60. //记录鼠标拖选完成后形成的路径
  61. private GraphicsPath m_selectmulti_gpath = new GraphicsPath();
  62. //缩放的增大缩小的增量
  63. private float m_f_zoom_increment = 0.1f;
  64. //缩放的基数,临时变量
  65. private float m_f_widthandheight_js = 0;
  66. //与原先缩放的记录数
  67. public float m_f_zoom_record = 1;
  68. private float m_f_zoom_max;
  69. private float m_f_zoom_mix;
  70. //标尺的大小记录
  71. public float m_f_ruler_size = 100;
  72. //标尺原先大小的记录,参与计算
  73. private float m_f_old_ruler_size = 100;
  74. //每像素代表的尺寸大小,还不知道在哪里进行计算
  75. public float m_pixelSize = 4.5f;
  76. //提供鼠标在右下角显示的文本,左侧
  77. private string m_str_mouseshow_left = "";
  78. //提供鼠标在右下角显示的文本,右侧
  79. private string m_str_mouseshow_right = "";
  80. //分栏网格边框的颜色
  81. private Color m_c_ColumnRectangleColor = Color.LightSteelBlue;
  82. //底层封装类
  83. OTSIncAReportFun m_ReportFun = null;
  84. //鼠标移动经过的颗粒对象,临时存放,用来记录是否要显示xray与隐藏xray
  85. DisplayParticle m_move_dparticle = null;
  86. //保存数据源名称
  87. private string m_showsourcename = "";
  88. //保存数据源的ID
  89. private int m_datasourceid = 0;
  90. //记录当前鼠标位置对应SEM电镜的位置
  91. Point m_sem_mouse_now_point = new Point();
  92. //移动SEM到指定位置发生线程
  93. private Thread m_mythread;
  94. //记录线程是否已经运行完成的状态
  95. private bool m_mythread_state = false;
  96. private bool m_CtrlKeyDown = false;
  97. /// <summary>
  98. /// 当前正在显示的数据源名称,用来与框架调用条件判断使用
  99. /// </summary>
  100. public string ShowSourceName
  101. {
  102. set { m_showsourcename = value; }
  103. get { return m_showsourcename; }
  104. }
  105. /// <summary>
  106. /// 当前正在显示的数据源ID
  107. /// </summary>
  108. public int DataSourceID
  109. {
  110. set { m_datasourceid = value; }
  111. get { return m_datasourceid; }
  112. }
  113. /// <summary>
  114. /// 返回当前缩放的大小因数
  115. /// </summary>
  116. public float FZOOMRecord
  117. {
  118. get { return m_f_zoom_record; }
  119. set { m_f_zoom_record = value; }
  120. }
  121. //进度条窗体
  122. public Frm_UserProgress m_frm_userprogress;
  123. /// <summary>
  124. /// 是否显示过小颗粒
  125. /// </summary>
  126. public bool bShowSmallParticle = false;
  127. ReportCondition m_list_cgriddataclr = null;
  128. public OTSIncAReportApp.frmReportApp m_ReportApp;
  129. //国际化存储信息
  130. Hashtable resourceTable;
  131. ResultFile resultFile = null;
  132. #endregion
  133. #region 构造函数及窗体加载
  134. /// <summary>
  135. /// 排序图构造函数
  136. /// </summary>
  137. /// <param name="in_sec">传入,委托类对象</param>
  138. /// <param name="in_Cotsreportprojfilemgrclr">传入,项目管理类对象</param>
  139. /// <param name="in_cotsreportprojfileclr">传入,项目类对象</param>
  140. /// <param name="in_csmplmsrresultfilemgrclr">传入,文件管理类对象</param>
  141. /// <param name="in_csmplmsrresultfileclr">传入,文件类对象</param>
  142. public Control_DrawDistrbutionSortImage(OTSIncAReportApp.frmReportApp ReportApp)
  143. {
  144. m_list_baseobject = new List<BaseObject>();
  145. m_list_historyapolygon = new List<HistoryApolygon>();
  146. m_list_sortparticledistribution = new List<SortParticleDistribution>();
  147. m_old_list_sortparticledistribution = new List<SortParticleDistribution>();
  148. m_mythread_state = false;
  149. m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
  150. m_frm_userprogress = new Frm_UserProgress();
  151. m_ReportApp = ReportApp;
  152. resultFile = m_ReportApp.m_DataMgrFun.resultFilesList[m_ReportApp.m_DataMgrFun.WorkingResult];
  153. //初始化底层操作类
  154. m_ReportFun = new OTSIncAReportFun( resultFile);
  155. InitializeComponent();
  156. #region 国际化语言
  157. Language stringResource = new Language(this);
  158. resourceTable = stringResource.GetNameTable(this.Name);
  159. #endregion
  160. }
  161. private void Control_DrawDistrbutionSortImage_Load(object sender, EventArgs e)
  162. {
  163. //向父窗体注册键盘按键事件
  164. this.Parent.KeyDown += new KeyEventHandler(Control_DrawDistrbutionSortImage_KeyDown);
  165. this.Parent.KeyUp += new KeyEventHandler(Control_DrawDistrbutionSortImage_KeyUp);
  166. control_Ruler1 = new Control_Ruler();
  167. control_XRayTable1 = new Control_XRayTable();
  168. //设置鼠标为等待样式
  169. //m_sec.SendCall("设置鼠标样式", "", "WaitCursor");
  170. //显示进度条,计算进度条应该显示的位置和宽度
  171. Form ls_main_form = this.ParentForm.ParentForm;//取出父窗体
  172. m_frm_userprogress.Width = (int)(MyPrimaryScreen.DESKTOP.Width / MyPrimaryScreen.ScaleX * 0.9);
  173. m_frm_userprogress.Location = new Point(ls_main_form.Location.X + 80, ls_main_form.Location.Y + (int)(MyPrimaryScreen.DESKTOP.Height / MyPrimaryScreen.ScaleX) / 2);
  174. m_frm_userprogress.Show();
  175. m_frm_userprogress.SetProgressValueAndText(0, resourceTable["str1"].ToString());
  176. //调用填充排序图颗粒数据,总过程方法
  177. GetDistrbutionSortImage_Total();
  178. //设置双缓冲
  179. SetDoubleBufferByIsDraw();
  180. //设置标尺
  181. //根据f_onepixel_size计算出要显示出100um的实际宽度
  182. double d_onefixel_width = 100 / m_pixelSize;
  183. if (d_onefixel_width == 0)
  184. {
  185. this.control_Ruler1.Visible = false;
  186. }
  187. else
  188. {
  189. //将标尺定位到合理的位置上
  190. this.control_Ruler1.Location = new Point(10, MyPrimaryScreen.WorkingArea.Height - 300);
  191. this.control_Ruler1.Visible = true;
  192. this.control_Ruler1.SetValue(m_f_ruler_size, m_pixelSize);
  193. }
  194. //加载时将背景rect设置与整个窗体一边大小
  195. m_backrectf = this.ClientRectangle; //该背景大小并未与实际获得像素的进行关联,这里注意一下,回头观察是否需要改进掉
  196. m_old_backrectf = m_backrectf;
  197. //进入时首先对XRayTable进行隐藏
  198. control_XRayTable1.Visible = false;
  199. //设置鼠标为默认
  200. //m_sec.SendCall("设置鼠标样式", "", "Default");
  201. m_frm_userprogress.SetProgressValueAndText(100, resourceTable["str2"].ToString());
  202. //加载完成,关闭进度条
  203. m_frm_userprogress.Close();
  204. }
  205. /// <summary>
  206. /// 排序图获取底层数据,组建整张排序图的总方法过程
  207. /// </summary>
  208. public void GetDistrbutionSortImage_Total()
  209. {
  210. string str48 = "begin to load data....";
  211. //str48 = table["str48"].ToString();
  212. m_frm_userprogress.SetProgressValueAndText(1, str48);
  213. string path = resultFile.FilePath;
  214. FieldData fieldData = new FieldData(path);
  215. List<Field> fieldlist=new List<Field>();
  216. if (m_ReportFun.m_list_OTSField.Count == 0)
  217. {
  218. fieldlist = fieldData.GetFieldList();
  219. m_ReportFun.m_list_OTSField = fieldlist;
  220. }
  221. //将field的list对象给全局变量中,供后面获取xray使用
  222. string str49 = "begin to composit image....";
  223. //str49 = table["str49"].ToString();
  224. m_frm_userprogress.SetProgressValueAndText(15, str49);
  225. //第一次,用来计算,总大小等,获取Field的坐标,id,同时获取对应的ImgClr里的宽高,图像大小
  226. List<Point> list_point = new List<Point>();
  227. int i_field_width = 0, i_field_height = 0;
  228. //获取到该field的分辨率大小,循环中都是一样的
  229. if (fieldlist.Count > 0)
  230. {
  231. Bitmap bitmp = DrawFunction.ReadImageFile(fieldlist[0].FieldImage);
  232. i_field_width = bitmp.Width;
  233. i_field_height = bitmp.Height;
  234. }
  235. for (int i = 0; i < fieldlist.Count(); i++)
  236. {
  237. //然后取出物理坐标,这个一会要与分辨率坐标进行变算一下
  238. Point ls_point = new Point() { X = fieldlist[i].FieldPosX, Y = fieldlist[i].FieldPosY };
  239. list_point.Add(ls_point);
  240. }
  241. //对单个Field视域的屏幕像素宽高,进行记录
  242. m_OneField_Screen_BackRectf = new RectangleF(0, 0, i_field_width, i_field_height);
  243. //获取单个OTS视域像素宽高,并进行记录
  244. RectangleF OTS_FieldRect = m_ReportFun.GetPhysicalFieldWidthAndHeight(list_point,i_field_width,i_field_height);
  245. m_OneField_OTS_Rectf = OTS_FieldRect;
  246. string str50 = "calculate ruler....";
  247. //str50 = table["str50"].ToString();
  248. m_frm_userprogress.SetProgressValueAndText(18, str50);
  249. #region //标尺相关------------------------------------------------------------------------------
  250. //在此处通过上面的i_field_width,ifield_height和list_point,来计算出个像素与实际物理值的比例
  251. RectangleF ls_jsblrect = m_ReportFun.GetPhysicalFieldWidthAndHeight(list_point,i_field_width,i_field_height);
  252. //然后用宽度来除以i_field_width 获取单个的像素比例
  253. double d_onepixel_scale = Convert.ToDouble(ls_jsblrect.Width) / Convert.ToDouble(i_field_width);
  254. //再用该比例对标尺进行相应的赋值
  255. m_pixelSize = (float)d_onepixel_scale;
  256. #endregion //---------------------------------------------------------------------------------------
  257. string str51 = "build the whole image....";
  258. m_frm_userprogress.SetProgressValueAndText(20, str51);
  259. //70的进度条给到下面的循环中
  260. float ls_int_progresscalc = 0;
  261. if (fieldlist.Count > 0)
  262. ls_int_progresscalc = (float)80 / (float)fieldlist.Count;
  263. string str52 = "Finished";
  264. string str53 = "total";
  265. string str54 = "...";
  266. var otsLeftBottomPoint = m_ReportFun.GetPhysicalCoordLeftBottomPoint(list_point);
  267. //var physicalFldRect = m_ReportFun.GetPhysicalFieldWidthAndHeight(list_point,i_field_width,i_field_height);
  268. //var pixelSize =Convert.ToDouble( physicalFldRect.Width) / i_field_width;
  269. //第二次,再通过Field取到对应的Particle,循环一次
  270. for (int i = 0; i < fieldlist.Count(); i++)
  271. {
  272. m_frm_userprogress.SetProgressValueAndText(20 + (int)(ls_int_progresscalc * (i + 1)), str52 + i.ToString() + str53 + m_ReportFun.m_list_OTSField.Count.ToString() + str54);
  273. //先获取该field中的所有particle
  274. List<Particle> list_part = new List<Particle>();
  275. list_part = fieldlist[i].ParticleList;
  276. Point thisfield_point = new Point() { X = fieldlist[i].FieldPosX, Y = fieldlist[i].FieldPosY };
  277. //取出该Field中,从物理坐标转换到像素坐标后.不知道该算法是否可靠,先进行测试判断
  278. Point offset_point =m_ReportFun.ConvertPhysicalCoordinateToScreenCoord(otsLeftBottomPoint, m_pixelSize, thisfield_point);
  279. //然后将取出的数据,转换成Bitmap对象
  280. Bitmap ls_bt = DrawFunction.ReadImageFile(fieldlist[i].FieldImage);
  281. //再循环取出所有的particle
  282. foreach (Particle part in list_part)
  283. {
  284. List<Segment> list_segment = new List<Segment>();
  285. list_segment = part.SegmentList;
  286. //创建颗粒分布图对应的类对象
  287. List<DisplaySegment> list_dsegment = new List<DisplaySegment>();
  288. //定义particle颗粒,并获取该颗粒与标准库中对应的颜色
  289. DisplayParticle ls_dp = new DisplayParticle(part);
  290. //再循环取出里面所有的segment
  291. foreach (Segment seg in list_segment)
  292. {
  293. //这里的坐标未转换
  294. DisplaySegment ds = new DisplaySegment();
  295. ds.Rect = new Rectangle(seg.Start + offset_point.X,
  296. seg.Height + offset_point.Y,
  297. seg.Length,
  298. 1);
  299. //合成图像完成,开始抠取像素---------------------为显示BSE原图而用--------------------------------------------
  300. int i_ls_length = seg.Length;
  301. List<Color> ls_list_colors = new List<Color>();
  302. for (int m = 0; m < i_ls_length; m++)
  303. {
  304. //这里实现一下代码保护
  305. int lsjs_x = seg.Start + m;
  306. int lsjs_y = seg.Height;
  307. if (lsjs_x < 0)
  308. lsjs_x = 0;
  309. if (lsjs_x >= i_field_width)
  310. lsjs_x = i_field_width - 1;
  311. if (lsjs_y < 0)
  312. lsjs_y = 0;
  313. if (lsjs_y >= i_field_height)
  314. lsjs_y = i_field_height - 1;
  315. //按理说这里应该加上个横向抠取像素颜色,这里需要再处理一下
  316. ls_list_colors.Add(ls_bt.GetPixel(lsjs_x,
  317. lsjs_y));
  318. }
  319. //---------------------------------------------存入标准库相关的信息------------------------------------------------
  320. ds.Color = ls_dp.Color;//将线的颜色对应到颗粒的颜色
  321. //------------------------------------------------------------------------------------------------------
  322. ds.List_Colors = ls_list_colors;
  323. list_dsegment.Add(ds);
  324. }
  325. ls_dp.displayState = DisplayState.NORMALDISPLAY;
  326. ls_dp.DSegments = list_dsegment; //将segment对应的设置到particle中
  327. //并对DParticle相关信息进行计算
  328. ls_dp.Rect = ls_dp.GetRectFromDSegment();
  329. ls_dp.GPath = ls_dp.GetRegionFromDSegments();
  330. ls_dp.SmallRect = ls_dp.GetSmallRectangleFromRect();
  331. //将每个颗粒添加到颗粒分布图中的列表中
  332. m_list_baseobject.Add(ls_dp);
  333. }
  334. }
  335. }
  336. /// <summary>
  337. /// 根据颗粒排序图获取已经选择上的颗粒,返回被选择上的颗粒的列表
  338. /// </summary>
  339. /// <returns></returns>
  340. public List<Particle> GetSelectedParticleList_ForDrawDistrbutionSortImage()
  341. {
  342. List<Particle> ls_list_cotsparticleclr = new List<Particle>();
  343. //防止为空校验判断
  344. if (m_ReportFun.m_list_OTSField == null)
  345. {
  346. return ls_list_cotsparticleclr;
  347. }
  348. //先取出,所有被选择的dparticle列表的
  349. List<DisplayParticle> ls_list_dp = new List<DisplayParticle>();
  350. foreach (SortParticleDistribution spd in m_list_sortparticledistribution)
  351. {
  352. foreach (DisplayParticle ls_dp in spd.List_DParticle)
  353. {
  354. if (ls_dp.IsSelect)
  355. {
  356. ls_list_dp.Add(ls_dp);
  357. }
  358. }
  359. }
  360. //并开始查找包含tagid和fieldid的cotsparticle的对象,保存到list当中
  361. for (int i = 0; i < ls_list_dp.Count(); i++)
  362. {
  363. for (int j = 0; j < m_ReportFun.m_list_OTSField.Count(); j++)
  364. {
  365. //先获取该field中的所有particle
  366. List<Particle> list_cotsparticleclr = new List<Particle>();
  367. list_cotsparticleclr = m_ReportFun.m_list_OTSField[j].ParticleList;
  368. for (int k = 0; k < list_cotsparticleclr.Count(); k++)
  369. {
  370. if (list_cotsparticleclr[k].ParticleId == ls_list_dp[i].ParticleId
  371. && list_cotsparticleclr[k].FieldId == ls_list_dp[i].FieldId)
  372. {
  373. //将cotsparticleclr保存到list当中
  374. ls_list_cotsparticleclr.Add(list_cotsparticleclr[k]);
  375. }
  376. }
  377. }
  378. }
  379. return ls_list_cotsparticleclr;
  380. }
  381. #endregion
  382. #region 获取数据及初始化数据等
  383. private void ClassifyDParticleGrid()
  384. {
  385. //-------------------这里开始对分布图的颗粒信息,位置大小等重新进行计算-----------------------------------------------------
  386. //初始化分栏的大小,及多少个分栏。
  387. //模拟数据,分别将<=1和>1 and <=2和 >2 and <=3的颗粒数据分成三组,进行显示
  388. SortParticleDistribution sortparticledistribution = new SortParticleDistribution();
  389. sortparticledistribution.RectF = new RectangleF(this.ClientRectangle.X, this.ClientRectangle.Y, 800, this.ClientRectangle.Height);
  390. sortparticledistribution.ShowStr = "AAAA的颗粒[尺寸<=1的颗粒]";
  391. sortparticledistribution.Size_Min = 0;
  392. sortparticledistribution.Size_Max = 1;
  393. SortParticleDistribution sortparticledistribution2 = new SortParticleDistribution();
  394. sortparticledistribution2.RectF = new RectangleF(this.ClientRectangle.X, this.ClientRectangle.Y, 800, this.ClientRectangle.Height);
  395. sortparticledistribution2.ShowStr = "BBBBB的颗粒[尺寸<2的颗粒]";
  396. sortparticledistribution2.Size_Min = 0;
  397. sortparticledistribution2.Size_Max = 1;
  398. SortParticleDistribution sortparticledistribution3 = new SortParticleDistribution();
  399. sortparticledistribution3.RectF = new RectangleF(this.ClientRectangle.X, this.ClientRectangle.Y, 800, this.ClientRectangle.Height);
  400. sortparticledistribution3.ShowStr = "CCCCC的颗粒[尺寸<3的颗粒]";
  401. sortparticledistribution3.Size_Min = 0;
  402. sortparticledistribution3.Size_Max = 1;
  403. //筛选并进行装载
  404. foreach (DisplayParticle ls_dp in m_list_baseobject)
  405. {
  406. if (ls_dp.Zoom_DisPlayThreshold <= 1f)
  407. {
  408. DisplayParticle sort_dp = ls_dp.Clone() as DisplayParticle;
  409. sort_dp.Rect = sort_dp.GetRectFromDSegment();
  410. sortparticledistribution.List_DParticle.Add(sort_dp);
  411. }
  412. if (ls_dp.Zoom_DisPlayThreshold > 1f && ls_dp.Zoom_DisPlayThreshold <= 1.5f)
  413. {
  414. DisplayParticle sort_dp = ls_dp.Clone() as DisplayParticle;
  415. sort_dp.Rect = sort_dp.GetRectFromDSegment();
  416. sortparticledistribution2.List_DParticle.Add(sort_dp);
  417. }
  418. if (ls_dp.Zoom_DisPlayThreshold > 1.5f && ls_dp.Zoom_DisPlayThreshold <= 2f)
  419. {
  420. DisplayParticle sort_dp = ls_dp.Clone() as DisplayParticle;
  421. sort_dp.Rect = sort_dp.GetRectFromDSegment();
  422. sortparticledistribution3.List_DParticle.Add(sort_dp);
  423. }
  424. }
  425. //这里计算每个Grid所在的坐标位置,第二个跟在第一个y轴下面,第三个跟在第二个y轴下面,依此类推
  426. sortparticledistribution.RectF = new RectangleF(sortparticledistribution.RectF.X,
  427. sortparticledistribution.RectF.Y,
  428. sortparticledistribution.RectF.Width,
  429. sortparticledistribution.GetSortGridHeight());
  430. sortparticledistribution2.RectF = new RectangleF(sortparticledistribution2.RectF.X,
  431. sortparticledistribution.RectF.Y + sortparticledistribution.RectF.Height + sortparticledistribution2.RectF.Y - 10,/*-5是为了分栏边框不开缝*/
  432. sortparticledistribution2.RectF.Width,
  433. sortparticledistribution2.GetSortGridHeight());
  434. sortparticledistribution3.RectF = new RectangleF(sortparticledistribution3.RectF.X,
  435. sortparticledistribution2.RectF.Y + sortparticledistribution2.RectF.Height + sortparticledistribution3.RectF.Y - 10,
  436. sortparticledistribution3.RectF.Width,
  437. sortparticledistribution3.GetSortGridHeight());
  438. m_list_sortparticledistribution.Clear();
  439. m_old_list_sortparticledistribution.Clear();
  440. m_list_sortparticledistribution.Add(sortparticledistribution);
  441. m_list_sortparticledistribution.Add(sortparticledistribution2);
  442. m_list_sortparticledistribution.Add(sortparticledistribution3);
  443. //分类完成后,对颗粒重新进行摆放,包括重新计算里面的线,和计算里面多边形的外矩形,+号位置等
  444. sortparticledistribution.SortDParticle(m_f_zoom_record);
  445. sortparticledistribution2.SortDParticle(m_f_zoom_record);
  446. sortparticledistribution3.SortDParticle(m_f_zoom_record);
  447. //记录原值,从这里继续,clone未完成
  448. foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution)
  449. {
  450. SortParticleDistribution old_sortparticledistribution = ls_sortparticledistribution.Clone() as SortParticleDistribution;
  451. m_old_list_sortparticledistribution.Add(old_sortparticledistribution);
  452. foreach (DisplayParticle ls_dp in old_sortparticledistribution.List_DParticle)
  453. {
  454. ls_dp.Rect = ls_dp.GetRectFromDSegment();
  455. }
  456. }
  457. //--------------------------------分类排序颗粒结束-----------------------------------------------------
  458. }
  459. /// <summary>
  460. /// 获取随机的颜色
  461. /// </summary>
  462. /// <returns></returns>
  463. public Color GetRandomColor()
  464. {
  465. int R = new Random((int)DateTime.Now.Ticks).Next(255);
  466. int G = new Random((int)DateTime.Now.Ticks).Next(255);
  467. int B = new Random((int)DateTime.Now.Ticks).Next(255);
  468. B = (R + G > 400) ? R + G - 400 : B;//0 : 380 - R - G;
  469. B = (B > 255) ? 255 : B;
  470. return Color.FromArgb(R, G, B);
  471. }
  472. /// <summary>
  473. /// 随机获取一个多边形
  474. /// </summary>
  475. /// <param name="x"></param>
  476. /// <param name="y"></param>
  477. /// <param name="width"></param>
  478. /// <param name="height"></param>
  479. /// <returns></returns>
  480. public DisplayParticle GetRondemDParticle(int x, int y, int width, int height, int r)
  481. {
  482. DisplayParticle ls_dp = new DisplayParticle();
  483. for (int i = 0; i < height; i++)
  484. {
  485. DisplaySegment ls_ds = new DisplaySegment();
  486. ls_ds.Color = GetRandomColor();
  487. //随机生成x坐标偏移,和宽度
  488. Random rd = new Random((int)DateTime.Now.Ticks);
  489. int a = rd.Next(1);
  490. if (a == 0)
  491. {
  492. int n = rd.Next(r);
  493. x = x + n;
  494. width = width + n;
  495. }
  496. else
  497. {
  498. int n = rd.Next(r);
  499. x = -+n;
  500. width = width - n;
  501. }
  502. ls_ds.Rect = new Rectangle(x, y + i, width, 1);//高度是1的线段
  503. ls_dp.DSegments.Add(ls_ds);
  504. }
  505. return ls_dp;
  506. }
  507. #endregion
  508. #region 设置双缓冲
  509. /// <summary>
  510. /// 设置双缓冲
  511. /// </summary>
  512. public void SetDoubleBufferByIsDraw()
  513. {
  514. SetStyle(ControlStyles.UserPaint, true);
  515. SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
  516. this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // 双缓冲
  517. SetStyle(ControlStyles.UserMouse, true);//执行自己的鼠标行为,这个打开后,在win7下鼠标操作明显改善
  518. }
  519. #endregion
  520. #region 绘制函数
  521. protected override void OnPaint(PaintEventArgs e)//处理重绘情况
  522. {
  523. #region //填充个背景色矩形-----------------------------------------------
  524. foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution)
  525. {
  526. SolidBrush b = new SolidBrush(Color.White);
  527. e.Graphics.FillRectangle(b, ls_sortparticledistribution.RectF);
  528. //绘制矩形的外边框
  529. ControlPaint.DrawBorder(e.Graphics, Rectangle.Round(ls_sortparticledistribution.RectF),
  530. m_c_ColumnRectangleColor,
  531. 3,
  532. ButtonBorderStyle.Solid,
  533. m_c_ColumnRectangleColor,
  534. 3,
  535. ButtonBorderStyle.Solid,
  536. m_c_ColumnRectangleColor,
  537. 3,
  538. ButtonBorderStyle.Solid,
  539. m_c_ColumnRectangleColor,
  540. 3,
  541. ButtonBorderStyle.Solid);
  542. }
  543. #endregion
  544. #region //计算并进行绘制部份------------------------------------
  545. //绘制完缩放的图形后,将基数变回,否则会一直刷新无限变大变小
  546. if (m_f_widthandheight_js != 0)
  547. {
  548. foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution)
  549. {
  550. //缩放完成,重新计算颗粒的矩形,和边缘路径,这里应该写成,判断 如果有进行了缩放的操作后,再进行重新的计算
  551. foreach (BaseObject item in ls_sortparticledistribution.List_DParticle)
  552. {
  553. DisplayParticle dp = (DisplayParticle)item;
  554. //获取矩形的rectangle
  555. dp.Rect = dp.GetRectFromDSegment();
  556. //通过line获取路径边缘
  557. dp.GPath = dp.GetRegionFromDSegments();
  558. //重新计算小矩形边框
  559. dp.SmallRect = dp.GetSmallRectangleFromRect();
  560. }
  561. }
  562. m_f_widthandheight_js = 0;
  563. }
  564. foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution)
  565. {
  566. //开始向下传递并进行绘制
  567. foreach (BaseObject item in ls_sortparticledistribution.List_DParticle)
  568. {
  569. DisplayParticle dp = (DisplayParticle)item;
  570. if (dp.IsDeleted==false)
  571. {
  572. if (dp.displayState == DisplayState.NORMALDISPLAY)
  573. {
  574. item.OnPaint(e);
  575. }
  576. }
  577. }
  578. }
  579. #endregion
  580. #region //判断是否使用了矩形或圆形工具进行多选,是的话,那么这里就开始绘制------------------------
  581. if (true == m_is_multiselect_onpaint)
  582. {
  583. if (true == m_is_multiselect_rectangle && m_multiselect_rect.Width > 0 && m_multiselect_rect.Height > 0)
  584. {
  585. Graphics g = e.Graphics;
  586. //绘制矩形
  587. g.DrawRectangle(new Pen(Color.Blue), m_multiselect_rect.X, m_multiselect_rect.Y, m_multiselect_rect.Width, m_multiselect_rect.Height);
  588. //半透明画刷
  589. SolidBrush brush = new SolidBrush(Color.FromArgb(50, Color.SkyBlue));
  590. //填充选择矩形
  591. g.FillRectangle(brush, m_multiselect_rect.X, m_multiselect_rect.Y, m_multiselect_rect.Width, m_multiselect_rect.Height);
  592. }
  593. if (true == m_is_multiselect_ellipse && m_multiselect_rect.Width > 0 && m_multiselect_rect.Height > 0)
  594. {
  595. Graphics g = e.Graphics;
  596. //绘制圆形
  597. g.DrawEllipse(new Pen(Color.Blue), m_multiselect_rect.X, m_multiselect_rect.Y, m_multiselect_rect.Width, m_multiselect_rect.Height);
  598. //半透明画刷
  599. SolidBrush brush = new SolidBrush(Color.FromArgb(50, Color.SkyBlue));
  600. //填充选择圆形
  601. g.FillEllipse(brush, m_multiselect_rect.X, m_multiselect_rect.Y, m_multiselect_rect.Width, m_multiselect_rect.Height);
  602. }
  603. }
  604. #endregion
  605. #region 分栏Grid的标签文本透明文字实现
  606. foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution)
  607. {
  608. SolidBrush b = new SolidBrush(Color.White);
  609. string str_show = ls_sortparticledistribution.ShowStr;
  610. SizeF sif = e.Graphics.MeasureString(str_show, new Font("宋体", 9));
  611. e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(125, m_c_ColumnRectangleColor)), ls_sortparticledistribution.RectF.X + ls_sortparticledistribution.RectF.Width - sif.Width - 3, ls_sortparticledistribution.RectF.Y, sif.Width, sif.Height + 3);
  612. e.Graphics.DrawString(str_show, new Font("宋体", 9), new SolidBrush(Color.Black), ls_sortparticledistribution.RectF.X + ls_sortparticledistribution.RectF.Width - sif.Width - 3, ls_sortparticledistribution.RectF.Y + 3);
  613. }
  614. #endregion
  615. }
  616. #endregion
  617. #region 鼠标操作相关事件
  618. protected override void OnMouseWheel(MouseEventArgs e)
  619. {
  620. if (m_CtrlKeyDown == true)
  621. {
  622. if (e.Delta > 0)
  623. {
  624. ZoomIn();
  625. }
  626. else
  627. {
  628. ZoomOut();
  629. }
  630. }
  631. else
  632. {
  633. foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution)
  634. {
  635. foreach (BaseObject item in ls_sortparticledistribution.List_DParticle)
  636. {
  637. DisplayParticle dp = (DisplayParticle)item;
  638. foreach (DisplaySegment ds in dp.DSegments)
  639. {
  640. ds.Rect = new RectangleF(
  641. ds.Rect.X, //获取到原先点与移动点的增减量,+原先的x坐标,就是新的坐标
  642. ds.Rect.Y + e.Delta / 2,
  643. ds.Rect.Width,
  644. ds.Rect.Height);
  645. }
  646. //获取矩形的rectangle
  647. dp.Rect = dp.GetRectFromDSegment();
  648. if (dp.Rect.Left < -60 || dp.Rect.Right > this.Width +60|| dp.Rect.Top < -60 || dp.Rect.Bottom > this.Height+60)
  649. {
  650. dp.displayState = DisplayState.NODISPLAY;
  651. }
  652. else
  653. {
  654. dp.displayState = DisplayState.NORMALDISPLAY;
  655. }
  656. }
  657. }
  658. foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution)
  659. {
  660. ls_sortparticledistribution.RectF = new RectangleF(ls_sortparticledistribution.RectF.Location.X,
  661. ls_sortparticledistribution.RectF.Location.Y + e.Delta / 2, ls_sortparticledistribution.RectF.Width, ls_sortparticledistribution.RectF.Height);
  662. }
  663. }
  664. Invalidate();
  665. }
  666. /// <summary>
  667. /// 放大
  668. /// </summary>
  669. private void ZoomIn()
  670. {
  671. #region //图形缩放计算部份-------放大------------//是放大
  672. m_f_widthandheight_js = m_f_zoom_increment;
  673. for (int x = 0; x < m_list_sortparticledistribution.Count(); x++)
  674. {
  675. SortParticleDistribution ls_sortparticledistribution = m_list_sortparticledistribution[x];
  676. SortParticleDistribution old_ls_sortparticledstribution = m_old_list_sortparticledistribution[x];
  677. //先计算Grid的背景矩形
  678. ls_sortparticledistribution.RectF = new RectangleF(ls_sortparticledistribution.RectF.X + old_ls_sortparticledstribution.RectF.X * m_f_zoom_increment,
  679. ls_sortparticledistribution.RectF.Y + old_ls_sortparticledstribution.RectF.Y * m_f_zoom_increment,
  680. ls_sortparticledistribution.RectF.Width + Convert.ToInt32(old_ls_sortparticledstribution.RectF.Width * m_f_zoom_increment),
  681. ls_sortparticledistribution.RectF.Height + Convert.ToInt32(old_ls_sortparticledstribution.RectF.Height * m_f_zoom_increment));
  682. for (int y = 0; y < ls_sortparticledistribution.List_DParticle.Count(); y++)
  683. {
  684. DisplayParticle ls_dp = ls_sortparticledistribution.List_DParticle[y];
  685. DisplayParticle old_ls_dp = m_old_list_sortparticledistribution[x].List_DParticle[y];
  686. for (int z = 0; z < ls_dp.DSegments.Count(); z++)
  687. {
  688. DisplaySegment ds = ls_dp.DSegments[z];
  689. DisplaySegment old_ds = old_ls_dp.DSegments[z];
  690. ds.PenWidthAndHeight = ds.PenWidthAndHeight + old_ds.PenWidthAndHeight
  691. * m_f_zoom_increment;
  692. ds.Rect = new RectangleF(ds.Rect.X + old_ds.Rect.X * m_f_zoom_increment, ds.Rect.Y + old_ds.Rect.Y * m_f_zoom_increment,
  693. ds.Rect.Width + old_ds.Rect.Width * m_f_zoom_increment, ds.Rect.Height + old_ds.Rect.Height * m_f_zoom_increment);
  694. }
  695. //设置缩放到多少倍时进行显示
  696. if ( m_f_zoom_record>=ls_dp.Zoom_DisPlayThreshold)
  697. {
  698. ls_dp.displayState = DisplayState.NORMALDISPLAY;
  699. }
  700. else
  701. {
  702. ls_dp.displayState = DisplayState.CONCISEDISPLAY;
  703. }
  704. }
  705. }
  706. m_f_zoom_record = m_f_zoom_record + m_f_zoom_increment;
  707. m_f_zoom_record = float.Parse(m_f_zoom_record.ToString("#0.0")); //四舍五入,保留一位小数,如果不这样,float会不附合规则
  708. #endregion
  709. #region 计算标尺尺寸部份-----放大------
  710. m_f_ruler_size = m_f_ruler_size + Convert.ToInt32(m_f_old_ruler_size * m_f_zoom_increment);
  711. control_Ruler1.SetValue(m_f_ruler_size, m_pixelSize);
  712. #endregion
  713. }
  714. /// <summary>
  715. /// 缩小
  716. /// </summary>
  717. private void ZoomOut()
  718. {
  719. #region //图形缩放计算部份------缩小--------------------
  720. m_f_widthandheight_js = -m_f_zoom_increment;
  721. for (int x = 0; x < m_list_sortparticledistribution.Count(); x++)
  722. {
  723. SortParticleDistribution ls_sortparticledistribution = m_list_sortparticledistribution[x];
  724. SortParticleDistribution old_ls_sortparticledistribution = m_old_list_sortparticledistribution[x];
  725. //先计算Grid的背景矩形
  726. ls_sortparticledistribution.RectF = new RectangleF(ls_sortparticledistribution.RectF.X + old_ls_sortparticledistribution.RectF.X * -m_f_zoom_increment,
  727. ls_sortparticledistribution.RectF.Y + old_ls_sortparticledistribution.RectF.Y * -m_f_zoom_increment,
  728. ls_sortparticledistribution.RectF.Width + Convert.ToInt32(old_ls_sortparticledistribution.RectF.Width * -m_f_zoom_increment),
  729. ls_sortparticledistribution.RectF.Height + Convert.ToInt32(old_ls_sortparticledistribution.RectF.Height * -m_f_zoom_increment));
  730. for (int y = 0; y < ls_sortparticledistribution.List_DParticle.Count(); y++)
  731. {
  732. DisplayParticle ls_dp = ls_sortparticledistribution.List_DParticle[y];
  733. DisplayParticle old_ls_dp = m_old_list_sortparticledistribution[x].List_DParticle[y];
  734. for (int z = 0; z < ls_dp.DSegments.Count(); z++)
  735. {
  736. DisplaySegment ds = ls_dp.DSegments[z];
  737. DisplaySegment old_ds = old_ls_dp.DSegments[z];
  738. ds.PenWidthAndHeight = ds.PenWidthAndHeight + old_ds.PenWidthAndHeight
  739. * -m_f_zoom_increment;
  740. ds.Rect = new RectangleF(ds.Rect.X + old_ds.Rect.X * -m_f_zoom_increment, ds.Rect.Y + old_ds.Rect.Y * -m_f_zoom_increment,
  741. ds.Rect.Width + old_ds.Rect.Width * -m_f_zoom_increment, ds.Rect.Height + old_ds.Rect.Height * -m_f_zoom_increment);
  742. }
  743. //设置缩放到多少倍时进行显示
  744. if (m_f_zoom_record>=ls_dp.Zoom_DisPlayThreshold )
  745. {
  746. ls_dp.displayState = DisplayState.NORMALDISPLAY;
  747. }
  748. else
  749. {
  750. ls_dp.displayState = DisplayState.CONCISEDISPLAY;
  751. }
  752. }
  753. }
  754. m_f_zoom_record = m_f_zoom_record - m_f_zoom_increment;
  755. m_f_zoom_record = float.Parse(m_f_zoom_record.ToString("#0.0")); //四舍五入,保留一位小数,如果不这样,float会不附合规则
  756. #endregion
  757. #region 计算标尺尺寸部份-----缩小------f_onepixel_size,是不是该乘以rulerwidth是实际的长度
  758. m_f_ruler_size = m_f_ruler_size + Convert.ToInt32(m_f_old_ruler_size * -m_f_zoom_increment);
  759. control_Ruler1.SetValue(m_f_ruler_size, m_pixelSize);
  760. #endregion
  761. }
  762. private void Control_DrawDistrbutionSortImage_KeyDown(object sender, KeyEventArgs e)
  763. {
  764. //判断是否按下了ctrl键
  765. if (e.KeyCode == Keys.ControlKey)
  766. {
  767. m_CtrlKeyDown = true;
  768. }
  769. }
  770. private void Control_DrawDistrbutionSortImage_KeyUp(object sender, KeyEventArgs e)
  771. {
  772. //判断是否按下了ctrl键
  773. if (e.KeyCode == Keys.ControlKey)
  774. {
  775. m_CtrlKeyDown = false;
  776. }
  777. }
  778. protected override void OnMouseDown(MouseEventArgs e)
  779. {
  780. if (e.Button == MouseButtons.Left)
  781. {
  782. this.Cursor = Cursors.Hand;
  783. //是否可以按矩形进行选取,如果选择了矩形或圆形多选后
  784. if (true == m_is_multiselect_rectangle || true == m_is_multiselect_ellipse)
  785. {
  786. m_multiselect_rect.Width = 0;
  787. m_multiselect_rect.Height = 0;
  788. m_is_multiselect_onpaint = true;
  789. m_beforemultiselect_point = e.Location;
  790. }
  791. //在进行多选时,不让其拖动
  792. if (false == m_is_multiselect_onpaint)
  793. {
  794. foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution)
  795. {
  796. foreach (DisplayParticle ls_dp in ls_sortparticledistribution.List_DParticle)
  797. {
  798. ls_dp.IsDragging = true;
  799. ls_dp.DraggingPoint = e.Location;
  800. }
  801. }
  802. }
  803. m_isDrag = true;
  804. m_beforedrag_pointf = e.Location;
  805. }
  806. Invalidate();
  807. }
  808. protected override void OnMouseUp(MouseEventArgs e)
  809. {
  810. if (e.Button == MouseButtons.Left)
  811. {
  812. this.Cursor = Cursors.Default;
  813. //还原多选变量
  814. if (true == m_is_multiselect_onpaint)
  815. {
  816. //首先清除掉所有已经选择的项
  817. //foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution)
  818. //{
  819. // foreach (DisplayParticle dp in ls_sortparticledistribution.List_DParticle)
  820. // {
  821. // if (dp.IsSelect)
  822. // {
  823. // dp.Operator = ParticleOperator.DISPLAY;
  824. // }
  825. // }
  826. //}
  827. //然后在这里判断都有哪些颗粒所有的point点,是否在选取的图形graphicsPath闭合路径中
  828. //首先先将选取的图形填充成graphicsPath
  829. if (m_multiselect_rect.Width > 0 && m_multiselect_rect.Height > 0)
  830. {
  831. GraphicsPath ls_gpath = new GraphicsPath();
  832. ls_gpath.AddRectangle(m_multiselect_rect);
  833. foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution)
  834. {
  835. foreach (DisplayParticle dp in ls_sortparticledistribution.List_DParticle)
  836. {
  837. if (dp.displayState != DisplayState.NODISPLAY && dp.IsDeleted==true)//不显示的和删除状态的不让进行选择
  838. {
  839. PointF[] lspointf = dp.GPath.PathPoints;
  840. for (int i = 0; i < lspointf.Count(); i++)
  841. {
  842. if (true == m_ReportFun.WhetherInRange(dp, lspointf[i]))
  843. {
  844. //选择到了该路径,那么就选取该图像
  845. dp.IsSelect=true;
  846. }
  847. }
  848. }
  849. }
  850. }
  851. }
  852. //这里恢复默认值
  853. m_multiselect_rect.Width = 0;
  854. m_multiselect_rect.Height = 0;
  855. m_is_multiselect_onpaint = false;
  856. m_is_multiselect_ellipse = false;
  857. m_is_multiselect_rectangle = false;
  858. //将排列图选择的颗粒传送给报告框架中
  859. SelectParticleListSendToReportFrame();
  860. }
  861. //在进行多选时,不让其拖动
  862. if (false == m_is_multiselect_onpaint)
  863. {
  864. foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution)
  865. {
  866. foreach (BaseObject item in ls_sortparticledistribution.List_DParticle)
  867. {
  868. if (true == item.IsDragging)
  869. {
  870. item.IsSelect = false;
  871. item.IsDragging = false;
  872. item.DraggingPoint = Point.Empty;
  873. }
  874. }
  875. }
  876. m_isDrag = false;
  877. //在颗粒上点击,则对该颗粒附加显示x-ray的状态,同时将其它颗粒上显示x-ray的状态全部去掉。
  878. if (false == m_isDrag)
  879. {
  880. foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution)
  881. {
  882. foreach (DisplayParticle dp in ls_sortparticledistribution.List_DParticle)
  883. {
  884. PointF[] lspointf = dp.GPath.PathPoints;
  885. if (true ==m_ReportFun. WhetherInRange(dp, new Point(e.X, e.Y)))
  886. {
  887. //选择到了该路径,那么就选取该图像b
  888. dp.Operator_ShowXRay = ParticleOperatorShowXray.SELECTANDDISPLAYXRAY;
  889. }
  890. else
  891. {
  892. dp.Operator_ShowXRay = ParticleOperatorShowXray.NODISPLAY;
  893. }
  894. }
  895. }
  896. }
  897. }
  898. }
  899. //右键菜单控件
  900. CMenuStrip.Items[0].Tag = "";
  901. CMenuStrip.Items[0].Enabled = false;
  902. CMenuStrip.Items[1].Tag = "";
  903. CMenuStrip.Items[1].Enabled = false;
  904. CMenuStrip.Items[2].Tag = "";
  905. CMenuStrip.Items[2].Enabled = false;
  906. CMenuStrip.Items[3].Tag = "";
  907. CMenuStrip.Items[3].Enabled = false;
  908. CMenuStrip.Items[4].Tag = "";
  909. CMenuStrip.Items[4].Enabled = false;
  910. if (e.Button == MouseButtons.Right)
  911. {
  912. //这个判断右键菜单加在这里,也不知道对不对
  913. foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution)
  914. {
  915. foreach (BaseObject item in ls_sortparticledistribution.List_DParticle)
  916. {
  917. if (true == m_ReportFun.WhetherInRange((DisplayParticle)item, e.Location))
  918. {
  919. DisplayParticle dp = (DisplayParticle)item;
  920. if (dp.displayState == DisplayState.NORMALDISPLAY )
  921. {
  922. CMenuStrip.Items[0].Enabled = true;
  923. CMenuStrip.Items[0].Tag = dp;
  924. CMenuStrip.Items[1].Enabled = true;
  925. if (dp.IsSelect)
  926. {
  927. CMenuStrip.Items[1].Text = "取消颗粒选择";
  928. }
  929. else
  930. {
  931. CMenuStrip.Items[1].Text = "选择颗粒";
  932. }
  933. CMenuStrip.Items[2].Enabled = true;
  934. CMenuStrip.Items[3].Enabled = true;
  935. //线程未执行完成,则不让再进行选择,右键移动到SEM位置的菜单选项
  936. if (m_mythread_state == false)
  937. CMenuStrip.Items[4].Enabled = true;
  938. else
  939. CMenuStrip.Items[4].Enabled = false;
  940. m_sem_mouse_now_point = new Point(dp.SEMPosX, dp.SEMPosY);
  941. m_str_mouseshow_left = "颗粒SEM位置:" + dp.SEMPosX.ToString() + ":" + dp.SEMPosY.ToString();
  942. //获取颜色方法1,使用API来获取当前鼠标指向位置的颜色值-------------------------------------------
  943. Graphics g = Graphics.FromHwnd(this.Handle);
  944. IntPtr hdc = g.GetHdc();
  945. uint u_color = 0;
  946. try
  947. {
  948. u_color = DrawFunction.GetPixel(hdc, e.X, e.Y);
  949. }
  950. catch
  951. { }
  952. Color ls_c = Color.FromArgb
  953. (
  954. (int)(u_color << 24 >> 24),
  955. (int)(u_color << 16 >> 24),
  956. (int)(u_color << 8 >> 24)
  957. );
  958. m_str_mouseshow_right = "灰度#" + ls_c.R.ToString();
  959. // 这里发送消息
  960. m_ReportApp.mouseMatter.Text = m_str_mouseshow_right;
  961. m_ReportApp.RSGrayVal.Text = m_str_mouseshow_left;
  962. }
  963. }
  964. }
  965. }
  966. }
  967. //Invalidate();
  968. }
  969. protected override void OnMouseMove(MouseEventArgs e)
  970. {
  971. //如果是进行多选的话
  972. if (true == m_is_multiselect_onpaint)
  973. {
  974. if (e.Location.X > m_beforemultiselect_point.X && e.Location.Y > m_beforemultiselect_point.Y)
  975. {
  976. //右下拖动
  977. m_multiselect_rect = new RectangleF(m_beforemultiselect_point, new SizeF(e.Location.X - m_beforemultiselect_point.X, e.Location.Y - m_beforemultiselect_point.Y));
  978. }
  979. if (e.Location.X < m_beforemultiselect_point.X && e.Location.Y < m_beforemultiselect_point.Y)
  980. {
  981. //左上拖动
  982. PointF lspointf = new PointF(e.Location.X, e.Location.Y);
  983. m_multiselect_rect = new RectangleF(lspointf, new SizeF(m_beforemultiselect_point.X - e.Location.X, m_beforemultiselect_point.Y - e.Location.Y));
  984. }
  985. if (e.Location.X > m_beforemultiselect_point.X && e.Location.Y < m_beforemultiselect_point.Y)
  986. {
  987. //右上,这种画法,需要将左下,右上两点转换成左上,右下
  988. PointF left_pointf = new PointF(m_beforemultiselect_point.X, e.Location.Y);
  989. PointF right_pointf = new PointF(e.Location.X, m_beforemultiselect_point.Y);
  990. m_multiselect_rect = new RectangleF(left_pointf, new SizeF(right_pointf.X - left_pointf.X, right_pointf.Y - left_pointf.Y));
  991. }
  992. if (e.Location.X < m_beforemultiselect_point.X && e.Location.Y > m_beforemultiselect_point.Y)
  993. {
  994. //左下,这种画法,需要将左下,右上两点转换成左上,右下
  995. PointF left_pointf = new PointF(e.Location.X, m_beforemultiselect_point.Y);
  996. PointF right_pointf = new PointF(m_beforemultiselect_point.X, e.Location.Y);
  997. m_multiselect_rect = new RectangleF(left_pointf, new SizeF(right_pointf.X - left_pointf.X, right_pointf.Y - left_pointf.Y));
  998. }
  999. }
  1000. //判断没有在进行多选状态时,在进行多选时,不让其拖动
  1001. if (false == m_is_multiselect_onpaint)
  1002. {
  1003. foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution)
  1004. {
  1005. foreach (BaseObject item in ls_sortparticledistribution.List_DParticle)
  1006. {
  1007. DisplayParticle dp = (DisplayParticle)item;
  1008. //在计算前,先重新对颗粒的边缘进行计算,防止错误
  1009. dp.GPath = dp.GetRegionFromDSegments();
  1010. if (true == m_ReportFun.WhetherInRange(dp, e.Location))
  1011. {
  1012. //if (dp.displayState == DisplayState.NORMALDISPLAY)
  1013. //{
  1014. dp.IsMouseOver = true;
  1015. //显示xray图
  1016. if (control_XRayTable1.Visible == false)
  1017. ShowXRay(dp);
  1018. //}
  1019. }
  1020. else
  1021. {
  1022. dp.IsMouseOver = false;
  1023. //移动在颗粒外面时,要判断,Operator_ShowXray不为选下显示XRAY时,才对XRay进行隐藏
  1024. if (dp.Operator_ShowXRay != ParticleOperatorShowXray.SELECTANDDISPLAYXRAY)
  1025. {
  1026. //隐藏x-ray能谱图
  1027. HideXRay(dp);
  1028. }
  1029. }
  1030. if (true == item.IsDragging)
  1031. {
  1032. //再将里面的线也进行计算坐标
  1033. foreach (DisplaySegment ds in dp.DSegments)
  1034. {
  1035. ds.Rect = new RectangleF(
  1036. ds.Rect.X + e.X - item.DraggingPoint.X, //获取到原先点与移动点的增减量,+原先的x坐标,就是新的坐标
  1037. ds.Rect.Y + e.Y - item.DraggingPoint.Y,
  1038. ds.Rect.Width,
  1039. ds.Rect.Height);
  1040. ds.DraggingPoint = e.Location;
  1041. }
  1042. item.DraggingPoint = e.Location;
  1043. //获取矩形的rectangle
  1044. dp.Rect = dp.GetRectFromDSegment();
  1045. //通过line获取路径边缘
  1046. dp.GPath = dp.GetRegionFromDSegments();
  1047. //重新计算小矩形边框
  1048. dp.SmallRect = dp.GetSmallRectangleFromRect();
  1049. if (dp.Rect.Left < 0 || dp.Rect.Right > this.Width || dp.Rect.Top < 0 || dp.Rect.Bottom > this.Height)
  1050. {
  1051. dp.displayState = DisplayState.NODISPLAY;
  1052. }
  1053. }
  1054. }
  1055. }
  1056. //如果在拖动中
  1057. if (true == m_isDrag)
  1058. {
  1059. //同样重新计算backrectf的坐标
  1060. foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution)
  1061. {
  1062. ls_sortparticledistribution.RectF = new RectangleF(ls_sortparticledistribution.RectF.Location.X + e.X - m_beforedrag_pointf.X,
  1063. ls_sortparticledistribution.RectF.Location.Y + e.Y - m_beforedrag_pointf.Y, ls_sortparticledistribution.RectF.Width, ls_sortparticledistribution.RectF.Height);
  1064. }
  1065. m_beforedrag_pointf = e.Location;
  1066. }
  1067. }
  1068. #region 向报告程序右下角,传送鼠标颗粒等相关信息
  1069. //然后这里还要将鼠标移动经过的过程,传输给reportapp中,为了能让reportapp能显示出来
  1070. //如果前面鼠标没有移动到颗粒的位置上,str_mouseshow_left=="",所以再取显示鼠标的位置信息
  1071. m_str_mouseshow_left = "无";
  1072. foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution)
  1073. {
  1074. foreach (BaseObject item in ls_sortparticledistribution.List_DParticle)
  1075. {
  1076. DisplayParticle dp = (DisplayParticle)item;
  1077. if (true == m_ReportFun.WhetherInRange(dp, e.Location))
  1078. {
  1079. if (dp.displayState == DisplayState.NORMALDISPLAY)
  1080. {
  1081. m_sem_mouse_now_point = new Point(dp.SEMPosX, dp.SEMPosY);
  1082. m_str_mouseshow_left = "颗粒SEM位置:" + dp.SEMPosX.ToString() + ":" + dp.SEMPosY.ToString();
  1083. }
  1084. }
  1085. }
  1086. }
  1087. //获取颜色方法1,使用API来获取当前鼠标指向位置的颜色值-------------------------------------------
  1088. Graphics g = Graphics.FromHwnd(this.Handle);
  1089. IntPtr hdc = g.GetHdc();
  1090. uint u_color = 0;
  1091. try
  1092. {
  1093. u_color = DrawFunction.GetPixel(hdc, e.X, e.Y);
  1094. }
  1095. catch
  1096. { }
  1097. Color ls_c = Color.FromArgb
  1098. (
  1099. (int)(u_color << 24 >> 24),
  1100. (int)(u_color << 16 >> 24),
  1101. (int)(u_color << 8 >> 24)
  1102. );
  1103. m_str_mouseshow_right = "灰度#" + ls_c.R.ToString();
  1104. // 这里发送消息
  1105. m_ReportApp.mouseMatter.Text = m_str_mouseshow_right;
  1106. m_ReportApp.RSGrayVal.Text = m_str_mouseshow_left;
  1107. #endregion
  1108. Invalidate();
  1109. }
  1110. #endregion
  1111. #region 自定义功能函数
  1112. /// <summary>
  1113. /// 复制图像
  1114. /// </summary>
  1115. private void CopyImage()
  1116. {
  1117. int height, width;
  1118. width = this.Width;
  1119. height = this.Height;
  1120. Bitmap image = new Bitmap(width, height);
  1121. this.DrawToBitmap(image, new Rectangle(0, 0, width, height));
  1122. Clipboard.SetImage(image);
  1123. }
  1124. /// <summary>
  1125. /// 移动SEM到指定位置线程函数
  1126. /// </summary>
  1127. private void Thread_GO(object in_obj)
  1128. {
  1129. if (m_mythread_state == false)
  1130. {
  1131. m_mythread_state = true;
  1132. Point sem_point = (Point)in_obj;
  1133. //第一步,连接电镜
  1134. m_ReportFun.ConnectToSEM();
  1135. Thread.Sleep(500);
  1136. //第二步,移动到指定位置,先读取再设置
  1137. if (m_ReportFun.m_SEMConnectionState == true)
  1138. {
  1139. m_ReportFun.MoveSemToPointXY(sem_point.X, sem_point.Y);
  1140. }
  1141. Thread.Sleep(1500);
  1142. //第三步,断开电镜连接
  1143. m_ReportFun.DisConnectSEM();
  1144. //Thread.Sleep(1000);
  1145. m_mythread_state = false;
  1146. }
  1147. }
  1148. /// <summary>
  1149. /// 显示x-ray能谱图
  1150. /// </summary>
  1151. /// <param name="in_dparticle"></param>
  1152. private void ShowXRay(DisplayParticle in_dparticle)
  1153. {
  1154. //显示xray相关信息
  1155. uint[] Search_xray = new uint[2000];
  1156. uint[] Analysis_xray = new uint[2000];
  1157. //
  1158. int i_xray_id = 0;
  1159. List<Element> list_celementchemistryclr = new List<Element>();
  1160. //获取Xray数据
  1161. m_ReportFun.GetXrayByParticleTagIDAndFieldID_ForDrawDistrbutionImageAndBSE(in_dparticle.ParticleId, in_dparticle.FieldId, out Search_xray, out Analysis_xray, out i_xray_id, out list_celementchemistryclr);
  1162. //get CElementChemistryClr list
  1163. List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
  1164. for (int i = 0; i < list_celementchemistryclr.Count; i++)
  1165. {
  1166. ShowElementInfo ls_sei = new ShowElementInfo();
  1167. ls_sei.ElementName = list_celementchemistryclr[i].Name;
  1168. ls_sei.Percentage = list_celementchemistryclr[i].Percentage;
  1169. ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByYsm(CListPeriodic.GetListPeriodic(), ls_sei.ElementName).SX1);
  1170. list_showelementinfo.Add(ls_sei);
  1171. }
  1172. //获取使用标准库的名称,也许这个也不是很正确??
  1173. string str_stdname = "";
  1174. string str_IncALibName = "";
  1175. //获取数据后,需要对xraytable设置
  1176. control_XRayTable1.Visible = false;
  1177. control_XRayTable1.SetXRayShowLineValue(Search_xray, Analysis_xray, list_showelementinfo);
  1178. //control_XRayTable1.GoodName = str_IncALibName + "(" + in_dparticle.STDTypeID.ToString() + ")";//杂夹物
  1179. control_XRayTable1.MaterialName = str_IncALibName;//杂夹物
  1180. control_XRayTable1.STDName = str_stdname;//标准库
  1181. control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
  1182. control_XRayTable1.Visible = true;
  1183. //将显示xray的dparticle记录给全局变量
  1184. m_move_dparticle = in_dparticle;
  1185. this.Refresh();
  1186. }
  1187. /// <summary>
  1188. /// 隐藏x-ray能谱图
  1189. /// </summary>
  1190. private void HideXRay(DisplayParticle in_dparticle)
  1191. {
  1192. if (m_move_dparticle == null)
  1193. return;
  1194. else if (m_move_dparticle.guid == in_dparticle.guid)
  1195. {
  1196. //如果是刚才移动过的颗粒的话,那么这里再对xray进行隐藏
  1197. control_XRayTable1.Visible = false;
  1198. }
  1199. }
  1200. /// <summary>
  1201. /// 封装,将排列图中的颗粒list传送给报告项目框架中
  1202. /// </summary>
  1203. private void SelectParticleListSendToReportFrame()
  1204. {
  1205. //先获取排列图中,有哪些颗粒已经被选择上了
  1206. m_ReportApp.SelectedParticles = GetSelectedParticleList_ForDrawDistrbutionSortImage();
  1207. }
  1208. /// <summary>
  1209. /// 设置当前对哪些颗粒进行设置为选择状态
  1210. /// </summary>
  1211. /// <param name="in_list_cotsparticleclr"></param>
  1212. public void SetSelectParticle(List<Particle> in_list_cotsparticleclr)
  1213. {
  1214. if (in_list_cotsparticleclr == null)
  1215. {
  1216. return;
  1217. }
  1218. if (in_list_cotsparticleclr.Count == 0)
  1219. {
  1220. return;
  1221. }
  1222. foreach (SortParticleDistribution spd in m_list_sortparticledistribution)
  1223. {
  1224. foreach (DisplayParticle ls_dp in spd.List_DParticle)
  1225. {
  1226. //只有显示状态,才可以切换到选择状态,考虑可能会出现如果在条件选择成不显示状态下,如果被选择了,是不是就强制切换成了选择状态
  1227. if (ls_dp.displayState == DisplayState.NORMALDISPLAY)
  1228. {
  1229. for (int i = 0; i < in_list_cotsparticleclr.Count; i++)
  1230. {
  1231. if (in_list_cotsparticleclr[i].ParticleId == ls_dp.ParticleId
  1232. && in_list_cotsparticleclr[i].FieldId == ls_dp.FieldId)
  1233. {
  1234. ls_dp.IsSelect=true;
  1235. }
  1236. }
  1237. }
  1238. }
  1239. }
  1240. }
  1241. /// <summary>
  1242. /// 颗粒排序图中的颗粒,重新组织显示颗粒排序规则
  1243. /// </summary>
  1244. public void GetDistrbutionSortimage_ByQuery(OTSIncAReportApp.OTSSampleReportInfo.ReportCondition sourceGridData)
  1245. {
  1246. m_list_cgriddataclr = sourceGridData;
  1247. List<string> FLNameList = new List<string>();
  1248. //List<int> FLID = new List<int>() { -1,0, 1, 2, 4, 6, 7, 8, 9 };
  1249. List<int> FLID = new List<int>() { 0, 1, 2, 4, 6, 9, 10 };
  1250. List<string> NameList = new List<string>();
  1251. ParticleClassifyType fltype = ParticleClassifyType.MaterialType;
  1252. //先清除list
  1253. m_list_sortparticledistribution.Clear();
  1254. m_old_list_sortparticledistribution.Clear();
  1255. m_f_zoom_record = 1;
  1256. //------------------------------------分解结果内容部份------------------------------------
  1257. string display_type = "";
  1258. string con = "";
  1259. var list = sourceGridData.ConditionItemList.Find(s => Convert.ToInt32(s.iItemId) == 4);
  1260. string sort_type = list.itemVal.ToString();
  1261. int _type = list.comboDownList.IndexOf(sort_type);
  1262. switch (_type)
  1263. {
  1264. case 0:
  1265. fltype = ParticleClassifyType.MaterialType;
  1266. break;
  1267. case 1:
  1268. fltype = ParticleClassifyType.MaterialType; ;
  1269. // break;
  1270. //case 2:
  1271. // fltype = 2;
  1272. display_type = sourceGridData.ConditionItemList.Find(s => Convert.ToInt32(s.iItemId) == 13).itemVal.ToString();
  1273. switch (display_type)
  1274. {
  1275. case "DMAX":
  1276. con = "DMAX";
  1277. break;
  1278. case "DMIN":
  1279. con = "DMIN";
  1280. break;
  1281. case "Area":
  1282. con = "Area";
  1283. break;
  1284. case "FERET":
  1285. con = "DFERET";
  1286. break;
  1287. }
  1288. break;
  1289. }
  1290. string path = resultFile.FilePath;
  1291. ParticleData particleData = new ParticleData(path);
  1292. List<Particle> particles = particleData.GetParticleListByCon("", "", "", 0);
  1293. foreach (DisplayParticle ls_dp in m_list_baseobject)
  1294. {
  1295. int dis = 0;
  1296. foreach (Particle particle in particles)
  1297. {
  1298. //找到对应的颗粒,将分类设置进去
  1299. if (ls_dp.ParticleId == particle.ParticleId && ls_dp.FieldId == particle.FieldId)
  1300. {
  1301. if (!FLNameList.Contains(particle.TypeName) && particle.TypeName != "")
  1302. {
  1303. FLNameList.Add(particle.TypeName);
  1304. }
  1305. if (fltype == ParticleClassifyType.MaterialType)
  1306. {
  1307. ls_dp.ParticleFL = particle.TypeName.ToString();
  1308. }
  1309. if (fltype == ParticleClassifyType.SizeType)
  1310. {
  1311. if (con == "DMAX")
  1312. ls_dp.ParticleFL = particle.DMAX.ToString();
  1313. if (con == "DMIN")
  1314. ls_dp.ParticleFL = particle.DMIN.ToString();
  1315. if (con == "Area")
  1316. ls_dp.ParticleFL = particle.Area.ToString();
  1317. if (con == "DFERET")
  1318. ls_dp.ParticleFL = particle.FERET.ToString();
  1319. }
  1320. ls_dp.displayState = DisplayState.NORMALDISPLAY;
  1321. dis = 1;
  1322. break;
  1323. }
  1324. }
  1325. if (dis == 0)
  1326. {
  1327. ls_dp.displayState = DisplayState.NODISPLAY;
  1328. }
  1329. }
  1330. //if (fltype == 0)
  1331. //{
  1332. // //NameList = new List<string>() { table["partcletype0"].ToString(), table["partcletype1"].ToString(), table["partcletype2"].ToString(), table["partcletype4"].ToString(), table["partcletype6"].ToString(), table["partcletype7"].ToString(), table["partcletype8"].ToString(), table["partcletype9"].ToString(), table["partcletype10"].ToString() };
  1333. // NameList = new List<string>() { resourceTable["partcletype9"].ToString(), resourceTable["partcletype10"].ToString() };
  1334. //}
  1335. if (fltype == ParticleClassifyType.MaterialType)
  1336. {
  1337. NameList = FLNameList;
  1338. }
  1339. if (fltype == ParticleClassifyType.SizeType)
  1340. {
  1341. //获取粒级表
  1342. string flpath = m_ReportApp.m_DataMgrFun.m_RptConfigFile.FileFolderSize + m_ReportApp.m_DataMgrFun.m_RptConfigFile.PartSizeFile;
  1343. DataSet ds = XMLoperate.GetXml(flpath);
  1344. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  1345. List<string> sizeList = new List<string>();
  1346. for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
  1347. {
  1348. if (sizestr.Split(',')[i].Length > 0)
  1349. {
  1350. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  1351. double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
  1352. sizeList.Add(d1.ToString() + "~" + d2.ToString());
  1353. }
  1354. }
  1355. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  1356. sizeList.Add(d.ToString() + "~MAX");
  1357. NameList = sizeList;
  1358. }
  1359. //为颗粒排序图,创建分栏grid
  1360. foreach (string name in NameList)
  1361. {
  1362. SortParticleDistribution sortparticledistribution = new SortParticleDistribution();
  1363. sortparticledistribution.RectF = new RectangleF(ClientRectangle.X, ClientRectangle.Y,
  1364. 800, ClientRectangle.Height);
  1365. sortparticledistribution.ShowStr = name;//设置分类grid
  1366. m_list_sortparticledistribution.Add(sortparticledistribution);
  1367. }
  1368. //然后再重新将list_baseobject中的颗粒,分别添加到对应的sortgrid中
  1369. foreach (DisplayParticle ls_dp in m_list_baseobject)
  1370. {
  1371. var sort = m_list_sortparticledistribution;
  1372. for (int i = 0; i < sort.Count; i++)
  1373. {
  1374. //if (fltype == 0)
  1375. //{
  1376. // if (ls_dp.TypeId == FLID[i])
  1377. // {
  1378. // //将对应的颗粒添加到分栏grid中
  1379. // DisplayParticle sort_dp = ls_dp.Clone() as DisplayParticle;
  1380. // sort_dp.Rect = sort_dp.GetRectFromDSegment();
  1381. // sort[i].List_DParticle.Add(sort_dp);
  1382. // break;
  1383. // }
  1384. // else if (ls_dp.TypeId > 10000)
  1385. // {
  1386. // //将对应的颗粒添加到分栏grid中
  1387. // DisplayParticle sort_dp = ls_dp.Clone() as DisplayParticle;
  1388. // sort_dp.Rect = sort_dp.GetRectFromDSegment();
  1389. // sort[sort.Count - 1].List_DParticle.Add(sort_dp);
  1390. // break;
  1391. // }
  1392. //}
  1393. if (fltype == ParticleClassifyType.MaterialType)
  1394. {
  1395. if (ls_dp.TypeName == NameList[i])
  1396. {
  1397. //将对应的颗粒添加到分栏grid中
  1398. DisplayParticle sort_dp = ls_dp.Clone() as DisplayParticle;
  1399. sort_dp.Rect = sort_dp.GetRectFromDSegment();
  1400. sort[i].List_DParticle.Add(sort_dp);
  1401. break;
  1402. }
  1403. }
  1404. else if (fltype == ParticleClassifyType.SizeType)
  1405. {
  1406. double min = Convert.ToDouble(NameList[i].Split('~')[0]);
  1407. double max = 0;
  1408. if (NameList[i].Split('~')[1].ToLower() != "max")
  1409. { max = Convert.ToDouble(NameList[i].Split('~')[1]); }
  1410. else
  1411. {
  1412. max = 999;
  1413. }
  1414. double size = Convert.ToDouble(ls_dp.ParticleFL);
  1415. if (size <= max && size >= min)
  1416. {
  1417. //将对应的颗粒添加到分栏grid中
  1418. DisplayParticle sort_dp = ls_dp.Clone() as DisplayParticle;
  1419. sort_dp.Rect = sort_dp.GetRectFromDSegment();
  1420. sort[i].List_DParticle.Add(sort_dp);
  1421. break;
  1422. }
  1423. }
  1424. }
  1425. }
  1426. //循环分栏grid,对各分栏grid进行摆放
  1427. for (int i = 0; i < m_list_sortparticledistribution.Count(); i++)
  1428. {
  1429. //计算y轴,的增量
  1430. float ls_height = 0;
  1431. if (i == 0)
  1432. {
  1433. ls_height = 0;
  1434. }
  1435. else
  1436. {
  1437. ls_height = m_list_sortparticledistribution[i - 1].RectF.Y +
  1438. m_list_sortparticledistribution[i - 1].RectF.Height - 10;
  1439. }
  1440. m_list_sortparticledistribution[i].RectF = new RectangleF(
  1441. m_list_sortparticledistribution[i].RectF.X,
  1442. m_list_sortparticledistribution[i].RectF.Y + ls_height,
  1443. m_list_sortparticledistribution[i].RectF.Width,
  1444. m_list_sortparticledistribution[i].GetSortGridHeight() + 50);//为每栏的高度增加了50补充,防止图像溢出
  1445. }
  1446. //然后再重新对分栏grid中的颗粒,重新进行摆放
  1447. foreach (SortParticleDistribution ls_spd in m_list_sortparticledistribution)
  1448. {
  1449. ls_spd.SortDParticle(FZOOMRecord);
  1450. }
  1451. //最后,将分栏grid,分别存放到old的分栏grid中
  1452. foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution)
  1453. {
  1454. SortParticleDistribution old_sortparticledistribution = ls_sortparticledistribution.Clone() as SortParticleDistribution;
  1455. m_old_list_sortparticledistribution.Add(old_sortparticledistribution);
  1456. foreach (DisplayParticle ls_dp in old_sortparticledistribution.List_DParticle)
  1457. {
  1458. ls_dp.Rect = ls_dp.GetRectFromDSegment();
  1459. }
  1460. }
  1461. }
  1462. /// <summary>
  1463. /// 是否显示标尺控件,自动切换显示与不显示
  1464. /// </summary>
  1465. /// <param name="b_show"></param>
  1466. public void ShowRulerControl()
  1467. {
  1468. control_Ruler1.Visible = !control_Ruler1.Visible;
  1469. }
  1470. /// <summary>
  1471. /// 是否显示标尺控件,带参重载
  1472. /// </summary>
  1473. /// <param name="b_show"></param>
  1474. public void ShowRulerControl(bool b_show)
  1475. {
  1476. control_Ruler1.Visible = b_show;
  1477. }
  1478. /// <summary>
  1479. /// 设置显示BSE原图,还是显示排序图带有标准库的
  1480. /// </summary>
  1481. /// <param name="in_b">false为显示原bse图像,true为显示带有标准库代表色的图像</param>
  1482. public void ShowMode(bool in_b)
  1483. {
  1484. if (in_b == false)
  1485. {
  1486. foreach (SortParticleDistribution item in m_list_sortparticledistribution)
  1487. {
  1488. foreach (DisplayParticle ls_dp in item.List_DParticle)
  1489. {
  1490. foreach (DisplaySegment ls_ds in ls_dp.DSegments)
  1491. {
  1492. ls_ds.ShowMode = SegmentShowMode.DRAWPOINT;
  1493. }
  1494. }
  1495. }
  1496. }
  1497. else
  1498. {
  1499. foreach (SortParticleDistribution item in m_list_sortparticledistribution)
  1500. {
  1501. foreach (DisplayParticle ls_dp in item.List_DParticle)
  1502. {
  1503. foreach (DisplaySegment ls_ds in ls_dp.DSegments)
  1504. {
  1505. ls_ds.ShowMode = SegmentShowMode.DRAWLINE;
  1506. }
  1507. }
  1508. }
  1509. }
  1510. this.Invalidate();
  1511. }
  1512. /// <summary>
  1513. /// 对颗粒进行排序
  1514. /// </summary>
  1515. /// <param name="in_list_baseobject"></param>
  1516. /// <param name="str_sort">排序的方法,从小到到,小大到小</param>
  1517. public void SortDParticleBySize(List<BaseObject> in_list_baseobject, string str_sort)
  1518. {
  1519. List<DisplayParticle> list_dp1 = new List<DisplayParticle>();
  1520. foreach (DisplayParticle ls_dp in in_list_baseobject)
  1521. {
  1522. DisplayParticle dp1 = ls_dp.Clone() as DisplayParticle;
  1523. list_dp1.Add(dp1);
  1524. }
  1525. in_list_baseobject.Clear();
  1526. if (str_sort == "从小到大")
  1527. {
  1528. int icount = list_dp1.Count();
  1529. for (int i = 0; i < icount; i++)
  1530. {
  1531. float f_min_size = 10000000;
  1532. Guid str_jlguid ;
  1533. DisplayParticle ls_dp = new DisplayParticle();
  1534. foreach (DisplayParticle ls_del_dp in list_dp1)
  1535. {
  1536. ls_del_dp.FSize = ls_del_dp.GetSizeFormSegmentsAllWidth();
  1537. if (f_min_size > ls_del_dp.FSize)
  1538. {
  1539. f_min_size = ls_del_dp.FSize;
  1540. str_jlguid = ls_del_dp.guid;
  1541. ls_dp = ls_del_dp;
  1542. }
  1543. }
  1544. list_dp1.Remove(ls_dp);
  1545. in_list_baseobject.Add(ls_dp);
  1546. }
  1547. }
  1548. else if (str_sort == "从大到小")
  1549. {
  1550. int icount = list_dp1.Count();
  1551. for (int i = 0; i < icount; i++)
  1552. {
  1553. float f_max_size = 0;
  1554. Guid str_jlguid ;
  1555. DisplayParticle ls_dp = new DisplayParticle();
  1556. foreach (DisplayParticle ls_del_dp in list_dp1)
  1557. {
  1558. ls_del_dp.FSize = ls_del_dp.GetSizeFormSegmentsAllWidth();
  1559. if (f_max_size < ls_del_dp.FSize)
  1560. {
  1561. f_max_size = ls_del_dp.FSize;
  1562. str_jlguid = ls_del_dp.guid;
  1563. ls_dp = ls_del_dp;
  1564. }
  1565. }
  1566. list_dp1.Remove(ls_dp);
  1567. ls_dp.Rect = ls_dp.GetRectFromDSegment();
  1568. in_list_baseobject.Add(ls_dp);
  1569. }
  1570. }
  1571. }
  1572. /// <summary>
  1573. /// 是否进行矩形多选操作
  1574. /// </summary>
  1575. public void MultiSelect_Rectangle()
  1576. {
  1577. if (m_is_multiselect_ellipse == true)
  1578. {
  1579. m_is_multiselect_ellipse = false;
  1580. }
  1581. m_is_multiselect_rectangle = true;
  1582. }
  1583. /// <summary>
  1584. /// 是否进行圆形多选操作
  1585. /// </summary>
  1586. public void MultiSelect_Ellipse()
  1587. {
  1588. if (m_is_multiselect_rectangle == true)
  1589. {
  1590. m_is_multiselect_rectangle = false;
  1591. }
  1592. m_is_multiselect_ellipse = true;
  1593. }
  1594. /// <summary>
  1595. /// 对选择的多边形进行反选操作
  1596. /// </summary>
  1597. public void ReverSeSelection()
  1598. {
  1599. foreach (SortParticleDistribution aag in m_list_sortparticledistribution)
  1600. {
  1601. foreach (DisplayParticle dp in aag.List_DParticle)
  1602. {
  1603. if (dp.IsSelect)
  1604. {
  1605. dp.IsSelect = false;
  1606. }
  1607. else
  1608. {
  1609. dp.IsSelect = true;
  1610. }
  1611. }
  1612. }
  1613. //将排列图选择的颗粒传送给报告框架中
  1614. SelectParticleListSendToReportFrame();
  1615. this.Invalidate();
  1616. }
  1617. /// <summary>
  1618. /// 取消所有的颗粒的选择状态
  1619. /// </summary>
  1620. public void DeselectAllParticle()
  1621. {
  1622. foreach (SortParticleDistribution aag in m_list_sortparticledistribution)
  1623. {
  1624. foreach (DisplayParticle dp in aag.List_DParticle)
  1625. {
  1626. //if (ParticleOperator.SELECTED == dp.Operator)
  1627. //{
  1628. dp.IsSelect=false;
  1629. //}
  1630. }
  1631. }
  1632. //将排列图选择的颗粒传送给报告框架中
  1633. SelectParticleListSendToReportFrame();
  1634. this.Invalidate();
  1635. }
  1636. /// <summary>
  1637. /// 将整个图像拷贝到内存中
  1638. /// </summary>
  1639. public void CopyToBitmap()
  1640. {
  1641. Bitmap bp = new Bitmap(this.Size.Width, this.Size.Height);
  1642. this.DrawToBitmap(bp, new Rectangle(0, 0, this.Size.Width, this.Size.Height));
  1643. Clipboard.SetImage(bp);
  1644. }
  1645. #endregion
  1646. #region 鼠标菜单右键
  1647. private void ToolStripMenuItem_id_Click(object sender, EventArgs e)
  1648. {
  1649. //ID
  1650. DisplayParticle dp = (DisplayParticle)CMenuStrip.Items[0].Tag;
  1651. MessageBox.Show(dp.guid.ToString());
  1652. }
  1653. private void ToolStripMenuItem_selected_Click(object sender, EventArgs e)
  1654. {
  1655. //选择
  1656. DisplayParticle dp = (DisplayParticle)CMenuStrip.Items[0].Tag;
  1657. if (dp.IsSelect)
  1658. {
  1659. dp.displayState = DisplayState.NORMALDISPLAY;
  1660. CMenuStrip.Items[1].Text = "选择颗粒";
  1661. control_XRayTable1.Visible = false;
  1662. }
  1663. else
  1664. {
  1665. dp.IsSelect=false;
  1666. CMenuStrip.Items[1].Text = "取消颗粒选择";
  1667. }
  1668. //将排列图选择的颗粒传送给报告框架中
  1669. SelectParticleListSendToReportFrame();
  1670. }
  1671. private void ToolStripMenuItem_delete_Click(object sender, EventArgs e)
  1672. {
  1673. //删除颗粒
  1674. DisplayParticle dp = (DisplayParticle)CMenuStrip.Items[0].Tag;
  1675. //同样,要在历史操作记录类中,添加记录,好可以进行撤消操作
  1676. HistoryApolygon hApolygon = new HistoryApolygon();
  1677. hApolygon.APolygonID = dp.guid;
  1678. hApolygon.IsDeleted = true;
  1679. hApolygon.OldOperator = dp.displayState;
  1680. hApolygon.ID = m_list_historyapolygon.Count;
  1681. m_list_historyapolygon.Add(hApolygon);
  1682. m_operator_currentid = hApolygon.ID;//当前操作到的历史操作记录
  1683. //设置颗粒的状态为已经被删除
  1684. dp.displayState = DisplayState.NODISPLAY;
  1685. }
  1686. private void ToolStripMenuItem_movesempoint_Click(object sender, EventArgs e)
  1687. {
  1688. //移动SEM到指定位置
  1689. if (m_mythread == null)
  1690. {
  1691. return;
  1692. }
  1693. if (m_mythread.ThreadState == ThreadState.Running || m_mythread.ThreadState == ThreadState.WaitSleepJoin)
  1694. {
  1695. return;
  1696. }
  1697. if (m_mythread.ThreadState == ThreadState.Stopped)
  1698. {
  1699. m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
  1700. }
  1701. if (m_sem_mouse_now_point.X != 0 && m_sem_mouse_now_point.Y != 0)
  1702. {
  1703. //改为线程调用,先判断线程状态
  1704. m_mythread.Start(new Point(m_sem_mouse_now_point.X, m_sem_mouse_now_point.Y));
  1705. }
  1706. }
  1707. //复制图像
  1708. private void ToolStripMenuItem_copyimage_Click(object sender, EventArgs e)
  1709. {
  1710. CopyImage();
  1711. }
  1712. //显示过小颗粒
  1713. private void ToolStripMenuItemShowSmallParticle_Click(object sender, EventArgs e)
  1714. {
  1715. if (bShowSmallParticle == false)
  1716. {
  1717. bShowSmallParticle = true;
  1718. CMenuStrip.Items[6].Text = "不显示过小颗粒";
  1719. }
  1720. else
  1721. {
  1722. bShowSmallParticle = false;
  1723. CMenuStrip.Items[6].Text = "显示过小颗粒";
  1724. }
  1725. //缩放的增大缩小的增量
  1726. m_f_zoom_increment = 0.1f;
  1727. //缩放的基数,临时变量
  1728. m_f_widthandheight_js = 0;
  1729. //与原先缩放的记录数
  1730. m_f_zoom_record = 1;
  1731. //最大缩放倍数
  1732. m_f_zoom_max = 4f;
  1733. //最小缩放倍数
  1734. m_f_zoom_mix = 0.5f;
  1735. //标尺的大小记录
  1736. m_f_ruler_size = 100;
  1737. //标尺原先大小的记录,参与计算
  1738. m_f_old_ruler_size = 100;
  1739. //每像素代表的尺寸大小,还不知道在哪里进行计算
  1740. m_pixelSize = 4.5f;
  1741. //提供鼠标在右下角显示的文本,左侧
  1742. m_str_mouseshow_left = "";
  1743. //提供鼠标在右下角显示的文本,右侧
  1744. m_str_mouseshow_right = "";
  1745. //分栏网格边框的颜色
  1746. m_c_ColumnRectangleColor = Color.LightSteelBlue;
  1747. //记录操作记录类
  1748. m_list_historyapolygon = null;
  1749. //操作历史类,当前操作到的id
  1750. m_operator_currentid = 0;
  1751. m_list_baseobject = new List<BaseObject>();
  1752. m_list_historyapolygon = new List<HistoryApolygon>();
  1753. m_list_sortparticledistribution = new List<SortParticleDistribution>();
  1754. m_old_list_sortparticledistribution = new List<SortParticleDistribution>();
  1755. m_mythread_state = false;
  1756. m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
  1757. m_frm_userprogress = new Frm_UserProgress();
  1758. Control_DrawDistrbutionSortImage_Load(null, null);
  1759. GetDistrbutionSortimage_ByQuery(m_list_cgriddataclr);
  1760. }
  1761. #endregion
  1762. }
  1763. }