12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301 |
- using OTSCLRINTERFACE;
- using OTSDataType;
- using OTSModelSharp.ServiceCenter;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Windows.Forms;
- using System.Xml;
- using static OTSDataType.otsdataconst;
- namespace OTSModelSharp
- {
- public class COTSMsrPrjResultData
- {
- // SEM stage data
- CSEMStageData m_pSEMStageData;
- //// stage
- CSampleHolder m_pStage;
- // general parameter
- COTSCommonParam m_CommonParam;
- // sample list
- List<COTSSample> m_listSamples = new List<COTSSample>();
-
- bool m_bModify;
- // path name
- String m_strPathName;
- // working sample index
- int m_nWorkingSampeIndex;
- const String UNTITLED_FILE_NAME = "Untitled";
- const String SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER = "FIELD_FILES";
- // Inclusion file name
- const String SMPL_MSR_RESULT_INCLUSION_FILE = "Inclusion.db";//put all the table in one db file so that report can make join query.
- private otsdataconst.OTS_SysType_ID systemTypeId;
-
- public OTS_SysType_ID SystemTypeId { get => systemTypeId; set => systemTypeId = value; }
- public COTSMsrPrjResultData()
- {
- Init();
- }
- // initialization
- public void Init()
- {
- m_listSamples.Clear();
- //m_listHoleBSEImg.Clear();
- m_bModify = false;
- m_strPathName = "";
- m_nWorkingSampeIndex = -1;
- }
- public void SetPathName(String a_strPathName) { m_strPathName = a_strPathName; }
- public bool Load(string strPathName)
- {
- Cleanup();
- // check if the file exist
- if (!FileExists(strPathName))
- {
- // shouldn't happen, file does not exist
- return false;
- }
- //获取测量项目文件
- XmlDocument doc = new XmlDocument();
- //载入xml文件
- doc.Load(strPathName);
- XmlNode root = doc.SelectSingleNode("XMLData");
- Serialize(false, doc, root);
- //设置测量项目文件路径
- SetPathName(strPathName);
-
- //-------------
- foreach (var smpl in m_listSamples)
- {
- // get path of the pathname
-
- List<COTSField> allMeasuredFlds = new List<COTSField>();
- CMsrSampleStatus poMsrStatus = new CMsrSampleStatus();
- CMsrResultItems poMsrResults = smpl.GetMsrResults();
- double aFldArea = smpl.CalculateAFieldArea();
-
- int w, h;
- smpl.GetBSESize(out w, out h);
- double pixelsize = smpl.CalculatePixelSize();
- var overlap = smpl.GetMsrParams().GetImageProcessParam().GetOverlapParam();
- var noParticledataFields = smpl.GetFieldsData();//there's only the field postion info in the xml file,so the initial filed has only postion info.
- List<COTSField> allflddata = new List<COTSField>();//contains all the field
- if (GetAllFieldsFromDB(ref allMeasuredFlds, ref poMsrStatus,smpl.GetName(),ref poMsrResults, aFldArea, new Size(w, h), pixelsize))
- {
- //------------complete the infomation that doesn't contain in database-----
- foreach (var f in allMeasuredFlds)
- {
- f.SetPixelSize(pixelsize);
- f.ImgWidth = w;
- f.ImgHeight = h;
- double effectiveWidth = f.ImgWidth * pixelsize - 2 * overlap;
- double effectiveHeight = f.ImgHeight * pixelsize - 2 * overlap;
- PointF fldPos = f.GetOTSPosition();
- Point lt = new Point((int)fldPos.X - (int)effectiveWidth / 2, (int)fldPos.Y - (int)effectiveHeight / 2);
- Point rb = new Point((int)fldPos.X + (int)effectiveWidth / 2, (int)fldPos.Y + (int)effectiveHeight / 2);
- f.SetOTSRect(new OTSMeasureApp._0_OTSModel.OTSDataType.COTSRect(lt, rb));
- f.SetMeasureSequence(f.GetId());
- f.SetIsMeasureComplete(true);
- }
- }
- //------------------------------
- foreach (var emptyfld in noParticledataFields)
- {
- bool isMeasured = false;
- foreach (var measuredField in allMeasuredFlds)
- {
- if (measuredField.PositionEquals(emptyfld))
- {
- allflddata.Add(measuredField);
- isMeasured = true;
- break;
- }
- }
- if (!isMeasured)
- {
- emptyfld.SetPixelSize(pixelsize);
- emptyfld.ImgWidth = w;
- emptyfld.ImgHeight = h;
- double effectiveWidth = emptyfld.ImgWidth * pixelsize - 2 * overlap;
- double effectiveHeight = emptyfld.ImgHeight * pixelsize - 2 * overlap;
- PointF fldPos = emptyfld.GetOTSPosition();
- Point lt = new Point((int)fldPos.X - (int)effectiveWidth / 2, (int)fldPos.Y - (int)effectiveHeight / 2);
- Point rb = new Point((int)fldPos.X + (int)effectiveWidth / 2, (int)fldPos.Y + (int)effectiveHeight / 2);
- emptyfld.SetOTSRect(new OTSMeasureApp._0_OTSModel.OTSDataType.COTSRect(lt, rb));
- emptyfld.SetIsMeasureComplete(false);
- emptyfld.SetMeasureSequence(emptyfld.GetId());
- allflddata.Add(emptyfld);
- }
- }
- smpl.SetFieldsData(allflddata);
- // file validation
- smpl.SetMsrStatus(poMsrStatus);
- smpl.SetMsrResults(poMsrResults);
- List<Point> listCenterPoint = new List<Point>();
- Size rectSize = new Size();
- smpl.InitFieldPosData(out listCenterPoint, out rectSize);//init the underlevel fieldmgr object ,so that we can use it later
- }
- if (m_listSamples.Count > 0)
- {
- m_nWorkingSampeIndex = 0;
- }
- //-----------------------------------------
- return true;
- }
- // gets the name of the folder
- public String GetFolderName(String a_strPathName)
- {
- string str = "";
- str = Path.GetDirectoryName(a_strPathName);
- return str.ToString();
- }
- public bool FileExists(string a_sPath)
- {
- bool b_IsExists = File.Exists(a_sPath);
- return b_IsExists;
- }
- public bool DirectoryExists(string a_sPath)
- {
- bool b_IsExists = Directory.Exists(a_sPath);
- return b_IsExists;
- }
- // cleanup
- public void Cleanup()
- {
- //m_listHoleBSEImg.Clear();
- m_listSamples.Clear();
- m_bModify = false;
- m_strPathName = "";
- m_nWorkingSampeIndex = -1;
- }
- // set modify flag
- public void SetModify(bool a_bModify = true) { m_bModify = a_bModify; }
- // file pathname
- public String GetPathName() { return m_strPathName; }
- public bool GetAllFieldsFromDB(ref List<COTSField> allFlds, ref CMsrSampleStatus status,string sampleName,ref CMsrResultItems rst, double aFieldArea, Size picSize, double pixelSize)
- {
-
- String strFilePath = GetFolderName(m_strPathName);
- if (strFilePath == "")
- {
- // file path string is an empty string
- return false;
- }
- // field file sub folder string
- String strFieldFileSubFolder = strFilePath + "\\" + sampleName + "\\" + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + "\\";
- String strIncAFilename = strFieldFileSubFolder + "\\" + SMPL_MSR_RESULT_INCLUSION_FILE;
- if (!FileExists(strIncAFilename))
- {
- return false;
- }
- List<System.Drawing.PointF> completedFldPositions = new List<System.Drawing.PointF>();
- CIncAFileMgr incAFileMgr = new CIncAFileMgr(strIncAFilename);
- var m_IncADataDB = incAFileMgr.GetIncADB();
- List<COTSField> allFldsWithdata = new List<COTSField>();
- m_IncADataDB.GetAllFieldsRecord(pixelSize, ref allFldsWithdata);
- var eleChemistryDB = incAFileMgr.GetPosXrayDBMgr().GetElementChemistryDB();
- Dictionary<string, CPosXrayClr> mapXrayInfo = new Dictionary<string, CPosXrayClr>();
- eleChemistryDB.GetAllMapedXrayInfo(ref mapXrayInfo);
- foreach (var f in allFldsWithdata)
- {
- foreach (var p in f.GetListAnalysisParticles())
- {
- int curFldId = f.GetId();
- int xrayId = p.GetAnalysisId();
- string fldvec = "";
- fldvec += curFldId.ToString();
- fldvec += "_";
- fldvec += xrayId.ToString();
- if (mapXrayInfo.ContainsKey(fldvec))
- {
- var xray = mapXrayInfo[fldvec];
- p.SetXray(xray);
- }
- }
- }
- var xrayDataDBDB = incAFileMgr.GetPosXrayDBMgr().GetXrayDataDB();
- Dictionary<string, CPosXrayClr> mapXrayData = new Dictionary<string, CPosXrayClr>();// map structure:[(fieldId,xrayId),CPosXrayPtr],every element of this map represent one unique xraydata.
- xrayDataDBDB.GetAllMapedXrayData(ref mapXrayData);
- foreach (var f in allFldsWithdata)
- {
- foreach (var p in f.GetListAnalysisParticles())
- {
- int curFldId = f.GetId();
- int xrayId = p.GetAnalysisId();
- string fldvec = "";
- fldvec += curFldId.ToString();
- fldvec += "_";
- fldvec += xrayId.ToString();
- if (mapXrayData.ContainsKey(fldvec))
- {
- var xray = mapXrayData[fldvec];
- CPosXrayClr t2 = p.GetXray();
- if (t2 == null)
- {
- t2 = new CPosXrayClr();
- p.SetXray(t2);
- }
- t2.SetXrayData(xray.GetXrayData());
- }
- }
- }
- CSegmentDB SegmentDB = incAFileMgr.GetSegmentDB();
- double msrFldsArea = 0;
- Dictionary<int, List<COTSParticleClr>> mapTypeParticles = new Dictionary<int, List<COTSParticleClr>>();//record typeId relevants particlelist;
- List<COTSSegmentClr> AllSegments;
- Dictionary<string, List<COTSSegmentClr>> mapSegments = new Dictionary<string, List<COTSSegmentClr>>();
- if (SegmentDB.GetAllSegmentsRecord(mapSegments))
- {
- foreach (var fld in allFldsWithdata)
- {
- int fldId = fld.GetId();
- List<COTSParticleClr> parts = fld.GetListAnalysisParticles();
- foreach (var part in parts)
- {
- string fldvec = "";
- fldvec += fldId.ToString();
- fldvec += "_";
- fldvec += part.GetParticleId().ToString();
- if (mapSegments.ContainsKey(fldvec))
- {
- COTSFeatureClr f = new COTSFeatureClr();
- AllSegments = mapSegments[fldvec];
- f.SetSegmentsList(AllSegments, true);
- part.SetFeature(f);
- if (mapTypeParticles.ContainsKey(part.GetType()))
- {
- mapTypeParticles[part.GetType()].Add(part);
- }
- else
- {
- List<COTSParticleClr> ps = new List<COTSParticleClr>();
- ps.Add(part);
- mapTypeParticles.Add(part.GetType(), ps);
- }
- }
-
- }
- msrFldsArea += aFieldArea;
- }
- }
- var fielddb = incAFileMgr.GetFieldDB();
- var fielddata = fielddb.GetTableQueryForDataTable();
- foreach (DataRow r in fielddata.Rows)
- {
- var p = new Point(Convert.ToInt32(r[(int)CFieldTable.ColumnID.N_FIELDPOS_X]), Convert.ToInt32(r[(int)CFieldTable.ColumnID.N_FIELDPOS_Y]));
- completedFldPositions.Add(p);
- }
- status.SetCompletedFieldsCenter(completedFldPositions);
- //add the empty field(there's no any particle in the bse image,so the field is empty)
- foreach (var p in completedFldPositions)
- {
- bool haveData = false;
- var emptyFld = new COTSField(p, pixelSize);
-
- foreach (var fld in allFldsWithdata)
- {
- if (fld.PositionEquals(emptyFld))
- {
- haveData = true;
- allFlds.Add(fld);
- break;
- }
- }
- if (!haveData)
- {
- allFlds.Add(emptyFld);
- }
- }
- // get MsrStatus info from DB.
- var m_GenInfoDB = incAFileMgr.GetGeneralInfoDB();//DBStoreFile类
- String strTimeStart = "";
- String strTimeEnd = "";
- String strRstStatus = "";
- m_GenInfoDB.GetStringValue(m_GenInfoDB.GetTableItemNameTimeStart(), ref strTimeStart);
- m_GenInfoDB.GetStringValue(m_GenInfoDB.GetTableItemNameTimeEnd(), ref strTimeEnd);
- m_GenInfoDB.GetStringValue(m_GenInfoDB.GetTableItemNameResultStatus(), ref strRstStatus);
- DateTime timeStart, timeEnd;
- try
- {
- timeStart = Convert.ToDateTime(ConvertFormatOfDateString(strTimeStart)); //此处为兼容之前得测量得结果可以打开,故在此进行数据格式变换
- timeEnd = Convert.ToDateTime(ConvertFormatOfDateString(strTimeEnd));
- }
- catch
- {
- timeStart = Convert.ToDateTime(strTimeStart); //此处为兼容之前得测量得结果可以打开,故在此进行数据格式变换
- timeEnd = Convert.ToDateTime(strTimeEnd);
- }
- status.SetStartTime(timeStart);
- status.SetEndTime(timeEnd);
- status.SetUsedTime(timeEnd - timeStart);
- status.SetStatus((OTS_MSR_SAMPLE_STATUS)Convert.ToInt32(strRstStatus));
- //get MsrResults data from map.
- List<CMsrResultItem> rstItms = new List<CMsrResultItem>();
- double allPartArea = 0;
- int typeNum;
-
- foreach (var typeParticles in mapTypeParticles)
- {
- typeNum = 0;
- double typeArea = 0;
- CMsrResultItem rstItm = new CMsrResultItem();
- foreach (var p in typeParticles.Value)
- {
- typeNum += 1;
- typeArea += p.GetActualArea();
- }
- rstItm.SetTypeId(typeParticles.Key);
- rstItm.SetNumber((uint)typeNum);
- rstItm.SetArea(Convert.ToDouble(typeArea.ToString("0.00")));
- rstItm.SetName(typeParticles.Value[0].GetTypeName());
- rstItms.Add(rstItm);
- allPartArea += typeArea;
- }
- rst.SetResultItems(rstItms);
- rst.SetMeasuredArea(Convert.ToUInt64(msrFldsArea * 1000000));
- rst.SetRatio(allPartArea / (msrFldsArea * 1000000));
- return true;
- //return false;
- }
- string ConvertFormatOfDateString(string Time)
- {
- string[] str1 = Time.Split(' ');
- string[] str2 = str1[0].Split('/');
- return str2[2] + "/" + str2[1] + "/" + str2[0] + " " + str1[1];
- }
- public string GetSampleWorkingFolder(string sampleName)
- {
- var pathname = FileHelper.GetFolderName(GetPathName());
- var samplePathName = pathname + "\\" + sampleName + "\\";
- return samplePathName;
- }
- public bool Save()
- {
- // Save or Save As, if strPathName is not empty, it is exist in the computer, this is a save action
- String strPathName = GetPathName();
- if (strPathName.CompareTo(UNTITLED_FILE_NAME) == 0)
- {
- // this is a new file
- // return save as result
- return SaveAs();
- }
- // is this a new file?
- strPathName.Trim();
- //保存测量项目文件 .prj
- XmlDocument doc = new XmlDocument();
- doc.Load(strPathName);
- doc.RemoveAll();
- //添加xml文件头申明
- XmlDeclaration xmldecl = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
- doc.AppendChild(xmldecl);
- XmlElement rootNode = doc.CreateElement("XMLData");
- doc.AppendChild(rootNode);
- Serialize(true, doc, rootNode);
- try
- {
- doc.Save(strPathName);
- }
- catch
- {
- return false;
- }
- // set file modify flag
- SetModify(false);
- // Ok, return TRUE
- return true;
- }
- public bool SaveAs()
- {
- // get file name
- String strPathName = "";
- // file open dialog
- SaveFileDialog saveFileDialog = new SaveFileDialog();
- saveFileDialog.FileName = m_strPathName.Split('\\')[m_strPathName.Split('\\').Length - 1];
- saveFileDialog.Filter = "Directory (*.*)|*.*";
- saveFileDialog.AddExtension = false;
- if (saveFileDialog.ShowDialog() != DialogResult.OK)
- {
- return false;
- }
- // get file pathname
- strPathName = saveFileDialog.FileName;
- string DirectoryName = Path.GetDirectoryName(strPathName);
- try
- {
- Directory.CreateDirectory(strPathName);
- }
- catch
- {
- MessageBox.Show("CreateDirectoryFailed!");
- return false;
- }
- strPathName += "\\" + Path.GetFileNameWithoutExtension(strPathName) + ".prj";
- //保存测量项目文件 .prj
- XmlDocument doc = new XmlDocument();
- //添加xml文件头申明
- XmlDeclaration xmldecl = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
- doc.AppendChild(xmldecl);
- XmlElement rootNode = doc.CreateElement("XMLData");
- doc.AppendChild(rootNode);
- Serialize(true, doc, rootNode);
- try
- {
- doc.Save(strPathName);
- }
- catch
- {
- return false;
- }
- // set file modify flag
- m_bModify = false;
- // Set project Path
- SetPathName(strPathName);
- // Ok, return TRUE
- return true;
- }
- // SEM stage data
- public CSEMStageData GetSEMStageData() { return m_pSEMStageData; }
- // SEM stage data
- public void SetSEMStageData(CSEMStageData a_pCSEMStageData)
- {
- m_pSEMStageData = a_pCSEMStageData;
- }
- // stage
- public CSampleHolder GetStageHolder() { return m_pStage; }
- public void SetStage(CSampleHolder a_pStage)
- {
- m_pStage = new CSampleHolder(a_pStage);
- }
- // samples list
- public List<COTSSample> GetSampleList() { return m_listSamples; }
- public COTSSample GetSampleByIndex(int a_nIndex)
- {
- // safe check
- if (a_nIndex < 0 || a_nIndex >= (int)m_listSamples.Count)
- {
- // invalid sample id
- return null;
- }
- // get the matching sample
- COTSSample pSample = m_listSamples[a_nIndex];
- // return the sample
- return pSample;
- }
- public COTSSample GetSampleByName(String a_strSampleName)
- {
- bool Isfind = false;
- COTSSample pOTSSample = null;
- for (int itr = 0; itr < m_listSamples.Count; itr++)
- {
- if (m_listSamples[itr].GetName() == a_strSampleName)
- {
- pOTSSample = m_listSamples[itr];
-
- Isfind = true;
- }
- }
- if (Isfind)
- {
- return pOTSSample;
- }
- return m_listSamples[0];
- }
- public void AddSample(COTSSample pSample)
- {
- // add the new sample into the samples list
- m_listSamples.Add(pSample);
- // set the project file modified.
- SetModify();
- // set the new as working sample
- m_nWorkingSampeIndex = (int)m_listSamples.Count - 1;
- }
- public bool DeleteSampleByIndex(int a_nIndex)
- {
- // check the index
- if (a_nIndex < 0 || a_nIndex >= (int)m_listSamples.Count)
- {
- // invalid input sample index
- return true;
- }
- // calculate new working sample index
- int nNewWorkingSampeIndex;
- if (a_nIndex < m_nWorkingSampeIndex)
- {
- nNewWorkingSampeIndex = m_nWorkingSampeIndex - 1;
- }
- else if (a_nIndex > m_nWorkingSampeIndex)
- {
- nNewWorkingSampeIndex = m_nWorkingSampeIndex;
- }
- else
- {
- // deleting working sample.
- if (a_nIndex == (int)m_listSamples.Count - 1)
- {
- // this is the last sample, select the above sample as working sample
- // if this is only sample in the list working sample index will be -1;
- nNewWorkingSampeIndex = m_nWorkingSampeIndex - 1;
- }
- else
- {
- // select next sample as working sample
- nNewWorkingSampeIndex = m_nWorkingSampeIndex;
- }
- }
- // delete the sample
- for (int i = m_listSamples.Count - 1; i >= 0; i--)
- {
- if (i == a_nIndex)
- {
- var sam = m_listSamples[i];
- sam.GetMsrStatus().ClearCompletedFieldsInfo();
- sam.GetMsrStatus().ClearCompletedFieldsInfo();
- sam.ClearFields();
- sam.GetMsrStatus().SetStatus(OTS_MSR_SAMPLE_STATUS.UNMEASURED);
- m_listSamples.Remove(m_listSamples[i]);
- break;
- }
- }
- // the file is modified.
- SetModify();
- // reset working sample index
- m_nWorkingSampeIndex = nNewWorkingSampeIndex;
- // ok, return TRUE
- return true;
- }
- public bool DeleteSampleByName(String a_strSampleName)
- {
- // check input sample name
- a_strSampleName.Trim();
- if (a_strSampleName == "")
- {
- // input sample name is empty
- return false;
- }
- // go through sample list
- int nIndex = 0;
- 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 (strSampleName.CompareTo(a_strSampleName) == 0)
- {
- // find the sample, return deleting result
- return DeleteSampleByIndex(nIndex);
- }
- ++nIndex;
- }
- // can't find the sample in the samples list, return FALSE
- return false;
- }
- public COTSSample GetWorkingSample()
- {
- return GetSampleByIndex(m_nWorkingSampeIndex);
- }
- public bool SetWorkingSampleByIndex(int a_nIndex)
- {
- // special treatment
- if (a_nIndex == -1 && m_listSamples.Count == 0)
- {
- m_nWorkingSampeIndex = -1;
- return true;
- }
- // check if the working sample index
- if (0 > a_nIndex || a_nIndex >= (int)m_listSamples.Count)
- {
- // invalid sample index
- return false;
- }
- m_nWorkingSampeIndex = a_nIndex;
- return true;
- }
- public bool SetWorkingSampleByName(String a_pSampleName)
- {
- // check input sample name
- a_pSampleName.Trim();
- if (a_pSampleName == "")
- {
- // input sample name is empty
- return false;
- }
- // go through sample list
- int nIndex = 0;
- 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 (strSampleName.CompareTo(a_pSampleName) == 0)
- {
- // find the sample, return deleting result
- return SetWorkingSampleByIndex(nIndex);
- }
- ++nIndex;
- }
- // failed to find the named sample return FALSE
- return false;
- }
-
- // get modify flag
- public bool IsModified() { return m_bModify; }
- // file name
- public String GetFileName()
- {
- // make a copy of file path name
- String strPathName = m_strPathName;
- // is this a new file?
- if (strPathName.CompareTo(UNTITLED_FILE_NAME) == 0)
- {
- return strPathName;
- }
- // get file name
- String strFileName = GetFileNameWithoutExtension(strPathName);
- // return file name
- return strFileName;
- }
- // get file name without extension
- public String GetFileNameWithoutExtension(String a_strPathName)
- {
- string str = "";
- str = Path.GetFileNameWithoutExtension(a_strPathName);
- return str;
- }
- // if the new sample name can be used.
- public bool IsValidSampleName(String a_sName)
- {
- foreach (var pSample in m_listSamples)
- {
- String sSampleName = pSample.GetName();
- if (a_sName.Equals(sSampleName))
- {
- return false;
- }
- }
- return true;
- }
- static String FindFile(String filename, String path)
- {
- if (Directory.Exists(path))
- {
- if (File.Exists(path + filename))
- return path + filename;
- String[] directorys = Directory.GetDirectories(path);
- foreach (String d in directorys)
- {
- String p = FindFile(filename, d);
- if (p != null)
- return p;
- }
- }
- return null;
- }
- // calculate measurement area
- public CDomain CalculateMsrArea(CHole a_pHole)
- {
- CDomain pMsrArea = new CDomain(a_pHole.GetShape(), a_pHole.GetDomainRect());
-
- // measurement area should smaller than the sample hole
- RectangleF rectMsrArea = pMsrArea.GetDomainRect();
- float nWidth = rectMsrArea.Width;
- float nHeight = rectMsrArea.Height;
- float nDeflateX = CalculateDeflateValue(nWidth);
- float nDeflateY = CalculateDeflateValue(nHeight);
- rectMsrArea.Offset(nDeflateX, nDeflateY);
- pMsrArea.SetDomainRect(rectMsrArea);
- // return measurement area
- return pMsrArea;
- }
- // calculate deflate value
- public float CalculateDeflateValue(float a_nWitchOrHeight)
- {
- const long LENGTH_THRESHOLD = 150000;
- const long LENGTH_THRESHOLD_MIN = 10000;
- const int EDGE = 1000;
- const int EDGE_MIN = 500;
- // deflate 1000 if width or height is greater than 15000
- if (a_nWitchOrHeight >= LENGTH_THRESHOLD)
- {
- return EDGE;
- }
- // deflate 500 if width or height is greater than 15000
- else if (a_nWitchOrHeight >= LENGTH_THRESHOLD_MIN)
- {
- return EDGE_MIN;
- }
- // otherwise, no deflate
- return 0;
- }
- //合并后新添加的需要的方法
- public void SetGenParam(COTSCommonParam GenParam) { m_CommonParam = GenParam; }
- public COTSCommonParam GetGenParam() { return m_CommonParam; }
- public bool Reclassify(bool IgnoreUserModify)
- {
- string strFilePath = FileHelper.GetFolderName(m_strPathName);
- if (strFilePath == null)
- {
- return false;
- }
- foreach (var spl in m_listSamples)
- {
- //get the parameter MsrParam object
- CSampleParam pMsrParam = spl.GetMsrParams();
- string stdFileName = pMsrParam.GetSTDName();
- if (!stdFileName.Contains(".db"))
- {
- stdFileName += ".db";
- }
- string filename = strFilePath + "\\" + spl.GetName() + "\\" + spl.GetName() + ".rst";
- XmlDocument doc = new XmlDocument();
- doc.Load(filename);
- XmlNode root = doc.SelectSingleNode("XMLData");
- var members = root.SelectNodes("Member");
- foreach (XmlNode member1 in members)
- {
- if (member1.Attributes["RegName"].Value == "Sample")
- {
- var paramNode = member1.SelectNodes("Member");
- foreach (XmlNode member2 in paramNode)
- {
- if (member2.Attributes["RegName"].Value == "MsrParams")
- {
- ((XmlElement)member2).SetAttribute("STDName", stdFileName);
- }
- }
- }
- }
- doc.Save(filename);//save the new std db name
- foreach (var fld in spl.GetFieldsData())
- {
-
- if (IgnoreUserModify)
- {
- foreach (var part in fld.GetListAnalysisParticles())
- {
- if (part.GetClassifyId() < USR_MODIFY_CLASSIFYID_BASE)
- {
- part.SetType((int)OTS_PARTICLE_TYPE.NOT_IDENTIFIED);
- part.SetClassifyId((int)OTS_PARTICLE_TYPE.NOT_IDENTIFIED);
- part.SetTypeName("Not Identified");
- part.SetTypeColor("#000000");
- }
-
- }
- }
- else
- {
- foreach (var part in fld.GetListAnalysisParticles())
- {
- part.SetType((int)OTS_PARTICLE_TYPE.NOT_IDENTIFIED);
- part.SetClassifyId((int)OTS_PARTICLE_TYPE.NOT_IDENTIFIED);
- part.SetTypeName("Not Identified");
- part.SetTypeColor("#000000");
- }
- }
-
- }
- var analysisparts = new List<COTSParticleClr>();
- var m_classifyEngine = new CClassifyEngine();
- if (SystemTypeId == OTS_SysType_ID.IncA|| SystemTypeId == OTS_SysType_ID.SteelMineral)
- {
- //get the steel technology parameter
- STEEL_TECHNOLOGY steelTech = pMsrParam.GetSteelTechnology();
- if (spl.GetMsrParams().GetEngineType() == OTS_CLASSIFY_ENGINE_TYPE.InclutionPlusExpressionParse)
- {
- if (stdFileName != "NoSTDDB.db")
- {
- foreach (var fld in spl.GetFieldsData())
- {
- foreach (var part in fld.GetListAnalysisParticles())
- {
- IClassifyEngine partEngine = m_classifyEngine.GetExpressionClassifyEngine(stdFileName);
- if (IsLowCounts(part))
- {
- continue;
- }
- if (!partEngine.ClassifyByExpression(part))
- {
- NLog.LogManager.GetCurrentClassLogger().Error("1 failed to classify!" + "Particle Engine");
- }
- if (part.GetType() == (int)OTS_PARTICLE_TYPE.NOT_IDENTIFIED)
- {
- IClassifyEngine incAEngine = m_classifyEngine.GetIncClassifyEngine();
- if (!incAEngine.ClassifyIncA(part, (int)steelTech))
- {
- NLog.LogManager.GetCurrentClassLogger().Error("2 failed to classify!" + "IncA Engine");
- }
- }
- }
- analysisparts.AddRange(fld.GetListAnalysisParticles());
- }
- }
- }
- else if (spl.GetMsrParams().GetEngineType() == OTS_CLASSIFY_ENGINE_TYPE.ExpressionParse)
- {
- if (stdFileName != "NoSTDDB.db")
- {
- foreach (var fld in spl.GetFieldsData())
- {
- foreach (var part in fld.GetListAnalysisParticles())
- {
- if (IsLowCounts(part))
- {
- continue;
- }
- IClassifyEngine engine = m_classifyEngine.GetExpressionClassifyEngine(stdFileName);
- if (!engine.ClassifyByExpression(part))
- {
- NLog.LogManager.GetCurrentClassLogger().Error("3 failed to classify!" + "Particle Engine");
- }
- }
- analysisparts.AddRange(fld.GetListAnalysisParticles());
- }
- }
- }
- else if (spl.GetMsrParams().GetEngineType() == OTS_CLASSIFY_ENGINE_TYPE.InclustionEngine)
- {
- foreach (var fld in spl.GetFieldsData())
- {
- foreach (var part in fld.GetListAnalysisParticles())
- {
- if (IsLowCounts(part))
- {
- continue;
- }
- IClassifyEngine incAEngine = m_classifyEngine.GetIncClassifyEngine();
- if (!incAEngine.ClassifyIncA(part, (int)steelTech))
- {
- NLog.LogManager.GetCurrentClassLogger().Error("2 failed to classify!" + "IncA Engine");
- }
- }
- analysisparts.AddRange(fld.GetListAnalysisParticles());
- }
- }
- else if (spl.GetMsrParams().GetEngineType() == OTS_CLASSIFY_ENGINE_TYPE.SpectrumMatch)
- {
- foreach (var fld in spl.GetFieldsData())
- {
- foreach (var part in fld.GetListAnalysisParticles())
- {
- if (IsLowCounts(part))
- {
- continue;
- }
- IClassifyEngine spectrumEng = m_classifyEngine.GetSpectrumCompareEngine(stdFileName);
- if (!spectrumEng.ClassifyBySpectrum(part))
- {
- NLog.LogManager.GetCurrentClassLogger().Error("2 failed to classify!" + "IncA Engine");
- }
- }
- analysisparts.AddRange(fld.GetListAnalysisParticles());
- }
- }
- }
- else if (SystemTypeId == OTS_SysType_ID.TCCleannessA|| SystemTypeId == OTS_SysType_ID.BatteryCleannessA)
- {
- if (stdFileName != "NoSTDDB.db")
- {
- foreach (var fld in spl.GetFieldsData())
- {
- foreach (var part in fld.GetListAnalysisParticles())
- {
- if (IsLowCounts(part))
- {
- continue;
- }
- IClassifyEngine engine = m_classifyEngine.GetExpressionClassifyEngine(stdFileName);
- if (!engine.ClassifyByExpression(part))
- {
- NLog.LogManager.GetCurrentClassLogger().Error("3 failed to classify!" + "Particle Engine");
- }
- }
- analysisparts.AddRange(fld.GetListAnalysisParticles());
- }
- }
- }
- string strFieldFileSubFolder = strFilePath + "\\" + spl.GetName() + "\\" + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER;
- string strIncAFilename = strFieldFileSubFolder + "\\" + SMPL_MSR_RESULT_INCLUSION_FILE;
- CIncAFileMgr pIncAFileMgr = new CIncAFileMgr(strIncAFilename);
- pIncAFileMgr.UpdateParticleList(analysisparts);
- if (stdFileName.ToLower() != "nostddb.db")
- {
- try
- {
- string userdBpath = Application.StartupPath + "\\Config\\SysData\\" + stdFileName;
- File.Copy(userdBpath, strFilePath + "\\" + spl.GetName() + "\\" + stdFileName, true);
- }
- catch (Exception ex)
- {
- MessageBox.Show(stdFileName + " copy failed:" + ex.ToString());
- return false;
- }
- }
- }
- return true;
- }
- private bool IsLowCounts(COTSParticleClr particle)
- {
- COTSXRayParam pXRayParam = this.GetWorkingSample().GetMsrParams().GetXRayParam();
- if (pXRayParam.GetUsingXray() == true)
- {
- var thecount = particle.GetXray().GetTotalCount();
- var expect = pXRayParam.GetAnalyExpCount();
- if (thecount < expect)
- {
- particle.SetType((int)OTS_PARTICLE_TYPE.LOW_COUNT);//4 represent "lowcount"
- particle.SetClassifyId((int)OTS_PARTICLE_TYPE.LOW_COUNT);//4 represent "lowcount"
- particle.SetTypeColor("#000000");
- particle.SetTypeName("LowCounts");
- return true;
- }
- }
- return false;
- }
- public void DeleteWorkingSampleFieldDataByFieldNo(int fieldNo)
- {
- string strFilePath = FileHelper.GetFolderName(m_strPathName);
- string strFieldFileSubFolder = strFilePath + "\\" + GetWorkingSample().GetName() + "\\" + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER;
- string strIncAFilename = strFieldFileSubFolder + "\\" + SMPL_MSR_RESULT_INCLUSION_FILE;
- CIncAFileMgr pIncAFileMgr = new CIncAFileMgr(strIncAFilename);
- var fldDB = pIncAFileMgr.GetFieldDB();
- var incADataDb = pIncAFileMgr.GetIncADB();
- var segmentDb = pIncAFileMgr.GetSegmentDB();
- var posxrayinfodb = pIncAFileMgr.GetPosXrayDBMgr().GetXrayInfoDB();
- var posxraydatadb = pIncAFileMgr.GetPosXrayDBMgr().GetXrayDataDB();
- var elechemistrydb = pIncAFileMgr.GetPosXrayDBMgr().GetElementChemistryDB();
- fldDB.DeleteDataByFieldNo (fieldNo);
- incADataDb.DeleteDataByFieldNo(fieldNo);
- segmentDb.DeleteDataByFieldNo(fieldNo);
- posxrayinfodb.DeleteDataByFieldNo(fieldNo);
- posxraydatadb.DeleteDataByFieldNo(fieldNo);
- elechemistrydb.DeleteDataByFieldNo(fieldNo);
- }
- /// <summary>
- /// 设置样品中对象属性 赋值
- /// </summary>
- /// <param name="pSample"></param>
- /// <param name="poMsrParams"></param>
- /// <returns></returns>
- void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
- {
- // copy data over
- if (m_pSEMStageData == null)
- {
- m_pSEMStageData = new CSEMStageData();
- }
- if (m_pStage == null)
- {
- m_pStage = new CSampleHolder();
- }
- xInt xProjMgrFileMark = new xInt();
- xString xProjMgrFileVersion = new xString();
- xString xstrPathName = new xString();
- xString xSystype = new xString();
- //Collection<CHoleBSEImg> xholeBSEImgs = new Collection<CHoleBSEImg>();
- Collection<COTSSample> xsamples = new Collection<COTSSample>();
- Slo slo = new Slo();
- slo.Register("ProjMgrFileMark", xProjMgrFileMark);
- slo.Register("ProjMgrFileVersion", xProjMgrFileVersion);
- slo.Register("strPathName", xstrPathName);
- slo.Register("SysType", xSystype);
- slo.Register("SEMStageData", m_pSEMStageData);
- slo.Register("Stage", m_pStage);
- //slo.Register("HoleBSEImg", xholeBSEImgs);
- slo.Register("Samples", xsamples);
- if (isStoring)
- {
- xProjMgrFileMark.AssignValue(0);
- xProjMgrFileVersion.AssignValue("");
- xSystype.AssignValue(systemTypeId.ToString());
- xstrPathName.AssignValue(m_strPathName);
- //xholeBSEImgs.Clear();
- xsamples.Clear();
- foreach (var sample in m_listSamples)
- {
- xsamples.addItem(sample);
- }
- slo.Serialize(true, classDoc, rootNode);
- }
- else
- {
- slo.Serialize(false, classDoc, rootNode);
- m_strPathName = xstrPathName.value();
- //m_listHoleBSEImg.Clear();
- m_listSamples.Clear();
- for (int i = 0; i < (int)xsamples.size(); i++)
- {
- m_listSamples.Add(xsamples.getItem(i));
- }
- if (xSystype.value() == "IncA")
- {
- systemTypeId = otsdataconst.OTS_SysType_ID.IncA;
- }
- else if(xSystype.value() == "TCCleannessA")
- {
- systemTypeId = otsdataconst.OTS_SysType_ID.TCCleannessA;
- }
- else if (xSystype.value() == "BatteryCleannessA")
- {
- systemTypeId = otsdataconst.OTS_SysType_ID.BatteryCleannessA;
- }
- else if (xSystype.value() == "SteelMineral")
- {
- systemTypeId = otsdataconst.OTS_SysType_ID.SteelMineral;
- }
- }
- }
- }
- }
|