OTSSamplespaceWindow.cs 228 KB

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