OTSSamplespaceWindow.cs 115 KB

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