OTSSamplespaceWindow.cs 127 KB

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