OTSSamplespaceWindow.cs 127 KB

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