VMModelCheck.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* ==============================================================================
  2. * 功能描述:DataCheckContext
  3. * 创 建 者:Garrett
  4. * 创建日期:2018/11/29 14:43:26
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.IO;
  10. using Autodesk.Revit.DB;
  11. using Saga.PlugIn.CreateFacility;
  12. using SAGA.DotNetUtils.Extend;
  13. using SAGA.DotNetUtils.WPF;
  14. using SAGA.RevitUtils;
  15. namespace Saga.PlugIn.ModelCheck
  16. {
  17. /// <summary>
  18. /// DataCheckContext
  19. /// </summary>
  20. public class VMModelCheck : BaseViewModelStub
  21. {
  22. public VMModelCheck(Document doc)
  23. {
  24. m_Doc = doc;
  25. ModelFilePath = doc.PathName;
  26. SaveDir = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory));
  27. CheckItems = CheckOperation.GetModeCheckItems();
  28. ModelCheckState = ModelCheckState.Prepare;
  29. CurrentIndex = 1;
  30. }
  31. private Document m_Doc;
  32. private string m_ModelFilePath;
  33. /// <summary>
  34. /// 模型文件地址
  35. /// </summary>
  36. public string ModelFilePath
  37. {
  38. get { return m_ModelFilePath; }
  39. set
  40. {
  41. m_ModelFilePath = value;
  42. NotifyPropertyChanged("ModelFilePath");
  43. }
  44. }
  45. private List<ICheckBase> m_CheckItems;
  46. /// <summary>
  47. /// 检查项
  48. /// </summary>
  49. public List<ICheckBase> CheckItems
  50. {
  51. get { return m_CheckItems; }
  52. set
  53. {
  54. m_CheckItems = value;
  55. NotifyPropertyChanged("CheckItems");
  56. }
  57. }
  58. private ModelCheckState m_ModelCheckState;
  59. public ModelCheckState ModelCheckState
  60. {
  61. get { return m_ModelCheckState; }
  62. set
  63. {
  64. m_ModelCheckState = value;
  65. NotifyPropertyChanged(nameof(ModelCheckState));
  66. }
  67. }
  68. private string m_SaveDir;
  69. /// <summary>
  70. /// 保存路径
  71. /// </summary>
  72. public string SaveDir
  73. {
  74. get { return m_SaveDir; }
  75. set
  76. {
  77. m_SaveDir = value;
  78. NotifyPropertyChanged("SaveDir");
  79. }
  80. }
  81. private string m_SavePath;
  82. /// <summary>
  83. /// 保存路径
  84. /// </summary>
  85. public string SavePath
  86. {
  87. get { return m_SavePath; }
  88. set
  89. {
  90. m_SavePath = value;
  91. NotifyPropertyChanged("SavePath");
  92. }
  93. }
  94. private int m_CurrentIndex;
  95. /// <summary>
  96. /// 检查进度
  97. /// </summary>
  98. public int CurrentIndex
  99. {
  100. get { return m_CurrentIndex; }
  101. set
  102. {
  103. m_CurrentIndex = value;
  104. NotifyPropertyChanged("CurrentIndex");
  105. }
  106. }
  107. public WinModeCheck Win { get; set; }
  108. [Command]
  109. public void Execute(object param)
  110. {
  111. try
  112. {
  113. switch (ModelCheckState)
  114. {
  115. case ModelCheckState.Prepare:
  116. Win = param as WinModeCheck;
  117. CheckItems.ForEach(t => t.ModelCheckState = ModelCheckState.Progress);
  118. ModelCheckState = ModelCheckState.Progress;
  119. string savePath = Path.Combine(SaveDir,
  120. $"{ModelFilePath.GetFileName()}{"模型规范检查报告"}{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx");
  121. CheckOperation.Execute(CheckItems, m_Doc, savePath, this);
  122. ModelCheckState = ModelCheckState.Ending;
  123. //为了Ending的界面显示,出问题注释掉
  124. SavePath = savePath;
  125. WinTipCheckComplete win = new WinTipCheckComplete();
  126. win.ShowDialog();
  127. break;
  128. case ModelCheckState.Progress:
  129. break;
  130. case ModelCheckState.Ending:
  131. System.Diagnostics.Process.Start("explorer.exe", SaveDir);
  132. break;
  133. }
  134. }
  135. catch (Exception e)
  136. {
  137. MessageShow.Show(e);
  138. }
  139. }
  140. public bool CanExecute(object param)
  141. {
  142. return ModelCheckState.Progress != ModelCheckState;
  143. }
  144. }
  145. public enum ModelCheckState
  146. {
  147. Prepare,
  148. Progress,
  149. Ending
  150. }
  151. }