OTSSamplespaceWindow.cs 121 KB

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