OTSSamplespaceWindow.cs 245 KB

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