瀏覽代碼

xls:探索新的整理流向的方法

xulisong 6 年之前
父節點
當前提交
aec834e06f

+ 158 - 10
MBI/SAGA.GplotRelationComputerManage/RevitSystemParse/Handler/GplotGraphParse.cs

@@ -101,7 +101,16 @@ namespace SAGA.GplotRelationComputerManage
             */
             #endregion
             AttachVertexInfo(graph);
-            CombineVertex(graph);
+            var newCount = graph.GetBootVertexs().Count;
+            var oldCount = 0;
+            do
+            {
+               oldCount = newCount;
+               CombineVertex(graph);
+               newCount = graph.GetBootVertexs().Count;
+                //数量不变,算处理完
+            } while (oldCount != newCount);
+           
         }
         /// <summary>
         /// 附加节点信息
@@ -350,8 +359,9 @@ namespace SAGA.GplotRelationComputerManage
             }
             #endregion
             #region 确定开始点
-            List<string> edgeIds = new List<string>();
-            List<string> vertexIds = new List<string>();
+            HashSet<string> edgeIds = new HashSet<string>();
+            //点遍历id区分系 flowType信息
+            HashSet<string> vertexIds = new HashSet<string>();
             foreach (var systemVertex in vertexes)
             {
                 if (vertexIds.Contains(systemVertex.Id))
@@ -383,14 +393,16 @@ namespace SAGA.GplotRelationComputerManage
                 }
                 Queue<SystemVertex> queueVertexes = new Queue<SystemVertex>();
                 queueVertexes.Enqueue(systemVertex);
+                Func<string, string> commonId = (str) =>  useFlowType + "_" + str ;
                 while (queueVertexes.Any())
                 {
                     var currentVertex = queueVertexes.Dequeue();
-                    if (vertexIds.Contains(currentVertex.Id))
+                    //普通节点Id
+                    if (vertexIds.Contains(commonId(currentVertex.Id)))
                     {
                         continue;
                     }
-                    vertexIds.Add(currentVertex.Id);
+                    vertexIds.Add(commonId(currentVertex.Id));
                     
                     var edges = graph.GetInEdges(currentVertex.Id);
                     foreach (var systemEdge in edges)
@@ -412,12 +424,9 @@ namespace SAGA.GplotRelationComputerManage
                         if ((isStart && systemEdge.ContainVertex(currentVertex.Id) == 1) || (!isStart && systemEdge.ContainVertex(currentVertex.Id) == 0))
                         {
                             systemEdge.Reverse();
-                        }
-
-                       
-                        if (!vertexIds.Contains(otherId))
+                        }                     
+                        if (!vertexIds.Contains(commonId(otherId)))
                         {
-
                             var nextVertex = graph.FindVertex(otherId);
                             if (nextVertex != null)
                             {
@@ -527,6 +536,145 @@ namespace SAGA.GplotRelationComputerManage
             }
             #endregion
         }
+
+        /// <summary>
+        /// 确定流向
+        /// </summary>
+        /// <param name="graph"></param>
+        private void DirectedEdge3(SystemGraph graph)
+        {
+            #region 加载边的系统信息
+            var originEdges = graph.Edges.Where(e => !e.Children.Any()).ToList();
+            foreach (var originEdge in originEdges)
+            {
+                var refElements = originEdge.Data;
+                //获取边系统类型
+                originEdge.SystemName = (refElements.FirstOrDefault(e => e is MEPCurve) as MEPCurve)?.GetSystemTypeName();
+                //根据系统类型和特殊设备确定旁通和补水;未完,待续
+                var systemItem = Setting.RelationTypeShell.GetFirstMatchSystem(originEdge.SystemName);
+                if (systemItem != null)
+                {
+                    originEdge.EdgeCategory = systemItem.ContainEdgeTypes.FirstOrDefault();
+                    originEdge.FlowType = systemItem.FlowType == FlowType.In ? 2 : 1;
+                }
+            }
+            #endregion
+
+            #region 描述
+            /*
+             * 1、查找遍历起点
+             * 2、根据起点遍历所有的节点,并调整节点的顺序
+             */
+            #endregion
+            #region 获取定义端点
+            var vertexes = graph.GetBootVertexs().Where(v => SystemCalcUtil.IsStartValveName(v.GetEquipment()?.Name)).ToList();
+            if (!vertexes.Any())
+                return;
+            //将顶点按前缀分组
+           // Group
+            Dictionary<string, List<SystemVertex>> dicVertexes = new Dictionary<string, List<SystemVertex>>();
+            foreach (var systemVertex in vertexes)
+            {
+                var tempEdges = graph.GetInEdges(systemVertex.Id);
+                if (tempEdges.Any())
+                {
+                    var item = systemVertex.GetEquipment();
+                    if (item == null)
+                    {
+                        continue;
+                    }
+                    if (tempEdges.Any(e => e.FlowType == 2))
+                    {
+                        item.Name = "出口" + item.Id;
+                    }
+                    else
+                    {
+                        item.Name = "入口" + item.Id;
+                    }
+                   // dicValues
+                }
+            }
+            #endregion
+            #region 确定开始点
+            HashSet<string> edgeIds = new HashSet<string>();
+            //点遍历id区分系 flowType信息
+            HashSet<string> vertexIds = new HashSet<string>();
+            foreach (var systemVertex in vertexes)
+            {
+                if (vertexIds.Contains(systemVertex.Id))
+                {
+                    continue;
+                }
+                bool isStart = true;
+
+                var currentVertexName = systemVertex.GetEquipment().Name;
+                if (string.IsNullOrWhiteSpace(currentVertexName))
+                {
+                    continue;
+                }
+
+                var useFlowType = 0;
+                if (currentVertexName.Contains("入口"))
+                {
+                    useFlowType = 1;
+                    isStart = true;
+                }
+                else if (currentVertexName.Contains("出口"))
+                {
+                    useFlowType = 2;
+                    isStart = false;
+                }
+                else
+                {
+                    continue;
+                }
+                Queue<SystemVertex> queueVertexes = new Queue<SystemVertex>();
+                queueVertexes.Enqueue(systemVertex);
+                Func<string, string> commonId = (str) => useFlowType + "_" + str;
+                while (queueVertexes.Any())
+                {
+                    var currentVertex = queueVertexes.Dequeue();
+                    //普通节点Id
+                    if (vertexIds.Contains(commonId(currentVertex.Id)))
+                    {
+                        continue;
+                    }
+                    vertexIds.Add(commonId(currentVertex.Id));
+
+                    var edges = graph.GetInEdges(currentVertex.Id);
+                    foreach (var systemEdge in edges)
+                    {
+                        if (systemEdge.FlowType != useFlowType)
+                        {
+                            continue;
+                        }
+                        if (edgeIds.Contains(systemEdge.Id))
+                        {
+                            continue;
+                        }
+                        var otherId = systemEdge.GetAnotherVertex(currentVertex.Id);
+                        if (vertexes.Any(v => v.Id == otherId))
+                        {
+                            continue;
+                        }
+                        edgeIds.Add(systemEdge.Id);
+                        if ((isStart && systemEdge.ContainVertex(currentVertex.Id) == 1) || (!isStart && systemEdge.ContainVertex(currentVertex.Id) == 0))
+                        {
+                            systemEdge.Reverse();
+                        }
+                        if (!vertexIds.Contains(commonId(otherId)))
+                        {
+                            var nextVertex = graph.FindVertex(otherId);
+                            if (nextVertex != null)
+                            {
+                                queueVertexes.Enqueue(nextVertex);
+                            }
+                        }
+                    }
+                }
+            }
+            #endregion
+        }
         #endregion
         #endregion
     }

+ 19 - 5
MBI/SAGA.GplotRelationComputerManage/SystemRelation/Common/SystemParseManager.cs

@@ -627,13 +627,27 @@ namespace SAGA.GplotRelationComputerManage
                     var equipmentItem = elementsVertex.GetEquipment();
                     if (equipmentItem != null)
                     {
-                        node.Name = equipmentItem.Name;
-                        var fi = elementsVertex.Data.FirstOrDefault(e => e is FamilyInstance);
-                        if (fi != null)
+                        node.Name = equipmentItem.Name;                      
+                    }
+                    var fi = elementsVertex.Data.FirstOrDefault(e => e is FamilyInstance);
+                    if (fi != null)
+                    {
+                        node.Location = fi.GetLocationPoint().XYZToPoint3D();
+                    }
+                    else
+                    {
+                        var mepCurve = elementsVertex.Data.FirstOrDefault(e => e is MEPCurve);
+                        if (mepCurve != null)
                         {
-                            node.Location = fi.GetLocationPoint().XYZToPoint3D();
+                            try
+                            {
+                                node.Location = mepCurve.GetLocationCurve().MiddlePoint().XYZToPoint3D();
+                            }
+                            catch (Exception)
+                            {
+                            }
                         }
-                      
+                        
                     }
                     nodeGraph.Nodes.Add(node);
                 }

+ 1 - 1
MBI/SAGA.RevitUtils/Data/Graph/SystemEdge.cs

@@ -39,7 +39,7 @@ namespace SAGA.RevitUtils.Data.Graph
         /// </summary>
         public string EdgeCategory { get; set; }
         /// <summary>
-        /// flowType[2表示从源流出,1表示流入源]
+        /// flowType[2表示从源流出,1表示流入源]
         /// </summary>
         public int FlowType { get; set; }
         #endregion