OTSSamplespaceWindow.cs 117 KB

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