OTSSamplespaceWindow.cs 120 KB

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