瀏覽代碼

xls:关系调整

xls 6 年之前
父節點
當前提交
95d26ef832
共有 28 個文件被更改,包括 641 次插入102 次删除
  1. 二進制
      MBI/MBIResource/Config/物理世界关系定义列表-2019-1.xlsx
  2. 64 0
      MBI/SAGA.DotNetUtils/Extend/IEnumerableExtensions.cs
  3. 1 0
      MBI/SAGA.DotNetUtils/SAGA.DotNetUtils.csproj
  4. 37 14
      MBI/SAGA.GplotDrawData/View/WinMachineRoom.xaml.cs
  5. 69 28
      MBI/SAGA.GplotDrawData/View/WinSystem.xaml.cs
  6. 2 4
      MBI/SAGA.GplotManage/GplotCommand.cs
  7. 11 0
      MBI/SAGA.GplotRelationComputerManage/Common/ComputerFileSetting.cs
  8. 26 0
      MBI/SAGA.GplotRelationComputerManage/PowerDistribution/Common/DataNodeUtil.cs
  9. 1 0
      MBI/SAGA.GplotRelationComputerManage/Common/DataServerUtil.cs
  10. 25 6
      MBI/SAGA.GplotRelationComputerManage/DataServer/DataServer.cs
  11. 1 1
      MBI/SAGA.GplotRelationComputerManage/DataServer/TimeVersionFile.cs
  12. 1 1
      MBI/SAGA.GplotRelationComputerManage/RelationType/Data/RelationItem.cs
  13. 22 1
      MBI/SAGA.GplotRelationComputerManage/RelationType/RelationTypeManager.cs
  14. 5 1
      MBI/SAGA.GplotRelationComputerManage/SAGA.GplotRelationComputerManage.csproj
  15. 43 0
      MBI/SAGA.GplotRelationComputerManage/SystemRelation/Common/RelationTypeUtil.cs
  16. 13 10
      MBI/SAGA.GplotRelationComputerManage/SystemRelation/FloorSystemItem.cs
  17. 191 0
      MBI/SAGA.GplotRelationComputerManage/SystemRelation/RelationComputerData.cs
  18. 37 0
      MBI/SAGA.GplotRelationComputerManage/SystemRelation/RelationDataCheck.cs
  19. 1 1
      MBI/SAGA.GplotRelationComputerManage/SystemRelation/ServerData/FloorDrawData.cs
  20. 2 5
      MBI/SAGA.GplotRelationComputerManage/SystemRelation/ServerData/FloorRecord.cs
  21. 1 1
      MBI/SAGA.GplotRelationComputerManage/SystemRelation/ServerData/MachineRoomDrawRecord.cs
  22. 1 1
      MBI/SAGA.GplotRelationComputerManage/SystemRelation/ServerData/MachineRoomRelationRecord.cs
  23. 25 0
      MBI/SAGA.GplotRelationComputerManage/SystemRelation/ServerData/ServerData.cs
  24. 1 1
      MBI/SAGA.GplotRelationComputerManage/SystemRelation/ServerData/VerticalDrawData.cs
  25. 1 1
      MBI/SAGA.GplotRelationComputerManage/SystemRelation/ServerData/VerticalRelationRecord.cs
  26. 28 23
      MBI/SAGA.GplotRelationComputerManage/SystemRelation/SystemComputerContext.cs
  27. 31 3
      MBI/SAGA.GplotRelationComputerManage/SystemRelation/SystemComputerHandler.cs
  28. 1 0
      MBI/SAGA.RevitUtils/SAGA.RevitUtils.csproj

二進制
MBI/MBIResource/Config/物理世界关系定义列表-2019-1.xlsx


+ 64 - 0
MBI/SAGA.DotNetUtils/Extend/IEnumerableExtensions.cs

@@ -0,0 +1,64 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:IEnumerableExtensions
+ * 作者:xulisong
+ * 创建时间: 2019/1/25 11:15:03
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.DotNetUtils.Extend
+{
+    public static class IEnumerableExtensions
+    {
+        /*
+         * 没有什么是string办不了的
+         */
+        #region 分组扩展
+        /// <summary>
+        /// 给指定数据源分组
+        /// </summary>
+        /// <typeparam name="IN"></typeparam>
+        /// <typeparam name="TREE"></typeparam>
+        /// <param name="inputSource"></param>
+        /// <param name="treeAdd"></param>
+        /// <param name="groupConditions"></param>
+        /// <returns></returns>
+        public static List<TREE> GroupTree<IN, TREE>(this IEnumerable<IN> inputSource, Action<TREE, List<TREE>> treeAdd, List<GroupCondition<IN, TREE>> groupConditions)
+        {
+            List<TREE> reuslt = new List<TREE>();
+            var firstCondition = groupConditions.FirstOrDefault();
+            if (firstCondition == null)
+                return reuslt;
+            var groups = inputSource.GroupBy(firstCondition.GroupKeySelect);
+            foreach (var groupItem in groups)
+            {
+                var tree = firstCondition.GroupSelect(groupItem);
+                reuslt.Add(tree);
+                if (!firstCondition.GroupContinue(groupItem))
+                {
+                    continue;
+                }
+                var childNodes = groupItem.ToList().GroupTree(treeAdd, groupConditions.GetRange(1, groupConditions.Count-1));
+                treeAdd(tree, childNodes);
+            }
+            return reuslt;
+        }
+        #endregion
+    }
+    /// <summary>
+    /// 分组约束类
+    /// </summary>
+    /// <typeparam name="IN"></typeparam>
+    /// <typeparam name="TREE"></typeparam>
+    public class GroupCondition<IN, TREE>
+    {
+        public Func<IN, string> GroupKeySelect { get; set; }
+        public Func<IGrouping<string, IN>, bool> GroupContinue { get; set; }
+        public Func<IGrouping<string, IN>, TREE> GroupSelect { get; set; }
+    }
+}

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

@@ -267,6 +267,7 @@
     <Compile Include="Extend\DoubleExt.cs" />
     <Compile Include="Extend\EnumExtends.cs" />
     <Compile Include="Extend\FilePathExt.cs" />
+    <Compile Include="Extend\IEnumerableExtensions.cs" />
     <Compile Include="Extend\JObjectExt.cs" />
     <Compile Include="Extend\ObjectExtend.cs" />
     <Compile Include="FileOperate\FileStreamOperate.cs" />

+ 37 - 14
MBI/SAGA.GplotDrawData/View/WinMachineRoom.xaml.cs

@@ -29,30 +29,53 @@ namespace SAGA.GplotDrawData.View
         #region 事件相关
         private void RootNode_OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
         {
-            if (TreeRootNode.SelectedItem is DocumentNode ln)
+            if (TreeRootNode.SelectedItem is DataNode ln)
             {
-                Draw(ln);
+                Draw(ln.GetData<MachineRoomDrawRecord>());
             }
         }
         #endregion
         #region 数据相关处理
-
+        /// <summary>
+        /// 获取平面绘图数据
+        /// </summary>
+        /// <returns></returns>
+        private List<List<MachineRoomDrawRecord>> GetMachineRoomDrawData()
+        {
+            List<List<MachineRoomDrawRecord>> datas = new List<List<MachineRoomDrawRecord>>();
+            List<string> relationTypes = RelationTypeManager.GetSystemRelationTypeNames();
+            foreach (string relationType in relationTypes)
+            {
+                LoadMachineRoomDrawData loadData = new LoadMachineRoomDrawData(relationType);
+                loadData.LoadData();
+                datas.Add(loadData.MachineRoomDrawRecords);
+            }
+            return datas;
+        }
+        /// <summary>
+        /// 初始化树形结构显示
+        /// </summary>
         private void InitTreeNode()
         {
-            var drawData = DataServerUtil.Current.LoadData<VerticalDrawData>(ComputerFileSetting.MachineRoomDraw);
-            List<GplotDocument> nodes = new List<GplotDocument>();
-            
-           // nodes.GroupBy()
-            //增加建筑级别的分级处理
-            // this.TreeRootNode.ItemsSource = DocumentNodes;
+            List<List<MachineRoomDrawRecord>> drawDatas = GetMachineRoomDrawData();
+            List<DataNode> treeDataSource = new List<DataNode>();
+            foreach (var drawData in drawDatas)
+            {
+                foreach (var drawRecord in drawData)
+                {
+                    var recordNode= new DataNode(drawRecord.RelationName);
+                    recordNode.SetData(recordNode);
+                    treeDataSource.Add(recordNode);
+                }
+            }
+           this.TreeRootNode.ItemsSource = treeDataSource;
         }
-        private void Draw(DocumentNode docNode)
+        private void Draw(MachineRoomDrawRecord record)
         {
-            if (docNode?.LinkDocument == null)
+            if (record == null)
                 return;
-            GplotDocument document = docNode.LinkDocument;
-            RoomGraphView view = new RoomGraphView();
-            var db = view.CreateDb(document);
+            MachineRoomGraphView view = new MachineRoomGraphView();
+            var db = view.CreateDb(record);
             ConstData.ResponseData = db.CreateJObjectGroup();
             ucShowElement.Show(WebGplotSettings.GplotUrl);
         } 

+ 69 - 28
MBI/SAGA.GplotDrawData/View/WinSystem.xaml.cs

@@ -59,30 +59,52 @@ namespace SAGA.GplotDrawData.View
             }
         }
         #region 平面数据处理
-
+        /// <summary>
+        /// 获取平面绘图数据
+        /// </summary>
+        /// <returns></returns>
+        private List<List<FloorDrawRecord>> GetFloorDrawData()
+        {
+            List<List<FloorDrawRecord>> datas = new List<List<FloorDrawRecord>>();
+            List<string> relationTypes = RelationTypeManager.GetSystemRelationTypeNames();
+            foreach (string relationType in relationTypes)
+            {
+                LoadFloorDrawData loadData = new LoadFloorDrawData(relationType);
+                loadData.LoadData();
+                datas.Add(loadData.FloorDrawRecords);
+            }
+            return datas;
+        }
+        /// <summary>
+        /// 初始化平面数据
+        /// </summary>
         private void InitFloorData()
         {
-            var records = DataServerUtil.Current.LoadData<List<FloorDrawRecord>>(ComputerFileSetting.FloorDraw);
-            if (records == null || !records.Any())
-                return;
-            var groupSystems = records.GroupBy(r => r.SystemName);
+            List<List<FloorDrawRecord>> recordDatas=GetFloorDrawData();
             List<DataNode> treeDataSource = new List<DataNode>();
-            foreach (var groupSystem in groupSystems)
+            foreach (var records in recordDatas)
             {
-                var system = new DataNode(groupSystem.Key);
-                var groupFloors = groupSystem.GroupBy(g => g.FloorName);
-                foreach (var groupFloor in groupFloors)
+                if (records == null || !records.Any())
+                    continue;
+                var groupSystems = records.GroupBy(r => r.SystemName);              
+                foreach (var groupSystem in groupSystems)
                 {
-                    var floor = new DataNode(groupFloor.Key);
-                    system.Childrens.Add(floor);
-                    var currentRecords = groupFloor.ToList();
-                    FloorDrawData floorData = new FloorDrawData() {FloorId = currentRecords.FirstOrDefault()?.FloorId};
-                    floorData.DrawRecords = currentRecords;
-                    floor.SetData(floorData);
-                }
+                    var system = new DataNode(groupSystem.Key);
+                    var groupFloors = groupSystem.GroupBy(g => g.FloorName);
+                    foreach (var groupFloor in groupFloors)
+                    {
+                        var floor = new DataNode(groupFloor.Key);
+                        system.Childrens.Add(floor);
+                        var currentRecords = groupFloor.ToList();
+                        FloorDrawData floorData = new FloorDrawData() { FloorId = currentRecords.FirstOrDefault()?.FloorId };
+                        floorData.DrawRecords = currentRecords;
+                        floor.SetData(floorData);
+                    }
 
-                treeDataSource.Add(system);
+                    treeDataSource.Add(system);
+                }
             }
+         
             this.rootNode.ItemsSource = treeDataSource;
               
         }
@@ -102,21 +124,40 @@ namespace SAGA.GplotDrawData.View
         #endregion
 
         #region 立面数据处理
+        /// <summary>
+        /// 获取立面展示数据
+        /// </summary>
+        /// <returns></returns>
+        private List<VerticalDrawData> GetVerticalDrawData()
+        {
+            List<VerticalDrawData> datas = new List<VerticalDrawData>();
+            List<string> relationTypes = RelationTypeManager.GetSystemRelationTypeNames();
+            foreach (string relationType in relationTypes)
+            {
+                LoadVerticalDrawData loadData = new LoadVerticalDrawData(relationType);
+                loadData.LoadData();
+                datas.Add(loadData.VerticalDrawData);
+            }
+            return datas;
+        }
         private void InitVerticalData()
         {
             List<DataNode> dataNode = new List<DataNode>();
-            var drawData = DataServerUtil.Current.LoadData<VerticalDrawData>(ComputerFileSetting.VerticalDraw);
-            var groups = (drawData.DrawRecords ?? new List<VerticalDrawRecord>()).GroupBy(c => c.SystemName);
-            foreach (var group in groups)
+            List<VerticalDrawData> drawDatas = GetVerticalDrawData();
+            foreach (var drawData in drawDatas)
             {
-                if (string.IsNullOrEmpty(group.Key))
-                    continue;
-                var node = new DataNode() {EName = group.Key};
-                var currentDrawData = new VerticalDrawData(){LevelDatas=drawData.LevelDatas};
-                currentDrawData.DrawRecords = group.ToList();
-                node.SetData(currentDrawData);
-                dataNode.Add(node);
-            }
+                var groups = (drawData.DrawRecords ?? new List<VerticalDrawRecord>()).GroupBy(c => c.SystemName);
+                foreach (var group in groups)
+                {
+                    if (string.IsNullOrEmpty(group.Key))
+                        continue;
+                    var node = new DataNode() { EName = group.Key };
+                    var currentDrawData = new VerticalDrawData() { LevelDatas = drawData.LevelDatas };
+                    currentDrawData.DrawRecords = group.ToList();
+                    node.SetData(currentDrawData);
+                    dataNode.Add(node);
+                }
+            }          
             this.rootNode.ItemsSource = dataNode;
         }
         /// <summary>

+ 2 - 4
MBI/SAGA.GplotManage/GplotCommand.cs

@@ -154,11 +154,9 @@ namespace SAGA.GplotManage
         public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
         {
             var relationType = RelationTypeManager.GetRelationTypeItem("ChillWaterLoop");
-            //return Result.Succeeded;
+            List<string> useRelations = new List<string>() { "ChillWaterLoop" };
             SystemComputerHandler handler1 = new SystemComputerHandler();
-            SystemComputerContext context = new SystemComputerContext();
-            context.Relations.Add("ChillWaterLoop");
-            handler1.GetParseData(context);
+            handler1.ComputerWidthCache(useRelations);
             WinSystem floorWin = new WinSystem(GplotShowType.ViewPlan);
             floorWin.Show();
             WinSystem verticalWin = new WinSystem(GplotShowType.VerticalPlan);

+ 11 - 0
MBI/SAGA.GplotRelationComputerManage/Common/ComputerFileSetting.cs

@@ -17,5 +17,16 @@ namespace SAGA.GplotRelationComputerManage
         public const string VerticalRelation = "VerticalRelation";
         public const string MachineRoomDraw = "MechineRoomDraw";
         public const string MachineRoomRelation = "MechineRoomRelation";
+
+        /// <summary>
+        /// 获取通用的文件名称
+        /// </summary>
+        /// <param name="relationType">关系类型</param>
+        /// <param name="commonKey">通用键值</param>
+        /// <returns></returns>
+        public static string GetRealKey(string relationType,string commonKey)
+        {
+            return string.Format("{0}_{1}", relationType, commonKey);
+        }
     }
 }

+ 26 - 0
MBI/SAGA.GplotRelationComputerManage/PowerDistribution/Common/DataNodeUtil.cs

@@ -10,6 +10,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using SAGA.DotNetUtils.Extend;
 using SAGA.Models;
 
 namespace SAGA.GplotRelationComputerManage
@@ -65,5 +66,30 @@ namespace SAGA.GplotRelationComputerManage
             }
             #endregion
         }
+
+        /// <summary>
+        /// 将数据源分组处理
+        /// </summary>
+        /// <typeparam name="IN"></typeparam>
+        /// <param name="source"></param>
+        /// <param name="selects"></param>
+        /// <returns></returns>
+        public static List<DataNode> CreateTree<IN>(List<IN> source, List<Func<IN, string>> selects)
+        {
+            List<GroupCondition<IN, DataNode>> conditions = new List<GroupCondition<IN, DataNode>>();
+            foreach (var selectItem in selects)
+            {
+                GroupCondition<IN, DataNode> condition = new GroupCondition<IN, DataNode>();
+                condition.GroupContinue = (g) => true;
+                condition.GroupSelect = (g) => {
+                    var tempNode=new DataNode { EName = g.Key };
+                    tempNode.SetData(g.ToList());
+                    return tempNode;
+                };
+                condition.GroupKeySelect = selectItem;
+                conditions.Add(condition);
+            }
+            return source.GroupTree<IN, DataNode>((p, children) => { p.Childrens.AddRange(children); }, conditions);
+        }
     }
 }

+ 1 - 0
MBI/SAGA.GplotRelationComputerManage/Common/DataServerUtil.cs

@@ -30,5 +30,6 @@ namespace SAGA.GplotRelationComputerManage
 
             }
         }
+
     }
 }

+ 25 - 6
MBI/SAGA.GplotRelationComputerManage/DataServer/DataServer.cs

@@ -17,10 +17,10 @@ namespace SAGA.GplotRelationComputerManage
         public DataServer(Func<string, IVersionFile> versionFileBuilder)
         {
             m_BuilderVersionFile = versionFileBuilder;
-        }      
+        }
         public virtual IVersionFile CreateVersionFile(string fileName)
         {
-           return m_BuilderVersionFile?.Invoke(fileName);
+            return m_BuilderVersionFile?.Invoke(fileName);
         }
         #region 功能相关类
         /// <summary>
@@ -112,10 +112,29 @@ namespace SAGA.GplotRelationComputerManage
         }
         public bool IsExpired<T>(DateTime dateTime)
         {
-            var fileName = DataServer.GetFileKey<T>();
-            return IsExpired(fileName, dateTime);
+            var fileKey = DataServer.GetFileKey<T>();
+            return IsExpired(fileKey, dateTime);
 
-        } 
+        }
+        /// <summary>
+        /// 获取当前文件信息
+        /// </summary>
+        /// <param name="fileKey"></param>
+        /// <returns></returns>
+        public IVersionFile GetFile(string fileKey)
+        {
+            return CreateVersionFile(fileKey);
+        }
+        /// <summary>
+        /// 获取当前文件信息
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <returns></returns>
+        public IVersionFile GetFile<T>()
+        {
+            var fileKey = DataServer.GetFileKey<T>();
+            return GetFile(fileKey);
+        }
         #endregion
         /// <summary>
         /// 获取文件类型key值
@@ -125,7 +144,7 @@ namespace SAGA.GplotRelationComputerManage
         public static string GetFileKey<T>()
         {
             var type = typeof(T);
-            FileKeyAttribute fileKey = null;        
+            FileKeyAttribute fileKey = null;
             fileKey = type.GetCustomAttribute<FileKeyAttribute>();
             if (type.IsGenericType && fileKey == null)
             {

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

@@ -110,7 +110,7 @@ namespace SAGA.GplotRelationComputerManage
         public string ReadVersion()
         {
             string filePath = GetFilePath();
-            if (filePath != null)
+            if (string.IsNullOrWhiteSpace(filePath))
                 return ReadFileVersion(Path.GetFileName(filePath));
             return string.Empty;
         }

+ 1 - 1
MBI/SAGA.GplotRelationComputerManage/RelationType/Data/RelationItem.cs

@@ -17,7 +17,7 @@ namespace SAGA.GplotRelationComputerManage
             Objects = new List<ObjectItem>();
             Systems = new List<SystemItem>();
             ObjectRelations = new List<BinaryItem<ObjectItem>>();
-            this.SystemType = SystemType.Pipe;
+            this.SystemType = SystemType.Unknown;
         }
         #region 属性相关维护
         /// <summary>

+ 22 - 1
MBI/SAGA.GplotRelationComputerManage/RelationType/RelationTypeManager.cs

@@ -63,7 +63,12 @@ namespace SAGA.GplotRelationComputerManage
                 ParseSystems(relationItem, strSystem);
                 #endregion
 
-                if (firstItem.SystemType == "1")
+
+                if (firstItem.SystemType == "0")
+                {
+                    relationItem.SystemType = SystemType.Pipe;
+                }
+                else if (firstItem.SystemType == "1")
                 {
                     relationItem.SystemType = SystemType.Duct;
                 }
@@ -208,5 +213,21 @@ namespace SAGA.GplotRelationComputerManage
         {
             return Items.FirstOrDefault(c => c.Type == relationType);
         }
+        /// <summary>
+        /// 获取全部系统的关系类型
+        /// </summary>
+        /// <returns></returns>
+        public static List<RelationItem> GetSystemRelationTypes()
+        {
+            return Items.Where(r => r.SystemType!=SystemType.Unknown).ToList();
+        }
+        /// <summary>
+        /// 获取全部系统的关系类型
+        /// </summary>
+        /// <returns></returns>
+        public static List<string> GetSystemRelationTypeNames()
+        {
+            return GetSystemRelationTypes().Select(r => r.Type).ToList() ;
+        }
     }
 }

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

@@ -108,7 +108,7 @@
     <Compile Include="Draw\IDraw.cs" />
     <Compile Include="Draw\PointExtension.cs" />
     <Compile Include="LvSpace.cs" />
-    <Compile Include="PowerDistribution\Common\DataNodeUtil.cs" />
+    <Compile Include="Common\DataNodeUtil.cs" />
     <Compile Include="PowerDistribution\Common\PowerComputerContext.cs" />
     <Compile Include="PowerDistribution\ComputerHandler\DistributionRelationshipHandler.cs" />
     <Compile Include="PowerDistribution\ComputerHandler\EquipPowerRelationshipHandler.cs" />
@@ -137,6 +137,7 @@
     <Compile Include="SpaceRelation\SpaceComputerHandler.cs" />
     <Compile Include="SpaceRelation\SpaceComputerManager.cs" />
     <Compile Include="SystemRelation\Common\PointItemType.cs" />
+    <Compile Include="SystemRelation\Common\RelationTypeUtil.cs" />
     <Compile Include="SystemRelation\Common\SystemCalcUtil.cs" />
     <Compile Include="SystemRelation\Common\SystemParseManager.cs" />
     <Compile Include="SystemRelation\Common\VerticalResult.cs" />
@@ -148,9 +149,12 @@
     <Compile Include="SystemRelation\Data\SystemDrawItems.cs" />
     <Compile Include="SystemRelation\Data\SystemPointItem.cs" />
     <Compile Include="SystemRelation\FloorSystemItem.cs" />
+    <Compile Include="SystemRelation\RelationComputerData.cs" />
+    <Compile Include="SystemRelation\RelationDataCheck.cs" />
     <Compile Include="SystemRelation\ServerData\FloorDrawData.cs" />
     <Compile Include="SystemRelation\ServerData\MachineRoomDrawRecord.cs" />
     <Compile Include="SystemRelation\ServerData\MachineRoomRelationRecord.cs" />
+    <Compile Include="SystemRelation\ServerData\ServerData.cs" />
     <Compile Include="SystemRelation\ServerData\VerticalDrawData.cs" />
     <Compile Include="SystemRelation\ServerData\VerticalDrawRecord.cs" />
     <Compile Include="SystemRelation\ServerData\FloorDrawRecord.cs" />

+ 43 - 0
MBI/SAGA.GplotRelationComputerManage/SystemRelation/Common/RelationTypeUtil.cs

@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.GplotRelationComputerManage
+{
+    /// <summary>
+    /// 图类型相关计算方法
+    /// </summary>
+    public class RelationTypeUtil
+    {
+        /// <summary>
+        /// 获取需要重新计算的图类型
+        /// </summary>
+        /// <param name="relationTypes"></param>
+        /// <returns></returns>
+        public static List<string> NeedResetRelationTypes(List<string> relationTypes)
+        {
+            List<string> result = new List<string>();
+            foreach (string relationType in relationTypes)
+            {
+                RelationDataCheck check = new RelationDataCheck(relationType);
+                if(check.IsMissData())
+                {
+                    result.Add(relationType);
+                    continue;
+                }
+                //获取日志变更时间
+                DateTime dateTime = DateTime.Now;
+                if(check.IsExpired(dateTime))
+                {
+                    result.Add(relationType);
+                    continue;
+                }
+            }
+
+            return result;
+        }
+     
+    }
+}

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

@@ -202,6 +202,7 @@ namespace SAGA.GplotRelationComputerManage
         public void ParsePipe(SystemComputerContext context, RelationTypeShell relationSetting)
         {
             Domain useDomain = Domain.DomainPiping;
+            var relationType = relationSetting.RelationItem.Type;
             List<FloorDrawRecord> drawRecords = new List<FloorDrawRecord>();
             List<FloorRelationRecord> relationRecords = new List<FloorRelationRecord>();
             List<Element> roomStartElements = new List<Element>();
@@ -269,7 +270,7 @@ namespace SAGA.GplotRelationComputerManage
             #region 解析机房数据
 
             var useEquipments = ParseMachineRoomData(context, relationSetting, roomStartElements);
-            useEquipments=useEquipments.Distinct().ToList();
+            useEquipments = useEquipments.Distinct().ToList();
             #endregion
 
             //获取没有使用过的对象节点
@@ -278,7 +279,7 @@ namespace SAGA.GplotRelationComputerManage
             for (int i = 0; i < singleInstances.Count; i++)
             {
                 var useInstance = singleInstances[i];
-                if (useIds.Any(id => id == useInstance.Id.IntegerValue)|| useEquipments.Any(id=>id==useInstance.Id.ToString()))
+                if (useIds.Any(id => id == useInstance.Id.IntegerValue) || useEquipments.Any(id => id == useInstance.Id.ToString()))
                 {
                     continue;
                 }
@@ -330,9 +331,9 @@ namespace SAGA.GplotRelationComputerManage
             #endregion
 
             //增加立管数据
-            ComputerVerticalPipes(UseLevel, verticalMepCurves, context);
-            context.FloorDrawRecords.AddRange(drawRecords);
-            context.FloorRelationRecords.AddRange(relationRecords);
+            ComputerVerticalPipes(UseLevel, verticalMepCurves, context, relationSetting);
+            context[relationType].FloorDrawRecords.AddRange(drawRecords);
+            context[relationType].FloorRelationRecords.AddRange(relationRecords);
         }
 
         #endregion
@@ -353,11 +354,12 @@ namespace SAGA.GplotRelationComputerManage
          * 1、解析立管需要考虑,竖直风管,水管,空间的情况;
          *2、将各层数据汇总,才能统一计算立管的相关关系数据
          */
-        private void ComputerVerticalPipes(Level refLevel, List<MEPCurve> mepCurves, SystemComputerContext context)
+        private void ComputerVerticalPipes(Level refLevel, List<MEPCurve> mepCurves, SystemComputerContext context, RelationTypeShell relationSetting)
         {
             var result = new List<VerticalPipe>();
             var spaces = Document.GetElements<SpatialElement>(BuiltInCategory.OST_MEPSpaces).OfType<Space>();
             var level = refLevel;
+            var relationType = relationSetting.RelationItem.Type;
             var currentLevelName = MBIInfoUtil.GetFloorNameByLevel(level.Name);
             foreach (var pipe in mepCurves)
             {
@@ -392,8 +394,8 @@ namespace SAGA.GplotRelationComputerManage
                 Id = refLevel.Id.ToString(),
                 Name = MBIInfoUtil.GetFloorNameByLevel(refLevel.Name)
             };
-            context.VerticalPipes.AddRange(result);
-            context.Levels.Add(levelData);
+            context[relationType].VerticalPipes.AddRange(result);
+            context[relationType].Levels.Add(levelData);
         }
 
         #endregion
@@ -513,6 +515,7 @@ namespace SAGA.GplotRelationComputerManage
              * 2、设备整理,带缓存的设备信息读取
              */
             List<string> useEquipments = new List<string>();
+            var relationType = relationSetting.RelationItem.Type;
             SystemParse parse = new SystemParse(new SystemParseSetting(relationSetting));
             List<Element> useStartElements = new List<Element>(startElements);
             var arrays = parse.Execute(useStartElements);
@@ -525,7 +528,7 @@ namespace SAGA.GplotRelationComputerManage
             MachineRoomDrawRecord record = new MachineRoomDrawRecord();
             record.RelationName = relationSetting.RelationItem.Name;
             record.DrawIems = drawData;
-            context.MachineRoomDrawRecords.Add(record);
+            context[relationType].MachineRoomDrawRecords.Add(record);
             #endregion
 
             #region 生成关系数据
@@ -546,7 +549,7 @@ namespace SAGA.GplotRelationComputerManage
 
 
             }
-            context.MachineRoomRelationRecords.Add(relationRecord);
+            context[relationType].MachineRoomRelationRecords.Add(relationRecord);
             #endregion
 
             return useEquipments;

+ 191 - 0
MBI/SAGA.GplotRelationComputerManage/SystemRelation/RelationComputerData.cs

@@ -0,0 +1,191 @@
+using SAGA.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.GplotRelationComputerManage
+{
+    /*
+     * 为了控制属性的安全想,想计算数据分为保存数据,和加载数据
+     */
+    /// <summary>
+    /// 关系计算数据
+    /// </summary>
+    public class RelationComputerData
+    {
+
+        public RelationComputerData(string relationType)
+        {
+            this.RelationType = relationType;
+        }
+
+        /// <summary>
+        /// 关系类型
+        /// </summary>
+        public string RelationType { get; protected set; }
+
+
+
+        /// <summary>
+        /// 获取当前关系类型的通用键值
+        /// </summary>
+        /// <param name="commonKey"></param>
+        /// <returns></returns>
+        public string RealKey(string commonKey)
+        {
+            return ComputerFileSetting.GetRealKey(RelationType, commonKey);
+        }
+
+    }
+
+    /// <summary>
+    /// 保存的计算数据类型
+    /// </summary>
+    public class SaveComputerData : RelationComputerData
+    {
+        public SaveComputerData(string relationType) : base(relationType)
+        {
+            Init();
+        }
+        /// <summary>
+        /// 初始化集合字段
+        /// </summary>
+        private void Init()
+        {
+            VerticalPipes = new List<VerticalPipe>();
+            Levels = new List<LevelData>();
+            FloorDrawRecords = new List<FloorDrawRecord>();
+            FloorRelationRecords = new List<FloorRelationRecord>();
+            MachineRoomDrawRecords = new List<MachineRoomDrawRecord>();
+            MachineRoomRelationRecords = new List<MachineRoomRelationRecord>();
+        }
+        #region 存储数据
+        public List<VerticalPipe> VerticalPipes { get; private set; }
+        public List<LevelData> Levels { get; private set; }
+
+        public List<FloorDrawRecord> FloorDrawRecords { get; protected set; }
+        public List<FloorRelationRecord> FloorRelationRecords { get; protected set; }
+        public List<MachineRoomDrawRecord> MachineRoomDrawRecords { get; protected set; }
+        public List<MachineRoomRelationRecord> MachineRoomRelationRecords { get; protected set; }
+        #endregion
+
+        /// <summary>
+        /// 保存立面数据
+        /// </summary>
+        public void SaveData()
+        {
+            DataServerUtil.Current.SaveData(RealKey(ComputerFileSetting.FloorDraw), FloorDrawRecords);
+            DataServerUtil.Current.SaveData(RealKey(ComputerFileSetting.FloorRelation), FloorRelationRecords);
+            DataServerUtil.Current.SaveData(RealKey(ComputerFileSetting.MachineRoomDraw), MachineRoomDrawRecords);
+            DataServerUtil.Current.SaveData(RealKey(ComputerFileSetting.MachineRoomRelation), MachineRoomRelationRecords);
+            var result = SystemParseManager.ComputerVerticalData(VerticalPipes, Levels);
+            DataServerUtil.Current.SaveData(RealKey(ComputerFileSetting.VerticalDraw), result.DrawData);
+            DataServerUtil.Current.SaveData(RealKey(ComputerFileSetting.VerticalRelation), result.RelationData);
+        }
+    }
+
+    /// <summary>
+    /// 加载的关系数据
+    /// </summary>
+    public class LoadRelationData : RelationComputerData
+    {
+        public LoadRelationData(string relationType) : base(relationType)
+        {
+            FloorRelationRecords = new List<FloorRelationRecord>();
+            VerticalRelationRecords = new List<VerticalRelationRecord>();
+            MachineRoomRelationRecords = new List<MachineRoomRelationRecord>();
+        }
+        #region 存储数据
+
+        public List<FloorRelationRecord> FloorRelationRecords { get; protected set; }
+        public List<MachineRoomRelationRecord> MachineRoomRelationRecords { get; protected set; }
+        public List<VerticalRelationRecord> VerticalRelationRecords { get; private set; }
+        #endregion
+        #region 数据的保存加载
+        /// <summary>
+        /// 加载计算数据
+        /// </summary>
+        public void LoadData()
+        {
+            FloorRelationRecords = DataServerUtil.Current.LoadData<List<FloorRelationRecord>>(RealKey(ComputerFileSetting.FloorRelation));
+            MachineRoomRelationRecords = DataServerUtil.Current.LoadData<List<MachineRoomRelationRecord>>(RealKey(ComputerFileSetting.MachineRoomRelation));
+            VerticalRelationRecords = DataServerUtil.Current.LoadData<List<VerticalRelationRecord>>(RealKey(ComputerFileSetting.VerticalRelation));
+        }
+
+        #endregion
+    }
+
+    /// <summary>
+    /// 加载平面展示数据
+    /// </summary>
+    public class LoadFloorDrawData : RelationComputerData
+    {
+        public LoadFloorDrawData(string relationType) : base(relationType)
+        {
+            FloorDrawRecords = new List<FloorDrawRecord>();
+        }
+        #region 存储数据
+
+        public List<FloorDrawRecord> FloorDrawRecords { get; protected set; }
+
+        #endregion
+        #region 数据的保存加载
+        /// <summary>
+        /// 加载计算数据
+        /// </summary>
+        public void LoadData()
+        {
+            FloorDrawRecords = DataServerUtil.Current.LoadData<List<FloorDrawRecord>>(RealKey(ComputerFileSetting.FloorDraw));
+        }
+
+        #endregion
+    }
+
+    /// <summary>
+    /// 加载机房展示数据
+    /// </summary>
+    public class LoadMachineRoomDrawData : RelationComputerData
+    {
+        public LoadMachineRoomDrawData(string relationType) : base(relationType)
+        {
+            MachineRoomDrawRecords = new List<MachineRoomDrawRecord>();
+        }
+
+        public List<MachineRoomDrawRecord> MachineRoomDrawRecords { get; protected set; }
+        #region 数据的保存加载
+        /// <summary>
+        /// 加载计算数据
+        /// </summary>
+        public void LoadData()
+        {
+            MachineRoomDrawRecords = DataServerUtil.Current.LoadData<List<MachineRoomDrawRecord>>(RealKey(ComputerFileSetting.MachineRoomDraw));
+        }
+        #endregion
+    }
+
+    /// <summary>
+    /// 加载立面展示
+    /// </summary>
+    public class LoadVerticalDrawData : RelationComputerData
+    {
+        public LoadVerticalDrawData(string relationType) : base(relationType)
+        {
+            VerticalDrawData = new VerticalDrawData();
+        }
+        #region 存储数据
+
+        public VerticalDrawData VerticalDrawData { get; protected set; }
+        #endregion
+        /// <summary>
+        /// 加载计算数据
+        /// </summary>
+        public void LoadData()
+        {
+
+            VerticalDrawData = DataServerUtil.Current.LoadData<VerticalDrawData>(RealKey(ComputerFileSetting.VerticalDraw));
+
+        }
+    }
+}

+ 37 - 0
MBI/SAGA.GplotRelationComputerManage/SystemRelation/RelationDataCheck.cs

@@ -0,0 +1,37 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.GplotRelationComputerManage
+{
+    /// <summary>
+    /// 关系数据检查[借用基类的数据和方法:在语义上应该没有关联关系]
+    /// </summary>
+    public class RelationDataCheck:RelationComputerData
+    {
+
+        public RelationDataCheck(string relationType):base(relationType)
+        {
+          
+        }
+        /// <summary>
+        /// 判定数据是否过期
+        /// </summary>
+        /// <param name="dateTime"></param>
+        /// <returns></returns>
+        public bool IsExpired(DateTime dateTime)
+        {
+           return DataServerUtil.Current.IsExpired(RealKey(ComputerFileSetting.FloorDraw), dateTime);
+        }
+        /// <summary>
+        /// 判断计算数据是否缺失
+        /// </summary>
+        /// <returns></returns>
+        public bool IsMissData()
+        {
+            return DataServerUtil.Current.GetFile(RealKey(ComputerFileSetting.FloorDraw)).Exists();
+        }
+    }
+}

+ 1 - 1
MBI/SAGA.GplotRelationComputerManage/SystemRelation/ServerData/FloorDrawData.cs

@@ -16,7 +16,7 @@ namespace SAGA.GplotRelationComputerManage
     /// <summary>
     /// 平面数据结构
     /// </summary>
-    public class FloorDrawData
+    public class FloorDrawData: ServerData
     {
         /// <summary>
         /// 楼层信息

+ 2 - 5
MBI/SAGA.GplotRelationComputerManage/SystemRelation/ServerData/FloorRecord.cs

@@ -22,7 +22,7 @@ namespace SAGA.GplotRelationComputerManage
     /// <summary>
     /// 楼层信息记录
     /// </summary>
-    public class FloorRecord
+    public class FloorRecord: ServerData
     {
         public string FloorId { get; set; }
         public string FloorName { get; set; }
@@ -31,10 +31,7 @@ namespace SAGA.GplotRelationComputerManage
         /// 楼层高度
         /// </summary>
         public double FloorLevelElevation { get; set; }
-        /// <summary>
-        /// 关联类型
-        /// </summary>
-        public string RelationType { get; set; }
+     
 
         /// <summary>
         /// 设置楼层信息

+ 1 - 1
MBI/SAGA.GplotRelationComputerManage/SystemRelation/ServerData/MachineRoomDrawRecord.cs

@@ -16,7 +16,7 @@ namespace SAGA.GplotRelationComputerManage
     /// <summary>
     /// 机房绘图数据
     /// </summary>
-    public class MachineRoomDrawRecord
+    public class MachineRoomDrawRecord : ServerData
     {
         /// <summary>
         /// 关系名称

+ 1 - 1
MBI/SAGA.GplotRelationComputerManage/SystemRelation/ServerData/MachineRoomRelationRecord.cs

@@ -16,7 +16,7 @@ namespace SAGA.GplotRelationComputerManage
     /// <summary>
     /// 机房关系数据
     /// </summary>
-    public class MachineRoomRelationRecord
+    public class MachineRoomRelationRecord : ServerData
     {
         /// <summary>
         /// 关系名称

+ 25 - 0
MBI/SAGA.GplotRelationComputerManage/SystemRelation/ServerData/ServerData.cs

@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.GplotRelationComputerManage
+{ 
+    public class ServerData
+    {
+        /// <summary>
+        /// 建筑Id
+        /// </summary>
+        public string BuildingId { get; set; }
+        /// <summary>
+        /// 建筑名称
+        /// </summary>
+        public string BuildingName { get; set; }
+
+        /// <summary>
+        /// 关联类型
+        /// </summary>
+        public string RelationType { get; set; }
+    }
+}

+ 1 - 1
MBI/SAGA.GplotRelationComputerManage/SystemRelation/ServerData/VerticalDrawData.cs

@@ -11,7 +11,7 @@ namespace SAGA.GplotRelationComputerManage
     /// <summary>
     /// 垂直立管相关信息
     /// </summary>
-    public class VerticalDrawData
+    public class VerticalDrawData : ServerData
     {
         public VerticalDrawData()
         {

+ 1 - 1
MBI/SAGA.GplotRelationComputerManage/SystemRelation/ServerData/VerticalRelationRecord.cs

@@ -16,7 +16,7 @@ namespace SAGA.GplotRelationComputerManage
     /// <summary>
     /// 立面关系数据
     /// </summary>
-    public class VerticalRelationRecord
+    public class VerticalRelationRecord : ServerData
     {
         /// <summary>
         /// 系统名称

+ 28 - 23
MBI/SAGA.GplotRelationComputerManage/SystemRelation/SystemComputerContext.cs

@@ -23,13 +23,7 @@ namespace SAGA.GplotRelationComputerManage
             Rooms = SystemCalcUtil.CreateRoomItems();
             RelationShells = SystemCalcUtil.CreateRelationShellItems();
             EquipmentItems = SystemCalcUtil.CreateEquipmentItems();
-            VerticalPipes = new List<VerticalPipe>();
-            Levels = new List<LevelData>();
             Relations = new List<string>();
-            FloorDrawRecords = new List<FloorDrawRecord>();
-            FloorRelationRecords = new List<FloorRelationRecord>();
-            MachineRoomDrawRecords = new List<MachineRoomDrawRecord>();
-            MachineRoomRelationRecords = new List<MachineRoomRelationRecord>();
             #endregion
         }
         #region 计算缓存对象
@@ -77,16 +71,30 @@ namespace SAGA.GplotRelationComputerManage
         }
         #endregion
 
-        #region 计算结果存储类
-        /*
-         *计算数据存储在Context中,FloorSystemItem尽量只跟解析算法相关
-         */
-        public List<VerticalPipe> VerticalPipes { get; private set; }
-        public List<LevelData> Levels { get; private set; }
-        public List<FloorDrawRecord> FloorDrawRecords { get; private set; }
-        public List<FloorRelationRecord> FloorRelationRecords { get; private set; }
-        public List<MachineRoomDrawRecord> MachineRoomDrawRecords { get; private set; }
-        public List<MachineRoomRelationRecord> MachineRoomRelationRecords { get; private set; }
+        #region 计算结果存储类      
+        private Dictionary<string, SaveComputerData> m_DicComputerData = new Dictionary<string, SaveComputerData>();
+        /// <summary>
+        /// 获取指定类型的保存数据
+        /// </summary>
+        /// <param name="relationType"></param>
+        /// <returns></returns>
+        public SaveComputerData this[string relationType]
+        {
+            get
+            {
+                if (string.IsNullOrWhiteSpace(relationType))
+                    throw new ArgumentNullException(nameof(relationType));
+                if (m_DicComputerData.TryGetValue(relationType, out SaveComputerData tempData))
+                {
+                    return tempData;
+                }
+                else
+                {
+                    m_DicComputerData[relationType] = tempData = new SaveComputerData(relationType);
+                    return tempData;
+                }
+            }
+        }
         #endregion
 
         #region 需要计算的系统相关
@@ -107,13 +115,10 @@ namespace SAGA.GplotRelationComputerManage
         /// </summary>
         public void SaveComputerData()
         {
-            DataServerUtil.Current.SaveData(ComputerFileSetting.FloorDraw, FloorDrawRecords);
-            DataServerUtil.Current.SaveData(ComputerFileSetting.FloorRelation, FloorRelationRecords);
-            DataServerUtil.Current.SaveData(ComputerFileSetting.MachineRoomDraw, MachineRoomDrawRecords);
-            DataServerUtil.Current.SaveData(ComputerFileSetting.MachineRoomRelation, MachineRoomRelationRecords);
-            var result = SystemParseManager.ComputerVerticalData(VerticalPipes, Levels);
-            DataServerUtil.Current.SaveData(ComputerFileSetting.VerticalDraw, result.DrawData);
-            DataServerUtil.Current.SaveData(ComputerFileSetting.VerticalRelation, result.RelationData);
+            foreach (var item in m_DicComputerData)
+            {
+                item.Value.SaveData();
+            }
         }
         #endregion
     }

+ 31 - 3
MBI/SAGA.GplotRelationComputerManage/SystemRelation/SystemComputerHandler.cs

@@ -17,7 +17,11 @@ namespace SAGA.GplotRelationComputerManage
 {
    public  class SystemComputerHandler
     {
-        public List<object> GetParseData(SystemComputerContext context)
+        /// <summary>
+        /// 根据上下文计算系统数据
+        /// </summary>
+        /// <param name="context"></param>
+        public void Computer(SystemComputerContext context)
         {
             List<object> items = new List<object>();
             var fileInfos = RevitModelPath.GetAllRevitFiles();
@@ -31,8 +35,32 @@ namespace SAGA.GplotRelationComputerManage
                 }
             }
             context.SaveComputerData();
-            //最后统保存缓存数据
-            return items;
+        }
+        
+        /// <summary>
+        /// 根据输入系统类型计算系统数据
+        /// </summary>
+        /// <param name="relationTypes"></param>
+        public void Computer(List<string> relationTypes)
+        {
+            SystemComputerContext context = new SystemComputerContext();
+            context.Relations.AddRange(relationTypes);
+            Computer(context);
+        }
+        /// <summary>
+        /// 计算没有被缓存或者缓存过期的数据
+        /// </summary>
+        /// <param name="relationTypes"></param>
+        public void ComputerWidthCache(List<string> relationTypes)
+        {
+            if (relationTypes == null || relationTypes.Any())
+                return;
+            var useRelationTypes = RelationTypeUtil.NeedResetRelationTypes(relationTypes);
+            if(!useRelationTypes.Any())
+            {
+                return;
+            }
+            Computer(useRelationTypes);
         }
     }
 }

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

@@ -310,5 +310,6 @@
       <Name>SAGA.RevitUtility</Name>
     </ProjectReference>
   </ItemGroup>
+  <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>