OTSSamplespaceWindow.cs 127 KB

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