Control_DrawDistrbutionSortImage.cs 93 KB

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