|
@@ -0,0 +1,370 @@
|
|
|
+/*-------------------------------------------------------------------------
|
|
|
+ * 功能描述:SystemParseManager
|
|
|
+ * 作者:xulisong
|
|
|
+ * 创建时间: 2019/1/10 14:34:23
|
|
|
+ * 版本号:v1.0
|
|
|
+ * -------------------------------------------------------------------------*/
|
|
|
+
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using Autodesk.Revit.DB;
|
|
|
+using Autodesk.Revit.DB.Mechanical;
|
|
|
+using Autodesk.Revit.DB.Plumbing;
|
|
|
+using SAGA.RevitUtils;
|
|
|
+using SAGA.RevitUtils.Extends;
|
|
|
+using SAGA.RevitUtils.MEP;
|
|
|
+
|
|
|
+namespace SAGA.GplotRelationComputerManage
|
|
|
+{
|
|
|
+ /// <summary>
|
|
|
+ /// 系统解析管理
|
|
|
+ /// </summary>
|
|
|
+ public class SystemParseManager
|
|
|
+ {
|
|
|
+ #region 解析管路系统数据
|
|
|
+ #region 通用基础方法
|
|
|
+ /// <summary>
|
|
|
+ /// 创建树节点
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="startElement"></param>
|
|
|
+ /// <param name="startConnector"></param>
|
|
|
+ /// <param name="predicateEnd"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static ElementTreeNode CreateTreeNode(Element startElement, Connector startConnector,
|
|
|
+ Predicate<Element> predicateEnd)
|
|
|
+ {
|
|
|
+ ElementTreeNode node = new ElementTreeNode();
|
|
|
+ node.Current = startElement;
|
|
|
+ List<ElementTreeNode> reference = new List<ElementTreeNode>();
|
|
|
+ reference.Add(node);
|
|
|
+ for (int i = 0; i < reference.Count; i++)
|
|
|
+ {
|
|
|
+ var baseNode = reference[i];
|
|
|
+ List<Connector> connectors;
|
|
|
+ if (i == 0 && startConnector != null)
|
|
|
+ {
|
|
|
+ connectors = new List<Connector> { startConnector };
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ connectors = baseNode.Current.GetAllConnectors().ToList();
|
|
|
+ }
|
|
|
+ foreach (var connector in connectors)
|
|
|
+ {
|
|
|
+ if (connector.Searchable())
|
|
|
+ {
|
|
|
+ var refConnectors = connector.GetReferenceConnectors()
|
|
|
+ .Where(c => ConnectorType.Physical.HasFlag(c.ConnectorType)).ToList();
|
|
|
+ foreach (var refConnector in refConnectors)
|
|
|
+ {
|
|
|
+ var refElement = refConnector.Owner;
|
|
|
+ ElementTreeNode refNode = new ElementTreeNode();
|
|
|
+ refNode.Current = refElement;
|
|
|
+ refNode.StartLocation = refConnector.Origin;
|
|
|
+ baseNode.Nodes.Add(refNode);
|
|
|
+ if (predicateEnd != null && predicateEnd(refElement))
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (reference.All(e => e.Current.Id.IntegerValue != refElement.Id.IntegerValue))
|
|
|
+ {
|
|
|
+ reference.Add(refNode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return node;
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 构件系统连接节点
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="etn">开始元素</param>
|
|
|
+ /// <param name="domain"></param>
|
|
|
+ /// <param name="endConditon">遍历中断条件,遇到指定条件的管道则停止遍历</param>
|
|
|
+ /// <returns>树形节点中包好的Id信息</returns>
|
|
|
+ public static List<int> BuildSystemNode(ElementTreeNode etn, Domain domain, Func<MEPCurve, bool> endConditon)
|
|
|
+ {
|
|
|
+ List<int> useIds = new List<int>();
|
|
|
+ etn.GetAllNodes().ForEach(n =>
|
|
|
+ {
|
|
|
+ if (!n.IsLeaf&&n.Current != null)
|
|
|
+ {
|
|
|
+ useIds.Add(n.Current.Id.IntegerValue);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ var leaves = etn.GetLeaves();
|
|
|
+ foreach (var elementTreeNode in leaves)
|
|
|
+ {
|
|
|
+ BuildSystemNode(elementTreeNode, domain, useIds, endConditon);
|
|
|
+ }
|
|
|
+ return useIds;
|
|
|
+ }
|
|
|
+ private static void BuildSystemNode(ElementTreeNode etn, Domain domain, List<int> useIds, Func<MEPCurve, bool> endConditon)
|
|
|
+ {
|
|
|
+ var useElement = etn.Current;
|
|
|
+ #region 预判退出
|
|
|
+ if (useElement == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (useIds.Any(id => id == useElement.Id.IntegerValue))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ useIds.Add(useElement.Id.IntegerValue);
|
|
|
+ var connectors = useElement.GetConnectors(domain);
|
|
|
+ foreach (var baseConnector in connectors)
|
|
|
+ {
|
|
|
+ if (!baseConnector.Searchable())
|
|
|
+ continue;
|
|
|
+ var refConnectors = baseConnector.GetReferenceConnectors()
|
|
|
+ .Where(c => ConnectorType.Physical.HasFlag(c.ConnectorType)).ToList();
|
|
|
+ foreach (var refConnector in refConnectors)
|
|
|
+ {
|
|
|
+ var refElement = refConnector.Owner;
|
|
|
+ if (useIds.Any(id => id == refElement.Id.IntegerValue))
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //初始化当前节点,未必一定加入集合,为了下面代码书写方便,先进性初始化
|
|
|
+ ElementTreeNode currentNode = new ElementTreeNode()
|
|
|
+ {
|
|
|
+ Current = refElement,
|
|
|
+ StartLocation = refConnector.Origin
|
|
|
+ };
|
|
|
+ if (refElement is MEPCurve mepCurve)
|
|
|
+ {
|
|
|
+ //优先判定系统,再进行立管相关逻辑的处理;如果系统不兼容则直接退出遍历
|
|
|
+ //var systemName=mepCurve.GetSystemTypeName();
|
|
|
+ if (endConditon != null && endConditon(mepCurve))
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (SystemCalcUtil.IsStart(mepCurve))
|
|
|
+ {
|
|
|
+ currentNode.ElementTypeName = AcType.MarkStandPipe;
|
|
|
+ etn.AddChild(currentNode);
|
|
|
+ useIds.Add(refElement.Id.IntegerValue);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (refElement is FamilyInstance fi)
|
|
|
+ {
|
|
|
+ //非管线,遇到结束标志,加入当前子节点,但不在进行递归;
|
|
|
+ if (SystemCalcUtil.IsStart(fi))
|
|
|
+ {
|
|
|
+ currentNode.ElementTypeName = AcType.Valve;
|
|
|
+ etn.AddChild(currentNode);
|
|
|
+ useIds.Add(refElement.Id.IntegerValue);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //useIds的控制:跳出时,直接加入UseIds。继续遍历的,在遍历函数中加入
|
|
|
+ etn.AddChild(currentNode);
|
|
|
+ BuildSystemNode(currentNode, domain, useIds, endConditon);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+
|
|
|
+ #region 创建绘图数据相关
|
|
|
+ /// <summary>
|
|
|
+ /// 构件绘图数据
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="etn"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static SystemDrawItems CreateDrawing(ElementTreeNode etn)
|
|
|
+ {
|
|
|
+ #region 描述
|
|
|
+ /*
|
|
|
+ *读取几何信息
|
|
|
+ * 1、管道,管件直接按connector连线获取。
|
|
|
+ * 2、设备,可能出现多个connector,确定有效的连线;
|
|
|
+ * 最终:如果是管道,通过本身的connector生成线。如果是familyInstance通过定位点连接,父节点和子节点
|
|
|
+ * 3、具体名字相关内容,后续操作中添加
|
|
|
+ */
|
|
|
+ #endregion
|
|
|
+ List<SystemCurveItem> curveItems = new List<SystemCurveItem>();
|
|
|
+ List<SystemPointItem> pointItems = new List<SystemPointItem>();
|
|
|
+ Queue<ElementTreeNode> nodeQueue = new Queue<ElementTreeNode>() ;
|
|
|
+ nodeQueue.Enqueue(etn);
|
|
|
+ while (nodeQueue.Any())
|
|
|
+ {
|
|
|
+ #region 控制验证
|
|
|
+ var currentNode = nodeQueue.Dequeue();
|
|
|
+ if (currentNode == null)
|
|
|
+ continue;
|
|
|
+ var element = currentNode.Current;
|
|
|
+ if (element == null)
|
|
|
+ continue;
|
|
|
+ #endregion
|
|
|
+ if (element is MEPCurve mepCurve)
|
|
|
+ {
|
|
|
+ #region 联通线处理
|
|
|
+ Curve curve = mepCurve.GetCurve();
|
|
|
+ var xyzs = curve.Tessellate().Select(xyz => xyz.XYZToPoint());
|
|
|
+ SystemCurveItem curveItem = new SystemCurveItem();
|
|
|
+ curveItem.Points.AddRange(xyzs.ToList());
|
|
|
+ curveItem.RefId = element.Id.IntegerValue;
|
|
|
+ curveItems.Add(curveItem);
|
|
|
+ #endregion
|
|
|
+ #region 点信息处理
|
|
|
+
|
|
|
+ if (SystemCalcUtil.IsStart(mepCurve))
|
|
|
+ {
|
|
|
+ SystemPointItem point = new SystemPointItem();
|
|
|
+ point.Point = mepCurve.GetCurve().StartPoint().XYZToPoint();
|
|
|
+ point.RefId = mepCurve.Id.IntegerValue;
|
|
|
+ point.IsVirtual = true;
|
|
|
+ point.EquipmentType = PointItemType.StandPipe.ToString();
|
|
|
+ pointItems.Add(point);
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+ }
|
|
|
+ else if (element is FamilyInstance fiEq)
|
|
|
+ {
|
|
|
+ #region 获取引用点
|
|
|
+ List<XYZ> usePoints = new List<XYZ>();
|
|
|
+ if (currentNode.StartLocation != null)
|
|
|
+ {
|
|
|
+ usePoints.Add(currentNode.StartLocation);
|
|
|
+ }
|
|
|
+ foreach (ElementTreeNode childNode in currentNode.Nodes)
|
|
|
+ {
|
|
|
+ var usePoint = childNode.StartLocation;
|
|
|
+ if (usePoint != null)
|
|
|
+ {
|
|
|
+ usePoints.Add(usePoint);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+ var location = element.GetBoxCenter().XYZToPoint();
|
|
|
+ #region 根据定位点并创建线条
|
|
|
+
|
|
|
+ foreach (var usePoint in usePoints)
|
|
|
+ {
|
|
|
+ SystemCurveItem curveItem = new SystemCurveItem();
|
|
|
+ curveItem.Points.Add(location);
|
|
|
+ curveItem.Points.Add(usePoint.XYZToPoint());
|
|
|
+ curveItem.RefId = element.Id.IntegerValue;
|
|
|
+ curveItems.Add(curveItem);
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 判断是否是设备
|
|
|
+ //先初始化不一定加入
|
|
|
+ SystemPointItem point = new SystemPointItem();
|
|
|
+ point.Point = location;
|
|
|
+ point.RefId = fiEq.Id.IntegerValue;
|
|
|
+ point.BimId = element.GetBimId();
|
|
|
+ if (MBIInfoUtil.IsEquipment(fiEq))
|
|
|
+ {
|
|
|
+ point.Name = string.Empty;
|
|
|
+ point.EquipmentType = PointItemType.Equipment.ToString();
|
|
|
+ pointItems.Add(point);
|
|
|
+ }
|
|
|
+ else if (SystemCalcUtil.IsStart(fiEq))
|
|
|
+ {
|
|
|
+ point.Name = string.Empty;
|
|
|
+ point.EquipmentType = PointItemType.StartValve.ToString(); ;
|
|
|
+ point.IsVirtual = true;
|
|
|
+ pointItems.Add(point);
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+ }
|
|
|
+ else if (element is Space)
|
|
|
+ {
|
|
|
+ SystemPointItem point = new SystemPointItem();
|
|
|
+ point.Point = element.GetLocationPoint().XYZToPoint();
|
|
|
+ point.RefId = element.Id.IntegerValue;
|
|
|
+ point.EquipmentType = PointItemType.Space.ToString();
|
|
|
+ point.IsVirtual = true;
|
|
|
+ pointItems.Add(point);
|
|
|
+ }
|
|
|
+ currentNode.Nodes.ForEach(e => nodeQueue.Enqueue(e));
|
|
|
+ }
|
|
|
+
|
|
|
+ SystemDrawItems drawItems = new SystemDrawItems();
|
|
|
+ drawItems.Curves = curveItems;
|
|
|
+ drawItems.Points = pointItems;
|
|
|
+ return drawItems;
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 创建关系数据相关
|
|
|
+ public static List<EquipmentNode> CreateRelation(ElementTreeNode etn)
|
|
|
+ {
|
|
|
+ #region 描述
|
|
|
+ /*
|
|
|
+ * 1、将树形结构初步处理,修剪成存留设备之间的关系
|
|
|
+ */
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ return ConvertEquipmentNodes(etn);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 将elment树转换成设备节点类
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="etn"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private static List<EquipmentNode> ConvertEquipmentNodes(ElementTreeNode etn)
|
|
|
+ {
|
|
|
+ List<EquipmentNode> nodes = new List<EquipmentNode>();
|
|
|
+ if (TryGetNode(etn.Current,out EquipmentNode outNode))
|
|
|
+ {
|
|
|
+ nodes.Add(outNode);
|
|
|
+ return nodes;
|
|
|
+ }
|
|
|
+ foreach (var elementTreeNode in etn.Nodes)
|
|
|
+ {
|
|
|
+ nodes.AddRange(ConvertEquipmentNodes(elementTreeNode));
|
|
|
+ }
|
|
|
+ return nodes;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 获取element对应节点
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="element">输入element</param>
|
|
|
+ /// <param name="outNode">成功获取时,node真实值</param>
|
|
|
+ /// <returns>成功获取</returns>
|
|
|
+ private static bool TryGetNode(Element element,out EquipmentNode outNode)
|
|
|
+ {
|
|
|
+ bool flag = false;
|
|
|
+ EquipmentNode node = new EquipmentNode();
|
|
|
+ node.RevitId = element.Id.IntegerValue;
|
|
|
+ node.BimId = element.GetBimId();
|
|
|
+ if (element is Space space)
|
|
|
+ {
|
|
|
+ node.Category = PointItemType.Space.ToString();
|
|
|
+ }
|
|
|
+ else if (element is Pipe&& SystemCalcUtil.IsStart(element))
|
|
|
+ {
|
|
|
+ node.Category = PointItemType.StandPipe.ToString();
|
|
|
+ }
|
|
|
+ else if (element is FamilyInstance)
|
|
|
+ {
|
|
|
+ if (MBIInfoUtil.IsEquipment(element))
|
|
|
+ {
|
|
|
+ node.Category = PointItemType.Equipment.ToString();
|
|
|
+ }
|
|
|
+ else if (SystemCalcUtil.IsStart(element))
|
|
|
+ {
|
|
|
+ node.Category = PointItemType.StartValve.ToString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ flag = !string.IsNullOrEmpty(node.Category);
|
|
|
+ outNode = flag ? node : null;
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+ }
|
|
|
+}
|