OTSSamplespaceWindow.cs 126 KB

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