OTSSamplespaceWindow.cs 126 KB

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