浏览代码

xls:底图数据缓存整理

xulisong 6 年之前
父节点
当前提交
8603d7c169
共有 21 个文件被更改,包括 491 次插入88 次删除
  1. 0 18
      MBI/SAGA.GplotDrawData/DBView/BaseMapManager.cs
  2. 1 1
      MBI/SAGA.GplotDrawData/DBView/FloorSystemGraphView.cs
  3. 1 1
      MBI/SAGA.GplotDrawData/DBView/MachineRoomGraphView.cs
  4. 2 1
      MBI/SAGA.GplotDrawData/DBView/PipeEndGraphView.cs
  5. 4 20
      MBI/SAGA.GplotDrawData/DBView/SpaceGraphView.cs
  6. 0 1
      MBI/SAGA.GplotDrawData/SAGA.GplotDrawData.csproj
  7. 2 1
      MBI/SAGA.GplotManage/GplotCommand.cs
  8. 120 28
      MBI/SAGA.GplotManage/SystemRelation/RelationDataUtil.cs
  9. 93 0
      MBI/SAGA.GplotRelationComputerManage/BaseMap/BaseMapManager.cs
  10. 43 0
      MBI/SAGA.GplotRelationComputerManage/BaseMap/FloorMapData.cs
  11. 46 0
      MBI/SAGA.GplotRelationComputerManage/BaseMap/FloorMapDataCheck.cs
  12. 2 2
      MBI/SAGA.GplotRelationComputerManage/Common/ComputerFileSetting.cs
  13. 25 10
      MBI/SAGA.GplotRelationComputerManage/Common/MBIInfoUtil.cs
  14. 1 1
      MBI/SAGA.GplotRelationComputerManage/DataServer/TimeVersionFile.cs
  15. 4 0
      MBI/SAGA.GplotRelationComputerManage/SAGA.GplotRelationComputerManage.csproj
  16. 1 1
      MBI/SAGA.GplotRelationComputerManage/SystemRelation/Common/SystemCalcUtil.cs
  17. 1 0
      MBI/SAGA.GplotRelationComputerManage/SystemRelation/Common/SystemParseManager.cs
  18. 40 1
      MBI/SAGA.GplotRelationComputerManage/SystemRelation/Data/BinaryRelationItem.cs
  19. 11 1
      MBI/SAGA.GplotRelationComputerManage/SystemRelation/FloorSystemItem.cs
  20. 4 1
      MBI/SAGA.GplotRelationComputerManage/SystemRelation/SystemComputerHandler.cs
  21. 90 0
      MBI/SAGA.MBI/TestCommand.cs

+ 0 - 18
MBI/SAGA.GplotDrawData/DBView/BaseMapManager.cs

@@ -47,23 +47,5 @@ namespace SAGA.GplotDrawData
             var exportDb=manager.ExportMbiEelemntDB(ExportDataBuilder.CreateExportData(elements));
             return exportDb.ToJsonObject();
         }
-        /// <summary>
-        /// 初始化当前楼层信息
-        /// </summary>
-        public static void InitCurrentProjectFloor()
-        {
-            //var fileInfos = RevitModelPath.GetAllRevitFiles();
-            ////所有项目中所有文档
-            //List<Element> startElements = new List<Element>();
-            //Dictionary<Document, List<Element>> allDatas = new Dictionary<Document, List<Element>>();
-            //foreach (var tPath in fileInfos)
-            //{
-            //    if (File.Exists(tPath))
-            //    {
-            //        Document linkDoc = ExternalDataWrapper.Current.App.OpenDocumentFile(tPath);
-            //        startElements.AddRange(startManager.GetStartElements(linkDoc));
-            //    }
-            //}
-        }
     }
 }

+ 1 - 1
MBI/SAGA.GplotDrawData/DBView/FloorSystemGraphView.cs

@@ -45,7 +45,7 @@ namespace SAGA.GplotDrawData
             var floorName = floorId;
             try
             {
-                var jsObject = BaseMapManager.GetFloorInfo(floorName);
+                var jsObject = BaseMapManager.GetFloorInfoWithCache(floorName);
                 db.RefJObjects.Add(jsObject);
             }
             catch (Exception ex)

+ 1 - 1
MBI/SAGA.GplotDrawData/DBView/MachineRoomGraphView.cs

@@ -31,7 +31,7 @@ namespace SAGA.GplotDrawData
             }
             foreach (var curve in drawItem.Curves)
             {
-                GLine gline = new GLine(curve.Points[0].ConvertToPoint3D(), curve.Points[0].ConvertToPoint3D());
+                GLine gline = new GLine(curve.Points[0].ConvertToPoint3D(), curve.Points[1].ConvertToPoint3D());
                 gline.ElementColor = Colors.Red;
                 db.Elements.Add(gline);
             }

+ 2 - 1
MBI/SAGA.GplotDrawData/DBView/PipeEndGraphView.cs

@@ -8,6 +8,7 @@ using System.Text;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Media;
+using SAGA.GplotRelationComputerManage;
 
 namespace SAGA.GplotDrawData
 {
@@ -69,7 +70,7 @@ namespace SAGA.GplotDrawData
             var floorName = fd.Id.Split('-')[1];
             try
             {
-                var jsObject = BaseMapManager.GetFloorInfo(floorName);
+                var jsObject = BaseMapManager.GetFloorInfoWithCache(floorName);
                 db.RefJObjects.Add(jsObject);
             }
             catch (Exception ex)

+ 4 - 20
MBI/SAGA.GplotDrawData/DBView/SpaceGraphView.cs

@@ -1,4 +1,5 @@
-using SAGA.Models;
+using SAGA.GplotRelationComputerManage;
+using SAGA.Models;
 using SAGA.Models.Graphs;
 using System;
 using System.Collections.Generic;
@@ -49,30 +50,13 @@ namespace SAGA.GplotDrawData
             var floorName = fd.Id.Split('-')[1];
             try
             {
-                var jsObject = BaseMapManager.GetFloorInfo(floorName);
+                var jsObject = BaseMapManager.GetFloorInfoWithCache(floorName);
                 db.RefJObjects.Add(jsObject);
             }
             catch (Exception ex)
             {
 
-            }
-            //var walls = DrawDataServer.GetWallData().FloorDatas?.FirstOrDefault(t => t.Id == floorName);;         
-            //foreach (var line in walls.Lines)
-            //{
-            //    var path=line.ConvertToGPath();
-            //    if (!path.Data.Any())
-            //        continue;
-            //    path.Thickness = 7;
-            //    db.Elements.Add(path);
-            //}
-            //foreach (var line in walls.VirLines)
-            //{
-            //    var path = line.ConvertToGPath();
-            //    if (!path.Data.Any())
-            //        continue;
-            //    path.ElementColor = Colors.Green;
-            //    db.Elements.Add(path);
-            //}    
+            }    
             #endregion
             return db;
         }

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

@@ -67,7 +67,6 @@
       <SubType>Designer</SubType>
     </ApplicationDefinition>
     <Compile Include="Common\WebGplotSettings.cs" />
-    <Compile Include="DBView\BaseMapManager.cs" />
     <Compile Include="DBView\EquipmentGraphView.cs" />
     <Compile Include="DBView\FloorSystemGraphView.cs" />
     <Compile Include="DBView\IGraphDBView.cs" />

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

@@ -64,7 +64,8 @@ namespace SAGA.GplotManage
     {
         public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
         {
-            List<string> useRelations = new List<string>() { "ChillWaterLoop" };
+            //RelationTypeManager.GetSystemRelationTypeNames() 
+            List<string> useRelations =new List<string>() { "ChillWaterLoop" };
             SystemComputerHandler handler1 = new SystemComputerHandler();
             handler1.ComputerWidthCache(useRelations);
             WinSystem floorWin = new WinSystem(GplotShowType.ViewPlan);

+ 120 - 28
MBI/SAGA.GplotManage/SystemRelation/RelationDataUtil.cs

@@ -21,6 +21,7 @@ namespace SAGA.GplotManage
         public static List<ReleateData> BuildRelations(LoadRelationData relationData)
         {
             #region 说明
+
             /*
              * 数据关联项:
              * 机房设备---特殊阀门
@@ -28,11 +29,15 @@ namespace SAGA.GplotManage
              * 立管--立管
              * 立管---平面设备;由此=》机房设备---平面设备
              */
+
             #endregion
+
             List<ReleateData> result = new List<ReleateData>();
             List<BinaryRelationItem> roomRelations = new List<BinaryRelationItem>();
             List<BinaryRelationItem> floorRelations = new List<BinaryRelationItem>();
+
             #region 机房关系数据
+
             var machineRoomData = relationData.MachineRoomRelationRecords;
             foreach (var machineRelation in machineRoomData)
             {
@@ -48,8 +53,11 @@ namespace SAGA.GplotManage
                     }
                 }
             }
+
             #endregion
+
             #region 平面关系数据
+
             foreach (var floorRelation in relationData.FloorRelationRecords)
             {
                 foreach (var item in floorRelation.RelationItems)
@@ -60,26 +68,34 @@ namespace SAGA.GplotManage
                     }
                     else
                     {
-                        roomRelations.Add(item);
+                        floorRelations.Add(item);
                     }
                 }
             }
+
             #endregion
 
             var verticalSets = relationData.VerticalRelationRecords;
 
             #region 机房和平面关联
+
             /*
              * 前提不是全设备
+             * 产生关系方式 源--端--立管--源--端,源--端--立管--端,源--端
              */
             foreach (var roomRelation in roomRelations)
             {
                 EquipmentNode equipmentNode, linkNode;
-                if(!roomRelation.From.IsRealEquipment&&!roomRelation.To.IsRealEquipment)
+                var systemName = roomRelation.RelationType;
+
+                #region 源
+
+                if (!roomRelation.From.IsRealEquipment && !roomRelation.To.IsRealEquipment)
                 {
                     continue;
                 }
-                if(roomRelation.From.IsRealEquipment)
+
+                if (roomRelation.From.IsRealEquipment)
                 {
                     equipmentNode = roomRelation.From;
                     linkNode = roomRelation.To;
@@ -89,38 +105,113 @@ namespace SAGA.GplotManage
                     equipmentNode = roomRelation.To;
                     linkNode = roomRelation.From;
                 }
-                List<string> useLinks = new List<string>();
-                var useSet = verticalSets.FirstOrDefault(s => s.RelationItems.Any(item => item == linkNode.BimId));
-                if(useSet==null)
-                {
-                    useLinks.Add(linkNode.BimId);
-                }
-                else
-                {
-                    useLinks.AddRange(useSet.RelationItems);
-                }
-                foreach (var useLink in useLinks)
+
+                #endregion
+
+                #region 端
+
+                foreach (var endRelation in floorRelations)
                 {
-                   var floorRelation= floorRelations.FirstOrDefault(c => c.From.BimId == useLink || c.To.BimId == useLink);
-                    BinaryRelationItem newRelationItem = new BinaryRelationItem();
-                    newRelationItem.From = equipmentNode;
-                    newRelationItem.To = floorRelation.From.BimId != useLink ? floorRelation.From : floorRelation.To;
-                    newRelationItem.RelationType = floorRelation.RelationType;
-
-                    //加入关系数据
-                    result.Add(CreateRelationData(newRelationItem));
+                    var mathFlag = endRelation.TryGetNode(n => n.BimId == linkNode.BimId, out EquipmentNode refNode);
+                    if (mathFlag > -1)
+                    {
+                        var anotherNode = endRelation.GetAnotherNode(n => n.BimId == refNode.BimId);
+                        if (anotherNode.IsRealEquipment)
+                        {
+                            //第三种情况
+                            BinaryRelationItem newRelationItem = new BinaryRelationItem();
+                            newRelationItem.From = equipmentNode;
+                            newRelationItem.To = anotherNode;
+                            newRelationItem.RelationType = systemName;
+                            result.Add(CreateRelationData(newRelationItem));
+                        }
+                        else
+                        {
+                            var verticalSet = verticalSets.FirstOrDefault(s =>
+                                s.RelationItems.Any(item => item == anotherNode.BimId));
+                            if (verticalSet == null)
+                                continue;
+                            var verticalIds = new List<string>(verticalSet.RelationItems);
+                            foreach (var verticalId in verticalIds)
+                            {
+                                bool findV = false;
+
+                                #region 立管找端
+
+                                foreach (var vEndRelation in floorRelations)
+                                {
+                                    var vAnother = vEndRelation.GetAnotherNode(n => n.BimId == verticalId);
+                                    if (vAnother == null || !vAnother.IsRealEquipment)
+                                    {
+                                        continue;
+                                    }
+
+                                    //第二种情况
+                                    BinaryRelationItem newRelationItem = new BinaryRelationItem();
+                                    newRelationItem.From = equipmentNode;
+                                    newRelationItem.To = vAnother;
+                                    newRelationItem.RelationType = systemName;
+                                    result.Add(CreateRelationData(newRelationItem));
+                                    findV = true;
+                                }
+
+                                #endregion
+
+                                if (findV)
+                                {
+                                    continue;
+                                }
+
+                                #region 立管找源
+
+                                foreach (var vSourceRelation in roomRelations)
+                                {
+                                    var vAnother = vSourceRelation.GetAnotherNode(n => n.BimId == verticalId);
+                                    if (vAnother == null)
+                                    {
+                                        continue;
+                                    }
+
+                                    #region 源找端
+
+                                    foreach (var floorRelation in floorRelations)
+                                    {
+                                        var sa = floorRelation.GetAnotherNode(n => n.BimId == vAnother.BimId);
+                                        if (sa == null || !sa.IsRealEquipment)
+                                        {
+                                            //第一种情况
+                                            BinaryRelationItem newRelationItem = new BinaryRelationItem();
+                                            newRelationItem.From = equipmentNode;
+                                            newRelationItem.To = sa;
+                                            newRelationItem.RelationType = systemName;
+                                            result.Add(CreateRelationData(newRelationItem));
+                                        }
+                                    }
+
+                                    #endregion
+                                }
+
+                                #endregion
+                            }
+                        }
+                    }
                 }
 
+                #endregion
             }
-            #endregion
+
             return result;
+
+            #endregion
         }
+
+
         /// <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();
@@ -139,6 +230,7 @@ namespace SAGA.GplotManage
             relation.from_id = relationItem.From.MbiId;
             relation.to_id = relationItem.To.MbiId;
             relation.rel_type = relationItem.RelationType;
+            relation.infos = new Info() {info1 = relationItem.From.BimId, info2 = relationItem.To.BimId};
             return relation;
         }
         #endregion

+ 93 - 0
MBI/SAGA.GplotRelationComputerManage/BaseMap/BaseMapManager.cs

@@ -0,0 +1,93 @@
+using Autodesk.Revit.DB;
+using Newtonsoft.Json.Linq;
+using SAGA.MBI.DataArrange;
+using SAGA.MBI.RevitExport;
+using SAGA.RevitUtils.Extends;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.GplotRelationComputerManage
+{
+    /// <summary>
+    /// 底图管理
+    /// </summary>
+    public static class BaseMapManager
+    {
+        /*
+         * 静态方法传相关参数
+         */
+        public const string BaseMapDirectoryName = "BaseMap";
+        /// <summary>
+        /// 获取带缓存的楼层底图数据
+        /// </summary>
+        /// <param name="floorId"></param>
+        /// <returns></returns>
+        public static JObject GetFloorInfoWithCache(string floorId)
+        {
+            FloorMapDataCheck check = new FloorMapDataCheck(floorId);
+            var filePath = DalProjectTree.GetFloorByFloorId(floorId)?.FullPath;
+            if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))
+            {
+                return new JObject();
+            }
+            bool isComputer = false;
+            #region 监测缓存
+            if (check.IsMissData())
+            {
+                //文件缺失,则重新计算
+                isComputer = true;
+            }
+            else
+            {
+                DateTime dateTime = File.GetLastWriteTime(filePath);
+                //过期则重新计算
+                isComputer = check.IsExpired(dateTime);
+            } 
+            #endregion
+            JObject result = null;
+            FloorMapData floorMap = new FloorMapData(floorId);
+            if (isComputer)
+            {
+                result = GetFloorMap(filePath);
+             
+                floorMap.FloorMap = result;
+                floorMap.SaveData();
+            }
+            else
+            {
+                floorMap.LoadData();
+                result = floorMap.FloorMap;
+            }
+            return result;
+        }
+        #region 辅助方法
+        public static string RealKey(string floorId)
+        {
+            var key=  ComputerFileSetting.GetRealKey(floorId, ComputerFileSetting.FloorMap);
+            return Path.Combine(BaseMapDirectoryName, key);
+        }
+        /// <summary>
+        /// 获取指定路径下的值
+        /// </summary>
+        /// <param name="filePath"></param>
+        /// <returns></returns>
+        public static JObject GetFloorMap(string filePath)
+        {
+            List<Element> elements = new List<Element>();
+            if (string.IsNullOrEmpty(filePath) || File.Exists(filePath))
+            {
+                Document linkDoc = ExternalDataWrapper.Current.App.OpenDocumentFile(filePath);
+                elements = linkDoc.GetElements<Wall>().ToList<Element>();
+                elements.AddRange(linkDoc.GetElements<CurveElement>(BuiltInCategory.OST_MEPSpaceSeparationLines).ToList<Element>());
+            }
+            MbiElementManager manager = new MbiElementManager();
+            var exportDb = manager.ExportMbiEelemntDB(ExportDataBuilder.CreateExportData(elements));
+            return exportDb.ToJsonObject();
+        }
+        #endregion
+    }
+}

+ 43 - 0
MBI/SAGA.GplotRelationComputerManage/BaseMap/FloorMapData.cs

@@ -0,0 +1,43 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:FloorMapData
+ * 作者:xulisong
+ * 创建时间: 2019/1/29 15:52:51
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Newtonsoft.Json.Linq;
+
+namespace SAGA.GplotRelationComputerManage
+{
+    /// <summary>
+    /// 楼层数据
+    /// </summary>
+    public class FloorMapData
+    {
+        public FloorMapData(string floorId)
+        {
+            FloorId = floorId;
+        }
+        public string FloorId { get; private set; }
+        public JObject FloorMap { get; set; }
+        /// <summary>
+        /// 保存楼层数据
+        /// </summary>
+        public void SaveData()
+        {
+            DataServerUtil.Current.SaveData(BaseMapManager.RealKey(FloorId), FloorMap??new JObject());            
+        }
+        /// <summary>
+        /// 加载楼层数据
+        /// </summary>
+        public void LoadData()
+        {
+            FloorMap = DataServerUtil.Current.LoadData<JObject>(BaseMapManager.RealKey(FloorId)) ?? new JObject();           
+        }
+    }
+}

+ 46 - 0
MBI/SAGA.GplotRelationComputerManage/BaseMap/FloorMapDataCheck.cs

@@ -0,0 +1,46 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:FloorMapDataCheck
+ * 作者:xulisong
+ * 创建时间: 2019/1/29 15:36:04
+ * 版本号: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 FloorMapDataCheck
+    {
+        public FloorMapDataCheck(string floorId)
+        {
+            FloorId = floorId;
+        }
+        public string FloorId { get; private set; }
+        /// <summary>
+        /// 判定数据是否过期
+        /// </summary>
+        /// <param name="dateTime"></param>
+        /// <returns></returns>
+        public bool IsExpired(DateTime dateTime)
+        {
+            return DataServerUtil.Current.IsExpired(BaseMapManager.RealKey(FloorId), dateTime);
+        }
+        /// <summary>
+        /// 判断计算数据是否缺失
+        /// </summary>
+        /// <returns></returns>
+        public bool IsMissData()
+        {
+            return !DataServerUtil.Current.GetFile(BaseMapManager.RealKey(FloorId)).Exists();
+        }
+
+
+    }
+}

+ 2 - 2
MBI/SAGA.GplotRelationComputerManage/Common/ComputerFileSetting.cs

@@ -7,7 +7,7 @@ using System.Threading.Tasks;
 namespace SAGA.GplotRelationComputerManage
 {
     /// <summary>
-  //
+    /// 计算文件相关数据管理
     /// </summary>
     public class ComputerFileSetting
     {
@@ -17,7 +17,7 @@ namespace SAGA.GplotRelationComputerManage
         public const string VerticalRelation = "VerticalRelation";
         public const string MachineRoomDraw = "MechineRoomDraw";
         public const string MachineRoomRelation = "MechineRoomRelation";
-
+        public const string FloorMap = "FloorMap";
         /// <summary>
         /// 获取通用的文件名称
         /// </summary>

+ 25 - 10
MBI/SAGA.GplotRelationComputerManage/Common/MBIInfoUtil.cs

@@ -81,14 +81,14 @@ namespace SAGA.GplotRelationComputerManage
                 return false;
             }
             string familyName = element.GetFamily()?.Name ?? string.Empty;
-            var match = Regex.Match(familyName, @"^(?:((?:[A-Z][A-Z]){2,3})\s*-\s*\S*)");
-            return match.Success;
+            return TryGetEquipmentCategory(familyName, out string category); ;
         }
 
         /// <summary>
         /// 获取设备的分类
         /// </summary>
         /// <param name="element"></param>
+        /// <param name="category"></param>
         /// <returns></returns>
         public static bool TryGetEquipmentCategory(Element element,out string category)
         {
@@ -105,12 +105,7 @@ namespace SAGA.GplotRelationComputerManage
                 return false;
             }
             string familyName = element.GetFamily()?.Name ?? string.Empty;
-            var match = Regex.Match(familyName, @"^(?:((?:[A-Z][A-Z]){2,3})\s*-\s*\S*)");
-            if (match.Success)
-            {
-                category = match.Groups[1].ToString();
-            }
-            return match.Success;
+            return TryGetEquipmentCategory(familyName, out category);
         }
         /// <summary>
         /// 获取设备的设备分类
@@ -125,12 +120,32 @@ namespace SAGA.GplotRelationComputerManage
                 return category;
             }
             string familyName = fi.GetFamily()?.Name;
-            var match = Regex.Match(familyName, @"^(?:((?:[A-Z][A-Z]){2,3})\s*-\s*\S*)");
+            TryGetEquipmentCategory(familyName,out category);
+            return category;
+        }
+        /// <summary>
+        /// 截取指定字符串的category信息【如果不符合规范返回null】
+        /// </summary>
+        /// <param name="name"></param>
+        /// <returns></returns>
+        public static string GetEquipmentCategory(string name)
+        {
+            string category;
+            TryGetEquipmentCategory(name, out category);
+            return category;
+        }
+
+        public static bool TryGetEquipmentCategory(string name, out string category)
+        {
+            bool result = false;
+            category = null;
+            var match = Regex.Match(name, @"^(?:((?:[A-Z][A-Z]){2,3})\s*-\s*\S*)");
             if (match.Success)
             {
                 category = match.Groups[1].ToString();
+                result = true;
             }
-            return category;
+            return result;
         }
         /// <summary>
         /// 通过标高名称获取楼层名称

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

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

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

@@ -77,6 +77,9 @@
     <Reference Include="WindowsBase" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="BaseMap\BaseMapManager.cs" />
+    <Compile Include="BaseMap\FloorMapData.cs" />
+    <Compile Include="BaseMap\FloorMapDataCheck.cs" />
     <Compile Include="ColdRoom\ColdRoomManager.cs" />
     <Compile Include="ColdRoom\ElementsVertexExtension.cs" />
     <Compile Include="ColdRoom\EquipmentItem.cs" />
@@ -195,5 +198,6 @@
   <ItemGroup>
     <Content Include="RelationType\read.txt" />
   </ItemGroup>
+  <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>

+ 1 - 1
MBI/SAGA.GplotRelationComputerManage/SystemRelation/Common/SystemCalcUtil.cs

@@ -144,7 +144,7 @@ namespace SAGA.GplotRelationComputerManage
                 foreach (var jobject in equipDatas)
                 {
                     var item = MBIItemFactory.Create<MBIEquipItem>(jobject);
-                    if (item != null && string.IsNullOrWhiteSpace(item.BimId))
+                    if (item != null && !string.IsNullOrWhiteSpace(item.BimId))
                     {
                         equipmentItems[item.BimId]= item;
                     }

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

@@ -531,6 +531,7 @@ namespace SAGA.GplotRelationComputerManage
                     SystemCurveItem curveItem = new SystemCurveItem();
                     curveItem.Points.Add(line.StartPoint);
                     curveItem.Points.Add(line.EndPoint);
+                    curveItems.Add(curveItem);
                     continue;
                 }
                 if (element is TText text)

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

@@ -49,7 +49,46 @@ namespace SAGA.GplotRelationComputerManage
         {
             return From.IsRealEquipment && To.IsRealEquipment;
         }
+        /// <summary>
+        /// 获取指定条件的Node
+        /// </summary>
+        /// <param name="match"></param>
+        /// <param name="node"></param>
+        /// <returns>-1表示没有,0,From;1,To</returns>
+        public int TryGetNode(Predicate<EquipmentNode> match, out EquipmentNode node)
+        {
+            node = null;
+            var list = new List<EquipmentNode>() {From, To};
+            for (int i = 0; i < list.Count; i++)
+            {
+                if (match(From))
+                {
+                    node = From;
+                    return i;
+                }
+            }
+
+            return -1;
+        }
+        /// <summary>
+        /// 获取匹配元素之外的另一个节点
+        /// </summary>
+        /// <param name="match"></param>
+        /// <returns></returns>
+        public EquipmentNode GetAnotherNode(Predicate<EquipmentNode> match)
+        {
+            //只有有一个相等,才称得上另一个
+            var list = new List<EquipmentNode>() { From, To };
+            for (int i = 0; i < list.Count; i++)
+            {
+                if (match(From))
+                {
+                    
+                    return list[i%2];
+                }
+            }
+            return null;
+        }
 
-       
     }
 }

+ 11 - 1
MBI/SAGA.GplotRelationComputerManage/SystemRelation/FloorSystemItem.cs

@@ -592,9 +592,19 @@ namespace SAGA.GplotRelationComputerManage
         private EquipmentNode ConverEquipmentNode(EquipmentItem item, SystemComputerContext context)
         {
             EquipmentNode result = new EquipmentNode();
+            result.IsRealEquipment = !item.IsVirtual;
             result.RevitId = item.Id;
             result.BimId = CreateBimId(result.RevitId);
-            result.MbiId = context.EquipmentItems.GetItem(result.BimId)?.Id ?? string.Empty;
+            var equipment = context.EquipmentItems.GetItem(result.BimId);
+            if (equipment != null)
+            {
+                result.MbiId = equipment.Id ?? string.Empty;
+                result.Category = equipment.Category;
+            }
+            else
+            {
+                result.Category = MBIInfoUtil.GetEquipmentCategory(item.Name) ?? string.Empty;
+            }
             return result;
         }
         #endregion 解析机房数据

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

@@ -23,12 +23,15 @@ namespace SAGA.GplotRelationComputerManage
         /// <param name="context"></param>
         public void Computer(SystemComputerContext context)
         {
+            List<string> testFiles = new List<string>();
+            testFiles.Add("Fl420105000119b7c08edcee11e8a553abe8a598be93.rvt");
+            testFiles.Add("Fl4201050001d4f1ea8fdce711e8a55335c5dd75d7b3.rvt");
             var fileInfos = RevitModelPath.GetAllRevitFiles();
             foreach (var fileInfo in fileInfos)
             {
                 if (File.Exists(fileInfo))
                 {
-                    if (!fileInfo.Contains("Fl420105000189c43312dce811e8a5530301735c51a0.rvt"))
+                    if (testFiles.All(f=>!fileInfo.Contains(f)))
                     {
                         continue;
                     }

+ 90 - 0
MBI/SAGA.MBI/TestCommand.cs

@@ -332,4 +332,94 @@ namespace SAGA.MBI
             return true;
         }
     }
+
+    /// <summary>
+    /// 掉转阀件方向
+    /// </summary>
+    [Transaction(TransactionMode.Manual)]
+    [Regeneration(RegenerationOption.Manual)]
+    public class ReDirectionCommand : ExternalCommand
+    {
+        public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
+        {
+            using (Transaction tran = new Transaction(ExternalDataWrapper.Current.Doc, "调整阀门"))
+            {
+                tran.Start();
+                try
+                {
+                    var pickElement = ExternalDataWrapper.Current.UiApp.PickElement("请选择阀件", typeof(FamilyInstance)) as FamilyInstance;
+                    if (pickElement == null)
+                    {
+                        return Result.Succeeded;
+                    }
+
+                    var handling = pickElement.HandOrientation;
+                    var facing = pickElement.FacingOrientation;
+                    var location = pickElement.GetLocationPoint();
+                    var axis = location.NewLine(location + handling.CrossProduct(facing));
+                    var connectors = pickElement.GetAllConnectors();
+                    List<Connector> refConnectors = new List<Connector>();
+                    foreach (var connector in connectors)
+                    {
+                        if (!ConnectorType.Physical.HasFlag(connector.ConnectorType))
+                        {
+                            continue;
+                        }
+                        var tempRefs = connector.GetReferenceConnectors();
+                        foreach (var tempRef in tempRefs)
+                        {
+                            if (ConnectorType.Physical.HasFlag(tempRef.ConnectorType)&& tempRef.IsConnectedTo(connector))
+                            {
+                                connector.DisconnectFrom(tempRef);
+
+                                refConnectors.Add(tempRef);
+                            }
+                        }
+
+                    }
+
+                    ElementTransformUtils.RotateElement(pickElement.Document, pickElement.Id, axis, Math.PI);
+                    pickElement.Document.Regenerate();
+                    connectors = pickElement.GetAllConnectors();
+                    for (int i = 0; i < refConnectors.Count; i++)
+                    {
+                        var refCon = refConnectors[i];
+                        if (refCon == null)
+                            continue;
+                        var maxLength = double.MaxValue;
+                        Connector bConnector = null;
+                        foreach (var connector in connectors)
+                        {
+                            var newLength = refCon.Origin.Subtract(connector.Origin).GetLength();
+                            if (newLength < maxLength&&!connector.IsConnected)
+                            {
+                                maxLength = newLength;
+                                bConnector = connector;
+                            }
+                        }
+
+                        if (bConnector != null)
+                        {
+                            bConnector.ConnectTo(refCon);
+                        }
+                    }
+
+                    tran.Commit();
+                }
+                catch (Exception e)
+                {
+                    tran.RollBack();
+                    MessageShow.Show(e);
+                    return Result.Cancelled;
+                }
+            }
+               
+            return Result.Succeeded;
+        }
+
+        public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
+        {
+            return true;
+        }
+    }
 }