SystemParseSetting.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using Autodesk.Revit.DB;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using SAGA.RevitUtils.Extends;
  8. using SAGA.RevitUtils.MEP;
  9. using SAGA.RevitUtils;
  10. using SAGA.MBI.Tools;
  11. using System.Text.RegularExpressions;
  12. namespace SAGA.GplotRelationComputerManage
  13. {
  14. /// <summary>
  15. /// 系统导出设置
  16. /// </summary>
  17. public class SystemParseSetting
  18. {
  19. public SystemParseSetting(GplotOptions options)
  20. {
  21. //GplotOptions = options;
  22. //var relationType = RelationTypeManager.GetRelationTypeItem(options.);
  23. }
  24. public SystemParseSetting(RelationTypeShell relationShell)
  25. {
  26. RelationTypeShell = relationShell;
  27. Domain = relationShell.IsPipeSystem() ? Domain.DomainPiping : Domain.DomainHvac;
  28. }
  29. ///// <summary>
  30. ///// 图相关设置
  31. ///// </summary>
  32. //public GplotOptions GplotOptions { get; set; }
  33. /// <summary>
  34. /// 关系类型相关
  35. /// </summary>
  36. public RelationTypeShell RelationTypeShell { get;private set; }
  37. /// <summary>
  38. /// 使用域枚举
  39. /// </summary>
  40. public Domain Domain { get;private set; }
  41. #region 设置相关信息
  42. /*
  43. * 1、确定边界:
  44. * 哪些确定成点标记,哪些确定成边标记【用以处理非点标记甄别】
  45. * 2、确定遇到什么情况断开
  46. *
  47. * 3、确定那些事旁通边
  48. */
  49. #endregion
  50. /// <summary>
  51. /// 判断是否是节点标记
  52. /// </summary>
  53. /// <param name="element"></param>
  54. /// <returns></returns>
  55. public bool IsForkNode(Element element)
  56. {
  57. Domain domain = Domain;
  58. var connectors = element.GetConnectors(domain);
  59. return connectors.Count > 2;
  60. }
  61. public List<JoinItem> GetJoinItems(Element element,List<int> usedIds)
  62. {
  63. List<JoinItem> joinItems = new List<JoinItem>();
  64. Domain domain = Domain;
  65. var connectors = element.GetConnectors(domain);
  66. foreach (var connector in connectors)
  67. {
  68. if (connector.IsLogical())
  69. continue;
  70. if (!(element is MEPCurve||connector.IsConnected))
  71. {
  72. continue;
  73. }
  74. if (IgnoreConnector(connector))
  75. continue;
  76. if (!connector.IsConnected)
  77. {
  78. joinItems.Add(new JoinItem(connector,null));
  79. }
  80. else
  81. {
  82. foreach (Connector refConnector in connector.AllRefs)
  83. {
  84. if (refConnector.IsLogical() || refConnector.Owner.Id == element.Id || usedIds.Any(id => refConnector.Owner.Id.IntegerValue == id))
  85. continue;
  86. if (IgnoreConnector(refConnector))
  87. continue;
  88. joinItems.Add(new JoinItem(connector, refConnector));
  89. }
  90. }
  91. }
  92. return joinItems;
  93. }
  94. /// <summary>
  95. /// 标识元素是否是设备
  96. /// </summary>
  97. /// <param name="element"></param>
  98. /// <returns></returns>
  99. public bool IsEquipment(Element element)
  100. {
  101. if (!(element is FamilyInstance fi))
  102. {
  103. return false;
  104. }
  105. return MBIInfoUtil.IsEquipment(element);
  106. }
  107. /// <summary>
  108. /// 无用边,节点可连通
  109. /// </summary>
  110. /// <param name="edge"></param>
  111. /// <returns></returns>
  112. public bool UselessEdge(ElementsEdge edge)
  113. {
  114. //如果该边的断点含有空点,则证明是虚拟设备
  115. if (edge.RealStart.IsEmpty() || edge.RealEnd.IsEmpty())
  116. return false;
  117. if (edge.RealStart.GetDisableCombine() || edge.RealEnd.GetDisableCombine())
  118. return false;
  119. if (edge.RealStart.RefData.Any(e => !e.IsWaterComponment()) ||
  120. edge.RealEnd.RefData.Any(e => !e.IsWaterComponment()))
  121. return false;
  122. return edge.RefData.All(e => e.IsWaterComponment());
  123. }
  124. /// <summary>
  125. /// 忽略的连接关系
  126. /// </summary>
  127. /// <param name="connector"></param>
  128. /// <returns></returns>
  129. public bool IgnoreConnector(Connector connector)
  130. {
  131. bool result = false;
  132. do
  133. {
  134. Element owner = connector.Owner;
  135. #region 通用判断
  136. if (owner is MEPCurve mepCurve)
  137. {
  138. string typeName = mepCurve.GetSystemTypeName();
  139. result = !RelationTypeShell.IsMatchSystem(typeName);
  140. break;
  141. }
  142. if (SystemCalcUtil.IsStartValve(owner))
  143. {
  144. result = Regex.IsMatch(connector.Description, AppSetting.EndFlag);// connector.Description != GplotOptions.ValveConnectorDescription;
  145. break;
  146. }
  147. #endregion
  148. if (!owner.IsWaterComponment())
  149. {
  150. var mepCurves= owner.GetFirstElements<MEPCurve>(connector);
  151. if (mepCurves.Any())
  152. {
  153. string typeName = (mepCurves[0] as MEPCurve).GetSystemTypeName();
  154. result = !RelationTypeShell.IsMatchSystem(typeName);// !GplotOptions.MatchSystemType(typeName);
  155. }
  156. break;
  157. }
  158. } while (false);
  159. return result;
  160. }
  161. #region 制定特殊阀门判断
  162. /// <summary>
  163. /// 判断制定元素是否是特定阀门
  164. /// </summary>
  165. /// <param name="element"></param>
  166. /// <returns></returns>
  167. public bool IsSpecialValve(Element element)
  168. {
  169. if(element is FamilyInstance fi)
  170. {
  171. var name = fi.GetFamily().Name;
  172. return Regex.IsMatch(name, AppSetting.FamilyStartFlag);
  173. }
  174. return false;
  175. }
  176. #endregion
  177. }
  178. }