OTSSamplespaceWindow.cs 245 KB

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