OTSSamplespaceWindow.cs 130 KB

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