OTSSamplespaceWindow.cs 120 KB

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