OTSSamplespaceWindow.cs 236 KB

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