OTSSamplespaceWindow.cs 128 KB

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