OTSSamplespaceWindow.cs 120 KB

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