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; /// /// 创建 private COTSMsrPrjResultData resultData; //参数文件 private COTSDefaultParam defaultParam = null; //样品台文件(读取样品台数据等) private CStageParam stageParam = null; private CSpecialGrayRangeParam specialRanges = null; //测量样品链表 List m_MeasureSampleList = new List(); NLog.Logger log ; public CSpecialGrayRangeParam SpecialRanges { get => specialRanges; set => specialRanges = value; } public List 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 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 PolygonPoint = new List(); 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 MSampleList = new List(); 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 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 listSamplMessages = new List(); List listSamples = a_pProjMgrFile.GetSampleList(); List listMeasurableSamples = new List(); List listWithWarningMeasurableSamples = new List(); 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 a_listErrorCodes = new List(); 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 a_listWarningCodes = new List(); 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 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 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 SampleList = new List(); 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 FieldList) { COTSSample WSample = GetResultData().GetWorkingSample(); if (null == WSample) { return false; } MsrSampleName = WSample.GetName(); FieldList = WSample.GetMsrStatus().GetCompletedFieldsCenter(); return true; } /// /// 通过样品孔信息 返回默认测量区域大小 /// /// /// 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(); } /// /// 获取已完成测量的结果文件路径 /// /// 返回测量结果文件路径 /// public bool GetCompletedMeasureFileName(ref List mrFilePathList) { //测量文件路径 string proFilePath = GetResultData().GetPathName(); //样品列表 List 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; } /// /// 获取工作样品的测量状态 /// /// /// 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; } } }