OTSSamplespaceWindow.cs 245 KB

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