OTSSamplespaceWindow.cs 127 KB

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