OTSSamplespaceWindow.cs 119 KB

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