OTSSamplespaceWindow.cs 123 KB

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