OTSSamplespaceWindow.cs 127 KB

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