VMModelCheck.cs 4.6 KB

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