VMModelCheck.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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.DotNetUtils.Extend;
  12. using SAGA.DotNetUtils.WPF;
  13. using SAGA.RevitUtils;
  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. SavePath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory));
  26. CheckItems = CheckOperation.GetModeCheckItems();
  27. ModelCheckState = ModelCheckState.Prepare;
  28. }
  29. private Document m_Doc;
  30. /// <summary>
  31. /// 保存模板地址
  32. /// </summary>
  33. public string TemplatePath { get; set; }
  34. private string m_ModelFilePath;
  35. /// <summary>
  36. /// 模型文件地址
  37. /// </summary>
  38. public string ModelFilePath
  39. {
  40. get { return m_ModelFilePath; }
  41. set
  42. {
  43. m_ModelFilePath = value;
  44. NotifyPropertyChanged("ModelFilePath");
  45. }
  46. }
  47. private List<ICheckBase> m_CheckItems;
  48. /// <summary>
  49. /// 检查项
  50. /// </summary>
  51. public List<ICheckBase> CheckItems
  52. {
  53. get { return m_CheckItems; }
  54. set
  55. {
  56. m_CheckItems = value;
  57. NotifyPropertyChanged("CheckItems");
  58. }
  59. }
  60. private ModelCheckState m_ModelCheckState;
  61. public ModelCheckState ModelCheckState
  62. {
  63. get { return m_ModelCheckState; }
  64. set
  65. {
  66. m_ModelCheckState = value;
  67. NotifyPropertyChanged(nameof(ModelCheckState));
  68. }
  69. }
  70. private string m_SavePath;
  71. /// <summary>
  72. /// 保存路径
  73. /// </summary>
  74. public string SavePath
  75. {
  76. get { return m_SavePath; }
  77. set
  78. {
  79. m_SavePath = value;
  80. NotifyPropertyChanged("SavePath");
  81. }
  82. }
  83. [Command]
  84. public void Execute(object param)
  85. {
  86. try
  87. {
  88. switch (ModelCheckState)
  89. {
  90. case ModelCheckState.Prepare:
  91. CheckItems.ForEach(t => t.ModelCheckState = ModelCheckState.Progress);
  92. ModelCheckState = ModelCheckState.Progress;
  93. string savePath = Path.Combine(SavePath,
  94. $"{ModelFilePath.GetFileName()}{"模型规范检查报告"}{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx");
  95. CheckOperation.Execute(CheckItems, m_Doc, savePath);
  96. ModelCheckState = ModelCheckState.Ending;
  97. break;
  98. case ModelCheckState.Progress:
  99. break;
  100. case ModelCheckState.Ending:
  101. System.Diagnostics.Process.Start("explorer.exe", SavePath);
  102. break;
  103. }
  104. }
  105. catch (Exception e)
  106. {
  107. MessageShow.Show(e);
  108. }
  109. }
  110. public bool CanExecute(object param)
  111. {
  112. return ModelCheckState.Progress!=ModelCheckState;
  113. }
  114. }
  115. public enum ModelCheckState
  116. {
  117. Prepare,
  118. Progress,
  119. Ending
  120. }
  121. }