OTSSamplespaceWindow.cs 127 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553
  1. using MyControls;
  2. using OTS.WinFormsUI.Docking;
  3. using OTSDataType;
  4. using OTSMeasureApp._0_OTSModel.OTSDataType;
  5. using OTSMeasureApp._1_OTSMeasure.Measure._3_MeasureFlow;
  6. using OTSMeasureApp._4_OTSSamplespaceGraphicsPanel;
  7. using OTSMeasureApp._4_OTSSamplespaceGraphicsPanel.VisualGDIObjects;
  8. using OTSModelSharp;
  9. using OTSModelSharp.ServiceCenter;
  10. using System;
  11. using System.Collections;
  12. using System.Collections.Generic;
  13. using System.Drawing;
  14. using System.Threading;
  15. using System.Windows.Forms;
  16. namespace OTSMeasureApp
  17. {
  18. public enum EnumMousePointPosition
  19. {
  20. MouseSizeNone = 0, //'无
  21. MouseSizeRight = 1, //'拉伸右边框
  22. MouseSizeLeft = 2, //'拉伸左边框
  23. MouseSizeBottom = 3, //'拉伸下边框
  24. MouseSizeTop = 4, //'拉伸上边框
  25. MouseSizeTopLeft = 5, //'拉伸左上角
  26. MouseSizeTopRight = 6, //'拉伸右上角
  27. MouseSizeBottomLeft = 7, //'拉伸左下角
  28. MouseSizeBottomRight = 8, //'拉伸右下角
  29. MouseDrag = 9 // '鼠标拖动
  30. }
  31. public enum ContextMenuType
  32. {
  33. //样品孔右键菜单
  34. SampleHoleMenu = 0,
  35. //样品右键菜单
  36. SampleMenu = 1,
  37. //测量区域右键菜单
  38. MeasureMenu = 2,
  39. //线程运行后菜单
  40. ThreadRunMenu = 3,
  41. //样品台右键菜单
  42. SampleStateMenu = 4,
  43. //样品孔BSE图像
  44. SampleHoleBSEImage = 5,
  45. //帧图菜单
  46. FieldMenu = 6
  47. }
  48. public enum MenuIndex
  49. {
  50. AddSample = 0,
  51. DeleteSample = 1,
  52. SampleStripSeparator = 2,
  53. ReadSEMData = 3,
  54. SetSemData = 4,
  55. SetSEMCenterLocation = 5,
  56. DriveSEMToCenterLocation = 6,
  57. DriveSEMToCurrentLocation = 7,
  58. SEMStripSeparator = 8,
  59. ShootBSEPicture = 9,
  60. DeleteBSEPicture = 10,
  61. DeleteSampleData = 11,
  62. SlopFocus = 12
  63. }
  64. public enum DrawMeasureAreaActionType
  65. {
  66. NoAction = 1,
  67. //圆形
  68. Circle = 2,
  69. Rectangle = 3,
  70. //多边形
  71. Polygon = 4,
  72. //圆形三点法
  73. CircleByThreePoints = 5,
  74. InverseSelection = 6,
  75. OnlyShot = 7
  76. }
  77. public partial class OTSSamplespaceWindow : DockContent
  78. {
  79. #region 全局变量定义
  80. public CVisualStage m_visualStage;
  81. string m_SampleHoleSelectName = string.Empty;
  82. public string m_SampleSelectName = string.Empty;
  83. public List<CVisualSampleArea> m_visualSamples;
  84. //手绘测量区域
  85. public static CMeasureArea m_DrawMeasureGDIObject = new CMeasureArea();
  86. //多边形测量区域完成标识
  87. public static CDisplayGDIObject m_DrawPolygonFinishGDIObject;
  88. //主窗体对象
  89. OTSIncAMeasureAppForm m_MeasureAppForm;
  90. SEMControlService m_SEMDATAService;
  91. private SlopFocus slopFocus = null;
  92. const float m_PenWidth = 5;
  93. const int m_MinMeasureWidthValue = 20;
  94. //点数量
  95. const int m_PolygonMinPointCount = 2;
  96. //与多边形绘制的开始点相差的像素值
  97. const int m_OffsetPX = 10;
  98. //默认值
  99. const int m_DValue = 1;
  100. SetSEMDATAMParameterWindows setSEMDATAMParameterWindows = null;
  101. #region 手动绘制测量区域
  102. Point m_MouseDownPoint;
  103. Point m_MouseMovePoint;
  104. //手动绘制多边形测量区域完成标识
  105. bool m_IsDrawPolygonFinish = false;
  106. //手动绘制测量区域的形状类型
  107. DrawMeasureAreaActionType m_DrawMeasureType = DrawMeasureAreaActionType.NoAction;
  108. //是否手绘标识
  109. bool m_IsDrawMeasure = false;
  110. #endregion
  111. #endregion
  112. NLog.Logger log;
  113. #region 标尺变量
  114. //最小缩放倍数
  115. const float f_zoom_mix = 0.5f;
  116. //标尺的大小记录
  117. private float f_ruler_size = 100;
  118. //标尺原先大小的记录,参与计算
  119. private float f_old_ruler_size = 100;
  120. #endregion
  121. //国际化
  122. OTSCommon.Language lan;
  123. Hashtable table;
  124. public CDisplayGDIObject sampleHoleImageBuffer = new CDisplayGDIObject(new RectangleF(0, 0, 10, 10), GDIType.SampleHoleImageBuffer);
  125. #region 设置双缓冲
  126. /// <summary>
  127. /// 设置双缓冲
  128. /// </summary>
  129. public void SetDoubleBufferByIsDraw()
  130. {
  131. SetStyle(ControlStyles.UserPaint, true);
  132. SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
  133. this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // 双缓冲
  134. }
  135. #endregion
  136. CFieldPositionHelper pFieldMgr = new CFieldPositionHelper();
  137. #region 构造函数 获取父窗体对象
  138. public OTSSamplespaceWindow(OTSIncAMeasureAppForm MeasureAppForm)
  139. {
  140. InitializeComponent();
  141. m_MeasureAppForm = MeasureAppForm;
  142. SetDoubleBufferByIsDraw();// 双缓冲
  143. //国际化
  144. lan = new OTSCommon.Language(this);
  145. table = lan.GetNameTable(this.Name);
  146. }
  147. #region 菜单操作
  148. private void CMStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  149. {
  150. Point mousePoint = this.PointToClient(Control.MousePosition);
  151. CMStrip.Hide();
  152. switch (e.ClickedItem.Name)
  153. {
  154. case "AddStage":
  155. //添加样品
  156. m_MeasureAppForm.AddNewSampleMeasure(m_SampleHoleSelectName);
  157. break;
  158. case "DeleteStage":
  159. //删除样品
  160. DeleteSampleInfo(m_SampleSelectName);
  161. break;
  162. case "DriveSEMToCenterLocation":
  163. //驱动SEM到中心位置
  164. SetSEMToCenterPoint();
  165. ReadSEMDataAndSetToCurrentSample();
  166. break;
  167. case "DriveSEMToCurrentLocation":
  168. //驱动SEM到当前位置
  169. SetSEMCurrentLocation();
  170. ReadSEMDataAndSetToCurrentSample();
  171. break;
  172. case "SetSEMCenterLocation":
  173. //将测量区域移到SEM当前位置
  174. SetMeasureToSEMLocation();
  175. ReadSEMDataAndSetToCurrentSample();
  176. PrepareVisualMeasureField(GetWorkingVisualSample());
  177. break;
  178. case "ReadSEMData":
  179. ReadSEMDataAndSetToCurrentSample();
  180. PrepareVisualMeasureField(GetWorkingVisualSample());
  181. break;
  182. case "SetSemData":
  183. double SemMag = 0;
  184. double dDistance = 0;
  185. double bri = 0;
  186. double contra = 0;
  187. double kv = 0;
  188. if (m_MeasureAppForm.m_ProjParam.GetWorkingSampleSEMData(ref dDistance, ref SemMag, ref bri, ref contra, ref kv))
  189. {
  190. //设置SEM数据
  191. if(setSEMDATAMParameterWindows==null || setSEMDATAMParameterWindows.IsDisposed)
  192. {
  193. setSEMDATAMParameterWindows = new SetSEMDATAMParameterWindows(m_SEMDATAService);
  194. setSEMDATAMParameterWindows.Show();
  195. }
  196. else
  197. {
  198. setSEMDATAMParameterWindows.Activate();
  199. }
  200. }
  201. break;
  202. case "ShootBSEPicture":
  203. var domain = ConvertMeasureAreaGDIToDomain(GetWorkingVisualSample().GetMeasureGDIObject());
  204. List<CVisualFieldGDIObject> visualfieldRects = null;
  205. visualfieldRects = GetPreviewVisualRects(domain);//get all the possible field rects through C++ code.
  206. PrepareVisualPreviewGDIobj(visualfieldRects);
  207. List<Point> listFieldCenter = new List<Point>();
  208. foreach (var fld in visualfieldRects)
  209. {
  210. listFieldCenter.Add(fld.GetOTSPos());
  211. }
  212. CSmplPreviewMeasure cSmplPreviewMeasure = new CSmplPreviewMeasure(m_MeasureAppForm.m_MsrThreadWrapper.m_measure, listFieldCenter);
  213. Thread thread = new Thread(() =>
  214. {
  215. cSmplPreviewMeasure.DoHolePreview();
  216. });
  217. thread.Start();
  218. break;
  219. case "DeleteBSEPicture":
  220. DeleteHoleBSEImageDataNoMessageBox();
  221. break;
  222. case "DeleteSampleData":
  223. try
  224. {
  225. var frmFieldStart = new frmInitializeStartInput();
  226. frmFieldStart.ShowDialog();
  227. if (frmFieldStart.okcancel == true)
  228. {
  229. InitSampleMeasure(m_MeasureAppForm.m_ProjParam.GetWorkSample(), frmFieldStart.fieldStartNo);
  230. }
  231. }
  232. catch (Exception ex)
  233. {
  234. MessageBox.Show(ex.ToString());
  235. }
  236. break;
  237. case "SlopFocusMenuItem":
  238. if (slopFocus == null)
  239. {
  240. slopFocus = new SlopFocus(this);
  241. }
  242. slopFocus.Show();
  243. break;
  244. }
  245. }
  246. #endregion
  247. public void InitSampleMeasure(COTSSample smpl, int fieldStartNo)
  248. {
  249. m_MeasureAppForm.m_ProjParam.SetWorkSample(smpl.GetName());
  250. m_MeasureAppForm.m_ProjParam.InitWorkingSampleData(fieldStartNo);
  251. m_MeasureAppForm.InitCurrentSampleState();
  252. m_MeasureAppForm.m_MsrThreadWrapper.m_measure.mapSmplMsr.Clear();
  253. var visualsam = GetWorkingVisualSample();
  254. var sam = m_MeasureAppForm.m_ProjRstData.GetWorkingSample();
  255. var allflds = sam.GetFieldsData();
  256. foreach (var f in allflds)
  257. {
  258. if (f.GetMeasureSequence() >= fieldStartNo)
  259. {
  260. Color ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.FieldColor);
  261. ChangeMeasureFieldColor(visualsam, f.GetOTSPosition(), ColorStr);
  262. }
  263. }
  264. m_MeasureAppForm.m_MeasureResultWindow.UpdateResultInfoBySampleName(sam.GetName());
  265. }
  266. /// <summary>
  267. /// 画圆形测试区域 事件
  268. /// </summary>
  269. public void DrawCircleMeasure()
  270. {
  271. //手绘测量区域类型为圆形
  272. m_DrawMeasureType = DrawMeasureAreaActionType.Circle;
  273. m_IsDrawMeasure = true;
  274. m_DrawMeasureGDIObject = null;
  275. this.Cursor = Cursors.Hand;
  276. }
  277. /// <summary>
  278. /// 画矩形测试区域 事件
  279. /// </summary>
  280. public void DrawRectangleMeasure()
  281. {
  282. //手绘测量区域类型为矩形
  283. m_DrawMeasureType = DrawMeasureAreaActionType.Rectangle;
  284. m_IsDrawMeasure = true;
  285. m_DrawMeasureGDIObject = null;
  286. this.Cursor = Cursors.Hand;
  287. }
  288. public void DrawOnlyShotMeasure()
  289. {
  290. //手绘测量区域类型为矩形
  291. m_DrawMeasureType = DrawMeasureAreaActionType.OnlyShot;
  292. m_IsDrawMeasure = true;
  293. m_DrawMeasureGDIObject = null;
  294. this.Cursor = Cursors.Hand;
  295. }
  296. /// <summary>
  297. /// 画多边形测试区域 事件
  298. /// </summary>
  299. public void DrawPolygonMeasure()
  300. {
  301. m_DrawMeasureType = DrawMeasureAreaActionType.Polygon;
  302. m_IsDrawMeasure = true;
  303. //m_DrawMeasureGDIObject = null;
  304. m_DrawMeasureGDIObject = new CMeasureArea(new List<PointF>(), ShapeType.POLYGON, "", "", Color.Red);
  305. this.Cursor = Cursors.Hand;
  306. }
  307. /// <summary>
  308. /// 三点画圆形测试区域 事件 先多边形后圆形
  309. /// </summary>
  310. public void DrawCircleMeasureByThreePoints()
  311. {
  312. //手绘测量区域类型为圆形
  313. m_DrawMeasureType = DrawMeasureAreaActionType.CircleByThreePoints;
  314. m_IsDrawMeasure = true;
  315. m_DrawMeasureGDIObject = null;
  316. this.Cursor = Cursors.Hand;
  317. }
  318. public void DrawRingShapeArea()
  319. {
  320. //手绘测量区域类型为圆形
  321. RingGdiDataInput frmInput = new RingGdiDataInput();
  322. if (frmInput.ShowDialog() == DialogResult.OK)
  323. {
  324. float diameter = (float)m_visualStage.MicronConvertToPixel(frmInput.Diameter);
  325. float ringwidth = (float)m_visualStage.MicronConvertToPixel(frmInput.RingWidth);
  326. var sam = GetWorkingVisualSample();
  327. SizeF size = new SizeF(diameter, diameter);
  328. var position = sam.GetMeasureGDIObject().GetZoomedRegionF().Location;
  329. RectangleF rec = sam.GetMeasureGDIObject().GetZoomedRegionF();
  330. PointF centerPos = new PointF(position.X + rec.Width / 2, position.Y + rec.Height / 2);
  331. PointF newRegionFPos = new PointF(centerPos.X - diameter / 2, centerPos.Y - diameter / 2);
  332. RectangleF rectangle = new RectangleF(newRegionFPos, size);
  333. Color MeasureColor = Color.Red;
  334. CRingGDIObject newGDI;
  335. newGDI = new CRingGDIObject(rectangle, sam.GetSampleGDIObject().HoleNo, sam.GetSampleName(), MeasureColor);
  336. newGDI.SetRingWidth(ringwidth);
  337. newGDI.SetZoomNumber(m_visualStage.GetZoomNum());
  338. newGDI.SetDisplayRefPoint(m_visualStage.GetDisplayRefPoint());
  339. newGDI.IsWorkSample = true;
  340. sam.SetMeasureGDIObject(newGDI);
  341. m_DrawPolygonFinishGDIObject = null;
  342. m_DrawMeasureGDIObject = null;
  343. var para = m_visualStage.GetSampleMeasurePara(sam.GetMeasureGDIObject());
  344. SetWorkSampleMeasureArea(para);
  345. }
  346. }
  347. public void DrawRectangleBytTwoPoint()
  348. {
  349. //手绘测量区域类型为圆形
  350. frmInitializeTwoPointRectangle frmInput = new frmInitializeTwoPointRectangle();
  351. DialogResult result=frmInput.ShowDialog();
  352. if (result == DialogResult.OK)
  353. {
  354. PointF lt =frmInput.LTPoint;
  355. PointF rb= frmInput.RBPoint;
  356. var sam = GetWorkingVisualSample();
  357. PointF otslt=new PointF(), otsrb=new PointF();
  358. m_visualStage.m_SEMStageData.ConvertSEMToOTSCoord(lt,ref otslt);
  359. m_visualStage.m_SEMStageData.ConvertSEMToOTSCoord(rb, ref otsrb);
  360. var visualRec= m_visualStage.GetCtrlCoordRectF(otslt, otsrb);
  361. Color MeasureColor = Color.Red;
  362. CMeasureArea newGDI=new CMeasureArea(visualRec, ShapeType.RECTANGLE,"", sam.GetSampleName(), MeasureColor);
  363. newGDI.SetZoomNumber(m_visualStage.GetZoomNum());
  364. newGDI.SetDisplayRefPoint(m_visualStage.GetDisplayRefPoint());
  365. newGDI.IsWorkSample = true;
  366. sam.SetMeasureGDIObject(newGDI);
  367. m_DrawPolygonFinishGDIObject = null;
  368. m_DrawMeasureGDIObject = null;
  369. var para = m_visualStage.GetSampleMeasurePara(sam.GetMeasureGDIObject());
  370. SetWorkSampleMeasureArea(para);
  371. if(frmInput.IsInclinedPlaneFocus) m_MeasureAppForm.m_ProjParam.GetWorkSample().GetMsrParams().SlopParam = frmInput.GetCSlopFocusParam();
  372. CSEMFieldData semdata = m_MeasureAppForm.m_ProjParam.GetResultData().GetWorkingSample().GetSEMDataMsr();
  373. semdata.SetMagnification(frmInput.GetMagnification());
  374. PrepareVisualMeasureField(GetWorkingVisualSample());
  375. }
  376. }
  377. public void DrawCircleByFixedpoint()
  378. {
  379. frmInitializeImageboundary frmInput = new frmInitializeImageboundary();
  380. DialogResult result = frmInput.ShowDialog();
  381. if (result == DialogResult.OK)
  382. {
  383. PointF firstp = frmInput.FirstPoint;
  384. PointF secondp = frmInput.SecondPoint;
  385. PointF thirdp=frmInput.ThirdPoint;
  386. var sam = GetWorkingVisualSample();
  387. PointF otsfir = new PointF(), otssec = new PointF(), otsthi = new PointF();
  388. m_visualStage.m_SEMStageData.ConvertSEMToOTSCoord(firstp, ref otsfir);
  389. m_visualStage.m_SEMStageData.ConvertSEMToOTSCoord(secondp, ref otssec);
  390. m_visualStage.m_SEMStageData.ConvertSEMToOTSCoord(thirdp, ref otsthi);
  391. float r;
  392. PointF Centerpoint;
  393. GetTriangleExcenterRadius(otsfir, otssec, otsthi, out r, out Centerpoint);
  394. RectangleF rectangleThree = new RectangleF(new PointF(Centerpoint.X - r, Centerpoint.Y - r), new SizeF(r * 2, r * 2));
  395. Color MeasureColor = Color.Red;
  396. CMeasureArea newGDI = new CMeasureArea(rectangleThree, ShapeType.CIRCLE, "", sam.GetSampleName(), MeasureColor);
  397. newGDI.SetZoomNumber(m_visualStage.GetZoomNum());
  398. newGDI.SetDisplayRefPoint(m_visualStage.GetDisplayRefPoint());
  399. newGDI.IsWorkSample = true;
  400. sam.SetMeasureGDIObject(newGDI);
  401. m_DrawPolygonFinishGDIObject = null;
  402. m_DrawMeasureGDIObject = null;
  403. var para = m_visualStage.GetSampleMeasurePara(sam.GetMeasureGDIObject());
  404. SetWorkSampleMeasureArea(para);
  405. if (frmInput.IsInclinedPlaneFocus) {
  406. m_MeasureAppForm.m_ProjParam.GetWorkSample().GetMsrParams().SlopParam = frmInput.GetCSlopFocusParam();
  407. }
  408. CSEMFieldData semdata = m_MeasureAppForm.m_ProjParam.GetWorkSample().GetSEMDataMsr();
  409. semdata.SetMagnification(frmInput.GetMagnification());
  410. PrepareVisualMeasureField(GetWorkingVisualSample());
  411. }
  412. }
  413. public void SetWorkSampleMeasureArea(SampleMeasurePara SMeasurePara)
  414. {
  415. COTSSample WSample = m_MeasureAppForm.m_ProjParam.GetResultData().GetWorkingSample();
  416. if (null == WSample)
  417. {
  418. return;
  419. }
  420. CDomain Domain = new CDomain();
  421. Domain.SetShape((otsdataconst.DOMAIN_SHAPE)SMeasurePara.iShape);
  422. Domain.SetRectDomain(SMeasurePara.MeasureRect);
  423. if (SMeasurePara.DrawPolygonPointList != null)
  424. {
  425. List<Point> PolygonPoint = new List<Point>();
  426. foreach (var item in SMeasurePara.DrawPolygonPointList)
  427. {
  428. PolygonPoint.Add(new Point((int)item.X, (int)item.Y));
  429. }
  430. Domain.SetPolygonPoint(PolygonPoint);
  431. }
  432. WSample.SetSampleHoleName(SMeasurePara.sampleHoleName);
  433. WSample.SetMsrDomain(Domain);
  434. return;
  435. }
  436. public CVisualSampleArea GetWorkingVisualSample()
  437. {
  438. foreach (var s in m_visualSamples)
  439. {
  440. if (s.IsWorkSample())
  441. {
  442. return s;
  443. }
  444. }
  445. return null;
  446. }
  447. public CVisualSampleArea GetVisualSampleByName(string name)
  448. {
  449. foreach (var s in m_visualSamples)
  450. {
  451. if (s.GetSampleName() == name)
  452. {
  453. return s;
  454. }
  455. }
  456. return null;
  457. }
  458. public void DisplayVisualStage(CSampleHolder SStage, CSEMStageData SEMStageData)
  459. {
  460. m_visualStage.clear();
  461. m_visualStage.InitSampleStageData(SStage, SEMStageData, this.Width, this.Height);
  462. m_visualStage.DrawSampleStage();
  463. }
  464. public void DisplayExistSamples(List<SampleMeasurePara> SMeasrueParaList)
  465. {
  466. foreach (var SMeasrueArea in SMeasrueParaList)
  467. {
  468. DisplaySample(SMeasrueArea);
  469. }
  470. SwitchWorkSample(SMeasrueParaList[0].sSampleName);
  471. m_SampleSelectName = SMeasrueParaList[0].sSampleName;
  472. //重新绘制
  473. Invalidate();
  474. }
  475. public void DisplaySample(SampleMeasurePara SMeasrueArea)
  476. {
  477. var m_Sample = m_MeasureAppForm.m_ProjParam.GetResultData().GetSampleByName(SMeasrueArea.sSampleName);
  478. var FldDatas = m_Sample.GetFieldsData();
  479. if (FldDatas.Count == 0)
  480. {
  481. //this part code is to be compatible with previouse version result file which there's no AllField position info.
  482. DrawSampleAndMeasureInfo(SMeasrueArea);
  483. }
  484. else
  485. {
  486. var item = m_visualStage.GetHoleGDIByHoleName(SMeasrueArea.sampleHoleName);
  487. if (item != null)
  488. {
  489. CVisualSampleArea sam;
  490. if (InitVisualSample(SMeasrueArea.sampleHoleName, SMeasrueArea.sSampleName, out sam))
  491. {
  492. if (SMeasrueArea.iShape == ShapeType.POLYGON)
  493. {
  494. var ps = new List<PointF>();
  495. foreach (var p in SMeasrueArea.DrawPolygonPointList)
  496. {
  497. var ctrlcoordPoint = m_visualStage.OTSCoordToCtrlCoord(p);
  498. ps.Add(ctrlcoordPoint);
  499. }
  500. CMeasureArea polygonGdi = new CMeasureArea(ps, ShapeType.POLYGON, SMeasrueArea.sampleHoleName, SMeasrueArea.sSampleName, Color.Red);
  501. sam.SetMeasureGDIObject(polygonGdi);
  502. }
  503. else
  504. {
  505. PointF xHole = new PointF(SMeasrueArea.MeasureRect.Left, SMeasrueArea.MeasureRect.Top);
  506. PointF yHole = new PointF(SMeasrueArea.MeasureRect.Right, SMeasrueArea.MeasureRect.Bottom);
  507. CDisplayGDIObject gdi = m_visualStage.GetCtrlCoordGDI(xHole, yHole, m_visualStage.ConvertShapeTypeToGDIType(SMeasrueArea.iShape), "", "");
  508. gdi.SampleName = SMeasrueArea.sSampleName;
  509. gdi.HoleNo = SMeasrueArea.sampleHoleName;
  510. CMeasureArea measureGdi;
  511. if (m_visualStage.GetMeasureGdiObjectFromSampleGdi(gdi, out measureGdi))
  512. {
  513. sam.SetMeasureGDIObject(measureGdi);
  514. }
  515. }
  516. List<CVisualFieldGDIObject> visualfieldRects = new List<CVisualFieldGDIObject>();
  517. foreach (var fld in FldDatas)
  518. {
  519. float micronWidth = (float)fld.GetOTSRect().GetWidth();
  520. float micronHeight = (float)fld.GetOTSRect().GetHeight();
  521. var fldRect = new RectangleF(new PointF(fld.GetOTSPosition().X - micronWidth / 2, fld.GetOTSPosition().Y - micronHeight / 2), new SizeF(micronWidth, micronHeight));
  522. PointF lt = new PointF(fldRect.Left, fldRect.Top);
  523. PointF rb = new PointF(fldRect.Right, fldRect.Bottom);
  524. RectangleF visualRect = m_visualStage.GetCtrlCoordRectF(lt, rb);
  525. var ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.FieldColor);
  526. string sampleName = sam.GetSampleName();
  527. string sampleHoleName = sam.GetSampleGDIObject().HoleNo;
  528. CVisualFieldGDIObject createRect = new CVisualFieldGDIObject(visualRect, (int)fld.GetOTSPosition().X, (int)fld.GetOTSPosition().Y, sampleHoleName, sampleName, ColorStr);
  529. createRect.Enable = fld.Enable;
  530. visualfieldRects.Add(createRect);
  531. }
  532. sam.GetMeasureGDIObject().SubItems().Clear();
  533. foreach (var r in visualfieldRects)
  534. {
  535. sam.AddFieldGDIObject(r);
  536. }
  537. COTSMsrPrjResultData cProjMgr = m_MeasureAppForm.m_ProjParam.GetResultData();
  538. List<PointF> CompleteFieldList = cProjMgr.GetSampleByName(SMeasrueArea.sSampleName).GetMsrStatus().GetCompletedFieldsCenter();
  539. if (CompleteFieldList.Count > 0)
  540. {
  541. ChangeCompleteFieldMeasureState(CompleteFieldList, Color.Green, sam);
  542. }
  543. }
  544. }
  545. }
  546. }
  547. public void SwitchWorkSample(string sNewWSampleName, bool bDrawField = false)
  548. {
  549. try
  550. {
  551. for (int i = 0; i < m_visualSamples.Count; i++)
  552. {
  553. //获取颜色
  554. if (m_visualSamples[i].GetSampleName() == sNewWSampleName)
  555. {
  556. var theColor = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  557. m_visualSamples[i].GetSampleGDIObject().SelColor = theColor;
  558. m_visualSamples[i].SetIsWorkSample(true);
  559. }
  560. else
  561. {
  562. var SampleColor = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
  563. m_visualSamples[i].GetSampleGDIObject().SelColor = SampleColor;
  564. m_visualSamples[i].SetIsWorkSample(false);
  565. }
  566. }
  567. m_IsDrawMeasure = false;
  568. this.Invalidate();
  569. return;
  570. }
  571. catch (Exception ex)
  572. {
  573. log.Trace(ex.ToString());
  574. }
  575. }
  576. public void ChangeCompleteFieldMeasureState(List<PointF> CompleteFieldList, Color changeColor, CVisualSampleArea vsSam)
  577. {
  578. foreach (var p in CompleteFieldList)
  579. {
  580. ChangeMeasureFieldColor(vsSam, p, changeColor);
  581. }
  582. }
  583. public void ChangeMeasureFieldColor(CVisualSampleArea vsSam, PointF CurrentFIELDOTSPoint, Color changeColor)
  584. {
  585. foreach (var gdi in vsSam.GetMeasureFieldGDIObjects())
  586. {
  587. var fieldPoint = m_visualStage.OTSCoordToCtrlCoord(new PointF((float)CurrentFIELDOTSPoint.X, (float)CurrentFIELDOTSPoint.Y));
  588. if (gdi.IfContains(fieldPoint))
  589. {
  590. //修改完成状态
  591. gdi.SelColor = changeColor;
  592. break;
  593. }
  594. }
  595. }
  596. public void ChangeWorkSampleName(string sNewWSampleName)
  597. {
  598. //更换样品名称
  599. var sam = GetWorkingVisualSample();
  600. sam.SetSampleName(sNewWSampleName);
  601. this.Invalidate();
  602. return;
  603. }
  604. public void SetMeasureState(Color setColor)
  605. {
  606. foreach (var items in m_visualSamples)
  607. {
  608. items.GetMeasureGDIObject().SelColor = setColor;
  609. }
  610. }
  611. #endregion
  612. public void SetSampleState(Color setColor)
  613. {
  614. foreach (var items in m_visualSamples)
  615. {
  616. if (items.GetSampleGDIObject().IsDragging)
  617. {
  618. //设置颜色
  619. var ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  620. items.GetSampleGDIObject().SelColor = ColorStr;
  621. }
  622. else
  623. {
  624. items.GetSampleGDIObject().SelColor = setColor;
  625. }
  626. }
  627. }
  628. public bool DeleteSample(string SampleName)
  629. {
  630. var sam = GetVisualSampleByName(SampleName);
  631. m_visualStage.DecreaseSampleCount(SampleName);
  632. m_visualSamples.Remove(sam);
  633. var ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
  634. SetSampleState(ColorStr);
  635. SetMeasureState(ColorStr);
  636. return false;
  637. }
  638. public void DeleteWorkSample(string sDeleteWSampleName)
  639. {
  640. try
  641. {
  642. DeleteSample(sDeleteWSampleName);
  643. }
  644. catch (Exception ex)
  645. {
  646. log.Error(ex.ToString());
  647. }
  648. }
  649. #region 更改工作样品中 测量区域形状
  650. public void changeShape(ShapeType iShape)
  651. {
  652. try
  653. {
  654. string sampleName = m_MeasureAppForm.m_ProjParam.GetWorkSampleName();
  655. //m_Shap 更换样品形状
  656. var sam = GetWorkingVisualSample();
  657. var itemMeasure = sam.GetMeasureGDIObject();
  658. itemMeasure.Myshape = iShape;
  659. var sampleMeasurePara = m_visualStage.GetSampleMeasurePara(sam.GetMeasureGDIObject());
  660. SetWorkSampleMeasureArea(sampleMeasurePara);
  661. PrepareVisualMeasureField(sam);
  662. this.Invalidate();
  663. return;
  664. }
  665. catch (Exception ex)
  666. {
  667. log.Error(ex.ToString());
  668. }
  669. }
  670. #endregion
  671. public void AddSampleArea(SampleMeasurePara SMeasurePara)
  672. {
  673. try
  674. {
  675. CMStrip.Hide();
  676. CVisualSampleArea sam;
  677. //添加样品
  678. foreach (var itemSample in m_visualSamples)
  679. {
  680. //设置颜色
  681. var ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
  682. itemSample.GetSampleGDIObject().SelColor = ColorStr;
  683. itemSample.SetIsWorkSample(false);
  684. }
  685. if (m_visualStage.GetVisualSampleArea(SMeasurePara, out sam))
  686. {
  687. sam.SetIsWorkSample(true);
  688. m_visualSamples.Add(sam);
  689. m_SampleSelectName = SMeasurePara.sSampleName;
  690. var para = m_visualStage.GetSampleMeasurePara(sam.GetMeasureGDIObject());
  691. //var para = SMeasurePara;
  692. SetWorkSampleMeasureArea(para);
  693. Invalidate();
  694. }
  695. }
  696. catch (Exception ex)
  697. {
  698. log.Error(ex.ToString());
  699. }
  700. }
  701. public bool InitVisualSample(string SampleHoleNo, string SampleName, out CVisualSampleArea outsample)
  702. {
  703. CDisplayGDIObject itemAdd;
  704. //设置样品选择状态为非工作样品
  705. foreach (var Sample in m_visualSamples)
  706. {
  707. var itemSample = Sample.GetSampleGDIObject();
  708. //设置颜色
  709. var ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
  710. itemSample.SelColor = ColorStr;
  711. itemSample.IsWorkSample = false;
  712. }
  713. itemAdd = m_visualStage.GetHoleGDIByHoleName(SampleHoleNo);
  714. if (itemAdd != null)
  715. {
  716. //获取样品台类型
  717. //var shape = itemAdd.Shape;
  718. //设置颜色
  719. var ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  720. Color selColor = ColorStr;
  721. CDisplayGDIObject sample = new CDisplayGDIObject(itemAdd.GetOrigionalDrawRegionF(), itemAdd.GDIType, itemAdd.HoleNo, selColor);
  722. //累加样品数量
  723. itemAdd.SampleCount += 1;
  724. itemAdd.IsWorkSample = true;
  725. sample.SampleName = SampleName;
  726. sample.HoleNo = itemAdd.HoleNo;
  727. var newSam = new CVisualSampleArea();
  728. newSam.SetSampleGDIObject(sample);
  729. newSam.SetSampleName(sample.SampleName);
  730. m_visualSamples.Add(newSam);
  731. outsample = newSam;
  732. return true;
  733. }
  734. outsample = null;
  735. return false;
  736. }
  737. #region 设置工作样品
  738. /// <summary>
  739. /// 设置工作样品与测量区域
  740. /// </summary>
  741. /// <param name="sampleName">样品名称</param>
  742. public void SetSampleOrder(string sampleName)
  743. {
  744. //修改测量区域集合 索引 (添加样品或者切换样品时,将当前工作样品显示在样品孔的最上)
  745. m_visualSamples = SelectMeasureIndexIsTop(m_visualSamples, sampleName);
  746. }
  747. #endregion
  748. private List<CVisualSampleArea> SelectMeasureIndexIsTop(List<CVisualSampleArea> objList, string SampleName)
  749. {
  750. List<CVisualSampleArea> objListTemp = objList;
  751. CVisualSampleArea itemTemp;
  752. foreach (CVisualSampleArea item in objList)
  753. {
  754. if (item.GetSampleName() == SampleName)
  755. {
  756. //临时记录所选测量区域
  757. itemTemp = item;
  758. //删除原信息
  759. objListTemp.Remove(item);
  760. //添加新信息
  761. objListTemp.Insert(objListTemp.Count, itemTemp);
  762. break;
  763. }
  764. }
  765. return objListTemp;
  766. }
  767. //响应委托事件的样品台数据
  768. public void InitStageDisplay(CSampleHolder SStage, CSEMStageData SEMStageData)
  769. {
  770. m_visualStage.InitSampleStageData(SStage, SEMStageData, this.Width, this.Height);
  771. //清除所有绘制的图形信息
  772. ClearDrawInfo();
  773. //绘制样品台信息
  774. m_visualStage.DrawSampleStage();
  775. //标尺初始化
  776. RulerInit(m_visualStage.GetOTSSampleStageData());
  777. ShowRulerLocation();
  778. if (m_visualSamples.Count == 0)
  779. {
  780. //将测量状态初始化
  781. m_MeasureAppForm.m_MessureStatuWindow.SetMeasureStatusInit();
  782. }
  783. Invalidate();
  784. }
  785. private void GetTriangleExcenterRadius(PointF px1, PointF px2, PointF px3, out float R, out PointF center)
  786. {
  787. float x1, y1, x2, y2, x3, y3;
  788. float a, b;
  789. x1 = px1.X;
  790. y1 = px1.Y;
  791. x2 = px2.X;
  792. y2 = px2.Y;
  793. x3 = px3.X;
  794. y3 = px3.Y;
  795. a = ((y2 - y1) * (y3 * y3 - y1 * y1 + x3 * x3 - x1 * x1) - (y3 - y1) * (y2 * y2 - y1 * y1 + x2 * x2 - x1 * x1)) / (2 * ((x3 - x1) * (y2 - y1) - (x2 - x1) * (y3 - y1)));
  796. b = ((x2 - x1) * (x3 * x3 - x1 * x1 + y3 * y3 - y1 * y1) - (x3 - x1) * (x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1)) / (2 * ((y3 - y1) * (x2 - x1) - (y2 - y1) * (x3 - x1)));
  797. center = new PointF(a, b);
  798. R = (float)Math.Sqrt((x1 - a) * (x1 - a) + (y1 - b) * (y1 - b));
  799. }
  800. #region 窗体事件
  801. private void OTSSamplespaceWindow_Load(object sender, EventArgs e)
  802. {
  803. m_visualStage = new CVisualStage();
  804. m_visualSamples = new List<CVisualSampleArea>();
  805. this.ResizeRedraw = false;
  806. control_Ruler2 = new Control_Ruler();
  807. Point rulerLocation = new Point(10, this.Height - (int)(control_Ruler2.Height * 2));
  808. control_Ruler2.Location = rulerLocation;
  809. this.pictureBox1.Controls.Add(control_Ruler2);
  810. log = NLog.LogManager.GetCurrentClassLogger();
  811. pictureBox1.BackColor = Color.Transparent;
  812. sampleHoleImageBuffer = new CDisplayGDIObject(new RectangleF(0, 0, m_MeasureAppForm.Width, m_MeasureAppForm.Height), GDIType.SampleHoleImageBuffer); ;
  813. sampleHoleImageBuffer.BSEImage = new Bitmap(m_MeasureAppForm.Width, m_MeasureAppForm.Height);//the m_measureAppForm.Width and Height is large enough to contain the BSE image and not changed.
  814. }
  815. public static void SetShowCMStrip(ContextMenuType menuType, ContextMenuStrip cmStrip)
  816. {
  817. switch (menuType)
  818. {
  819. case ContextMenuType.SampleHoleMenu:
  820. cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
  821. cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = false;
  822. cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = false;
  823. cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = false;
  824. cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = false;
  825. cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = false;
  826. cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
  827. cmStrip.Items[(int)MenuIndex.SEMStripSeparator].Enabled = false;
  828. cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = false;
  829. cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = false;
  830. cmStrip.Items[(int)MenuIndex.DeleteSampleData].Enabled = false;
  831. cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = false;
  832. break;
  833. case ContextMenuType.SampleMenu:
  834. cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
  835. cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = true;
  836. cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = true;
  837. cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = false;
  838. cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = false;
  839. cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = false;
  840. cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
  841. cmStrip.Items[(int)MenuIndex.SEMStripSeparator].Enabled = false;
  842. cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = true;
  843. cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = false;
  844. cmStrip.Items[(int)MenuIndex.DeleteSampleData].Enabled = true;
  845. cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = true;
  846. break;
  847. case ContextMenuType.MeasureMenu:
  848. cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
  849. cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = true;
  850. cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = true;
  851. cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = true;
  852. cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = true;
  853. cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = true;
  854. cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
  855. cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = true;
  856. cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = true;
  857. cmStrip.Items[(int)MenuIndex.DeleteSampleData].Enabled = false;
  858. cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = true;
  859. break;
  860. case ContextMenuType.FieldMenu:
  861. cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
  862. cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = true;
  863. cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = true;
  864. cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = true;
  865. cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = true;
  866. cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = true;
  867. cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
  868. cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = true;
  869. cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = true;
  870. cmStrip.Items[(int)MenuIndex.DeleteSampleData].Enabled = true;
  871. cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = true;
  872. break;
  873. case ContextMenuType.SampleStateMenu:
  874. cmStrip.Items[(int)MenuIndex.AddSample].Enabled = false;
  875. cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = false;
  876. cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = false;
  877. cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = false;
  878. cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = false;
  879. cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = false;
  880. cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
  881. cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = false;
  882. cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = false;
  883. cmStrip.Items[(int)MenuIndex.DeleteSampleData].Enabled = false;
  884. cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = false;
  885. break;
  886. case ContextMenuType.SampleHoleBSEImage:
  887. cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
  888. cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = false;
  889. cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = false;
  890. cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = false;
  891. cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = false;
  892. cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = false;
  893. cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
  894. cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = true;
  895. cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = true;
  896. cmStrip.Items[(int)MenuIndex.DeleteSampleData].Enabled = false;
  897. cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = false;
  898. break;
  899. }
  900. }
  901. private List<CDisplayGDIObject> GetAllVisualSampleGDIObject()
  902. {
  903. List<CDisplayGDIObject> allobj = new List<CDisplayGDIObject>();
  904. foreach (var s in m_visualSamples)
  905. {
  906. allobj.Add(s.GetSampleGDIObject());
  907. allobj.Add(s.GetMeasureGDIObject());
  908. }
  909. allobj.AddRange(m_visualStage.FrameOfHoleGDIObjects);
  910. allobj.Add(sampleHoleImageBuffer);
  911. return allobj;
  912. }
  913. private List<CDisplayGDIObject> GetOnlyVisualSampleGDIObject()
  914. {
  915. List<CDisplayGDIObject> allobj = new List<CDisplayGDIObject>();
  916. foreach (var s in m_visualSamples)
  917. {
  918. allobj.Add(s.GetSampleGDIObject());
  919. }
  920. return allobj;
  921. }
  922. private List<CDisplayGDIObject> GetAllVisualFieldGdiObject()
  923. {
  924. List<CDisplayGDIObject> allobj = new List<CDisplayGDIObject>();
  925. foreach (var s in m_visualSamples)
  926. {
  927. allobj.Add(s.GetMeasureGDIObject());
  928. }
  929. return allobj;
  930. }
  931. private EnumMousePointPosition MousePointPosition(Point point, Point e)
  932. {
  933. //MouseDrag 中心
  934. if ((e.X == point.X) && (e.Y == point.Y))
  935. {
  936. return EnumMousePointPosition.MouseDrag;
  937. }
  938. //MouseSizeTopLeft 上左
  939. if ((e.X < point.X) && (e.Y < point.Y))
  940. {
  941. return EnumMousePointPosition.MouseSizeTopLeft;
  942. }
  943. //MouseSizeTopRight 下右
  944. if ((e.X > point.X) && (e.Y < point.Y))
  945. {
  946. return EnumMousePointPosition.MouseSizeTopRight;
  947. }
  948. //MouseSizeLeft 左侧
  949. if ((e.X < point.X) && (e.Y == point.Y))
  950. {
  951. return EnumMousePointPosition.MouseSizeLeft;
  952. }
  953. //MouseSizeRight 右侧
  954. if ((e.X > point.X) && (e.Y == point.Y))
  955. {
  956. return EnumMousePointPosition.MouseSizeRight;
  957. }
  958. //MouseSizeTop 上侧
  959. if ((e.X == point.X) && (e.Y < point.Y))
  960. {
  961. return EnumMousePointPosition.MouseSizeTop;
  962. }
  963. //MouseSizeBottom 下侧
  964. if ((e.X == point.X) && (e.Y > point.Y))
  965. {
  966. return EnumMousePointPosition.MouseSizeBottom;
  967. }
  968. //MouseSizeBottomRight 下左
  969. if ((e.X < point.X) && (e.Y > point.Y))
  970. {
  971. return EnumMousePointPosition.MouseSizeBottomLeft;
  972. }
  973. //MouseSizeBottomRight 下右
  974. if ((e.X > point.X) && (e.Y > point.Y))
  975. {
  976. return EnumMousePointPosition.MouseSizeBottomRight;
  977. }
  978. return EnumMousePointPosition.MouseSizeNone;
  979. }
  980. protected override void OnMouseDown(MouseEventArgs e)
  981. {
  982. bool runflag = m_MeasureAppForm.MeasureThreadRunFlag;
  983. if (runflag)
  984. {
  985. return;
  986. }
  987. Point _Point;
  988. this.m_MouseDownPoint = new Point(e.X, e.Y);
  989. //判断当前是否手绘
  990. if (m_IsDrawMeasure)
  991. {
  992. var measurepoint = new Rectangle(this.m_MouseDownPoint, new Size(2, 2));
  993. if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(measurepoint))
  994. {
  995. m_IsDrawMeasure = true;
  996. }
  997. else
  998. {
  999. m_IsDrawMeasure = false;
  1000. return;
  1001. }
  1002. COTSSample workSample = m_MeasureAppForm.m_ProjParam.GetWorkSample();
  1003. string sampleHoleName = "";
  1004. string sampleName = "";
  1005. if (workSample != null)
  1006. {
  1007. sampleHoleName = workSample.GetSampleHoleName();
  1008. sampleName = workSample.GetName();
  1009. }
  1010. //绘制多边形 测量区域
  1011. if (m_DrawMeasureType == DrawMeasureAreaActionType.Polygon)
  1012. {
  1013. if (m_DrawMeasureGDIObject == null)
  1014. {
  1015. m_DrawMeasureGDIObject = new CMeasureArea(new List<PointF>(), ShapeType.POLYGON, sampleHoleName, sampleName, Color.Red);
  1016. }
  1017. var polygonPoints = m_DrawMeasureGDIObject.GetPolygonPointFList();
  1018. if (m_IsDrawPolygonFinish)
  1019. {
  1020. DialogResult dResult = MessageBox.Show(table["message10"].ToString(), table["message11"].ToString(), MessageBoxButtons.YesNo);
  1021. if (dResult == DialogResult.Yes)
  1022. {
  1023. Point startPoint = new Point((int)(polygonPoints[0].X), (int)(polygonPoints[0].Y));//the last point is the first point too.we get the first point as the last point.
  1024. polygonPoints.Add(startPoint);
  1025. CMeasureArea polygonGdi = new CMeasureArea(polygonPoints, ShapeType.POLYGON, sampleHoleName, sampleName, Color.Red);
  1026. polygonGdi.SetZoomNumber(m_visualStage.GetZoomNum());
  1027. polygonGdi.SetDisplayRefPoint(m_visualStage.GetDisplayRefPoint());
  1028. polygonGdi.SetPolygonPointFList(polygonPoints);
  1029. polygonGdi.IsWorkSample = true;
  1030. var sam = GetVisualSampleByName(sampleName);
  1031. if (sam == null) return;
  1032. sam.SetMeasureGDIObject(polygonGdi);
  1033. m_DrawPolygonFinishGDIObject = null;
  1034. m_DrawMeasureGDIObject = null;
  1035. var para = m_visualStage.GetSampleMeasurePara(sam.GetMeasureGDIObject());
  1036. SetWorkSampleMeasureArea(para);
  1037. m_MeasureAppForm.SwitchWSample(m_SampleSelectName);
  1038. //-------------------- draw measrue field and save these data to sample
  1039. PrepareVisualMeasureField(sam);
  1040. //--------------------
  1041. Invalidate();
  1042. m_IsDrawMeasure = false;
  1043. m_IsDrawPolygonFinish = false;
  1044. this.Cursor = Cursors.Default;
  1045. return;
  1046. }
  1047. else
  1048. {
  1049. return;
  1050. }
  1051. }
  1052. polygonPoints.Add(m_MouseDownPoint);
  1053. m_DrawMeasureGDIObject.SetPolygonPointFList(polygonPoints);
  1054. return;
  1055. }
  1056. else if (m_DrawMeasureType == DrawMeasureAreaActionType.CircleByThreePoints)
  1057. {
  1058. if (m_DrawMeasureGDIObject == null)
  1059. {
  1060. m_DrawMeasureGDIObject = new CMeasureArea(new List<PointF>(), ShapeType.POLYGON, sampleHoleName, sampleName, Color.Red);
  1061. }
  1062. var m_ThreePointCirclePoints = m_DrawMeasureGDIObject.GetPolygonPointFList();
  1063. m_ThreePointCirclePoints.Add(m_MouseDownPoint);
  1064. if (m_ThreePointCirclePoints.Count == 3)//three point can make a circle .
  1065. {
  1066. float r;
  1067. PointF Centerpoint;
  1068. GetTriangleExcenterRadius(m_ThreePointCirclePoints[0], m_ThreePointCirclePoints[1], m_ThreePointCirclePoints[2], out r, out Centerpoint);
  1069. RectangleF rectangleThree = new RectangleF(new PointF(Centerpoint.X - r, Centerpoint.Y - r), new SizeF(r * 2, r * 2));
  1070. if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(rectangleThree))
  1071. {
  1072. m_IsDrawMeasure = true;
  1073. }
  1074. else
  1075. {
  1076. m_IsDrawMeasure = false;
  1077. return;
  1078. }
  1079. Color MeasureColor = Color.Red;
  1080. CMeasureArea CRectangleGDI = new CMeasureArea(rectangleThree, ShapeType.CIRCLE, sampleHoleName, sampleName, MeasureColor);
  1081. m_DrawMeasureGDIObject = CRectangleGDI;
  1082. m_DrawMeasureGDIObject.SetZoomNumber(m_visualStage.GetZoomNum());
  1083. m_DrawMeasureGDIObject.SetDisplayRefPoint(m_visualStage.GetDisplayRefPoint());
  1084. var sam1 = GetVisualSampleByName(sampleName);
  1085. if (sam1 == null) return;
  1086. sam1.SetMeasureGDIObject(m_DrawMeasureGDIObject);
  1087. sam1.GetMeasureGDIObject().SetZoomedRegionF(rectangleThree);
  1088. m_DrawMeasureGDIObject = null;
  1089. m_ThreePointCirclePoints.Clear();
  1090. var para = m_visualStage.GetSampleMeasurePara(sam1.GetMeasureGDIObject());
  1091. SetWorkSampleMeasureArea(para);
  1092. m_MeasureAppForm.SwitchWSample(m_SampleSelectName);
  1093. Invalidate();
  1094. //设置手绘标识
  1095. m_IsDrawMeasure = false;
  1096. this.Cursor = Cursors.Default;
  1097. return;
  1098. }
  1099. Invalidate();
  1100. return;
  1101. }
  1102. else if (m_DrawMeasureType == DrawMeasureAreaActionType.Rectangle || m_DrawMeasureType == DrawMeasureAreaActionType.OnlyShot)
  1103. {
  1104. int sizeWH = 5;
  1105. Size size = new Size(sizeWH, sizeWH);
  1106. Rectangle rectangle = new Rectangle(m_MouseDownPoint, size);
  1107. Color MeasureColor = Color.Red;
  1108. if (m_DrawMeasureType == DrawMeasureAreaActionType.OnlyShot)
  1109. {
  1110. MeasureColor = Color.Green;
  1111. }
  1112. CMeasureArea newGDI;
  1113. newGDI = new CMeasureArea(rectangle, ShapeType.RECTANGLE, sampleName, sampleName, MeasureColor);
  1114. newGDI.SetZoomNumber(m_visualStage.GetZoomNum());
  1115. newGDI.SetDisplayRefPoint(m_visualStage.GetDisplayRefPoint());
  1116. m_DrawMeasureGDIObject = newGDI;
  1117. return;
  1118. }
  1119. else if (m_DrawMeasureType == DrawMeasureAreaActionType.Circle)
  1120. {
  1121. int sizeWH = 5;
  1122. Size size = new Size(sizeWH, sizeWH);
  1123. Rectangle rectangle = new Rectangle(m_MouseDownPoint, size);
  1124. Color MeasureColor = Color.Red;
  1125. CMeasureArea newGDI;
  1126. newGDI = new CMeasureArea(rectangle, ShapeType.CIRCLE, sampleName, sampleName, MeasureColor);
  1127. newGDI.SetZoomNumber(m_visualStage.GetZoomNum());
  1128. newGDI.SetDisplayRefPoint(m_visualStage.GetDisplayRefPoint());
  1129. m_DrawMeasureGDIObject = newGDI;
  1130. return;
  1131. }
  1132. else if (m_DrawMeasureType == DrawMeasureAreaActionType.InverseSelection)
  1133. {
  1134. int sizeWH = 5;
  1135. Size size = new Size(sizeWH, sizeWH);
  1136. Rectangle rectangle = new Rectangle(m_MouseDownPoint, size);
  1137. Color MeasureColor = Color.Red;
  1138. CMeasureArea newGDI;
  1139. newGDI = new CMeasureArea(rectangle, ShapeType.RECTANGLE, sampleName, sampleName, MeasureColor);
  1140. newGDI.SetZoomNumber(m_visualStage.GetZoomNum());
  1141. newGDI.SetDisplayRefPoint(m_visualStage.GetDisplayRefPoint());
  1142. m_DrawMeasureGDIObject = newGDI;
  1143. return;
  1144. }
  1145. }
  1146. else if (!m_IsDrawMeasure)
  1147. {
  1148. if (e.Button == MouseButtons.Right)
  1149. {
  1150. //获取鼠标右键点击位置
  1151. m_MouseDownPoint = e.Location;
  1152. var workingSam = GetWorkingVisualSample();
  1153. if (workingSam != null)
  1154. {
  1155. foreach (CDisplayGDIObject item in workingSam.GetMeasureFieldGDIObjects())
  1156. {
  1157. if (item.IfZoomContains(e.Location))
  1158. {
  1159. _Point = this.PointToClient(Cursor.Position);
  1160. SetShowCMStrip(ContextMenuType.FieldMenu, CMStrip);
  1161. this.CMStrip.Show(this, _Point);
  1162. return;
  1163. }
  1164. }
  1165. }
  1166. foreach (var item in m_visualSamples)
  1167. {
  1168. bool isSelectingMeasureArea = false;
  1169. if (item.GetMeasureGDIObject().Myshape == ShapeType.POLYGON)
  1170. {
  1171. if (item.GetMeasureGDIObject().GetGPath().IsVisible(e.Location))
  1172. {
  1173. isSelectingMeasureArea = true;
  1174. }
  1175. }
  1176. else
  1177. {
  1178. if (item.GetMeasureGDIObject().IfZoomContains(e.Location))
  1179. {
  1180. isSelectingMeasureArea = true;
  1181. int WH = 2;
  1182. Rectangle rect = new Rectangle(e.Location, new Size(WH, WH));
  1183. if (!m_visualStage.CheckMeasureAreaIsBeyondStageArea(rect))
  1184. {
  1185. break;
  1186. }
  1187. }
  1188. }
  1189. if (isSelectingMeasureArea)
  1190. {
  1191. SetShowCMStrip(ContextMenuType.MeasureMenu, CMStrip);
  1192. _Point = this.PointToClient(Cursor.Position);
  1193. this.CMStrip.Show(this, _Point);
  1194. m_SampleHoleSelectName = item.GetMeasureGDIObject().HoleNo;
  1195. if (m_SampleSelectName != item.GetMeasureGDIObject().SampleName)
  1196. {
  1197. m_SampleSelectName = item.GetSampleName();
  1198. item.SetIsWorkSample(true);
  1199. //设置工作样品
  1200. m_MeasureAppForm.SwitchWSample(m_SampleSelectName);
  1201. Invalidate();
  1202. }
  1203. return;
  1204. }
  1205. }
  1206. foreach (CDisplayGDIObject item in m_visualStage.FrameOfHoleGDIObjects)
  1207. {
  1208. if (item.IfZoomContains(e.Location))
  1209. {
  1210. _Point = this.PointToClient(Cursor.Position);
  1211. SetShowCMStrip(ContextMenuType.SampleHoleBSEImage, CMStrip);
  1212. this.CMStrip.Show(this, _Point);
  1213. return;
  1214. }
  1215. }
  1216. //只点击样品上(测量区域被移动到其他地方)
  1217. for (int i = m_visualSamples.Count - 1; i >= 0; i--)
  1218. {
  1219. if (m_visualSamples[i].GetSampleGDIObject().IfZoomContains(e.Location))
  1220. {
  1221. _Point = this.PointToClient(Cursor.Position);
  1222. //设置编辑右键菜单项
  1223. SetShowCMStrip(ContextMenuType.SampleMenu, CMStrip);
  1224. this.CMStrip.Show(this, _Point);
  1225. if (m_SampleSelectName != m_visualSamples[i].GetSampleName())
  1226. {
  1227. m_SampleSelectName = m_visualSamples[i].GetSampleName();
  1228. m_SampleHoleSelectName = m_visualSamples[i].GetMeasureGDIObject().HoleNo;
  1229. m_visualSamples[i].SetIsWorkSample(true);
  1230. m_MeasureAppForm.SwitchWSample(m_SampleSelectName);
  1231. Invalidate();
  1232. }
  1233. return;
  1234. }
  1235. }
  1236. //点击样品孔
  1237. CDisplayGDIObject gdiitem;
  1238. if (m_visualStage.IfMouseInSampleHole(e.Location, out gdiitem))
  1239. {
  1240. _Point = this.PointToClient(Cursor.Position);
  1241. SetShowCMStrip(ContextMenuType.SampleHoleMenu, CMStrip);
  1242. this.CMStrip.Show(this, _Point);
  1243. m_SampleHoleSelectName = gdiitem.HoleNo;
  1244. return;
  1245. }
  1246. if (m_visualStage.IfMouseInStage(e.Location))
  1247. {
  1248. SetShowCMStrip(ContextMenuType.SampleStateMenu, CMStrip);
  1249. _Point = this.PointToClient(Cursor.Position);
  1250. this.CMStrip.Show(this, _Point);
  1251. return;
  1252. }
  1253. return;
  1254. }
  1255. else if (e.Button == MouseButtons.Left)
  1256. {
  1257. //测量区域
  1258. if (Control.ModifierKeys == Keys.Control)// ctrl key is pressed,means changing position or altering the visual sample area.
  1259. {
  1260. var sam = GetWorkingVisualSample();
  1261. if (sam != null)
  1262. {
  1263. //var selWSampleMeasureStatus = m_MeasureAppForm.m_ProjParam.GetWorkSampleMeasureStatus();
  1264. COTSSample COTSSample = m_MeasureAppForm.m_ProjParam.GetResultData().GetWorkingSample();
  1265. int completeflds = COTSSample.GetMsrStatus().GetCompletedFields();
  1266. if (completeflds > 0)
  1267. {
  1268. return;
  1269. }
  1270. var item = sam.GetMeasureGDIObject();
  1271. if (item.Myshape == ShapeType.POLYGON)
  1272. {
  1273. bool isSelPolygonPoint = false;
  1274. foreach (PointF itemPoint in item.GetPolygonPointFList())
  1275. {
  1276. if (Math.Abs(itemPoint.X - e.X) <= m_OffsetPX && Math.Abs(itemPoint.Y - e.Y) <= m_OffsetPX)
  1277. {
  1278. isSelPolygonPoint = true;
  1279. item.SelColor = Color.Red;
  1280. item.DraggingPoint = new PointF(itemPoint.X, itemPoint.Y);//e.Location;
  1281. item.IsAltering = true;//this state means operator want to alter the size of the polygon shape.
  1282. item.IsDragging = false;
  1283. break;
  1284. }
  1285. }
  1286. if (!isSelPolygonPoint)//not selecting the polygon point,just dragging on the inside area of the polygon shape.
  1287. {
  1288. if (item.GetGPath().IsVisible(e.Location))
  1289. {
  1290. item.SelColor = Color.Red;
  1291. item.IsDragging = true;
  1292. item.DraggingPoint = e.Location;
  1293. item.IsAltering = false;
  1294. }
  1295. }
  1296. }
  1297. else
  1298. {
  1299. if (item.GetGPath().IsOutlineVisible((float)e.X, (float)e.Y, new Pen(Color.Gray, m_PenWidth)))
  1300. {
  1301. item.SelColor = Color.Red;
  1302. item.IsDragging = false;
  1303. item.DraggingPoint = e.Location;
  1304. item.IsAltering = true;
  1305. }
  1306. else//not outlinevisible then is altering sample area position.
  1307. {
  1308. if (item.IfZoomContains(e.Location))
  1309. {
  1310. item.SelColor = Color.Red;
  1311. item.IsDragging = true;
  1312. item.DraggingPoint = e.Location;
  1313. item.IsAltering = false;
  1314. }
  1315. }
  1316. }
  1317. }
  1318. }
  1319. //click on the sample area without ctrl key,just switch to that sample.
  1320. if (!(Control.ModifierKeys == Keys.Control) )
  1321. {
  1322. for (int i = m_visualSamples.Count - 1; i >= 0; i--)
  1323. {
  1324. var sam1 = m_visualSamples[i];
  1325. if (sam1.GetSampleGDIObject().IfZoomContains(e.Location) || sam1.GetMeasureGDIObject().IfZoomContains(e.Location))
  1326. {
  1327. //NLog.LogManager.GetCurrentClassLogger().Info(sam1.GetMeasureGDIObject().GetOrigionalDrawRegionF().ToString());
  1328. var measureItem = sam1.GetMeasureGDIObject();
  1329. measureItem.SelColor = Color.Red;
  1330. //设置为工作样品
  1331. sam1.SetIsWorkSample(true);
  1332. //获取颜色
  1333. var theColor = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  1334. sam1.GetSampleGDIObject().SelColor = theColor;
  1335. m_SampleSelectName = sam1.GetSampleName();
  1336. m_MeasureAppForm.SwitchWSample(m_SampleSelectName);
  1337. break;
  1338. }
  1339. }
  1340. }
  1341. CDisplayGDIObject stageobj;
  1342. if (m_visualStage.IfMouseInStage(e.Location, out stageobj))
  1343. {
  1344. MouseDownFunction(m_visualStage.GetAllGDIObject(), e);
  1345. //样品
  1346. MouseDownFunction(GetAllVisualSampleGDIObject(), e);
  1347. }
  1348. }
  1349. }
  1350. //重绘控件
  1351. Invalidate();
  1352. }
  1353. protected override void OnMouseMove(MouseEventArgs e)
  1354. {
  1355. bool runflag = m_MeasureAppForm.MeasureThreadRunFlag;
  1356. if (runflag)
  1357. {
  1358. return;
  1359. }
  1360. this.m_MouseMovePoint = new Point(e.X, e.Y);
  1361. if (m_IsDrawMeasure)
  1362. {
  1363. if (m_DrawMeasureGDIObject == null) return;//the object must be initialized by mousedown event.
  1364. //绘制多边形
  1365. if (m_DrawMeasureType == DrawMeasureAreaActionType.Polygon)
  1366. {
  1367. m_DrawMeasureGDIObject.PolygonDrawingEndPoint = this.m_MouseMovePoint;
  1368. var m_PolygonPoint = m_DrawMeasureGDIObject.GetPolygonPointFList();
  1369. //显示直线开始点与鼠标当前位置的直线
  1370. PointF startPoint = new PointF();
  1371. if (m_PolygonPoint.Count > 0)
  1372. {
  1373. startPoint = m_PolygonPoint[0];
  1374. }
  1375. //显示绘制多边形完成标识
  1376. if (m_PolygonPoint.Count > m_PolygonMinPointCount)
  1377. {
  1378. if (Math.Abs(m_MouseMovePoint.X - startPoint.X) <= m_OffsetPX && Math.Abs(m_MouseMovePoint.Y - startPoint.Y) <= m_OffsetPX)
  1379. {
  1380. //显示绘制多边形完成标识
  1381. m_IsDrawPolygonFinish = true;
  1382. int rectSize = m_MinMeasureWidthValue;
  1383. if (m_DrawPolygonFinishGDIObject == null)
  1384. {
  1385. Point PolygonFinishPoint = new Point((int)(startPoint.X - m_MinMeasureWidthValue / 2), (int)(startPoint.Y - m_MinMeasureWidthValue / 2));
  1386. Rectangle pRect = new Rectangle(PolygonFinishPoint, new Size(rectSize, rectSize));
  1387. CDisplayGDIObject createPolygonFinish = new CDisplayGDIObject(pRect, GDIType.DrawPolygonFinish, "", "", Color.Green);
  1388. m_DrawPolygonFinishGDIObject = createPolygonFinish;
  1389. }
  1390. }
  1391. else
  1392. {
  1393. m_DrawPolygonFinishGDIObject = null;
  1394. m_IsDrawPolygonFinish = false;
  1395. }
  1396. }
  1397. }
  1398. //圆形三点法
  1399. else if (m_DrawMeasureType == DrawMeasureAreaActionType.CircleByThreePoints)
  1400. {
  1401. m_DrawMeasureGDIObject.PolygonDrawingEndPoint = this.m_MouseMovePoint;
  1402. }
  1403. else
  1404. {
  1405. RectangleF rectangle = m_DrawMeasureGDIObject.GetZoomedRegion;
  1406. int tmp = (int)Math.Sqrt((m_MouseDownPoint.X - m_MouseMovePoint.X) * (m_MouseDownPoint.X - m_MouseMovePoint.X) + (m_MouseDownPoint.Y - m_MouseMovePoint.Y) * (m_MouseDownPoint.Y - m_MouseMovePoint.Y));
  1407. if (tmp == 0)
  1408. {
  1409. tmp = m_DValue;
  1410. }
  1411. EnumMousePointPosition enumMouse = MousePointPosition(m_MouseDownPoint, m_MouseMovePoint);
  1412. Point LTPoint = new Point();
  1413. Size RBSize = new Size();
  1414. switch (enumMouse)
  1415. {
  1416. case EnumMousePointPosition.MouseSizeTopLeft:
  1417. if (m_DrawMeasureType == DrawMeasureAreaActionType.Circle)
  1418. {
  1419. LTPoint.X = m_MouseDownPoint.X - tmp;
  1420. LTPoint.Y = m_MouseDownPoint.Y - tmp;
  1421. RBSize.Width = tmp;
  1422. RBSize.Height = tmp;
  1423. rectangle = new Rectangle(LTPoint, RBSize);
  1424. }
  1425. else
  1426. {
  1427. LTPoint.X = m_MouseMovePoint.X;
  1428. LTPoint.Y = m_MouseMovePoint.Y;
  1429. RBSize.Width = m_MouseDownPoint.X - m_MouseMovePoint.X;
  1430. RBSize.Height = m_MouseDownPoint.Y - m_MouseMovePoint.Y;
  1431. rectangle = new Rectangle(LTPoint, RBSize);
  1432. }
  1433. break;
  1434. case EnumMousePointPosition.MouseSizeTopRight:
  1435. if (m_DrawMeasureType == DrawMeasureAreaActionType.Circle)
  1436. {
  1437. LTPoint.X = m_MouseDownPoint.X;
  1438. LTPoint.Y = m_MouseDownPoint.Y - tmp;
  1439. RBSize.Width = tmp;
  1440. RBSize.Height = tmp;
  1441. rectangle = new Rectangle(LTPoint, RBSize);
  1442. }
  1443. else
  1444. {
  1445. LTPoint.X = m_MouseDownPoint.X;
  1446. LTPoint.Y = m_MouseDownPoint.Y - (m_MouseDownPoint.Y - m_MouseMovePoint.Y);
  1447. RBSize.Width = m_MouseMovePoint.X - m_MouseDownPoint.X;
  1448. RBSize.Height = m_MouseDownPoint.Y - m_MouseMovePoint.Y;
  1449. rectangle = new Rectangle(LTPoint, RBSize);
  1450. }
  1451. break;
  1452. case EnumMousePointPosition.MouseSizeBottomLeft:
  1453. if (m_DrawMeasureType == DrawMeasureAreaActionType.Circle)
  1454. {
  1455. LTPoint.X = m_MouseDownPoint.X - tmp;
  1456. LTPoint.Y = m_MouseDownPoint.Y;
  1457. RBSize.Width = tmp;
  1458. RBSize.Height = tmp;
  1459. rectangle = new Rectangle(LTPoint, RBSize);
  1460. }
  1461. else
  1462. {
  1463. LTPoint.X = m_MouseDownPoint.X - (m_MouseDownPoint.X - m_MouseMovePoint.X);
  1464. LTPoint.Y = m_MouseDownPoint.Y;
  1465. RBSize.Width = m_MouseDownPoint.X - m_MouseMovePoint.X;
  1466. RBSize.Height = m_MouseMovePoint.Y - m_MouseDownPoint.Y;
  1467. rectangle = new Rectangle(LTPoint, RBSize);
  1468. }
  1469. break;
  1470. case EnumMousePointPosition.MouseSizeBottomRight:
  1471. if (m_DrawMeasureType == DrawMeasureAreaActionType.Circle)
  1472. {
  1473. LTPoint.X = m_MouseDownPoint.X;
  1474. LTPoint.Y = m_MouseDownPoint.Y;
  1475. RBSize.Width = tmp;
  1476. RBSize.Height = tmp;
  1477. rectangle = new Rectangle(LTPoint, RBSize);
  1478. }
  1479. else
  1480. {
  1481. LTPoint.X = m_MouseDownPoint.X;
  1482. LTPoint.Y = m_MouseDownPoint.Y;
  1483. RBSize.Width = m_MouseMovePoint.X - m_MouseDownPoint.X;
  1484. RBSize.Height = m_MouseMovePoint.Y - m_MouseDownPoint.Y;
  1485. rectangle = new Rectangle(LTPoint, RBSize);
  1486. }
  1487. break;
  1488. }
  1489. //在样品台内部缩放
  1490. if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(rectangle))
  1491. {
  1492. var rec = new Rectangle(LTPoint, RBSize);
  1493. m_DrawMeasureGDIObject.SetZoomedRegionF(new RectangleF(new PointF((rec.X), (rec.Y)), new SizeF(rec.Width, rec.Height)));
  1494. }
  1495. }
  1496. }
  1497. if (Control.ModifierKeys == Keys.Control)//is dragging on the edge or on the vertex so we can alter the size of the item.
  1498. {
  1499. var sam = GetWorkingVisualSample();
  1500. if (sam == null) return;
  1501. var curMeasureGdi = sam.GetMeasureGDIObject();
  1502. if (curMeasureGdi.IsAltering)//click on the edge or on the polygon point(or vertex point of rectangle).
  1503. {
  1504. if (curMeasureGdi.Myshape == ShapeType.POLYGON)
  1505. {
  1506. var points = curMeasureGdi.GetPolygonPointFList();
  1507. for (int i = 0; i < points.Count; i++)
  1508. {
  1509. if (Math.Abs(points[i].X - e.X) <= m_OffsetPX && Math.Abs(points[i].Y - e.Y) <= m_OffsetPX)
  1510. {
  1511. //移动点的位置
  1512. RectangleF selPolygonPointRect = new RectangleF(0, 0, 2, 2);
  1513. selPolygonPointRect.X = curMeasureGdi.DraggingPoint.X + e.X - curMeasureGdi.DraggingPoint.X;
  1514. selPolygonPointRect.Y = curMeasureGdi.DraggingPoint.Y + e.Y - curMeasureGdi.DraggingPoint.Y;
  1515. //判断样品是否超越样品台
  1516. if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(selPolygonPointRect))
  1517. {
  1518. List<PointF> polygonPs = curMeasureGdi.GetPolygonPointFList();
  1519. if (i == 0 || i == curMeasureGdi.GetPolygonPointFList().Count - 1)
  1520. {
  1521. curMeasureGdi.DraggingPoint = new Point(e.X, e.Y);
  1522. polygonPs[0] = curMeasureGdi.DraggingPoint;
  1523. polygonPs[curMeasureGdi.GetPolygonPointFList().Count - 1] = curMeasureGdi.DraggingPoint;//the last point and the first point of one polygon object are the same.
  1524. }
  1525. else
  1526. {
  1527. curMeasureGdi.DraggingPoint = new Point(e.X, e.Y);
  1528. polygonPs[i] = curMeasureGdi.DraggingPoint;
  1529. }
  1530. curMeasureGdi.SetPolygonPointFList(polygonPs);
  1531. curMeasureGdi.DraggingPoint = e.Location;
  1532. break;
  1533. }
  1534. }
  1535. }
  1536. }
  1537. else
  1538. {
  1539. if (curMeasureGdi.Myshape == ShapeType.RECTANGLE)
  1540. {
  1541. List<PointF> vertexPoint = curMeasureGdi.GetVertexPoints();
  1542. var oldRegion = curMeasureGdi.GetZoomedRegionF();
  1543. for (int i = 0; i < vertexPoint.Count; i++)
  1544. {
  1545. var itemPoint = vertexPoint[i];
  1546. PointF lefttop, leftBottom, rightTop, rightBottom;
  1547. float width;
  1548. float height;
  1549. if (Math.Abs(itemPoint.X - e.X) <= m_OffsetPX && Math.Abs(itemPoint.Y - e.Y) <= m_OffsetPX)
  1550. {
  1551. switch (i)
  1552. {
  1553. case 0://left top point
  1554. lefttop = new PointF(e.X, e.Y);
  1555. width = vertexPoint[2].X - e.X;
  1556. height = vertexPoint[1].Y - e.Y;
  1557. curMeasureGdi.SetZoomedRegionF(new RectangleF(lefttop, new SizeF(width, height)));
  1558. break;
  1559. case 1://left bottom
  1560. leftBottom = new PointF(e.X, e.Y);
  1561. width = vertexPoint[3].X - e.X;
  1562. height = -(vertexPoint[0].Y - e.Y);
  1563. curMeasureGdi.SetZoomedRegionF(new RectangleF(new PointF(leftBottom.X, leftBottom.Y - height), new SizeF(width, height)));
  1564. break;
  1565. case 2://right top
  1566. rightTop = new PointF(e.X, e.Y);
  1567. width = -(vertexPoint[0].X - e.X);
  1568. height = (vertexPoint[3].Y - e.Y);
  1569. curMeasureGdi.SetZoomedRegionF(new RectangleF(new PointF(rightTop.X - width, rightTop.Y), new SizeF(width, height)));
  1570. break;
  1571. case 3://right bottom
  1572. rightBottom = new PointF(e.X, e.Y);
  1573. width = (e.X - vertexPoint[0].X);
  1574. height = (e.Y - vertexPoint[0].Y);
  1575. curMeasureGdi.SetZoomedRegionF(new RectangleF(new PointF(rightBottom.X - width, rightBottom.Y - height), new SizeF(width, height)));
  1576. break;
  1577. }
  1578. Invalidate();
  1579. }
  1580. }
  1581. }
  1582. else
  1583. {
  1584. PointF gdicenter = m_visualStage.GetCenterPoint(curMeasureGdi.GetZoomedRegion);
  1585. //获取鼠标坐标
  1586. PointF mousePoint = e.Location;
  1587. RectangleF rectTemp;
  1588. //计算偏离半径
  1589. float a = (gdicenter.X - mousePoint.X) * (gdicenter.X - mousePoint.X);
  1590. float b = (gdicenter.Y - mousePoint.Y) * (gdicenter.Y - mousePoint.Y);
  1591. float c = a + b;
  1592. double r = System.Math.Sqrt(c);
  1593. float width = (float)r * 2;
  1594. rectTemp = new RectangleF(gdicenter.X - (float)r, gdicenter.Y - (float)r, width, width);
  1595. if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(rectTemp))
  1596. {
  1597. //如果大于最小测量高度 设置图形大小
  1598. if (rectTemp.Width / curMeasureGdi.GetZoomNumber() > m_MinMeasureWidthValue)
  1599. {
  1600. curMeasureGdi.SetZoomedRegionF(rectTemp);
  1601. curMeasureGdi.DraggingPoint = e.Location;
  1602. }
  1603. }
  1604. else
  1605. {
  1606. return;
  1607. }
  1608. Invalidate();
  1609. return;
  1610. }
  1611. }
  1612. }
  1613. else if (curMeasureGdi.IsDragging)
  1614. {
  1615. if (curMeasureGdi.GetGPath().IsVisible(e.Location))
  1616. {
  1617. if (m_visualStage.GetEdgeGDIObj().GetGPath().IsVisible(e.Location))
  1618. {
  1619. curMeasureGdi.PositionAltering(e.Location, true);
  1620. }
  1621. }
  1622. }
  1623. }
  1624. else
  1625. {
  1626. //样品台
  1627. MouseMoveFucntion(m_visualStage.GetAllGDIObject(), e);
  1628. //样品
  1629. MouseMoveFucntion(GetAllVisualSampleGDIObject(), e);
  1630. //样品孔BSE图片
  1631. MouseMoveFucntion(m_visualStage.FrameOfHoleGDIObjects, e);
  1632. }
  1633. //显示XY轴
  1634. m_visualStage.ShowSemCoordvAL(e.Location, m_MeasureAppForm);
  1635. Invalidate();
  1636. }
  1637. private CDomain ConvertMeasureAreaGDIToDomain(CMeasureArea area)
  1638. {
  1639. var para = m_visualStage.GetSampleMeasurePara(area);
  1640. CDomain Domain = new CDomain();
  1641. Domain.SetShape((otsdataconst.DOMAIN_SHAPE)para.iShape);
  1642. Domain.SetRectDomain(para.MeasureRect);
  1643. return Domain;
  1644. }
  1645. protected override void OnMouseUp(MouseEventArgs e)
  1646. {
  1647. //如果正在进行测量线程,则退出鼠标点击操作
  1648. var runflag = m_MeasureAppForm.MeasureThreadRunFlag;
  1649. if (runflag)
  1650. {
  1651. return;
  1652. }
  1653. var sam = GetWorkingVisualSample();
  1654. //判断当前是否手绘
  1655. if (m_IsDrawMeasure)
  1656. {
  1657. if (m_DrawMeasureType == DrawMeasureAreaActionType.InverseSelection)
  1658. {
  1659. var workspl = m_MeasureAppForm.m_ProjParam.GetWorkSample();
  1660. foreach (var gdi in sam.GetMeasureFieldGDIObjects())
  1661. {
  1662. if (m_DrawMeasureGDIObject.IfContains(new Point((int)gdi.GetCenterPoint().X, (int)gdi.GetCenterPoint().Y)))
  1663. {
  1664. gdi.Enable = !gdi.Enable;
  1665. workspl.SetFieldEnable(new Point(gdi.OTSX, gdi.OTSY), gdi.Enable);
  1666. }
  1667. }
  1668. m_DrawMeasureGDIObject = null;
  1669. this.Cursor = Cursors.Default;
  1670. //设置手绘标识
  1671. m_IsDrawMeasure = false;
  1672. }
  1673. else if (m_DrawMeasureType == DrawMeasureAreaActionType.Circle)
  1674. {
  1675. m_DrawMeasureGDIObject.HoleNo = sam.GetMeasureGDIObject().HoleNo;
  1676. m_DrawMeasureGDIObject.IsWorkSample = sam.GetMeasureGDIObject().IsWorkSample;
  1677. sam.GetMeasureFieldGDIObjects().Clear();
  1678. sam.SetMeasureGDIObject(m_DrawMeasureGDIObject);
  1679. var para = m_visualStage.GetSampleMeasurePara(m_DrawMeasureGDIObject);
  1680. SetWorkSampleMeasureArea(para);
  1681. PrepareVisualMeasureField(sam);
  1682. m_MeasureAppForm.UpdatePropertyVal();
  1683. //-------------
  1684. m_DrawMeasureGDIObject = null;
  1685. this.Cursor = Cursors.Default;
  1686. //设置手绘标识
  1687. m_IsDrawMeasure = false;
  1688. }
  1689. else if (m_DrawMeasureType == DrawMeasureAreaActionType.Rectangle)
  1690. {
  1691. m_DrawMeasureGDIObject.HoleNo = sam.GetMeasureGDIObject().HoleNo;
  1692. m_DrawMeasureGDIObject.IsWorkSample = sam.GetMeasureGDIObject().IsWorkSample;
  1693. sam.GetMeasureFieldGDIObjects().Clear();
  1694. sam.SetMeasureGDIObject(m_DrawMeasureGDIObject);
  1695. var para1 = m_visualStage.GetSampleMeasurePara(m_DrawMeasureGDIObject);
  1696. SetWorkSampleMeasureArea(para1);
  1697. PrepareVisualMeasureField(sam);
  1698. //according to the calculated fields outermost border rectangle update the measure area to include all the fields.
  1699. var rec = sam.GetAllGDIObjectsRectangle();
  1700. m_DrawMeasureGDIObject.SetZoomedRegionF(rec);
  1701. sam.SetMeasureGDIObject(m_DrawMeasureGDIObject);
  1702. para1 = m_visualStage.GetSampleMeasurePara(m_DrawMeasureGDIObject);
  1703. SetWorkSampleMeasureArea(para1);
  1704. m_MeasureAppForm.UpdatePropertyVal();
  1705. //-------------
  1706. m_DrawMeasureGDIObject = null;
  1707. this.Cursor = Cursors.Default;
  1708. //设置手绘标识
  1709. m_IsDrawMeasure = false;
  1710. }
  1711. else if (m_DrawMeasureType == DrawMeasureAreaActionType.OnlyShot)
  1712. {
  1713. m_IsDrawMeasure = false;
  1714. this.Cursor = Cursors.Default;
  1715. m_visualStage.AddSampleHoleGDIobj(m_DrawMeasureGDIObject);
  1716. CDomain domain = ConvertMeasureAreaGDIToDomain(m_DrawMeasureGDIObject);
  1717. List<CVisualFieldGDIObject> visualfieldRects = null;
  1718. visualfieldRects = GetPreviewVisualRects(domain);//get all the possible field rects through C++ code.
  1719. PrepareVisualPreviewGDIobj(visualfieldRects);
  1720. List<Point> listFieldCenter = new List<Point>();
  1721. foreach (var fld in visualfieldRects)
  1722. {
  1723. listFieldCenter.Add(fld.GetOTSPos());
  1724. }
  1725. CSmplPreviewMeasure cSmplPreviewMeasure = new CSmplPreviewMeasure(m_MeasureAppForm.m_MsrThreadWrapper.m_measure, listFieldCenter);
  1726. Thread thread = new Thread(() =>
  1727. {
  1728. cSmplPreviewMeasure.DoHolePreview();
  1729. });
  1730. thread.Start();
  1731. }
  1732. }
  1733. if (sam != null)
  1734. {
  1735. var measureItem = sam.GetMeasureGDIObject();
  1736. if (measureItem.IsDragging || measureItem.IsAltering)//while pressing ctrl key then it must be altering something(position or size)
  1737. {
  1738. //var selWSampleMeasureStatus = m_MeasureAppForm.m_ProjParam.GetWorkSampleMeasureStatus();
  1739. COTSSample COTSSample = m_MeasureAppForm.m_ProjParam.GetResultData().GetWorkingSample();
  1740. int completeflds = COTSSample.GetMsrStatus().GetCompletedFields();
  1741. if (completeflds==0)
  1742. {
  1743. var para = m_visualStage.GetSampleMeasurePara(measureItem);
  1744. SetWorkSampleMeasureArea(para);//set the altering result to the public parameter object
  1745. this.Cursor = Cursors.Default;
  1746. PrepareVisualMeasureField(sam);
  1747. }
  1748. measureItem.IsAltering = false;
  1749. measureItem.IsDragging = false;
  1750. Invalidate();
  1751. }
  1752. }
  1753. //only moving the whole stage
  1754. MouseUpFucntion(m_visualStage.GetAllGDIObject(), e);
  1755. MouseUpFucntion(GetAllVisualSampleGDIObject(), e);
  1756. }
  1757. public void DrawSampleHoleImage(CDisplayGDIObject img)
  1758. {
  1759. var m_RegionF = img.GetOrigionalDrawRegionF();
  1760. PointF startPointF = new PointF(m_RegionF.Left, m_RegionF.Top);
  1761. PointF endPointF = new PointF(m_RegionF.Right + 2, m_RegionF.Bottom + 2);
  1762. //绘制样品孔中图像信息
  1763. if (img.BSEImage != null)
  1764. {
  1765. Image thumbnail = img.BSEImage.GetThumbnailImage((int)m_RegionF.Width + 2, (int)m_RegionF.Height + 2, null, IntPtr.Zero);
  1766. var g = Graphics.FromImage(sampleHoleImageBuffer.BSEImage);
  1767. g.DrawImage(thumbnail, startPointF);
  1768. }
  1769. }
  1770. protected override void OnPaint(PaintEventArgs e)//处理重绘情况
  1771. {
  1772. OnPaint(e, m_visualStage.GetAllGDIObject());
  1773. OnPaint(e, GetOnlyVisualSampleGDIObject());
  1774. if (IsShowSampleHoleImage)
  1775. {
  1776. //e.Graphics.DrawImage(sampleHoleImageBuffer.BSEImage, sampleHoleImageBuffer.GetOrigionalDrawRegionF());
  1777. if (sampleHoleImageBuffer.BSEImage != null)
  1778. {
  1779. e.Graphics.DrawImage(sampleHoleImageBuffer.BSEImage, sampleHoleImageBuffer.GetZoomedRegionF());
  1780. }
  1781. OnPaint(e, m_visualStage.FrameOfHoleGDIObjects);
  1782. }
  1783. }
  1784. public void OnPaint(PaintEventArgs e, List<CDisplayGDIObject> m_ObjectGDIObjects)//处理重绘情况
  1785. {
  1786. foreach (CDisplayGDIObject item in m_ObjectGDIObjects.ToArray())
  1787. {
  1788. if (item != null)
  1789. {
  1790. item.OnPaint(e);
  1791. }
  1792. }
  1793. }
  1794. protected override void OnMouseWheel(MouseEventArgs e)
  1795. {
  1796. bool runflag = m_MeasureAppForm.MeasureThreadRunFlag;
  1797. if (runflag)
  1798. {
  1799. return;
  1800. }
  1801. var currentZoomNum = m_visualStage.GetZoomNum();
  1802. //如果正在进行测量线程,则退出鼠标点击操作
  1803. if (e.Delta > 0)
  1804. {
  1805. #region 计算标尺尺寸部份-----放大------
  1806. //计算标尺实际占用像素的宽度
  1807. f_ruler_size = f_old_ruler_size * currentZoomNum;
  1808. control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);
  1809. control_Ruler2.Value = 1;
  1810. //放大过长时,这里将宽度与代表的实际宽度进行折半显示
  1811. while (control_Ruler2.Width > 300)
  1812. {
  1813. control_Ruler2.RulerWidth = Convert.ToInt32(control_Ruler2.RulerWidth) / 2;
  1814. control_Ruler2.Value = control_Ruler2.Value * 2;
  1815. }
  1816. control_Ruler2.SetValue(control_Ruler2.RulerWidth, control_Ruler2.Value.ToString() + "mm");
  1817. #endregion
  1818. }
  1819. else
  1820. {
  1821. if (currentZoomNum >= f_zoom_mix)
  1822. {
  1823. #region 计算标尺尺寸部份-----缩小
  1824. f_ruler_size = f_old_ruler_size * currentZoomNum;
  1825. control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);
  1826. control_Ruler2.Value = 1;
  1827. while (control_Ruler2.Width > 300)
  1828. {
  1829. control_Ruler2.RulerWidth = Convert.ToInt32(control_Ruler2.RulerWidth) / 2;
  1830. control_Ruler2.Value = control_Ruler2.Value * 2;
  1831. }
  1832. control_Ruler2.SetValue(control_Ruler2.RulerWidth, control_Ruler2.Value.ToString() + "mm");
  1833. #endregion
  1834. }
  1835. }
  1836. //设置记录每次比例缩放后的总体比例系数
  1837. if (e.Delta > 0)
  1838. {
  1839. currentZoomNum += 0.1f;
  1840. }
  1841. else
  1842. {
  1843. currentZoomNum -= 0.1f;
  1844. if (currentZoomNum < 1)
  1845. {
  1846. currentZoomNum = 1;
  1847. }
  1848. if (currentZoomNum == 1)
  1849. {
  1850. //标尺恢复初始
  1851. f_ruler_size = f_old_ruler_size;
  1852. control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);
  1853. control_Ruler2.ShowString = "1mm";
  1854. control_Ruler2.SetValue(control_Ruler2.RulerWidth);
  1855. }
  1856. }
  1857. MouseWheelFunction(GetAllVisualSampleGDIObject(), e.Location, currentZoomNum);
  1858. //样品孔
  1859. MouseWheelFunction(m_visualStage.GetAllGDIObject(), e.Location, currentZoomNum);
  1860. base.OnMouseWheel(e);
  1861. //重新绘制
  1862. Invalidate();
  1863. }
  1864. private void MouseWheelFunction(List<CDisplayGDIObject> objList, Point mousePoint, float ZoomNum)
  1865. {
  1866. for (int i = 0; i < objList.Count; i++)
  1867. {
  1868. objList[i].Zoom(mousePoint, ZoomNum);
  1869. }
  1870. }
  1871. #endregion
  1872. #region 鼠标方法操作
  1873. public void MouseDownFunction(List<CDisplayGDIObject> objList, MouseEventArgs e)
  1874. {
  1875. foreach (CDisplayGDIObject item in objList)
  1876. {
  1877. item.IsMoving = true;
  1878. item.DraggingPoint = e.Location;
  1879. }
  1880. }
  1881. public void MouseMoveFucntion(List<CDisplayGDIObject> objList, MouseEventArgs e)
  1882. {
  1883. foreach (CDisplayGDIObject item in objList)
  1884. {
  1885. if (item.IsMoving)
  1886. {
  1887. item.Move(e.Location);
  1888. }
  1889. }
  1890. }
  1891. public void MouseUpFucntion(List<CDisplayGDIObject> objList, MouseEventArgs e)
  1892. {
  1893. foreach (CDisplayGDIObject item in objList)
  1894. {
  1895. if (item.IsDragging)
  1896. {
  1897. item.IsDragging = false;
  1898. item.DraggingPoint = Point.Empty;
  1899. }
  1900. if (item.IsMoving)
  1901. {
  1902. item.IsMoving = false;
  1903. item.DraggingPoint = Point.Empty;
  1904. }
  1905. }
  1906. }
  1907. #endregion
  1908. private void DeleteSampleInfo(string sampleSelectName)
  1909. {
  1910. if (ShowDeleteDialog(sampleSelectName))
  1911. {
  1912. m_MeasureAppForm.DeleteSample(sampleSelectName);
  1913. }
  1914. return;
  1915. }
  1916. private bool ShowDeleteDialog(string sampleName)
  1917. {
  1918. //国际化
  1919. OTSCommon.Language lan = new OTSCommon.Language();
  1920. Hashtable table = lan.GetNameTable("OTSIncAMeasureAppForm");
  1921. string str1 = table["message5"].ToString();
  1922. string str2 = table["message6"].ToString();
  1923. string sDeleteSampleName = str1;
  1924. sDeleteSampleName += sampleName;
  1925. sDeleteSampleName += " 信息 ?";
  1926. if (DialogResult.OK == MessageBox.Show(sDeleteSampleName, "Delete sample information prompt", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
  1927. {
  1928. return true;
  1929. }
  1930. else
  1931. {
  1932. return false;
  1933. }
  1934. }
  1935. public bool setSlopFocusParam(SlopFocus slopFocus)
  1936. {
  1937. if (slopFocus == null)
  1938. {
  1939. return false;
  1940. }
  1941. else
  1942. {
  1943. m_MeasureAppForm.m_ProjParam.GetWorkSample().GetMsrParams().SlopParam = slopFocus.GetCSlopFocusParam();
  1944. return true;
  1945. }
  1946. }
  1947. protected override bool ProcessDialogKey(Keys keyData)
  1948. {
  1949. if (keyData == Keys.Up || keyData == Keys.Down || keyData == Keys.Left || keyData == Keys.Right)
  1950. {
  1951. return false;
  1952. }
  1953. else
  1954. {
  1955. return base.ProcessDialogKey(keyData);
  1956. }
  1957. }
  1958. public void OTSSamplespaceWindow_KeyDown(object sender, KeyEventArgs e)
  1959. {
  1960. //鼠标相对于屏幕的坐标
  1961. Point p1 = MousePosition;
  1962. //鼠标相对于窗体的坐标
  1963. Point mousePoint = this.PointToClient(p1);
  1964. Pen GrayPen = new Pen(Color.Gray, m_PenWidth);
  1965. //设置鼠标在样品测量区域上的样式
  1966. foreach (var sam in m_visualSamples)
  1967. {
  1968. var item = sam.GetMeasureGDIObject();
  1969. if (item.GetGPath() != null)
  1970. {
  1971. if (item.Myshape == ShapeType.POLYGON)
  1972. {
  1973. //在多边形点附近切换光标
  1974. foreach (PointF itemPoint in item.GetPolygonPointFList())
  1975. {
  1976. if (Math.Abs(itemPoint.X - mousePoint.X) <= m_OffsetPX && Math.Abs(itemPoint.Y - mousePoint.Y) <= m_OffsetPX)
  1977. {
  1978. if (Control.ModifierKeys == Keys.Control)
  1979. {
  1980. this.Cursor = System.Windows.Forms.Cursors.NoMove2D;
  1981. return;
  1982. }
  1983. }
  1984. }
  1985. if (item.GetGPath().IsVisible(mousePoint))
  1986. {
  1987. if (Control.ModifierKeys == Keys.Control)
  1988. {
  1989. this.Cursor = System.Windows.Forms.Cursors.SizeAll;
  1990. return;
  1991. }
  1992. }
  1993. }
  1994. else
  1995. {
  1996. if (item.GetGPath().IsOutlineVisible(mousePoint, GrayPen))
  1997. {
  1998. if (item.Myshape == ShapeType.RECTANGLE)
  1999. {
  2000. List<PointF> vertexPoint = item.GetVertexPoints();
  2001. foreach (PointF itemPoint in vertexPoint)
  2002. {
  2003. if (Math.Abs(itemPoint.X - mousePoint.X) <= m_OffsetPX && Math.Abs(itemPoint.Y - mousePoint.Y) <= m_OffsetPX)
  2004. {
  2005. if (Control.ModifierKeys == Keys.Control)
  2006. {
  2007. this.Cursor = System.Windows.Forms.Cursors.NoMove2D;
  2008. return;
  2009. }
  2010. }
  2011. }
  2012. }
  2013. else
  2014. {
  2015. if (Control.ModifierKeys == Keys.Control)
  2016. {
  2017. this.Cursor = System.Windows.Forms.Cursors.NoMove2D;
  2018. return;
  2019. }
  2020. }
  2021. }
  2022. if (item.IfZoomContains(mousePoint))
  2023. {
  2024. if (Control.ModifierKeys == Keys.Control)
  2025. {
  2026. this.Cursor = System.Windows.Forms.Cursors.SizeAll;
  2027. return;
  2028. }
  2029. }
  2030. }
  2031. }
  2032. }
  2033. //设置鼠标在样品上的样式
  2034. foreach (var sam in m_visualSamples)
  2035. {
  2036. var item = sam.GetSampleGDIObject();
  2037. if (!item.SelColor.Name.Equals("Transparent"))
  2038. {
  2039. if (item.IfZoomContains(mousePoint))
  2040. {
  2041. if ((Control.ModifierKeys == Keys.Alt))
  2042. {
  2043. this.Cursor = System.Windows.Forms.Cursors.SizeAll;
  2044. return;
  2045. }
  2046. }
  2047. }
  2048. }
  2049. if (e.KeyCode == Keys.Escape && m_IsDrawMeasure == true && m_DrawMeasureType == DrawMeasureAreaActionType.Polygon)
  2050. {
  2051. var polygonPoints = m_DrawMeasureGDIObject.GetPolygonPointFList();
  2052. if (polygonPoints.Count > 0)
  2053. {
  2054. polygonPoints.RemoveAt(polygonPoints.Count - 1);//remove the last one.
  2055. m_DrawMeasureGDIObject.SetPolygonPointFList(polygonPoints);
  2056. }
  2057. else
  2058. {
  2059. m_IsDrawMeasure = false;
  2060. }
  2061. }
  2062. else if (e.KeyCode == Keys.Escape && m_IsDrawMeasure == true)
  2063. {
  2064. m_IsDrawMeasure = false;
  2065. }
  2066. }
  2067. private void OTSSamplespaceWindow_KeyUp(object sender, KeyEventArgs e)
  2068. {
  2069. //键盘抬起时,将选择区域的标识 设置为未选择状态
  2070. this.Cursor = System.Windows.Forms.Cursors.Default;
  2071. this.Invalidate();
  2072. }
  2073. public void KeyUps()
  2074. {
  2075. this.Cursor = System.Windows.Forms.Cursors.Default;
  2076. }
  2077. #region 处理方法总汇
  2078. #region 清除所需图形
  2079. public void ClearDrawInfo()
  2080. {
  2081. try
  2082. {
  2083. m_visualStage.FrameOfHoleGDIObjects.Clear();
  2084. m_visualStage.cleargdiobj();
  2085. var sam = GetWorkingVisualSample();
  2086. if (sam != null)
  2087. {
  2088. if (m_DrawMeasureGDIObject != null)
  2089. {
  2090. m_DrawMeasureGDIObject = null;
  2091. }
  2092. }
  2093. m_visualSamples.Clear();
  2094. }
  2095. catch (Exception ex)
  2096. {
  2097. log.Error(ex.ToString());
  2098. }
  2099. }
  2100. #endregion
  2101. #endregion
  2102. #region 绘制样品以及测量区域
  2103. /// <summary>
  2104. /// 绘制样品以及测量区域
  2105. /// </summary>
  2106. /// <param name="SMeasrueAreaList">测量区域的集合</param>
  2107. public void DrawSampleAndMeasureInfo(SampleMeasurePara SMeasrueArea)
  2108. {
  2109. var item = m_visualStage.GetHoleGDIByHoleName(SMeasrueArea.sampleHoleName);
  2110. if (item != null)
  2111. {
  2112. CVisualSampleArea sam;
  2113. if (InitVisualSample(SMeasrueArea.sampleHoleName, SMeasrueArea.sSampleName, out sam))
  2114. {
  2115. if (SMeasrueArea.iShape == ShapeType.POLYGON)
  2116. {
  2117. var ps = new List<PointF>();
  2118. foreach (var p in SMeasrueArea.DrawPolygonPointList)
  2119. {
  2120. var ctrlcoordPoint = m_visualStage.OTSCoordToCtrlCoord(p);
  2121. ps.Add(ctrlcoordPoint);
  2122. }
  2123. CMeasureArea polygongdi = new CMeasureArea(ps, SMeasrueArea.iShape, SMeasrueArea.sampleHoleName, SMeasrueArea.sSampleName, Color.Red);
  2124. sam.SetMeasureGDIObject(polygongdi);
  2125. PrepareVisualMeasureField(sam);
  2126. }
  2127. else
  2128. {
  2129. PointF xHole = new PointF(SMeasrueArea.MeasureRect.Left, SMeasrueArea.MeasureRect.Top);
  2130. PointF yHole = new PointF(SMeasrueArea.MeasureRect.Right, SMeasrueArea.MeasureRect.Bottom);
  2131. CDisplayGDIObject gdi = m_visualStage.GetCtrlCoordGDI(xHole, yHole, m_visualStage.ConvertShapeTypeToGDIType(SMeasrueArea.iShape), "", "");
  2132. gdi.SampleName = SMeasrueArea.sSampleName;
  2133. gdi.HoleNo = SMeasrueArea.sampleHoleName;
  2134. CMeasureArea measureGdi;
  2135. if (m_visualStage.GetMeasureGdiObjectFromSampleGdi(gdi, out measureGdi))
  2136. {
  2137. sam.SetMeasureGDIObject(measureGdi);
  2138. PrepareVisualMeasureField(sam);
  2139. }
  2140. }
  2141. COTSMsrPrjResultData cProjMgr = m_MeasureAppForm.m_ProjParam.GetResultData();
  2142. List<PointF> CompleteFieldList = cProjMgr.GetSampleByName(SMeasrueArea.sSampleName).GetMsrStatus().GetCompletedFieldsCenter();
  2143. if (CompleteFieldList.Count > 0)
  2144. {
  2145. ChangeCompleteFieldMeasureState(CompleteFieldList, Color.Green, sam);
  2146. }
  2147. }
  2148. }
  2149. }
  2150. #endregion
  2151. #region 获取帧图信息
  2152. public void ReadSEMDataAndSetToCurrentSample()
  2153. {
  2154. List<double> semParameters;
  2155. #region 获取电镜参数
  2156. ////获取Field操作类对象
  2157. if (m_SEMDATAService == null)
  2158. {
  2159. m_SEMDATAService = new SEMControlService();
  2160. }
  2161. //判断是否连接电镜
  2162. if (m_SEMDATAService.InitAndConnection())
  2163. {
  2164. //获取电镜参数 放大倍数与工作距离 等参数
  2165. semParameters = m_SEMDATAService.GetSEMMagAndWDParameter();
  2166. double mag = semParameters[0];
  2167. double wd = semParameters[1];
  2168. double bri = semParameters[2];
  2169. double contra = semParameters[3];
  2170. double kv = semParameters[4];
  2171. double mag0 = 100;
  2172. double wd0 = 10;
  2173. double bri0 = 10;
  2174. double contra0 = 10;
  2175. double kv0 = 10;
  2176. m_MeasureAppForm.m_ProjParam.GetWorkingSampleSEMData(ref wd0, ref mag0, ref bri0, ref contra0, ref kv0);
  2177. if ((mag > 500) && (mag != mag0))
  2178. {
  2179. var rst = MessageBox.Show("Change Magnification to: " + mag.ToString("F2") + "\n" + "Previous Magnification: " + mag0.ToString("F2"), "SEM Data Info", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
  2180. if (rst == DialogResult.Yes)
  2181. {
  2182. if (mag != 0 && wd != 0)
  2183. {
  2184. //设置样品文件中的电镜参数
  2185. m_MeasureAppForm.m_ProjParam.SetWorkingSampleSEMData(wd, mag, bri, contra, kv);
  2186. //将右键SEM数据菜单设置为可编辑状态
  2187. CMStrip.Items[(int)MenuIndex.SetSemData].Enabled = true;
  2188. }
  2189. }
  2190. else
  2191. {
  2192. if (wd != 0)
  2193. {
  2194. m_MeasureAppForm.m_ProjParam.SetWorkingSampleSEMData(wd, mag0, bri, contra, kv);
  2195. //将右键SEM数据菜单设置为可编辑状态
  2196. CMStrip.Items[(int)MenuIndex.SetSemData].Enabled = true;
  2197. }
  2198. }
  2199. }
  2200. else
  2201. {
  2202. if (mag != 0 && wd != 0)
  2203. {
  2204. //设置样品文件中的电镜参数
  2205. m_MeasureAppForm.m_ProjParam.SetWorkingSampleSEMData(wd, mag, bri, contra, kv);
  2206. //将右键SEM数据菜单设置为可编辑状态
  2207. CMStrip.Items[(int)MenuIndex.SetSemData].Enabled = true;
  2208. }
  2209. }
  2210. }
  2211. }
  2212. #endregion
  2213. #region 获取Filed帧图
  2214. public List<CVisualFieldGDIObject> GetOTSFieldVisualRects(CVisualSampleArea sam)
  2215. {
  2216. List<Point> listCenterPoint = new List<Point>();
  2217. Size rectSize = new Size();
  2218. var m_ResultData = m_MeasureAppForm.m_ProjParam.GetResultData();
  2219. //the coresponding sample must be in the result data,and must be initialized.
  2220. var sample = m_ResultData.GetSampleByName(sam.GetSampleName());
  2221. List<CVisualFieldGDIObject> visualfieldRects = new List<CVisualFieldGDIObject>();
  2222. sample.InitFieldPosData(out listCenterPoint, out rectSize);
  2223. for (int i = 0; i < listCenterPoint.Count; i++)
  2224. {
  2225. //convert the center point to leftTop point of rectangle.
  2226. Point otsPoint = listCenterPoint[i];
  2227. int left = otsPoint.X - rectSize.Width / 2;
  2228. int top = otsPoint.Y - rectSize.Height / 2;//the ots coordinate is leftbottom is (0,0),but the control coordinate is leftTop is (0,0),so here use minus.
  2229. var rect = new Rectangle(new Point(left, top), rectSize);
  2230. Point lt = new Point(rect.Left, rect.Top);
  2231. Point rb = new Point(rect.Right, rect.Bottom);
  2232. RectangleF visualRect = m_visualStage.GetCtrlCoordRectF(lt, rb);
  2233. Color ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.FieldColor);
  2234. string sampleName = sam.GetSampleName();
  2235. string sampleHoleName = sam.GetSampleGDIObject().HoleNo;
  2236. CVisualFieldGDIObject createRect = new CVisualFieldGDIObject(visualRect, otsPoint.X, otsPoint.Y, sampleHoleName, sampleName, ColorStr);
  2237. createRect.Enable = true;
  2238. visualfieldRects.Add(createRect);
  2239. }
  2240. return visualfieldRects;
  2241. }
  2242. public List<CVisualFieldGDIObject> GetPreviewVisualRects(CDomain area)
  2243. {
  2244. List<Point> listCenterPoint = new List<Point>();
  2245. Size rectSize = new Size();
  2246. List<CVisualFieldGDIObject> visualfieldRects = new List<CVisualFieldGDIObject>();
  2247. InitHoleImgPosData(area, out listCenterPoint, out rectSize);
  2248. for (int i = 0; i < listCenterPoint.Count; i++)
  2249. {
  2250. //convert the center point to leftTop point of rectangle.
  2251. Point otsPoint = listCenterPoint[i];
  2252. int left = otsPoint.X - rectSize.Width / 2;
  2253. int top = otsPoint.Y - rectSize.Height / 2;//the ots coordinate is leftbottom is (0,0),but the control coordinate is leftTop is (0,0),so here use minus.
  2254. var rect = new Rectangle(new Point(left, top), rectSize);
  2255. Point lt = new Point(rect.Left, rect.Top);
  2256. Point rb = new Point(rect.Right, rect.Bottom);
  2257. RectangleF visualRect = m_visualStage.GetCtrlCoordRectF(lt, rb);
  2258. Color ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.FieldColor);
  2259. string sampleName = "";
  2260. string sampleHoleName = "";
  2261. CVisualFieldGDIObject createRect = new CVisualFieldGDIObject(visualRect, otsPoint.X, otsPoint.Y, sampleHoleName, sampleName, ColorStr);
  2262. createRect.Enable = true;
  2263. visualfieldRects.Add(createRect);
  2264. }
  2265. return visualfieldRects;
  2266. }
  2267. public bool InitHoleImgPosData(CDomain pMsrArea, out List<Point> lisFieldPos, out Size iSzie)
  2268. {
  2269. lisFieldPos = new List<Point>();
  2270. iSzie = new Size();
  2271. COTSImgScanPrm pImgScanParam = m_MeasureAppForm.m_ProjParam.GetDefaultParam().GetImageScanParam();
  2272. COTSImageProcParam pImgProcParam = m_MeasureAppForm.m_ProjParam.GetDefaultParam().GetImageProcParam();
  2273. CSEMFieldData pSEMDataMsr;
  2274. List<PointF> listPoint = new List<PointF>();
  2275. listPoint.Clear();
  2276. pSEMDataMsr = new CSEMFieldData();
  2277. pSEMDataMsr.SetScanFieldSize100(m_visualStage.GetOTSSampleStageData().iScanFieldSize100);
  2278. double dMagnification = m_MeasureAppForm.m_ProjParam.GetDefaultParam().GetStageDataParam().GetMinMag();//using the min mag to photo the hole image.
  2279. pSEMDataMsr.SetMagnification(dMagnification);
  2280. //calculate all the field position point in OTS coordination.
  2281. if (!pFieldMgr.Init(pMsrArea, pImgScanParam, 0, pSEMDataMsr, listPoint))
  2282. {
  2283. return false;
  2284. }
  2285. lisFieldPos = pFieldMgr.GetFieldCentrePoints();
  2286. var oValue = new COTSRect();
  2287. if (!pFieldMgr.GetOTSRectByIndex(0, ref oValue))
  2288. {
  2289. return false;
  2290. }
  2291. iSzie = new Size((int)oValue.GetWidth(), (int)oValue.GetHeight());
  2292. return true;
  2293. }
  2294. #endregion
  2295. public void PrepareVisualMeasureField(CVisualSampleArea visualsam)
  2296. {
  2297. try
  2298. {
  2299. List<CVisualFieldGDIObject> visualfieldRects = null;
  2300. visualfieldRects = GetOTSFieldVisualRects(visualsam);//get all the possible field rects through C++ code.
  2301. visualsam.GetMeasureGDIObject().SubItems().Clear();
  2302. for (int i = 0; i < visualfieldRects.Count; i++)
  2303. {
  2304. visualsam.AddFieldGDIObject(visualfieldRects[i]);
  2305. }
  2306. MemoryFieldPositionInfoToSample(visualsam);
  2307. m_MeasureAppForm.UpdatePropertyVal();
  2308. }
  2309. catch (Exception ex)
  2310. {
  2311. log.Error(ex.ToString());
  2312. }
  2313. Invalidate();
  2314. }
  2315. public void PrepareVisualPreviewGDIobj(List<CVisualFieldGDIObject> visualfieldRects)
  2316. {
  2317. //-------maybe take more than one visualsample hole image for one sample,
  2318. //if the previous visual area's fields don't finish,then the unfinished field's area may overlap with the current visualsample's area.
  2319. // then there positions will conflict. So we should remove the unfinished fields first.
  2320. var completeHoleImgs = new List<CDisplayGDIObject>();
  2321. foreach (var holeImgfld in m_visualStage.FrameOfHoleGDIObjects)
  2322. {
  2323. if (holeImgfld.BSEImage != null)
  2324. {
  2325. completeHoleImgs.Add(holeImgfld);
  2326. }
  2327. }
  2328. m_visualStage.FrameOfHoleGDIObjects = completeHoleImgs;
  2329. //------
  2330. foreach (var r in visualfieldRects)
  2331. {
  2332. r.SetDisplayRefPoint(m_visualStage.GetDisplayRefPoint());
  2333. r.SetZoomNumber(m_visualStage.GetZoomNum());
  2334. RectangleF ImgRegionF;
  2335. float ImgRegionWidth;
  2336. float ImgRegionHeight;
  2337. ImgRegionF = r.GetOrigionalDrawRegionF();
  2338. ImgRegionWidth = Convert.ToInt32(ImgRegionF.Width);
  2339. ImgRegionHeight = Convert.ToInt32(ImgRegionF.Height);
  2340. //绘制图像
  2341. CDisplayGDIObject createImageRect = new CDisplayGDIObject(ImgRegionF, r.OTSX, r.OTSY, r.SampleName, r.HoleNo, ImgRegionWidth, ImgRegionHeight, GDIType.DrawFrameOfHoleBSEImage);
  2342. //添加至List集合中
  2343. createImageRect.SetInitRegionF(r.GetOrigionalDrawRegionF());
  2344. //createImageRect.HoleNo = r.HoleNo;
  2345. createImageRect.SetZoomNumber(m_visualStage.GetZoomNum());
  2346. createImageRect.SetDisplayRefPoint(m_visualStage.GetDisplayRefPoint());
  2347. m_visualStage.FrameOfHoleGDIObjects.Add(createImageRect);
  2348. }
  2349. Invalidate();
  2350. }
  2351. public void MemoryFieldPositionInfoToSample(CVisualSampleArea sam)
  2352. {
  2353. var m_ResultData = m_MeasureAppForm.m_ProjParam.GetResultData();
  2354. var sample = m_ResultData.GetSampleByName(sam.GetSampleName());
  2355. var fields = sam.GetMeasureFieldGDIObjects();
  2356. sample.ClearFields();
  2357. for (int i = 0; i < fields.Count; i++)
  2358. {
  2359. var f = (CVisualFieldGDIObject)fields[i];
  2360. var otsPoint = new Point(f.OTSX, f.OTSY);
  2361. var pixelsize = sample.CalculatePixelSize();
  2362. var newfld = new COTSField(otsPoint, pixelsize);
  2363. COTSRect r = new COTSRect();
  2364. sample.pFieldMgr.GetOTSRectByIndex(i, ref r);//get this field's global position(in the whole ots coordination)
  2365. newfld.SetOTSRect(r);
  2366. newfld.SetMeasureSequence(f.SequenceNum);
  2367. sample.pFieldMgr.CalculateFieldNeighbour(sample.GetFieldsData(), newfld);
  2368. newfld.Sample = sample;
  2369. sample.AddNewField(newfld);
  2370. }
  2371. }
  2372. #endregion
  2373. #region 设置SEM数据
  2374. public bool SetSEMDATAMParameter(double magnification, double semWorkingDistance, double bri, double contra)
  2375. {
  2376. #region 获取电镜参数
  2377. //获取Field操作类对象
  2378. if (m_SEMDATAService == null)
  2379. {
  2380. m_SEMDATAService = new SEMControlService();
  2381. }
  2382. //判断是否连接电镜
  2383. if (m_SEMDATAService.InitAndConnection())
  2384. {
  2385. //获取电镜参数
  2386. bool mFlag;
  2387. bool wFlag;
  2388. mFlag = m_SEMDATAService.SetGMagnification(magnification);
  2389. log.Warn("Set Magnification:" + magnification.ToString("F2"));
  2390. wFlag = m_SEMDATAService.SetSemWorkingDistance(semWorkingDistance);
  2391. log.Warn("Set WD:" + semWorkingDistance.ToString("F2"));
  2392. bool c = m_SEMDATAService.SetSembrightness(bri);
  2393. log.Warn("Set Brightness:" + bri.ToString("F2"));
  2394. bool d = m_SEMDATAService.SetSemContrast(contra);
  2395. log.Warn("Set Contrast:" + contra.ToString("F2"));
  2396. if (mFlag && wFlag && c && d)
  2397. {
  2398. return true;
  2399. }
  2400. }
  2401. return false;
  2402. #endregion
  2403. }
  2404. #endregion
  2405. #region 驱动到SEM当前位置
  2406. protected void SetMeasureToSEMLocation()
  2407. {
  2408. COTSSample COTSSample = m_MeasureAppForm.m_ProjParam.GetResultData().GetWorkingSample();
  2409. int completeflds = COTSSample.GetMsrStatus().GetCompletedFields();
  2410. if (completeflds > 0)
  2411. {
  2412. return;
  2413. }
  2414. try
  2415. {
  2416. List<double> SemLocation = new List<double>();
  2417. if (GetSemLocation(ref SemLocation))
  2418. {
  2419. PointF OTSLocation = new PointF((int)Math.Round(SemLocation[(int)XYIndex.X], 0), (int)Math.Round(SemLocation[(int)XYIndex.Y], 0));
  2420. m_MeasureAppForm.m_ProjParam.GetDefaultParam().GetStageDataParam().ConvertSEMToOTSCoord(OTSLocation, ref OTSLocation);
  2421. NLog.LogManager.GetCurrentClassLogger().Warn(OTSLocation.ToString());
  2422. var sam = GetWorkingVisualSample();
  2423. var MeasureItem = sam.GetMeasureGDIObject();
  2424. var measurePos = m_visualStage.OTSCoordToCtrlCoord(OTSLocation);
  2425. MeasureItem.DraggingPoint = MeasureItem.GetCenterPoint();
  2426. MeasureItem.PositionAltering(measurePos, false);
  2427. var para = m_visualStage.GetSampleMeasurePara(MeasureItem);
  2428. SetWorkSampleMeasureArea(para);
  2429. }
  2430. Invalidate();
  2431. }
  2432. catch (Exception ex)
  2433. {
  2434. log.Error(ex.ToString());
  2435. }
  2436. }
  2437. #endregion
  2438. #region 驱动SEM到当前位置
  2439. public bool SetSEMCurrentLocation()
  2440. {
  2441. bool bret = false;
  2442. //获取Field操作类对象
  2443. if (m_SEMDATAService == null)
  2444. {
  2445. m_SEMDATAService = new SEMControlService();
  2446. }
  2447. //判断是否连接电镜
  2448. if (m_SEMDATAService.InitAndConnection())
  2449. {
  2450. bret = m_SEMDATAService.SetSEMCurrentLocation(m_MouseDownPoint, m_visualStage);
  2451. }
  2452. return bret;
  2453. }
  2454. #endregion
  2455. #region 设置SEM到中心
  2456. public bool SetSEMToCenterPoint()
  2457. {
  2458. try
  2459. {
  2460. //获取Field操作类对象
  2461. if (m_SEMDATAService == null)
  2462. {
  2463. m_SEMDATAService = new SEMControlService();
  2464. }
  2465. //判断是否连接电镜
  2466. bool bret = false;
  2467. var sam = GetWorkingVisualSample();
  2468. if (m_SEMDATAService.InitAndConnection())
  2469. {
  2470. bret = (m_SEMDATAService.DriveSEMToLocation(m_MouseDownPoint, m_visualStage, sam.GetMeasureFieldGDIObjects()));
  2471. }
  2472. return bret;
  2473. }
  2474. catch (Exception ex)
  2475. {
  2476. log.Error("OTSSamplespaceWindow_" + "SetSEMToCenterPoint" + ":" + ex.ToString() + "");
  2477. return false;
  2478. }
  2479. }
  2480. #endregion
  2481. #region 获取SEM当前位置
  2482. public bool GetSemLocation(ref List<double> SemLocation)
  2483. {
  2484. //获取Field操作类对象
  2485. if (m_SEMDATAService == null)
  2486. {
  2487. m_SEMDATAService = new SEMControlService();
  2488. }
  2489. //判断是否连接电镜
  2490. bool bret = false;
  2491. if (m_SEMDATAService.InitAndConnection())
  2492. {
  2493. bret = m_SEMDATAService.GetSemLocation(ref SemLocation);
  2494. }
  2495. return bret;
  2496. }
  2497. #endregion
  2498. #region 显示标尺
  2499. /// <summary>
  2500. /// 是否显示标尺控件
  2501. /// </summary>
  2502. /// <param name="b_show"></param>
  2503. public void ShowRulerLocation()
  2504. {
  2505. //设置标尺位置
  2506. Point rulerLocation = new Point(10, this.Height - (int)(control_Ruler2.Height * 2));
  2507. this.control_Ruler2.Location = rulerLocation;
  2508. control_Ruler2.Visible = true;
  2509. var m_GlobalZoomNum = m_visualStage.GetZoomNum();
  2510. f_ruler_size = Convert.ToInt32(f_old_ruler_size * m_GlobalZoomNum);
  2511. control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);
  2512. control_Ruler2.Value = 1;
  2513. //放大过长时,这里将宽度与代表的实际宽度进行折半显示
  2514. while (control_Ruler2.Width > 300)
  2515. {
  2516. control_Ruler2.RulerWidth = Convert.ToInt32(control_Ruler2.RulerWidth) / 2;
  2517. control_Ruler2.Value = control_Ruler2.Value * 2;
  2518. }
  2519. control_Ruler2.SetValue(control_Ruler2.RulerWidth, control_Ruler2.Value.ToString() + "mm");
  2520. }
  2521. public void RulerInit(StageDrawingData SData)
  2522. {
  2523. control_Ruler2.ShowString = "1mm";
  2524. PointF xDomain = new PointF(SData.StageDomain.Left, SData.StageDomain.Top);
  2525. PointF yDomain = new PointF(SData.StageDomain.Right, SData.StageDomain.Bottom);
  2526. //OTS宽度高度差值
  2527. float widthDomain = Math.Abs(yDomain.X - xDomain.X);
  2528. float length = this.Height > this.Width ? this.Width : this.Height;
  2529. control_Ruler2.RulerWidth = (int)(length / widthDomain * 1000);
  2530. f_ruler_size = f_old_ruler_size = length / widthDomain * 1000;
  2531. control_Ruler2.Value = 1000;
  2532. }
  2533. #endregion
  2534. #region 隐藏与显示样品孔照片
  2535. static bool IsShowSampleHoleImage = true;
  2536. public void ChangeSampleHoleImage()
  2537. {
  2538. IsShowSampleHoleImage = IsShowSampleHoleImage ? false : true;
  2539. Invalidate();
  2540. }
  2541. #endregion
  2542. #region 添加样品孔中BSE图像信息
  2543. public void AddHoleBSEImageData(byte[] ImageData, int width, int height, Point fieldPos, int fieldId)
  2544. {
  2545. //获取样品孔BSE图像
  2546. Image bseImage;
  2547. int m_iWidth = width;
  2548. int m_iHeigh = height;
  2549. if (m_visualStage.FrameOfHoleGDIObjects.Count > 0)
  2550. {
  2551. for (int i = 0; i < m_visualStage.FrameOfHoleGDIObjects.Count; i++)
  2552. {
  2553. var ctrlPos = m_visualStage.OTSCoordToCtrlCoord(fieldPos);
  2554. if (m_visualStage.FrameOfHoleGDIObjects[i].BSEImage == null)// prevent miss match when this sample area is overlaying on the other area(already took image in the field)
  2555. {
  2556. if (m_visualStage.FrameOfHoleGDIObjects[i].IfContains(ctrlPos))
  2557. //if (i == fieldId)
  2558. {
  2559. bseImage = CImageHandler.ToGrayBitmap(ImageData, m_iWidth, m_iHeigh);
  2560. m_visualStage.FrameOfHoleGDIObjects[i].BSEImage = bseImage;
  2561. if (m_MeasureAppForm.MeasureThreadRunFlag)//only when it's in running mode,we update the samplehole image.prvent conflict using of sampleHoleImageBuffer.BSEImage
  2562. {
  2563. DrawSampleHoleImage(m_visualStage.FrameOfHoleGDIObjects[i]);
  2564. }
  2565. break;
  2566. }
  2567. }
  2568. }
  2569. }
  2570. //显示样品孔照片
  2571. IsShowSampleHoleImage = true;
  2572. Invalidate();
  2573. }
  2574. #endregion
  2575. #region 删除样品孔中BSE图像信息
  2576. public void DeleteHoleBSEImageDataNoMessageBox()
  2577. {
  2578. m_visualStage.FrameOfHoleGDIObjects.Clear();
  2579. var w = sampleHoleImageBuffer.BSEImage.Width;
  2580. var h = sampleHoleImageBuffer.BSEImage.Height;
  2581. sampleHoleImageBuffer.BSEImage = new Bitmap(w, h);
  2582. Invalidate();
  2583. }
  2584. #endregion
  2585. #region 复位工作样品区域
  2586. public CDisplayGDIObject ResetMeasure(CDisplayGDIObject SampleGDIObjects, CMeasureArea MeasureGDIObjects)
  2587. {
  2588. m_visualStage.GetMeasureGdiObjectFromSampleGdi(SampleGDIObjects, out MeasureGDIObjects);
  2589. return MeasureGDIObjects;
  2590. }
  2591. public void InverseSelectWorkSampleMeasure()
  2592. {
  2593. m_DrawMeasureType = DrawMeasureAreaActionType.InverseSelection;
  2594. m_IsDrawMeasure = true;
  2595. m_DrawMeasureGDIObject = null;
  2596. this.Cursor = Cursors.Hand;
  2597. }
  2598. #endregion
  2599. private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
  2600. {
  2601. this.OnMouseDown(e);
  2602. }
  2603. private void pictureBox1_Paint(object sender, PaintEventArgs e)
  2604. {
  2605. OnPaint(e, GetAllVisualFieldGdiObject());
  2606. if (m_DrawMeasureGDIObject != null)
  2607. {
  2608. m_DrawMeasureGDIObject.OnPaint(e);
  2609. }
  2610. if (m_DrawPolygonFinishGDIObject != null) m_DrawPolygonFinishGDIObject.OnPaint(e);
  2611. }
  2612. private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
  2613. {
  2614. this.OnMouseUp(e);
  2615. }
  2616. private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
  2617. {
  2618. this.OnMouseMove(e);
  2619. }
  2620. }
  2621. }