xulisong 6 роки тому
батько
коміт
55eb32b18b

+ 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; }
+    }
+}

+ 13 - 2
MBI/SAGA.GplotRelationComputerManage/RevitSystemParse/Handler/GplotGraphParse.cs

@@ -360,28 +360,39 @@ namespace SAGA.GplotRelationComputerManage
                     continue;
                 }
 
+                var useFlowType = 0;
                 if (currentVertexName.Contains("入口"))
                 {
+                    useFlowType = 1;
                     isStart = true;
                 }
                 else if(currentVertexName.Contains("出口"))
                 {
+                    useFlowType = 2;
                     isStart = false;
                 }
                 else
                 {
                     continue;
                 }
-
                 Queue<SystemVertex> queueVertexes = new Queue<SystemVertex>();
                 queueVertexes.Enqueue(systemVertex);
                 while (queueVertexes.Any())
                 {
-                    var currentVertex = queueVertexes.Dequeue();                  
+                    var currentVertex = queueVertexes.Dequeue();
+                    if (vertexIds.Contains(currentVertex.Id))
+                    {
+                        continue;
+                    }
                     vertexIds.Add(currentVertex.Id);
+                    
                     var edges = graph.GetInEdges(currentVertex.Id);
                     foreach (var systemEdge in edges)
                     {
+                        if (systemEdge.FlowType != useFlowType)
+                        {
+                            continue;
+                        }
                         if (edgeIds.Contains(systemEdge.Id))
                         {
                             continue;

+ 1 - 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" />

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

@@ -579,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>
         /// 是否是真实设备

+ 42 - 11
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
@@ -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
 

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

@@ -24,17 +24,17 @@ 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)
             {
                 if (File.Exists(fileInfo))
                 {
-                    //if (testFiles.All(f => !fileInfo.Contains(f)))
-                    //{
-                    //    continue;
-                    //}
+                    if (testFiles.All(f => !fileInfo.Contains(f)))
+                    {
+                        continue;
+                    }
                     FloorSystemItem floorItems = context.FloorItems.GetItem(fileInfo);
                     floorItems.Parse(context);
                     floorItems.Document.CloseDocSimple();

+ 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))
             {