1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381 |
- using OTSModelSharp;
- using OTSDataType;
- 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.OTSDataType;
- namespace OTSMeasureApp
- {
-
- //设置线程状态
- public enum MSR_RUN_TYPE
- {
- RUNMEASURE = 1, //normal
- RUNSampleHoleImage = 2 //take photo of the measure area.
- };
- 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 List<COTSSample> MeasureSampleList { get => m_MeasureSampleList; set => m_MeasureSampleList = 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());
- return GetDefaultParam().LoadInfoFromProgMgrFile();
-
-
- }
- //检查参数样品台文件是否存在
- 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().SystemTypeId = GetDefaultParam().SystemTypeId;
- 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 PointF ConvertOTSToSemCoord(PointF POTSCoord)
- {
- System.Drawing.PointF VSemCoord = new System.Drawing.PointF();
- GetDefaultParam().GetStageDataParam().ConvertOTSToSEMCoord(POTSCoord, ref VSemCoord);
- return VSemCoord;
- }
- //将Sem 坐标转换为样品台坐标
- public PointF ConverSEMToOTSCoord(PointF PSEMCoord)
- {
- System.Drawing.PointF VOTSCoord = new System.Drawing.PointF();
- GetDefaultParam().GetStageDataParam().ConvertSEMToOTSCoord(PSEMCoord, ref VOTSCoord);
- return VOTSCoord;
- }
- public OTSSampleVisualPropertyInfo AddNewSampleMeasure(string a_strHoleName = "")
- {
- COTSSample NewSample = new COTSSample();
- SetSampleDefaultPara(ref NewSample, a_strHoleName);
- //NewSample.
- //添加样品
- GetResultData().AddSample(NewSample);
-
- // 获取样品的属性值
- OTSSampleVisualPropertyInfo MeasureInfo = new OTSSampleVisualPropertyInfo(NewSample, defaultParam.GetSysType());
-
- return MeasureInfo;
- }
- public void InitWorkingSampleData(int startfieldNo)
- {
- COTSSample Sample = GetWorkSample();
- if (Sample == null) return ;
- var sname= Sample.GetName();
- var pathname = resultData.GetFolderName(resultData.GetPathName());
- var sampleResultFolder = pathname + "\\" + sname;
- if (Directory.Exists(sampleResultFolder))
- {
- resultData.DeleteWorkingSampleFieldDataByFieldNo(startfieldNo);
- //Directory.Delete(sampleResultFolder, true);
- var flds = Sample.GetFieldsData();
- foreach (var f in flds)
- {
- if (f.GetMeasureSequence() >= startfieldNo)
- {
- f.ClearAllMeausredData();
- f.SetIsMeasureComplete(false);
- }
-
- }
-
- }
- var sta = Sample.GetMsrStatus();
- sta.ClearCompletedFieldsInfo();
- sta.SetStatus(OTS_MSR_SAMPLE_STATUS.UNMEASURED);
- var rsts = Sample.GetMsrResults();
- var itms = rsts.GetResultItems();
- itms.Clear();
- rsts.SetResultItems(itms);
- rsts.SetMeasuredArea(0);
- rsts.SetRatio(0);
- }
- public OTSSampleVisualPropertyInfo GetWorkingSampleVisualPropertyInfo()
- {
-
- COTSSample Sample = GetWorkSample();
- if (Sample == null) return null;
- OTSSampleVisualPropertyInfo MeasureInfo = new OTSSampleVisualPropertyInfo(Sample, defaultParam.GetSysType());
- 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().SystemTypeId;
- 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());
- poMsrParams.SetSysSTDSwitch(m_pParam.GetSysSTD());
- pSample.SetMsrDomain(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 ;
- // 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
-
- for (int i = 0; i < listHoles.Count; i++)
- {
- if (listHoles[i].GetName() == a_strHoleName)
- {
- cReHole = listHoles[i];
- 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())
- {
-
- 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)
- {
- RectangleF rectHole = a_pHole.GetDomainRect();
- System.Drawing.PointF ptCenter = new System.Drawing.PointF((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.PointF ptLeftTop = new System.Drawing.Point();
- System.Drawing.SizeF 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;
- }
- RectangleF MsrRect = new RectangleF(ptLeftTop, ptSize);
- CDomain pMsrArea = new CDomain(nShape, MsrRect);
-
- return pMsrArea;
- }
- //设置工作样品的属性值
- public bool SetSampleParamVal(OTS_SAMPLE_PROP_GRID_ITEMS ItemId, OTS_ITEM_TYPES ValType, object objVal)
- {
- COTSSample WSample = GetResultData().GetWorkingSample();
- OTSSampleVisualPropertyInfo MeasureInfo = new OTSSampleVisualPropertyInfo(WSample, defaultParam.GetSysType());
- bool bSetFalg = false;
-
- bSetFalg = MeasureInfo.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();
-
- 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;
- }
- //移动工作样品到其他样品孔,样品孔名称和测量区域都要改变,重新设置工作样品参数
-
- public void SetWorkSampleHoleAndMeasureArea(SampleMeasurePara SMeasurePara)
- {
-
- COTSSample WSample = GetResultData().GetWorkingSample();
- if (null == WSample)
- {
- return ;
- }
- CDomain Domain = new CDomain();
- Domain.SetShape((otsdataconst.DOMAIN_SHAPE)SMeasurePara.iShape);
- Domain.SetRectDomain(SMeasurePara.MeasureRect);
- if (SMeasurePara.DrawPolygonPointList != null)
- {
- List<Point> PolygonPoint = new List<Point>();
- foreach (var item in SMeasurePara.DrawPolygonPointList)
- {
- PolygonPoint.Add(new Point((int)item.X, (int)item.Y));
- }
- Domain.SetPolygonPoint(PolygonPoint);
- }
- WSample.SetSampleHoleName(SMeasurePara.sampleHoleName);
- WSample.SetMsrDomain(Domain);
-
-
- return ;
- }
- //设置测量区域的形状 (通过RIBBON 上的画圆,画矩形 设置)
- //int iShape: 测量区域形状 0: 圆形; 1 :矩形
- public void SetMeasureAreaShape(ShapeType iShape)
- {
-
- COTSSample WSample = GetResultData().GetWorkingSample();
- if (null == WSample)
- {
- return;
- }
- CDomain Domain = new CDomain();
- Domain.SetShape((otsdataconst.DOMAIN_SHAPE)iShape);
- }
- //public bool SetWorkSampleParamLock(bool ParaLockFlag)
- //{
- // COTSSample WSample = GetResultData().GetWorkingSample();
- // if (null == WSample)
- // {
- // return false;
- // }
- // WSample.SetParamLock(ParaLockFlag);
- // GetResultData().SetModify(true);
- // 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 is bigger than 1/2 of the min size,than can't see the object clearly on current magnification
- 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);
- }
- }
-
- //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值测量文件名
- OTSSampleVisualPropertyInfo SMInfo = new OTSSampleVisualPropertyInfo(WSample,defaultParam.GetSysType());
-
- 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,double bri,double contra,double kv)
- {
- var semdata = GetResultData().GetWorkingSample().GetSEMDataMsr();
- semdata.SetWorkingDistance(iWDistance);
- semdata.SetMagnification(dMagni);
- semdata.Brightness = bri;
- semdata.Contrast = contra;
- semdata.KV = kv;
-
- }
-
- public bool GetWorkingSampleSEMData(ref double iWDistance, ref double dMagni, ref double bri, ref double contra, ref double kv)
- {
- COTSSample WSample = GetResultData().GetWorkingSample();
- if (null == WSample)
- {
- return false;
- }
- var semdata = GetResultData().GetWorkingSample().GetSEMDataMsr();
- iWDistance = semdata.GetWorkingDistance();
- dMagni = semdata.GetMagnification();
- bri = semdata.Brightness;
- contra = semdata.Contrast;
- kv = semdata.KV;
- 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 GetBSEImageResolutionStr()
- {
- try
- {
- COTSSample WSample = GetResultData().GetWorkingSample();
- var res= WSample.GetMsrParams().GetImageScanParam().GetImageResolutionSize();
-
-
- return res.cx+"X"+res.cy;
- }
- catch (Exception)
- {
- return "";
- }
- }
- //获取放大倍数和工作距离
- //public bool GetMagAndDistance(ref double SemMag, ref double dDistance)
- //{
-
- // COTSSample WSample = GetResultData().GetWorkingSample();
- // if (null == WSample)
- // {
- // return false;
- // }
-
- // GetWorkingSampleSEMData(ref dDistance, ref SemMag);
- // 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<PointF> 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 RectangleF 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 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();
- if (COTSSample == null) return false;
- int sampleStatus = COTSSample.GetMsrStatus().GetCompletedFields();
- if (sampleStatus > 0)
- {
- reuslt = true;
- }
- return reuslt;
- }
-
- }
-
- }
|