OTSSamplespaceWindow.cs 127 KB

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