OTSSamplespaceWindow.cs 124 KB

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