Control_DrawDistrbutionImageAndBSE.cs 101 KB

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