OTSSamplespaceWindow.cs 243 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using OTS.WinFormsUI.Docking;
  6. using System.IO;
  7. using System.Drawing.Drawing2D;
  8. using System.Collections;
  9. using OTSDataType;
  10. using OTSModelSharp;
  11. using static OTSDataType.otsdataconst;
  12. using OTSCLRINTERFACE;
  13. namespace OTSMeasureApp
  14. {
  15. public partial class OTSSamplespaceWindow : DockContent
  16. {
  17. #region 全局变量定义
  18. //样品台对象
  19. //StageDrawingData m_StageDrawingData;
  20. public StageDrawingData m_OTSSampleStageData = null;
  21. //样品测量集合对象
  22. public List<SampleMeasurePara> m_SMeasrueAreaList = null;
  23. //样品台存在的List集合 the rectangle on the edge of stage ,usually one.
  24. public static List<ARectangleGDIObject> m_RectangleGDIObjects;
  25. //标样存在的List集合 usually it is a samll circle.
  26. public static List<ARectangleGDIObject> m_SpecimenGDIObjects;
  27. //样品孔的List集合
  28. string m_SampleHoleSelectName = string.Empty;
  29. public static string m_SampleSelectName = string.Empty;
  30. string m_MeasureSelectName = string.Empty;
  31. public static List<ARectangleGDIObject> m_SampleHoleGDIObjects;// the hole gdi of the stage
  32. //样品的List集合
  33. string m_SelectName = string.Empty;
  34. public static ARectangleGDIObject selectSampleGDIObjects;
  35. public static List<ARectangleGDIObject> m_SampleGDIObjects;
  36. //工作样品的List集合
  37. string m_WorkSelectName = string.Empty;
  38. public static List<ARectangleGDIObject> m_WorkStageGDIObjects;
  39. //测量区域
  40. public static List<ARectangleGDIObject> m_MeasureGDIObjects;
  41. //文字内容
  42. public static List<ARectangleGDIObject> m_ContentGDIObjects;//the text that will display in the hole.
  43. //测量区域
  44. public static List<ARectangleGDIObject> m_MeasurePathGDIObjects;
  45. //帧图
  46. public static List<ARectangleGDIObject> m_SingleGDIObjects;
  47. //所有帧图
  48. public static List<ARectangleGDIObject> m_ALLSingleGDIObjects;
  49. //BSE图像
  50. public static List<ARectangleGDIObject> m_ImageGDIObjects;
  51. //BSE图像帧图 为了获取位置与尺寸
  52. public static List<ARectangleGDIObject> m_ImageSingleGDIObjects;
  53. //手绘测量区域
  54. public static List<ARectangleGDIObject> m_DrawMeasureGDIObjects;
  55. //SEM中心位置
  56. public static List<ARectangleGDIObject> m_SEMCenterGDIObjects;
  57. //多边形测量区域完成标识
  58. public static List<ARectangleGDIObject> m_DrawPolygonFinishGDIObjects;
  59. //记录添加帧图的尺寸 鼠标滚动时使用的原值
  60. //public static List<RectangleF> f;
  61. //鼠标点击样品台(Mouse Down 里设置),说明样品台被选中,允许拖动被选中的样品台
  62. bool m_RectangIsDragging = false;
  63. float m_PenWidth = 5;
  64. //分辨率 计算方式 0:宽度 1:高度
  65. public static int IsWidth = 0;
  66. static int m_WDomain = 0;
  67. int m_DefaultW = 0;
  68. int m_DefaultH = 0;
  69. int m_DefaultWidth = 0;
  70. int m_DefaultHeight = 0;
  71. int m_DefaultStageWidth = 0;
  72. int m_DefaultStageHeight = 0;
  73. int m_DefaultSampleWidth = 0;
  74. int m_DefaultSampleHeight = 0;
  75. //当前位置与原位置的样品台相差位置
  76. PointF m_DifferentPoint = new PointF();
  77. //主窗体对象
  78. OTSIncAMeasureAppForm m_MeasureAppForm;
  79. //鼠标右键选择的类型 0:样品台 1:样品 2:测量区域
  80. public int m_IsSelectType = 0;
  81. //当前是否选择测量区域
  82. public static bool m_IsMeasure = false;
  83. SEMDATAFieldManage m_SEMDATAFieldManage;
  84. List<Rectangle> m_RectFieldRects = null;
  85. //记录绘制样品台时的中心位置
  86. Point m_RegionStartCenterPoint = new Point(0, 0);
  87. //记录绘制后样品台的电镜坐标范围
  88. Point StageLTPointToSEMLocation = new Point(0, 0);
  89. Point StageRBPointToSEMLocation = new Point(0, 0);
  90. //当前是否移动样品
  91. bool m_IsMoveSample = false;
  92. //XML文件名称
  93. static string m_XMLFileName = System.Configuration.ConfigurationManager.ConnectionStrings["XMLFileName"].ConnectionString;
  94. //电镜与样品参数中的放大倍数与工作距离
  95. public static double m_SEMIWDistance = 0;
  96. public static double m_SEMDMagni = 0;
  97. public static double m_PropIWDistance = 0;
  98. public static double m_PropDMagni = 0;
  99. #region 鼠标滚动所需参数
  100. public static float m_ScaleNum = 1;
  101. public static float m_GlobalZoomNum = 1;//记录每次比例缩放后的总体比例系数。
  102. //改变窗体 记录的比例系数
  103. public static float m_WorkAreaZoom = 1;
  104. //加载的样品台类型 默认为原型样品台
  105. public static int m_Shape = 0;
  106. private Size m_intSize = new Size(0, 0);
  107. int m_MinMeasureWidthValue = 20;
  108. Point m_MouseDownLocation = new Point(0, 0);
  109. #endregion
  110. #region 手动绘制测量区域
  111. Point m_MouseDownPoint;
  112. Point m_MouseUpPoint;
  113. Point m_MouseMovePoint;
  114. //绘制多边形,点集合
  115. List<PointF> m_PolygonPoint;
  116. //点数量
  117. int m_PointCount = 2;
  118. //与多边形绘制的开始点相差的像素值
  119. int m_OffsetPX = 10;
  120. //手动绘制多边形测量区域完成标识
  121. bool m_IsDrawPolygonFinish = false;
  122. //手动绘制测量区域的形状类型
  123. int m_DrawMeasureType = 1;
  124. //是否为3点发画圆形
  125. bool IsCirCleByThree = false;
  126. //是否手绘标识准备
  127. public bool m_IsDrawMeasureReady = false;
  128. //是否手绘标识
  129. public bool m_IsDrawMeasure = false;
  130. #endregion
  131. //所选测量区域的矩形对象
  132. Rectangle m_SelMeasureRect;
  133. //是否选中样品台标识
  134. bool m_IsSelectSampleStage = false;
  135. private Point m_P, m_P1;
  136. protected Point m_MeasureToSamplePoint;
  137. //是否按下Ctrl键
  138. bool m_IsCtrl = false;
  139. bool m_IsAlt = false;
  140. //配合Ctrol键是否选中多边形的点标识
  141. bool m_IsSelPolygonPoint = false;
  142. //配合Ctrol键是否选中多边形的点
  143. PointF m_SelPolygonPoint = new Point();
  144. //测量区域矩形对象
  145. static Rectangle m_MeasureRectangle = new Rectangle();
  146. //默认值
  147. const int m_DValue = 1;
  148. int m_CompletedFieldsCount = 0;
  149. NLog.Logger log ;
  150. //选择工作样品测量的状态
  151. bool selWSampleMeasureStatus = false;
  152. #endregion
  153. #region 标尺变量
  154. //缩放的增大缩小的增量
  155. private float f_zoom_increment = 0.1f;
  156. //缩放的基数,临时变量
  157. private float f_widthandheight_js = 0;
  158. //与原先缩放的记录数
  159. private float f_zoom_record = 1;
  160. //最小缩放倍数
  161. private float f_zoom_mix = 0.5f;
  162. //标尺的大小记录
  163. private float f_ruler_size = 100;
  164. //标尺原先大小的记录,参与计算
  165. private float f_old_ruler_size = 100;
  166. public RectangleF BackRectF
  167. {
  168. set { backrectf = value; }
  169. get { return backrectf; }
  170. }
  171. //背景矩形
  172. public RectangleF backrectf = new RectangleF();
  173. //记录原值,背景矩形
  174. public RectangleF old_backrectf = new RectangleF();
  175. //国际化
  176. OTSSysMgrTools.Language lan;
  177. Hashtable table;
  178. #endregion
  179. #region 设置双缓冲
  180. /// <summary>
  181. /// 设置双缓冲
  182. /// </summary>
  183. public void SetDoubleBufferByIsDraw()
  184. {
  185. SetStyle(ControlStyles.UserPaint, true);
  186. SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
  187. this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // 双缓冲
  188. }
  189. #endregion
  190. #region 构造函数 获取父窗体对象
  191. public OTSSamplespaceWindow(OTSIncAMeasureAppForm MeasureAppForm)
  192. {
  193. InitializeComponent();
  194. m_MeasureAppForm = MeasureAppForm;
  195. //this.InitDataEvent();
  196. SetDoubleBufferByIsDraw();// 双缓冲
  197. m_OTSSampleStageData = new StageDrawingData();
  198. //国际化
  199. lan = new OTSSysMgrTools.Language(this);
  200. table = lan.GetNameTable(this.Name);
  201. }
  202. /// <summary>
  203. /// 画圆形测试区域 事件
  204. /// </summary>
  205. public void Rev_DDrawCircleMeasure_MeasureAppToSampleWindow_Event()
  206. {
  207. //手绘测量区域类型为圆形
  208. m_DrawMeasureType = (int)CreateRectangleType.Circle;
  209. m_IsDrawMeasureReady = true;
  210. m_RectangIsDragging = false;
  211. this.Cursor = Cursors.Hand;
  212. }
  213. /// <summary>
  214. /// 画矩形测试区域 事件
  215. /// </summary>
  216. public void Rev_DDrawRectangleMeasure_MeasureAppToSampleWindow_Event()
  217. {
  218. //手绘测量区域类型为矩形
  219. m_DrawMeasureType = (int)CreateRectangleType.SampleBackGround_Rectangle;
  220. m_IsDrawMeasureReady = true;
  221. m_RectangIsDragging = false;
  222. this.Cursor = Cursors.Hand;
  223. }
  224. /// <summary>
  225. /// 画多边形测试区域 事件
  226. /// </summary>
  227. public void Rev_DDrawPolygonMeasure_MeasureAppToSampleWindow_Event()
  228. {
  229. //多边形测量区域完成标识
  230. m_DrawPolygonFinishGDIObjects = new List<ARectangleGDIObject>();
  231. //手绘测量区域类型为矩形
  232. m_DrawMeasureType = (int)CreateRectangleType.Polygon;
  233. m_IsDrawMeasureReady = true;
  234. m_IsDrawMeasure = true;
  235. m_RectangIsDragging = false;
  236. m_PolygonPoint = new List<PointF>();
  237. this.Cursor = Cursors.Hand;
  238. }
  239. /// <summary>
  240. /// 三点画圆形测试区域 事件 先多边形后圆形
  241. /// </summary>
  242. public void Rev_DDrawCircleMeasureByThreePoints_MeasureAppToSampleWindow_Event()
  243. {
  244. //手绘测量区域类型为圆形
  245. m_DrawMeasureType = (int)CreateRectangleType.CircleByThreePoints;
  246. m_IsDrawMeasureReady = true;
  247. m_IsDrawMeasure = true;
  248. m_RectangIsDragging = false;
  249. m_PolygonPoint = new List<PointF>();
  250. this.Cursor = Cursors.Hand;
  251. }
  252. /// <summary>
  253. /// 当修改了GRID 的样品台测量精度、放大倍数和图片像素大小 时,SAMPLEWINDOW重新绘制样品台
  254. /// </summary>
  255. public void Rev_DDDrawSampleStage_EventHandler_Event()
  256. {
  257. m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;
  258. //显示帧图
  259. if (m_SingleGDIObjects.Count > 0)
  260. {
  261. showSingleInfo();
  262. }
  263. }
  264. public void Rev_MeasureApp_OpenExistSampleFile_Event(CStage SStage, CSEMStageData SEMStageData, List<SampleMeasurePara> SMeasrueAreaList, string sWorkSampleName)
  265. {
  266. GetSampleStageData(SStage, SEMStageData);
  267. var SStageData = m_OTSSampleStageData;
  268. m_GlobalZoomNum = 1;
  269. //清除所有绘制的图形信息
  270. ClearDrawInfo();
  271. //绘制样品台信息
  272. if (SStageData != null)
  273. {
  274. m_OTSSampleStageData = SStageData;
  275. DrawSampleStage(SStageData);
  276. }
  277. //绘制样品与测量区域
  278. //1.绘制样品
  279. if (SMeasrueAreaList != null)
  280. {
  281. m_SMeasrueAreaList = SMeasrueAreaList;
  282. DrawSampleAndMeasureInfo(SMeasrueAreaList);
  283. }
  284. //2.测量区域
  285. //设置工作样品
  286. if (sWorkSampleName != "")
  287. {
  288. Rev_MeasureApp_SwitchWorkSample_Event(sWorkSampleName);
  289. //打开文件后 设置工作样品名称
  290. m_SampleSelectName = sWorkSampleName;
  291. }
  292. //重新绘制
  293. Invalidate();
  294. }
  295. ///MeasureApp和 SampleSpaceWindow 切换工作样品名称事件委托
  296. ///string sNewWSampleName: 切换新工作样品名称
  297. public void Rev_MeasureApp_SwitchWorkSample_Event(string sNewWSampleName, bool bDrawField = false)
  298. {
  299. try
  300. {
  301. //获取存在帧图的样品名称
  302. string singleSampleName = string.Empty;
  303. if (m_SingleGDIObjects != null)
  304. {
  305. if (m_SingleGDIObjects.Count > 0)
  306. {
  307. singleSampleName = m_SingleGDIObjects[0].SampleName;
  308. }
  309. }
  310. //判断当前帧图所在样品的样品名称与新样品名称是否相同
  311. if (!singleSampleName.Equals(""))
  312. {
  313. if (singleSampleName != sNewWSampleName)
  314. {
  315. //先清空帧图信息
  316. ClearImageAndSingleGDIObjects();
  317. this.Invalidate();
  318. }
  319. }
  320. //判断当前帧图所在样品的样品名称与新样品名称是否相同
  321. if (m_SingleGDIObjects != null)
  322. {
  323. if (m_SingleGDIObjects.Count > 0)
  324. {
  325. if (m_SingleGDIObjects[0].SampleName != sNewWSampleName)
  326. {
  327. //先清空帧图信息
  328. ClearImageAndSingleGDIObjects();
  329. this.Invalidate();
  330. }
  331. }
  332. }
  333. //设置工作样品样式
  334. CStageManage.SetWorkSampleAndWorkMeasure(sNewWSampleName);
  335. foreach (var itemMeasure in m_MeasureGDIObjects)
  336. {
  337. if (itemMeasure.IsSingle && itemMeasure.IsWorkSample && sNewWSampleName == itemMeasure.SampleName)
  338. {
  339. //当前工作样品的测量区域 获取帧图信息
  340. if (m_SingleGDIObjects.Count == 0)
  341. {
  342. string message = table["message1"].ToString();
  343. //log.Trace("Rev_MeasureApp_SwitchWorkSample_Event:--" + message + "--begin--");
  344. showSingleInfo();
  345. //log.Trace("Rev_MeasureApp_SwitchWorkSample_Event:--" + message + "--end--");
  346. break;
  347. }
  348. }
  349. }
  350. ////绘制已完成的帧图状态
  351. COTSMsrPrjResultData cProjMgr = m_MeasureAppForm.m_ProjParam.m_ResultData;
  352. //当前工作样品的测量区域 获取帧图信息
  353. COTSSample cSample = cProjMgr.GetWorkingSample();
  354. int CompletedFieldsCount = cSample.GetMsrStatus().GetCompletedFields();
  355. if (CompletedFieldsCount > 0)
  356. {
  357. //设置测量区域获取帧图
  358. foreach (var itemMeasure in m_MeasureGDIObjects)
  359. {
  360. if (cSample.GetName() == itemMeasure.SampleName)
  361. {
  362. itemMeasure.IsSingle = true;
  363. break;
  364. }
  365. }
  366. if (m_SingleGDIObjects.Count == 0)
  367. {
  368. showSingleInfo();
  369. }
  370. //获取已完成测量的帧图中心点
  371. List<Point> CompleteFieldList = cProjMgr.GetWorkingSample().GetMsrStatus().GetCompletedFieldsCenter();
  372. //修改帧图完成状态
  373. OTSMeasureDisplayResult.ChangeCompleteFieldMeasureState(CompleteFieldList, Color.Green, m_MeasureAppForm);
  374. }
  375. else
  376. {
  377. //根据测量文件中已获取sem信息
  378. if (cSample.GetSEMDataMsr().GetTotalFields() > 0)
  379. {
  380. foreach (var itemMeasure in m_MeasureGDIObjects)
  381. {
  382. if (cSample.GetName() == itemMeasure.SampleName)
  383. {
  384. itemMeasure.IsSingle = true;
  385. showSingleInfo();
  386. break;
  387. }
  388. }
  389. }
  390. }
  391. //设置为手绘测量区域
  392. m_IsDrawMeasureReady = false;
  393. m_IsDrawMeasure = false;
  394. this.Invalidate();
  395. return;
  396. }
  397. catch (Exception ex)
  398. {
  399. string message = table["message2"].ToString();
  400. //记录错误日志
  401. log.Trace("Rev_MeasureApp_SwitchWorkSample_Event():" + message + ":" + ex.ToString() + "");
  402. }
  403. }
  404. //MeasureApp和 SampleSpaceWindow 修改工作样品名称事件委托
  405. //string sSampleHoleName: 修改工作样品名称
  406. public void Rev_MeasureApp_ChangeWorkSampleName_Event(string sNewWSampleName)
  407. {
  408. try
  409. {
  410. string oldSampleName = string.Empty;
  411. foreach (ARectangleGDIObject itemSample in OTSSamplespaceWindow.m_SampleGDIObjects)
  412. {
  413. if (itemSample.IsWorkSample)
  414. {
  415. oldSampleName = itemSample.SampleName;
  416. }
  417. }
  418. //更换样品名称
  419. CStageManage.ChangeSampleName(sNewWSampleName);
  420. this.Invalidate();
  421. return;
  422. }
  423. catch (Exception ex)
  424. {
  425. string message = table["message2"].ToString();
  426. //记录错误日志
  427. log.Trace("Rev_MeasureApp_ChangeWorkSampleName_Event():" + message + ":" + ex.ToString() + "");
  428. }
  429. }
  430. //MeasureApp和 SampleSpaceWindow 删除样品事件委托, MeasureApp 给 SampleSpaceWindow 发送删除样品委托事件
  431. //string sSampleHoleName: 删除工作样品名
  432. public void Rev_MeasureApp_DeleteWorkSample_Event(string sDeleteWSampleName, string sNewWSampleName)
  433. {
  434. try
  435. {
  436. foreach (ARectangleGDIObject itemSample in OTSSamplespaceWindow.m_SampleGDIObjects)
  437. {
  438. if (itemSample.SampleName == sDeleteWSampleName)
  439. {
  440. if (itemSample.IsWorkSample)
  441. {
  442. //删除样品测量集合中的对象
  443. if (CStageManage.DeleteSample(sDeleteWSampleName))
  444. {
  445. if (m_SampleGDIObjects.Count == 0)
  446. {
  447. //将测量状态初始化
  448. m_MeasureAppForm.m_MessureStatuWindow.SetMeasureStatusInit();
  449. }
  450. //根据样品名称 删除对应帧图信息
  451. OTSSamplespaceGraphicsPanelFun.DeleteALLSingleInfo(m_ALLSingleGDIObjects, sDeleteWSampleName);
  452. if (!string.IsNullOrEmpty(sNewWSampleName))
  453. {
  454. //设置工作样品
  455. m_MeasureAppForm.Rev_SoluWindowReqSwitchWSample_Event(sNewWSampleName);
  456. }
  457. else
  458. {
  459. //先清空帧图信息
  460. ClearImageAndSingleGDIObjects();
  461. }
  462. this.Invalidate();
  463. return;
  464. }
  465. }
  466. }
  467. }
  468. }
  469. catch (Exception ex)
  470. {
  471. string message = table["message2"].ToString();
  472. //记录错误日志
  473. log.Error("Rev_MeasureApp_DeleteWorkSample_Event():" + message + ":" + ex.ToString() + "");
  474. }
  475. }
  476. #region 更改工作样品中 测量区域形状
  477. public void changeShape(int iShape)
  478. {
  479. try
  480. {
  481. string sampleName = m_MeasureAppForm.m_ProjParam.GetWorkSampleName();
  482. //m_Shap 更换样品形状
  483. if (CStageManage.ChangeSampleShape(iShape))
  484. {
  485. //设置新添加测量区域更改位置与缩放
  486. foreach (var item in m_MeasureGDIObjects)
  487. {
  488. if (item.SampleName == sampleName)
  489. {
  490. item.IsWorkSample = true;
  491. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(item, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  492. {
  493. //保存原位置
  494. Rectangle rectPara = item.Region;
  495. #region 测量区域与样品中心相差的距离
  496. foreach (var itemSample in m_SampleGDIObjects)
  497. {
  498. if (itemSample.SampleName == item.SampleName)
  499. {
  500. item.SampleCenterDifferCenterPoint = OTSSamplespaceGraphicsPanelFun.GetSampleCenterDifferCenterPoint(rectPara, itemSample.Region);
  501. break;
  502. }
  503. }
  504. if (item.IsSingle)
  505. {
  506. showSingleInfo();
  507. }
  508. #endregion
  509. }
  510. }
  511. }
  512. }
  513. this.Invalidate();
  514. return;
  515. }
  516. catch (Exception ex)
  517. {
  518. string message = table["message2"].ToString();
  519. //记录错误日志
  520. log.Error("changeShape():" + message + ":" + ex.ToString() + "");
  521. }
  522. }
  523. #endregion
  524. #region 还原测量区域形状
  525. public void ResetShape()
  526. {
  527. try
  528. {
  529. //设置新添加测量区域更改位置与缩放
  530. foreach (var item in m_MeasureGDIObjects)
  531. {
  532. if (item.IsWorkSample)
  533. {
  534. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(item, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  535. {
  536. //保存原位置
  537. Rectangle rectPara = item.Region;
  538. #region 测量区域与样品中心相差的距离
  539. foreach (var itemSample in m_SampleGDIObjects)
  540. {
  541. if (itemSample.SampleName == item.SampleName)
  542. {
  543. item.SampleCenterDifferCenterPoint = OTSSamplespaceGraphicsPanelFun.GetSampleCenterDifferCenterPoint(rectPara, itemSample.Region);
  544. break;
  545. }
  546. }
  547. if (item.IsSingle)
  548. {
  549. showSingleInfo();
  550. }
  551. #endregion
  552. }
  553. }
  554. }
  555. this.Invalidate();
  556. return;
  557. }
  558. catch (Exception ex)
  559. {
  560. string message = table["message2"].ToString();
  561. //记录错误日志
  562. log.Error("changeShape():" + message + ":" + ex.ToString() + "");
  563. }
  564. }
  565. #endregion
  566. ///MeasureApp 给SampleWindow窗口发送添加样品的样品孔名,测量区域信息
  567. //string sSampleName : 新添加样品名
  568. //string sSampleHoleName: 新添加样品所在的样品孔名称
  569. //int iShape: 测量区域形状
  570. //Point pStartPoint: 测量区域起点
  571. //Point pEndPoint : 测量区域终点
  572. public void AddOneSampleArea(SampleMeasurePara SMeasurePara)
  573. {
  574. try
  575. {
  576. CMStrip.Hide();
  577. //获取样品信息
  578. Point xHole = new Point(SMeasurePara.MeasureRect.Left, SMeasurePara.MeasureRect.Top);
  579. Point yHole = new Point(SMeasurePara.MeasureRect.Right, SMeasurePara.MeasureRect.Bottom);
  580. //将微米转换为像素
  581. int widthHole = (int)(Math.Abs(((Point)yHole).X - ((Point)xHole).X));
  582. int heightHole = (int)(Math.Abs(((Point)yHole).Y - ((Point)xHole).Y));
  583. //定义测量区域
  584. RectangleF SampleRectangleF = OTSSamplespaceGraphicsPanelFun.GetPixRectF(m_WDomain, yHole, xHole, "", "", IsWidth, m_DefaultW, m_DefaultH);
  585. ARectangleGDIObject m_SampleGDIObject = OTSSamplespaceGraphicsPanelFun.GetPixRect(m_WDomain, yHole, xHole, SMeasurePara.iShape, "", "", IsWidth, m_DefaultW, m_DefaultH);
  586. m_SampleGDIObject.Region = new Rectangle((int)SampleRectangleF.X, (int)SampleRectangleF.Y, (int)SampleRectangleF.Width, (int)SampleRectangleF.Height);
  587. m_SampleGDIObject.RegionF = SampleRectangleF;
  588. m_SampleGDIObject.DrawRegionF = SampleRectangleF;
  589. //测量区域名称 样品名称
  590. m_SampleGDIObject.SampleName = SMeasurePara.sSampleName;
  591. //测量区域类型
  592. m_SampleGDIObject.CreateType = SMeasurePara.iShape;
  593. //添加样品
  594. if (CStageManage.AddSample(SMeasurePara.sHoleName, SMeasurePara.sSampleName, m_SampleGDIObject, this, m_GlobalZoomNum))
  595. {
  596. //设置新添加样品测量的位置
  597. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(m_MeasureGDIObjects[m_MeasureGDIObjects.Count - 1], m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  598. {
  599. CStageManage.SetWorkSampleAndWorkMeasure(SMeasurePara.sSampleName);
  600. //清除帧图信息
  601. ClearImageAndSingleGDIObjects();
  602. Invalidate();
  603. }
  604. }
  605. }
  606. catch (Exception ex)
  607. {
  608. string message = table["message2"].ToString();
  609. //记录错误日志
  610. log.Error("OTSSamplespaceWindow_Rev_MeasureApp_AddSample_Event():--" + message + ":" + ex.ToString() + "");
  611. }
  612. }
  613. //响应委托事件的样品台数据
  614. public void InitStageDisplay(CStage SStage, CSEMStageData SEMStageData)
  615. {
  616. GetSampleStageData(SStage, SEMStageData);
  617. m_GlobalZoomNum = 1;
  618. //清除所有绘制的图形信息
  619. ClearDrawInfo();
  620. //绘制样品台信息
  621. DrawSampleStage(m_OTSSampleStageData);
  622. //标尺初始化
  623. RulerInit();
  624. //重新绘制
  625. Invalidate();
  626. //1.将测量结果窗体中已存在的内容清空
  627. //2.将测量图像清空
  628. //图像隐藏
  629. HideMessureStatuWindowBSEImage(m_MeasureAppForm);
  630. //将测量结果信息状态初始化
  631. InitMeasureStateInfo();
  632. if (m_SampleGDIObjects != null)
  633. {
  634. if (m_SampleGDIObjects.Count == 0)
  635. {
  636. //将测量状态初始化
  637. m_MeasureAppForm.m_MessureStatuWindow.SetMeasureStatusInit();
  638. }
  639. }
  640. }
  641. public void HideMessureStatuWindowBSEImage(OTSIncAMeasureAppForm m_MeasureApps)
  642. {
  643. m_MeasureApps.m_MessureStatuWindow.pbBSEImage.Hide();
  644. }
  645. #region 将测量状态进度窗口信息初始化
  646. public void InitMeasureStateInfo()
  647. {
  648. m_MeasureAppForm.m_MeasureRetWindow.SetInit();
  649. }
  650. #endregion
  651. //获取绘制样品台的数据
  652. private bool GetSampleStageData(CStage SStage ,CSEMStageData SEMStageData)
  653. {
  654. //StageDrawingData m_OTSSampleStageData = new StageDrawingData();
  655. //获取样品台信息
  656. //CStage SStage = m_ResultData.GetStage();
  657. if (null == SStage)
  658. {
  659. return false;
  660. }
  661. //获得样品台数据
  662. m_OTSSampleStageData.sStageName = SStage.GetName();
  663. m_OTSSampleStageData.bStageShape = (int)SStage.GetBoundary().GetShape();
  664. m_OTSSampleStageData.StageDomain = (Rectangle)SStage.GetBoundary().GetRectDomain();
  665. m_OTSSampleStageData.bSampleShape = (int)SStage.GetSTD().GetShape();
  666. m_OTSSampleStageData.SampleRect = (Rectangle)SStage.GetSTD().GetRectDomain();
  667. int iSHoleCount = SStage.GetHoleList().Count; //样品孔个数
  668. if (m_OTSSampleStageData.sSHoleInfoList.Count > 0)
  669. {
  670. m_OTSSampleStageData.sSHoleInfoList.Clear();
  671. }
  672. var holeLst = SStage.GetHoleList();
  673. for (int i = 0; i < iSHoleCount; i++)
  674. {
  675. CHole d = holeLst[i];
  676. OTSSampleHoleInfo SHoleInfo = new OTSSampleHoleInfo();
  677. //获取样品口的名称,形状,坐标
  678. SHoleInfo.sSHoleName = d.GetName();
  679. SHoleInfo.iSHoleShape = (int)d.GetShape();
  680. Rectangle r = (Rectangle)d.GetRectDomain();
  681. SHoleInfo.HoleRect = r;
  682. m_OTSSampleStageData.sSHoleInfoList.Add(SHoleInfo);
  683. }
  684. //获取SEMData 绘制样品
  685. m_OTSSampleStageData.iScanFieldSize100 = SEMStageData.GetScanFieldSize100(); //放大倍数为100倍时的屏幕尺寸
  686. m_OTSSampleStageData.iXAxisDir = (int)SEMStageData.GetXAxisDir();
  687. m_OTSSampleStageData.iYAxisDir = (int)SEMStageData.GetYAxisDir();
  688. m_OTSSampleStageData.iXAxisStartVal = SEMStageData.GetXAxis().GetStart();
  689. m_OTSSampleStageData.iXAxisEndVal = SEMStageData.GetXAxis().GetEnd();
  690. m_OTSSampleStageData.iYAxisStartVal = SEMStageData.GetYAxis().GetStart();
  691. m_OTSSampleStageData.iYAxisEndVal = SEMStageData.GetYAxis().GetEnd();
  692. return true;
  693. }
  694. //记录样品台的最大宽度
  695. static int RegionMaxWidth = 0;
  696. #region 绘制样品台信息
  697. /// <summary>
  698. /// 绘制样品台信息
  699. /// </summary>
  700. /// <returns></returns>
  701. public void DrawSampleStage(StageDrawingData SData)
  702. {
  703. try
  704. {
  705. if (SData.StageDomain.X == 0 && SData.StageDomain.Y == 0)
  706. {
  707. return;
  708. }
  709. string stageName = SData.sStageName;
  710. int widthDomain = 0;
  711. int heightDomain = 0;
  712. //获取样品台
  713. int StageShape = SData.bStageShape;
  714. Point xDomain = new Point(SData.StageDomain.Left, SData.StageDomain.Top);
  715. Point yDomain = new Point(SData.StageDomain.Right, SData.StageDomain.Bottom);
  716. //OTS宽度高度差值
  717. widthDomain = Math.Abs(yDomain.X - xDomain.X);
  718. heightDomain = Math.Abs(yDomain.Y - xDomain.Y);
  719. //样品台转换在电镜位置的宽度与高度
  720. StageLTPointToSEMLocation = m_MeasureAppForm.m_ProjParam.ChangeOTSToSemCoord(xDomain);
  721. StageRBPointToSEMLocation = m_MeasureAppForm.m_ProjParam.ChangeOTSToSemCoord(yDomain);
  722. //设置样品台宽度
  723. m_WDomain = widthDomain;
  724. IsWidth = this.Height > this.Width ? 0 : 1;
  725. //记录添加帧图的尺寸 鼠标滚动时使用的原值
  726. m_DefaultW = this.Width;
  727. m_DefaultH = this.Height;
  728. m_Shape = SData.bStageShape;
  729. CreateRectangle CreateBourary = null;
  730. //0:圆角矩形 1:圆形 2:文字 3:矩形
  731. if (SData.bStageShape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  732. {
  733. CreateBourary = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xDomain, yDomain, (int)CreateRectangleType.SampleBackGround_Rectangle, "", "", IsWidth, m_DefaultW, m_DefaultH);
  734. }
  735. else
  736. {
  737. CreateBourary = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xDomain, yDomain, (int)CreateRectangleType.SampleBackGround_Circle, "", "", IsWidth, m_DefaultW, m_DefaultH);
  738. }
  739. //获取默认尺寸
  740. m_DefaultWidth = CreateBourary.Region.Width;
  741. m_DefaultHeight = CreateBourary.Region.Height;
  742. //添加样品台 对象
  743. //设置路径
  744. GraphicsPath MeasurePath = new GraphicsPath();
  745. if (StageShape == (int)CreateRectangleType.Circle)
  746. {
  747. MeasurePath.AddEllipse(CreateBourary.Region);
  748. }
  749. else
  750. {
  751. MeasurePath.AddRectangle(CreateBourary.Region);
  752. }
  753. CreateBourary.GPath = MeasurePath;
  754. CreateBourary.Shape = StageShape;
  755. m_RectangleGDIObjects.Add(CreateBourary);
  756. //绘制后的样品台中心位置
  757. Point m_Region = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(m_RectangleGDIObjects[0].Region);
  758. //获取绘制后的样品台中心位置
  759. if (m_RegionStartCenterPoint.X != m_Region.X || m_RegionStartCenterPoint.Y != m_Region.Y)
  760. {
  761. m_RegionStartCenterPoint = m_Region;
  762. }
  763. //获取最大宽度
  764. if (RegionMaxWidth <= 0)
  765. {
  766. RegionMaxWidth = (IsWidth == 0 ? this.Width : this.Height);
  767. }
  768. //获取样品孔
  769. System.Collections.Generic.List<OTSSampleHoleInfo> ChloeClrList = SData.sSHoleInfoList;
  770. if (ChloeClrList.Count > 0)
  771. {
  772. for (int i = 0; i < ChloeClrList.Count; i++)
  773. {
  774. //获取微米信息
  775. var xHole = new Point(ChloeClrList[i].HoleRect.Left, ChloeClrList[i].HoleRect.Top);
  776. var yHole = new Point(ChloeClrList[i].HoleRect.Right, ChloeClrList[i].HoleRect.Bottom);
  777. //将微米转换为像素
  778. int widthHole = Math.Abs(yHole.X - xHole.X);
  779. int heightHole = Math.Abs(yHole.Y - xHole.Y);
  780. //获取矩形
  781. CreateRectangle CreateHole = null;
  782. //0:圆角矩形 1:圆形 2:文字 3:矩形
  783. if (ChloeClrList[i].iSHoleShape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  784. {
  785. CreateHole = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xHole, yHole, (int)CreateRectangleType.Rectangle, "", ChloeClrList[i].sSHoleName, IsWidth, m_DefaultW, m_DefaultH);
  786. }
  787. else
  788. {
  789. CreateHole = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xHole, yHole, (int)CreateRectangleType.Circle, "", ChloeClrList[i].sSHoleName, IsWidth, m_DefaultW, m_DefaultH);
  790. }
  791. //获取样品孔默认尺寸
  792. m_DefaultStageWidth = CreateHole.Region.Width;
  793. m_DefaultStageHeight = CreateHole.Region.Height;
  794. //绘制样品孔路径
  795. GraphicsPath HolePath = new GraphicsPath();
  796. if (ChloeClrList[i].iSHoleShape == (int)CreateRectangleType.Circle)
  797. {
  798. HolePath.AddEllipse(CreateHole.Region);
  799. }
  800. else
  801. {
  802. HolePath.AddRectangle(CreateHole.Region);
  803. }
  804. CreateHole.GPath = HolePath;
  805. m_SampleHoleGDIObjects.Add(CreateHole);
  806. //添加文字
  807. CreateRectangle CreateContent = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xHole, yHole, (int)CreateRectangleType.Rectangle, "", "", IsWidth, m_DefaultW, m_DefaultH);
  808. //类型 文字:2
  809. CreateContent.CreateType = (int)CreateRectangleType.Font;
  810. CreateContent.Region = CreateHole.Region;
  811. CreateContent.strContent = ChloeClrList[i].sSHoleName;
  812. CreateContent.Name = ChloeClrList[i].sSHoleName;
  813. m_ContentGDIObjects.Add(CreateContent);
  814. }
  815. }
  816. //获取标样
  817. int StageShapes = SData.bStageShape;
  818. Point xSTD = new Point(SData.SampleRect.Left, SData.SampleRect.Top);
  819. Point ySTD = new Point(SData.SampleRect.Right, SData.SampleRect.Bottom);
  820. //获取矩形
  821. CreateRectangle CreateSTD = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xSTD, ySTD, (int)CreateRectangleType.Rectangle, "", "", IsWidth, m_DefaultW, m_DefaultH);
  822. if (StageShapes == (int)CreateRectangleType.Circle)
  823. {
  824. CreateSTD = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xSTD, ySTD, (int)CreateRectangleType.SpecimenCircle, "", "", IsWidth, m_DefaultW, m_DefaultH);
  825. }
  826. else
  827. {
  828. CreateSTD = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xSTD, ySTD, (int)CreateRectangleType.SpecimenRectangle, "", "", IsWidth, m_DefaultW, m_DefaultH);
  829. }
  830. m_DefaultSampleWidth = CreateSTD.Region.Width;
  831. m_DefaultSampleHeight = CreateSTD.Region.Height;
  832. //绘制标样路径
  833. GraphicsPath STDPath = new GraphicsPath();
  834. if (StageShapes == (int)CreateRectangleType.Circle)
  835. {
  836. STDPath.AddEllipse(CreateSTD.Region);
  837. }
  838. else
  839. {
  840. STDPath.AddRectangle(CreateSTD.Region);
  841. }
  842. CreateSTD.GPath = STDPath;
  843. m_SpecimenGDIObjects.Add(CreateSTD);
  844. return;
  845. }
  846. catch (Exception ex)
  847. {
  848. string message = table["message2"].ToString();
  849. log.Error("OTSSamplespaceWindow_DrawSampleInfo():--" + message + ":" + ex.ToString() + "");
  850. }
  851. }
  852. #endregion
  853. private string m_fileName = string.Empty;
  854. public string FileName
  855. {
  856. get { return m_fileName; }
  857. set
  858. {
  859. if (value != string.Empty)
  860. {
  861. Stream s = new FileStream(value, FileMode.Open);
  862. FileInfo efInfo = new FileInfo(value);
  863. string fext = efInfo.Extension.ToUpper();
  864. s.Close();
  865. }
  866. m_fileName = value;
  867. this.ToolTipText = value;
  868. }
  869. }
  870. #endregion
  871. private void GetTriangleExcenterRadius(PointF px1, PointF px2, PointF px3, out float R, out PointF center)
  872. {
  873. float x1, y1, x2, y2, x3, y3;
  874. float a, b;
  875. x1 = px1.X;
  876. y1 = px1.Y;
  877. x2 = px2.X;
  878. y2 = px2.Y;
  879. x3 = px3.X;
  880. y3 = px3.Y;
  881. a = ((y2 - y1) * (y3 * y3 - y1 * y1 + x3 * x3 - x1 * x1) - (y3 - y1) * (y2 * y2 - y1 * y1 + x2 * x2 - x1 * x1)) / (2 * ((x3 - x1) * (y2 - y1) - (x2 - x1) * (y3 - y1)));
  882. b = ((x2 - x1) * (x3 * x3 - x1 * x1 + y3 * y3 - y1 * y1) - (x3 - x1) * (x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1)) / (2 * ((y3 - y1) * (x2 - x1) - (y2 - y1) * (x3 - x1)));
  883. center = new PointF(a, b);
  884. R = (float)Math.Sqrt((x1 - a) * (x1 - a) + (y1 - b) * (y1 - b));
  885. }
  886. private float GetDistance(PointF A, PointF B)
  887. {
  888. return (float)Math.Sqrt(Math.Pow((A.X - B.X), 2) + Math.Pow((A.Y - B.Y), 2));
  889. }
  890. #region 窗体事件
  891. private void OTSSamplespaceWindow_Load(object sender, EventArgs e)
  892. {
  893. try
  894. {
  895. //样品台
  896. m_RectangleGDIObjects = new List<ARectangleGDIObject>();
  897. //标样
  898. m_SpecimenGDIObjects = new List<ARectangleGDIObject>();
  899. //样品孔
  900. m_SampleHoleGDIObjects = new List<ARectangleGDIObject>();
  901. //样品孔文字内容
  902. m_ContentGDIObjects = new List<ARectangleGDIObject>();
  903. //样品
  904. m_SampleGDIObjects = new List<ARectangleGDIObject>();
  905. //工作样品
  906. m_WorkStageGDIObjects = new List<ARectangleGDIObject>();
  907. //测量区域
  908. m_MeasureGDIObjects = new List<ARectangleGDIObject>();
  909. //测量区域图形路径
  910. m_MeasurePathGDIObjects = new List<ARectangleGDIObject>();
  911. //手绘测量区域
  912. m_DrawMeasureGDIObjects = new List<ARectangleGDIObject>();
  913. //帧图
  914. m_SingleGDIObjects = new List<ARectangleGDIObject>();
  915. //所有帧图
  916. m_ALLSingleGDIObjects = new List<ARectangleGDIObject>();
  917. //样品孔BSE图像
  918. m_ImageGDIObjects = new List<ARectangleGDIObject>();
  919. //BSE图像帧图为了获取位置与尺寸
  920. m_ImageSingleGDIObjects = new List<ARectangleGDIObject>();
  921. //SEM中心位置
  922. m_SEMCenterGDIObjects = new List<ARectangleGDIObject>();
  923. this.ResizeRedraw = true;
  924. log = NLog.LogManager.GetCurrentClassLogger();
  925. }
  926. catch (Exception ex)
  927. {
  928. string message = table["message2"].ToString();
  929. log.Error("OTSSamplespaceWindow_OTSSamplespaceWindow_Load:--" + message + ":" + ex.ToString() + "");
  930. }
  931. }
  932. protected override void OnMouseDown(MouseEventArgs e)
  933. {
  934. lblFocus.Focus();
  935. //记录鼠标按下的位置
  936. m_P.X = e.X;
  937. m_P.Y = e.Y;
  938. m_P1.X = e.X;
  939. m_P1.Y = e.Y;
  940. int WH = 2;
  941. //鼠标点击时的位置
  942. Point _Point = new Point();
  943. m_RectangIsDragging = false;
  944. if (m_RectangleGDIObjects == null)
  945. return;
  946. //判断当前是否手绘
  947. if (m_IsDrawMeasureReady)
  948. {
  949. //获取当前的鼠标点击位置
  950. this.m_MouseDownPoint = new Point(e.X, e.Y);
  951. //获取当前工作样品
  952. COTSSample cSample = m_MeasureAppForm.m_ProjParam.GetWorkSample();
  953. string sampleHoleName = cSample.GetSampleHoleName();
  954. string sampleName = cSample.GetName();
  955. int sizeWH = 5;
  956. Size size = new Size(sizeWH, sizeWH);
  957. Rectangle rectangle = new Rectangle(m_MouseDownPoint, size);
  958. //绘制多边形 测量区域
  959. if (m_DrawMeasureType == (int)CreateRectangleType.Polygon)
  960. {
  961. //显示绘制多边形完成标识
  962. if (m_PolygonPoint.Count > m_PointCount)
  963. {
  964. Point startPoint = new Point((int)(m_PolygonPoint[0].X), (int)(m_PolygonPoint[0].Y));
  965. if (m_IsDrawPolygonFinish)
  966. {
  967. DialogResult dResult = MessageBox.Show(table["message10"].ToString(), table["message11"].ToString(), MessageBoxButtons.YesNo);
  968. if (dResult == DialogResult.Yes)
  969. {
  970. m_PolygonPoint.Add(startPoint);
  971. CreateRectangle createFinishPoint = new CreateRectangle(m_PolygonPoint, (int)CreateRectangleType.Polygon, m_DrawMeasureType, sampleHoleName, sampleName, Color.Red);
  972. GraphicsPath PolygonMeasurePath = new GraphicsPath();
  973. PolygonMeasurePath.AddPolygon(m_PolygonPoint.ToArray());
  974. createFinishPoint.GPath = PolygonMeasurePath;
  975. for (int i = 0; i < createFinishPoint.PolygonPointRegionF.Count; i++)
  976. {
  977. float X = createFinishPoint.PolygonPointRegionF[i].X / m_GlobalZoomNum;
  978. float Y = createFinishPoint.PolygonPointRegionF[i].Y / m_GlobalZoomNum;
  979. PointF DrawPoint = new PointF(X, Y);
  980. createFinishPoint.DrawPolygonPointRegionF[i] = DrawPoint;
  981. }
  982. if (m_DrawMeasureGDIObjects.Count > 0)
  983. {
  984. m_DrawMeasureGDIObjects[0] = createFinishPoint;
  985. }
  986. bool IsSingle = false;
  987. //清除当前的样品测量区域
  988. for (int measureIndex = m_MeasureGDIObjects.Count - 1; measureIndex >= 0; measureIndex--)
  989. {
  990. if (m_MeasureGDIObjects[measureIndex].SampleName == sampleName)
  991. {
  992. IsSingle = m_MeasureGDIObjects[measureIndex].IsSingle;
  993. m_MeasureGDIObjects.RemoveAt(measureIndex);
  994. break;
  995. }
  996. }
  997. //删除存在的帧图
  998. for (int singleIndex = m_SingleGDIObjects.Count - 1; singleIndex >= 0; singleIndex--)
  999. {
  1000. if (m_SingleGDIObjects[singleIndex].SampleName == sampleName)
  1001. {
  1002. m_SingleGDIObjects.RemoveAt(singleIndex);
  1003. }
  1004. }
  1005. //将绘制好的多边形测量区域赋值给 多边形测量区域对象
  1006. if (m_DrawMeasureGDIObjects.Count > 0)
  1007. {
  1008. m_DrawMeasureGDIObjects[0].IsSelect = true;
  1009. m_DrawMeasureGDIObjects[0].IsWorkSample = true;
  1010. //创建多边形外接矩形
  1011. m_DrawMeasureGDIObjects[0].Region = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(OTSSamplespaceGraphicsPanelFun.PointConvertPointF(m_DrawMeasureGDIObjects[0].PolygonPointRegion));
  1012. m_DrawMeasureGDIObjects[0].RegionF = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(m_DrawMeasureGDIObjects[0].DrawPolygonPointRegionF);
  1013. m_DrawMeasureGDIObjects[0].DrawRegionF = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(m_DrawMeasureGDIObjects[0].DrawPolygonPointRegionF);
  1014. m_DrawMeasureGDIObjects[0].IsSingle = IsSingle;
  1015. m_DrawMeasureGDIObjects[0].IsWorkSample = true;
  1016. m_MeasureGDIObjects.Add(m_DrawMeasureGDIObjects[0]);
  1017. m_DrawMeasureGDIObjects.Clear();
  1018. m_DrawPolygonFinishGDIObjects.Clear();
  1019. }
  1020. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(m_MeasureGDIObjects[m_MeasureGDIObjects.Count - 1], m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  1021. {
  1022. m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;
  1023. CMeasureThreadWrapper.DoRunType = (int)MSR_THREAD_RunSTATUS.RUNMEASURE;
  1024. //设置工作样品
  1025. m_MeasureAppForm.Rev_SoluWindowReqSwitchWSample_Event(m_SampleSelectName);
  1026. Invalidate();
  1027. }
  1028. //设置手绘标识
  1029. m_IsDrawMeasureReady = false;
  1030. m_IsDrawMeasure = false;
  1031. m_IsDrawPolygonFinish = false;
  1032. this.Cursor = Cursors.Default;
  1033. return;
  1034. }
  1035. else
  1036. {
  1037. return;
  1038. }
  1039. }
  1040. }
  1041. //添加多边形点信息
  1042. m_MouseDownPoint = new Point((int)(m_MouseDownPoint.X), (int)(m_MouseDownPoint.Y));
  1043. m_PolygonPoint.Add(m_MouseDownPoint);
  1044. CreateRectangle createPoint = new CreateRectangle(m_PolygonPoint, (int)CreateRectangleType.Polygon, m_DrawMeasureType, sampleHoleName, sampleName, Color.Red);
  1045. if (m_DrawMeasureGDIObjects.Count > 0)
  1046. {
  1047. m_DrawMeasureGDIObjects[0] = createPoint;
  1048. }
  1049. else
  1050. {
  1051. m_DrawMeasureGDIObjects.Add(createPoint);
  1052. }
  1053. //添加当前绘制的第一点位置,生成多边形测量区域完成标识
  1054. if (m_DrawPolygonFinishGDIObjects.Count == 0)
  1055. {
  1056. int rectSize = m_MinMeasureWidthValue;
  1057. Point PolygonFinishPoint = new Point((int)(m_MouseDownPoint.X - m_MinMeasureWidthValue / 2), (int)(m_MouseDownPoint.Y - m_MinMeasureWidthValue / 2));
  1058. Rectangle pRect = new Rectangle(PolygonFinishPoint, new Size(rectSize, rectSize));
  1059. CreateRectangle createPolygonFinish = new CreateRectangle(pRect, (int)CreateRectangleType.DrawPolygonFinish, sampleHoleName, sampleName, Color.Green);
  1060. m_DrawPolygonFinishGDIObjects.Add(createPolygonFinish);
  1061. }
  1062. return;
  1063. }
  1064. else if(m_DrawMeasureType == (int)CreateRectangleType.CircleByThreePoints)
  1065. {
  1066. //添加多边形点信息
  1067. m_MouseDownPoint = new Point((int)(m_MouseDownPoint.X), (int)(m_MouseDownPoint.Y));
  1068. m_PolygonPoint.Add(m_MouseDownPoint);
  1069. CreateRectangle createPoint = new CreateRectangle(m_PolygonPoint, (int)CreateRectangleType.Polygon, m_DrawMeasureType, sampleHoleName, sampleName, Color.Red);
  1070. if (m_DrawMeasureGDIObjects.Count > 0)
  1071. {
  1072. m_DrawMeasureGDIObjects[0] = createPoint;
  1073. }
  1074. else
  1075. {
  1076. m_DrawMeasureGDIObjects.Add(createPoint);
  1077. }
  1078. //显示绘制多边形完成标识
  1079. if (m_PolygonPoint.Count == 3)
  1080. {
  1081. //转为圆形这里
  1082. //m_DrawMeasureType = (int)CreateRectangleType.Circle;
  1083. float r = 0;
  1084. PointF Centerpoint = new PointF();
  1085. GetTriangleExcenterRadius(m_PolygonPoint[0], m_PolygonPoint[1], m_PolygonPoint[2], out r, out Centerpoint);
  1086. RectangleF rectangleThree = new RectangleF(new PointF(Centerpoint.X-r, Centerpoint.Y-r), new SizeF(r*2, r*2));
  1087. //在样品台内部缩放
  1088. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(new Rectangle(new Point((int)(Centerpoint.X - r), (int)(Centerpoint.Y - r)), new Size((int)r * 2, (int)r * 2)), m_RectangleGDIObjects[0].Region, (int)CreateRectangleType.Circle))
  1089. {
  1090. m_IsDrawMeasure = true;
  1091. }
  1092. else
  1093. {
  1094. m_IsDrawMeasure = false;
  1095. return;
  1096. }
  1097. Color MeasureColor = Color.Red;
  1098. CreateRectangle createRectangle = new CreateRectangle(rectangleThree, m_PolygonPoint[0], (int)CreateRectangleType.CircleByThreePoints, m_DrawMeasureType, sampleName, sampleName, MeasureColor);
  1099. //在鼠标点击时添加一个默认大小与位置的图形
  1100. createRectangle.RegionF = createRectangle.Region;
  1101. createRectangle.DrawRegionF = createRectangle.Region;
  1102. if (m_DrawMeasureGDIObjects.Count > 0)
  1103. {
  1104. m_DrawMeasureGDIObjects[0] = createRectangle;
  1105. }
  1106. else
  1107. {
  1108. m_DrawMeasureGDIObjects.Add(createRectangle);
  1109. }
  1110. //清除当前的样品测量区域
  1111. for (int measureIndex = m_MeasureGDIObjects.Count - 1; measureIndex >= 0; measureIndex--)
  1112. {
  1113. if (m_MeasureGDIObjects[measureIndex].SampleName == sampleName)
  1114. {
  1115. m_MeasureGDIObjects.RemoveAt(measureIndex);
  1116. break;
  1117. }
  1118. }
  1119. //删除存在的帧图
  1120. for (int singleIndex = m_SingleGDIObjects.Count - 1; singleIndex >= 0; singleIndex--)
  1121. {
  1122. if (m_SingleGDIObjects[singleIndex].SampleName == sampleName)
  1123. {
  1124. m_SingleGDIObjects.RemoveAt(singleIndex);
  1125. }
  1126. }
  1127. m_MeasureGDIObjects.Add(m_DrawMeasureGDIObjects[0]);
  1128. m_DrawMeasureGDIObjects.Clear();
  1129. //设置手绘标识
  1130. m_IsDrawMeasureReady = false;
  1131. this.Cursor = Cursors.Default;
  1132. return;
  1133. }
  1134. return;
  1135. }
  1136. else
  1137. {
  1138. //在样品台内部缩放
  1139. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(new Rectangle(this.m_MouseDownPoint, new Size(2, 2)), m_RectangleGDIObjects[0].Region, m_DrawMeasureType))
  1140. {
  1141. m_IsDrawMeasure = true;
  1142. }
  1143. else
  1144. {
  1145. m_IsDrawMeasure = false;
  1146. return;
  1147. }
  1148. Color MeasureColor = Color.Red;
  1149. CreateRectangle createRectangle = new CreateRectangle(rectangle, m_DifferentPoint, (int)CreateRectangleType.MeasureArea, m_DrawMeasureType, sampleName, sampleName, MeasureColor);
  1150. //在鼠标点击时添加一个默认大小与位置的图形
  1151. createRectangle.RegionF = createRectangle.Region;
  1152. createRectangle.DrawRegionF = createRectangle.Region;
  1153. m_DrawMeasureGDIObjects.Add(createRectangle);
  1154. return;
  1155. }
  1156. }
  1157. else
  1158. {
  1159. if (e.Button == MouseButtons.Right)
  1160. {
  1161. if (m_MeasureAppForm.MeasureThreadRunFlag)
  1162. {
  1163. m_IsSelectType = (int)ContextMenuType.ThreadRunMenu;
  1164. //设置编辑右键菜单项
  1165. CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, false);
  1166. _Point = this.PointToClient(Cursor.Position);
  1167. this.CMStrip.Show(this, _Point);
  1168. return;
  1169. }
  1170. //获取鼠标右键点击位置
  1171. m_MouseDownLocation = e.Location;
  1172. //显示XY轴
  1173. OTSSamplespaceGraphicsPanelFun.ShowSemCoordvAL(e.Location, m_MeasureAppForm, m_RectangleGDIObjects, m_OTSSampleStageData, IsWidth);
  1174. string workSampleName = string.Empty;
  1175. foreach (ARectangleGDIObject item in m_SingleGDIObjects)
  1176. {
  1177. if (item.RegionF.Contains(e.Location))
  1178. {
  1179. //样品孔菜单
  1180. m_IsSelectType = (int)ContextMenuType.SingleMenu;
  1181. _Point = this.PointToClient(Cursor.Position);
  1182. bool IsTrue = false;
  1183. //设置编辑右键菜单项
  1184. foreach (ARectangleGDIObject imageItem in m_ImageGDIObjects)
  1185. {
  1186. if (imageItem.SampleName == item.SampleName)
  1187. {
  1188. IsTrue = true;
  1189. break;
  1190. }
  1191. }
  1192. //设置编辑右键菜单项
  1193. CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, IsTrue);
  1194. //将删除样品与测量 设置为不可编辑状态
  1195. this.CMStrip.Show(this, _Point);
  1196. return;
  1197. }
  1198. }
  1199. foreach (ARectangleGDIObject item in m_SampleGDIObjects)
  1200. {
  1201. if (item.IsWorkSample)
  1202. {
  1203. workSampleName = item.SampleName;
  1204. break;
  1205. }
  1206. }
  1207. for (int i = m_MeasureGDIObjects.Count - 1; i >= 0; i--)
  1208. {
  1209. foreach (var SampleItem in m_SampleGDIObjects)
  1210. {
  1211. if (m_MeasureGDIObjects[i].SampleName == SampleItem.SampleName)
  1212. {
  1213. bool isSelMeasure = false;
  1214. if (m_MeasureGDIObjects[i].Shape == (int)CreateRectangleType.Polygon)
  1215. {
  1216. //判断当前位置是否在不规则形状里面
  1217. if (OTSSamplespaceGraphicsPanelFun.PositionPnpoly(OTSSamplespaceGraphicsPanelFun.PointFConvertPoint(m_MeasureGDIObjects[i].PolygonPointRegionF), e.Location) && !m_MeasureGDIObjects[i].SelColor.Name.Equals("Transparent"))
  1218. {
  1219. isSelMeasure = true;
  1220. }
  1221. }
  1222. else
  1223. {
  1224. if (m_MeasureGDIObjects[i].Region.Contains(e.Location) && !m_MeasureGDIObjects[i].SelColor.Name.Equals("Transparent"))
  1225. {
  1226. isSelMeasure = true;
  1227. Rectangle rect = new Rectangle(e.Location, new Size(WH, WH));
  1228. int CheckShape = (int)CreateRectangleType.Circle;
  1229. if (m_MeasureGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  1230. {
  1231. CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;
  1232. }
  1233. if (!OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rect, m_MeasureGDIObjects[i].Region, CheckShape))
  1234. {
  1235. break;
  1236. }
  1237. }
  1238. }
  1239. if (isSelMeasure)
  1240. {
  1241. //如果选择的样品不是当前工作样品 则删除原有帧图信息
  1242. if (m_MeasureGDIObjects[i].SampleName != workSampleName)
  1243. {
  1244. ClearImageAndSingleGDIObjects();
  1245. }
  1246. //删除BSE照片
  1247. bool IsTrue = false;
  1248. //设置编辑右键菜单项
  1249. foreach (ARectangleGDIObject imageItem in m_ImageGDIObjects)
  1250. {
  1251. if (imageItem.SampleName == m_MeasureGDIObjects[i].SampleName)
  1252. {
  1253. IsTrue = true;
  1254. break;
  1255. }
  1256. }
  1257. //测量区域菜单
  1258. m_IsSelectType = (int)ContextMenuType.MeasureMenu;
  1259. //设置编辑右键菜单项
  1260. CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, IsTrue);
  1261. _Point = this.PointToClient(Cursor.Position);
  1262. this.CMStrip.Show(this, _Point);
  1263. m_MeasureSelectName = m_MeasureGDIObjects[i].SampleName;
  1264. m_SampleHoleSelectName = m_MeasureGDIObjects[i].Name;
  1265. if (m_SampleSelectName != m_MeasureGDIObjects[i].SampleName)
  1266. {
  1267. m_SampleSelectName = m_MeasureGDIObjects[i].SampleName;
  1268. m_MeasureGDIObjects[i].IsSelect = true;
  1269. m_MeasureGDIObjects[i].IsWorkSample = true;
  1270. //设置工作样品
  1271. m_MeasureAppForm.Rev_SoluWindowReqSwitchWSample_Event(m_SampleSelectName);
  1272. Invalidate();
  1273. }
  1274. return;
  1275. }
  1276. }
  1277. }
  1278. }
  1279. foreach (ARectangleGDIObject item in m_ImageGDIObjects)
  1280. {
  1281. if (item.Region.Contains(e.Location))
  1282. {
  1283. //样品孔菜单
  1284. m_IsSelectType = (int)ContextMenuType.SampleHoleBSEImage;
  1285. _Point = this.PointToClient(Cursor.Position);
  1286. //设置编辑右键菜单项
  1287. CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, false);
  1288. this.CMStrip.Show(this, _Point);
  1289. return;
  1290. }
  1291. }
  1292. //只点击样品上(测量区域被移动到其他地方)
  1293. for (int i = m_SampleGDIObjects.Count - 1; i >= 0; i--)
  1294. {
  1295. if (m_SampleGDIObjects[i].Region.Contains(e.Location))
  1296. {
  1297. //如果选择的样品不是当前工作样品 则删除原有帧图信息
  1298. if (m_SampleGDIObjects[i].SampleName != workSampleName)
  1299. {
  1300. ClearImageAndSingleGDIObjects();
  1301. }
  1302. Rectangle rect = new Rectangle(e.Location, new Size(WH, WH));
  1303. //判断样品形状
  1304. int CheckShape = (int)CreateRectangleType.Circle;
  1305. if (m_MeasureGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  1306. {
  1307. CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;
  1308. }
  1309. if (!OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rect, m_SampleGDIObjects[i].Region, CheckShape))
  1310. {
  1311. break;
  1312. }
  1313. //样品菜单
  1314. m_IsSelectType = (int)ContextMenuType.SampleMenu;
  1315. //将删除样品与测量 设置为不可编辑状态
  1316. _Point = this.PointToClient(Cursor.Position);
  1317. bool flag = false;
  1318. foreach (var MeasureItem in m_MeasureGDIObjects)
  1319. {
  1320. if (m_SampleGDIObjects[i].SampleName == MeasureItem.SampleName)
  1321. {
  1322. if (MeasureItem.Region.Contains(e.Location))
  1323. {
  1324. //测量区域菜单
  1325. m_IsSelectType = (int)ContextMenuType.MeasureMenu;
  1326. //flag = !MeasureItem.IsSingle;
  1327. break;
  1328. }
  1329. }
  1330. }
  1331. //设置编辑右键菜单项
  1332. CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, flag);
  1333. this.CMStrip.Show(this, _Point);
  1334. if (m_SampleSelectName != m_SampleGDIObjects[i].SampleName)
  1335. {
  1336. m_SampleSelectName = m_SampleGDIObjects[i].SampleName;
  1337. m_SampleHoleSelectName = m_SampleGDIObjects[i].Name;
  1338. m_SampleGDIObjects[i].IsSelect = true;
  1339. m_SampleGDIObjects[i].IsWorkSample = true;
  1340. //设置工作样品 向主窗体发送请求
  1341. m_MeasureAppForm.Rev_SoluWindowReqSwitchWSample_Event(m_SampleSelectName);
  1342. Invalidate();
  1343. }
  1344. return;
  1345. }
  1346. }
  1347. //点击样品孔
  1348. foreach (ARectangleGDIObject item in m_SampleHoleGDIObjects)
  1349. {
  1350. if (item.Region.Contains(e.Location))
  1351. {
  1352. Rectangle rect = new Rectangle(e.Location, new Size(WH, WH));
  1353. int CheckShape = (int)CreateRectangleType.Circle;
  1354. if (item.Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  1355. {
  1356. CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;
  1357. }
  1358. //样品孔菜单
  1359. m_IsSelectType = (int)ContextMenuType.SampleHoleMenu;
  1360. _Point = this.PointToClient(Cursor.Position);
  1361. //设置编辑右键菜单项
  1362. CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, false);
  1363. //将删除样品与测量 设置为不可编辑状态
  1364. this.CMStrip.Show(this, _Point);
  1365. m_SampleHoleSelectName = item.Name;
  1366. item.IsSelect = true;
  1367. return;
  1368. }
  1369. }
  1370. foreach (ARectangleGDIObject item in m_RectangleGDIObjects)
  1371. {
  1372. if (item.Region.Contains(e.Location))
  1373. {
  1374. //样品台菜单
  1375. m_IsSelectType = (int)ContextMenuType.SampleStateMenu;
  1376. //设置编辑右键菜单项
  1377. CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, false);
  1378. _Point = this.PointToClient(Cursor.Position);
  1379. this.CMStrip.Show(this, _Point);
  1380. break;
  1381. }
  1382. }
  1383. return;
  1384. }
  1385. //左键点击样品台上
  1386. else
  1387. {
  1388. //如果正在进行测量线程,则退出鼠标点击操作
  1389. if (m_MeasureAppForm.MeasureThreadRunFlag)
  1390. {
  1391. return;
  1392. }
  1393. foreach (ARectangleGDIObject item in m_RectangleGDIObjects)
  1394. {
  1395. if (item.Region.Contains(e.Location))
  1396. {
  1397. m_RectangIsDragging = true;
  1398. m_IsSelectSampleStage = true;
  1399. }
  1400. item.IsDragging = true;
  1401. item.DraggingPoint = e.Location;
  1402. }
  1403. //测量区域
  1404. foreach (ARectangleGDIObject item in m_MeasureGDIObjects)
  1405. {
  1406. if (Control.ModifierKeys == Keys.Control)
  1407. {
  1408. //获取选择工作样品的测量状态
  1409. selWSampleMeasureStatus = m_MeasureAppForm.m_ProjParam.GetWorkSampleMeasureStatus();
  1410. if (selWSampleMeasureStatus)
  1411. {
  1412. return;
  1413. }
  1414. //如果选择的测量区域 颜色不是透明 可以选择
  1415. if (!item.SelColor.Name.Equals("Transparent"))
  1416. {
  1417. if (item.CreateType == (int)CreateRectangleType.Polygon)
  1418. {
  1419. if (item.GPath != null)
  1420. {
  1421. //在多边形点附近切换光标
  1422. foreach (PointF itemPoint in item.PolygonPointRegionF)
  1423. {
  1424. if (Math.Abs(itemPoint.X - e.X) <= m_OffsetPX && Math.Abs(itemPoint.Y - e.Y) <= m_OffsetPX)
  1425. {
  1426. if (Control.ModifierKeys == Keys.Control)
  1427. {
  1428. if (m_DrawPolygonFinishGDIObjects != null)
  1429. {
  1430. if (m_DrawPolygonFinishGDIObjects.Count > 0)
  1431. {
  1432. m_DrawPolygonFinishGDIObjects.Clear();
  1433. }
  1434. }
  1435. m_IsSelPolygonPoint = true;
  1436. m_IsCtrl = true;
  1437. m_IsSelectSampleStage = false;
  1438. //选择前测量区域的尺寸
  1439. m_SelMeasureRect = item.Region;
  1440. m_MeasureRectangle = item.Region;
  1441. item.SelColor = Color.Red;
  1442. item.IsDragging = true;
  1443. item.DraggingPoint = e.Location;
  1444. item.IsSelect = true;
  1445. item.IsWorkSample = true;
  1446. //记录选择的多边形点信息
  1447. m_SelPolygonPoint = itemPoint;
  1448. int rectSize = m_MinMeasureWidthValue;
  1449. Point PolygonFinishPoint = new Point((int)(itemPoint.X - m_MinMeasureWidthValue / 2), (int)(itemPoint.Y - m_MinMeasureWidthValue / 2));
  1450. Rectangle pRect = new Rectangle(PolygonFinishPoint, new Size(rectSize, rectSize));
  1451. CreateRectangle createPolygonFinish = new CreateRectangle(pRect, (int)CreateRectangleType.DrawPolygonFinish, "", "", Color.Green);
  1452. if (m_DrawPolygonFinishGDIObjects != null)
  1453. {
  1454. m_DrawPolygonFinishGDIObjects.Add(createPolygonFinish);
  1455. }
  1456. break;
  1457. }
  1458. }
  1459. }
  1460. //如果鼠标已选择多边形的点,跳出循环
  1461. if (item.IsSelect == true)
  1462. {
  1463. break;
  1464. }
  1465. if (item.GPath.IsVisible(e.Location))
  1466. {
  1467. m_IsCtrl = true;
  1468. m_IsSelectSampleStage = false;
  1469. //选择前测量区域的尺寸
  1470. m_SelMeasureRect = item.Region;
  1471. m_MeasureRectangle = item.Region;
  1472. item.SelColor = Color.Red;
  1473. item.IsDragging = true;
  1474. item.DraggingPoint = e.Location;
  1475. item.IsWorkSample = true;
  1476. item.IsSelect = false;
  1477. break;
  1478. }
  1479. }
  1480. }
  1481. else
  1482. {
  1483. if (item.GPath != null)
  1484. {
  1485. if (item.GPath.IsOutlineVisible((float)e.X, (float)e.Y, new Pen(Color.Gray, m_PenWidth)))
  1486. {
  1487. m_IsCtrl = true;
  1488. m_IsSelectSampleStage = false;
  1489. //选择前测量区域的尺寸
  1490. m_SelMeasureRect = item.Region;
  1491. m_MeasureRectangle = item.Region;
  1492. item.SelColor = Color.Red;
  1493. item.IsDragging = true;
  1494. item.DraggingPoint = e.Location;
  1495. item.IsSelect = true;
  1496. item.IsWorkSample = true;
  1497. break;
  1498. }
  1499. }
  1500. if (item.Region.Contains(e.Location))
  1501. {
  1502. m_IsCtrl = true;
  1503. m_IsSelectSampleStage = false;
  1504. //选择前测量区域的尺寸
  1505. m_SelMeasureRect = item.Region;
  1506. m_MeasureRectangle = item.Region;
  1507. item.SelColor = Color.Red;
  1508. item.IsDragging = true;
  1509. item.DraggingPoint = e.Location;
  1510. item.IsWorkSample = true;
  1511. item.IsSelect = false;
  1512. break;
  1513. }
  1514. }
  1515. }
  1516. }
  1517. }
  1518. //当鼠标点击样品上(测量区域被拖动到其他地方)
  1519. for (int i = m_SampleGDIObjects.Count - 1; i >= 0; i--)
  1520. {
  1521. if ((Control.ModifierKeys == Keys.Alt))
  1522. {
  1523. if (m_SampleGDIObjects[i].Region.Contains(e.Location))
  1524. {
  1525. m_IsMoveSample = true;
  1526. m_IsSelectSampleStage = false;
  1527. m_IsAlt = true;
  1528. }
  1529. }
  1530. if (!(Control.ModifierKeys == Keys.Control))
  1531. {
  1532. if (m_SampleGDIObjects[i].Region.Contains(e.Location))
  1533. {
  1534. foreach (var measureItem in m_MeasureGDIObjects)
  1535. {
  1536. if (measureItem.SampleName == m_SampleGDIObjects[i].SampleName)
  1537. {
  1538. m_MeasureRectangle = measureItem.Region;
  1539. measureItem.SelColor = Color.Red;
  1540. }
  1541. else
  1542. {
  1543. measureItem.SelColor = Color.Transparent;
  1544. }
  1545. }
  1546. for (int x = 0; x < m_SampleGDIObjects.Count; x++)
  1547. {
  1548. //获取颜色
  1549. string SampleColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
  1550. m_SampleGDIObjects[x].SelColor = ColorTranslator.FromHtml(SampleColorStr);
  1551. m_SampleGDIObjects[x].IsWorkSample = false;
  1552. m_SampleGDIObjects[x].IsSelect = false;
  1553. }
  1554. //设置为工作样品
  1555. m_SampleGDIObjects[i].IsWorkSample = true;
  1556. m_SampleGDIObjects[i].IsSelect = true;
  1557. //获取颜色
  1558. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  1559. m_SampleGDIObjects[i].SelColor = ColorTranslator.FromHtml(ColorStr);
  1560. selectSampleGDIObjects = m_SampleGDIObjects[i];
  1561. if (m_SampleSelectName != m_SampleGDIObjects[i].SampleName)
  1562. {
  1563. //获取工作样品名称
  1564. m_SampleSelectName = m_SampleGDIObjects[i].SampleName;
  1565. //设置工作样品 向主窗体发送请求
  1566. m_MeasureAppForm.Rev_SoluWindowReqSwitchWSample_Event(m_SampleSelectName);
  1567. }
  1568. break;
  1569. }
  1570. }
  1571. }
  1572. //样品
  1573. MouseDownFucntion(m_SampleGDIObjects, e);
  1574. //样品孔
  1575. MouseDownFucntion(m_SampleHoleGDIObjects, e);
  1576. //标样
  1577. MouseDownFucntion(m_SpecimenGDIObjects, e);
  1578. //测量
  1579. MouseDownFucntion(m_MeasureGDIObjects, e);
  1580. //文字
  1581. MouseDownFucntion(m_ContentGDIObjects, e);
  1582. //帧图
  1583. MouseDownFucntion(m_SingleGDIObjects, e);
  1584. //所有获取的帧图
  1585. MouseDownFucntion(m_ALLSingleGDIObjects, e);
  1586. //样品台中BSE图片
  1587. MouseDownFucntion(m_ImageGDIObjects, e);
  1588. //SEM中心位置
  1589. MouseDownFucntion(m_SEMCenterGDIObjects, e);
  1590. for (int i = m_SampleGDIObjects.Count - 1; i >= 0; i--)
  1591. {
  1592. if (m_SampleGDIObjects[i].Region.Contains(e.Location) && m_SampleGDIObjects[i].IsWorkSample)
  1593. {
  1594. //获取当前样品与测量区域的位置
  1595. foreach (ARectangleGDIObject item in m_MeasureGDIObjects)
  1596. {
  1597. if (m_SampleGDIObjects[i].SampleName == item.SampleName && m_SampleGDIObjects[i].IsWorkSample)
  1598. {
  1599. m_MeasureToSamplePoint.X = m_SampleGDIObjects[i].Region.X - item.Region.X;
  1600. m_MeasureToSamplePoint.Y = m_SampleGDIObjects[i].Region.Y - item.Region.Y;
  1601. break;
  1602. }
  1603. }
  1604. }
  1605. }
  1606. }
  1607. }
  1608. //重绘控件
  1609. Invalidate();
  1610. }
  1611. protected override void OnMouseMove(MouseEventArgs e)
  1612. {
  1613. //'记录光标拖动的当前点
  1614. m_P1.X = e.X;
  1615. m_P1.Y = e.Y;
  1616. bool InMeasure = false;
  1617. //如果正在进行测量线程,则退出鼠标点击操作
  1618. if (m_MeasureAppForm.MeasureThreadRunFlag)
  1619. {
  1620. return;
  1621. }
  1622. //获取选择工作样品的测量状态
  1623. if (selWSampleMeasureStatus)
  1624. {
  1625. return;
  1626. }
  1627. //手动绘制 记录鼠标移动位置
  1628. if (m_IsDrawMeasure)
  1629. {
  1630. this.m_MouseMovePoint = new Point(e.X, e.Y);
  1631. //绘制多边形
  1632. if (m_DrawMeasureType == (int)CreateRectangleType.Polygon)
  1633. {
  1634. PointF startPoint = new PointF();
  1635. PointF endPoint = new PointF();
  1636. //显示直线开始点与鼠标当前位置的直线
  1637. if (m_PolygonPoint.Count > 0)
  1638. {
  1639. startPoint = m_PolygonPoint[0];
  1640. endPoint = m_PolygonPoint[m_PolygonPoint.Count - 1];
  1641. }
  1642. //显示绘制多边形完成标识
  1643. if (m_PolygonPoint.Count > m_PointCount)
  1644. {
  1645. if (Math.Abs(m_MouseMovePoint.X - startPoint.X) <= m_OffsetPX && Math.Abs(m_MouseMovePoint.Y - startPoint.Y) <= m_OffsetPX)
  1646. {
  1647. //显示绘制多边形完成标识
  1648. m_IsDrawPolygonFinish = true;
  1649. }
  1650. else
  1651. {
  1652. m_IsDrawPolygonFinish = false;
  1653. }
  1654. }
  1655. }
  1656. //圆形三点法
  1657. else if (m_DrawMeasureType == (int)CreateRectangleType.CircleByThreePoints)
  1658. {
  1659. PointF startPoint = new PointF();
  1660. PointF endPoint = new PointF();
  1661. //显示直线开始点与鼠标当前位置的直线
  1662. if (m_PolygonPoint.Count > 0)
  1663. {
  1664. startPoint = m_PolygonPoint[0];
  1665. endPoint = m_PolygonPoint[m_PolygonPoint.Count - 1];
  1666. }
  1667. }
  1668. else
  1669. {
  1670. if (m_DrawMeasureGDIObjects == null || m_RectangleGDIObjects == null)
  1671. {
  1672. return;
  1673. }
  1674. Rectangle rectangle = new Rectangle();
  1675. foreach (var item in m_DrawMeasureGDIObjects)
  1676. {
  1677. rectangle = item.Region;
  1678. //移动鼠标绘制测量区域
  1679. 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));
  1680. if (tmp == 0)
  1681. {
  1682. tmp = m_DValue;
  1683. }
  1684. //移动鼠标绘制测量区域
  1685. //以中心绘制测量区域方法
  1686. //rectangle = new Rectangle(m_MouseDownPoint.X - tmp, m_MouseDownPoint.Y - tmp, 2 * tmp, 2 * tmp);
  1687. OTSSamplespaceGraphicsPanelFun.EnumMousePointPosition enumMouse = OTSSamplespaceGraphicsPanelFun.MousePointPosition(m_MouseDownPoint, m_MouseMovePoint);
  1688. Point LTPoint = new Point();
  1689. Size RBSize = new Size();
  1690. switch (enumMouse)
  1691. {
  1692. case OTSSamplespaceGraphicsPanelFun.EnumMousePointPosition.MouseSizeTopLeft:
  1693. if (m_DrawMeasureType == (int)CreateRectangleType.Circle)
  1694. {
  1695. LTPoint.X = m_MouseDownPoint.X - tmp;
  1696. LTPoint.Y = m_MouseDownPoint.Y - tmp;
  1697. RBSize.Width = tmp;
  1698. RBSize.Height = tmp;
  1699. rectangle = new Rectangle(LTPoint, RBSize);
  1700. }
  1701. else
  1702. {
  1703. LTPoint.X = m_MouseMovePoint.X;
  1704. LTPoint.Y = m_MouseMovePoint.Y;
  1705. RBSize.Width = m_MouseDownPoint.X - m_MouseMovePoint.X;
  1706. RBSize.Height = m_MouseDownPoint.Y - m_MouseMovePoint.Y;
  1707. rectangle = new Rectangle(LTPoint, RBSize);
  1708. }
  1709. break;
  1710. case OTSSamplespaceGraphicsPanelFun.EnumMousePointPosition.MouseSizeTopRight:
  1711. if (m_DrawMeasureType == (int)CreateRectangleType.Circle)
  1712. {
  1713. LTPoint.X = m_MouseDownPoint.X;
  1714. LTPoint.Y = m_MouseDownPoint.Y - tmp;
  1715. RBSize.Width = tmp;
  1716. RBSize.Height = tmp;
  1717. rectangle = new Rectangle(LTPoint, RBSize);
  1718. }
  1719. else
  1720. {
  1721. LTPoint.X = m_MouseDownPoint.X;
  1722. LTPoint.Y = m_MouseDownPoint.Y - (m_MouseDownPoint.Y - m_MouseMovePoint.Y);
  1723. RBSize.Width = m_MouseMovePoint.X - m_MouseDownPoint.X;
  1724. RBSize.Height = m_MouseDownPoint.Y - m_MouseMovePoint.Y;
  1725. rectangle = new Rectangle(LTPoint, RBSize);
  1726. }
  1727. break;
  1728. case OTSSamplespaceGraphicsPanelFun.EnumMousePointPosition.MouseSizeBottomLeft:
  1729. if (m_DrawMeasureType == (int)CreateRectangleType.Circle)
  1730. {
  1731. LTPoint.X = m_MouseDownPoint.X - tmp;
  1732. LTPoint.Y = m_MouseDownPoint.Y;
  1733. RBSize.Width = tmp;
  1734. RBSize.Height = tmp;
  1735. rectangle = new Rectangle(LTPoint, RBSize);
  1736. }
  1737. else
  1738. {
  1739. LTPoint.X = m_MouseDownPoint.X - (m_MouseDownPoint.X - m_MouseMovePoint.X);
  1740. LTPoint.Y = m_MouseDownPoint.Y;
  1741. RBSize.Width = m_MouseDownPoint.X - m_MouseMovePoint.X;
  1742. RBSize.Height = m_MouseMovePoint.Y - m_MouseDownPoint.Y;
  1743. rectangle = new Rectangle(LTPoint, RBSize);
  1744. }
  1745. break;
  1746. case OTSSamplespaceGraphicsPanelFun.EnumMousePointPosition.MouseSizeBottomRight:
  1747. if (m_DrawMeasureType == (int)CreateRectangleType.Circle)
  1748. {
  1749. LTPoint.X = m_MouseDownPoint.X;
  1750. LTPoint.Y = m_MouseDownPoint.Y;
  1751. RBSize.Width = tmp;
  1752. RBSize.Height = tmp;
  1753. rectangle = new Rectangle(LTPoint, RBSize);
  1754. }
  1755. else
  1756. {
  1757. LTPoint.X = m_MouseDownPoint.X;
  1758. LTPoint.Y = m_MouseDownPoint.Y;
  1759. RBSize.Width = m_MouseMovePoint.X - m_MouseDownPoint.X;
  1760. RBSize.Height = m_MouseMovePoint.Y - m_MouseDownPoint.Y;
  1761. rectangle = new Rectangle(LTPoint, RBSize);
  1762. }
  1763. break;
  1764. }
  1765. //在样品台内部缩放
  1766. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectangle, m_RectangleGDIObjects[0].Region, m_DrawMeasureType))
  1767. {
  1768. //移动鼠标绘制测量区域
  1769. //以中心绘制测量区域方法
  1770. //item.Region = new Rectangle(m_MouseDownPoint.X - tmp, m_MouseDownPoint.Y - tmp, 2 * tmp, 2 * tmp);
  1771. item.Region = new Rectangle(LTPoint, RBSize);
  1772. 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));
  1773. item.DrawRegionF = item.RegionF;
  1774. //生成图形路径
  1775. GraphicsPath MeasurePath = new GraphicsPath();
  1776. if (item.Shape == (int)CreateRectangleType.Rectangle)
  1777. {
  1778. MeasurePath.AddRectangle(item.Region);
  1779. }
  1780. else
  1781. {
  1782. MeasurePath.AddEllipse(item.Region);
  1783. }
  1784. item.GPath = MeasurePath;
  1785. break;
  1786. }
  1787. }
  1788. }
  1789. }
  1790. if (m_RectangIsDragging)
  1791. {
  1792. if (m_RectangleGDIObjects == null) { return; }
  1793. if (!m_IsSelectSampleStage)
  1794. {
  1795. foreach (ARectangleGDIObject item in m_SampleGDIObjects)
  1796. {
  1797. if (!m_IsMeasure)
  1798. {
  1799. if (item.Region.Contains(e.Location))
  1800. {
  1801. if (item.IsDragging)
  1802. {
  1803. if (item.IsWorkSample)
  1804. {
  1805. if (item.IsSelect)
  1806. {
  1807. //判断移动的样品 是否在样品台尺寸范围内
  1808. foreach (ARectangleGDIObject measureItem in m_MeasureGDIObjects)
  1809. {
  1810. if (measureItem.SampleName == item.SampleName)
  1811. {
  1812. if (measureItem.CreateType == (int)CreateRectangleType.Polygon)
  1813. {
  1814. if (this.Cursor != Cursors.Default)
  1815. {
  1816. return;
  1817. }
  1818. //判断移动的样品 是否在样品台尺寸范围内
  1819. Rectangle rectTemp = item.Region;
  1820. rectTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;
  1821. rectTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;
  1822. int CheckShape = (int)CreateRectangleType.Circle;
  1823. if (m_RectangleGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  1824. {
  1825. CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;
  1826. }
  1827. //判断样品是否超越样品台
  1828. if (!OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  1829. {
  1830. return;
  1831. }
  1832. else
  1833. {
  1834. //生成多边形最小面积外接矩形
  1835. Rectangle rectMeasureTemp = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(measureItem.PolygonPointRegionF);
  1836. //判断多边形是否超越样品台
  1837. rectMeasureTemp.X = rectMeasureTemp.Left + e.X - measureItem.DraggingPoint.X;
  1838. rectMeasureTemp.Y = rectMeasureTemp.Top + e.Y - measureItem.DraggingPoint.Y;
  1839. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectMeasureTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  1840. {
  1841. Rectangle rectSampleTemp = item.Region;
  1842. rectSampleTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;
  1843. rectSampleTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;
  1844. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectSampleTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  1845. {
  1846. MouseMovePolygonMeasureFucntion(measureItem, e);
  1847. OTSSamplespaceGraphicsPanelFun.GetMouseMoveLocation(item, e);
  1848. //计算两个点之间的距离 移动样品台后与绘制样品台时的位置
  1849. m_DifferentPoint = OTSSamplespaceGraphicsPanelFun.StartToEndPointDist(m_RectangleGDIObjects[0], m_RegionStartCenterPoint);
  1850. isChange = true;
  1851. }
  1852. }
  1853. }
  1854. }
  1855. else
  1856. {
  1857. Rectangle rectMeasureTemp = measureItem.Region;
  1858. rectMeasureTemp.X = measureItem.Region.Left + e.X - measureItem.DraggingPoint.X;
  1859. rectMeasureTemp.Y = measureItem.Region.Top + e.Y - measureItem.DraggingPoint.Y;
  1860. //判断移动的样品 是否在样品台尺寸范围内
  1861. Rectangle rectTemp = item.Region;
  1862. rectTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;
  1863. rectTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;
  1864. int CheckShape = (int)CreateRectangleType.Circle;
  1865. if (m_RectangleGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  1866. {
  1867. CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;
  1868. }
  1869. //判断样品是否超越样品台
  1870. if (!OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  1871. {
  1872. return;
  1873. }
  1874. //判断测量区域是否超越样品台
  1875. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectMeasureTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  1876. {
  1877. Rectangle rectSampleTemp = item.Region;
  1878. rectSampleTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;
  1879. rectSampleTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;
  1880. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectSampleTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  1881. {
  1882. MouseMoveMeasureFucntion(measureItem, e);
  1883. OTSSamplespaceGraphicsPanelFun.GetMouseMoveLocation(item, e);
  1884. //计算两个点之间的距离 移动样品台后与绘制样品台时的位置
  1885. m_DifferentPoint = OTSSamplespaceGraphicsPanelFun.StartToEndPointDist(m_RectangleGDIObjects[0], m_RegionStartCenterPoint);
  1886. isChange = true;
  1887. }
  1888. }
  1889. else
  1890. {
  1891. return;
  1892. }
  1893. }
  1894. }
  1895. }
  1896. }
  1897. foreach (ARectangleGDIObject sampleHoleItem in m_SampleHoleGDIObjects)
  1898. {
  1899. //获取样品孔中心点
  1900. Point sampleHoleCenterPoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(sampleHoleItem);
  1901. if (item.Region.Contains(sampleHoleCenterPoint))
  1902. {
  1903. if (item.Name != sampleHoleItem.Name)
  1904. {
  1905. //获取颜色
  1906. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
  1907. item.SelColor = ColorTranslator.FromHtml(ColorStr);
  1908. break;
  1909. }
  1910. }
  1911. else
  1912. {
  1913. //获取颜色
  1914. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  1915. item.SelColor = ColorTranslator.FromHtml(ColorStr);
  1916. }
  1917. }
  1918. }
  1919. Invalidate();
  1920. }
  1921. }
  1922. }
  1923. }
  1924. foreach (ARectangleGDIObject item in m_MeasureGDIObjects)
  1925. {
  1926. //检测鼠标光标点是否在路径上
  1927. if (item.IsDragging)
  1928. {
  1929. if (item.IsWorkSample)
  1930. {
  1931. if (item.IsSelect)
  1932. {
  1933. if (item.DraggingPoint != Point.Empty)
  1934. {
  1935. //获取中心点
  1936. Point xy1 = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(item.Region);
  1937. //获取鼠标坐标
  1938. Point xy2 = e.Location;
  1939. Rectangle rectTemp = new Rectangle();
  1940. int CheckShape = (int)CreateRectangleType.Circle;
  1941. if (item.CreateType == (int)CreateRectangleType.Polygon)
  1942. {
  1943. if (m_IsSelPolygonPoint)
  1944. {
  1945. //获取选中点进行移动,代码
  1946. #region MyRegion
  1947. if (Control.ModifierKeys == Keys.Control)
  1948. {
  1949. //int pointCount = m_DrawPolygonFinishGDIObjects.Count;
  1950. //在多边形点附近切换光标
  1951. for (int i = 0; i < item.PolygonPointRegionF.Count; i++)
  1952. {
  1953. if (item.PolygonPointRegionF[i].X == m_SelPolygonPoint.X && item.PolygonPointRegionF[i].Y == m_SelPolygonPoint.Y)
  1954. {
  1955. //移动点的位置
  1956. Rectangle selPolygonPointRect = new Rectangle(0, 0, 2, 2);
  1957. selPolygonPointRect.X = (int)m_SelPolygonPoint.X + e.X - item.DraggingPoint.X;
  1958. selPolygonPointRect.Y = (int)m_SelPolygonPoint.Y + e.Y - item.DraggingPoint.Y;
  1959. //判断样品是否超越样品台
  1960. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(selPolygonPointRect, m_RectangleGDIObjects[0].Region, CheckShape))
  1961. {
  1962. if (i == 0 || i == item.PolygonPointRegionF.Count - 1)
  1963. {
  1964. //移动点
  1965. m_SelPolygonPoint = new Point(e.X, e.Y);
  1966. item.PolygonPointRegion[item.PolygonPointRegionF.Count - 1] = new Point((int)m_SelPolygonPoint.X, (int)m_SelPolygonPoint.Y);
  1967. item.PolygonPointRegionF[item.PolygonPointRegionF.Count - 1] = m_SelPolygonPoint;
  1968. item.DrawPolygonPointRegionF[item.PolygonPointRegionF.Count - 1] = new PointF(m_SelPolygonPoint.X / m_GlobalZoomNum, m_SelPolygonPoint.Y / m_GlobalZoomNum);
  1969. item.PolygonPointRegionF[0] = m_SelPolygonPoint;
  1970. item.PolygonPointRegion[0] = new Point((int)m_SelPolygonPoint.X, (int)m_SelPolygonPoint.Y);
  1971. item.PolygonPointRegionF[0] = m_SelPolygonPoint;
  1972. item.DrawPolygonPointRegionF[0] = new PointF(m_SelPolygonPoint.X / m_GlobalZoomNum, m_SelPolygonPoint.Y / m_GlobalZoomNum);
  1973. }
  1974. else
  1975. {
  1976. m_SelPolygonPoint = new Point(e.X, e.Y);
  1977. item.PolygonPointRegion[i] = new Point((int)m_SelPolygonPoint.X, (int)m_SelPolygonPoint.Y);
  1978. item.PolygonPointRegionF[i] = m_SelPolygonPoint;
  1979. item.DrawPolygonPointRegionF[i] = new PointF(m_SelPolygonPoint.X / m_GlobalZoomNum, m_SelPolygonPoint.Y / m_GlobalZoomNum);
  1980. }
  1981. 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));
  1982. 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));
  1983. 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));
  1984. //生成多边形最小面积外接矩形
  1985. Rectangle rectPolygonMeasure = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(item.PolygonPointRegionF);
  1986. item.Region = rectPolygonMeasure;
  1987. item.RegionF = rectPolygonMeasure;
  1988. item.DrawRegionF = rectPolygonMeasure;
  1989. item.DraggingPoint = e.Location;
  1990. break;
  1991. }
  1992. }
  1993. }
  1994. }
  1995. #endregion
  1996. }
  1997. }
  1998. else
  1999. {
  2000. //计算偏离半径
  2001. int a = (xy1.X - xy2.X) * (xy1.X - xy2.X);
  2002. int b = (xy1.Y - xy2.Y) * (xy1.Y - xy2.Y);
  2003. int c = a + b;
  2004. int r = Convert.ToInt32(System.Math.Sqrt(c));
  2005. int width = r * 2;
  2006. rectTemp = new Rectangle(xy1.X - r, xy1.Y - r, width, width);
  2007. //在样品台内部缩放
  2008. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  2009. {
  2010. #region 需抽出作为公共方法
  2011. int xMove = rectTemp.X - item.Region.X;
  2012. int yMove = rectTemp.Y - item.Region.Y;
  2013. int Width = rectTemp.Width - item.Region.Width;
  2014. int Height = rectTemp.Height - item.Region.Height;
  2015. //如果大于最小测量高度 设置图形大小
  2016. if (rectTemp.Width / m_GlobalZoomNum > m_MinMeasureWidthValue)
  2017. {
  2018. item.Region = rectTemp;
  2019. float WidthNew = (float)((item.RegionF.Width + Width / m_GlobalZoomNum));
  2020. float HeightNew = (float)((item.RegionF.Height + Height / m_GlobalZoomNum));
  2021. //设置原测量区域图形大小
  2022. float xMoveNew = (float)((item.RegionF.X + xMove / m_GlobalZoomNum));
  2023. float yMoveNew = (float)((item.RegionF.Y + yMove / m_GlobalZoomNum));
  2024. item.RegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));
  2025. item.DrawRegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));
  2026. item.DraggingPoint = e.Location;
  2027. isChange = true;
  2028. }
  2029. #endregion
  2030. }
  2031. else
  2032. {
  2033. return;
  2034. }
  2035. Invalidate();
  2036. return;
  2037. }
  2038. }
  2039. }
  2040. else
  2041. {
  2042. //鼠标配合Ctrol键 移动单个测量区域
  2043. if (item.Shape == (int)CreateRectangleType.Polygon)
  2044. {
  2045. //判断是否已存在多边形的点,不能移动多边形
  2046. if (!m_IsSelPolygonPoint)
  2047. {
  2048. if (this.Cursor == Cursors.SizeAll)
  2049. {
  2050. if (item.GPath.IsVisible(e.Location))
  2051. {
  2052. isChange = true;
  2053. MouseMovePolygonMeasureFucntion(item, e);
  2054. }
  2055. }
  2056. }
  2057. }
  2058. else
  2059. {
  2060. if (item.Region.Contains(e.Location))
  2061. {
  2062. isChange = true;
  2063. MouseMoveMeasureFucntion(item, e);
  2064. }
  2065. }
  2066. }
  2067. }
  2068. }
  2069. }
  2070. }
  2071. //移动样品台
  2072. if (m_IsSelectSampleStage)
  2073. {
  2074. if (m_IsCtrl)
  2075. {
  2076. return;
  2077. }
  2078. if (m_IsAlt)
  2079. {
  2080. return;
  2081. }
  2082. //样品台
  2083. MouseMoveFucntion(m_RectangleGDIObjects, e);
  2084. //样品孔
  2085. MouseMoveFucntion(m_SampleHoleGDIObjects, e);
  2086. //样品
  2087. MouseMoveFucntion(m_SampleGDIObjects, e);
  2088. //标样
  2089. MouseMoveFucntion(m_SpecimenGDIObjects, e);
  2090. //测量
  2091. MouseMoveFucntion(m_MeasureGDIObjects, e);
  2092. //文字
  2093. MouseMoveFucntion(m_ContentGDIObjects, e);
  2094. //帧图
  2095. if (m_SingleGDIObjects.Count > 0)
  2096. {
  2097. MouseMoveSingleFucntion(m_SingleGDIObjects, e);
  2098. string sampleName = m_SingleGDIObjects[0].SampleName;
  2099. }
  2100. //样品孔BSE图片
  2101. MouseMoveSingleFucntion(m_ImageGDIObjects, e);
  2102. //计算两个点之间的距离 移动样品台后与绘制样品台时的位置
  2103. m_DifferentPoint = OTSSamplespaceGraphicsPanelFun.StartToEndPointDist(m_RectangleGDIObjects[0], m_RegionStartCenterPoint);
  2104. }
  2105. }
  2106. //显示XY轴
  2107. OTSSamplespaceGraphicsPanelFun.ShowSemCoordvAL(e.Location, m_MeasureAppForm, m_RectangleGDIObjects, m_OTSSampleStageData, IsWidth);
  2108. Invalidate();
  2109. foreach (var item in m_MeasureGDIObjects)
  2110. {
  2111. if (item.CreateType == (int)CreateRectangleType.Polygon)
  2112. {
  2113. if (m_IsSelPolygonPoint)
  2114. {
  2115. InMeasure = true;
  2116. }
  2117. }
  2118. if (item.Region.Contains(e.Location))
  2119. {
  2120. InMeasure = true;
  2121. }
  2122. }
  2123. if (!InMeasure)
  2124. {
  2125. //this.Cursor = Cursors.Default;
  2126. }
  2127. }
  2128. bool isChange = false;
  2129. protected override void OnMouseUp(MouseEventArgs e)
  2130. {
  2131. //判断当前是否手绘
  2132. if (m_IsDrawMeasure)
  2133. {
  2134. //获取当前的鼠标点击位置
  2135. this.m_MouseUpPoint = new Point(e.X, e.Y);
  2136. //绘制多边形
  2137. if (m_DrawMeasureType != (int)CreateRectangleType.Polygon && m_DrawMeasureType != (int)CreateRectangleType.CircleByThreePoints)
  2138. {
  2139. foreach (var item in m_DrawMeasureGDIObjects)
  2140. {
  2141. for (int i = 0; i < m_MeasureGDIObjects.Count; i++)
  2142. {
  2143. if (item.SampleName == m_MeasureGDIObjects[i].SampleName)
  2144. {
  2145. //获取样品孔名称与其他属性
  2146. item.Name = m_MeasureGDIObjects[i].Name;
  2147. item.IsSingle = m_MeasureGDIObjects[i].IsSingle;
  2148. item.IsWorkSample = m_MeasureGDIObjects[i].IsWorkSample;
  2149. //删除存在的帧图
  2150. for (int singleIndex = m_SingleGDIObjects.Count - 1; singleIndex >= 0; singleIndex--)
  2151. {
  2152. if (m_SingleGDIObjects[singleIndex].SampleName == item.SampleName)
  2153. {
  2154. m_SingleGDIObjects.RemoveAt(singleIndex);
  2155. }
  2156. }
  2157. m_MeasureGDIObjects[i] = item;
  2158. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(item, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  2159. {
  2160. m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;
  2161. CMeasureThreadWrapper.DoRunType = (int)MSR_THREAD_RunSTATUS.RUNMEASURE;
  2162. showSingleInfo();
  2163. break;
  2164. }
  2165. }
  2166. }
  2167. }
  2168. //清空绘制测量区域
  2169. if (m_DrawMeasureGDIObjects.Count > 0)
  2170. {
  2171. m_DrawMeasureGDIObjects.Clear();
  2172. }
  2173. this.Cursor = Cursors.Default;
  2174. //设置手绘标识
  2175. m_IsDrawMeasureReady = false;
  2176. m_IsDrawMeasure = false;
  2177. }
  2178. }
  2179. //如果正在进行测量线程,则退出鼠标点击操作
  2180. if (m_MeasureAppForm.MeasureThreadRunFlag)
  2181. {
  2182. return;
  2183. }
  2184. //是否移动至新样品孔
  2185. int IsContains = 0;
  2186. string HoleName = string.Empty;
  2187. //如果没有选择样品台
  2188. if (!m_IsSelectSampleStage)
  2189. {
  2190. //根据选择工作样品的测量状态,控制操作
  2191. if (selWSampleMeasureStatus)
  2192. {
  2193. return;
  2194. }
  2195. if (isChange)
  2196. {
  2197. if (m_RectangleGDIObjects == null)
  2198. {
  2199. return;
  2200. }
  2201. foreach (var measureItem in m_MeasureGDIObjects)
  2202. {
  2203. if (measureItem.IsWorkSample)
  2204. {
  2205. if (measureItem.Region.Contains(e.Location))
  2206. {
  2207. if (isChange == false)
  2208. {
  2209. isChange = true;
  2210. }
  2211. }
  2212. //保存原位置
  2213. Rectangle rectPara = measureItem.Region;
  2214. #region 测量区域与样品中心相差的距离
  2215. foreach (var itemSample in m_SampleGDIObjects)
  2216. {
  2217. if (itemSample.SampleName == measureItem.SampleName)
  2218. {
  2219. measureItem.SampleCenterDifferCenterPoint = OTSSamplespaceGraphicsPanelFun.GetSampleCenterDifferCenterPoint(rectPara, itemSample.Region);
  2220. break;
  2221. }
  2222. }
  2223. #endregion
  2224. //获取修改后的测量区域的位置与尺寸
  2225. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(measureItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  2226. {
  2227. //设置图形位置与大小
  2228. measureItem.Region = rectPara;
  2229. //重新绘制测量区域路径
  2230. OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(measureItem, rectPara);
  2231. //恢复光标
  2232. this.Cursor = System.Windows.Forms.Cursors.Default;
  2233. foreach (ARectangleGDIObject item in m_RectangleGDIObjects)
  2234. {
  2235. if (item.Region.Contains(e.Location))
  2236. {
  2237. m_IsSelectSampleStage = true;
  2238. }
  2239. else
  2240. {
  2241. m_IsSelectSampleStage = false;
  2242. }
  2243. }
  2244. }
  2245. break;
  2246. }
  2247. }
  2248. if (isChange)
  2249. {
  2250. //设置颜色
  2251. if (m_SingleGDIObjects.Count > 0)
  2252. {
  2253. for (int i = 0; i < m_SingleGDIObjects.Count; i++)
  2254. {
  2255. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SingleColor);
  2256. m_SingleGDIObjects[i].SelColor = ColorTranslator.FromHtml(ColorStr);
  2257. }
  2258. }
  2259. //切换至测量模式
  2260. m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;
  2261. CMeasureThreadWrapper.DoRunType = (int)MSR_THREAD_RunSTATUS.RUNMEASURE;
  2262. showSingleInfo();
  2263. }
  2264. foreach (ARectangleGDIObject item in m_SampleGDIObjects)
  2265. {
  2266. //判断鼠标是否在样品中
  2267. if (item.Region.Contains(e.Location))
  2268. {
  2269. if (item.IsWorkSample)
  2270. {
  2271. //获取原样品孔名称
  2272. HoleName = item.Name;
  2273. foreach (ARectangleGDIObject sampleHoleItem in m_SampleHoleGDIObjects)
  2274. {
  2275. //获取样品孔中心点
  2276. Point sampleHoleCenterPoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(sampleHoleItem);
  2277. //移动的样品在样品孔中心时
  2278. if (item.Region.Contains(sampleHoleCenterPoint))
  2279. {
  2280. if (item.Name != sampleHoleItem.Name)
  2281. {
  2282. sampleHoleItem.SampleCount += 1;
  2283. //样品孔信息
  2284. item.Name = sampleHoleItem.Name;
  2285. //样品Rectangle
  2286. item.Region = sampleHoleItem.Region;
  2287. item.RegionF = sampleHoleItem.RegionF;
  2288. item.DrawRegionF = sampleHoleItem.DrawRegionF;
  2289. IsContains++;
  2290. foreach (var sampleHoleCountItem in m_SampleHoleGDIObjects)
  2291. {
  2292. if (HoleName != string.Empty)
  2293. {
  2294. if (sampleHoleCountItem.Name == HoleName)
  2295. {
  2296. //减少样品数量
  2297. sampleHoleCountItem.SampleCount -= 1;
  2298. }
  2299. }
  2300. }
  2301. }
  2302. }
  2303. }
  2304. //获取工作样品中的测量区域
  2305. foreach (ARectangleGDIObject measureItem in m_MeasureGDIObjects)
  2306. {
  2307. if (item.SampleName == measureItem.SampleName)
  2308. {
  2309. //设置样品与样品孔名称
  2310. measureItem.Name = item.Name;
  2311. measureItem.SampleName = item.SampleName;
  2312. Rectangle rectPara = item.Region;
  2313. RectangleF rectParaF = item.RegionF;
  2314. if (m_IsMoveSample)
  2315. {
  2316. #region 样品移动至其他样品台后 修改测量区域位置
  2317. rectPara.X = item.Region.X - m_MeasureToSamplePoint.X;
  2318. rectPara.Y = item.Region.Y - m_MeasureToSamplePoint.Y;
  2319. rectPara.Width = measureItem.Region.Width;
  2320. rectPara.Height = measureItem.Region.Height;
  2321. rectParaF.X = rectPara.X / m_GlobalZoomNum;
  2322. rectParaF.Y = rectPara.Y / m_GlobalZoomNum;
  2323. rectParaF.Width = measureItem.RegionF.Width;
  2324. rectParaF.Height = measureItem.RegionF.Height;
  2325. //判断移动到其他样品孔后、当前测量区域是否超越样品台边缘
  2326. int CheckShape = measureItem.Shape;
  2327. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectPara, m_RectangleGDIObjects[0].Region, CheckShape))
  2328. {
  2329. measureItem.Region = rectPara;
  2330. measureItem.RegionF = rectParaF;
  2331. measureItem.DrawRegionF = rectParaF;
  2332. }
  2333. #endregion
  2334. }
  2335. //测量区域与样品中心相差的距离
  2336. measureItem.SampleCenterDifferCenterPoint = OTSSamplespaceGraphicsPanelFun.GetSampleCenterDifferCenterPoint(rectPara, measureItem.Region);
  2337. //获取修改后的测量区域的位置与尺寸
  2338. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(measureItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  2339. {
  2340. //设置测量区域信息
  2341. measureItem.SampleName = item.SampleName;
  2342. measureItem.Name = item.Name;
  2343. //将所有帧图移动测量区域位置中
  2344. //获取样品孔 与 样品名称
  2345. foreach (var SampleItem in m_SampleGDIObjects)
  2346. {
  2347. if (item.IsWorkSample)
  2348. {
  2349. //设置工作样品的测量区域 存在帧图
  2350. foreach (var MeasureItem in m_MeasureGDIObjects)
  2351. {
  2352. if (MeasureItem.SampleName == item.SampleName)
  2353. {
  2354. //设置工作样品的测量区域 存在帧图标识
  2355. if (m_SingleGDIObjects.Count > 0)
  2356. {
  2357. OTSSamplespaceGraphicsPanelFun.SetSingleLocationToMeasureLocation(m_SingleGDIObjects, MeasureItem);
  2358. }
  2359. }
  2360. }
  2361. }
  2362. }
  2363. //更新Grid 工作样品属性值
  2364. m_MeasureAppForm.UpdateTreeSampleAndGridSampleVal();
  2365. Invalidate();
  2366. break;
  2367. }
  2368. }
  2369. }
  2370. }
  2371. }
  2372. if (item.IsWorkSample)
  2373. {
  2374. //设置颜色
  2375. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  2376. item.SelColor = ColorTranslator.FromHtml(ColorStr);
  2377. }
  2378. }
  2379. isChange = false;
  2380. }
  2381. //移动多边形的点后,显示已获取的帧图
  2382. if (m_IsSelPolygonPoint)
  2383. {
  2384. foreach (var measureItem in m_MeasureGDIObjects)
  2385. {
  2386. if (measureItem.IsWorkSample)
  2387. {
  2388. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(measureItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  2389. {
  2390. if (measureItem.IsSingle)
  2391. {
  2392. showSingleInfo();
  2393. }
  2394. }
  2395. }
  2396. }
  2397. }
  2398. Invalidate();
  2399. }
  2400. //样品台
  2401. MouseUpFucntion(m_RectangleGDIObjects, e);
  2402. //样品
  2403. MouseUpFucntion(m_SampleGDIObjects, e);
  2404. //样品孔
  2405. MouseUpFucntion(m_SampleHoleGDIObjects, e);
  2406. //标样
  2407. MouseUpFucntion(m_SpecimenGDIObjects, e);
  2408. //测量
  2409. MouseUpFucntion(m_MeasureGDIObjects, e);
  2410. //测量路径
  2411. MouseUpFucntion(m_MeasurePathGDIObjects, e);
  2412. //文字
  2413. MouseUpFucntion(m_ContentGDIObjects, e);
  2414. //帧图
  2415. MouseUpFucntion(m_SingleGDIObjects, e);
  2416. //已获取的帧图
  2417. MouseUpFucntion(m_ALLSingleGDIObjects, e);
  2418. //样品孔中BSE图片
  2419. MouseUpFucntion(m_ImageGDIObjects, e);
  2420. //SEM中心位置
  2421. MouseUpFucntion(m_SEMCenterGDIObjects, e);
  2422. //撤回原样品孔中
  2423. if (IsContains == 0)
  2424. {
  2425. foreach (var item in m_SampleGDIObjects)
  2426. {
  2427. //if (item.Region.Contains(e.Location))
  2428. //{
  2429. //鼠标按下事件中获取选择的样品原有位置
  2430. //如果没有找到其他样品孔的中心点,则将移动的样品设置为原位置
  2431. foreach (ARectangleGDIObject sampleHoleItems in m_SampleHoleGDIObjects)
  2432. {
  2433. if (sampleHoleItems.SampleCount > 0)
  2434. {
  2435. if (item.IsWorkSample)
  2436. {
  2437. //设置颜色
  2438. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  2439. item.SelColor = ColorTranslator.FromHtml(ColorStr);
  2440. if (selectSampleGDIObjects != null)
  2441. {
  2442. if (sampleHoleItems.Name == selectSampleGDIObjects.Name && item.SampleName == selectSampleGDIObjects.SampleName)
  2443. {
  2444. item.Region = sampleHoleItems.Region;
  2445. Invalidate();
  2446. break;
  2447. }
  2448. }
  2449. }
  2450. }
  2451. }
  2452. //}
  2453. //获取帧图与测量区域的相差的位置
  2454. int m_singleDiffX = 0;
  2455. int m_singleDiffY = 0;
  2456. //如果当前样品没有移动至其他样品孔 测量区域恢复原位置
  2457. if (m_IsMoveSample)
  2458. {
  2459. if (item.IsWorkSample)
  2460. {
  2461. foreach (var measureItem in m_MeasureGDIObjects)
  2462. {
  2463. if (measureItem.SampleName == item.SampleName)
  2464. {
  2465. //获取测量区域与样品之间相差的距离
  2466. if (m_SingleGDIObjects.Count > 0)
  2467. {
  2468. m_singleDiffX = measureItem.Region.X - item.Region.X + m_MeasureToSamplePoint.X;
  2469. m_singleDiffY = measureItem.Region.Y - item.Region.Y + m_MeasureToSamplePoint.Y;
  2470. }
  2471. RectangleF rectParaF = item.RegionF;
  2472. Rectangle rectPara = item.Region;
  2473. rectPara.X = item.Region.X - m_MeasureToSamplePoint.X;
  2474. rectPara.Y = item.Region.Y - m_MeasureToSamplePoint.Y;
  2475. rectPara.Width = measureItem.Region.Width;
  2476. rectPara.Height = measureItem.Region.Height;
  2477. measureItem.Region = rectPara;
  2478. rectParaF.X = rectPara.X / m_GlobalZoomNum;
  2479. rectParaF.Y = rectPara.Y / m_GlobalZoomNum;
  2480. rectParaF.Width = measureItem.RegionF.Width;
  2481. rectParaF.Height = measureItem.RegionF.Height;
  2482. measureItem.RegionF = rectParaF;
  2483. measureItem.DrawRegionF = rectParaF;
  2484. break;
  2485. }
  2486. }
  2487. //将帧图恢复至原位置
  2488. foreach (var singleItem in m_SingleGDIObjects)
  2489. {
  2490. if (singleItem.SampleName == item.SampleName)
  2491. {
  2492. RectangleF rectParaDrawF = singleItem.DrawRegionF;
  2493. RectangleF rectParaF = singleItem.RegionF;
  2494. Rectangle rectPara = singleItem.Region;
  2495. rectPara.X = singleItem.Region.X - m_singleDiffX;
  2496. rectPara.Y = singleItem.Region.Y - m_singleDiffY;
  2497. rectPara.Width = singleItem.Region.Width;
  2498. rectPara.Height = singleItem.Region.Height;
  2499. singleItem.Region = rectPara;
  2500. //更改帧图RegionF
  2501. rectParaF.X = singleItem.RegionF.X - m_singleDiffX;
  2502. rectParaF.Y = singleItem.RegionF.Y - m_singleDiffY;
  2503. singleItem.RegionF = rectParaF;
  2504. //更改帧图绘制原位置DrawRegionF
  2505. rectParaDrawF.X = (rectParaDrawF.X - m_singleDiffX / m_GlobalZoomNum);
  2506. rectParaDrawF.Y = (rectParaDrawF.Y - m_singleDiffY / m_GlobalZoomNum);
  2507. rectParaDrawF.Width = rectParaDrawF.Width;
  2508. rectParaDrawF.Height = rectParaDrawF.Height;
  2509. singleItem.DrawRegionF = rectParaDrawF;
  2510. }
  2511. }
  2512. //删除已添加的帧图信息、重新添加帧图信息
  2513. if (m_ALLSingleGDIObjects.Count > 0)
  2514. {
  2515. OTSSamplespaceGraphicsPanelFun.DeleteALLSingleInfo(m_ALLSingleGDIObjects, item.SampleName);
  2516. OTSSamplespaceGraphicsPanelFun.AddALLSingleInfo(m_ALLSingleGDIObjects, m_SingleGDIObjects, item.SampleName);
  2517. }
  2518. }
  2519. }
  2520. }
  2521. }
  2522. m_IsMoveSample = false;
  2523. m_MeasureToSamplePoint = new Point();
  2524. //计算两个点之间的距离 移动样品台后与绘制样品台时的位置
  2525. if (m_RectangleGDIObjects.Count > 0)
  2526. {
  2527. m_DifferentPoint = OTSSamplespaceGraphicsPanelFun.StartToEndPointDist(m_RectangleGDIObjects[0], m_RegionStartCenterPoint);
  2528. }
  2529. m_IsCtrl = false;
  2530. m_IsAlt = false;
  2531. m_IsSelPolygonPoint = false;
  2532. selWSampleMeasureStatus = false;
  2533. }
  2534. protected override void OnPaint(PaintEventArgs e)//处理重绘情况
  2535. {
  2536. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_RectangleGDIObjects);
  2537. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_SampleHoleGDIObjects);
  2538. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_SampleGDIObjects);
  2539. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_SpecimenGDIObjects);
  2540. //切换显示样品孔中的文字
  2541. if (IsShowSampleHoleFont)
  2542. {
  2543. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_ContentGDIObjects);
  2544. }
  2545. //切换显示样品孔中的BSE图片
  2546. if (IsShowSampleHoleImage)
  2547. {
  2548. if (m_ImageGDIObjects != null)
  2549. {
  2550. if (m_ImageGDIObjects.Count > 0)
  2551. {
  2552. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_ImageGDIObjects);
  2553. }
  2554. }
  2555. }
  2556. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_MeasurePathGDIObjects);
  2557. try
  2558. {
  2559. if (m_SingleGDIObjects != null)
  2560. {
  2561. if (m_SingleGDIObjects.Count > 0)
  2562. {
  2563. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_SingleGDIObjects);
  2564. }
  2565. }
  2566. }
  2567. catch (Exception)
  2568. {
  2569. }
  2570. //手动绘制测量区域
  2571. if (m_DrawMeasureGDIObjects != null)
  2572. {
  2573. if (m_DrawMeasureGDIObjects.Count > 0)
  2574. {
  2575. for (int i = 0; i < m_DrawMeasureGDIObjects.Count; i++)
  2576. {
  2577. if (m_DrawMeasureGDIObjects[i] != null)
  2578. {
  2579. m_DrawMeasureGDIObjects[i].EndPoint = this.m_MouseMovePoint;
  2580. log.Trace("aaa");
  2581. m_DrawMeasureGDIObjects[i].OnPaint(e);
  2582. }
  2583. }
  2584. }
  2585. }
  2586. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_MeasureGDIObjects);
  2587. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_SEMCenterGDIObjects);
  2588. if (m_IsDrawPolygonFinish || m_IsSelPolygonPoint)
  2589. {
  2590. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_DrawPolygonFinishGDIObjects);
  2591. }
  2592. }
  2593. protected override void OnMouseWheel(MouseEventArgs e)
  2594. {
  2595. //如果正在进行测量线程,则退出鼠标点击操作
  2596. if (m_MeasureAppForm.MeasureThreadRunFlag)
  2597. {
  2598. return;
  2599. }
  2600. base.OnMouseWheel(e);
  2601. //设置记录每次比例缩放后的总体比例系数
  2602. if (e.Delta > 0)
  2603. {
  2604. m_GlobalZoomNum += 0.1f;
  2605. }
  2606. else
  2607. {
  2608. m_GlobalZoomNum -= 0.1f;
  2609. if (m_GlobalZoomNum < 1)
  2610. {
  2611. m_GlobalZoomNum = 1;
  2612. }
  2613. }
  2614. if (e.Delta > 0)
  2615. {
  2616. //if (f_zoom_record <= f_zoom_max)
  2617. //{
  2618. #region //图形缩放计算部份-------放大------------//是放大
  2619. f_widthandheight_js = f_zoom_increment;
  2620. f_zoom_record = f_zoom_record + f_zoom_increment;
  2621. f_zoom_record = float.Parse(f_zoom_record.ToString("#0.0")); //四舍五入,保留一位小数,如果不这样,float会不附合规则
  2622. #endregion
  2623. #region 计算标尺尺寸部份-----放大------
  2624. //计算标尺实际占用像素的宽度
  2625. f_ruler_size = f_ruler_size + Convert.ToInt32(f_old_ruler_size * f_zoom_increment);
  2626. control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);
  2627. //显示该像素宽度代表的实际宽度
  2628. control_Ruler2.SetValueInspector(f_ruler_size, ((Convert.ToDouble(m_OTSSampleStageData.StageDomain.Width) / Convert.ToDouble(54)) / 10));
  2629. //放大过长时,这里将宽度与代表的实际宽度进行折半显示
  2630. if (control_Ruler2.RulerWidth > 200)
  2631. {
  2632. control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size) / 2;
  2633. }
  2634. #endregion
  2635. //}
  2636. }
  2637. else
  2638. {
  2639. if (f_zoom_record >= f_zoom_mix)
  2640. {
  2641. #region //图形缩放计算部份------缩小--------------------
  2642. f_widthandheight_js = -f_zoom_increment;
  2643. f_zoom_record = f_zoom_record - f_zoom_increment;
  2644. f_zoom_record = float.Parse(f_zoom_record.ToString("#0.0")); //四舍五入,保留一位小数,如果不这样,float会不附合规则
  2645. #endregion
  2646. #region 计算标尺尺寸部份-----缩小------f_onepixel_size,是不是该乘以rulerwidth是实际的长度
  2647. f_ruler_size = f_ruler_size + Convert.ToInt32(f_old_ruler_size * -f_zoom_increment);
  2648. control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);
  2649. control_Ruler2.SetValueInspector(f_ruler_size, ((Convert.ToDouble(m_OTSSampleStageData.StageDomain.Width) / Convert.ToDouble(54)) / 10));
  2650. if (control_Ruler2.RulerWidth > 200)
  2651. {
  2652. control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size) / 2;
  2653. }
  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.SetValueInspector(110, ((Convert.ToDouble(m_OTSSampleStageData.StageDomain.Width) / Convert.ToDouble(54)) / 10));
  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 = "1000um";
  4112. f_ruler_size = f_ruler_size + Convert.ToInt32(f_old_ruler_size * f_zoom_increment);
  4113. control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);
  4114. control_Ruler2.SetValueInspector(f_ruler_size, ((Convert.ToDouble(m_OTSSampleStageData.StageDomain.Width) / Convert.ToDouble(54)) / 10));
  4115. }
  4116. }
  4117. public void RulerInit()
  4118. {
  4119. control_Ruler2.ShowString = "100um";
  4120. control_Ruler2.Width = 130;
  4121. }
  4122. #endregion
  4123. #region 隐藏与显示样品台中的文字
  4124. static bool IsShowSampleHoleFont = true;
  4125. public void ChangeSampleHoleFont()
  4126. {
  4127. IsShowSampleHoleFont = IsShowSampleHoleFont ? false : true;
  4128. Invalidate();
  4129. }
  4130. #endregion
  4131. #region 隐藏与显示样品孔照片
  4132. static bool IsShowSampleHoleImage = true;
  4133. public void ChangeSampleHoleImage()
  4134. {
  4135. IsShowSampleHoleImage = IsShowSampleHoleImage ? false : true;
  4136. Invalidate();
  4137. }
  4138. #endregion
  4139. #region 添加样品孔中BSE图像信息
  4140. public void AddHoleBSEImageData(byte[] ImageData, int width, int height, Point fieldPos)
  4141. {
  4142. //获取样品孔名称
  4143. string sampleHoleName = string.Empty;
  4144. ARectangleGDIObject itemWorkSample = null;
  4145. foreach (ARectangleGDIObject item in m_SampleGDIObjects)
  4146. {
  4147. if (item.IsWorkSample)
  4148. {
  4149. sampleHoleName = item.Name;
  4150. itemWorkSample = item;
  4151. break;
  4152. }
  4153. }
  4154. //获取样品孔BSE图像
  4155. Image bseImage = null;
  4156. int m_iWidth = width;
  4157. int m_iHeigh = height;
  4158. RectangleF ImgRegionF = new RectangleF();
  4159. float ImgRegionWidth = 0;
  4160. float ImgRegionHeight = 0;
  4161. if (m_ImageSingleGDIObjects.Count > 0)
  4162. {
  4163. for (int i = 0; i < m_ImageSingleGDIObjects.Count; i++)
  4164. {
  4165. if (m_ImageSingleGDIObjects[i].OTSX == fieldPos.X && m_ImageSingleGDIObjects[i].OTSY == fieldPos.Y)
  4166. {
  4167. ImgRegionF = m_ImageSingleGDIObjects[i].RegionF;
  4168. ImgRegionWidth = Convert.ToInt32(m_ImageSingleGDIObjects[i].RegionF.Width);
  4169. ImgRegionHeight = Convert.ToInt32(m_ImageSingleGDIObjects[i].RegionF.Height);
  4170. //获取图片
  4171. bseImage = OTSSysMgrTools.Imagepro.ToGrayBitmap(ImageData, m_iWidth, m_iHeigh);
  4172. //获取工作样品位置
  4173. Point drawImageLocation = itemWorkSample.Region.Location;
  4174. //绘制图像
  4175. CreateRectangle createImageRect = new CreateRectangle(ImgRegionF, fieldPos.X, fieldPos.Y, itemWorkSample.SampleName, itemWorkSample.Name, bseImage, ImgRegionWidth, ImgRegionHeight, drawImageLocation, (int)CreateRectangleType.DrawSampleHoleBSEImage);
  4176. //添加至List集合中
  4177. createImageRect.DrawRegionF = m_ImageSingleGDIObjects[i].DrawRegionF;
  4178. createImageRect.RegionF = m_ImageSingleGDIObjects[i].RegionF;
  4179. createImageRect.Region = m_ImageSingleGDIObjects[i].Region;
  4180. createImageRect.Name = m_ImageSingleGDIObjects[i].Name;
  4181. m_ImageGDIObjects.Add(createImageRect);
  4182. break;
  4183. }
  4184. }
  4185. }
  4186. //显示样品孔照片
  4187. IsShowSampleHoleImage = true;
  4188. Invalidate();
  4189. }
  4190. #endregion
  4191. #region 删除样品孔中BSE图像信息
  4192. public void DeleteHoleBSEImageData()
  4193. {
  4194. try
  4195. {
  4196. //鼠标右键点击的位置坐标
  4197. Point mouseCurrent = m_MouseDownLocation;
  4198. //样品名称
  4199. string SampleName = "";
  4200. //获取当前工作样品并删除对应BSE图
  4201. foreach (ARectangleGDIObject ImageItem in m_ImageGDIObjects)
  4202. {
  4203. if (ImageItem.Region.Contains(mouseCurrent))
  4204. {
  4205. SampleName = ImageItem.SampleName;
  4206. break;
  4207. }
  4208. }
  4209. if (SampleName != null && !SampleName.Equals(""))
  4210. {
  4211. string message = table["message7"].ToString();
  4212. if (MessageBox.Show(message, "Tip", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  4213. {
  4214. CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag = MessageState.StartMeasure;
  4215. DeleteHoleBSEImageDataNoMessageBox();
  4216. return;
  4217. }
  4218. else
  4219. {
  4220. return;
  4221. }
  4222. }
  4223. //删除样品孔BSE图
  4224. //样品孔名称
  4225. string HoleName = "";
  4226. foreach (ARectangleGDIObject item in m_SampleHoleGDIObjects)
  4227. {
  4228. if (item.Region.Contains(mouseCurrent))
  4229. {
  4230. HoleName = item.Name;
  4231. break;
  4232. }
  4233. }
  4234. if (HoleName != null && !HoleName.Equals(""))
  4235. {
  4236. string message = table["message8"].ToString();
  4237. if (MessageBox.Show(message, "Tip", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  4238. {
  4239. CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag = MessageState.ShotBSEPicture;
  4240. DeleteHoleBSEImageDataNoMessageBox();
  4241. return;
  4242. }
  4243. else
  4244. {
  4245. return;
  4246. }
  4247. }
  4248. }
  4249. catch (Exception ex)
  4250. {
  4251. string message = table["message9"].ToString();
  4252. log.Trace(message + ex.ToString());
  4253. }
  4254. }
  4255. public void DeleteHoleBSEImageDataNoMessageBox()
  4256. {
  4257. try
  4258. {
  4259. if (CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag != null)
  4260. {
  4261. if ((int)CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag == (int)MessageState.ShotBSEPicture)
  4262. {
  4263. string HoleName = string.Empty;
  4264. //鼠标右键点击的位置坐标
  4265. Point mouseCurrent = m_MouseDownLocation;
  4266. //获取当前工作样品并删除对应BSE图
  4267. foreach (ARectangleGDIObject item in m_SampleHoleGDIObjects)
  4268. {
  4269. if (item.Region.Contains(mouseCurrent))
  4270. {
  4271. HoleName = item.Name;
  4272. break;
  4273. }
  4274. }
  4275. if (!HoleName.Equals(""))
  4276. {
  4277. for (int i = m_ImageGDIObjects.Count - 1; i >= 0; i--)
  4278. {
  4279. if (m_ImageGDIObjects[i].Name == HoleName && m_ImageGDIObjects[i].SampleName == null)
  4280. {
  4281. m_ImageGDIObjects.RemoveAt(i);
  4282. }
  4283. }
  4284. for (int i = m_ImageSingleGDIObjects.Count - 1; i >= 0; i--)
  4285. {
  4286. if (m_ImageSingleGDIObjects[i].Name == HoleName && m_ImageGDIObjects[i].SampleName == null)
  4287. {
  4288. m_ImageSingleGDIObjects.RemoveAt(i);
  4289. }
  4290. }
  4291. Invalidate();
  4292. }
  4293. }
  4294. else
  4295. {
  4296. string SampleName = string.Empty;
  4297. //鼠标右键点击的位置坐标
  4298. Point mouseCurrent = m_MouseDownLocation;
  4299. //获取当前工作样品并删除对应BSE图
  4300. foreach (ARectangleGDIObject item in m_ImageGDIObjects)
  4301. {
  4302. if (item.Region.Contains(mouseCurrent))
  4303. {
  4304. SampleName = item.SampleName;
  4305. break;
  4306. }
  4307. }
  4308. if (!SampleName.Equals(""))
  4309. {
  4310. for (int i = m_ImageGDIObjects.Count - 1; i >= 0; i--)
  4311. {
  4312. if (m_ImageGDIObjects[i].SampleName == SampleName)
  4313. {
  4314. m_ImageGDIObjects.RemoveAt(i);
  4315. }
  4316. }
  4317. for (int i = m_ImageSingleGDIObjects.Count - 1; i >= 0; i--)
  4318. {
  4319. if (m_ImageSingleGDIObjects[i].SampleName == SampleName)
  4320. {
  4321. m_ImageSingleGDIObjects.RemoveAt(i);
  4322. }
  4323. }
  4324. Invalidate();
  4325. }
  4326. }
  4327. }
  4328. }
  4329. catch (Exception)
  4330. {
  4331. }
  4332. }
  4333. #endregion
  4334. #region 获取样品孔图片
  4335. public void GetBSEPictures()
  4336. {
  4337. //获取当前工作的测量区域信息
  4338. CDomain cDomain = new CDomain();
  4339. DOMAIN_SHAPE iShape = 0;
  4340. Rectangle Srect = new Rectangle();
  4341. //拍摄样品孔BSE照片
  4342. if (CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag != null)
  4343. {
  4344. if ((int)CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag == (int)MessageState.ShotBSEPicture)
  4345. {
  4346. //获取当前样品孔的索引 与 样品中对应的测量区域
  4347. OTSSampleHoleInfo sampleHoleInfo = null;
  4348. int sampleHoleIndex = OTSSamplespaceGraphicsPanelFun.GetSampleHoleIndex(m_OTSSampleStageData, m_SampleHoleSelectName, ref sampleHoleInfo);
  4349. if (sampleHoleInfo != null)
  4350. {
  4351. foreach (var sampleHoleItem in m_SampleHoleGDIObjects)
  4352. {
  4353. if (sampleHoleItem.Name == sampleHoleInfo.sSHoleName)
  4354. {
  4355. SampleHolePara sampleHolePara = OTSSamplespaceGraphicsPanelFun.GetSampleHoleRect(sampleHoleItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain);
  4356. iShape = (DOMAIN_SHAPE)sampleHolePara.iShape;
  4357. Srect = sampleHolePara.SampleHoleRect;
  4358. //设置测量区域形状
  4359. cDomain.SetShape(iShape);
  4360. cDomain.SetRectDomain(Srect);
  4361. //开始获取样品孔中的照片
  4362. m_MeasureAppForm.StartSampleHoleBSEImage((int)MSR_THREAD_RunSTATUS.RUNSampleHoleImage, sampleHoleIndex, cDomain);
  4363. break;
  4364. }
  4365. }
  4366. }
  4367. }
  4368. else
  4369. {
  4370. int measureIndex = 0;
  4371. //获取测量区域信息
  4372. foreach (var MeasureItem in m_MeasureGDIObjects)
  4373. {
  4374. if (MeasureItem.SampleName == m_SampleSelectName)
  4375. {
  4376. measureIndex++;
  4377. SampleMeasurePara sampleMeasure = OTSSamplespaceGraphicsPanelFun.GetSampleMeasureRect(MeasureItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain);
  4378. iShape = (DOMAIN_SHAPE)sampleMeasure.iShape;
  4379. Srect = sampleMeasure.MeasureRect;
  4380. //设置测量区域形状
  4381. if (iShape == (DOMAIN_SHAPE)(int)CreateRectangleType.Polygon)
  4382. {
  4383. if (iShape > 0)
  4384. {
  4385. cDomain.SetShape(iShape);
  4386. }
  4387. else
  4388. {
  4389. cDomain.SetShape((DOMAIN_SHAPE.ROUND));
  4390. }
  4391. }
  4392. else
  4393. {
  4394. cDomain.SetShape(iShape);
  4395. }
  4396. cDomain.SetRectDomain(Srect);
  4397. List<Point> PolygonPoint = OTSSamplespaceGraphicsPanelFun.PointFConvertPoint(sampleMeasure.DrawPolygonPointRegionF);
  4398. cDomain.SetPolygonPoint(PolygonPoint);
  4399. //开始获取样品孔中的照片
  4400. m_MeasureAppForm.StartSampleHoleBSEImage((int)MSR_THREAD_RunSTATUS.RUNSampleHoleImage, 2, cDomain);
  4401. break;
  4402. }
  4403. }
  4404. }
  4405. }
  4406. }
  4407. #endregion
  4408. #region 复位工作样品区域
  4409. public void ResetWorkSampleMeasure()
  4410. {
  4411. COTSSample WSample = m_MeasureAppForm.m_ProjParam.GetWorkSample();
  4412. OTSSamplePropertyInfo MeasureInfo = new OTSSamplePropertyInfo();
  4413. if (!m_MeasureAppForm.m_ProjParam.GetWorkSamplePerameter(WSample, ref MeasureInfo))
  4414. {
  4415. return;
  4416. }
  4417. Rectangle measureSize = m_MeasureAppForm.m_ProjParam.CalculateMsrArea(MeasureInfo.SMeasurePara.sHoleName);
  4418. //获取位置与尺寸
  4419. MeasureInfo.SMeasurePara.MeasureRect.Location = measureSize.Location;
  4420. MeasureInfo.SMeasurePara.MeasureRect.Size = measureSize.Size;
  4421. //获取样品信息
  4422. Point xHole = new Point(MeasureInfo.SMeasurePara.MeasureRect.Left, MeasureInfo.SMeasurePara.MeasureRect.Top);
  4423. Point yHole = new Point(MeasureInfo.SMeasurePara.MeasureRect.Right, MeasureInfo.SMeasurePara.MeasureRect.Bottom);
  4424. //将微米转换为像素
  4425. int widthHole = (int)(Math.Abs(((Point)yHole).X - ((Point)xHole).X));
  4426. int heightHole = (int)(Math.Abs(((Point)yHole).Y - ((Point)xHole).Y));
  4427. //定义测量区域
  4428. RectangleF SampleRectangleF = OTSSamplespaceGraphicsPanelFun.GetPixRectF(m_WDomain, yHole, xHole, "", "", IsWidth, m_DefaultW, m_DefaultH);
  4429. ARectangleGDIObject m_MeasureGDIObject = OTSSamplespaceGraphicsPanelFun.GetPixRect(m_WDomain, yHole, xHole, MeasureInfo.SMeasurePara.iShape, "", "", IsWidth, m_DefaultW, m_DefaultH);
  4430. m_MeasureGDIObject.Region = new Rectangle((int)SampleRectangleF.X, (int)SampleRectangleF.Y, (int)SampleRectangleF.Width, (int)SampleRectangleF.Height);
  4431. m_MeasureGDIObject.RegionF = SampleRectangleF;
  4432. m_MeasureGDIObject.DrawRegionF = SampleRectangleF;
  4433. foreach (var itemSample in m_SampleGDIObjects)
  4434. {
  4435. if (itemSample.IsWorkSample)
  4436. {
  4437. for (int i = 0; i < m_MeasureGDIObjects.Count; i++)
  4438. {
  4439. if (m_MeasureGDIObjects[i].IsWorkSample)
  4440. {
  4441. ARectangleGDIObject m_ResetMeasureGDIobjects = CStageManage.ResetMeasure((int)CreateRectangleType.Circle, itemSample, m_MeasureGDIObject, m_GlobalZoomNum);
  4442. m_MeasureGDIObjects[i].Region = m_ResetMeasureGDIobjects.Region;
  4443. m_MeasureGDIObjects[i].RegionF = m_ResetMeasureGDIobjects.RegionF;
  4444. m_MeasureGDIObjects[i].DrawRegionF = m_ResetMeasureGDIobjects.DrawRegionF;
  4445. m_MeasureGDIObjects[i].Shape = m_ResetMeasureGDIobjects.Shape;
  4446. Invalidate();
  4447. break;
  4448. }
  4449. }
  4450. break;
  4451. }
  4452. }
  4453. }
  4454. #endregion
  4455. #region 清空帧图对象与图像位置对象
  4456. public void ClearImageAndSingleGDIObjects()
  4457. {
  4458. //先清空帧图信息
  4459. if (m_MeasureAppForm.m_MessageStates == (int)MessageState.StartMeasure)
  4460. {
  4461. m_SingleGDIObjects = OTSSamplespaceGraphicsPanelFun.ListClear(m_SingleGDIObjects);
  4462. }
  4463. if (m_MeasureAppForm.m_MessageStates == MessageState.ShotBSEPicture)
  4464. {
  4465. m_ImageSingleGDIObjects = OTSSamplespaceGraphicsPanelFun.ListClear(m_ImageSingleGDIObjects);
  4466. }
  4467. }
  4468. #endregion
  4469. #region 样品对象列表中无样品信息 则清除帧图对象列表信息
  4470. /// <summary>
  4471. /// 样品对象列表中无样品信息 则清除帧图对象列表信息
  4472. /// </summary>
  4473. /// <returns></returns>
  4474. public bool SampleIsEmptyClearSingleInfo()
  4475. {
  4476. bool result = false;
  4477. if (m_SampleGDIObjects != null)
  4478. {
  4479. if (m_SampleGDIObjects.Count == 0)
  4480. {
  4481. result = true;
  4482. ClearImageAndSingleGDIObjects();
  4483. }
  4484. }
  4485. return result;
  4486. }
  4487. #endregion
  4488. #region 切换样品 填充帧图信息
  4489. public static void ChangeSampleFillSingleInfo(string sampleName)
  4490. {
  4491. OTSSamplespaceGraphicsPanelFun.ChangeSampleFillSingleInfo(m_ALLSingleGDIObjects, m_SingleGDIObjects, sampleName);
  4492. }
  4493. #endregion
  4494. #region 设置工作样品测量区域
  4495. public bool SetWorkSampleMeasureArea(int shape = 0)
  4496. {
  4497. bool IsSingle = false;
  4498. //获取当前工作的测量区域信息
  4499. CDomain cDomain = new CDomain();
  4500. DOMAIN_SHAPE iShape = 0;
  4501. Rectangle Srect = new Rectangle();
  4502. List<Point> PolygonPoint = new List<Point>();
  4503. //获取测量区域形状与位置
  4504. //获取当前测量区域
  4505. foreach (var MeasureItem in m_MeasureGDIObjects)
  4506. {
  4507. if (MeasureItem.IsSingle && MeasureItem.IsWorkSample)
  4508. {
  4509. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(MeasureItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  4510. {
  4511. IsSingle = true;
  4512. SampleMeasurePara sampleMeasure = GetSampleMeasureRect(MeasureItem);
  4513. if (sampleMeasure.PolygonPointRegion == null)
  4514. {
  4515. sampleMeasure.PolygonPointRegion = new List<Point>();
  4516. }
  4517. PolygonPoint = OTSSamplespaceGraphicsPanelFun.PointFConvertPoint(sampleMeasure.PolygonPointRegionF);
  4518. iShape = (DOMAIN_SHAPE)sampleMeasure.iShape;
  4519. //设置测量区域形状
  4520. if (iShape == (DOMAIN_SHAPE)(int)CreateRectangleType.Polygon)
  4521. {
  4522. if (shape > 0)
  4523. {
  4524. cDomain.SetShape((DOMAIN_SHAPE)shape);
  4525. }
  4526. else
  4527. {
  4528. cDomain.SetShape((DOMAIN_SHAPE.ROUND));
  4529. }
  4530. }
  4531. else
  4532. {
  4533. cDomain.SetShape((DOMAIN_SHAPE)iShape);
  4534. }
  4535. Srect = sampleMeasure.MeasureRect;
  4536. cDomain.SetRectDomain(Srect);
  4537. cDomain.SetPolygonPoint(PolygonPoint);
  4538. //线程执行类型 1:测量类型 2:获取样品孔图片类型
  4539. CMeasureThreadWrapper.DoRunType = (int)MSR_THREAD_RunSTATUS.RUNMEASURE;
  4540. //设置获取样品孔中照片所需的参数
  4541. CMeasureThreadWrapper.c_DomainMessure = cDomain;
  4542. }
  4543. break;
  4544. }
  4545. }
  4546. return IsSingle;
  4547. }
  4548. #endregion
  4549. }
  4550. }