OTSSamplespaceWindow.cs 218 KB

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