OTSSamplespaceWindow.cs 237 KB

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