OTSSamplespaceWindow.cs 128 KB

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