OTSSamplespaceWindow.cs 118 KB

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