OTSSamplespaceWindow.cs 116 KB

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