OTSSamplespaceWindow.cs 127 KB

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