12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409 |
- 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 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)
- {
-
- GetResultData().GetWorkingSample().GetSEMDataMsr().SetWorkingDistance(iWDistance);
- GetResultData().GetWorkingSample().GetSEMDataMsr().SetMagnification(dMagni);
-
- }
- //public void SetFliedsCount(int FliedsCount)
- //{
- // GetResultData().GetWorkingSample().GetSEMDataMsr().SetTotalFields(FliedsCount);
- //}
- 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 GetWorkSampleMrsArea(ref int iShape, ref RectangleF Srect)
- //{
- // COTSSample WSample = GetResultData().GetWorkingSample();
- // if (null == WSample)
- // {
- // return false;
- // }
- // CDomain pMsrArea = new CDomain();
- // pMsrArea = WSample.GetMsrDomain();
- // if (null == pMsrArea)
- // {
- // return false;
- // }
- // iShape = (int)pMsrArea.GetShape();
-
- // Srect = pMsrArea.GetRectDomain();
-
- // 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;
-
- }
-
- //保存测量样品的
- //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<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;
- }
-
- }
-
- }
|