Control_DrawDistrbutionImageAndBSE.cs 102 KB

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