OTSSamplespaceWindow.cs 244 KB

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