OTSSamplespaceWindow.cs 245 KB

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