Command.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. /* ==============================================================================
  2. * 功能描述:Command
  3. * 创 建 者:Garrett
  4. * 创建日期:2018/3/27 11:42:20
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text.RegularExpressions;
  11. using System.Windows;
  12. using Autodesk.Revit.Attributes;
  13. using Autodesk.Revit.DB;
  14. using Autodesk.Revit.DB.ExtensibleStorage;
  15. using Autodesk.Revit.DB.Mechanical;
  16. using Autodesk.Revit.UI;
  17. using CEFSharpWpf;
  18. using SAGA.DotNetUtils;
  19. using SAGA.DotNetUtils.Extend;
  20. using SAGA.DotNetUtils.Logger;
  21. using SAGA.MBI.Calc;
  22. using SAGA.MBI.Common;
  23. using SAGA.MBI.DataArrange;
  24. using SAGA.MBI.Interaction;
  25. using SAGA.MBI.Login;
  26. using SAGA.MBI.Model;
  27. using SAGA.MBI.RequestData;
  28. using SAGA.MBI.Tools;
  29. using SAGA.MBI.WinView;
  30. using SAGA.MBI.WinView.BeModingDutyList;
  31. using SAGA.MBI.WinView.Login;
  32. using SAGA.MBI.WinView.ModeInfoMaintenance;
  33. using SAGA.MBI.WinView.PositionBeaconModeling;
  34. using SAGA.MBI.WinView.Space;
  35. using SAGA.MBI.WinView.Upload;
  36. using SAGA.Models;
  37. using SAGA.RevitUtils;
  38. using SAGA.RevitUtils.Extends;
  39. using SAGA.RevitUtils.Windows;
  40. using Application = Autodesk.Revit.Creation.Application;
  41. using Visibility = System.Windows.Visibility;
  42. namespace SAGA.MBI
  43. {
  44. /// <summary>
  45. /// 打开楼层模型
  46. /// </summary>
  47. [Transaction(TransactionMode.Manual)]
  48. [Regeneration(RegenerationOption.Manual)]
  49. public class OpenModeFileCommand : ExternalCommand, IExternalCommandAvailability
  50. {
  51. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  52. {
  53. try
  54. {
  55. WinOpenFile win = new WinOpenFile();
  56. win.ShowWindow();
  57. }
  58. catch (Exception e)
  59. {
  60. MessageShow.Show(e);
  61. return Result.Cancelled;
  62. }
  63. return Result.Succeeded;
  64. }
  65. /// <summary>
  66. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  67. /// when a document is open.
  68. /// </summary>
  69. public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  70. {
  71. return true;
  72. }
  73. }
  74. /// <summary>
  75. /// 模型文件管理
  76. /// </summary>
  77. [Transaction(TransactionMode.Manual)]
  78. [Regeneration(RegenerationOption.Manual)]
  79. public class EditModeFileCommand : ExternalCommand, IExternalCommandAvailability
  80. {
  81. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  82. {
  83. try
  84. {
  85. Log4Net.Debug("开始命令:模型文件管理");
  86. if (DalUploadFloor.IsAllFloorClosed())
  87. {
  88. WinModeFileManage win = new WinModeFileManage();
  89. win.ShowDialog();
  90. }
  91. Log4Net.Debug("结束命令:模型文件管理");
  92. }
  93. catch (Exception e)
  94. {
  95. MessageShow.Show(e);
  96. return Result.Cancelled;
  97. }
  98. return Result.Succeeded;
  99. }
  100. /// <summary>
  101. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  102. /// when a document is open.
  103. /// </summary>
  104. public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  105. {
  106. return true;
  107. }
  108. }
  109. /// <summary>
  110. /// 申请模型权限
  111. /// </summary>
  112. [Transaction(TransactionMode.Manual)]
  113. [Regeneration(RegenerationOption.Manual)]
  114. public class LockFloorCommand : ExternalCommand
  115. {
  116. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  117. {
  118. try
  119. {
  120. var doc = ExternalDataWrapper.Current.Doc;
  121. if (doc == null) return Result.Cancelled;
  122. string floorId = doc.PathName.GetFileName();
  123. DalLock.LockFloor(floorId, true);
  124. }
  125. catch (Exception e)
  126. {
  127. MessageShow.Show(e);
  128. return Result.Cancelled;
  129. }
  130. return Result.Succeeded;
  131. }
  132. /// <summary>
  133. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  134. /// when a document is open.
  135. /// </summary>
  136. public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  137. {
  138. return false;
  139. }
  140. }
  141. /// <summary>
  142. /// 模型信息点值维护
  143. /// </summary>
  144. [Transaction(TransactionMode.Manual)]
  145. [Regeneration(RegenerationOption.Manual)]
  146. public class EditModeInfoCommand : ExternalCommand//, IExternalCommandAvailability
  147. {
  148. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  149. {
  150. try
  151. {
  152. WinModeInfoMaintenance win = WinModeInfoMaintenance.GetWindow();
  153. if (win.Visibility != Visibility.Visible)
  154. {
  155. win.Show();
  156. IdlingEditInstance.RefrushInstance();
  157. ExternalDataWrapper.Current.UiApp.Idling += IdlingEditInstance.EditInstance_Idling;
  158. }
  159. }
  160. catch (Exception e)
  161. {
  162. MessageShow.Show(e);
  163. ExternalDataWrapper.Current.UiApp.Idling -= IdlingEditInstance.EditInstance_Idling;
  164. return Result.Cancelled;
  165. }
  166. return Result.Succeeded;
  167. }
  168. /// <summary>
  169. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  170. /// when a document is open.
  171. /// </summary>
  172. public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  173. {
  174. return false;
  175. }
  176. }
  177. /// <summary>
  178. /// 待建模型清单
  179. /// </summary>
  180. [Transaction(TransactionMode.Manual)]
  181. [Regeneration(RegenerationOption.Manual)]
  182. public class BeModeDutyListCommand : ExternalCommand
  183. {
  184. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  185. {
  186. try
  187. {
  188. Log4Net.Debug("开始命令:待建模型清单");
  189. var doc = ExternalDataWrapper.Current.Doc;
  190. if (doc == null) return Result.Cancelled;
  191. VMBeModeDutyList vm = new VMBeModeDutyList();
  192. WinBeModeDutyList win = new WinBeModeDutyList();
  193. win.DataContext = vm;
  194. win.Show();
  195. Log4Net.Debug("结束命令:待建模型清单");
  196. }
  197. catch (Exception e)
  198. {
  199. MessageShow.Show(e);
  200. return Result.Cancelled;
  201. }
  202. return Result.Succeeded;
  203. }
  204. /// <summary>
  205. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  206. /// when a document is open.
  207. /// </summary>
  208. public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  209. {
  210. return false;
  211. }
  212. }
  213. /// <summary>
  214. /// 未实体化模型清单
  215. /// </summary>
  216. [Transaction(TransactionMode.Manual)]
  217. [Regeneration(RegenerationOption.Manual)]
  218. public class ShowMissFMListCommand : ExternalCommand//, IExternalCommandAvailability
  219. {
  220. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  221. {
  222. try
  223. {
  224. Log4Net.Debug("开始命令:未实体化模型清单");
  225. var doc = ExternalDataWrapper.Current.Doc;
  226. if (doc == null) return Result.Cancelled;
  227. string floorId = doc.PathName.GetFileName();
  228. WinMissFMList win = new WinMissFMList(floorId);
  229. win.Show();
  230. Log4Net.Debug("结束命令:未实体化模型清单");
  231. }
  232. catch (Exception e)
  233. {
  234. MessageShow.Show(e);
  235. return Result.Cancelled;
  236. }
  237. return Result.Succeeded;
  238. }
  239. /// <summary>
  240. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  241. /// when a document is open.
  242. /// </summary>
  243. public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  244. {
  245. return false;
  246. }
  247. }
  248. /// <summary>
  249. /// 高亮显示空模型
  250. /// </summary>
  251. [Transaction(TransactionMode.Manual)]
  252. [Regeneration(RegenerationOption.Manual)]
  253. public class HeightLightMissFMListCommand : ExternalCommand//, IExternalCommandAvailability
  254. {
  255. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  256. {
  257. try
  258. {
  259. var doc = ExternalDataWrapper.Current.Doc;
  260. if (doc == null) return Result.Cancelled;
  261. string floorId = doc.PathName.GetFileName();
  262. WinMissFMList win = new WinMissFMList(floorId);
  263. List<Element> ids = win.MissFMEquips.Select(t => doc.GetElement(t.Equipment.BimID.GetBIMID())).Where(tt => tt != null).ToList();
  264. ExternalDataWrapper.Current.UiApp.SetShowElements(ids);
  265. }
  266. catch (Exception e)
  267. {
  268. MessageShow.Show(e);
  269. return Result.Cancelled;
  270. }
  271. return Result.Succeeded;
  272. }
  273. /// <summary>
  274. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  275. /// when a document is open.
  276. /// </summary>
  277. public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  278. {
  279. return false;
  280. }
  281. }
  282. /// <summary>
  283. /// 位置信标建模
  284. /// </summary>
  285. [Transaction(TransactionMode.Manual)]
  286. [Regeneration(RegenerationOption.Manual)]
  287. public class PositionBeaconModelingCommand : ExternalCommand//, IExternalCommandAvailability
  288. {
  289. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  290. {
  291. try
  292. {
  293. var doc = ExternalDataWrapper.Current.Doc;
  294. if (doc == null) return Result.Cancelled;
  295. string floorId = doc.PathName.GetFileName();
  296. WinBeacon win = new WinBeacon(floorId);
  297. win.Show();
  298. }
  299. catch (Exception e)
  300. {
  301. MessageShow.Show(e);
  302. return Result.Cancelled;
  303. }
  304. return Result.Succeeded;
  305. }
  306. /// <summary>
  307. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  308. /// when a document is open.
  309. /// </summary>
  310. public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  311. {
  312. return false;
  313. }
  314. }
  315. /// <summary>
  316. /// 上传模型
  317. /// </summary>
  318. [Transaction(TransactionMode.Manual)]
  319. [Regeneration(RegenerationOption.Manual)]
  320. public class UploadModeCommand : ExternalCommand, IExternalCommandAvailability
  321. {
  322. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  323. {
  324. try
  325. {
  326. if (DalUploadFloor.IsAllFloorClosed())
  327. {
  328. if (DalUploadFloor.IsNeedUpdataFile())
  329. return Result.Succeeded;
  330. VMUploadModeManage vm = DalUploadFloor.PrepareUploadFloors();
  331. if (vm != null)
  332. {
  333. WinUploadModeManage win = new WinUploadModeManage();
  334. win.DataContext = vm;
  335. win.ShowDialog();
  336. }
  337. }
  338. }
  339. catch (Exception e)
  340. {
  341. MessageShow.Show(e);
  342. return Result.Cancelled;
  343. }
  344. return Result.Succeeded;
  345. }
  346. /// <summary>
  347. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  348. /// when a document is open.
  349. /// </summary>
  350. public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  351. {
  352. return true;
  353. }
  354. }
  355. /// <summary>
  356. /// 空间管理
  357. /// </summary>
  358. [Transaction(TransactionMode.Manual)]
  359. [Regeneration(RegenerationOption.Manual)]
  360. public class CreateSpaceCommand : ExternalCommand
  361. {
  362. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  363. {
  364. try
  365. {
  366. var win = new WinCreateSpaces();
  367. win.Show();
  368. }
  369. catch (Exception e)
  370. {
  371. MessageShow.Show(e);
  372. return Result.Cancelled;
  373. }
  374. return Result.Succeeded;
  375. }
  376. public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  377. {
  378. return true;
  379. }
  380. }
  381. /// <summary>
  382. /// 同步模型本地名称
  383. /// </summary>
  384. [Transaction(TransactionMode.Manual)]
  385. [Regeneration(RegenerationOption.Manual)]
  386. public class SyncLocalNameCommand : ExternalCommand//, IExternalCommandAvailability
  387. {
  388. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  389. {
  390. try
  391. {
  392. WaitingView wait = new WaitingView();
  393. wait.Start();
  394. var floors = DalUploadFloor.GetHasFileFloors();
  395. List<CalcContext> contexts = new List<CalcContext>();
  396. foreach (UploadFloor floor in floors)
  397. {
  398. if (floor.MFloor.FloorLock.LockState != MFloorLockState.LockBySelf)
  399. {
  400. continue;
  401. }
  402. contexts.Add(new CalcContext(floor.MFloor));
  403. }
  404. MBIModelInfoManager.SyncPlatformToRevit(contexts);
  405. wait.Close();
  406. }
  407. catch (Exception e)
  408. {
  409. MessageShow.Show(e);
  410. return Result.Cancelled;
  411. }
  412. return Result.Succeeded;
  413. }
  414. public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  415. {
  416. return true;
  417. }
  418. }
  419. }