OTSSamplespaceWindow.cs 244 KB

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