VMModelCheck.cs 3.7 KB

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