|
@@ -6,11 +6,12 @@ using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
+using System.Windows.Forms;
|
|
|
|
|
|
using FileManager;
|
|
|
using System.Xml;
|
|
|
using System.IO;
|
|
|
-//using System.Windows.Forms.dll;
|
|
|
+
|
|
|
|
|
|
namespace MeasureData
|
|
|
{
|
|
@@ -172,320 +173,92 @@ namespace MeasureData
|
|
|
}
|
|
|
|
|
|
//从文件生成切割孔信息
|
|
|
- public void GetCutHolesFromFile(string a_FilePathName)
|
|
|
+ public bool GetCutHolesFromFile(string a_FilePathName)
|
|
|
{
|
|
|
//弹出打开txt文件的对话矿
|
|
|
a_FilePathName.Trim();
|
|
|
if (string.IsNullOrEmpty(a_FilePathName))
|
|
|
{
|
|
|
- ////新建一个文件对话框
|
|
|
- //OpenFileDialog pOpenFileDialog = new OpenFileDialog();
|
|
|
-
|
|
|
- ////设置对话框标题
|
|
|
- //pOpenFileDialog.Title = "打开shp文件";
|
|
|
-
|
|
|
- ////设置打开文件类型
|
|
|
- //pOpenFileDialog.Filter = "Shape文件(*.shp)|*.shp";
|
|
|
-
|
|
|
- ////监测文件是否存在
|
|
|
- //pOpenFileDialog.CheckFileExists = true;
|
|
|
-
|
|
|
- ////文件打开后执行以下程序
|
|
|
- //if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
|
|
|
- //{
|
|
|
- // System.IO.Path.GetFullPath(openFileDialog1.FileName); //绝对路径
|
|
|
- // System.IO.Path.GetExtension(openFileDialog1.FileName); //文件扩展名
|
|
|
- // System.IO.Path.GetFileNameWithoutExtension(openFileDialog1.FileName);//文件名没有扩展
|
|
|
- // 名
|
|
|
- // System.IO.Path.GetFileName(openFileDialog1.FileName); //得到文件
|
|
|
- // System.IO.Path.GetDirectoryName(openFileDialog1.FileName); //得到路径
|
|
|
- //}
|
|
|
+ //新建一个文件对话框
|
|
|
+ OpenFileDialog pOpenFileDialog = new OpenFileDialog();
|
|
|
+ //设置对话框标题
|
|
|
+ pOpenFileDialog.Title = "打开电镜位置列表文件";
|
|
|
+ //设置打开文件类型
|
|
|
+ pOpenFileDialog.Filter = "txt文件(*.txt)|*.txt";
|
|
|
+ //监测文件是否存在
|
|
|
+ pOpenFileDialog.CheckFileExists = true;
|
|
|
+ //文件打开后执行以下程序
|
|
|
+ if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
|
|
|
+ {
|
|
|
+ a_FilePathName = System.IO.Path.GetFullPath(pOpenFileDialog.FileName); //绝对路径
|
|
|
+ }
|
|
|
}
|
|
|
- //按行取出txt文件
|
|
|
- //解析切孔生成带有位置的切孔
|
|
|
-
|
|
|
- //// check file pathname
|
|
|
- //a_strFilePathName.Trim();
|
|
|
- //if (a_strFilePathName.IsEmpty())
|
|
|
- //{
|
|
|
- // // open file dialog
|
|
|
- // CFileDialog dlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST, TEXTFILE_FILTER);
|
|
|
- // CString strDlgTitle = _T("");
|
|
|
- // strDlgTitle.LoadString(IDS_OPEN_STAGE_FILE);
|
|
|
- // dlg.m_ofn.lpstrTitle = strDlgTitle;
|
|
|
- // if (dlg.DoModal() != IDOK)
|
|
|
- // {
|
|
|
- // // user didn't click OK button, return FALSE
|
|
|
- // LogTrace(__FILE__, __LINE__, _T("LoadStageFromTextFile: user canceled on file open dialog."));
|
|
|
- // return FALSE;
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // a_strFilePathName = dlg.GetPathName();
|
|
|
- // }
|
|
|
- //}
|
|
|
-
|
|
|
- //// load string lines from the file
|
|
|
- //std::vector<CString> listLineStr = COTSHelper::LoadTextFileToCStingList(a_strFilePathName);
|
|
|
-
|
|
|
- //// get stage components
|
|
|
- //// stage name
|
|
|
- //CString strName = _T("");
|
|
|
- //// coordinate system
|
|
|
- //COORDINATE_SYSTEM_SETTING nCoodrSysSetting = COORDINATE_SYSTEM_SETTING::INVALID;
|
|
|
- //// boundary
|
|
|
- //CDomainPtr pBoundary = nullptr;
|
|
|
- //// STD
|
|
|
- //CDomainPtr pSTD = nullptr;
|
|
|
- //// Ferrari
|
|
|
- //CDomainPtr pFerrari = nullptr;
|
|
|
- //// Holes list
|
|
|
- //CHolesList listHoles;
|
|
|
- //for (auto strLine : listLineStr)
|
|
|
- //{
|
|
|
- // // split the string line with ":"
|
|
|
- // std::vector<CString> listStr = COTSHelper::SplitString(strLine, FILE_TITLE_SPLIT);
|
|
|
-
|
|
|
- // // jump over the string if it is invalid
|
|
|
- // // it should have a title string and value string
|
|
|
- // if ((int)listStr.size() != TEXTFILE_ITEM_COLUMN_NUMBER)
|
|
|
- // {
|
|
|
- // continue;
|
|
|
- // }
|
|
|
- // CString strTitle = listStr[0];
|
|
|
- // CString strValue = listStr[1];
|
|
|
-
|
|
|
- // // get stage component
|
|
|
- // for (int i = (int)STAGE_ITEMS::MIN; i <= (int)STAGE_ITEMS::MAX; ++i)
|
|
|
- // {
|
|
|
- // // match title?
|
|
|
- // CString strFileItemTitle;
|
|
|
- // strFileItemTitle.LoadString(IDS_STAGE_FILE_TITLE_FIRST + i);
|
|
|
- // if (strTitle.CompareNoCase(strFileItemTitle) == 0)
|
|
|
- // {
|
|
|
- // // found a stage item
|
|
|
- // switch ((STAGE_ITEMS)i)
|
|
|
- // {
|
|
|
- // case STAGE_ITEMS::NAME:
|
|
|
- // {
|
|
|
- // // jump over if name is set
|
|
|
- // if (strName.IsEmpty())
|
|
|
- // {
|
|
|
- // // jump over if value string is empty
|
|
|
- // strValue.Trim();
|
|
|
- // if (!strValue.IsEmpty())
|
|
|
- // {
|
|
|
- // strName = strValue;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // break;
|
|
|
-
|
|
|
- // case STAGE_ITEMS::COORDINATE_SYSTEM:
|
|
|
- // {
|
|
|
- // // jump over if coordinate system setting is set
|
|
|
- // if (nCoodrSysSetting == COORDINATE_SYSTEM_SETTING::INVALID)
|
|
|
- // {
|
|
|
- // // jump over if value string is empty
|
|
|
- // strValue.Trim();
|
|
|
- // if (!strValue.IsEmpty())
|
|
|
- // {
|
|
|
- // // string to int
|
|
|
- // int nValue;
|
|
|
- // if (COTSHelper::StringToInt(strValue, nValue))
|
|
|
- // {
|
|
|
- // // validation
|
|
|
- // if (nValue >= (int)COORDINATE_SYSTEM_SETTING::MIN && nValue <= (int)COORDINATE_SYSTEM_SETTING::MAX)
|
|
|
- // {
|
|
|
- // nCoodrSysSetting = (COORDINATE_SYSTEM_SETTING)nValue;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
- // }
|
|
|
- // }
|
|
|
- // break;
|
|
|
-
|
|
|
- // case STAGE_ITEMS::BOUNDARY:
|
|
|
- // {
|
|
|
- // // jump over if boundary is set
|
|
|
- // if (pBoundary == nullptr)
|
|
|
- // {
|
|
|
- // // get boundary
|
|
|
- // CDomainPtr pDomain = GetDomain(strValue);
|
|
|
- // if (pDomain != nullptr)
|
|
|
- // {
|
|
|
- // pBoundary = pDomain;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // break;
|
|
|
-
|
|
|
- // case STAGE_ITEMS::STD:
|
|
|
- // {
|
|
|
- // // jump over if STD is set
|
|
|
- // if (pSTD == nullptr)
|
|
|
- // {
|
|
|
- // // get STD
|
|
|
- // CDomainPtr pDomain = GetDomain(strValue);
|
|
|
- // if (pDomain != nullptr)
|
|
|
- // {
|
|
|
- // pSTD = pDomain;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // break;
|
|
|
-
|
|
|
- // case STAGE_ITEMS::FERRARI:
|
|
|
- // {
|
|
|
- // // jump over if pFerrari is set
|
|
|
- // if (pFerrari == nullptr)
|
|
|
- // {
|
|
|
- // // get STD
|
|
|
- // CDomainPtr pDomain = GetDomain(strValue);
|
|
|
- // if (pDomain != nullptr)
|
|
|
- // {
|
|
|
- // pFerrari = pDomain;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // break;
|
|
|
-
|
|
|
- // case STAGE_ITEMS::HOLE:
|
|
|
- // {
|
|
|
- // // try to get a sample hole with the value string
|
|
|
- // CHolePtr pHole = GetHole(strValue);
|
|
|
- // if (pHole != nullptr)
|
|
|
- // {
|
|
|
- // listHoles.push_back(pHole);
|
|
|
- // }
|
|
|
- // }
|
|
|
- // break;
|
|
|
- // }
|
|
|
-
|
|
|
- // // get out the for loop
|
|
|
- // break;
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
|
|
|
- //// check stage components
|
|
|
- //// name should be ok
|
|
|
- //if (pBoundary == nullptr)
|
|
|
- //{
|
|
|
- // return FALSE;
|
|
|
- //}
|
|
|
- //if (pBoundary->IsInvalid())
|
|
|
- //{
|
|
|
- // // boundary is invalid
|
|
|
- // return FALSE;
|
|
|
- //}
|
|
|
- //if (pSTD != nullptr)
|
|
|
- //{
|
|
|
- // // STD has to be inside of the boundary
|
|
|
- // if (!pBoundary->DomainInDomain(*(pSTD.get())))
|
|
|
- // {
|
|
|
- // // STD is over the boundary
|
|
|
- // return FALSE;
|
|
|
- // }
|
|
|
- //}
|
|
|
- //else
|
|
|
- //{
|
|
|
- // LogErrorTrace(__FILE__, __LINE__, _T("LoadStageFromTextFile: empty STD domain pointer."));
|
|
|
- // return FALSE;
|
|
|
- //}
|
|
|
+ //按行取出txt文件
|
|
|
+ string[] lines = File.ReadAllLines(a_FilePathName, System.Text.Encoding.Default);
|
|
|
|
|
|
- //if (pFerrari != nullptr)
|
|
|
- //{
|
|
|
- // // Ferrari has to be inside of the boundary
|
|
|
- // if (!pBoundary->DomainInDomain(*(pFerrari.get())))
|
|
|
- // {
|
|
|
- // // Ferrari is over the boundary
|
|
|
- // return FALSE;
|
|
|
- // }
|
|
|
- // else if (pSTD->IntersectDomain(*(pFerrari.get())))
|
|
|
- // {
|
|
|
- // // Ferrari has common part with STD
|
|
|
- // return FALSE;
|
|
|
- // }
|
|
|
- //}
|
|
|
- //else
|
|
|
- //{
|
|
|
- // LogErrorTrace(__FILE__, __LINE__, _T("LoadStageFromTextFile: empty Ferrari domain pointer."));
|
|
|
- // return FALSE;
|
|
|
- //}
|
|
|
+ //按现有的文件格式生成
|
|
|
+ string posMode = lines[1];
|
|
|
+ if (posMode.CompareTo(@"Absolute") != 0)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
+ //解析切孔生成带有位置的切孔
|
|
|
+ //验证数量是否正确
|
|
|
+ int nNum = Convert.ToInt32(lines[3]);
|
|
|
+ int nLines = lines.Length;
|
|
|
+ if (nNum != (lines.Length - 4))
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- //// hole has to be inside of the boundary and can't have common part with STD and each other
|
|
|
- //CHolesList listStageHoles;
|
|
|
- //for (auto pHole : listHoles)
|
|
|
- //{
|
|
|
- // if (!pBoundary->DomainInDomain(*(pHole.get())))
|
|
|
- // {
|
|
|
- // // this hole is over the boundary, jump over
|
|
|
- // continue;
|
|
|
- // }
|
|
|
- // else if (pSTD->IntersectDomain(*(pHole.get())))
|
|
|
- // {
|
|
|
- // // this hole has common part with STD, jump over
|
|
|
- // continue;
|
|
|
- // }
|
|
|
- // else if (pFerrari->IntersectDomain(*(pHole.get())))
|
|
|
- // {
|
|
|
- // // this hole has common part with Ferrari, jump over
|
|
|
- // continue;
|
|
|
- // }
|
|
|
-
|
|
|
- // BOOL bHasCommonPart = FALSE;
|
|
|
- // for (auto pStageHole : listStageHoles)
|
|
|
- // {
|
|
|
- // if (pStageHole->IntersectDomain(*(pHole.get())))
|
|
|
- // {
|
|
|
- // // this hole has common part with a hole already on the stage
|
|
|
- // bHasCommonPart = TRUE;
|
|
|
- // break;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // if (bHasCommonPart)
|
|
|
- // {
|
|
|
- // // this hole has common part with a hole already on the stage, jump over
|
|
|
- // continue;
|
|
|
- // }
|
|
|
-
|
|
|
- // // the hole is ok, add it into stage holes list
|
|
|
- // listStageHoles.push_back(pHole);
|
|
|
- //}
|
|
|
- //if (listStageHoles.size() == 0)
|
|
|
- //{
|
|
|
- // // no hole at all
|
|
|
- // return FALSE;
|
|
|
- //}
|
|
|
+ //行内标识的个数及位置
|
|
|
+ string[] titles = lines[2].Split(',');
|
|
|
+ int numPos = titles.Length;
|
|
|
|
|
|
- //// the stage is in SEM coordinate system, convert all components to OTS system
|
|
|
- //if (nCoodrSysSetting == COORDINATE_SYSTEM_SETTING::SEM)
|
|
|
- //{
|
|
|
- // if (!ConverSEMToOTSSystem(pBoundary, pSTD, listStageHoles))
|
|
|
- // {
|
|
|
- // return FALSE;
|
|
|
- // }
|
|
|
- //}
|
|
|
+ int nLabelPos = Array.IndexOf(titles, "Label");
|
|
|
+ int nXPos = Array.IndexOf(titles, "X");
|
|
|
+ int nYPos = Array.IndexOf(titles, "Y");
|
|
|
+ int nZPos = Array.IndexOf(titles, "Z");
|
|
|
+ int nTPos = Array.IndexOf(titles, "T");
|
|
|
+ int nRPos = Array.IndexOf(titles, "R");
|
|
|
+ int nMPos = Array.IndexOf(titles, "M");
|
|
|
|
|
|
- //// create stage
|
|
|
- //CStagePtr pStage(new CStage());
|
|
|
+ for (int i = 0; i < nNum; i++)
|
|
|
+ {
|
|
|
+ int currentLine = i + 4;
|
|
|
+ string currentString = lines[currentLine];
|
|
|
+ string[] CurrentPos = currentString.Split(',');
|
|
|
+ int nCurrentPosNum = CurrentPos.Length;
|
|
|
|
|
|
- //// set stage components
|
|
|
- //pStage->SetName(strName);
|
|
|
- //pStage->SetBoundary(pBoundary);
|
|
|
- //pStage->SetSTD(pSTD);
|
|
|
- //pStage->SetFerrari(pFerrari);
|
|
|
- //pStage->SetHoleList(listStageHoles);
|
|
|
+ //当前行内的标识及位置个数不够
|
|
|
+ if (nCurrentPosNum != numPos)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- //// add the stage into stages list
|
|
|
- //m_listStages.push_back(pStage);
|
|
|
+ //切孔标识
|
|
|
+ CutHole CHole = new CutHole();
|
|
|
+ CHole.HoleName = CurrentPos[nLabelPos];
|
|
|
+ //切孔位置
|
|
|
+ SemPosition holePos = new SemPosition();
|
|
|
+ holePos.X = (float)Convert.ToDouble(CurrentPos[nXPos]);
|
|
|
+ holePos.Y = (float)Convert.ToDouble(CurrentPos[nYPos]);
|
|
|
+ holePos.Z = (float)Convert.ToDouble(CurrentPos[nZPos]);
|
|
|
+ holePos.M = (float)Convert.ToDouble(CurrentPos[nMPos]);
|
|
|
+ holePos.T = (float)Convert.ToDouble(CurrentPos[nTPos]);
|
|
|
+ holePos.R = (float)Convert.ToDouble(CurrentPos[nRPos]);
|
|
|
+ CHole.Position = holePos;
|
|
|
+
|
|
|
+ //更新切孔链表
|
|
|
+ this.ListCutHole.Add(CHole);
|
|
|
+ }
|
|
|
|
|
|
- //// ok, return TRUE
|
|
|
- //return TRUE;
|
|
|
+ return true;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
#endregion
|
|
|
}
|
|
|
}
|