Control_DrawDistrbutionImageAndBSE.cs 102 KB

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