OTSSamplespaceWindow.cs 244 KB

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