OTSSamplespaceWindow.cs 244 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791
  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. #region 鼠标滚动所需参数
  99. public static float m_ScaleNum = 1;
  100. public static float m_GlobalZoomNum = 1;//记录每次比例缩放后的总体比例系数。
  101. //改变窗体 记录的比例系数
  102. public static float m_WorkAreaZoom = 1;
  103. //加载的样品台类型 默认为原型样品台
  104. public static int m_Shape = 0;
  105. private Size m_intSize = new Size(0, 0);
  106. int m_MinMeasureWidthValue = 20;
  107. Point m_MouseDownLocation = new Point(0, 0);
  108. #endregion
  109. #region 手动绘制测量区域
  110. Point m_MouseDownPoint;
  111. Point m_MouseUpPoint;
  112. Point m_MouseMovePoint;
  113. //绘制多边形,点集合
  114. List<PointF> m_PolygonPoint;
  115. //点数量
  116. int m_PointCount = 2;
  117. //与多边形绘制的开始点相差的像素值
  118. int m_OffsetPX = 10;
  119. //手动绘制多边形测量区域完成标识
  120. bool m_IsDrawPolygonFinish = false;
  121. //手动绘制测量区域的形状类型
  122. int m_DrawMeasureType = 1;
  123. //是否为3点发画圆形
  124. bool IsCirCleByThree = false;
  125. //是否手绘标识准备
  126. public bool m_IsDrawMeasureReady = false;
  127. //是否手绘标识
  128. public bool m_IsDrawMeasure = false;
  129. #endregion
  130. //所选测量区域的矩形对象
  131. Rectangle m_SelMeasureRect;
  132. //是否选中样品台标识
  133. bool m_IsSelectSampleStage = false;
  134. private Point m_P, m_P1;
  135. protected Point m_MeasureToSamplePoint;
  136. //是否按下Ctrl键
  137. bool m_IsCtrl = false;
  138. bool m_IsAlt = false;
  139. //配合Ctrol键是否选中多边形的点标识
  140. bool m_IsSelPolygonPoint = false;
  141. //配合Ctrol键是否选中多边形的点
  142. PointF m_SelPolygonPoint = new Point();
  143. //测量区域矩形对象
  144. static Rectangle m_MeasureRectangle = new Rectangle();
  145. //默认值
  146. const int m_DValue = 1;
  147. int m_CompletedFieldsCount = 0;
  148. NLog.Logger log ;
  149. //选择工作样品测量的状态
  150. bool selWSampleMeasureStatus = false;
  151. #endregion
  152. #region 标尺变量
  153. //缩放的增大缩小的增量
  154. private float f_zoom_increment = 0.1f;
  155. //缩放的基数,临时变量
  156. private float f_widthandheight_js = 0;
  157. //与原先缩放的记录数
  158. private float f_zoom_record = 1;
  159. //最小缩放倍数
  160. private float f_zoom_mix = 0.5f;
  161. //标尺的大小记录
  162. private float f_ruler_size = 100;
  163. //标尺原先大小的记录,参与计算
  164. private float f_old_ruler_size = 100;
  165. public RectangleF BackRectF
  166. {
  167. set { backrectf = value; }
  168. get { return backrectf; }
  169. }
  170. //背景矩形
  171. public RectangleF backrectf = new RectangleF();
  172. //记录原值,背景矩形
  173. public RectangleF old_backrectf = new RectangleF();
  174. //国际化
  175. OTSSysMgrTools.Language lan;
  176. Hashtable table;
  177. #endregion
  178. #region 设置双缓冲
  179. /// <summary>
  180. /// 设置双缓冲
  181. /// </summary>
  182. public void SetDoubleBufferByIsDraw()
  183. {
  184. SetStyle(ControlStyles.UserPaint, true);
  185. SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
  186. this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // 双缓冲
  187. }
  188. #endregion
  189. #region 构造函数 获取父窗体对象
  190. public OTSSamplespaceWindow(OTSIncAMeasureAppForm MeasureAppForm)
  191. {
  192. InitializeComponent();
  193. m_MeasureAppForm = MeasureAppForm;
  194. //this.InitDataEvent();
  195. SetDoubleBufferByIsDraw();// 双缓冲
  196. m_OTSSampleStageData = new StageDrawingData();
  197. //国际化
  198. lan = new OTSSysMgrTools.Language(this);
  199. table = lan.GetNameTable(this.Name);
  200. }
  201. /// <summary>
  202. /// 画圆形测试区域 事件
  203. /// </summary>
  204. public void Rev_DDrawCircleMeasure_MeasureAppToSampleWindow_Event()
  205. {
  206. //手绘测量区域类型为圆形
  207. m_DrawMeasureType = (int)CreateRectangleType.Circle;
  208. m_IsDrawMeasureReady = true;
  209. m_RectangIsDragging = false;
  210. this.Cursor = Cursors.Hand;
  211. }
  212. /// <summary>
  213. /// 画矩形测试区域 事件
  214. /// </summary>
  215. public void Rev_DDrawRectangleMeasure_MeasureAppToSampleWindow_Event()
  216. {
  217. //手绘测量区域类型为矩形
  218. m_DrawMeasureType = (int)CreateRectangleType.SampleBackGround_Rectangle;
  219. m_IsDrawMeasureReady = true;
  220. m_RectangIsDragging = false;
  221. this.Cursor = Cursors.Hand;
  222. }
  223. /// <summary>
  224. /// 画多边形测试区域 事件
  225. /// </summary>
  226. public void Rev_DDrawPolygonMeasure_MeasureAppToSampleWindow_Event()
  227. {
  228. //多边形测量区域完成标识
  229. m_DrawPolygonFinishGDIObjects = new List<ARectangleGDIObject>();
  230. //手绘测量区域类型为矩形
  231. m_DrawMeasureType = (int)CreateRectangleType.Polygon;
  232. m_IsDrawMeasureReady = true;
  233. m_IsDrawMeasure = true;
  234. m_RectangIsDragging = false;
  235. m_PolygonPoint = new List<PointF>();
  236. this.Cursor = Cursors.Hand;
  237. }
  238. /// <summary>
  239. /// 三点画圆形测试区域 事件 先多边形后圆形
  240. /// </summary>
  241. public void Rev_DDrawCircleMeasureByThreePoints_MeasureAppToSampleWindow_Event()
  242. {
  243. //手绘测量区域类型为圆形
  244. m_DrawMeasureType = (int)CreateRectangleType.CircleByThreePoints;
  245. m_IsDrawMeasureReady = true;
  246. m_IsDrawMeasure = true;
  247. m_RectangIsDragging = false;
  248. m_PolygonPoint = new List<PointF>();
  249. this.Cursor = Cursors.Hand;
  250. }
  251. /// <summary>
  252. /// 当修改了GRID 的样品台测量精度、放大倍数和图片像素大小 时,SAMPLEWINDOW重新绘制样品台
  253. /// </summary>
  254. public void Rev_DDDrawSampleStage_EventHandler_Event()
  255. {
  256. m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;
  257. //显示帧图
  258. if (m_SingleGDIObjects.Count > 0)
  259. {
  260. showSingleInfo();
  261. }
  262. }
  263. public void Rev_MeasureApp_OpenExistSampleFile_Event(CStage SStage, CSEMStageData SEMStageData, List<SampleMeasurePara> SMeasrueAreaList, string sWorkSampleName)
  264. {
  265. GetSampleStageData(SStage, SEMStageData);
  266. var SStageData = m_OTSSampleStageData;
  267. m_GlobalZoomNum = 1;
  268. //清除所有绘制的图形信息
  269. ClearDrawInfo();
  270. //绘制样品台信息
  271. if (SStageData != null)
  272. {
  273. m_OTSSampleStageData = SStageData;
  274. DrawSampleStage(SStageData);
  275. }
  276. //绘制样品与测量区域
  277. //1.绘制样品
  278. if (SMeasrueAreaList != null)
  279. {
  280. m_SMeasrueAreaList = SMeasrueAreaList;
  281. DrawSampleAndMeasureInfo(SMeasrueAreaList);
  282. }
  283. //2.测量区域
  284. //设置工作样品
  285. if (sWorkSampleName != "")
  286. {
  287. Rev_MeasureApp_SwitchWorkSample_Event(sWorkSampleName);
  288. //打开文件后 设置工作样品名称
  289. m_SampleSelectName = sWorkSampleName;
  290. }
  291. //重新绘制
  292. Invalidate();
  293. }
  294. ///MeasureApp和 SampleSpaceWindow 切换工作样品名称事件委托
  295. ///string sNewWSampleName: 切换新工作样品名称
  296. public void Rev_MeasureApp_SwitchWorkSample_Event(string sNewWSampleName, bool bDrawField = false)
  297. {
  298. try
  299. {
  300. //获取存在帧图的样品名称
  301. string singleSampleName = string.Empty;
  302. if (m_SingleGDIObjects != null)
  303. {
  304. if (m_SingleGDIObjects.Count > 0)
  305. {
  306. singleSampleName = m_SingleGDIObjects[0].SampleName;
  307. }
  308. }
  309. //判断当前帧图所在样品的样品名称与新样品名称是否相同
  310. if (!singleSampleName.Equals(""))
  311. {
  312. if (singleSampleName != sNewWSampleName)
  313. {
  314. //先清空帧图信息
  315. ClearImageAndSingleGDIObjects();
  316. this.Invalidate();
  317. }
  318. }
  319. //判断当前帧图所在样品的样品名称与新样品名称是否相同
  320. if (m_SingleGDIObjects != null)
  321. {
  322. if (m_SingleGDIObjects.Count > 0)
  323. {
  324. if (m_SingleGDIObjects[0].SampleName != sNewWSampleName)
  325. {
  326. //先清空帧图信息
  327. ClearImageAndSingleGDIObjects();
  328. this.Invalidate();
  329. }
  330. }
  331. }
  332. //设置工作样品样式
  333. CStageManage.SetWorkSampleAndWorkMeasure(sNewWSampleName);
  334. foreach (var itemMeasure in m_MeasureGDIObjects)
  335. {
  336. if (itemMeasure.IsSingle && itemMeasure.IsWorkSample && sNewWSampleName == itemMeasure.SampleName)
  337. {
  338. //当前工作样品的测量区域 获取帧图信息
  339. if (m_SingleGDIObjects.Count == 0)
  340. {
  341. string message = table["message1"].ToString();
  342. //log.Trace("Rev_MeasureApp_SwitchWorkSample_Event:--" + message + "--begin--");
  343. showSingleInfo();
  344. //log.Trace("Rev_MeasureApp_SwitchWorkSample_Event:--" + message + "--end--");
  345. break;
  346. }
  347. }
  348. }
  349. ////绘制已完成的帧图状态
  350. COTSMsrPrjResultData cProjMgr = m_MeasureAppForm.m_ProjParam.m_ResultData;
  351. //当前工作样品的测量区域 获取帧图信息
  352. COTSSample cSample = cProjMgr.GetWorkingSample();
  353. int CompletedFieldsCount = cSample.GetMsrStatus().GetCompletedFields();
  354. if (CompletedFieldsCount > 0)
  355. {
  356. //设置测量区域获取帧图
  357. foreach (var itemMeasure in m_MeasureGDIObjects)
  358. {
  359. if (cSample.GetName() == itemMeasure.SampleName)
  360. {
  361. itemMeasure.IsSingle = true;
  362. break;
  363. }
  364. }
  365. if (m_SingleGDIObjects.Count == 0)
  366. {
  367. showSingleInfo();
  368. }
  369. //获取已完成测量的帧图中心点
  370. List<Point> CompleteFieldList = cProjMgr.GetWorkingSample().GetMsrStatus().GetCompletedFieldsCenter();
  371. //修改帧图完成状态
  372. OTSMeasureDisplayResult.ChangeCompleteFieldMeasureState(CompleteFieldList, Color.Green, m_MeasureAppForm);
  373. }
  374. else
  375. {
  376. //根据测量文件中已获取sem信息
  377. if (cSample.GetSEMDataMsr().GetTotalFields() > 0)
  378. {
  379. foreach (var itemMeasure in m_MeasureGDIObjects)
  380. {
  381. if (cSample.GetName() == itemMeasure.SampleName)
  382. {
  383. itemMeasure.IsSingle = true;
  384. showSingleInfo();
  385. break;
  386. }
  387. }
  388. }
  389. }
  390. //设置为手绘测量区域
  391. m_IsDrawMeasureReady = false;
  392. m_IsDrawMeasure = false;
  393. this.Invalidate();
  394. return;
  395. }
  396. catch (Exception ex)
  397. {
  398. string message = table["message2"].ToString();
  399. //记录错误日志
  400. log.Trace("Rev_MeasureApp_SwitchWorkSample_Event():" + message + ":" + ex.ToString() + "");
  401. }
  402. }
  403. //MeasureApp和 SampleSpaceWindow 修改工作样品名称事件委托
  404. //string sSampleHoleName: 修改工作样品名称
  405. public void Rev_MeasureApp_ChangeWorkSampleName_Event(string sNewWSampleName)
  406. {
  407. try
  408. {
  409. string oldSampleName = string.Empty;
  410. foreach (ARectangleGDIObject itemSample in OTSSamplespaceWindow.m_SampleGDIObjects)
  411. {
  412. if (itemSample.IsWorkSample)
  413. {
  414. oldSampleName = itemSample.SampleName;
  415. }
  416. }
  417. //更换样品名称
  418. CStageManage.ChangeSampleName(sNewWSampleName);
  419. this.Invalidate();
  420. return;
  421. }
  422. catch (Exception ex)
  423. {
  424. string message = table["message2"].ToString();
  425. //记录错误日志
  426. log.Trace("Rev_MeasureApp_ChangeWorkSampleName_Event():" + message + ":" + ex.ToString() + "");
  427. }
  428. }
  429. //MeasureApp和 SampleSpaceWindow 删除样品事件委托, MeasureApp 给 SampleSpaceWindow 发送删除样品委托事件
  430. //string sSampleHoleName: 删除工作样品名
  431. public void Rev_MeasureApp_DeleteWorkSample_Event(string sDeleteWSampleName, string sNewWSampleName)
  432. {
  433. try
  434. {
  435. foreach (ARectangleGDIObject itemSample in OTSSamplespaceWindow.m_SampleGDIObjects)
  436. {
  437. if (itemSample.SampleName == sDeleteWSampleName)
  438. {
  439. if (itemSample.IsWorkSample)
  440. {
  441. //删除样品测量集合中的对象
  442. if (CStageManage.DeleteSample(sDeleteWSampleName))
  443. {
  444. if (m_SampleGDIObjects.Count == 0)
  445. {
  446. //将测量状态初始化
  447. m_MeasureAppForm.m_MessureStatuWindow.SetMeasureStatusInit();
  448. }
  449. //根据样品名称 删除对应帧图信息
  450. OTSSamplespaceGraphicsPanelFun.DeleteALLSingleInfo(m_ALLSingleGDIObjects, sDeleteWSampleName);
  451. if (!string.IsNullOrEmpty(sNewWSampleName))
  452. {
  453. //设置工作样品
  454. m_MeasureAppForm.Rev_SoluWindowReqSwitchWSample_Event(sNewWSampleName);
  455. }
  456. else
  457. {
  458. //先清空帧图信息
  459. ClearImageAndSingleGDIObjects();
  460. }
  461. this.Invalidate();
  462. return;
  463. }
  464. }
  465. }
  466. }
  467. }
  468. catch (Exception ex)
  469. {
  470. string message = table["message2"].ToString();
  471. //记录错误日志
  472. log.Error("Rev_MeasureApp_DeleteWorkSample_Event():" + message + ":" + ex.ToString() + "");
  473. }
  474. }
  475. #region 更改工作样品中 测量区域形状
  476. public void changeShape(int iShape)
  477. {
  478. try
  479. {
  480. string sampleName = m_MeasureAppForm.m_ProjParam.GetWorkSampleName();
  481. //m_Shap 更换样品形状
  482. if (CStageManage.ChangeSampleShape(iShape))
  483. {
  484. //设置新添加测量区域更改位置与缩放
  485. foreach (var item in m_MeasureGDIObjects)
  486. {
  487. if (item.SampleName == sampleName)
  488. {
  489. item.IsWorkSample = true;
  490. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(item, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  491. {
  492. //保存原位置
  493. Rectangle rectPara = item.Region;
  494. #region 测量区域与样品中心相差的距离
  495. foreach (var itemSample in m_SampleGDIObjects)
  496. {
  497. if (itemSample.SampleName == item.SampleName)
  498. {
  499. item.SampleCenterDifferCenterPoint = OTSSamplespaceGraphicsPanelFun.GetSampleCenterDifferCenterPoint(rectPara, itemSample.Region);
  500. break;
  501. }
  502. }
  503. if (item.IsSingle)
  504. {
  505. showSingleInfo();
  506. }
  507. #endregion
  508. }
  509. }
  510. }
  511. }
  512. this.Invalidate();
  513. return;
  514. }
  515. catch (Exception ex)
  516. {
  517. string message = table["message2"].ToString();
  518. //记录错误日志
  519. log.Error("changeShape():" + message + ":" + ex.ToString() + "");
  520. }
  521. }
  522. #endregion
  523. #region 还原测量区域形状
  524. public void ResetShape()
  525. {
  526. try
  527. {
  528. //设置新添加测量区域更改位置与缩放
  529. foreach (var item in m_MeasureGDIObjects)
  530. {
  531. if (item.IsWorkSample)
  532. {
  533. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(item, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  534. {
  535. //保存原位置
  536. Rectangle rectPara = item.Region;
  537. #region 测量区域与样品中心相差的距离
  538. foreach (var itemSample in m_SampleGDIObjects)
  539. {
  540. if (itemSample.SampleName == item.SampleName)
  541. {
  542. item.SampleCenterDifferCenterPoint = OTSSamplespaceGraphicsPanelFun.GetSampleCenterDifferCenterPoint(rectPara, itemSample.Region);
  543. break;
  544. }
  545. }
  546. if (item.IsSingle)
  547. {
  548. showSingleInfo();
  549. }
  550. #endregion
  551. }
  552. }
  553. }
  554. this.Invalidate();
  555. return;
  556. }
  557. catch (Exception ex)
  558. {
  559. string message = table["message2"].ToString();
  560. //记录错误日志
  561. log.Error("changeShape():" + message + ":" + ex.ToString() + "");
  562. }
  563. }
  564. #endregion
  565. ///MeasureApp 给SampleWindow窗口发送添加样品的样品孔名,测量区域信息
  566. //string sSampleName : 新添加样品名
  567. //string sSampleHoleName: 新添加样品所在的样品孔名称
  568. //int iShape: 测量区域形状
  569. //Point pStartPoint: 测量区域起点
  570. //Point pEndPoint : 测量区域终点
  571. public void AddOneSampleArea(SampleMeasurePara SMeasurePara)
  572. {
  573. try
  574. {
  575. CMStrip.Hide();
  576. //获取样品信息
  577. Point xHole = new Point(SMeasurePara.MeasureRect.Left, SMeasurePara.MeasureRect.Top);
  578. Point yHole = new Point(SMeasurePara.MeasureRect.Right, SMeasurePara.MeasureRect.Bottom);
  579. //将微米转换为像素
  580. int widthHole = (int)(Math.Abs(((Point)yHole).X - ((Point)xHole).X));
  581. int heightHole = (int)(Math.Abs(((Point)yHole).Y - ((Point)xHole).Y));
  582. //定义测量区域
  583. RectangleF SampleRectangleF = OTSSamplespaceGraphicsPanelFun.GetPixRectF(m_WDomain, yHole, xHole, "", "", IsWidth, m_DefaultW, m_DefaultH);
  584. ARectangleGDIObject m_SampleGDIObject = OTSSamplespaceGraphicsPanelFun.GetPixRect(m_WDomain, yHole, xHole, SMeasurePara.iShape, "", "", IsWidth, m_DefaultW, m_DefaultH);
  585. m_SampleGDIObject.Region = new Rectangle((int)SampleRectangleF.X, (int)SampleRectangleF.Y, (int)SampleRectangleF.Width, (int)SampleRectangleF.Height);
  586. m_SampleGDIObject.RegionF = SampleRectangleF;
  587. m_SampleGDIObject.DrawRegionF = SampleRectangleF;
  588. //测量区域名称 样品名称
  589. m_SampleGDIObject.SampleName = SMeasurePara.sSampleName;
  590. //测量区域类型
  591. m_SampleGDIObject.CreateType = SMeasurePara.iShape;
  592. //添加样品
  593. if (CStageManage.AddSample(SMeasurePara.sHoleName, SMeasurePara.sSampleName, m_SampleGDIObject, this, m_GlobalZoomNum))
  594. {
  595. //设置新添加样品测量的位置
  596. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(m_MeasureGDIObjects[m_MeasureGDIObjects.Count - 1], m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  597. {
  598. CStageManage.SetWorkSampleAndWorkMeasure(SMeasurePara.sSampleName);
  599. //清除帧图信息
  600. ClearImageAndSingleGDIObjects();
  601. Invalidate();
  602. }
  603. }
  604. }
  605. catch (Exception ex)
  606. {
  607. string message = table["message2"].ToString();
  608. //记录错误日志
  609. log.Error("OTSSamplespaceWindow_Rev_MeasureApp_AddSample_Event():--" + message + ":" + ex.ToString() + "");
  610. }
  611. }
  612. //响应委托事件的样品台数据
  613. public void InitStageDisplay(CStage SStage, CSEMStageData SEMStageData)
  614. {
  615. GetSampleStageData(SStage, SEMStageData);
  616. m_GlobalZoomNum = 1;
  617. //清除所有绘制的图形信息
  618. ClearDrawInfo();
  619. //绘制样品台信息
  620. DrawSampleStage(m_OTSSampleStageData);
  621. //标尺初始化
  622. RulerInit();
  623. //重新绘制
  624. Invalidate();
  625. //1.将测量结果窗体中已存在的内容清空
  626. //2.将测量图像清空
  627. //图像隐藏
  628. HideMessureStatuWindowBSEImage(m_MeasureAppForm);
  629. //将测量结果信息状态初始化
  630. InitMeasureStateInfo();
  631. if (m_SampleGDIObjects != null)
  632. {
  633. if (m_SampleGDIObjects.Count == 0)
  634. {
  635. //将测量状态初始化
  636. m_MeasureAppForm.m_MessureStatuWindow.SetMeasureStatusInit();
  637. }
  638. }
  639. }
  640. public void HideMessureStatuWindowBSEImage(OTSIncAMeasureAppForm m_MeasureApps)
  641. {
  642. m_MeasureApps.m_MessureStatuWindow.pbBSEImage.Hide();
  643. }
  644. #region 将测量状态进度窗口信息初始化
  645. public void InitMeasureStateInfo()
  646. {
  647. m_MeasureAppForm.m_MeasureRetWindow.SetInit();
  648. }
  649. #endregion
  650. //获取绘制样品台的数据
  651. private bool GetSampleStageData(CStage SStage ,CSEMStageData SEMStageData)
  652. {
  653. //StageDrawingData m_OTSSampleStageData = new StageDrawingData();
  654. //获取样品台信息
  655. //CStage SStage = m_ResultData.GetStage();
  656. if (null == SStage)
  657. {
  658. return false;
  659. }
  660. //获得样品台数据
  661. m_OTSSampleStageData.sStageName = SStage.GetName();
  662. m_OTSSampleStageData.bStageShape = (int)SStage.GetBoundary().GetShape();
  663. m_OTSSampleStageData.StageDomain = (Rectangle)SStage.GetBoundary().GetRectDomain();
  664. m_OTSSampleStageData.bSampleShape = (int)SStage.GetSTD().GetShape();
  665. m_OTSSampleStageData.SampleRect = (Rectangle)SStage.GetSTD().GetRectDomain();
  666. int iSHoleCount = SStage.GetHoleList().Count; //样品孔个数
  667. if (m_OTSSampleStageData.sSHoleInfoList.Count > 0)
  668. {
  669. m_OTSSampleStageData.sSHoleInfoList.Clear();
  670. }
  671. var holeLst = SStage.GetHoleList();
  672. for (int i = 0; i < iSHoleCount; i++)
  673. {
  674. CHole d = holeLst[i];
  675. OTSSampleHoleInfo SHoleInfo = new OTSSampleHoleInfo();
  676. //获取样品口的名称,形状,坐标
  677. SHoleInfo.sSHoleName = d.GetName();
  678. SHoleInfo.iSHoleShape = (int)d.GetShape();
  679. Rectangle r = (Rectangle)d.GetRectDomain();
  680. SHoleInfo.HoleRect = r;
  681. m_OTSSampleStageData.sSHoleInfoList.Add(SHoleInfo);
  682. }
  683. //获取SEMData 绘制样品
  684. m_OTSSampleStageData.iScanFieldSize100 = SEMStageData.GetScanFieldSize100(); //放大倍数为100倍时的屏幕尺寸
  685. m_OTSSampleStageData.iXAxisDir = (int)SEMStageData.GetXAxisDir();
  686. m_OTSSampleStageData.iYAxisDir = (int)SEMStageData.GetYAxisDir();
  687. m_OTSSampleStageData.iXAxisStartVal = SEMStageData.GetXAxis().GetStart();
  688. m_OTSSampleStageData.iXAxisEndVal = SEMStageData.GetXAxis().GetEnd();
  689. m_OTSSampleStageData.iYAxisStartVal = SEMStageData.GetYAxis().GetStart();
  690. m_OTSSampleStageData.iYAxisEndVal = SEMStageData.GetYAxis().GetEnd();
  691. return true;
  692. }
  693. //记录样品台的最大宽度
  694. static int RegionMaxWidth = 0;
  695. #region 绘制样品台信息
  696. /// <summary>
  697. /// 绘制样品台信息
  698. /// </summary>
  699. /// <returns></returns>
  700. public void DrawSampleStage(StageDrawingData SData)
  701. {
  702. try
  703. {
  704. if (SData.StageDomain.X == 0 && SData.StageDomain.Y == 0)
  705. {
  706. return;
  707. }
  708. string stageName = SData.sStageName;
  709. int widthDomain = 0;
  710. int heightDomain = 0;
  711. //获取样品台
  712. int StageShape = SData.bStageShape;
  713. Point xDomain = new Point(SData.StageDomain.Left, SData.StageDomain.Top);
  714. Point yDomain = new Point(SData.StageDomain.Right, SData.StageDomain.Bottom);
  715. //OTS宽度高度差值
  716. widthDomain = Math.Abs(yDomain.X - xDomain.X);
  717. heightDomain = Math.Abs(yDomain.Y - xDomain.Y);
  718. //样品台转换在电镜位置的宽度与高度
  719. StageLTPointToSEMLocation = m_MeasureAppForm.m_ProjParam.ChangeOTSToSemCoord(xDomain);
  720. StageRBPointToSEMLocation = m_MeasureAppForm.m_ProjParam.ChangeOTSToSemCoord(yDomain);
  721. //设置样品台宽度
  722. m_WDomain = widthDomain;
  723. IsWidth = this.Height > this.Width ? 0 : 1;
  724. //记录添加帧图的尺寸 鼠标滚动时使用的原值
  725. m_DefaultW = this.Width;
  726. m_DefaultH = this.Height;
  727. m_Shape = SData.bStageShape;
  728. CreateRectangle CreateBourary = null;
  729. //0:圆角矩形 1:圆形 2:文字 3:矩形
  730. if (SData.bStageShape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  731. {
  732. CreateBourary = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xDomain, yDomain, (int)CreateRectangleType.SampleBackGround_Rectangle, "", "", IsWidth, m_DefaultW, m_DefaultH);
  733. }
  734. else
  735. {
  736. CreateBourary = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xDomain, yDomain, (int)CreateRectangleType.SampleBackGround_Circle, "", "", IsWidth, m_DefaultW, m_DefaultH);
  737. }
  738. //获取默认尺寸
  739. m_DefaultWidth = CreateBourary.Region.Width;
  740. m_DefaultHeight = CreateBourary.Region.Height;
  741. //添加样品台 对象
  742. //设置路径
  743. GraphicsPath MeasurePath = new GraphicsPath();
  744. if (StageShape == (int)CreateRectangleType.Circle)
  745. {
  746. MeasurePath.AddEllipse(CreateBourary.Region);
  747. }
  748. else
  749. {
  750. MeasurePath.AddRectangle(CreateBourary.Region);
  751. }
  752. CreateBourary.GPath = MeasurePath;
  753. CreateBourary.Shape = StageShape;
  754. m_RectangleGDIObjects.Add(CreateBourary);
  755. //绘制后的样品台中心位置
  756. Point m_Region = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(m_RectangleGDIObjects[0].Region);
  757. //获取绘制后的样品台中心位置
  758. if (m_RegionStartCenterPoint.X != m_Region.X || m_RegionStartCenterPoint.Y != m_Region.Y)
  759. {
  760. m_RegionStartCenterPoint = m_Region;
  761. }
  762. //获取最大宽度
  763. if (RegionMaxWidth <= 0)
  764. {
  765. RegionMaxWidth = (IsWidth == 0 ? this.Width : this.Height);
  766. }
  767. //获取样品孔
  768. System.Collections.Generic.List<OTSSampleHoleInfo> ChloeClrList = SData.sSHoleInfoList;
  769. if (ChloeClrList.Count > 0)
  770. {
  771. for (int i = 0; i < ChloeClrList.Count; i++)
  772. {
  773. //获取微米信息
  774. var xHole = new Point(ChloeClrList[i].HoleRect.Left, ChloeClrList[i].HoleRect.Top);
  775. var yHole = new Point(ChloeClrList[i].HoleRect.Right, ChloeClrList[i].HoleRect.Bottom);
  776. //将微米转换为像素
  777. int widthHole = Math.Abs(yHole.X - xHole.X);
  778. int heightHole = Math.Abs(yHole.Y - xHole.Y);
  779. //获取矩形
  780. CreateRectangle CreateHole = null;
  781. //0:圆角矩形 1:圆形 2:文字 3:矩形
  782. if (ChloeClrList[i].iSHoleShape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  783. {
  784. CreateHole = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xHole, yHole, (int)CreateRectangleType.Rectangle, "", ChloeClrList[i].sSHoleName, IsWidth, m_DefaultW, m_DefaultH);
  785. }
  786. else
  787. {
  788. CreateHole = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xHole, yHole, (int)CreateRectangleType.Circle, "", ChloeClrList[i].sSHoleName, IsWidth, m_DefaultW, m_DefaultH);
  789. }
  790. //获取样品孔默认尺寸
  791. m_DefaultStageWidth = CreateHole.Region.Width;
  792. m_DefaultStageHeight = CreateHole.Region.Height;
  793. //绘制样品孔路径
  794. GraphicsPath HolePath = new GraphicsPath();
  795. if (ChloeClrList[i].iSHoleShape == (int)CreateRectangleType.Circle)
  796. {
  797. HolePath.AddEllipse(CreateHole.Region);
  798. }
  799. else
  800. {
  801. HolePath.AddRectangle(CreateHole.Region);
  802. }
  803. CreateHole.GPath = HolePath;
  804. m_SampleHoleGDIObjects.Add(CreateHole);
  805. //添加文字
  806. CreateRectangle CreateContent = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xHole, yHole, (int)CreateRectangleType.Rectangle, "", "", IsWidth, m_DefaultW, m_DefaultH);
  807. //类型 文字:2
  808. CreateContent.CreateType = (int)CreateRectangleType.Font;
  809. CreateContent.Region = CreateHole.Region;
  810. CreateContent.strContent = ChloeClrList[i].sSHoleName;
  811. CreateContent.Name = ChloeClrList[i].sSHoleName;
  812. m_ContentGDIObjects.Add(CreateContent);
  813. }
  814. }
  815. //获取标样
  816. int StageShapes = SData.bStageShape;
  817. Point xSTD = new Point(SData.SampleRect.Left, SData.SampleRect.Top);
  818. Point ySTD = new Point(SData.SampleRect.Right, SData.SampleRect.Bottom);
  819. //获取矩形
  820. CreateRectangle CreateSTD = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xSTD, ySTD, (int)CreateRectangleType.Rectangle, "", "", IsWidth, m_DefaultW, m_DefaultH);
  821. if (StageShapes == (int)CreateRectangleType.Circle)
  822. {
  823. CreateSTD = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xSTD, ySTD, (int)CreateRectangleType.SpecimenCircle, "", "", IsWidth, m_DefaultW, m_DefaultH);
  824. }
  825. else
  826. {
  827. CreateSTD = OTSSamplespaceGraphicsPanelFun.GetPixRect(widthDomain, xSTD, ySTD, (int)CreateRectangleType.SpecimenRectangle, "", "", IsWidth, m_DefaultW, m_DefaultH);
  828. }
  829. m_DefaultSampleWidth = CreateSTD.Region.Width;
  830. m_DefaultSampleHeight = CreateSTD.Region.Height;
  831. //绘制标样路径
  832. GraphicsPath STDPath = new GraphicsPath();
  833. if (StageShapes == (int)CreateRectangleType.Circle)
  834. {
  835. STDPath.AddEllipse(CreateSTD.Region);
  836. }
  837. else
  838. {
  839. STDPath.AddRectangle(CreateSTD.Region);
  840. }
  841. CreateSTD.GPath = STDPath;
  842. m_SpecimenGDIObjects.Add(CreateSTD);
  843. return;
  844. }
  845. catch (Exception ex)
  846. {
  847. string message = table["message2"].ToString();
  848. log.Error("OTSSamplespaceWindow_DrawSampleInfo():--" + message + ":" + ex.ToString() + "");
  849. }
  850. }
  851. #endregion
  852. private string m_fileName = string.Empty;
  853. public string FileName
  854. {
  855. get { return m_fileName; }
  856. set
  857. {
  858. if (value != string.Empty)
  859. {
  860. Stream s = new FileStream(value, FileMode.Open);
  861. FileInfo efInfo = new FileInfo(value);
  862. string fext = efInfo.Extension.ToUpper();
  863. s.Close();
  864. }
  865. m_fileName = value;
  866. this.ToolTipText = value;
  867. }
  868. }
  869. #endregion
  870. private void GetTriangleExcenterRadius(PointF px1, PointF px2, PointF px3, out float R, out PointF center)
  871. {
  872. float x1, y1, x2, y2, x3, y3;
  873. float a, b;
  874. x1 = px1.X;
  875. y1 = px1.Y;
  876. x2 = px2.X;
  877. y2 = px2.Y;
  878. x3 = px3.X;
  879. y3 = px3.Y;
  880. 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)));
  881. 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)));
  882. center = new PointF(a, b);
  883. R = (float)Math.Sqrt((x1 - a) * (x1 - a) + (y1 - b) * (y1 - b));
  884. }
  885. private float GetDistance(PointF A, PointF B)
  886. {
  887. return (float)Math.Sqrt(Math.Pow((A.X - B.X), 2) + Math.Pow((A.Y - B.Y), 2));
  888. }
  889. #region 窗体事件
  890. private void OTSSamplespaceWindow_Load(object sender, EventArgs e)
  891. {
  892. try
  893. {
  894. //样品台
  895. m_RectangleGDIObjects = new List<ARectangleGDIObject>();
  896. //标样
  897. m_SpecimenGDIObjects = new List<ARectangleGDIObject>();
  898. //样品孔
  899. m_SampleHoleGDIObjects = new List<ARectangleGDIObject>();
  900. //样品孔文字内容
  901. m_ContentGDIObjects = new List<ARectangleGDIObject>();
  902. //样品
  903. m_SampleGDIObjects = new List<ARectangleGDIObject>();
  904. //工作样品
  905. m_WorkStageGDIObjects = new List<ARectangleGDIObject>();
  906. //测量区域
  907. m_MeasureGDIObjects = new List<ARectangleGDIObject>();
  908. //测量区域图形路径
  909. m_MeasurePathGDIObjects = new List<ARectangleGDIObject>();
  910. //手绘测量区域
  911. m_DrawMeasureGDIObjects = new List<ARectangleGDIObject>();
  912. //帧图
  913. m_SingleGDIObjects = new List<ARectangleGDIObject>();
  914. //所有帧图
  915. m_ALLSingleGDIObjects = new List<ARectangleGDIObject>();
  916. //样品孔BSE图像
  917. m_ImageGDIObjects = new List<ARectangleGDIObject>();
  918. //BSE图像帧图为了获取位置与尺寸
  919. m_ImageSingleGDIObjects = new List<ARectangleGDIObject>();
  920. //SEM中心位置
  921. m_SEMCenterGDIObjects = new List<ARectangleGDIObject>();
  922. this.ResizeRedraw = true;
  923. control_Ruler2 = new Control_Ruler();
  924. Point rulerLocation = new Point(10, this.Height - (int)(control_Ruler2.Height * 2));
  925. control_Ruler2.Location = rulerLocation;
  926. this.Controls.Add(control_Ruler2);
  927. log = NLog.LogManager.GetCurrentClassLogger();
  928. }
  929. catch (Exception ex)
  930. {
  931. string message = table["message2"].ToString();
  932. log.Error("OTSSamplespaceWindow_OTSSamplespaceWindow_Load:--" + message + ":" + ex.ToString() + "");
  933. }
  934. }
  935. protected override void OnMouseDown(MouseEventArgs e)
  936. {
  937. lblFocus.Focus();
  938. //记录鼠标按下的位置
  939. m_P.X = e.X;
  940. m_P.Y = e.Y;
  941. m_P1.X = e.X;
  942. m_P1.Y = e.Y;
  943. int WH = 2;
  944. //鼠标点击时的位置
  945. Point _Point = new Point();
  946. m_RectangIsDragging = false;
  947. if (m_RectangleGDIObjects == null)
  948. return;
  949. //判断当前是否手绘
  950. if (m_IsDrawMeasureReady)
  951. {
  952. //获取当前的鼠标点击位置
  953. this.m_MouseDownPoint = new Point(e.X, e.Y);
  954. //获取当前工作样品
  955. COTSSample cSample = m_MeasureAppForm.m_ProjParam.GetWorkSample();
  956. string sampleHoleName = cSample.GetSampleHoleName();
  957. string sampleName = cSample.GetName();
  958. int sizeWH = 5;
  959. Size size = new Size(sizeWH, sizeWH);
  960. Rectangle rectangle = new Rectangle(m_MouseDownPoint, size);
  961. //绘制多边形 测量区域
  962. if (m_DrawMeasureType == (int)CreateRectangleType.Polygon)
  963. {
  964. //显示绘制多边形完成标识
  965. if (m_PolygonPoint.Count > m_PointCount)
  966. {
  967. Point startPoint = new Point((int)(m_PolygonPoint[0].X), (int)(m_PolygonPoint[0].Y));
  968. if (m_IsDrawPolygonFinish)
  969. {
  970. DialogResult dResult = MessageBox.Show(table["message10"].ToString(), table["message11"].ToString(), MessageBoxButtons.YesNo);
  971. if (dResult == DialogResult.Yes)
  972. {
  973. m_PolygonPoint.Add(startPoint);
  974. CreateRectangle createFinishPoint = new CreateRectangle(m_PolygonPoint, (int)CreateRectangleType.Polygon, m_DrawMeasureType, sampleHoleName, sampleName, Color.Red);
  975. GraphicsPath PolygonMeasurePath = new GraphicsPath();
  976. PolygonMeasurePath.AddPolygon(m_PolygonPoint.ToArray());
  977. createFinishPoint.GPath = PolygonMeasurePath;
  978. for (int i = 0; i < createFinishPoint.PolygonPointRegionF.Count; i++)
  979. {
  980. float X = createFinishPoint.PolygonPointRegionF[i].X / m_GlobalZoomNum;
  981. float Y = createFinishPoint.PolygonPointRegionF[i].Y / m_GlobalZoomNum;
  982. PointF DrawPoint = new PointF(X, Y);
  983. createFinishPoint.DrawPolygonPointRegionF[i] = DrawPoint;
  984. }
  985. if (m_DrawMeasureGDIObjects.Count > 0)
  986. {
  987. m_DrawMeasureGDIObjects[0] = createFinishPoint;
  988. }
  989. bool IsSingle = false;
  990. //清除当前的样品测量区域
  991. for (int measureIndex = m_MeasureGDIObjects.Count - 1; measureIndex >= 0; measureIndex--)
  992. {
  993. if (m_MeasureGDIObjects[measureIndex].SampleName == sampleName)
  994. {
  995. IsSingle = m_MeasureGDIObjects[measureIndex].IsSingle;
  996. m_MeasureGDIObjects.RemoveAt(measureIndex);
  997. break;
  998. }
  999. }
  1000. //删除存在的帧图
  1001. for (int singleIndex = m_SingleGDIObjects.Count - 1; singleIndex >= 0; singleIndex--)
  1002. {
  1003. if (m_SingleGDIObjects[singleIndex].SampleName == sampleName)
  1004. {
  1005. m_SingleGDIObjects.RemoveAt(singleIndex);
  1006. }
  1007. }
  1008. //将绘制好的多边形测量区域赋值给 多边形测量区域对象
  1009. if (m_DrawMeasureGDIObjects.Count > 0)
  1010. {
  1011. m_DrawMeasureGDIObjects[0].IsSelect = true;
  1012. m_DrawMeasureGDIObjects[0].IsWorkSample = true;
  1013. //创建多边形外接矩形
  1014. m_DrawMeasureGDIObjects[0].Region = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(OTSSamplespaceGraphicsPanelFun.PointConvertPointF(m_DrawMeasureGDIObjects[0].PolygonPointRegion));
  1015. m_DrawMeasureGDIObjects[0].RegionF = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(m_DrawMeasureGDIObjects[0].DrawPolygonPointRegionF);
  1016. m_DrawMeasureGDIObjects[0].DrawRegionF = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(m_DrawMeasureGDIObjects[0].DrawPolygonPointRegionF);
  1017. m_DrawMeasureGDIObjects[0].IsSingle = IsSingle;
  1018. m_DrawMeasureGDIObjects[0].IsWorkSample = true;
  1019. m_MeasureGDIObjects.Add(m_DrawMeasureGDIObjects[0]);
  1020. m_DrawMeasureGDIObjects.Clear();
  1021. m_DrawPolygonFinishGDIObjects.Clear();
  1022. }
  1023. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(m_MeasureGDIObjects[m_MeasureGDIObjects.Count - 1], m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  1024. {
  1025. m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;
  1026. CMeasureThreadWrapper.DoRunType = (int)MSR_THREAD_RunSTATUS.RUNMEASURE;
  1027. //设置工作样品
  1028. m_MeasureAppForm.Rev_SoluWindowReqSwitchWSample_Event(m_SampleSelectName);
  1029. Invalidate();
  1030. }
  1031. //设置手绘标识
  1032. m_IsDrawMeasureReady = false;
  1033. m_IsDrawMeasure = false;
  1034. m_IsDrawPolygonFinish = false;
  1035. this.Cursor = Cursors.Default;
  1036. return;
  1037. }
  1038. else
  1039. {
  1040. return;
  1041. }
  1042. }
  1043. }
  1044. //添加多边形点信息
  1045. m_MouseDownPoint = new Point((int)(m_MouseDownPoint.X), (int)(m_MouseDownPoint.Y));
  1046. m_PolygonPoint.Add(m_MouseDownPoint);
  1047. CreateRectangle createPoint = new CreateRectangle(m_PolygonPoint, (int)CreateRectangleType.Polygon, m_DrawMeasureType, sampleHoleName, sampleName, Color.Red);
  1048. if (m_DrawMeasureGDIObjects.Count > 0)
  1049. {
  1050. m_DrawMeasureGDIObjects[0] = createPoint;
  1051. }
  1052. else
  1053. {
  1054. m_DrawMeasureGDIObjects.Add(createPoint);
  1055. }
  1056. //添加当前绘制的第一点位置,生成多边形测量区域完成标识
  1057. if (m_DrawPolygonFinishGDIObjects.Count == 0)
  1058. {
  1059. int rectSize = m_MinMeasureWidthValue;
  1060. Point PolygonFinishPoint = new Point((int)(m_MouseDownPoint.X - m_MinMeasureWidthValue / 2), (int)(m_MouseDownPoint.Y - m_MinMeasureWidthValue / 2));
  1061. Rectangle pRect = new Rectangle(PolygonFinishPoint, new Size(rectSize, rectSize));
  1062. CreateRectangle createPolygonFinish = new CreateRectangle(pRect, (int)CreateRectangleType.DrawPolygonFinish, sampleHoleName, sampleName, Color.Green);
  1063. m_DrawPolygonFinishGDIObjects.Add(createPolygonFinish);
  1064. }
  1065. return;
  1066. }
  1067. else if(m_DrawMeasureType == (int)CreateRectangleType.CircleByThreePoints)
  1068. {
  1069. //添加多边形点信息
  1070. m_MouseDownPoint = new Point((int)(m_MouseDownPoint.X), (int)(m_MouseDownPoint.Y));
  1071. m_PolygonPoint.Add(m_MouseDownPoint);
  1072. CreateRectangle createPoint = new CreateRectangle(m_PolygonPoint, (int)CreateRectangleType.Polygon, m_DrawMeasureType, sampleHoleName, sampleName, Color.Red);
  1073. if (m_DrawMeasureGDIObjects.Count > 0)
  1074. {
  1075. m_DrawMeasureGDIObjects[0] = createPoint;
  1076. }
  1077. else
  1078. {
  1079. m_DrawMeasureGDIObjects.Add(createPoint);
  1080. }
  1081. //显示绘制多边形完成标识
  1082. if (m_PolygonPoint.Count == 3)
  1083. {
  1084. //转为圆形这里
  1085. m_DrawMeasureType = (int)CreateRectangleType.Circle;
  1086. float r = 0;
  1087. PointF Centerpoint = new PointF();
  1088. GetTriangleExcenterRadius(m_PolygonPoint[0], m_PolygonPoint[1], m_PolygonPoint[2], out r, out Centerpoint);
  1089. //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));
  1090. RectangleF rectangleThree = new RectangleF(new PointF(Centerpoint.X - r, Centerpoint.Y - r), new SizeF(r * 2, r * 2));
  1091. //在样品台内部缩放
  1092. 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))
  1093. {
  1094. m_IsDrawMeasure = true;
  1095. }
  1096. else
  1097. {
  1098. m_IsDrawMeasure = false;
  1099. return;
  1100. }
  1101. Color MeasureColor = Color.Red;
  1102. CreateRectangle createRectangle = new CreateRectangle(rectangleThree, m_PolygonPoint[0], (int)CreateRectangleType.CircleByThreePoints, m_DrawMeasureType, sampleName, sampleName, MeasureColor);
  1103. //在鼠标点击时添加一个默认大小与位置的图形
  1104. //createRectangle.RegionF = createRectangle.Region;
  1105. createRectangle.RegionF = new RectangleF(createRectangle.RegionF.X / m_GlobalZoomNum, createRectangle.RegionF.Y / m_GlobalZoomNum, createRectangle.RegionF.Width / m_GlobalZoomNum, createRectangle.RegionF.Height / m_GlobalZoomNum);
  1106. createRectangle.DrawRegionF = createRectangle.Region;
  1107. if (m_DrawMeasureGDIObjects.Count > 0)
  1108. {
  1109. m_DrawMeasureGDIObjects[0] = createRectangle;
  1110. }
  1111. else
  1112. {
  1113. m_DrawMeasureGDIObjects.Add(createRectangle);
  1114. }
  1115. //清除当前的样品测量区域
  1116. for (int measureIndex = m_MeasureGDIObjects.Count - 1; measureIndex >= 0; measureIndex--)
  1117. {
  1118. if (m_MeasureGDIObjects[measureIndex].SampleName == sampleName)
  1119. {
  1120. m_MeasureGDIObjects.RemoveAt(measureIndex);
  1121. break;
  1122. }
  1123. }
  1124. //删除存在的帧图
  1125. for (int singleIndex = m_SingleGDIObjects.Count - 1; singleIndex >= 0; singleIndex--)
  1126. {
  1127. if (m_SingleGDIObjects[singleIndex].SampleName == sampleName)
  1128. {
  1129. m_SingleGDIObjects.RemoveAt(singleIndex);
  1130. }
  1131. }
  1132. m_MeasureGDIObjects.Add(m_DrawMeasureGDIObjects[0]);
  1133. m_DrawMeasureGDIObjects.Clear();
  1134. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(m_MeasureGDIObjects[0], m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  1135. {
  1136. m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;
  1137. CMeasureThreadWrapper.DoRunType = (int)MSR_THREAD_RunSTATUS.RUNMEASURE;
  1138. //showSingleInfo();
  1139. // 设置工作样品
  1140. m_MeasureAppForm.Rev_SoluWindowReqSwitchWSample_Event(m_SampleSelectName);
  1141. Invalidate();
  1142. }
  1143. //设置手绘标识
  1144. m_IsDrawMeasureReady = false;
  1145. this.Cursor = Cursors.Default;
  1146. return;
  1147. }
  1148. return;
  1149. }
  1150. else
  1151. {
  1152. //在样品台内部缩放
  1153. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(new Rectangle(this.m_MouseDownPoint, new Size(2, 2)), m_RectangleGDIObjects[0].Region, m_DrawMeasureType))
  1154. {
  1155. m_IsDrawMeasure = true;
  1156. }
  1157. else
  1158. {
  1159. m_IsDrawMeasure = false;
  1160. return;
  1161. }
  1162. Color MeasureColor = Color.Red;
  1163. CreateRectangle createRectangle = new CreateRectangle(rectangle, m_DifferentPoint, (int)CreateRectangleType.MeasureArea, m_DrawMeasureType, sampleName, sampleName, MeasureColor);
  1164. //在鼠标点击时添加一个默认大小与位置的图形
  1165. createRectangle.RegionF = createRectangle.Region;
  1166. createRectangle.DrawRegionF = createRectangle.Region;
  1167. m_DrawMeasureGDIObjects.Add(createRectangle);
  1168. return;
  1169. }
  1170. }
  1171. else
  1172. {
  1173. if (e.Button == MouseButtons.Right)
  1174. {
  1175. if (m_MeasureAppForm.MeasureThreadRunFlag)
  1176. {
  1177. m_IsSelectType = (int)ContextMenuType.ThreadRunMenu;
  1178. //设置编辑右键菜单项
  1179. CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, false);
  1180. _Point = this.PointToClient(Cursor.Position);
  1181. this.CMStrip.Show(this, _Point);
  1182. return;
  1183. }
  1184. //获取鼠标右键点击位置
  1185. m_MouseDownLocation = e.Location;
  1186. //显示XY轴
  1187. OTSSamplespaceGraphicsPanelFun.ShowSemCoordvAL(e.Location, m_MeasureAppForm, m_RectangleGDIObjects, m_OTSSampleStageData, IsWidth);
  1188. string workSampleName = string.Empty;
  1189. foreach (ARectangleGDIObject item in m_SingleGDIObjects)
  1190. {
  1191. if (item.RegionF.Contains(e.Location))
  1192. {
  1193. //样品孔菜单
  1194. m_IsSelectType = (int)ContextMenuType.SingleMenu;
  1195. _Point = this.PointToClient(Cursor.Position);
  1196. bool IsTrue = false;
  1197. //设置编辑右键菜单项
  1198. foreach (ARectangleGDIObject imageItem in m_ImageGDIObjects)
  1199. {
  1200. if (imageItem.SampleName == item.SampleName)
  1201. {
  1202. IsTrue = true;
  1203. break;
  1204. }
  1205. }
  1206. //设置编辑右键菜单项
  1207. CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, IsTrue);
  1208. //将删除样品与测量 设置为不可编辑状态
  1209. this.CMStrip.Show(this, _Point);
  1210. return;
  1211. }
  1212. }
  1213. foreach (ARectangleGDIObject item in m_SampleGDIObjects)
  1214. {
  1215. if (item.IsWorkSample)
  1216. {
  1217. workSampleName = item.SampleName;
  1218. break;
  1219. }
  1220. }
  1221. for (int i = m_MeasureGDIObjects.Count - 1; i >= 0; i--)
  1222. {
  1223. foreach (var SampleItem in m_SampleGDIObjects)
  1224. {
  1225. if (m_MeasureGDIObjects[i].SampleName == SampleItem.SampleName)
  1226. {
  1227. bool isSelMeasure = false;
  1228. if (m_MeasureGDIObjects[i].Shape == (int)CreateRectangleType.Polygon)
  1229. {
  1230. //判断当前位置是否在不规则形状里面
  1231. if (OTSSamplespaceGraphicsPanelFun.PositionPnpoly(OTSSamplespaceGraphicsPanelFun.PointFConvertPoint(m_MeasureGDIObjects[i].PolygonPointRegionF), e.Location) && !m_MeasureGDIObjects[i].SelColor.Name.Equals("Transparent"))
  1232. {
  1233. isSelMeasure = true;
  1234. }
  1235. }
  1236. else
  1237. {
  1238. if (m_MeasureGDIObjects[i].Region.Contains(e.Location) && !m_MeasureGDIObjects[i].SelColor.Name.Equals("Transparent"))
  1239. {
  1240. isSelMeasure = true;
  1241. Rectangle rect = new Rectangle(e.Location, new Size(WH, WH));
  1242. int CheckShape = (int)CreateRectangleType.Circle;
  1243. if (m_MeasureGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  1244. {
  1245. CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;
  1246. }
  1247. if (!OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rect, m_MeasureGDIObjects[i].Region, CheckShape))
  1248. {
  1249. break;
  1250. }
  1251. }
  1252. }
  1253. if (isSelMeasure)
  1254. {
  1255. //如果选择的样品不是当前工作样品 则删除原有帧图信息
  1256. if (m_MeasureGDIObjects[i].SampleName != workSampleName)
  1257. {
  1258. ClearImageAndSingleGDIObjects();
  1259. }
  1260. //删除BSE照片
  1261. bool IsTrue = false;
  1262. //设置编辑右键菜单项
  1263. foreach (ARectangleGDIObject imageItem in m_ImageGDIObjects)
  1264. {
  1265. if (imageItem.SampleName == m_MeasureGDIObjects[i].SampleName)
  1266. {
  1267. IsTrue = true;
  1268. break;
  1269. }
  1270. }
  1271. //测量区域菜单
  1272. m_IsSelectType = (int)ContextMenuType.MeasureMenu;
  1273. //设置编辑右键菜单项
  1274. CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, IsTrue);
  1275. _Point = this.PointToClient(Cursor.Position);
  1276. this.CMStrip.Show(this, _Point);
  1277. m_MeasureSelectName = m_MeasureGDIObjects[i].SampleName;
  1278. m_SampleHoleSelectName = m_MeasureGDIObjects[i].Name;
  1279. if (m_SampleSelectName != m_MeasureGDIObjects[i].SampleName)
  1280. {
  1281. m_SampleSelectName = m_MeasureGDIObjects[i].SampleName;
  1282. m_MeasureGDIObjects[i].IsSelect = true;
  1283. m_MeasureGDIObjects[i].IsWorkSample = true;
  1284. //设置工作样品
  1285. m_MeasureAppForm.Rev_SoluWindowReqSwitchWSample_Event(m_SampleSelectName);
  1286. Invalidate();
  1287. }
  1288. return;
  1289. }
  1290. }
  1291. }
  1292. }
  1293. foreach (ARectangleGDIObject item in m_ImageGDIObjects)
  1294. {
  1295. if (item.Region.Contains(e.Location))
  1296. {
  1297. //样品孔菜单
  1298. m_IsSelectType = (int)ContextMenuType.SampleHoleBSEImage;
  1299. _Point = this.PointToClient(Cursor.Position);
  1300. //设置编辑右键菜单项
  1301. CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, false);
  1302. this.CMStrip.Show(this, _Point);
  1303. return;
  1304. }
  1305. }
  1306. //只点击样品上(测量区域被移动到其他地方)
  1307. for (int i = m_SampleGDIObjects.Count - 1; i >= 0; i--)
  1308. {
  1309. if (m_SampleGDIObjects[i].Region.Contains(e.Location))
  1310. {
  1311. //如果选择的样品不是当前工作样品 则删除原有帧图信息
  1312. if (m_SampleGDIObjects[i].SampleName != workSampleName)
  1313. {
  1314. ClearImageAndSingleGDIObjects();
  1315. }
  1316. Rectangle rect = new Rectangle(e.Location, new Size(WH, WH));
  1317. //判断样品形状
  1318. int CheckShape = (int)CreateRectangleType.Circle;
  1319. if (m_MeasureGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  1320. {
  1321. CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;
  1322. }
  1323. if (!OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rect, m_SampleGDIObjects[i].Region, CheckShape))
  1324. {
  1325. break;
  1326. }
  1327. //样品菜单
  1328. m_IsSelectType = (int)ContextMenuType.SampleMenu;
  1329. //将删除样品与测量 设置为不可编辑状态
  1330. _Point = this.PointToClient(Cursor.Position);
  1331. bool flag = false;
  1332. foreach (var MeasureItem in m_MeasureGDIObjects)
  1333. {
  1334. if (m_SampleGDIObjects[i].SampleName == MeasureItem.SampleName)
  1335. {
  1336. if (MeasureItem.Region.Contains(e.Location))
  1337. {
  1338. //测量区域菜单
  1339. m_IsSelectType = (int)ContextMenuType.MeasureMenu;
  1340. //flag = !MeasureItem.IsSingle;
  1341. break;
  1342. }
  1343. }
  1344. }
  1345. //设置编辑右键菜单项
  1346. CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, flag);
  1347. this.CMStrip.Show(this, _Point);
  1348. if (m_SampleSelectName != m_SampleGDIObjects[i].SampleName)
  1349. {
  1350. m_SampleSelectName = m_SampleGDIObjects[i].SampleName;
  1351. m_SampleHoleSelectName = m_SampleGDIObjects[i].Name;
  1352. m_SampleGDIObjects[i].IsSelect = true;
  1353. m_SampleGDIObjects[i].IsWorkSample = true;
  1354. //设置工作样品 向主窗体发送请求
  1355. m_MeasureAppForm.Rev_SoluWindowReqSwitchWSample_Event(m_SampleSelectName);
  1356. Invalidate();
  1357. }
  1358. return;
  1359. }
  1360. }
  1361. //点击样品孔
  1362. foreach (ARectangleGDIObject item in m_SampleHoleGDIObjects)
  1363. {
  1364. if (item.Region.Contains(e.Location))
  1365. {
  1366. Rectangle rect = new Rectangle(e.Location, new Size(WH, WH));
  1367. int CheckShape = (int)CreateRectangleType.Circle;
  1368. if (item.Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  1369. {
  1370. CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;
  1371. }
  1372. //样品孔菜单
  1373. m_IsSelectType = (int)ContextMenuType.SampleHoleMenu;
  1374. _Point = this.PointToClient(Cursor.Position);
  1375. //设置编辑右键菜单项
  1376. CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, false);
  1377. //将删除样品与测量 设置为不可编辑状态
  1378. this.CMStrip.Show(this, _Point);
  1379. m_SampleHoleSelectName = item.Name;
  1380. item.IsSelect = true;
  1381. return;
  1382. }
  1383. }
  1384. foreach (ARectangleGDIObject item in m_RectangleGDIObjects)
  1385. {
  1386. if (item.Region.Contains(e.Location))
  1387. {
  1388. //样品台菜单
  1389. m_IsSelectType = (int)ContextMenuType.SampleStateMenu;
  1390. //设置编辑右键菜单项
  1391. CStageManage.SetShowCMStrip(m_IsSelectType, CMStrip, false);
  1392. _Point = this.PointToClient(Cursor.Position);
  1393. this.CMStrip.Show(this, _Point);
  1394. break;
  1395. }
  1396. }
  1397. return;
  1398. }
  1399. //左键点击样品台上
  1400. else
  1401. {
  1402. //如果正在进行测量线程,则退出鼠标点击操作
  1403. if (m_MeasureAppForm.MeasureThreadRunFlag)
  1404. {
  1405. return;
  1406. }
  1407. foreach (ARectangleGDIObject item in m_RectangleGDIObjects)
  1408. {
  1409. if (item.Region.Contains(e.Location))
  1410. {
  1411. m_RectangIsDragging = true;
  1412. m_IsSelectSampleStage = true;
  1413. }
  1414. item.IsDragging = true;
  1415. item.DraggingPoint = e.Location;
  1416. }
  1417. //测量区域
  1418. foreach (ARectangleGDIObject item in m_MeasureGDIObjects)
  1419. {
  1420. if (Control.ModifierKeys == Keys.Control)
  1421. {
  1422. //获取选择工作样品的测量状态
  1423. selWSampleMeasureStatus = m_MeasureAppForm.m_ProjParam.GetWorkSampleMeasureStatus();
  1424. if (selWSampleMeasureStatus)
  1425. {
  1426. return;
  1427. }
  1428. //如果选择的测量区域 颜色不是透明 可以选择
  1429. if (!item.SelColor.Name.Equals("Transparent"))
  1430. {
  1431. if (item.CreateType == (int)CreateRectangleType.Polygon)
  1432. {
  1433. if (item.GPath != null)
  1434. {
  1435. //在多边形点附近切换光标
  1436. foreach (PointF itemPoint in item.PolygonPointRegionF)
  1437. {
  1438. if (Math.Abs(itemPoint.X - e.X) <= m_OffsetPX && Math.Abs(itemPoint.Y - e.Y) <= m_OffsetPX)
  1439. {
  1440. if (Control.ModifierKeys == Keys.Control)
  1441. {
  1442. if (m_DrawPolygonFinishGDIObjects != null)
  1443. {
  1444. if (m_DrawPolygonFinishGDIObjects.Count > 0)
  1445. {
  1446. m_DrawPolygonFinishGDIObjects.Clear();
  1447. }
  1448. }
  1449. m_IsSelPolygonPoint = true;
  1450. m_IsCtrl = true;
  1451. m_IsSelectSampleStage = false;
  1452. //选择前测量区域的尺寸
  1453. m_SelMeasureRect = item.Region;
  1454. m_MeasureRectangle = item.Region;
  1455. item.SelColor = Color.Red;
  1456. item.IsDragging = true;
  1457. item.DraggingPoint = e.Location;
  1458. item.IsSelect = true;
  1459. item.IsWorkSample = true;
  1460. //记录选择的多边形点信息
  1461. m_SelPolygonPoint = itemPoint;
  1462. int rectSize = m_MinMeasureWidthValue;
  1463. Point PolygonFinishPoint = new Point((int)(itemPoint.X - m_MinMeasureWidthValue / 2), (int)(itemPoint.Y - m_MinMeasureWidthValue / 2));
  1464. Rectangle pRect = new Rectangle(PolygonFinishPoint, new Size(rectSize, rectSize));
  1465. CreateRectangle createPolygonFinish = new CreateRectangle(pRect, (int)CreateRectangleType.DrawPolygonFinish, "", "", Color.Green);
  1466. if (m_DrawPolygonFinishGDIObjects != null)
  1467. {
  1468. m_DrawPolygonFinishGDIObjects.Add(createPolygonFinish);
  1469. }
  1470. break;
  1471. }
  1472. }
  1473. }
  1474. //如果鼠标已选择多边形的点,跳出循环
  1475. if (item.IsSelect == true)
  1476. {
  1477. break;
  1478. }
  1479. if (item.GPath.IsVisible(e.Location))
  1480. {
  1481. m_IsCtrl = true;
  1482. m_IsSelectSampleStage = false;
  1483. //选择前测量区域的尺寸
  1484. m_SelMeasureRect = item.Region;
  1485. m_MeasureRectangle = item.Region;
  1486. item.SelColor = Color.Red;
  1487. item.IsDragging = true;
  1488. item.DraggingPoint = e.Location;
  1489. item.IsWorkSample = true;
  1490. item.IsSelect = false;
  1491. break;
  1492. }
  1493. }
  1494. }
  1495. else
  1496. {
  1497. if (item.GPath != null)
  1498. {
  1499. if (item.GPath.IsOutlineVisible((float)e.X, (float)e.Y, new Pen(Color.Gray, m_PenWidth)))
  1500. {
  1501. m_IsCtrl = true;
  1502. m_IsSelectSampleStage = false;
  1503. //选择前测量区域的尺寸
  1504. m_SelMeasureRect = item.Region;
  1505. m_MeasureRectangle = item.Region;
  1506. item.SelColor = Color.Red;
  1507. item.IsDragging = true;
  1508. item.DraggingPoint = e.Location;
  1509. item.IsSelect = true;
  1510. item.IsWorkSample = true;
  1511. break;
  1512. }
  1513. }
  1514. if (item.Region.Contains(e.Location))
  1515. {
  1516. m_IsCtrl = true;
  1517. m_IsSelectSampleStage = false;
  1518. //选择前测量区域的尺寸
  1519. m_SelMeasureRect = item.Region;
  1520. m_MeasureRectangle = item.Region;
  1521. item.SelColor = Color.Red;
  1522. item.IsDragging = true;
  1523. item.DraggingPoint = e.Location;
  1524. item.IsWorkSample = true;
  1525. item.IsSelect = false;
  1526. break;
  1527. }
  1528. }
  1529. }
  1530. }
  1531. }
  1532. //当鼠标点击样品上(测量区域被拖动到其他地方)
  1533. for (int i = m_SampleGDIObjects.Count - 1; i >= 0; i--)
  1534. {
  1535. if ((Control.ModifierKeys == Keys.Alt))
  1536. {
  1537. if (m_SampleGDIObjects[i].Region.Contains(e.Location))
  1538. {
  1539. m_IsMoveSample = true;
  1540. m_IsSelectSampleStage = false;
  1541. m_IsAlt = true;
  1542. }
  1543. }
  1544. if (!(Control.ModifierKeys == Keys.Control))
  1545. {
  1546. if (m_SampleGDIObjects[i].Region.Contains(e.Location))
  1547. {
  1548. foreach (var measureItem in m_MeasureGDIObjects)
  1549. {
  1550. if (measureItem.SampleName == m_SampleGDIObjects[i].SampleName)
  1551. {
  1552. m_MeasureRectangle = measureItem.Region;
  1553. measureItem.SelColor = Color.Red;
  1554. }
  1555. else
  1556. {
  1557. measureItem.SelColor = Color.Transparent;
  1558. }
  1559. }
  1560. for (int x = 0; x < m_SampleGDIObjects.Count; x++)
  1561. {
  1562. //获取颜色
  1563. string SampleColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
  1564. m_SampleGDIObjects[x].SelColor = ColorTranslator.FromHtml(SampleColorStr);
  1565. m_SampleGDIObjects[x].IsWorkSample = false;
  1566. m_SampleGDIObjects[x].IsSelect = false;
  1567. }
  1568. //设置为工作样品
  1569. m_SampleGDIObjects[i].IsWorkSample = true;
  1570. m_SampleGDIObjects[i].IsSelect = true;
  1571. //获取颜色
  1572. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  1573. m_SampleGDIObjects[i].SelColor = ColorTranslator.FromHtml(ColorStr);
  1574. selectSampleGDIObjects = m_SampleGDIObjects[i];
  1575. if (m_SampleSelectName != m_SampleGDIObjects[i].SampleName)
  1576. {
  1577. //获取工作样品名称
  1578. m_SampleSelectName = m_SampleGDIObjects[i].SampleName;
  1579. //设置工作样品 向主窗体发送请求
  1580. m_MeasureAppForm.Rev_SoluWindowReqSwitchWSample_Event(m_SampleSelectName);
  1581. }
  1582. break;
  1583. }
  1584. }
  1585. }
  1586. //样品
  1587. MouseDownFucntion(m_SampleGDIObjects, e);
  1588. //样品孔
  1589. MouseDownFucntion(m_SampleHoleGDIObjects, e);
  1590. //标样
  1591. MouseDownFucntion(m_SpecimenGDIObjects, e);
  1592. //测量
  1593. MouseDownFucntion(m_MeasureGDIObjects, e);
  1594. //文字
  1595. MouseDownFucntion(m_ContentGDIObjects, e);
  1596. //帧图
  1597. MouseDownFucntion(m_SingleGDIObjects, e);
  1598. //所有获取的帧图
  1599. MouseDownFucntion(m_ALLSingleGDIObjects, e);
  1600. //样品台中BSE图片
  1601. MouseDownFucntion(m_ImageGDIObjects, e);
  1602. //SEM中心位置
  1603. MouseDownFucntion(m_SEMCenterGDIObjects, e);
  1604. for (int i = m_SampleGDIObjects.Count - 1; i >= 0; i--)
  1605. {
  1606. if (m_SampleGDIObjects[i].Region.Contains(e.Location) && m_SampleGDIObjects[i].IsWorkSample)
  1607. {
  1608. //获取当前样品与测量区域的位置
  1609. foreach (ARectangleGDIObject item in m_MeasureGDIObjects)
  1610. {
  1611. if (m_SampleGDIObjects[i].SampleName == item.SampleName && m_SampleGDIObjects[i].IsWorkSample)
  1612. {
  1613. m_MeasureToSamplePoint.X = m_SampleGDIObjects[i].Region.X - item.Region.X;
  1614. m_MeasureToSamplePoint.Y = m_SampleGDIObjects[i].Region.Y - item.Region.Y;
  1615. break;
  1616. }
  1617. }
  1618. }
  1619. }
  1620. }
  1621. }
  1622. //重绘控件
  1623. Invalidate();
  1624. }
  1625. protected override void OnMouseMove(MouseEventArgs e)
  1626. {
  1627. //'记录光标拖动的当前点
  1628. m_P1.X = e.X;
  1629. m_P1.Y = e.Y;
  1630. bool InMeasure = false;
  1631. //如果正在进行测量线程,则退出鼠标点击操作
  1632. if (m_MeasureAppForm.MeasureThreadRunFlag)
  1633. {
  1634. return;
  1635. }
  1636. //获取选择工作样品的测量状态
  1637. if (selWSampleMeasureStatus)
  1638. {
  1639. return;
  1640. }
  1641. //手动绘制 记录鼠标移动位置
  1642. if (m_IsDrawMeasure)
  1643. {
  1644. this.m_MouseMovePoint = new Point(e.X, e.Y);
  1645. //绘制多边形
  1646. if (m_DrawMeasureType == (int)CreateRectangleType.Polygon)
  1647. {
  1648. PointF startPoint = new PointF();
  1649. PointF endPoint = new PointF();
  1650. //显示直线开始点与鼠标当前位置的直线
  1651. if (m_PolygonPoint.Count > 0)
  1652. {
  1653. startPoint = m_PolygonPoint[0];
  1654. endPoint = m_PolygonPoint[m_PolygonPoint.Count - 1];
  1655. }
  1656. //显示绘制多边形完成标识
  1657. if (m_PolygonPoint.Count > m_PointCount)
  1658. {
  1659. if (Math.Abs(m_MouseMovePoint.X - startPoint.X) <= m_OffsetPX && Math.Abs(m_MouseMovePoint.Y - startPoint.Y) <= m_OffsetPX)
  1660. {
  1661. //显示绘制多边形完成标识
  1662. m_IsDrawPolygonFinish = true;
  1663. }
  1664. else
  1665. {
  1666. m_IsDrawPolygonFinish = false;
  1667. }
  1668. }
  1669. }
  1670. //圆形三点法
  1671. else if (m_DrawMeasureType == (int)CreateRectangleType.CircleByThreePoints)
  1672. {
  1673. PointF startPoint = new PointF();
  1674. PointF endPoint = new PointF();
  1675. //显示直线开始点与鼠标当前位置的直线
  1676. if (m_PolygonPoint.Count > 0)
  1677. {
  1678. startPoint = m_PolygonPoint[0];
  1679. endPoint = m_PolygonPoint[m_PolygonPoint.Count - 1];
  1680. }
  1681. }
  1682. else
  1683. {
  1684. if (m_DrawMeasureGDIObjects == null || m_RectangleGDIObjects == null)
  1685. {
  1686. return;
  1687. }
  1688. Rectangle rectangle = new Rectangle();
  1689. foreach (var item in m_DrawMeasureGDIObjects)
  1690. {
  1691. rectangle = item.Region;
  1692. //移动鼠标绘制测量区域
  1693. 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));
  1694. if (tmp == 0)
  1695. {
  1696. tmp = m_DValue;
  1697. }
  1698. //移动鼠标绘制测量区域
  1699. //以中心绘制测量区域方法
  1700. //rectangle = new Rectangle(m_MouseDownPoint.X - tmp, m_MouseDownPoint.Y - tmp, 2 * tmp, 2 * tmp);
  1701. OTSSamplespaceGraphicsPanelFun.EnumMousePointPosition enumMouse = OTSSamplespaceGraphicsPanelFun.MousePointPosition(m_MouseDownPoint, m_MouseMovePoint);
  1702. Point LTPoint = new Point();
  1703. Size RBSize = new Size();
  1704. switch (enumMouse)
  1705. {
  1706. case OTSSamplespaceGraphicsPanelFun.EnumMousePointPosition.MouseSizeTopLeft:
  1707. if (m_DrawMeasureType == (int)CreateRectangleType.Circle)
  1708. {
  1709. LTPoint.X = m_MouseDownPoint.X - tmp;
  1710. LTPoint.Y = m_MouseDownPoint.Y - tmp;
  1711. RBSize.Width = tmp;
  1712. RBSize.Height = tmp;
  1713. rectangle = new Rectangle(LTPoint, RBSize);
  1714. }
  1715. else
  1716. {
  1717. LTPoint.X = m_MouseMovePoint.X;
  1718. LTPoint.Y = m_MouseMovePoint.Y;
  1719. RBSize.Width = m_MouseDownPoint.X - m_MouseMovePoint.X;
  1720. RBSize.Height = m_MouseDownPoint.Y - m_MouseMovePoint.Y;
  1721. rectangle = new Rectangle(LTPoint, RBSize);
  1722. }
  1723. break;
  1724. case OTSSamplespaceGraphicsPanelFun.EnumMousePointPosition.MouseSizeTopRight:
  1725. if (m_DrawMeasureType == (int)CreateRectangleType.Circle)
  1726. {
  1727. LTPoint.X = m_MouseDownPoint.X;
  1728. LTPoint.Y = m_MouseDownPoint.Y - tmp;
  1729. RBSize.Width = tmp;
  1730. RBSize.Height = tmp;
  1731. rectangle = new Rectangle(LTPoint, RBSize);
  1732. }
  1733. else
  1734. {
  1735. LTPoint.X = m_MouseDownPoint.X;
  1736. LTPoint.Y = m_MouseDownPoint.Y - (m_MouseDownPoint.Y - m_MouseMovePoint.Y);
  1737. RBSize.Width = m_MouseMovePoint.X - m_MouseDownPoint.X;
  1738. RBSize.Height = m_MouseDownPoint.Y - m_MouseMovePoint.Y;
  1739. rectangle = new Rectangle(LTPoint, RBSize);
  1740. }
  1741. break;
  1742. case OTSSamplespaceGraphicsPanelFun.EnumMousePointPosition.MouseSizeBottomLeft:
  1743. if (m_DrawMeasureType == (int)CreateRectangleType.Circle)
  1744. {
  1745. LTPoint.X = m_MouseDownPoint.X - tmp;
  1746. LTPoint.Y = m_MouseDownPoint.Y;
  1747. RBSize.Width = tmp;
  1748. RBSize.Height = tmp;
  1749. rectangle = new Rectangle(LTPoint, RBSize);
  1750. }
  1751. else
  1752. {
  1753. LTPoint.X = m_MouseDownPoint.X - (m_MouseDownPoint.X - m_MouseMovePoint.X);
  1754. LTPoint.Y = m_MouseDownPoint.Y;
  1755. RBSize.Width = m_MouseDownPoint.X - m_MouseMovePoint.X;
  1756. RBSize.Height = m_MouseMovePoint.Y - m_MouseDownPoint.Y;
  1757. rectangle = new Rectangle(LTPoint, RBSize);
  1758. }
  1759. break;
  1760. case OTSSamplespaceGraphicsPanelFun.EnumMousePointPosition.MouseSizeBottomRight:
  1761. if (m_DrawMeasureType == (int)CreateRectangleType.Circle)
  1762. {
  1763. LTPoint.X = m_MouseDownPoint.X;
  1764. LTPoint.Y = m_MouseDownPoint.Y;
  1765. RBSize.Width = tmp;
  1766. RBSize.Height = tmp;
  1767. rectangle = new Rectangle(LTPoint, RBSize);
  1768. }
  1769. else
  1770. {
  1771. LTPoint.X = m_MouseDownPoint.X;
  1772. LTPoint.Y = m_MouseDownPoint.Y;
  1773. RBSize.Width = m_MouseMovePoint.X - m_MouseDownPoint.X;
  1774. RBSize.Height = m_MouseMovePoint.Y - m_MouseDownPoint.Y;
  1775. rectangle = new Rectangle(LTPoint, RBSize);
  1776. }
  1777. break;
  1778. }
  1779. //在样品台内部缩放
  1780. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectangle, m_RectangleGDIObjects[0].Region, m_DrawMeasureType))
  1781. {
  1782. //移动鼠标绘制测量区域
  1783. //以中心绘制测量区域方法
  1784. //item.Region = new Rectangle(m_MouseDownPoint.X - tmp, m_MouseDownPoint.Y - tmp, 2 * tmp, 2 * tmp);
  1785. item.Region = new Rectangle(LTPoint, RBSize);
  1786. 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));
  1787. item.DrawRegionF = item.RegionF;
  1788. //生成图形路径
  1789. GraphicsPath MeasurePath = new GraphicsPath();
  1790. if (item.Shape == (int)CreateRectangleType.Rectangle)
  1791. {
  1792. MeasurePath.AddRectangle(item.Region);
  1793. }
  1794. else
  1795. {
  1796. MeasurePath.AddEllipse(item.Region);
  1797. }
  1798. item.GPath = MeasurePath;
  1799. break;
  1800. }
  1801. }
  1802. }
  1803. }
  1804. if (m_RectangIsDragging)
  1805. {
  1806. if (m_RectangleGDIObjects == null) { return; }
  1807. if (!m_IsSelectSampleStage)
  1808. {
  1809. foreach (ARectangleGDIObject item in m_SampleGDIObjects)
  1810. {
  1811. if (!m_IsMeasure)
  1812. {
  1813. if (item.Region.Contains(e.Location))
  1814. {
  1815. if (item.IsDragging)
  1816. {
  1817. if (item.IsWorkSample)
  1818. {
  1819. if (item.IsSelect)
  1820. {
  1821. //判断移动的样品 是否在样品台尺寸范围内
  1822. foreach (ARectangleGDIObject measureItem in m_MeasureGDIObjects)
  1823. {
  1824. if (measureItem.SampleName == item.SampleName)
  1825. {
  1826. if (measureItem.CreateType == (int)CreateRectangleType.Polygon)
  1827. {
  1828. if (this.Cursor != Cursors.Default)
  1829. {
  1830. return;
  1831. }
  1832. //判断移动的样品 是否在样品台尺寸范围内
  1833. Rectangle rectTemp = item.Region;
  1834. rectTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;
  1835. rectTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;
  1836. int CheckShape = (int)CreateRectangleType.Circle;
  1837. if (m_RectangleGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  1838. {
  1839. CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;
  1840. }
  1841. //判断样品是否超越样品台
  1842. if (!OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  1843. {
  1844. return;
  1845. }
  1846. else
  1847. {
  1848. //生成多边形最小面积外接矩形
  1849. Rectangle rectMeasureTemp = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(measureItem.PolygonPointRegionF);
  1850. //判断多边形是否超越样品台
  1851. rectMeasureTemp.X = rectMeasureTemp.Left + e.X - measureItem.DraggingPoint.X;
  1852. rectMeasureTemp.Y = rectMeasureTemp.Top + e.Y - measureItem.DraggingPoint.Y;
  1853. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectMeasureTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  1854. {
  1855. Rectangle rectSampleTemp = item.Region;
  1856. rectSampleTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;
  1857. rectSampleTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;
  1858. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectSampleTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  1859. {
  1860. MouseMovePolygonMeasureFucntion(measureItem, e);
  1861. OTSSamplespaceGraphicsPanelFun.GetMouseMoveLocation(item, e);
  1862. //计算两个点之间的距离 移动样品台后与绘制样品台时的位置
  1863. m_DifferentPoint = OTSSamplespaceGraphicsPanelFun.StartToEndPointDist(m_RectangleGDIObjects[0], m_RegionStartCenterPoint);
  1864. isChange = true;
  1865. }
  1866. }
  1867. }
  1868. }
  1869. else
  1870. {
  1871. Rectangle rectMeasureTemp = measureItem.Region;
  1872. rectMeasureTemp.X = measureItem.Region.Left + e.X - measureItem.DraggingPoint.X;
  1873. rectMeasureTemp.Y = measureItem.Region.Top + e.Y - measureItem.DraggingPoint.Y;
  1874. //判断移动的样品 是否在样品台尺寸范围内
  1875. Rectangle rectTemp = item.Region;
  1876. rectTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;
  1877. rectTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;
  1878. int CheckShape = (int)CreateRectangleType.Circle;
  1879. if (m_RectangleGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  1880. {
  1881. CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;
  1882. }
  1883. //判断样品是否超越样品台
  1884. if (!OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  1885. {
  1886. return;
  1887. }
  1888. //判断测量区域是否超越样品台
  1889. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectMeasureTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  1890. {
  1891. Rectangle rectSampleTemp = item.Region;
  1892. rectSampleTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;
  1893. rectSampleTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;
  1894. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectSampleTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  1895. {
  1896. MouseMoveMeasureFucntion(measureItem, e);
  1897. OTSSamplespaceGraphicsPanelFun.GetMouseMoveLocation(item, e);
  1898. //计算两个点之间的距离 移动样品台后与绘制样品台时的位置
  1899. m_DifferentPoint = OTSSamplespaceGraphicsPanelFun.StartToEndPointDist(m_RectangleGDIObjects[0], m_RegionStartCenterPoint);
  1900. isChange = true;
  1901. }
  1902. }
  1903. else
  1904. {
  1905. return;
  1906. }
  1907. }
  1908. }
  1909. }
  1910. }
  1911. foreach (ARectangleGDIObject sampleHoleItem in m_SampleHoleGDIObjects)
  1912. {
  1913. //获取样品孔中心点
  1914. Point sampleHoleCenterPoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(sampleHoleItem);
  1915. if (item.Region.Contains(sampleHoleCenterPoint))
  1916. {
  1917. if (item.Name != sampleHoleItem.Name)
  1918. {
  1919. //获取颜色
  1920. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
  1921. item.SelColor = ColorTranslator.FromHtml(ColorStr);
  1922. break;
  1923. }
  1924. }
  1925. else
  1926. {
  1927. //获取颜色
  1928. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  1929. item.SelColor = ColorTranslator.FromHtml(ColorStr);
  1930. }
  1931. }
  1932. }
  1933. Invalidate();
  1934. }
  1935. }
  1936. }
  1937. }
  1938. foreach (ARectangleGDIObject item in m_MeasureGDIObjects)
  1939. {
  1940. //检测鼠标光标点是否在路径上
  1941. if (item.IsDragging)
  1942. {
  1943. if (item.IsWorkSample)
  1944. {
  1945. if (item.IsSelect)
  1946. {
  1947. if (item.DraggingPoint != Point.Empty)
  1948. {
  1949. //获取中心点
  1950. Point xy1 = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(item.Region);
  1951. //获取鼠标坐标
  1952. Point xy2 = e.Location;
  1953. Rectangle rectTemp = new Rectangle();
  1954. int CheckShape = (int)CreateRectangleType.Circle;
  1955. if (item.CreateType == (int)CreateRectangleType.Polygon)
  1956. {
  1957. if (m_IsSelPolygonPoint)
  1958. {
  1959. //获取选中点进行移动,代码
  1960. #region MyRegion
  1961. if (Control.ModifierKeys == Keys.Control)
  1962. {
  1963. //int pointCount = m_DrawPolygonFinishGDIObjects.Count;
  1964. //在多边形点附近切换光标
  1965. for (int i = 0; i < item.PolygonPointRegionF.Count; i++)
  1966. {
  1967. if (item.PolygonPointRegionF[i].X == m_SelPolygonPoint.X && item.PolygonPointRegionF[i].Y == m_SelPolygonPoint.Y)
  1968. {
  1969. //移动点的位置
  1970. Rectangle selPolygonPointRect = new Rectangle(0, 0, 2, 2);
  1971. selPolygonPointRect.X = (int)m_SelPolygonPoint.X + e.X - item.DraggingPoint.X;
  1972. selPolygonPointRect.Y = (int)m_SelPolygonPoint.Y + e.Y - item.DraggingPoint.Y;
  1973. //判断样品是否超越样品台
  1974. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(selPolygonPointRect, m_RectangleGDIObjects[0].Region, CheckShape))
  1975. {
  1976. if (i == 0 || i == item.PolygonPointRegionF.Count - 1)
  1977. {
  1978. //移动点
  1979. m_SelPolygonPoint = new Point(e.X, e.Y);
  1980. item.PolygonPointRegion[item.PolygonPointRegionF.Count - 1] = new Point((int)m_SelPolygonPoint.X, (int)m_SelPolygonPoint.Y);
  1981. item.PolygonPointRegionF[item.PolygonPointRegionF.Count - 1] = m_SelPolygonPoint;
  1982. item.DrawPolygonPointRegionF[item.PolygonPointRegionF.Count - 1] = new PointF(m_SelPolygonPoint.X / m_GlobalZoomNum, m_SelPolygonPoint.Y / m_GlobalZoomNum);
  1983. item.PolygonPointRegionF[0] = m_SelPolygonPoint;
  1984. item.PolygonPointRegion[0] = new Point((int)m_SelPolygonPoint.X, (int)m_SelPolygonPoint.Y);
  1985. item.PolygonPointRegionF[0] = m_SelPolygonPoint;
  1986. item.DrawPolygonPointRegionF[0] = new PointF(m_SelPolygonPoint.X / m_GlobalZoomNum, m_SelPolygonPoint.Y / m_GlobalZoomNum);
  1987. }
  1988. else
  1989. {
  1990. m_SelPolygonPoint = new Point(e.X, e.Y);
  1991. item.PolygonPointRegion[i] = new Point((int)m_SelPolygonPoint.X, (int)m_SelPolygonPoint.Y);
  1992. item.PolygonPointRegionF[i] = m_SelPolygonPoint;
  1993. item.DrawPolygonPointRegionF[i] = new PointF(m_SelPolygonPoint.X / m_GlobalZoomNum, m_SelPolygonPoint.Y / m_GlobalZoomNum);
  1994. }
  1995. 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));
  1996. 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));
  1997. 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));
  1998. //生成多边形最小面积外接矩形
  1999. Rectangle rectPolygonMeasure = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(item.PolygonPointRegionF);
  2000. item.Region = rectPolygonMeasure;
  2001. item.RegionF = rectPolygonMeasure;
  2002. item.DrawRegionF = rectPolygonMeasure;
  2003. item.DraggingPoint = e.Location;
  2004. break;
  2005. }
  2006. }
  2007. }
  2008. }
  2009. #endregion
  2010. }
  2011. }
  2012. else
  2013. {
  2014. //计算偏离半径
  2015. int a = (xy1.X - xy2.X) * (xy1.X - xy2.X);
  2016. int b = (xy1.Y - xy2.Y) * (xy1.Y - xy2.Y);
  2017. int c = a + b;
  2018. int r = Convert.ToInt32(System.Math.Sqrt(c));
  2019. int width = r * 2;
  2020. rectTemp = new Rectangle(xy1.X - r, xy1.Y - r, width, width);
  2021. //在样品台内部缩放
  2022. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  2023. {
  2024. #region 需抽出作为公共方法
  2025. int xMove = rectTemp.X - item.Region.X;
  2026. int yMove = rectTemp.Y - item.Region.Y;
  2027. int Width = rectTemp.Width - item.Region.Width;
  2028. int Height = rectTemp.Height - item.Region.Height;
  2029. //如果大于最小测量高度 设置图形大小
  2030. if (rectTemp.Width / m_GlobalZoomNum > m_MinMeasureWidthValue)
  2031. {
  2032. item.Region = rectTemp;
  2033. float WidthNew = (float)((item.RegionF.Width + Width / m_GlobalZoomNum));
  2034. float HeightNew = (float)((item.RegionF.Height + Height / m_GlobalZoomNum));
  2035. //设置原测量区域图形大小
  2036. float xMoveNew = (float)((item.RegionF.X + xMove / m_GlobalZoomNum));
  2037. float yMoveNew = (float)((item.RegionF.Y + yMove / m_GlobalZoomNum));
  2038. item.RegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));
  2039. item.DrawRegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));
  2040. item.DraggingPoint = e.Location;
  2041. isChange = true;
  2042. }
  2043. #endregion
  2044. }
  2045. else
  2046. {
  2047. return;
  2048. }
  2049. Invalidate();
  2050. return;
  2051. }
  2052. }
  2053. }
  2054. else
  2055. {
  2056. //鼠标配合Ctrol键 移动单个测量区域
  2057. if (item.Shape == (int)CreateRectangleType.Polygon)
  2058. {
  2059. //判断是否已存在多边形的点,不能移动多边形
  2060. if (!m_IsSelPolygonPoint)
  2061. {
  2062. if (this.Cursor == Cursors.SizeAll)
  2063. {
  2064. if (item.GPath.IsVisible(e.Location))
  2065. {
  2066. isChange = true;
  2067. MouseMovePolygonMeasureFucntion(item, e);
  2068. }
  2069. }
  2070. }
  2071. }
  2072. else
  2073. {
  2074. if (item.Region.Contains(e.Location))
  2075. {
  2076. isChange = true;
  2077. MouseMoveMeasureFucntion(item, e);
  2078. }
  2079. }
  2080. }
  2081. }
  2082. }
  2083. }
  2084. }
  2085. //移动样品台
  2086. if (m_IsSelectSampleStage)
  2087. {
  2088. if (m_IsCtrl)
  2089. {
  2090. return;
  2091. }
  2092. if (m_IsAlt)
  2093. {
  2094. return;
  2095. }
  2096. //样品台
  2097. MouseMoveFucntion(m_RectangleGDIObjects, e);
  2098. //样品孔
  2099. MouseMoveFucntion(m_SampleHoleGDIObjects, e);
  2100. //样品
  2101. MouseMoveFucntion(m_SampleGDIObjects, e);
  2102. //标样
  2103. MouseMoveFucntion(m_SpecimenGDIObjects, e);
  2104. //测量
  2105. MouseMoveFucntion(m_MeasureGDIObjects, e);
  2106. //文字
  2107. MouseMoveFucntion(m_ContentGDIObjects, e);
  2108. //帧图
  2109. if (m_SingleGDIObjects.Count > 0)
  2110. {
  2111. MouseMoveSingleFucntion(m_SingleGDIObjects, e);
  2112. string sampleName = m_SingleGDIObjects[0].SampleName;
  2113. }
  2114. //样品孔BSE图片
  2115. MouseMoveSingleFucntion(m_ImageGDIObjects, e);
  2116. //计算两个点之间的距离 移动样品台后与绘制样品台时的位置
  2117. m_DifferentPoint = OTSSamplespaceGraphicsPanelFun.StartToEndPointDist(m_RectangleGDIObjects[0], m_RegionStartCenterPoint);
  2118. }
  2119. }
  2120. //显示XY轴
  2121. OTSSamplespaceGraphicsPanelFun.ShowSemCoordvAL(e.Location, m_MeasureAppForm, m_RectangleGDIObjects, m_OTSSampleStageData, IsWidth);
  2122. Invalidate();
  2123. foreach (var item in m_MeasureGDIObjects)
  2124. {
  2125. if (item.CreateType == (int)CreateRectangleType.Polygon)
  2126. {
  2127. if (m_IsSelPolygonPoint)
  2128. {
  2129. InMeasure = true;
  2130. }
  2131. }
  2132. if (item.Region.Contains(e.Location))
  2133. {
  2134. InMeasure = true;
  2135. }
  2136. }
  2137. if (!InMeasure)
  2138. {
  2139. //this.Cursor = Cursors.Default;
  2140. }
  2141. }
  2142. bool isChange = false;
  2143. protected override void OnMouseUp(MouseEventArgs e)
  2144. {
  2145. //判断当前是否手绘
  2146. if (m_IsDrawMeasure)
  2147. {
  2148. //获取当前的鼠标点击位置
  2149. this.m_MouseUpPoint = new Point(e.X, e.Y);
  2150. //绘制多边形
  2151. if (m_DrawMeasureType != (int)CreateRectangleType.Polygon && m_DrawMeasureType != (int)CreateRectangleType.CircleByThreePoints)
  2152. {
  2153. foreach (var item in m_DrawMeasureGDIObjects)
  2154. {
  2155. for (int i = 0; i < m_MeasureGDIObjects.Count; i++)
  2156. {
  2157. if (item.SampleName == m_MeasureGDIObjects[i].SampleName)
  2158. {
  2159. //获取样品孔名称与其他属性
  2160. item.Name = m_MeasureGDIObjects[i].Name;
  2161. item.IsSingle = m_MeasureGDIObjects[i].IsSingle;
  2162. item.IsWorkSample = m_MeasureGDIObjects[i].IsWorkSample;
  2163. //删除存在的帧图
  2164. for (int singleIndex = m_SingleGDIObjects.Count - 1; singleIndex >= 0; singleIndex--)
  2165. {
  2166. if (m_SingleGDIObjects[singleIndex].SampleName == item.SampleName)
  2167. {
  2168. m_SingleGDIObjects.RemoveAt(singleIndex);
  2169. }
  2170. }
  2171. m_MeasureGDIObjects[i] = item;
  2172. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(item, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  2173. {
  2174. m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;
  2175. CMeasureThreadWrapper.DoRunType = (int)MSR_THREAD_RunSTATUS.RUNMEASURE;
  2176. showSingleInfo();
  2177. break;
  2178. }
  2179. }
  2180. }
  2181. }
  2182. //清空绘制测量区域
  2183. if (m_DrawMeasureGDIObjects.Count > 0)
  2184. {
  2185. m_DrawMeasureGDIObjects.Clear();
  2186. }
  2187. this.Cursor = Cursors.Default;
  2188. //设置手绘标识
  2189. m_IsDrawMeasureReady = false;
  2190. m_IsDrawMeasure = false;
  2191. }
  2192. }
  2193. //如果正在进行测量线程,则退出鼠标点击操作
  2194. if (m_MeasureAppForm.MeasureThreadRunFlag)
  2195. {
  2196. return;
  2197. }
  2198. //是否移动至新样品孔
  2199. int IsContains = 0;
  2200. string HoleName = string.Empty;
  2201. //如果没有选择样品台
  2202. if (!m_IsSelectSampleStage)
  2203. {
  2204. //根据选择工作样品的测量状态,控制操作
  2205. if (selWSampleMeasureStatus)
  2206. {
  2207. return;
  2208. }
  2209. if (isChange)
  2210. {
  2211. if (m_RectangleGDIObjects == null)
  2212. {
  2213. return;
  2214. }
  2215. foreach (var measureItem in m_MeasureGDIObjects)
  2216. {
  2217. if (measureItem.IsWorkSample)
  2218. {
  2219. if (measureItem.Region.Contains(e.Location))
  2220. {
  2221. if (isChange == false)
  2222. {
  2223. isChange = true;
  2224. }
  2225. }
  2226. //保存原位置
  2227. Rectangle rectPara = measureItem.Region;
  2228. #region 测量区域与样品中心相差的距离
  2229. foreach (var itemSample in m_SampleGDIObjects)
  2230. {
  2231. if (itemSample.SampleName == measureItem.SampleName)
  2232. {
  2233. measureItem.SampleCenterDifferCenterPoint = OTSSamplespaceGraphicsPanelFun.GetSampleCenterDifferCenterPoint(rectPara, itemSample.Region);
  2234. break;
  2235. }
  2236. }
  2237. #endregion
  2238. //获取修改后的测量区域的位置与尺寸
  2239. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(measureItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  2240. {
  2241. //设置图形位置与大小
  2242. measureItem.Region = rectPara;
  2243. //重新绘制测量区域路径
  2244. OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(measureItem, rectPara);
  2245. //恢复光标
  2246. this.Cursor = System.Windows.Forms.Cursors.Default;
  2247. foreach (ARectangleGDIObject item in m_RectangleGDIObjects)
  2248. {
  2249. if (item.Region.Contains(e.Location))
  2250. {
  2251. m_IsSelectSampleStage = true;
  2252. }
  2253. else
  2254. {
  2255. m_IsSelectSampleStage = false;
  2256. }
  2257. }
  2258. }
  2259. break;
  2260. }
  2261. }
  2262. if (isChange)
  2263. {
  2264. //设置颜色
  2265. if (m_SingleGDIObjects.Count > 0)
  2266. {
  2267. for (int i = 0; i < m_SingleGDIObjects.Count; i++)
  2268. {
  2269. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SingleColor);
  2270. m_SingleGDIObjects[i].SelColor = ColorTranslator.FromHtml(ColorStr);
  2271. }
  2272. }
  2273. //切换至测量模式
  2274. m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;
  2275. CMeasureThreadWrapper.DoRunType = (int)MSR_THREAD_RunSTATUS.RUNMEASURE;
  2276. showSingleInfo();
  2277. }
  2278. foreach (ARectangleGDIObject item in m_SampleGDIObjects)
  2279. {
  2280. //判断鼠标是否在样品中
  2281. if (item.Region.Contains(e.Location))
  2282. {
  2283. if (item.IsWorkSample)
  2284. {
  2285. //获取原样品孔名称
  2286. HoleName = item.Name;
  2287. foreach (ARectangleGDIObject sampleHoleItem in m_SampleHoleGDIObjects)
  2288. {
  2289. //获取样品孔中心点
  2290. Point sampleHoleCenterPoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(sampleHoleItem);
  2291. //移动的样品在样品孔中心时
  2292. if (item.Region.Contains(sampleHoleCenterPoint))
  2293. {
  2294. if (item.Name != sampleHoleItem.Name)
  2295. {
  2296. sampleHoleItem.SampleCount += 1;
  2297. //样品孔信息
  2298. item.Name = sampleHoleItem.Name;
  2299. //样品Rectangle
  2300. item.Region = sampleHoleItem.Region;
  2301. item.RegionF = sampleHoleItem.RegionF;
  2302. item.DrawRegionF = sampleHoleItem.DrawRegionF;
  2303. IsContains++;
  2304. foreach (var sampleHoleCountItem in m_SampleHoleGDIObjects)
  2305. {
  2306. if (HoleName != string.Empty)
  2307. {
  2308. if (sampleHoleCountItem.Name == HoleName)
  2309. {
  2310. //减少样品数量
  2311. sampleHoleCountItem.SampleCount -= 1;
  2312. }
  2313. }
  2314. }
  2315. }
  2316. }
  2317. }
  2318. //获取工作样品中的测量区域
  2319. foreach (ARectangleGDIObject measureItem in m_MeasureGDIObjects)
  2320. {
  2321. if (item.SampleName == measureItem.SampleName)
  2322. {
  2323. //设置样品与样品孔名称
  2324. measureItem.Name = item.Name;
  2325. measureItem.SampleName = item.SampleName;
  2326. Rectangle rectPara = item.Region;
  2327. RectangleF rectParaF = item.RegionF;
  2328. if (m_IsMoveSample)
  2329. {
  2330. #region 样品移动至其他样品台后 修改测量区域位置
  2331. rectPara.X = item.Region.X - m_MeasureToSamplePoint.X;
  2332. rectPara.Y = item.Region.Y - m_MeasureToSamplePoint.Y;
  2333. rectPara.Width = measureItem.Region.Width;
  2334. rectPara.Height = measureItem.Region.Height;
  2335. rectParaF.X = rectPara.X / m_GlobalZoomNum;
  2336. rectParaF.Y = rectPara.Y / m_GlobalZoomNum;
  2337. rectParaF.Width = measureItem.RegionF.Width;
  2338. rectParaF.Height = measureItem.RegionF.Height;
  2339. //判断移动到其他样品孔后、当前测量区域是否超越样品台边缘
  2340. int CheckShape = measureItem.Shape;
  2341. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectPara, m_RectangleGDIObjects[0].Region, CheckShape))
  2342. {
  2343. measureItem.Region = rectPara;
  2344. measureItem.RegionF = rectParaF;
  2345. measureItem.DrawRegionF = rectParaF;
  2346. }
  2347. #endregion
  2348. }
  2349. //测量区域与样品中心相差的距离
  2350. measureItem.SampleCenterDifferCenterPoint = OTSSamplespaceGraphicsPanelFun.GetSampleCenterDifferCenterPoint(rectPara, measureItem.Region);
  2351. //获取修改后的测量区域的位置与尺寸
  2352. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(measureItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  2353. {
  2354. //设置测量区域信息
  2355. measureItem.SampleName = item.SampleName;
  2356. measureItem.Name = item.Name;
  2357. //将所有帧图移动测量区域位置中
  2358. //获取样品孔 与 样品名称
  2359. foreach (var SampleItem in m_SampleGDIObjects)
  2360. {
  2361. if (item.IsWorkSample)
  2362. {
  2363. //设置工作样品的测量区域 存在帧图
  2364. foreach (var MeasureItem in m_MeasureGDIObjects)
  2365. {
  2366. if (MeasureItem.SampleName == item.SampleName)
  2367. {
  2368. //设置工作样品的测量区域 存在帧图标识
  2369. if (m_SingleGDIObjects.Count > 0)
  2370. {
  2371. OTSSamplespaceGraphicsPanelFun.SetSingleLocationToMeasureLocation(m_SingleGDIObjects, MeasureItem);
  2372. }
  2373. }
  2374. }
  2375. }
  2376. }
  2377. //更新Grid 工作样品属性值
  2378. m_MeasureAppForm.UpdateTreeSampleAndGridSampleVal();
  2379. Invalidate();
  2380. break;
  2381. }
  2382. }
  2383. }
  2384. }
  2385. }
  2386. if (item.IsWorkSample)
  2387. {
  2388. //设置颜色
  2389. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  2390. item.SelColor = ColorTranslator.FromHtml(ColorStr);
  2391. }
  2392. }
  2393. isChange = false;
  2394. }
  2395. //移动多边形的点后,显示已获取的帧图
  2396. if (m_IsSelPolygonPoint)
  2397. {
  2398. foreach (var measureItem in m_MeasureGDIObjects)
  2399. {
  2400. if (measureItem.IsWorkSample)
  2401. {
  2402. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(measureItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  2403. {
  2404. if (measureItem.IsSingle)
  2405. {
  2406. showSingleInfo();
  2407. }
  2408. }
  2409. }
  2410. }
  2411. }
  2412. Invalidate();
  2413. }
  2414. //样品台
  2415. MouseUpFucntion(m_RectangleGDIObjects, e);
  2416. //样品
  2417. MouseUpFucntion(m_SampleGDIObjects, e);
  2418. //样品孔
  2419. MouseUpFucntion(m_SampleHoleGDIObjects, e);
  2420. //标样
  2421. MouseUpFucntion(m_SpecimenGDIObjects, e);
  2422. //测量
  2423. MouseUpFucntion(m_MeasureGDIObjects, e);
  2424. //测量路径
  2425. MouseUpFucntion(m_MeasurePathGDIObjects, e);
  2426. //文字
  2427. MouseUpFucntion(m_ContentGDIObjects, e);
  2428. //帧图
  2429. MouseUpFucntion(m_SingleGDIObjects, e);
  2430. //已获取的帧图
  2431. MouseUpFucntion(m_ALLSingleGDIObjects, e);
  2432. //样品孔中BSE图片
  2433. MouseUpFucntion(m_ImageGDIObjects, e);
  2434. //SEM中心位置
  2435. MouseUpFucntion(m_SEMCenterGDIObjects, e);
  2436. //撤回原样品孔中
  2437. if (IsContains == 0)
  2438. {
  2439. foreach (var item in m_SampleGDIObjects)
  2440. {
  2441. //if (item.Region.Contains(e.Location))
  2442. //{
  2443. //鼠标按下事件中获取选择的样品原有位置
  2444. //如果没有找到其他样品孔的中心点,则将移动的样品设置为原位置
  2445. foreach (ARectangleGDIObject sampleHoleItems in m_SampleHoleGDIObjects)
  2446. {
  2447. if (sampleHoleItems.SampleCount > 0)
  2448. {
  2449. if (item.IsWorkSample)
  2450. {
  2451. //设置颜色
  2452. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  2453. item.SelColor = ColorTranslator.FromHtml(ColorStr);
  2454. if (selectSampleGDIObjects != null)
  2455. {
  2456. if (sampleHoleItems.Name == selectSampleGDIObjects.Name && item.SampleName == selectSampleGDIObjects.SampleName)
  2457. {
  2458. item.Region = sampleHoleItems.Region;
  2459. Invalidate();
  2460. break;
  2461. }
  2462. }
  2463. }
  2464. }
  2465. }
  2466. //}
  2467. //获取帧图与测量区域的相差的位置
  2468. int m_singleDiffX = 0;
  2469. int m_singleDiffY = 0;
  2470. //如果当前样品没有移动至其他样品孔 测量区域恢复原位置
  2471. if (m_IsMoveSample)
  2472. {
  2473. if (item.IsWorkSample)
  2474. {
  2475. foreach (var measureItem in m_MeasureGDIObjects)
  2476. {
  2477. if (measureItem.SampleName == item.SampleName)
  2478. {
  2479. //获取测量区域与样品之间相差的距离
  2480. if (m_SingleGDIObjects.Count > 0)
  2481. {
  2482. m_singleDiffX = measureItem.Region.X - item.Region.X + m_MeasureToSamplePoint.X;
  2483. m_singleDiffY = measureItem.Region.Y - item.Region.Y + m_MeasureToSamplePoint.Y;
  2484. }
  2485. RectangleF rectParaF = item.RegionF;
  2486. Rectangle rectPara = item.Region;
  2487. rectPara.X = item.Region.X - m_MeasureToSamplePoint.X;
  2488. rectPara.Y = item.Region.Y - m_MeasureToSamplePoint.Y;
  2489. rectPara.Width = measureItem.Region.Width;
  2490. rectPara.Height = measureItem.Region.Height;
  2491. measureItem.Region = rectPara;
  2492. rectParaF.X = rectPara.X / m_GlobalZoomNum;
  2493. rectParaF.Y = rectPara.Y / m_GlobalZoomNum;
  2494. rectParaF.Width = measureItem.RegionF.Width;
  2495. rectParaF.Height = measureItem.RegionF.Height;
  2496. measureItem.RegionF = rectParaF;
  2497. measureItem.DrawRegionF = rectParaF;
  2498. break;
  2499. }
  2500. }
  2501. //将帧图恢复至原位置
  2502. foreach (var singleItem in m_SingleGDIObjects)
  2503. {
  2504. if (singleItem.SampleName == item.SampleName)
  2505. {
  2506. RectangleF rectParaDrawF = singleItem.DrawRegionF;
  2507. RectangleF rectParaF = singleItem.RegionF;
  2508. Rectangle rectPara = singleItem.Region;
  2509. rectPara.X = singleItem.Region.X - m_singleDiffX;
  2510. rectPara.Y = singleItem.Region.Y - m_singleDiffY;
  2511. rectPara.Width = singleItem.Region.Width;
  2512. rectPara.Height = singleItem.Region.Height;
  2513. singleItem.Region = rectPara;
  2514. //更改帧图RegionF
  2515. rectParaF.X = singleItem.RegionF.X - m_singleDiffX;
  2516. rectParaF.Y = singleItem.RegionF.Y - m_singleDiffY;
  2517. singleItem.RegionF = rectParaF;
  2518. //更改帧图绘制原位置DrawRegionF
  2519. rectParaDrawF.X = (rectParaDrawF.X - m_singleDiffX / m_GlobalZoomNum);
  2520. rectParaDrawF.Y = (rectParaDrawF.Y - m_singleDiffY / m_GlobalZoomNum);
  2521. rectParaDrawF.Width = rectParaDrawF.Width;
  2522. rectParaDrawF.Height = rectParaDrawF.Height;
  2523. singleItem.DrawRegionF = rectParaDrawF;
  2524. }
  2525. }
  2526. //删除已添加的帧图信息、重新添加帧图信息
  2527. if (m_ALLSingleGDIObjects.Count > 0)
  2528. {
  2529. OTSSamplespaceGraphicsPanelFun.DeleteALLSingleInfo(m_ALLSingleGDIObjects, item.SampleName);
  2530. OTSSamplespaceGraphicsPanelFun.AddALLSingleInfo(m_ALLSingleGDIObjects, m_SingleGDIObjects, item.SampleName);
  2531. }
  2532. }
  2533. }
  2534. }
  2535. }
  2536. m_IsMoveSample = false;
  2537. m_MeasureToSamplePoint = new Point();
  2538. //计算两个点之间的距离 移动样品台后与绘制样品台时的位置
  2539. if (m_RectangleGDIObjects.Count > 0)
  2540. {
  2541. m_DifferentPoint = OTSSamplespaceGraphicsPanelFun.StartToEndPointDist(m_RectangleGDIObjects[0], m_RegionStartCenterPoint);
  2542. }
  2543. m_IsCtrl = false;
  2544. m_IsAlt = false;
  2545. m_IsSelPolygonPoint = false;
  2546. selWSampleMeasureStatus = false;
  2547. }
  2548. protected override void OnPaint(PaintEventArgs e)//处理重绘情况
  2549. {
  2550. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_RectangleGDIObjects);
  2551. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_SampleHoleGDIObjects);
  2552. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_SampleGDIObjects);
  2553. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_SpecimenGDIObjects);
  2554. //切换显示样品孔中的文字
  2555. if (IsShowSampleHoleFont)
  2556. {
  2557. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_ContentGDIObjects);
  2558. }
  2559. //切换显示样品孔中的BSE图片
  2560. if (IsShowSampleHoleImage)
  2561. {
  2562. if (m_ImageGDIObjects != null)
  2563. {
  2564. if (m_ImageGDIObjects.Count > 0)
  2565. {
  2566. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_ImageGDIObjects);
  2567. }
  2568. }
  2569. }
  2570. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_MeasurePathGDIObjects);
  2571. try
  2572. {
  2573. if (m_SingleGDIObjects != null)
  2574. {
  2575. if (m_SingleGDIObjects.Count > 0)
  2576. {
  2577. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_SingleGDIObjects);
  2578. }
  2579. }
  2580. }
  2581. catch (Exception)
  2582. {
  2583. }
  2584. //手动绘制测量区域
  2585. if (m_DrawMeasureGDIObjects != null)
  2586. {
  2587. if (m_DrawMeasureGDIObjects.Count > 0)
  2588. {
  2589. for (int i = 0; i < m_DrawMeasureGDIObjects.Count; i++)
  2590. {
  2591. if (m_DrawMeasureGDIObjects[i] != null)
  2592. {
  2593. m_DrawMeasureGDIObjects[i].EndPoint = this.m_MouseMovePoint;
  2594. m_DrawMeasureGDIObjects[i].OnPaint(e);
  2595. }
  2596. }
  2597. }
  2598. }
  2599. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_MeasureGDIObjects);
  2600. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_SEMCenterGDIObjects);
  2601. if (m_IsDrawPolygonFinish || m_IsSelPolygonPoint)
  2602. {
  2603. OTSSamplespaceGraphicsPanelFun.OnPaint(e, m_DrawPolygonFinishGDIObjects);
  2604. }
  2605. }
  2606. protected override void OnMouseWheel(MouseEventArgs e)
  2607. {
  2608. //如果正在进行测量线程,则退出鼠标点击操作
  2609. if (m_MeasureAppForm.MeasureThreadRunFlag)
  2610. {
  2611. return;
  2612. }
  2613. base.OnMouseWheel(e);
  2614. //设置记录每次比例缩放后的总体比例系数
  2615. if (e.Delta > 0)
  2616. {
  2617. m_GlobalZoomNum += 0.1f;
  2618. }
  2619. else
  2620. {
  2621. m_GlobalZoomNum -= 0.1f;
  2622. if (m_GlobalZoomNum < 1)
  2623. {
  2624. m_GlobalZoomNum = 1;
  2625. }
  2626. }
  2627. if (e.Delta > 0)
  2628. {
  2629. #region //图形缩放计算部份-------放大------------//是放大
  2630. f_widthandheight_js = f_zoom_increment;
  2631. f_zoom_record = f_zoom_record + f_zoom_increment;
  2632. f_zoom_record = float.Parse(f_zoom_record.ToString("#0.0")); //四舍五入,保留一位小数,如果不这样,float会不附合规则
  2633. #endregion
  2634. #region 计算标尺尺寸部份-----放大------
  2635. //计算标尺实际占用像素的宽度
  2636. f_ruler_size = f_ruler_size + Convert.ToInt32(f_old_ruler_size * f_zoom_increment);
  2637. control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);
  2638. //显示该像素宽度代表的实际宽度
  2639. control_Ruler2.SetValueInspector(f_ruler_size, ((Convert.ToDouble(m_OTSSampleStageData.StageDomain.Width) / 54f) / 10));
  2640. //放大过长时,这里将宽度与代表的实际宽度进行折半显示
  2641. if (control_Ruler2.RulerWidth > 200)
  2642. {
  2643. control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size) / 2;
  2644. }
  2645. #endregion
  2646. }
  2647. else
  2648. {
  2649. if (f_zoom_record >= f_zoom_mix)
  2650. {
  2651. #region //图形缩放计算部份------缩小--------------------
  2652. f_widthandheight_js = -f_zoom_increment;
  2653. f_zoom_record = f_zoom_record - f_zoom_increment;
  2654. f_zoom_record = float.Parse(f_zoom_record.ToString("#0.0")); //四舍五入,保留一位小数,如果不这样,float会不附合规则
  2655. #endregion
  2656. #region 计算标尺尺寸部份-----缩小------f_onepixel_size,是不是该乘以rulerwidth是实际的长度
  2657. f_ruler_size = f_ruler_size + Convert.ToInt32(f_old_ruler_size * -f_zoom_increment);
  2658. control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);
  2659. control_Ruler2.SetValueInspector(f_ruler_size, ((Convert.ToDouble(m_OTSSampleStageData.StageDomain.Width) / Convert.ToDouble(54)) / 10));
  2660. if (control_Ruler2.RulerWidth > 200)
  2661. {
  2662. control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size) / 2;
  2663. }
  2664. #endregion
  2665. }
  2666. }
  2667. if (m_GlobalZoomNum >= 1)
  2668. {
  2669. if (m_RectangleGDIObjects.Count > 0)
  2670. {
  2671. //恢复图像初始位置
  2672. OTSSamplespaceGraphicsPanelFun.RecoverInitialPosition(m_SingleGDIObjects, m_GlobalZoomNum);
  2673. OTSSamplespaceGraphicsPanelFun.RecoverInitialPosition(m_ALLSingleGDIObjects, m_GlobalZoomNum);
  2674. OTSSamplespaceGraphicsPanelFun.RecoverInitialPosition(m_ImageGDIObjects, m_GlobalZoomNum);
  2675. //样品
  2676. OTSSamplespaceGraphicsPanelFun.MouseWheelFunction(m_SampleGDIObjects, m_RectangleGDIObjects[0], m_GlobalZoomNum);
  2677. //样品孔
  2678. OTSSamplespaceGraphicsPanelFun.MouseWheelFunction(m_SampleHoleGDIObjects, m_RectangleGDIObjects[0], m_GlobalZoomNum);
  2679. //标样
  2680. OTSSamplespaceGraphicsPanelFun.MouseWheelFunction(m_SpecimenGDIObjects, m_RectangleGDIObjects[0], m_GlobalZoomNum);
  2681. //测量区域
  2682. OTSSamplespaceGraphicsPanelFun.MouseWheelFunction(m_MeasureGDIObjects, m_RectangleGDIObjects[0], m_GlobalZoomNum);
  2683. //文字
  2684. OTSSamplespaceGraphicsPanelFun.MouseWheelFunction(m_ContentGDIObjects, m_RectangleGDIObjects[0], m_GlobalZoomNum);
  2685. //样品台
  2686. OTSSamplespaceGraphicsPanelFun.MouseWheelFunction(m_RectangleGDIObjects, m_RectangleGDIObjects[0], m_GlobalZoomNum);
  2687. if (m_GlobalZoomNum == 1)
  2688. {
  2689. // 将绘制的样品台信息 按屏幕中心移动
  2690. //获取当前样品台中心点
  2691. Point samplePoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(m_RectangleGDIObjects[0].Region);
  2692. //获取当前工作区域中心点
  2693. Point workAreaPoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(this.ClientRectangle);
  2694. //计算样品台中心点与工作区域中心点相差的距离
  2695. PointF distancePoint = new PointF(samplePoint.X - workAreaPoint.X, samplePoint.Y - workAreaPoint.Y);
  2696. if (distancePoint.X != 0 || distancePoint.Y != 0)
  2697. {
  2698. MoveToSrceenCenterFunction(distancePoint);
  2699. }
  2700. //标尺恢复初始
  2701. f_ruler_size = f_old_ruler_size;
  2702. control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);
  2703. control_Ruler2.ShowString = "1000um";
  2704. control_Ruler2.SetValueInspector(110, ((Convert.ToDouble(m_OTSSampleStageData.StageDomain.Width) / Convert.ToDouble(54)) / 10));
  2705. }
  2706. //重新绘制
  2707. Invalidate();
  2708. }
  2709. }
  2710. }
  2711. #endregion
  2712. #region 鼠标方法操作
  2713. public void MouseDownFucntion(List<ARectangleGDIObject> objList, MouseEventArgs e)
  2714. {
  2715. foreach (ARectangleGDIObject item in objList)
  2716. {
  2717. item.IsDragging = true;
  2718. item.DraggingPoint = e.Location;
  2719. }
  2720. }
  2721. public void MouseMoveFucntion(List<ARectangleGDIObject> objList, MouseEventArgs e)
  2722. {
  2723. foreach (ARectangleGDIObject item in objList)
  2724. {
  2725. if (item.IsDragging)
  2726. {
  2727. item.Region = new Rectangle(
  2728. item.Region.Left + Convert.ToInt32((e.X - item.DraggingPoint.X)),
  2729. item.Region.Top + Convert.ToInt32((e.Y - item.DraggingPoint.Y)),
  2730. item.Region.Width,
  2731. item.Region.Height);
  2732. item.RegionF = new RectangleF(
  2733. item.RegionF.Left + (float)(e.X - item.DraggingPoint.X) / m_GlobalZoomNum,
  2734. item.RegionF.Top + (float)(e.Y - item.DraggingPoint.Y) / m_GlobalZoomNum,
  2735. item.RegionF.Width,
  2736. item.RegionF.Height);
  2737. item.DrawRegionF = new RectangleF(
  2738. item.DrawRegionF.Left + (float)(e.X - item.DraggingPoint.X),
  2739. item.DrawRegionF.Top + (float)(e.Y - item.DraggingPoint.Y),
  2740. item.DrawRegionF.Width,
  2741. item.DrawRegionF.Height);
  2742. item.LineStartPoint = new PointF(
  2743. item.Region.Left + (e.X - item.DraggingPoint.X),
  2744. item.Region.Top + (e.Y - item.DraggingPoint.Y));
  2745. item.BSEImageLocation = new PointF(
  2746. item.BSEImageLocation.X + e.X - item.DraggingPoint.X,
  2747. item.BSEImageLocation.Y + e.Y - item.DraggingPoint.Y);
  2748. //移动SEM中心点位置
  2749. item.SEMCenterPoint = new PointF(
  2750. item.SEMCenterPoint.X + (e.X - item.DraggingPoint.X),
  2751. item.SEMCenterPoint.Y + (e.Y - item.DraggingPoint.Y));
  2752. //多边形样品台移动
  2753. if (item.Shape == (int)CreateRectangleType.Polygon)
  2754. {
  2755. if (item.DrawPolygonPointRegionF != null)
  2756. {
  2757. if (item.DrawPolygonPointRegionF.Count > 0)
  2758. {
  2759. int polygonPointCount = item.DrawPolygonPointRegionF.Count;
  2760. if (polygonPointCount > 0)
  2761. {
  2762. for (int pointIndex = 0; pointIndex < polygonPointCount; pointIndex++)
  2763. {
  2764. item.PolygonPointRegion[pointIndex] = new Point(
  2765. item.PolygonPointRegion[pointIndex].X + Convert.ToInt32((e.X - item.DraggingPoint.X)),
  2766. item.PolygonPointRegion[pointIndex].Y + Convert.ToInt32((e.Y - item.DraggingPoint.Y)));
  2767. item.PolygonPointRegionF[pointIndex] = new PointF(
  2768. item.PolygonPointRegionF[pointIndex].X + (float)(e.X - item.DraggingPoint.X),
  2769. item.PolygonPointRegionF[pointIndex].Y + (float)(e.Y - item.DraggingPoint.Y));
  2770. //2020-12-1日注释
  2771. item.DrawPolygonPointRegionF[pointIndex] = new PointF(
  2772. item.DrawPolygonPointRegionF[pointIndex].X + (float)(e.X - item.DraggingPoint.X) / m_GlobalZoomNum,
  2773. item.DrawPolygonPointRegionF[pointIndex].Y + (float)(e.Y - item.DraggingPoint.Y) / m_GlobalZoomNum);
  2774. }
  2775. }
  2776. }
  2777. }
  2778. }
  2779. item.DraggingPoint = e.Location;
  2780. //重新绘制测量区域路径
  2781. OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(item, item.Region);
  2782. }
  2783. }
  2784. }
  2785. public void MouseMoveMeasureFucntion(ARectangleGDIObject item, MouseEventArgs e)
  2786. {
  2787. //判断移动的样品 是否在样品台尺寸范围内
  2788. Rectangle rectTemp = item.Region;
  2789. rectTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;
  2790. rectTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;
  2791. int CheckShape = (int)CreateRectangleType.Circle;
  2792. if (m_RectangleGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  2793. {
  2794. CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;
  2795. }
  2796. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  2797. {
  2798. #region 需抽出作为公共方法
  2799. int xMove = rectTemp.X - item.Region.X;
  2800. int yMove = rectTemp.Y - item.Region.Y;
  2801. int Width = rectTemp.Width - item.Region.Width;
  2802. int Height = rectTemp.Height - item.Region.Height;
  2803. //设置图形大小
  2804. item.Region = rectTemp;
  2805. int WidthNew = (int)((item.RegionF.Width + Width / m_GlobalZoomNum));
  2806. int HeightNew = (int)((item.RegionF.Height + Height / m_GlobalZoomNum));
  2807. //设置原测量区域图形大小
  2808. float xMoveNew = (float)((item.RegionF.X + (xMove / m_GlobalZoomNum)));
  2809. float yMoveNew = (float)((item.RegionF.Y + (yMove / m_GlobalZoomNum)));
  2810. item.RegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));
  2811. item.DrawRegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));
  2812. item.DraggingPoint = e.Location;
  2813. #endregion
  2814. //重新绘制测量区域路径
  2815. OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(item, item.Region);
  2816. //帧图
  2817. MouseMoveSingleFucntion(m_SingleGDIObjects, e);
  2818. Invalidate();
  2819. return;
  2820. }
  2821. }
  2822. public void MouseMovePolygonMeasureFucntion(ARectangleGDIObject item, MouseEventArgs e)
  2823. {
  2824. //多边形样品台移动
  2825. if (item.Shape == (int)CreateRectangleType.Polygon)
  2826. {
  2827. //判断样品台形状
  2828. int CheckShape = (int)CreateRectangleType.Circle;
  2829. if (m_RectangleGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  2830. {
  2831. CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;
  2832. }
  2833. //生成多边形最小面积外接矩形
  2834. Rectangle rectMeasureTemp = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(item.PolygonPointRegionF);
  2835. //判断多边形是否超越样品台
  2836. rectMeasureTemp.X = rectMeasureTemp.Left + e.X - item.DraggingPoint.X;
  2837. rectMeasureTemp.Y = rectMeasureTemp.Top + e.Y - item.DraggingPoint.Y;
  2838. if (OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectMeasureTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  2839. {
  2840. int polygonPointCount = item.DrawPolygonPointRegionF.Count;
  2841. if (polygonPointCount > 0)
  2842. {
  2843. for (int pointIndex = 0; pointIndex < polygonPointCount; pointIndex++)
  2844. {
  2845. item.PolygonPointRegion[pointIndex] = new Point(
  2846. item.PolygonPointRegion[pointIndex].X + Convert.ToInt32((e.X - item.DraggingPoint.X)),
  2847. item.PolygonPointRegion[pointIndex].Y + Convert.ToInt32((e.Y - item.DraggingPoint.Y)));
  2848. item.PolygonPointRegionF[pointIndex] = new PointF(
  2849. item.PolygonPointRegionF[pointIndex].X + (float)(e.X - item.DraggingPoint.X),
  2850. item.PolygonPointRegionF[pointIndex].Y + (float)(e.Y - item.DraggingPoint.Y));
  2851. item.DrawPolygonPointRegionF[pointIndex] = new PointF(
  2852. item.DrawPolygonPointRegionF[pointIndex].X + (float)(e.X - item.DraggingPoint.X) / m_GlobalZoomNum,
  2853. item.DrawPolygonPointRegionF[pointIndex].Y + (float)(e.Y - item.DraggingPoint.Y) / m_GlobalZoomNum);
  2854. }
  2855. Rectangle rectTemp = item.Region;
  2856. rectTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;
  2857. rectTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;
  2858. #region 需抽出作为公共方法
  2859. int xMove = rectTemp.X - item.Region.X;
  2860. int yMove = rectTemp.Y - item.Region.Y;
  2861. int Width = rectTemp.Width - item.Region.Width;
  2862. int Height = rectTemp.Height - item.Region.Height;
  2863. //设置图形大小
  2864. item.Region = rectTemp;
  2865. int WidthNew = (int)((item.RegionF.Width + Width / m_GlobalZoomNum));
  2866. int HeightNew = (int)((item.RegionF.Height + Height / m_GlobalZoomNum));
  2867. //设置原测量区域图形大小
  2868. float xMoveNew = (float)((item.RegionF.X + (xMove / m_GlobalZoomNum)));
  2869. float yMoveNew = (float)((item.RegionF.Y + (yMove / m_GlobalZoomNum)));
  2870. //item.Region = new Rectangle(new Point((int)xMoveNew, (int)yMoveNew), new Size(WidthNew, HeightNew));
  2871. item.RegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));
  2872. item.DrawRegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));
  2873. item.DraggingPoint = e.Location;
  2874. #endregion
  2875. ////生成多边形最小面积外接矩形
  2876. //Rectangle rectPolygonMeasure = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(item.PolygonPointRegionF);
  2877. //item.Region = rectPolygonMeasure;
  2878. //item.RegionF = rectPolygonMeasure;
  2879. //item.DrawRegionF = rectPolygonMeasure;
  2880. }
  2881. item.DraggingPoint = e.Location;
  2882. //重新绘制测量区域路径
  2883. OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(item, item.Region);
  2884. //帧图
  2885. MouseMoveSingleFucntion(m_SingleGDIObjects, e);
  2886. }
  2887. }
  2888. Invalidate();
  2889. return;
  2890. }
  2891. public bool MoveMeasureInStage(ARectangleGDIObject item, Point m_StageCenterPoint, Point semLocation, double m_GlobalZoomNum)
  2892. {
  2893. //判断测量区域移动到SEM的当前位置 是否在样品台尺寸范围内
  2894. Rectangle rectTemp = item.Region;
  2895. rectTemp.X = m_StageCenterPoint.X + semLocation.X;// - rectTemp.Width / 2;
  2896. rectTemp.Y = m_StageCenterPoint.Y - semLocation.Y;// - rectTemp.Height/ 2;
  2897. rectTemp.Width = 2;
  2898. rectTemp.Height = 2;
  2899. int CheckShape = (int)CreateRectangleType.Circle;
  2900. if (m_RectangleGDIObjects[0].Shape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  2901. {
  2902. CheckShape = (int)CreateRectangleType.SampleBackGround_Rectangle;
  2903. }
  2904. if (!OTSSamplespaceGraphicsPanelFun.CheckMeasureAreaIsBeyondStageArea(rectTemp, m_RectangleGDIObjects[0].Region, CheckShape))
  2905. {
  2906. return false;
  2907. }
  2908. return true;
  2909. }
  2910. public void MouseMoveSingleFucntion(List<ARectangleGDIObject> objList, MouseEventArgs e)
  2911. {
  2912. foreach (ARectangleGDIObject item in objList)
  2913. {
  2914. if (item.IsDragging)
  2915. {
  2916. item.Region = new Rectangle(
  2917. item.Region.Left + e.X - item.DraggingPoint.X,
  2918. item.Region.Top + e.Y - item.DraggingPoint.Y,
  2919. item.Region.Width,
  2920. item.Region.Height);
  2921. item.RegionF = new RectangleF(
  2922. item.RegionF.Left + (e.X - item.DraggingPoint.X),
  2923. item.RegionF.Top + (e.Y - item.DraggingPoint.Y),
  2924. item.RegionF.Width,
  2925. item.RegionF.Height);
  2926. item.DrawRegionF = new RectangleF(
  2927. item.DrawRegionF.Left + (e.X - item.DraggingPoint.X) / m_GlobalZoomNum,
  2928. item.DrawRegionF.Top + (e.Y - item.DraggingPoint.Y) / m_GlobalZoomNum,
  2929. item.DrawRegionF.Width,
  2930. item.DrawRegionF.Height);
  2931. item.LineStartPoint = new PointF(
  2932. item.Region.Left + (e.X - item.DraggingPoint.X),
  2933. item.Region.Top + (e.Y - item.DraggingPoint.Y));
  2934. item.DraggingPoint = e.Location;
  2935. //重新绘制测量区域路径
  2936. OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(item, item.Region);
  2937. }
  2938. }
  2939. }
  2940. public void MouseUpFucntion(List<ARectangleGDIObject> objList, MouseEventArgs e)
  2941. {
  2942. foreach (ARectangleGDIObject item in objList)
  2943. {
  2944. if (item.IsDragging)
  2945. {
  2946. item.IsSelect = false;
  2947. item.IsDragging = false;
  2948. item.DraggingPoint = Point.Empty;
  2949. //item.IsWorkSample = false;
  2950. }
  2951. }
  2952. }
  2953. public void SizeChangeFucntion(List<ARectangleGDIObject> objList, float Zoom)
  2954. {
  2955. foreach (ARectangleGDIObject item in objList)
  2956. {
  2957. float x = item.RegionF.X * Zoom;
  2958. float y = item.RegionF.Y * Zoom;
  2959. float widthRect = item.RegionF.Width * Zoom;
  2960. float heightRect = item.RegionF.Height * Zoom;
  2961. //改变窗体时,修改图形位置与大小
  2962. item.Region = new Rectangle((int)x, (int)y, (int)widthRect, (int)heightRect);
  2963. item.RegionF = new RectangleF(x, y, widthRect, heightRect);
  2964. item.DrawRegionF = new RectangleF(x, y, widthRect, heightRect);
  2965. }
  2966. }
  2967. public void SizeFChangeFucntion(List<ARectangleGDIObject> objList, float Zoom)
  2968. {
  2969. foreach (ARectangleGDIObject item in objList)
  2970. {
  2971. float x = item.DrawRegionF.X * Zoom;
  2972. float y = item.DrawRegionF.Y * Zoom;
  2973. float widthRect = item.DrawRegionF.Width * Zoom;
  2974. float heightRect = item.DrawRegionF.Height * Zoom;
  2975. //改变窗体时,修改图形位置与大小
  2976. item.Region = new Rectangle((int)x, (int)y, (int)widthRect, (int)heightRect);
  2977. item.RegionF = new RectangleF(x, y, widthRect, heightRect);
  2978. item.DrawRegionF = new RectangleF(x, y, widthRect, heightRect);
  2979. }
  2980. }
  2981. /// <summary>
  2982. /// 将绘制的样品台信息 按屏幕中心移动
  2983. /// </summary>
  2984. public void MoveToSrceenCenterFunction(PointF distancePoint)
  2985. {
  2986. if (distancePoint.X != 0 || distancePoint.Y != 0)
  2987. {
  2988. //循环样品台上的图形,将其按工作区域中心点移动
  2989. MoveLocationToSrceenCenterFunction(m_RectangleGDIObjects, distancePoint);
  2990. MoveLocationToSrceenCenterFunction(m_SampleHoleGDIObjects, distancePoint);
  2991. MoveLocationToSrceenCenterFunction(m_SampleGDIObjects, distancePoint);
  2992. MoveLocationToSrceenCenterFunction(m_SpecimenGDIObjects, distancePoint);
  2993. MoveLocationToSrceenCenterFunction(m_ContentGDIObjects, distancePoint);
  2994. MoveLocationToSrceenCenterFunction(m_MeasureGDIObjects, distancePoint);
  2995. MoveLocationToSrceenCenterFunction(m_MeasurePathGDIObjects, distancePoint);
  2996. MoveLocationToSrceenCenterFunction(m_SingleGDIObjects, distancePoint);
  2997. MoveLocationToSrceenCenterFunction(m_ImageGDIObjects, distancePoint);
  2998. }
  2999. }
  3000. public void MoveLocationToSrceenCenterFunction(List<ARectangleGDIObject> objList, PointF distancePoint)
  3001. {
  3002. foreach (var item in objList)
  3003. {
  3004. if (item.Shape == (int)CreateRectangleType.Polygon)
  3005. {
  3006. for (int i = 0; i < item.PolygonPointRegion.Count; i++)
  3007. {
  3008. item.PolygonPointRegion[i] = new Point((int)(item.PolygonPointRegion[i].X - distancePoint.X), (int)(item.PolygonPointRegion[i].Y - distancePoint.Y));
  3009. item.PolygonPointRegionF[i] = new PointF(item.PolygonPointRegionF[i].X - distancePoint.X, (item.PolygonPointRegionF[i].Y - distancePoint.Y));
  3010. item.DrawPolygonPointRegionF[i] = new PointF(item.DrawPolygonPointRegionF[i].X - distancePoint.X, (item.DrawPolygonPointRegionF[i].Y - distancePoint.Y));
  3011. }
  3012. }
  3013. item.Region = new Rectangle((int)((item.Region.X - distancePoint.X)), (int)(item.Region.Y - distancePoint.Y), item.Region.Width, item.Region.Height);
  3014. item.RegionF = new RectangleF((item.RegionF.X - distancePoint.X), (item.RegionF.Y - distancePoint.Y), item.RegionF.Width, item.RegionF.Height);
  3015. item.DrawRegionF = new RectangleF((item.DrawRegionF.X - distancePoint.X), (item.DrawRegionF.Y - distancePoint.Y), item.DrawRegionF.Width, item.DrawRegionF.Height);
  3016. item.BSEImageWitdh = item.Region.Width;
  3017. item.BSEImageHeight = item.Region.Height;
  3018. item.BSEImageLocation = item.Region.Location;
  3019. //重新绘制测量区域路径
  3020. OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(item, item.Region);
  3021. }
  3022. }
  3023. #endregion
  3024. #region 菜单操作
  3025. private void CMStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  3026. {
  3027. Point mousePoint = this.PointToClient(Control.MousePosition);
  3028. CMStrip.Hide();
  3029. switch (e.ClickedItem.Name)
  3030. {
  3031. case "AddStage":
  3032. m_MeasureAppForm.m_SPropertyWindows.TSSaveAs.Enabled = true;
  3033. m_MeasureAppForm.m_SPropertyWindows.TSLoad.Enabled = true;
  3034. m_MeasureAppForm.m_SPropertyWindows.TSEdit.Enabled = false;
  3035. m_MeasureAppForm.m_SPropertyWindows.TSEdit.Visible = false;
  3036. //添加样品
  3037. m_MeasureAppForm.AddNewSampleMeasure(m_SampleHoleSelectName);
  3038. break;
  3039. case "DeleteStage":
  3040. //删除样品
  3041. OTSSamplespaceGraphicsPanelFun.DeleteSampleInfo(m_MeasureAppForm, m_SampleSelectName);
  3042. break;
  3043. case "DriveSEMToCenterLocation":
  3044. //驱动SEM到中心位置
  3045. SetSEMToCenterPoint();
  3046. break;
  3047. case "DriveSEMToCurrentLocation":
  3048. //驱动SEM到当前位置
  3049. SetSEMCurrentLocation();
  3050. break;
  3051. case "SetSEMCenterLocation":
  3052. //将测量区域移到SEM当前位置
  3053. SetMeasureToSEMLocation();
  3054. break;
  3055. case "ReadSEMData":
  3056. m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;
  3057. //设定SEM数据
  3058. CMeasureThreadWrapper.DoRunType = (int)MSR_THREAD_RunSTATUS.RUNMEASURE;
  3059. GetSingleInfo();
  3060. // 根据已完成测量的帧图信息 绘制帧图已完成状态
  3061. GetSingleInfoForSampleNameAndOTSSamplespaceWindow();
  3062. break;
  3063. case "SetSemData":
  3064. double SemMag = 0;
  3065. double dDistance = 0;
  3066. log.Trace("OTSSamplespaceWindow_CMStrip_ItemClicked:--begin--");
  3067. if (m_MeasureAppForm.m_ProjParam.GetMagAndDistance(ref SemMag, ref dDistance))
  3068. {
  3069. //设置SEM数据
  3070. bool IsTrue = SetSEMDATAMParameter(SemMag, dDistance);
  3071. if (!IsTrue)
  3072. {
  3073. log.Error("OTSSamplespaceWindow_CMStrip_ItemClicked:--SetSemData:--Mag:" + SemMag + "--Distance:" + dDistance + "--");
  3074. }
  3075. }
  3076. break;
  3077. case "ShootBSEPicture":
  3078. //设置消息类型 拍摄样品孔
  3079. m_MeasureAppForm.m_MessageStates = MessageState.ShotBSEPicture;
  3080. //清除原图片信息
  3081. DeleteHoleBSEImageDataNoMessageBox();
  3082. //记录当前放大倍数 在停止拍摄图片后设置回原放大倍数
  3083. m_MeasureAppForm.m_ProjParam.GetWorkingSampleSEMData(ref m_PropIWDistance, ref m_PropDMagni);
  3084. GetSEMDATAMParameter(ref m_SEMDMagni, ref m_SEMIWDistance);
  3085. GetBSEPictures();
  3086. break;
  3087. case "DeleteBSEPicture":
  3088. DeleteHoleBSEImageData();
  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 = "1000um";
  4122. f_ruler_size = f_ruler_size + Convert.ToInt32(f_old_ruler_size * f_zoom_increment);
  4123. control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);
  4124. control_Ruler2.SetValueInspector(f_ruler_size, ((Convert.ToDouble(m_OTSSampleStageData.StageDomain.Width) / Convert.ToDouble(54)) / 10));
  4125. }
  4126. }
  4127. public void RulerInit()
  4128. {
  4129. control_Ruler2.ShowString = "100um";
  4130. control_Ruler2.Width = 130;
  4131. }
  4132. #endregion
  4133. #region 隐藏与显示样品台中的文字
  4134. static bool IsShowSampleHoleFont = true;
  4135. public void ChangeSampleHoleFont()
  4136. {
  4137. IsShowSampleHoleFont = IsShowSampleHoleFont ? false : true;
  4138. Invalidate();
  4139. }
  4140. #endregion
  4141. #region 隐藏与显示样品孔照片
  4142. static bool IsShowSampleHoleImage = true;
  4143. public void ChangeSampleHoleImage()
  4144. {
  4145. IsShowSampleHoleImage = IsShowSampleHoleImage ? false : true;
  4146. Invalidate();
  4147. }
  4148. #endregion
  4149. #region 添加样品孔中BSE图像信息
  4150. public void AddHoleBSEImageData(byte[] ImageData, int width, int height, Point fieldPos)
  4151. {
  4152. //获取样品孔名称
  4153. string sampleHoleName = string.Empty;
  4154. ARectangleGDIObject itemWorkSample = null;
  4155. foreach (ARectangleGDIObject item in m_SampleGDIObjects)
  4156. {
  4157. if (item.IsWorkSample)
  4158. {
  4159. sampleHoleName = item.Name;
  4160. itemWorkSample = item;
  4161. break;
  4162. }
  4163. }
  4164. //获取样品孔BSE图像
  4165. Image bseImage = null;
  4166. int m_iWidth = width;
  4167. int m_iHeigh = height;
  4168. RectangleF ImgRegionF = new RectangleF();
  4169. float ImgRegionWidth = 0;
  4170. float ImgRegionHeight = 0;
  4171. if (m_ImageSingleGDIObjects.Count > 0)
  4172. {
  4173. for (int i = 0; i < m_ImageSingleGDIObjects.Count; i++)
  4174. {
  4175. if (m_ImageSingleGDIObjects[i].OTSX == fieldPos.X && m_ImageSingleGDIObjects[i].OTSY == fieldPos.Y)
  4176. {
  4177. ImgRegionF = m_ImageSingleGDIObjects[i].RegionF;
  4178. ImgRegionWidth = Convert.ToInt32(m_ImageSingleGDIObjects[i].RegionF.Width);
  4179. ImgRegionHeight = Convert.ToInt32(m_ImageSingleGDIObjects[i].RegionF.Height);
  4180. //获取图片
  4181. bseImage = OTSSysMgrTools.Imagepro.ToGrayBitmap(ImageData, m_iWidth, m_iHeigh);
  4182. //获取工作样品位置
  4183. Point drawImageLocation = itemWorkSample.Region.Location;
  4184. //绘制图像
  4185. CreateRectangle createImageRect = new CreateRectangle(ImgRegionF, fieldPos.X, fieldPos.Y, itemWorkSample.SampleName, itemWorkSample.Name, bseImage, ImgRegionWidth, ImgRegionHeight, drawImageLocation, (int)CreateRectangleType.DrawSampleHoleBSEImage);
  4186. //添加至List集合中
  4187. createImageRect.DrawRegionF = m_ImageSingleGDIObjects[i].DrawRegionF;
  4188. createImageRect.RegionF = m_ImageSingleGDIObjects[i].RegionF;
  4189. createImageRect.Region = m_ImageSingleGDIObjects[i].Region;
  4190. createImageRect.Name = m_ImageSingleGDIObjects[i].Name;
  4191. m_ImageGDIObjects.Add(createImageRect);
  4192. break;
  4193. }
  4194. }
  4195. }
  4196. //显示样品孔照片
  4197. IsShowSampleHoleImage = true;
  4198. Invalidate();
  4199. }
  4200. #endregion
  4201. #region 删除样品孔中BSE图像信息
  4202. public void DeleteHoleBSEImageData()
  4203. {
  4204. try
  4205. {
  4206. //鼠标右键点击的位置坐标
  4207. Point mouseCurrent = m_MouseDownLocation;
  4208. //样品名称
  4209. string SampleName = "";
  4210. //获取当前工作样品并删除对应BSE图
  4211. foreach (ARectangleGDIObject ImageItem in m_ImageGDIObjects)
  4212. {
  4213. if (ImageItem.Region.Contains(mouseCurrent))
  4214. {
  4215. SampleName = ImageItem.SampleName;
  4216. break;
  4217. }
  4218. }
  4219. if (SampleName != null && !SampleName.Equals(""))
  4220. {
  4221. string message = table["message7"].ToString();
  4222. if (MessageBox.Show(message, "Tip", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  4223. {
  4224. CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag = MessageState.StartMeasure;
  4225. DeleteHoleBSEImageDataNoMessageBox();
  4226. return;
  4227. }
  4228. else
  4229. {
  4230. return;
  4231. }
  4232. }
  4233. //删除样品孔BSE图
  4234. //样品孔名称
  4235. string HoleName = "";
  4236. foreach (ARectangleGDIObject item in m_SampleHoleGDIObjects)
  4237. {
  4238. if (item.Region.Contains(mouseCurrent))
  4239. {
  4240. HoleName = item.Name;
  4241. break;
  4242. }
  4243. }
  4244. if (HoleName != null && !HoleName.Equals(""))
  4245. {
  4246. string message = table["message8"].ToString();
  4247. if (MessageBox.Show(message, "Tip", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  4248. {
  4249. CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag = MessageState.ShotBSEPicture;
  4250. DeleteHoleBSEImageDataNoMessageBox();
  4251. return;
  4252. }
  4253. else
  4254. {
  4255. return;
  4256. }
  4257. }
  4258. }
  4259. catch (Exception ex)
  4260. {
  4261. string message = table["message9"].ToString();
  4262. log.Trace(message + ex.ToString());
  4263. }
  4264. }
  4265. public void DeleteHoleBSEImageDataNoMessageBox()
  4266. {
  4267. try
  4268. {
  4269. if (CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag != null)
  4270. {
  4271. if ((int)CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag == (int)MessageState.ShotBSEPicture)
  4272. {
  4273. string HoleName = string.Empty;
  4274. //鼠标右键点击的位置坐标
  4275. Point mouseCurrent = m_MouseDownLocation;
  4276. //获取当前工作样品并删除对应BSE图
  4277. foreach (ARectangleGDIObject item in m_SampleHoleGDIObjects)
  4278. {
  4279. if (item.Region.Contains(mouseCurrent))
  4280. {
  4281. HoleName = item.Name;
  4282. break;
  4283. }
  4284. }
  4285. if (!HoleName.Equals(""))
  4286. {
  4287. for (int i = m_ImageGDIObjects.Count - 1; i >= 0; i--)
  4288. {
  4289. if (m_ImageGDIObjects[i].Name == HoleName && m_ImageGDIObjects[i].SampleName == null)
  4290. {
  4291. m_ImageGDIObjects.RemoveAt(i);
  4292. }
  4293. }
  4294. for (int i = m_ImageSingleGDIObjects.Count - 1; i >= 0; i--)
  4295. {
  4296. if (m_ImageSingleGDIObjects[i].Name == HoleName && m_ImageGDIObjects[i].SampleName == null)
  4297. {
  4298. m_ImageSingleGDIObjects.RemoveAt(i);
  4299. }
  4300. }
  4301. Invalidate();
  4302. }
  4303. }
  4304. else
  4305. {
  4306. string SampleName = string.Empty;
  4307. //鼠标右键点击的位置坐标
  4308. Point mouseCurrent = m_MouseDownLocation;
  4309. //获取当前工作样品并删除对应BSE图
  4310. foreach (ARectangleGDIObject item in m_ImageGDIObjects)
  4311. {
  4312. if (item.Region.Contains(mouseCurrent))
  4313. {
  4314. SampleName = item.SampleName;
  4315. break;
  4316. }
  4317. }
  4318. if (!SampleName.Equals(""))
  4319. {
  4320. for (int i = m_ImageGDIObjects.Count - 1; i >= 0; i--)
  4321. {
  4322. if (m_ImageGDIObjects[i].SampleName == SampleName)
  4323. {
  4324. m_ImageGDIObjects.RemoveAt(i);
  4325. }
  4326. }
  4327. for (int i = m_ImageSingleGDIObjects.Count - 1; i >= 0; i--)
  4328. {
  4329. if (m_ImageSingleGDIObjects[i].SampleName == SampleName)
  4330. {
  4331. m_ImageSingleGDIObjects.RemoveAt(i);
  4332. }
  4333. }
  4334. Invalidate();
  4335. }
  4336. }
  4337. }
  4338. }
  4339. catch (Exception)
  4340. {
  4341. }
  4342. }
  4343. #endregion
  4344. #region 获取样品孔图片
  4345. public void GetBSEPictures()
  4346. {
  4347. //获取当前工作的测量区域信息
  4348. CDomain cDomain = new CDomain();
  4349. DOMAIN_SHAPE iShape = 0;
  4350. Rectangle Srect = new Rectangle();
  4351. //拍摄样品孔BSE照片
  4352. if (CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag != null)
  4353. {
  4354. if ((int)CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag == (int)MessageState.ShotBSEPicture)
  4355. {
  4356. //获取当前样品孔的索引 与 样品中对应的测量区域
  4357. OTSSampleHoleInfo sampleHoleInfo = null;
  4358. int sampleHoleIndex = OTSSamplespaceGraphicsPanelFun.GetSampleHoleIndex(m_OTSSampleStageData, m_SampleHoleSelectName, ref sampleHoleInfo);
  4359. if (sampleHoleInfo != null)
  4360. {
  4361. foreach (var sampleHoleItem in m_SampleHoleGDIObjects)
  4362. {
  4363. if (sampleHoleItem.Name == sampleHoleInfo.sSHoleName)
  4364. {
  4365. SampleHolePara sampleHolePara = OTSSamplespaceGraphicsPanelFun.GetSampleHoleRect(sampleHoleItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain);
  4366. iShape = (DOMAIN_SHAPE)sampleHolePara.iShape;
  4367. Srect = sampleHolePara.SampleHoleRect;
  4368. //设置测量区域形状
  4369. cDomain.SetShape(iShape);
  4370. cDomain.SetRectDomain(Srect);
  4371. //开始获取样品孔中的照片
  4372. m_MeasureAppForm.StartSampleHoleBSEImage((int)MSR_THREAD_RunSTATUS.RUNSampleHoleImage, sampleHoleIndex, cDomain);
  4373. break;
  4374. }
  4375. }
  4376. }
  4377. }
  4378. else
  4379. {
  4380. int measureIndex = 0;
  4381. //获取测量区域信息
  4382. foreach (var MeasureItem in m_MeasureGDIObjects)
  4383. {
  4384. if (MeasureItem.SampleName == m_SampleSelectName)
  4385. {
  4386. measureIndex++;
  4387. SampleMeasurePara sampleMeasure = OTSSamplespaceGraphicsPanelFun.GetSampleMeasureRect(MeasureItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain);
  4388. iShape = (DOMAIN_SHAPE)sampleMeasure.iShape;
  4389. Srect = sampleMeasure.MeasureRect;
  4390. //设置测量区域形状
  4391. if (iShape == (DOMAIN_SHAPE)(int)CreateRectangleType.Polygon)
  4392. {
  4393. if (iShape > 0)
  4394. {
  4395. cDomain.SetShape(iShape);
  4396. }
  4397. else
  4398. {
  4399. cDomain.SetShape((DOMAIN_SHAPE.ROUND));
  4400. }
  4401. }
  4402. else
  4403. {
  4404. cDomain.SetShape(iShape);
  4405. }
  4406. cDomain.SetRectDomain(Srect);
  4407. List<Point> PolygonPoint = OTSSamplespaceGraphicsPanelFun.PointFConvertPoint(sampleMeasure.DrawPolygonPointRegionF);
  4408. cDomain.SetPolygonPoint(PolygonPoint);
  4409. //开始获取样品孔中的照片
  4410. m_MeasureAppForm.StartSampleHoleBSEImage((int)MSR_THREAD_RunSTATUS.RUNSampleHoleImage, 2, cDomain);
  4411. break;
  4412. }
  4413. }
  4414. }
  4415. }
  4416. }
  4417. #endregion
  4418. #region 复位工作样品区域
  4419. public void ResetWorkSampleMeasure()
  4420. {
  4421. COTSSample WSample = m_MeasureAppForm.m_ProjParam.GetWorkSample();
  4422. OTSSamplePropertyInfo MeasureInfo = new OTSSamplePropertyInfo();
  4423. if (!m_MeasureAppForm.m_ProjParam.GetWorkSamplePerameter(WSample, ref MeasureInfo))
  4424. {
  4425. return;
  4426. }
  4427. Rectangle measureSize = m_MeasureAppForm.m_ProjParam.CalculateMsrArea(MeasureInfo.SMeasurePara.sHoleName);
  4428. //获取位置与尺寸
  4429. MeasureInfo.SMeasurePara.MeasureRect.Location = measureSize.Location;
  4430. MeasureInfo.SMeasurePara.MeasureRect.Size = measureSize.Size;
  4431. //获取样品信息
  4432. Point xHole = new Point(MeasureInfo.SMeasurePara.MeasureRect.Left, MeasureInfo.SMeasurePara.MeasureRect.Top);
  4433. Point yHole = new Point(MeasureInfo.SMeasurePara.MeasureRect.Right, MeasureInfo.SMeasurePara.MeasureRect.Bottom);
  4434. //将微米转换为像素
  4435. int widthHole = (int)(Math.Abs(((Point)yHole).X - ((Point)xHole).X));
  4436. int heightHole = (int)(Math.Abs(((Point)yHole).Y - ((Point)xHole).Y));
  4437. //定义测量区域
  4438. RectangleF SampleRectangleF = OTSSamplespaceGraphicsPanelFun.GetPixRectF(m_WDomain, yHole, xHole, "", "", IsWidth, m_DefaultW, m_DefaultH);
  4439. ARectangleGDIObject m_MeasureGDIObject = OTSSamplespaceGraphicsPanelFun.GetPixRect(m_WDomain, yHole, xHole, MeasureInfo.SMeasurePara.iShape, "", "", IsWidth, m_DefaultW, m_DefaultH);
  4440. m_MeasureGDIObject.Region = new Rectangle((int)SampleRectangleF.X, (int)SampleRectangleF.Y, (int)SampleRectangleF.Width, (int)SampleRectangleF.Height);
  4441. m_MeasureGDIObject.RegionF = SampleRectangleF;
  4442. m_MeasureGDIObject.DrawRegionF = SampleRectangleF;
  4443. foreach (var itemSample in m_SampleGDIObjects)
  4444. {
  4445. if (itemSample.IsWorkSample)
  4446. {
  4447. for (int i = 0; i < m_MeasureGDIObjects.Count; i++)
  4448. {
  4449. if (m_MeasureGDIObjects[i].IsWorkSample)
  4450. {
  4451. ARectangleGDIObject m_ResetMeasureGDIobjects = CStageManage.ResetMeasure((int)CreateRectangleType.Circle, itemSample, m_MeasureGDIObject, m_GlobalZoomNum);
  4452. m_MeasureGDIObjects[i].Region = m_ResetMeasureGDIobjects.Region;
  4453. m_MeasureGDIObjects[i].RegionF = m_ResetMeasureGDIobjects.RegionF;
  4454. m_MeasureGDIObjects[i].DrawRegionF = m_ResetMeasureGDIobjects.DrawRegionF;
  4455. m_MeasureGDIObjects[i].Shape = m_ResetMeasureGDIobjects.Shape;
  4456. Invalidate();
  4457. break;
  4458. }
  4459. }
  4460. break;
  4461. }
  4462. }
  4463. }
  4464. #endregion
  4465. #region 清空帧图对象与图像位置对象
  4466. public void ClearImageAndSingleGDIObjects()
  4467. {
  4468. //先清空帧图信息
  4469. if (m_MeasureAppForm.m_MessageStates == (int)MessageState.StartMeasure)
  4470. {
  4471. m_SingleGDIObjects = OTSSamplespaceGraphicsPanelFun.ListClear(m_SingleGDIObjects);
  4472. }
  4473. if (m_MeasureAppForm.m_MessageStates == MessageState.ShotBSEPicture)
  4474. {
  4475. m_ImageSingleGDIObjects = OTSSamplespaceGraphicsPanelFun.ListClear(m_ImageSingleGDIObjects);
  4476. }
  4477. }
  4478. #endregion
  4479. #region 样品对象列表中无样品信息 则清除帧图对象列表信息
  4480. /// <summary>
  4481. /// 样品对象列表中无样品信息 则清除帧图对象列表信息
  4482. /// </summary>
  4483. /// <returns></returns>
  4484. public bool SampleIsEmptyClearSingleInfo()
  4485. {
  4486. bool result = false;
  4487. if (m_SampleGDIObjects != null)
  4488. {
  4489. if (m_SampleGDIObjects.Count == 0)
  4490. {
  4491. result = true;
  4492. ClearImageAndSingleGDIObjects();
  4493. }
  4494. }
  4495. return result;
  4496. }
  4497. #endregion
  4498. #region 切换样品 填充帧图信息
  4499. public static void ChangeSampleFillSingleInfo(string sampleName)
  4500. {
  4501. OTSSamplespaceGraphicsPanelFun.ChangeSampleFillSingleInfo(m_ALLSingleGDIObjects, m_SingleGDIObjects, sampleName);
  4502. }
  4503. private void OTSSamplespaceWindow_Activated(object sender, EventArgs e)
  4504. {
  4505. ShowRulerLocation();
  4506. }
  4507. #endregion
  4508. #region 设置工作样品测量区域
  4509. public bool SetWorkSampleMeasureArea(int shape = 0)
  4510. {
  4511. bool IsSingle = false;
  4512. //获取当前工作的测量区域信息
  4513. CDomain cDomain = new CDomain();
  4514. DOMAIN_SHAPE iShape = 0;
  4515. Rectangle Srect = new Rectangle();
  4516. List<Point> PolygonPoint = new List<Point>();
  4517. //获取测量区域形状与位置
  4518. //获取当前测量区域
  4519. foreach (var MeasureItem in m_MeasureGDIObjects)
  4520. {
  4521. if (MeasureItem.IsSingle && MeasureItem.IsWorkSample)
  4522. {
  4523. if (OTSSamplespaceGraphicsPanelFun.SetWorkSamplHoleAndMeasureArea(MeasureItem, m_MeasureAppForm, m_OTSSampleStageData, m_RectangleGDIObjects[0], IsWidth, Width, Height, m_WDomain))
  4524. {
  4525. IsSingle = true;
  4526. SampleMeasurePara sampleMeasure = GetSampleMeasureRect(MeasureItem);
  4527. if (sampleMeasure.PolygonPointRegion == null)
  4528. {
  4529. sampleMeasure.PolygonPointRegion = new List<Point>();
  4530. }
  4531. PolygonPoint = OTSSamplespaceGraphicsPanelFun.PointFConvertPoint(sampleMeasure.PolygonPointRegionF);
  4532. iShape = (DOMAIN_SHAPE)sampleMeasure.iShape;
  4533. //设置测量区域形状
  4534. if (iShape == (DOMAIN_SHAPE)(int)CreateRectangleType.Polygon)
  4535. {
  4536. if (shape > 0)
  4537. {
  4538. cDomain.SetShape((DOMAIN_SHAPE)shape);
  4539. }
  4540. else
  4541. {
  4542. cDomain.SetShape((DOMAIN_SHAPE.ROUND));
  4543. }
  4544. }
  4545. else
  4546. {
  4547. cDomain.SetShape((DOMAIN_SHAPE)iShape);
  4548. }
  4549. Srect = sampleMeasure.MeasureRect;
  4550. cDomain.SetRectDomain(Srect);
  4551. cDomain.SetPolygonPoint(PolygonPoint);
  4552. //线程执行类型 1:测量类型 2:获取样品孔图片类型
  4553. CMeasureThreadWrapper.DoRunType = (int)MSR_THREAD_RunSTATUS.RUNMEASURE;
  4554. //设置获取样品孔中照片所需的参数
  4555. CMeasureThreadWrapper.c_DomainMessure = cDomain;
  4556. }
  4557. break;
  4558. }
  4559. }
  4560. return IsSingle;
  4561. }
  4562. #endregion
  4563. }
  4564. }