OTSSamplespaceWindow.cs 118 KB

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