MeasureFile.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. //时间:20200610
  2. //作者:郝爽
  3. //功能:测量文件
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using FileManager;
  10. using System.Xml;
  11. using System.IO;
  12. //using System.Windows.Forms.dll;
  13. namespace MeasureData
  14. {
  15. public class MeasureFile:ISlo
  16. {
  17. public const string UNTITLED_FILE_NAME = "Untitled";
  18. #region 内容
  19. //文件名
  20. private string m_fileName;
  21. public string FileName
  22. {
  23. get { return this.m_fileName; }
  24. set { this.m_fileName = value; }
  25. }
  26. //文件路径
  27. private string m_filepath;
  28. public string FilePath
  29. {
  30. get { return this.m_filepath; }
  31. set { this.m_filepath = value; }
  32. }
  33. //切孔链表
  34. private List<CutHole> m_listCutHole;
  35. public List<CutHole> ListCutHole
  36. {
  37. get { return this.m_listCutHole; }
  38. set { this.m_listCutHole = value; }
  39. }
  40. //测量参数
  41. private MeasureParam m_measureParam;
  42. public MeasureParam MParam
  43. {
  44. get { return this.m_measureParam; }
  45. set { this.m_measureParam = value; }
  46. }
  47. #endregion
  48. /// <summary>
  49. /// 创建XML文件
  50. /// </summary>
  51. /// <returns>0:失败;1:成功;2:文件已存在</returns>
  52. public int CreateXml()
  53. {
  54. if (!File.Exists(this.FilePath + "\\" + this.FileName))
  55. {
  56. if( XmlManager.CreateXmlFile(this.FilePath + "\\" + this.FileName))
  57. {
  58. return 1;
  59. }
  60. else
  61. {
  62. return 0;
  63. }
  64. }
  65. else
  66. {
  67. return 2;
  68. }
  69. }
  70. //XML文件保存
  71. //样品孔存储xml文档
  72. public override void Serialize(bool isStoring, XmlDocument xml, XmlNode rootNode)
  73. {
  74. Slo<MeasureFile> slo_msf = new Slo<MeasureFile>();
  75. Slo<CutHole> slo_cuthole = new Slo<CutHole>();
  76. Collection<CutHole> cot_cuthole = new Collection<CutHole>();
  77. for (int i = 0; i < this.ListCutHole.Count; i++)
  78. {
  79. cot_cuthole.addItem(ListCutHole[i]);
  80. }
  81. xString FileName = new xString();
  82. xString FilePath = new xString();
  83. FileName.AssignValue(this.FileName);
  84. FilePath.AssignValue(this.FilePath);
  85. slo_cuthole.Register("FileName", FileName);
  86. slo_cuthole.Register("FilePath", FilePath);
  87. slo_cuthole.Register("ListCutHole", cot_cuthole);
  88. slo_msf.Register("MeasureFile", slo_cuthole);
  89. if (isStoring)
  90. {
  91. slo_msf.Serialize(true, xml, rootNode);
  92. }
  93. else
  94. {
  95. slo_msf.Serialize(false, xml, rootNode);
  96. this.FileName = FileName.value();
  97. this.FilePath = FilePath.value();
  98. for (int i = 0; i < cot_cuthole.m_vCollection.Count; i++)
  99. {
  100. this.ListCutHole.Add(cot_cuthole.getItem(i));
  101. }
  102. }
  103. }
  104. //构造函数
  105. public MeasureFile()
  106. {
  107. Init();
  108. }
  109. public void Init()
  110. {
  111. this.ListCutHole = new List<CutHole>();
  112. this.FileName = @"";
  113. this.FilePath = @"";
  114. this.MParam = new MeasureParam();
  115. }
  116. #region 操作
  117. //新建
  118. public bool New()
  119. {
  120. //int ret = CreateXml();
  121. //if(ret>0)
  122. //{
  123. // XmlDocument doc = new XmlDocument();
  124. // doc.Load(this.FilePath + "\\" + this.FileName);//载入xml文件
  125. // XmlNode root = doc.SelectSingleNode("XMLData");
  126. // Serialize(true, doc, root);
  127. // doc.Save(this.FilePath + "\\" + this.FileName);
  128. //}
  129. // 设置路径为初始默认路径
  130. FilePath = UNTITLED_FILE_NAME;
  131. // Ok, return TRUE
  132. return true;
  133. }
  134. //打开
  135. public void Open()
  136. {
  137. }
  138. //保存
  139. public void Save()
  140. {
  141. //Serialize();
  142. }
  143. //另存为
  144. public void SaveAs()
  145. {
  146. }
  147. //从文件生成切割孔信息
  148. public void GetCutHolesFromFile(string a_FilePathName)
  149. {
  150. //弹出打开txt文件的对话矿
  151. a_FilePathName.Trim();
  152. if (string.IsNullOrEmpty(a_FilePathName))
  153. {
  154. ////新建一个文件对话框
  155. //OpenFileDialog pOpenFileDialog = new OpenFileDialog();
  156. ////设置对话框标题
  157. //pOpenFileDialog.Title = "打开shp文件";
  158. ////设置打开文件类型
  159. //pOpenFileDialog.Filter = "Shape文件(*.shp)|*.shp";
  160. ////监测文件是否存在
  161. //pOpenFileDialog.CheckFileExists = true;
  162. ////文件打开后执行以下程序
  163. //if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
  164. //{
  165. // System.IO.Path.GetFullPath(openFileDialog1.FileName); //绝对路径
  166. // System.IO.Path.GetExtension(openFileDialog1.FileName); //文件扩展名
  167. // System.IO.Path.GetFileNameWithoutExtension(openFileDialog1.FileName);//文件名没有扩展
  168. // 名
  169. // System.IO.Path.GetFileName(openFileDialog1.FileName); //得到文件
  170. // System.IO.Path.GetDirectoryName(openFileDialog1.FileName); //得到路径
  171. //}
  172. }
  173. //按行取出txt文件
  174. //解析切孔生成带有位置的切孔
  175. //// check file pathname
  176. //a_strFilePathName.Trim();
  177. //if (a_strFilePathName.IsEmpty())
  178. //{
  179. // // open file dialog
  180. // CFileDialog dlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST, TEXTFILE_FILTER);
  181. // CString strDlgTitle = _T("");
  182. // strDlgTitle.LoadString(IDS_OPEN_STAGE_FILE);
  183. // dlg.m_ofn.lpstrTitle = strDlgTitle;
  184. // if (dlg.DoModal() != IDOK)
  185. // {
  186. // // user didn't click OK button, return FALSE
  187. // LogTrace(__FILE__, __LINE__, _T("LoadStageFromTextFile: user canceled on file open dialog."));
  188. // return FALSE;
  189. // }
  190. // else
  191. // {
  192. // a_strFilePathName = dlg.GetPathName();
  193. // }
  194. //}
  195. //// load string lines from the file
  196. //std::vector<CString> listLineStr = COTSHelper::LoadTextFileToCStingList(a_strFilePathName);
  197. //// get stage components
  198. //// stage name
  199. //CString strName = _T("");
  200. //// coordinate system
  201. //COORDINATE_SYSTEM_SETTING nCoodrSysSetting = COORDINATE_SYSTEM_SETTING::INVALID;
  202. //// boundary
  203. //CDomainPtr pBoundary = nullptr;
  204. //// STD
  205. //CDomainPtr pSTD = nullptr;
  206. //// Ferrari
  207. //CDomainPtr pFerrari = nullptr;
  208. //// Holes list
  209. //CHolesList listHoles;
  210. //for (auto strLine : listLineStr)
  211. //{
  212. // // split the string line with ":"
  213. // std::vector<CString> listStr = COTSHelper::SplitString(strLine, FILE_TITLE_SPLIT);
  214. // // jump over the string if it is invalid
  215. // // it should have a title string and value string
  216. // if ((int)listStr.size() != TEXTFILE_ITEM_COLUMN_NUMBER)
  217. // {
  218. // continue;
  219. // }
  220. // CString strTitle = listStr[0];
  221. // CString strValue = listStr[1];
  222. // // get stage component
  223. // for (int i = (int)STAGE_ITEMS::MIN; i <= (int)STAGE_ITEMS::MAX; ++i)
  224. // {
  225. // // match title?
  226. // CString strFileItemTitle;
  227. // strFileItemTitle.LoadString(IDS_STAGE_FILE_TITLE_FIRST + i);
  228. // if (strTitle.CompareNoCase(strFileItemTitle) == 0)
  229. // {
  230. // // found a stage item
  231. // switch ((STAGE_ITEMS)i)
  232. // {
  233. // case STAGE_ITEMS::NAME:
  234. // {
  235. // // jump over if name is set
  236. // if (strName.IsEmpty())
  237. // {
  238. // // jump over if value string is empty
  239. // strValue.Trim();
  240. // if (!strValue.IsEmpty())
  241. // {
  242. // strName = strValue;
  243. // }
  244. // }
  245. // }
  246. // break;
  247. // case STAGE_ITEMS::COORDINATE_SYSTEM:
  248. // {
  249. // // jump over if coordinate system setting is set
  250. // if (nCoodrSysSetting == COORDINATE_SYSTEM_SETTING::INVALID)
  251. // {
  252. // // jump over if value string is empty
  253. // strValue.Trim();
  254. // if (!strValue.IsEmpty())
  255. // {
  256. // // string to int
  257. // int nValue;
  258. // if (COTSHelper::StringToInt(strValue, nValue))
  259. // {
  260. // // validation
  261. // if (nValue >= (int)COORDINATE_SYSTEM_SETTING::MIN && nValue <= (int)COORDINATE_SYSTEM_SETTING::MAX)
  262. // {
  263. // nCoodrSysSetting = (COORDINATE_SYSTEM_SETTING)nValue;
  264. // }
  265. // }
  266. // }
  267. // }
  268. // }
  269. // break;
  270. // case STAGE_ITEMS::BOUNDARY:
  271. // {
  272. // // jump over if boundary is set
  273. // if (pBoundary == nullptr)
  274. // {
  275. // // get boundary
  276. // CDomainPtr pDomain = GetDomain(strValue);
  277. // if (pDomain != nullptr)
  278. // {
  279. // pBoundary = pDomain;
  280. // }
  281. // }
  282. // }
  283. // break;
  284. // case STAGE_ITEMS::STD:
  285. // {
  286. // // jump over if STD is set
  287. // if (pSTD == nullptr)
  288. // {
  289. // // get STD
  290. // CDomainPtr pDomain = GetDomain(strValue);
  291. // if (pDomain != nullptr)
  292. // {
  293. // pSTD = pDomain;
  294. // }
  295. // }
  296. // }
  297. // break;
  298. // case STAGE_ITEMS::FERRARI:
  299. // {
  300. // // jump over if pFerrari is set
  301. // if (pFerrari == nullptr)
  302. // {
  303. // // get STD
  304. // CDomainPtr pDomain = GetDomain(strValue);
  305. // if (pDomain != nullptr)
  306. // {
  307. // pFerrari = pDomain;
  308. // }
  309. // }
  310. // }
  311. // break;
  312. // case STAGE_ITEMS::HOLE:
  313. // {
  314. // // try to get a sample hole with the value string
  315. // CHolePtr pHole = GetHole(strValue);
  316. // if (pHole != nullptr)
  317. // {
  318. // listHoles.push_back(pHole);
  319. // }
  320. // }
  321. // break;
  322. // }
  323. // // get out the for loop
  324. // break;
  325. // }
  326. // }
  327. //}
  328. //// check stage components
  329. //// name should be ok
  330. //if (pBoundary == nullptr)
  331. //{
  332. // return FALSE;
  333. //}
  334. //if (pBoundary->IsInvalid())
  335. //{
  336. // // boundary is invalid
  337. // return FALSE;
  338. //}
  339. //if (pSTD != nullptr)
  340. //{
  341. // // STD has to be inside of the boundary
  342. // if (!pBoundary->DomainInDomain(*(pSTD.get())))
  343. // {
  344. // // STD is over the boundary
  345. // return FALSE;
  346. // }
  347. //}
  348. //else
  349. //{
  350. // LogErrorTrace(__FILE__, __LINE__, _T("LoadStageFromTextFile: empty STD domain pointer."));
  351. // return FALSE;
  352. //}
  353. //if (pFerrari != nullptr)
  354. //{
  355. // // Ferrari has to be inside of the boundary
  356. // if (!pBoundary->DomainInDomain(*(pFerrari.get())))
  357. // {
  358. // // Ferrari is over the boundary
  359. // return FALSE;
  360. // }
  361. // else if (pSTD->IntersectDomain(*(pFerrari.get())))
  362. // {
  363. // // Ferrari has common part with STD
  364. // return FALSE;
  365. // }
  366. //}
  367. //else
  368. //{
  369. // LogErrorTrace(__FILE__, __LINE__, _T("LoadStageFromTextFile: empty Ferrari domain pointer."));
  370. // return FALSE;
  371. //}
  372. //// hole has to be inside of the boundary and can't have common part with STD and each other
  373. //CHolesList listStageHoles;
  374. //for (auto pHole : listHoles)
  375. //{
  376. // if (!pBoundary->DomainInDomain(*(pHole.get())))
  377. // {
  378. // // this hole is over the boundary, jump over
  379. // continue;
  380. // }
  381. // else if (pSTD->IntersectDomain(*(pHole.get())))
  382. // {
  383. // // this hole has common part with STD, jump over
  384. // continue;
  385. // }
  386. // else if (pFerrari->IntersectDomain(*(pHole.get())))
  387. // {
  388. // // this hole has common part with Ferrari, jump over
  389. // continue;
  390. // }
  391. // BOOL bHasCommonPart = FALSE;
  392. // for (auto pStageHole : listStageHoles)
  393. // {
  394. // if (pStageHole->IntersectDomain(*(pHole.get())))
  395. // {
  396. // // this hole has common part with a hole already on the stage
  397. // bHasCommonPart = TRUE;
  398. // break;
  399. // }
  400. // }
  401. // if (bHasCommonPart)
  402. // {
  403. // // this hole has common part with a hole already on the stage, jump over
  404. // continue;
  405. // }
  406. // // the hole is ok, add it into stage holes list
  407. // listStageHoles.push_back(pHole);
  408. //}
  409. //if (listStageHoles.size() == 0)
  410. //{
  411. // // no hole at all
  412. // return FALSE;
  413. //}
  414. //// the stage is in SEM coordinate system, convert all components to OTS system
  415. //if (nCoodrSysSetting == COORDINATE_SYSTEM_SETTING::SEM)
  416. //{
  417. // if (!ConverSEMToOTSSystem(pBoundary, pSTD, listStageHoles))
  418. // {
  419. // return FALSE;
  420. // }
  421. //}
  422. //// create stage
  423. //CStagePtr pStage(new CStage());
  424. //// set stage components
  425. //pStage->SetName(strName);
  426. //pStage->SetBoundary(pBoundary);
  427. //pStage->SetSTD(pSTD);
  428. //pStage->SetFerrari(pFerrari);
  429. //pStage->SetHoleList(listStageHoles);
  430. //// add the stage into stages list
  431. //m_listStages.push_back(pStage);
  432. //// ok, return TRUE
  433. //return TRUE;
  434. }
  435. #endregion
  436. }
  437. }