浏览代码

xls:设备信息加载

xulisong 6 年之前
父节点
当前提交
a0f9040281

+ 49 - 1
MBI/SAGA.DotNetUtils/Data/EdgesArray/EdgesArrayGraphUtil.cs

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
 
 namespace SAGA.DotNetUtils.Data
 {
-    public class EdgesArrayGraphUtil
+    public static class EdgesArrayGraphUtil
     {
         /// <summary>
         /// 串联处理
@@ -160,5 +160,53 @@ namespace SAGA.DotNetUtils.Data
 
                 return edgesArray;
         }
+
+        public static List<PathNodes<V, E>> GetPaths<V, VD, E, ED>(this EdgesArrayGraph<V, VD, E, ED> edgesArray, V start, Predicate<V> endPredicate) where V : EAVertex<VD>, new() where E : EAEdge<ED>, new()
+        {
+            List<PathNodes<V, E>> list = new List<PathNodes<V, E>>();
+            var edges = edgesArray.GetOutEdges(start.Id);
+            foreach (var edge in edges)
+            {
+                var anotherId = edge.GetAnotherVertex(start.Id);
+                var v=edgesArray.FindVertex(anotherId)?.GetRoot() as V;
+                if (v == null)
+                    continue;
+                if (endPredicate != null && endPredicate(v))
+                {
+                    PathNodes<V, E> nodes = new PathNodes<V, E>();
+                    nodes.Add(new PathNode<V, E>(v, edge));
+                    list.Add(nodes);
+                }
+                else
+                {
+                    var nextList = GetPaths(edgesArray, v, endPredicate);
+                    foreach (var next in nextList)
+                    {
+                        next.Insert(0, new PathNode<V, E>(v, edge));
+                    }
+                }
+            }
+            return list;
+        }
     }
+
+    public class PathNode<V,E>
+    {
+        public PathNode()
+        {
+
+        }
+
+        public PathNode(V end, E path)
+        {
+            NextNode = end;
+            Path = path;
+        }
+
+        public V NextNode { get; set; }
+        public E Path { get; set; }
+    }
+
+    public class PathNodes<V,E>:List<PathNode<V, E>>
+    { }
 }

+ 25 - 0
MBI/SAGA.GplotRelationComputerManage/ColdRoom/EquipmentItem.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.ComponentModel;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -32,6 +33,11 @@ namespace SAGA.GplotRelationComputerManage
         /// 是否是虚构的节点
         /// </summary>
         public bool IsVirtual { get; set; } 
+
+        /// <summary>
+        /// 设备类型
+        /// </summary>
+        public ElementType ElementType { get; set; }
     }
 
     /// <summary>
@@ -92,4 +98,23 @@ namespace SAGA.GplotRelationComputerManage
             return null;
         }
     }
+    /// <summary>
+    /// 设备类型
+    /// </summary>
+    [Flags]
+    public enum ElementType
+    {
+        [Description("设备")]
+        Equipment=1,
+        [Description("空间")]
+        Space=1<<1,
+        [Description("立管")]
+        VerticalPipe = 1 << 2,
+        [Description("开始阀门")]
+        StartValve = 1 << 3,
+        [Description("其他")]
+        Other = 1 << 4,
+
+        Virtual=VerticalPipe|StartValve|Other
+    }
 }

+ 8 - 3
MBI/SAGA.GplotRelationComputerManage/RevitSystemParse/Handler/GplotGraphParse.cs

@@ -33,6 +33,7 @@ namespace SAGA.GplotRelationComputerManage
         /// </summary>
         public GplotGraphSetting Setting { get; private set; }
         #endregion
+        #region 创建拓扑图信息
         /// <summary>
         /// 创建拓扑结构图
         /// </summary>
@@ -65,7 +66,8 @@ namespace SAGA.GplotRelationComputerManage
             //边处理
             ArrangeEdge(graph);
             return graph;
-        }
+        } 
+        #endregion
         #region 解析原始图
         /// <summary>
         /// 创建原始的节点图,以起点元素为首个节点
@@ -146,6 +148,7 @@ namespace SAGA.GplotRelationComputerManage
                                 {
                                     item.Name = string.Format("空间{0}", location.ToString());
                                 }
+                                item.ElementType = ElementType.Space;
                                 systemVertex.SetEquipment(item);
                                 break;
                             }
@@ -159,18 +162,20 @@ namespace SAGA.GplotRelationComputerManage
                 #region 真实设备处理
                 item.Id = useElement.Id.ToString();
                 item.BimId = useElement.GetBimId();
+                item.Name = useElement.GetFamily()?.Name;
                 if (MBIInfoUtil.IsEquipment(useElement))
                 {
                     systemVertex.CanCombine = false;
+                    item.ElementType = ElementType.Equipment;
                     systemVertex.SetEquipment(item);
                     continue;
                 }
                 if (SystemCalcUtil.IsStartValve(useElement))
                 {
                     systemVertex.CanCombine = false;
-                    item.IsVirtual = true;
+                    item.IsVirtual = true;           
+                    item.ElementType = ElementType.Equipment;
                     systemVertex.SetEquipment(item);
-                    item.Name = useElement.GetFamily()?.Name;
                     continue;
                 }
                 #endregion

+ 86 - 2
MBI/SAGA.GplotRelationComputerManage/SystemRelation/Common/SystemParseManager.cs

@@ -12,10 +12,12 @@ using System.Windows.Media.Media3D;
 using Autodesk.Revit.DB;
 using Autodesk.Revit.DB.Mechanical;
 using Autodesk.Revit.DB.Plumbing;
+using SAGA.DotNetUtils.Data;
 using SAGA.Models;
 using SAGA.Models.GplotElement;
 using SAGA.Models.Graphs;
 using SAGA.RevitUtils;
+using SAGA.RevitUtils.Data.Graph;
 using SAGA.RevitUtils.Extends;
 using SAGA.RevitUtils.MEP;
 
@@ -522,7 +524,7 @@ namespace SAGA.GplotRelationComputerManage
                     SystemPointItem point = new SystemPointItem();
                     point.Point = vertex.Location;
                     point.Name = vertex.Name;
-                    point.IsVirtual = vertex.VertexType != Models.GplotElement.VertexType.Solid;
+                    point.IsVirtual = vertex.VertexType != VertexType.Solid;
                     pointItems.Add(point);
                     continue;
                 }
@@ -545,8 +547,90 @@ namespace SAGA.GplotRelationComputerManage
             drawItems.Points = pointItems;
             return drawItems;
         }
+        /// <summary>
+        /// 创建机房绘图数据
+        /// </summary>
+        /// <param name="graphs"></param>
+        /// <returns></returns>
+        public static List<GNodeGraph> CreateRoomDrawing(List<SystemGraph> graphs)
+        {
+            List<GNodeGraph> nodeGraphs = new List<GNodeGraph>();
+            foreach (var graph in graphs)
+            {
+                var edges = graph.GeFirstStateEdges();
+                GNodeGraph nodeGraph = new GNodeGraph();
+                foreach (var elementsEdge in edges)
+                {
+                    GNodePath path = new GNodePath();
+                    path.StartNodeId = elementsEdge.StartVertex;
+                    path.EndNodeId = elementsEdge.EndVertex;
+                    nodeGraph.Paths.Add(path);
+                }
+                var vertexes = graph.GetBootVertexs();
+                foreach (var elementsVertex in vertexes)
+                {
+                    GNode node = new GNode();
+                    node.SetId(elementsVertex.Id);
+                    var equipmentItem = elementsVertex.GetEquipment();
+                    if (equipmentItem != null)
+                    {
+                        node.Name = equipmentItem.Name;
+                    }
+                    nodeGraph.Nodes.Add(node);
+                }
+                nodeGraphs.Add(nodeGraph);
+            }
+            return nodeGraphs;
+        }
+        /// <summary>
+        /// 创建机房图关系
+        /// </summary>
+        /// <param name="graphs"></param>
+        /// <returns></returns>
+        public static List<EquipmentRelation> CreateRoomRelation(List<SystemGraph> graphs)
+        {
+            List<EquipmentRelation> relations = new List<EquipmentRelation>();
+            foreach (var graph in graphs)
+            {
+                var sytemVertexes = graph.GetBootVertexs().Where(v => v.IsEquipment());
+                var currentRelation = new List<EquipmentRelation>();
+                foreach (SystemVertex vertex in sytemVertexes)
+                {
+
+                    var paths = graph.GetPaths(vertex, v => v.IsEquipment());
+                    foreach (var path in paths)
+                    {
+                        if (path == null)
+                        {
+                            continue;
+                        }
+
+                        var firstEdge = path.FirstOrDefault()?.Path;
+                        var lastNode = path.LastOrDefault()?.NextNode;
+                        if (lastNode == null)
+                        {
+                            continue;
+                        }
+
+                        var tempRelation = new EquipmentRelation(vertex.GetEquipment(), lastNode.GetEquipment());
+                        if (currentRelation.Any(r => r.Id == tempRelation.Id))
+                        {
+                            continue;
+                        }
+
+                        string category = firstEdge?.EdgeCategory ?? string.Empty;
+                        tempRelation.LinkType = category;
+                        currentRelation.Add(tempRelation);
+                    }
+                }
+
+                relations.AddRange(currentRelation);
+            }
+            return relations;
+        }
+
         #endregion
-    }
+        }
 
     /// <summary>
     /// 点位置比较相关

+ 120 - 5
MBI/SAGA.GplotRelationComputerManage/SystemRelation/FloorSystemItem.cs

@@ -271,7 +271,7 @@ namespace SAGA.GplotRelationComputerManage
 
             #region 解析机房数据
 
-            var useEquipments = ParseMachineRoomData(context, relationSetting, roomStartElements);
+            var useEquipments = ParseMachineRoomData2(context, relationSetting, roomStartElements);
             useEquipments = useEquipments.Distinct().ToList();
             #endregion
 
@@ -552,7 +552,42 @@ namespace SAGA.GplotRelationComputerManage
             var arrays = parse.Execute(useStartElements);
             arrays.RemoveAll(c => c.GetAvailableVertexes(null).All(v => !v.IsRealEquipment()));
 
-       
+            #region 加载设备显示信息
+            foreach (var elementEdgesArray in arrays)
+            {
+                var vertexes = elementEdgesArray.Vertexes.Where(v => v.Children.Count == 0);
+                foreach (var elementsVertex in vertexes)
+                {
+                    var equipmentItem = elementsVertex.GetEquipment();
+                    if (equipmentItem == null)
+                    {
+                        continue;
+                    }
+                    if (string.IsNullOrWhiteSpace(equipmentItem.BimId))
+                    {
+                        continue;
+                    }
+                    if (equipmentItem.ElementType == ElementType.Space)
+                    {
+                        var spaceIem = context.Rooms.GetItem(equipmentItem.BimId);
+                        if (spaceIem != null)
+                        {
+                            equipmentItem.Name = spaceIem.Name;
+                        }
+                    }
+                    else if (equipmentItem.ElementType == ElementType.Equipment)
+                    {
+                        var equipment = context.EquipmentItems.GetItem(equipmentItem.BimId);
+                        if (equipment != null)
+                        {
+                            equipmentItem.Name = equipment.Name;
+                        }
+                    }
+                }
+
+            }
+            #endregion
+
             #region 生成图形数据
             ColdRoomManager manager = new ColdRoomManager();
             var doc = manager.CreateDocument(new List<ElementEdgesArray>(arrays));
@@ -575,20 +610,100 @@ namespace SAGA.GplotRelationComputerManage
                 node.To = ConverEquipmentNode(item.EquipmentItem2, context); 
                 node.RelationType = item.LinkType;
                 relationRecord.RelationItems.Add(node);
-
-
                 var newIds = new List<string>() {item.EquipmentItem1.Id, item.EquipmentItem2.Id};
                 useEquipments.AddRange(newIds);
+            }
+            context[relationType].MachineRoomRelationRecords.Add(relationRecord);
+            #endregion
 
+            return useEquipments;
+
+        }
+        /// <summary>
+        /// 解析机房数据
+        /// </summary>
+        /// <param name="context"></param>
+        /// <param name="relationSetting"></param>
+        /// <param name="startElements"></param>
+        private List<string> ParseMachineRoomData2(SystemComputerContext context, RelationTypeShell relationSetting,
+            List<Element> startElements)
+        {
+            /*
+             *1、解析过程中尽量少处理和后续相关的数据
+             * 2、设备整理,带缓存的设备信息读取
+             */
+            List<string> useEquipments = new List<string>();
+            var relationType = relationSetting.RelationItem.Type;
+            GplotGraphParse parse = new GplotGraphParse(new GplotGraphSetting(relationSetting));
+            List<Element> useStartElements = new List<Element>(startElements);
+            var graphs = parse.CreateGplotGraphs(useStartElements);
+            graphs.RemoveAll(c => c.Vertexes.All(v => !v.IsRealEquipment()));
+
+            #region 加载设备显示信息
+            foreach (var elementEdgesArray in graphs)
+            {
+                var vertexes = elementEdgesArray.Vertexes.Where(v => v.Children.Count == 0);
+                foreach (var elementsVertex in vertexes)
+                {
+                    var equipmentItem = elementsVertex.GetEquipment();
+                    if (equipmentItem == null)
+                    {
+                        continue;
+                    }
+                    if (string.IsNullOrWhiteSpace(equipmentItem.BimId))
+                    {
+                        continue;
+                    }
+                    if (equipmentItem.ElementType == ElementType.Space)
+                    {
+                        var spaceIem = context.Rooms.GetItem(equipmentItem.BimId);
+                        if (spaceIem != null)
+                        {
+                            equipmentItem.Name = spaceIem.Name;
+                        }
+                    }
+                    else if (equipmentItem.ElementType == ElementType.Equipment)
+                    {
+                        var equipment = context.EquipmentItems.GetItem(equipmentItem.BimId);
+                        if (equipment != null)
+                        {
+                            equipmentItem.Name = equipment.Name;
+                        }
+                    }
+                }
 
             }
+            #endregion
+
+            #region 生成图形数据
+            var drawData = SystemParseManager.CreateRoomDrawing(graphs);           
+            MachineRoomDrawRecord record = new MachineRoomDrawRecord();
+            record.RelationName = relationSetting.RelationItem.Name;
+            record.FloorName = MBIInfoUtil.GetFloorNameByLevel(UseLevel.Name);
+            record.NodePaths = drawData;
+            context[relationType].MachineRoomDrawRecords.Add(record);
+            #endregion
+
+            #region 生成关系数据
+            var relations = SystemParseManager.CreateRoomRelation(graphs);
+            MachineRoomRelationRecord relationRecord = new MachineRoomRelationRecord();
+            relationRecord.RelationName = relationSetting.RelationItem.Name;
+            foreach (var item in relations)
+            {
+                var node = new BinaryRelationItem();
+                node.From = ConverEquipmentNode(item.EquipmentItem1, context);
+                node.To = ConverEquipmentNode(item.EquipmentItem2, context);
+                node.RelationType = item.LinkType;
+                relationRecord.RelationItems.Add(node);
+                var newIds = new List<string>() { item.EquipmentItem1.Id, item.EquipmentItem2.Id };
+                useEquipments.AddRange(newIds);
+            }
             context[relationType].MachineRoomRelationRecords.Add(relationRecord);
             #endregion
 
             return useEquipments;
 
         }
-
         private EquipmentNode ConverEquipmentNode(EquipmentItem item, SystemComputerContext context)
         {
             EquipmentNode result = new EquipmentNode();

+ 6 - 1
MBI/SAGA.GplotRelationComputerManage/SystemRelation/ServerData/MachineRoomDrawRecord.cs

@@ -10,6 +10,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using SAGA.Models.Graphs;
 
 namespace SAGA.GplotRelationComputerManage
 {
@@ -21,6 +22,7 @@ namespace SAGA.GplotRelationComputerManage
         public MachineRoomDrawRecord()
         {
             DrawIems = new SystemDrawItems();
+            NodePaths = new List<GNodeGraph>();
         }
         /// <summary>
         /// 楼层名称
@@ -34,6 +36,9 @@ namespace SAGA.GplotRelationComputerManage
         /// 绘图数据
         /// </summary>
         public SystemDrawItems DrawIems { get; set; }
-      
+        /// <summary>
+        /// 绘图路径
+        /// </summary>
+        public List<GNodeGraph> NodePaths { get; set; }
     }
 }