OTSSamplespaceWindow.cs 117 KB

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