OTSSamplespaceWindow.cs 218 KB

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