OTSSamplespaceWindow.cs 123 KB

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