VMCreateFacility.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /* ==============================================================================
  2. * 功能描述:VMCreateFacility
  3. * 创 建 者:Garrett
  4. * 创建日期:2019/10/23 9:46:45
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using Autodesk.Revit.DB;
  13. using Saga.PlugIn.ModelCheck;
  14. using SAGA.DotNetUtils.Others;
  15. using SAGA.DotNetUtils.WPF;
  16. namespace Saga.PlugIn.CreateFacility
  17. {
  18. /// <summary>
  19. /// VMCreateFacility
  20. /// </summary>
  21. public class VMCreateFacility:BaseViewModelStub
  22. {
  23. public VMCreateFacility(Document doc)
  24. {
  25. m_Document = doc;
  26. ModelFilePath = doc.PathName;
  27. }
  28. private Document m_Document;
  29. private string m_TabCode;
  30. /// <summary>
  31. /// 标记码
  32. /// </summary>
  33. public string TabCode
  34. {
  35. get { return m_TabCode; }
  36. set
  37. {
  38. m_TabCode = value;
  39. NotifyPropertyChanged("TabCode");
  40. MFacilityTabCode = ParseFacilityTabCode.Parse(value);
  41. }
  42. }
  43. private MFacilityTabCode m_MFacilityTabCode;
  44. public MFacilityTabCode MFacilityTabCode
  45. {
  46. get { return m_MFacilityTabCode; }
  47. set
  48. {
  49. m_MFacilityTabCode = value;
  50. FacilityLocated = $"{value?.BuildingName}-{value?.FloorName}";
  51. }
  52. }
  53. private string m_FacilityLocated;
  54. /// <summary>
  55. /// 设备所在位置
  56. /// </summary>
  57. public string FacilityLocated
  58. {
  59. get { return m_FacilityLocated; }
  60. set
  61. {
  62. m_FacilityLocated = value;
  63. NotifyPropertyChanged("FacilityLocated");
  64. }
  65. }
  66. private string m_ModelFilePath;
  67. /// <summary>
  68. /// 模型文件地址
  69. /// </summary>
  70. public string ModelFilePath
  71. {
  72. get { return m_ModelFilePath; }
  73. set
  74. {
  75. m_ModelFilePath = value;
  76. NotifyPropertyChanged("ModelFilePath");
  77. }
  78. }
  79. #region command
  80. [Command]
  81. public void PasteTabCode(object param)
  82. {
  83. IDataObject iData = Clipboard.GetDataObject();
  84. if (iData.GetDataPresent(DataFormats.Text))
  85. {
  86. TabCode = (String)iData.GetData(DataFormats.Text);
  87. }
  88. }
  89. public bool CanPasteTabCode(object param)
  90. {
  91. return true;
  92. }
  93. [Command]
  94. public void ClearTabCode(object param)
  95. {
  96. TabCode = null;
  97. }
  98. public bool CanClearTabCode(object param)
  99. {
  100. return true;
  101. }
  102. [Command]
  103. public void Execute(object param)
  104. {
  105. if (string.IsNullOrEmpty(MFacilityTabCode.Id))
  106. {
  107. MessageShowBase.Infomation("粘贴设备类数据异常,请检查");
  108. return;
  109. }
  110. //选择设备类
  111. var facilityCodes = MFacilityTabCode.EquipClasses;
  112. WinSelectDeviceClass win=new WinSelectDeviceClass(facilityCodes);
  113. if (facilityCodes.Count > 1)
  114. {
  115. if(win.ShowDialog()!=true)
  116. return;
  117. }
  118. var facilityClass = win.SelectedCode;
  119. if (facilityClass == null)
  120. {
  121. MessageShowBase.Infomation("粘贴设备类数据异常,请检查");
  122. return;
  123. }
  124. //判断是否存在
  125. var id = CreateFacilityRevitUtils.FindFacility(m_Document, facilityClass.code, MFacilityTabCode.Id);
  126. if (!string.IsNullOrEmpty(id))
  127. {
  128. WinTipExisted winTipExisted=new WinTipExisted(id);
  129. if (winTipExisted.ShowDialog() == true)
  130. TabCode = null;
  131. return;
  132. }
  133. //创建
  134. id = CreateFacilityRevitUtils.CreateFacility(m_Document, facilityClass, MFacilityTabCode.BIMLocation,
  135. MFacilityTabCode.Id);
  136. if (!string.IsNullOrEmpty(id))
  137. {
  138. CreateFacilityRevitUtils.FocusFacility(id);
  139. WinTipCreateSuccess winTipCreateSuccess = new WinTipCreateSuccess(id);
  140. winTipCreateSuccess.ShowDialog();
  141. }
  142. }
  143. public bool CanExecute(object param)
  144. {
  145. return MFacilityTabCode!=null;
  146. }
  147. #endregion
  148. }
  149. }