OTSSamplespaceWindow.cs 127 KB

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