Selaa lähdekoodia

Merge branch 'master' of http://dev.dp.sagacloud.cn:8886/r/Revit/SAGA.MBI

mengxiangge 6 vuotta sitten
vanhempi
commit
f0a0d80546
30 muutettua tiedostoa jossa 1689 lisäystä ja 379 poistoa
  1. 33 3
      MBI/SAGA.DotNetUtils/Data/EdgesArray/EAEdge.cs
  2. 58 9
      MBI/SAGA.DotNetUtils/Data/EdgesArray/EAElement.cs
  3. 2 2
      MBI/SAGA.DotNetUtils/Data/EdgesArray/EAVertex.cs
  4. 0 223
      MBI/SAGA.DotNetUtils/Data/EdgesArray/EdgesArray.cs
  5. 2 2
      MBI/SAGA.DotNetUtils/Data/EdgesArray/BaseEdgesArray.cs
  6. 462 0
      MBI/SAGA.DotNetUtils/Data/EdgesArray/EdgesArrayGraph.cs
  7. 4 4
      MBI/SAGA.DotNetUtils/Data/EdgesArray/EdgesArrayUtil.cs
  8. 1 1
      MBI/SAGA.DotNetUtils/Data/EdgesArray/ForwardStar.cs
  9. 53 0
      MBI/SAGA.DotNetUtils/Data/NumberGenerater.cs
  10. 4 3
      MBI/SAGA.DotNetUtils/SAGA.DotNetUtils.csproj
  11. 18 18
      MBI/SAGA.GplotManage/GplotCommand.cs
  12. 4 0
      MBI/SAGA.GplotRelationComputerManage/ColdRoom/EquipmentItem.cs
  13. 386 0
      MBI/SAGA.GplotRelationComputerManage/RevitSystemParse/Handler/GplotGraphParse.cs
  14. 107 0
      MBI/SAGA.GplotRelationComputerManage/RevitSystemParse/Handler/GplotGraphSetting.cs
  15. 95 0
      MBI/SAGA.GplotRelationComputerManage/RevitSystemParse/Handler/JoinElement.cs
  16. 107 0
      MBI/SAGA.GplotRelationComputerManage/RevitSystemParse/Handler/SystemGraphUtil.cs
  17. 8 8
      MBI/SAGA.GplotRelationComputerManage/RevitSystemParse/Handler/SystemParse.cs
  18. 5 49
      MBI/SAGA.GplotRelationComputerManage/RevitSystemParse/Handler/SystemParseSetting.cs
  19. 40 0
      MBI/SAGA.GplotRelationComputerManage/RevitSystemParse/Handler/SystemVertexGplotExtension.cs
  20. 5 0
      MBI/SAGA.GplotRelationComputerManage/SAGA.GplotRelationComputerManage.csproj
  21. 5 14
      MBI/SAGA.RevitUtils/Data/ElementEdgesArray.cs
  22. 20 40
      MBI/SAGA.RevitUtils/Data/ElementsVertex.cs
  23. 76 0
      MBI/SAGA.RevitUtils/Data/Graph/SystemData.cs
  24. 47 0
      MBI/SAGA.RevitUtils/Data/Graph/SystemEdge.cs
  25. 46 0
      MBI/SAGA.RevitUtils/Data/Graph/SystemGraph.cs
  26. 41 0
      MBI/SAGA.RevitUtils/Data/Graph/SystemVertex.cs
  27. 54 1
      MBI/SAGA.RevitUtils/MEP/MepJoinUtil.cs
  28. 4 0
      MBI/SAGA.RevitUtils/SAGA.RevitUtils.csproj
  29. 1 1
      MBI/Test/Edges/EdgeGraph.cs
  30. 1 1
      MBI/Test/MainWindow.xaml.cs

+ 33 - 3
MBI/SAGA.DotNetUtils/Data/EdgesArray/EAEdge.cs

@@ -38,19 +38,45 @@ namespace SAGA.DotNetUtils.Data
         /// 边类型
         /// </summary>
         public EAEdgeType EdgeType { get; set; }
+
+        private string m_StartVertex;
         /// <summary>
         /// 开始点
         /// </summary>
-        public string StartVertex { get; set; }
+        public string StartVertex
+        {
+            get { return m_StartVertex;}
+            set
+            {
+                if (ValidId)
+                {
+                    throw new Exception("确定id的点不能修改");
+                }
+                m_StartVertex = value;
+            }
+        }
+
+        private string m_EndVertex;
         /// <summary>
         /// 结束点
         /// </summary>
-        public string EndVertex { get; set; }
+        public string EndVertex
+        {
+            get { return m_EndVertex; }
+            set
+            {
+                if (ValidId)
+                {
+                    throw new Exception("确定id的点不能修改");
+                }
+                m_EndVertex = value;
+            }
+        }
         #endregion
 
         #region 边提供方法
         /// <summary>
-        /// 判断是否包含指定id的点
+        /// 判断是否包含指定id的点(-1 表示不包含;0,开始点,1,结束点)
         /// </summary>
         /// <param name="id"></param>
         /// <returns>(-1 表示不包含;0,开始点,1,结束点)</returns>
@@ -84,5 +110,9 @@ namespace SAGA.DotNetUtils.Data
             EndVertex = tempId;
         }
         #endregion
+
+        #region 缓存相关数据
+
+        #endregion
     }
 }

+ 58 - 9
MBI/SAGA.DotNetUtils/Data/EdgesArray/EAElement.cs

@@ -14,23 +14,31 @@ namespace SAGA.DotNetUtils.Data
         {
             Children = new EAElementCollection<T>(this as T);
         }
+
         /// <summary>
         /// 节点Id
         /// </summary>
-        public string Id { get;internal set; }
+        public string Id { get; internal set; }
+
         /// <summary>
         /// 节点名称
         /// </summary>
         public string Name { get; set; }
+
         /// <summary>
         /// 关联相关元素
         /// </summary>
         public object Tag { get; set; }
+
         #region 父子关联元素处理
+
         public EAElementCollection<T> Children { get; private set; }
         public T Parent { get; internal set; }
+
         #endregion
+
         #region 公开方法
+
         /// <summary>
         /// 获取根节点
         /// </summary>
@@ -44,8 +52,10 @@ namespace SAGA.DotNetUtils.Data
             {
                 root = root.Parent;
             }
+
             return root;
         }
+
         /// <summary>
         /// 节点深度
         /// </summary>
@@ -93,8 +103,10 @@ namespace SAGA.DotNetUtils.Data
             }
 
             return result;
-        } 
+        }
+
         #endregion
+
         /// <summary>
         /// 有效的Id
         /// </summary>
@@ -102,6 +114,7 @@ namespace SAGA.DotNetUtils.Data
         {
             get { return !string.IsNullOrWhiteSpace(Id); }
         }
+
         /// <summary>
         /// 两个对象是否匹配
         /// </summary>
@@ -109,18 +122,45 @@ namespace SAGA.DotNetUtils.Data
         /// <returns></returns>
         public virtual bool IsMatch(EAElement<T> ea)
         {
-            if (ea == null)
+            if (ea == null || !ValidId)
             {
                 return false;
             }
-            if (Id == ea.Id)
-            {
-                return true;
-            }
-            return this.Equals(ea);
-        }       
+
+            return Id == ea.Id || this.Equals(ea);
+        }
+
+
+        #region 扩展数据相关
+
+        protected Dictionary<string, object> m_DicRef = new Dictionary<string, object>();
+
+        /// <summary>
+        /// 注册关联值
+        /// </summary>
+        public void Set<V>(string key, V refObject)
+        {
+            m_DicRef[key] = refObject;
+        }
+
+        /// <summary>
+        /// 获取关联对象
+        /// </summary>
+        /// <typeparam name="V"></typeparam>
+        /// <param name="key"></param>
+        /// <returns></returns>
+        public V Get<V>(string key)
+        {
+            if (!m_DicRef.ContainsKey(key))
+                return default(V);
+            return (V) m_DicRef[key];
+        }
+
+        #endregion
     }
+
     #region 节点集合类
+
     /// <summary>
     /// 节点子项目集合类
     /// </summary>
@@ -128,6 +168,7 @@ namespace SAGA.DotNetUtils.Data
     public class EAElementCollection<T> : ObservableCollection<T> where T : EAElement<T>
     {
         private T m_Parent;
+
         internal EAElementCollection(T parent)
         {
             m_Parent = parent;
@@ -144,21 +185,26 @@ namespace SAGA.DotNetUtils.Data
                 }
 
             }
+
             base.ClearItems();
         }
+
         protected override void InsertItem(int index, T item)
         {
             base.InsertItem(index, item);
             item.Parent = m_Parent;
         }
+
         protected override void RemoveItem(int index)
         {
             if (this[index] != null)
             {
                 this[index].Parent = null;
             }
+
             base.RemoveItem(index);
         }
+
         protected override void SetItem(int index, T item)
         {
 
@@ -180,5 +226,8 @@ namespace SAGA.DotNetUtils.Data
             list?.Reverse();
         }
     }
+
     #endregion
+
+
 }

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

@@ -20,7 +20,7 @@ namespace SAGA.DotNetUtils.Data
         /// </summary>
         /// <param name="data"></param>
         /// <returns></returns>
-        public virtual bool DataEqual(T data)
+        public virtual bool DataEquals(T data)
         {
             
             if (Data==null||data == null)
@@ -36,7 +36,7 @@ namespace SAGA.DotNetUtils.Data
                 EAVertex<T> refV = ea as EAVertex<T>;
                 if (refV != null)
                 {
-                    flag = DataEqual(refV.Data);
+                    flag = DataEquals(refV.Data);
                 }             
             }
             return flag;

+ 0 - 223
MBI/SAGA.DotNetUtils/Data/EdgesArray/EdgesArray.cs

@@ -1,223 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-namespace SAGA.DotNetUtils.Data
-{
-    #region 概述
-    /*
-     * 有向图,和无向图,部分方法不同;
-     * 
-     * 内部操作使用索引;功能扩展使用Data
-     */ 
-    #endregion
-    /// <summary>
-    /// 边集列表
-    /// </summary>
-    public  class EdgesArray<V,VD,E,ED> : BaseEdgesArray<V, VD, E, ED> where V : EAVertex<VD> where E : EAEdge<ED>
-    {
-        public EdgesArray()
-        {
-          
-        }
-        #region 控制属性
-        /// <summary>
-        /// 表示该图信息是否是有向的
-        /// </summary>
-        public bool IsDirection { get; set; }
-        #endregion
-        #region 编号系统
-        private int m_CurrentVertexIndex;
-        /// <summary>
-        /// 生成节点索引
-        /// </summary>
-        /// <returns></returns>
-        private string GenerateVertexIndex()
-        {
-            return "V" + (++m_CurrentVertexIndex);
-        }
-        /// <summary>
-        /// 生成节点索引
-        /// </summary>
-        /// <returns></returns>
-        private string GenerateEdgeIndex()
-        {
-            return "E" + (++m_CurrentVertexIndex);
-        }
-        #endregion
-
-        #region 点操作
-        /// <summary>
-        /// 增加顶点
-        /// </summary>
-        /// <param name="vertex"></param>
-        /// <returns></returns>
-        public virtual V AddVertex(V vertex)
-        {
-            if (vertex == null)
-                return null;
-            V result = vertex;
-            var useVertex = FindVertex(vertex);
-            if (useVertex == null)
-            {
-                vertex.Id = GenerateVertexIndex();
-                this.m_Vertexes.Add(vertex);
-            }
-            else
-            {
-                useVertex.Merge(vertex);
-                result = useVertex;
-            }     
-            return result;
-        }
-
-        /// <summary>
-        /// 根据顶点Id查询相应的节点
-        /// </summary>
-        /// <param name="vertexId"></param>
-        /// <returns></returns>
-        public virtual V FindVertex(string vertexId)
-        {
-            if (string.IsNullOrWhiteSpace(vertexId))
-            {
-                return null;
-            }
-            if (this.m_Vertexes.Contains(vertexId))
-            {
-                return this.m_Vertexes[vertexId];
-            }
-            return null ;
-        }
-        /// <summary>
-        /// 根据顶点Id查询相应的节点
-        /// </summary>
-        /// <param name="v">根据顶点信息去检索点</param>
-        /// <returns></returns>
-        public virtual V FindVertex(V v)
-        {
-            /*
-             * 待改进:id快索引,IsMatch值匹配慢索引
-             */
-            var useV = FindVertex(v.Id);
-            if(useV==null)
-            {
-                useV= this.Vertexes.FirstOrDefault(c =>c.IsMatch(v));
-            }
-            return useV;
-        }
-        /// <summary>
-        /// 根据Id移除节点
-        /// </summary>
-        /// <param name="vertexId"></param>
-        /// <returns></returns>
-        public virtual bool RemoveVertex(string vertexId)
-        {
-            var realRemove = this.m_Vertexes.Remove(vertexId);
-            if (realRemove)
-            {
-                //移除节点需要移除相应的边
-            }
-            return realRemove;
-        }
-        /// <summary>
-        /// 隐藏点
-        /// </summary>
-        /// <param name="vertexId"></param>
-        public virtual void HideVertex(string vertexId)
-        {
-
-        }
-        /// <summary>
-        /// 合并关联的点
-        /// </summary>
-        /// <param name="vs"></param>
-        /// <returns></returns>
-        public virtual V CombineVertexes(List<V> vs)
-        {
-            return null;
-        }
-        #endregion
-
-        #region 边操作
-        public E GetEdge(string edgeId)
-        {
-            if (this.m_Edges.Contains(edgeId))
-            {
-                return m_Edges[edgeId];
-            }
-            return null;
-        }
-        /// <summary>
-        /// 增加边
-        /// </summary>
-        /// <param name="edge"></param>
-        /// <returns></returns>
-        public virtual E AddEdge(E edge)
-        {
-            var start = FindVertex(edge.StartVertex);
-            if (start == null)
-                throw new Exception("start元素必须在图中");
-            var end = FindVertex(edge.EndVertex);
-            if (end == null)
-                throw new Exception("end元素必须在图中");
-            edge.Id = GenerateEdgeIndex();
-            this.m_Edges.Add(edge);
-            return edge;
-        }
-        /// <summary>
-        /// 增加边信息
-        /// </summary>
-        /// <param name="start"></param>
-        /// <param name="end"></param>
-        /// <param name="edge"></param>
-        /// <returns></returns>
-        public virtual E AddEdge(V start, V end, E edge)
-        {
-            var startV = AddVertex(start);
-            if (startV == null)
-            {
-                throw new Exception("start不能为null");
-            }
-            var endV = AddVertex(end);
-            if (endV == null)
-            {
-                throw new Exception("end不能为null");
-            }
-            edge.StartVertex =startV.Id;
-            edge.EndVertex = endV.Id;
-            edge.Id = GenerateEdgeIndex();
-            this.m_Edges.Add(edge);
-            return edge;
-        }
-        /// <summary>
-        /// 移除边信息
-        /// </summary>
-        /// <param name="edgeId"></param>
-        /// <returns></returns>
-        public virtual bool RemoveEdge(string edgeId)
-        {
-            return this.m_Edges.Remove(edgeId); ;
-        }
-        #endregion
-
-        #region 相关公开方法
-        /// <summary>
-        /// 获取最后一个状态的边集集合
-        /// </summary>
-        /// <returns></returns>
-        public List<E> GetLastStateEdges()
-        {
-            var edges=this.Edges.Where(e => e.Parent == null).ToList();
-            return edges;
-        }
-        /// <summary>
-        /// 获取原始状态的边集合
-        /// </summary>
-        /// <returns></returns>
-        public List<E> GeFirstStateEdges()
-        {
-            var edges = this.Edges.Where(e => e.Parent.Children.Count==0).ToList();
-            return edges;
-        }
-        #endregion
-    }
-}

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

@@ -10,9 +10,9 @@ namespace SAGA.DotNetUtils.Data
     /// <summary>
     /// 基础边集数据
     /// </summary>
-    public class BaseEdgesArray<V, VD, E, ED> where V : EAVertex<VD> where E : EAEdge<ED>
+    public class EdgesArrayBase<V, VD, E, ED> where V : EAVertex<VD> where E : EAEdge<ED>
     {
-        public BaseEdgesArray()
+        public EdgesArrayBase()
         {
             m_Vertexes = new VCollection<V, VD>();
             Vertexes = new ReadOnlyCollection<V>(m_Vertexes);

+ 462 - 0
MBI/SAGA.DotNetUtils/Data/EdgesArray/EdgesArrayGraph.cs

@@ -0,0 +1,462 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+namespace SAGA.DotNetUtils.Data
+{
+    #region 概述
+    /*
+     * 有向图,和无向图,部分方法不同;
+     * 
+     * 内部操作使用索引;功能扩展使用Data
+     */ 
+    #endregion
+    /// <summary>
+    /// 边集列表
+    /// </summary>
+    public  class EdgesArrayGraph<V,VD,E,ED> : EdgesArrayBase<V, VD, E, ED> where V : EAVertex<VD> ,new() where E : EAEdge<ED>,new()
+    {
+        public EdgesArrayGraph()
+        {
+          
+        }
+        #region 控制属性
+        /// <summary>
+        /// 表示该图信息是否是有向的
+        /// </summary>
+        public bool IsDirection { get; set; }
+        #endregion
+        #region 编号系统
+        private int m_CurrentVertexIndex;
+        /// <summary>
+        /// 生成节点索引
+        /// </summary>
+        /// <returns></returns>
+        private string GenerateVertexIndex()
+        {
+            return "V" + (++m_CurrentVertexIndex);
+        }
+        /// <summary>
+        /// 生成节点索引
+        /// </summary>
+        /// <returns></returns>
+        private string GenerateEdgeIndex()
+        {
+            return "E" + (++m_CurrentVertexIndex);
+        }
+        #endregion
+
+        #region 点操作
+
+        #region 查找点
+        /// <summary>
+        /// 根据顶点Id查询相应的节点
+        /// </summary>
+        /// <param name="vertexId"></param>
+        /// <returns></returns>
+        public virtual V FindVertex(string vertexId)
+        {
+            if (string.IsNullOrWhiteSpace(vertexId))
+            {
+                return null;
+            }
+            if (this.m_Vertexes.Contains(vertexId))
+            {
+                return this.m_Vertexes[vertexId];
+            }
+            return null;
+        }
+        /// <summary>
+        /// 根据顶点Id查询相应的节点
+        /// </summary>
+        /// <param name="v">根据顶点信息去检索点</param>
+        /// <returns></returns>
+        public virtual V FindVertex(V v)
+        {
+            /*
+             * 待改进:id快索引,IsMatch值匹配慢索引
+             */
+            var useV = FindVertex(v.Id) ?? this.Vertexes.FirstOrDefault(c => c.IsMatch(v));
+            return useV;
+        }
+        #endregion
+
+        #region 增加点
+        /// <summary>
+        /// 增加顶点
+        /// </summary>
+        /// <param name="vertex"></param>
+        /// <returns></returns>
+        public virtual V AddVertex(V vertex)
+        {
+            if (vertex == null)
+                return null;
+            V result = vertex;
+            //var useVertex = FindVertex(vertex);
+            /*如果是集合形式的比较,相等不传递。比如List1与List2兼容,List2与List3兼容,不能推导出List1与List3兼容
+               综合考虑,不在基类做这种数据的处理,而是直接插入点
+             */
+            vertex.Id = GenerateVertexIndex();
+            this.m_Vertexes.Add(vertex);
+            #region 重复点判断在子类去处理
+            //if (useVertex == null)
+            //{
+            //    vertex.Id = GenerateVertexIndex();
+            //    this.m_Vertexes.Add(vertex);
+            //}
+            //else
+            //{
+            //    useVertex.Merge(vertex);
+            //    result = useVertex;
+            //} 
+            #endregion
+            return result;
+        }
+
+        /// <summary>
+        /// 增加顶点
+        /// </summary>
+        /// <param name="vData"></param>
+        /// <returns></returns>
+        public virtual V AddVertex(VD vData)
+        {
+            if (vData == null)
+                return null;
+            var v = new V();
+            v.Data = vData;
+            return AddVertex(v);
+        }
+        #endregion
+
+        #region 移除点相关操作
+        /// <summary>
+        /// 根据Id移除节点
+        /// </summary>
+        /// <param name="vertexId"></param>
+        /// <returns></returns>
+        public virtual bool RemoveVertex(string vertexId)
+        {
+            var realRemove = this.m_Vertexes.Remove(vertexId);
+            if (realRemove)
+            {
+                //移除节点需要移除相应的边
+                #region 移除相关联的边
+                var edges = this.Edges.Where(e => e.ContainVertex(vertexId) > -1);
+                foreach (var edge in edges)
+                {
+                    this.m_Edges.Remove(edge.Id);
+                } 
+                #endregion
+
+            }
+            return realRemove;
+        }
+        /// <summary>
+        /// 隐藏点
+        /// </summary>
+        /// <param name="vertexId"></param>
+        public virtual void HideVertex(string vertexId)
+        {
+            /*
+             * 将指定点隐藏:概念上是将该点关联的边和点信息删除重构;
+             * 一般适用于三点一线,隐藏掉中间点的情况;
+             * 其他情况下,边关联信息可能会出现问题
+             */
+        }
+        #endregion
+
+        #region 合并点
+        /// <summary>
+        /// 合并关联的点
+        /// </summary>
+        /// <param name="vs"></param>
+        /// <returns></returns>
+        public virtual V CombineVertexes(List<V> vs)
+        {
+            //将关联点合并。1、将点与点之间的边信息进行处理;2、创建新的点
+            return null;
+        }
+        #endregion
+        #endregion
+
+        #region 边操作
+        #region 查找边
+        /// <summary>
+        /// 获取边信息
+        /// </summary>
+        /// <param name="edgeId"></param>
+        /// <returns></returns>
+        public E FindEdge(string edgeId)
+        {
+            if (this.m_Edges.Contains(edgeId))
+            {
+                return m_Edges[edgeId];
+            }
+            return null;
+        }
+        #endregion
+        #region 增加边
+        /// <summary>
+        /// 增加边
+        /// </summary>
+        /// <param name="edge"></param>
+        /// <returns></returns>
+        public virtual E AddEdge(E edge)
+        {
+            var start = FindVertex(edge.StartVertex);
+            if (start == null)
+                throw new Exception("start元素必须在图中");
+            var end = FindVertex(edge.EndVertex);
+            if (end == null)
+                throw new Exception("end元素必须在图中");
+            edge.Id = GenerateEdgeIndex();
+            this.m_Edges.Add(edge);
+            return edge;
+        }
+        /// <summary>
+        /// 增加边信息
+        /// </summary>
+        /// <param name="start"></param>
+        /// <param name="end"></param>
+        /// <param name="edge"></param>
+        /// <returns></returns>
+        public virtual E AddEdge(V start, V end, E edge)
+        {
+            var startV = AddVertex(start);
+            if (startV == null)
+            {
+                throw new Exception("start不能为null");
+            }
+            var endV = AddVertex(end);
+            if (endV == null)
+            {
+                throw new Exception("end不能为null");
+            }
+            edge.StartVertex = startV.Id;
+            edge.EndVertex = endV.Id;
+            edge.Id = GenerateEdgeIndex();
+            this.m_Edges.Add(edge);
+            return edge;
+        } 
+        #endregion
+        /// <summary>
+        /// 移除边信息
+        /// </summary>
+        /// <param name="edgeId"></param>
+        /// <returns></returns>
+        public virtual bool RemoveEdge(string edgeId)
+        {
+            return this.m_Edges.Remove(edgeId); ;
+        }
+        #endregion
+
+        #region 联动查询
+        /*
+         * 念念不忘的可优化部分;根据点去查询边的情况
+         */
+        /// <summary>
+        /// 获取出边
+        /// </summary>
+        /// <param name="vertexId"></param>
+        /// <returns></returns>
+        public List<E> GetOutEdges(string vertexId)
+        {
+            List<E> result = new List<E>();
+            foreach (var edge in this.Edges)
+            {
+                var flag = edge.ContainVertex(vertexId);
+                if (flag == -1)
+                    continue;
+                if (!IsDirection)
+                {
+                    result.Add(edge);
+                }
+                else
+                {
+                    if (flag == 0)
+                    {
+                        result.Add(edge);
+                    }
+                }
+            }
+            return result;
+        }
+        /// <summary>
+        /// 获取入边
+        /// </summary>
+        /// <param name="vertexId"></param>
+        /// <returns></returns>
+        public List<E> GetInEdges(string vertexId)
+        {
+            List<E> result = new List<E>();
+            foreach (var edge in this.Edges)
+            {
+                var flag = edge.ContainVertex(vertexId);
+                if (flag == -1)
+                    continue;
+                if (!IsDirection)
+                {
+                    result.Add(edge);
+                }
+                else
+                {
+                    if (flag == 1)
+                    {
+                        result.Add(edge);
+                    }
+                }
+            }
+            return result;
+        }
+
+        /// <summary>
+        /// 获取两个点确定的边信息
+        /// </summary>
+        /// <param name="startId"></param>
+        /// <param name="endId"></param>
+        /// <returns></returns>
+        public List<E> GetEdges(string startId, string endId)
+        {
+            List<E> result = new List<E>();
+            var edges = GetOutEdges(startId);
+            foreach (var edge in edges)
+            {
+                if (edge.GetAnotherVertex(startId) == endId)
+                {
+                    result.Add(edge);
+                }
+            }
+            return result;
+        }
+        /// <summary>
+        /// 获取出的邻节点
+        /// </summary>
+        /// <param name="vertexId"></param>
+        /// <returns></returns>
+        public List<V> GetOutVertexes(string vertexId)
+        {
+            List<V> result = new List<V>();
+            var edges = GetOutEdges(vertexId);
+            foreach (var edge in edges)
+            {
+                var otherId = edge.GetAnotherVertex(vertexId);
+                if (this.m_Vertexes.Contains(otherId))
+                {
+                    result.Add(this.m_Vertexes[otherId]);
+                }
+            }
+            return result;
+        }
+        /// <summary>
+        /// 获取入的邻接点
+        /// </summary>
+        /// <param name="vertexId"></param>
+        /// <returns></returns>
+        public List<V> GetInVertexes(string vertexId)
+        {
+            List<V> result = new List<V>();
+            var edges = GetInEdges(vertexId);
+            foreach (var edge in edges)
+            {
+                var otherId = edge.GetAnotherVertex(vertexId);
+                if (this.m_Vertexes.Contains(otherId))
+                {
+                    result.Add(this.m_Vertexes[otherId]);
+                }
+            }
+            return result;
+        }
+        /// <summary>
+        /// 获取边的开始点
+        /// </summary>
+        /// <param name="edge"></param>
+        /// <returns></returns>
+        public V GetStartVertex(E edge)
+        {
+            return FindVertex(edge.StartVertex);
+        }
+        /// <summary>
+        /// 获取边的结束点
+        /// </summary>
+        /// <param name="edge"></param>
+        /// <returns></returns>
+        public V GetEndVertex(E edge)
+        {
+            return FindVertex(edge.EndVertex);
+        }
+
+        /// <summary>
+        /// 获取边的开始点的根节点
+        /// </summary>
+        /// <param name="edge"></param>
+        /// <returns></returns>
+        public V GetBootStartVertex(E edge)
+        {
+            return FindVertex(edge.StartVertex)?.GetRoot() as V;
+        }
+        /// <summary>
+        /// 获取边的结束店的根节点
+        /// </summary>
+        /// <param name="edge"></param>
+        /// <returns></returns>
+        public V GetBootEndVertex(E edge)
+        {
+            return FindVertex(edge.EndVertex)?.GetRoot() as V;
+        }
+        #endregion
+
+        #region 相关公开方法
+        /// <summary>
+        /// 获取最后一个状态的边集集合
+        /// </summary>
+        /// <returns></returns>
+        public static List<E> GetLastStateEdges(IEnumerable<E> inputEdges)
+        {
+            var edges = inputEdges.Where(e => e.Parent == null).ToList();
+            return edges;
+        }
+        /// <summary>
+        /// 获取原始状态的边集合
+        /// </summary>
+        /// <returns></returns>
+        public static List<E> GeFirstStateEdges(IEnumerable<E> inputEdges)
+        {
+            var edges = inputEdges.Where(e => e.Parent.Children.Count == 0).ToList();
+            return edges;
+        }
+        /// <summary>
+        /// 获取最后一个状态的边集集合
+        /// </summary>
+        /// <returns></returns>
+        public List<E> GetLastStateEdges()
+        {
+            return GetLastStateEdges(this.Edges);
+        }
+        /// <summary>
+        /// 获取原始状态的边集合
+        /// </summary>
+        /// <returns></returns>
+        public List<E> GeFirstStateEdges()
+        {
+            return GeFirstStateEdges(this.Edges);
+        }
+        /// <summary>
+        /// 获取根边
+        /// </summary>
+        /// <returns></returns>
+        public List<E> GetBootEdges()
+        {
+            var edges = this.Edges.Where(e => e.Parent == null).ToList();
+            return edges;
+        }
+        /// <summary>
+        /// 获取根点
+        /// </summary>
+        /// <returns></returns>
+        public List<V> GetBootVertexs()
+        {
+            var vertexes = this.Vertexes.Where(e => e.Parent == null).ToList();
+            return vertexes;
+        }
+        #endregion
+    }
+}

+ 4 - 4
MBI/SAGA.DotNetUtils/Data/EdgesArray/EdgesArrayUtil.cs

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
 
 namespace SAGA.DotNetUtils.Data
 {
-    public class EdgesArrayUtil
+    public class EdgesArrayGraphUtil
     {
         /// <summary>
         /// 串联处理
@@ -17,7 +17,7 @@ namespace SAGA.DotNetUtils.Data
         /// <typeparam name="ED"></typeparam>
         /// <param name="edgesArray"></param>
         /// <returns></returns>
-        public static EdgesArray<V, VD, E, ED> ParallelHandle<V, VD, E, ED>(EdgesArray<V, VD, E, ED> edgesArray) where V : EAVertex<VD> where E : EAEdge<ED>,new ()
+        public static EdgesArrayGraph<V, VD, E, ED> ParallelHandle<V, VD, E, ED>(EdgesArrayGraph<V, VD, E, ED> edgesArray) where V : EAVertex<VD>,new() where E : EAEdge<ED>,new ()
         {
             var edges = edgesArray.GetLastStateEdges();
             VisitControl map = new VisitControl();
@@ -62,7 +62,7 @@ namespace SAGA.DotNetUtils.Data
         /// <typeparam name="ED"></typeparam>
         /// <param name="edgesArray"></param>
         /// <returns></returns>
-        public static EdgesArray<V, VD, E, ED> SeriesHandle<V, VD, E, ED>(EdgesArray<V, VD, E, ED> edgesArray) where V : EAVertex<VD> where E : EAEdge<ED>,new ()
+        public static EdgesArrayGraph<V, VD, E, ED> SeriesHandle<V, VD, E, ED>(EdgesArrayGraph<V, VD, E, ED> edgesArray) where V : EAVertex<VD>, new() where E : EAEdge<ED>,new ()
         {
             var edges = edgesArray.GetLastStateEdges();
             VisitControl map = new VisitControl();
@@ -139,7 +139,7 @@ namespace SAGA.DotNetUtils.Data
         /// <typeparam name="ED"></typeparam>
         /// <param name="edgesArray"></param>
         /// <returns></returns>
-        public static EdgesArray<V, VD, E, ED> GplotAnalyse<V, VD, E, ED>(EdgesArray<V, VD, E, ED> edgesArray) where V : EAVertex<VD> where E : EAEdge<ED>,new ()
+        public static EdgesArrayGraph<V, VD, E, ED> GplotAnalyse<V, VD, E, ED>(EdgesArrayGraph<V, VD, E, ED> edgesArray) where V : EAVertex<VD>, new() where E : EAEdge<ED>,new ()
         {
                 var preCount = edgesArray.GetLastStateEdges().Count;
                 do

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

@@ -7,7 +7,7 @@ using System.Threading.Tasks;
 
 namespace SAGA.DotNetUtils.Data
 {
-    public class ForwardStar<V, VD,E, ED> : BaseEdgesArray<V, VD, E, ED> where V : EAVertex<VD> where E : EAEdge<ED>
+    public class ForwardStar<V, VD,E, ED> : EdgesArrayBase<V, VD, E, ED> where V : EAVertex<VD> where E : EAEdge<ED>
     {
         public ForwardStar()
         {

+ 53 - 0
MBI/SAGA.DotNetUtils/Data/NumberGenerater.cs

@@ -0,0 +1,53 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:NumberGenerater
+ * 作者:xulisong
+ * 创建时间: 2019/2/13 17:31:00
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.DotNetUtils.Data
+{
+    /// <summary>
+    /// 序号生成器
+    /// </summary>
+    public class NumberGenerater
+    {
+        private const string DefaultCategory = "D39D59D2-A068-4366-B915-CA651698E30A";
+        private Dictionary<string, int> m_Seeds;
+        public NumberGenerater()
+        {
+            m_Seeds = new Dictionary<string, int>();
+        }
+        public string GetNumber(string category, string format)
+        {
+            if (!m_Seeds.TryGetValue(category, out int seed))
+            {
+                m_Seeds[category] = seed;
+            }
+            return string.Format(format, ++seed);
+        }
+        
+        public string GetNumber(string format)
+        {
+            return GetNumber(DefaultCategory, format);
+        }
+        public string GetNumberWithPrefix(string category, string prefix)
+        {
+            if (!m_Seeds.TryGetValue(category, out int seed))
+            {
+                m_Seeds[category] = seed;
+            }
+            return string.Format("{0}{1}", prefix, ++seed);
+        }
+        public string GetNumberWithPrefix(string prefix)
+        {
+            return GetNumberWithPrefix(DefaultCategory, prefix);
+        }
+    }
+}

+ 4 - 3
MBI/SAGA.DotNetUtils/SAGA.DotNetUtils.csproj

@@ -273,18 +273,19 @@
     <Compile Include="Configration\TSZVersion.cs" />
     <Compile Include="Configration\XMLFile.cs" />
     <Compile Include="Configration\XmlManger.cs" />
-    <Compile Include="Data\EdgesArray\BaseEdgesArray.cs" />
+    <Compile Include="Data\EdgesArray\EdgesArrayBase.cs" />
     <Compile Include="Data\EdgesArray\DBCollection.cs" />
     <Compile Include="Data\EdgesArray\EAEdge.cs" />
     <Compile Include="Data\EdgesArray\EAVertex.cs" />
     <Compile Include="Data\EdgesArray\EAElement.cs" />
-    <Compile Include="Data\EdgesArray\EdgesArray.cs" />
-    <Compile Include="Data\EdgesArray\EdgesArrayUtil.cs" />
+    <Compile Include="Data\EdgesArray\EdgesArrayGraph.cs" />
+    <Compile Include="Data\EdgesArray\EdgesArrayGraphUtil.cs" />
     <Compile Include="Data\EdgesArray\ForwardStar.cs" />
     <Compile Include="Data\EdgesArray\VisitControl.cs" />
     <Compile Include="Data\FlagDecorator.cs" />
     <Compile Include="Data\InitAttribute.cs" />
     <Compile Include="Data\InitObejct.cs" />
+    <Compile Include="Data\NumberGenerater.cs" />
     <Compile Include="Data\SingleInstance.cs" />
     <Compile Include="DB\SQLiteHelper.cs" />
     <Compile Include="DB\TableNameAttribute.cs" />

+ 18 - 18
MBI/SAGA.GplotManage/GplotCommand.cs

@@ -142,25 +142,25 @@ namespace SAGA.GplotManage
         public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
         {
             //var graph = new ChillWaterLoop();
-            //List<Gplot> gplots = new List<Gplot>();
-            //gplots.Add(new ElementSpNeighborhood());
-            //gplots.Add(new TrafficNetwork());
-            //gplots.Add(new ConvectionNetwork());
-            //gplots.Add(new RadiationNetwork());
-            //foreach (var gplot in gplots)
-            //{
-            //    var graph =gplot;//new ElementSpNeighborhood();
-            //    graph.Relationship = graph.ComputerEffectRelationShip;
-            //    graph.Upload();
+            List<Gplot> gplots = new List<Gplot>();
+            gplots.Add(new ElementSpNeighborhood());
+            gplots.Add(new TrafficNetwork());
+            gplots.Add(new ConvectionNetwork());
+            gplots.Add(new RadiationNetwork());
+            foreach (var gplot in gplots)
+            {
+                var graph = gplot;//new ElementSpNeighborhood();
+                graph.Relationship = graph.ComputerEffectRelationShip;
+                graph.Upload();
 
-            //}
-            var relationDatas = RelationDataUtil.BuildRelations("ChillWaterLoop");
-              Criteria Criterias= new Criteria
-              {
-                  criterias = relationDatas
-              };
-            var relation= ConvertJsonString(Criterias);
-            MessageShow.Infomation(relation);
+            }
+            //var relationDatas = RelationDataUtil.BuildRelations("ChillWaterLoop");
+            //  Criteria Criterias= new Criteria
+            //  {
+            //      criterias = relationDatas
+            //  };
+            //var relation= ConvertJsonString(Criterias);
+            //MessageShow.Infomation(relation);
             return Result.Succeeded;
         }
         private string ConvertJsonString(object object1)

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

@@ -20,6 +20,10 @@ namespace SAGA.GplotRelationComputerManage
         /// </summary>
         public string Id { get; set; }
         /// <summary>
+        /// BimId
+        /// </summary>
+        public string BimId { get; set; }
+        /// <summary>
         /// 设备名称
         /// </summary>
         public string Name { get; set; }

+ 386 - 0
MBI/SAGA.GplotRelationComputerManage/RevitSystemParse/Handler/GplotGraphParse.cs

@@ -0,0 +1,386 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:GplotGraphParse
+ * 作者:xulisong
+ * 创建时间: 2019/2/14 17:51:58
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+using SAGA.DotNetUtils.Data;
+using SAGA.RevitUtils;
+using SAGA.RevitUtils.Data.Graph;
+using SAGA.RevitUtils.Extends;
+
+namespace SAGA.GplotRelationComputerManage
+{
+    /// <summary>
+    /// 拓扑图解析
+    /// </summary>
+    public class GplotGraphParse
+    {
+        public GplotGraphParse(GplotGraphSetting setting)
+        {
+            Setting = setting;
+        }
+        #region 属性相关
+        /// <summary>
+        /// 系统解析设置
+        /// </summary>
+        public GplotGraphSetting Setting { get; private set; }
+        #endregion
+        /// <summary>
+        /// 创建拓扑结构图
+        /// </summary>
+        /// <param name="startElements"></param>
+        /// <returns></returns>
+        public List<SystemGraph> CreateGplotGraphs(List<Element> startElements)
+        {
+            List<SystemGraph> arrays = new List<SystemGraph>();
+            var newStartElements = startElements.Distinct(new ElementEqualComparer()).ToList();
+            while (newStartElements.Any())
+            {
+                var baseElement = newStartElements[0];
+                var graph = CreateGplotGraph(baseElement);
+                var containElements = graph.GetRefElements();
+                newStartElements = newStartElements.Except(containElements, new ElementEqualComparer()).ToList();
+                arrays.Add(graph);
+            }
+            return arrays;
+        }
+        /// <summary>
+        /// 创建拓扑结构图
+        /// </summary>
+        /// <param name="element"></param>
+        /// <returns></returns>
+        public SystemGraph CreateGplotGraph(Element element)
+        {
+            SystemGraph graph = GetOriginGraph(element);
+            //节点处理
+            ArrangeVertex(graph);
+            //边处理
+            ArrangeEdge(graph);
+            return graph;
+        }
+        #region 解析原始图
+        /// <summary>
+        /// 创建原始的节点图,以起点元素为首个节点
+        /// </summary>
+        /// <param name="element"></param>
+        /// <returns></returns>
+        public SystemGraph GetOriginGraph(Element element)
+        {
+            return SystemGraphUtil.CreateGraph(element, Setting.IgnoredConnector, Setting.BreakElement);
+        }
+        #endregion
+
+        #region 相关子方法
+        #region 节点处理
+        /// <summary>
+        /// 整理点
+        /// </summary>
+        /// <param name="graph"></param>
+        private void ArrangeVertex(SystemGraph graph)
+        {
+            #region 分析
+            /*
+            * 1、如果节点元素是一个管道,则将管道没有连接的那一个点创建一个“空间”设备,标记不可合并
+            * 2、如果节点是设备或者特殊阀门,则标记不能合并,并加载物理世界相关设备信息
+            * 3、如果一个点只有两条边,且该点可以被合并,则创建新边,关联上述两条边和点信息;删除旧的信息
+            * 4、如果一条边的两个点,都是可合并,并过滤所有以这两个点为顶点的边,将这些信息合并成新的点;
+            *     处理这种点融合边的情况,有两种方案:1,创建新点,将旧的点设置为新点的子节点。2、修改所有边的相依的节点Id为新Id
+            *     方案各有利弊,第一种保留了初始状态,第二种以后遍历时方便
+            */
+            #endregion
+            AttachVertexInfo(graph);
+            CombineVertex(graph);
+        }
+        /// <summary>
+        /// 附加节点信息
+        /// </summary>
+        /// <param name="graph"></param>
+        private void AttachVertexInfo(SystemGraph graph)
+        {
+            var useVertexes = graph.GetBootVertexs();
+            #region 
+            foreach (var systemVertex in useVertexes)
+            {
+                var data = systemVertex.Data;
+                if (data.Any())
+                {
+                    continue;
+                }
+                //理论上此时场景,有且仅有一个关联元素
+                var useElement = data[0];
+                #region 虚拟设备处理
+                EquipmentItem item = new EquipmentItem();
+                if (useElement is MEPCurve)
+                {
+                    item.IsVirtual = true;
+                    var edges = graph.GetOutEdges(systemVertex.Id);
+                    if (edges.Count == 1)
+                    {
+                        var currentEdge = edges[0];
+                        var joinItems = JoinItem.GetJoinItems(useElement);
+                        foreach (var joinItem in joinItems)
+                        {
+                            if (joinItem.RefElement != null && currentEdge.Data.All(e => e.Id != joinItem.RefElement.Id))
+                            {
+                                //处理点边关联信息
+                                currentEdge.Data.Add(useElement);
+                                systemVertex.Data.Remove(useElement);
+                                systemVertex.CanCombine = false;
+                                //找到断头点
+                                var location = joinItem.RefConnector.Origin;
+                                var space = useElement.Document.GetSpaceAtPoint(location);
+                                if (space != null)
+                                {
+                                    item.Id = space.Id.ToString();
+                                    item.BimId = space.GetBimId();
+                                }
+                                else
+                                {
+                                    item.Name = string.Format("空间{0}", location.ToString());
+                                }
+                                systemVertex.SetEquipment(item);
+                                break;
+                            }
+                        }
+                    }
+
+                    continue;
+                }
+                #endregion
+
+                #region 真实设备处理
+                item.Id = useElement.Id.ToString();
+                item.BimId = useElement.GetBimId();
+                if (MBIInfoUtil.IsEquipment(useElement))
+                {
+                    systemVertex.CanCombine = false;
+                    systemVertex.SetEquipment(item);
+                    continue;
+                }
+                if (SystemCalcUtil.IsStartValve(useElement))
+                {
+                    systemVertex.CanCombine = false;
+                    item.IsVirtual = true;
+                    systemVertex.SetEquipment(item);
+                    item.Name = useElement.GetFamily()?.Name;
+                    continue;
+                }
+                #endregion
+            }
+            #endregion
+        }
+        /// <summary>
+        /// 合并节点
+        /// </summary>
+        /// <param name="graph"></param>
+        public void CombineVertex(SystemGraph graph)
+        {
+            #region 以点为基础处理
+            var useVertexes = graph.GetBootVertexs();
+            foreach (var systemVertex in useVertexes)
+            {
+                if (!systemVertex.CanCombine)
+                {
+                    continue;
+                }
+                var edges = graph.GetInEdges(systemVertex.Id);
+                if (edges.Count != 2)
+                {
+                    continue;
+                }
+
+                string startId = edges[0].GetAnotherVertex(systemVertex.Id);
+                string endId = edges[1].GetAnotherVertex(systemVertex.Id);
+                edges.ForEach(e => graph.RemoveEdge(e.Id));
+                graph.RemoveVertex(systemVertex.Id);
+                var newEdge = new SystemEdge(startId, endId);
+                newEdge.Data = new SystemData(edges[0].Data);
+                newEdge.Data.ExtendRefElements(edges[1].Data);
+                newEdge.Data.ExtendRefElements(systemVertex.Data);
+                graph.AddEdge(newEdge);
+            }
+            #endregion
+
+            #region 以边为基础处理
+            HandledMap map = new HandledMap();
+            var useEdges = graph.GetBootEdges();
+            for (int i = 0; i < useEdges.Count; i++)
+            {
+                var baseEdge = useEdges[i];
+                if (map.GetHandled(baseEdge))
+                    continue;
+                var startVertex = graph.GetBootStartVertex(baseEdge);
+                var endVertex = graph.GetBootEndVertex(baseEdge);
+                if (startVertex == null || endVertex == null)
+                {
+                    continue;
+                }
+                if (!startVertex.CanCombine || !endVertex.CanCombine)
+                {
+                    continue;
+                }
+                // 如果两个节点之下还有一条其他的包含设备的边,则该边的两点不能合并
+                var refEdges = graph.GetEdges(baseEdge.StartVertex, baseEdge.EndVertex);
+                #region 创建新的点
+                List<Element> elements = new List<Element>();
+                elements.AddRange(startVertex.Data);
+                elements.AddRange(endVertex.Data);
+                foreach (var elementsEdge in refEdges)
+                {
+                    elements.AddRange(elementsEdge.Data);
+                    graph.RemoveEdge(elementsEdge.Id);
+                    map.SetHandled(elementsEdge.Id, true);
+                }
+                graph.RemoveVertex(startVertex.Id);
+                graph.RemoveVertex(endVertex.Id);
+                elements = elements.Distinct(new ElementEqualComparer()).ToList();
+                SystemVertex newVertex = new SystemVertex(new SystemData(elements));
+                newVertex = graph.AddVertex(newVertex);
+                #endregion
+                #region 更新关联边的关联点
+                var vertexIds = new List<string>() { startVertex.Id, endVertex.Id };
+                foreach (var vertexId in vertexIds)
+                {
+                    var edges = graph.GetInEdges(vertexId);
+                    foreach (var systemEdge in edges)
+                    {
+                        var flag = systemEdge.ContainVertex(vertexId);
+                        if (flag == 0)
+                        {
+                            systemEdge.StartVertex = newVertex.Id;
+                        }
+                        else if (flag == 1)
+                        {
+                            systemEdge.EndVertex = newVertex.Id;
+                        }
+                    }
+                }
+                #endregion
+
+            }
+            #endregion
+        }
+        #endregion
+
+        #region 边处理
+        /// <summary>
+        /// 整理边
+        /// </summary>
+        /// <param name="graph"></param>
+        private void ArrangeEdge(SystemGraph graph)
+        {
+            //有向化处理
+            DirectedEdge(graph);
+            graph.IsDirection = true;
+            //串并联处理
+            EdgesArrayGraphUtil.GplotAnalyse(graph);
+        }
+        /// <summary>
+        /// 确定流向
+        /// </summary>
+        /// <param name="graph"></param>
+        private void DirectedEdge(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;
+            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;
+                    }
+                }
+            }
+            #endregion
+            #region 确定开始点
+            List<string> edgeIds = new List<string>();
+            List<string> vertexIds = new List<string>();
+            Queue<SystemVertex> queueVertexes = new Queue<SystemVertex>();
+            vertexes.ForEach(v => queueVertexes.Enqueue(v));
+            bool isDeepSearch = false;
+            bool isStart = true;
+            while (queueVertexes.Any())
+            {
+                var currentVertex = queueVertexes.Dequeue();
+                if (!isDeepSearch)
+                {
+                    isStart = (currentVertex.GetEquipment()?.Name ?? string.Empty).Contains("入口");
+                    isDeepSearch = vertexes.LastOrDefault().Id == currentVertex.Id;
+                }
+
+                vertexIds.Add(currentVertex.Id);
+                var edges = graph.GetInEdges(currentVertex.Id);               
+                foreach (var systemEdge in edges)
+                {
+                    if (edgeIds.Contains(systemEdge.Id))
+                    {
+                        continue;
+                    }
+                    edgeIds.Add(systemEdge.Id);
+                    if ((isStart && systemEdge.ContainVertex(currentVertex.Id) == 1)||(!isStart&& systemEdge.ContainVertex(currentVertex.Id) == 0))
+                    {
+                        systemEdge.Reverse();
+                    }
+
+                    var otherId = systemEdge.GetAnotherVertex(currentVertex.Id);
+                    if (!vertexIds.Contains(otherId))
+                    {
+                        var nextVertex = graph.FindVertex(otherId);
+                        if (nextVertex != null)
+                        {
+                            queueVertexes.Enqueue(nextVertex);
+                        }                      
+                    }
+                }
+            }
+            #endregion
+        }
+        #endregion
+        #endregion
+    }
+}

+ 107 - 0
MBI/SAGA.GplotRelationComputerManage/RevitSystemParse/Handler/GplotGraphSetting.cs

@@ -0,0 +1,107 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:GraphSetting
+ * 作者:xulisong
+ * 创建时间: 2019/2/14 17:50:52
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+using SAGA.RevitUtils.MEP;
+
+namespace SAGA.GplotRelationComputerManage
+{
+    public class GplotGraphSetting
+    {
+        public GplotGraphSetting(RelationTypeShell relationShell)
+        {
+            RelationTypeShell = relationShell;
+            Domain = relationShell.IsPipeSystem() ? Domain.DomainPiping : Domain.DomainHvac;
+        }
+        /// <summary>
+        /// 关系类型相关
+        /// </summary>
+        public RelationTypeShell RelationTypeShell { get; private set; }
+        /// <summary>
+        /// 使用域枚举
+        /// </summary>
+        public Domain Domain { get; private set; }
+
+        #region 忽略连接点
+        /// <summary>
+        /// 忽略的连接点
+        /// </summary>
+        /// <param name="connector"></param>
+        /// <returns></returns>
+        public  bool IgnoredConnector(Connector connector)
+        {
+            bool ignored = true;
+            do
+            {
+                if (connector.IsLogical())
+                    break;
+                if (connector.Domain != Domain)
+                    break;
+                var useElement = connector.Owner;
+                if (!(useElement is MEPCurve)&&!connector.IsConnected)
+                {
+                    break;
+                }
+                ignored = InnerIgnoredConnector(connector);
+            } while (false);
+
+            return ignored;
+        }
+
+        private bool InnerIgnoredConnector(Connector connector)
+        {
+            bool result = false;
+            do
+            {
+                Element owner = connector.Owner;
+                #region 通用判断
+                if (owner is MEPCurve mepCurve)
+                {
+                    string typeName = mepCurve.GetSystemTypeName();
+                    result = !RelationTypeShell.IsMatchSystem(typeName);
+                    break;
+                }
+                if (SystemCalcUtil.IsStartValve(owner))
+                {
+                    result = Regex.IsMatch(connector.Description, AppSetting.SourceFlag);
+                    break;
+                }
+                #endregion
+                if (!owner.IsWaterComponment())
+                {
+                    var mepCurves = owner.GetFirstElements<MEPCurve>(connector);
+                    if (mepCurves.Any())
+                    {
+                        string typeName = (mepCurves[0] as MEPCurve).GetSystemTypeName();
+                        result = !RelationTypeShell.IsMatchSystem(typeName);
+                    }
+                    break;
+                }
+            } while (false);
+            return result;
+        }
+        #endregion
+
+        #region 元素断开点
+        /// <summary>
+        /// 节点断开条件
+        /// </summary>
+        /// <param name="element"></param>
+        /// <returns></returns>
+        public bool BreakElement(Element element)
+        {
+           return SystemCalcUtil.IsStartValve(element)||MBIInfoUtil.IsEquipment(element);
+        }
+        #endregion
+    }
+}

+ 95 - 0
MBI/SAGA.GplotRelationComputerManage/RevitSystemParse/Handler/JoinElement.cs

@@ -0,0 +1,95 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:JoinElement
+ * 作者:xulisong
+ * 创建时间: 2019/2/14 14:23:10
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using SAGA.RevitUtils;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+
+namespace SAGA.GplotRelationComputerManage
+{
+    /// <summary>
+    /// 连接元素
+    /// </summary>
+    public class JoinElement
+    {
+        private List<JoinItem> m_JoinItems;
+        public JoinElement(List<JoinItem> joinItems)
+        {
+            JoinItems = new ReadOnlyCollection<JoinItem>(m_JoinItems = new List<JoinItem>(joinItems));
+            Element = JoinItems.FirstOrDefault()?.BaseElement;
+            if (Element == null)
+                throw new ArgumentNullException(nameof(Element));
+            UsedRefIds = new List<int>();
+        }
+        public JoinElement(Element element)
+        {
+            Element = element;
+            JoinItems =  new ReadOnlyCollection<JoinItem>(m_JoinItems = JoinItem.GetJoinItems(element));
+            UsedRefIds = new List<int>();
+        }
+        public JoinElement(Element element,List<JoinItem> joinItems)
+        {
+            Element = element;
+            JoinItems = new ReadOnlyCollection<JoinItem>(m_JoinItems = joinItems);
+            UsedRefIds = new List<int>();
+        }
+        #region 属性相关
+        /// <summary>
+        /// 关联基础元素
+        /// </summary>
+        public Element Element { get; private set; }
+        /// <summary>
+        /// 使用过的节点,存储joinItem的referenceItem id
+        /// </summary>
+        public List<int> UsedRefIds { get; private set; }
+        /// <summary>
+        /// 关联连接项
+        /// </summary>
+        public ReadOnlyCollection<JoinItem> JoinItems { get; private set; } 
+        #endregion
+
+        #region 方法相关
+        /// <summary>
+        /// 获取当前可用连接数据
+        /// </summary>
+        /// <returns></returns>
+        private JoinItem GetCurrentItem()
+        {
+            //null判断 在前边 
+            return this.JoinItems.FirstOrDefault(ji => ji.RefElement == null || UsedRefIds.All(i => i != ji.RefElement.Id.IntegerValue));
+        }
+        /// <summary>
+        /// 获取节点,并移动到下一个获取位置
+        /// </summary>
+        /// <returns></returns>
+        public JoinItem MoveNext()
+        {
+            var item = GetCurrentItem();
+            if (item != null)
+            {
+                if (item.RefElement == null)
+                {
+                    this.m_JoinItems.RemoveAll(i => i == item);
+                }
+                else
+                {
+                    this.UsedRefIds.Add(item.RefElement.Id.IntegerValue);
+                }
+            }
+
+
+
+            return item;
+        } 
+        #endregion
+    }
+}

+ 107 - 0
MBI/SAGA.GplotRelationComputerManage/RevitSystemParse/Handler/SystemGraphUtil.cs

@@ -0,0 +1,107 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:SystemGraphUtil
+ * 作者:xulisong
+ * 创建时间: 2019/2/14 10:28:28
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Autodesk.Revit.DB;
+using SAGA.RevitUtils;
+using SAGA.RevitUtils.Data.Graph;
+using SAGA.RevitUtils.MEP;
+
+namespace SAGA.GplotRelationComputerManage
+{
+    /// <summary>
+    /// 系统图使用单元
+    /// </summary>
+    public static class SystemGraphUtil
+    {
+        /// <summary>
+        /// 根据起点创建系统图
+        /// </summary>
+        /// <param name="startElement"></param>
+        /// <param name="ignoredConnector">忽略的Connector</param>
+        /// <param name="breakCondition">当connector数量不满足,却又想识别成节点的元素控制</param>
+        /// <returns></returns>
+        public static SystemGraph CreateGraph(Element startElement,Predicate<Connector> ignoredConnector, Predicate<Element> breakCondition)
+        {          
+            SystemGraph graph = new SystemGraph();
+            Queue<JoinElement> joinElements = new Queue<JoinElement>();           
+            joinElements.Enqueue(CreateJoinElement(startElement, ignoredConnector, new List<int>()));
+            while (joinElements.Any())
+            {
+                var current = joinElements.Peek();
+                var joinItem = current.MoveNext();
+                if (joinItem == null)
+                {
+                    joinElements.Dequeue();
+                    continue;
+                }
+                var pathElements = joinItem.BaseElement.GetPathElements(joinItem.BaseConnector, breakCondition);
+                if (pathElements.Count < 2)
+                {
+                    continue;
+                }
+
+                #region 添加边
+                var start = pathElements[0];
+                var end = pathElements[pathElements.Count - 1];
+                var startVertex = graph.AddVertex(new SystemData(start));
+                var endVertex = graph.AddVertex(new SystemData(end));
+                var edge = graph.AddEdge(new SystemEdge(new SystemData(pathElements.GetRange(1, pathElements.Count - 2))));
+                edge.StartVertex = startVertex.Id;
+                edge.EndVertex = endVertex.Id;
+                edge = graph.AddEdge(edge);
+                #endregion
+                #region 延伸遍历项
+                var existJoinElement = joinElements.FirstOrDefault(j => j.Element.Id == end.Id);
+                if (existJoinElement == null)
+                {
+                    existJoinElement = CreateJoinElement(startElement, ignoredConnector, new List<int>(){ });
+                    joinElements.Enqueue(existJoinElement);
+                }
+                existJoinElement.UsedRefIds.Add(pathElements[pathElements.Count - 2].Id.IntegerValue);
+                #endregion
+
+            }
+
+            return graph;
+        }
+        #region 辅助类构建
+        public static JoinElement CreateJoinElement(Element element, Predicate<Connector> ignoredConnector, List<int> usedIds)
+        {
+            var joinItems = GetJoinItems(element, ignoredConnector, usedIds);
+            JoinElement joinElement = new JoinElement(element, joinItems);
+            return joinElement;
+        }
+
+        public static List<JoinItem> GetJoinItems(Element element, Predicate<Connector> ignoredConnector, List<int> usedIds)
+        {
+            List<JoinItem> joinItems = new List<JoinItem>();
+            var connectors = element.GetAllConnectors();
+            foreach (var connector in connectors)
+            {
+                if (ignoredConnector(connector))
+                    continue;
+                if (connector.IsConnected)
+                {
+                    foreach (Connector refConnector in connector.AllRefs)
+                    {
+                        if (refConnector.IsLogical() || refConnector.Owner.Id == element.Id || usedIds.Any(id => refConnector.Owner.Id.IntegerValue == id))
+                            continue;
+                        if (ignoredConnector(refConnector))
+                            continue;
+                        joinItems.Add(new JoinItem(connector, refConnector));
+                    }
+                }
+            }
+            return joinItems;
+        }
+
+        #endregion
+    }
+}

+ 8 - 8
MBI/SAGA.GplotRelationComputerManage/RevitSystemParse/Handler/SystemParse.cs

@@ -135,7 +135,7 @@ namespace SAGA.GplotRelationComputerManage
 
                     #region 如果是节点                 
                     var existVertex = edges.GetAvailableVertexes(v => v.IsMatch(current)).Any();
-                    if (existVertex || Setting.IsForkNode(current)||Setting.IsEquipment(current))
+                    if (existVertex || Setting.IsForkNode(current)|| MBIInfoUtil.IsEquipment(current))
                     {
                         var newVertex = new ElementsVertex(current);
                         var paths = elements.GetRange(0, i).ToList();
@@ -269,7 +269,7 @@ namespace SAGA.GplotRelationComputerManage
                 for (int j = 0; j < elements.Count; j++)
                 {
                     var currentElement = elements[j];
-                    if (Setting.IsEquipment(currentElement))
+                    if (MBIInfoUtil.IsEquipment(currentElement))
                     {
                         var tempEnd = edgeArray.AddVertex(new ElementsVertex(currentElement));
                         var tempEdge = ElementsEdge.CreateEdge(start, tempEnd, elements.GetRange(0, j));
@@ -307,7 +307,7 @@ namespace SAGA.GplotRelationComputerManage
             foreach (var vertex in originVertexes)
             {
                 var edges = edgeArray.GetEdges(vertex.Id);
-                if (edges.Count == 2 && vertex.RefData.All(e=> !Setting.IsEquipment(e)))
+                if (edges.Count == 2 && vertex.RefData.All(e=> !MBIInfoUtil.IsEquipment(e)))
                 {
                     edgeArray.DeleteVertex(vertex.Id, null);
                 }
@@ -325,7 +325,7 @@ namespace SAGA.GplotRelationComputerManage
             for (int i = 0; i < vertexes.Count; i++)
             {
                 var current = vertexes[i];
-                if (current.RefData == null && current.RefData.Any(e => Setting.IsSpecialValve(e)))
+                if (current.RefData == null && current.RefData.Any(SystemCalcUtil.IsStartValve))
                 {
                     current.SetDisableCombine(true);
                 }
@@ -348,15 +348,15 @@ namespace SAGA.GplotRelationComputerManage
                 }
                 else
                 {
-                    var equipment = elements.FirstOrDefault(e => setting.IsEquipment(e));
+                    var equipment = elements.FirstOrDefault(e => MBIInfoUtil.IsEquipment(e));
                    
                     if (equipment != null)
                     {
-                        string name = MBIInfoUtil.GetShowName(equipment);//equipment.Id + equipment.Name;
+                        string name = MBIInfoUtil.GetShowName(equipment);
                         vertex.SetEquipment(new EquipmentItem() { Name = name, Id= equipment.Id.ToString() });
                         continue;
                     }
-                    var valve = elements.FirstOrDefault(e => setting.IsSpecialValve(e));
+                    var valve = elements.FirstOrDefault(e => SystemCalcUtil.IsStartValve(e));
                     if (valve != null)
                     {
                         vertex.SetEquipment(new EquipmentItem() {IsVirtual=true, Name = valve.GetFamily().Name, Id = valve.Id.ToString() });
@@ -386,7 +386,7 @@ namespace SAGA.GplotRelationComputerManage
                 var systemItem = Setting.RelationTypeShell.GetFirstMatchSystem(originEdge.SystemName);
                 if (systemItem != null)
                 {
-                    originEdge.EdgeCategory = systemItem.ContainEdgeTypes.FirstOrDefault();// Setting.GplotOptions.GetCategory(originEdge.SystemName);
+                    originEdge.EdgeCategory = systemItem.ContainEdgeTypes.FirstOrDefault();
                     originEdge.FlowType = systemItem.FlowType == FlowType.In ? 2 : 1;
                 }
             

+ 5 - 49
MBI/SAGA.GplotRelationComputerManage/RevitSystemParse/Handler/SystemParseSetting.cs

@@ -1,13 +1,10 @@
-using Autodesk.Revit.DB;
+
 using System;
 using System.Collections.Generic;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using SAGA.RevitUtils.Extends;
+using Autodesk.Revit.DB;
 using SAGA.RevitUtils.MEP;
 using SAGA.RevitUtils;
-using SAGA.MBI.Tools;
 using System.Text.RegularExpressions;
 
 namespace SAGA.GplotRelationComputerManage
@@ -17,20 +14,11 @@ namespace SAGA.GplotRelationComputerManage
     /// </summary>
     public class SystemParseSetting
     {
-        //public SystemParseSetting(GplotOptions options)
-        //{
-        //    //GplotOptions = options;
-        //    //var relationType = RelationTypeManager.GetRelationTypeItem(options.);
-        //}
         public SystemParseSetting(RelationTypeShell relationShell)
         {
             RelationTypeShell = relationShell;
             Domain = relationShell.IsPipeSystem() ? Domain.DomainPiping : Domain.DomainHvac;
         }
-        ///// <summary>
-        ///// 图相关设置
-        ///// </summary>
-        //public GplotOptions GplotOptions { get; set; }
         /// <summary>
         /// 关系类型相关
         /// </summary>
@@ -95,21 +83,6 @@ namespace SAGA.GplotRelationComputerManage
             return joinItems;
         }
 
-
-
-        /// <summary>
-        /// 标识元素是否是设备
-        /// </summary>
-        /// <param name="element"></param>
-        /// <returns></returns>
-        public bool IsEquipment(Element element)
-        {
-            if (!(element is FamilyInstance fi))
-            {
-                return false;
-            }
-            return MBIInfoUtil.IsEquipment(element);         
-        }
         /// <summary>
         /// 无用边,节点可连通
         /// </summary>
@@ -147,7 +120,7 @@ namespace SAGA.GplotRelationComputerManage
                 }
                 if (SystemCalcUtil.IsStartValve(owner))
                 {
-                    result = Regex.IsMatch(connector.Description, AppSetting.SourceFlag);// connector.Description != GplotOptions.ValveConnectorDescription;
+                    result = Regex.IsMatch(connector.Description, AppSetting.SourceFlag);
                     break;
                 } 
                 #endregion
@@ -157,30 +130,13 @@ namespace SAGA.GplotRelationComputerManage
                     if (mepCurves.Any())
                     {
                         string typeName = (mepCurves[0] as MEPCurve).GetSystemTypeName();
-                        result = !RelationTypeShell.IsMatchSystem(typeName);// !GplotOptions.MatchSystemType(typeName);
+                        result = !RelationTypeShell.IsMatchSystem(typeName);
                     }
-
                     break;
                 }
             } while (false);
             return result;
         }
-        #region 制定特殊阀门判断
-        /// <summary>
-        /// 判断制定元素是否是特定阀门
-        /// </summary>
-        /// <param name="element"></param>
-        /// <returns></returns>
-        public bool IsSpecialValve(Element element)
-        {
-            if(element is FamilyInstance fi)
-            {
-                var name = fi.GetFamily().Name;
-
-               return Regex.IsMatch(name, AppSetting.FamilyStartFlag);
-            }
-            return false;
-        } 
-        #endregion
+      
     }
 }

+ 40 - 0
MBI/SAGA.GplotRelationComputerManage/RevitSystemParse/Handler/SystemVertexGplotExtension.cs

@@ -0,0 +1,40 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:SystemVertexGplotExtendion
+ * 作者:xulisong
+ * 创建时间: 2019/2/15 11:21:58
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SAGA.RevitUtils;
+using SAGA.RevitUtils.Data.Graph;
+
+namespace SAGA.GplotRelationComputerManage
+{
+    public static class SystemVertexGplotExtension
+    {
+        private static string Equipment = "Equipment";
+        public static void SetEquipment(this SystemVertex vertex, EquipmentItem item)
+        {
+            vertex.Set(Equipment, item);
+        }
+        public static EquipmentItem GetEquipment(this SystemVertex vertex)
+        {
+            return vertex.Get<EquipmentItem>(Equipment);
+        }
+        public static bool IsEquipment(this SystemVertex vertex)
+        {
+            return vertex.GetEquipment() != null;
+        }
+        public static bool IsRealEquipment(this SystemVertex vertex)
+        {
+            var item = vertex.GetEquipment();
+            return item != null && !item.IsVirtual;
+        }
+      
+    }
+}

+ 5 - 0
MBI/SAGA.GplotRelationComputerManage/SAGA.GplotRelationComputerManage.csproj

@@ -137,6 +137,11 @@
     <Compile Include="RelationType\RelationTypeShell.cs" />
     <Compile Include="RevitModelPath.cs" />
     <Compile Include="RevitSystemParse\GplotOptions.cs" />
+    <Compile Include="RevitSystemParse\Handler\GplotGraphParse.cs" />
+    <Compile Include="RevitSystemParse\Handler\GplotGraphSetting.cs" />
+    <Compile Include="RevitSystemParse\Handler\JoinElement.cs" />
+    <Compile Include="RevitSystemParse\Handler\SystemGraphUtil.cs" />
+    <Compile Include="RevitSystemParse\Handler\SystemVertexGplotExtension.cs" />
     <Compile Include="RevitSystemParse\MepExtension.cs" />
     <Compile Include="RevitSystemParse\Handler\ParseQueueItem.cs" />
     <Compile Include="RevitSystemParse\Handler\SystemParse.cs" />

+ 5 - 14
MBI/SAGA.RevitUtils/Data/ElementEdgesArray.cs

@@ -2,9 +2,6 @@
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Documents;
 using Autodesk.Revit.DB;
 using SAGA.RevitUtils;
 
@@ -19,24 +16,19 @@ namespace SAGA.RevitUtils
         {
             m_Vertexes = new List<ElementsVertex>();
             Vertexes = new ReadOnlyCollection<ElementsVertex>(m_Vertexes);
-
             m_Edges = new List<ElementsEdge>();
             Edges = new ReadOnlyCollection<ElementsEdge>(m_Edges);
-
             VERelations = new Dictionary<string, List<string>>();
         }
-
         #region 编号系统
-
-        private int m_CurrentVertexIndex;
-
+        private int m_CurrentIndex;
         /// <summary>
         /// 生成节点索引
         /// </summary>
         /// <returns></returns>
         private string GenerateVertexIndex()
         {
-            return "V" + (++m_CurrentVertexIndex);
+            return "V" + (++m_CurrentIndex);
         }
 
         /// <summary>
@@ -45,9 +37,8 @@ namespace SAGA.RevitUtils
         /// <returns></returns>
         private string GenerateEdgeIndex()
         {
-            return "E" + (++m_CurrentVertexIndex);
+            return "E" + (++m_CurrentIndex);
         }
-
         #endregion
 
         /// <summary>
@@ -112,7 +103,7 @@ namespace SAGA.RevitUtils
         /*
          * 增加一个点和边的关联关系,便于以后的查找速度 
          */
-        private Dictionary<string, List<string>> VERelations { get; set; }
+        private Dictionary<string, List<string>> VERelations { get;  set; }
         /// <summary>
         /// 增加点与边的关联关系
         /// </summary>
@@ -238,7 +229,7 @@ namespace SAGA.RevitUtils
             });
         }
         /// <summary>
-        /// 删除指定Id的节点,并把该节点关联的点直连新的边
+        /// 删除指定Id的节点,并把该节点关联的点直连新的边
         /// </summary>
         /// <param name="id"></param>
         /// <param name="predicate">重新连接的点</param>

+ 20 - 40
MBI/SAGA.RevitUtils/Data/ElementsVertex.cs

@@ -1,36 +1,33 @@
-
-using System;
+using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
-using System.ComponentModel;
 using System.Linq;
 using Autodesk.Revit.DB;
 
 namespace SAGA.RevitUtils
 {
-    public enum VertexType
-    {
-        [Description("原始点")]
-        Origin,
-        [Description("融合点")]
-        Combine,
-    }
     /*
      * 节点,可以记录水流方向,这个方向,可以决定拓扑中的串并联
      */
     public class ElementsVertex:GraphNode<ElementsVertex>
     {
-        protected List<Element> m_RefElelemts;
-      
+        protected List<Element> m_RefElelemts;    
         public ElementsVertex(List<Element> elements)
         {
+            if (elements == null)
+                throw new ArgumentNullException(nameof(elements));
             this.m_RefElelemts = new List<Element>(elements);
             this.RefData = new ReadOnlyCollection<Element>(this.m_RefElelemts);
-            if (elements.Any())
+            if (RefData.Any())
             {
-                this.Name = elements.FirstOrDefault().Id.IntegerValue.ToString();
+                this.Name = RefData.FirstOrDefault().Id.IntegerValue.ToString();
             }
         }
+
+        public ElementsVertex(Element element) : this(new List<Element>() { element })
+        {
+        }
+
         /// <summary>
         /// 创建空点
         /// </summary>
@@ -47,20 +44,11 @@ namespace SAGA.RevitUtils
         public bool IsEmpty()
         {
             return this.RefData.Count == 0;
-        }
-
-        public ElementsVertex(Element element):this(new List<Element>() { element })
-        {
-           
-        }
+        } 
         /// <summary>
         /// 关联卫星数据
         /// </summary>
         public ReadOnlyCollection<Element> RefData { get; private set; }
-        /// <summary>
-        /// 节点的点类型
-        /// </summary>
-        public VertexType Type { get; set; }
 
         #region 匹配数据
         /// <summary>
@@ -120,10 +108,12 @@ namespace SAGA.RevitUtils
             if (element == null)
                 return;
             ExtendRefElements(new List<Element>() { element });
-        }   /// <summary>
-            /// 扩展关联数据
-            /// </summary>
-            /// <param name="elements"></param>
+        }
+
+        /// <summary>
+        /// 扩展关联数据
+        /// </summary>
+        /// <param name="elements"></param>
         public void ExtendRefElements(List<Element> elements)
         {
             if (elements == null || !elements.Any())
@@ -131,26 +121,16 @@ namespace SAGA.RevitUtils
             elements.ForEach(e =>
             {
                 if (
-                   RefData.All(
+                    RefData.All(
                         ori => e.Id.IntegerValue != ori.Id.IntegerValue))
                 {
                     this.m_RefElelemts.Add(e);
                 }
+
                 ;
             });
         }
 
-        /// <summary>
-        /// 去除关联数据中的关联id
-        /// </summary>
-        /// <param name="elementId"></param>
-        public void RemoveRefElements(ElementId elementId)
-        {
-            if (elementId == null)
-                return;
-            this.m_RefElelemts.RemoveAll(e => e.Id == elementId);
-        }
-
         #endregion
 
         /// <summary>

+ 76 - 0
MBI/SAGA.RevitUtils/Data/Graph/SystemData.cs

@@ -0,0 +1,76 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:PipeData
+ * 作者:xulisong
+ * 创建时间: 2019/2/14 9:44:51
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using Autodesk.Revit.DB;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.RevitUtils.Data.Graph
+{
+    /// <summary>
+    /// 点,边关联核心数据
+    /// </summary>
+    public class SystemData:List<Element>
+    {
+        #region 构造函数
+        public SystemData()
+        {
+
+        }
+        public SystemData(IEnumerable<Element> source):base(source)
+        {
+
+        }
+        public SystemData(Element source)
+        {
+            this.Add(source);
+        }
+        #endregion
+        #region 重写Equals
+        public override bool Equals(object obj)
+        {
+            var data = obj as SystemData;
+            if (data == null)
+                return false;
+            var flag = this.Intersect(data, new ElementEqualityComparer()).Any();
+            return flag;
+        }
+        #endregion
+
+        #region 增加元素
+
+        /// <summary>
+        /// 扩展关联数据
+        /// </summary>
+        /// <param name="elements"></param>
+        public void ExtendRefElements(List<Element> elements)
+        {
+            if (elements == null || !elements.Any())
+                return;
+            elements.ForEach(e =>
+            {
+                if (
+                    this.All(
+                        ori => e.Id.IntegerValue != ori.Id.IntegerValue))
+                {
+                    this.Add(e);
+                }
+            });
+        }
+
+        #endregion
+
+        public static implicit operator SystemData(Collection<Element> payment)
+        {
+            return new SystemData(payment);
+        }
+    }
+}

+ 47 - 0
MBI/SAGA.RevitUtils/Data/Graph/SystemEdge.cs

@@ -0,0 +1,47 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:SystemEdge
+ * 作者:xulisong
+ * 创建时间: 2019/2/14 9:46:14
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SAGA.DotNetUtils.Data;
+
+namespace SAGA.RevitUtils.Data.Graph
+{
+    public class SystemEdge:EAEdge<SystemData>
+    {
+        public SystemEdge()
+        { }
+
+        public SystemEdge(SystemData data)
+        {
+            this.Data = data;
+        }
+
+        public SystemEdge(string startId, string endId)
+        {
+            this.StartVertex = startId;
+            this.EndVertex = endId;
+        }
+        #region 业务属性
+        /// <summary>
+        /// 关联系统类型
+        /// </summary>
+        public string SystemName { get; set; }
+        /// <summary>
+        /// 边类别
+        /// </summary>
+        public string EdgeCategory { get; set; }
+        /// <summary>
+        /// flowType[2表示从源端流出,1表示流入源端]
+        /// </summary>
+        public int FlowType { get; set; }
+        #endregion
+    }
+}

+ 46 - 0
MBI/SAGA.RevitUtils/Data/Graph/SystemGraph.cs

@@ -0,0 +1,46 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:SystemGraph
+ * 作者:xulisong
+ * 创建时间: 2019/2/14 9:46:31
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+using SAGA.DotNetUtils.Data;
+
+namespace SAGA.RevitUtils.Data.Graph
+{
+    /// <summary>
+    /// 系统图结构
+    /// </summary>
+    public class SystemGraph: EdgesArrayGraph<SystemVertex,SystemData,SystemEdge,SystemData>
+    {
+        public override SystemVertex AddVertex(SystemVertex vertex)
+        {
+            var existVertex = FindVertex(vertex);
+            if (existVertex != null)
+            {
+                existVertex.Merge(vertex);
+                return existVertex;
+            }
+            return base.AddVertex(vertex);
+        }
+
+        /// <summary>
+        /// 获取图中涵盖的元素集合
+        /// </summary>
+        /// <returns></returns>
+        public List<Element> GetRefElements()
+        {
+            List<Element> result = new List<Element>();
+            result.AddRange(this.Vertexes.SelectMany(v => v.Data));
+            result.AddRange(this.Edges.SelectMany(e => e.Data));
+            return result.Distinct(new ElementEqualComparer()).ToList();
+        }
+    }
+}

+ 41 - 0
MBI/SAGA.RevitUtils/Data/Graph/SystemVertex.cs

@@ -0,0 +1,41 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:SystemVertex
+ * 作者:xulisong
+ * 创建时间: 2019/2/14 9:45:47
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SAGA.DotNetUtils.Data;
+
+namespace SAGA.RevitUtils.Data.Graph
+{
+    /// <summary>
+    /// 点信息
+    /// </summary>
+    public class SystemVertex: EAVertex<SystemData>
+    {
+        public SystemVertex()
+        { }
+
+        public SystemVertex(SystemData data)
+        {
+            this.Data = data;
+        }
+        public override void Merge(EAElement<EAVertex<SystemData>> ea)
+        {
+            var sv = ea as SystemVertex;
+            if (sv == null)
+                return;
+            this.Data.ExtendRefElements(sv.Data);
+        }
+        /// <summary>
+        /// 是否允许合并[默认为true]
+        /// </summary>
+        public bool CanCombine { get; set; } = true;
+    }
+}

+ 54 - 1
MBI/SAGA.RevitUtils/MEP/MepJoinUtil.cs

@@ -47,7 +47,7 @@ namespace SAGA.RevitUtils.MEP
         public static bool IsWaterComponment(this Element element)
         {
             var compatibleCategories =
-                new List<int>() {(int) BuiltInCategory.OST_PipeCurves, (int) BuiltInCategory.OST_PipeFitting};
+                new List<int>() {(int) BuiltInCategory.OST_PipeCurves, (int) BuiltInCategory.OST_PipeFitting,(int)BuiltInCategory.OST_DuctCurves, (int)BuiltInCategory.OST_DuctFitting };
 
 
            return compatibleCategories.Any(c => c == element.Category.Id.IntegerValue);
@@ -129,5 +129,58 @@ namespace SAGA.RevitUtils.MEP
             sameTypeElements.RemoveAll(r => r.Id.IntegerValue == startElement.Id.IntegerValue);
             return sameTypeElements;
         }
+        /// <summary>
+        /// 获取单线Path
+        /// </summary>
+        /// <param name="startElement">起始元素</param>
+        /// <param name="startConnector">指定元素上一点</param>
+        /// <param name="breakCondition">断开约束条件</param>
+        /// <returns></returns>
+        public static List<Element> GetPathElements(this Element startElement, Connector startConnector,Predicate<Element> breakCondition)
+        {
+            /*
+             * 获取元素以指定Connector开始的Path,单点相连情况,不分叉
+             */
+            List<Element> elements = new List<Element>();
+            List<Element> useElements = new List<Element>(){startElement};
+            Connector useConnector = startConnector;
+            while (useConnector != null)
+            {
+                var joinElements = useConnector.GetJoinElements();
+                if (joinElements.Count==0||joinElements.Count > 1)
+                {
+                    break;
+                }
+                var nextElement = joinElements[0];
+                //如果原始集合中存在,如环路情况。则收尾元素相等;【理论上是只可能和第一个元素相等】
+                if (startElement.Id == nextElement.Id)
+                {
+                    useElements.Add(nextElement);
+                    break;
+                }
+                useElements.Add(nextElement);
+                if (breakCondition != null && breakCondition(nextElement))
+                {                
+                    break;
+                }
+                var connectors=nextElement.GetAllConnectors();
+                if (connectors.Count !=2)
+                {
+                    break;
+                }
+                var preElement = useConnector.Owner;
+                useConnector = null;
+                for (int i = 0; i < connectors.Count; i++)
+                {
+                    var element = connectors[i].GetReferenceConnector()?.Owner;
+                    if (element != null && element.Id != preElement.Id)
+                    {
+                        useConnector = connectors[i];
+                        break;
+                    }
+                }
+            }
+            return elements;
+        }
     }
 }

+ 4 - 0
MBI/SAGA.RevitUtils/SAGA.RevitUtils.csproj

@@ -190,6 +190,10 @@
     <Compile Include="Data\ElementsEdge.cs" />
     <Compile Include="Data\ElementsVertex.cs" />
     <Compile Include="Data\GraphNode.cs" />
+    <Compile Include="Data\Graph\SystemData.cs" />
+    <Compile Include="Data\Graph\SystemEdge.cs" />
+    <Compile Include="Data\Graph\SystemGraph.cs" />
+    <Compile Include="Data\Graph\SystemVertex.cs" />
     <Compile Include="Data\HandledMap.cs" />
     <Compile Include="Data\JoinItem.cs" />
     <Compile Include="Data\TElement.cs" />

+ 1 - 1
MBI/Test/Edges/EdgeGraph.cs

@@ -20,7 +20,7 @@ namespace Test.Edges
     {
 
     }
-    public class EdgeGraph: EdgesArray<VertexString, string, EdgeString, string>
+    public class EdgeGraph: EdgesArrayGraph<VertexString, string, EdgeString, string>
     {
     }
 }

+ 1 - 1
MBI/Test/MainWindow.xaml.cs

@@ -71,7 +71,7 @@ namespace Test
             graph.AddEdge(v6, v5, new EdgeString() { Data = "6-5" });
             graph.AddEdge(v7, v5, new EdgeString() { Data = "7-5" });
 
-            graph=EdgesArrayUtil.GplotAnalyse(graph) as EdgeGraph;
+            graph=EdgesArrayGraphUtil.GplotAnalyse(graph) as EdgeGraph;
 
             var edges = graph.Edges;
             StringBuilder builder = new StringBuilder();