OTSSamplespaceWindow.cs 240 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724
  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.IO;
  7. using System.Drawing.Drawing2D;
  8. using System.Collections;
  9. using OTSDataType;
  10. using OTSModelSharp;
  11. using static OTSDataType.otsdataconst;
  12. using OTSCLRINTERFACE;
  13. namespace OTSMeasureApp
  14. {
  15. public partial class OTSSamplespaceWindow : DockContent
  16. {
  17. #region 全局变量定义
  18. //样品台对象
  19. //StageDrawingData m_StageDrawingData;
  20. public StageDrawingData m_OTSSampleStageData = null;
  21. //样品测量集合对象
  22. public List<SampleMeasurePara> m_SMeasrueAreaList = null;
  23. //样品台存在的List集合 the rectangle on the edge of stage ,usually one.
  24. public static List<ARectangleGDIObject> m_RectangleGDIObjects;
  25. //标样存在的List集合 usually it is a samll circle.
  26. public static List<ARectangleGDIObject> m_SpecimenGDIObjects;
  27. //样品孔的List集合
  28. string m_SampleHoleSelectName = string.Empty;
  29. public static string m_SampleSelectName = string.Empty;
  30. string m_MeasureSelectName = string.Empty;
  31. public static List<ARectangleGDIObject> m_SampleHoleGDIObjects;// the hole gdi of the stage
  32. //样品的List集合
  33. string m_SelectName = string.Empty;
  34. public static ARectangleGDIObject selectSampleGDIObjects;
  35. public static List<ARectangleGDIObject> m_SampleGDIObjects;
  36. //工作样品的List集合
  37. string m_WorkSelectName = string.Empty;
  38. public static List<ARectangleGDIObject> m_WorkStageGDIObjects;
  39. //测量区域
  40. public static List<ARectangleGDIObject> m_MeasureGDIObjects;
  41. //文字内容
  42. public static List<ARectangleGDIObject> m_ContentGDIObjects;//the text that will display in the hole.
  43. //测量区域
  44. public static List<ARectangleGDIObject> m_MeasurePathGDIObjects;
  45. //帧图
  46. public static List<ARectangleGDIObject> m_SingleGDIObjects;
  47. //所有帧图
  48. public static List<ARectangleGDIObject> m_ALLSingleGDIObjects;
  49. //BSE图像
  50. public static List<ARectangleGDIObject> m_ImageGDIObjects;
  51. //BSE图像帧图 为了获取位置与尺寸
  52. public static List<ARectangleGDIObject> m_ImageSingleGDIObjects;
  53. //手绘测量区域
  54. public static List<ARectangleGDIObject> m_DrawMeasureGDIObjects;
  55. //SEM中心位置
  56. public static List<ARectangleGDIObject> m_SEMCenterGDIObjects;
  57. //多边形测量区域完成标识
  58. public static List<ARectangleGDIObject> m_DrawPolygonFinishGDIObjects;
  59. //记录添加帧图的尺寸 鼠标滚动时使用的原值
  60. //public static List<RectangleF> f;
  61. //鼠标点击样品台(Mouse Down 里设置),说明样品台被选中,允许拖动被选中的样品台
  62. bool m_RectangIsDragging = false;
  63. float m_PenWidth = 5;
  64. //分辨率 计算方式 0:宽度 1:高度
  65. public static int IsWidth = 0;
  66. static int m_WDomain = 0;
  67. int m_DefaultW = 0;
  68. int m_DefaultH = 0;
  69. int m_DefaultWidth = 0;
  70. int m_DefaultHeight = 0;
  71. int m_DefaultStageWidth = 0;
  72. int m_DefaultStageHeight = 0;
  73. int m_DefaultSampleWidth = 0;
  74. int m_DefaultSampleHeight = 0;
  75. //当前位置与原位置的样品台相差位置
  76. PointF m_DifferentPoint = new PointF();
  77. //主窗体对象
  78. OTSIncAMeasureAppForm m_MeasureAppForm;
  79. //鼠标右键选择的类型 0:样品台 1:样品 2:测量区域
  80. public int m_IsSelectType = 0;
  81. //当前是否选择测量区域
  82. public static bool m_IsMeasure = false;
  83. SEMDATAFieldManage m_SEMDATAFieldManage;
  84. List<Rectangle> m_RectFieldRects = null;
  85. //记录绘制样品台时的中心位置
  86. Point m_RegionStartCenterPoint = new Point(0, 0);
  87. //记录绘制后样品台的电镜坐标范围
  88. Point StageLTPointToSEMLocation = new Point(0, 0);
  89. Point StageRBPointToSEMLocation = new Point(0, 0);
  90. //当前是否移动样品
  91. bool m_IsMoveSample = false;
  92. //XML文件名称
  93. static string m_XMLFileName = System.Configuration.ConfigurationManager.ConnectionStrings["XMLFileName"].ConnectionString;
  94. //电镜与样品参数中的放大倍数与工作距离
  95. public static double m_SEMIWDistance = 0;
  96. public static double m_SEMDMagni = 0;
  97. public static double m_PropIWDistance = 0;
  98. public static double m_PropDMagni = 0;
  99. #region 鼠标滚动所需参数
  100. public static float m_ScaleNum = 1;
  101. public static float m_GlobalZoomNum = 1;//记录每次比例缩放后的总体比例系数。
  102. //改变窗体 记录的比例系数
  103. public static float m_WorkAreaZoom = 1;
  104. //加载的样品台类型 默认为原型样品台
  105. public static int m_Shape = 0;
  106. private Size m_intSize = new Size(0, 0);
  107. int m_MinMeasureWidthValue = 20;
  108. Point m_MouseDownLocation = new Point(0, 0);
  109. #endregion
  110. #region 手动绘制测量区域
  111. Point m_MouseDownPoint;
  112. Point m_MouseUpPoint;
  113. Point m_MouseMovePoint;
  114. //绘制多边形,点集合
  115. List<PointF> m_PolygonPoint;
  116. //点数量
  117. int m_PointCount = 2;
  118. //与多边形绘制的开始点相差的像素值
  119. int m_OffsetPX = 10;
  120. //手动绘制多边形测量区域完成标识
  121. bool m_IsDrawPolygonFinish = false;
  122. //手动绘制测量区域的形状类型
  123. int m_DrawMeasureType = 1;
  124. //是否手绘标识准备
  125. public bool m_IsDrawMeasureReady = false;
  126. //是否手绘标识
  127. public bool m_IsDrawMeasure = false;
  128. #endregion
  129. //所选测量区域的矩形对象
  130. Rectangle m_SelMeasureRect;
  131. //是否选中样品台标识
  132. bool m_IsSelectSampleStage = false;
  133. private Point m_P, m_P1;
  134. protected Point m_MeasureToSamplePoint;
  135. //是否按下Ctrl键
  136. bool m_IsCtrl = false;
  137. bool m_IsAlt = false;
  138. //配合Ctrol键是否选中多边形的点标识
  139. bool m_IsSelPolygonPoint = false;
  140. //配合Ctrol键是否选中多边形的点
  141. PointF m_SelPolygonPoint = new Point();
  142. //测量区域矩形对象
  143. static Rectangle m_MeasureRectangle = new Rectangle();
  144. //默认值
  145. const int m_DValue = 1;
  146. int m_CompletedFieldsCount = 0;
  147. NLog.Logger log ;
  148. //选择工作样品测量的状态
  149. bool selWSampleMeasureStatus = false;
  150. #endregion
  151. #region 标尺变量
  152. //缩放的增大缩小的增量
  153. private float f_zoom_increment = 0.1f;
  154. //缩放的基数,临时变量
  155. private float f_widthandheight_js = 0;
  156. //与原先缩放的记录数
  157. private float f_zoom_record = 1;
  158. //最小缩放倍数
  159. private float f_zoom_mix = 0.5f;
  160. //标尺的大小记录
  161. private float f_ruler_size = 100;
  162. //标尺原先大小的记录,参与计算
  163. private float f_old_ruler_size = 100;
  164. public RectangleF BackRectF
  165. {
  166. set { backrectf = value; }
  167. get { return backrectf; }
  168. }
  169. //背景矩形
  170. public RectangleF backrectf = new RectangleF();
  171. //记录原值,背景矩形
  172. public RectangleF old_backrectf = new RectangleF();
  173. //国际化
  174. OTSSysMgrTools.Language lan;
  175. Hashtable table;
  176. #endregion
  177. #region 设置双缓冲
  178. /// <summary>
  179. /// 设置双缓冲
  180. /// </summary>
  181. public void SetDoubleBufferByIsDraw()
  182. {
  183. SetStyle(ControlStyles.UserPaint, true);
  184. SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
  185. this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // 双缓冲
  186. }
  187. #endregion
  188. #region 构造函数 获取父窗体对象
  189. public OTSSamplespaceWindow(OTSIncAMeasureAppForm MeasureAppForm)
  190. {
  191. InitializeComponent();
  192. m_MeasureAppForm = MeasureAppForm;
  193. //this.InitDataEvent();
  194. SetDoubleBufferByIsDraw();// 双缓冲
  195. m_OTSSampleStageData = new StageDrawingData();
  196. //国际化
  197. lan = new OTSSysMgrTools.Language(this);
  198. table = lan.GetNameTable(this.Name);
  199. }
  200. /// <summary>
  201. /// 画圆形测试区域 事件
  202. /// </summary>
  203. public void Rev_DDrawCircleMeasure_MeasureAppToSampleWindow_Event()
  204. {
  205. //手绘测量区域类型为圆形
  206. m_DrawMeasureType = (int)CreateRectangleType.Circle;
  207. m_IsDrawMeasureReady = true;
  208. m_RectangIsDragging = false;
  209. this.Cursor = Cursors.Hand;
  210. }
  211. /// <summary>
  212. /// 画矩形测试区域 事件
  213. /// </summary>
  214. public void Rev_DDrawRectangleMeasure_MeasureAppToSampleWindow_Event()
  215. {
  216. //手绘测量区域类型为矩形
  217. m_DrawMeasureType = (int)CreateRectangleType.SampleBackGround_Rectangle;
  218. m_IsDrawMeasureReady = true;
  219. m_RectangIsDragging = false;
  220. this.Cursor = Cursors.Hand;
  221. }
  222. /// <summary>
  223. /// 画多边形测试区域 事件
  224. /// </summary>
  225. public void Rev_DDrawPolygonMeasure_MeasureAppToSampleWindow_Event()
  226. {
  227. //多边形测量区域完成标识
  228. m_DrawPolygonFinishGDIObjects = new List<ARectangleGDIObject>();
  229. //手绘测量区域类型为矩形
  230. m_DrawMeasureType = (int)CreateRectangleType.Polygon;
  231. m_IsDrawMeasureReady = true;
  232. m_IsDrawMeasure = true;
  233. m_RectangIsDragging = false;
  234. m_PolygonPoint = new List<PointF>();
  235. this.Cursor = Cursors.Hand;
  236. }
  237. /// <summary>
  238. /// 三点画圆形测试区域 事件
  239. /// </summary>
  240. public void Rev_DDrawCircleMeasureByThreePoints_MeasureAppToSampleWindow_Event()
  241. {
  242. //多边形测量区域完成标识
  243. m_DrawPolygonFinishGDIObjects = new List<ARectangleGDIObject>();
  244. //手绘测量区域类型为圆形
  245. m_DrawMeasureType = (int)CreateRectangleType.CircleByThreePoints;
  246. m_IsDrawMeasureReady = true;
  247. m_IsDrawMeasure = true;
  248. m_RectangIsDragging = false;
  249. m_PolygonPoint = new List<PointF>();
  250. this.Cursor = Cursors.Hand;
  251. }
  252. /// <summary>
  253. /// 当修改了GRID 的样品台测量精度、放大倍数和图片像素大小 时,SAMPLEWINDOW重新绘制样品台
  254. /// </summary>
  255. public void Rev_DDDrawSampleStage_EventHandler_Event()
  256. {
  257. m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;
  258. //显示帧图
  259. if (m_SingleGDIObjects.Count > 0)
  260. {
  261. showSingleInfo();
  262. }
  263. }
  264. public void Rev_MeasureApp_OpenExistSampleFile_Event(CStage SStage, CSEMStageData SEMStageData, List<SampleMeasurePara> SMeasrueAreaList, string sWorkSampleName)
  265. {
  266. GetSampleStageData(SStage, SEMStageData);
  267. var SStageData = m_OTSSampleStageData;
  268. m_GlobalZoomNum = 1;
  269. //清除所有绘制的图形信息
  270. ClearDrawInfo();
  271. //绘制样品台信息
  272. if (SStageData != null)
  273. {
  274. m_OTSSampleStageData = SStageData;
  275. DrawSampleStage(SStageData);
  276. }
  277. //绘制样品与测量区域
  278. //1.绘制样品
  279. if (SMeasrueAreaList != null)
  280. {
  281. m_SMeasrueAreaList = SMeasrueAreaList;
  282. DrawSampleAndMeasureInfo(SMeasrueAreaList);
  283. }
  284. //2.测量区域
  285. //设置工作样品
  286. if (sWorkSampleName != "")
  287. {
  288. Rev_MeasureApp_SwitchWorkSample_Event(sWorkSampleName);
  289. //打开文件后 设置工作样品名称
  290. m_SampleSelectName = sWorkSampleName;
  291. }
  292. //重新绘制
  293. Invalidate();
  294. }
  295. ///MeasureApp和 SampleSpaceWindow 切换工作样品名称事件委托
  296. ///string sNewWSampleName: 切换新工作样品名称
  297. public void Rev_MeasureApp_SwitchWorkSample_Event(string sNewWSampleName, bool bDrawField = false)
  298. {
  299. try
  300. {
  301. //获取存在帧图的样品名称
  302. string singleSampleName = string.Empty;
  303. if (m_SingleGDIObjects != null)
  304. {
  305. if (m_SingleGDIObjects.Count > 0)
  306. {
  307. singleSampleName = m_SingleGDIObjects[0].SampleName;
  308. }
  309. }
  310. //判断当前帧图所在样品的样品名称与新样品名称是否相同
  311. if (!singleSampleName.Equals(""))
  312. {
  313. if (singleSampleName != sNewWSampleName)
  314. {
  315. //先清空帧图信息
  316. ClearImageAndSingleGDIObjects();
  317. this.Invalidate();
  318. }
  319. }
  320. //判断当前帧图所在样品的样品名称与新样品名称是否相同
  321. if (m_SingleGDIObjects != null)
  322. {
  323. if (m_SingleGDIObjects.Count > 0)
  324. {
  325. if (m_SingleGDIObjects[0].SampleName != sNewWSampleName)
  326. {
  327. //先清空帧图信息
  328. ClearImageAndSingleGDIObjects();
  329. this.Invalidate();
  330. }
  331. }
  332. }
  333. //设置工作样品样式
  334. CStageManage.SetWorkSampleAndWorkMeasure(sNewWSampleName);
  335. foreach (var itemMeasure in m_MeasureGDIObjects)
  336. {
  337. if (itemMeasure.IsSingle && itemMeasure.IsWorkSample && sNewWSampleName == itemMeasure.SampleName)
  338. {
  339. //当前工作样品的测量区域 获取帧图信息
  340. if (m_SingleGDIObjects.Count == 0)
  341. {
  342. string message = table["message1"].ToString();
  343. //log.Trace("Rev_MeasureApp_SwitchWorkSample_Event:--" + message + "--begin--");
  344. showSingleInfo();
  345. //log.Trace("Rev_MeasureApp_SwitchWorkSample_Event:--" + message + "--end--");
  346. break;
  347. }
  348. }
  349. }
  350. ////绘制已完成的帧图状态
  351. COTSMsrPrjResultData cProjMgr = m_MeasureAppForm.m_ProjParam.m_ResultData;
  352. //当前工作样品的测量区域 获取帧图信息
  353. COTSSample cSample = cProjMgr.GetWorkingSample();
  354. int CompletedFieldsCount = cSample.GetMsrStatus().GetCompletedFields();
  355. if (CompletedFieldsCount > 0)
  356. {
  357. //设置测量区域获取帧图
  358. foreach (var itemMeasure in m_MeasureGDIObjects)
  359. {
  360. if (cSample.GetName() == itemMeasure.SampleName)
  361. {
  362. itemMeasure.IsSingle = true;
  363. break;
  364. }
  365. }
  366. if (m_SingleGDIObjects.Count == 0)
  367. {
  368. showSingleInfo();
  369. }
  370. //获取已完成测量的帧图中心点
  371. List<Point> CompleteFieldList = cProjMgr.GetWorkingSample().GetMsrStatus().GetCompletedFieldsCenter();
  372. //修改帧图完成状态
  373. OTSMeasureDisplayResult.ChangeCompleteFieldMeasureState(CompleteFieldList, Color.Green, m_MeasureAppForm);
  374. }
  375. else
  376. {
  377. //根据测量文件中已获取sem信息
  378. if (cSample.GetSEMDataMsr().GetTotalFields() > 0)
  379. {
  380. foreach (var itemMeasure in m_MeasureGDIObjects)
  381. {
  382. if (cSample.GetName() == itemMeasure.SampleName)
  383. {
  384. itemMeasure.IsSingle = true;
  385. showSingleInfo();
  386. break;
  387. }
  388. }
  389. }
  390. }
  391. //设置为手绘测量区域
  392. m_IsDrawMeasureReady = false;
  393. m_IsDrawMeasure = false;
  394. this.Invalidate();
  395. return;
  396. }
  397. catch (Exception ex)
  398. {
  399. string message = table["message2"].ToString();
  400. //记录错误日志
  401. log.Trace("Rev_MeasureApp_SwitchWorkSample_Event():" + message + ":" + ex.ToString() + "");
  402. }
  403. }
  404. //MeasureApp和 SampleSpaceWindow 修改工作样品名称事件委托
  405. //string sSampleHoleName: 修改工作样品名称
  406. public void Rev_MeasureApp_ChangeWorkSampleName_Event(string sNewWSampleName)
  407. {
  408. try
  409. {
  410. string oldSampleName = string.Empty;
  411. foreach (ARectangleGDIObject itemSample in OTSSamplespaceWindow.m_SampleGDIObjects)
  412. {
  413. if (itemSample.IsWorkSample)
  414. {
  415. oldSampleName = itemSample.SampleName;
  416. }
  417. }
  418. //更换样品名称
  419. CStageManage.ChangeSampleName(sNewWSampleName);
  420. this.Invalidate();
  421. return;
  422. }
  423. catch (Exception ex)
  424. {
  425. string message = table["message2"].ToString();
  426. //记录错误日志
  427. log.Trace("Rev_MeasureApp_ChangeWorkSampleName_Event():" + message + ":" + ex.ToString() + "");
  428. }
  429. }
  430. //MeasureApp和 SampleSpaceWindow 删除样品事件委托, MeasureApp 给 SampleSpaceWindow 发送删除样品委托事件
  431. //string sSampleHoleName: 删除工作样品名
  432. public void Rev_MeasureApp_DeleteWorkSample_Event(string sDeleteWSampleName, string sNewWSampleName)
  433. {
  434. try
  435. {
  436. foreach (ARectangleGDIObject itemSample in OTSSamplespaceWindow.m_SampleGDIObjects)
  437. {
  438. if (itemSample.SampleName == sDeleteWSampleName)
  439. {
  440. if (itemSample.IsWorkSample)
  441. {
  442. //删除样品测量集合中的对象
  443. if (CStageManage.DeleteSample(sDeleteWSampleName))
  444. {
  445. if (m_SampleGDIObjects.Count == 0)
  446. {
  447. //将测量状态初始化
  448. m_MeasureAppForm.m_MessureStatuWindow.SetMeasureStatusInit();
  449. }
  450. //根据样品名称 删除对应帧图信息
  451. OTSSamplespaceGraphicsPanelFun.DeleteALLSingleInfo(m_ALLSingleGDIObjects, sDeleteWSampleName);
  452. if (!string.IsNullOrEmpty(sNewWSampleName))
  453. {
  454. //设置工作样品
  455. m_MeasureAppForm.Rev_SoluWindowReqSwitchWSample_Event(sNewWSampleName);
  456. }
  457. else
  458. {
  459. //先清空帧图信息
  460. ClearImageAndSingleGDIObjects();
  461. }
  462. this.Invalidate();
  463. return;
  464. }
  465. }
  466. }
  467. }
  468. }
  469. catch (Exception ex)
  470. {
  471. string message = table["message2"].ToString();
  472. //记录错误日志
  473. log.Error("Rev_MeasureApp_DeleteWorkSample_Event():" + message + ":" + ex.ToString() + "");
  474. }
  475. }
  476. #region 更改工作样品中 测量区域形状
  477. public void changeShape(int iShape)
  478. {
  479. try
  480. {
  481. string sampleName = m_MeasureAppForm.m_ProjParam.GetWorkSampleName();
  482. //m_Shap 更换样品形状
  483. if (CStageManage.ChangeSampleShape(iShape))
  484. {
  485. //设置新添加测量区域更改位置与缩放
  486. foreach (var item in m_MeasureGDIObjects)
  487. {
  488. if (item.SampleName == sampleName)
  489. {
  490. item.IsWorkSample = true;
  491. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(item, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  492. {
  493. //保存原位置
  494. Rectangle rectPara = item.Region;
  495. #region 测量区域与样品中心相差的距离
  496. foreach (var itemSample in m_SampleGDIObjects)
  497. {
  498. if (itemSample.SampleName == item.SampleName)
  499. {
  500. item.SampleCenterDifferCenterPoint = OTSSamplespaceGraphicsPanelFun.GetSampleCenterDifferCenterPoint(rectPara, itemSample.Region);
  501. break;
  502. }
  503. }
  504. if (item.IsSingle)
  505. {
  506. showSingleInfo();
  507. }
  508. #endregion
  509. }
  510. }
  511. }
  512. }
  513. this.Invalidate();
  514. return;
  515. }
  516. catch (Exception ex)
  517. {
  518. string message = table["message2"].ToString();
  519. //记录错误日志
  520. log.Error("changeShape():" + message + ":" + ex.ToString() + "");
  521. }
  522. }
  523. #endregion
  524. #region 还原测量区域形状
  525. public void ResetShape()
  526. {
  527. try
  528. {
  529. //设置新添加测量区域更改位置与缩放
  530. foreach (var item in m_MeasureGDIObjects)
  531. {
  532. if (item.IsWorkSample)
  533. {
  534. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(item, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  535. {
  536. //保存原位置
  537. Rectangle rectPara = item.Region;
  538. #region 测量区域与样品中心相差的距离
  539. foreach (var itemSample in m_SampleGDIObjects)
  540. {
  541. if (itemSample.SampleName == item.SampleName)
  542. {
  543. item.SampleCenterDifferCenterPoint = OTSSamplespaceGraphicsPanelFun.GetSampleCenterDifferCenterPoint(rectPara, itemSample.Region);
  544. break;
  545. }
  546. }
  547. if (item.IsSingle)
  548. {
  549. showSingleInfo();
  550. }
  551. #endregion
  552. }
  553. }
  554. }
  555. this.Invalidate();
  556. return;
  557. }
  558. catch (Exception ex)
  559. {
  560. string message = table["message2"].ToString();
  561. //记录错误日志
  562. log.Error("changeShape():" + message + ":" + ex.ToString() + "");
  563. }
  564. }
  565. #endregion
  566. ///MeasureApp 给SampleWindow窗口发送添加样品的样品孔名,测量区域信息
  567. //string sSampleName : 新添加样品名
  568. //string sSampleHoleName: 新添加样品所在的样品孔名称
  569. //int iShape: 测量区域形状
  570. //Point pStartPoint: 测量区域起点
  571. //Point pEndPoint : 测量区域终点
  572. public void AddOneSampleArea(SampleMeasurePara SMeasurePara)
  573. {
  574. try
  575. {
  576. CMStrip.Hide();
  577. //获取样品信息
  578. Point xHole = new Point(SMeasurePara.MeasureRect.Left, SMeasurePara.MeasureRect.Top);
  579. Point yHole = new Point(SMeasurePara.MeasureRect.Right, SMeasurePara.MeasureRect.Bottom);
  580. //将微米转换为像素
  581. int widthHole = (int)(Math.Abs(((Point)yHole).X - ((Point)xHole).X));
  582. int heightHole = (int)(Math.Abs(((Point)yHole).Y - ((Point)xHole).Y));
  583. //定义测量区域
  584. RectangleF SampleRectangleF = OTSSamplespaceGraphicsPanelFun.GetPixRectF(m_WDomain, yHole, xHole, "", "", IsWidth, m_DefaultW, m_DefaultH);
  585. ARectangleGDIObject m_SampleGDIObject = OTSSamplespaceGraphicsPanelFun.GetPixRect(m_WDomain, yHole, xHole, SMeasurePara.iShape, "", "", IsWidth, m_DefaultW, m_DefaultH);
  586. m_SampleGDIObject.Region = new Rectangle((int)SampleRectangleF.X, (int)SampleRectangleF.Y, (int)SampleRectangleF.Width, (int)SampleRectangleF.Height);
  587. m_SampleGDIObject.RegionF = SampleRectangleF;
  588. m_SampleGDIObject.DrawRegionF = SampleRectangleF;
  589. //测量区域名称 样品名称
  590. m_SampleGDIObject.SampleName = SMeasurePara.sSampleName;
  591. //测量区域类型
  592. m_SampleGDIObject.CreateType = SMeasurePara.iShape;
  593. //添加样品
  594. if (CStageManage.AddSample(SMeasurePara.sHoleName, SMeasurePara.sSampleName, m_SampleGDIObject, this, m_GlobalZoomNum))
  595. {
  596. //设置新添加样品测量的位置
  597. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(m_MeasureGDIObjects[m_MeasureGDIObjects.Count - 1], m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  598. {
  599. CStageManage.SetWorkSampleAndWorkMeasure(SMeasurePara.sSampleName);
  600. //清除帧图信息
  601. ClearImageAndSingleGDIObjects();
  602. Invalidate();
  603. }
  604. }
  605. }
  606. catch (Exception ex)
  607. {
  608. string message = table["message2"].ToString();
  609. //记录错误日志
  610. log.Error("OTSSamplespaceWindow_Rev_MeasureApp_AddSample_Event():--" + message + ":" + ex.ToString() + "");
  611. }
  612. }
  613. //响应委托事件的样品台数据
  614. public void InitStageDisplay(CStage SStage, CSEMStageData SEMStageData)
  615. {
  616. GetSampleStageData(SStage, SEMStageData);
  617. m_GlobalZoomNum = 1;
  618. //清除所有绘制的图形信息
  619. ClearDrawInfo();
  620. //绘制样品台信息
  621. DrawSampleStage(m_OTSSampleStageData);
  622. //标尺初始化
  623. RulerInit();
  624. //重新绘制
  625. Invalidate();
  626. //1.将测量结果窗体中已存在的内容清空
  627. //2.将测量图像清空
  628. //图像隐藏
  629. HideMessureStatuWindowBSEImage(m_MeasureAppForm);
  630. //将测量结果信息状态初始化
  631. InitMeasureStateInfo();
  632. if (m_SampleGDIObjects != null)
  633. {
  634. if (m_SampleGDIObjects.Count == 0)
  635. {
  636. //将测量状态初始化
  637. m_MeasureAppForm.m_MessureStatuWindow.SetMeasureStatusInit();
  638. }
  639. }
  640. }
  641. public void HideMessureStatuWindowBSEImage(OTSIncAMeasureAppForm m_MeasureApps)
  642. {
  643. m_MeasureApps.m_MessureStatuWindow.pbBSEImage.Hide();
  644. }
  645. #region 将测量状态进度窗口信息初始化
  646. public void InitMeasureStateInfo()
  647. {
  648. m_MeasureAppForm.m_MeasureRetWindow.SetInit();
  649. }
  650. #endregion
  651. //获取绘制样品台的数据
  652. private bool GetSampleStageData(CStage SStage ,CSEMStageData SEMStageData)
  653. {
  654. //StageDrawingData m_OTSSampleStageData = new StageDrawingData();
  655. //获取样品台信息
  656. //CStage SStage = m_ResultData.GetStage();
  657. if (null == SStage)
  658. {
  659. return false;
  660. }
  661. //获得样品台数据
  662. m_OTSSampleStageData.sStageName = SStage.GetName();
  663. m_OTSSampleStageData.bStageShape = (int)SStage.GetBoundary().GetShape();
  664. m_OTSSampleStageData.StageDomain = (Rectangle)SStage.GetBoundary().GetRectDomain();
  665. m_OTSSampleStageData.bSampleShape = (int)SStage.GetSTD().GetShape();
  666. m_OTSSampleStageData.SampleRect = (Rectangle)SStage.GetSTD().GetRectDomain();
  667. int iSHoleCount = SStage.GetHoleList().Count; //样品孔个数
  668. if (m_OTSSampleStageData.sSHoleInfoList.Count > 0)
  669. {
  670. m_OTSSampleStageData.sSHoleInfoList.Clear();
  671. }
  672. var holeLst = SStage.GetHoleList();
  673. for (int i = 0; i < iSHoleCount; i++)
  674. {
  675. CHole d = holeLst[i];
  676. OTSSampleHoleInfo SHoleInfo = new OTSSampleHoleInfo();
  677. //获取样品口的名称,形状,坐标
  678. SHoleInfo.sSHoleName = d.GetName();
  679. SHoleInfo.iSHoleShape = (int)d.GetShape();
  680. Rectangle r = (Rectangle)d.GetRectDomain();
  681. SHoleInfo.HoleRect = r;
  682. m_OTSSampleStageData.sSHoleInfoList.Add(SHoleInfo);
  683. }
  684. //获取SEMData 绘制样品
  685. m_OTSSampleStageData.iScanFieldSize100 = SEMStageData.GetScanFieldSize100(); //放大倍数为100倍时的屏幕尺寸
  686. m_OTSSampleStageData.iXAxisDir = (int)SEMStageData.GetXAxisDir();
  687. m_OTSSampleStageData.iYAxisDir = (int)SEMStageData.GetYAxisDir();
  688. m_OTSSampleStageData.iXAxisStartVal = SEMStageData.GetXAxis().GetStart();
  689. m_OTSSampleStageData.iXAxisEndVal = SEMStageData.GetXAxis().GetEnd();
  690. m_OTSSampleStageData.iYAxisStartVal = SEMStageData.GetYAxis().GetStart();
  691. m_OTSSampleStageData.iYAxisEndVal = SEMStageData.GetYAxis().GetEnd();
  692. return true;
  693. }
  694. //记录样品台的最大宽度
  695. static int RegionMaxWidth = 0;
  696. #region 绘制样品台信息
  697. /// <summary>
  698. /// 绘制样品台信息
  699. /// </summary>
  700. /// <returns></returns>
  701. public void DrawSampleStage(StageDrawingData SData)
  702. {
  703. try
  704. {
  705. if (SData.StageDomain.X == 0 && SData.StageDomain.Y == 0)
  706. {
  707. return;
  708. }
  709. string stageName = SData.sStageName;
  710. int widthDomain = 0;
  711. int heightDomain = 0;
  712. //获取样品台
  713. int StageShape = SData.bStageShape;
  714. Point xDomain = new Point(SData.StageDomain.Left, SData.StageDomain.Top);
  715. Point yDomain = new Point(SData.StageDomain.Right, SData.StageDomain.Bottom);
  716. //OTS宽度高度差值
  717. widthDomain = Math.Abs(yDomain.X - xDomain.X);
  718. heightDomain = Math.Abs(yDomain.Y - xDomain.Y);
  719. //样品台转换在电镜位置的宽度与高度
  720. StageLTPointToSEMLocation = m_MeasureAppForm.m_ProjParam.ChangeOTSToSemCoord(xDomain);
  721. StageRBPointToSEMLocation = m_MeasureAppForm.m_ProjParam.ChangeOTSToSemCoord(yDomain);
  722. //设置样品台宽度
  723. m_WDomain = widthDomain;
  724. IsWidth = this.Height > this.Width ? 0 : 1;
  725. //记录添加帧图的尺寸 鼠标滚动时使用的原值
  726. m_DefaultW = this.Width;
  727. m_DefaultH = this.Height;
  728. m_Shape = SData.bStageShape;
  729. CreateRectangle CreateBourary = null;
  730. //0:圆角矩形 1:圆形 2:文字 3:矩形
  731. if (SData.bStageShape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  732. {
  733. CreateBourary = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xDomain, yDomain, (int)CreateRectangleType.SampleBackGround_Rectangle, "", "", IsWidth, m_DefaultW, m_DefaultH);
  734. }
  735. else
  736. {
  737. CreateBourary = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xDomain, yDomain, (int)CreateRectangleType.SampleBackGround_Circle, "", "", IsWidth, m_DefaultW, m_DefaultH);
  738. }
  739. //获取默认尺寸
  740. m_DefaultWidth = CreateBourary.Region.Width;
  741. m_DefaultHeight = CreateBourary.Region.Height;
  742. //添加样品台 对象
  743. //设置路径
  744. GraphicsPath MeasurePath = new GraphicsPath();
  745. if (StageShape == (int)CreateRectangleType.Circle)
  746. {
  747. MeasurePath.AddEllipse(CreateBourary.Region);
  748. }
  749. else
  750. {
  751. MeasurePath.AddRectangle(CreateBourary.Region);
  752. }
  753. CreateBourary.GPath = MeasurePath;
  754. CreateBourary.Shape = StageShape;
  755. m_RectangleGDIObjects.Add(CreateBourary);
  756. //绘制后的样品台中心位置
  757. Point m_Region = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(m_RectangleGDIObjects[0].Region);
  758. //获取绘制后的样品台中心位置
  759. if (m_RegionStartCenterPoint.X != m_Region.X || m_RegionStartCenterPoint.Y != m_Region.Y)
  760. {
  761. m_RegionStartCenterPoint = m_Region;
  762. }
  763. //获取最大宽度
  764. if (RegionMaxWidth <= 0)
  765. {
  766. RegionMaxWidth = (IsWidth == 0 ? this.Width : this.Height);
  767. }
  768. //获取样品孔
  769. System.Collections.Generic.List<OTSSampleHoleInfo> ChloeClrList = SData.sSHoleInfoList;
  770. if (ChloeClrList.Count > 0)
  771. {
  772. for (int i = 0; i < ChloeClrList.Count; i++)
  773. {
  774. //获取微米信息
  775. var xHole = new Point(ChloeClrList[i].HoleRect.Left, ChloeClrList[i].HoleRect.Top);
  776. var yHole = new Point(ChloeClrList[i].HoleRect.Right, ChloeClrList[i].HoleRect.Bottom);
  777. //将微米转换为像素
  778. int widthHole = Math.Abs(yHole.X - xHole.X);
  779. int heightHole = Math.Abs(yHole.Y - xHole.Y);
  780. //获取矩形
  781. CreateRectangle CreateHole = null;
  782. //0:圆角矩形 1:圆形 2:文字 3:矩形
  783. if (ChloeClrList[i].iSHoleShape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  784. {
  785. CreateHole = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xHole, yHole, (int)CreateRectangleType.Rectangle, "", ChloeClrList[i].sSHoleName, IsWidth, m_DefaultW, m_DefaultH);
  786. }
  787. else
  788. {
  789. CreateHole = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xHole, yHole, (int)CreateRectangleType.Circle, "", ChloeClrList[i].sSHoleName, IsWidth, m_DefaultW, m_DefaultH);
  790. }
  791. //获取样品孔默认尺寸
  792. m_DefaultStageWidth = CreateHole.Region.Width;
  793. m_DefaultStageHeight = CreateHole.Region.Height;
  794. //绘制样品孔路径
  795. GraphicsPath HolePath = new GraphicsPath();
  796. if (ChloeClrList[i].iSHoleShape == (int)CreateRectangleType.Circle)
  797. {
  798. HolePath.AddEllipse(CreateHole.Region);
  799. }
  800. else
  801. {
  802. HolePath.AddRectangle(CreateHole.Region);
  803. }
  804. CreateHole.GPath = HolePath;
  805. m_SampleHoleGDIObjects.Add(CreateHole);
  806. //添加文字
  807. CreateRectangle CreateContent = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xHole, yHole, (int)CreateRectangleType.Rectangle, "", "", IsWidth, m_DefaultW, m_DefaultH);
  808. //类型 文字:2
  809. CreateContent.CreateType = (int)CreateRectangleType.Font;
  810. CreateContent.Region = CreateHole.Region;
  811. CreateContent.strContent = ChloeClrList[i].sSHoleName;
  812. CreateContent.Name = ChloeClrList[i].sSHoleName;
  813. m_ContentGDIObjects.Add(CreateContent);
  814. }
  815. }
  816. //获取标样
  817. int StageShapes = SData.bStageShape;
  818. Point xSTD = new Point(SData.SampleRect.Left, SData.SampleRect.Top);
  819. Point ySTD = new Point(SData.SampleRect.Right, SData.SampleRect.Bottom);
  820. //获取矩形
  821. CreateRectangle CreateSTD = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xSTD, ySTD, (int)CreateRectangleType.Rectangle, "", "", IsWidth, m_DefaultW, m_DefaultH);
  822. if (StageShapes == (int)CreateRectangleType.Circle)
  823. {
  824. CreateSTD = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xSTD, ySTD, (int)CreateRectangleType.SpecimenCircle, "", "", IsWidth, m_DefaultW, m_DefaultH);
  825. }
  826. else
  827. {
  828. CreateSTD = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xSTD, ySTD, (int)CreateRectangleType.SpecimenRectangle, "", "", IsWidth, m_DefaultW, m_DefaultH);
  829. }
  830. m_DefaultSampleWidth = CreateSTD.Region.Width;
  831. m_DefaultSampleHeight = CreateSTD.Region.Height;
  832. //绘制标样路径
  833. GraphicsPath STDPath = new GraphicsPath();
  834. if (StageShapes == (int)CreateRectangleType.Circle)
  835. {
  836. STDPath.AddEllipse(CreateSTD.Region);
  837. }
  838. else
  839. {
  840. STDPath.AddRectangle(CreateSTD.Region);
  841. }
  842. CreateSTD.GPath = STDPath;
  843. m_SpecimenGDIObjects.Add(CreateSTD);
  844. return;
  845. }
  846. catch (Exception ex)
  847. {
  848. string message = table["message2"].ToString();
  849. log.Error("OTSSamplespaceWindow_DrawSampleInfo():--" + message + ":" + ex.ToString() + "");
  850. }
  851. }
  852. #endregion
  853. private string m_fileName = string.Empty;
  854. public string FileName
  855. {
  856. get { return m_fileName; }
  857. set
  858. {
  859. if (value != string.Empty)
  860. {
  861. Stream s = new FileStream(value, FileMode.Open);
  862. FileInfo efInfo = new FileInfo(value);
  863. string fext = efInfo.Extension.ToUpper();
  864. s.Close();
  865. }
  866. m_fileName = value;
  867. this.ToolTipText = value;
  868. }
  869. }
  870. #endregion
  871. #region 窗体事件
  872. private void OTSSamplespaceWindow_Load(object sender, EventArgs e)
  873. {
  874. try
  875. {
  876. //样品台
  877. m_RectangleGDIObjects = new List<ARectangleGDIObject>();
  878. //标样
  879. m_SpecimenGDIObjects = new List<ARectangleGDIObject>();
  880. //样品孔
  881. m_SampleHoleGDIObjects = new List<ARectangleGDIObject>();
  882. //样品孔文字内容
  883. m_ContentGDIObjects = new List<ARectangleGDIObject>();
  884. //样品
  885. m_SampleGDIObjects = new List<ARectangleGDIObject>();
  886. //工作样品
  887. m_WorkStageGDIObjects = new List<ARectangleGDIObject>();
  888. //测量区域
  889. m_MeasureGDIObjects = new List<ARectangleGDIObject>();
  890. //测量区域图形路径
  891. m_MeasurePathGDIObjects = new List<ARectangleGDIObject>();
  892. //手绘测量区域
  893. m_DrawMeasureGDIObjects = new List<ARectangleGDIObject>();
  894. //帧图
  895. m_SingleGDIObjects = new List<ARectangleGDIObject>();
  896. //所有帧图
  897. m_ALLSingleGDIObjects = new List<ARectangleGDIObject>();
  898. //样品孔BSE图像
  899. m_ImageGDIObjects = new List<ARectangleGDIObject>();
  900. //BSE图像帧图为了获取位置与尺寸
  901. m_ImageSingleGDIObjects = new List<ARectangleGDIObject>();
  902. //SEM中心位置
  903. m_SEMCenterGDIObjects = new List<ARectangleGDIObject>();
  904. this.ResizeRedraw = true;
  905. log = NLog.LogManager.GetCurrentClassLogger();
  906. }
  907. catch (Exception ex)
  908. {
  909. string message = table["message2"].ToString();
  910. log.Error("OTSSamplespaceWindow_OTSSamplespaceWindow_Load:--" + message + ":" + ex.ToString() + "");
  911. }
  912. }
  913. protected override void OnMouseDown(MouseEventArgs e)
  914. {
  915. lblFocus.Focus();
  916. //记录鼠标按下的位置
  917. m_P.X = e.X;
  918. m_P.Y = e.Y;
  919. m_P1.X = e.X;
  920. m_P1.Y = e.Y;
  921. int WH = 2;
  922. //鼠标点击时的位置
  923. Point _Point = new Point();
  924. m_RectangIsDragging = false;
  925. if (m_RectangleGDIObjects == null)
  926. return;
  927. //判断当前是否手绘
  928. if (m_IsDrawMeasureReady)
  929. {
  930. //获取当前的鼠标点击位置
  931. this.m_MouseDownPoint = new Point(e.X, e.Y);
  932. //获取当前工作样品
  933. COTSSample cSample = m_MeasureAppForm.m_ProjParam.GetWorkSample();
  934. string sampleHoleName = cSample.GetSampleHoleName();
  935. string sampleName = cSample.GetName();
  936. int sizeWH = 5;
  937. Size size = new Size(sizeWH, sizeWH);
  938. Rectangle rectangle = new Rectangle(m_MouseDownPoint, size);
  939. //绘制多边形 测量区域
  940. if (m_DrawMeasureType == (int)CreateRectangleType.Polygon)
  941. {
  942. //显示绘制多边形完成标识
  943. if (m_PolygonPoint.Count > m_PointCount)
  944. {
  945. Point startPoint = new Point((int)(m_PolygonPoint[0].X), (int)(m_PolygonPoint[0].Y));
  946. if (m_IsDrawPolygonFinish)
  947. {
  948. DialogResult dResult = MessageBox.Show(table["message10"].ToString(), table["message11"].ToString(), MessageBoxButtons.YesNo);
  949. if (dResult == DialogResult.Yes)
  950. {
  951. m_PolygonPoint.Add(startPoint);
  952. CreateRectangle createFinishPoint = new CreateRectangle(m_PolygonPoint, (int)CreateRectangleType.Polygon, m_DrawMeasureType, sampleHoleName, sampleName, Color.Red);
  953. GraphicsPath PolygonMeasurePath = new GraphicsPath();
  954. PolygonMeasurePath.AddPolygon(m_PolygonPoint.ToArray());
  955. createFinishPoint.GPath = PolygonMeasurePath;
  956. for (int i = 0; i < createFinishPoint.PolygonPointRegionF.Count; i++)
  957. {
  958. float X = createFinishPoint.PolygonPointRegionF[i].X / m_GlobalZoomNum;
  959. float Y = createFinishPoint.PolygonPointRegionF[i].Y / m_GlobalZoomNum;
  960. PointF DrawPoint = new PointF(X, Y);
  961. createFinishPoint.DrawPolygonPointRegionF[i] = DrawPoint;
  962. }
  963. if (m_DrawMeasureGDIObjects.Count > 0)
  964. {
  965. m_DrawMeasureGDIObjects[0] = createFinishPoint;
  966. }
  967. bool IsSingle = false;
  968. //清除当前的样品测量区域
  969. for (int measureIndex = m_MeasureGDIObjects.Count - 1; measureIndex >= 0; measureIndex--)
  970. {
  971. if (m_MeasureGDIObjects[measureIndex].SampleName == sampleName)
  972. {
  973. IsSingle = m_MeasureGDIObjects[measureIndex].IsSingle;
  974. m_MeasureGDIObjects.RemoveAt(measureIndex);
  975. break;
  976. }
  977. }
  978. //删除存在的帧图
  979. for (int singleIndex = m_SingleGDIObjects.Count - 1; singleIndex >= 0; singleIndex--)
  980. {
  981. if (m_SingleGDIObjects[singleIndex].SampleName == sampleName)
  982. {
  983. m_SingleGDIObjects.RemoveAt(singleIndex);
  984. }
  985. }
  986. //将绘制好的多边形测量区域赋值给 多边形测量区域对象
  987. if (m_DrawMeasureGDIObjects.Count > 0)
  988. {
  989. m_DrawMeasureGDIObjects[0].IsSelect = true;
  990. m_DrawMeasureGDIObjects[0].IsWorkSample = true;
  991. //创建多边形外接矩形
  992. m_DrawMeasureGDIObjects[0].Region = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(OTSSamplespaceGraphicsPanelFun.PointConvertPointF(m_DrawMeasureGDIObjects[0].PolygonPointRegion));
  993. m_DrawMeasureGDIObjects[0].RegionF = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(m_DrawMeasureGDIObjects[0].DrawPolygonPointRegionF);
  994. m_DrawMeasureGDIObjects[0].DrawRegionF = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(m_DrawMeasureGDIObjects[0].DrawPolygonPointRegionF);
  995. m_DrawMeasureGDIObjects[0].IsSingle = IsSingle;
  996. m_DrawMeasureGDIObjects[0].IsWorkSample = true;
  997. m_MeasureGDIObjects.Add(m_DrawMeasureGDIObjects[0]);
  998. m_DrawMeasureGDIObjects.Clear();
  999. m_DrawPolygonFinishGDIObjects.Clear();
  1000. }
  1001. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(m_MeasureGDIObjects[m_MeasureGDIObjects.Count - 1], m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  1002. {
  1003. m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;
  1004. CMeasureThreadWrapper.DoRunType = (int)MSR_THREAD_RunSTATUS.RUNMEASURE;
  1005. //设置工作样品
  1006. m_MeasureAppForm.Rev_SoluWindowReqSwitchWSample_Event(m_SampleSelectName);
  1007. Invalidate();
  1008. }
  1009. //设置手绘标识
  1010. m_IsDrawMeasureReady = false;
  1011. m_IsDrawMeasure = false;
  1012. m_IsDrawPolygonFinish = false;
  1013. this.Cursor = Cursors.Default;
  1014. return;
  1015. }
  1016. else
  1017. {
  1018. return;
  1019. }
  1020. }
  1021. }
  1022. //添加多边形点信息
  1023. m_MouseDownPoint = new Point((int)(m_MouseDownPoint.X), (int)(m_MouseDownPoint.Y));
  1024. m_PolygonPoint.Add(m_MouseDownPoint);
  1025. CreateRectangle createPoint = new CreateRectangle(m_PolygonPoint, (int)CreateRectangleType.Polygon, m_DrawMeasureType, sampleHoleName, sampleName, Color.Red);
  1026. if (m_DrawMeasureGDIObjects.Count > 0)
  1027. {
  1028. m_DrawMeasureGDIObjects[0] = createPoint;
  1029. }
  1030. else
  1031. {
  1032. m_DrawMeasureGDIObjects.Add(createPoint);
  1033. }
  1034. //添加当前绘制的第一点位置,生成多边形测量区域完成标识
  1035. if (m_DrawPolygonFinishGDIObjects.Count == 0)
  1036. {
  1037. int rectSize = m_MinMeasureWidthValue;
  1038. Point PolygonFinishPoint = new Point((int)(m_MouseDownPoint.X - m_MinMeasureWidthValue / 2), (int)(m_MouseDownPoint.Y - m_MinMeasureWidthValue / 2));
  1039. Rectangle pRect = new Rectangle(PolygonFinishPoint, new Size(rectSize, rectSize));
  1040. CreateRectangle createPolygonFinish = new CreateRectangle(pRect, (int)CreateRectangleType.DrawPolygonFinish, sampleHoleName, sampleName, Color.Green);
  1041. m_DrawPolygonFinishGDIObjects.Add(createPolygonFinish);
  1042. }
  1043. return;
  1044. }
  1045. else if(m_DrawMeasureType == (int)CreateRectangleType.CircleByThreePoints)
  1046. {
  1047. //显示绘制多边形完成标识
  1048. if (m_PolygonPoint.Count == 3)
  1049. {
  1050. Point startPoint = new Point((int)(m_PolygonPoint[0].X), (int)(m_PolygonPoint[0].Y));
  1051. //清除当前的样品测量区域
  1052. for (int measureIndex = m_MeasureGDIObjects.Count - 1; measureIndex >= 0; measureIndex--)
  1053. {
  1054. if (m_MeasureGDIObjects[measureIndex].SampleName == sampleName)
  1055. {
  1056. m_MeasureGDIObjects.RemoveAt(measureIndex);
  1057. break;
  1058. }
  1059. }
  1060. //删除存在的帧图
  1061. for (int singleIndex = m_SingleGDIObjects.Count - 1; singleIndex >= 0; singleIndex--)
  1062. {
  1063. if (m_SingleGDIObjects[singleIndex].SampleName == sampleName)
  1064. {
  1065. m_SingleGDIObjects.RemoveAt(singleIndex);
  1066. }
  1067. }
  1068. //设置手绘标识
  1069. m_IsDrawMeasureReady = false;
  1070. m_IsDrawMeasure = false;
  1071. m_IsDrawPolygonFinish = false;
  1072. this.Cursor = Cursors.Default;
  1073. return;
  1074. }
  1075. //添加多边形点信息
  1076. m_MouseDownPoint = new Point((int)(m_MouseDownPoint.X), (int)(m_MouseDownPoint.Y));
  1077. m_PolygonPoint.Add(m_MouseDownPoint);
  1078. CreateRectangle createPoint = new CreateRectangle(m_PolygonPoint, (int)CreateRectangleType.CircleByThreePoints, m_DrawMeasureType, sampleHoleName, sampleName, Color.Red);
  1079. if (m_DrawMeasureGDIObjects.Count > 0)
  1080. {
  1081. m_DrawMeasureGDIObjects[0] = createPoint;
  1082. }
  1083. else
  1084. {
  1085. m_DrawMeasureGDIObjects.Add(createPoint);
  1086. System.Threading.Thread.Sleep(1);
  1087. //MessageBox.Show("a");
  1088. }
  1089. return;
  1090. }
  1091. else
  1092. {
  1093. //在样品台内部缩放
  1094. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(new Rectangle(this.m_MouseDownPoint, new Size(2, 2)), m_RectangleGDIObjects[0].Region, m_DrawMeasureType))
  1095. {
  1096. m_IsDrawMeasure = true;
  1097. }
  1098. else
  1099. {
  1100. m_IsDrawMeasure = false;
  1101. return;
  1102. }
  1103. Color MeasureColor = Color.Red;
  1104. CreateRectangle createRectangle = new CreateRectangle(rectangle, m_DifferentPoint, (int)CreateRectangleType.MeasureArea, m_DrawMeasureType, sampleName, sampleName, MeasureColor);
  1105. //在鼠标点击时添加一个默认大小与位置的图形
  1106. createRectangle.RegionF = createRectangle.Region;
  1107. createRectangle.DrawRegionF = createRectangle.Region;
  1108. m_DrawMeasureGDIObjects.Add(createRectangle);
  1109. return;
  1110. }
  1111. }
  1112. else
  1113. {
  1114. if (e.Button == MouseButtons.Right)
  1115. {
  1116. if (m_MeasureAppForm.MeasureThreadRunFlag)
  1117. {
  1118. m_IsSelectType = (int)ContextMenuType.ThreadRunMenu;
  1119. //设置编辑右键菜单项
  1120. CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, false);
  1121. _Point = this.PointToClient(Cursor.Position);
  1122. this.CMStrip.Show(this, _Point);
  1123. return;
  1124. }
  1125. //获取鼠标右键点击位置
  1126. m_MouseDownLocation = e.Location;
  1127. //显示XY轴
  1128. OTSSamplespaceGraphicsPanelFun.ShowSemCoordvAL(e.Location, m_MeasureAppForm, m_RectangleGDIObjects, m_OTSSampleStageData, IsWidth);
  1129. string workSampleName = string.Empty;
  1130. foreach (ARectangleGDIObject item in m_SingleGDIObjects)
  1131. {
  1132. if (item.RegionF.Contains(e.Location))
  1133. {
  1134. //样品孔菜单
  1135. m_IsSelectType = (int)ContextMenuType.SingleMenu;
  1136. _Point = this.PointToClient(Cursor.Position);
  1137. bool IsTrue = false;
  1138. //设置编辑右键菜单项
  1139. foreach (ARectangleGDIObject imageItem in m_ImageGDIObjects)
  1140. {
  1141. if (imageItem.SampleName == item.SampleName)
  1142. {
  1143. IsTrue = true;
  1144. break;
  1145. }
  1146. }
  1147. //设置编辑右键菜单项
  1148. CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, IsTrue);
  1149. //将删除样品与测量 设置为不可编辑状态
  1150. this.CMStrip.Show(this, _Point);
  1151. return;
  1152. }
  1153. }
  1154. foreach (ARectangleGDIObject item in m_SampleGDIObjects)
  1155. {
  1156. if (item.IsWorkSample)
  1157. {
  1158. workSampleName = item.SampleName;
  1159. break;
  1160. }
  1161. }
  1162. for (int i = m_MeasureGDIObjects.Count - 1; i >= 0; i--)
  1163. {
  1164. foreach (var SampleItem in m_SampleGDIObjects)
  1165. {
  1166. if (m_MeasureGDIObjects[i].SampleName == SampleItem.SampleName)
  1167. {
  1168. bool isSelMeasure = false;
  1169. if (m_MeasureGDIObjects[i].Shape == (int)CreateRectangleType.Polygon)
  1170. {
  1171. //判断当前位置是否在不规则形状里面
  1172. if (OTSSamplespaceGraphicsPanelFun.PositionPnpoly(OTSSamplespaceGraphicsPanelFun.PointFConvertPoint(m_MeasureGDIObjects[i].PolygonPointRegionF), e.Location) && !m_MeasureGDIObjects[i].SelColor.Name.Equals("Transparent"))
  1173. {
  1174. isSelMeasure = true;
  1175. }
  1176. }
  1177. else
  1178. {
  1179. if (m_MeasureGDIObjects[i].Region.Contains(e.Location) && !m_MeasureGDIObjects[i].SelColor.Name.Equals("Transparent"))
  1180. {
  1181. isSelMeasure = true;
  1182. Rectangle rect = new Rectangle(e.Location, new Size(WH, WH));
  1183. int CheckShape = (int)CreateRectangleType.Circle;
  1184. if (m_MeasureGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  1185. {
  1186. CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;
  1187. }
  1188. if (!OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rect, m_MeasureGDIObjects[i].Region, CheckShape))
  1189. {
  1190. break;
  1191. }
  1192. }
  1193. }
  1194. if (isSelMeasure)
  1195. {
  1196. //如果选择的样品不是当前工作样品 则删除原有帧图信息
  1197. if (m_MeasureGDIObjects[i].SampleName != workSampleName)
  1198. {
  1199. ClearImageAndSingleGDIObjects();
  1200. }
  1201. //删除BSE照片
  1202. bool IsTrue = false;
  1203. //设置编辑右键菜单项
  1204. foreach (ARectangleGDIObject imageItem in m_ImageGDIObjects)
  1205. {
  1206. if (imageItem.SampleName == m_MeasureGDIObjects[i].SampleName)
  1207. {
  1208. IsTrue = true;
  1209. break;
  1210. }
  1211. }
  1212. //测量区域菜单
  1213. m_IsSelectType = (int)ContextMenuType.MeasureMenu;
  1214. //设置编辑右键菜单项
  1215. CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, IsTrue);
  1216. _Point = this.PointToClient(Cursor.Position);
  1217. this.CMStrip.Show(this, _Point);
  1218. m_MeasureSelectName = m_MeasureGDIObjects[i].SampleName;
  1219. m_SampleHoleSelectName = m_MeasureGDIObjects[i].Name;
  1220. if (m_SampleSelectName != m_MeasureGDIObjects[i].SampleName)
  1221. {
  1222. m_SampleSelectName = m_MeasureGDIObjects[i].SampleName;
  1223. m_MeasureGDIObjects[i].IsSelect = true;
  1224. m_MeasureGDIObjects[i].IsWorkSample = true;
  1225. //设置工作样品
  1226. m_MeasureAppForm.Rev_SoluWindowReqSwitchWSample_Event(m_SampleSelectName);
  1227. Invalidate();
  1228. }
  1229. return;
  1230. }
  1231. }
  1232. }
  1233. }
  1234. foreach (ARectangleGDIObject item in m_ImageGDIObjects)
  1235. {
  1236. if (item.Region.Contains(e.Location))
  1237. {
  1238. //样品孔菜单
  1239. m_IsSelectType = (int)ContextMenuType.SampleHoleBSEImage;
  1240. _Point = this.PointToClient(Cursor.Position);
  1241. //设置编辑右键菜单项
  1242. CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, false);
  1243. this.CMStrip.Show(this, _Point);
  1244. return;
  1245. }
  1246. }
  1247. //只点击样品上(测量区域被移动到其他地方)
  1248. for (int i = m_SampleGDIObjects.Count - 1; i >= 0; i--)
  1249. {
  1250. if (m_SampleGDIObjects[i].Region.Contains(e.Location))
  1251. {
  1252. //如果选择的样品不是当前工作样品 则删除原有帧图信息
  1253. if (m_SampleGDIObjects[i].SampleName != workSampleName)
  1254. {
  1255. ClearImageAndSingleGDIObjects();
  1256. }
  1257. Rectangle rect = new Rectangle(e.Location, new Size(WH, WH));
  1258. //判断样品形状
  1259. int CheckShape = (int)CreateRectangleType.Circle;
  1260. if (m_MeasureGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  1261. {
  1262. CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;
  1263. }
  1264. if (!OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rect, m_SampleGDIObjects[i].Region, CheckShape))
  1265. {
  1266. break;
  1267. }
  1268. //样品菜单
  1269. m_IsSelectType = (int)ContextMenuType.SampleMenu;
  1270. //将删除样品与测量 设置为不可编辑状态
  1271. _Point = this.PointToClient(Cursor.Position);
  1272. bool flag = false;
  1273. foreach (var MeasureItem in m_MeasureGDIObjects)
  1274. {
  1275. if (m_SampleGDIObjects[i].SampleName == MeasureItem.SampleName)
  1276. {
  1277. if (MeasureItem.Region.Contains(e.Location))
  1278. {
  1279. //测量区域菜单
  1280. m_IsSelectType = (int)ContextMenuType.MeasureMenu;
  1281. //flag = !MeasureItem.IsSingle;
  1282. break;
  1283. }
  1284. }
  1285. }
  1286. //设置编辑右键菜单项
  1287. CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, flag);
  1288. this.CMStrip.Show(this, _Point);
  1289. if (m_SampleSelectName != m_SampleGDIObjects[i].SampleName)
  1290. {
  1291. m_SampleSelectName = m_SampleGDIObjects[i].SampleName;
  1292. m_SampleHoleSelectName = m_SampleGDIObjects[i].Name;
  1293. m_SampleGDIObjects[i].IsSelect = true;
  1294. m_SampleGDIObjects[i].IsWorkSample = true;
  1295. //设置工作样品 向主窗体发送请求
  1296. m_MeasureAppForm.Rev_SoluWindowReqSwitchWSample_Event(m_SampleSelectName);
  1297. Invalidate();
  1298. }
  1299. return;
  1300. }
  1301. }
  1302. //点击样品孔
  1303. foreach (ARectangleGDIObject item in m_SampleHoleGDIObjects)
  1304. {
  1305. if (item.Region.Contains(e.Location))
  1306. {
  1307. Rectangle rect = new Rectangle(e.Location, new Size(WH, WH));
  1308. int CheckShape = (int)CreateRectangleType.Circle;
  1309. if (item.Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  1310. {
  1311. CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;
  1312. }
  1313. //样品孔菜单
  1314. m_IsSelectType = (int)ContextMenuType.SampleHoleMenu;
  1315. _Point = this.PointToClient(Cursor.Position);
  1316. //设置编辑右键菜单项
  1317. CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, false);
  1318. //将删除样品与测量 设置为不可编辑状态
  1319. this.CMStrip.Show(this, _Point);
  1320. m_SampleHoleSelectName = item.Name;
  1321. item.IsSelect = true;
  1322. return;
  1323. }
  1324. }
  1325. foreach (ARectangleGDIObject item in m_RectangleGDIObjects)
  1326. {
  1327. if (item.Region.Contains(e.Location))
  1328. {
  1329. //样品台菜单
  1330. m_IsSelectType = (int)ContextMenuType.SampleStateMenu;
  1331. //设置编辑右键菜单项
  1332. CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, false);
  1333. _Point = this.PointToClient(Cursor.Position);
  1334. this.CMStrip.Show(this, _Point);
  1335. break;
  1336. }
  1337. }
  1338. return;
  1339. }
  1340. //左键点击样品台上
  1341. else
  1342. {
  1343. //如果正在进行测量线程,则退出鼠标点击操作
  1344. if (m_MeasureAppForm.MeasureThreadRunFlag)
  1345. {
  1346. return;
  1347. }
  1348. foreach (ARectangleGDIObject item in m_RectangleGDIObjects)
  1349. {
  1350. if (item.Region.Contains(e.Location))
  1351. {
  1352. m_RectangIsDragging = true;
  1353. m_IsSelectSampleStage = true;
  1354. }
  1355. item.IsDragging = true;
  1356. item.DraggingPoint = e.Location;
  1357. }
  1358. //测量区域
  1359. foreach (ARectangleGDIObject item in m_MeasureGDIObjects)
  1360. {
  1361. if (Control.ModifierKeys == Keys.Control)
  1362. {
  1363. //获取选择工作样品的测量状态
  1364. selWSampleMeasureStatus = m_MeasureAppForm.m_ProjParam.GetWorkSampleMeasureStatus();
  1365. if (selWSampleMeasureStatus)
  1366. {
  1367. return;
  1368. }
  1369. //如果选择的测量区域 颜色不是透明 可以选择
  1370. if (!item.SelColor.Name.Equals("Transparent"))
  1371. {
  1372. if (item.CreateType == (int)CreateRectangleType.Polygon)
  1373. {
  1374. if (item.GPath != null)
  1375. {
  1376. //在多边形点附近切换光标
  1377. foreach (PointF itemPoint in item.PolygonPointRegionF)
  1378. {
  1379. if (Math.Abs(itemPoint.X - e.X) <= m_OffsetPX && Math.Abs(itemPoint.Y - e.Y) <= m_OffsetPX)
  1380. {
  1381. if (Control.ModifierKeys == Keys.Control)
  1382. {
  1383. if (m_DrawPolygonFinishGDIObjects != null)
  1384. {
  1385. if (m_DrawPolygonFinishGDIObjects.Count > 0)
  1386. {
  1387. m_DrawPolygonFinishGDIObjects.Clear();
  1388. }
  1389. }
  1390. m_IsSelPolygonPoint = true;
  1391. m_IsCtrl = true;
  1392. m_IsSelectSampleStage = false;
  1393. //选择前测量区域的尺寸
  1394. m_SelMeasureRect = item.Region;
  1395. m_MeasureRectangle = item.Region;
  1396. item.SelColor = Color.Red;
  1397. item.IsDragging = true;
  1398. item.DraggingPoint = e.Location;
  1399. item.IsSelect = true;
  1400. item.IsWorkSample = true;
  1401. //记录选择的多边形点信息
  1402. m_SelPolygonPoint = itemPoint;
  1403. int rectSize = m_MinMeasureWidthValue;
  1404. Point PolygonFinishPoint = new Point((int)(itemPoint.X - m_MinMeasureWidthValue / 2), (int)(itemPoint.Y - m_MinMeasureWidthValue / 2));
  1405. Rectangle pRect = new Rectangle(PolygonFinishPoint, new Size(rectSize, rectSize));
  1406. CreateRectangle createPolygonFinish = new CreateRectangle(pRect, (int)CreateRectangleType.DrawPolygonFinish, "", "", Color.Green);
  1407. if (m_DrawPolygonFinishGDIObjects != null)
  1408. {
  1409. m_DrawPolygonFinishGDIObjects.Add(createPolygonFinish);
  1410. }
  1411. break;
  1412. }
  1413. }
  1414. }
  1415. //如果鼠标已选择多边形的点,跳出循环
  1416. if (item.IsSelect == true)
  1417. {
  1418. break;
  1419. }
  1420. if (item.GPath.IsVisible(e.Location))
  1421. {
  1422. m_IsCtrl = true;
  1423. m_IsSelectSampleStage = false;
  1424. //选择前测量区域的尺寸
  1425. m_SelMeasureRect = item.Region;
  1426. m_MeasureRectangle = item.Region;
  1427. item.SelColor = Color.Red;
  1428. item.IsDragging = true;
  1429. item.DraggingPoint = e.Location;
  1430. item.IsWorkSample = true;
  1431. item.IsSelect = false;
  1432. break;
  1433. }
  1434. }
  1435. }
  1436. else
  1437. {
  1438. if (item.GPath != null)
  1439. {
  1440. if (item.GPath.IsOutlineVisible((float)e.X, (float)e.Y, new Pen(Color.Gray, m_PenWidth)))
  1441. {
  1442. m_IsCtrl = true;
  1443. m_IsSelectSampleStage = false;
  1444. //选择前测量区域的尺寸
  1445. m_SelMeasureRect = item.Region;
  1446. m_MeasureRectangle = item.Region;
  1447. item.SelColor = Color.Red;
  1448. item.IsDragging = true;
  1449. item.DraggingPoint = e.Location;
  1450. item.IsSelect = true;
  1451. item.IsWorkSample = true;
  1452. break;
  1453. }
  1454. }
  1455. if (item.Region.Contains(e.Location))
  1456. {
  1457. m_IsCtrl = true;
  1458. m_IsSelectSampleStage = false;
  1459. //选择前测量区域的尺寸
  1460. m_SelMeasureRect = item.Region;
  1461. m_MeasureRectangle = item.Region;
  1462. item.SelColor = Color.Red;
  1463. item.IsDragging = true;
  1464. item.DraggingPoint = e.Location;
  1465. item.IsWorkSample = true;
  1466. item.IsSelect = false;
  1467. break;
  1468. }
  1469. }
  1470. }
  1471. }
  1472. }
  1473. //当鼠标点击样品上(测量区域被拖动到其他地方)
  1474. for (int i = m_SampleGDIObjects.Count - 1; i >= 0; i--)
  1475. {
  1476. if ((Control.ModifierKeys == Keys.Alt))
  1477. {
  1478. if (m_SampleGDIObjects[i].Region.Contains(e.Location))
  1479. {
  1480. m_IsMoveSample = true;
  1481. m_IsSelectSampleStage = false;
  1482. m_IsAlt = true;
  1483. }
  1484. }
  1485. if (!(Control.ModifierKeys == Keys.Control))
  1486. {
  1487. if (m_SampleGDIObjects[i].Region.Contains(e.Location))
  1488. {
  1489. foreach (var measureItem in m_MeasureGDIObjects)
  1490. {
  1491. if (measureItem.SampleName == m_SampleGDIObjects[i].SampleName)
  1492. {
  1493. m_MeasureRectangle = measureItem.Region;
  1494. measureItem.SelColor = Color.Red;
  1495. }
  1496. else
  1497. {
  1498. measureItem.SelColor = Color.Transparent;
  1499. }
  1500. }
  1501. for (int x = 0; x < m_SampleGDIObjects.Count; x++)
  1502. {
  1503. //获取颜色
  1504. string SampleColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
  1505. m_SampleGDIObjects[x].SelColor = ColorTranslator.FromHtml(SampleColorStr);
  1506. m_SampleGDIObjects[x].IsWorkSample = false;
  1507. m_SampleGDIObjects[x].IsSelect = false;
  1508. }
  1509. //设置为工作样品
  1510. m_SampleGDIObjects[i].IsWorkSample = true;
  1511. m_SampleGDIObjects[i].IsSelect = true;
  1512. //获取颜色
  1513. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  1514. m_SampleGDIObjects[i].SelColor = ColorTranslator.FromHtml(ColorStr);
  1515. selectSampleGDIObjects = m_SampleGDIObjects[i];
  1516. if (m_SampleSelectName != m_SampleGDIObjects[i].SampleName)
  1517. {
  1518. //获取工作样品名称
  1519. m_SampleSelectName = m_SampleGDIObjects[i].SampleName;
  1520. //设置工作样品 向主窗体发送请求
  1521. m_MeasureAppForm.Rev_SoluWindowReqSwitchWSample_Event(m_SampleSelectName);
  1522. }
  1523. break;
  1524. }
  1525. }
  1526. }
  1527. //样品
  1528. MouseDownFucntion(m_SampleGDIObjects, e);
  1529. //样品孔
  1530. MouseDownFucntion(m_SampleHoleGDIObjects, e);
  1531. //标样
  1532. MouseDownFucntion(m_SpecimenGDIObjects, e);
  1533. //测量
  1534. MouseDownFucntion(m_MeasureGDIObjects, e);
  1535. //文字
  1536. MouseDownFucntion(m_ContentGDIObjects, e);
  1537. //帧图
  1538. MouseDownFucntion(m_SingleGDIObjects, e);
  1539. //所有获取的帧图
  1540. MouseDownFucntion(m_ALLSingleGDIObjects, e);
  1541. //样品台中BSE图片
  1542. MouseDownFucntion(m_ImageGDIObjects, e);
  1543. //SEM中心位置
  1544. MouseDownFucntion(m_SEMCenterGDIObjects, e);
  1545. for (int i = m_SampleGDIObjects.Count - 1; i >= 0; i--)
  1546. {
  1547. if (m_SampleGDIObjects[i].Region.Contains(e.Location) && m_SampleGDIObjects[i].IsWorkSample)
  1548. {
  1549. //获取当前样品与测量区域的位置
  1550. foreach (ARectangleGDIObject item in m_MeasureGDIObjects)
  1551. {
  1552. if (m_SampleGDIObjects[i].SampleName == item.SampleName && m_SampleGDIObjects[i].IsWorkSample)
  1553. {
  1554. m_MeasureToSamplePoint.X = m_SampleGDIObjects[i].Region.X - item.Region.X;
  1555. m_MeasureToSamplePoint.Y = m_SampleGDIObjects[i].Region.Y - item.Region.Y;
  1556. break;
  1557. }
  1558. }
  1559. }
  1560. }
  1561. }
  1562. }
  1563. //重绘控件
  1564. Invalidate();
  1565. }
  1566. protected override void OnMouseMove(MouseEventArgs e)
  1567. {
  1568. //'记录光标拖动的当前点
  1569. m_P1.X = e.X;
  1570. m_P1.Y = e.Y;
  1571. bool InMeasure = false;
  1572. //如果正在进行测量线程,则退出鼠标点击操作
  1573. if (m_MeasureAppForm.MeasureThreadRunFlag)
  1574. {
  1575. return;
  1576. }
  1577. //获取选择工作样品的测量状态
  1578. if (selWSampleMeasureStatus)
  1579. {
  1580. return;
  1581. }
  1582. //手动绘制 记录鼠标移动位置
  1583. if (m_IsDrawMeasure)
  1584. {
  1585. this.m_MouseMovePoint = new Point(e.X, e.Y);
  1586. //绘制多边形
  1587. if (m_DrawMeasureType == (int)CreateRectangleType.Polygon)
  1588. {
  1589. PointF startPoint = new PointF();
  1590. PointF endPoint = new PointF();
  1591. //显示直线开始点与鼠标当前位置的直线
  1592. if (m_PolygonPoint.Count > 0)
  1593. {
  1594. startPoint = m_PolygonPoint[0];
  1595. endPoint = m_PolygonPoint[m_PolygonPoint.Count - 1];
  1596. }
  1597. //显示绘制多边形完成标识
  1598. if (m_PolygonPoint.Count > m_PointCount)
  1599. {
  1600. if (Math.Abs(m_MouseMovePoint.X - startPoint.X) <= m_OffsetPX && Math.Abs(m_MouseMovePoint.Y - startPoint.Y) <= m_OffsetPX)
  1601. {
  1602. //显示绘制多边形完成标识
  1603. m_IsDrawPolygonFinish = true;
  1604. }
  1605. else
  1606. {
  1607. m_IsDrawPolygonFinish = false;
  1608. }
  1609. }
  1610. }
  1611. //圆形三点法
  1612. else if (m_DrawMeasureType == (int)CreateRectangleType.CircleByThreePoints)
  1613. {
  1614. PointF startPoint = new PointF();
  1615. PointF endPoint = new PointF();
  1616. //显示直线开始点与鼠标当前位置的直线
  1617. if (m_PolygonPoint.Count > 0)
  1618. {
  1619. startPoint = m_PolygonPoint[0];
  1620. endPoint = m_PolygonPoint[m_PolygonPoint.Count - 1];
  1621. }
  1622. }
  1623. else
  1624. {
  1625. if (m_DrawMeasureGDIObjects == null || m_RectangleGDIObjects == null)
  1626. {
  1627. return;
  1628. }
  1629. Rectangle rectangle = new Rectangle();
  1630. foreach (var item in m_DrawMeasureGDIObjects)
  1631. {
  1632. rectangle = item.Region;
  1633. //移动鼠标绘制测量区域
  1634. 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));
  1635. if (tmp == 0)
  1636. {
  1637. tmp = m_DValue;
  1638. }
  1639. //移动鼠标绘制测量区域
  1640. //以中心绘制测量区域方法
  1641. //rectangle = new Rectangle(m_MouseDownPoint.X - tmp, m_MouseDownPoint.Y - tmp, 2 * tmp, 2 * tmp);
  1642. OTSSamplespaceGraphicsPanelFun.EnumMousePointPosition enumMouse = OTSSamplespaceGraphicsPanelFun.MousePointPosition(m_MouseDownPoint, m_MouseMovePoint);
  1643. Point LTPoint = new Point();
  1644. Size RBSize = new Size();
  1645. switch (enumMouse)
  1646. {
  1647. case OTSSamplespaceGraphicsPanelFun.EnumMousePointPosition.MouseSizeTopLeft:
  1648. if (m_DrawMeasureType == (int)CreateRectangleType.Circle)
  1649. {
  1650. LTPoint.X = m_MouseDownPoint.X - tmp;
  1651. LTPoint.Y = m_MouseDownPoint.Y - tmp;
  1652. RBSize.Width = tmp;
  1653. RBSize.Height = tmp;
  1654. rectangle = new Rectangle(LTPoint, RBSize);
  1655. }
  1656. else
  1657. {
  1658. LTPoint.X = m_MouseMovePoint.X;
  1659. LTPoint.Y = m_MouseMovePoint.Y;
  1660. RBSize.Width = m_MouseDownPoint.X - m_MouseMovePoint.X;
  1661. RBSize.Height = m_MouseDownPoint.Y - m_MouseMovePoint.Y;
  1662. rectangle = new Rectangle(LTPoint, RBSize);
  1663. }
  1664. break;
  1665. case OTSSamplespaceGraphicsPanelFun.EnumMousePointPosition.MouseSizeTopRight:
  1666. if (m_DrawMeasureType == (int)CreateRectangleType.Circle)
  1667. {
  1668. LTPoint.X = m_MouseDownPoint.X;
  1669. LTPoint.Y = m_MouseDownPoint.Y - tmp;
  1670. RBSize.Width = tmp;
  1671. RBSize.Height = tmp;
  1672. rectangle = new Rectangle(LTPoint, RBSize);
  1673. }
  1674. else
  1675. {
  1676. LTPoint.X = m_MouseDownPoint.X;
  1677. LTPoint.Y = m_MouseDownPoint.Y - (m_MouseDownPoint.Y - m_MouseMovePoint.Y);
  1678. RBSize.Width = m_MouseMovePoint.X - m_MouseDownPoint.X;
  1679. RBSize.Height = m_MouseDownPoint.Y - m_MouseMovePoint.Y;
  1680. rectangle = new Rectangle(LTPoint, RBSize);
  1681. }
  1682. break;
  1683. case OTSSamplespaceGraphicsPanelFun.EnumMousePointPosition.MouseSizeBottomLeft:
  1684. if (m_DrawMeasureType == (int)CreateRectangleType.Circle)
  1685. {
  1686. LTPoint.X = m_MouseDownPoint.X - tmp;
  1687. LTPoint.Y = m_MouseDownPoint.Y;
  1688. RBSize.Width = tmp;
  1689. RBSize.Height = tmp;
  1690. rectangle = new Rectangle(LTPoint, RBSize);
  1691. }
  1692. else
  1693. {
  1694. LTPoint.X = m_MouseDownPoint.X - (m_MouseDownPoint.X - m_MouseMovePoint.X);
  1695. LTPoint.Y = m_MouseDownPoint.Y;
  1696. RBSize.Width = m_MouseDownPoint.X - m_MouseMovePoint.X;
  1697. RBSize.Height = m_MouseMovePoint.Y - m_MouseDownPoint.Y;
  1698. rectangle = new Rectangle(LTPoint, RBSize);
  1699. }
  1700. break;
  1701. case OTSSamplespaceGraphicsPanelFun.EnumMousePointPosition.MouseSizeBottomRight:
  1702. if (m_DrawMeasureType == (int)CreateRectangleType.Circle)
  1703. {
  1704. LTPoint.X = m_MouseDownPoint.X;
  1705. LTPoint.Y = m_MouseDownPoint.Y;
  1706. RBSize.Width = tmp;
  1707. RBSize.Height = tmp;
  1708. rectangle = new Rectangle(LTPoint, RBSize);
  1709. }
  1710. else
  1711. {
  1712. LTPoint.X = m_MouseDownPoint.X;
  1713. LTPoint.Y = m_MouseDownPoint.Y;
  1714. RBSize.Width = m_MouseMovePoint.X - m_MouseDownPoint.X;
  1715. RBSize.Height = m_MouseMovePoint.Y - m_MouseDownPoint.Y;
  1716. rectangle = new Rectangle(LTPoint, RBSize);
  1717. }
  1718. break;
  1719. }
  1720. //在样品台内部缩放
  1721. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectangle, m_RectangleGDIObjects[0].Region, m_DrawMeasureType))
  1722. {
  1723. //移动鼠标绘制测量区域
  1724. //以中心绘制测量区域方法
  1725. //item.Region = new Rectangle(m_MouseDownPoint.X - tmp, m_MouseDownPoint.Y - tmp, 2 * tmp, 2 * tmp);
  1726. item.Region = new Rectangle(LTPoint, RBSize);
  1727. item.RegionF = new RectangleF(new PointF((item.Region.X) / m_GlobalZoomNum, (item.Region.Y) / m_GlobalZoomNum), new SizeF(item.Region.Width / m_GlobalZoomNum, item.Region.Height / m_GlobalZoomNum));
  1728. item.DrawRegionF = item.RegionF;
  1729. //生成图形路径
  1730. GraphicsPath MeasurePath = new GraphicsPath();
  1731. if (item.Shape == (int)CreateRectangleType.Rectangle)
  1732. {
  1733. MeasurePath.AddRectangle(item.Region);
  1734. }
  1735. else
  1736. {
  1737. MeasurePath.AddEllipse(item.Region);
  1738. }
  1739. item.GPath = MeasurePath;
  1740. break;
  1741. }
  1742. }
  1743. }
  1744. }
  1745. if (m_RectangIsDragging)
  1746. {
  1747. if (m_RectangleGDIObjects == null) { return; }
  1748. if (!m_IsSelectSampleStage)
  1749. {
  1750. foreach (ARectangleGDIObject item in m_SampleGDIObjects)
  1751. {
  1752. if (!m_IsMeasure)
  1753. {
  1754. if (item.Region.Contains(e.Location))
  1755. {
  1756. if (item.IsDragging)
  1757. {
  1758. if (item.IsWorkSample)
  1759. {
  1760. if (item.IsSelect)
  1761. {
  1762. //判断移动的样品 是否在样品台尺寸范围内
  1763. foreach (ARectangleGDIObject measureItem in m_MeasureGDIObjects)
  1764. {
  1765. if (measureItem.SampleName == item.SampleName)
  1766. {
  1767. if (measureItem.CreateType == (int)CreateRectangleType.Polygon)
  1768. {
  1769. if (this.Cursor != Cursors.Default)
  1770. {
  1771. return;
  1772. }
  1773. //判断移动的样品 是否在样品台尺寸范围内
  1774. Rectangle rectTemp = item.Region;
  1775. rectTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;
  1776. rectTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;
  1777. int CheckShape = (int)CreateRectangleType.Circle;
  1778. if (m_RectangleGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  1779. {
  1780. CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;
  1781. }
  1782. //判断样品是否超越样品台
  1783. if (!OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  1784. {
  1785. return;
  1786. }
  1787. else
  1788. {
  1789. //生成多边形最小面积外接矩形
  1790. Rectangle rectMeasureTemp = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(measureItem.PolygonPointRegionF);
  1791. //判断多边形是否超越样品台
  1792. rectMeasureTemp.X = rectMeasureTemp.Left + e.X - measureItem.DraggingPoint.X;
  1793. rectMeasureTemp.Y = rectMeasureTemp.Top + e.Y - measureItem.DraggingPoint.Y;
  1794. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectMeasureTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  1795. {
  1796. Rectangle rectSampleTemp = item.Region;
  1797. rectSampleTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;
  1798. rectSampleTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;
  1799. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectSampleTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  1800. {
  1801. MouseMovePolygonMeasureFucntion(measureItem, e);
  1802. OTSSamplespaceGraphicsPanelFun.GetMouseMoveLocation(item, e);
  1803. //计算两个点之间的距离 移动样品台后与绘制样品台时的位置
  1804. m_DifferentPoint = OTSSamplespaceGraphicsPanelFun.StartToEndPointDist(m_RectangleGDIObjects[0], m_RegionStartCenterPoint);
  1805. isChange = true;
  1806. }
  1807. }
  1808. }
  1809. }
  1810. else
  1811. {
  1812. Rectangle rectMeasureTemp = measureItem.Region;
  1813. rectMeasureTemp.X = measureItem.Region.Left + e.X - measureItem.DraggingPoint.X;
  1814. rectMeasureTemp.Y = measureItem.Region.Top + e.Y - measureItem.DraggingPoint.Y;
  1815. //判断移动的样品 是否在样品台尺寸范围内
  1816. Rectangle rectTemp = item.Region;
  1817. rectTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;
  1818. rectTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;
  1819. int CheckShape = (int)CreateRectangleType.Circle;
  1820. if (m_RectangleGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  1821. {
  1822. CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;
  1823. }
  1824. //判断样品是否超越样品台
  1825. if (!OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  1826. {
  1827. return;
  1828. }
  1829. //判断测量区域是否超越样品台
  1830. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectMeasureTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  1831. {
  1832. Rectangle rectSampleTemp = item.Region;
  1833. rectSampleTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;
  1834. rectSampleTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;
  1835. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectSampleTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  1836. {
  1837. MouseMoveMeasureFucntion(measureItem, e);
  1838. OTSSamplespaceGraphicsPanelFun.GetMouseMoveLocation(item, e);
  1839. //计算两个点之间的距离 移动样品台后与绘制样品台时的位置
  1840. m_DifferentPoint = OTSSamplespaceGraphicsPanelFun.StartToEndPointDist(m_RectangleGDIObjects[0], m_RegionStartCenterPoint);
  1841. isChange = true;
  1842. }
  1843. }
  1844. else
  1845. {
  1846. return;
  1847. }
  1848. }
  1849. }
  1850. }
  1851. }
  1852. foreach (ARectangleGDIObject sampleHoleItem in m_SampleHoleGDIObjects)
  1853. {
  1854. //获取样品孔中心点
  1855. Point sampleHoleCenterPoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(sampleHoleItem);
  1856. if (item.Region.Contains(sampleHoleCenterPoint))
  1857. {
  1858. if (item.Name != sampleHoleItem.Name)
  1859. {
  1860. //获取颜色
  1861. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
  1862. item.SelColor = ColorTranslator.FromHtml(ColorStr);
  1863. break;
  1864. }
  1865. }
  1866. else
  1867. {
  1868. //获取颜色
  1869. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  1870. item.SelColor = ColorTranslator.FromHtml(ColorStr);
  1871. }
  1872. }
  1873. }
  1874. Invalidate();
  1875. }
  1876. }
  1877. }
  1878. }
  1879. foreach (ARectangleGDIObject item in m_MeasureGDIObjects)
  1880. {
  1881. //检测鼠标光标点是否在路径上
  1882. if (item.IsDragging)
  1883. {
  1884. if (item.IsWorkSample)
  1885. {
  1886. if (item.IsSelect)
  1887. {
  1888. if (item.DraggingPoint != Point.Empty)
  1889. {
  1890. //获取中心点
  1891. Point xy1 = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(item.Region);
  1892. //获取鼠标坐标
  1893. Point xy2 = e.Location;
  1894. Rectangle rectTemp = new Rectangle();
  1895. int CheckShape = (int)CreateRectangleType.Circle;
  1896. if (item.CreateType == (int)CreateRectangleType.Polygon)
  1897. {
  1898. if (m_IsSelPolygonPoint)
  1899. {
  1900. //获取选中点进行移动,代码
  1901. #region MyRegion
  1902. if (Control.ModifierKeys == Keys.Control)
  1903. {
  1904. //int pointCount = m_DrawPolygonFinishGDIObjects.Count;
  1905. //在多边形点附近切换光标
  1906. for (int i = 0; i < item.PolygonPointRegionF.Count; i++)
  1907. {
  1908. if (item.PolygonPointRegionF[i].X == m_SelPolygonPoint.X && item.PolygonPointRegionF[i].Y == m_SelPolygonPoint.Y)
  1909. {
  1910. //移动点的位置
  1911. Rectangle selPolygonPointRect = new Rectangle(0, 0, 2, 2);
  1912. selPolygonPointRect.X = (int)m_SelPolygonPoint.X + e.X - item.DraggingPoint.X;
  1913. selPolygonPointRect.Y = (int)m_SelPolygonPoint.Y + e.Y - item.DraggingPoint.Y;
  1914. //判断样品是否超越样品台
  1915. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(selPolygonPointRect, m_RectangleGDIObjects[0].Region, CheckShape))
  1916. {
  1917. if (i == 0 || i == item.PolygonPointRegionF.Count - 1)
  1918. {
  1919. //移动点
  1920. m_SelPolygonPoint = new Point(e.X, e.Y);
  1921. item.PolygonPointRegion[item.PolygonPointRegionF.Count - 1] = new Point((int)m_SelPolygonPoint.X, (int)m_SelPolygonPoint.Y);
  1922. item.PolygonPointRegionF[item.PolygonPointRegionF.Count - 1] = m_SelPolygonPoint;
  1923. item.DrawPolygonPointRegionF[item.PolygonPointRegionF.Count - 1] = new PointF(m_SelPolygonPoint.X / m_GlobalZoomNum, m_SelPolygonPoint.Y / m_GlobalZoomNum);
  1924. item.PolygonPointRegionF[0] = m_SelPolygonPoint;
  1925. item.PolygonPointRegion[0] = new Point((int)m_SelPolygonPoint.X, (int)m_SelPolygonPoint.Y);
  1926. item.PolygonPointRegionF[0] = m_SelPolygonPoint;
  1927. item.DrawPolygonPointRegionF[0] = new PointF(m_SelPolygonPoint.X / m_GlobalZoomNum, m_SelPolygonPoint.Y / m_GlobalZoomNum);
  1928. }
  1929. else
  1930. {
  1931. m_SelPolygonPoint = new Point(e.X, e.Y);
  1932. item.PolygonPointRegion[i] = new Point((int)m_SelPolygonPoint.X, (int)m_SelPolygonPoint.Y);
  1933. item.PolygonPointRegionF[i] = m_SelPolygonPoint;
  1934. item.DrawPolygonPointRegionF[i] = new PointF(m_SelPolygonPoint.X / m_GlobalZoomNum, m_SelPolygonPoint.Y / m_GlobalZoomNum);
  1935. }
  1936. m_DrawPolygonFinishGDIObjects[0].Region = new Rectangle(new Point((int)m_SelPolygonPoint.X - m_OffsetPX, (int)m_SelPolygonPoint.Y - m_OffsetPX), new Size(m_MinMeasureWidthValue, m_MinMeasureWidthValue));
  1937. m_DrawPolygonFinishGDIObjects[0].RegionF = new Rectangle(new Point((int)m_SelPolygonPoint.X - m_OffsetPX, (int)m_SelPolygonPoint.Y - m_OffsetPX), new Size(m_MinMeasureWidthValue, m_MinMeasureWidthValue));
  1938. m_DrawPolygonFinishGDIObjects[0].DrawRegionF = new Rectangle(new Point((int)m_SelPolygonPoint.X - m_OffsetPX, (int)m_SelPolygonPoint.Y - m_OffsetPX), new Size(m_MinMeasureWidthValue, m_MinMeasureWidthValue));
  1939. //生成多边形最小面积外接矩形
  1940. Rectangle rectPolygonMeasure = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(item.PolygonPointRegionF);
  1941. item.Region = rectPolygonMeasure;
  1942. item.RegionF = rectPolygonMeasure;
  1943. item.DrawRegionF = rectPolygonMeasure;
  1944. item.DraggingPoint = e.Location;
  1945. break;
  1946. }
  1947. }
  1948. }
  1949. }
  1950. #endregion
  1951. }
  1952. }
  1953. else
  1954. {
  1955. //计算偏离半径
  1956. int a = (xy1.X - xy2.X) * (xy1.X - xy2.X);
  1957. int b = (xy1.Y - xy2.Y) * (xy1.Y - xy2.Y);
  1958. int c = a + b;
  1959. int r = Convert.ToInt32(System.Math.Sqrt(c));
  1960. int width = r * 2;
  1961. rectTemp = new Rectangle(xy1.X - r, xy1.Y - r, width, width);
  1962. //在样品台内部缩放
  1963. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  1964. {
  1965. #region 需抽出作为公共方法
  1966. int xMove = rectTemp.X - item.Region.X;
  1967. int yMove = rectTemp.Y - item.Region.Y;
  1968. int Width = rectTemp.Width - item.Region.Width;
  1969. int Height = rectTemp.Height - item.Region.Height;
  1970. //如果大于最小测量高度 设置图形大小
  1971. if (rectTemp.Width / m_GlobalZoomNum > m_MinMeasureWidthValue)
  1972. {
  1973. item.Region = rectTemp;
  1974. float WidthNew = (float)((item.RegionF.Width + Width / m_GlobalZoomNum));
  1975. float HeightNew = (float)((item.RegionF.Height + Height / m_GlobalZoomNum));
  1976. //设置原测量区域图形大小
  1977. float xMoveNew = (float)((item.RegionF.X + xMove / m_GlobalZoomNum));
  1978. float yMoveNew = (float)((item.RegionF.Y + yMove / m_GlobalZoomNum));
  1979. item.RegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));
  1980. item.DrawRegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));
  1981. item.DraggingPoint = e.Location;
  1982. isChange = true;
  1983. }
  1984. #endregion
  1985. }
  1986. else
  1987. {
  1988. return;
  1989. }
  1990. Invalidate();
  1991. return;
  1992. }
  1993. }
  1994. }
  1995. else
  1996. {
  1997. //鼠标配合Ctrol键 移动单个测量区域
  1998. if (item.Shape == (int)CreateRectangleType.Polygon)
  1999. {
  2000. //判断是否已存在多边形的点,不能移动多边形
  2001. if (!m_IsSelPolygonPoint)
  2002. {
  2003. if (this.Cursor == Cursors.SizeAll)
  2004. {
  2005. if (item.GPath.IsVisible(e.Location))
  2006. {
  2007. isChange = true;
  2008. MouseMovePolygonMeasureFucntion(item, e);
  2009. }
  2010. }
  2011. }
  2012. }
  2013. else
  2014. {
  2015. if (item.Region.Contains(e.Location))
  2016. {
  2017. isChange = true;
  2018. MouseMoveMeasureFucntion(item, e);
  2019. }
  2020. }
  2021. }
  2022. }
  2023. }
  2024. }
  2025. }
  2026. //移动样品台
  2027. if (m_IsSelectSampleStage)
  2028. {
  2029. if (m_IsCtrl)
  2030. {
  2031. return;
  2032. }
  2033. if (m_IsAlt)
  2034. {
  2035. return;
  2036. }
  2037. //样品台
  2038. MouseMoveFucntion(m_RectangleGDIObjects, e);
  2039. //样品孔
  2040. MouseMoveFucntion(m_SampleHoleGDIObjects, e);
  2041. //样品
  2042. MouseMoveFucntion(m_SampleGDIObjects, e);
  2043. //标样
  2044. MouseMoveFucntion(m_SpecimenGDIObjects, e);
  2045. //测量
  2046. MouseMoveFucntion(m_MeasureGDIObjects, e);
  2047. //文字
  2048. MouseMoveFucntion(m_ContentGDIObjects, e);
  2049. //帧图
  2050. if (m_SingleGDIObjects.Count > 0)
  2051. {
  2052. MouseMoveSingleFucntion(m_SingleGDIObjects, e);
  2053. string sampleName = m_SingleGDIObjects[0].SampleName;
  2054. }
  2055. //样品孔BSE图片
  2056. MouseMoveSingleFucntion(m_ImageGDIObjects, e);
  2057. //计算两个点之间的距离 移动样品台后与绘制样品台时的位置
  2058. m_DifferentPoint = OTSSamplespaceGraphicsPanelFun.StartToEndPointDist(m_RectangleGDIObjects[0], m_RegionStartCenterPoint);
  2059. }
  2060. }
  2061. //显示XY轴
  2062. OTSSamplespaceGraphicsPanelFun.ShowSemCoordvAL(e.Location, m_MeasureAppForm, m_RectangleGDIObjects, m_OTSSampleStageData, IsWidth);
  2063. Invalidate();
  2064. foreach (var item in m_MeasureGDIObjects)
  2065. {
  2066. if (item.CreateType == (int)CreateRectangleType.Polygon)
  2067. {
  2068. if (m_IsSelPolygonPoint)
  2069. {
  2070. InMeasure = true;
  2071. }
  2072. }
  2073. if (item.Region.Contains(e.Location))
  2074. {
  2075. InMeasure = true;
  2076. }
  2077. }
  2078. if (!InMeasure)
  2079. {
  2080. //this.Cursor = Cursors.Default;
  2081. }
  2082. }
  2083. bool isChange = false;
  2084. protected override void OnMouseUp(MouseEventArgs e)
  2085. {
  2086. //判断当前是否手绘
  2087. if (m_IsDrawMeasure)
  2088. {
  2089. //获取当前的鼠标点击位置
  2090. this.m_MouseUpPoint = new Point(e.X, e.Y);
  2091. //绘制多边形
  2092. if (m_DrawMeasureType != (int)CreateRectangleType.Polygon)
  2093. {
  2094. foreach (var item in m_DrawMeasureGDIObjects)
  2095. {
  2096. for (int i = 0; i < m_MeasureGDIObjects.Count; i++)
  2097. {
  2098. if (item.SampleName == m_MeasureGDIObjects[i].SampleName)
  2099. {
  2100. //获取样品孔名称与其他属性
  2101. item.Name = m_MeasureGDIObjects[i].Name;
  2102. item.IsSingle = m_MeasureGDIObjects[i].IsSingle;
  2103. item.IsWorkSample = m_MeasureGDIObjects[i].IsWorkSample;
  2104. //删除存在的帧图
  2105. for (int singleIndex = m_SingleGDIObjects.Count - 1; singleIndex >= 0; singleIndex--)
  2106. {
  2107. if (m_SingleGDIObjects[singleIndex].SampleName == item.SampleName)
  2108. {
  2109. m_SingleGDIObjects.RemoveAt(singleIndex);
  2110. }
  2111. }
  2112. m_MeasureGDIObjects[i] = item;
  2113. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(item, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  2114. {
  2115. m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;
  2116. CMeasureThreadWrapper.DoRunType = (int)MSR_THREAD_RunSTATUS.RUNMEASURE;
  2117. showSingleInfo();
  2118. break;
  2119. }
  2120. }
  2121. }
  2122. }
  2123. //清空绘制测量区域
  2124. if (m_DrawMeasureGDIObjects.Count > 0)
  2125. {
  2126. m_DrawMeasureGDIObjects.Clear();
  2127. }
  2128. this.Cursor = Cursors.Default;
  2129. //设置手绘标识
  2130. m_IsDrawMeasureReady = false;
  2131. m_IsDrawMeasure = false;
  2132. }
  2133. }
  2134. //如果正在进行测量线程,则退出鼠标点击操作
  2135. if (m_MeasureAppForm.MeasureThreadRunFlag)
  2136. {
  2137. return;
  2138. }
  2139. //是否移动至新样品孔
  2140. int IsContains = 0;
  2141. string HoleName = string.Empty;
  2142. //如果没有选择样品台
  2143. if (!m_IsSelectSampleStage)
  2144. {
  2145. //根据选择工作样品的测量状态,控制操作
  2146. if (selWSampleMeasureStatus)
  2147. {
  2148. return;
  2149. }
  2150. if (isChange)
  2151. {
  2152. if (m_RectangleGDIObjects == null)
  2153. {
  2154. return;
  2155. }
  2156. foreach (var measureItem in m_MeasureGDIObjects)
  2157. {
  2158. if (measureItem.IsWorkSample)
  2159. {
  2160. if (measureItem.Region.Contains(e.Location))
  2161. {
  2162. if (isChange == false)
  2163. {
  2164. isChange = true;
  2165. }
  2166. }
  2167. //保存原位置
  2168. Rectangle rectPara = measureItem.Region;
  2169. #region 测量区域与样品中心相差的距离
  2170. foreach (var itemSample in m_SampleGDIObjects)
  2171. {
  2172. if (itemSample.SampleName == measureItem.SampleName)
  2173. {
  2174. measureItem.SampleCenterDifferCenterPoint = OTSSamplespaceGraphicsPanelFun.GetSampleCenterDifferCenterPoint(rectPara, itemSample.Region);
  2175. break;
  2176. }
  2177. }
  2178. #endregion
  2179. //获取修改后的测量区域的位置与尺寸
  2180. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(measureItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  2181. {
  2182. //设置图形位置与大小
  2183. measureItem.Region = rectPara;
  2184. //重新绘制测量区域路径
  2185. OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(measureItem, rectPara);
  2186. //恢复光标
  2187. this.Cursor = System.Windows.Forms.Cursors.Default;
  2188. foreach (ARectangleGDIObject item in m_RectangleGDIObjects)
  2189. {
  2190. if (item.Region.Contains(e.Location))
  2191. {
  2192. m_IsSelectSampleStage = true;
  2193. }
  2194. else
  2195. {
  2196. m_IsSelectSampleStage = false;
  2197. }
  2198. }
  2199. }
  2200. break;
  2201. }
  2202. }
  2203. if (isChange)
  2204. {
  2205. //设置颜色
  2206. if (m_SingleGDIObjects.Count > 0)
  2207. {
  2208. for (int i = 0; i < m_SingleGDIObjects.Count; i++)
  2209. {
  2210. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SingleColor);
  2211. m_SingleGDIObjects[i].SelColor = ColorTranslator.FromHtml(ColorStr);
  2212. }
  2213. }
  2214. //切换至测量模式
  2215. m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;
  2216. CMeasureThreadWrapper.DoRunType = (int)MSR_THREAD_RunSTATUS.RUNMEASURE;
  2217. showSingleInfo();
  2218. }
  2219. foreach (ARectangleGDIObject item in m_SampleGDIObjects)
  2220. {
  2221. //判断鼠标是否在样品中
  2222. if (item.Region.Contains(e.Location))
  2223. {
  2224. if (item.IsWorkSample)
  2225. {
  2226. //获取原样品孔名称
  2227. HoleName = item.Name;
  2228. foreach (ARectangleGDIObject sampleHoleItem in m_SampleHoleGDIObjects)
  2229. {
  2230. //获取样品孔中心点
  2231. Point sampleHoleCenterPoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(sampleHoleItem);
  2232. //移动的样品在样品孔中心时
  2233. if (item.Region.Contains(sampleHoleCenterPoint))
  2234. {
  2235. if (item.Name != sampleHoleItem.Name)
  2236. {
  2237. sampleHoleItem.SampleCount += 1;
  2238. //样品孔信息
  2239. item.Name = sampleHoleItem.Name;
  2240. //样品Rectangle
  2241. item.Region = sampleHoleItem.Region;
  2242. item.RegionF = sampleHoleItem.RegionF;
  2243. item.DrawRegionF = sampleHoleItem.DrawRegionF;
  2244. IsContains++;
  2245. foreach (var sampleHoleCountItem in m_SampleHoleGDIObjects)
  2246. {
  2247. if (HoleName != string.Empty)
  2248. {
  2249. if (sampleHoleCountItem.Name == HoleName)
  2250. {
  2251. //减少样品数量
  2252. sampleHoleCountItem.SampleCount -= 1;
  2253. }
  2254. }
  2255. }
  2256. }
  2257. }
  2258. }
  2259. //获取工作样品中的测量区域
  2260. foreach (ARectangleGDIObject measureItem in m_MeasureGDIObjects)
  2261. {
  2262. if (item.SampleName == measureItem.SampleName)
  2263. {
  2264. //设置样品与样品孔名称
  2265. measureItem.Name = item.Name;
  2266. measureItem.SampleName = item.SampleName;
  2267. Rectangle rectPara = item.Region;
  2268. RectangleF rectParaF = item.RegionF;
  2269. if (m_IsMoveSample)
  2270. {
  2271. #region 样品移动至其他样品台后 修改测量区域位置
  2272. rectPara.X = item.Region.X - m_MeasureToSamplePoint.X;
  2273. rectPara.Y = item.Region.Y - m_MeasureToSamplePoint.Y;
  2274. rectPara.Width = measureItem.Region.Width;
  2275. rectPara.Height = measureItem.Region.Height;
  2276. rectParaF.X = rectPara.X / m_GlobalZoomNum;
  2277. rectParaF.Y = rectPara.Y / m_GlobalZoomNum;
  2278. rectParaF.Width = measureItem.RegionF.Width;
  2279. rectParaF.Height = measureItem.RegionF.Height;
  2280. //判断移动到其他样品孔后、当前测量区域是否超越样品台边缘
  2281. int CheckShape = measureItem.Shape;
  2282. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectPara, m_RectangleGDIObjects[0].Region, CheckShape))
  2283. {
  2284. measureItem.Region = rectPara;
  2285. measureItem.RegionF = rectParaF;
  2286. measureItem.DrawRegionF = rectParaF;
  2287. }
  2288. #endregion
  2289. }
  2290. //测量区域与样品中心相差的距离
  2291. measureItem.SampleCenterDifferCenterPoint = OTSSamplespaceGraphicsPanelFun.GetSampleCenterDifferCenterPoint(rectPara, measureItem.Region);
  2292. //获取修改后的测量区域的位置与尺寸
  2293. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(measureItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  2294. {
  2295. //设置测量区域信息
  2296. measureItem.SampleName = item.SampleName;
  2297. measureItem.Name = item.Name;
  2298. //将所有帧图移动测量区域位置中
  2299. //获取样品孔 与 样品名称
  2300. foreach (var SampleItem in m_SampleGDIObjects)
  2301. {
  2302. if (item.IsWorkSample)
  2303. {
  2304. //设置工作样品的测量区域 存在帧图
  2305. foreach (var MeasureItem in m_MeasureGDIObjects)
  2306. {
  2307. if (MeasureItem.SampleName == item.SampleName)
  2308. {
  2309. //设置工作样品的测量区域 存在帧图标识
  2310. if (m_SingleGDIObjects.Count > 0)
  2311. {
  2312. OTSSamplespaceGraphicsPanelFun.SetSingleLocationToMeasureLocation(m_SingleGDIObjects, MeasureItem);
  2313. }
  2314. }
  2315. }
  2316. }
  2317. }
  2318. //更新Grid 工作样品属性值
  2319. m_MeasureAppForm.UpdateTreeSampleAndGridSampleVal();
  2320. Invalidate();
  2321. break;
  2322. }
  2323. }
  2324. }
  2325. }
  2326. }
  2327. if (item.IsWorkSample)
  2328. {
  2329. //设置颜色
  2330. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  2331. item.SelColor = ColorTranslator.FromHtml(ColorStr);
  2332. }
  2333. }
  2334. isChange = false;
  2335. }
  2336. //移动多边形的点后,显示已获取的帧图
  2337. if (m_IsSelPolygonPoint)
  2338. {
  2339. foreach (var measureItem in m_MeasureGDIObjects)
  2340. {
  2341. if (measureItem.IsWorkSample)
  2342. {
  2343. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(measureItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  2344. {
  2345. if (measureItem.IsSingle)
  2346. {
  2347. showSingleInfo();
  2348. }
  2349. }
  2350. }
  2351. }
  2352. }
  2353. Invalidate();
  2354. }
  2355. //样品台
  2356. MouseUpFucntion(m_RectangleGDIObjects, e);
  2357. //样品
  2358. MouseUpFucntion(m_SampleGDIObjects, e);
  2359. //样品孔
  2360. MouseUpFucntion(m_SampleHoleGDIObjects, e);
  2361. //标样
  2362. MouseUpFucntion(m_SpecimenGDIObjects, e);
  2363. //测量
  2364. MouseUpFucntion(m_MeasureGDIObjects, e);
  2365. //测量路径
  2366. MouseUpFucntion(m_MeasurePathGDIObjects, e);
  2367. //文字
  2368. MouseUpFucntion(m_ContentGDIObjects, e);
  2369. //帧图
  2370. MouseUpFucntion(m_SingleGDIObjects, e);
  2371. //已获取的帧图
  2372. MouseUpFucntion(m_ALLSingleGDIObjects, e);
  2373. //样品孔中BSE图片
  2374. MouseUpFucntion(m_ImageGDIObjects, e);
  2375. //SEM中心位置
  2376. MouseUpFucntion(m_SEMCenterGDIObjects, e);
  2377. //撤回原样品孔中
  2378. if (IsContains == 0)
  2379. {
  2380. foreach (var item in m_SampleGDIObjects)
  2381. {
  2382. //if (item.Region.Contains(e.Location))
  2383. //{
  2384. //鼠标按下事件中获取选择的样品原有位置
  2385. //如果没有找到其他样品孔的中心点,则将移动的样品设置为原位置
  2386. foreach (ARectangleGDIObject sampleHoleItems in m_SampleHoleGDIObjects)
  2387. {
  2388. if (sampleHoleItems.SampleCount > 0)
  2389. {
  2390. if (item.IsWorkSample)
  2391. {
  2392. //设置颜色
  2393. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  2394. item.SelColor = ColorTranslator.FromHtml(ColorStr);
  2395. if (selectSampleGDIObjects != null)
  2396. {
  2397. if (sampleHoleItems.Name == selectSampleGDIObjects.Name && item.SampleName == selectSampleGDIObjects.SampleName)
  2398. {
  2399. item.Region = sampleHoleItems.Region;
  2400. Invalidate();
  2401. break;
  2402. }
  2403. }
  2404. }
  2405. }
  2406. }
  2407. //}
  2408. //获取帧图与测量区域的相差的位置
  2409. int m_singleDiffX = 0;
  2410. int m_singleDiffY = 0;
  2411. //如果当前样品没有移动至其他样品孔 测量区域恢复原位置
  2412. if (m_IsMoveSample)
  2413. {
  2414. if (item.IsWorkSample)
  2415. {
  2416. foreach (var measureItem in m_MeasureGDIObjects)
  2417. {
  2418. if (measureItem.SampleName == item.SampleName)
  2419. {
  2420. //获取测量区域与样品之间相差的距离
  2421. if (m_SingleGDIObjects.Count > 0)
  2422. {
  2423. m_singleDiffX = measureItem.Region.X - item.Region.X + m_MeasureToSamplePoint.X;
  2424. m_singleDiffY = measureItem.Region.Y - item.Region.Y + m_MeasureToSamplePoint.Y;
  2425. }
  2426. RectangleF rectParaF = item.RegionF;
  2427. Rectangle rectPara = item.Region;
  2428. rectPara.X = item.Region.X - m_MeasureToSamplePoint.X;
  2429. rectPara.Y = item.Region.Y - m_MeasureToSamplePoint.Y;
  2430. rectPara.Width = measureItem.Region.Width;
  2431. rectPara.Height = measureItem.Region.Height;
  2432. measureItem.Region = rectPara;
  2433. rectParaF.X = rectPara.X / m_GlobalZoomNum;
  2434. rectParaF.Y = rectPara.Y / m_GlobalZoomNum;
  2435. rectParaF.Width = measureItem.RegionF.Width;
  2436. rectParaF.Height = measureItem.RegionF.Height;
  2437. measureItem.RegionF = rectParaF;
  2438. measureItem.DrawRegionF = rectParaF;
  2439. break;
  2440. }
  2441. }
  2442. //将帧图恢复至原位置
  2443. foreach (var singleItem in m_SingleGDIObjects)
  2444. {
  2445. if (singleItem.SampleName == item.SampleName)
  2446. {
  2447. RectangleF rectParaDrawF = singleItem.DrawRegionF;
  2448. RectangleF rectParaF = singleItem.RegionF;
  2449. Rectangle rectPara = singleItem.Region;
  2450. rectPara.X = singleItem.Region.X - m_singleDiffX;
  2451. rectPara.Y = singleItem.Region.Y - m_singleDiffY;
  2452. rectPara.Width = singleItem.Region.Width;
  2453. rectPara.Height = singleItem.Region.Height;
  2454. singleItem.Region = rectPara;
  2455. //更改帧图RegionF
  2456. rectParaF.X = singleItem.RegionF.X - m_singleDiffX;
  2457. rectParaF.Y = singleItem.RegionF.Y - m_singleDiffY;
  2458. singleItem.RegionF = rectParaF;
  2459. //更改帧图绘制原位置DrawRegionF
  2460. rectParaDrawF.X = (rectParaDrawF.X - m_singleDiffX / m_GlobalZoomNum);
  2461. rectParaDrawF.Y = (rectParaDrawF.Y - m_singleDiffY / m_GlobalZoomNum);
  2462. rectParaDrawF.Width = rectParaDrawF.Width;
  2463. rectParaDrawF.Height = rectParaDrawF.Height;
  2464. singleItem.DrawRegionF = rectParaDrawF;
  2465. }
  2466. }
  2467. //删除已添加的帧图信息、重新添加帧图信息
  2468. if (m_ALLSingleGDIObjects.Count > 0)
  2469. {
  2470. OTSSamplespaceGraphicsPanelFun.DeleteALLSingleInfo(m_ALLSingleGDIObjects, item.SampleName);
  2471. OTSSamplespaceGraphicsPanelFun.AddALLSingleInfo(m_ALLSingleGDIObjects, m_SingleGDIObjects, item.SampleName);
  2472. }
  2473. }
  2474. }
  2475. }
  2476. }
  2477. m_IsMoveSample = false;
  2478. m_MeasureToSamplePoint = new Point();
  2479. //计算两个点之间的距离 移动样品台后与绘制样品台时的位置
  2480. if (m_RectangleGDIObjects.Count > 0)
  2481. {
  2482. m_DifferentPoint = OTSSamplespaceGraphicsPanelFun.StartToEndPointDist(m_RectangleGDIObjects[0], m_RegionStartCenterPoint);
  2483. }
  2484. m_IsCtrl = false;
  2485. m_IsAlt = false;
  2486. m_IsSelPolygonPoint = false;
  2487. selWSampleMeasureStatus = false;
  2488. }
  2489. protected override void OnPaint(PaintEventArgs e)//处理重绘情况
  2490. {
  2491. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_RectangleGDIObjects);
  2492. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_SampleHoleGDIObjects);
  2493. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_SampleGDIObjects);
  2494. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_SpecimenGDIObjects);
  2495. //切换显示样品孔中的文字
  2496. if (IsShowSampleHoleFont)
  2497. {
  2498. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_ContentGDIObjects);
  2499. }
  2500. //切换显示样品孔中的BSE图片
  2501. if (IsShowSampleHoleImage)
  2502. {
  2503. if (m_ImageGDIObjects != null)
  2504. {
  2505. if (m_ImageGDIObjects.Count > 0)
  2506. {
  2507. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_ImageGDIObjects);
  2508. }
  2509. }
  2510. }
  2511. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_MeasurePathGDIObjects);
  2512. try
  2513. {
  2514. if (m_SingleGDIObjects != null)
  2515. {
  2516. if (m_SingleGDIObjects.Count > 0)
  2517. {
  2518. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_SingleGDIObjects);
  2519. }
  2520. }
  2521. }
  2522. catch (Exception)
  2523. {
  2524. }
  2525. //手动绘制测量区域
  2526. if (m_DrawMeasureGDIObjects != null)
  2527. {
  2528. if (m_DrawMeasureGDIObjects.Count > 0)
  2529. {
  2530. for (int i = 0; i < m_DrawMeasureGDIObjects.Count; i++)
  2531. {
  2532. if (m_DrawMeasureGDIObjects[i] != null)
  2533. {
  2534. m_DrawMeasureGDIObjects[i].EndPoint = this.m_MouseMovePoint;
  2535. m_DrawMeasureGDIObjects[i].OnPaint(e);
  2536. }
  2537. }
  2538. }
  2539. }
  2540. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_MeasureGDIObjects);
  2541. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_SEMCenterGDIObjects);
  2542. if (m_IsDrawPolygonFinish || m_IsSelPolygonPoint)
  2543. {
  2544. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_DrawPolygonFinishGDIObjects);
  2545. }
  2546. }
  2547. protected override void OnMouseWheel(MouseEventArgs e)
  2548. {
  2549. //如果正在进行测量线程,则退出鼠标点击操作
  2550. if (m_MeasureAppForm.MeasureThreadRunFlag)
  2551. {
  2552. return;
  2553. }
  2554. base.OnMouseWheel(e);
  2555. //设置记录每次比例缩放后的总体比例系数
  2556. if (e.Delta > 0)
  2557. {
  2558. m_GlobalZoomNum += 0.1f;
  2559. }
  2560. else
  2561. {
  2562. m_GlobalZoomNum -= 0.1f;
  2563. if (m_GlobalZoomNum < 1)
  2564. {
  2565. m_GlobalZoomNum = 1;
  2566. }
  2567. }
  2568. if (e.Delta > 0)
  2569. {
  2570. //if (f_zoom_record <= f_zoom_max)
  2571. //{
  2572. #region //图形缩放计算部份-------放大------------//是放大
  2573. f_widthandheight_js = f_zoom_increment;
  2574. f_zoom_record = f_zoom_record + f_zoom_increment;
  2575. f_zoom_record = float.Parse(f_zoom_record.ToString("#0.0")); //四舍五入,保留一位小数,如果不这样,float会不附合规则
  2576. #endregion
  2577. #region 计算标尺尺寸部份-----放大------
  2578. //计算标尺实际占用像素的宽度
  2579. f_ruler_size = f_ruler_size + Convert.ToInt32(f_old_ruler_size * f_zoom_increment);
  2580. control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);
  2581. //显示该像素宽度代表的实际宽度
  2582. control_Ruler2.SetValueInspector(f_ruler_size, ((Convert.ToDouble(m_OTSSampleStageData.StageDomain.Width) / Convert.ToDouble(54)) / 10));
  2583. //放大过长时,这里将宽度与代表的实际宽度进行折半显示
  2584. if (control_Ruler2.RulerWidth > 200)
  2585. {
  2586. control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size) / 2;
  2587. }
  2588. #endregion
  2589. //}
  2590. }
  2591. else
  2592. {
  2593. if (f_zoom_record >= f_zoom_mix)
  2594. {
  2595. #region //图形缩放计算部份------缩小--------------------
  2596. f_widthandheight_js = -f_zoom_increment;
  2597. f_zoom_record = f_zoom_record - f_zoom_increment;
  2598. f_zoom_record = float.Parse(f_zoom_record.ToString("#0.0")); //四舍五入,保留一位小数,如果不这样,float会不附合规则
  2599. #endregion
  2600. #region 计算标尺尺寸部份-----缩小------f_onepixel_size,是不是该乘以rulerwidth是实际的长度
  2601. f_ruler_size = f_ruler_size + Convert.ToInt32(f_old_ruler_size * -f_zoom_increment);
  2602. control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);
  2603. control_Ruler2.SetValueInspector(f_ruler_size, ((Convert.ToDouble(m_OTSSampleStageData.StageDomain.Width) / Convert.ToDouble(54)) / 10));
  2604. if (control_Ruler2.RulerWidth > 200)
  2605. {
  2606. control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size) / 2;
  2607. }
  2608. #endregion
  2609. }
  2610. }
  2611. if (m_GlobalZoomNum >= 1)
  2612. {
  2613. if (m_RectangleGDIObjects.Count > 0)
  2614. {
  2615. //恢复图像初始位置
  2616. OTSSamplespaceGraphicsPanelFun.RecoverInitialPosition(m_SingleGDIObjects, m_GlobalZoomNum);
  2617. OTSSamplespaceGraphicsPanelFun.RecoverInitialPosition(m_ALLSingleGDIObjects, m_GlobalZoomNum);
  2618. OTSSamplespaceGraphicsPanelFun.RecoverInitialPosition(m_ImageGDIObjects, m_GlobalZoomNum);
  2619. //样品
  2620. OTSSamplespaceGraphicsPanelFun.MouseWheelFunction(m_SampleGDIObjects, m_RectangleGDIObjects[0], m_GlobalZoomNum);
  2621. //样品孔
  2622. OTSSamplespaceGraphicsPanelFun.MouseWheelFunction(m_SampleHoleGDIObjects, m_RectangleGDIObjects[0], m_GlobalZoomNum);
  2623. //标样
  2624. OTSSamplespaceGraphicsPanelFun.MouseWheelFunction(m_SpecimenGDIObjects, m_RectangleGDIObjects[0], m_GlobalZoomNum);
  2625. //测量区域
  2626. OTSSamplespaceGraphicsPanelFun.MouseWheelFunction(m_MeasureGDIObjects, m_RectangleGDIObjects[0], m_GlobalZoomNum);
  2627. //文字
  2628. OTSSamplespaceGraphicsPanelFun.MouseWheelFunction(m_ContentGDIObjects, m_RectangleGDIObjects[0], m_GlobalZoomNum);
  2629. //样品台
  2630. OTSSamplespaceGraphicsPanelFun.MouseWheelFunction(m_RectangleGDIObjects, m_RectangleGDIObjects[0], m_GlobalZoomNum);
  2631. if (m_GlobalZoomNum == 1)
  2632. {
  2633. // 将绘制的样品台信息 按屏幕中心移动
  2634. //获取当前样品台中心点
  2635. Point samplePoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(m_RectangleGDIObjects[0].Region);
  2636. //获取当前工作区域中心点
  2637. Point workAreaPoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(this.ClientRectangle);
  2638. //计算样品台中心点与工作区域中心点相差的距离
  2639. PointF distancePoint = new PointF(samplePoint.X - workAreaPoint.X, samplePoint.Y - workAreaPoint.Y);
  2640. if (distancePoint.X != 0 || distancePoint.Y != 0)
  2641. {
  2642. MoveToSrceenCenterFunction(distancePoint);
  2643. }
  2644. //标尺恢复初始
  2645. f_ruler_size = f_old_ruler_size;
  2646. control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);
  2647. control_Ruler2.ShowString = "1000um";
  2648. control_Ruler2.SetValueInspector(110, ((Convert.ToDouble(m_OTSSampleStageData.StageDomain.Width) / Convert.ToDouble(54)) / 10));
  2649. }
  2650. //重新绘制
  2651. Invalidate();
  2652. }
  2653. }
  2654. }
  2655. #endregion
  2656. #region 鼠标方法操作
  2657. public void MouseDownFucntion(List<ARectangleGDIObject> objList, MouseEventArgs e)
  2658. {
  2659. foreach (ARectangleGDIObject item in objList)
  2660. {
  2661. item.IsDragging = true;
  2662. item.DraggingPoint = e.Location;
  2663. }
  2664. }
  2665. public void MouseMoveFucntion(List<ARectangleGDIObject> objList, MouseEventArgs e)
  2666. {
  2667. foreach (ARectangleGDIObject item in objList)
  2668. {
  2669. if (item.IsDragging)
  2670. {
  2671. item.Region = new Rectangle(
  2672. item.Region.Left + Convert.ToInt32((e.X - item.DraggingPoint.X)),
  2673. item.Region.Top + Convert.ToInt32((e.Y - item.DraggingPoint.Y)),
  2674. item.Region.Width,
  2675. item.Region.Height);
  2676. item.RegionF = new RectangleF(
  2677. item.RegionF.Left + (float)(e.X - item.DraggingPoint.X) / m_GlobalZoomNum,
  2678. item.RegionF.Top + (float)(e.Y - item.DraggingPoint.Y) / m_GlobalZoomNum,
  2679. item.RegionF.Width,
  2680. item.RegionF.Height);
  2681. item.DrawRegionF = new RectangleF(
  2682. item.DrawRegionF.Left + (float)(e.X - item.DraggingPoint.X),
  2683. item.DrawRegionF.Top + (float)(e.Y - item.DraggingPoint.Y),
  2684. item.DrawRegionF.Width,
  2685. item.DrawRegionF.Height);
  2686. item.LineStartPoint = new PointF(
  2687. item.Region.Left + (e.X - item.DraggingPoint.X),
  2688. item.Region.Top + (e.Y - item.DraggingPoint.Y));
  2689. item.BSEImageLocation = new PointF(
  2690. item.BSEImageLocation.X + e.X - item.DraggingPoint.X,
  2691. item.BSEImageLocation.Y + e.Y - item.DraggingPoint.Y);
  2692. //移动SEM中心点位置
  2693. item.SEMCenterPoint = new PointF(
  2694. item.SEMCenterPoint.X + (e.X - item.DraggingPoint.X),
  2695. item.SEMCenterPoint.Y + (e.Y - item.DraggingPoint.Y));
  2696. //多边形样品台移动
  2697. if (item.Shape == (int)CreateRectangleType.Polygon)
  2698. {
  2699. if (item.DrawPolygonPointRegionF != null)
  2700. {
  2701. if (item.DrawPolygonPointRegionF.Count > 0)
  2702. {
  2703. int polygonPointCount = item.DrawPolygonPointRegionF.Count;
  2704. if (polygonPointCount > 0)
  2705. {
  2706. for (int pointIndex = 0; pointIndex < polygonPointCount; pointIndex++)
  2707. {
  2708. item.PolygonPointRegion[pointIndex] = new Point(
  2709. item.PolygonPointRegion[pointIndex].X + Convert.ToInt32((e.X - item.DraggingPoint.X)),
  2710. item.PolygonPointRegion[pointIndex].Y + Convert.ToInt32((e.Y - item.DraggingPoint.Y)));
  2711. item.PolygonPointRegionF[pointIndex] = new PointF(
  2712. item.PolygonPointRegionF[pointIndex].X + (float)(e.X - item.DraggingPoint.X),
  2713. item.PolygonPointRegionF[pointIndex].Y + (float)(e.Y - item.DraggingPoint.Y));
  2714. //2020-12-1日注释
  2715. item.DrawPolygonPointRegionF[pointIndex] = new PointF(
  2716. item.DrawPolygonPointRegionF[pointIndex].X + (float)(e.X - item.DraggingPoint.X) / m_GlobalZoomNum,
  2717. item.DrawPolygonPointRegionF[pointIndex].Y + (float)(e.Y - item.DraggingPoint.Y) / m_GlobalZoomNum);
  2718. }
  2719. }
  2720. }
  2721. }
  2722. }
  2723. item.DraggingPoint = e.Location;
  2724. //重新绘制测量区域路径
  2725. OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(item, item.Region);
  2726. }
  2727. }
  2728. }
  2729. public void MouseMoveMeasureFucntion(ARectangleGDIObject item, MouseEventArgs e)
  2730. {
  2731. //判断移动的样品 是否在样品台尺寸范围内
  2732. Rectangle rectTemp = item.Region;
  2733. rectTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;
  2734. rectTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;
  2735. int CheckShape = (int)CreateRectangleType.Circle;
  2736. if (m_RectangleGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  2737. {
  2738. CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;
  2739. }
  2740. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  2741. {
  2742. #region 需抽出作为公共方法
  2743. int xMove = rectTemp.X - item.Region.X;
  2744. int yMove = rectTemp.Y - item.Region.Y;
  2745. int Width = rectTemp.Width - item.Region.Width;
  2746. int Height = rectTemp.Height - item.Region.Height;
  2747. //设置图形大小
  2748. item.Region = rectTemp;
  2749. int WidthNew = (int)((item.RegionF.Width + Width / m_GlobalZoomNum));
  2750. int HeightNew = (int)((item.RegionF.Height + Height / m_GlobalZoomNum));
  2751. //设置原测量区域图形大小
  2752. float xMoveNew = (float)((item.RegionF.X + (xMove / m_GlobalZoomNum)));
  2753. float yMoveNew = (float)((item.RegionF.Y + (yMove / m_GlobalZoomNum)));
  2754. item.RegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));
  2755. item.DrawRegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));
  2756. item.DraggingPoint = e.Location;
  2757. #endregion
  2758. //重新绘制测量区域路径
  2759. OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(item, item.Region);
  2760. //帧图
  2761. MouseMoveSingleFucntion(m_SingleGDIObjects, e);
  2762. Invalidate();
  2763. return;
  2764. }
  2765. }
  2766. public void MouseMovePolygonMeasureFucntion(ARectangleGDIObject item, MouseEventArgs e)
  2767. {
  2768. //多边形样品台移动
  2769. if (item.Shape == (int)CreateRectangleType.Polygon)
  2770. {
  2771. //判断样品台形状
  2772. int CheckShape = (int)CreateRectangleType.Circle;
  2773. if (m_RectangleGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  2774. {
  2775. CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;
  2776. }
  2777. //生成多边形最小面积外接矩形
  2778. Rectangle rectMeasureTemp = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(item.PolygonPointRegionF);
  2779. //判断多边形是否超越样品台
  2780. rectMeasureTemp.X = rectMeasureTemp.Left + e.X - item.DraggingPoint.X;
  2781. rectMeasureTemp.Y = rectMeasureTemp.Top + e.Y - item.DraggingPoint.Y;
  2782. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectMeasureTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  2783. {
  2784. int polygonPointCount = item.DrawPolygonPointRegionF.Count;
  2785. if (polygonPointCount > 0)
  2786. {
  2787. for (int pointIndex = 0; pointIndex < polygonPointCount; pointIndex++)
  2788. {
  2789. item.PolygonPointRegion[pointIndex] = new Point(
  2790. item.PolygonPointRegion[pointIndex].X + Convert.ToInt32((e.X - item.DraggingPoint.X)),
  2791. item.PolygonPointRegion[pointIndex].Y + Convert.ToInt32((e.Y - item.DraggingPoint.Y)));
  2792. item.PolygonPointRegionF[pointIndex] = new PointF(
  2793. item.PolygonPointRegionF[pointIndex].X + (float)(e.X - item.DraggingPoint.X),
  2794. item.PolygonPointRegionF[pointIndex].Y + (float)(e.Y - item.DraggingPoint.Y));
  2795. item.DrawPolygonPointRegionF[pointIndex] = new PointF(
  2796. item.DrawPolygonPointRegionF[pointIndex].X + (float)(e.X - item.DraggingPoint.X) / m_GlobalZoomNum,
  2797. item.DrawPolygonPointRegionF[pointIndex].Y + (float)(e.Y - item.DraggingPoint.Y) / m_GlobalZoomNum);
  2798. }
  2799. Rectangle rectTemp = item.Region;
  2800. rectTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;
  2801. rectTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;
  2802. #region 需抽出作为公共方法
  2803. int xMove = rectTemp.X - item.Region.X;
  2804. int yMove = rectTemp.Y - item.Region.Y;
  2805. int Width = rectTemp.Width - item.Region.Width;
  2806. int Height = rectTemp.Height - item.Region.Height;
  2807. //设置图形大小
  2808. item.Region = rectTemp;
  2809. int WidthNew = (int)((item.RegionF.Width + Width / m_GlobalZoomNum));
  2810. int HeightNew = (int)((item.RegionF.Height + Height / m_GlobalZoomNum));
  2811. //设置原测量区域图形大小
  2812. float xMoveNew = (float)((item.RegionF.X + (xMove / m_GlobalZoomNum)));
  2813. float yMoveNew = (float)((item.RegionF.Y + (yMove / m_GlobalZoomNum)));
  2814. //item.Region = new Rectangle(new Point((int)xMoveNew, (int)yMoveNew), new Size(WidthNew, HeightNew));
  2815. item.RegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));
  2816. item.DrawRegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));
  2817. item.DraggingPoint = e.Location;
  2818. #endregion
  2819. ////生成多边形最小面积外接矩形
  2820. //Rectangle rectPolygonMeasure = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(item.PolygonPointRegionF);
  2821. //item.Region = rectPolygonMeasure;
  2822. //item.RegionF = rectPolygonMeasure;
  2823. //item.DrawRegionF = rectPolygonMeasure;
  2824. }
  2825. item.DraggingPoint = e.Location;
  2826. //重新绘制测量区域路径
  2827. OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(item, item.Region);
  2828. //帧图
  2829. MouseMoveSingleFucntion(m_SingleGDIObjects, e);
  2830. }
  2831. }
  2832. Invalidate();
  2833. return;
  2834. }
  2835. public bool MoveMeasureInStage(ARectangleGDIObject item, Point m_StageCenterPoint, Point semLocation, double m_GlobalZoomNum)
  2836. {
  2837. //判断测量区域移动到SEM的当前位置 是否在样品台尺寸范围内
  2838. Rectangle rectTemp = item.Region;
  2839. rectTemp.X = m_StageCenterPoint.X + semLocation.X;// - rectTemp.Width / 2;
  2840. rectTemp.Y = m_StageCenterPoint.Y - semLocation.Y;// - rectTemp.Height/ 2;
  2841. rectTemp.Width = 2;
  2842. rectTemp.Height = 2;
  2843. int CheckShape = (int)CreateRectangleType.Circle;
  2844. if (m_RectangleGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  2845. {
  2846. CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;
  2847. }
  2848. if (!OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  2849. {
  2850. return false;
  2851. }
  2852. return true;
  2853. }
  2854. public void MouseMoveSingleFucntion(List<ARectangleGDIObject> objList, MouseEventArgs e)
  2855. {
  2856. foreach (ARectangleGDIObject item in objList)
  2857. {
  2858. if (item.IsDragging)
  2859. {
  2860. item.Region = new Rectangle(
  2861. item.Region.Left + e.X - item.DraggingPoint.X,
  2862. item.Region.Top + e.Y - item.DraggingPoint.Y,
  2863. item.Region.Width,
  2864. item.Region.Height);
  2865. item.RegionF = new RectangleF(
  2866. item.RegionF.Left + (e.X - item.DraggingPoint.X),
  2867. item.RegionF.Top + (e.Y - item.DraggingPoint.Y),
  2868. item.RegionF.Width,
  2869. item.RegionF.Height);
  2870. item.DrawRegionF = new RectangleF(
  2871. item.DrawRegionF.Left + (e.X - item.DraggingPoint.X) / m_GlobalZoomNum,
  2872. item.DrawRegionF.Top + (e.Y - item.DraggingPoint.Y) / m_GlobalZoomNum,
  2873. item.DrawRegionF.Width,
  2874. item.DrawRegionF.Height);
  2875. item.LineStartPoint = new PointF(
  2876. item.Region.Left + (e.X - item.DraggingPoint.X),
  2877. item.Region.Top + (e.Y - item.DraggingPoint.Y));
  2878. item.DraggingPoint = e.Location;
  2879. //重新绘制测量区域路径
  2880. OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(item, item.Region);
  2881. }
  2882. }
  2883. }
  2884. public void MouseUpFucntion(List<ARectangleGDIObject> objList, MouseEventArgs e)
  2885. {
  2886. foreach (ARectangleGDIObject item in objList)
  2887. {
  2888. if (item.IsDragging)
  2889. {
  2890. item.IsSelect = false;
  2891. item.IsDragging = false;
  2892. item.DraggingPoint = Point.Empty;
  2893. //item.IsWorkSample = false;
  2894. }
  2895. }
  2896. }
  2897. public void SizeChangeFucntion(List<ARectangleGDIObject> objList, float Zoom)
  2898. {
  2899. foreach (ARectangleGDIObject item in objList)
  2900. {
  2901. float x = item.RegionF.X * Zoom;
  2902. float y = item.RegionF.Y * Zoom;
  2903. float widthRect = item.RegionF.Width * Zoom;
  2904. float heightRect = item.RegionF.Height * Zoom;
  2905. //改变窗体时,修改图形位置与大小
  2906. item.Region = new Rectangle((int)x, (int)y, (int)widthRect, (int)heightRect);
  2907. item.RegionF = new RectangleF(x, y, widthRect, heightRect);
  2908. item.DrawRegionF = new RectangleF(x, y, widthRect, heightRect);
  2909. }
  2910. }
  2911. public void SizeFChangeFucntion(List<ARectangleGDIObject> objList, float Zoom)
  2912. {
  2913. foreach (ARectangleGDIObject item in objList)
  2914. {
  2915. float x = item.DrawRegionF.X * Zoom;
  2916. float y = item.DrawRegionF.Y * Zoom;
  2917. float widthRect = item.DrawRegionF.Width * Zoom;
  2918. float heightRect = item.DrawRegionF.Height * Zoom;
  2919. //改变窗体时,修改图形位置与大小
  2920. item.Region = new Rectangle((int)x, (int)y, (int)widthRect, (int)heightRect);
  2921. item.RegionF = new RectangleF(x, y, widthRect, heightRect);
  2922. item.DrawRegionF = new RectangleF(x, y, widthRect, heightRect);
  2923. }
  2924. }
  2925. /// <summary>
  2926. /// 将绘制的样品台信息 按屏幕中心移动
  2927. /// </summary>
  2928. public void MoveToSrceenCenterFunction(PointF distancePoint)
  2929. {
  2930. if (distancePoint.X != 0 || distancePoint.Y != 0)
  2931. {
  2932. //循环样品台上的图形,将其按工作区域中心点移动
  2933. MoveLocationToSrceenCenterFunction(m_RectangleGDIObjects, distancePoint);
  2934. MoveLocationToSrceenCenterFunction(m_SampleHoleGDIObjects, distancePoint);
  2935. MoveLocationToSrceenCenterFunction(m_SampleGDIObjects, distancePoint);
  2936. MoveLocationToSrceenCenterFunction(m_SpecimenGDIObjects, distancePoint);
  2937. MoveLocationToSrceenCenterFunction(m_ContentGDIObjects, distancePoint);
  2938. MoveLocationToSrceenCenterFunction(m_MeasureGDIObjects, distancePoint);
  2939. MoveLocationToSrceenCenterFunction(m_MeasurePathGDIObjects, distancePoint);
  2940. MoveLocationToSrceenCenterFunction(m_SingleGDIObjects, distancePoint);
  2941. MoveLocationToSrceenCenterFunction(m_ImageGDIObjects, distancePoint);
  2942. }
  2943. }
  2944. public void MoveLocationToSrceenCenterFunction(List<ARectangleGDIObject> objList, PointF distancePoint)
  2945. {
  2946. foreach (var item in objList)
  2947. {
  2948. if (item.Shape == (int)CreateRectangleType.Polygon)
  2949. {
  2950. for (int i = 0; i < item.PolygonPointRegion.Count; i++)
  2951. {
  2952. item.PolygonPointRegion[i] = new Point((int)(item.PolygonPointRegion[i].X - distancePoint.X), (int)(item.PolygonPointRegion[i].Y - distancePoint.Y));
  2953. item.PolygonPointRegionF[i] = new PointF(item.PolygonPointRegionF[i].X - distancePoint.X, (item.PolygonPointRegionF[i].Y - distancePoint.Y));
  2954. item.DrawPolygonPointRegionF[i] = new PointF(item.DrawPolygonPointRegionF[i].X - distancePoint.X, (item.DrawPolygonPointRegionF[i].Y - distancePoint.Y));
  2955. }
  2956. }
  2957. item.Region = new Rectangle((int)((item.Region.X - distancePoint.X)), (int)(item.Region.Y - distancePoint.Y), item.Region.Width, item.Region.Height);
  2958. item.RegionF = new RectangleF((item.RegionF.X - distancePoint.X), (item.RegionF.Y - distancePoint.Y), item.RegionF.Width, item.RegionF.Height);
  2959. item.DrawRegionF = new RectangleF((item.DrawRegionF.X - distancePoint.X), (item.DrawRegionF.Y - distancePoint.Y), item.DrawRegionF.Width, item.DrawRegionF.Height);
  2960. item.BSEImageWitdh = item.Region.Width;
  2961. item.BSEImageHeight = item.Region.Height;
  2962. item.BSEImageLocation = item.Region.Location;
  2963. //重新绘制测量区域路径
  2964. OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(item, item.Region);
  2965. }
  2966. }
  2967. #endregion
  2968. #region 菜单操作
  2969. private void CMStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  2970. {
  2971. Point mousePoint = this.PointToClient(Control.MousePosition);
  2972. CMStrip.Hide();
  2973. switch (e.ClickedItem.Name)
  2974. {
  2975. case "AddStage":
  2976. m_MeasureAppForm.m_SPropertyWindows.TSSaveAs.Enabled = true;
  2977. m_MeasureAppForm.m_SPropertyWindows.TSLoad.Enabled = true;
  2978. m_MeasureAppForm.m_SPropertyWindows.TSEdit.Enabled = false;
  2979. m_MeasureAppForm.m_SPropertyWindows.TSEdit.Visible = false;
  2980. //添加样品
  2981. m_MeasureAppForm.AddNewSampleMeasure(m_SampleHoleSelectName);
  2982. break;
  2983. case "DeleteStage":
  2984. //删除样品
  2985. OTSSamplespaceGraphicsPanelFun.DeleteSampleInfo(m_MeasureAppForm, m_SampleSelectName);
  2986. break;
  2987. case "DriveSEMToCenterLocation":
  2988. //驱动SEM到中心位置
  2989. SetSEMToCenterPoint();
  2990. break;
  2991. case "DriveSEMToCurrentLocation":
  2992. //驱动SEM到当前位置
  2993. SetSEMCurrentLocation();
  2994. break;
  2995. case "SetSEMCenterLocation":
  2996. //将测量区域移到SEM当前位置
  2997. SetMeasureToSEMLocation();
  2998. break;
  2999. case "ReadSEMData":
  3000. m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;
  3001. //设定SEM数据
  3002. CMeasureThreadWrapper.DoRunType = (int)MSR_THREAD_RunSTATUS.RUNMEASURE;
  3003. GetSingleInfo();
  3004. // 根据已完成测量的帧图信息 绘制帧图已完成状态
  3005. GetSingleInfoForSampleNameAndOTSSamplespaceWindow();
  3006. break;
  3007. case "SetSemData":
  3008. double SemMag = 0;
  3009. double dDistance = 0;
  3010. log.Trace("OTSSamplespaceWindow_CMStrip_ItemClicked:--begin--");
  3011. if (m_MeasureAppForm.m_ProjParam.GetMagAndDistance(ref SemMag, ref dDistance))
  3012. {
  3013. //设置SEM数据
  3014. bool IsTrue = SetSEMDATAMParameter(SemMag, dDistance);
  3015. if (!IsTrue)
  3016. {
  3017. log.Error("OTSSamplespaceWindow_CMStrip_ItemClicked:--SetSemData:--Mag:" + SemMag + "--Distance:" + dDistance + "--");
  3018. }
  3019. }
  3020. break;
  3021. case "ShootBSEPicture":
  3022. //设置消息类型 拍摄样品孔
  3023. m_MeasureAppForm.m_MessageStates = MessageState.ShotBSEPicture;
  3024. //清除原图片信息
  3025. DeleteHoleBSEImageDataNoMessageBox();
  3026. //记录当前放大倍数 在停止拍摄图片后设置回原放大倍数
  3027. m_MeasureAppForm.m_ProjParam.GetWorkingSampleSEMData(ref m_PropIWDistance, ref m_PropDMagni);
  3028. GetSEMDATAMParameter(ref m_SEMDMagni, ref m_SEMIWDistance);
  3029. GetBSEPictures();
  3030. break;
  3031. case "DeleteBSEPicture":
  3032. DeleteHoleBSEImageData();
  3033. break;
  3034. }
  3035. }
  3036. protected override bool ProcessDialogKey(Keys keyData)
  3037. {
  3038. if (keyData == Keys.Up || keyData == Keys.Down || keyData == Keys.Left || keyData == Keys.Right)
  3039. {
  3040. return false;
  3041. }
  3042. else
  3043. {
  3044. return base.ProcessDialogKey(keyData);
  3045. }
  3046. }
  3047. private void OTSSamplespaceWindow_KeyDown(object sender, KeyEventArgs e)
  3048. {
  3049. KeyDowns();
  3050. }
  3051. private void OTSSamplespaceWindow_KeyUp(object sender, KeyEventArgs e)
  3052. {
  3053. //键盘抬起时,将选择区域的标识 设置为未选择状态
  3054. m_IsMeasure = false;
  3055. this.Cursor = System.Windows.Forms.Cursors.Default;
  3056. //删除正在绘制的多边形的点
  3057. if (e.KeyValue == (int)Keys.Back)
  3058. {
  3059. if (m_IsDrawMeasure)
  3060. {
  3061. if (m_PolygonPoint.Count > 0)
  3062. {
  3063. for (int i = m_PolygonPoint.Count - 1; i >= 0;)
  3064. {
  3065. m_PolygonPoint.RemoveAt(i);
  3066. break;
  3067. }
  3068. }
  3069. }
  3070. if (m_PolygonPoint.Count == 0)
  3071. {
  3072. //设置手绘标识
  3073. m_IsDrawMeasureReady = false;
  3074. m_IsDrawMeasure = false;
  3075. m_IsDrawPolygonFinish = false;
  3076. }
  3077. this.Invalidate();
  3078. }
  3079. }
  3080. public void KeyDowns()
  3081. {
  3082. //鼠标相对于屏幕的坐标
  3083. Point p1 = MousePosition;
  3084. //鼠标相对于窗体的坐标
  3085. Point p2 = this.PointToClient(p1);
  3086. Pen GrayPen = new Pen(Color.Gray, m_PenWidth);
  3087. //设置鼠标在样品测量区域上的样式
  3088. foreach (ARectangleGDIObject item in m_MeasureGDIObjects)
  3089. {
  3090. if (!item.SelColor.Name.Equals("Transparent"))
  3091. {
  3092. //判断鼠标是否在测量区域的绘制线上,更改光标样式
  3093. if (item.GPath != null)
  3094. {
  3095. if (item.CreateType == (int)CreateRectangleType.Polygon)
  3096. {
  3097. //在多边形点附近切换光标
  3098. foreach (PointF itemPoint in item.PolygonPointRegionF)
  3099. {
  3100. if (Math.Abs(itemPoint.X - p2.X) <= m_OffsetPX && Math.Abs(itemPoint.Y - p2.Y) <= m_OffsetPX)
  3101. {
  3102. if (Control.ModifierKeys == Keys.Control)
  3103. {
  3104. this.Cursor = System.Windows.Forms.Cursors.Hand;
  3105. return;
  3106. }
  3107. }
  3108. }
  3109. }
  3110. else
  3111. {
  3112. if (item.GPath.IsOutlineVisible(p2, GrayPen))
  3113. {
  3114. if (Control.ModifierKeys == Keys.Control)
  3115. {
  3116. this.Cursor = System.Windows.Forms.Cursors.NoMove2D;
  3117. return;
  3118. }
  3119. }
  3120. }
  3121. }
  3122. //判断鼠标是否在测量区域内,更改光标样式
  3123. if (item.GPath != null)
  3124. {
  3125. if (!m_IsSelPolygonPoint)
  3126. {
  3127. if (item.GPath.IsVisible(p2))
  3128. {
  3129. if (Control.ModifierKeys == Keys.Control)
  3130. {
  3131. if (!m_IsMeasure)
  3132. {
  3133. this.Cursor = System.Windows.Forms.Cursors.SizeAll;
  3134. return;
  3135. }
  3136. }
  3137. }
  3138. }
  3139. }
  3140. if (item.Region.Contains(p2))
  3141. {
  3142. if (!m_IsSelPolygonPoint)
  3143. {
  3144. if (Control.ModifierKeys == Keys.Control)
  3145. {
  3146. if (!m_IsMeasure)
  3147. {
  3148. this.Cursor = System.Windows.Forms.Cursors.SizeAll;
  3149. return;
  3150. }
  3151. }
  3152. }
  3153. }
  3154. }
  3155. }
  3156. //设置鼠标在样品上的样式
  3157. foreach (ARectangleGDIObject item in m_SampleGDIObjects)
  3158. {
  3159. if (!item.SelColor.Name.Equals("Transparent"))
  3160. {
  3161. if (item.Region.Contains(p2))
  3162. {
  3163. if ((Control.ModifierKeys == Keys.Alt))
  3164. {
  3165. if (!m_IsMeasure)
  3166. {
  3167. this.Cursor = System.Windows.Forms.Cursors.SizeAll;
  3168. return;
  3169. }
  3170. }
  3171. }
  3172. }
  3173. }
  3174. }
  3175. public void KeyUps()
  3176. {
  3177. //鼠标相对于屏幕的坐标
  3178. Point p1 = MousePosition;
  3179. //鼠标相对于窗体的坐标
  3180. Point p2 = this.PointToClient(p1);
  3181. Pen GrayPen = new Pen(Color.Gray, m_PenWidth);
  3182. foreach (ARectangleGDIObject item in m_RectangleGDIObjects)
  3183. {
  3184. if (item.Region.Contains(p2))
  3185. {
  3186. m_RectangIsDragging = true;
  3187. m_IsSelectSampleStage = true;
  3188. }
  3189. }
  3190. //键盘抬起时,将选择区域的标识 设置为未选择状态
  3191. m_IsMeasure = false;
  3192. this.Cursor = System.Windows.Forms.Cursors.Default;
  3193. }
  3194. #endregion
  3195. #region 处理方法总汇
  3196. #region 清除所需图形
  3197. public void ClearDrawInfoForChangeWindownSize()
  3198. {
  3199. try
  3200. {
  3201. if (m_RectangleGDIObjects != null)
  3202. {
  3203. m_RectangleGDIObjects.Clear();
  3204. }
  3205. if (m_SampleHoleGDIObjects != null)
  3206. {
  3207. m_SampleHoleGDIObjects.Clear();
  3208. }
  3209. if (m_SpecimenGDIObjects != null)
  3210. {
  3211. m_SpecimenGDIObjects.Clear();
  3212. }
  3213. if (m_ContentGDIObjects != null)
  3214. {
  3215. m_ContentGDIObjects.Clear();
  3216. }
  3217. }
  3218. catch (Exception ex)
  3219. {
  3220. string message = table["message2"].ToString();
  3221. log.Error("OTSSamplespaceWindow_ClearDrawInfo():--" + message + ":" + ex.ToString() + "");
  3222. }
  3223. }
  3224. public void ClearDrawInfo()
  3225. {
  3226. try
  3227. {
  3228. if (m_RectangleGDIObjects != null)
  3229. {
  3230. m_RectangleGDIObjects.Clear();
  3231. }
  3232. if (m_MeasureGDIObjects != null)
  3233. {
  3234. m_MeasureGDIObjects.Clear();
  3235. }
  3236. if (m_MeasurePathGDIObjects != null)
  3237. {
  3238. m_MeasurePathGDIObjects.Clear();
  3239. }
  3240. if (m_SampleGDIObjects != null)
  3241. {
  3242. m_SampleGDIObjects.Clear();
  3243. }
  3244. if (m_SampleHoleGDIObjects != null)
  3245. {
  3246. m_SampleHoleGDIObjects.Clear();
  3247. }
  3248. if (m_SpecimenGDIObjects != null)
  3249. {
  3250. m_SpecimenGDIObjects.Clear();
  3251. }
  3252. if (m_ContentGDIObjects != null)
  3253. {
  3254. m_ContentGDIObjects.Clear();
  3255. }
  3256. if (m_SingleGDIObjects != null)
  3257. {
  3258. m_SingleGDIObjects.Clear();
  3259. }
  3260. if (m_ImageGDIObjects != null)
  3261. {
  3262. m_ImageGDIObjects.Clear();
  3263. }
  3264. if (m_ImageSingleGDIObjects != null)
  3265. {
  3266. m_ImageSingleGDIObjects.Clear();
  3267. }
  3268. if (m_DrawMeasureGDIObjects != null)
  3269. {
  3270. m_DrawMeasureGDIObjects.Clear();
  3271. }
  3272. if (m_SEMCenterGDIObjects != null)
  3273. {
  3274. m_SEMCenterGDIObjects.Clear();
  3275. }
  3276. if (m_ALLSingleGDIObjects != null)
  3277. {
  3278. m_ALLSingleGDIObjects.Clear();
  3279. }
  3280. }
  3281. catch (Exception ex)
  3282. {
  3283. string message = table["message2"].ToString();
  3284. log.Error("OTSSamplespaceWindow_ClearDrawInfo():--" + message + ":" + ex.ToString() + "");
  3285. }
  3286. }
  3287. #endregion
  3288. #endregion
  3289. #region 绘制样品以及测量区域
  3290. /// <summary>
  3291. /// 绘制样品以及测量区域
  3292. /// </summary>
  3293. /// <param name="SMeasrueAreaList">测量区域的集合</param>
  3294. public void DrawSampleAndMeasureInfo(List<SampleMeasurePara> SMeasrueAreaList)
  3295. {
  3296. //获取样品孔
  3297. if (SMeasrueAreaList.Count > 0)
  3298. {
  3299. for (int i = 0; i < SMeasrueAreaList.Count; i++)
  3300. {
  3301. foreach (var item in m_SampleHoleGDIObjects)
  3302. {
  3303. if (item.Name == SMeasrueAreaList[i].sHoleName)
  3304. {
  3305. if (CStageManage.AddOnlySample(SMeasrueAreaList[i].sHoleName, SMeasrueAreaList[i].sSampleName, this))
  3306. {
  3307. //获取样品信息
  3308. Point xHole = new Point(SMeasrueAreaList[i].MeasureRect.Left, SMeasrueAreaList[i].MeasureRect.Top);
  3309. Point yHole = new Point(SMeasrueAreaList[i].MeasureRect.Right, SMeasrueAreaList[i].MeasureRect.Bottom);
  3310. //获取测量区域中的四个点位置
  3311. int left = Convert.ToInt32(OTSSamplespaceGraphicsPanelFun.MillimetersToPixelsWidth(m_WDomain, Convert.ToDouble(xHole.X), IsWidth, m_DefaultW, m_DefaultH));
  3312. int top = Convert.ToInt32(OTSSamplespaceGraphicsPanelFun.MillimetersToPixelsWidth(m_WDomain, Convert.ToDouble(xHole.Y), IsWidth, m_DefaultW, m_DefaultH));
  3313. int right = Convert.ToInt32(OTSSamplespaceGraphicsPanelFun.MillimetersToPixelsWidth(m_WDomain, Convert.ToDouble(yHole.X), IsWidth, m_DefaultW, m_DefaultH));
  3314. int bottom = Convert.ToInt32(OTSSamplespaceGraphicsPanelFun.MillimetersToPixelsWidth(m_WDomain, Convert.ToDouble(yHole.Y), IsWidth, m_DefaultW, m_DefaultH));
  3315. //生成测量区域的绘制点
  3316. Point StartPoint = new Point(Math.Abs(left), Math.Abs(top));
  3317. Size endPoint = new Size(Math.Abs(right), Math.Abs(bottom));
  3318. //定义测量区域
  3319. Rectangle rectMeasure = new Rectangle(StartPoint, endPoint);
  3320. //获取样品信息
  3321. Rectangle rectSample = new Rectangle();
  3322. Point sampleCenterDifferPoint = new Point();
  3323. foreach (var itemSample in m_SampleGDIObjects)
  3324. {
  3325. if (item.Name == itemSample.Name)
  3326. {
  3327. rectSample = item.Region;
  3328. //获取测量区域中心与样品中心相差的距离
  3329. sampleCenterDifferPoint = OTSSamplespaceGraphicsPanelFun.GetSampleCenterDifferCenterPoint(rectMeasure, rectSample);
  3330. break;
  3331. }
  3332. }
  3333. if (SMeasrueAreaList[i].iShape == (int)CreateRectangleType.Polygon)
  3334. {
  3335. //多边形测量区域完成标识
  3336. m_DrawPolygonFinishGDIObjects = new List<ARectangleGDIObject>();
  3337. //获取样品台 中心点
  3338. PointF RectanglePointCenter = OTSSamplespaceGraphicsPanelFun.GetCenterPointF(m_RectangleGDIObjects[0].RegionF);
  3339. //获取样品台中心点
  3340. int w = (IsWidth == 0 ? m_DefaultW : m_DefaultH);
  3341. float CenterX = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)RectanglePointCenter.X, m_WDomain, w);
  3342. float CenterY = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)RectanglePointCenter.Y, m_WDomain, w);
  3343. //绘制多边形测量区域
  3344. List<PointF> drawPointList = new List<PointF>();
  3345. for (int pointIndex = 0; pointIndex < SMeasrueAreaList[i].DrawPolygonPointRegionF.Count; pointIndex++)
  3346. {
  3347. float offX = CenterX + SMeasrueAreaList[i].PolygonPointRegionF[pointIndex].X;
  3348. float offY = CenterY - SMeasrueAreaList[i].PolygonPointRegionF[pointIndex].Y;
  3349. //获取测量区域中的四个点位置
  3350. float X = Convert.ToInt32(OTSSamplespaceGraphicsPanelFun.MillimetersToPixelsWidth(m_WDomain, Convert.ToDouble(offX), IsWidth, m_DefaultW, m_DefaultH));
  3351. float Y = Convert.ToInt32(OTSSamplespaceGraphicsPanelFun.MillimetersToPixelsWidth(m_WDomain, Convert.ToDouble(offY), IsWidth, m_DefaultW, m_DefaultH));
  3352. PointF DrawPoint = new PointF(X / m_GlobalZoomNum, Y / m_GlobalZoomNum);
  3353. drawPointList.Add(DrawPoint);
  3354. }
  3355. CreateRectangle createFinishPoint = new CreateRectangle(drawPointList, (int)CreateRectangleType.Polygon, m_DrawMeasureType, SMeasrueAreaList[i].sHoleName, SMeasrueAreaList[i].sSampleName, Color.Red);
  3356. GraphicsPath PolygonMeasurePath = new GraphicsPath();
  3357. PolygonMeasurePath.AddPolygon(drawPointList.ToArray());
  3358. createFinishPoint.GPath = PolygonMeasurePath;
  3359. m_DrawMeasureGDIObjects.Add(createFinishPoint);
  3360. //设置测量区域位置与尺寸
  3361. //获取外接矩形
  3362. Rectangle polygonRectPara = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(drawPointList);
  3363. m_DrawMeasureGDIObjects[0].Region = polygonRectPara;
  3364. m_DrawMeasureGDIObjects[0].RegionF = polygonRectPara;
  3365. m_DrawMeasureGDIObjects[0].DrawRegionF = polygonRectPara;
  3366. //将绘制好的多边形测量区域赋值给 多边形测量区域对象
  3367. m_MeasureGDIObjects.Add(m_DrawMeasureGDIObjects[0]);
  3368. m_DrawMeasureGDIObjects.Clear();
  3369. if (m_DrawPolygonFinishGDIObjects != null)
  3370. {
  3371. m_DrawPolygonFinishGDIObjects.Clear();
  3372. }
  3373. //设置手绘标识
  3374. m_IsDrawMeasureReady = false;
  3375. m_IsDrawMeasure = false;
  3376. m_IsDrawPolygonFinish = false;
  3377. break;
  3378. }
  3379. else
  3380. {
  3381. //正常绘制测量区域
  3382. CreateRectangle cRect = OTSSamplespaceGraphicsPanelFun.GetPixRect(m_WDomain, xHole, yHole, SMeasrueAreaList[i].iShape, "", "", IsWidth, m_DefaultW, m_DefaultH);
  3383. //测量区域名称 样品名称
  3384. cRect.SampleName = SMeasrueAreaList[i].sSampleName;
  3385. cRect.Name = SMeasrueAreaList[i].sHoleName;
  3386. //测量区域类型
  3387. cRect.CreateType = SMeasrueAreaList[i].iShape;
  3388. if (CStageManage.AddMeasure(cRect.CreateType, cRect))
  3389. {
  3390. break;
  3391. }
  3392. }
  3393. }
  3394. }
  3395. }
  3396. }
  3397. }
  3398. }
  3399. #endregion
  3400. #region 获取工作样品的测量区域信息
  3401. public SampleMeasurePara GetSampleMeasureRect(ARectangleGDIObject MeasureItem)
  3402. {
  3403. int w = (IsWidth == 0 ? Width : Height);
  3404. int iShape = 0;
  3405. Rectangle Srect = new Rectangle();
  3406. SampleMeasurePara sampleMeasureParas = new SampleMeasurePara();
  3407. //获取当前工作的测量区域信息
  3408. bool returnResult = m_MeasureAppForm.m_ProjParam.GetWSampleMrsArea(ref iShape, ref Srect);
  3409. sampleMeasureParas.iShape = iShape;
  3410. sampleMeasureParas.MeasureRect = Srect;
  3411. sampleMeasureParas.sHoleName = MeasureItem.Name;
  3412. sampleMeasureParas.sSampleName = MeasureItem.SampleName;
  3413. if (MeasureItem.CreateType == (int)CreateRectangleType.Polygon)
  3414. {
  3415. //获取测量区域中的四个点位置
  3416. float Left = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)MeasureItem.RegionF.Left, m_WDomain, w);
  3417. float Top = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)MeasureItem.RegionF.Top, m_WDomain, w);
  3418. float Right = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)MeasureItem.RegionF.Right, m_WDomain, w);
  3419. float Bottom = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)MeasureItem.RegionF.Bottom, m_WDomain, w);
  3420. float Widths = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)MeasureItem.RegionF.Width, m_WDomain, w);
  3421. float Height = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)MeasureItem.RegionF.Height, m_WDomain, w);
  3422. //生成测量区域的绘制点
  3423. Point StartPoint = new Point((int)Left, (int)Top);
  3424. Size endPoint = new Size((int)Right, (int)Bottom);
  3425. //定义测量区域
  3426. Rectangle rectMeasure = new Rectangle(StartPoint, endPoint);
  3427. sampleMeasureParas.PolygonPointRegion = MeasureItem.PolygonPointRegion;
  3428. sampleMeasureParas.PolygonPointRegionF = MeasureItem.PolygonPointRegionF;
  3429. sampleMeasureParas.DrawPolygonPointRegionF = MeasureItem.DrawPolygonPointRegionF;
  3430. }
  3431. return sampleMeasureParas;
  3432. }
  3433. /// <summary>
  3434. /// 获取所有测量区域的位置
  3435. /// </summary>
  3436. /// <param name="MeasureItem"></param>
  3437. /// <returns></returns>
  3438. public List<SampleMeasurePara> GetALLSampleMeasureRect()
  3439. {
  3440. Rectangle Srect = new Rectangle();
  3441. List<SampleMeasurePara> sampleMeasureParasList = new List<SampleMeasurePara>();
  3442. List<COTSSample> cSample = m_MeasureAppForm.m_ProjParam.m_ResultData.GetSampleList();
  3443. foreach (var item in cSample)
  3444. {
  3445. CDomain pMsrArea = new CDomain();
  3446. pMsrArea = item.GetMsrArea();
  3447. ValueType ValType = new Rectangle();
  3448. ValType = pMsrArea.GetRectDomain();
  3449. Srect = (Rectangle)ValType;
  3450. SampleMeasurePara sampleMeasureParas = new SampleMeasurePara();
  3451. sampleMeasureParas.iShape = (int)pMsrArea.GetShape();
  3452. sampleMeasureParas.MeasureRect = Srect;
  3453. sampleMeasureParas.sHoleName = item.GetSampleHoleName();
  3454. sampleMeasureParas.sSampleName = item.GetName();
  3455. List<Point> Points = item.GetMsrArea().GetPolygonPoint();
  3456. List<PointF> PointFs = OTSSamplespaceGraphicsPanelFun.PointConvertPointF(Points);
  3457. sampleMeasureParas.PolygonPointRegion = Points;
  3458. sampleMeasureParas.PolygonPointRegionF = PointFs;
  3459. sampleMeasureParas.DrawPolygonPointRegionF = PointFs;
  3460. sampleMeasureParasList.Add(sampleMeasureParas);
  3461. }
  3462. return sampleMeasureParasList;
  3463. }
  3464. #endregion
  3465. #region 获取帧图信息
  3466. public void GetSingleInfo()
  3467. {
  3468. #region 设置电镜参数
  3469. //判断是否为模拟模式
  3470. List<double> semParameters ;
  3471. //初始放大倍数与工作距离
  3472. #region 获取电镜参数
  3473. ////获取Field操作类对象
  3474. if (m_SEMDATAFieldManage == null)
  3475. {
  3476. m_SEMDATAFieldManage = new SEMDATAFieldManage(m_MeasureAppForm.m_ProjParam);
  3477. }
  3478. //判断是否连接电镜
  3479. if (m_SEMDATAFieldManage.InitAndConnection())
  3480. {
  3481. //获取电镜参数 放大倍数与工作距离 [Magnification]:放大倍数 [WorkingDistance]工作距离
  3482. semParameters = m_SEMDATAFieldManage.GetSEMMagAndWDParameter();
  3483. double mag = semParameters[0];
  3484. double wd = semParameters[1];
  3485. if (mag != 0 && wd != 0)
  3486. {
  3487. //设置样品文件中的电镜参数
  3488. m_MeasureAppForm.m_ProjParam.SetWorkingSampleSEMData(wd, mag);
  3489. //设置工作样品的测量区域 存在帧图
  3490. foreach (var MeasureItem in m_MeasureGDIObjects)
  3491. {
  3492. if (MeasureItem.IsWorkSample)
  3493. {
  3494. //设置工作样品的测量区域 存在帧图标识
  3495. MeasureItem.IsSingle = true;
  3496. break;
  3497. }
  3498. }
  3499. //将右键SEM数据菜单设置为可编辑状态
  3500. CMStrip.Items[(int)MenuIndex.SetSemData].Enabled = true;
  3501. }
  3502. //m_SEMDATAFieldManage.CloseSEM();
  3503. }
  3504. #endregion
  3505. #endregion
  3506. if (m_SingleGDIObjects != null)
  3507. {
  3508. showSingleInfo();
  3509. }
  3510. }
  3511. #region 获取Filed帧图
  3512. public List<Rectangle> GetFieldRects()
  3513. {
  3514. List<Point> listCenterPoint = new List<Point>();
  3515. Size rectSize = new Size();
  3516. //获取所有帧图的中心点信息 与矩形尺寸信息
  3517. bool flag = GetField(ref listCenterPoint, ref rectSize);
  3518. //将所有中心点 转换为矩形
  3519. List<Rectangle> returnRectList = new List<Rectangle>();
  3520. foreach (Point item in listCenterPoint)
  3521. {
  3522. returnRectList.Add(new Rectangle(item, rectSize));
  3523. }
  3524. return returnRectList;
  3525. }
  3526. public bool GetField(ref List<Point> pFields, ref Size iSzie)
  3527. {
  3528. var m_ResultData = m_MeasureAppForm.m_ProjParam.m_ResultData;
  3529. COTSSample WSample = m_ResultData.GetWorkingSample();
  3530. if (null == WSample)
  3531. {
  3532. return false;
  3533. }
  3534. CDomain pMsrArea = WSample.GetMsrArea();
  3535. //m_MeasureAppForm.m_ProjParam.m_ResultData.GetImageProcParam
  3536. COTSImgScanPrm pImgScanParam = WSample.GetMsrParams().GetImageScanParam();
  3537. CSEMDataMsr pSEMDataMsr = WSample.GetSEMDataMsr();
  3538. CFieldPositionMgr pFieldMgr = new CFieldPositionMgr();
  3539. List<Point> listPoint = new List<Point>();
  3540. listPoint.Clear();
  3541. //设置测量区域
  3542. if (m_MeasureAppForm.m_MessageStates == MessageState.ShotBSEPicture)
  3543. {
  3544. //获取最小放大倍数与FieldSize100倍数
  3545. pSEMDataMsr.SetScanFieldSize100(m_OTSSampleStageData.iScanFieldSize100);
  3546. double dMagnification = m_MeasureAppForm.m_ProjParam.m_DefaultParam.GetStageDataParam().GetMinMag();
  3547. pSEMDataMsr.SetMagnification(dMagnification);
  3548. //设置样品孔当前位置信息
  3549. Rectangle sampleHoleRect = CMeasureThreadWrapper.c_DomainMessure.GetRectDomain();
  3550. //判断
  3551. if ((int)this.CMStrip.Items[9].Tag == 1)
  3552. {
  3553. int shape = 0;
  3554. foreach (var item in m_SampleHoleGDIObjects)
  3555. {
  3556. if (item.Name == WSample.GetName())
  3557. {
  3558. shape = item.Shape;
  3559. }
  3560. }
  3561. pMsrArea.SetShape((DOMAIN_SHAPE)shape);
  3562. }
  3563. pMsrArea.SetRectDomain(sampleHoleRect);
  3564. }
  3565. else if (m_MeasureAppForm.m_MessageStates == MessageState.MeasureBSEPicture)
  3566. {
  3567. //获取最小放大倍数与FieldSize100倍数
  3568. pSEMDataMsr.SetScanFieldSize100(m_OTSSampleStageData.iScanFieldSize100);
  3569. double dMagnification = WSample.GetSEMDataMsr().GetMagnification();
  3570. pSEMDataMsr.SetMagnification(dMagnification);
  3571. //设置样品孔当前位置信息
  3572. Rectangle sampleHoleRect = CMeasureThreadWrapper.c_DomainMessure.GetRectDomain();
  3573. pMsrArea.SetRectDomain(sampleHoleRect);
  3574. }
  3575. else
  3576. {
  3577. try
  3578. {
  3579. //设置当前工作区域
  3580. if (CMeasureThreadWrapper.c_DomainMessure != null)
  3581. {
  3582. Rectangle measureRect = CMeasureThreadWrapper.c_DomainMessure.GetRectDomain();
  3583. pMsrArea.SetRectDomain(measureRect);
  3584. }
  3585. }
  3586. catch (Exception ex)
  3587. {
  3588. log.Error("获取幁图数问题:" + ex.ToString());
  3589. }
  3590. pSEMDataMsr.SetScanFieldSize100(m_OTSSampleStageData.iScanFieldSize100);
  3591. double dMagnification = WSample.GetSEMDataMsr().GetMagnification();
  3592. pSEMDataMsr.SetMagnification(dMagnification);
  3593. }
  3594. ////初始化
  3595. if (!pFieldMgr.Init(pMsrArea, pImgScanParam, pSEMDataMsr, listPoint))
  3596. {
  3597. return false;
  3598. }
  3599. //获取幁图的中心点
  3600. pFields = pFieldMgr.GetFieldCentrePoints();
  3601. //获取幁图数
  3602. int iFieldCount = pFieldMgr.GetTotalFields();
  3603. var oValue = new Rectangle();
  3604. if (!pFieldMgr.GetFieldRectByIndex(0, ref oValue))
  3605. {
  3606. return false;
  3607. }
  3608. iSzie = oValue.Size;
  3609. //将幁图数赋值给工作样品后
  3610. WSample.GetSEMDataMsr().SetTotalFields(iFieldCount);
  3611. return true;
  3612. }
  3613. #endregion
  3614. public void showSingleInfo()
  3615. {
  3616. try
  3617. {
  3618. if (m_SingleGDIObjects == null)
  3619. {
  3620. return;
  3621. }
  3622. //清除帧图信息
  3623. ClearImageAndSingleGDIObjects();
  3624. #region 获取帧图与绘制帧图
  3625. #region 获取当前工作的测量区域信息
  3626. //是否获取过帧图标识
  3627. bool IsSingle = false;
  3628. if (m_MeasureAppForm.m_MessageStates == (int)MessageState.StartMeasure)
  3629. {
  3630. //设置测量区域形状与位置
  3631. IsSingle = SetWorkSampleMeasureArea();
  3632. if (!IsSingle)
  3633. {
  3634. return;
  3635. }
  3636. }
  3637. #endregion
  3638. //获取Field集合
  3639. m_RectFieldRects = GetFieldRects();
  3640. if (m_MeasureAppForm.m_MessageStates == (int)MessageState.StartMeasure)
  3641. {
  3642. m_MeasureAppForm.UpdatePropertyVal();
  3643. }
  3644. //如果当前工作样品是多边形则设置回原测量区域参数
  3645. if (IsSingle)
  3646. {
  3647. foreach (var MeasureItem in m_MeasureGDIObjects)
  3648. {
  3649. if (MeasureItem.IsSingle && MeasureItem.IsWorkSample)
  3650. {
  3651. if (MeasureItem.CreateType == (int)CreateRectangleType.Polygon)
  3652. {
  3653. SetWorkSampleMeasureArea((int)CreateRectangleType.Polygon);
  3654. }
  3655. }
  3656. }
  3657. }
  3658. //样品孔名称与样品名称
  3659. string sampleName = string.Empty;
  3660. string sampleHoleName = string.Empty;
  3661. //获取样品孔 与 样品名称
  3662. foreach (var item in m_SampleGDIObjects)
  3663. {
  3664. if (item.IsWorkSample)
  3665. {
  3666. sampleName = item.SampleName;
  3667. sampleHoleName = item.Name;
  3668. }
  3669. }
  3670. //以矩形绘制帧图
  3671. for (int i = m_RectFieldRects.Count - 1; i >= 0; i--)
  3672. {
  3673. Point pt = new Point(m_RectFieldRects[i].X, m_RectFieldRects[i].Y);
  3674. pt.X = m_RectFieldRects[i].X - m_RectFieldRects[i].Width / 2;
  3675. pt.Y = m_RectFieldRects[i].Y + m_RectFieldRects[i].Height / 2;
  3676. //获取Rectang 两点信息
  3677. Point XSTD = new Point(m_RectFieldRects[i].Left, m_RectFieldRects[i].Top);
  3678. Point YSTD = new Point(m_RectFieldRects[i].Right, m_RectFieldRects[i].Bottom);
  3679. //绘制帧图
  3680. RectangleF rectSingle = OTSSamplespaceGraphicsPanelFun.GetPixRectF(m_WDomain, XSTD, YSTD, sampleName, sampleHoleName, IsWidth, Width, Height);
  3681. //设置每一个帧图的宽与高 以中心点大小为标准
  3682. rectSingle = new RectangleF(new PointF(rectSingle.X, rectSingle.Y), new SizeF(rectSingle.Width, rectSingle.Height));
  3683. //添加所有转换后的RectangleF
  3684. //根据缩放倍数
  3685. float xZoom = (rectSingle.X * m_GlobalZoomNum);
  3686. float yZoom = (rectSingle.Y * m_GlobalZoomNum);
  3687. float widthZoom = (rectSingle.Width * m_GlobalZoomNum);
  3688. float heightZoom = (rectSingle.Height * m_GlobalZoomNum);
  3689. RectangleF rectZoomSingle = new RectangleF(xZoom, yZoom, widthZoom, heightZoom);
  3690. //设置颜色
  3691. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SingleColor);
  3692. CreateRectangle createRect = new CreateRectangle(rectZoomSingle, m_RectFieldRects[i].X, m_RectFieldRects[i].Y, (int)CreateRectangleType.SingleRectangle, sampleHoleName, sampleName, ColorTranslator.FromHtml(ColorStr));
  3693. //如果选择为测量区域BSE照片 则添加样品名称
  3694. if (CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag != null)
  3695. {
  3696. if ((int)CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag == (int)MessageState.StartMeasure)
  3697. {
  3698. createRect.SampleName = sampleName;
  3699. }
  3700. }
  3701. createRect.Name = sampleHoleName;
  3702. //保留原帧图位置与大小
  3703. createRect.RegionF = rectZoomSingle;
  3704. createRect.DrawRegionF = rectSingle;
  3705. //拍摄样品孔照片
  3706. if (m_MeasureAppForm.m_MessageStates == MessageState.ShotBSEPicture)
  3707. {
  3708. //添加样品孔图片列表
  3709. m_ImageSingleGDIObjects.Add(createRect);
  3710. }
  3711. else if (m_MeasureAppForm.m_MessageStates == (int)MessageState.StartMeasure)
  3712. {
  3713. //添加帧图列表
  3714. m_SingleGDIObjects.Add(createRect);
  3715. }
  3716. }
  3717. if (m_MeasureAppForm.m_MessageStates == (int)MessageState.StartMeasure)
  3718. {
  3719. //添加帧图信息
  3720. OTSSamplespaceGraphicsPanelFun.DeleteALLSingleInfo(m_ALLSingleGDIObjects, sampleName);
  3721. OTSSamplespaceGraphicsPanelFun.AddALLSingleInfo(m_ALLSingleGDIObjects, m_SingleGDIObjects, sampleName);
  3722. }
  3723. //将所有帧图移植测量区域位置中
  3724. //获取样品孔 与 样品名称
  3725. foreach (var item in m_SampleGDIObjects)
  3726. {
  3727. if (item.IsWorkSample)
  3728. {
  3729. sampleName = item.SampleName;
  3730. sampleHoleName = item.Name;
  3731. if (m_MeasureAppForm.m_MessageStates == (int)MessageState.StartMeasure)
  3732. {
  3733. //设置工作样品的测量区域 存在帧图
  3734. foreach (var MeasureItem in m_MeasureGDIObjects)
  3735. {
  3736. if (MeasureItem.SampleName == item.SampleName)
  3737. {
  3738. //设置工作样品的测量区域 存在帧图标识
  3739. if (m_SingleGDIObjects.Count > 0)
  3740. {
  3741. //if (!(MeasureItem.CreateType == (int)CreateRectangleType.Polygon))
  3742. //{
  3743. OTSSamplespaceGraphicsPanelFun.SetSingleLocationToMeasureLocation(m_SingleGDIObjects, MeasureItem);
  3744. //}
  3745. }
  3746. break;
  3747. }
  3748. }
  3749. }
  3750. if (m_MeasureAppForm.m_MessageStates == MessageState.ShotBSEPicture)
  3751. {
  3752. if (CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag != null)
  3753. {
  3754. if ((int)CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag == (int)(int)MessageState.ShotBSEPicture)
  3755. {
  3756. //设置工作样品的测量区域 存在帧图
  3757. foreach (var SampleHoleItem in m_SampleHoleGDIObjects)
  3758. {
  3759. if (SampleHoleItem.Name == item.Name)
  3760. {
  3761. //设置工作样品的测量区域 存在帧图标识
  3762. if (m_ImageSingleGDIObjects.Count > 0)
  3763. {
  3764. OTSSamplespaceGraphicsPanelFun.SetSingleLocationToMeasureLocation(m_ImageSingleGDIObjects, SampleHoleItem);
  3765. }
  3766. break;
  3767. }
  3768. }
  3769. }
  3770. else
  3771. {
  3772. //设置工作样品的测量区域 存在帧图
  3773. foreach (var MeasureItem in m_MeasureGDIObjects)
  3774. {
  3775. if (MeasureItem.SampleName == item.SampleName)
  3776. {
  3777. //设置工作样品的测量区域 存在帧图标识
  3778. if (m_ImageSingleGDIObjects.Count > 0)
  3779. {
  3780. OTSSamplespaceGraphicsPanelFun.SetSingleLocationToMeasureLocation(m_ImageSingleGDIObjects, MeasureItem);
  3781. }
  3782. break;
  3783. }
  3784. }
  3785. }
  3786. }
  3787. }
  3788. }
  3789. }
  3790. Invalidate();
  3791. #endregion
  3792. }
  3793. catch (Exception ex)
  3794. {
  3795. string message = table["message2"].ToString();
  3796. log.Error("OTSSamplespaceWindow_CMStrip_ItemClicked:--" + message + ":" + ex.ToString());
  3797. }
  3798. }
  3799. #endregion
  3800. #region 设置SEM数据
  3801. public bool SetSEMDATAMParameter(double magnification, double semWorkingDistance)
  3802. {
  3803. #region 获取电镜参数
  3804. //获取Field操作类对象
  3805. if (m_SEMDATAFieldManage == null)
  3806. {
  3807. m_SEMDATAFieldManage = new SEMDATAFieldManage(m_MeasureAppForm.m_ProjParam);
  3808. }
  3809. //判断是否连接电镜
  3810. if (m_SEMDATAFieldManage.InitAndConnection())
  3811. {
  3812. //获取电镜参数
  3813. List<double> semParameters = m_SEMDATAFieldManage.GetSEMMagAndWDParameter();
  3814. bool mFlag = false;
  3815. bool wFlag = false;
  3816. mFlag = m_SEMDATAFieldManage.SetSEMMagnificationParameter(magnification);
  3817. wFlag = m_SEMDATAFieldManage.SetSEMWorkingDistanceParameter(semWorkingDistance);
  3818. if (mFlag || wFlag)
  3819. {
  3820. return true;
  3821. }
  3822. //m_SEMDATAFieldManage.CloseSEM();
  3823. }
  3824. return false;
  3825. #endregion
  3826. }
  3827. public bool GetSEMDATAMParameter(ref double magnification, ref double WorkingDistance)
  3828. {
  3829. #region 获取电镜参数
  3830. //获取Field操作类对象
  3831. if (m_SEMDATAFieldManage == null)
  3832. {
  3833. m_SEMDATAFieldManage = new SEMDATAFieldManage(m_MeasureAppForm.m_ProjParam);
  3834. }
  3835. //判断是否连接电镜
  3836. if (m_SEMDATAFieldManage.InitAndConnection())
  3837. {
  3838. //获取电镜参数
  3839. List<double> semParameters = m_SEMDATAFieldManage.GetSEMMagAndWDParameter();
  3840. //放大倍数
  3841. magnification = semParameters[0];
  3842. WorkingDistance = semParameters[1];
  3843. //m_SEMDATAFieldManage.CloseSEM();
  3844. return true;
  3845. }
  3846. return false;
  3847. #endregion
  3848. }
  3849. #endregion
  3850. #region 驱动到SEM当前位置
  3851. protected void SetMeasureToSEMLocation()
  3852. {
  3853. try
  3854. {
  3855. //获取SEM位置
  3856. List<double> SemLocation = new List<double>();
  3857. if (GetSemLocation(ref SemLocation))
  3858. {
  3859. //SemLocation[0] = 60000;
  3860. //SemLocation[1] = 60000;
  3861. Point OTSLocation = m_MeasureAppForm.m_ProjParam.ConverSEMToOTSPoint(new Point((int)SemLocation[(int)XYIndex.X], (int)SemLocation[(int)XYIndex.Y]));
  3862. //转换为工作区域位置坐标
  3863. int w = (int)OTSSamplespaceGraphicsPanelFun.MillimetersToPixelsWidth(m_WDomain, Convert.ToDouble(OTSLocation.X), IsWidth, m_DefaultW, m_DefaultH);
  3864. int h = (int)OTSSamplespaceGraphicsPanelFun.MillimetersToPixelsWidth(m_WDomain, Convert.ToDouble(OTSLocation.Y), IsWidth, m_DefaultW, m_DefaultH);
  3865. //样品台中心点
  3866. Point m_StageCenterPoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(m_RectangleGDIObjects[0]);
  3867. Point moveToSEMLocation = new Point(w, h);
  3868. //根据鼠标右键点击的位置 重新绘制帧图
  3869. if (m_MeasureGDIObjects != null)
  3870. {
  3871. if (m_MeasureGDIObjects.Count > 0)
  3872. {
  3873. foreach (var MeasureItem in m_MeasureGDIObjects)
  3874. {
  3875. if (MeasureItem.IsWorkSample)
  3876. {
  3877. bool selWSampleMeasureStatus = m_MeasureAppForm.m_ProjParam.GetWorkSampleMeasureStatus();
  3878. if (selWSampleMeasureStatus)
  3879. {
  3880. return;
  3881. }
  3882. if (MoveMeasureInStage(MeasureItem, m_StageCenterPoint, moveToSEMLocation, m_GlobalZoomNum))
  3883. {
  3884. if (OTSSamplespaceGraphicsPanelFun.NewLocationDrawSingleInfo(m_MeasureAppForm, this, m_RectangleGDIObjects, m_OTSSampleStageData, IsWidth, moveToSEMLocation, m_SingleGDIObjects, MeasureItem, m_GlobalZoomNum))
  3885. {
  3886. //根据鼠标右键点击的位置 重新绘制区域
  3887. OTSSamplespaceGraphicsPanelFun.NewLocationDrawMeasureInfo(this, m_RectangleGDIObjects, m_OTSSampleStageData, IsWidth, moveToSEMLocation, m_MeasureGDIObjects, m_GlobalZoomNum);
  3888. //根据鼠标右键点击的位置 重新绘制区域路径
  3889. OTSSamplespaceGraphicsPanelFun.NewLocationDrawMeasureInfo(this, m_RectangleGDIObjects, m_OTSSampleStageData, IsWidth, moveToSEMLocation, m_MeasurePathGDIObjects, m_GlobalZoomNum);
  3890. //设置当前测量区域的位置
  3891. bool result = OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(MeasureItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain);
  3892. //删除已存在的帧图信息 在重新添加当前操作的帧图信息
  3893. OTSSamplespaceGraphicsPanelFun.DeleteALLSingleInfo(m_ALLSingleGDIObjects, MeasureItem.SampleName);
  3894. OTSSamplespaceGraphicsPanelFun.AddALLSingleInfo(m_ALLSingleGDIObjects, m_SingleGDIObjects, MeasureItem.SampleName);
  3895. break;
  3896. }
  3897. }
  3898. else
  3899. {
  3900. MessageBox.Show(table["message12"].ToString(), table["message11"].ToString());
  3901. return;
  3902. }
  3903. }
  3904. }
  3905. }
  3906. }
  3907. }
  3908. Invalidate();
  3909. }
  3910. catch (Exception ex)
  3911. {
  3912. string message = table["message2"].ToString();
  3913. log.Error("OTSSamplespaceWindow_SetSEMCenterLocation_" + message + ":" + ex.ToString());
  3914. }
  3915. }
  3916. #endregion
  3917. #region 驱动SEM到当前位置
  3918. public bool SetSEMCurrentLocation()
  3919. {
  3920. bool bret=false;
  3921. //获取Field操作类对象
  3922. if (m_SEMDATAFieldManage == null)
  3923. {
  3924. m_SEMDATAFieldManage = new SEMDATAFieldManage(m_MeasureAppForm.m_ProjParam);
  3925. }
  3926. //判断是否连接电镜
  3927. if (m_SEMDATAFieldManage.InitAndConnection())
  3928. {
  3929. bret = m_SEMDATAFieldManage.SetSEMCurrentLocation(m_MouseDownLocation, m_RectangleGDIObjects, m_OTSSampleStageData, IsWidth, Width, Height);
  3930. //m_SEMDATAFieldManage.CloseSEM();
  3931. }
  3932. return bret;
  3933. }
  3934. #endregion
  3935. #region 设置SEM到中心
  3936. public bool SetSEMToCenterPoint()
  3937. {
  3938. try
  3939. {
  3940. //获取Field操作类对象
  3941. if (m_SEMDATAFieldManage == null)
  3942. {
  3943. m_SEMDATAFieldManage = new SEMDATAFieldManage(m_MeasureAppForm.m_ProjParam);
  3944. }
  3945. //判断是否连接电镜
  3946. bool bret = false;
  3947. if (m_SEMDATAFieldManage.InitAndConnection())
  3948. {
  3949. bret = (m_SEMDATAFieldManage.DriveSEMToLocation(m_MouseDownLocation, m_RectangleGDIObjects, m_SingleGDIObjects, m_OTSSampleStageData, IsWidth, Width, Height));
  3950. //m_SEMDATAFieldManage.CloseSEM();
  3951. }
  3952. return bret;
  3953. }
  3954. catch (Exception ex)
  3955. {
  3956. log.Error("OTSSamplespaceWindow_" + "SetSEMToCenterPoint" + ":" + ex.ToString() + "");
  3957. return false;
  3958. }
  3959. }
  3960. #endregion
  3961. #region 获取SEM当前位置
  3962. public bool GetSemLocation(ref List<double> SemLocation)
  3963. {
  3964. //获取Field操作类对象
  3965. if (m_SEMDATAFieldManage == null)
  3966. {
  3967. m_SEMDATAFieldManage = new SEMDATAFieldManage(m_MeasureAppForm.m_ProjParam);
  3968. }
  3969. //判断是否连接电镜
  3970. bool bret=false;
  3971. if (m_SEMDATAFieldManage.InitAndConnection())
  3972. {
  3973. bret = m_SEMDATAFieldManage.GetSemLocation(ref SemLocation);
  3974. //m_SEMDATAFieldManage.CloseSEM();
  3975. }
  3976. return bret;
  3977. }
  3978. #endregion
  3979. #region 根据已完成测量的帧图信息 绘制帧图已完成状态
  3980. /// <summary>
  3981. /// 根据已完成测量的帧图信息 绘制帧图已完成状态
  3982. /// </summary>
  3983. public void GetSingleInfoForSampleNameAndOTSSamplespaceWindow()
  3984. {
  3985. #region 根据已完成测量的帧图信息 绘制帧图已完成状态
  3986. //获取完成帧图信息的方法返回布尔值
  3987. bool GetBeforeCompleteFieldResult = false;
  3988. //当前测量名称
  3989. string msrSampleName = string.Empty;
  3990. //已完成的帧图坐标中心信息列表
  3991. List<Point> CompleteFieldList = new List<Point>();
  3992. GetBeforeCompleteFieldResult = m_MeasureAppForm.m_ProjParam.GetBeforeCompleteField(ref msrSampleName, ref CompleteFieldList);
  3993. //如果获取的返回值为false
  3994. if (!GetBeforeCompleteFieldResult)
  3995. {
  3996. return;
  3997. }
  3998. else
  3999. {
  4000. //如果当前工作样品名称与返回的工作样品名称一致
  4001. if (m_SampleSelectName.Equals(msrSampleName))
  4002. {
  4003. //如果已完成的帧图数量为0
  4004. if (CompleteFieldList.Count == 0)
  4005. {
  4006. //重新加载帧图信息
  4007. }
  4008. else
  4009. {
  4010. //绘制已完成的帧图信息
  4011. OTSMeasureDisplayResult.ChangeCompleteFieldMeasureState(CompleteFieldList, Color.Green, m_MeasureAppForm);
  4012. }
  4013. }
  4014. }
  4015. #endregion
  4016. }
  4017. #endregion
  4018. #region 连接电镜连接
  4019. public bool ConnectToSEM()
  4020. {
  4021. if (m_SEMDATAFieldManage == null)
  4022. {
  4023. m_SEMDATAFieldManage = new SEMDATAFieldManage(m_MeasureAppForm.m_ProjParam);
  4024. }
  4025. //连接电镜连接
  4026. bool result = m_SEMDATAFieldManage.InitAndConnection();
  4027. return result;
  4028. }
  4029. public bool ConnectionSEM(ref SEMDATAFieldManage m_SEMDATAFieldManage)
  4030. {
  4031. if (m_SEMDATAFieldManage == null)
  4032. {
  4033. m_SEMDATAFieldManage = new SEMDATAFieldManage(m_MeasureAppForm.m_ProjParam);
  4034. }
  4035. //string message = table["message6"].ToString();
  4036. //连接电镜连接
  4037. log.Trace("--" + "connect to SEM" + "--");
  4038. bool result = m_SEMDATAFieldManage.InitAndConnection();
  4039. if (result)
  4040. {
  4041. log.Trace("--" + "connect succeed" + ":True--");
  4042. }
  4043. return result;
  4044. }
  4045. #endregion
  4046. #region 显示标尺
  4047. /// <summary>
  4048. /// 是否显示标尺控件
  4049. /// </summary>
  4050. /// <param name="b_show"></param>
  4051. public void ShowRulerLocation()
  4052. {
  4053. //设置标尺位置
  4054. Point rulerLocation = new Point(10, this.Height - (int)(control_Ruler2.Height * 2));
  4055. this.control_Ruler2.Location = rulerLocation;
  4056. if (control_Ruler2.Visible)
  4057. {
  4058. //显示
  4059. control_Ruler2.Visible = false;
  4060. }
  4061. else
  4062. {
  4063. //显示
  4064. control_Ruler2.Visible = true;
  4065. control_Ruler2.ShowString = "1000um";
  4066. f_ruler_size = f_ruler_size + Convert.ToInt32(f_old_ruler_size * f_zoom_increment);
  4067. control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);
  4068. control_Ruler2.SetValueInspector(f_ruler_size, ((Convert.ToDouble(m_OTSSampleStageData.StageDomain.Width) / Convert.ToDouble(54)) / 10));
  4069. }
  4070. }
  4071. public void RulerInit()
  4072. {
  4073. control_Ruler2.ShowString = "100um";
  4074. control_Ruler2.Width = 130;
  4075. }
  4076. #endregion
  4077. #region 隐藏与显示样品台中的文字
  4078. static bool IsShowSampleHoleFont = true;
  4079. public void ChangeSampleHoleFont()
  4080. {
  4081. IsShowSampleHoleFont = IsShowSampleHoleFont ? false : true;
  4082. Invalidate();
  4083. }
  4084. #endregion
  4085. #region 隐藏与显示样品孔照片
  4086. static bool IsShowSampleHoleImage = true;
  4087. public void ChangeSampleHoleImage()
  4088. {
  4089. IsShowSampleHoleImage = IsShowSampleHoleImage ? false : true;
  4090. Invalidate();
  4091. }
  4092. #endregion
  4093. #region 添加样品孔中BSE图像信息
  4094. public void AddHoleBSEImageData(byte[] ImageData, int width, int height, Point fieldPos)
  4095. {
  4096. //获取样品孔名称
  4097. string sampleHoleName = string.Empty;
  4098. ARectangleGDIObject itemWorkSample = null;
  4099. foreach (ARectangleGDIObject item in m_SampleGDIObjects)
  4100. {
  4101. if (item.IsWorkSample)
  4102. {
  4103. sampleHoleName = item.Name;
  4104. itemWorkSample = item;
  4105. break;
  4106. }
  4107. }
  4108. //获取样品孔BSE图像
  4109. Image bseImage = null;
  4110. int m_iWidth = width;
  4111. int m_iHeigh = height;
  4112. RectangleF ImgRegionF = new RectangleF();
  4113. float ImgRegionWidth = 0;
  4114. float ImgRegionHeight = 0;
  4115. if (m_ImageSingleGDIObjects.Count > 0)
  4116. {
  4117. for (int i = 0; i < m_ImageSingleGDIObjects.Count; i++)
  4118. {
  4119. if (m_ImageSingleGDIObjects[i].OTSX == fieldPos.X && m_ImageSingleGDIObjects[i].OTSY == fieldPos.Y)
  4120. {
  4121. ImgRegionF = m_ImageSingleGDIObjects[i].RegionF;
  4122. ImgRegionWidth = Convert.ToInt32(m_ImageSingleGDIObjects[i].RegionF.Width);
  4123. ImgRegionHeight = Convert.ToInt32(m_ImageSingleGDIObjects[i].RegionF.Height);
  4124. //获取图片
  4125. bseImage = OTSSysMgrTools.Imagepro.ToGrayBitmap(ImageData, m_iWidth, m_iHeigh);
  4126. //获取工作样品位置
  4127. Point drawImageLocation = itemWorkSample.Region.Location;
  4128. //绘制图像
  4129. CreateRectangle createImageRect = new CreateRectangle(ImgRegionF, fieldPos.X, fieldPos.Y, itemWorkSample.SampleName, itemWorkSample.Name, bseImage, ImgRegionWidth, ImgRegionHeight, drawImageLocation, (int)CreateRectangleType.DrawSampleHoleBSEImage);
  4130. //添加至List集合中
  4131. createImageRect.DrawRegionF = m_ImageSingleGDIObjects[i].DrawRegionF;
  4132. createImageRect.RegionF = m_ImageSingleGDIObjects[i].RegionF;
  4133. createImageRect.Region = m_ImageSingleGDIObjects[i].Region;
  4134. createImageRect.Name = m_ImageSingleGDIObjects[i].Name;
  4135. m_ImageGDIObjects.Add(createImageRect);
  4136. break;
  4137. }
  4138. }
  4139. }
  4140. //显示样品孔照片
  4141. IsShowSampleHoleImage = true;
  4142. Invalidate();
  4143. }
  4144. #endregion
  4145. #region 删除样品孔中BSE图像信息
  4146. public void DeleteHoleBSEImageData()
  4147. {
  4148. try
  4149. {
  4150. //鼠标右键点击的位置坐标
  4151. Point mouseCurrent = m_MouseDownLocation;
  4152. //样品名称
  4153. string SampleName = "";
  4154. //获取当前工作样品并删除对应BSE图
  4155. foreach (ARectangleGDIObject ImageItem in m_ImageGDIObjects)
  4156. {
  4157. if (ImageItem.Region.Contains(mouseCurrent))
  4158. {
  4159. SampleName = ImageItem.SampleName;
  4160. break;
  4161. }
  4162. }
  4163. if (SampleName != null && !SampleName.Equals(""))
  4164. {
  4165. string message = table["message7"].ToString();
  4166. if (MessageBox.Show(message, "Tip", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  4167. {
  4168. CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag = MessageState.StartMeasure;
  4169. DeleteHoleBSEImageDataNoMessageBox();
  4170. return;
  4171. }
  4172. else
  4173. {
  4174. return;
  4175. }
  4176. }
  4177. //删除样品孔BSE图
  4178. //样品孔名称
  4179. string HoleName = "";
  4180. foreach (ARectangleGDIObject item in m_SampleHoleGDIObjects)
  4181. {
  4182. if (item.Region.Contains(mouseCurrent))
  4183. {
  4184. HoleName = item.Name;
  4185. break;
  4186. }
  4187. }
  4188. if (HoleName != null && !HoleName.Equals(""))
  4189. {
  4190. string message = table["message8"].ToString();
  4191. if (MessageBox.Show(message, "Tip", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  4192. {
  4193. CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag = MessageState.ShotBSEPicture;
  4194. DeleteHoleBSEImageDataNoMessageBox();
  4195. return;
  4196. }
  4197. else
  4198. {
  4199. return;
  4200. }
  4201. }
  4202. }
  4203. catch (Exception ex)
  4204. {
  4205. string message = table["message9"].ToString();
  4206. log.Trace(message + ex.ToString());
  4207. }
  4208. }
  4209. public void DeleteHoleBSEImageDataNoMessageBox()
  4210. {
  4211. try
  4212. {
  4213. if (CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag != null)
  4214. {
  4215. if ((int)CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag == (int)MessageState.ShotBSEPicture)
  4216. {
  4217. string HoleName = string.Empty;
  4218. //鼠标右键点击的位置坐标
  4219. Point mouseCurrent = m_MouseDownLocation;
  4220. //获取当前工作样品并删除对应BSE图
  4221. foreach (ARectangleGDIObject item in m_SampleHoleGDIObjects)
  4222. {
  4223. if (item.Region.Contains(mouseCurrent))
  4224. {
  4225. HoleName = item.Name;
  4226. break;
  4227. }
  4228. }
  4229. if (!HoleName.Equals(""))
  4230. {
  4231. for (int i = m_ImageGDIObjects.Count - 1; i >= 0; i--)
  4232. {
  4233. if (m_ImageGDIObjects[i].Name == HoleName && m_ImageGDIObjects[i].SampleName == null)
  4234. {
  4235. m_ImageGDIObjects.RemoveAt(i);
  4236. }
  4237. }
  4238. for (int i = m_ImageSingleGDIObjects.Count - 1; i >= 0; i--)
  4239. {
  4240. if (m_ImageSingleGDIObjects[i].Name == HoleName && m_ImageGDIObjects[i].SampleName == null)
  4241. {
  4242. m_ImageSingleGDIObjects.RemoveAt(i);
  4243. }
  4244. }
  4245. Invalidate();
  4246. }
  4247. }
  4248. else
  4249. {
  4250. string SampleName = string.Empty;
  4251. //鼠标右键点击的位置坐标
  4252. Point mouseCurrent = m_MouseDownLocation;
  4253. //获取当前工作样品并删除对应BSE图
  4254. foreach (ARectangleGDIObject item in m_ImageGDIObjects)
  4255. {
  4256. if (item.Region.Contains(mouseCurrent))
  4257. {
  4258. SampleName = item.SampleName;
  4259. break;
  4260. }
  4261. }
  4262. if (!SampleName.Equals(""))
  4263. {
  4264. for (int i = m_ImageGDIObjects.Count - 1; i >= 0; i--)
  4265. {
  4266. if (m_ImageGDIObjects[i].SampleName == SampleName)
  4267. {
  4268. m_ImageGDIObjects.RemoveAt(i);
  4269. }
  4270. }
  4271. for (int i = m_ImageSingleGDIObjects.Count - 1; i >= 0; i--)
  4272. {
  4273. if (m_ImageSingleGDIObjects[i].SampleName == SampleName)
  4274. {
  4275. m_ImageSingleGDIObjects.RemoveAt(i);
  4276. }
  4277. }
  4278. Invalidate();
  4279. }
  4280. }
  4281. }
  4282. }
  4283. catch (Exception)
  4284. {
  4285. }
  4286. }
  4287. #endregion
  4288. #region 获取样品孔图片
  4289. public void GetBSEPictures()
  4290. {
  4291. //获取当前工作的测量区域信息
  4292. CDomain cDomain = new CDomain();
  4293. DOMAIN_SHAPE iShape = 0;
  4294. Rectangle Srect = new Rectangle();
  4295. //拍摄样品孔BSE照片
  4296. if (CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag != null)
  4297. {
  4298. if ((int)CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag == (int)MessageState.ShotBSEPicture)
  4299. {
  4300. //获取当前样品孔的索引 与 样品中对应的测量区域
  4301. OTSSampleHoleInfo sampleHoleInfo = null;
  4302. int sampleHoleIndex = OTSSamplespaceGraphicsPanelFun.GetSampleHoleIndex(m_OTSSampleStageData, m_SampleHoleSelectName, ref sampleHoleInfo);
  4303. if (sampleHoleInfo != null)
  4304. {
  4305. foreach (var sampleHoleItem in m_SampleHoleGDIObjects)
  4306. {
  4307. if (sampleHoleItem.Name == sampleHoleInfo.sSHoleName)
  4308. {
  4309. SampleHolePara sampleHolePara = OTSSamplespaceGraphicsPanelFun.GetSampleHoleRect(sampleHoleItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain);
  4310. iShape = (DOMAIN_SHAPE)sampleHolePara.iShape;
  4311. Srect = sampleHolePara.SampleHoleRect;
  4312. //设置测量区域形状
  4313. cDomain.SetShape(iShape);
  4314. cDomain.SetRectDomain(Srect);
  4315. //开始获取样品孔中的照片
  4316. m_MeasureAppForm.StartSampleHoleBSEImage((int)MSR_THREAD_RunSTATUS.RUNSampleHoleImage, sampleHoleIndex, cDomain);
  4317. break;
  4318. }
  4319. }
  4320. }
  4321. }
  4322. else
  4323. {
  4324. int measureIndex = 0;
  4325. //获取测量区域信息
  4326. foreach (var MeasureItem in m_MeasureGDIObjects)
  4327. {
  4328. if (MeasureItem.SampleName == m_SampleSelectName)
  4329. {
  4330. measureIndex++;
  4331. SampleMeasurePara sampleMeasure = OTSSamplespaceGraphicsPanelFun.GetSampleMeasureRect(MeasureItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain);
  4332. iShape = (DOMAIN_SHAPE)sampleMeasure.iShape;
  4333. Srect = sampleMeasure.MeasureRect;
  4334. //设置测量区域形状
  4335. if (iShape == (DOMAIN_SHAPE)(int)CreateRectangleType.Polygon)
  4336. {
  4337. if (iShape > 0)
  4338. {
  4339. cDomain.SetShape(iShape);
  4340. }
  4341. else
  4342. {
  4343. cDomain.SetShape((DOMAIN_SHAPE.ROUND));
  4344. }
  4345. }
  4346. else
  4347. {
  4348. cDomain.SetShape(iShape);
  4349. }
  4350. cDomain.SetRectDomain(Srect);
  4351. List<Point> PolygonPoint = OTSSamplespaceGraphicsPanelFun.PointFConvertPoint(sampleMeasure.DrawPolygonPointRegionF);
  4352. cDomain.SetPolygonPoint(PolygonPoint);
  4353. //开始获取样品孔中的照片
  4354. m_MeasureAppForm.StartSampleHoleBSEImage((int)MSR_THREAD_RunSTATUS.RUNSampleHoleImage, 2, cDomain);
  4355. break;
  4356. }
  4357. }
  4358. }
  4359. }
  4360. }
  4361. #endregion
  4362. #region 复位工作样品区域
  4363. public void ResetWorkSampleMeasure()
  4364. {
  4365. COTSSample WSample = m_MeasureAppForm.m_ProjParam.GetWorkSample();
  4366. OTSSamplePropertyInfo MeasureInfo = new OTSSamplePropertyInfo();
  4367. if (!m_MeasureAppForm.m_ProjParam.GetWorkSamplePerameter(WSample, ref MeasureInfo))
  4368. {
  4369. return;
  4370. }
  4371. Rectangle measureSize = m_MeasureAppForm.m_ProjParam.CalculateMsrArea(MeasureInfo.SMeasurePara.sHoleName);
  4372. //获取位置与尺寸
  4373. MeasureInfo.SMeasurePara.MeasureRect.Location = measureSize.Location;
  4374. MeasureInfo.SMeasurePara.MeasureRect.Size = measureSize.Size;
  4375. //获取样品信息
  4376. Point xHole = new Point(MeasureInfo.SMeasurePara.MeasureRect.Left, MeasureInfo.SMeasurePara.MeasureRect.Top);
  4377. Point yHole = new Point(MeasureInfo.SMeasurePara.MeasureRect.Right, MeasureInfo.SMeasurePara.MeasureRect.Bottom);
  4378. //将微米转换为像素
  4379. int widthHole = (int)(Math.Abs(((Point)yHole).X - ((Point)xHole).X));
  4380. int heightHole = (int)(Math.Abs(((Point)yHole).Y - ((Point)xHole).Y));
  4381. //定义测量区域
  4382. RectangleF SampleRectangleF = OTSSamplespaceGraphicsPanelFun.GetPixRectF(m_WDomain, yHole, xHole, "", "", IsWidth, m_DefaultW, m_DefaultH);
  4383. ARectangleGDIObject m_MeasureGDIObject = OTSSamplespaceGraphicsPanelFun.GetPixRect(m_WDomain, yHole, xHole, MeasureInfo.SMeasurePara.iShape, "", "", IsWidth, m_DefaultW, m_DefaultH);
  4384. m_MeasureGDIObject.Region = new Rectangle((int)SampleRectangleF.X, (int)SampleRectangleF.Y, (int)SampleRectangleF.Width, (int)SampleRectangleF.Height);
  4385. m_MeasureGDIObject.RegionF = SampleRectangleF;
  4386. m_MeasureGDIObject.DrawRegionF = SampleRectangleF;
  4387. foreach (var itemSample in m_SampleGDIObjects)
  4388. {
  4389. if (itemSample.IsWorkSample)
  4390. {
  4391. for (int i = 0; i < m_MeasureGDIObjects.Count; i++)
  4392. {
  4393. if (m_MeasureGDIObjects[i].IsWorkSample)
  4394. {
  4395. ARectangleGDIObject m_ResetMeasureGDIobjects = CStageManage.ResetMeasure((int)CreateRectangleType.Circle, itemSample, m_MeasureGDIObject, m_GlobalZoomNum);
  4396. m_MeasureGDIObjects[i].Region = m_ResetMeasureGDIobjects.Region;
  4397. m_MeasureGDIObjects[i].RegionF = m_ResetMeasureGDIobjects.RegionF;
  4398. m_MeasureGDIObjects[i].DrawRegionF = m_ResetMeasureGDIobjects.DrawRegionF;
  4399. m_MeasureGDIObjects[i].Shape = m_ResetMeasureGDIobjects.Shape;
  4400. Invalidate();
  4401. break;
  4402. }
  4403. }
  4404. break;
  4405. }
  4406. }
  4407. }
  4408. #endregion
  4409. #region 清空帧图对象与图像位置对象
  4410. public void ClearImageAndSingleGDIObjects()
  4411. {
  4412. //先清空帧图信息
  4413. if (m_MeasureAppForm.m_MessageStates == (int)MessageState.StartMeasure)
  4414. {
  4415. m_SingleGDIObjects = OTSSamplespaceGraphicsPanelFun.ListClear(m_SingleGDIObjects);
  4416. }
  4417. if (m_MeasureAppForm.m_MessageStates == MessageState.ShotBSEPicture)
  4418. {
  4419. m_ImageSingleGDIObjects = OTSSamplespaceGraphicsPanelFun.ListClear(m_ImageSingleGDIObjects);
  4420. }
  4421. }
  4422. #endregion
  4423. #region 样品对象列表中无样品信息 则清除帧图对象列表信息
  4424. /// <summary>
  4425. /// 样品对象列表中无样品信息 则清除帧图对象列表信息
  4426. /// </summary>
  4427. /// <returns></returns>
  4428. public bool SampleIsEmptyClearSingleInfo()
  4429. {
  4430. bool result = false;
  4431. if (m_SampleGDIObjects != null)
  4432. {
  4433. if (m_SampleGDIObjects.Count == 0)
  4434. {
  4435. result = true;
  4436. ClearImageAndSingleGDIObjects();
  4437. }
  4438. }
  4439. return result;
  4440. }
  4441. #endregion
  4442. #region 切换样品 填充帧图信息
  4443. public static void ChangeSampleFillSingleInfo(string sampleName)
  4444. {
  4445. OTSSamplespaceGraphicsPanelFun.ChangeSampleFillSingleInfo(m_ALLSingleGDIObjects, m_SingleGDIObjects, sampleName);
  4446. }
  4447. #endregion
  4448. #region 设置工作样品测量区域
  4449. public bool SetWorkSampleMeasureArea(int shape = 0)
  4450. {
  4451. bool IsSingle = false;
  4452. //获取当前工作的测量区域信息
  4453. CDomain cDomain = new CDomain();
  4454. DOMAIN_SHAPE iShape = 0;
  4455. Rectangle Srect = new Rectangle();
  4456. List<Point> PolygonPoint = new List<Point>();
  4457. //获取测量区域形状与位置
  4458. //获取当前测量区域
  4459. foreach (var MeasureItem in m_MeasureGDIObjects)
  4460. {
  4461. if (MeasureItem.IsSingle && MeasureItem.IsWorkSample)
  4462. {
  4463. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(MeasureItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  4464. {
  4465. IsSingle = true;
  4466. SampleMeasurePara sampleMeasure = GetSampleMeasureRect(MeasureItem);
  4467. if (sampleMeasure.PolygonPointRegion == null)
  4468. {
  4469. sampleMeasure.PolygonPointRegion = new List<Point>();
  4470. }
  4471. PolygonPoint = OTSSamplespaceGraphicsPanelFun.PointFConvertPoint(sampleMeasure.PolygonPointRegionF);
  4472. iShape = (DOMAIN_SHAPE)sampleMeasure.iShape;
  4473. //设置测量区域形状
  4474. if (iShape == (DOMAIN_SHAPE)(int)CreateRectangleType.Polygon)
  4475. {
  4476. if (shape > 0)
  4477. {
  4478. cDomain.SetShape((DOMAIN_SHAPE)shape);
  4479. }
  4480. else
  4481. {
  4482. cDomain.SetShape((DOMAIN_SHAPE.ROUND));
  4483. }
  4484. }
  4485. else
  4486. {
  4487. cDomain.SetShape((DOMAIN_SHAPE)iShape);
  4488. }
  4489. Srect = sampleMeasure.MeasureRect;
  4490. cDomain.SetRectDomain(Srect);
  4491. cDomain.SetPolygonPoint(PolygonPoint);
  4492. //线程执行类型 1:测量类型 2:获取样品孔图片类型
  4493. CMeasureThreadWrapper.DoRunType = (int)MSR_THREAD_RunSTATUS.RUNMEASURE;
  4494. //设置获取样品孔中照片所需的参数
  4495. CMeasureThreadWrapper.c_DomainMessure = cDomain;
  4496. }
  4497. break;
  4498. }
  4499. }
  4500. return IsSingle;
  4501. }
  4502. #endregion
  4503. }
  4504. }