SystemCalcUtil.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:SystemCalcUtil
  3. * 作者:xulisong
  4. * 创建时间: 2019/1/2 17:55:55
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using Autodesk.Revit.DB;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Text.RegularExpressions;
  14. using System.Threading.Tasks;
  15. using Newtonsoft.Json.Linq;
  16. using SAGA.DotNetUtils.Cache;
  17. using SAGA.MBI.RequestData;
  18. using SAGA.Models;
  19. using SAGA.RevitUtils.Extends;
  20. using MBIEquipItem = SAGA.Models.EquipmentItem;
  21. namespace SAGA.GplotRelationComputerManage
  22. {
  23. /// <summary>
  24. /// 系统计算相关
  25. /// </summary>
  26. public class SystemCalcUtil
  27. {
  28. /// <summary>
  29. /// 判断元素是否是开始元素
  30. /// </summary>
  31. /// <param name="element"></param>
  32. /// <returns></returns>
  33. public static bool IsStart(Element element)
  34. {
  35. if (element is FamilyInstance)
  36. {
  37. var name = element.GetFamily().Name;
  38. return Regex.IsMatch(name, AppSetting.FamilyStartFlag);
  39. }
  40. return (element.GetParameterString(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)??string.Empty).StartsWith(AppSetting.StartFlag);
  41. }
  42. /// <summary>
  43. /// 创建房间缓冲集合
  44. /// </summary>
  45. /// <returns></returns>
  46. public static CacheItems<string,RoomItem> CreateRoomItems()
  47. {
  48. CacheItems<string, RoomItem> items = new CacheItems<string, RoomItem>((s) =>
  49. {
  50. var rooms = new Dictionary<string, RoomItem>();
  51. var str = new string[] {MBIBuiltInCategory.Si};
  52. List<JObject> datas = CommonConvert.QueryObjectInfoByTypes(str);
  53. foreach (var data in datas)
  54. {
  55. var roomItem = MBIItemFactory.Create<RoomItem>(data);
  56. rooms[roomItem.BimId] = roomItem;
  57. }
  58. return rooms;
  59. });
  60. return items;
  61. }
  62. /// <summary>
  63. /// 创建楼层缓冲集合
  64. /// </summary>
  65. /// <returns></returns>
  66. public static CacheItems<string, FloorSystemItem> CreateFloorItems()
  67. {
  68. CacheItems<string, FloorSystemItem> items = new CacheItems<string, FloorSystemItem>(null, (path) =>
  69. {
  70. var floorId = Path.GetFileNameWithoutExtension(path);
  71. Dictionary<string, FloorSystemItem> miss = new Dictionary<string, FloorSystemItem>();
  72. if (File.Exists(path))
  73. {
  74. var uiApp = ExternalDataWrapper.Current.UiApp.Application;
  75. var doc = uiApp.OpenDocumentFile(path);
  76. var floor = new FloorSystemItem(doc);
  77. miss[floorId] = floor;
  78. }
  79. return miss;
  80. }, Path.GetFileNameWithoutExtension);
  81. return items;
  82. }
  83. /// <summary>
  84. /// 创建关系类型壳对象
  85. /// </summary>
  86. /// <returns></returns>
  87. public static CacheItems<string, RelationTypeShell> CreateRelationShellItems()
  88. {
  89. CacheItems<string, RelationTypeShell> items = new CacheItems<string, RelationTypeShell>((s) =>
  90. {
  91. var shells = new Dictionary<string, RelationTypeShell>();
  92. foreach (var relationItem in RelationTypeManager.Items)
  93. {
  94. shells[relationItem.Type] = new RelationTypeShell(relationItem);
  95. }
  96. return shells;
  97. });
  98. return items;
  99. }
  100. /// <summary>
  101. /// 创建设备缓存对象
  102. /// </summary>
  103. /// <returns></returns>
  104. public static CacheItems<string, MBIEquipItem> CreateEquipmentItems()
  105. {
  106. CacheItems<string, MBIEquipItem> items = new CacheItems<string, MBIEquipItem>((s) =>
  107. {
  108. var equipmentItems = new Dictionary<string, MBIEquipItem>();
  109. var types = new string[] { MBIBuiltInCategory.Eq };
  110. List<JObject> equipDatas = CommonConvert.QueryObjectInfoByTypes(types);
  111. foreach (var jobject in equipDatas)
  112. {
  113. var item = MBIItemFactory.Create<MBIEquipItem>(jobject);
  114. if (item != null && string.IsNullOrWhiteSpace(item.BimId))
  115. {
  116. equipmentItems[item.BimId]= item;
  117. }
  118. }
  119. return equipmentItems;
  120. });
  121. return items;
  122. }
  123. }
  124. }