1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Windows.Forms;
- using OTS.WinFormsUI.Docking;
- using System.IO;
- using System.Drawing.Drawing2D;
- using System.Collections;
- using OTSDataType;
- using OTSModelSharp;
- using static OTSDataType.otsdataconst;
- using MyControls;
- using OTSModelSharp.ServiceInterface;
- using OTSModelSharp.ServiceCenter;
- using OTSMeasureApp._4_OTSSamplespaceGraphicsPanel;
- namespace OTSMeasureApp
- {
-
- public partial class OTSSamplespaceWindow : DockContent
- {
- #region 全局变量定义
- public CVisualStage m_visualStage;
- //样品测量集合对象
- public List<SampleMeasurePara> m_SMeasrueAreaList = null;
-
- //样品孔的List集合
- string m_SampleHoleSelectName = string.Empty;
- public string m_SampleSelectName = string.Empty;
-
-
- public static CRectangleGDIObject selectSampleGDIObjects;
- public List<CRectangleGDIObject> m_SampleGDIObjects;
-
- //测量区域
- public List<CRectangleGDIObject> m_MeasureGDIObjects;
- //帧图
- public List<CRectangleGDIObject> m_MeasureFieldGDIObjects;
- //BSE图像
- public static List<CRectangleGDIObject> m_ImageGDIObjects;
- //BSE图像帧图 为了获取位置与尺寸
- public static List<CRectangleGDIObject> m_ImageOfFieldGDIObjects;
- //手绘测量区域
- public static List<CRectangleGDIObject> m_DrawMeasureGDIObjects;
-
- //多边形测量区域完成标识
- public static List<CRectangleGDIObject> m_DrawPolygonFinishGDIObjects;
- bool m_RectangIsDragging = false;
- float m_PenWidth = 5;
-
- //主窗体对象
- OTSIncAMeasureAppForm m_MeasureAppForm;
- //鼠标右键选择的类型 0:样品台 1:样品 2:测量区域
- //public ContextMenuType m_IsSelectType = 0;
- //当前是否选择测量区域
- public static bool m_IsMeasure = false;
- SEMDATAFieldManage m_SEMDATAFieldManage;
- //当前是否移动样品
- bool m_IsMoveSample = false;
- bool isChange = false;
-
-
- private _5_OTSMeasureStatuImageFun.SlopFocus slopFocus=null;
- #region 鼠标滚动所需参数
-
- public static float m_GlobalZoomNum = 1;//记录每次比例缩放后的总体比例系数。
-
-
- int m_MinMeasureWidthValue = 20;
-
- Point m_MouseDownLocation ;
- #endregion
- #region 手动绘制测量区域
- Point m_MouseDownPoint;
-
- Point m_MouseMovePoint;
- //绘制多边形,点集合
- List<PointF> m_PolygonPoint;
- //点数量
- int m_PointCount = 2;
- //与多边形绘制的开始点相差的像素值
- int m_OffsetPX = 10;
- //手动绘制多边形测量区域完成标识
- bool m_IsDrawPolygonFinish = false;
- //手动绘制测量区域的形状类型
- CreateRectangleType m_DrawMeasureType = (CreateRectangleType)1;
- //是否手绘标识准备
- public bool m_IsDrawMeasureReady = false;
- //是否手绘标识
- public bool m_IsDrawMeasure = false;
- #endregion
- //是否选中样品台标识
- bool m_IsSelectSampleStage = false;
- private Point m_P, m_P1;
- protected Point m_MeasureToSamplePoint;
- //是否按下Ctrl键
- bool m_IsCtrl = false;
- bool m_IsAlt = false;
- //配合Ctrol键是否选中多边形的点标识
- bool m_IsSelPolygonPoint = false;
- //配合Ctrol键是否选中多边形的点
- PointF m_SelPolygonPoint ;
- //默认值
- const int m_DValue = 1;
- NLog.Logger log ;
- //选择工作样品测量的状态
- bool selWSampleMeasureStatus = false;
- #endregion
- #region 标尺变量
-
- //最小缩放倍数
- private float f_zoom_mix = 0.5f;
- //标尺的大小记录
- private float f_ruler_size = 100;
- //标尺原先大小的记录,参与计算
- private float f_old_ruler_size = 100;
- public RectangleF BackRectF
- {
- set { backrectf = value; }
- get { return backrectf; }
- }
- //背景矩形
- public RectangleF backrectf = new RectangleF();
- //记录原值,背景矩形
- public RectangleF old_backrectf = new RectangleF();
- //国际化
- OTSCommon.Language lan;
- Hashtable table;
- #endregion
- #region 设置双缓冲
- /// <summary>
- /// 设置双缓冲
- /// </summary>
- public void SetDoubleBufferByIsDraw()
- {
- SetStyle(ControlStyles.UserPaint, true);
- SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
- this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // 双缓冲
- }
- #endregion
- #region 构造函数 获取父窗体对象
- public OTSSamplespaceWindow(OTSIncAMeasureAppForm MeasureAppForm)
- {
- InitializeComponent();
- m_MeasureAppForm = MeasureAppForm;
-
- SetDoubleBufferByIsDraw();// 双缓冲
-
-
- //国际化
- lan = new OTSCommon.Language(this);
- table = lan.GetNameTable(this.Name);
- }
- /// <summary>
- /// 画圆形测试区域 事件
- /// </summary>
- public void DrawCircleMeasure()
- {
- //手绘测量区域类型为圆形
- m_DrawMeasureType = CreateRectangleType.Circle;
- m_IsDrawMeasureReady = true;
- m_RectangIsDragging = false;
- this.Cursor = Cursors.Hand;
- }
- /// <summary>
- /// 画矩形测试区域 事件
- /// </summary>
- public void DrawRectangleMeasure()
- {
- //手绘测量区域类型为矩形
- m_DrawMeasureType = CreateRectangleType.SampleBackGround_Rectangle;
- m_IsDrawMeasureReady = true;
- m_RectangIsDragging = false;
- this.Cursor = Cursors.Hand;
- }
- /// <summary>
- /// 画多边形测试区域 事件
- /// </summary>
- public void DrawPolygonMeasure()
- {
- //多边形测量区域完成标识
- m_DrawPolygonFinishGDIObjects = new List<CRectangleGDIObject>();
- //手绘测量区域类型为矩形
- m_DrawMeasureType = CreateRectangleType.Polygon;
- m_IsDrawMeasureReady = true;
- m_IsDrawMeasure = true;
- m_RectangIsDragging = false;
- m_PolygonPoint = new List<PointF>();
- this.Cursor = Cursors.Hand;
- }
- /// <summary>
- /// 三点画圆形测试区域 事件 先多边形后圆形
- /// </summary>
- public void DrawCircleMeasureByThreePoints()
- {
- //手绘测量区域类型为圆形
- m_DrawMeasureType = CreateRectangleType.CircleByThreePoints;
- m_IsDrawMeasureReady = true;
- m_IsDrawMeasure = true;
- m_RectangIsDragging = false;
- m_PolygonPoint = new List<PointF>();
- this.Cursor = Cursors.Hand;
- }
- /// <summary>
- /// 当修改了GRID 的样品台测量精度、放大倍数和图片像素大小 时,SAMPLEWINDOW重新绘制样品台
- /// </summary>
- public void DrawSampleField()
- {
- m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;
- //显示帧图
- if (m_MeasureFieldGDIObjects.Count > 0)
- {
- DrawMeasureField();
- }
- }
- public void OpenExistSampleFile(CStage SStage, CSEMStageData SEMStageData, List<SampleMeasurePara> SMeasrueAreaList, string sWorkSampleName)
- {
- m_visualStage.InitSampleStageData(SStage, SEMStageData,this.Width,this.Height);
-
-
- m_GlobalZoomNum = 1;
- //清除所有绘制的图形信息
- ClearDrawInfo();
- //绘制样品台信息
-
-
- m_visualStage. DrawSampleStage();
-
- //绘制样品与测量区域
- //1.绘制样品
- if (SMeasrueAreaList != null)
- {
- m_SMeasrueAreaList = SMeasrueAreaList;
- DrawSampleAndMeasureInfo(SMeasrueAreaList);
- }
- //2.测量区域
- //设置工作样品
- if (sWorkSampleName != "")
- {
- SwitchWorkSample(sWorkSampleName);
- //打开文件后 设置工作样品名称
- m_SampleSelectName = sWorkSampleName;
- }
- //重新绘制
- Invalidate();
- }
- public void SwitchWorkSample(string sNewWSampleName, bool bDrawField = false)
- {
- try
- {
- //获取存在帧图的样品名称
- string singleSampleName = string.Empty;
- if (m_MeasureFieldGDIObjects != null)
- {
- if (m_MeasureFieldGDIObjects.Count > 0)
- {
- singleSampleName = m_MeasureFieldGDIObjects[0].SampleName;
- }
- }
- //判断当前帧图所在样品的样品名称与新样品名称是否相同
- if (!singleSampleName.Equals(""))
- {
- if (singleSampleName != sNewWSampleName)
- {
- //先清空帧图信息
- ClearImageAndSingleGDIObjects();
- this.Invalidate();
- }
- }
- //判断当前帧图所在样品的样品名称与新样品名称是否相同
- if (m_MeasureFieldGDIObjects != null)
- {
- if (m_MeasureFieldGDIObjects.Count > 0)
- {
- if (m_MeasureFieldGDIObjects[0].SampleName != sNewWSampleName)
- {
- //先清空帧图信息
- ClearImageAndSingleGDIObjects();
- this.Invalidate();
- }
- }
- }
- //设置工作样品样式
- SetWorkSampleAndWorkMeasure(sNewWSampleName);
- foreach (var itemMeasure in m_MeasureGDIObjects)
- {
- if (itemMeasure.IsWorkSample && sNewWSampleName == itemMeasure.SampleName)
- {
- //当前工作样品的测量区域 获取帧图信息
- if (m_MeasureFieldGDIObjects.Count == 0)
- {
-
-
- DrawMeasureField();
-
- break;
- }
- }
- }
- ////绘制已完成的帧图状态
- COTSMsrPrjResultData cProjMgr = m_MeasureAppForm.m_ProjParam.GetResultData();
- //当前工作样品的测量区域 获取帧图信息
- COTSSample cSample = cProjMgr.GetWorkingSample();
- int CompletedFieldsCount = cSample.GetMsrStatus().GetCompletedFields();
- if (CompletedFieldsCount > 0)
- {
- //设置测量区域获取帧图
- foreach (var itemMeasure in m_MeasureGDIObjects)
- {
- if (cSample.GetName() == itemMeasure.SampleName)
- {
-
- break;
- }
- }
- if (m_MeasureFieldGDIObjects.Count == 0)
- {
- DrawMeasureField();
- }
- //获取已完成测量的帧图中心点
- List<Point> CompleteFieldList = cProjMgr.GetWorkingSample().GetMsrStatus().GetCompletedFieldsCenter();
- //修改帧图完成状态
- ChangeCompleteFieldMeasureState(CompleteFieldList, Color.Green, m_MeasureAppForm);
- }
- else
- {
- //根据测量文件中已获取sem信息
- if (cSample.GetSEMDataMsr().GetTotalFields() > 0)
- {
- foreach (var itemMeasure in m_MeasureGDIObjects)
- {
- if (cSample.GetName() == itemMeasure.SampleName)
- {
-
- DrawMeasureField();
- break;
- }
- }
- }
- }
- //设置为手绘测量区域
- m_IsDrawMeasureReady = false;
- m_IsDrawMeasure = false;
- this.Invalidate();
- return;
- }
- catch (Exception ex)
- {
-
- log.Trace(ex.ToString() );
- }
- }
- public void ChangeCompleteFieldMeasureState(List<Point> CompleteFieldList, Color changeColor, OTSIncAMeasureAppForm m_MeasureApp)
- {
- foreach(var p in CompleteFieldList)
- {
- ChangeDoneMeasureState(p, changeColor);
-
- }
-
- }
- public void ChangeDoneMeasureState(Point CurrentFIELDOTSPoint, Color changeColor)
- {
- //根据完成的测量帧图 更改帧图的完成状态
- if (m_MeasureFieldGDIObjects != null)
- {
- if (m_MeasureFieldGDIObjects.Count > 0)
- {
-
- foreach (var gdi in m_MeasureFieldGDIObjects)
- {
- var x1 = m_visualStage.MillimetersToPixelsWidth(CurrentFIELDOTSPoint.X);
- var y1 = m_visualStage.MillimetersToPixelsWidth(CurrentFIELDOTSPoint.Y);
- PointF cptPoint = m_visualStage.CalculateLocationF(new PointF((float)x1, (float)y1));
- if (gdi.IfContains(new Point((int)cptPoint.X, (int)cptPoint.Y)))
- {
- //修改完成状态
- gdi.SelColor = changeColor;
-
- break;
- }
- }
- }
- }
- }
-
- public void ChangeSampleName(string sampleName)
- {
- //循环 样品与测量区域的名称修改为新名称
- foreach (CRectangleGDIObject itemSample in m_SampleGDIObjects)
- {
- if (itemSample.IsWorkSample)
- {
- foreach (CRectangleGDIObject measureItemSample in m_MeasureGDIObjects)
- {
- if (measureItemSample.SampleName == itemSample.SampleName)
- {
- measureItemSample.SampleName = sampleName;
- itemSample.SampleName = sampleName;
- return;
- }
- }
- }
- }
- }
- public void ChangeWorkSampleName(string sNewWSampleName)
- {
- try
- {
- string oldSampleName = string.Empty;
- foreach (CRectangleGDIObject itemSample in m_SampleGDIObjects)
- {
- if (itemSample.IsWorkSample)
- {
- oldSampleName = itemSample.SampleName;
- }
- }
- //更换样品名称
- ChangeSampleName(sNewWSampleName);
- this.Invalidate();
- return;
- }
- catch (Exception ex)
- {
-
-
- log.Trace( ex.ToString() );
- }
- }
- public void SetMeasureState(Color setColor)
- {
- foreach (CRectangleGDIObject items in m_MeasureGDIObjects)
- {
- items.SelColor = setColor;
- }
- }
- #endregion
- #region 修改样品选择状态
- public void SetSampleState(Color setColor)
- {
- foreach (CRectangleGDIObject items in m_SampleGDIObjects)
- {
- if (items.IsDragging)
- {
- //设置颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
- items.SelColor = ColorTranslator.FromHtml(ColorStr);
- }
- else
- {
- items.SelColor = setColor;
- }
- }
- }
- public bool DeleteMeasure(string sampleName)
- {
-
- if (m_MeasureGDIObjects.Count > 0)
- {
- foreach (CRectangleGDIObject items in m_MeasureGDIObjects)
- {
- //删除样品测量
- if (items.SampleName == sampleName)
- {
- //将样品孔恢复未拖动状态
- items.IsSelect = false;
- m_MeasureGDIObjects.Remove(items);
-
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
- SetSampleState(ColorTranslator.FromHtml(ColorStr));
- SetMeasureState(ColorTranslator.FromHtml(ColorStr));
- m_IsMeasure = false;
- foreach (CRectangleGDIObject sampleItem in m_SampleGDIObjects)
- {
- if (sampleItem.SampleName == items.SampleName)
- {
- sampleItem.IsWorkSample = true;
- //设置颜色
- string SampleSelColor = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
- sampleItem.SelColor = ColorTranslator.FromHtml(SampleSelColor);
- }
- }
- return true;
- }
- }
- }
-
- return false;
- }
- public bool DeleteSample(string SampleName)
- {
-
- CRectangleGDIObject itemAdd = null;
- if (m_SampleGDIObjects.Count > 0)
- {
- foreach (CRectangleGDIObject items in m_SampleGDIObjects)
- {
- itemAdd = items;
- if (items.SampleName == SampleName)
- {
- m_visualStage.DecreaseSampleCount(SampleName);
-
- //将样品孔恢复未拖动状态
- items.IsSelect = false;
- m_SampleGDIObjects.Remove(items);
- if (DeleteMeasure(SampleName))
- {
- return true;
- }
- }
- }
- }
-
- return false;
- }
-
- //string sSampleHoleName: 删除工作样品名
- public void DeleteWorkSample(string sDeleteWSampleName, string sNewWSampleName)
- {
- try
- {
- foreach (CRectangleGDIObject itemSample in m_SampleGDIObjects)
- {
- if (itemSample.SampleName == sDeleteWSampleName)
- {
- if (itemSample.IsWorkSample)
- {
- //删除样品测量集合中的对象
- if (DeleteSample(sDeleteWSampleName))
- {
- if (m_SampleGDIObjects.Count == 0)
- {
- //将测量状态初始化
- m_MeasureAppForm.m_MessureStatuWindow.SetMeasureStatusInit();
- }
- //根据样品名称 删除对应帧图信息
- //OTSSamplespaceGraphicsPanelFun.DeleteALLSingleInfo(m_AllFieldGDIObjects, sDeleteWSampleName);
- if (!string.IsNullOrEmpty(sNewWSampleName))
- {
- //设置工作样品
- m_MeasureAppForm.SwitchWSample(sNewWSampleName);
- }
- else
- {
- //先清空帧图信息
- ClearImageAndSingleGDIObjects();
- }
- this.Invalidate();
- return;
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
-
- log.Error( ex.ToString() );
- }
- }
- #region 更改工作样品中 测量区域形状
- public bool ChangeSampleShape(ShapeType iShape)
- {
- foreach (CRectangleGDIObject itemSample in m_SampleGDIObjects)
- {
- if (itemSample.IsWorkSample)
- {
- foreach (CRectangleGDIObject itemMeasure in m_MeasureGDIObjects)
- {
- if (itemSample.SampleName == itemMeasure.SampleName)
- {
- if (itemMeasure.Shape != iShape)
- {
- //改变大小
- itemMeasure.Region = new Rectangle(itemMeasure.Region.X, itemMeasure.Region.Y, itemMeasure.Region.Height, itemMeasure.Region.Height);
- itemMeasure.RegionF = new RectangleF(itemMeasure.RegionF.X, itemMeasure.RegionF.Y, itemMeasure.RegionF.Height, itemMeasure.RegionF.Height);
- itemMeasure.DrawRegionF = new RectangleF(itemMeasure.DrawRegionF.X, itemMeasure.DrawRegionF.Y, itemMeasure.DrawRegionF.Height, itemMeasure.DrawRegionF.Height);
- itemMeasure.Shape = iShape;
- GraphicsPath NewMeasurePath = new GraphicsPath();
- if (itemMeasure.Shape == (int)CreateRectangleType.Circle)
- {
- NewMeasurePath.AddEllipse(itemMeasure.Region);
- }
- else
- {
- NewMeasurePath.AddRectangle(itemMeasure.Region);
- }
- itemMeasure.GPath = NewMeasurePath;
- return true;
- }
- return false;
- }
- }
- }
- }
- return false;
- }
- public void changeShape(ShapeType iShape)
- {
- try
- {
- string sampleName = m_MeasureAppForm.m_ProjParam.GetWorkSampleName();
- //m_Shap 更换样品形状
- if (ChangeSampleShape(iShape))
- {
- //设置新添加测量区域更改位置与缩放
- foreach (var item in m_MeasureGDIObjects)
- {
- if (item.SampleName == sampleName)
- {
- item.IsWorkSample = true;
-
- var sampleMeasurePara = m_visualStage. GetSampleMeasurePara(item);
-
- m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(sampleMeasurePara);
-
-
-
-
- if (item.IsWorkSample)
- {
- DrawMeasureField();
- }
-
-
- }
- }
- }
- this.Invalidate();
- return;
- }
- catch (Exception ex)
- {
-
- log.Error(ex.ToString() );
- }
- }
- #endregion
- #region 还原测量区域形状
- public void ResetShape()
- {
- try
- {
- //设置新添加测量区域更改位置与缩放
- foreach (var item in m_MeasureGDIObjects)
- {
- if (item.IsWorkSample)
- {
-
- var para = m_visualStage.GetSampleMeasurePara(item);
- m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);
-
-
-
-
- if (item.IsWorkSample)
- {
- DrawMeasureField();
- }
-
-
- }
- }
- this.Invalidate();
- return;
- }
- catch (Exception ex)
- {
-
- log.Error( ex.ToString() );
- }
- }
- #endregion
-
- public void AddOneSampleArea(SampleMeasurePara SMeasurePara)
- {
- try
- {
- CMStrip.Hide();
- //获取样品信息
- CRectangleGDIObject sampleGdi;
- CRectangleGDIObject measureGdi;
- //添加样品
- foreach (CRectangleGDIObject itemSample in m_SampleGDIObjects)
- {
- //设置颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
- itemSample.SelColor = ColorTranslator.FromHtml(ColorStr);
- itemSample.IsWorkSample = false;
- }
- if (m_visualStage. AddSample(SMeasurePara, m_GlobalZoomNum,out sampleGdi,out measureGdi))
- {
-
- m_SampleGDIObjects.Add(sampleGdi);
- m_MeasureGDIObjects.Add(measureGdi);
- m_SampleSelectName = SMeasurePara.sSampleName;
- var para = m_visualStage.GetSampleMeasurePara(measureGdi);
- m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);
-
- SetWorkSampleAndWorkMeasure(SMeasurePara.sSampleName);
-
- ClearImageAndSingleGDIObjects();
- Invalidate();
-
- }
- }
- catch (Exception ex)
- {
-
- log.Error( ex.ToString() );
- }
- }
- #region 设置工作样品
- /// <summary>
- /// 设置工作样品与测量区域
- /// </summary>
- /// <param name="sampleName">样品名称</param>
- public void SetWorkSampleAndWorkMeasure(string sampleName)
- {
- foreach (CRectangleGDIObject itemSample in m_SampleGDIObjects)
- {
- if (itemSample.SampleName == sampleName)
- {
- itemSample.IsWorkSample = true;
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
- itemSample.SelColor = ColorTranslator.FromHtml(ColorStr);
- }
- else
- {
- itemSample.IsWorkSample = false;
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
- itemSample.SelColor = ColorTranslator.FromHtml(ColorStr);
- }
- }
- foreach (CRectangleGDIObject itemMeasure in m_MeasureGDIObjects)
- {
- if (itemMeasure.SampleName == sampleName)
- {
- itemMeasure.IsWorkSample = true;
- itemMeasure.SelColor = Color.Red;
- }
- else
- {
- itemMeasure.IsWorkSample = false;
- itemMeasure.SelColor = Color.Transparent;
- }
- }
- //修改测量区域集合 索引 (添加样品或者切换样品时,将当前工作样品显示在样品孔的最上)
- m_MeasureGDIObjects = OTSSamplespaceGraphicsPanelFun.SelectMeasureIndexIsTop(m_MeasureGDIObjects, sampleName);
- //修改样品集合 索引
- m_SampleGDIObjects = OTSSamplespaceGraphicsPanelFun.SelectSampleIndexIsTop(m_SampleGDIObjects, sampleName);
- }
- #endregion
- //响应委托事件的样品台数据
- public void InitStageDisplay(CStage SStage, CSEMStageData SEMStageData)
- {
- m_visualStage. InitSampleStageData(SStage, SEMStageData,this.Width,this.Height);
- m_GlobalZoomNum = 1;
-
- //清除所有绘制的图形信息
- ClearDrawInfo();
- //绘制样品台信息
- m_visualStage. DrawSampleStage();
-
- //标尺初始化
- RulerInit(m_visualStage.GetOTSSampleStageData());
- //重新绘制
-
-
- //图像隐藏
- HideMessureStatuWindowBSEImage(m_MeasureAppForm);
- //将测量结果信息状态初始化
- InitMeasureStateInfo();
-
- if (m_SampleGDIObjects != null)
- {
- if (m_SampleGDIObjects.Count == 0)
- {
- //将测量状态初始化
- m_MeasureAppForm.m_MessureStatuWindow.SetMeasureStatusInit();
- }
- }
-
- Invalidate();
- }
-
- public void HideMessureStatuWindowBSEImage(OTSIncAMeasureAppForm m_MeasureApps)
- {
- m_MeasureApps.m_MessureStatuWindow.pbBSEImage.Hide();
- }
- #region 将测量状态进度窗口信息初始化
- public void InitMeasureStateInfo()
- {
- m_MeasureAppForm.m_MeasureRetWindow.SetInit();
- }
- #endregion
-
- private void GetTriangleExcenterRadius(PointF px1, PointF px2, PointF px3, out float R, out PointF center)
- {
- float x1, y1, x2, y2, x3, y3;
- float a, b;
- x1 = px1.X;
- y1 = px1.Y;
- x2 = px2.X;
- y2 = px2.Y;
- x3 = px3.X;
- y3 = px3.Y;
- 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)));
- 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)));
- center = new PointF(a, b);
- R = (float)Math.Sqrt((x1 - a) * (x1 - a) + (y1 - b) * (y1 - b));
- }
- private float GetDistance(PointF A, PointF B)
- {
- return (float)Math.Sqrt(Math.Pow((A.X - B.X), 2) + Math.Pow((A.Y - B.Y), 2));
- }
- #region 窗体事件
- private void OTSSamplespaceWindow_Load(object sender, EventArgs e)
- {
-
- m_visualStage = new CVisualStage();
- //样品
- m_SampleGDIObjects = new List<CRectangleGDIObject>();
-
-
- //测量区域
- m_MeasureGDIObjects = new List<CRectangleGDIObject>();
-
- //手绘测量区域
- m_DrawMeasureGDIObjects = new List<CRectangleGDIObject>();
- //帧图
- m_MeasureFieldGDIObjects = new List<CRectangleGDIObject>();
-
- //样品孔BSE图像
- m_ImageGDIObjects = new List<CRectangleGDIObject>();
- //BSE图像帧图为了获取位置与尺寸
- m_ImageOfFieldGDIObjects = new List<CRectangleGDIObject>();
-
- this.ResizeRedraw = true;
- control_Ruler2 = new Control_Ruler();
- Point rulerLocation = new Point(10, this.Height - (int)(control_Ruler2.Height * 2));
- control_Ruler2.Location = rulerLocation;
- this.Controls.Add(control_Ruler2);
- log = NLog.LogManager.GetCurrentClassLogger();
-
- }
- public static void SetShowCMStrip(ContextMenuType IsSelectType, ContextMenuStrip cmStrip, bool IsTrue)
- {
- //鼠标右键选择的类型 0:样品台 1:样品 2:测量区域
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag = (int)MessageState.ShotBSEPicture;
- switch (IsSelectType)
- {
- case ContextMenuType.SampleHoleMenu:
- cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = false;
- cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = false;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = false;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SEMStripSeparator].Enabled = false;
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = false;
- cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = false;
- break;
- case ContextMenuType.SampleMenu:
- cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = false;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = false;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SEMStripSeparator].Enabled = false;
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = true;
- break;
- case ContextMenuType.MeasureMenu:
- cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = true;
-
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag = MessageState.MeasureBSEPicture;
- break;
- case ContextMenuType.FieldMenu:
- cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = true;
-
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag = MessageState.MeasureBSEPicture;
- break;
- case ContextMenuType.ThreadRunMenu:
- for (int i = 0; i < cmStrip.Items.Count; i++)
- {
- cmStrip.Items[i].Enabled = false;
- }
- break;
- case ContextMenuType.SampleStateMenu:
- cmStrip.Items[(int)MenuIndex.AddSample].Enabled = false;
- cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = false;
- cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = false;
- cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = false;
- cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = false;
- break;
- case ContextMenuType.SampleHoleBSEImage:
- cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
- cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
- cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = IsTrue;
- cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = true;
- cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = IsTrue;
- break;
- }
- }
- protected override void OnMouseDown(MouseEventArgs e)
- {
- lblFocus.Focus();
- //记录鼠标按下的位置
- m_P.X = e.X;
- m_P.Y = e.Y;
- m_P1.X = e.X;
- m_P1.Y = e.Y;
- int WH = 2;
- //鼠标点击时的位置
- Point _Point ;
- m_RectangIsDragging = false;
-
- //判断当前是否手绘
- if (m_IsDrawMeasureReady)
- {
- //获取当前的鼠标点击位置
- this.m_MouseDownPoint = new Point(e.X, e.Y);
- //获取当前工作样品
- COTSSample cSample = m_MeasureAppForm.m_ProjParam.GetWorkSample();
- string sampleHoleName = cSample.GetSampleHoleName();
- string sampleName = cSample.GetName();
- int sizeWH = 5;
- Size size = new Size(sizeWH, sizeWH);
- Rectangle rectangle = new Rectangle(m_MouseDownPoint, size);
- //绘制多边形 测量区域
- if (m_DrawMeasureType == CreateRectangleType.Polygon)
- {
- //显示绘制多边形完成标识
- if (m_PolygonPoint.Count > m_PointCount)
- {
- Point startPoint = new Point((int)(m_PolygonPoint[0].X), (int)(m_PolygonPoint[0].Y));
- if (m_IsDrawPolygonFinish)
- {
- DialogResult dResult = MessageBox.Show(table["message10"].ToString(), table["message11"].ToString(), MessageBoxButtons.YesNo);
- if (dResult == DialogResult.Yes)
- {
- m_PolygonPoint.Add(startPoint);
- CreateRectangle createFinishPoint = new CreateRectangle(m_PolygonPoint, CreateRectangleType.Polygon, (ShapeType)m_DrawMeasureType, sampleHoleName, sampleName, Color.Red);
- GraphicsPath PolygonMeasurePath = new GraphicsPath();
- PolygonMeasurePath.AddPolygon(m_PolygonPoint.ToArray());
- createFinishPoint.GPath = PolygonMeasurePath;
- for (int i = 0; i < createFinishPoint.PolygonPointRegionF.Count; i++)
- {
- float X = createFinishPoint.PolygonPointRegionF[i].X / m_GlobalZoomNum;
- float Y = createFinishPoint.PolygonPointRegionF[i].Y / m_GlobalZoomNum;
- PointF DrawPoint = new PointF(X, Y);
- createFinishPoint.DrawPolygonPointRegionF[i] = DrawPoint;
- }
- if (m_DrawMeasureGDIObjects.Count > 0)
- {
- m_DrawMeasureGDIObjects[0] = createFinishPoint;
- }
-
- //清除当前的样品测量区域
- for (int measureIndex = m_MeasureGDIObjects.Count - 1; measureIndex >= 0; measureIndex--)
- {
- if (m_MeasureGDIObjects[measureIndex].SampleName == sampleName)
- {
-
- m_MeasureGDIObjects.RemoveAt(measureIndex);
- break;
- }
- }
- //删除存在的帧图
- for (int singleIndex = m_MeasureFieldGDIObjects.Count - 1; singleIndex >= 0; singleIndex--)
- {
- if (m_MeasureFieldGDIObjects[singleIndex].SampleName == sampleName)
- {
- m_MeasureFieldGDIObjects.RemoveAt(singleIndex);
- }
- }
- //将绘制好的多边形测量区域赋值给 多边形测量区域对象
- if (m_DrawMeasureGDIObjects.Count > 0)
- {
- m_DrawMeasureGDIObjects[0].IsSelect = true;
- m_DrawMeasureGDIObjects[0].IsWorkSample = true;
- //创建多边形外接矩形
- m_DrawMeasureGDIObjects[0].Region = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(m_visualStage.PointConvertPointF(m_DrawMeasureGDIObjects[0].PolygonPointRegion));
- m_DrawMeasureGDIObjects[0].RegionF = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(m_DrawMeasureGDIObjects[0].DrawPolygonPointRegionF);
- m_DrawMeasureGDIObjects[0].DrawRegionF = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(m_DrawMeasureGDIObjects[0].DrawPolygonPointRegionF);
-
- m_DrawMeasureGDIObjects[0].IsWorkSample = true;
- m_MeasureGDIObjects.Add(m_DrawMeasureGDIObjects[0]);
- m_DrawMeasureGDIObjects.Clear();
- m_DrawPolygonFinishGDIObjects.Clear();
- }
-
- var para = m_visualStage.GetSampleMeasurePara(m_MeasureGDIObjects[m_MeasureGDIObjects.Count - 1]);
- m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);
-
- m_MeasureAppForm.m_MessageStates = MessageState.StartMeasure;
- CMeasureThreadWrapper.DoRunType = MSR_THREAD_RunSTATUS.RUNMEASURE;
- //设置工作样品
- m_MeasureAppForm.SwitchWSample(m_SampleSelectName);
- Invalidate();
-
- //设置手绘标识
- m_IsDrawMeasureReady = false;
- m_IsDrawMeasure = false;
- m_IsDrawPolygonFinish = false;
- this.Cursor = Cursors.Default;
- return;
- }
- else
- {
- return;
- }
- }
- }
- //添加多边形点信息
- m_MouseDownPoint = new Point((int)(m_MouseDownPoint.X), (int)(m_MouseDownPoint.Y));
- m_PolygonPoint.Add(m_MouseDownPoint);
- CreateRectangle createPoint = new CreateRectangle(m_PolygonPoint, CreateRectangleType.Polygon, (ShapeType)m_DrawMeasureType, sampleHoleName, sampleName, Color.Red);
- if (m_DrawMeasureGDIObjects.Count > 0)
- {
- m_DrawMeasureGDIObjects[0] = createPoint;
- }
- else
- {
- m_DrawMeasureGDIObjects.Add(createPoint);
- }
- //添加当前绘制的第一点位置,生成多边形测量区域完成标识
- if (m_DrawPolygonFinishGDIObjects.Count == 0)
- {
- int rectSize = m_MinMeasureWidthValue;
- Point PolygonFinishPoint = new Point((int)(m_MouseDownPoint.X - m_MinMeasureWidthValue / 2), (int)(m_MouseDownPoint.Y - m_MinMeasureWidthValue / 2));
- Rectangle pRect = new Rectangle(PolygonFinishPoint, new Size(rectSize, rectSize));
- CreateRectangle createPolygonFinish = new CreateRectangle(pRect, CreateRectangleType.DrawPolygonFinish, sampleHoleName, sampleName, Color.Green);
- m_DrawPolygonFinishGDIObjects.Add(createPolygonFinish);
- }
- return;
- }
- else if(m_DrawMeasureType == CreateRectangleType.CircleByThreePoints)
- {
- //添加多边形点信息
- m_MouseDownPoint = new Point((int)(m_MouseDownPoint.X), (int)(m_MouseDownPoint.Y));
- m_PolygonPoint.Add(m_MouseDownPoint);
- CreateRectangle createPoint = new CreateRectangle(m_PolygonPoint, CreateRectangleType.Polygon, (ShapeType)m_DrawMeasureType, sampleHoleName, sampleName, Color.Red);
- if (m_DrawMeasureGDIObjects.Count > 0)
- {
- m_DrawMeasureGDIObjects[0] = createPoint;
- }
- else
- {
- m_DrawMeasureGDIObjects.Add(createPoint);
- }
- //显示绘制多边形完成标识
- if (m_PolygonPoint.Count == 3)
- {
- //转为圆形这里
- m_DrawMeasureType = (int)CreateRectangleType.Circle;
- float r = 0;
- PointF Centerpoint ;
- GetTriangleExcenterRadius(m_PolygonPoint[0], m_PolygonPoint[1], m_PolygonPoint[2], out r, out Centerpoint);
-
- RectangleF rectangleThree = new RectangleF(new PointF(Centerpoint.X - r, Centerpoint.Y - r), new SizeF(r * 2, r * 2));
-
- //在样品台内部缩放
- if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(rectangleThree))
- {
- m_IsDrawMeasure = true;
- }
- else
- {
- m_IsDrawMeasure = false;
- return;
- }
- Color MeasureColor = Color.Red;
- CreateRectangle createRectangle = new CreateRectangle(rectangleThree, CreateRectangleType.CircleByThreePoints, (ShapeType)m_DrawMeasureType, sampleName, sampleName, MeasureColor);
- //在鼠标点击时添加一个默认大小与位置的图形
-
- createRectangle.RegionF = new RectangleF(createRectangle.RegionF.X / m_GlobalZoomNum, createRectangle.RegionF.Y / m_GlobalZoomNum, createRectangle.RegionF.Width / m_GlobalZoomNum, createRectangle.RegionF.Height / m_GlobalZoomNum);
- createRectangle.DrawRegionF = createRectangle.Region;
- if (m_DrawMeasureGDIObjects.Count > 0)
- {
- m_DrawMeasureGDIObjects[0]=(createRectangle);
- }
- else
- {
- m_DrawMeasureGDIObjects.Add(createRectangle);
- }
- //清除当前的样品测量区域
- for (int measureIndex = m_MeasureGDIObjects.Count - 1; measureIndex >= 0; measureIndex--)
- {
- if (m_MeasureGDIObjects[measureIndex].SampleName == sampleName)
- {
- m_MeasureGDIObjects.RemoveAt(measureIndex);
- break;
- }
- }
- //删除存在的帧图
- for (int singleIndex = m_MeasureFieldGDIObjects.Count - 1; singleIndex >= 0; singleIndex--)
- {
- if (m_MeasureFieldGDIObjects[singleIndex].SampleName == sampleName)
- {
- m_MeasureFieldGDIObjects.RemoveAt(singleIndex);
- }
- }
- m_MeasureGDIObjects.Add(m_DrawMeasureGDIObjects[0]);
- m_DrawMeasureGDIObjects.Clear();
- var para = m_visualStage.GetSampleMeasurePara(m_MeasureGDIObjects[0]);
- m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);
-
- m_MeasureAppForm.m_MessageStates = MessageState.StartMeasure;
- CMeasureThreadWrapper.DoRunType = MSR_THREAD_RunSTATUS.RUNMEASURE;
-
- // 设置工作样品
- m_MeasureAppForm.SwitchWSample(m_SampleSelectName);
- Invalidate();
-
- //设置手绘标识
- m_IsDrawMeasureReady = false;
- this.Cursor = Cursors.Default;
- return;
- }
- return;
- }
- else
- {
- //在样品台内部缩放
- var measureArea = new Rectangle(this.m_MouseDownPoint, new Size(2, 2));
- if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(measureArea))
- {
- m_IsDrawMeasure = true;
- }
- else
- {
- m_IsDrawMeasure = false;
- return;
- }
- Color MeasureColor = Color.Red;
- CreateRectangle createRectangle = new CreateRectangle(rectangle, CreateRectangleType.MeasureArea, (ShapeType)m_DrawMeasureType, sampleName, sampleName, MeasureColor);
- //在鼠标点击时添加一个默认大小与位置的图形
- createRectangle.RegionF = createRectangle.Region;
- createRectangle.DrawRegionF = createRectangle.Region;
- m_DrawMeasureGDIObjects.Add(createRectangle);
- return;
- }
- }
- else
- {
- if (e.Button == MouseButtons.Right)
- {
- if (m_MeasureAppForm.MeasureThreadRunFlag)
- {
-
- SetShowCMStrip(ContextMenuType.ThreadRunMenu, CMStrip, false);
- _Point = this.PointToClient(Cursor.Position);
- this.CMStrip.Show(this, _Point);
- return;
- }
- //获取鼠标右键点击位置
- m_MouseDownLocation = e.Location;
- //显示XY轴
- //m_visualStage.ShowSemCoordvAL(e.Location, m_MeasureAppForm);
- string workSampleName = string.Empty;
- foreach (CRectangleGDIObject item in m_MeasureFieldGDIObjects)
- {
- if (item.IfContains(e.Location))
- {
- //样品孔菜单
-
- _Point = this.PointToClient(Cursor.Position);
- bool IsTrue = false;
- //设置编辑右键菜单项
- foreach (CRectangleGDIObject imageItem in m_ImageGDIObjects)
- {
- if (imageItem.SampleName == item.SampleName)
- {
- IsTrue = true;
- break;
- }
- }
- //设置编辑右键菜单项
- SetShowCMStrip(ContextMenuType.FieldMenu, CMStrip, IsTrue);
- //将删除样品与测量 设置为不可编辑状态
- this.CMStrip.Show(this, _Point);
- return;
- }
- }
- foreach (CRectangleGDIObject item in m_SampleGDIObjects)
- {
- if (item.IsWorkSample)
- {
- workSampleName = item.SampleName;
- break;
- }
- }
- for (int i = m_MeasureGDIObjects.Count - 1; i >= 0; i--)
- {
- foreach (var SampleItem in m_SampleGDIObjects)
- {
- if (m_MeasureGDIObjects[i].SampleName == SampleItem.SampleName)
- {
- bool isSelMeasure = false;
- if (m_MeasureGDIObjects[i].CreateType == CreateRectangleType.Polygon)
- {
- //判断当前位置是否在不规则形状里面
- if (OTSSamplespaceGraphicsPanelFun.PositionPnpoly(m_visualStage.PointFConvertPoint(m_MeasureGDIObjects[i].PolygonPointRegionF), e.Location) && !m_MeasureGDIObjects[i].SelColor.Name.Equals("Transparent"))
- {
- isSelMeasure = true;
- }
- }
- else
- {
- if (m_MeasureGDIObjects[i].IfContains(e.Location) && !m_MeasureGDIObjects[i].SelColor.Name.Equals("Transparent"))
- {
- isSelMeasure = true;
- Rectangle rect = new Rectangle(e.Location, new Size(WH, WH));
-
- if (!m_visualStage.CheckMeasureAreaIsBeyondStageArea(rect))
- {
- break;
- }
- }
- }
- if (isSelMeasure)
- {
- //如果选择的样品不是当前工作样品 则删除原有帧图信息
- if (m_MeasureGDIObjects[i].SampleName != workSampleName)
- {
- ClearImageAndSingleGDIObjects();
- }
- //删除BSE照片
- bool IsTrue = false;
- //设置编辑右键菜单项
- foreach (CRectangleGDIObject imageItem in m_ImageGDIObjects)
- {
- if (imageItem.SampleName == m_MeasureGDIObjects[i].SampleName)
- {
- IsTrue = true;
- break;
- }
- }
-
- //设置编辑右键菜单项
- SetShowCMStrip(ContextMenuType.MeasureMenu, CMStrip, IsTrue);
- _Point = this.PointToClient(Cursor.Position);
- this.CMStrip.Show(this, _Point);
-
- m_SampleHoleSelectName = m_MeasureGDIObjects[i].Name;
- if (m_SampleSelectName != m_MeasureGDIObjects[i].SampleName)
- {
- m_SampleSelectName = m_MeasureGDIObjects[i].SampleName;
- m_MeasureGDIObjects[i].IsSelect = true;
- m_MeasureGDIObjects[i].IsWorkSample = true;
- //设置工作样品
- m_MeasureAppForm.SwitchWSample(m_SampleSelectName);
- Invalidate();
- }
- return;
- }
- }
- }
- }
- foreach (CRectangleGDIObject item in m_ImageGDIObjects)
- {
- if (item.IfContains(e.Location))
- {
- //样品孔菜单
- //m_IsSelectType = ContextMenuType.SampleHoleBSEImage;
- _Point = this.PointToClient(Cursor.Position);
- //设置编辑右键菜单项
- SetShowCMStrip(ContextMenuType.SampleHoleBSEImage, CMStrip, false);
- this.CMStrip.Show(this, _Point);
- return;
- }
- }
- //只点击样品上(测量区域被移动到其他地方)
- for (int i = m_SampleGDIObjects.Count - 1; i >= 0; i--)
- {
- if (m_SampleGDIObjects[i].IfContains(e.Location))
- {
- //如果选择的样品不是当前工作样品 则删除原有帧图信息
- if (m_SampleGDIObjects[i].SampleName != workSampleName)
- {
- ClearImageAndSingleGDIObjects();
- }
- Rectangle rect = new Rectangle(e.Location, new Size(WH, WH));
-
- //样品菜单
- var _IsSelectType =ContextMenuType.SampleMenu;
- //将删除样品与测量 设置为不可编辑状态
- _Point = this.PointToClient(Cursor.Position);
- bool flag = false;
- foreach (var MeasureItem in m_MeasureGDIObjects)
- {
- if (m_SampleGDIObjects[i].SampleName == MeasureItem.SampleName)
- {
- if (MeasureItem.IfContains(e.Location))
- {
- //测量区域菜单
- _IsSelectType = ContextMenuType.MeasureMenu;
-
- break;
- }
- }
- }
- //设置编辑右键菜单项
- SetShowCMStrip(_IsSelectType, CMStrip, flag);
- this.CMStrip.Show(this, _Point);
- if (m_SampleSelectName != m_SampleGDIObjects[i].SampleName)
- {
- m_SampleSelectName = m_SampleGDIObjects[i].SampleName;
- m_SampleHoleSelectName = m_SampleGDIObjects[i].Name;
- m_SampleGDIObjects[i].IsSelect = true;
- m_SampleGDIObjects[i].IsWorkSample = true;
- //设置工作样品 向主窗体发送请求
- m_MeasureAppForm.SwitchWSample(m_SampleSelectName);
- Invalidate();
- }
- return;
- }
- }
- //点击样品孔
-
- CRectangleGDIObject gdiitem;
- if (m_visualStage.IfMouseInSampleHole(e.Location,out gdiitem))
- {
-
-
-
- //样品孔菜单
- //m_IsSelectType = ContextMenuType.SampleHoleMenu;
- _Point = this.PointToClient(Cursor.Position);
- //设置编辑右键菜单项
- SetShowCMStrip(ContextMenuType.SampleHoleMenu, CMStrip, false);
- //将删除样品与测量 设置为不可编辑状态
- this.CMStrip.Show(this, _Point);
-
- m_SampleHoleSelectName = gdiitem.Name;
- gdiitem.IsSelect = true;
- return;
- }
-
-
- if (m_visualStage.IfMouseInStage(e.Location))
- {
- //样品台菜单
- //m_IsSelectType = ContextMenuType.SampleStateMenu;
- //设置编辑右键菜单项
- SetShowCMStrip(ContextMenuType.SampleStateMenu, CMStrip, false);
- _Point = this.PointToClient(Cursor.Position);
- this.CMStrip.Show(this, _Point);
- return;
- }
-
- return;
- }
- //左键点击样品台上
- else
- {
- //如果正在进行测量线程,则退出鼠标点击操作
- if (m_MeasureAppForm.MeasureThreadRunFlag)
- {
- return;
- }
-
- CRectangleGDIObject stageobj;
- if (m_visualStage.IfMouseInStage(e.Location, out stageobj))
- {
- m_RectangIsDragging = true;
- m_IsSelectSampleStage = true;
- stageobj.IsDragging = true;
- stageobj.DraggingPoint = e.Location;
- }
-
- //测量区域
- foreach (CRectangleGDIObject item in m_MeasureGDIObjects)
- {
- if (Control.ModifierKeys == Keys.Control)
- {
- selWSampleMeasureStatus = m_MeasureAppForm.m_ProjParam.GetWorkSampleMeasureStatus();
- if (selWSampleMeasureStatus)
- {
- return;
- }
- //如果选择的测量区域 颜色不是透明 可以选择
- if (!item.SelColor.Name.Equals("Transparent"))
- {
- if (item.CreateType == CreateRectangleType.Polygon)
- {
- if (item.GPath != null)
- {
- //在多边形点附近切换光标
- foreach (PointF itemPoint in item.PolygonPointRegionF)
- {
- if (Math.Abs(itemPoint.X - e.X) <= m_OffsetPX && Math.Abs(itemPoint.Y - e.Y) <= m_OffsetPX)
- {
- if (Control.ModifierKeys == Keys.Control)
- {
- if (m_DrawPolygonFinishGDIObjects != null)
- {
- if (m_DrawPolygonFinishGDIObjects.Count > 0)
- {
- m_DrawPolygonFinishGDIObjects.Clear();
- }
- }
- m_IsSelPolygonPoint = true;
- m_IsCtrl = true;
- m_IsSelectSampleStage = false;
-
-
-
- item.SelColor = Color.Red;
- item.IsDragging = true;
- item.DraggingPoint = e.Location;
- item.IsSelect = true;
- item.IsWorkSample = true;
- //记录选择的多边形点信息
- m_SelPolygonPoint = itemPoint;
- int rectSize = m_MinMeasureWidthValue;
- Point PolygonFinishPoint = new Point((int)(itemPoint.X - m_MinMeasureWidthValue / 2), (int)(itemPoint.Y - m_MinMeasureWidthValue / 2));
- Rectangle pRect = new Rectangle(PolygonFinishPoint, new Size(rectSize, rectSize));
- CreateRectangle createPolygonFinish = new CreateRectangle(pRect, CreateRectangleType.DrawPolygonFinish, "", "", Color.Green);
- if (m_DrawPolygonFinishGDIObjects != null)
- {
- m_DrawPolygonFinishGDIObjects.Add(createPolygonFinish);
- }
- break;
- }
- }
- }
- //如果鼠标已选择多边形的点,跳出循环
- if (item.IsSelect == true)
- {
- break;
- }
- if (item.GPath.IsVisible(e.Location))
- {
- m_IsCtrl = true;
- m_IsSelectSampleStage = false;
-
-
- item.SelColor = Color.Red;
- item.IsDragging = true;
- item.DraggingPoint = e.Location;
- item.IsWorkSample = true;
- item.IsSelect = false;
- break;
- }
- }
- }
- else
- {
- if (item.GPath != null)
- {
- if (item.GPath.IsOutlineVisible((float)e.X, (float)e.Y, new Pen(Color.Gray, m_PenWidth)))
- {
- m_IsCtrl = true;
- m_IsSelectSampleStage = false;
-
-
- item.SelColor = Color.Red;
- item.IsDragging = true;
- item.DraggingPoint = e.Location;
- item.IsSelect = true;
- item.IsWorkSample = true;
- break;
- }
- }
- if (item.IfContains(e.Location))
- {
- m_IsCtrl = true;
- m_IsSelectSampleStage = false;
-
-
- item.SelColor = Color.Red;
- item.IsDragging = true;
- item.DraggingPoint = e.Location;
- item.IsWorkSample = true;
- item.IsSelect = false;
- break;
- }
- }
- }
- }
- }
- //当鼠标点击样品上(测量区域被拖动到其他地方)
- for (int i = m_SampleGDIObjects.Count - 1; i >= 0; i--)
- {
- if ((Control.ModifierKeys == Keys.Alt))
- {
- if (m_SampleGDIObjects[i].IfContains(e.Location))
- {
- m_IsMoveSample = true;
- m_IsSelectSampleStage = false;
- m_IsAlt = true;
- }
- }
- if (!(Control.ModifierKeys == Keys.Control))
- {
- if (m_SampleGDIObjects[i].IfContains(e.Location))
- {
- foreach (var measureItem in m_MeasureGDIObjects)
- {
- if (measureItem.SampleName == m_SampleGDIObjects[i].SampleName)
- {
-
- measureItem.SelColor = Color.Red;
- }
- else
- {
- measureItem.SelColor = Color.Transparent;
- }
- }
- for (int x = 0; x < m_SampleGDIObjects.Count; x++)
- {
- //获取颜色
- string SampleColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
- m_SampleGDIObjects[x].SelColor = ColorTranslator.FromHtml(SampleColorStr);
- m_SampleGDIObjects[x].IsWorkSample = false;
- m_SampleGDIObjects[x].IsSelect = false;
- }
- //设置为工作样品
- m_SampleGDIObjects[i].IsWorkSample = true;
- m_SampleGDIObjects[i].IsSelect = true;
- //获取颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
- m_SampleGDIObjects[i].SelColor = ColorTranslator.FromHtml(ColorStr);
- selectSampleGDIObjects = m_SampleGDIObjects[i];
- if (m_SampleSelectName != m_SampleGDIObjects[i].SampleName)
- {
- //获取工作样品名称
- m_SampleSelectName = m_SampleGDIObjects[i].SampleName;
- //设置工作样品 向主窗体发送请求
- m_MeasureAppForm.SwitchWSample(m_SampleSelectName);
- }
- break;
- }
- }
- }
- MouseDownFunction(m_visualStage.GetAllGDIObject(), e);
- //样品
- MouseDownFunction(m_SampleGDIObjects, e);
- //样品孔
- ;
- //测量
- MouseDownFunction(m_MeasureGDIObjects, e);
- //文字
-
- //帧图
- MouseDownFunction(m_MeasureFieldGDIObjects, e);
-
- //样品台中BSE图片
- MouseDownFunction(m_ImageGDIObjects, e);
- //SEM中心位置
- //MouseDownFunction(m_SEMCenterGDIObjects, e);
- for (int i = m_SampleGDIObjects.Count - 1; i >= 0; i--)
- {
- if (m_SampleGDIObjects[i].IfContains(e.Location) && m_SampleGDIObjects[i].IsWorkSample)
- {
- //获取当前样品与测量区域的位置
- foreach (CRectangleGDIObject item in m_MeasureGDIObjects)
- {
- if (m_SampleGDIObjects[i].SampleName == item.SampleName && m_SampleGDIObjects[i].IsWorkSample)
- {
- m_MeasureToSamplePoint.X = m_SampleGDIObjects[i].Region.X - item.Region.X;
- m_MeasureToSamplePoint.Y = m_SampleGDIObjects[i].Region.Y - item.Region.Y;
- break;
- }
- }
- }
- }
- }
- }
- //重绘控件
- Invalidate();
- }
- protected override void OnMouseMove(MouseEventArgs e)
- {
- //'记录光标拖动的当前点
- m_P1.X = e.X;
- m_P1.Y = e.Y;
-
- //如果正在进行测量线程,则退出鼠标点击操作
- if (m_MeasureAppForm.MeasureThreadRunFlag)
- {
- return;
- }
- //获取选择工作样品的测量状态
- if (selWSampleMeasureStatus)
- {
- return;
- }
- //手动绘制 记录鼠标移动位置
- if (m_IsDrawMeasure)
- {
- this.m_MouseMovePoint = new Point(e.X, e.Y);
- //绘制多边形
- if (m_DrawMeasureType == CreateRectangleType.Polygon)
- {
- PointF startPoint = new PointF();
-
- //显示直线开始点与鼠标当前位置的直线
- if (m_PolygonPoint.Count > 0)
- {
- startPoint = m_PolygonPoint[0];
-
- }
- //显示绘制多边形完成标识
- if (m_PolygonPoint.Count > m_PointCount)
- {
- if (Math.Abs(m_MouseMovePoint.X - startPoint.X) <= m_OffsetPX && Math.Abs(m_MouseMovePoint.Y - startPoint.Y) <= m_OffsetPX)
- {
- //显示绘制多边形完成标识
- m_IsDrawPolygonFinish = true;
- }
- else
- {
- m_IsDrawPolygonFinish = false;
- }
- }
- }
- //圆形三点法
- else if (m_DrawMeasureType == CreateRectangleType.CircleByThreePoints)
- {
- //PointF startPoint = new PointF();
- //PointF endPoint = new PointF();
- //显示直线开始点与鼠标当前位置的直线
- //if (m_PolygonPoint.Count > 0)
- //{
- // startPoint = m_PolygonPoint[0];
- // endPoint = m_PolygonPoint[m_PolygonPoint.Count - 1];
- //}
- }
- else
- {
- if (m_DrawMeasureGDIObjects == null )
- {
- return;
- }
- Rectangle rectangle ;
- foreach (var item in m_DrawMeasureGDIObjects)
- {
- rectangle = item.Region;
- //移动鼠标绘制测量区域
- 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));
- if (tmp == 0)
- {
- tmp = m_DValue;
- }
- //移动鼠标绘制测量区域
- //以中心绘制测量区域方法
-
- OTSSamplespaceGraphicsPanelFun.EnumMousePointPosition enumMouse = OTSSamplespaceGraphicsPanelFun.MousePointPosition(m_MouseDownPoint, m_MouseMovePoint);
- Point LTPoint = new Point();
- Size RBSize = new Size();
- switch (enumMouse)
- {
- case OTSSamplespaceGraphicsPanelFun.EnumMousePointPosition.MouseSizeTopLeft:
- if (m_DrawMeasureType == (int)CreateRectangleType.Circle)
- {
- LTPoint.X = m_MouseDownPoint.X - tmp;
- LTPoint.Y = m_MouseDownPoint.Y - tmp;
- RBSize.Width = tmp;
- RBSize.Height = tmp;
- rectangle = new Rectangle(LTPoint, RBSize);
- }
- else
- {
- LTPoint.X = m_MouseMovePoint.X;
- LTPoint.Y = m_MouseMovePoint.Y;
- RBSize.Width = m_MouseDownPoint.X - m_MouseMovePoint.X;
- RBSize.Height = m_MouseDownPoint.Y - m_MouseMovePoint.Y;
- rectangle = new Rectangle(LTPoint, RBSize);
- }
- break;
- case OTSSamplespaceGraphicsPanelFun.EnumMousePointPosition.MouseSizeTopRight:
- if (m_DrawMeasureType == (int)CreateRectangleType.Circle)
- {
- LTPoint.X = m_MouseDownPoint.X;
- LTPoint.Y = m_MouseDownPoint.Y - tmp;
- RBSize.Width = tmp;
- RBSize.Height = tmp;
- rectangle = new Rectangle(LTPoint, RBSize);
- }
- else
- {
- LTPoint.X = m_MouseDownPoint.X;
- LTPoint.Y = m_MouseDownPoint.Y - (m_MouseDownPoint.Y - m_MouseMovePoint.Y);
- RBSize.Width = m_MouseMovePoint.X - m_MouseDownPoint.X;
- RBSize.Height = m_MouseDownPoint.Y - m_MouseMovePoint.Y;
- rectangle = new Rectangle(LTPoint, RBSize);
- }
- break;
- case OTSSamplespaceGraphicsPanelFun.EnumMousePointPosition.MouseSizeBottomLeft:
- if (m_DrawMeasureType == (int)CreateRectangleType.Circle)
- {
- LTPoint.X = m_MouseDownPoint.X - tmp;
- LTPoint.Y = m_MouseDownPoint.Y;
- RBSize.Width = tmp;
- RBSize.Height = tmp;
- rectangle = new Rectangle(LTPoint, RBSize);
- }
- else
- {
- LTPoint.X = m_MouseDownPoint.X - (m_MouseDownPoint.X - m_MouseMovePoint.X);
- LTPoint.Y = m_MouseDownPoint.Y;
- RBSize.Width = m_MouseDownPoint.X - m_MouseMovePoint.X;
- RBSize.Height = m_MouseMovePoint.Y - m_MouseDownPoint.Y;
- rectangle = new Rectangle(LTPoint, RBSize);
- }
- break;
- case OTSSamplespaceGraphicsPanelFun.EnumMousePointPosition.MouseSizeBottomRight:
- if (m_DrawMeasureType == (int)CreateRectangleType.Circle)
- {
- LTPoint.X = m_MouseDownPoint.X;
- LTPoint.Y = m_MouseDownPoint.Y;
- RBSize.Width = tmp;
- RBSize.Height = tmp;
- rectangle = new Rectangle(LTPoint, RBSize);
- }
- else
- {
- LTPoint.X = m_MouseDownPoint.X;
- LTPoint.Y = m_MouseDownPoint.Y;
- RBSize.Width = m_MouseMovePoint.X - m_MouseDownPoint.X;
- RBSize.Height = m_MouseMovePoint.Y - m_MouseDownPoint.Y;
- rectangle = new Rectangle(LTPoint, RBSize);
- }
- break;
- }
- //在样品台内部缩放
- if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(rectangle))
- {
- //移动鼠标绘制测量区域
- //以中心绘制测量区域方法
-
- item.Region = new Rectangle(LTPoint, RBSize);
- 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));
- item.DrawRegionF = item.RegionF;
- //生成图形路径
- GraphicsPath MeasurePath = new GraphicsPath();
- if (item.CreateType == CreateRectangleType.Rectangle)
- {
- MeasurePath.AddRectangle(item.Region);
- }
- else
- {
- MeasurePath.AddEllipse(item.Region);
- }
- item.GPath = MeasurePath;
- break;
- }
- }
- }
- }
- if (m_RectangIsDragging)
- {
-
- if (!m_IsSelectSampleStage)
- {
- foreach (CRectangleGDIObject item in m_SampleGDIObjects)
- {
- if (!m_IsMeasure)
- {
- if (item.IfContains(e.Location))
- {
- if (item.IsDragging)
- {
- if (item.IsWorkSample)
- {
- if (item.IsSelect)
- {
- //判断移动的样品 是否在样品台尺寸范围内
- foreach (CRectangleGDIObject measureItem in m_MeasureGDIObjects)
- {
- if (measureItem.SampleName == item.SampleName)
- {
- if (measureItem.CreateType == CreateRectangleType.Polygon)
- {
- if (this.Cursor != Cursors.Default)
- {
- return;
- }
- //判断移动的样品 是否在样品台尺寸范围内
- Rectangle rectTemp = item.Region;
- rectTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;
- rectTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;
-
- //判断样品是否超越样品台
- if (!m_visualStage.CheckMeasureAreaIsBeyondStageArea(rectTemp))
- {
- return;
- }
- else
- {
- //生成多边形最小面积外接矩形
- Rectangle rectMeasureTemp = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(measureItem.PolygonPointRegionF);
- //判断多边形是否超越样品台
- rectMeasureTemp.X = rectMeasureTemp.Left + e.X - measureItem.DraggingPoint.X;
- rectMeasureTemp.Y = rectMeasureTemp.Top + e.Y - measureItem.DraggingPoint.Y;
- if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(rectMeasureTemp))
- {
- Rectangle rectSampleTemp = item.Region;
- rectSampleTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;
- rectSampleTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;
- if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(rectSampleTemp))
- {
- MouseMovePolygonMeasureFucntion(measureItem, e);
- OTSSamplespaceGraphicsPanelFun.GetMouseMoveLocation(item, e);
-
- isChange = true;
- }
- }
- }
- }
- else
- {
- Rectangle rectMeasureTemp = measureItem.Region;
- rectMeasureTemp.X = measureItem.Region.Left + e.X - measureItem.DraggingPoint.X;
- rectMeasureTemp.Y = measureItem.Region.Top + e.Y - measureItem.DraggingPoint.Y;
- //判断移动的样品 是否在样品台尺寸范围内
- Rectangle rectTemp = item.Region;
- rectTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;
- rectTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;
-
- //判断样品是否超越样品台
- if (!m_visualStage.CheckMeasureAreaIsBeyondStageArea(rectTemp))
- {
- return;
- }
- //判断测量区域是否超越样品台
- if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(rectMeasureTemp))
- {
- Rectangle rectSampleTemp = item.Region;
- rectSampleTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;
- rectSampleTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;
- if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(rectSampleTemp))
- {
- MouseMoveMeasureFucntion(measureItem, e);
- OTSSamplespaceGraphicsPanelFun.GetMouseMoveLocation(item, e);
-
- isChange = true;
- }
- }
- else
- {
- return;
- }
- }
- }
- }
- }
- m_visualStage.OnMouseMove(item, e);
-
- }
- Invalidate();
- }
- }
- }
- }
- foreach (CRectangleGDIObject item in m_MeasureGDIObjects)
- {
- //检测鼠标光标点是否在路径上
- if (item.IsDragging)
- {
- if (item.IsWorkSample)
- {
- if (item.IsSelect)
- {
- if (item.DraggingPoint != Point.Empty)
- {
- //获取中心点
- Point xy1 =m_visualStage. GetCenterPoint(item.Region);
- //获取鼠标坐标
- Point xy2 = e.Location;
- Rectangle rectTemp ;
-
- if (item.CreateType == CreateRectangleType.Polygon)
- {
- if (m_IsSelPolygonPoint)
- {
- //获取选中点进行移动,代码
- #region MyRegion
- if (Control.ModifierKeys == Keys.Control)
- {
-
- //在多边形点附近切换光标
- for (int i = 0; i < item.PolygonPointRegionF.Count; i++)
- {
- if (item.PolygonPointRegionF[i].X == m_SelPolygonPoint.X && item.PolygonPointRegionF[i].Y == m_SelPolygonPoint.Y)
- {
- //移动点的位置
- Rectangle selPolygonPointRect = new Rectangle(0, 0, 2, 2);
- selPolygonPointRect.X = (int)m_SelPolygonPoint.X + e.X - item.DraggingPoint.X;
- selPolygonPointRect.Y = (int)m_SelPolygonPoint.Y + e.Y - item.DraggingPoint.Y;
- //判断样品是否超越样品台
- if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(selPolygonPointRect))
- {
- if (i == 0 || i == item.PolygonPointRegionF.Count - 1)
- {
- //移动点
- m_SelPolygonPoint = new Point(e.X, e.Y);
- item.PolygonPointRegion[item.PolygonPointRegionF.Count - 1] = new Point((int)m_SelPolygonPoint.X, (int)m_SelPolygonPoint.Y);
- item.PolygonPointRegionF[item.PolygonPointRegionF.Count - 1] = m_SelPolygonPoint;
- item.DrawPolygonPointRegionF[item.PolygonPointRegionF.Count - 1] = new PointF(m_SelPolygonPoint.X / m_GlobalZoomNum, m_SelPolygonPoint.Y / m_GlobalZoomNum);
- item.PolygonPointRegionF[0] = m_SelPolygonPoint;
- item.PolygonPointRegion[0] = new Point((int)m_SelPolygonPoint.X, (int)m_SelPolygonPoint.Y);
- item.PolygonPointRegionF[0] = m_SelPolygonPoint;
- item.DrawPolygonPointRegionF[0] = new PointF(m_SelPolygonPoint.X / m_GlobalZoomNum, m_SelPolygonPoint.Y / m_GlobalZoomNum);
- }
- else
- {
- m_SelPolygonPoint = new Point(e.X, e.Y);
- item.PolygonPointRegion[i] = new Point((int)m_SelPolygonPoint.X, (int)m_SelPolygonPoint.Y);
- item.PolygonPointRegionF[i] = m_SelPolygonPoint;
- item.DrawPolygonPointRegionF[i] = new PointF(m_SelPolygonPoint.X / m_GlobalZoomNum, m_SelPolygonPoint.Y / m_GlobalZoomNum);
- }
- 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));
- 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));
- 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));
- //生成多边形最小面积外接矩形
- Rectangle rectPolygonMeasure = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(item.PolygonPointRegionF);
- item.Region = rectPolygonMeasure;
- item.RegionF = rectPolygonMeasure;
- item.DrawRegionF = rectPolygonMeasure;
- item.DraggingPoint = e.Location;
- break;
- }
- }
- }
- }
- #endregion
- }
- }
- else
- {
- //计算偏离半径
- int a = (xy1.X - xy2.X) * (xy1.X - xy2.X);
- int b = (xy1.Y - xy2.Y) * (xy1.Y - xy2.Y);
- int c = a + b;
- int r = Convert.ToInt32(System.Math.Sqrt(c));
- int width = r * 2;
- rectTemp = new Rectangle(xy1.X - r, xy1.Y - r, width, width);
- //在样品台内部缩放
- if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(rectTemp))
- {
- #region 需抽出作为公共方法
- int xMove = rectTemp.X - item.Region.X;
- int yMove = rectTemp.Y - item.Region.Y;
- int Width = rectTemp.Width - item.Region.Width;
- int Height = rectTemp.Height - item.Region.Height;
- //如果大于最小测量高度 设置图形大小
- if (rectTemp.Width / m_GlobalZoomNum > m_MinMeasureWidthValue)
- {
- item.Region = rectTemp;
- float WidthNew = (float)((item.RegionF.Width + Width / m_GlobalZoomNum));
- float HeightNew = (float)((item.RegionF.Height + Height / m_GlobalZoomNum));
- //设置原测量区域图形大小
- float xMoveNew = (float)((item.RegionF.X + xMove / m_GlobalZoomNum));
- float yMoveNew = (float)((item.RegionF.Y + yMove / m_GlobalZoomNum));
- item.RegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));
- item.DrawRegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));
- item.DraggingPoint = e.Location;
- isChange = true;
- }
- #endregion
- }
- else
- {
- return;
- }
- Invalidate();
- return;
- }
- }
- }
- else
- {
- //鼠标配合Ctrol键 移动单个测量区域
- if (item.CreateType == CreateRectangleType.Polygon)
- {
- //判断是否已存在多边形的点,不能移动多边形
- if (!m_IsSelPolygonPoint)
- {
- if (this.Cursor == Cursors.SizeAll)
- {
- if (item.GPath.IsVisible(e.Location))
- {
- isChange = true;
- MouseMovePolygonMeasureFucntion(item, e);
- }
- }
- }
- }
- else
- {
- if (item.IfContains(e.Location))
- {
- isChange = true;
- MouseMoveMeasureFucntion(item, e);
- }
- }
- }
- }
- }
- }
- }
- //移动样品台
- if (m_IsSelectSampleStage)
- {
- if (m_IsCtrl)
- {
- return;
- }
- if (m_IsAlt)
- {
- return;
- }
- //样品台
- MouseMoveFucntion(m_visualStage.GetAllGDIObject(), e);
-
- //样品
- MouseMoveFucntion(m_SampleGDIObjects, e);
-
- //测量
- MouseMoveFucntion(m_MeasureGDIObjects, e);
-
- //帧图
- if (m_MeasureFieldGDIObjects.Count > 0)
- {
- MouseMoveSingleFucntion(m_MeasureFieldGDIObjects, e);
-
- }
- //样品孔BSE图片
- MouseMoveSingleFucntion(m_ImageGDIObjects, e);
-
- }
- }
- //显示XY轴
- m_visualStage.ShowSemCoordvAL(e.Location, m_MeasureAppForm);
- Invalidate();
- }
-
- protected override void OnMouseUp(MouseEventArgs e)
- {
- //判断当前是否手绘
- if (m_IsDrawMeasure)
- {
-
- //绘制多边形
- if (m_DrawMeasureType != CreateRectangleType.Polygon && m_DrawMeasureType != CreateRectangleType.CircleByThreePoints)
- {
- foreach (var item in m_DrawMeasureGDIObjects)
- {
- for (int i = 0; i < m_MeasureGDIObjects.Count; i++)
- {
- if (item.SampleName == m_MeasureGDIObjects[i].SampleName)
- {
- //获取样品孔名称与其他属性
- item.Name = m_MeasureGDIObjects[i].Name;
-
- item.IsWorkSample = m_MeasureGDIObjects[i].IsWorkSample;
- //删除存在的帧图
- for (int singleIndex = m_MeasureFieldGDIObjects.Count - 1; singleIndex >= 0; singleIndex--)
- {
- if (m_MeasureFieldGDIObjects[singleIndex].SampleName == item.SampleName)
- {
- m_MeasureFieldGDIObjects.RemoveAt(singleIndex);
- }
- }
- m_MeasureGDIObjects[i] = item;
- var para = m_visualStage.GetSampleMeasurePara(item);
- m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);
-
- m_MeasureAppForm.m_MessageStates = MessageState.StartMeasure;
- CMeasureThreadWrapper.DoRunType = MSR_THREAD_RunSTATUS.RUNMEASURE;
- DrawMeasureField();
- break;
-
- }
- }
- }
- //清空绘制测量区域
- if (m_DrawMeasureGDIObjects.Count > 0)
- {
- m_DrawMeasureGDIObjects.Clear();
- }
- this.Cursor = Cursors.Default;
- //设置手绘标识
- m_IsDrawMeasureReady = false;
- m_IsDrawMeasure = false;
- }
- }
- //如果正在进行测量线程,则退出鼠标点击操作
- if (m_MeasureAppForm.MeasureThreadRunFlag)
- {
- return;
- }
- //是否移动至新样品孔
- //int IsContains = 0;
- string HoleName = string.Empty;
- //如果没有选择样品台
- if (!m_IsSelectSampleStage)
- {
- //根据选择工作样品的测量状态,控制操作
- if (selWSampleMeasureStatus)
- {
- return;
- }
- if (isChange)
- {
- foreach (var measureItem in m_MeasureGDIObjects)
- {
- if (measureItem.IsWorkSample)
- {
- if (measureItem.IfContains(e.Location))
- {
- if (isChange == false)
- {
- isChange = true;
- }
- }
- //保存原位置
- Rectangle rectPara = measureItem.Region;
- #region 测量区域与样品中心相差的距离
-
- #endregion
- //获取修改后的测量区域的位置与尺寸
- var para = m_visualStage.GetSampleMeasurePara(measureItem);
- m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);
- //设置图形位置与大小
- measureItem.Region = rectPara;
- //重新绘制测量区域路径
- OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(measureItem, rectPara);
- //恢复光标
- this.Cursor = System.Windows.Forms.Cursors.Default;
-
- if (m_visualStage.IfMouseInStage(e.Location))
- {
- m_IsSelectSampleStage = true;
- }
- else
- {
- m_IsSelectSampleStage = false;
- }
-
- break;
- }
- }
- if (isChange)
- {
- //设置颜色
- if (m_MeasureFieldGDIObjects.Count > 0)
- {
- for (int i = 0; i < m_MeasureFieldGDIObjects.Count; i++)
- {
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SingleColor);
- m_MeasureFieldGDIObjects[i].SelColor = ColorTranslator.FromHtml(ColorStr);
- }
- }
- //切换至测量模式
- m_MeasureAppForm.m_MessageStates = MessageState.StartMeasure;
- CMeasureThreadWrapper.DoRunType = MSR_THREAD_RunSTATUS.RUNMEASURE;
- DrawMeasureField();
- }
- foreach (CRectangleGDIObject item in m_SampleGDIObjects)
- {
- //判断鼠标是否在样品中
- if (item.IfContains(e.Location))
- {
- if (item.IsWorkSample)
- {
- //获取原样品孔名称
- HoleName = item.Name;
-
- var sampleHoleItem = m_visualStage.GetHoleGDIByMousePoint(item.GetCenterPoint());
- //获取样品孔中心点
- if (sampleHoleItem != null)
- {
-
-
- if (item.Name != sampleHoleItem.Name)
- {
- sampleHoleItem.SampleCount += 1;
- //样品孔信息
- item.Name = sampleHoleItem.Name;
- //样品Rectangle
- item.Region = sampleHoleItem.Region;
- item.RegionF = sampleHoleItem.RegionF;
- item.DrawRegionF = sampleHoleItem.DrawRegionF;
- //IsContains++;
- var sampleHoleCountItem = m_visualStage.GetHoleGDIByHoleName(HoleName);
-
- if (sampleHoleCountItem != null)
- {
- if (sampleHoleCountItem.Name == HoleName)
- {
- //减少样品数量
- sampleHoleCountItem.SampleCount -= 1;
- }
- }
-
- }
- }
-
-
- //获取工作样品中的测量区域
- foreach (CRectangleGDIObject measureItem in m_MeasureGDIObjects)
- {
- if (item.SampleName == measureItem.SampleName)
- {
- //设置样品与样品孔名称
- measureItem.Name = item.Name;
- measureItem.SampleName = item.SampleName;
- Rectangle rectPara = item.Region;
- RectangleF rectParaF = item.RegionF;
- if (m_IsMoveSample)
- {
- #region 样品移动至其他样品台后 修改测量区域位置
- rectPara.X = item.Region.X - m_MeasureToSamplePoint.X;
- rectPara.Y = item.Region.Y - m_MeasureToSamplePoint.Y;
- rectPara.Width = measureItem.Region.Width;
- rectPara.Height = measureItem.Region.Height;
- rectParaF.X = rectPara.X / m_GlobalZoomNum;
- rectParaF.Y = rectPara.Y / m_GlobalZoomNum;
- rectParaF.Width = measureItem.RegionF.Width;
- rectParaF.Height = measureItem.RegionF.Height;
- //判断移动到其他样品孔后、当前测量区域是否超越样品台边缘
-
- if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(rectPara))
- {
- measureItem.Region = rectPara;
- measureItem.RegionF = rectParaF;
- measureItem.DrawRegionF = rectParaF;
- }
- #endregion
- }
-
- //获取修改后的测量区域的位置与尺寸
-
- var para = m_visualStage.GetSampleMeasurePara(measureItem);
- m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);
-
- //设置测量区域信息
- measureItem.SampleName = item.SampleName;
- measureItem.Name = item.Name;
- //将所有帧图移动测量区域位置中
- //获取样品孔 与 样品名称
- foreach (var SampleItem in m_SampleGDIObjects)
- {
- if (item.IsWorkSample)
- {
- //设置工作样品的测量区域 存在帧图
- foreach (var MeasureItem in m_MeasureGDIObjects)
- {
- if (MeasureItem.SampleName == item.SampleName)
- {
- //设置工作样品的测量区域 存在帧图标识
- if (m_MeasureFieldGDIObjects.Count > 0)
- {
- OTSSamplespaceGraphicsPanelFun.SetSingleLocationToMeasureLocation(m_MeasureFieldGDIObjects, MeasureItem);
- }
- }
- }
- }
- }
- //更新Grid 工作样品属性值
- m_MeasureAppForm.UpdateTreeSampleAndGridSampleVal();
- Invalidate();
- break;
-
- }
- }
- }
- }
- if (item.IsWorkSample)
- {
- //设置颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
- item.SelColor = ColorTranslator.FromHtml(ColorStr);
- }
- }
- isChange = false;
- }
- //移动多边形的点后,显示已获取的帧图
- if (m_IsSelPolygonPoint)
- {
- foreach (var measureItem in m_MeasureGDIObjects)
- {
- if (measureItem.IsWorkSample)
- {
- var para = m_visualStage.GetSampleMeasurePara(measureItem);
- m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);
-
- if (measureItem.IsWorkSample)
- {
- DrawMeasureField();
- }
-
- }
- }
- }
- Invalidate();
- }
- //样品台
- MouseUpFucntion(m_visualStage.GetAllGDIObject(), e);
- //样品
- MouseUpFucntion(m_SampleGDIObjects, e);
-
- //测量
- MouseUpFucntion(m_MeasureGDIObjects, e);
- //测量路径
- //MouseUpFucntion(m_MeasurePathGDIObjects, e);
-
- //帧图
- MouseUpFucntion(m_MeasureFieldGDIObjects, e);
- //已获取的帧图
- //MouseUpFucntion(m_AllFieldGDIObjects, e);
- //样品孔中BSE图片
- MouseUpFucntion(m_ImageGDIObjects, e);
- //SEM中心位置
- //MouseUpFucntion(m_SEMCenterGDIObjects, e);
- //撤回原样品孔中
- //if (IsContains == 0)
- //{
- // foreach (var item in m_SampleGDIObjects)
- // {
-
- // //鼠标按下事件中获取选择的样品原有位置
- // //如果没有找到其他样品孔的中心点,则将移动的样品设置为原位置
- // foreach (CRectangleGDIObject sampleHoleItems in m_visualStage. m_SampleHoleGDIObjects)
- // {
- // if (sampleHoleItems.SampleCount > 0)
- // {
- // if (item.IsWorkSample)
- // {
- // //设置颜色
- // string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
- // item.SelColor = ColorTranslator.FromHtml(ColorStr);
- // if (selectSampleGDIObjects != null)
- // {
- // if (sampleHoleItems.Name == selectSampleGDIObjects.Name && item.SampleName == selectSampleGDIObjects.SampleName)
- // {
- // item.Region = sampleHoleItems.Region;
- // Invalidate();
- // break;
- // }
- // }
- // }
- // }
- // }
-
- // //获取帧图与测量区域的相差的位置
- // int m_singleDiffX = 0;
- // int m_singleDiffY = 0;
- // //如果当前样品没有移动至其他样品孔 测量区域恢复原位置
- // if (m_IsMoveSample)
- // {
- // if (item.IsWorkSample)
- // {
- // foreach (var measureItem in m_MeasureGDIObjects)
- // {
- // if (measureItem.SampleName == item.SampleName)
- // {
- // //获取测量区域与样品之间相差的距离
- // if (m_MeasureFieldGDIObjects.Count > 0)
- // {
- // m_singleDiffX = measureItem.Region.X - item.Region.X + m_MeasureToSamplePoint.X;
- // m_singleDiffY = measureItem.Region.Y - item.Region.Y + m_MeasureToSamplePoint.Y;
- // }
- // RectangleF rectParaF = item.RegionF;
- // Rectangle rectPara = item.Region;
- // rectPara.X = item.Region.X - m_MeasureToSamplePoint.X;
- // rectPara.Y = item.Region.Y - m_MeasureToSamplePoint.Y;
- // rectPara.Width = measureItem.Region.Width;
- // rectPara.Height = measureItem.Region.Height;
- // measureItem.Region = rectPara;
- // rectParaF.X = rectPara.X / m_GlobalZoomNum;
- // rectParaF.Y = rectPara.Y / m_GlobalZoomNum;
- // rectParaF.Width = measureItem.RegionF.Width;
- // rectParaF.Height = measureItem.RegionF.Height;
- // measureItem.RegionF = rectParaF;
- // measureItem.DrawRegionF = rectParaF;
- // break;
- // }
- // }
- // //将帧图恢复至原位置
- // foreach (var singleItem in m_MeasureFieldGDIObjects)
- // {
- // if (singleItem.SampleName == item.SampleName)
- // {
- // RectangleF rectParaDrawF = singleItem.DrawRegionF;
- // RectangleF rectParaF = singleItem.RegionF;
- // Rectangle rectPara = singleItem.Region;
- // rectPara.X = singleItem.Region.X - m_singleDiffX;
- // rectPara.Y = singleItem.Region.Y - m_singleDiffY;
- // rectPara.Width = singleItem.Region.Width;
- // rectPara.Height = singleItem.Region.Height;
- // singleItem.Region = rectPara;
- // //更改帧图RegionF
- // rectParaF.X = singleItem.RegionF.X - m_singleDiffX;
- // rectParaF.Y = singleItem.RegionF.Y - m_singleDiffY;
- // singleItem.RegionF = rectParaF;
- // //更改帧图绘制原位置DrawRegionF
- // rectParaDrawF.X = (rectParaDrawF.X - m_singleDiffX / m_GlobalZoomNum);
- // rectParaDrawF.Y = (rectParaDrawF.Y - m_singleDiffY / m_GlobalZoomNum);
- // rectParaDrawF.Width = rectParaDrawF.Width;
- // rectParaDrawF.Height = rectParaDrawF.Height;
- // singleItem.DrawRegionF = rectParaDrawF;
- // }
- // }
-
- // }
- // }
- // }
- //}
- m_IsMoveSample = false;
- m_MeasureToSamplePoint = new Point();
-
- m_IsCtrl = false;
- m_IsAlt = false;
- m_IsSelPolygonPoint = false;
- selWSampleMeasureStatus = false;
- }
- protected override void OnPaint(PaintEventArgs e)//处理重绘情况
- {
- OnPaint(e,m_visualStage.GetAllGDIObject());
- OnPaint(e, m_SampleGDIObjects);
- //切换显示样品孔中的文字
- //if (IsShowSampleHoleFont)
- //{
- // OnPaint(e, m_visualStage.m_ContentGDIObjects);
- //}
- //切换显示样品孔中的BSE图片
- if (IsShowSampleHoleImage)
- {
- if (m_ImageGDIObjects != null)
- {
- if (m_ImageGDIObjects.Count > 0)
- {
- OnPaint(e, m_ImageGDIObjects);
- }
- }
- }
-
- if (m_MeasureFieldGDIObjects != null)
- {
- if (m_MeasureFieldGDIObjects.Count > 0)
- {
- OnPaint(e, m_MeasureFieldGDIObjects);
- }
- }
-
- //手动绘制测量区域
- if (m_DrawMeasureGDIObjects != null)
- {
- if (m_DrawMeasureGDIObjects.Count > 0)
- {
- for (int i = 0; i < m_DrawMeasureGDIObjects.Count; i++)
- {
- if (m_DrawMeasureGDIObjects[i] != null)
- {
- m_DrawMeasureGDIObjects[i].EndPoint = this.m_MouseMovePoint;
- m_DrawMeasureGDIObjects[i].OnPaint(e);
- }
- }
- }
- }
- OnPaint(e, m_MeasureGDIObjects);
-
- if (m_IsDrawPolygonFinish || m_IsSelPolygonPoint)
- {
- OnPaint(e, m_DrawPolygonFinishGDIObjects);
- }
- }
- public void OnPaint(PaintEventArgs e, List<CRectangleGDIObject> m_ObjectGDIObjects)//处理重绘情况
- {
- foreach (CRectangleGDIObject item in m_ObjectGDIObjects)
- {
- if (item != null)
- {
- item.OnPaint(e);
- }
- }
- }
- protected override void OnMouseWheel(MouseEventArgs e)
- {
- //如果正在进行测量线程,则退出鼠标点击操作
- if (m_MeasureAppForm.MeasureThreadRunFlag)
- {
- return;
- }
- base.OnMouseWheel(e);
- //设置记录每次比例缩放后的总体比例系数
- if (e.Delta > 0)
- {
- m_GlobalZoomNum += 0.1f;
- }
- else
- {
- m_GlobalZoomNum -= 0.1f;
- if (m_GlobalZoomNum < 1)
- {
- m_GlobalZoomNum = 1;
- }
- }
- if (e.Delta > 0)
- {
- #region 计算标尺尺寸部份-----放大------
- //计算标尺实际占用像素的宽度
- f_ruler_size = f_old_ruler_size * m_GlobalZoomNum;
- control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);
- control_Ruler2.Value = 1;
-
- //放大过长时,这里将宽度与代表的实际宽度进行折半显示
- while (control_Ruler2.Width > 300)
- {
- control_Ruler2.RulerWidth = Convert.ToInt32(control_Ruler2.RulerWidth) / 2;
- control_Ruler2.Value = control_Ruler2.Value * 2;
- }
- control_Ruler2.SetValue(control_Ruler2.RulerWidth, control_Ruler2.Value.ToString());
- #endregion
-
- }
- else
- {
- if (m_GlobalZoomNum >= f_zoom_mix)
- {
- #region 计算标尺尺寸部份-----缩小
- f_ruler_size =f_old_ruler_size * m_GlobalZoomNum;
- control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);
- control_Ruler2.Value = 1;
-
- while (control_Ruler2.Width > 300)
- {
- control_Ruler2.RulerWidth = Convert.ToInt32(control_Ruler2.RulerWidth) / 2;
- control_Ruler2.Value = control_Ruler2.Value * 2;
- }
- control_Ruler2.SetValue(control_Ruler2.RulerWidth, control_Ruler2.Value.ToString());
- #endregion
- }
- }
- if (m_GlobalZoomNum >= 1)
- {
-
- //恢复图像初始位置
- OTSSamplespaceGraphicsPanelFun.RestoreInitialPosition(m_MeasureFieldGDIObjects, m_GlobalZoomNum);
- OTSSamplespaceGraphicsPanelFun.RestoreInitialPosition(m_ImageGDIObjects, m_GlobalZoomNum);
- //样品
- OTSSamplespaceGraphicsPanelFun.MouseWheelFunction(m_SampleGDIObjects,m_visualStage.GetEdgeGDIObj(), m_GlobalZoomNum);
- //样品孔
- OTSSamplespaceGraphicsPanelFun.MouseWheelFunction(m_visualStage.GetAllGDIObject(), m_visualStage.GetEdgeGDIObj(), m_GlobalZoomNum);
- //测量区域
- OTSSamplespaceGraphicsPanelFun.MouseWheelFunction(m_MeasureGDIObjects,m_visualStage.GetEdgeGDIObj(), m_GlobalZoomNum);
-
- if (m_GlobalZoomNum == 1)
- {
- // 将绘制的样品台信息 按屏幕中心移动
- //获取当前样品台中心点
- Point samplePoint = m_visualStage.GetCenterPoint();
- //获取当前工作区域中心点
- Point workAreaPoint = m_visualStage.GetCenterPoint(this.ClientRectangle);
- //计算样品台中心点与工作区域中心点相差的距离
- PointF distancePoint = new PointF(samplePoint.X - workAreaPoint.X, samplePoint.Y - workAreaPoint.Y);
- if (distancePoint.X != 0 || distancePoint.Y != 0)
- {
- MoveToSrceenCenterFunction(distancePoint);
- }
- //标尺恢复初始
- f_ruler_size = f_old_ruler_size;
- control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);
- control_Ruler2.ShowString = "1mm";
- control_Ruler2.SetValue(control_Ruler2.RulerWidth);
- }
- //重新绘制
- Invalidate();
-
- }
- }
- #endregion
- #region 鼠标方法操作
- public void MouseDownFunction(List<CRectangleGDIObject> objList, MouseEventArgs e)
- {
- foreach (CRectangleGDIObject item in objList)
- {
- item.IsDragging = true;
- item.DraggingPoint = e.Location;
- }
- }
- public void MouseMoveFucntion(List<CRectangleGDIObject> objList, MouseEventArgs e)
- {
- foreach (CRectangleGDIObject item in objList)
- {
- if (item.IsDragging)
- {
- item.Region = new Rectangle(
- item.Region.Left + Convert.ToInt32((e.X - item.DraggingPoint.X)),
- item.Region.Top + Convert.ToInt32((e.Y - item.DraggingPoint.Y)),
- item.Region.Width,
- item.Region.Height);
- item.RegionF = new RectangleF(
- item.RegionF.Left + (float)(e.X - item.DraggingPoint.X) / m_GlobalZoomNum,
- item.RegionF.Top + (float)(e.Y - item.DraggingPoint.Y) / m_GlobalZoomNum,
- item.RegionF.Width,
- item.RegionF.Height);
- item.DrawRegionF = new RectangleF(
- item.DrawRegionF.Left + (float)(e.X - item.DraggingPoint.X),
- item.DrawRegionF.Top + (float)(e.Y - item.DraggingPoint.Y),
- item.DrawRegionF.Width,
- item.DrawRegionF.Height);
- item.LineStartPoint = new PointF(
- item.Region.Left + (e.X - item.DraggingPoint.X),
- item.Region.Top + (e.Y - item.DraggingPoint.Y));
- item.BSEImageLocation = new PointF(
- item.BSEImageLocation.X + e.X - item.DraggingPoint.X,
- item.BSEImageLocation.Y + e.Y - item.DraggingPoint.Y);
- //移动SEM中心点位置
- item.SEMCenterPoint = new PointF(
- item.SEMCenterPoint.X + (e.X - item.DraggingPoint.X),
- item.SEMCenterPoint.Y + (e.Y - item.DraggingPoint.Y));
- //多边形样品台移动
- if (item.Shape == (ShapeType)CreateRectangleType.Polygon)
- {
- if (item.DrawPolygonPointRegionF != null)
- {
- if (item.DrawPolygonPointRegionF.Count > 0)
- {
- int polygonPointCount = item.DrawPolygonPointRegionF.Count;
- if (polygonPointCount > 0)
- {
- for (int pointIndex = 0; pointIndex < polygonPointCount; pointIndex++)
- {
- item.PolygonPointRegion[pointIndex] = new Point(
- item.PolygonPointRegion[pointIndex].X + Convert.ToInt32((e.X - item.DraggingPoint.X)),
- item.PolygonPointRegion[pointIndex].Y + Convert.ToInt32((e.Y - item.DraggingPoint.Y)));
- item.PolygonPointRegionF[pointIndex] = new PointF(
- item.PolygonPointRegionF[pointIndex].X + (float)(e.X - item.DraggingPoint.X),
- item.PolygonPointRegionF[pointIndex].Y + (float)(e.Y - item.DraggingPoint.Y));
- //2020-12-1日注释
- item.DrawPolygonPointRegionF[pointIndex] = new PointF(
- item.DrawPolygonPointRegionF[pointIndex].X + (float)(e.X - item.DraggingPoint.X) / m_GlobalZoomNum,
- item.DrawPolygonPointRegionF[pointIndex].Y + (float)(e.Y - item.DraggingPoint.Y) / m_GlobalZoomNum);
- }
- }
- }
- }
- }
- item.DraggingPoint = e.Location;
- //重新绘制测量区域路径
- OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(item, item.Region);
- }
- }
- }
- public void MouseMoveMeasureFucntion(CRectangleGDIObject item, MouseEventArgs e)
- {
- //判断移动的样品 是否在样品台尺寸范围内
- Rectangle rectTemp = item.Region;
- rectTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;
- rectTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;
-
- if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(rectTemp))
- {
- #region 需抽出作为公共方法
- int xMove = rectTemp.X - item.Region.X;
- int yMove = rectTemp.Y - item.Region.Y;
- int Width = rectTemp.Width - item.Region.Width;
- int Height = rectTemp.Height - item.Region.Height;
- //设置图形大小
- item.Region = rectTemp;
- int WidthNew = (int)((item.RegionF.Width + Width / m_GlobalZoomNum));
- int HeightNew = (int)((item.RegionF.Height + Height / m_GlobalZoomNum));
- //设置原测量区域图形大小
- float xMoveNew = (float)((item.RegionF.X + (xMove / m_GlobalZoomNum)));
- float yMoveNew = (float)((item.RegionF.Y + (yMove / m_GlobalZoomNum)));
- item.RegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));
- item.DrawRegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));
- item.DraggingPoint = e.Location;
- #endregion
- //重新绘制测量区域路径
- OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(item, item.Region);
- //帧图
- MouseMoveSingleFucntion(m_MeasureFieldGDIObjects, e);
- Invalidate();
- return;
- }
- }
- public void MouseMovePolygonMeasureFucntion(CRectangleGDIObject item, MouseEventArgs e)
- {
- //多边形样品台移动
- if (item.CreateType == CreateRectangleType.Polygon)
- {
- //判断样品台形状
-
- //生成多边形最小面积外接矩形
- Rectangle rectMeasureTemp = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(item.PolygonPointRegionF);
- //判断多边形是否超越样品台
- rectMeasureTemp.X = rectMeasureTemp.Left + e.X - item.DraggingPoint.X;
- rectMeasureTemp.Y = rectMeasureTemp.Top + e.Y - item.DraggingPoint.Y;
- if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(rectMeasureTemp))
- {
- int polygonPointCount = item.DrawPolygonPointRegionF.Count;
- if (polygonPointCount > 0)
- {
- for (int pointIndex = 0; pointIndex < polygonPointCount; pointIndex++)
- {
- item.PolygonPointRegion[pointIndex] = new Point(
- item.PolygonPointRegion[pointIndex].X + Convert.ToInt32((e.X - item.DraggingPoint.X)),
- item.PolygonPointRegion[pointIndex].Y + Convert.ToInt32((e.Y - item.DraggingPoint.Y)));
- item.PolygonPointRegionF[pointIndex] = new PointF(
- item.PolygonPointRegionF[pointIndex].X + (float)(e.X - item.DraggingPoint.X),
- item.PolygonPointRegionF[pointIndex].Y + (float)(e.Y - item.DraggingPoint.Y));
- item.DrawPolygonPointRegionF[pointIndex] = new PointF(
- item.DrawPolygonPointRegionF[pointIndex].X + (float)(e.X - item.DraggingPoint.X) / m_GlobalZoomNum,
- item.DrawPolygonPointRegionF[pointIndex].Y + (float)(e.Y - item.DraggingPoint.Y) / m_GlobalZoomNum);
- }
- Rectangle rectTemp = item.Region;
- rectTemp.X = item.Region.Left + e.X - item.DraggingPoint.X;
- rectTemp.Y = item.Region.Top + e.Y - item.DraggingPoint.Y;
- #region 需抽出作为公共方法
- int xMove = rectTemp.X - item.Region.X;
- int yMove = rectTemp.Y - item.Region.Y;
- int Width = rectTemp.Width - item.Region.Width;
- int Height = rectTemp.Height - item.Region.Height;
- //设置图形大小
- item.Region = rectTemp;
- int WidthNew = (int)((item.RegionF.Width + Width / m_GlobalZoomNum));
- int HeightNew = (int)((item.RegionF.Height + Height / m_GlobalZoomNum));
- //设置原测量区域图形大小
- float xMoveNew = (float)((item.RegionF.X + (xMove / m_GlobalZoomNum)));
- float yMoveNew = (float)((item.RegionF.Y + (yMove / m_GlobalZoomNum)));
-
- item.RegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));
- item.DrawRegionF = new RectangleF(new PointF(xMoveNew, yMoveNew), new SizeF(WidthNew, HeightNew));
- item.DraggingPoint = e.Location;
- #endregion
-
- }
- item.DraggingPoint = e.Location;
- //重新绘制测量区域路径
- OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(item, item.Region);
- //帧图
- MouseMoveSingleFucntion(m_MeasureFieldGDIObjects, e);
- }
- }
-
- Invalidate();
- return;
- }
- public bool MoveMeasureInStage(CRectangleGDIObject item, Point m_StageCenterPoint, Point semLocation, double m_GlobalZoomNum)
- {
- //判断测量区域移动到SEM的当前位置 是否在样品台尺寸范围内
- Rectangle rectTemp = item.Region;
- rectTemp.X = m_StageCenterPoint.X + semLocation.X;// - rectTemp.Width / 2;
- rectTemp.Y = m_StageCenterPoint.Y - semLocation.Y;// - rectTemp.Height/ 2;
- rectTemp.Width = 2;
- rectTemp.Height = 2;
-
- if (!m_visualStage.CheckMeasureAreaIsBeyondStageArea(rectTemp))
- {
- return false;
- }
- return true;
- }
- public void MouseMoveSingleFucntion(List<CRectangleGDIObject> objList, MouseEventArgs e)
- {
- foreach (CRectangleGDIObject item in objList)
- {
- if (item.IsDragging)
- {
- item.Region = new Rectangle(
- item.Region.Left + e.X - item.DraggingPoint.X,
- item.Region.Top + e.Y - item.DraggingPoint.Y,
- item.Region.Width,
- item.Region.Height);
- item.RegionF = new RectangleF(
- item.RegionF.Left + (e.X - item.DraggingPoint.X),
- item.RegionF.Top + (e.Y - item.DraggingPoint.Y),
- item.RegionF.Width,
- item.RegionF.Height);
- item.DrawRegionF = new RectangleF(
- item.DrawRegionF.Left + (e.X - item.DraggingPoint.X) / m_GlobalZoomNum,
- item.DrawRegionF.Top + (e.Y - item.DraggingPoint.Y) / m_GlobalZoomNum,
- item.DrawRegionF.Width,
- item.DrawRegionF.Height);
- item.LineStartPoint = new PointF(
- item.Region.Left + (e.X - item.DraggingPoint.X),
- item.Region.Top + (e.Y - item.DraggingPoint.Y));
- item.DraggingPoint = e.Location;
- //重新绘制测量区域路径
- OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(item, item.Region);
- }
- }
- }
- public void MouseUpFucntion(List<CRectangleGDIObject> objList, MouseEventArgs e)
- {
- foreach (CRectangleGDIObject item in objList)
- {
- if (item.IsDragging)
- {
- item.IsSelect = false;
- item.IsDragging = false;
- item.DraggingPoint = Point.Empty;
-
- }
- }
- }
- public void SizeChangeFucntion(List<CRectangleGDIObject> objList, float Zoom)
- {
- foreach (CRectangleGDIObject item in objList)
- {
- float x = item.RegionF.X * Zoom;
- float y = item.RegionF.Y * Zoom;
- float widthRect = item.RegionF.Width * Zoom;
- float heightRect = item.RegionF.Height * Zoom;
- //改变窗体时,修改图形位置与大小
- item.Region = new Rectangle((int)x, (int)y, (int)widthRect, (int)heightRect);
- item.RegionF = new RectangleF(x, y, widthRect, heightRect);
- item.DrawRegionF = new RectangleF(x, y, widthRect, heightRect);
- }
- }
- public void SizeFChangeFucntion(List<CRectangleGDIObject> objList, float Zoom)
- {
- foreach (CRectangleGDIObject item in objList)
- {
- float x = item.DrawRegionF.X * Zoom;
- float y = item.DrawRegionF.Y * Zoom;
- float widthRect = item.DrawRegionF.Width * Zoom;
- float heightRect = item.DrawRegionF.Height * Zoom;
- //改变窗体时,修改图形位置与大小
- item.Region = new Rectangle((int)x, (int)y, (int)widthRect, (int)heightRect);
- item.RegionF = new RectangleF(x, y, widthRect, heightRect);
- item.DrawRegionF = new RectangleF(x, y, widthRect, heightRect);
- }
- }
- /// <summary>
- /// 将绘制的样品台信息 按屏幕中心移动
- /// </summary>
- public void MoveToSrceenCenterFunction(PointF distancePoint)
- {
- if (distancePoint.X != 0 || distancePoint.Y != 0)
- {
- //循环样品台上的图形,将其按工作区域中心点移动
- MoveLocationToSrceenCenterFunction(m_visualStage.GetAllGDIObject(), distancePoint);
-
- MoveLocationToSrceenCenterFunction(m_SampleGDIObjects, distancePoint);
-
- MoveLocationToSrceenCenterFunction(m_MeasureGDIObjects, distancePoint);
-
- MoveLocationToSrceenCenterFunction(m_MeasureFieldGDIObjects, distancePoint);
- MoveLocationToSrceenCenterFunction(m_ImageGDIObjects, distancePoint);
- }
- }
- public void MoveLocationToSrceenCenterFunction(List<CRectangleGDIObject> objList, PointF distancePoint)
- {
- foreach (var item in objList)
- {
- if (item.Shape == (ShapeType)CreateRectangleType.Polygon)
- {
- for (int i = 0; i < item.PolygonPointRegion.Count; i++)
- {
- item.PolygonPointRegion[i] = new Point((int)(item.PolygonPointRegion[i].X - distancePoint.X), (int)(item.PolygonPointRegion[i].Y - distancePoint.Y));
- item.PolygonPointRegionF[i] = new PointF(item.PolygonPointRegionF[i].X - distancePoint.X, (item.PolygonPointRegionF[i].Y - distancePoint.Y));
- item.DrawPolygonPointRegionF[i] = new PointF(item.DrawPolygonPointRegionF[i].X - distancePoint.X, (item.DrawPolygonPointRegionF[i].Y - distancePoint.Y));
- }
- }
- item.Region = new Rectangle((int)((item.Region.X - distancePoint.X)), (int)(item.Region.Y - distancePoint.Y), item.Region.Width, item.Region.Height);
- item.RegionF = new RectangleF((item.RegionF.X - distancePoint.X), (item.RegionF.Y - distancePoint.Y), item.RegionF.Width, item.RegionF.Height);
- item.DrawRegionF = new RectangleF((item.DrawRegionF.X - distancePoint.X), (item.DrawRegionF.Y - distancePoint.Y), item.DrawRegionF.Width, item.DrawRegionF.Height);
- item.BSEImageWitdh = item.Region.Width;
- item.BSEImageHeight = item.Region.Height;
- item.BSEImageLocation = item.Region.Location;
- //重新绘制测量区域路径
- OTSSamplespaceGraphicsPanelFun.UpdateMeasureGraphicsPath(item, item.Region);
- }
- }
- #endregion
- #region 菜单操作
- private void CMStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
- {
- Point mousePoint = this.PointToClient(Control.MousePosition);
- CMStrip.Hide();
- switch (e.ClickedItem.Name)
- {
- case "AddStage":
- m_MeasureAppForm.m_SPropertyWindows.TSSaveAs.Enabled = true;
- m_MeasureAppForm.m_SPropertyWindows.TSLoad.Enabled = true;
- m_MeasureAppForm.m_SPropertyWindows.TSEdit.Enabled = false;
- m_MeasureAppForm.m_SPropertyWindows.TSEdit.Visible = false;
- //添加样品
- m_MeasureAppForm.AddNewSampleMeasure(m_SampleHoleSelectName);
- break;
- case "DeleteStage":
- //删除样品
- OTSSamplespaceGraphicsPanelFun.DeleteSampleInfo(m_MeasureAppForm, m_SampleSelectName);
- break;
- case "DriveSEMToCenterLocation":
- //驱动SEM到中心位置
- SetSEMToCenterPoint();
- break;
- case "DriveSEMToCurrentLocation":
- //驱动SEM到当前位置
- SetSEMCurrentLocation();
- break;
- case "SetSEMCenterLocation":
- //将测量区域移到SEM当前位置
- SetMeasureToSEMLocation();
-
- break;
- case "ReadSEMData":
- m_MeasureAppForm.m_MessageStates = MessageState.StartMeasure;
- //设定SEM数据
- CMeasureThreadWrapper.DoRunType = MSR_THREAD_RunSTATUS.RUNMEASURE;
- GetSEMData();
-
- break;
- case "SetSemData":
- double SemMag = 0;
- double dDistance = 0;
- if (m_MeasureAppForm.m_ProjParam.GetMagAndDistance(ref SemMag, ref dDistance))
- {
- //设置SEM数据
-
- if (!SetSEMDATAMParameter(SemMag, dDistance))
- {
- log.Error("Failed SetSemData:--Mag:" + SemMag + "--Distance:" + dDistance + "--");
- }
- }
- break;
- case "ShootBSEPicture":
- //设置消息类型 拍摄样品孔
- m_MeasureAppForm.m_MessageStates = MessageState.ShotBSEPicture;
- //清除原图片信息
- DeleteHoleBSEImageDataNoMessageBox();
-
- GetBSEPictures();
- break;
- case "DeleteBSEPicture":
- DeleteHoleBSEImageData();
- break;
- case "SlopFocusMenuItem":
- if (slopFocus == null)
- {
- slopFocus = new _5_OTSMeasureStatuImageFun.SlopFocus(this);
- }
-
- slopFocus.Show();
-
- break;
- }
- }
- public bool setSlopFocusParam(_5_OTSMeasureStatuImageFun.SlopFocus slopFocus)
- {
- if (slopFocus == null)
- {
- return false;
- }
- else
- {
- m_MeasureAppForm.m_ProjParam.GetWorkSample().GetMsrParams().SlopParam = slopFocus.GetCSlopFocusParam();
- return true;
- }
- }
- protected override bool ProcessDialogKey(Keys keyData)
- {
- if (keyData == Keys.Up || keyData == Keys.Down || keyData == Keys.Left || keyData == Keys.Right)
- {
- return false;
- }
- else
- {
- return base.ProcessDialogKey(keyData);
- }
- }
- private void OTSSamplespaceWindow_KeyDown(object sender, KeyEventArgs e)
- {
- KeyDowns();
- }
- private void OTSSamplespaceWindow_KeyUp(object sender, KeyEventArgs e)
- {
- //键盘抬起时,将选择区域的标识 设置为未选择状态
- m_IsMeasure = false;
- this.Cursor = System.Windows.Forms.Cursors.Default;
- //删除正在绘制的多边形的点
- if (e.KeyValue == (int)Keys.Back)
- {
- if (m_IsDrawMeasure)
- {
- if (m_PolygonPoint.Count > 0)
- {
- for (int i = m_PolygonPoint.Count - 1; i >= 0;)
- {
- m_PolygonPoint.RemoveAt(i);
- break;
- }
- }
- }
- if (m_PolygonPoint.Count == 0)
- {
- //设置手绘标识
- m_IsDrawMeasureReady = false;
- m_IsDrawMeasure = false;
- m_IsDrawPolygonFinish = false;
- }
- this.Invalidate();
- }
- }
- public void KeyDowns()
- {
- //鼠标相对于屏幕的坐标
- Point p1 = MousePosition;
- //鼠标相对于窗体的坐标
- Point p2 = this.PointToClient(p1);
- Pen GrayPen = new Pen(Color.Gray, m_PenWidth);
- //设置鼠标在样品测量区域上的样式
- foreach (CRectangleGDIObject item in m_MeasureGDIObjects)
- {
- if (!item.SelColor.Name.Equals("Transparent"))
- {
- //判断鼠标是否在测量区域的绘制线上,更改光标样式
- if (item.GPath != null)
- {
- if (item.CreateType == CreateRectangleType.Polygon)
- {
- //在多边形点附近切换光标
- foreach (PointF itemPoint in item.PolygonPointRegionF)
- {
- if (Math.Abs(itemPoint.X - p2.X) <= m_OffsetPX && Math.Abs(itemPoint.Y - p2.Y) <= m_OffsetPX)
- {
- if (Control.ModifierKeys == Keys.Control)
- {
- this.Cursor = System.Windows.Forms.Cursors.Hand;
- return;
- }
- }
- }
- }
- else
- {
- if (item.GPath.IsOutlineVisible(p2, GrayPen))
- {
- if (Control.ModifierKeys == Keys.Control)
- {
- this.Cursor = System.Windows.Forms.Cursors.NoMove2D;
- return;
- }
- }
- }
- }
- //判断鼠标是否在测量区域内,更改光标样式
- if (item.GPath != null)
- {
- if (!m_IsSelPolygonPoint)
- {
- if (item.GPath.IsVisible(p2))
- {
- if (Control.ModifierKeys == Keys.Control)
- {
- if (!m_IsMeasure)
- {
- this.Cursor = System.Windows.Forms.Cursors.SizeAll;
- return;
- }
- }
- }
- }
- }
- if (item.IfContains(p2))
- {
- if (!m_IsSelPolygonPoint)
- {
- if (Control.ModifierKeys == Keys.Control)
- {
- if (!m_IsMeasure)
- {
- this.Cursor = System.Windows.Forms.Cursors.SizeAll;
- return;
- }
- }
- }
- }
- }
- }
- //设置鼠标在样品上的样式
- foreach (CRectangleGDIObject item in m_SampleGDIObjects)
- {
- if (!item.SelColor.Name.Equals("Transparent"))
- {
- if (item.IfContains(p2))
- {
- if ((Control.ModifierKeys == Keys.Alt))
- {
- if (!m_IsMeasure)
- {
- this.Cursor = System.Windows.Forms.Cursors.SizeAll;
- return;
- }
- }
- }
- }
- }
- }
- public void KeyUps()
- {
- //鼠标相对于屏幕的坐标
- Point p1 = MousePosition;
- //鼠标相对于窗体的坐标
- Point p2 = this.PointToClient(p1);
-
-
- if (m_visualStage.GetEdgeGDIObj().IfContains(p2))
- {
- m_RectangIsDragging = true;
- m_IsSelectSampleStage = true;
- }
-
- //键盘抬起时,将选择区域的标识 设置为未选择状态
- m_IsMeasure = false;
- this.Cursor = System.Windows.Forms.Cursors.Default;
- }
- #endregion
- #region 处理方法总汇
- #region 清除所需图形
- public void ClearDrawInfoForChangeWindownSize()
- {
-
-
- m_visualStage.cleargdiobj();
-
- }
- public void ClearDrawInfo()
- {
- try
- {
-
- m_visualStage.cleargdiobj();
-
- if (m_MeasureGDIObjects != null)
- {
- m_MeasureGDIObjects.Clear();
- }
-
- if (m_SampleGDIObjects != null)
- {
- m_SampleGDIObjects.Clear();
- }
-
- if (m_MeasureFieldGDIObjects != null)
- {
- m_MeasureFieldGDIObjects.Clear();
- }
- if (m_ImageGDIObjects != null)
- {
- m_ImageGDIObjects.Clear();
- }
- if (m_ImageOfFieldGDIObjects != null)
- {
- m_ImageOfFieldGDIObjects.Clear();
- }
- if (m_DrawMeasureGDIObjects != null)
- {
- m_DrawMeasureGDIObjects.Clear();
- }
-
- }
- catch (Exception ex)
- {
-
- log.Error( ex.ToString() );
- }
- }
- #endregion
- #endregion
- public bool AddOnlySample(string SampleHoleName, string SampleName, OTSSamplespaceWindow oTSSamplespaceWindow)
- {
-
-
-
- CRectangleGDIObject itemAdd ;
- //设置样品选择状态为非工作样品
- foreach (CRectangleGDIObject itemSample in m_SampleGDIObjects)
- {
- //设置颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
- itemSample.SelColor = ColorTranslator.FromHtml(ColorStr);
- itemSample.IsWorkSample = false;
- }
-
- itemAdd = m_visualStage.GetHoleGDIByHoleName(SampleHoleName);
- if (itemAdd != null)
- {
- //获取样品台类型
- var shape = itemAdd.Shape;
- //设置颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
- Color selColor = ColorTranslator.FromHtml(ColorStr);
- CreateRectangle AddSample = new CreateRectangle(itemAdd.Region, CreateRectangleType.SelectSample, shape, itemAdd.Name, selColor);
- //累加样品数量
- itemAdd.SampleCount += 1;
- itemAdd.IsWorkSample = true;
- AddSample.SampleName = SampleName;
- AddSample.Name = itemAdd.Name;
- //绘制测量区域路径
- GraphicsPath AddSamplePath = new GraphicsPath();
- AddSamplePath.AddRectangle(AddSample.Region);
- AddSample.GPath = AddSamplePath;
- m_SampleGDIObjects.Add(AddSample);
- return true;
- }
-
- return false;
- }
-
-
-
- #region 绘制样品以及测量区域
- /// <summary>
- /// 绘制样品以及测量区域
- /// </summary>
- /// <param name="SMeasrueAreaList">测量区域的集合</param>
- public void DrawSampleAndMeasureInfo(List<SampleMeasurePara> SMeasrueAreaList)
- {
- //获取样品孔
- if (SMeasrueAreaList.Count > 0)
- {
- for (int i = 0; i < SMeasrueAreaList.Count; i++)
- {
-
- var item = m_visualStage.GetHoleGDIByHoleName(SMeasrueAreaList[i].sampleHoleName);
- if (item!=null)
- {
- if (AddOnlySample(SMeasrueAreaList[i].sampleHoleName, SMeasrueAreaList[i].sSampleName, this))
- {
- //获取样品信息
- Point xHole = new Point(SMeasrueAreaList[i].MeasureRect.Left, SMeasrueAreaList[i].MeasureRect.Top);
- Point yHole = new Point(SMeasrueAreaList[i].MeasureRect.Right, SMeasrueAreaList[i].MeasureRect.Bottom);
-
-
- if (SMeasrueAreaList[i].iShape ==(ShapeType) CreateRectangleType.Polygon)
- {
- //多边形测量区域完成标识
- m_DrawPolygonFinishGDIObjects = new List<CRectangleGDIObject>();
- //获取样品台 中心点
- PointF RectanglePointCenter = m_visualStage.GetCenterPointF();
- //获取样品台中心点
-
- float CenterX = m_visualStage.PixelConvertToMicron((int)RectanglePointCenter.X);
- float CenterY = m_visualStage.PixelConvertToMicron((int)RectanglePointCenter.Y);
- //绘制多边形测量区域
- List<PointF> drawPointList = new List<PointF>();
- for (int pointIndex = 0; pointIndex < SMeasrueAreaList[i].DrawPolygonPointRegionF.Count; pointIndex++)
- {
- float offX = CenterX + SMeasrueAreaList[i].PolygonPointRegionF[pointIndex].X;
- float offY = CenterY - SMeasrueAreaList[i].PolygonPointRegionF[pointIndex].Y;
- //获取测量区域中的四个点位置
- float X = Convert.ToInt32(m_visualStage.MillimetersToPixelsWidth( Convert.ToDouble(offX)));
- float Y = Convert.ToInt32(m_visualStage.MillimetersToPixelsWidth( Convert.ToDouble(offY)));
- PointF DrawPoint = new PointF(X / m_GlobalZoomNum, Y / m_GlobalZoomNum);
- drawPointList.Add(DrawPoint);
- }
- CreateRectangle createFinishPoint = new CreateRectangle(drawPointList, CreateRectangleType.Polygon, (ShapeType)m_DrawMeasureType, SMeasrueAreaList[i].sampleHoleName, SMeasrueAreaList[i].sSampleName, Color.Red);
- GraphicsPath PolygonMeasurePath = new GraphicsPath();
- PolygonMeasurePath.AddPolygon(drawPointList.ToArray());
- createFinishPoint.GPath = PolygonMeasurePath;
- m_DrawMeasureGDIObjects.Add(createFinishPoint);
- //设置测量区域位置与尺寸
- //获取外接矩形
- Rectangle polygonRectPara = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(drawPointList);
- m_DrawMeasureGDIObjects[0].Region = polygonRectPara;
- m_DrawMeasureGDIObjects[0].RegionF = polygonRectPara;
- m_DrawMeasureGDIObjects[0].DrawRegionF = polygonRectPara;
- //将绘制好的多边形测量区域赋值给 多边形测量区域对象
- m_MeasureGDIObjects.Add(m_DrawMeasureGDIObjects[0]);
- m_DrawMeasureGDIObjects.Clear();
- if (m_DrawPolygonFinishGDIObjects != null)
- {
- m_DrawPolygonFinishGDIObjects.Clear();
- }
- //设置手绘标识
- m_IsDrawMeasureReady = false;
- m_IsDrawMeasure = false;
- m_IsDrawPolygonFinish = false;
-
- }
- else
- {
- //正常绘制测量区域
- CreateRectangle cRect = m_visualStage.GetCtrlCoordRect(xHole,yHole, (CreateRectangleType)SMeasrueAreaList[i].iShape, "", "");
- //测量区域名称 样品名称
- cRect.SampleName = SMeasrueAreaList[i].sSampleName;
- cRect.Name = SMeasrueAreaList[i].sampleHoleName;
- //测量区域类型
- cRect.CreateType =( CreateRectangleType)SMeasrueAreaList[i].iShape;
- CRectangleGDIObject measureGdi;
- if (m_visualStage. AddMeasure( cRect,out measureGdi))
- {
- m_MeasureGDIObjects.Add(measureGdi);
-
- }
- }
- }
- }
-
- }
- }
- }
- #endregion
- #region 获取工作样品的测量区域信息
- public SampleMeasurePara GetSampleMeasureRect(CRectangleGDIObject MeasureItem)
- {
-
- int iShape = 0;
- Rectangle Srect = new Rectangle();
- SampleMeasurePara sampleMeasureParas = new SampleMeasurePara();
- //获取当前工作的测量区域信息
- m_MeasureAppForm.m_ProjParam.GetWSampleMrsArea(ref iShape, ref Srect);
- sampleMeasureParas.iShape = (ShapeType)iShape;
- sampleMeasureParas.MeasureRect = Srect;
- sampleMeasureParas.sampleHoleName = MeasureItem.Name;
- sampleMeasureParas.sSampleName = MeasureItem.SampleName;
- if (MeasureItem.CreateType == CreateRectangleType.Polygon)
- {
-
- sampleMeasureParas.PolygonPointRegion = MeasureItem.PolygonPointRegion;
- sampleMeasureParas.PolygonPointRegionF = MeasureItem.PolygonPointRegionF;
- sampleMeasureParas.DrawPolygonPointRegionF = MeasureItem.DrawPolygonPointRegionF;
- }
- return sampleMeasureParas;
- }
- /// <summary>
- /// 获取所有测量区域的位置
- /// </summary>
- /// <param name="MeasureItem"></param>
- /// <returns></returns>
- public List<SampleMeasurePara> GetALLSampleMeasureRect()
- {
- Rectangle Srect;
- List<SampleMeasurePara> sampleMeasureParasList = new List<SampleMeasurePara>();
- List<COTSSample> cSample = m_MeasureAppForm.m_ProjParam.GetResultData().GetSampleList();
- foreach (var item in cSample)
- {
- CDomain pMsrArea = new CDomain();
- pMsrArea = item.GetMsrArea();
- ValueType ValType = new Rectangle();
- ValType = pMsrArea.GetRectDomain();
- Srect = (Rectangle)ValType;
- SampleMeasurePara sampleMeasureParas = new SampleMeasurePara();
- sampleMeasureParas.iShape = (ShapeType)pMsrArea.GetShape();
- sampleMeasureParas.MeasureRect = Srect;
- sampleMeasureParas.sampleHoleName = item.GetSampleHoleName();
- sampleMeasureParas.sSampleName = item.GetName();
- List<Point> Points = item.GetMsrArea().GetPolygonPoint();
- List<PointF> PointFs = m_visualStage.PointConvertPointF(Points);
- sampleMeasureParas.PolygonPointRegion = Points;
- sampleMeasureParas.PolygonPointRegionF = PointFs;
- sampleMeasureParas.DrawPolygonPointRegionF = PointFs;
- sampleMeasureParasList.Add(sampleMeasureParas);
- }
- return sampleMeasureParasList;
- }
- #endregion
- #region 获取帧图信息
- public void GetSEMData()
- {
- #region 设置电镜参数
- //判断是否为模拟模式
- List<double> semParameters ;
- //初始放大倍数与工作距离
-
- #region 获取电镜参数
- ////获取Field操作类对象
- if (m_SEMDATAFieldManage == null)
- {
- m_SEMDATAFieldManage = new SEMDATAFieldManage(m_MeasureAppForm.m_ProjParam);
- }
- //判断是否连接电镜
- if (m_SEMDATAFieldManage.InitAndConnection())
- {
- //获取电镜参数 放大倍数与工作距离 [Magnification]:放大倍数 [WorkingDistance]工作距离
- semParameters = m_SEMDATAFieldManage.GetSEMMagAndWDParameter();
- double mag = semParameters[0];
- double wd = semParameters[1];
- if (mag != 0 && wd != 0)
- {
- //设置样品文件中的电镜参数
- m_MeasureAppForm.m_ProjParam.SetWorkingSampleSEMData(wd, mag);
- //设置工作样品的测量区域 存在帧图
- foreach (var MeasureItem in m_MeasureGDIObjects)
- {
- if (MeasureItem.IsWorkSample)
- {
-
- break;
- }
- }
- //将右键SEM数据菜单设置为可编辑状态
- CMStrip.Items[(int)MenuIndex.SetSemData].Enabled = true;
-
- }
-
- }
-
- #endregion
- #endregion
- if (m_MeasureFieldGDIObjects != null)
- {
- DrawMeasureField();
- }
- }
- #region 获取Filed帧图
- public List<Rectangle> GetOTSFieldRects()
- {
- List<Point> listCenterPoint ;
- Size rectSize ;
- //获取所有帧图的中心点信息 与矩形尺寸信息
- List<Rectangle> returnRectList = new List<Rectangle>();
- if (GetFieldData(out listCenterPoint, out rectSize))
- {
- //将所有中心点 转换为矩形
-
- foreach (Point item in listCenterPoint)
- {
- returnRectList.Add(new Rectangle(item, rectSize));
- }
-
-
- }
- return returnRectList;
- }
- public bool GetFieldData(out List<Point> pFields, out Size iSzie)
- {
- pFields = new List<Point>();
- iSzie = new Size();
- var m_ResultData = m_MeasureAppForm.m_ProjParam.GetResultData();
-
- COTSSample WSample = m_ResultData.GetWorkingSample();
- if (null == WSample)
- {
- return false;
- }
- CDomain pMsrArea = WSample.GetMsrArea();
-
- COTSImgScanPrm pImgScanParam = WSample.GetMsrParams().GetImageScanParam();
- CSEMDataMsr pSEMDataMsr = WSample.GetSEMDataMsr();
-
- CFieldPositionMgr pFieldMgr = new CFieldPositionMgr();
- List<Point> listPoint = new List<Point>();
- listPoint.Clear();
- //设置测量区域
-
- if (m_MeasureAppForm.m_MessageStates == MessageState.ShotBSEPicture)
- {
- //获取最小放大倍数与FieldSize100倍数
- pSEMDataMsr.SetScanFieldSize100(m_visualStage.GetOTSSampleStageData().iScanFieldSize100);
- double dMagnification = m_MeasureAppForm.m_ProjParam.GetDefaultParam().GetStageDataParam().GetMinMag();
- pSEMDataMsr.SetMagnification(dMagnification);
- //设置样品孔当前位置信息
- Rectangle sampleHoleRect = CMeasureThreadWrapper.c_DomainMessure.GetRectDomain();
- //判断
- if ((int)this.CMStrip.Items[9].Tag == 1)
- {
- int shape = 0;
-
- var item = m_visualStage.GetHoleGDIBySampleName(WSample.GetName());
- if (item!=null)
- {
- shape =(int) item.Shape;
- }
-
- pMsrArea.SetShape((DOMAIN_SHAPE)shape);
- }
- pMsrArea.SetRectDomain(sampleHoleRect);
-
- }
- else if (m_MeasureAppForm.m_MessageStates == MessageState.MeasureBSEPicture)
- {
- //获取最小放大倍数与FieldSize100倍数
- pSEMDataMsr.SetScanFieldSize100(m_visualStage.GetOTSSampleStageData().iScanFieldSize100);
- double dMagnification = WSample.GetSEMDataMsr().GetMagnification();
- pSEMDataMsr.SetMagnification(dMagnification);
- //设置样品孔当前位置信息
- Rectangle sampleHoleRect = CMeasureThreadWrapper.c_DomainMessure.GetRectDomain();
- pMsrArea.SetRectDomain(sampleHoleRect);
-
- }
- else
- {
- try
- {
- //设置当前工作区域
- if (CMeasureThreadWrapper.c_DomainMessure != null)
- {
- Rectangle measureRect = CMeasureThreadWrapper.c_DomainMessure.GetRectDomain();
- pMsrArea.SetRectDomain(measureRect);
- }
- }
- catch (Exception ex)
- {
- log.Error("获取幁图数问题:" + ex.ToString());
- }
- pSEMDataMsr.SetScanFieldSize100(m_visualStage.GetOTSSampleStageData().iScanFieldSize100);
- double dMagnification = WSample.GetSEMDataMsr().GetMagnification();
- pSEMDataMsr.SetMagnification(dMagnification);
-
- }
- ////计算所有的帧图位置 calculate all the field position point in OTS coordination.
- if (!pFieldMgr.Init(pMsrArea, pImgScanParam, pSEMDataMsr, listPoint))
- {
- return false;
- }
- //获取幁图的中心点
- pFields = pFieldMgr.GetFieldCentrePoints();
- //获取幁图数
- int iFieldCount = pFieldMgr.GetTotalFields();
- var oValue = new Rectangle();
- if (!pFieldMgr.GetFieldRectByIndex(0, ref oValue))
- {
- return false;
- }
- iSzie = oValue.Size;
-
- WSample.GetSEMDataMsr().SetTotalFields(iFieldCount);
-
- return true;
- }
- #endregion
- public void DrawMeasureField()
- {
- try
- {
- if (m_MeasureFieldGDIObjects == null)
- {
- return;
- }
- //清除帧图信息
- ClearImageAndSingleGDIObjects();
-
-
-
- //是否获取过帧图标识
- bool IsPolygon = false;
- if (m_MeasureAppForm.m_MessageStates == (int)MessageState.StartMeasure)
- {
- //设置测量区域形状与位置
- IsPolygon = SetWorkSampleMeasureArea();
- if (!IsPolygon)
- {
- return;
- }
- }
-
- //获取Field集合
- List<Rectangle> fieldRects = null;
- fieldRects = GetOTSFieldRects();
- if (m_MeasureAppForm.m_MessageStates == (int)MessageState.StartMeasure)
- {
- m_MeasureAppForm.UpdatePropertyVal();
- }
- //如果当前工作样品是多边形则设置回原测量区域参数
- if (IsPolygon)
- {
- foreach (var MeasureItem in m_MeasureGDIObjects)
- {
- if (MeasureItem.IsWorkSample)
- {
- if (MeasureItem.CreateType == CreateRectangleType.Polygon)
- {
- SetWorkSampleMeasureArea(CreateRectangleType.Polygon);
- }
- }
- }
- }
- //样品孔名称与样品名称
- string sampleName = string.Empty;
- string sampleHoleName = string.Empty;
- //获取样品孔 与 样品名称
- foreach (var item in m_SampleGDIObjects)
- {
- if (item.IsWorkSample)
- {
- sampleName = item.SampleName;
- sampleHoleName = item.Name;
- }
- }
- //以矩形绘制帧图
- for (int i = fieldRects.Count - 1; i >= 0; i--)
- {
- Point pt = new Point(fieldRects[i].X, fieldRects[i].Y);
- pt.X = fieldRects[i].X - fieldRects[i].Width / 2;
- pt.Y = fieldRects[i].Y + fieldRects[i].Height / 2;
- //获取Rectang 两点信息
- Point XSTD = new Point(fieldRects[i].Left, fieldRects[i].Top);
- Point YSTD = new Point(fieldRects[i].Right, fieldRects[i].Bottom);
- //绘制帧图
- RectangleF visualRect = m_visualStage.GetCtrlCoordRectF( XSTD, YSTD);
- //设置每一个帧图的宽与高 以中心点大小为标准
- visualRect = new RectangleF(new PointF(visualRect.X, visualRect.Y), new SizeF(visualRect.Width, visualRect.Height));
- //添加所有转换后的RectangleF
- //根据缩放倍数
- float xZoom = (visualRect.X * m_GlobalZoomNum);
- float yZoom = (visualRect.Y * m_GlobalZoomNum);
- float widthZoom = (visualRect.Width * m_GlobalZoomNum);
- float heightZoom = (visualRect.Height * m_GlobalZoomNum);
- RectangleF rectZoomSingle = new RectangleF(xZoom, yZoom, widthZoom, heightZoom);
- //设置颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SingleColor);
-
- CreateRectangle createRect = new CreateRectangle(rectZoomSingle, fieldRects[i].X, fieldRects[i].Y, CreateRectangleType.FieldRectangle, sampleHoleName, sampleName, ColorTranslator.FromHtml(ColorStr));
- //如果选择为测量区域BSE照片 则添加样品名称
- if (CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag != null)
- {
- if ((int)CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag == (int)MessageState.StartMeasure)
- {
- createRect.SampleName = sampleName;
- }
- }
- createRect.Name = sampleHoleName;
- //保留原帧图位置与大小
- createRect.RegionF = rectZoomSingle;
- createRect.DrawRegionF = visualRect;
- //拍摄样品孔照片
- if (m_MeasureAppForm.m_MessageStates == MessageState.ShotBSEPicture)
- {
- //添加样品孔图片列表
- m_ImageOfFieldGDIObjects.Add(createRect);
- }
- else if (m_MeasureAppForm.m_MessageStates == (int)MessageState.StartMeasure)
- {
- //添加帧图列表
- m_MeasureFieldGDIObjects.Add(createRect);
- }
- }
- if (m_MeasureAppForm.m_MessageStates == (int)MessageState.StartMeasure)
- {
-
- }
- //将所有帧图移植测量区域位置中
- //获取样品孔 与 样品名称
- foreach (var item in m_SampleGDIObjects)
- {
- if (item.IsWorkSample)
- {
- sampleName = item.SampleName;
- sampleHoleName = item.Name;
- if (m_MeasureAppForm.m_MessageStates == (int)MessageState.StartMeasure)
- {
- //设置工作样品的测量区域 存在帧图
- foreach (var MeasureItem in m_MeasureGDIObjects)
- {
- if (MeasureItem.SampleName == item.SampleName)
- {
- //设置工作样品的测量区域 存在帧图标识
- if (m_MeasureFieldGDIObjects.Count > 0)
- {
-
- OTSSamplespaceGraphicsPanelFun.SetSingleLocationToMeasureLocation(m_MeasureFieldGDIObjects, MeasureItem);
-
- }
- break;
- }
- }
- }
- if (m_MeasureAppForm.m_MessageStates == MessageState.ShotBSEPicture)
- {
- if (CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag != null)
- {
- if ((int)CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag == (int)(int)MessageState.ShotBSEPicture)
- {
- //设置工作样品的测量区域 存在帧图
-
- var sampleHoleItem = m_visualStage.GetHoleGDIByHoleName(item.Name);
- if (sampleHoleItem!=null)
- {
- //设置工作样品的测量区域 存在帧图标识
- if (m_ImageOfFieldGDIObjects.Count > 0)
- {
- OTSSamplespaceGraphicsPanelFun.SetSingleLocationToMeasureLocation(m_ImageOfFieldGDIObjects, sampleHoleItem);
- }
- break;
- }
-
- }
- else
- {
- //设置工作样品的测量区域 存在帧图
- foreach (var MeasureItem in m_MeasureGDIObjects)
- {
- if (MeasureItem.SampleName == item.SampleName)
- {
- //设置工作样品的测量区域 存在帧图标识
- if (m_ImageOfFieldGDIObjects.Count > 0)
- {
- OTSSamplespaceGraphicsPanelFun.SetSingleLocationToMeasureLocation(m_ImageOfFieldGDIObjects, MeasureItem);
- }
- break;
- }
- }
- }
- }
- }
- }
- }
- //Invalidate();
-
- }
- catch (Exception ex)
- {
- log.Error( ex.ToString());
- }
- }
- #endregion
- #region 设置SEM数据
- public bool SetSEMDATAMParameter(double magnification, double semWorkingDistance)
- {
- #region 获取电镜参数
-
- //获取Field操作类对象
- if (m_SEMDATAFieldManage == null)
- {
- m_SEMDATAFieldManage = new SEMDATAFieldManage(m_MeasureAppForm.m_ProjParam);
- }
- //判断是否连接电镜
- if (m_SEMDATAFieldManage.InitAndConnection())
- {
- //获取电镜参数
- bool mFlag = false;
- bool wFlag = false;
-
- mFlag = m_SEMDATAFieldManage.SetGMagnification(magnification);
- wFlag = m_SEMDATAFieldManage.SetSemWorkingDistance(semWorkingDistance);
- if (mFlag || wFlag)
- {
- return true;
- }
-
- }
- return false;
- #endregion
- }
- public bool GetSEMDATAMParameter(ref double magnification, ref double WorkingDistance)
- {
- #region 获取电镜参数
- //获取Field操作类对象
- if (m_SEMDATAFieldManage == null)
- {
- m_SEMDATAFieldManage = new SEMDATAFieldManage(m_MeasureAppForm.m_ProjParam);
- }
- //判断是否连接电镜
- if (m_SEMDATAFieldManage.InitAndConnection())
- {
- //获取电镜参数
- List<double> semParameters = m_SEMDATAFieldManage.GetSEMMagAndWDParameter();
- //放大倍数
- magnification = semParameters[0];
- WorkingDistance = semParameters[1];
-
- return true;
- }
- return false;
- #endregion
- }
- #endregion
- #region 驱动到SEM当前位置
- protected void SetMeasureToSEMLocation()
- {
- try
- {
- //获取SEM位置
- List<double> SemLocation = new List<double>();
- if (GetSemLocation(ref SemLocation))
- {
-
- Point OTSLocation = m_MeasureAppForm.m_ProjParam.ConverSEMToOTSCoord(new Point((int)Math.Round(SemLocation[(int)XYIndex.X], 0), (int)Math.Round(SemLocation[(int)XYIndex.Y], 0)));
- //转换为工作区域位置坐标
- int w = (int)m_visualStage.MillimetersToPixelsWidth( Convert.ToDouble(OTSLocation.X));
- int h = (int)m_visualStage .MillimetersToPixelsWidth( Convert.ToDouble(OTSLocation.Y));
- //样品台中心点
- Point m_StageCenterPoint = m_visualStage.GetCenterPoint();
- Point moveToSEMLocation = new Point(w, h);
- //根据鼠标右键点击的位置 重新绘制帧图
- if (m_MeasureGDIObjects != null)
- {
- if (m_MeasureGDIObjects.Count > 0)
- {
- foreach (var MeasureItem in m_MeasureGDIObjects)
- {
- if (MeasureItem.IsWorkSample)
- {
- bool selWSampleMeasureStatus = m_MeasureAppForm.m_ProjParam.GetWorkSampleMeasureStatus();
- if (selWSampleMeasureStatus)
- {
- return;
- }
- if (MoveMeasureInStage(MeasureItem, m_StageCenterPoint, moveToSEMLocation, m_GlobalZoomNum))
- {
- if (m_visualStage.NewLocationDrawSingleInfo( moveToSEMLocation, m_MeasureFieldGDIObjects, MeasureItem, m_GlobalZoomNum))
- {
- //根据鼠标右键点击的位置 重新绘制区域
- m_visualStage.NewLocationDrawMeasureInfo( moveToSEMLocation, m_MeasureGDIObjects, m_GlobalZoomNum);
- var para = m_visualStage.GetSampleMeasurePara(MeasureItem);
- m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);
-
- break;
- }
- }
- else
- {
- MessageBox.Show(table["message12"].ToString(), table["message11"].ToString());
- return;
- }
- }
- }
- }
- }
- }
- Invalidate();
- }
- catch (Exception ex)
- {
-
- log.Error( ex.ToString());
- }
- }
- #endregion
- #region 驱动SEM到当前位置
- public bool SetSEMCurrentLocation()
- {
-
- bool bret=false;
- //获取Field操作类对象
- if (m_SEMDATAFieldManage == null)
- {
- m_SEMDATAFieldManage = new SEMDATAFieldManage(m_MeasureAppForm.m_ProjParam);
- }
- //判断是否连接电镜
- if (m_SEMDATAFieldManage.InitAndConnection())
- {
- bret = m_SEMDATAFieldManage.SetSEMCurrentLocation(m_MouseDownLocation,m_visualStage);
-
- }
-
- return bret;
-
-
- }
- #endregion
- #region 设置SEM到中心
- public bool SetSEMToCenterPoint()
- {
- try
- {
- //获取Field操作类对象
- if (m_SEMDATAFieldManage == null)
- {
- m_SEMDATAFieldManage = new SEMDATAFieldManage(m_MeasureAppForm.m_ProjParam);
- }
- //判断是否连接电镜
- bool bret = false;
- if (m_SEMDATAFieldManage.InitAndConnection())
- {
- bret = (m_SEMDATAFieldManage.DriveSEMToLocation(m_MouseDownLocation,m_visualStage, m_MeasureFieldGDIObjects));
-
- }
- return bret;
- }
- catch (Exception ex)
- {
-
- log.Error("OTSSamplespaceWindow_" + "SetSEMToCenterPoint" + ":" + ex.ToString() + "");
- return false;
- }
- }
- #endregion
- #region 获取SEM当前位置
- public bool GetSemLocation(ref List<double> SemLocation)
- {
-
- //获取Field操作类对象
- if (m_SEMDATAFieldManage == null)
- {
- m_SEMDATAFieldManage = new SEMDATAFieldManage(m_MeasureAppForm.m_ProjParam);
- }
- //判断是否连接电镜
- bool bret=false;
- if (m_SEMDATAFieldManage.InitAndConnection())
- {
- bret = m_SEMDATAFieldManage.GetSemLocation(ref SemLocation);
-
- }
- return bret;
-
- }
- #endregion
-
-
-
- #region 显示标尺
- /// <summary>
- /// 是否显示标尺控件
- /// </summary>
- /// <param name="b_show"></param>
- public void ShowRulerLocation()
- {
- //设置标尺位置
- Point rulerLocation = new Point(10, this.Height - (int)(control_Ruler2.Height * 2));
- this.control_Ruler2.Location = rulerLocation;
- if (control_Ruler2.Visible)
- {
- //显示
- control_Ruler2.Visible = false;
- }
- else
- {
- //显示
- control_Ruler2.Visible = true;
-
- f_ruler_size = Convert.ToInt32(f_old_ruler_size * m_GlobalZoomNum);
- control_Ruler2.RulerWidth = Convert.ToInt32(f_ruler_size);
- control_Ruler2.Value = 1;
-
- //放大过长时,这里将宽度与代表的实际宽度进行折半显示
- while (control_Ruler2.Width > 300)
- {
- control_Ruler2.RulerWidth = Convert.ToInt32(control_Ruler2.RulerWidth) / 2;
- control_Ruler2.Value = control_Ruler2.Value * 2;
- }
- control_Ruler2.SetValue(control_Ruler2.RulerWidth, control_Ruler2.Value.ToString());
- }
- }
- public void RulerInit(StageDrawingData SData)
- {
- control_Ruler2.ShowString = "1mm";
- Point xDomain = new Point(SData.StageDomain.Left, SData.StageDomain.Top);
- Point yDomain = new Point(SData.StageDomain.Right, SData.StageDomain.Bottom);
- //OTS宽度高度差值
- float widthDomain = Math.Abs(yDomain.X - xDomain.X);
- int length = this.Height > this.Width ? this.Width : this.Height;
- control_Ruler2.RulerWidth = (int)(length / widthDomain * 1000);
- f_ruler_size = f_old_ruler_size = control_Ruler2.RulerWidth;
- control_Ruler2.Value = 1000;
- }
- #endregion
- #region 隐藏与显示样品台中的文字
-
- //public void ChangeSampleHoleFont()
- //{
-
- // Invalidate();
- //}
- #endregion
- #region 隐藏与显示样品孔照片
- static bool IsShowSampleHoleImage = true;
- public void ChangeSampleHoleImage()
- {
- IsShowSampleHoleImage = IsShowSampleHoleImage ? false : true;
- Invalidate();
- }
- #endregion
- #region 添加样品孔中BSE图像信息
- public void AddHoleBSEImageData(byte[] ImageData, int width, int height, Point fieldPos)
- {
- //获取样品孔名称
-
- CRectangleGDIObject itemWorkSample = null;
- foreach (CRectangleGDIObject item in m_SampleGDIObjects)
- {
- if (item.IsWorkSample)
- {
-
- itemWorkSample = item;
- break;
- }
- }
- //获取样品孔BSE图像
- Image bseImage = null;
- int m_iWidth = width;
- int m_iHeigh = height;
- RectangleF ImgRegionF = new RectangleF();
- float ImgRegionWidth = 0;
- float ImgRegionHeight = 0;
- if (m_ImageOfFieldGDIObjects.Count > 0)
- {
- for (int i = 0; i < m_ImageOfFieldGDIObjects.Count; i++)
- {
- if (m_ImageOfFieldGDIObjects[i].OTSX == fieldPos.X && m_ImageOfFieldGDIObjects[i].OTSY == fieldPos.Y)
- {
- ImgRegionF = m_ImageOfFieldGDIObjects[i].RegionF;
- ImgRegionWidth = Convert.ToInt32(m_ImageOfFieldGDIObjects[i].RegionF.Width);
- ImgRegionHeight = Convert.ToInt32(m_ImageOfFieldGDIObjects[i].RegionF.Height);
- //获取图片
- bseImage = CImageHandler.ToGrayBitmap(ImageData, m_iWidth, m_iHeigh);
- //获取工作样品位置
- Point drawImageLocation = itemWorkSample.Region.Location;
- //绘制图像
- CreateRectangle createImageRect = new CreateRectangle(ImgRegionF, fieldPos.X, fieldPos.Y, itemWorkSample.SampleName, itemWorkSample.Name, bseImage, ImgRegionWidth, ImgRegionHeight, drawImageLocation, CreateRectangleType.DrawSampleHoleBSEImage);
- //添加至List集合中
- createImageRect.DrawRegionF = m_ImageOfFieldGDIObjects[i].DrawRegionF;
- createImageRect.RegionF = m_ImageOfFieldGDIObjects[i].RegionF;
- createImageRect.Region = m_ImageOfFieldGDIObjects[i].Region;
- createImageRect.Name = m_ImageOfFieldGDIObjects[i].Name;
- m_ImageGDIObjects.Add(createImageRect);
- break;
- }
- }
- }
- //显示样品孔照片
- IsShowSampleHoleImage = true;
- Invalidate();
- }
- #endregion
- #region 删除样品孔中BSE图像信息
- public void DeleteHoleBSEImageData()
- {
- try
- {
- //鼠标右键点击的位置坐标
- Point mouseCurrent = m_MouseDownLocation;
- //样品名称
- string SampleName = "";
- //获取当前工作样品并删除对应BSE图
- foreach (CRectangleGDIObject ImageItem in m_ImageGDIObjects)
- {
- if (ImageItem.IfContains(mouseCurrent))
- {
- SampleName = ImageItem.SampleName;
- break;
- }
- }
- if (SampleName != null && !SampleName.Equals(""))
- {
- string message = table["message7"].ToString();
- if (MessageBox.Show(message, "Tip", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
- {
- CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag = MessageState.StartMeasure;
- DeleteHoleBSEImageDataNoMessageBox();
- return;
- }
- else
- {
- return;
- }
- }
- //删除样品孔BSE图
- //样品孔名称
- string HoleName = "";
- var item = m_visualStage.GetHoleGDIByMousePoint(mouseCurrent);
-
- if (item!=null)
- {
- HoleName = item.Name;
-
- }
-
- if (HoleName != null && !HoleName.Equals(""))
- {
- string message = table["message8"].ToString();
- if (MessageBox.Show(message, "Tip", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
- {
- CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag = MessageState.ShotBSEPicture;
- DeleteHoleBSEImageDataNoMessageBox();
- return;
- }
- else
- {
- return;
- }
- }
- }
- catch (Exception ex)
- {
-
- log.Trace(ex.ToString());
- }
- }
- public void DeleteHoleBSEImageDataNoMessageBox()
- {
- try
- {
- if (CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag != null)
- {
- if ((int)CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag == (int)MessageState.ShotBSEPicture)
- {
- string HoleName = string.Empty;
- //鼠标右键点击的位置坐标
- Point mouseCurrent = m_MouseDownLocation;
- //获取当前工作样品并删除对应BSE图
- //foreach (CRectangleGDIObject item in m_visualStage. m_SampleHoleGDIObjects)
- //{
- var item = m_visualStage.GetHoleGDIByMousePoint(mouseCurrent);
- if (item!=null)
- {
- HoleName = item.Name;
- //break;
- }
- //}
- if (!HoleName.Equals(""))
- {
- for (int i = m_ImageGDIObjects.Count - 1; i >= 0; i--)
- {
- if (m_ImageGDIObjects[i].Name == HoleName && m_ImageGDIObjects[i].SampleName == null)
- {
- m_ImageGDIObjects.RemoveAt(i);
- }
- }
- for (int i = m_ImageOfFieldGDIObjects.Count - 1; i >= 0; i--)
- {
- if (m_ImageOfFieldGDIObjects[i].Name == HoleName && m_ImageGDIObjects[i].SampleName == null)
- {
- m_ImageOfFieldGDIObjects.RemoveAt(i);
- }
- }
- Invalidate();
- }
- }
- else
- {
- string SampleName = string.Empty;
- //鼠标右键点击的位置坐标
- Point mouseCurrent = m_MouseDownLocation;
- //获取当前工作样品并删除对应BSE图
- foreach (CRectangleGDIObject item in m_ImageGDIObjects)
- {
- if (item.IfContains(mouseCurrent))
- {
- SampleName = item.SampleName;
- break;
- }
- }
- if (!SampleName.Equals(""))
- {
- for (int i = m_ImageGDIObjects.Count - 1; i >= 0; i--)
- {
- if (m_ImageGDIObjects[i].SampleName == SampleName)
- {
- m_ImageGDIObjects.RemoveAt(i);
- }
- }
- for (int i = m_ImageOfFieldGDIObjects.Count - 1; i >= 0; i--)
- {
- if (m_ImageOfFieldGDIObjects[i].SampleName == SampleName)
- {
- m_ImageOfFieldGDIObjects.RemoveAt(i);
- }
- }
- Invalidate();
- }
- }
- }
- }
- catch (Exception)
- {
- }
- }
- #endregion
- #region 获取样品孔图片
- public void GetBSEPictures()
- {
- //获取当前工作的测量区域信息
- CDomain cDomain = new CDomain();
- DOMAIN_SHAPE iShape = 0;
- Rectangle Srect = new Rectangle();
- //拍摄样品孔BSE照片
- if (CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag != null)
- {
- if ((int)CMStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag == (int)MessageState.ShotBSEPicture)
- {
- //获取当前样品孔的索引 与 样品中对应的测量区域
- OTSSampleHoleInfo sampleHoleInfo = null;
- int sampleHoleIndex = OTSSamplespaceGraphicsPanelFun.GetSampleHoleIndex(m_visualStage.GetOTSSampleStageData(), m_SampleHoleSelectName, ref sampleHoleInfo);
- if (sampleHoleInfo != null)
- {
-
- var sampleHoleItem=m_visualStage.GetHoleGDIByHoleName(sampleHoleInfo.sSHoleName);
- if (sampleHoleItem!=null)
- {
- SampleHolePara sampleHolePara = m_visualStage.GetSampleHolePara(sampleHoleItem);
- iShape = (DOMAIN_SHAPE)sampleHolePara.iShape;
- Srect = sampleHolePara.SampleHoleRect;
- //设置测量区域形状
- cDomain.SetShape(iShape);
- cDomain.SetRectDomain(Srect);
- //开始获取样品孔中的照片
- m_MeasureAppForm.StartSampleHoleBSEImage(MSR_THREAD_RunSTATUS.RUNSampleHoleImage, sampleHoleIndex, cDomain);
-
- }
-
- }
- }
- else
- {
- int measureIndex = 0;
- //获取测量区域信息
- foreach (var MeasureItem in m_MeasureGDIObjects)
- {
- if (MeasureItem.SampleName == m_SampleSelectName)
- {
- measureIndex++;
- SampleMeasurePara sampleMeasure = m_visualStage.GetSampleMeasurePara(MeasureItem);
- iShape = (DOMAIN_SHAPE)sampleMeasure.iShape;
- Srect = sampleMeasure.MeasureRect;
- //设置测量区域形状
- if (iShape == (DOMAIN_SHAPE)(int)CreateRectangleType.Polygon)
- {
- if (iShape > 0)
- {
- cDomain.SetShape(iShape);
- }
- else
- {
- cDomain.SetShape((DOMAIN_SHAPE.ROUND));
- }
- }
- else
- {
- cDomain.SetShape(iShape);
- }
- cDomain.SetRectDomain(Srect);
- List<Point> PolygonPoint = m_visualStage.PointFConvertPoint(sampleMeasure.DrawPolygonPointRegionF);
-
- cDomain.SetPolygonPoint(PolygonPoint);
- //开始获取样品孔中的照片
- m_MeasureAppForm.StartSampleHoleBSEImage(MSR_THREAD_RunSTATUS.RUNSampleHoleImage, 2, cDomain);
- break;
- }
- }
- }
- }
- }
- #endregion
- #region 复位工作样品区域
- public CRectangleGDIObject ResetMeasure(CreateRectangleType CreateType, CRectangleGDIObject m_SampleGDIObjects, CRectangleGDIObject m_MeasureGDIObjects, float globalZoomNum)
- {
- try
- {
- //复位测量
- CreateRectangleType shape = CreateType;
- GraphicsPath MeasurePath = new GraphicsPath();
- if (shape == CreateRectangleType.Rectangle)
- {
- MeasurePath.AddRectangle(m_SampleGDIObjects.Region);
- }
- else
- {
- MeasurePath.AddEllipse(m_SampleGDIObjects.Region);
- }
- //缩小与样品的尺寸
- Rectangle rectMeasure = m_SampleGDIObjects.Region;
- Color MeasureColor = Color.Red;
- return m_visualStage. GetSampleMeasureInfo(m_SampleGDIObjects, m_MeasureGDIObjects, globalZoomNum);
- }
- catch (Exception)
- {
- return null;
- }
- }
- public void ResetWorkSampleMeasure()
- {
- COTSSample WSample = m_MeasureAppForm.m_ProjParam.GetWorkSample();
- OTSSamplePropertyInfo MeasureInfo = new OTSSamplePropertyInfo();
- if (!m_MeasureAppForm.m_ProjParam.GetWorkSamplePerameter(WSample, ref MeasureInfo))
- {
- return;
- }
- Rectangle measureSize = m_MeasureAppForm.m_ProjParam.CalculateMsrArea(MeasureInfo.SMeasurePara.sampleHoleName);
- //获取位置与尺寸
- MeasureInfo.SMeasurePara.MeasureRect.Location = measureSize.Location;
- MeasureInfo.SMeasurePara.MeasureRect.Size = measureSize.Size;
- //获取样品信息
- Point xHole = new Point(MeasureInfo.SMeasurePara.MeasureRect.Left, MeasureInfo.SMeasurePara.MeasureRect.Top);
- Point yHole = new Point(MeasureInfo.SMeasurePara.MeasureRect.Right, MeasureInfo.SMeasurePara.MeasureRect.Bottom);
-
- //定义测量区域
- RectangleF SampleRectangleF = m_visualStage.GetCtrlCoordRectF(xHole,yHole);
- CRectangleGDIObject m_MeasureGDIObject = m_visualStage.GetCtrlCoordRect(xHole,yHole,(CreateRectangleType)MeasureInfo.SMeasurePara.iShape, "", "");
- m_MeasureGDIObject.Region = new Rectangle((int)SampleRectangleF.X, (int)SampleRectangleF.Y, (int)SampleRectangleF.Width, (int)SampleRectangleF.Height);
- m_MeasureGDIObject.RegionF = SampleRectangleF;
- m_MeasureGDIObject.DrawRegionF = SampleRectangleF;
- foreach (var itemSample in m_SampleGDIObjects)
- {
- if (itemSample.IsWorkSample)
- {
- for (int i = 0; i < m_MeasureGDIObjects.Count; i++)
- {
- if (m_MeasureGDIObjects[i].IsWorkSample)
- {
- CRectangleGDIObject m_ResetMeasureGDIobjects = ResetMeasure((int)CreateRectangleType.Circle, itemSample, m_MeasureGDIObject, m_GlobalZoomNum);
- m_MeasureGDIObjects[i].Region = m_ResetMeasureGDIobjects.Region;
- m_MeasureGDIObjects[i].RegionF = m_ResetMeasureGDIobjects.RegionF;
- m_MeasureGDIObjects[i].DrawRegionF = m_ResetMeasureGDIobjects.DrawRegionF;
- m_MeasureGDIObjects[i].Shape = m_ResetMeasureGDIobjects.Shape;
- Invalidate();
- break;
- }
- }
- break;
- }
- }
- }
- #endregion
- #region 清空帧图对象与图像位置对象
- public void ClearImageAndSingleGDIObjects()
- {
- //先清空帧图信息
- if (m_MeasureAppForm.m_MessageStates == (int)MessageState.StartMeasure)
- {
- m_MeasureFieldGDIObjects.Clear();
-
- }
- if (m_MeasureAppForm.m_MessageStates == MessageState.ShotBSEPicture)
- {
- m_ImageOfFieldGDIObjects.Clear();
-
- }
- }
- #endregion
- #region 样品对象列表中无样品信息 则清除帧图对象列表信息
- /// <summary>
- /// 样品对象列表中无样品信息 则清除帧图对象列表信息
- /// </summary>
- /// <returns></returns>
- public bool SampleIsEmptyClearSingleInfo()
- {
- bool result = false;
- if (m_SampleGDIObjects != null)
- {
- if (m_SampleGDIObjects.Count == 0)
- {
- result = true;
- ClearImageAndSingleGDIObjects();
- }
- }
- return result;
- }
- #endregion
- #region 切换样品 填充帧图信息
-
- private void OTSSamplespaceWindow_Activated(object sender, EventArgs e)
- {
- ShowRulerLocation();
- }
-
- #endregion
- #region 设置工作样品测量区域
- public bool SetWorkSampleMeasureArea(CreateRectangleType shape = 0)
- {
- bool isPolygon = false;
- //获取当前工作的测量区域信息
- CDomain cDomain =new CDomain();
- DOMAIN_SHAPE iShape;
- Rectangle Srect ;
- List<Point> PolygonPoint ;
- //获取测量区域形状与位置
- //获取当前测量区域
- foreach (var MeasureItem in m_MeasureGDIObjects)
- {
- if (MeasureItem.IsWorkSample)
- {
- var para = m_visualStage.GetSampleMeasurePara(MeasureItem);
- m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);
-
- isPolygon = true;
- SampleMeasurePara sampleMeasure = GetSampleMeasureRect(MeasureItem);
- if (sampleMeasure.PolygonPointRegion == null)
- {
- sampleMeasure.PolygonPointRegion = new List<Point>();
- }
- PolygonPoint = m_visualStage.PointFConvertPoint(sampleMeasure.PolygonPointRegionF);
- iShape = (DOMAIN_SHAPE)sampleMeasure.iShape;
- //设置测量区域形状
- if (iShape == (DOMAIN_SHAPE)CreateRectangleType.Polygon)
- {
- if (shape > 0)
- {
- cDomain.SetShape((DOMAIN_SHAPE)shape);
- }
- else
- {
- cDomain.SetShape((DOMAIN_SHAPE.ROUND));
- }
- }
- else
- {
- cDomain.SetShape((DOMAIN_SHAPE)iShape);
- }
- Srect = sampleMeasure.MeasureRect;
- cDomain.SetRectDomain(Srect);
- cDomain.SetPolygonPoint(PolygonPoint);
- //线程执行类型 1:测量类型 2:获取样品孔图片类型
- CMeasureThreadWrapper.DoRunType = MSR_THREAD_RunSTATUS.RUNMEASURE;
- //设置获取样品孔中照片所需的参数
- CMeasureThreadWrapper.c_DomainMessure = cDomain;
-
- break;
- }
- }
- return isPolygon;
- }
- #endregion
- }
- }
- #endregion
|