Просмотр исходного кода

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

mengxiangge 6 лет назад
Родитель
Сommit
0e69a38548
30 измененных файлов с 650 добавлено и 141 удалено
  1. 1 9
      MBI/CEFSharpWPF/ModifyResponseFilter.cs
  2. 15 3
      MBI/SAGA.DotNetUtils/Data/EdgesArray/EAEdge.cs
  3. 9 4
      MBI/SAGA.DotNetUtils/Data/EdgesArray/EdgesArrayGraph.cs
  4. 58 0
      MBI/SAGA.DotNetUtils/Data/SingleFactory.cs
  5. 1 0
      MBI/SAGA.DotNetUtils/SAGA.DotNetUtils.csproj
  6. 5 1
      MBI/SAGA.GplotDrawData/Common/WebGplotSettings.cs
  7. 19 15
      MBI/SAGA.GplotDrawData/DBView/MachineRoomGraphView.cs
  8. 4 5
      MBI/SAGA.GplotDrawData/View/WinMachineRoom.xaml.cs
  9. 18 19
      MBI/SAGA.GplotManage/GplotCommand.cs
  10. 8 6
      MBI/SAGA.GplotManage/SystemRelation/RelationDataUtil.cs
  11. 70 0
      MBI/SAGA.GplotRelationComputerManage/Common/BinaryRelationUtil.cs
  12. 5 1
      MBI/SAGA.GplotRelationComputerManage/DataServer/DataServer.cs
  13. 35 0
      MBI/SAGA.GplotRelationComputerManage/RelationBll/GraphInstance.cs
  14. 28 0
      MBI/SAGA.GplotRelationComputerManage/RelationBll/GraphRelationItem.cs
  15. 175 0
      MBI/SAGA.GplotRelationComputerManage/RelationBll/RelationBll.cs
  16. 63 31
      MBI/SAGA.GplotRelationComputerManage/RevitSystemParse/Handler/GplotGraphParse.cs
  17. 20 1
      MBI/SAGA.GplotRelationComputerManage/RevitSystemParse/Handler/GplotGraphSetting.cs
  18. 5 4
      MBI/SAGA.GplotRelationComputerManage/RevitSystemParse/Handler/SystemGraphUtil.cs
  19. 4 0
      MBI/SAGA.GplotRelationComputerManage/SAGA.GplotRelationComputerManage.csproj
  20. 19 0
      MBI/SAGA.GplotRelationComputerManage/SystemRelation/Common/SystemParseManager.cs
  21. 1 1
      MBI/SAGA.GplotRelationComputerManage/SystemRelation/Data/BinaryRelationItem.cs
  22. 5 5
      MBI/SAGA.GplotRelationComputerManage/SystemRelation/Data/EquipmentNode.cs
  23. 44 13
      MBI/SAGA.GplotRelationComputerManage/SystemRelation/FloorSystemItem.cs
  24. 2 2
      MBI/SAGA.GplotRelationComputerManage/SystemRelation/SystemComputerHandler.cs
  25. 2 0
      MBI/SAGA.MBI/Common/CommonTool.cs
  26. 0 7
      MBI/SAGA.MBI/SAGA.MBI.csproj
  27. 2 0
      MBI/SAGA.Models/Graphs/GElement.cs
  28. 7 2
      MBI/SAGA.Models/Graphs/GElementConverter.cs
  29. 1 2
      MBI/SAGA.Models/Graphs/GraphDB.cs
  30. 24 10
      MBI/SAGA.RevitUtils/MEP/MepJoinUtil.cs

+ 1 - 9
MBI/CEFSharpWPF/ModifyResponseFilter.cs

@@ -6,25 +6,17 @@
  *  -------------------------------------------------------------------------*/
 
 using System;
-using System.Collections.Generic;
 using System.IO;
-using System.Linq;
-using System.Runtime.InteropServices;
 using System.Text;
 using System.Threading;
-using System.Threading.Tasks;
 using CefSharp;
 using Newtonsoft.Json;
-using Newtonsoft.Json.Converters;
 using Newtonsoft.Json.Linq;
 
 namespace CEFSharpWPF
 {
     public class ModifyResponseFilter : IResponseFilter
     {
-        private MemoryStream memoryStream;
-
-
         public void Dispose()
         {
 
@@ -87,7 +79,7 @@ namespace CEFSharpWPF
 
         public bool InitFilter()
         {
-            memoryStream = new MemoryStream();
+         //memoryStream = new MemoryStream();
             return true;
         }
     }

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

@@ -74,6 +74,18 @@ namespace SAGA.DotNetUtils.Data
         }
         #endregion
 
+        public void UpdateStartVertex(string vertexId)
+        {
+            if (string.IsNullOrWhiteSpace(vertexId))
+                throw new ArgumentNullException(nameof(vertexId));
+            this.m_StartVertex = vertexId;
+        }
+        public void UpdateEndVertex(string vertexId)
+        {
+            if (string.IsNullOrWhiteSpace(vertexId))
+                throw new ArgumentNullException(nameof(vertexId));
+            this.m_EndVertex = vertexId;
+        }
         #region 边提供方法
         /// <summary>
         /// 判断是否包含指定id的点(-1 表示不包含;0,开始点,1,结束点)
@@ -105,9 +117,9 @@ namespace SAGA.DotNetUtils.Data
         /// </summary>
         public virtual void Reverse()
         {
-            var tempId = StartVertex;
-            StartVertex = EndVertex;
-            EndVertex = tempId;
+            var tempId = m_StartVertex;
+            m_StartVertex = m_EndVertex;
+            m_EndVertex = tempId;
         }
         #endregion
 

+ 9 - 4
MBI/SAGA.DotNetUtils/Data/EdgesArray/EdgesArrayGraph.cs

@@ -135,16 +135,21 @@ namespace SAGA.DotNetUtils.Data
         /// <returns></returns>
         public virtual bool RemoveVertex(string vertexId)
         {
+            return RemoveVertex(vertexId, false);
+        }
+
+        public virtual bool RemoveVertex(string vertexId,bool deleteRefEdge)
+        {
             var realRemove = this.m_Vertexes.Remove(vertexId);
-            if (realRemove)
+            if (realRemove&&deleteRefEdge)
             {
                 //移除节点需要移除相应的边
                 #region 移除相关联的边
-                var edges = this.Edges.Where(e => e.ContainVertex(vertexId) > -1);
+                var edges = this.Edges.Where(e => e.ContainVertex(vertexId) > -1).ToList();
                 foreach (var edge in edges)
                 {
                     this.m_Edges.Remove(edge.Id);
-                } 
+                }
                 #endregion
 
             }
@@ -420,7 +425,7 @@ namespace SAGA.DotNetUtils.Data
         /// <returns></returns>
         public static List<E> GeFirstStateEdges(IEnumerable<E> inputEdges)
         {
-            var edges = inputEdges.Where(e => e.Parent.Children.Count == 0).ToList();
+            var edges = inputEdges.Where(e => e.Children.Count == 0).ToList();
             return edges;
         }
         /// <summary>

+ 58 - 0
MBI/SAGA.DotNetUtils/Data/SingleFactory.cs

@@ -0,0 +1,58 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:SingleFactory
+ * 作者:xulisong
+ * 创建时间: 2019/2/18 16:36:52
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.DotNetUtils.Data
+{
+    public class SingleFactory<T> where T:class
+    {
+        private static Hashtable m_ObjCache = new Hashtable();
+        private static object m_SyncRoot = new Object();
+
+        /// <summary>
+        /// 单例实例类
+        /// </summary>
+        public static T Instance
+        {
+            get
+            {
+                string cacheKey = typeof(T).FullName;
+                T instance = (T)m_ObjCache[cacheKey];
+                if (instance == null)
+                {
+                    lock (m_SyncRoot)
+                    {
+                        if (instance == null)
+                        {
+                            Assembly assObj = Assembly.Load(typeof(T).Assembly.GetName().Name);
+                            object obj = assObj.CreateInstance(cacheKey);
+                            instance = obj as T;
+                            m_ObjCache.Add(cacheKey, instance);
+                        }
+                    }
+                }
+                return instance
+;
+            }
+        }
+        /// <summary>
+        /// 清除集合信息
+        /// </summary>
+        public static void Clear()
+        {
+            string cacheKey = typeof(T).FullName;
+            m_ObjCache.Remove(cacheKey);
+        }
+    }
+}

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

@@ -286,6 +286,7 @@
     <Compile Include="Data\InitAttribute.cs" />
     <Compile Include="Data\InitObejct.cs" />
     <Compile Include="Data\NumberGenerater.cs" />
+    <Compile Include="Data\SingleFactory.cs" />
     <Compile Include="Data\SingleInstance.cs" />
     <Compile Include="DB\SQLiteHelper.cs" />
     <Compile Include="DB\TableNameAttribute.cs" />

+ 5 - 1
MBI/SAGA.GplotDrawData/Common/WebGplotSettings.cs

@@ -15,7 +15,7 @@ namespace SAGA.GplotDrawData
             MindMapUrl =MBIConst.GplotViewHost+"mindMap";
             VPipeUrl=MBIConst.GplotViewHost+"conduitGraphy";
             VSpaceUrl = MBIConst.GplotViewHost+"spaceGraphy";
-            
+            MachineRoomUrl = MBIConst.GplotViewHost + "coldside";
         }
         /// <summary>
         /// 拓扑图地址
@@ -33,5 +33,9 @@ namespace SAGA.GplotDrawData
         /// 立面空间地址
         /// </summary>
         public static readonly string VSpaceUrl;
+        /// <summary>
+        /// 机房地址
+        /// </summary>
+        public static readonly string MachineRoomUrl;
     }
 }

+ 19 - 15
MBI/SAGA.GplotDrawData/DBView/MachineRoomGraphView.cs

@@ -21,22 +21,26 @@ namespace SAGA.GplotDrawData
     {
         public override GraphDB AppendDb(MachineRoomDrawRecord t, GraphDB db)
         {
-            var drawItem = t.DrawIems;
-            foreach (var point in drawItem.Points)
-            {
-                GVertex gv = new GVertex() { Location = point.Point.ConvertToPoint3D(), IsSolid =!point.IsVirtual};
-                gv.ElementColor = Colors.Red;
-                gv.Name = point.Name;
-                db.Elements.Add(gv);
-            }
-            foreach (var curve in drawItem.Curves)
-            {
-                GLine gline = new GLine(curve.Points[0].ConvertToPoint3D(), curve.Points[1].ConvertToPoint3D());
-                gline.ElementColor = Colors.Red;
-                db.Elements.Add(gline);
-            }
-
+            #region 老方法
+            //var drawItem = t.DrawIems;
+            //foreach (var point in drawItem.Points)
+            //{
+            //    GVertex gv = new GVertex() { Location = point.Point.ConvertToPoint3D(), IsSolid = !point.IsVirtual };
+            //    gv.ElementColor = Colors.Red;
+            //    gv.Name = point.Name;
+            //    db.Elements.Add(gv);
+            //}
+            //foreach (var curve in drawItem.Curves)
+            //{
+            //    GLine gline = new GLine(curve.Points[0].ConvertToPoint3D(), curve.Points[1].ConvertToPoint3D());
+            //    gline.ElementColor = Colors.Red;
+            //    db.Elements.Add(gline);
+            //} 
+            #endregion
+            db.Elements.AddRange(t.NodePaths);
             return db;
         }
     }
+
+  
 }

+ 4 - 5
MBI/SAGA.GplotDrawData/View/WinMachineRoom.xaml.cs

@@ -1,12 +1,10 @@
 using System;
 using System.Collections.Generic;
-using System.Collections.ObjectModel;
 using System.Linq;
 using System.Windows;
 
 using CEFSharpWPF;
 using SAGA.GplotRelationComputerManage;
-using SAGA.GplotRelationComputerManage.Draw;
 using SAGA.Models;
 using SAGA.RevitUtils.Windows;
 
@@ -63,7 +61,7 @@ namespace SAGA.GplotDrawData.View
             {
                 foreach (var drawRecord in drawData)
                 {
-                    if (drawRecord.DrawIems.IsEmpty)
+                    if (!drawRecord.NodePaths.Any())
                         continue;
                     var relationNode = treeDataSource.FirstOrDefault(d => d.EName == drawRecord.RelationName);
                     if (relationNode == null)
@@ -85,8 +83,9 @@ namespace SAGA.GplotDrawData.View
             MachineRoomGraphView view = new MachineRoomGraphView();
             var db = view.CreateDb(record);
             ConstData.ResponseData = db.CreateJObjectGroup();
-            ucShowElement.Show(WebGplotSettings.GplotUrl);
-        } 
+            //ucShowElement.Show(WebGplotSettings.GplotUrl);
+            ucShowElement.Show(WebGplotSettings.MachineRoomUrl);
+        }
         #endregion
     }
 }

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

@@ -141,26 +141,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;
+            //    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)

+ 8 - 6
MBI/SAGA.GplotManage/SystemRelation/RelationDataUtil.cs

@@ -77,11 +77,13 @@ namespace SAGA.GplotManage
 
             var verticalSets = relationData.VerticalRelationRecords;
 
+            //连接类型,以机房端类型为基准
             #region 机房和平面关联
 
             /*
              * 前提不是全设备
-             * 产生关系方式 源--端--立管--源--端,源--端--立管--端,源--端
+             * 产生关系方式 源--阀门--立管a-立管b--端,源--阀门--端;
+             * 连接类型和连接方向,以源端的结果为准
              */
             foreach (var roomRelation in roomRelations)
             {
@@ -207,11 +209,11 @@ namespace SAGA.GplotManage
 
 
         /// <summary>
-            /// 创建上传关系数据
-            /// </summary>
-            /// <param name="relationType"></param>
-            /// <returns></returns>
-            public static List<ReleateData> BuildRelations(string  relationType)
+        /// 创建上传关系数据
+        /// </summary>
+        /// <param name="relationType"></param>
+        /// <returns></returns>
+        public static List<ReleateData> BuildRelations(string relationType)
         {
             LoadRelationData data = new LoadRelationData(relationType);
             data.LoadData();

+ 70 - 0
MBI/SAGA.GplotRelationComputerManage/Common/BinaryRelationUtil.cs

@@ -0,0 +1,70 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:BinaryRelationUtil
+ * 作者:xulisong
+ * 创建时间: 2019/2/20 10:25:03
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.GplotRelationComputerManage
+{
+    /// <summary>
+    /// 二维关系相关操作类
+    /// </summary>
+    public class BinaryRelationUtil
+    {
+        public static Dictionary<string, RelationVertexEntity<T>> CreateVertexGroup<T>(List<T> items,
+            Func<T, string> startId, Func<T, string> endId)
+        {
+            Dictionary<string, RelationVertexEntity<T>> result = new Dictionary<string, RelationVertexEntity<T>>();
+            foreach (var item in items)
+            {
+                var start = startId?.Invoke(item);
+                var end = endId?.Invoke(item);
+                var vertexes = new List<string>() {start, end};
+                if (vertexes.Any(v => string.IsNullOrWhiteSpace(v)))
+                {
+                    throw new Exception("获取节点值异常");
+                }
+
+                for (int i = 0; i < vertexes.Count; i++)
+                {
+                    var currentVertex = vertexes[i];
+                    if (!result.TryGetValue(currentVertex, out RelationVertexEntity<T> useEntity))
+                    {
+                        useEntity = new RelationVertexEntity<T>(currentVertex);
+                        result[currentVertex] = useEntity;
+                    }
+                    if (i == 0)
+                    {
+                        useEntity.OutItems.Add(item);
+                    }
+                    else
+                    {
+                        useEntity.InItems.Add(item);
+                    }
+                }
+            }
+
+            return result;
+        }
+    }
+
+    public class RelationVertexEntity<T>
+    {
+        public RelationVertexEntity(string vertex)
+        {
+            VertexId = vertex;
+            OutItems = new List<T>();
+            InItems = new List<T>();
+        }
+        public string VertexId { get;private set; }
+        public List<T> OutItems { get; private set; }
+        public List<T> InItems { get; private set; }
+    }
+}

+ 5 - 1
MBI/SAGA.GplotRelationComputerManage/DataServer/DataServer.cs

@@ -6,6 +6,7 @@ using System.Reflection;
 using System.Text;
 using System.Threading.Tasks;
 using Newtonsoft.Json;
+using SAGA.Models.Graphs;
 
 namespace SAGA.GplotRelationComputerManage
 {
@@ -80,7 +81,10 @@ namespace SAGA.GplotRelationComputerManage
             var content = file.ReadFileContent();
             if (!string.IsNullOrWhiteSpace(content))
             {
-                return JsonConvert.DeserializeObject<T>(content);
+                JsonSerializerSettings jsetting = new JsonSerializerSettings();
+                //jsetting.Converters.Add(new Point3DConverter());
+                //jsetting.Converters.Add(GElementConverter.CreateConverter());
+                return JsonConvert.DeserializeObject<T>(content, jsetting);
             }
             return default(T);
         }

+ 35 - 0
MBI/SAGA.GplotRelationComputerManage/RelationBll/GraphInstance.cs

@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.GplotRelationComputerManage
+{
+    /// <summary>
+    /// 图实例
+    /// </summary>
+    public class GraphInstance
+    {
+        /// <summary>
+        /// 图实例Id
+        /// </summary>
+        public string Id { get; set; }
+        /// <summary>
+        /// 图实例开始时间
+        /// </summary>
+        public string BeginTime { get; set; }
+        /// <summary>
+        /// 图实例结束时间
+        /// </summary>
+        public string UpdateTime { get; set; }
+        /// <summary>
+        /// 图实例类型
+        /// </summary>
+        public string Type { get; set; }
+        public bool IsValid
+        {
+            get { return !string.IsNullOrWhiteSpace(Id); }
+        }
+    }
+}

+ 28 - 0
MBI/SAGA.GplotRelationComputerManage/RelationBll/GraphRelationItem.cs

@@ -0,0 +1,28 @@
+using Newtonsoft.Json;
+
+namespace SAGA.GplotRelationComputerManage
+{
+    /// <summary>
+    /// 图关系类型
+    /// </summary>
+    public class GraphRelationItem
+    {
+        [JsonProperty("rel_type")]
+        public string RelType { get; set; }
+        [JsonProperty("from_id")]
+        public string FromId { get; set; }
+        [JsonProperty("to_id")]
+        public string ToId { get; set; }
+        [JsonProperty("graph_id")]
+        public string GraphId { get; set; }
+
+        public bool IsValid
+        {
+            get
+            {
+                return !string.IsNullOrWhiteSpace(GraphId)&&!string.IsNullOrWhiteSpace(FromId) && !string.IsNullOrWhiteSpace(ToId);
+            }
+        }
+     
+    }
+}

+ 175 - 0
MBI/SAGA.GplotRelationComputerManage/RelationBll/RelationBll.cs

@@ -0,0 +1,175 @@
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using SAGA.DotNetUtils.Http;
+using SAGA.MBI.Common;
+using SAGA.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.GplotRelationComputerManage
+{
+    public class RelationBll
+    {
+        #region 地址相关
+        /// <summary>
+        /// 获取基础地址
+        /// </summary>
+        /// <returns></returns>
+        public string GetBaseUrl()
+        {
+            return $"{ MBIConst.DataPlatformLocalHost}data - platform - 3 / relation / ";
+        }
+        /// <summary>
+        /// 获取密码相关地址字符串
+        /// </summary>
+        /// <returns></returns>
+        private string GetPasswordQuerry()
+        {
+            return $"projectId={MBIControl.ProjectCur.Id}&secret={MBIControl.ProjectCur.Password}";
+        }
+        #endregion
+
+        /// <summary>
+        /// 创建图实例
+        /// </summary>
+        /// <param name="graphType">图类型</param>
+        /// <param name="beginTime">实例启用时间</param>
+        /// <returns></returns>
+        public string AddGraphInstance(string graphType, string beginTime)
+        {
+            var baseUrl = GetBaseUrl();
+            var password = GetPasswordQuerry();
+            string url = $"{baseUrl}graph_instance/create?{password}";
+            JObject jObject = new JObject();
+            jObject.Add("graph_type", graphType);
+            var periods = new JArray();
+            var timeObject = new JObject();
+            timeObject.Add("begin_time", beginTime);
+            timeObject.Add("end_time", "29000101000000");
+            jObject.Add("periods", periods);
+            //string postData = $"{{\"graph_type\":\"{graphType}\",\"periods\":[{{\"begin_time\":\"{begin_time}\",\"end_time\":\"29000101000000\"}}]}}";
+            RestClient restClient = new RestClient(url, HttpVerb.POST, jObject.ToString());
+
+            return restClient.GetRequest().GetValue("graph_id");
+        }
+
+        /// <summary>
+        /// 根据图类型获取图实例id
+        /// </summary>
+        /// <param name="graphType"></param>
+        /// <returns></returns>
+        public GraphInstance QueryGraphInstance(string graphType)
+        {
+            var baseUrl = GetBaseUrl();
+            var password = GetPasswordQuerry();
+            string url = $"{baseUrl}graph_instance/query?{password}";
+            JObject jObject = new JObject();
+            JObject criteria = new JObject();
+            jObject.Add("criteria", criteria);
+            criteria.Add("jObjectValue", graphType);
+            //string postData = $"{{\"graph_type\":\"{graphType}\"}}";
+            //postData = $"{{\"criteria\":{{\"graph_type\":\"{graphType}\"}}}}";
+            RestClient restClient = new RestClient(url, HttpVerb.POST, jObject.ToString());
+            GraphInstance instance = new GraphInstance();
+            var result = restClient.GetRequest();
+            return instance;
+        }
+
+        /// <summary>
+        /// 修改实例(如果当前时间点与最新的节点有重复,
+        /// 修改之前的图实例时间,然后创建新的,20171123)
+        /// </summary>
+        /// <param name="graphId">图类型</param>
+        /// <param name="statrDateTime"></param>
+        /// <param name="endDateTime"></param>
+        /// <returns></returns>
+        public  string UpdateGraphInstance(string graphId, string biginTime, string endTime)
+        {
+            var baseUrl = GetBaseUrl();
+            var password = GetPasswordQuerry();
+            string url = $"{baseUrl}graph_instance/update?{password}";
+            JObject jObject = new JObject();
+            JObject criteria = new JObject();
+            jObject.Add("criteria", criteria);
+            criteria.Add("graph_id", graphId);
+
+            JObject set = new JObject();
+            jObject.Add("set", set);
+            var periods = new JArray();
+            set.Add("periods", periods);
+            var timeObject = new JObject();
+            timeObject.Add("begin_time", biginTime);
+            timeObject.Add("end_time", "endTime");
+          
+            //string postData = $"{{\"criteria\":{{\"graph_id\":\"{graphId}\"}},\"set\":{{\"periods\":[{{\"begin_time\":\"{statrDateTime}\",\"end_time\":\"{endDateTime}\"}}]}}}}";
+            RestClient restClient = new RestClient(url, HttpVerb.POST, jObject.ToString());
+
+            return restClient.GetRequest().GetValue("graph_id");
+        }
+
+        /// <summary>
+        /// 获取图实例ID
+        /// </summary>
+        /// <returns></returns>
+        public string GetGraphId(string graphyType)
+        {
+            var instance = QueryGraphInstance(graphyType);
+            var nowTime = DateTime.Now;
+          
+            if (instance.IsValid)
+            {
+                //将图类型的终止时间改成当前时间
+                UpdateGraphInstance(instance.Id, instance.BeginTime, nowTime.ToString("yyyyMMddHHmmss"));
+            }               
+            //创建新的图类型
+            var newGraphId = AddGraphInstance(graphyType, nowTime.ToString("yyyyMMddHHmmss"));
+            return newGraphId;
+        }
+        /// <summary>
+        /// 创建关系数据
+        /// </summary>
+        /// <param name="criteria">关系数据</param>
+        /// <returns></returns>
+        public  bool CreateRelations(List<GraphRelationItem> items)
+        {
+            var baseUrl = GetBaseUrl();
+            var password = GetPasswordQuerry();
+            string url = $"{baseUrl}create?{password}";
+            var useItems = new List<GraphRelationItem>();
+            foreach (var item in items)
+            {
+                if(item.IsValid)
+                {
+                    useItems.Add(item);
+                }
+            }
+            if(useItems.Count==0)
+            {
+                return true;
+            }
+            JObject jobject = new JObject();
+            jobject.Add("criterias", JArray.FromObject(useItems));
+            RestClient restClient1 = new RestClient(url, HttpVerb.POST, JsonConvert.SerializeObject(jobject).ToString());
+            var result =restClient1.GetRequest().IsSuccess();
+            return result;      
+        }
+
+        /// <summary>
+        /// 创建关系数据
+        /// </summary>
+        /// <param name="graphType"></param>
+        /// <param name="items"></param>
+        /// <returns></returns>
+        public bool CreateRelations(string graphType, List<GraphRelationItem> items)
+        {
+            var newGraphId = GetGraphId(graphType);
+            if (string.IsNullOrWhiteSpace(newGraphId))
+                return false;
+            items.ForEach(item => item.GraphId = newGraphId);
+            return CreateRelations(items);
+        }
+    }
+}

+ 63 - 31
MBI/SAGA.GplotRelationComputerManage/RevitSystemParse/Handler/GplotGraphParse.cs

@@ -46,6 +46,7 @@ namespace SAGA.GplotRelationComputerManage
             while (newStartElements.Any())
             {
                 var baseElement = newStartElements[0];
+                newStartElements.Remove(baseElement);
                 var graph = CreateGplotGraph(baseElement);
                 var containElements = graph.GetRefElements();
                 newStartElements = newStartElements.Except(containElements, new ElementEqualComparer()).ToList();
@@ -76,7 +77,7 @@ namespace SAGA.GplotRelationComputerManage
         /// <returns></returns>
         public SystemGraph GetOriginGraph(Element element)
         {
-            return SystemGraphUtil.CreateGraph(element, Setting.IgnoredConnector, Setting.BreakElement);
+            return SystemGraphUtil.CreateGraph(element, Setting.IgnoredConnector, Setting.IgnoredElement,Setting.BreakElement);
         }
         #endregion
 
@@ -112,7 +113,7 @@ namespace SAGA.GplotRelationComputerManage
             foreach (var systemVertex in useVertexes)
             {
                 var data = systemVertex.Data;
-                if (data.Any())
+                if (!data.Any())
                 {
                     continue;
                 }
@@ -220,7 +221,7 @@ namespace SAGA.GplotRelationComputerManage
             for (int i = 0; i < useEdges.Count; i++)
             {
                 var baseEdge = useEdges[i];
-                if (map.GetHandled(baseEdge))
+                if (map.GetHandled(baseEdge.Id))
                     continue;
                 var startVertex = graph.GetBootStartVertex(baseEdge);
                 var endVertex = graph.GetBootEndVertex(baseEdge);
@@ -260,11 +261,11 @@ namespace SAGA.GplotRelationComputerManage
                         var flag = systemEdge.ContainVertex(vertexId);
                         if (flag == 0)
                         {
-                            systemEdge.StartVertex = newVertex.Id;
+                            systemEdge.UpdateStartVertex(newVertex.Id);
                         }
                         else if (flag == 1)
                         {
-                            systemEdge.EndVertex = newVertex.Id;
+                            systemEdge.UpdateEndVertex(newVertex.Id);
                         }
                     }
                 }
@@ -286,7 +287,7 @@ namespace SAGA.GplotRelationComputerManage
             DirectedEdge(graph);
             graph.IsDirection = true;
             //串并联处理
-            EdgesArrayGraphUtil.GplotAnalyse(graph);
+            //EdgesArrayGraphUtil.GplotAnalyse(graph);
         }
         /// <summary>
         /// 确定流向
@@ -345,44 +346,75 @@ namespace SAGA.GplotRelationComputerManage
             #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())
+            foreach (var systemVertex in vertexes)
             {
-                var currentVertex = queueVertexes.Dequeue();
-                if (!isDeepSearch)
+                if (vertexIds.Contains(systemVertex.Id))
                 {
-                    isStart = (currentVertex.GetEquipment()?.Name ?? string.Empty).Contains("入口");
-                    isDeepSearch = vertexes.LastOrDefault().Id == currentVertex.Id;
+                    continue;
+                }
+                bool isStart = true;
+             
+                var currentVertexName = systemVertex.GetEquipment().Name;
+                if (string.IsNullOrWhiteSpace(currentVertexName))
+                {
+                    continue;
                 }
 
-                vertexIds.Add(currentVertex.Id);
-                var edges = graph.GetInEdges(currentVertex.Id);               
-                foreach (var systemEdge in edges)
+                var useFlowType = 0;
+                if (currentVertexName.Contains("入口"))
+                {
+                    useFlowType = 1;
+                    isStart = true;
+                }
+                else if(currentVertexName.Contains("出口"))
                 {
-                    if (edgeIds.Contains(systemEdge.Id))
+                    useFlowType = 2;
+                    isStart = false;
+                }
+                else
+                {
+                    continue;
+                }
+                Queue<SystemVertex> queueVertexes = new Queue<SystemVertex>();
+                queueVertexes.Enqueue(systemVertex);
+                while (queueVertexes.Any())
+                {
+                    var currentVertex = queueVertexes.Dequeue();
+                    if (vertexIds.Contains(currentVertex.Id))
                     {
                         continue;
                     }
-                    edgeIds.Add(systemEdge.Id);
-                    if ((isStart && systemEdge.ContainVertex(currentVertex.Id) == 1)||(!isStart&& systemEdge.ContainVertex(currentVertex.Id) == 0))
+                    vertexIds.Add(currentVertex.Id);
+                    
+                    var edges = graph.GetInEdges(currentVertex.Id);
+                    foreach (var systemEdge in edges)
                     {
-                        systemEdge.Reverse();
-                    }
+                        if (systemEdge.FlowType != useFlowType)
+                        {
+                            continue;
+                        }
+                        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)
+                        var otherId = systemEdge.GetAnotherVertex(currentVertex.Id);
+                        if (!vertexIds.Contains(otherId))
                         {
-                            queueVertexes.Enqueue(nextVertex);
-                        }                      
+                            var nextVertex = graph.FindVertex(otherId);
+                            if (nextVertex != null)
+                            {
+                                queueVertexes.Enqueue(nextVertex);
+                            }
+                        }
                     }
                 }
-            }
+            }    
             #endregion
         }
         #endregion

+ 20 - 1
MBI/SAGA.GplotRelationComputerManage/RevitSystemParse/Handler/GplotGraphSetting.cs

@@ -73,7 +73,7 @@ namespace SAGA.GplotRelationComputerManage
                 }
                 if (SystemCalcUtil.IsStartValve(owner))
                 {
-                    result = Regex.IsMatch(connector.Description, AppSetting.SourceFlag);
+                    result = !Regex.IsMatch(connector.Description, AppSetting.SourceFlag);
                     break;
                 }
                 #endregion
@@ -91,7 +91,26 @@ namespace SAGA.GplotRelationComputerManage
             return result;
         }
         #endregion
+        /// <summary>
+        /// 忽略元素信息
+        /// </summary>
+        /// <param name="element"></param>
+        /// <returns></returns>
+        public bool IgnoredElement(Element element)
+        {
+            bool result = false;
+            do
+            {
+                if (element is MEPCurve mepCurve)
+                {
+                    string typeName = mepCurve.GetSystemTypeName();
+                    result = !RelationTypeShell.IsMatchSystem(typeName);
+                    break;
+                }
+            } while (false);
 
+            return result;
+        }
         #region 元素断开点
         /// <summary>
         /// 节点断开条件

+ 5 - 4
MBI/SAGA.GplotRelationComputerManage/RevitSystemParse/Handler/SystemGraphUtil.cs

@@ -25,9 +25,10 @@ namespace SAGA.GplotRelationComputerManage
         /// </summary>
         /// <param name="startElement"></param>
         /// <param name="ignoredConnector">忽略的Connector</param>
+        /// <param name="ignoredElement">忽略的Connector</param>
         /// <param name="breakCondition">当connector数量不满足,却又想识别成节点的元素控制</param>
         /// <returns></returns>
-        public static SystemGraph CreateGraph(Element startElement,Predicate<Connector> ignoredConnector, Predicate<Element> breakCondition)
+        public static SystemGraph CreateGraph(Element startElement,Predicate<Connector> ignoredConnector, Predicate<Element> ignoredElement,Predicate<Element> breakCondition)
         {          
             SystemGraph graph = new SystemGraph();
             Queue<JoinElement> joinElements = new Queue<JoinElement>();           
@@ -41,7 +42,7 @@ namespace SAGA.GplotRelationComputerManage
                     joinElements.Dequeue();
                     continue;
                 }
-                var pathElements = joinItem.BaseElement.GetPathElements(joinItem.BaseConnector, breakCondition);
+                var pathElements = joinItem.BaseElement.GetPathElements(joinItem.BaseConnector, ignoredElement, breakCondition);
                 if (pathElements.Count < 2)
                 {
                     continue;
@@ -52,7 +53,7 @@ namespace SAGA.GplotRelationComputerManage
                 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))));
+                var edge = new SystemEdge(new SystemData(pathElements.GetRange(1, pathElements.Count - 2)));
                 edge.StartVertex = startVertex.Id;
                 edge.EndVertex = endVertex.Id;
                 edge = graph.AddEdge(edge);
@@ -61,7 +62,7 @@ namespace SAGA.GplotRelationComputerManage
                 var existJoinElement = joinElements.FirstOrDefault(j => j.Element.Id == end.Id);
                 if (existJoinElement == null)
                 {
-                    existJoinElement = CreateJoinElement(startElement, ignoredConnector, new List<int>(){ });
+                    existJoinElement = CreateJoinElement(end, ignoredConnector, new List<int>(){ });
                     joinElements.Enqueue(existJoinElement);
                 }
                 existJoinElement.UsedRefIds.Add(pathElements[pathElements.Count - 2].Id.IntegerValue);

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

@@ -94,6 +94,7 @@
     <Compile Include="ColdRoom\EquipmentItem.cs" />
     <Compile Include="ColdRoom\VectorExtension.cs" />
     <Compile Include="Common\AppSetting.cs" />
+    <Compile Include="Common\BinaryRelationUtil.cs" />
     <Compile Include="Common\ComputerFileSetting.cs" />
     <Compile Include="Common\DataServerUtil.cs" />
     <Compile Include="Common\FloorUtil.cs" />
@@ -129,6 +130,9 @@
     <Compile Include="PumpEnd\DuctTerminalBll.cs" />
     <Compile Include="ReadSpaceCommand.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="RelationBll\GraphInstance.cs" />
+    <Compile Include="RelationBll\GraphRelationItem.cs" />
+    <Compile Include="RelationBll\RelationBll.cs" />
     <Compile Include="RelationType\Data\EdgeItem.cs" />
     <Compile Include="RelationType\Data\ObjectItem.cs" />
     <Compile Include="RelationType\Data\RelationItem.cs" />

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

@@ -562,6 +562,7 @@ namespace SAGA.GplotRelationComputerManage
                 foreach (var elementsEdge in edges)
                 {
                     GNodePath path = new GNodePath();
+                    //path.Id = elementsEdge.Id;
                     path.StartNodeId = elementsEdge.StartVertex;
                     path.EndNodeId = elementsEdge.EndVertex;
                     nodeGraph.Paths.Add(path);
@@ -578,6 +579,24 @@ namespace SAGA.GplotRelationComputerManage
                     }
                     nodeGraph.Nodes.Add(node);
                 }
+                #region 调整入度为零的点的顺序
+                var dic = BinaryRelationUtil.CreateVertexGroup<GNodePath>(new List<GNodePath>(nodeGraph.Paths),
+                    g => g.StartNodeId, g => g.EndNodeId);
+                #region 原始值操作
+                var inZeroVertexes = dic.Values.Where(r => r.InItems.Count == 0 && r.OutItems.Count != 0);
+                GNode virtualNode = new GNode();
+                virtualNode.SetId("-1");
+                nodeGraph.Nodes.Insert(0,virtualNode);
+                foreach (var relationVertexEntity in inZeroVertexes)
+                {
+                    GNodePath path = new GNodePath();
+                    path.StartNodeId = virtualNode.Id;
+                    path.EndNodeId = relationVertexEntity.VertexId;
+                    nodeGraph.Paths.Add(path);
+                }
+                #endregion
+                #endregion
+
                 nodeGraphs.Add(nodeGraph);
             }
             return nodeGraphs;

+ 1 - 1
MBI/SAGA.GplotRelationComputerManage/SystemRelation/Data/BinaryRelationItem.cs

@@ -89,6 +89,6 @@ namespace SAGA.GplotRelationComputerManage
             }
             return null;
         }
-
+    
     }
 }

+ 5 - 5
MBI/SAGA.GplotRelationComputerManage/SystemRelation/Data/EquipmentNode.cs

@@ -43,11 +43,11 @@ namespace SAGA.GplotRelationComputerManage
         public EquipmentNode CloneCurrentNode()
         {
             EquipmentNode node = new EquipmentNode();
-            node.MbiId = this.MbiId;
-            node.BimId = this.BimId;
-            node.RevitId = this.RevitId;
-            node.Category = this.Category;
-            return node;
+            //node.MbiId = this.MbiId;
+            //node.BimId = this.BimId;
+            //node.RevitId = this.RevitId;
+            //node.Category = this.Category;
+            return node= this.MemberwiseClone() as EquipmentNode;
         }
         /// <summary>
         /// 是否是真实设备

+ 44 - 13
MBI/SAGA.GplotRelationComputerManage/SystemRelation/FloorSystemItem.cs

@@ -4,6 +4,8 @@
  * 创建时间: 2019/1/4 17:50:04
  * 版本号:v1.0
  *  -------------------------------------------------------------------------*/
+
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text.RegularExpressions;
@@ -126,6 +128,39 @@ namespace SAGA.GplotRelationComputerManage
             return m_StartNodes = startNodes;
         }
 
+        private List<StringFlag<Element>> m_RoomStartElements;
+        /// <summary>
+        /// 获取机房开始元素
+        /// </summary>
+        /// <param name="relationSetting"></param>
+        /// <returns></returns>
+        private List<Element> GetRoomStartNodes(RelationTypeShell relationSetting)
+        {
+            if (m_RoomStartElements == null)
+            {
+                m_RoomStartElements = new List<StringFlag<Element>>();
+                ElementCategoryFilter pipeFilter = new ElementCategoryFilter(BuiltInCategory.OST_PipeAccessory);
+                ElementCategoryFilter ductFilter = new ElementCategoryFilter(BuiltInCategory.OST_DuctAccessory);
+                ElementFilter filter = new LogicalOrFilter(pipeFilter, ductFilter);
+                var specialValves = Document.FilterElements(filter).Where(f => SystemCalcUtil.IsStart(f));
+                foreach (var familyInstance in specialValves)
+                {
+                    var connector = familyInstance.GetAllConnectors()
+                        .FirstOrDefault(c => Regex.IsMatch(c.Description, AppSetting.SourceFlag));
+                    if (connector == null)
+                        continue;
+                    var node = SystemParseManager.CreateTreeNode(familyInstance, connector, e => e is MEPCurve);
+                    var useMepCurve = node.GetLeaves().FirstOrDefault()?.Current as MEPCurve;
+                    if (useMepCurve == null)
+                        continue;
+                    var systemTypeName = useMepCurve.GetSystemTypeName();
+                    m_RoomStartElements.Add(new StringFlag<Element>(systemTypeName, familyInstance));
+                }
+            }
+
+            return m_RoomStartElements.Where(f => relationSetting.IsMatchSystem(f.Flag)).Select(f => f.Instance)
+                .ToList();
+        }
         #endregion
 
         #region 设备节点获取
@@ -202,7 +237,7 @@ namespace SAGA.GplotRelationComputerManage
             var relationType = relationSetting.RelationItem.Type;
             List<FloorDrawRecord> drawRecords = new List<FloorDrawRecord>();
             List<FloorRelationRecord> relationRecords = new List<FloorRelationRecord>();
-            List<Element> roomStartElements = new List<Element>();
+            //List<Element> roomStartElements = new List<Element>();
             #region 计算拓扑树形结构 
 
             /*
@@ -220,10 +255,10 @@ namespace SAGA.GplotRelationComputerManage
                 if (useRelation == null)
                     continue;
                 //加入开始元素
-                if (startNode.Instance.Current is FamilyInstance)
-                {
-                    roomStartElements.Add(startNode.Instance.Current);
-                }
+                //if (startNode.Instance.Current is FamilyInstance)
+                //{
+                //    roomStartElements.Add(startNode.Instance.Current);
+                //}
                 if (useIds.Any(id => id == startNode.Instance.Current.Id.IntegerValue))
                 {
                     continue;
@@ -236,10 +271,6 @@ namespace SAGA.GplotRelationComputerManage
 
                 var tempIds = SystemParseManager.BuildSystemNode(startNode.Instance, useDomain,
                     (m => !startNode.Flag.Equals(m.GetSystemTypeName())));
-                if (tempIds.Any(d => d == 534844|| d == 534845))
-                {
-
-                }
                 startNode.Instance.PipeSystemTypeName = startNode.Flag;
                 BuildElementNodeData(context, startNode.Instance);
                 useIds.AddRange(tempIds);
@@ -270,7 +301,7 @@ namespace SAGA.GplotRelationComputerManage
 
 
             #region 解析机房数据
-
+            var roomStartElements = GetRoomStartNodes(relationSetting);
             var useEquipments = ParseMachineRoomData2(context, relationSetting, roomStartElements);
             useEquipments = useEquipments.Distinct().ToList();
             #endregion
@@ -659,7 +690,7 @@ namespace SAGA.GplotRelationComputerManage
                         var spaceIem = context.Rooms.GetItem(equipmentItem.BimId);
                         if (spaceIem != null)
                         {
-                            equipmentItem.Name = spaceIem.Name;
+                            equipmentItem.Name = spaceIem.GetDisplay();
                         }
                     }
                     else if (equipmentItem.ElementType == ElementType.Equipment)
@@ -667,7 +698,7 @@ namespace SAGA.GplotRelationComputerManage
                         var equipment = context.EquipmentItems.GetItem(equipmentItem.BimId);
                         if (equipment != null)
                         {
-                            equipmentItem.Name = equipment.Name;
+                            equipmentItem.Name = equipment.GetDisplay();
                         }
                     }
                 }
@@ -697,7 +728,7 @@ namespace SAGA.GplotRelationComputerManage
                 relationRecord.RelationItems.Add(node);
                 var newIds = new List<string>() { item.EquipmentItem1.Id, item.EquipmentItem2.Id };
                 useEquipments.AddRange(newIds);
-            }
+            }  
             context[relationType].MachineRoomRelationRecords.Add(relationRecord);
             #endregion
 

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

@@ -24,8 +24,8 @@ namespace SAGA.GplotRelationComputerManage
         public void Computer(SystemComputerContext context)
         {
             List<string> testFiles = new List<string>();
-            testFiles.Add("Fl420105000119b7c08edcee11e8a553abe8a598be93.rvt");
-            testFiles.Add("Fl4201050001d4f1ea8fdce711e8a55335c5dd75d7b3.rvt");
+            testFiles.Add("Fl11010800037693bcbe34d611e9b7c25df55ced62cd.rvt");
+            //testFiles.Add("Fl4201050001d4f1ea8fdce711e8a55335c5dd75d7b3.rvt");
             var fileInfos = RevitModelPath.GetAllRevitFiles();
             foreach (var fileInfo in fileInfos)
             {

+ 2 - 0
MBI/SAGA.MBI/Common/CommonTool.cs

@@ -107,6 +107,8 @@ namespace SAGA.MBI.Common
         public static JArray GetPropertyJArray(string value)
         {
             JArray jArray = new JArray();
+            if (value == null)
+                return jArray;
             JObject valueJObject = new JObject();
             if (value.Equals(NullStr))
             {

+ 0 - 7
MBI/SAGA.MBI/SAGA.MBI.csproj

@@ -712,9 +712,6 @@
     <Compile Include="WinView\TraceView\WinTraceView.xaml.cs">
       <DependentUpon>WinTraceView.xaml</DependentUpon>
     </Compile>
-    <Compile Include="WinView\WinTestUserControl.xaml.cs">
-      <DependentUpon>WinTestUserControl.xaml</DependentUpon>
-    </Compile>
     <Compile Include="WinView\Upload\MTopologyGriph.cs" />
     <Compile Include="WinView\Upload\UploadFilesSelectConverter.cs" />
     <Compile Include="WinView\Upload\UploadFloor.cs" />
@@ -958,10 +955,6 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
-    <Page Include="WinView\WinTestUserControl.xaml">
-      <Generator>MSBuild:Compile</Generator>
-      <SubType>Designer</SubType>
-    </Page>
     <Page Include="WinView\Upload\WinUnlockedFloorList.xaml">
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>

+ 2 - 0
MBI/SAGA.Models/Graphs/GElement.cs

@@ -4,6 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Media;
+using Newtonsoft.Json;
 
 namespace SAGA.Models.Graphs
 {
@@ -21,6 +22,7 @@ namespace SAGA.Models.Graphs
         /// <summary>
         /// 关联Id
         /// </summary>
+        [JsonProperty]
         public string Id { get; internal set; }
         public string Name { get; set; } = string.Empty;
         /// <summary>

+ 7 - 2
MBI/SAGA.Models/Graphs/GElementConverter.cs

@@ -11,6 +11,10 @@ namespace SAGA.Models.Graphs
 {
     public class GElementConverter : JsonConverter
     {
+        public static JsonConverter CreateConverter()
+        {
+            return new GElementConverter();
+        }
         #region 初始化类型使用字典
         public static Dictionary<string, Type> Types { get; private set; }
         static GElementConverter()
@@ -48,8 +52,9 @@ namespace SAGA.Models.Graphs
             serializer.Serialize(writer, value);
         }
         public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
-        {
+        {        
             JObject jObject = (JObject)serializer.Deserialize(reader, typeof(JObject));
+            //var jObject = JsonSerializer.Create().Deserialize<JObject>(reader);
             //jObject.CreateReader()//下面直接直接使用reader会出问题,
             try
             {
@@ -83,7 +88,7 @@ namespace SAGA.Models.Graphs
 
         public override bool CanConvert(Type objectType)
         {
-            return objectType == typeof(GElement);
+            return typeof(GElement).IsAssignableFrom(objectType);
         }
 
      

+ 1 - 2
MBI/SAGA.Models/Graphs/GraphDB.cs

@@ -23,7 +23,7 @@ namespace SAGA.Models.Graphs
         {
             JsonSerializerSettings jsetting = new JsonSerializerSettings();
             jsetting.Converters.Add(new Point3DConverter());
-            jsetting.Converters.Add(new GElementConverter());
+           // jsetting.Converters.Add(new GElementConverter());
             return jsetting;
         }
         public List<GElement> Elements { get;private set; }
@@ -91,7 +91,6 @@ namespace SAGA.Models.Graphs
         {
             this.Elements.Clear();
             JsonSerializerSettings jsetting = CreateJsonSetting();
-            var serializer = JsonSerializer.Create(jsetting);
             var elements=JsonConvert.DeserializeObject<List<GElement>>(jsonStr, jsetting);
             this.Elements.AddRange(elements);
         }

+ 24 - 10
MBI/SAGA.RevitUtils/MEP/MepJoinUtil.cs

@@ -141,30 +141,44 @@ namespace SAGA.RevitUtils.MEP
             /*
              * 获取元素以指定Connector开始的Path,单点相连情况,不分叉
              */
-            List<Element> elements = new List<Element>();
-            List<Element> useElements = new List<Element>(){startElement};
+            return GetPathElements(startElement, startConnector, null, breakCondition);      
+        }
+        /// <summary>
+        /// 获取单线Path
+        /// </summary>
+        /// <param name="startElement">起始元素</param>
+        /// <param name="startConnector">指定元素上一点</param>
+        /// <param name="ignoredElement">忽略点位</param>
+        /// <param name="breakCondition">断开约束条件</param>
+        /// <returns></returns>
+        public static List<Element> GetPathElements(this Element startElement, Connector startConnector,Predicate<Element> ignoredElement, Predicate<Element> breakCondition)
+        {
+            List<Element> useElements = new List<Element>() { startElement };
             Connector useConnector = startConnector;
             while (useConnector != null)
             {
                 var joinElements = useConnector.GetJoinElements();
-                if (joinElements.Count==0||joinElements.Count > 1)
+                if (joinElements.Count !=1)
                 {
                     break;
                 }
                 var nextElement = joinElements[0];
-                //如果原始集合中存在,如环路情况。则收尾元素相等;【理论上是只可能和第一个元素相等】
-                if (startElement.Id == nextElement.Id)
+                if (ignoredElement != null&& ignoredElement(nextElement))
                 {
-                    useElements.Add(nextElement);
                     break;
                 }
                 useElements.Add(nextElement);
+                //如果原始集合中存在,如环路情况。则收尾元素相等;【理论上是只可能和第一个元素相等】
+                if (startElement.Id == nextElement.Id)
+                {        
+                    break;
+                }
                 if (breakCondition != null && breakCondition(nextElement))
-                {                
+                {
                     break;
                 }
-                var connectors=nextElement.GetAllConnectors();
-                if (connectors.Count !=2)
+                var connectors = nextElement.GetAllConnectors();            
+                if (connectors.Count != 2)
                 {
                     break;
                 }
@@ -180,7 +194,7 @@ namespace SAGA.RevitUtils.MEP
                     }
                 }
             }
-            return elements;
+            return useElements;
         }
     }
 }