| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719 | using OTSModelSharp;using OTSDataType;using OTSCLRINTERFACE;using System;using System.Collections.Generic;using System.Drawing;using System.Linq;using System.IO;using OTSModelSharp.ResourceManage;using static OTSModelSharp.ResourceManage.ResourceID;using static OTSModelSharp.ResourceManage.ResourceData;using static OTSDataType.otsdataconst;using System.Windows.Forms;using OTSMeasureApp._0_OTSModel.Measure.ParamData;namespace OTSMeasureApp{    public enum OTS_SOFT_PACKAGE_ID    {        OTSIncA = 0,             //夹杂物分析        OTSPartA = 1,            //颗粒度分析    };    //文件保存返回的结果,DataMgr返回    public enum OTS_SAVE_FILE_REV    {        SaveFile_Success = 0,        SaveFile_Cancel = 1,        SaveFile_Failed = 2,        SaveFile_NoNedd = 3      //文件不需要保存    }     //设置线程状态    public enum MSR_THREAD_RunSTATUS    {        RUNMEASURE = 1,         //开始测量        RUNSampleHoleImage = 2  //运行获取样品孔照片    };    enum SAMPLE_FAULT_WARN_CODE    {        INVALID = -1,        MIN = 0,        SEM_DATA_ERROR = 0,        AREA_OUTSIDE_HOLE = 1,        RESOLUTION_LOW = 2,        FINISHED = 3,        NO_ERROR_WARNING = 4,        FILE_NOT_SAVED = 5,        MAX = 5    };    enum SAMPLE_CHECK_RESULT_TYPE    {        INVALID = -1,        MIN = 0,        SWITCH_ON = 0,        FINISHED = 1,        SETTING_ERROR = 2,        SETTING_WARNING = 3,        MEASURABLE = 4,        NO_ERROR_WARNING = 5,        MAX = 5    };    public class COTSMeasureParam     {        OTSIncAMeasureAppForm m_MeasureAppFrom = null;        /// <summary></summary>        /// <remarks>创建</remarks>        private COTSMsrPrjResultData resultData;        //参数文件        private COTSDefaultParam defaultParam = null;        //样品台文件(读取样品台数据等)                                    private CStageParam stageParam = null;        private CSpecialGrayRangeParam specialRanges = null;        //测量样品链表        List<COTSSample> m_MeasureSampleList = new List<COTSSample>();        NLog.Logger log ;        public CSpecialGrayRangeParam SpecialRanges { get => specialRanges; set => specialRanges = value; }        public CStageParam GetStageParam()        {            return stageParam;        }        public void SetStageParam(CStageParam value)        {            stageParam = value;        }        public COTSDefaultParam GetDefaultParam()        {            return defaultParam;        }        public void SetDefaultParam(COTSDefaultParam value)        {            defaultParam = value;        }        public COTSMsrPrjResultData GetResultData()        {            return resultData;        }        public void SetResultData(COTSMsrPrjResultData value)        {            resultData = value;        }        public COTSMeasureParam(OTSIncAMeasureAppForm MeasureApp)        {            log = NLog.LogManager.GetCurrentClassLogger();            m_MeasureAppFrom = MeasureApp;            SetResultData(new COTSMsrPrjResultData());        }              //检查参数文件是否存在        public bool LoadParamFile()        {            //加载样品参数文件:   \Config\SysData\OTSProgMgrParam.pmf            SetDefaultParam(new COTSDefaultParam());            GetDefaultParam().LoadInfoFromProgMgrFile();            if (null == GetDefaultParam())            {                return false;            }            return true;        }        //检查参数样品台文件是否存在        public bool LoadStageParamFile()        {            SetStageParam(new CStageParam());            // 加载样品台文件;  \Config\SysData\OTSStage.stg            if (!GetStageParam().Load(true, false))            {                return false;            }            return true;                   }        public bool LoadSpecialGrayRangeParamFile()        {            SpecialRanges = new CSpecialGrayRangeParam();                       if (!SpecialRanges.LoadParam())            {                return false;            }                        return true;        }        //获取系统文件是否存在和有效        public bool InitResultData(bool bNewFileFlag = true)        {            //打开文件,则文件中保存有样品台信息,不需要使用系统样品名信息            if (bNewFileFlag)            {                //设置样品台参数                CStage Stage = GetStageParam().GetWorkingStage();                if (null == Stage)                {                    return false;                }                GetResultData().SetStage(Stage);                                // 设置 SEM stage data                CSEMStageData SEMData = GetDefaultParam().GetStageDataParam();                if (null == SEMData)                {                    return false;                }                GetResultData().SetSEMStageData(SEMData);            }            //设置 general parameter            COTSGeneralParam GenParam = GetDefaultParam().GetGenParam();            if (null == GenParam)            {                return false;            }            GetResultData().SetGenParam(GenParam);            if (GetResultData().GetPathName()=="")            {                GetResultData().SetPathName("Untitled");                         }            GetResultData().m_nPackId = GetDefaultParam().m_nPackId;            return true;        }               //新建样品工作文件 0:报错 1:正常 2:取消        public int CreateNewFile()        {            if (GetResultData().IsModified())    // 文件被修改            {                int iRev = m_MeasureAppFrom.ShowSaveInfoMsgBox();                if ((int)MessageBoxRev.DIALOG_YES == iRev)                {                    if (!GetResultData().Save())                    {                        return 0;                    }                }                else if((int)MessageBoxRev.DIALOG_CANCEL == iRev)                {                    return 2;                }            }            //新建新的工作文件            //重新生成一个工作文件对象            COTSMsrPrjResultData ProjDataMgr = new COTSMsrPrjResultData();            GetResultData().SetPathName("Untitled");            SetResultData(ProjDataMgr);            this.LoadStageParamFile();                       if (!this.InitResultData())            {                return 0;            }            return 1;        }         //将样品台坐标转换为Sem 坐标        public Point ChangeOTSToSemCoord(Point POTSCoord)        {            System.Drawing.Point VSemCoord = new System.Drawing.Point();            GetDefaultParam().GetStageDataParam().ConverOTSToSEMPoint(POTSCoord, ref VSemCoord);            return (Point)VSemCoord;        }        //将Sem 坐标转换为样品台坐标        public Point ConverSEMToOTSPoint(Point PSEMCoord)        {            System.Drawing.Point VOTSCoord = new System.Drawing.Point();            GetDefaultParam().GetStageDataParam().ConverSEMToOTSPoint(PSEMCoord, ref VOTSCoord);            return (Point)VOTSCoord;        }        //添加样品        //string sSHoleName:  样品孔名,当在样品孔上点击右键添加样品时,sSHoleName=样品孔名。当MEASUREAPP和TREEVIEW添加样品时,sSHoleName=""        //返回新的工作样品名称        public OTSSamplePropertyInfo AddNewSampleMeasure(string a_strHoleName = "")        {            COTSSample NewSample = new COTSSample();            SetSampleDefaultPara(ref NewSample, a_strHoleName);            //NewSample.            //添加样品            GetResultData().AddSample(NewSample);                      // 获取样品的属性值            OTSSamplePropertyInfo MeasureInfo = new OTSSamplePropertyInfo();            if (!GetWorkSamplePerameter(NewSample, ref MeasureInfo))            {                return null;            }                  return MeasureInfo;        }        protected COTSSample SetSampleDefaultPara(ref COTSSample pSample, String a_strHoleName)        {            // get new sample name            String strNewSampleName = GetNewSampleName();            // make sure the new sample name is not an empty string            strNewSampleName.Trim();            // get a suitable sample hole for the new sample            CHole pHole = SelectASmpleHole(a_strHoleName);            // check the sample hole            if (pHole == null)            {                // failed to get sample hole for the new sample                return null;            }            // measurement area 	            CDomain pMsrArea = CalculateDefaultArea(pHole);            // measure data parameters containing particle analysis std, image scan parameter, image process parameter and x-ray parameter             CSampleParam poMsrParams = new CSampleParam();            poMsrParams.m_nPackId = GetDefaultParam().m_nPackId;            poMsrParams.m_runmode = GetDefaultParam().m_runmode;            var m_pParam = GetDefaultParam().GetGenParam();            MEMBRANE_TYPE a_nVal = (MEMBRANE_TYPE)m_pParam.GetMembraneType();            poMsrParams.SetImageScanParam(GetDefaultParam().GetImageScanParam ());            poMsrParams.SetImageProcessParam(GetDefaultParam().GetImageProcParam());             poMsrParams.SetXRayParam(GetDefaultParam().GetXRayParam());            String sSTDName = m_pParam.GetSTDSelect();            poMsrParams.SetSTDName(sSTDName);            poMsrParams.SetSteelTechnology((STEEL_TECHNOLOGY)m_pParam.GetSteelTechnology());            poMsrParams.SetSpecialGrayRangeParam(SpecialRanges);            // set sample parameters            pSample.SetName(strNewSampleName);            pSample.SetSampleHoleName(pHole.GetName());            pSample.SetSwitch(m_pParam.GetMeasurementSwitch());            pSample.GetMsrParams().SetSysSTDSwitch(m_pParam.GetSysSTD());            pSample.SetMsrArea(pMsrArea);            pSample.SetMembraneType(a_nVal);            pSample.SetMsrParams(poMsrParams);            CSEMDataMsr semData = new CSEMDataMsr();            var m_pSEMStageData = GetDefaultParam().GetStageDataParam();            var imageScanParam = GetDefaultParam().GetImageScanParam();            string resol = imageScanParam.GetImageResulotion().ToString();            double resWidth = Convert.ToDouble(resol.Split('_')[1]);            double resHeight = Convert.ToDouble(resol.Split('_')[2]);            double heightWidthRatio = resHeight / resWidth;            semData.SetScanFieldSize100(m_pSEMStageData.GetScanFieldSize100());            double fieldHeight = m_pSEMStageData.GetScanFieldSize100() * heightWidthRatio;            semData.SetScanFieldHeight100((int)fieldHeight);            pSample.SetSEMDataMsr(semData);            return pSample;        }        public String GetNewSampleName()        {            // new sample name            String strNewSmplName = "";            // safety check            var m_pParam = GetDefaultParam().GetGenParam();            if (m_pParam == null)            {                // shouldn't happen, invalid general parameter pointer.                return strNewSmplName;            }            // new sample name base            String strNewSmplNameBase = m_pParam.GetSampleName() + @"{0}";            int nIndex = 1;            do            {                // new sample name is new sample name base + number string                strNewSmplName = string.Format(strNewSmplNameBase, nIndex);                ++nIndex;            }            // make sure that the new sample name is not same with any sample in the samples list            while (SameNameInList(strNewSmplName));            // new sample name            return strNewSmplName;        }        public bool SameNameInList(String a_strSampleName, int a_nExclude = -1)        {            // make sure the input sample name is not empty            a_strSampleName.Trim();            if (a_strSampleName == "")            {                // shouldn't happen, input name is an empty string                return false;            }            // go through sample list            int nIndex = 0;            var m_listSamples = GetResultData().GetSampleList();            foreach (var pSample in m_listSamples)            {                // return TRUE if this is not an exclude sample and its name is same with input                String strSampleName = pSample.GetName();                if (nIndex != a_nExclude && strSampleName.CompareTo(a_strSampleName) == 0)                {                    // find a same name sample                    return true;                }                ++nIndex;            }            // no, same name sample in the same list, return FALSE            return false;        }        // select a suitable sample hole for a new sample        public CHole SelectASmpleHole(String a_strHoleName /*= _T("")*/)        {            // get holes list of the stage            var m_pStage = GetStageParam().GetWorkingStage();            List<CHole> listHoles = m_pStage.GetHoleList();            //返回样品孔对象            CHole cReHole = new CHole();            // make sure the holes list is not empty            if (listHoles.Count == 0)            {                // shouldn't happen, stage have no hole.                return null;            }            // check the input hole name            a_strHoleName.Trim();            if (a_strHoleName != "")            {                // try to find matched hole                bool IsChanged = false;                int holeIndex = -1;                for (int itr = 0; itr < listHoles.Count; itr++)                {                    if (listHoles[itr].GetName() == a_strHoleName)                    {                        cReHole = listHoles[itr];                        //listHoles.RemoveAt(itr);                        IsChanged = true;                        holeIndex = itr;                        break;                    }                }                if (IsChanged)                {                    return cReHole;                }            }            // can't find a matched hole, then pick the first empty hole            //没有按照孔进行添加,则与样品列表进行判断            // go through the holes list            foreach (var pHole in listHoles)            {                // has this hole any sample in it?                String strHoleName = pHole.GetName();                bool IsChanged = false;                var m_listSamples = GetResultData().GetSampleList();                foreach (COTSSample sampleItem in m_listSamples)                {                    if (strHoleName == sampleItem.GetSampleHoleName())                    {                        //listHoles.RemoveAt(itr);                        IsChanged = true;                    }                }                if (!IsChanged)                {                    return pHole;                }            }            // no empty hole, then the first hole will be the one            return listHoles[0];        }        public CDomain CalculateDefaultArea(CHole a_pHole)        {            Rectangle rectHole = a_pHole.GetDomainRect();            System.Drawing.Point ptCenter = new System.Drawing.Point((rectHole.Left + rectHole.Right) / 2, (rectHole.Top + rectHole.Bottom) / 2);            var m_pParam = GetDefaultParam().GetGenParam();            DOMAIN_SHAPE nShape = m_pParam.GetShape();            double dArea = m_pParam.GetArea() * 1000000;            System.Drawing.Point ptLeftTop = new System.Drawing.Point();            System.Drawing.Size ptSize = new System.Drawing.Size();            int nEdge = 0;            int nRadius = 0;            switch ((int)nShape)            {                case (int)DOMAIN_SHAPE.RECTANGLE:                    nEdge = (int)Math.Sqrt(dArea) / 2;                    ptLeftTop.X = ptCenter.X - nEdge;                    ptLeftTop.Y = ptCenter.Y - nEdge;                    ptSize.Width = ptCenter.X + nEdge - ptLeftTop.X;                    ptSize.Height = ptCenter.Y + nEdge - ptLeftTop.Y;                    break;                case (int)DOMAIN_SHAPE.ROUND:                    nRadius = (int)Math.Sqrt(dArea / 3.1415926);                    ptLeftTop.X = ptCenter.X - nRadius;                    ptLeftTop.Y = ptCenter.Y - nRadius;                    ptSize.Width = ptCenter.X + nRadius - ptLeftTop.X;                    ptSize.Height = ptCenter.Y + nRadius - ptLeftTop.Y;                    break;            }            Rectangle MsrRect = new Rectangle(ptLeftTop, ptSize);            CDomain pMsrArea = new CDomain(nShape, MsrRect);            // return measurement area            return pMsrArea;        }        //设置工作样品的属性值        public bool SetSampleParamVal(OTS_SAMPLE_PROP_GRID_ITEMS ItemId, OTS_ITEM_TYPES ValType, object objVal)        {            COTSSample WSample = GetResultData().GetWorkingSample();            bool bSetFalg = false;            //判断样品名是否有效            if (ItemId == OTS_SAMPLE_PROP_GRID_ITEMS.SAMPLE_NAME)            {                if (!GetResultData().IsValidSampleName((string)objVal))                {                    bSetFalg = false;                    return false;                }            }            bSetFalg = WSample.SetParamVal(ItemId, ValType, objVal);            if (bSetFalg)            {                GetResultData().SetModify(true);            }            return bSetFalg;        }        //获取工作样品名称        public string GetWorkSampleName()        {            COTSSample WSample = GetResultData().GetWorkingSample();            if (null == WSample)            {                return "";            }            string sWorkSampleName = WSample.GetName();            if ("" == sWorkSampleName)            {                return "";            }            return sWorkSampleName;        }        //设置工作样品        //string sNewWorkSampleName:  新工作样品        public bool SetWorkSample(string sNewWorkSampleName)        {            if ("" == sNewWorkSampleName)            {                return false;            }            if (!GetResultData().SetWorkingSampleByName(sNewWorkSampleName))            {                return false;            }            return true;        }        //获取工作样品        // 返回工作样品对象        public COTSSample GetWorkSample()        {            COTSSample WSample = GetResultData().GetWorkingSample();            if (null == WSample)            {            }            return WSample;        }        //删除工作样品        //string sWorkSampleName : 删除工作样品名称        public bool DeleteWorkSample(string sWorkSampleName)        {            return GetResultData().DeleteSampleByName(sWorkSampleName);        }        // 获取样品总数        //返回样品总数        public int GetSampleCount()        {            return GetResultData().GetSampleList().Count();        }        //改变工作样品名称        //String sWSampleNewName        public bool ChangeWorkSampleName(String sWSampleNewName)        {            if (!GetResultData().IsValidSampleName(sWSampleNewName))            {                return false;            }            COTSSample WorkSample = GetResultData().GetWorkingSample();            if (null == WorkSample)            {                return false;            }            WorkSample.SetName(sWSampleNewName);            GetResultData().SetModify(true);            return true;        }        //移动工作样品到其他样品孔,样品孔名称和测量区域都要改变,重新设置工作样品参数        //SampleMeasurePara SMeasurePara:        public SampleMeasurePara SetWorkSampleHoleNameAndMeasureArea(SampleMeasurePara SMeasurePara)        {            SampleMeasurePara SMPara = new SampleMeasurePara();            COTSSample WSample = GetResultData().GetWorkingSample();            if (null == WSample)            {                return SMPara;            }            CDomain Domain = new CDomain();            Domain.SetShape((otsdataconst.DOMAIN_SHAPE)SMeasurePara.iShape);            Domain.SetRectDomain(SMeasurePara.MeasureRect);            if (SMeasurePara.DrawPolygonPointRegionF != null)            {                List<Point> PolygonPoint = new List<Point>();                foreach (var item in SMeasurePara.DrawPolygonPointRegionF)                {                    PolygonPoint.Add(new Point((int)item.X, (int)item.Y));                }                Domain.SetPolygonPoint(PolygonPoint);            }            WSample.SetSampleHoleName(SMeasurePara.sHoleName);            WSample.SetMsrArea(Domain);            //获取样品的测量区域信息             SMPara.sSampleName = WSample.GetName();    //获取样品名称            SMPara.iShape = (int)WSample.GetMsrArea().GetShape();  // 获取测量区域形状            SMPara.sHoleName = WSample.GetSampleHoleName(); //获取样品孔名称            SMPara.MeasureRect = (Rectangle)WSample.GetMsrArea().GetRectDomain();  //样品测量区域            //改变测量区域后重新设置样品修改状态            //m_ResultData.SetModify(true);            //string pathName = m_ProjDataMgr.GetPathName();            //if (pathName != "" && pathName != "Untitled")            //{            //    m_ProjDataMgr.Save();            //}            return SMPara;        }        //设置测量区域的形状 (通过RIBBON 上的画圆,画矩形 设置)        //int iShape:  测量区域形状 0: 圆形; 1 :矩形        public void SetMeasureAreaShape(int iShape)        {            //  SampleMeasurePara SMPara = new SampleMeasurePara();            COTSSample WSample = GetResultData().GetWorkingSample();            if (null == WSample)            {                return;            }            CDomain Domain = new CDomain();            Domain.SetShape((otsdataconst.DOMAIN_SHAPE)iShape);        }        //修改了ITEMID后,重新更新GROUPID和ITEMID        public void UpdateGroupValAndItemVal(OTS_SAMPLE_PROP_GRID_ITEMS ItemID)        {            OTS_SAMPLE_PROP_GRID_ITEM_GROUPS GroupID = OTS_SAMPLE_PROP_GRID_ITEM_GROUPS.INVALID;            OTS_SAMPLE_PROP_GRID_ITEMS iItemID = OTS_SAMPLE_PROP_GRID_ITEMS.INVALID;            COTSSample WSample = GetResultData().GetWorkingSample();            if (null == WSample)            {                return;            }            if (!WSample.GetRelatedPropItemGrp((OTS_SAMPLE_PROP_GRID_ITEMS)ItemID, ref GroupID))            {                bool bFlag = WSample.GetRelatedPropItem(ItemID, ref iItemID);            }        }          //设置样品参数锁        //bool ParaLockFlag : 样品参数锁        public bool SetWorkSampleParamLock(bool ParaLockFlag)        {            COTSSample WSample = GetResultData().GetWorkingSample();            if (null == WSample)            {                return false;            }            WSample.SetParamLock(ParaLockFlag);            GetResultData().SetModify(true);            return true;        }        //获取工作样品锁        //ref bool ParamLockFlag : 获取的工作样品参数锁        public bool GetWSampleParaLock(ref bool ParamLockFlag)        {            COTSSample WSample = GetResultData().GetWorkingSample();            if (null == WSample)            {                return false;            }            ParamLockFlag = WSample.GetParamLock();            return true;        }        //获取工作样品测量锁        public bool GetWSampleParaLock(ref OTSSamplePropertyInfo SMInfo)        {            COTSSample WSample = GetResultData().GetWorkingSample();            if (null == WSample)            {                return false;            }            if (!GetWorkSamplePerameter(WSample, ref SMInfo))            {                return false;            }            return true;        }        //重新设置样品在样品列表中的位置(当拖动TREEVIEW的样品顺序后执行 )        public bool SortSamplePosition(List<string> SNameList)        {            if (!GetResultData().ResetSamplesListOrder(SNameList))            {                return false;            }            List<COTSSample> SampleList = new List<COTSSample>();            SampleList = GetResultData().GetSampleList();            return true;        }              public bool CheckSampleParam(bool bCheckFlag)        {            m_MeasureSampleList.Clear();            List<COTSSample> MSampleList = new List<COTSSample>();            if (!CheckMeasureParam(GetResultData(), ref MSampleList, bCheckFlag))            {                return false;            }            if (MSampleList.Count > 0)            {                m_MeasureSampleList = MSampleList;                return true;            }            return false;        }        public bool CheckMeasureParam(COTSMsrPrjResultData a_pProjMgrFile, ref List<COTSSample> a_listMeasuableSamples, bool a_bCheckSetting)        {            // go through the sample list to check setting parameters             int nSwitchSmplNo = 0;            int nCompletedSmplNo = 0;            int nErrorSmplNo = 0;            int nWarningSmplNo = 0;            List<String> listSamplMessages = new List<string>();            List<COTSSample> listSamples = a_pProjMgrFile.GetSampleList();            List<COTSSample> listMeasurableSamples = new List<COTSSample>();            List<COTSSample> listWithWarningMeasurableSamples = new List<COTSSample>();            foreach (var pSample in listSamples)            {                // is the sample switch on                if (pSample.GetSwitch())                {                    ++nSwitchSmplNo;                    String strSmplMessage;                    strSmplMessage = pSample.GetName() + ":" + "\r\n";                    // is this a measurement completed sample                    if (IsMeasureCompletedSmpl(pSample))                    {   // measurement completed sample                        ++nCompletedSmplNo;                        string str2 = GetSampleErrorWarnString(SAMPLE_FAULT_WARN_CODE.FINISHED);                        strSmplMessage += str2;                        strSmplMessage += "\r\n";                    }                    else                    {                        // errors                        List<SAMPLE_FAULT_WARN_CODE> a_listErrorCodes = new List<SAMPLE_FAULT_WARN_CODE>();                        GetSampleErrorCodes(a_pProjMgrFile, pSample, ref a_listErrorCodes);                        if (a_listErrorCodes.Count != 0)                        {                            // has error, this is not a measurable sample                            ++nErrorSmplNo;                            foreach (var nErrorCode in a_listErrorCodes)                            {                                String str3 = GetSampleErrorWarnString(nErrorCode);                                strSmplMessage += str3;                                strSmplMessage += "\r\n";                            }                        }                        else                        {                            // no error, this is a measurable sample                            listMeasurableSamples.Add(pSample);                        }                        // warnings                        List<SAMPLE_FAULT_WARN_CODE> a_listWarningCodes = new List<SAMPLE_FAULT_WARN_CODE>();                        GetSampleWarningCodes(a_pProjMgrFile, pSample, ref a_listWarningCodes);                        if (a_listWarningCodes.Count != 0)                        {                            ++nWarningSmplNo;                            foreach (var nWarningCode in a_listWarningCodes)                            {                                String str3 = GetSampleErrorWarnString(nWarningCode);                                strSmplMessage += str3;                                strSmplMessage += "\r\n";                            }                            // has no error?                            if (a_listErrorCodes.Count == 0)                            {                                // this is a measurable sample but with setting warnings                                listWithWarningMeasurableSamples.Add(pSample);                            }                        }                        // no error and warning                        if (a_listErrorCodes.Count == 0 && a_listWarningCodes.Count == 0)                        {                            String str3 = GetSampleErrorWarnString(SAMPLE_FAULT_WARN_CODE.NO_ERROR_WARNING);                            strSmplMessage += str3;                            strSmplMessage += "\r\n";                        }                    }                    // add                     listSamplMessages.Add(strSmplMessage);                }            }            // dlg message string            String strDlgMessage = "";            String str;            String str1;            str1 = GetResourceByKey(GrpOtherParam, IDS_SAMPLE_CHECK_RESULT + (int)SAMPLE_CHECK_RESULT_TYPE.SWITCH_ON);            str1 = str1.Replace("%d", "{0}");            str = string.Format(str1, nSwitchSmplNo);            strDlgMessage += str;            strDlgMessage += "\r\n";            // add more string if there switch on sample            if (nSwitchSmplNo > 0)            {                // completed sample number (optional)                if (nCompletedSmplNo > 0)                {                    str1 = GetResourceByKey(GrpOtherParam, IDS_SAMPLE_CHECK_RESULT + (int)SAMPLE_CHECK_RESULT_TYPE.FINISHED);                    str1 = str1.Replace("%d", "{0}");                    str = string.Format(str1, nCompletedSmplNo);                    strDlgMessage += str;                    strDlgMessage += "\r\n";                }                // any unmeasured switch on samples?                if (nSwitchSmplNo > nCompletedSmplNo)                {                    // with setting error sample number                    str1 = GetResourceByKey(GrpOtherParam, IDS_SAMPLE_CHECK_RESULT + (int)SAMPLE_CHECK_RESULT_TYPE.SETTING_ERROR);                    str1 = str1.Replace("%d", "{0}");                    str = string.Format(str1, nErrorSmplNo);                    strDlgMessage += str;                    strDlgMessage += "\r\n";                    // with setting warning sample number                    str1 = GetResourceByKey(GrpOtherParam, IDS_SAMPLE_CHECK_RESULT + (int)SAMPLE_CHECK_RESULT_TYPE.SETTING_WARNING);                    str1 = str1.Replace("%d", "{0}");                    str = string.Format(str1, nWarningSmplNo);                    strDlgMessage += str;                    strDlgMessage += "\r\n";                }            }            // add an empty line strDlgMessage            strDlgMessage += "\r\n";            // add sample messages            foreach (var strSmplMessage in listSamplMessages)            {                strDlgMessage += strSmplMessage;                strDlgMessage += "\r\n";            }            // do we need to show dialog box?            if (nSwitchSmplNo == 0)            {                return false;            }            // measure button clicked?            if (a_bCheckSetting)            {                // there are measurable samples but no setting warnings samples                if (listMeasurableSamples.Count > 0 && listWithWarningMeasurableSamples.Count == 0)                {                    // set output measurable samples list                    foreach (var pSample in listMeasurableSamples)                    {                        a_listMeasuableSamples.Add(pSample);                    }                    return true;                }            }            //when there is sample setting error, and setting with no error and no warning samples, the dlg will not be show.??            //show the result dlg            DIALOG_CHECK_PARAM_RESULT dlg = new DIALOG_CHECK_PARAM_RESULT();            int nTatolMeasuableSmplNo = listMeasurableSamples.Count;            int nWithWarningMeasuableSmplNo = listWithWarningMeasurableSamples.Count;            // set the dlg parameters            dlg.SetCheckOnlyFlag(a_bCheckSetting);            dlg.SetMessageBase(strDlgMessage);            dlg.SetTatolMeasuableSmplNo(nTatolMeasuableSmplNo);            dlg.SetWithWarningMeasuableSmplNo(nWithWarningMeasuableSmplNo);            //no error not show dlg            if (nTatolMeasuableSmplNo == nSwitchSmplNo - nCompletedSmplNo && listMeasurableSamples.Count != 0)            {                foreach (var pSample in listMeasurableSamples)                {                    var itr = listWithWarningMeasurableSamples.Find(s => { return s.GetName() == pSample.GetName(); });                    if (itr == null)                    {                        a_listMeasuableSamples.Add(pSample);                    }                }                if (a_listMeasuableSamples.Count == listMeasurableSamples.Count)                {                    return true;                }            }            //show dlg            DialogResult dResult = dlg.ShowDialog();            if (!(dResult == System.Windows.Forms.DialogResult.OK))            {                // do something here                return false;            }            else            {                //if warnDo, back the listMeasuableSample                if (dlg.GetWarnDo())                {                    foreach (var pSample in listMeasurableSamples)                    {                        a_listMeasuableSamples.Add(pSample);                    }                }                else // back with no warn sample                {                    foreach (var pSample in listMeasurableSamples)                    {                        var itr = listWithWarningMeasurableSamples.Find(e => { return e.GetName() == pSample.GetName(); });                        if (itr == null)                        {                            a_listMeasuableSamples.Add(pSample);                        }                    }                }            }            return true;        }        bool IsMeasureCompletedSmpl(COTSSample a_pSample)        {            // safety check            if (a_pSample.GetMsrStatus().GetStatus() != OTSDataType.OTS_MSR_SAMPLE_STATUS.SUCCESSED)            {                return false;            }            return true;        }        string GetSampleErrorWarnString(SAMPLE_FAULT_WARN_CODE a_nSampleFaultWarn)        {            // check input            if (a_nSampleFaultWarn < SAMPLE_FAULT_WARN_CODE.MIN && a_nSampleFaultWarn > SAMPLE_FAULT_WARN_CODE.MAX)            {                return "";            }            // error/waring string            string strErrorWarn;            strErrorWarn = GetResourceByKey(GrpOtherParam, IDS_ERROR_WARNING + (int)a_nSampleFaultWarn);            return strErrorWarn;        }        // get error codes list of a sample        void GetSampleErrorCodes(COTSMsrPrjResultData a_pProjMgrFile, COTSSample a_pSample, ref List<SAMPLE_FAULT_WARN_CODE> a_listErrorCodes)        {            const string UNTITLED_FILE_NAME = "Untitled";            // file has not been saved            String strPathName = a_pProjMgrFile.GetPathName();            // is this a file no saved?            strPathName.Trim();            if (strPathName == UNTITLED_FILE_NAME || strPathName == "")            {                           a_listErrorCodes.Add(SAMPLE_FAULT_WARN_CODE.FILE_NOT_SAVED);            }        }        // get warning codes list of a sample        void GetSampleWarningCodes(COTSMsrPrjResultData a_pProjMgrFile, COTSSample a_pSample, ref List<SAMPLE_FAULT_WARN_CODE> a_listWarningCodes)        {            // get the work stage            CStage pStage = a_pProjMgrFile.GetStage();            //get hole            String sHoleName = a_pSample.GetSampleHoleName();            //look for the hole Domain            CHole pSampleHole = pStage.GetHoleByName(sHoleName);            if (pSampleHole == null)            {                return;            }            if (a_pSample.GetSEMDataMsr() != null)            {                // compute pixel size                double dPixleSize = a_pSample.CalculatePixelSize();                // get min size                COTSImageProcParam pImageProcParam = a_pSample.GetMsrParams().GetImageProcessParam();                double dMinSize = pImageProcParam.GetIncAreaRange().GetStart();                // if pixel size bigger than 1/2 of the min size, current magnification can't see clear of the object                if (dPixleSize >= dMinSize * 0.5)                {                    // resolution low                    a_listWarningCodes.Add(SAMPLE_FAULT_WARN_CODE.RESOLUTION_LOW);                }            }            if(a_pSample.GetSEMDataMsr().GetTotalFields()==0               && a_pSample.GetSEMDataMsr().GetScanFieldSize() == 0               && a_pSample.GetSEMDataMsr().GetWorkingDistance() == 0)            {                // SEM_DATA_ERROR                 a_listWarningCodes.Add(SAMPLE_FAULT_WARN_CODE.SEM_DATA_ERROR);            }        }        //获取测量参数文件名称        //int iNamePos:  文件名在链表中的位置        //List<string> MParamFileNameList:  测量参数文件链表        public bool GetMeasureParamFileName(ref int iNamePos, ref List<string> MParamFileNameList)        {            if (!GetResultData().GetParamFileList(ref iNamePos, ref MParamFileNameList))            {                return false;            }            return true;        }        //设置测量文件名称        //int iNamePos:  文件名在链表中的位置        public bool SetMeasrueParamFileName(int iNamePos)        {            if (!GetResultData().ChangeParamFromList(iNamePos))            {                return false;            }            return true;        }        //获取STD 标准库文件名称        //int iNamePos:  文件名在链表中的位置        //List<string> STDFileNameList:  STD文件链表        public bool GetSTDFileName(ref int iNamePos, ref List<string> STDFileNameList)        {            if (!GetResultData().GetSTDFileList(ref iNamePos, ref STDFileNameList))            {                return false;            }            return true;        }        //设置STD 标准库文件名称        public bool SetSTDFileName(int iNamePos)        {            if (!GetResultData().ChangeSTDFromList(iNamePos))            {                return false;            }            return true;        }        ///保存工作样品的测量参数文件             public bool SaveWorkMeasureFile()        {            CSampleParamMgr SMeasureParamData = new CSampleParamMgr();            COTSSample WSample = GetResultData().GetWorkingSample();            if (null == WSample)            {                return false;            }            if (!SMeasureParamData.SetMsrParamFile(WSample.GetMsrParams()))            {                return false;            }            // file open dialog            CSampleParamMgr cSampleParamMgr = new CSampleParamMgr();            SaveFileDialog saveFileDialog = new SaveFileDialog();            saveFileDialog.FileName = WSample.GetName() +"_Config"+ cSampleParamMgr.MESUREMENT_PARAM_FILE_EXT;            saveFileDialog.Filter = cSampleParamMgr.MESUREMENT_PARAM_FILE_FILTER;            if (saveFileDialog.ShowDialog() != DialogResult.OK)            {                return false;            }            // get file pathname            string strPathName = saveFileDialog.FileName;            SMeasureParamData.Save(strPathName);            return true;        }        //打开工作样品的测量参数文件             public bool LoadWorkMeasureFile()        {            CSampleParamMgr SMeasureParamData = new CSampleParamMgr();            OpenFileDialog openFileDialog = new OpenFileDialog();            openFileDialog.Filter = SMeasureParamData.MESUREMENT_PARAM_FILE_FILTER;            if (openFileDialog.ShowDialog() != DialogResult.OK)            {                return false;            }            // get file pathname            string strPathName = openFileDialog.FileName;            if (!SMeasureParamData.Load(strPathName, true))            {                return false;            }            COTSSample WSample = GetResultData().GetWorkingSample();            if (null == WSample)            {                return false;            }            WSample.SetMsrParams(SMeasureParamData.GetMsrParams());            //更新样品GRID值测量文件名            OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();            if (!this.GetWorkSamplePerameter(WSample, ref SMInfo))            {                return false;            }            m_MeasureAppFrom.m_SPropertyWindows.DisplaySampleMeasureInfo(SMInfo);            return true;        }        //判断是否允许修改样品名        public bool CheckSampleNameIsValid(string sNewName)        {            return GetResultData().IsValidSampleName(sNewName);        }        //设置电镜参数        //int iScanFieldSize: Field扫描参数        //int iWDistance: 电镜工作距离        //double dMagni: 放大倍数        public void SetWorkingSampleSEMData(double iWDistance, double dMagni)        {            try            {                GetResultData().GetWorkingSample().GetSEMDataMsr().SetWorkingDistance(iWDistance);                GetResultData().GetWorkingSample().GetSEMDataMsr().SetMagnification(dMagni);            }            catch (Exception)            {            }        }        public void SetFliedsCount(int FliedsCount)        {            GetResultData().GetWorkingSample().GetSEMDataMsr().SetTotalFields(FliedsCount);        }        //获取电镜参数        //int iScanFieldSize: Field扫描参数        //int iWDistance: 电镜工作距离        //double dMagni: 放大倍数        public void GetWorkingSampleSEMData(ref double iWDistance, ref double dMagni)        {            iWDistance = GetResultData().GetWorkingSample().GetSEMDataMsr().GetWorkingDistance();            dMagni = GetResultData().GetWorkingSample().GetSEMDataMsr().GetMagnification();        }        public int GetTotalFieldsCount()        {            int icount = GetResultData().GetWorkingSample().GetSEMDataMsr().GetTotalFields();            return icount;        }        //获取工作样品的测量区域        //int iShape :测量区域形状        //Rectangle Srect: 测量区域大小        public bool GetWSampleMrsArea(ref int iShape, ref Rectangle Srect)        {            COTSSample WSample = GetResultData().GetWorkingSample();            if (null == WSample)            {                return false;            }            CDomain pMsrArea = new CDomain();            pMsrArea = WSample.GetMsrArea();            if (null == pMsrArea)            {                return false;            }            iShape = (int)pMsrArea.GetShape();            ValueType ValType = new Rectangle();            ValType = pMsrArea.GetRectDomain();            Srect = (Rectangle)ValType;            return true;        }        //检查Samplelist中的sample的checkbox状态        //当Samplelist中的链表有sample 的checkbox状态是选中状态,则返回TRUE. 说明可以测量        public bool GetSampleCheckBoxStatus()        {            COTSSample WSample = GetResultData().GetWorkingSample();            if (null == WSample)            {                return false;            }            List<COTSSample> SampleList = new List<COTSSample>();            SampleList = GetResultData().GetSampleList();            int iCount = SampleList.Count();            if (0 == iCount)            {                return false;            }            for (int i = 0; i < iCount; i++)            {                if (SampleList[i].GetSwitch())                {                    return true;                }            }            return false;        }        //获取BSE图像数据        public bool GetBSEImageSize(ref int iHeight, ref int iWidth)        {            COTSSample WSample = GetResultData().GetWorkingSample();            if (null == WSample)            {                return false;            }            if (!WSample.GetBSESize(out iHeight, out iWidth))            {                return false;            }            return true;        }               //获取图像尺寸        public string GetBSEImageResolution()        {            try            {                COTSSample WSample = GetResultData().GetWorkingSample();                if (null == WSample)                {                    return "";                }                OTSSamplePropertyInfo SMInfo = new OTSSamplePropertyInfo();                if (!GetWorkSamplePerameter(WSample, ref SMInfo))                {                    return "";                }                int iCount = SMInfo.SampleDataList.Count();                for (int i = 0; i < iCount; i++)                {                    if (OTS_SAMPLE_PROP_GRID_ITEMS.IMAGE_RESOLUTION == SMInfo.SampleDataList[i].iSampleId)                    {                        String val = (String)SMInfo.SampleDataList[i].SampleVal;                        return val;                    }                }                return "";            }            catch (Exception)            {                return "";            }        }        //获取放大倍数和工作距离        public bool GetMagAndDistance(ref double SemMag, ref double dDistance)        {                          COTSSample WSample = GetResultData().GetWorkingSample();                if (null == WSample)                {                    return false;                }            //GetWorkingSampleSEMData(ref SemMag, ref dDistance);            GetWorkingSampleSEMData(ref dDistance, ref SemMag);            return true;                   }        public bool GetWorkSamplePerameter(COTSSample Sample, ref OTSSamplePropertyInfo SMeasureInfo)        {            //设置工作样品属性项            if (Sample.GetMsrParams().m_nPackId == OTS_SysType_ID.CleannessA)            {                Sample.SetPropItemGrpsForCleanlinessSys();            }            else            {                Sample.SetPropItemGrpsForIncA();            }                      bool MeasurementStatus = false;                       //样品的标题名 (Treeview的根节点名)                       SMeasureInfo.sSampleSoluName = GetResultData().GetFileName();            // Treeview 的样品信息              SMeasureInfo.TSampleParam.sSampleTitleName = GetResultData().GetFileName();            //获得 样品属性值                       SMeasureInfo.bSwitch = Sample.GetSwitch();// (bool)jo.GetValue("bSwitch");            SMeasureInfo.TSampleParam.bParamLock = Sample.GetParamLock();// (bool)jo.GetValue("ParamLock");            //获取样品的测量区域信息             //获取样品名称                      SMeasureInfo.SMeasurePara.sSampleName = Sample.GetName();// (String)SMeasurePara.GetValue("sNewSampleName");            // 获取测量区域形状            SMeasureInfo.SMeasurePara.iShape = (int)Sample.GetMsrArea().GetShape();// (int)SMeasurePara.GetValue("iShape");            //获取样品孔名称            SMeasureInfo.SMeasurePara.sHoleName = Sample.GetSampleHoleName();// (String)SMeasurePara.GetValue("sHoleName");                                                                             //样品测量区域                                                                             // JObject rec = (JObject)SMeasurePara.GetValue("MeasureRect");            Rectangle rec = Sample.GetMsrArea().GetDomainRect();            SMeasureInfo.SMeasurePara.MeasureRect = new Rectangle((int)rec.X, (int)rec.Y, (int)rec.Width, (int)rec.Height);                     SMeasureInfo.TSampleParam.sWorkSampleName = Sample.GetName();// (String)TSampleParam.GetValue("sWorkSampleName");            SMeasureInfo.TSampleParam.bSwitch = Sample.GetSwitch();// (bool)TSampleParam.GetValue("bSwitch");            List<CPropItemGrp> ja = Sample.GetPropItemGrps();// (JArray)jo.GetValue("ItemGrp");            for (int i = 0; i < ja.Count; i++)            {                //获取GROUP ID和Grid的显示组的标题名                var grp = ja[i];                int grpId = (int)grp.GetGroupId();                String sTitle = (String)grp.GetName();                //获取样品属性ID和值                var SDataArr = grp.GetItemsList();                if (SDataArr.Count == 0)                    continue;                SamplePropertyDataGroup smlgrp = new SamplePropertyDataGroup();                smlgrp.GroupId = (OTS_SAMPLE_PROP_GRID_ITEM_GROUPS)grpId;                smlgrp.sTitle = sTitle;                for (int j = 0; j < SDataArr.Count; j++)                {                      var SDataObj = SDataArr[j];                    SamplePropertyData SData = new SamplePropertyData();                    int smplid = (int)SDataObj.GetSmplItemId();                    SData.iSampleId = (OTS_SAMPLE_PROP_GRID_ITEMS)smplid;                    if (SData.iSampleId == OTS_SAMPLE_PROP_GRID_ITEMS.WORKING_DISTANCE)                    {                        bool b = (bool)SDataObj.IsReadOnly();                    }                    SData.sSCaptionName = (String)SDataObj.GetName();                    //------------------------------修改--------------------------                    if ((String)SDataObj.GetName() == "样品名")                    {                        for (int a = 0; a < ja.Count; a++)                        {                            var grpa = ja[a];                            var SDataArra = grpa.GetItemsList();                            for (int b = 0; b < SDataArra.Count; b++)                            {                                var SDataObb = SDataArra[b];                                if ((String)SDataObb.GetName() == "测量状态")                                {                                    if ((String)Sample.GetItemValueStr((OTS_SAMPLE_PROP_GRID_ITEMS)SDataObb.GetSmplItemId()) == "未测量")                                    {                                        MeasurementStatus = false;                                    }                                    else                                    {                                        MeasurementStatus = true;                                    }                                }                            }                        }                    }                    else                    {                        MeasurementStatus = false;                    }                    if (MeasurementStatus)                    {                        SData.bReadOnly = MeasurementStatus;                    }                    else                    {                        SData.bReadOnly = (bool)SDataObj.IsReadOnly();// OTS_ITEM_TYPES                    }                    //---------------------------------------------------------------                    int type = (int)SDataObj.GetTypeId();                    SData.iSampleValType = (OTS_ITEM_TYPES)type;                    SData.sDescriptionInfo = (String)SDataObj.GetDescription();                                    OTS_SAMPLE_PROP_GRID_ITEMS ItemId = SDataObj.GetSmplItemId();                    SData.SampleVal = (String)Sample.GetItemValueStr(ItemId);                    List<string> downStrList = new List<string>();                    if (type == (int)OTS_ITEM_TYPES.COMBO)                    {                        Sample.GetPropComboStrings(SDataObj.GetSmplItemId(), downStrList);                    }                    else if (type == (int)OTS_ITEM_TYPES.FILE_LIST)                    {                        //the sample object dosen't know anything about the fileList infomation so it has to delay this duty here.                        int iPos = -1;                        List<string> sFileNameList = new List<string>();                        if (OTS_SAMPLE_PROP_GRID_ITEMS.MEASURE_PARAM_FILE_NAME == (OTS_SAMPLE_PROP_GRID_ITEMS)smplid)                        {                            if (!this.GetMeasureParamFileName(ref iPos, ref sFileNameList))                            {                                return false;                            }                            foreach (var f in sFileNameList)                            {                                downStrList.Add(f);                            }                        }                        if (OTS_SAMPLE_PROP_GRID_ITEMS.STD_FILE_NAME == (OTS_SAMPLE_PROP_GRID_ITEMS)smplid)                        {                            if (!this.GetSTDFileName(ref iPos, ref sFileNameList))                            {                                return false;                            }                            foreach (var f in sFileNameList)                            {                                downStrList.Add(f);                            }                        }                    }                    if (downStrList.Count > 0)                    {                        for (int k = 0; k < downStrList.Count; k++)                        {                            SData.comboDownList.Add((String)downStrList[k]);                        }                    }                    smlgrp.SampleDataList.Add(SData);                }                SMeasureInfo.AddASampleDataGrp(smlgrp);            }            return true;        }        //保存测量样品的        public bool SaveMeasureSampleInfo()        {            if (!GetResultData().Save())            {                return false;            }            return true;        }        //获取测量Sample的开始时间        public bool GetMsrSampleStartTime(ref DateTime MsrFieldStartTime)        {            COTSSample WSample = GetResultData().GetWorkingSample();            if (null == WSample)            {                return false;            }            MsrFieldStartTime = (DateTime)WSample.GetMsrStatus().GetStartTime();            return true;        }        //获取测量已用时间        public bool GetMsrSampleUsedTime(ref TimeSpan TUsedTime)        {            COTSSample WSample = GetResultData().GetWorkingSample();            if (null == WSample)            {                return false;            }            TUsedTime = (TimeSpan)WSample.GetMsrStatus().GetUsedTime();            return true;        }        // 获取测量样品中之前已经测量完成Field帧图,(上一次未测量完成继续测试)        public bool GetBeforeCompleteField(ref string MsrSampleName, ref List<Point> FieldList)        {            COTSSample WSample = GetResultData().GetWorkingSample();            if (null == WSample)            {                return false;            }            MsrSampleName = WSample.GetName();            FieldList = WSample.GetMsrStatus().GetCompletedFieldsCenter();            return true;        }         /// <summary>        /// 通过样品孔信息 返回默认测量区域大小        /// </summary>        /// <param name="cHoleClr"></param>        /// <returns></returns>        public Rectangle CalculateMsrArea(string cHoleName)        {            CHole cHoleClr = null;            foreach (CHole item in GetResultData().GetStage().GetHoleList())            {                if (item.GetName() == cHoleName)                {                    cHoleClr = item;                }            }            CDomain CDomain = GetResultData().CalculateMsrArea(cHoleClr);            return (Rectangle)CDomain.GetRectDomain();        }        /// <summary>        /// 获取已完成测量的结果文件路径        /// </summary>        /// <param name="mrFilePathList">返回测量结果文件路径</param>        /// <returns></returns>        public bool GetCompletedMeasureFileName(ref List<string> mrFilePathList)        {            //测量文件路径            string proFilePath = GetResultData().GetPathName();            //样品列表            List<COTSSample> sampleList = GetResultData().GetSampleList();            //获取样品数量            int sampleCount = sampleList.Count;            string mrSuffix = ".rst";            int existsCount = 0;            //获取测量文件路径            if (proFilePath.Equals("Untitled"))            {                return false;            }            string mrFolderPath = string.Empty;            try            {                mrFolderPath = proFilePath.Substring(0, proFilePath.LastIndexOf("\\"));            }            catch (Exception)            {                mrFolderPath = string.Empty;            }            for (int sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++)            {                int CompleteFieldsCount = sampleList[sampleIndex].GetMsrStatus().GetCompletedFields();                //如果样品已测量成功后再加载至报告程序中                if (CompleteFieldsCount > 0)                {                    string sampleName = sampleList[sampleIndex].GetName();                    string mrFilePath = mrFolderPath + "\\" + sampleName + "\\" + sampleName + mrSuffix;                    //判断文件是否存在                    if (File.Exists(mrFilePath))                    {                        if (mrFilePathList != null)                        {                            mrFilePathList.Add(mrFilePath);                        }                        existsCount++;                    }                }            }            if (existsCount > 0)            {                return true;            }            return false;        }        /// <summary>        /// 获取工作样品的测量状态        /// </summary>        /// <param name="workingSampleName"></param>        /// <returns></returns>        public bool GetWorkSampleMeasureStatus()        {            bool reuslt = false;            COTSSample COTSSample = GetResultData().GetWorkingSample();            int sampleStatus = COTSSample.GetMsrStatus().GetCompletedFields();            if (sampleStatus > 0)            {                reuslt = true;            }            return reuslt;        }          }   }
 |