OTSSamplespaceWindow.cs 127 KB

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