OTSSamplespaceWindow.cs 115 KB

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