OTSSamplespaceWindow.cs 243 KB

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