OTSSamplespaceWindow.cs 120 KB

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