| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124 | using MyControls;using OTS.WinFormsUI.Docking;using OTSDataType;using OTSMeasureApp._0_OTSModel.OTSDataType;using OTSMeasureApp._4_OTSSamplespaceGraphicsPanel;using OTSModelSharp;using OTSModelSharp.ServiceCenter;using System;using System.Collections;using System.Collections.Generic;using System.Drawing;using System.Windows.Forms;namespace OTSMeasureApp{    public enum EnumMousePointPosition    {        MouseSizeNone = 0, //'无          MouseSizeRight = 1, //'拉伸右边框          MouseSizeLeft = 2, //'拉伸左边框          MouseSizeBottom = 3, //'拉伸下边框          MouseSizeTop = 4, //'拉伸上边框          MouseSizeTopLeft = 5, //'拉伸左上角          MouseSizeTopRight = 6, //'拉伸右上角          MouseSizeBottomLeft = 7, //'拉伸左下角          MouseSizeBottomRight = 8, //'拉伸右下角          MouseDrag = 9   // '鼠标拖动      }    public enum ContextMenuType    {        //样品孔右键菜单        SampleHoleMenu = 0,        //样品右键菜单        SampleMenu = 1,        //测量区域右键菜单        MeasureMenu = 2,        //线程运行后菜单        ThreadRunMenu = 3,        //样品台右键菜单        SampleStateMenu = 4,        //样品孔BSE图像        SampleHoleBSEImage = 5,        //帧图菜单        FieldMenu = 6    }    public enum MenuIndex    {        AddSample = 0,        DeleteSample = 1,        SampleStripSeparator = 2,        ReadSEMData = 3,        SetSemData = 4,        SetSEMCenterLocation = 5,        DriveSEMToCenterLocation = 6,        DriveSEMToCurrentLocation = 7,        SEMStripSeparator = 8,        ShootBSEPicture = 9,        DeleteBSEPicture = 10,        DeleteSampleData = 11,        SlopFocus = 12    }    public partial class OTSSamplespaceWindow : DockContent    {        #region 全局变量定义        public CVisualStage m_visualStage;               string m_SampleHoleSelectName = string.Empty;        public string m_SampleSelectName = string.Empty;        public List<CVisualSampleArea> m_visualSamples;        //手绘测量区域        public static CRectangleGDIObject m_DrawMeasureGDIObject = new CRectangleGDIObject();        //多边形测量区域完成标识        public static CRectangleGDIObject m_DrawPolygonFinishGDIObject;        //主窗体对象        OTSIncAMeasureAppForm m_MeasureAppForm;        SEMDATAFieldManage m_SEMDATAFieldManage;        private _5_OTSMeasureStatuImageFun.SlopFocus slopFocus = null;        const float m_PenWidth = 5;        const int m_MinMeasureWidthValue = 20;        //点数量        const int m_PolygonMinPointCount = 2;        //与多边形绘制的开始点相差的像素值        const int m_OffsetPX = 10;        //默认值        const int m_DValue = 1;        #region 手动绘制测量区域        Point m_MouseDownPoint;        Point m_MouseMovePoint;        //手动绘制多边形测量区域完成标识        bool m_IsDrawPolygonFinish = false;        //手动绘制测量区域的形状类型        CreateRectangleType m_DrawMeasureType = (CreateRectangleType)1;        //是否手绘标识        bool m_IsDrawMeasure = false;        #endregion        #endregion        NLog.Logger log;        #region 标尺变量        //最小缩放倍数        const float f_zoom_mix = 0.5f;        //标尺的大小记录        private float f_ruler_size = 100;        //标尺原先大小的记录,参与计算        private float f_old_ruler_size = 100;        #endregion        //国际化        OTSCommon.Language lan;        Hashtable table;        #region 设置双缓冲        /// <summary>        /// 设置双缓冲        /// </summary>        public void SetDoubleBufferByIsDraw()        {            SetStyle(ControlStyles.UserPaint, true);            SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // 双缓冲        }        #endregion        CFieldPositionHelper pFieldMgr = new CFieldPositionHelper();        #region 构造函数 获取父窗体对象        public OTSSamplespaceWindow(OTSIncAMeasureAppForm MeasureAppForm)        {            InitializeComponent();            m_MeasureAppForm = MeasureAppForm;            SetDoubleBufferByIsDraw();// 双缓冲            //国际化            lan = new OTSCommon.Language(this);            table = lan.GetNameTable(this.Name);        }        #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.AddNewSampleMeasure(m_SampleHoleSelectName);                    break;                case "DeleteStage":                    //删除样品                    DeleteSampleInfo(m_SampleSelectName);                    break;                case "DriveSEMToCenterLocation":                    //驱动SEM到中心位置                    SetSEMToCenterPoint();                    ReadSEMDataAndSetToCurrentSample();                    PrepareMeasureField(GetWorkingVisualSample(), MSR_RUN_TYPE.RUNMEASURE);                    break;                case "DriveSEMToCurrentLocation":                    //驱动SEM到当前位置                    SetSEMCurrentLocation();                    ReadSEMDataAndSetToCurrentSample();                    PrepareMeasureField(GetWorkingVisualSample(), MSR_RUN_TYPE.RUNMEASURE);                    break;                case "SetSEMCenterLocation":                    //将测量区域移到SEM当前位置                    SetMeasureToSEMLocation();                    ReadSEMDataAndSetToCurrentSample();                    PrepareMeasureField(GetWorkingVisualSample(), MSR_RUN_TYPE.RUNMEASURE);                    break;                case "ReadSEMData":                    m_MeasureAppForm.SetRunType(MSR_RUN_TYPE.RUNMEASURE);                    ReadSEMDataAndSetToCurrentSample();                    PrepareMeasureField(GetWorkingVisualSample(), MSR_RUN_TYPE.RUNMEASURE);                    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.SetRunType(MSR_RUN_TYPE.RUNSampleHoleImage);                    PrepareMeasureField(GetWorkingVisualSample(), MSR_RUN_TYPE.RUNSampleHoleImage);                    m_MeasureAppForm.StartSampleHoleBSEImage();                    break;                case "DeleteBSEPicture":                    DeleteHoleBSEImageDataNoMessageBox();                    break;                case "DeleteSampleData":                    try                                        {                        var frmFieldStart = new frmInitializeStartInput();                        frmFieldStart.ShowDialog();                        if (frmFieldStart.okcancel==true)                        {                            m_MeasureAppForm.m_ProjParam.InitWorkingSampleData(frmFieldStart.fieldStartNo);                            m_MeasureAppForm.InitCurrentSampleState();                            var visualsam = GetWorkingVisualSample();                            var sam=m_MeasureAppForm.m_ProjRstData.GetWorkingSample();                            var allflds = sam.GetFieldsData();                            foreach (var f in allflds)                            {                                if (f.GetMeasureSequence() >= frmFieldStart.fieldStartNo)                                {                                    Color ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.FieldColor);                                    ChangeMeasureFieldColor(visualsam, f.GetOTSPosition(), ColorStr);                                }                                                           }                                                        m_MeasureAppForm.m_MeasureResultWindow.UpdateResultInfoBySampleName(sam.GetName());                                                   }                    }                    catch (Exception ex)                    {                        MessageBox.Show(ex.ToString());                    }                    break;                case "SlopFocusMenuItem":                    if (slopFocus == null)                    {                        slopFocus = new _5_OTSMeasureStatuImageFun.SlopFocus(this);                    }                    slopFocus.Show();                    break;            }        }        #endregion        /// <summary>        /// 画圆形测试区域 事件        /// </summary>        public void DrawCircleMeasure()        {            //手绘测量区域类型为圆形            m_DrawMeasureType = CreateRectangleType.Circle;            m_IsDrawMeasure = true;            m_DrawMeasureGDIObject = null;            this.Cursor = Cursors.Hand;        }        /// <summary>        /// 画矩形测试区域 事件        /// </summary>        public void DrawRectangleMeasure()        {            //手绘测量区域类型为矩形            m_DrawMeasureType = CreateRectangleType.SampleBackGround_Rectangle;            m_IsDrawMeasure = true;            m_DrawMeasureGDIObject = null;            this.Cursor = Cursors.Hand;        }        /// <summary>        /// 画多边形测试区域 事件        /// </summary>        public void DrawPolygonMeasure()        {            m_DrawMeasureType = CreateRectangleType.Polygon;            m_IsDrawMeasure = true;            m_DrawMeasureGDIObject = null;            this.Cursor = Cursors.Hand;        }        /// <summary>        /// 三点画圆形测试区域 事件  先多边形后圆形        /// </summary>        public void DrawCircleMeasureByThreePoints()        {            //手绘测量区域类型为圆形            m_DrawMeasureType = CreateRectangleType.CircleByThreePoints;            m_IsDrawMeasure = true;            m_DrawMeasureGDIObject = null;            this.Cursor = Cursors.Hand;        }        public void DrawRingShapeArea()        {            //手绘测量区域类型为圆形            m_DrawMeasureType = CreateRectangleType.RingShape;            RingGdiDataInput frmInput = new RingGdiDataInput();            if (frmInput.ShowDialog() == DialogResult.OK)            {                float diameter = (float)m_visualStage.MicronConvertToPixel(frmInput.Diameter);                float ringwidth = (float)m_visualStage.MicronConvertToPixel(frmInput.RingWidth);                var sam = GetWorkingVisualSample();                SizeF size = new SizeF(diameter, diameter);                var position = sam.GetMeasureGDIObject().GetZoomedRegionF().Location;                RectangleF rec = sam.GetMeasureGDIObject().GetZoomedRegionF();                PointF centerPos = new PointF(position.X + rec.Width / 2, position.Y + rec.Height / 2);                PointF newRegionFPos = new PointF(centerPos.X - diameter / 2, centerPos.Y - diameter / 2);                RectangleF rectangle = new RectangleF(newRegionFPos, size);                Color MeasureColor = Color.Red;                CRingGDIObject newGDI;                newGDI = new CRingGDIObject(rectangle, CreateRectangleType.RingShape, sam.GetSampleGDIObject().NameOrHoleName, sam.GetSampleName(), MeasureColor);                newGDI.SetRingWidth(ringwidth);                newGDI.SetZoomNumber(m_visualStage.GetZoomNum());                newGDI.SetDisplayRefPoint(m_visualStage.GetDisplayRefPoint());                newGDI.IsWorkSample = true;                sam.SetMeasureGDIObject(newGDI);                m_DrawPolygonFinishGDIObject = null;                m_DrawMeasureGDIObject = null;                var para = m_visualStage.GetSampleMeasurePara(sam.GetMeasureGDIObject());                m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);            }        }                public CVisualSampleArea GetWorkingVisualSample()        {            foreach (var s in m_visualSamples)            {                if (s.IsWorkSample())                {                    return s;                }            }            return null;        }        public CVisualSampleArea GetVisualSampleByName(string name)        {            foreach (var s in m_visualSamples)            {                if (s.GetSampleName() == name)                {                    return s;                }            }            return null;        }        public void DisplayVisualStage(CStage SStage, CSEMStageData SEMStageData)        {            m_visualStage.clear();            m_visualStage.InitSampleStageData(SStage, SEMStageData, this.Width, this.Height);            m_visualStage.DrawSampleStage();        }        public void DisplayExistSamples(List<SampleMeasurePara> SMeasrueParaList)        {                       foreach (var SMeasrueArea in SMeasrueParaList)            {                DisplaySample(SMeasrueArea);            }            SwitchWorkSample(SMeasrueParaList[0].sSampleName);            m_SampleSelectName = SMeasrueParaList[0].sSampleName;            //重新绘制            Invalidate();        }        public void DisplaySample(SampleMeasurePara SMeasrueArea)        {            var m_Sample = m_MeasureAppForm.m_ProjParam.GetResultData().GetSampleByName(SMeasrueArea.sSampleName);            var FldDatas = m_Sample.GetFieldsData();            if (FldDatas.Count == 0)            {                //this part code is to be compatible with previouse version result file which there's no AllField position info.                DrawSampleAndMeasureInfo(SMeasrueArea);            }            else            {                var item = m_visualStage.GetHoleGDIByHoleName(SMeasrueArea.sampleHoleName);                if (item != null)                {                    CVisualSampleArea sam;                    if (InitVisualSample(SMeasrueArea.sampleHoleName, SMeasrueArea.sSampleName, out sam))                    {                        if (SMeasrueArea.iShape == (ShapeType)CreateRectangleType.Polygon)                        {                            var ps = new List<PointF>();                            foreach (var p in SMeasrueArea.DrawPolygonPointList)                            {                                var ctrlcoordPoint = m_visualStage.OTSCoordToCtrlCoord(p);                                ps.Add(ctrlcoordPoint);                            }                            CRectangleGDIObject polygonGdi = new CRectangleGDIObject(ps, CreateRectangleType.Polygon, (ShapeType)SMeasrueArea.iShape, SMeasrueArea.sampleHoleName, SMeasrueArea.sSampleName, Color.Red);                            sam.SetMeasureGDIObject(polygonGdi);                        }                        else                        {                            PointF xHole = new PointF(SMeasrueArea.MeasureRect.Left, SMeasrueArea.MeasureRect.Top);                            PointF yHole = new PointF(SMeasrueArea.MeasureRect.Right, SMeasrueArea.MeasureRect.Bottom);                            CRectangleGDIObject gdi = m_visualStage.GetCtrlCoordRect(xHole, yHole, (CreateRectangleType)SMeasrueArea.iShape, "", "");                            gdi.SampleName = SMeasrueArea.sSampleName;                            gdi.NameOrHoleName = SMeasrueArea.sampleHoleName;                            gdi.Shape = SMeasrueArea.iShape;                            CRectangleGDIObject measureGdi;                            if (m_visualStage.GetMeasureGdiObjectFromSampleGdi(gdi, out measureGdi))                            {                                sam.SetMeasureGDIObject(measureGdi);                            }                        }                        List<CRectangleGDIObject> visualfieldRects = new List<CRectangleGDIObject>();                        foreach (var fld in FldDatas)                        {                            float micronWidth = (float)fld.GetOTSRect().GetWidth();                            float micronHeight = (float)fld.GetOTSRect().GetHeight();                            var fldRect = new RectangleF(new PointF(fld.GetOTSPosition().X - micronWidth / 2, fld.GetOTSPosition().Y - micronHeight / 2), new SizeF(micronWidth, micronHeight));                            PointF lt = new PointF(fldRect.Left, fldRect.Top);                            PointF rb = new PointF(fldRect.Right, fldRect.Bottom);                            RectangleF visualRect = m_visualStage.GetCtrlCoordRectF(lt, rb);                            var ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.FieldColor);                            string sampleName = sam.GetSampleName();                            string sampleHoleName = sam.GetSampleGDIObject().NameOrHoleName;                            CRectangleGDIObject createRect = new CRectangleGDIObject(visualRect, (int)fld.GetOTSPosition().X, (int)fld.GetOTSPosition().Y, CreateRectangleType.FieldRectangle, sampleHoleName, sampleName, ColorStr);                            visualfieldRects.Add(createRect);                        }                        sam.GetMeasureGDIObject().SubItems().Clear();                        //添加帧图列表                        int sequenceNum = 0;                        foreach (var r in visualfieldRects)                        {                            if (sam.GetMeasureGDIObject().ifRectangleIntersect(r))//filter the unmeasure fields                            {                                r.SequenceNum = sequenceNum++;                                sam.AddFieldGDIObject(r);                            }                        }                        COTSMsrPrjResultData cProjMgr = m_MeasureAppForm.m_ProjParam.GetResultData();                        List<PointF> CompleteFieldList = cProjMgr.GetSampleByName(SMeasrueArea.sSampleName).GetMsrStatus().GetCompletedFieldsCenter();                        if (CompleteFieldList.Count > 0)                        {                            ChangeCompleteFieldMeasureState(CompleteFieldList, Color.Green, sam);                        }                    }                }            }        }        public void SwitchWorkSample(string sNewWSampleName, bool bDrawField = false)        {            try            {                for (int i = 0; i < m_visualSamples.Count; i++)                {                    //获取颜色                    if (m_visualSamples[i].GetSampleName() == sNewWSampleName)                    {                        var ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);                        m_visualSamples[i].GetSampleGDIObject().SelColor =ColorStr;                        m_visualSamples[i].SetIsWorkSample(true);                    }                    else                    {                        var SampleColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);                        m_visualSamples[i].GetSampleGDIObject().SelColor = SampleColorStr;                        m_visualSamples[i].SetIsWorkSample(false);                    }                }                m_IsDrawMeasure = false;                this.Invalidate();                return;            }            catch (Exception ex)            {                log.Trace(ex.ToString());            }        }        public void ChangeCompleteFieldMeasureState(List<PointF> CompleteFieldList, Color changeColor, CVisualSampleArea vsSam)        {            foreach (var p in CompleteFieldList)            {                ChangeMeasureFieldColor(vsSam, p, changeColor);            }        }        public void ChangeMeasureFieldColor(CVisualSampleArea vsSam, PointF CurrentFIELDOTSPoint, Color changeColor)        {            foreach (var gdi in vsSam.GetMeasureFieldGDIObjects())            {                var fieldPoint = m_visualStage.OTSCoordToCtrlCoord(new PointF((float)CurrentFIELDOTSPoint.X, (float)CurrentFIELDOTSPoint.Y));                if (gdi.IfContains(fieldPoint))                {                    //修改完成状态                    gdi.SelColor = changeColor;                    break;                }            }        }        public void ChangeWorkSampleName(string sNewWSampleName)        {            //更换样品名称            var sam = GetWorkingVisualSample();            sam.SetSampleName(sNewWSampleName);            this.Invalidate();            return;        }        public void SetMeasureState(Color setColor)        {            foreach (var items in m_visualSamples)            {                items.GetMeasureGDIObject().SelColor = setColor;            }        }        #endregion        public void SetSampleState(Color setColor)        {            foreach (var items in m_visualSamples)            {                if (items.GetSampleGDIObject().IsDragging)                {                    //设置颜色                    var ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);                    items.GetSampleGDIObject().SelColor = ColorStr;                }                else                {                    items.GetSampleGDIObject().SelColor = setColor;                }            }        }        public bool DeleteSample(string SampleName)        {            var sam = GetVisualSampleByName(SampleName);            m_visualStage.DecreaseSampleCount(SampleName);            m_visualSamples.Remove(sam);            var ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);            SetSampleState(ColorStr);            SetMeasureState(ColorStr);            return false;        }        public void DeleteWorkSample(string sDeleteWSampleName)        {            try            {                DeleteSample(sDeleteWSampleName);            }            catch (Exception ex)            {                log.Error(ex.ToString());            }        }        #region 更改工作样品中 测量区域形状        public void changeShape(ShapeType iShape)        {            try            {                string sampleName = m_MeasureAppForm.m_ProjParam.GetWorkSampleName();                //m_Shap 更换样品形状                var sam = GetWorkingVisualSample();                var itemMeasure = sam.GetMeasureGDIObject();                itemMeasure.Shape = iShape;                var sampleMeasurePara = m_visualStage.GetSampleMeasurePara(sam.GetMeasureGDIObject());                m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(sampleMeasurePara);                PrepareMeasureField(sam, m_MeasureAppForm.GetRunType());                this.Invalidate();                return;            }            catch (Exception ex)            {                log.Error(ex.ToString());            }        }        #endregion        public void AddSampleArea(SampleMeasurePara SMeasurePara)        {            try            {                CMStrip.Hide();                CVisualSampleArea sam;                //添加样品                foreach (var itemSample in m_visualSamples)                {                    //设置颜色                    var ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);                    itemSample.GetSampleGDIObject().SelColor = ColorStr;                    itemSample.SetIsWorkSample(false);                }                if (m_visualStage.GetVisualSampleArea(SMeasurePara, out sam))                {                    sam.SetIsWorkSample(true);                    m_visualSamples.Add(sam);                    m_SampleSelectName = SMeasurePara.sSampleName;                    var para = m_visualStage.GetSampleMeasurePara(sam.GetMeasureGDIObject());                    //var para = SMeasurePara;                    m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);                    Invalidate();                }            }            catch (Exception ex)            {                log.Error(ex.ToString());            }        }        public bool InitVisualSample(string SampleHoleName, string SampleName, out CVisualSampleArea outsample)        {            CRectangleGDIObject itemAdd;            //设置样品选择状态为非工作样品            foreach (var Sample in m_visualSamples)            {                var itemSample = Sample.GetSampleGDIObject();                //设置颜色                var ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);                itemSample.SelColor = ColorStr;                itemSample.IsWorkSample = false;            }            itemAdd = m_visualStage.GetHoleGDIByHoleName(SampleHoleName);            if (itemAdd != null)            {                //获取样品台类型                var shape = itemAdd.Shape;                //设置颜色                var ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);                Color selColor = ColorStr;                CRectangleGDIObject sample = new CRectangleGDIObject(itemAdd.GetOrigionalDrawRegionF(), CreateRectangleType.SelectSample, shape, itemAdd.NameOrHoleName, selColor);                //累加样品数量                itemAdd.SampleCount += 1;                itemAdd.IsWorkSample = true;                sample.SampleName = SampleName;                sample.NameOrHoleName = itemAdd.NameOrHoleName;                var newSam = new CVisualSampleArea();                newSam.SetSampleGDIObject(sample);                newSam.SetSampleName(sample.SampleName);                m_visualSamples.Add(newSam);                outsample = newSam;                return true;            }            outsample = null;            return false;        }        #region 设置工作样品        /// <summary>        /// 设置工作样品与测量区域        /// </summary>        /// <param name="sampleName">样品名称</param>        public void SetSampleOrder(string sampleName)        {            //修改测量区域集合 索引     (添加样品或者切换样品时,将当前工作样品显示在样品孔的最上)            m_visualSamples = SelectMeasureIndexIsTop(m_visualSamples, sampleName);        }        #endregion        private List<CVisualSampleArea> SelectMeasureIndexIsTop(List<CVisualSampleArea> objList, string SampleName)        {            List<CVisualSampleArea> objListTemp = objList;            CVisualSampleArea itemTemp;            foreach (CVisualSampleArea item in objList)            {                if (item.GetSampleName() == SampleName)                {                    //临时记录所选测量区域                    itemTemp = item;                    //删除原信息                    objListTemp.Remove(item);                    //添加新信息                    objListTemp.Insert(objListTemp.Count, itemTemp);                    break;                }            }            return objListTemp;        }        //响应委托事件的样品台数据        public void InitStageDisplay(CStage SStage, CSEMStageData SEMStageData)        {            m_visualStage.InitSampleStageData(SStage, SEMStageData, this.Width, this.Height);            //清除所有绘制的图形信息            ClearDrawInfo();            //绘制样品台信息            m_visualStage.DrawSampleStage();            //标尺初始化            RulerInit(m_visualStage.GetOTSSampleStageData());            ShowRulerLocation();            //图像隐藏            HideMessureStatuWindowBSEImage(m_MeasureAppForm);            //将测量结果信息状态初始化            InitMeasureStateInfo();            if (m_visualSamples.Count == 0)            {                //将测量状态初始化                m_MeasureAppForm.m_MessureStatuWindow.SetMeasureStatusInit();            }            Invalidate();        }        public void HideMessureStatuWindowBSEImage(OTSIncAMeasureAppForm m_MeasureApps)        {            m_MeasureApps.m_MessureStatuWindow.picBox.Hide();        }        #region 将测量状态进度窗口信息初始化        public void InitMeasureStateInfo()        {            m_MeasureAppForm.m_MeasureResultWindow.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));        }        #region 窗体事件        private void OTSSamplespaceWindow_Load(object sender, EventArgs e)        {            m_visualStage = new CVisualStage();            m_visualSamples = new List<CVisualSampleArea>();            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 menuType, ContextMenuStrip cmStrip)        {            switch (menuType)            {                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.DeleteSampleData].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.DeleteSampleData].Enabled = true;                    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 = true;                    cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;                    cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = true;                    cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = true;                    cmStrip.Items[(int)MenuIndex.DeleteSampleData].Enabled = false;                    cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = true;                    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 = true;                    cmStrip.Items[(int)MenuIndex.DeleteSampleData].Enabled = true;                    cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = true;                    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 = false;                    cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = false;                    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.DeleteSampleData].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 = 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.ShootBSEPicture].Enabled = true;                    cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = true;                    cmStrip.Items[(int)MenuIndex.DeleteSampleData].Enabled = false;                    cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = false;                    break;            }        }        private List<CRectangleGDIObject> GetAllVisualSampleGDIObject()        {            List<CRectangleGDIObject> allobj = new List<CRectangleGDIObject>();            foreach (var s in m_visualSamples)            {                allobj.Add(s.GetSampleGDIObject());                allobj.Add(s.GetMeasureGDIObject());                allobj.AddRange(s.FrameOfHoleGDIObjects);                foreach (var f in s.GetMeasureFieldGDIObjects())                {                    allobj.Add(f);                }            }            return allobj;        }        private List<CRectangleGDIObject> GetOnlyVisualSampleGDIObject()        {            List<CRectangleGDIObject> allobj = new List<CRectangleGDIObject>();            foreach (var s in m_visualSamples)            {                allobj.Add(s.GetSampleGDIObject());            }            return allobj;        }        private List<CRectangleGDIObject> GetAllVisualFieldGdiObject()        {            List<CRectangleGDIObject> allobj = new List<CRectangleGDIObject>();            foreach (var s in m_visualSamples)            {                allobj.Add(s.GetMeasureGDIObject());                var flds = s.GetMeasureFieldGDIObjects();                for (int i = flds.Count; i > 0; i--)//revert the sequence so that the last field will paint first.then the green or yellow rectangle can display fully.                {                    var f = flds[i - 1];                    allobj.Add(f);                }            }            return allobj;        }        private EnumMousePointPosition MousePointPosition(Point point, Point e)        {            //MouseDrag 中心            if ((e.X == point.X) && (e.Y == point.Y))            {                return EnumMousePointPosition.MouseDrag;            }            //MouseSizeTopLeft 上左            if ((e.X < point.X) && (e.Y < point.Y))            {                return EnumMousePointPosition.MouseSizeTopLeft;            }            //MouseSizeTopRight 下右            if ((e.X > point.X) && (e.Y < point.Y))            {                return EnumMousePointPosition.MouseSizeTopRight;            }            //MouseSizeLeft 左侧            if ((e.X < point.X) && (e.Y == point.Y))            {                return EnumMousePointPosition.MouseSizeLeft;            }            //MouseSizeRight 右侧            if ((e.X > point.X) && (e.Y == point.Y))            {                return EnumMousePointPosition.MouseSizeRight;            }            //MouseSizeTop 上侧            if ((e.X == point.X) && (e.Y < point.Y))            {                return EnumMousePointPosition.MouseSizeTop;            }            //MouseSizeBottom 下侧            if ((e.X == point.X) && (e.Y > point.Y))            {                return EnumMousePointPosition.MouseSizeBottom;            }            //MouseSizeBottomRight 下左            if ((e.X < point.X) && (e.Y > point.Y))            {                return EnumMousePointPosition.MouseSizeBottomLeft;            }            //MouseSizeBottomRight 下右            if ((e.X > point.X) && (e.Y > point.Y))            {                return EnumMousePointPosition.MouseSizeBottomRight;            }            return EnumMousePointPosition.MouseSizeNone;        }        protected override void OnMouseDown(MouseEventArgs e)        {            lblFocus.Focus();            bool runflag = m_MeasureAppForm.MeasureThreadRunFlag;                        Point _Point;            this.m_MouseDownPoint = new Point(e.X, e.Y);            //判断当前是否手绘            if (m_IsDrawMeasure && !runflag)            {                               COTSSample workSample = m_MeasureAppForm.m_ProjParam.GetWorkSample();                if (workSample == null) return;                string sampleHoleName = workSample.GetSampleHoleName();                string sampleName = workSample.GetName();                //绘制多边形 测量区域                if (m_DrawMeasureType == CreateRectangleType.Polygon)                {                    if (m_DrawMeasureGDIObject == null)                    {                        m_DrawMeasureGDIObject = new CRectangleGDIObject(new List<PointF>(), CreateRectangleType.Polygon, (ShapeType)m_DrawMeasureType, sampleHoleName, sampleName, Color.Red);                    }                    var polygonPoints = m_DrawMeasureGDIObject.GetPolygonPointFList();                    if (m_IsDrawPolygonFinish)                    {                        DialogResult dResult = MessageBox.Show(table["message10"].ToString(), table["message11"].ToString(), MessageBoxButtons.YesNo);                        if (dResult == DialogResult.Yes)                        {                            Point startPoint = new Point((int)(polygonPoints[0].X), (int)(polygonPoints[0].Y));//the last point is the first point too.we get the first point as the last point.                            polygonPoints.Add(startPoint);                            CRectangleGDIObject polygonGdi = new CRectangleGDIObject(polygonPoints, CreateRectangleType.Polygon, (ShapeType)m_DrawMeasureType, sampleHoleName, sampleName, Color.Red);                            polygonGdi.SetZoomNumber(m_visualStage.GetZoomNum());                            polygonGdi.SetDisplayRefPoint(m_visualStage.GetDisplayRefPoint());                            polygonGdi.SetPolygonPointFList(polygonPoints);                            polygonGdi.IsWorkSample = true;                            var sam = GetVisualSampleByName(sampleName);                            if (sam == null) return;                            sam.SetMeasureGDIObject(polygonGdi);                            m_DrawPolygonFinishGDIObject = null;                            m_DrawMeasureGDIObject = null;                            var para = m_visualStage.GetSampleMeasurePara(sam.GetMeasureGDIObject());                            m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);                            m_MeasureAppForm.SwitchWSample(m_SampleSelectName);                            //-------------------- draw measrue field and save these data to sample                            PrepareMeasureField(sam, MSR_RUN_TYPE.RUNMEASURE);                            //--------------------                            Invalidate();                            m_IsDrawMeasure = false;                            m_IsDrawPolygonFinish = false;                            this.Cursor = Cursors.Default;                            return;                        }                        else                        {                            return;                        }                    }                    polygonPoints.Add(m_MouseDownPoint);                    m_DrawMeasureGDIObject.SetPolygonPointFList(polygonPoints);                    return;                }                else if (m_DrawMeasureType == CreateRectangleType.CircleByThreePoints)                {                    if (m_DrawMeasureGDIObject == null)                    {                        m_DrawMeasureGDIObject = new CRectangleGDIObject(new List<PointF>(), CreateRectangleType.Polygon, (ShapeType)m_DrawMeasureType, sampleHoleName, sampleName, Color.Red);                    }                    var m_PolygonPoint = m_DrawMeasureGDIObject.GetPolygonPointFList();                    m_PolygonPoint.Add(m_MouseDownPoint);                    if (m_PolygonPoint.Count == 3)//three point can make a circle .                    {                        m_DrawMeasureType = (int)CreateRectangleType.Circle;                        float r;                        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;                        CRectangleGDIObject CRectangleGDI = new CRectangleGDIObject(rectangleThree, CreateRectangleType.CircleByThreePoints, (ShapeType)m_DrawMeasureType, sampleHoleName, sampleName, MeasureColor);                        m_DrawMeasureGDIObject = CRectangleGDI;                        m_DrawMeasureGDIObject.SetZoomNumber(m_visualStage.GetZoomNum());                        m_DrawMeasureGDIObject.SetDisplayRefPoint(m_visualStage.GetDisplayRefPoint());                        var sam1 = GetVisualSampleByName(sampleName);                        if (sam1 == null) return;                        sam1.SetMeasureGDIObject(m_DrawMeasureGDIObject);                        sam1.GetMeasureGDIObject().SetZoomedRegionF(rectangleThree);                        m_DrawMeasureGDIObject = null;                        var para = m_visualStage.GetSampleMeasurePara(sam1.GetMeasureGDIObject());                        m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);                        m_MeasureAppForm.SetRunType(MSR_RUN_TYPE.RUNMEASURE);                        m_MeasureAppForm.SwitchWSample(m_SampleSelectName);                        Invalidate();                        //设置手绘标识                        m_IsDrawMeasure = 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;                    }                    int sizeWH = 5;                    Size size = new Size(sizeWH, sizeWH);                    Rectangle rectangle = new Rectangle(m_MouseDownPoint, size);                    Color MeasureColor = Color.Red;                    CRectangleGDIObject newGDI;                    newGDI = new CRectangleGDIObject(rectangle, CreateRectangleType.MeasureArea, (ShapeType)m_DrawMeasureType, sampleName, sampleName, MeasureColor);                    newGDI.SetZoomNumber(m_visualStage.GetZoomNum());                    newGDI.SetDisplayRefPoint(m_visualStage.GetDisplayRefPoint());                    m_DrawMeasureGDIObject = newGDI;                    return;                }            }            else if (!m_IsDrawMeasure)            {                if (e.Button == MouseButtons.Right)                {                    if (m_MeasureAppForm.MeasureThreadRunFlag)                    {                        SetShowCMStrip(ContextMenuType.ThreadRunMenu, CMStrip);                        _Point = this.PointToClient(Cursor.Position);                        this.CMStrip.Show(this, _Point);                        return;                    }                    //获取鼠标右键点击位置                    m_MouseDownPoint = e.Location;                    var workingSam = GetWorkingVisualSample();                    if (workingSam != null)                    {                        foreach (CRectangleGDIObject item in workingSam.GetMeasureFieldGDIObjects())                        {                            if (item.IfZoomContains(e.Location))                            {                                                           _Point = this.PointToClient(Cursor.Position);                                                                                               SetShowCMStrip(ContextMenuType.FieldMenu, CMStrip);                                this.CMStrip.Show(this, _Point);                                return;                            }                        }                    }                    foreach (var item in m_visualSamples)                    {                        bool isSelectingMeasureArea = false;                        if (item.GetMeasureGDIObject().CreateType == CreateRectangleType.Polygon)                        {                            if (item.GetMeasureGDIObject().GetGPath().IsVisible(e.Location))                            {                                isSelectingMeasureArea = true;                            }                        }                        else                        {                            if (item.GetMeasureGDIObject().IfZoomContains(e.Location) )                            {                                isSelectingMeasureArea = true;                                int WH = 2;                                Rectangle rect = new Rectangle(e.Location, new Size(WH, WH));                                if (!m_visualStage.CheckMeasureAreaIsBeyondStageArea(rect))                                {                                    break;                                }                            }                        }                        if (isSelectingMeasureArea)                        {                            SetShowCMStrip(ContextMenuType.MeasureMenu, CMStrip);                            _Point = this.PointToClient(Cursor.Position);                            this.CMStrip.Show(this, _Point);                            m_SampleHoleSelectName = item.GetMeasureGDIObject().NameOrHoleName;                            if (m_SampleSelectName != item.GetMeasureGDIObject().SampleName)                            {                                m_SampleSelectName = item.GetSampleName();                                                              item.SetIsWorkSample(true);                                //设置工作样品                                m_MeasureAppForm.SwitchWSample(m_SampleSelectName);                                Invalidate();                            }                            return;                        }                    }                    if (GetWorkingVisualSample() != null)                    {                        foreach (CRectangleGDIObject item in GetWorkingVisualSample().FrameOfHoleGDIObjects)                        {                            if (item.IfZoomContains(e.Location))                            {                                                                _Point = this.PointToClient(Cursor.Position);                                                             SetShowCMStrip(ContextMenuType.SampleHoleBSEImage, CMStrip);                                this.CMStrip.Show(this, _Point);                                return;                            }                        }                    }                    //只点击样品上(测量区域被移动到其他地方)                    for (int i = m_visualSamples.Count - 1; i >= 0; i--)                    {                        if (m_visualSamples[i].GetSampleGDIObject().IfZoomContains(e.Location))                        {                            _Point = this.PointToClient(Cursor.Position);                                                      //设置编辑右键菜单项                            SetShowCMStrip(ContextMenuType.SampleMenu, CMStrip);                            this.CMStrip.Show(this, _Point);                            if (m_SampleSelectName != m_visualSamples[i].GetSampleName())                            {                                m_SampleSelectName = m_visualSamples[i].GetSampleName();                                m_SampleHoleSelectName = m_visualSamples[i].GetMeasureGDIObject().NameOrHoleName;                                m_visualSamples[i].SetIsWorkSample(true);                                m_MeasureAppForm.SwitchWSample(m_SampleSelectName);                                Invalidate();                            }                            return;                        }                    }                    //点击样品孔                    CRectangleGDIObject gdiitem;                    if (m_visualStage.IfMouseInSampleHole(e.Location, out gdiitem))                    {                        _Point = this.PointToClient(Cursor.Position);                                               SetShowCMStrip(ContextMenuType.SampleHoleMenu, CMStrip);                                              this.CMStrip.Show(this, _Point);                        m_SampleHoleSelectName = gdiitem.NameOrHoleName;                        return;                    }                    if (m_visualStage.IfMouseInStage(e.Location))                    {                                              SetShowCMStrip(ContextMenuType.SampleStateMenu, CMStrip);                        _Point = this.PointToClient(Cursor.Position);                        this.CMStrip.Show(this, _Point);                        return;                    }                    return;                }                else if (e.Button == MouseButtons.Left)                {                                     //测量区域                    if (Control.ModifierKeys == Keys.Control)// ctrl key is pressed,means changing position or altering the visual sample area.                    {                        var sam = GetWorkingVisualSample();                        if (sam != null)                        {                            var item = sam.GetMeasureGDIObject();                            var selWSampleMeasureStatus = m_MeasureAppForm.m_ProjParam.GetWorkSampleMeasureStatus();                            if (selWSampleMeasureStatus)                            {                                return;                            }                            if (item.CreateType == CreateRectangleType.Polygon)                            {                                bool isSelPolygonPoint = false;                                foreach (PointF itemPoint in item.GetPolygonPointFList())                                {                                    if (Math.Abs(itemPoint.X - e.X) <= m_OffsetPX && Math.Abs(itemPoint.Y - e.Y) <= m_OffsetPX)                                    {                                        isSelPolygonPoint = true;                                        item.SelColor = Color.Red;                                        item.DraggingPoint = new PointF(itemPoint.X, itemPoint.Y);//e.Location;                                        item.IsAltering = true;//this state means operator want to alter the size of the polygon shape.                                        item.IsDragging = false;                                        break;                                    }                                }                                if (!isSelPolygonPoint)//not selecting the polygon point,just dragging on the inside area of the polygon shape.                                {                                    if (item.GetGPath().IsVisible(e.Location))                                    {                                        item.SelColor = Color.Red;                                        item.IsDragging = true;                                        item.DraggingPoint = e.Location;                                        item.IsAltering = false;                                    }                                }                            }                            else                            {                                if (item.GetGPath().IsOutlineVisible((float)e.X, (float)e.Y, new Pen(Color.Gray, m_PenWidth)))                                {                                    item.SelColor = Color.Red;                                    item.IsDragging = false;                                    item.DraggingPoint = e.Location;                                    item.IsAltering = true;                                }                                else//not outlinevisible then is altering sample area position.                                {                                    if (item.IfZoomContains(e.Location))                                    {                                        item.SelColor = Color.Red;                                        item.IsDragging = true;                                        item.DraggingPoint = e.Location;                                        item.IsAltering = false;                                    }                                }                            }                        }                    }                    //click on the sample area without ctrl key,just switch to that sample.                    if (!(Control.ModifierKeys == Keys.Control) && !runflag)                    {                        for (int i = m_visualSamples.Count - 1; i >= 0; i--)                        {                            var sam1 = m_visualSamples[i];                            if (sam1.GetSampleGDIObject().IfZoomContains(e.Location) || sam1.GetMeasureGDIObject().IfZoomContains(e.Location))                            {                                //NLog.LogManager.GetCurrentClassLogger().Info(sam1.GetMeasureGDIObject().GetOrigionalDrawRegionF().ToString());                                var measureItem = sam1.GetMeasureGDIObject();                                measureItem.SelColor = Color.Red;                                //设置为工作样品                                sam1.SetIsWorkSample(true);                                //获取颜色                                var ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);                                sam1.GetSampleGDIObject().SelColor = ColorStr;                                m_SampleSelectName = sam1.GetSampleName();                                m_MeasureAppForm.SwitchWSample(m_SampleSelectName);                                break;                            }                        }                    }                    CRectangleGDIObject stageobj;                    if (m_visualStage.IfMouseInStage(e.Location, out stageobj) )                    {                        MouseDownFunction(m_visualStage.GetAllGDIObject(), e);                        //样品                        MouseDownFunction(GetAllVisualSampleGDIObject(), e);                    }                }            }            //重绘控件            Invalidate();        }        protected override void OnMouseMove(MouseEventArgs e)        {                bool runflag = m_MeasureAppForm.MeasureThreadRunFlag;            this.m_MouseMovePoint = new Point(e.X, e.Y);            if (m_IsDrawMeasure && !runflag)            {                                if (m_DrawMeasureGDIObject == null) return;//the object must be initialized by mousedown event.                //绘制多边形                if (m_DrawMeasureType == CreateRectangleType.Polygon)                {                    m_DrawMeasureGDIObject.PolygonDrawingEndPoint = this.m_MouseMovePoint;                    var m_PolygonPoint = m_DrawMeasureGDIObject.GetPolygonPointFList();                    //显示直线开始点与鼠标当前位置的直线                    PointF startPoint = new PointF();                    if (m_PolygonPoint.Count > 0)                    {                        startPoint = m_PolygonPoint[0];                    }                    //显示绘制多边形完成标识                    if (m_PolygonPoint.Count > m_PolygonMinPointCount)                    {                        if (Math.Abs(m_MouseMovePoint.X - startPoint.X) <= m_OffsetPX && Math.Abs(m_MouseMovePoint.Y - startPoint.Y) <= m_OffsetPX)                        {                            //显示绘制多边形完成标识                            m_IsDrawPolygonFinish = true;                            int rectSize = m_MinMeasureWidthValue;                            if (m_DrawPolygonFinishGDIObject == null)                            {                                Point PolygonFinishPoint = new Point((int)(startPoint.X - m_MinMeasureWidthValue / 2), (int)(startPoint.Y - m_MinMeasureWidthValue / 2));                                Rectangle pRect = new Rectangle(PolygonFinishPoint, new Size(rectSize, rectSize));                                CRectangleGDIObject createPolygonFinish = new CRectangleGDIObject(pRect, CreateRectangleType.DrawPolygonFinish, "", "", Color.Green);                                m_DrawPolygonFinishGDIObject = createPolygonFinish;                            }                        }                        else                        {                            m_DrawPolygonFinishGDIObject = null;                            m_IsDrawPolygonFinish = false;                        }                    }                }                //圆形三点法                else if (m_DrawMeasureType == CreateRectangleType.CircleByThreePoints)                {                    m_DrawMeasureGDIObject.PolygonDrawingEndPoint = this.m_MouseMovePoint;                }                else                {                    if (m_DrawMeasureGDIObject == null)                    {                        return;                    }                    RectangleF rectangle = m_DrawMeasureGDIObject.GetZoomedRegion;                    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;                    }                    EnumMousePointPosition enumMouse = MousePointPosition(m_MouseDownPoint, m_MouseMovePoint);                    Point LTPoint = new Point();                    Size RBSize = new Size();                    switch (enumMouse)                    {                        case 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 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 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 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))                    {                        var rec = new Rectangle(LTPoint, RBSize);                        m_DrawMeasureGDIObject.SetZoomedRegionF(new RectangleF(new PointF((rec.X), (rec.Y)), new SizeF(rec.Width, rec.Height)));                    }                }            }            if ((Control.ModifierKeys == Keys.Control) && !runflag)//is dragging on the edge or on the vertex so we can alter the size of the item.            {                var sam = GetWorkingVisualSample();                if (sam == null) return;                var curMeasureGdi = sam.GetMeasureGDIObject();                if (curMeasureGdi.IsAltering)//click on the  edge or on the polygon point(or vertex point of rectangle).                {                    if (curMeasureGdi.CreateType == CreateRectangleType.Polygon)                    {                        for (int i = 0; i < curMeasureGdi.GetPolygonPointFList().Count; i++)                        {                            if (curMeasureGdi.GetPolygonPointFList()[i].X == curMeasureGdi.DraggingPoint.X && curMeasureGdi.GetPolygonPointFList()[i].Y == curMeasureGdi.DraggingPoint.Y)                            {                                //移动点的位置                                RectangleF selPolygonPointRect = new RectangleF(0, 0, 2, 2);                                selPolygonPointRect.X = curMeasureGdi.DraggingPoint.X + e.X - curMeasureGdi.DraggingPoint.X;                                selPolygonPointRect.Y = curMeasureGdi.DraggingPoint.Y + e.Y - curMeasureGdi.DraggingPoint.Y;                                //判断样品是否超越样品台                                if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(selPolygonPointRect))                                {                                    List<PointF> polygonPs = curMeasureGdi.GetPolygonPointFList();                                    if (i == 0 || i == curMeasureGdi.GetPolygonPointFList().Count - 1)                                    {                                        curMeasureGdi.DraggingPoint = new Point(e.X, e.Y);                                        polygonPs[0] = curMeasureGdi.DraggingPoint;                                        polygonPs[curMeasureGdi.GetPolygonPointFList().Count - 1] = curMeasureGdi.DraggingPoint;//the last point and the first point of one polygon object are the same.                                    }                                    else                                    {                                        curMeasureGdi.DraggingPoint = new Point(e.X, e.Y);                                        polygonPs[i] = curMeasureGdi.DraggingPoint;                                    }                                    curMeasureGdi.SetPolygonPointFList(polygonPs);                                    curMeasureGdi.DraggingPoint = e.Location;                                    break;                                }                            }                        }                    }                    else                    {                        if (curMeasureGdi.Shape == ShapeType.RECTANGLE)                        {                            List<PointF> vertexPoint = curMeasureGdi.GetVertexPoints();                            var oldRegion = curMeasureGdi.GetZoomedRegionF();                            for (int i = 0; i < vertexPoint.Count; i++)                            {                                var itemPoint = vertexPoint[i];                                PointF lefttop, leftBottom, rightTop, rightBottom;                                float width;                                float height;                                if (Math.Abs(itemPoint.X - e.X) <= m_OffsetPX && Math.Abs(itemPoint.Y - e.Y) <= m_OffsetPX)                                {                                    switch (i)                                    {                                        case 0://left top point                                            lefttop = new PointF(e.X, e.Y);                                            width = vertexPoint[2].X - e.X;                                            height = vertexPoint[1].Y - e.Y;                                            curMeasureGdi.SetZoomedRegionF(new RectangleF(lefttop, new SizeF(width, height)));                                            break;                                        case 1://left bottom                                            leftBottom = new PointF(e.X, e.Y);                                            width = vertexPoint[3].X - e.X;                                            height = -(vertexPoint[0].Y - e.Y);                                            curMeasureGdi.SetZoomedRegionF(new RectangleF(new PointF(leftBottom.X, leftBottom.Y - height), new SizeF(width, height)));                                            break;                                        case 2://right top                                             rightTop = new PointF(e.X, e.Y);                                            width = -(vertexPoint[0].X - e.X);                                            height = (vertexPoint[3].Y - e.Y);                                            curMeasureGdi.SetZoomedRegionF(new RectangleF(new PointF(rightTop.X - width, rightTop.Y), new SizeF(width, height)));                                            break;                                        case 3://right bottom                                            rightBottom = new PointF(e.X, e.Y);                                            width = (e.X - vertexPoint[0].X);                                            height = (e.Y - vertexPoint[0].Y);                                            curMeasureGdi.SetZoomedRegionF(new RectangleF(new PointF(rightBottom.X - width, rightBottom.Y - height), new SizeF(width, height)));                                            break;                                    }                                    Invalidate();                                }                            }                        }                        else                        {                            PointF gdicenter = m_visualStage.GetCenterPoint(curMeasureGdi.GetZoomedRegion);                            //获取鼠标坐标                            PointF mousePoint = e.Location;                            RectangleF rectTemp;                            //计算偏离半径                            float a = (gdicenter.X - mousePoint.X) * (gdicenter.X - mousePoint.X);                            float b = (gdicenter.Y - mousePoint.Y) * (gdicenter.Y - mousePoint.Y);                            float c = a + b;                            double r = System.Math.Sqrt(c);                            float width = (float)r * 2;                            rectTemp = new RectangleF(gdicenter.X - (float)r, gdicenter.Y - (float)r, width, width);                            if (m_visualStage.CheckMeasureAreaIsBeyondStageArea(rectTemp))                            {                                //如果大于最小测量高度 设置图形大小                                if (rectTemp.Width / curMeasureGdi.GetZoomNumber() > m_MinMeasureWidthValue)                                {                                    curMeasureGdi.SetZoomedRegionF(rectTemp);                                    curMeasureGdi.DraggingPoint = e.Location;                                }                            }                            else                            {                                return;                            }                            Invalidate();                            return;                        }                    }                }                else if (curMeasureGdi.IsDragging)                {                    if (curMeasureGdi.GetGPath().IsVisible(e.Location))                    {                        if (m_visualStage.GetEdgeGDIObj().GetGPath().IsVisible(e.Location))                        {                            curMeasureGdi.PositionAltering(e.Location, true);                        }                    }                }            }            else            {                //样品台                MouseMoveFucntion(m_visualStage.GetAllGDIObject(), e);                //样品                MouseMoveFucntion(GetAllVisualSampleGDIObject(), e);                if (GetWorkingVisualSample() != null)                {                    //样品孔BSE图片                    MouseMoveFucntion(GetWorkingVisualSample().FrameOfHoleGDIObjects, e);                }            }            //显示XY轴            m_visualStage.ShowSemCoordvAL(e.Location, m_MeasureAppForm);            Invalidate();        }        protected override void OnMouseUp(MouseEventArgs e)        {            //如果正在进行测量线程,则退出鼠标点击操作            var runflag = m_MeasureAppForm.MeasureThreadRunFlag;                       var sam = GetWorkingVisualSample();            //判断当前是否手绘            if (m_IsDrawMeasure&& !runflag)            {                //绘制多边形                if (m_DrawMeasureType != CreateRectangleType.Polygon && m_DrawMeasureType != CreateRectangleType.CircleByThreePoints)                {                    var item = m_DrawMeasureGDIObject;                    item.NameOrHoleName = sam.GetMeasureGDIObject().NameOrHoleName;                    item.IsWorkSample = sam.GetMeasureGDIObject().IsWorkSample;                    sam.GetMeasureFieldGDIObjects().Clear();                    sam.SetMeasureGDIObject(item);                    var para = m_visualStage.GetSampleMeasurePara(item);                    m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);                    m_MeasureAppForm.SetRunType(MSR_RUN_TYPE.RUNMEASURE);                    PrepareMeasureField(sam, MSR_RUN_TYPE.RUNMEASURE);                    m_DrawMeasureGDIObject = null;                    this.Cursor = Cursors.Default;                    //设置手绘标识                    m_IsDrawMeasure = false;                }            }            if (sam != null && !runflag)            {                var measureItem = sam.GetMeasureGDIObject();                if (measureItem.IsDragging || measureItem.IsAltering)//while pressing ctrl key then it must be altering something(position or size)                {                    var selWSampleMeasureStatus = m_MeasureAppForm.m_ProjParam.GetWorkSampleMeasureStatus();                    if (!selWSampleMeasureStatus)                    {                        var para = m_visualStage.GetSampleMeasurePara(measureItem);                        m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);//set the altering result to the public parameter object                        this.Cursor = System.Windows.Forms.Cursors.Default;                        PrepareMeasureField(sam, m_MeasureAppForm.GetRunType());                    }                    measureItem.IsAltering = false;                    measureItem.IsDragging = false;                    Invalidate();                }            }            //only moving the whole stage            MouseUpFucntion(m_visualStage.GetAllGDIObject(), e);            //样品             MouseUpFucntion(GetAllVisualSampleGDIObject(), e);        }        protected override void OnPaint(PaintEventArgs e)//处理重绘情况        {            OnPaint(e, m_visualStage.GetAllGDIObject());            OnPaint(e, GetOnlyVisualSampleGDIObject());            if (IsShowSampleHoleImage)            {                if (GetWorkingVisualSample() != null)                {                    if (GetWorkingVisualSample().FrameOfHoleGDIObjects.Count > 0)                    {                        OnPaint(e, GetWorkingVisualSample().FrameOfHoleGDIObjects);                    }                }            }            OnPaint(e, GetAllVisualFieldGdiObject());            if (m_DrawMeasureGDIObject != null)            {                m_DrawMeasureGDIObject.OnPaint(e);            }            if (m_DrawPolygonFinishGDIObject != null) m_DrawPolygonFinishGDIObject.OnPaint(e);        }        public void OnPaint(PaintEventArgs e, List<CRectangleGDIObject> m_ObjectGDIObjects)//处理重绘情况        {            foreach (CRectangleGDIObject item in m_ObjectGDIObjects.ToArray())            {                if (item != null)                {                    item.OnPaint(e);                }            }        }        protected override void OnMouseWheel(MouseEventArgs e)        {            var currentZoomNum = m_visualStage.GetZoomNum();            //如果正在进行测量线程,则退出鼠标点击操作                      if (e.Delta > 0)            {                #region 计算标尺尺寸部份-----放大------                //计算标尺实际占用像素的宽度                f_ruler_size = f_old_ruler_size * currentZoomNum;                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 (currentZoomNum >= f_zoom_mix)                {                    #region 计算标尺尺寸部份-----缩小                    f_ruler_size = f_old_ruler_size * currentZoomNum;                    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 (e.Delta > 0)            {                currentZoomNum += 0.1f;            }            else            {                currentZoomNum -= 0.1f;                if (currentZoomNum < 1)                {                    currentZoomNum = 1;                }                if (currentZoomNum == 1)                {                    //标尺恢复初始                    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);                }            }            MouseWheelFunction(GetAllVisualSampleGDIObject(), e.Location, currentZoomNum);            //样品孔            MouseWheelFunction(m_visualStage.GetAllGDIObject(), e.Location, currentZoomNum);            base.OnMouseWheel(e);            //重新绘制            Invalidate();        }        private void MouseWheelFunction(List<CRectangleGDIObject> objList, Point mousePoint, float ZoomNum)        {            for (int i = 0; i < objList.Count; i++)            {                objList[i].Zoom(mousePoint, ZoomNum);            }        }        #endregion        #region 鼠标方法操作        public void MouseDownFunction(List<CRectangleGDIObject> objList, MouseEventArgs e)        {            foreach (CRectangleGDIObject item in objList)            {                item.IsMoving = true;                item.DraggingPoint = e.Location;            }        }        public void MouseMoveFucntion(List<CRectangleGDIObject> objList, MouseEventArgs e)        {            foreach (CRectangleGDIObject item in objList)            {                if (item.IsMoving)                {                    item.Move(e.Location);                }            }        }        public void MouseUpFucntion(List<CRectangleGDIObject> objList, MouseEventArgs e)        {            foreach (CRectangleGDIObject item in objList)            {                if (item.IsDragging)                {                    item.IsDragging = false;                    item.DraggingPoint = Point.Empty;                }                if (item.IsMoving)                {                    item.IsMoving = false;                    item.DraggingPoint = Point.Empty;                }            }        }        #endregion        private void DeleteSampleInfo(string sampleSelectName)        {            if (ShowDeleteDialog(sampleSelectName))            {                //设置当前状态                m_MeasureAppForm.SetRunType(MSR_RUN_TYPE.RUNMEASURE);                m_MeasureAppForm.DeleteSample(sampleSelectName);            }            return;        }        private bool ShowDeleteDialog(string sampleName)        {            //国际化            OTSCommon.Language lan = new OTSCommon.Language();            Hashtable table = lan.GetNameTable("OTSIncAMeasureAppForm");            string str1 = table["message5"].ToString();            string str2 = table["message6"].ToString();            string sDeleteSampleName = str1;            sDeleteSampleName += sampleName;            sDeleteSampleName += "  信息 ?";            if (DialogResult.OK == MessageBox.Show(sDeleteSampleName, "Delete sample information prompt", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))            {                return true;            }            else            {                return false;            }        }        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)        {            //键盘抬起时,将选择区域的标识 设置为未选择状态            this.Cursor = System.Windows.Forms.Cursors.Default;            this.Invalidate();        }        public void KeyDowns()        {            //鼠标相对于屏幕的坐标            Point p1 = MousePosition;            //鼠标相对于窗体的坐标            Point mousePoint = this.PointToClient(p1);            Pen GrayPen = new Pen(Color.Gray, m_PenWidth);            //设置鼠标在样品测量区域上的样式            foreach (var sam in m_visualSamples)            {                var item = sam.GetMeasureGDIObject();                if (item.GetGPath() != null)                {                    if (item.CreateType == CreateRectangleType.Polygon)                    {                        //在多边形点附近切换光标                        foreach (PointF itemPoint in item.GetPolygonPointFList())                        {                            if (Math.Abs(itemPoint.X - mousePoint.X) <= m_OffsetPX && Math.Abs(itemPoint.Y - mousePoint.Y) <= m_OffsetPX)                            {                                if (Control.ModifierKeys == Keys.Control)                                {                                    this.Cursor = System.Windows.Forms.Cursors.Hand;                                    return;                                }                            }                        }                        if (item.GetGPath().IsVisible(mousePoint))                        {                            if (Control.ModifierKeys == Keys.Control)                            {                                this.Cursor = System.Windows.Forms.Cursors.SizeAll;                                return;                            }                        }                    }                    else                    {                        if (item.GetGPath().IsOutlineVisible(mousePoint, GrayPen))                        {                            if (item.Shape == ShapeType.RECTANGLE)                            {                                List<PointF> vertexPoint = item.GetVertexPoints();                                foreach (PointF itemPoint in vertexPoint)                                {                                    if (Math.Abs(itemPoint.X - mousePoint.X) <= m_OffsetPX && Math.Abs(itemPoint.Y - mousePoint.Y) <= m_OffsetPX)                                    {                                        if (Control.ModifierKeys == Keys.Control)                                        {                                            this.Cursor = System.Windows.Forms.Cursors.Hand;                                            return;                                        }                                    }                                }                            }                            else                            {                                if (Control.ModifierKeys == Keys.Control)                                {                                    this.Cursor = System.Windows.Forms.Cursors.NoMove2D;                                    return;                                }                            }                        }                        if (item.IfZoomContains(mousePoint))                        {                            if (Control.ModifierKeys == Keys.Control)                            {                                this.Cursor = System.Windows.Forms.Cursors.SizeAll;                                return;                            }                        }                    }                }            }            //设置鼠标在样品上的样式            foreach (var sam in m_visualSamples)            {                var item = sam.GetSampleGDIObject();                if (!item.SelColor.Name.Equals("Transparent"))                {                    if (item.IfZoomContains(mousePoint))                    {                        if ((Control.ModifierKeys == Keys.Alt))                        {                            this.Cursor = System.Windows.Forms.Cursors.SizeAll;                            return;                        }                    }                }            }        }        public void KeyUps()        {            this.Cursor = System.Windows.Forms.Cursors.Default;        }        #region 处理方法总汇        #region 清除所需图形        public void ClearDrawInfo()        {            try            {                m_visualStage.cleargdiobj();                var sam = GetWorkingVisualSample();                if (sam != null)                {                    if (sam.FrameOfHoleGDIObjects != null)                    {                        sam.FrameOfHoleGDIObjects.Clear();                    }                    if (m_DrawMeasureGDIObject != null)                    {                        m_DrawMeasureGDIObject = null;                    }                }                m_visualSamples.Clear();            }            catch (Exception ex)            {                log.Error(ex.ToString());            }        }        #endregion        #endregion        #region 绘制样品以及测量区域        /// <summary>        /// 绘制样品以及测量区域        /// </summary>        /// <param name="SMeasrueAreaList">测量区域的集合</param>        public void DrawSampleAndMeasureInfo(SampleMeasurePara SMeasrueArea)        {            var item = m_visualStage.GetHoleGDIByHoleName(SMeasrueArea.sampleHoleName);            if (item != null)            {                CVisualSampleArea sam;                if (InitVisualSample(SMeasrueArea.sampleHoleName, SMeasrueArea.sSampleName, out sam))                {                    if (SMeasrueArea.iShape == (ShapeType)CreateRectangleType.Polygon)                    {                        var ps = new List<PointF>();                        foreach (var p in SMeasrueArea.DrawPolygonPointList)                        {                            var ctrlcoordPoint = m_visualStage.OTSCoordToCtrlCoord(p);                            ps.Add(ctrlcoordPoint);                        }                        CRectangleGDIObject polygongdi = new CRectangleGDIObject(ps, CreateRectangleType.Polygon, (ShapeType)SMeasrueArea.iShape, SMeasrueArea.sampleHoleName, SMeasrueArea.sSampleName, Color.Red);                        sam.SetMeasureGDIObject(polygongdi);                        PrepareMeasureField(sam, m_MeasureAppForm.GetRunType());                    }                    else                    {                        PointF xHole = new PointF(SMeasrueArea.MeasureRect.Left, SMeasrueArea.MeasureRect.Top);                        PointF yHole = new PointF(SMeasrueArea.MeasureRect.Right, SMeasrueArea.MeasureRect.Bottom);                        CRectangleGDIObject gdi = m_visualStage.GetCtrlCoordRect(xHole, yHole, (CreateRectangleType)SMeasrueArea.iShape, "", "");                        gdi.SampleName = SMeasrueArea.sSampleName;                        gdi.NameOrHoleName = SMeasrueArea.sampleHoleName;                        gdi.Shape = SMeasrueArea.iShape;                        CRectangleGDIObject measureGdi;                        if (m_visualStage.GetMeasureGdiObjectFromSampleGdi(gdi, out measureGdi))                        {                            sam.SetMeasureGDIObject(measureGdi);                            PrepareMeasureField(sam, m_MeasureAppForm.GetRunType());                        }                    }                    COTSMsrPrjResultData cProjMgr = m_MeasureAppForm.m_ProjParam.GetResultData();                    List<PointF> CompleteFieldList = cProjMgr.GetSampleByName(SMeasrueArea.sSampleName).GetMsrStatus().GetCompletedFieldsCenter();                    if (CompleteFieldList.Count > 0)                    {                        ChangeCompleteFieldMeasureState(CompleteFieldList, Color.Green, sam);                    }                }            }        }        #endregion        #region 获取帧图信息        public void ReadSEMDataAndSetToCurrentSample()        {            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);                    //将右键SEM数据菜单设置为可编辑状态                    CMStrip.Items[(int)MenuIndex.SetSemData].Enabled = true;                }            }            #endregion        }        #region 获取Filed帧图        public List<CRectangleGDIObject> GetOTSFieldVisualRects(CVisualSampleArea sam, MSR_RUN_TYPE runType)        {            List<Point> listCenterPoint=new List<Point>();            Size rectSize=new Size();            var m_ResultData = m_MeasureAppForm.m_ProjParam.GetResultData();            var sample = m_ResultData.GetSampleByName(sam.GetSampleName());            List<CRectangleGDIObject> visualfieldRects = new List<CRectangleGDIObject>();            if (runType == MSR_RUN_TYPE.RUNSampleHoleImage)            {                InitHoleImgPosData(sample,out listCenterPoint, out rectSize);            }            else if(runType==MSR_RUN_TYPE.RUNMEASURE)            {                sample.InitFieldPosData( out listCenterPoint, out rectSize);            }                                           for (int i = 0; i < listCenterPoint.Count; i++)                {                    //convert the center point to leftTop point of rectangle.                    Point otsPoint = listCenterPoint[i];                    int left = otsPoint.X - rectSize.Width / 2;                    int top = otsPoint.Y - rectSize.Height / 2;//the ots coordinate is leftbottom is (0,0),but the control coordinate is leftTop is (0,0),so here use minus.                    var rect = new Rectangle(new Point(left, top), rectSize);                    Point lt = new Point(rect.Left, rect.Top);                    Point rb = new Point(rect.Right, rect.Bottom);                    RectangleF visualRect = m_visualStage.GetCtrlCoordRectF(lt, rb);                    Color ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.FieldColor);                    string sampleName = sam.GetSampleName();                    string sampleHoleName = sam.GetSampleGDIObject().NameOrHoleName;                    CRectangleGDIObject createRect = new CRectangleGDIObject(visualRect, otsPoint.X, otsPoint.Y, CreateRectangleType.FieldRectangle, sampleHoleName, sampleName, ColorStr);                    visualfieldRects.Add(createRect);                }                       return visualfieldRects;        }        public bool InitHoleImgPosData(COTSSample sample, out List<Point> lisFieldPos, out Size iSzie)        {            lisFieldPos = new List<Point>();            iSzie = new Size();            COTSSample WSample = sample;            if (null == WSample)            {                return false;            }            CDomain pMsrArea = WSample.GetMsrDomain();            COTSImgScanPrm pImgScanParam = WSample.GetMsrParams().GetImageScanParam();            COTSImageProcParam pImgProcParam = WSample.GetMsrParams().GetImageProcessParam();            CSEMDataMsr pSEMDataMsr ;                       List<PointF> listPoint = new List<PointF>();            listPoint.Clear();                                     pSEMDataMsr = new CSEMDataMsr();                pSEMDataMsr.SetScanFieldSize100(m_visualStage.GetOTSSampleStageData().iScanFieldSize100);                double dMagnification = m_MeasureAppForm.m_ProjParam.GetDefaultParam().GetStageDataParam().GetMinMag();//using the min mag to photo the hole image.                pSEMDataMsr.SetMagnification(dMagnification);                       //calculate all the field position point in OTS coordination.            if (!pFieldMgr.Init(pMsrArea, pImgScanParam, 0, pSEMDataMsr, listPoint))            {                return false;            }            lisFieldPos = pFieldMgr.GetFieldCentrePoints();            var oValue = new COTSRect();            if (!pFieldMgr.GetOTSRectByIndex(0, ref oValue))            {                return false;            }            iSzie = new Size((int)oValue.GetWidth(),(int) oValue.GetHeight());            return true;        }        #endregion        public void PrepareMeasureField(CVisualSampleArea visualsam, MSR_RUN_TYPE runType)        {            try            {                List<CRectangleGDIObject> visualfieldRects = null;                visualfieldRects = GetOTSFieldVisualRects(visualsam, runType);//get all the possible field rects through C++ code.                if (runType == MSR_RUN_TYPE.RUNSampleHoleImage)                {                    //-------maybe take more than one visualsample hole image for one sample,                    //if the previous visual area's fields don't finish,then the unfinished field's area may overlap with the current visualsample's area.                    // then there positions will conflict. So we should remove the unfinished fields first.                    var completeHoleImgs = new List<CRectangleGDIObject>();                    foreach (var holeImgfld in visualsam.FrameOfHoleGDIObjects)                    {                        if (holeImgfld.BSEImage != null)                        {                            completeHoleImgs.Add(holeImgfld);                        }                    }                    visualsam.FrameOfHoleGDIObjects = completeHoleImgs;                    //------                    foreach (var r in visualfieldRects)                    {                        r.SetDisplayRefPoint(m_visualStage.GetDisplayRefPoint());                        r.SetZoomNumber(m_visualStage.GetZoomNum());                        RectangleF ImgRegionF;                        float ImgRegionWidth;                        float ImgRegionHeight;                        ImgRegionF = r.GetOrigionalDrawRegionF();                        ImgRegionWidth = Convert.ToInt32(ImgRegionF.Width);                        ImgRegionHeight = Convert.ToInt32(ImgRegionF.Height);                        //绘制图像                        CRectangleGDIObject createImageRect = new CRectangleGDIObject(ImgRegionF, r.OTSX, r.OTSY, r.SampleName, r.NameOrHoleName, ImgRegionWidth, ImgRegionHeight, CreateRectangleType.DrawFrameOfHoleBSEImage);                        //添加至List集合中                        createImageRect.SetInitRegionF(r.GetOrigionalDrawRegionF());                        createImageRect.NameOrHoleName = r.NameOrHoleName;                        createImageRect.SetZoomNumber(m_visualStage.GetZoomNum());                        createImageRect.SetDisplayRefPoint(m_visualStage.GetDisplayRefPoint());                                                                       visualsam.FrameOfHoleGDIObjects.Add(createImageRect);                    }                }                else if (runType == MSR_RUN_TYPE.RUNMEASURE)                {                    visualsam.GetMeasureGDIObject().SubItems().Clear();                    //添加帧图列表                    int sequenceNum = 0;                    for (int i = 0; i < visualfieldRects.Count; i++)                    {                        var r = visualfieldRects[i];                        if (visualsam.GetMeasureGDIObject().ifRectangleIntersect(r))//filter the unmeasure fields                        {                            r.SequenceNum = sequenceNum++;                            visualsam.AddFieldGDIObject(r);                        }                    }                    SaveFieldPositionInfoToSample(visualsam);                    m_MeasureAppForm.UpdatePropertyVal();                }            }            catch (Exception ex)            {                log.Error(ex.ToString());            }            Invalidate();        }        public void SaveFieldPositionInfoToSample(CVisualSampleArea sam)        {            var m_ResultData = m_MeasureAppForm.m_ProjParam.GetResultData();            var sample = m_ResultData.GetSampleByName(sam.GetSampleName());            var fields = sam.GetMeasureFieldGDIObjects();            sample.ClearFields();            for (int i = 0; i < fields.Count; i++)            {                var f = fields[i];                var otsPoint = new Point(f.OTSX, f.OTSY);                var pixelsize = sample.CalculatePixelSize();                var newfld = new COTSField(otsPoint, pixelsize);                COTSRect r=new COTSRect();                 sample.pFieldMgr.GetOTSRectByIndex(i,ref r);//get this field's global position(in the whole ots coordination)                newfld.SetOTSRect(r);                newfld.SetMeasureSequence(f.SequenceNum);                sample.pFieldMgr.CalculateFieldNeighbour(sample.GetFieldsData(), newfld);                newfld.Sample = sample;                sample.AddNewField(newfld);            }        }        #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;                bool wFlag;                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()        {            bool selWSampleMeasureStatus = m_MeasureAppForm.m_ProjParam.GetWorkSampleMeasureStatus();            if (selWSampleMeasureStatus)            {                return;            }            try            {                List<double> SemLocation = new List<double>();                if (GetSemLocation(ref SemLocation))                {                    PointF OTSLocation = m_MeasureAppForm.m_ProjParam.ConverSEMToOTSCoord(new PointF((int)Math.Round(SemLocation[(int)XYIndex.X], 0), (int)Math.Round(SemLocation[(int)XYIndex.Y], 0)));                    NLog.LogManager.GetCurrentClassLogger().Warn(OTSLocation.ToString());                    var sam = GetWorkingVisualSample();                    var MeasureItem = sam.GetMeasureGDIObject();                    var measurePos = m_visualStage.OTSCoordToCtrlCoord(OTSLocation);                    MeasureItem.DraggingPoint = MeasureItem.GetCenterPoint();                    MeasureItem.PositionAltering(measurePos, false);                    var para = m_visualStage.GetSampleMeasurePara(MeasureItem);                    m_MeasureAppForm.m_ProjParam.SetWorkSampleHoleAndMeasureArea(para);                }                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_MouseDownPoint, 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;                var sam = GetWorkingVisualSample();                if (m_SEMDATAFieldManage.InitAndConnection())                {                    bret = (m_SEMDATAFieldManage.DriveSEMToLocation(m_MouseDownPoint, m_visualStage, sam.GetMeasureFieldGDIObjects()));                }                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;            control_Ruler2.Visible = true;            var m_GlobalZoomNum = m_visualStage.GetZoomNum();            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";            PointF xDomain = new PointF(SData.StageDomain.Left, SData.StageDomain.Top);            PointF yDomain = new PointF(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 隐藏与显示样品孔照片        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, int fieldId)        {            CRectangleGDIObject itemWorkSample;            var sam = GetWorkingVisualSample();            itemWorkSample = GetWorkingVisualSample().GetSampleGDIObject();            //获取样品孔BSE图像            Image bseImage;            int m_iWidth = width;            int m_iHeigh = height;            if (sam.FrameOfHoleGDIObjects.Count > 0)            {                for (int i = 0; i < sam.FrameOfHoleGDIObjects.Count; i++)                {                    var ctrlPos = m_visualStage.OTSCoordToCtrlCoord(fieldPos);                    if (sam.FrameOfHoleGDIObjects[i].BSEImage == null)// prevent miss match when this sample area is overlaying on the other area(already took image in the field)                    {                        if (sam.FrameOfHoleGDIObjects[i].IfContains(ctrlPos))                        //if (i == fieldId)                        {                            bseImage = CImageHandler.ToGrayBitmap(ImageData, m_iWidth, m_iHeigh);                            sam.FrameOfHoleGDIObjects[i].BSEImage = bseImage;                            break;                        }                    }                                    }            }            //显示样品孔照片            IsShowSampleHoleImage = true;            Invalidate();        }        #endregion        #region 删除样品孔中BSE图像信息        public void DeleteHoleBSEImageDataNoMessageBox()        {            GetWorkingVisualSample().FrameOfHoleGDIObjects.Clear();            Invalidate();        }        #endregion               #region 复位工作样品区域        public CRectangleGDIObject ResetMeasure(CRectangleGDIObject SampleGDIObjects, CRectangleGDIObject MeasureGDIObjects)        {            m_visualStage.GetMeasureGdiObjectFromSampleGdi(SampleGDIObjects, out MeasureGDIObjects);            return MeasureGDIObjects;        }        public void ResetWorkSampleMeasure()        {            COTSSample WSample = m_MeasureAppForm.m_ProjParam.GetWorkSample();            var stype = m_MeasureAppForm.m_ProjParam.GetDefaultParam().GetSysType();            OTSSampleVisualPropertyInfo MeasureInfo = new OTSSampleVisualPropertyInfo(WSample, stype);            RectangleF measureSize = m_MeasureAppForm.m_ProjParam.CalculateMsrArea(MeasureInfo.SMeasurePara.sampleHoleName);            //获取位置与尺寸            MeasureInfo.SMeasurePara.MeasureRect.Location = measureSize.Location;            MeasureInfo.SMeasurePara.MeasureRect.Size = measureSize.Size;            //获取样品信息            PointF xHole = new PointF(MeasureInfo.SMeasurePara.MeasureRect.Left, MeasureInfo.SMeasurePara.MeasureRect.Top);            PointF yHole = new PointF(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.SetInitRegionF(SampleRectangleF);            var sam = GetWorkingVisualSample();            var mea = sam.GetMeasureGDIObject();            CRectangleGDIObject m_ResetMeasureGDIobjects = ResetMeasure(sam.GetSampleGDIObject(), m_MeasureGDIObject);            mea.SetInitRegionF(m_ResetMeasureGDIobjects.GetOrigionalDrawRegionF());            mea.Shape = m_ResetMeasureGDIobjects.Shape;            Invalidate();        }        #endregion           private void CMStrip_Opening(object sender, System.ComponentModel.CancelEventArgs e)        {        }    }}
 |