OTSSamplespaceWindow.cs 115 KB

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