Control_DrawDistrbutionImageAndBSE.cs 101 KB

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