123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692 |
- using OTSDataType;
- using OTSModelSharp.ServiceInterface;
- using OTSModelSharp.DTLBase;
- using OTSModelSharp.ImageProcess;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Forms;
- using static OTSDataType.otsdataconst;
- using System.Xml;
- using OTSCLRINTERFACE;
- using OTSModelSharp.ServiceCenter;
- using System.Data;
- namespace OTSModelSharp
- {
- public class COTSMsrPrjResultData
- {
- // SEM stage data
- CSEMStageData m_pSEMStageData;
- //// stage
- CStage m_pStage;
- // general parameter
- COTSGeneralParam m_GenParam;
- // sample list
- List<COTSSample> m_listSamples = new List<COTSSample>();
- List<CHoleBSEImg> m_listHoleBSEImg = new List<CHoleBSEImg>();
- 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.
- public otsdataconst.OTS_SysType_ID m_nPackId;
- public COTSMsrPrjResultData()
- {
- Init();
- }
- // initialization
- public void Init()
- {
- m_listSamples.Clear();
- m_listHoleBSEImg.Clear();
- m_bModify = false;
- m_strPathName = "";
- m_nWorkingSampeIndex = -1;
- }
- // duplication
- public void Duplicate(COTSMsrPrjResultData a_oSource)
- {
- // initialization
- Init();
- // copy data over
- m_pSEMStageData = new CSEMStageData(a_oSource.m_pSEMStageData);
- m_pStage = new CStage(a_oSource.m_pStage);
- foreach (var pHoleBSEImg in a_oSource.m_listHoleBSEImg)
- {
- CHoleBSEImg pHoleBSEImgNew = (new CHoleBSEImg(pHoleBSEImg));
- m_listHoleBSEImg.Add(pHoleBSEImgNew);
- }
- foreach (var pSample in a_oSource.m_listSamples)
- {
- COTSSample pSampleNew = new COTSSample();
- m_listSamples.Add(pSampleNew);
- }
- m_bModify = a_oSource.m_bModify;
- m_strPathName = a_oSource.m_strPathName;
- m_nWorkingSampeIndex = a_oSource.m_nWorkingSampeIndex;
- }
- 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);
- //设置测量项目文件路径
- m_strPathName = strPathName;
- //-------------
- foreach (var smpl in m_listSamples)
- {
- // get path of the pathname
- String strFilePath = GetFolderName(strPathName);
- if (strFilePath == "")
- {
- // file path string is an empty string
- return false;
- }
- // field file sub folder string
- String strFieldFileSubFolder = strFilePath + "\\" + smpl.GetName() + "\\" + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + "\\";
- // check if the field file sub folder exists
- if (!DirectoryExists(strFieldFileSubFolder))
- {// field files folder doesn't exist
- continue;
- }
- String strIncAFilename = strFieldFileSubFolder + "\\" + SMPL_MSR_RESULT_INCLUSION_FILE;
- //CIncAFileMgr pIncAFileMgr = new CIncAFileMgr(strIncAFilename);
- List<COTSFieldData> allMeasuredFlds = new List<COTSFieldData>();
- CMsrSampleStatus poMsrStatus = new CMsrSampleStatus();
-
- CMsrDisplayResults poMsrResults = smpl.GetMsrResults();
- double aFldArea = smpl.CalculateAFieldArea();
- SetPathName(strIncAFilename);
- int w, h;
- smpl.GetBSESize(out w, out h);
- double pixelsize = smpl.CalculatePixelSize();
- if (GetAllFieldsFromDB(ref allMeasuredFlds,ref poMsrStatus, poMsrResults, aFldArea,new Size(w,h),pixelsize))
- {
-
-
- var nodataFields = smpl.GetFieldsData();//there's only the field postion info in the xml file,so the initial filed has only postion info.
- List<COTSFieldData> allflddata = new List<COTSFieldData>() ;//contains all the field
- //------------complete the infomation that doesn't contained in database-----
-
- foreach (var f in allMeasuredFlds)
- {
- f.SetPixelSize(pixelsize);
- f.Width = w;
- f.Height = h;
- f.SetIsMeasureComplete(true);
- }
- //------------------------------
- foreach (var emptyfld in nodataFields)
- {
- bool isMeasured = false;
- foreach (var measuredField in allMeasuredFlds)
- {
- if (measuredField.PositionEquals(emptyfld))
- {
-
- allflddata.Add(measuredField);
- isMeasured = true;
- break;
- }
-
- }
- if (!isMeasured)
- {
- allflddata.Add(emptyfld);
- }
- }
- smpl.SetFieldsData(allflddata);
- // file validation
- smpl.SetMsrStatus(poMsrStatus);
- smpl.SetMsrResults(poMsrResults);
-
- // set pathname
- SetPathName(strPathName);
- // set working sample
- if (m_listSamples.Count > 0)
- {
- m_nWorkingSampeIndex = 0;
- }
- else
- {
- m_nWorkingSampeIndex = -1;
- }
- }
- else
- {
- return false;
- }
- }
- if (m_listSamples != null)
- {
- 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<COTSFieldData> allFlds, ref CMsrSampleStatus status, CMsrDisplayResults rst, double aFieldArea,Size picSize,double pixelSize)
- {
- String sDatabaseName = m_strPathName;
- if (!FileExists(sDatabaseName))
- {
- return false;
- }
- List<System.Drawing.PointF> completedFldPositions = new List<System.Drawing.PointF>();
- CIncAFileMgr incAFileMgr = new CIncAFileMgr(sDatabaseName);
- var m_IncADataDB = incAFileMgr.GetIncADB();
- List<COTSFieldData> allFldsWithdata=new List<COTSFieldData>();
- m_IncADataDB.GetAllFieldsRecord(ref allFldsWithdata);
- foreach (var f in allFldsWithdata)
- {
- f.Width = picSize.Width;
- f.Height = picSize.Height;
- f.SetPixelSize(pixelSize);
-
- }
- 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 = new List<COTSSegmentClr>();
- 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.GetTagId().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 empty)
- foreach (var p in completedFldPositions)
- {
- bool haveData=false;
- var emptyFld = new COTSFieldData();
- emptyFld.SetOTSPosition(p);
- 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 = 0;
- double typeArea = 0;
- foreach (var typeParticles in mapTypeParticles)
- {
- 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((uint)typeArea);
- 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 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 = "Probject Files (*.prj)|*.prj|All files (*.*)|*.*";
- if (saveFileDialog.ShowDialog() != DialogResult.OK)
- {
- return false;
- }
- // get file pathname
- strPathName = saveFileDialog.FileName;
- string DirectoryName = Path.GetDirectoryName(strPathName);
- DirectoryInfo Folder = new DirectoryInfo(DirectoryName);
- List<string> FolderNames = new List<string>();
- if (Folder.GetDirectories().Length != 0)
- {
- MessageBox.Show("Save failed, a folder exists in the current location, delete or create a new one!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- //保存测量项目文件 .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 CStage GetStage() { return m_pStage; }
- public void SetStage(CStage a_pStage)
- {
- m_pStage = new CStage(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];
- //m_listSamples.RemoveAt(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;
- // return the new sample
- }
- // get new sample name
- 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 ChangeParamFromList(int iNamePos)
- {
- throw new NotImplementedException();
- }
- public bool GetParamFileList(ref int iNamePos, ref List<string> mParamFileNameList)
- {
- throw new NotImplementedException();
- }
- 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 bool ResetSamplesListOrder(List<String> a_listSampleNames)
- {
- // no sample in the samples list; shouldn't be here
- if (m_listSamples.Count == 0)
- {
- return false;
- }
- // make sure that input sample names list size is same with the samples list
- if (m_listSamples.Count != a_listSampleNames.Count)
- {
- return false;
- }
- // new sample list
- List<COTSSample> listSamples = new List<COTSSample>();
- // go through the sample names list
- foreach (var strSampleName in a_listSampleNames)
- {
- bool IsChanged = false;
- for (int itr = 0; itr < m_listSamples.Count; itr++)
- {
- if (m_listSamples[itr].GetName() == strSampleName)
- {
- COTSSample pElementChemistry = m_listSamples[itr];
- IsChanged = true;
- }
- }
- if (!IsChanged)
- {
- return false;
- }
- }
- // reset the samples list
- m_listSamples.Clear();
- foreach (var pSample in listSamples)
- {
- m_listSamples.Add(pSample);
- }
- // set modify flag
- SetModify();
- // Ok, return TRUE
- return true;
- }
- public bool InsrtSample(COTSSample a_pSample, int a_nIndex)
- {
- // input check
- if (a_pSample != null)
- {
- // invalid input sample pointer
- return false;
- }
- if (m_listSamples.Count == 0 || a_nIndex >= (int)m_listSamples.Count)
- {
- m_listSamples.Add(a_pSample);
- }
- else if (a_nIndex <= 0)
- {
- m_listSamples.Insert(Convert.ToInt32(m_listSamples[a_nIndex]), a_pSample);
- }
- else
- {
- m_listSamples.Insert(Convert.ToInt32(m_listSamples[a_nIndex]) + a_nIndex, a_pSample);
- }
- // Ok, return TRUE
- return true;
- }
- public bool ChangeSamplePosition(int a_nIndexFrom, int a_nIndexTo)
- {
- // make sure both index are valid
- if (a_nIndexFrom < 0 || a_nIndexFrom >= (int)m_listSamples.Count)
- {
- // invalid from index
- return false;
- }
- if (a_nIndexTo < 0 || a_nIndexTo >= (int)m_listSamples.Count)
- {
- // invalid to index
- return false;
- }
- // need to do nothing if the two indexes are the same
- if (a_nIndexFrom != a_nIndexTo)
- {
- // move to last?
- bool bLast = (a_nIndexTo == ((int)m_listSamples.Count - 1));
- // get the sample
- COTSSample pSample = m_listSamples[a_nIndexFrom];
- // remove it from the samples list
- m_listSamples.Remove(pSample);
- // put the sample back in
- if (bLast)
- {
- m_listSamples.Add(pSample);
- }
- else
- {
- m_listSamples.Insert(Convert.ToInt32(m_listSamples[a_nIndexTo]) + a_nIndexTo, pSample);
- }
- }
- // Ok, return TRUE
- return true;
- }
- public bool MoveSamplePosition(COTSSample a_pTargetSample, COTSSample a_RefpSample, bool a_bBefore /*= TRUE*/)
- {
- // check input
- if (a_pTargetSample != null)
- {
- // invalid input target sample pointer
- return false;
- }
- if (a_RefpSample != null)
- {
- // invalid input ref sample pointer
- return false;
- }
- bool IsChanged = false;
- for (int itr = 0; itr < m_listSamples.Count; itr++)
- {
- if (m_listSamples[itr].GetName() == a_pTargetSample.GetName())
- {
- COTSSample pElementChemistry = m_listSamples[itr];
- // m_listSamples.RemoveAt(itr);
- IsChanged = true;
- }
- }
- if (!IsChanged)
- {
- return false;
- }
- for (int itr = 0; itr < m_listSamples.Count; itr++)
- {
- if (m_listSamples[itr].GetName() == a_RefpSample.GetName())
- {
- COTSSample pElementChemistry = m_listSamples[itr];
- //m_listSamples.RemoveAt(itr);
- IsChanged = true;
- }
- }
- if (!IsChanged)
- {
- return false;
- }
- // remove the sample from the samples list
- for (int itr = 0; itr < m_listSamples.Count; itr++)
- {
- if (m_listSamples[itr].GetName() == a_RefpSample.GetName())
- {
- COTSSample pElementChemistry = m_listSamples[itr];
- //m_listSamples.RemoveAt(itr);
- IsChanged = true;
- }
- }
- if (!IsChanged)
- {
- return false;
- }
- // put the sample back in
- if (a_bBefore)
- {
- m_listSamples.Insert(0, a_pTargetSample);
- }
- else
- {
- m_listSamples.Insert(1, a_pTargetSample);
- }
- // Ok, return TRUE
- return true;
- }
- public bool MoveSamplePosition(String a_strTargetSampleName, String a_strRefSampleName, bool a_bBefore /*= TRUE*/)
- {
- // input check
- a_strTargetSampleName.Trim();
- if (a_strTargetSampleName == "")
- {
- // input target sample is an empty string
- return false;
- }
- a_strRefSampleName.Trim();
- if (a_strRefSampleName == "")
- {
- // input ref sample is an empty string
- return false;
- }
- bool IsChanged = false;
- for (int itr = 0; itr < m_listSamples.Count; itr++)
- {
- if (m_listSamples[itr].GetName() == a_strTargetSampleName)
- {
- COTSSample pElementChemistry = m_listSamples[itr];
- IsChanged = true;
- }
- }
- if (!IsChanged)
- {
- return false;
- }
- COTSSample pTargetSample = m_listSamples[0];
- for (int itr = 0; itr < m_listSamples.Count; itr++)
- {
- if (m_listSamples[itr].GetName() == a_strTargetSampleName)
- {
- COTSSample pElementChemistry = m_listSamples[itr];
- IsChanged = true;
- }
- }
- if (!IsChanged)
- {
- return false;
- }
- COTSSample pRefSample = pTargetSample;
- // need to do nothing if the two name are same
- if (a_strTargetSampleName.CompareTo(a_strRefSampleName) != 0)
- {
- return MoveSamplePosition(pTargetSample, pRefSample, a_bBefore);
- }
- // Ok, return TRUE
- return true;
- }
- public COTSSample GetWorkingSample()
- {
-
- return GetSampleByIndex(m_nWorkingSampeIndex);
- }
- int GetWorkingSampleIndex() { return m_nWorkingSampeIndex; }
- void SetWorkingSampleIndex(int a_nWorkingSampleIndex) { m_nWorkingSampeIndex = a_nWorkingSampleIndex; }
- 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
- // failed to find the named sample return FALSE
- return false;
- }
- public bool DeleteWorkingSample()
- {
- // check if the working sample index
- if (m_nWorkingSampeIndex < 0 || m_nWorkingSampeIndex >= (int)m_listSamples.Count)
- {
- // invalid working sample index
- return false;
- }
- // return the result of DeleteSampleByIndex
- return DeleteSampleByIndex(m_nWorkingSampeIndex);
- }
- // Sample hole BSE image list
- public List<CHoleBSEImg> GetHoleBESImgList() { return m_listHoleBSEImg; }
- // hole BSE images list
- public void SetHoleBESImgList(List<CHoleBSEImg> a_listHoleBSEImg, bool a_bClear/* = TRUE*/)
- {
- // clear the hole BSE image list if necessary
- if (a_bClear)
- {
- m_listHoleBSEImg.Clear();
- }
- m_listHoleBSEImg = a_listHoleBSEImg;
- //if (m_nWorkingSampeIndex != -1)
- //{
- // COTSSample pSample = GetWorkingSample();
- //}
- }
- // 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)
- {
- int nindex = -1;
- foreach (var pSample in m_listSamples)
- {
- nindex++;
- String sSampleName = pSample.GetName();
- if (a_sName.CompareTo(sSampleName) != 0)
- {
- if (nindex != m_nWorkingSampeIndex)
- {
- return false;
- }
- }
- }
- return true;
- }
- // get std file list, a_nPos = -1, current do not use any STD lib, a_nPos = 0, current use STD lib.
- public bool GetSTDFileList(ref int a_nPos, ref List<String> a_listSTDLibName)
- {
- String a_strFolderName = m_GenParam.GetPartSTDLibFolderName();
- if (a_strFolderName == "")
- {
- return false;
- }
- // lib name list
- a_listSTDLibName.Clear();
- // file list
- List<String> listSTDFile = new List<string>();
- listSTDFile.Clear();
- const String STD_LIB_EXT = ".db";
- // get file list
- if (!GetFileNameList(a_strFolderName, STD_LIB_EXT, listSTDFile))
- {
- return false;
- }
- foreach (var file in listSTDFile)
- {
- //string fileName = file.Left(file.GetLength() - 3);
- String fileName = file;
- a_listSTDLibName.Add(fileName);
- }
- if (a_listSTDLibName.Count > -1)
- {
- string m_NoSTDDB = "NoSTDDB";
- a_listSTDLibName.Add(m_NoSTDDB);
- }
- //before the use choose one STD, always should be null.
- a_nPos = -1;
- String sCurrentSTD;
- CSampleParam pCurrentParam;
- COTSSample pSample = GetWorkingSample();
- if (pSample == null)
- {
- }
- else
- {
- pCurrentParam = pSample.GetMsrParams();
- if (pCurrentParam == null)
- {
- }
- //将当前使用的数据库的名字与下拉菜单的名字对应起来
- sCurrentSTD = pCurrentParam.GetSTDName();
- for (int i = 0; i < (int)a_listSTDLibName.Count; i++)
- {
- a_nPos++;
- if (a_listSTDLibName[i].CompareTo(sCurrentSTD) == 0)
- break;
- }
- }
- return true;
- }
- // get file name list in a folder
- public bool GetFileNameList(String a_strFolderName, String a_strFileType, List<String> a_listFileName)
- {
- try
- {
- //find first file
- //int FindFileData = 0;
- // int file = FindFirstFile(a_strFolderName, FindFileData);
- string path = a_strFolderName;
- List<string> lineStringList = new List<string>();//存储所有读取到的文件
- DirectoryInfo[] dateDirArr = new DirectoryInfo(path).GetDirectories(); //取指定路径下的所有目录
- string[] dir = Directory.GetDirectories(path); //文件夹列表
- DirectoryInfo fdir = new DirectoryInfo(path);
- FileInfo[] files = fdir.GetFiles();
- foreach (FileInfo file in files)
- {
- string extensionName = Path.GetExtension(file.FullName);
- if (extensionName == a_strFileType)
- {
- string FileNameWithoutExtension = Path.GetFileNameWithoutExtension(file.FullName);
- a_listFileName.Add(FileNameWithoutExtension);
- }
- }
- #region 原方法
- //foreach (DirectoryInfo directoryInfo in dateDirArr)
- //{
- // string fullName = directoryInfo.FullName + a_strFileType;
- // if (!File.Exists(fullName))
- // {
- // continue;//目录下不存在此文件,返回。
- // }
- // FileInfo file = new FileInfo(fullName);
- // StreamReader reader = new StreamReader(file.FullName);
- // while (!reader.EndOfStream)//判断是否读取完成
- // {
- // lineStringList.Add(reader.ReadLine());
- // }
- // reader.Close();
- //}
- //int INVALID_HANDLE_VALUE = 0;
- ////find other file
- //if (FindFileData != INVALID_HANDLE_VALUE)
- //{
- // a_listFileName.Add(FindFileData.ToString());
- // bool bState = false;
- // FindFile(a_strFolderName, FindFileData.ToString());
- // while (bState)
- // {
- // a_listFileName.Add(FindFileData.ToString());
- // FindFile(a_strFolderName, FindFileData.ToString());
- // }
- //}
- #endregion
- }
- catch (Exception pe)
- {
- 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;
- }
- //// change STD
- public bool ChangeSTDFromList(int a_nPos)
- {
- String a_strFolderName = m_GenParam.GetPartSTDLibFolderName();
- if (a_strFolderName == "")
- {
- return false;
- }
- // file list
- List<String> listSTDFile = new List<string>();
- listSTDFile.Clear();
- const String STD_LIB_EXT = ".db";
- // get file list
- if (!GetFileNameList(a_strFolderName, STD_LIB_EXT, listSTDFile))
- {
- return false;
- }
- List<String> listSTDLibName = new List<string>();
- listSTDLibName.Clear();
- foreach (var file in listSTDFile)
- {
- //string fileName = file.Left(file.GetLength() - 3);
- String fileName = file;
- listSTDLibName.Add(fileName);
- }
- if (listSTDLibName.Count > 0)
- {
- listSTDLibName.Add("NoSTDDB");
- }
- if (a_nPos > (int)listSTDLibName.Count)
- {
- return false;
- }
- String STDName = listSTDLibName[a_nPos];
- // updata STD to working sample
- COTSSample pSample = GetWorkingSample();
- CSampleParam pParam = pSample.GetMsrParams();
- pParam.SetSTDName(STDName);
- pSample.SetMsrParams(pParam);
- return true;
- }
- // get measured sample list
- public bool GetMsredSampleList(ref List<COTSSample> a_listMsredSample)
- {
- a_listMsredSample.Clear();
- foreach (var pSample in m_listSamples)
- {
- if (pSample.GetMsrResults() == new CMsrDisplayResults())
- {
- continue;
- }
- else
- {
- a_listMsredSample.Add(pSample);//the reference count will increament automatically.
- }
- }
- return true;
- }
- // calculate measurement area
- public CDomain CalculateMsrArea(CHole a_pHole)
- {
- CDomain pMsrArea = new CDomain(a_pHole.GetShape(), a_pHole.GetDomainRect());
- // create measurement area
- // reset measurement area
- // 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(COTSGeneralParam GenParam) { m_GenParam = GenParam; }
- public COTSGeneralParam GetGenParam() { return m_GenParam; }
- public bool Reclassify()
- {
- 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);
- //get the steel technology parameter
- STEEL_TECHNOLOGY steelTech = pMsrParam.GetSteelTechnology();
- foreach (var fld in spl.GetFieldsData())
- {
- foreach (var part in fld.GetListAnalysisParticles())
- {
- part.SetType((int)OTS_PARTCLE_TYPE.NOT_IDENTIFIED);
- part.SetTypeName("Not Identified");
- part.SetTypeColor("#000000");
- }
- }
- var analysisparts = new List<COTSParticleClr>();
- foreach (var fld in spl.GetFieldsData())
- {
- foreach (var part in fld.GetListAnalysisParticles())
- {
- if (spl.GetMsrParams().GetSysSTDSwitch())
- {
- if (stdFileName != "NoSTDDB.db")
- {
-
- var m_classifyEngine = new CClassifyEngine();
- IClassifyEngine engine = m_classifyEngine.GetParticleEngine(stdFileName);
- if (!engine.Classify(part))
- {
-
- return false;
- }
- }
- if (part.GetType() == (int)OTS_PARTCLE_TYPE.NOT_IDENTIFIED)
- {
- var m_classifyEngine = new CClassifyEngine();
- IClassifyEngine engine = m_classifyEngine.GetIncClassifyEngine();
- if (!engine.ClassifyIncA(part, (int)steelTech))
- {
-
- return false;
- }
- }
- }
- else
- {
-
- if (stdFileName != "NoSTDDB.db")
- {
- var m_classifyEngine = new CClassifyEngine();
- IClassifyEngine engine = m_classifyEngine.GetParticleEngine(stdFileName);
- if (!engine.Classify(part))
- {
-
- return false;
- }
- }
- }
- }
- 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.UpdateIncAList(analysisparts);
- }
- return true;
- }
- /// <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 CStage();
- }
- 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(m_nPackId.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")
- {
- m_nPackId = otsdataconst.OTS_SysType_ID.IncA;
- }
- else
- {
- m_nPackId = otsdataconst.OTS_SysType_ID.CleannessA;
- }
- }
- }
- }
- }
|