OTSSamplespaceWindow.cs 117 KB

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