Explorar o código

xls:关联相关数据

xulisong %!s(int64=6) %!d(string=hai) anos
pai
achega
b730c996f2

BIN=BIN
MBI/MBIResource/BaseDB/MBIAssistData.db


+ 1 - 1
MBI/SAGA.DotNetUtils/Data/EdgesArray/EAElement.cs

@@ -18,7 +18,7 @@ namespace SAGA.DotNetUtils.Data
         /// <summary>
         /// 节点Id
         /// </summary>
-        public string Id { get; internal set; }
+        public string Id { get;  set; }
 
         /// <summary>
         /// 节点名称

+ 2 - 2
MBI/SAGA.DotNetUtils/Data/EdgesArray/EdgesArrayGraph.cs

@@ -31,7 +31,7 @@ namespace SAGA.DotNetUtils.Data
         /// 生成节点索引
         /// </summary>
         /// <returns></returns>
-        private string GenerateVertexIndex()
+        protected string GenerateVertexIndex()
         {
             return "V" + (++m_CurrentVertexIndex);
         }
@@ -39,7 +39,7 @@ namespace SAGA.DotNetUtils.Data
         /// 生成节点索引
         /// </summary>
         /// <returns></returns>
-        private string GenerateEdgeIndex()
+        protected string GenerateEdgeIndex()
         {
             return "E" + (++m_CurrentVertexIndex);
         }

+ 73 - 2
MBI/SAGA.DotNetUtils/Data/EdgesArray/EdgesArrayGraphUtil.cs

@@ -188,6 +188,58 @@ namespace SAGA.DotNetUtils.Data
             }
             return list;
         }
+        /// <summary>
+        /// 获取指定起点,到指定条件的节点路径信息;
+        /// </summary>
+        /// <typeparam name="V"></typeparam>
+        /// <typeparam name="VD"></typeparam>
+        /// <typeparam name="E"></typeparam>
+        /// <typeparam name="ED"></typeparam>
+        /// <param name="edgesArray"></param>
+        /// <param name="start"></param>
+        /// <param name="endPredicate"></param>
+        /// <returns></returns>
+        public static List<PathNodes<V, E>> GetPaths2<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()
+        {
+            PathNodes<V, E> prePath = new PathNodes<V, E>();
+            prePath.Add(new PathNode<V, E>(start, null));
+            var paths = InternalGetPaths(edgesArray, start, prePath, endPredicate);
+            paths.ForEach(p => p.RemoveAt(0));
+            return paths;
+        }
+
+        internal static List<PathNodes<V, E>> InternalGetPaths<V, VD, E, ED>(this EdgesArrayGraph<V, VD, E, ED> edgesArray, V start, PathNodes<V, E> prePath,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 (prePath.Count > 1 && prePath[prePath.Count - 2].NextNode.Id == start.Id)
+                {
+                    continue; 
+                }
+                if ((prePath.Any(n => n.NextNode.Id == start.Id)) ||(endPredicate != null && endPredicate(v)))
+                {
+                    PathNodes<V, E> nodes = new PathNodes<V, E>(prePath);
+                    nodes.Add(new PathNode<V, E>(v, edge));
+                    list.Add(nodes);
+                }
+                else
+                {
+                    var newPath = new PathNodes<V, E>(prePath);
+                    newPath.Add(new PathNode<V, E>(v, edge));
+                    var nextList = InternalGetPaths(edgesArray, v, newPath, endPredicate);
+                    list.AddRange(nextList);
+                }
+            }
+            return list;
+        }
     }
 
     public class PathNode<V,E>
@@ -205,8 +257,27 @@ namespace SAGA.DotNetUtils.Data
 
         public V NextNode { get; set; }
         public E Path { get; set; }
+
+        /// <summary>
+        /// 虚拟的开始节点,当路径为null时,认为是开始节点
+        /// </summary>
+        /// <returns></returns>
+        public bool IsStart()
+        {
+            return Path == null;
+        }
     }
 
-    public class PathNodes<V,E>:List<PathNode<V, E>>
-    { }
+    public class PathNodes<V, E> : List<PathNode<V, E>>
+    {
+        public PathNodes()
+        {
+
+        }
+
+        public PathNodes(IEnumerable<PathNode<V, E>> nodes)
+        {
+            this.AddRange(nodes);
+        }
+    }
 }

+ 74 - 0
MBI/SAGA.DotNetUtils/Data/EdgesArray/SimpleGraph.cs

@@ -0,0 +1,74 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:SimpleGraph
+ * 作者:xulisong
+ * 创建时间: 2019/2/25 11:56:28
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using NPOI.SS.Formula.Functions;
+
+namespace SAGA.DotNetUtils.Data
+{
+    public class SimpleVertex<VD>:EAVertex<VD>
+    {
+        public SimpleVertex()
+        {
+
+        }
+        public SimpleVertex(VD d)
+        {
+            this.Data = d;
+        }
+    }
+
+    public class SimpleEdge<ED> : EAEdge<ED>
+    {
+        public SimpleEdge()
+        {
+        }
+
+        public SimpleEdge(ED data)
+        {
+            this.Data = data;
+        }
+
+        public SimpleEdge(string startId, string endId)
+        {
+            this.StartVertex = startId;
+            this.EndVertex = endId;
+        }
+    }
+
+    public class SimpleGraph<VD,ED>: EdgesArrayGraph<SimpleVertex<VD>, VD, SimpleEdge<ED>, ED>
+    {
+        /*
+         * 所谓简单:
+         * 1、可以放弃自定义点的Id,而不必自动生成;点传入的Id,可以被使用,而不是自动生成
+         */
+        public override SimpleVertex<VD> AddVertex(SimpleVertex<VD> vertex)
+        {
+            var existVertex = FindVertex(vertex);
+            if (existVertex != null)
+            {
+                existVertex.Merge(vertex);
+                return existVertex;
+            }
+
+            if (!vertex.ValidId)
+            {
+                vertex.Id = GenerateVertexIndex();
+            }
+            this.m_Vertexes.Add(vertex);
+            return vertex;
+        }
+    }
+
+    public class SimpleObjectGraph: SimpleGraph<object, object>
+    {
+    }
+}

+ 1 - 0
MBI/SAGA.DotNetUtils/SAGA.DotNetUtils.csproj

@@ -281,6 +281,7 @@
     <Compile Include="Data\EdgesArray\EdgesArrayGraph.cs" />
     <Compile Include="Data\EdgesArray\EdgesArrayGraphUtil.cs" />
     <Compile Include="Data\EdgesArray\ForwardStar.cs" />
+    <Compile Include="Data\EdgesArray\SimpleGraph.cs" />
     <Compile Include="Data\EdgesArray\VisitControl.cs" />
     <Compile Include="Data\FlagDecorator.cs" />
     <Compile Include="Data\InitAttribute.cs" />

+ 100 - 153
MBI/SAGA.GplotManage/SystemRelation/RelationDataUtil.cs

@@ -78,8 +78,6 @@ namespace SAGA.GplotManage
             var verticalSets = relationData.VerticalRelationRecords;
             var cacheFloorDatas = new List<BinaryRelationItem>(floorRelations);
             List < StringFlag <VerticalRelationRecord>> verticalNodes = new List<StringFlag<VerticalRelationRecord>>();
-            Dictionary<string,EquipmentNode> nodes =new Dictionary<string, EquipmentNode>();
-            List<EAEdge<string>> edges = new List<EAEdge<string>>();
             #region 初始化立管节点
             foreach (var verticalRelationRecord in verticalSets)
             {
@@ -89,14 +87,102 @@ namespace SAGA.GplotManage
             }
             #endregion
             #region 构建端部临时边集
-            for (int i = cacheFloorDatas.Count - 1; i >= 0; i--)
+            var endGraph = CreateGraph(verticalNodes, cacheFloorDatas);
+            #endregion
+            var roomItems = machineRoomData.SelectMany(c => c.RelationItems).ToList();
+            var sourceGraph = CreateGraph(verticalNodes, roomItems);
+            //连接类型,以机房端类型为基准
+            #region 机房和平面关联
+            foreach (var verticalNode in verticalNodes)
+            {
+                var startNode = sourceGraph.FindVertex(verticalNode.Flag);
+                #region 源路径
+                var sourcePathNodes = sourceGraph.GetPaths2(startNode, end =>
+                     {
+                         if (end.Data is EquipmentNode eqNode)
+                         {
+                             return eqNode.IsRealEquipment;
+                         }
+
+                         return false;
+                     });
+                #endregion
+                #region 端路径
+                var endPathNodes = endGraph.GetPaths2(startNode, end =>
+                      {
+                          if (end.Data is EquipmentNode eqNode)
+                          {
+                              return eqNode.IsRealEquipment;
+                          }
+
+                          return false;
+                      });
+                #endregion
+
+                List<EquipmentNode> endNodes = new List<EquipmentNode>();
+                foreach (var endPathNode in endPathNodes)
+                {
+                    var useEdge = endPathNode.LastOrDefault();
+                    if (useEdge == null)
+                        continue;
+                    if (useEdge.NextNode.Data is EquipmentNode node)
+                    {
+                        endNodes.Add(node);
+                    }                  
+                }
+
+                foreach (var sourcePathNode in sourcePathNodes)
+                {
+                    var useEdge = sourcePathNode.LastOrDefault();
+                    if (useEdge == null)
+                        continue;
+                    EquipmentNode useNode = null;
+                    if (useEdge.NextNode.Data is EquipmentNode node)
+                    {
+                        useNode=node;
+                    }
+                    else
+                    {
+                        continue;
+                    }
+                    foreach (var equipmentNode in endNodes)
+                    {
+                        BinaryRelationItem item = new BinaryRelationItem();
+                        item.RelationType = (useEdge.Path.Data as string) ?? string.Empty;
+                        if (useEdge.Path.ContainVertex(useEdge.NextNode.Id) == 0)
+                        {
+                            item.From = useNode;
+                            item.To = equipmentNode;
+                        }
+                        else
+                        {
+                            item.From = equipmentNode;
+                            item.To = useNode;
+                        }
+                        result.Add(CreateRelationData(item));
+                    }
+                }
+              
+                
+            }
+          
+            return result;
+
+            #endregion
+        }
+
+
+        private static SimpleObjectGraph CreateGraph(List<StringFlag<VerticalRelationRecord>> verticalNodes, List<BinaryRelationItem> sourceRelations)
+        {
+            SimpleObjectGraph graph = new SimpleObjectGraph();
+            #region 构建临时边集
+            for (int i = sourceRelations.Count - 1; i >= 0; i--)
             {
-                var currentRecord = cacheFloorDatas[i];
-                //找到立管,创建立管节点。不包含立管,直接将关联关系加入
+                var currentRecord = sourceRelations[i];
                 var startId = currentRecord.From.BimId;
                 var endId = currentRecord.To.BimId;
-                nodes[startId] = currentRecord.From;
-                nodes[endId] = currentRecord.To;
+                graph.AddVertex(new SimpleVertex<object>(currentRecord.From) {Id = startId});
+                graph.AddVertex(new SimpleVertex<object>(currentRecord.To) { Id = endId });
                 string replaceStart = null;
                 string replaceEnd = null;
                 for (int j = 0; j < verticalNodes.Count; j++)
@@ -104,167 +190,28 @@ namespace SAGA.GplotManage
                     if (replaceStart != null && replaceEnd != null)
                         break;
                     var currentVertical = verticalNodes[i];
-
                     if (currentVertical.Instance.RelationItems.Contains(startId))
                     {
-                        replaceStart = currentVertical.Flag;
-
+                        replaceStart = currentVertical.Flag;                                        
                     }
                     if (currentVertical.Instance.RelationItems.Contains(endId))
                     {
                         replaceEnd = currentVertical.Flag;
                     }
+                    graph.AddVertex(new SimpleVertex<object>(currentVertical.Instance) { Id = currentVertical.Flag });
                 }
-
                 replaceStart = replaceStart ?? startId;
                 replaceEnd = replaceEnd ?? startId;
                 if (!string.IsNullOrWhiteSpace(replaceStart) && !string.IsNullOrWhiteSpace(replaceEnd))
                 {
-                    EAEdge<string> edge = new EAEdge<string>();
-                    edge.StartVertex = replaceStart;
-                    edge.EndVertex = replaceEnd;
-                    edges.Add(edge);
-                }
-            } 
-            #endregion
-
-            foreach (var binaryRelationItem in roomRelations)
-            {
-                
-            }
-
-
-            //连接类型,以机房端类型为基准
-            #region 机房和平面关联
-
-            /*
-             * 前提不是全设备
-             * 产生关系方式 源--阀门--立管a-立管b--端,源--阀门--端;
-             * 连接类型和连接方向,以源端的结果为准
-             */
-            foreach (var roomRelation in roomRelations)
-            {
-                EquipmentNode equipmentNode, linkNode;
-                var systemName = roomRelation.RelationType;
-
-                #region 源
-
-                if (!roomRelation.From.IsRealEquipment && !roomRelation.To.IsRealEquipment)
-                {
-                    continue;
-                }
-
-                if (roomRelation.From.IsRealEquipment)
-                {
-                    equipmentNode = roomRelation.From;
-                    linkNode = roomRelation.To;
-                }
-                else
-                {
-                    equipmentNode = roomRelation.To;
-                    linkNode = roomRelation.From;
-                }
-
-                #endregion
-
-                #region 端
-
-                foreach (var endRelation in floorRelations)
-                {
-                    var mathFlag = endRelation.TryGetNode(n => n.BimId == linkNode.BimId, out EquipmentNode refNode);
-                    if (mathFlag > -1)
-                    {
-                        var anotherNode = endRelation.GetAnotherNode(n => n.BimId == refNode.BimId);
-                        if (anotherNode.IsRealEquipment)
-                        {
-                            //第三种情况
-                            BinaryRelationItem newRelationItem = new BinaryRelationItem();
-                            newRelationItem.From = equipmentNode;
-                            newRelationItem.To = anotherNode;
-                            newRelationItem.RelationType = systemName;
-                            result.Add(CreateRelationData(newRelationItem));
-                        }
-                        else
-                        {
-                            var verticalSet = verticalSets.FirstOrDefault(s =>
-                                s.RelationItems.Any(item => item == anotherNode.BimId));
-                            if (verticalSet == null)
-                                continue;
-                            var verticalIds = new List<string>(verticalSet.RelationItems);
-                            foreach (var verticalId in verticalIds)
-                            {
-                                bool findV = false;
-
-                                #region 立管找端
-
-                                foreach (var vEndRelation in floorRelations)
-                                {
-                                    var vAnother = vEndRelation.GetAnotherNode(n => n.BimId == verticalId);
-                                    if (vAnother == null || !vAnother.IsRealEquipment)
-                                    {
-                                        continue;
-                                    }
-
-                                    //第二种情况
-                                    BinaryRelationItem newRelationItem = new BinaryRelationItem();
-                                    newRelationItem.From = equipmentNode;
-                                    newRelationItem.To = vAnother;
-                                    newRelationItem.RelationType = systemName;
-                                    result.Add(CreateRelationData(newRelationItem));
-                                    findV = true;
-                                }
-
-                                #endregion
-
-                                if (findV)
-                                {
-                                    continue;
-                                }
-
-                                #region 立管找源
-
-                                foreach (var vSourceRelation in roomRelations)
-                                {
-                                    var vAnother = vSourceRelation.GetAnotherNode(n => n.BimId == verticalId);
-                                    if (vAnother == null)
-                                    {
-                                        continue;
-                                    }
-
-                                    #region 源找端
-
-                                    foreach (var floorRelation in floorRelations)
-                                    {
-                                        var sa = floorRelation.GetAnotherNode(n => n.BimId == vAnother.BimId);
-                                        if (sa == null || !sa.IsRealEquipment)
-                                        {
-                                            //第一种情况
-                                            BinaryRelationItem newRelationItem = new BinaryRelationItem();
-                                            newRelationItem.From = equipmentNode;
-                                            newRelationItem.To = sa;
-                                            newRelationItem.RelationType = systemName;
-                                            result.Add(CreateRelationData(newRelationItem));
-                                        }
-                                    }
-
-                                    #endregion
-                                }
-
-                                #endregion
-                            }
-                        }
-                    }
-                }
-
-                #endregion
+                    SimpleEdge<object> edge = new SimpleEdge<object>(replaceStart, replaceEnd);
+                    edge.Data = currentRecord.RelationType;
+                    graph.AddEdge(edge);
+                }             
             }
-
-            return result;
-
             #endregion
+            return graph;
         }
-
-
         /// <summary>
         /// 创建上传关系数据
         /// </summary>

+ 4 - 4
MBI/SAGA.GplotRelationComputerManage/SystemRelation/SystemComputerHandler.cs

@@ -31,10 +31,10 @@ namespace SAGA.GplotRelationComputerManage
             {
                 if (File.Exists(fileInfo))
                 {
-                    if (testFiles.All(f => !fileInfo.Contains(f)))
-                    {
-                        continue;
-                    }
+                    //if (testFiles.All(f => !fileInfo.Contains(f)))
+                    //{
+                    //    continue;
+                    //}
                     FloorSystemItem floorItems = context.FloorItems.GetItem(fileInfo);
                     floorItems.Parse(context);
                     floorItems.Document.CloseDocSimple();

+ 3 - 1
MBI/SAGA.MBI/SAGA.MBI.csproj

@@ -1105,7 +1105,9 @@
       <Install>false</Install>
     </BootstrapperPackage>
   </ItemGroup>
-  <ItemGroup />
+  <ItemGroup>
+    <Folder Include="SystemCheck\" />
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <PropertyGroup>
     <PreBuildEvent>