OTSSamplespaceWindow.cs 242 KB

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