OTSSamplespaceWindow.cs 117 KB

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