OTSSamplespaceWindow.cs 127 KB

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