OTSSamplespaceWindow.cs 117 KB

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