OTSSamplespaceWindow.cs 117 KB

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