OTSSamplespaceWindow.cs 242 KB

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