瀏覽代碼

xls:立管描述信息提示

xulisong 6 年之前
父節點
當前提交
0ec55dc95a

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

@@ -61,7 +61,8 @@ namespace SAGA.GplotDrawData
                     }
                     VPipe pipe = new VPipe();
                     pipe.LinkId = verData.Id;
-                    pipe.Name = verData.Id;
+                    pipe.Name = verData.Display;
+                    pipe.Tip = verData.DisplayTip;
                     pipe.PipeSystemType = verData.PipeSytemType;
                     pipe.FloorId = floorId;
                     pipes.Add(pipe);

+ 38 - 25
MBI/SAGA.GplotRelationComputerManage/ComputerPipes.cs

@@ -5,22 +5,24 @@
  * ==============================================================================*/
 
 
+using System;
 using SAGA.GplotRelationComputerManage.PumpEnd;
 using SAGA.RevitUtils.Extends;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
-using System.Text.RegularExpressions;
 using Autodesk.Revit.DB.Plumbing;
 using Autodesk.Revit.DB;
+using SAGA.RevitUtils;
+
 namespace SAGA.GplotRelationComputerManage
 {
     public class ComputerPipes
     {
         public static void Computer()
         {
-            //记录立管
-            Dictionary<Level, List<Pipe>> dicVerticalPipes = new Dictionary<Level, List<Pipe>>();
+            //打开所有楼层数据     
+            PipeCalcContext context = new PipeCalcContext();
             var fileInfos = RevitModelPath.GetAllRevitFiles();
             foreach (var fileInfo in fileInfos)
             {
@@ -28,33 +30,44 @@ namespace SAGA.GplotRelationComputerManage
                 {
                     var uiApp = ExternalDataWrapper.Current.UiApp.Application;
                     var doc = uiApp.OpenDocumentFile(fileInfo);
-                    new ExternalDataWrapper(doc);
-                   
-                    List<Pipe> verticalPipe = new List<Pipe>();
-                    //计算水管
-                   DuctTerminalBll.DrawPipePlane(false, verticalPipe);
-                    #region 立管处理
-                    //立管处理,分楼层存储 
-                    var usePlan = doc.GetViewPlan().Where(p => p.Name.Contains("-saga"))?.FirstOrDefault();
-                    var currentLevel = usePlan?.GenLevel;
-                    if (usePlan == null)
+                    if (doc == null)
+                        continue;
+                    try
                     {
-                        currentLevel = verticalPipe.FirstOrDefault()?.ReferenceLevel;
+                        new ExternalDataWrapper(doc);
+                        List<Pipe> verticalPipes = new List<Pipe>();
+                        //计算水管
+                        DuctTerminalBll.DrawPipePlane(false, verticalPipes);
+                        #region 立管处理
+                        ComputerVerticalPipe computerPipes = new ComputerVerticalPipe(doc);
+                        //立管处理,分楼层存储 
+                        var usePlan = doc.GetViewPlan().Where(p => p.Name.Contains("-saga"))?.FirstOrDefault();
+                        var currentLevel = usePlan?.GenLevel;
+                        if (usePlan == null)
+                        {
+                            currentLevel = verticalPipes.FirstOrDefault()?.ReferenceLevel;
+                        }
+                        //楼层必须要有,管道不一定要有
+                        if (currentLevel != null)
+                        {
+                            computerPipes.ComputerVerticalPipes(currentLevel, verticalPipes, context);
+                        }
+                        #endregion
+                        //计算风管
+                        DuctTerminalBll.DrawDuct();
                     }
-                    //楼层必须要有,管道不一定要有
-                    if (currentLevel != null)
+                    catch (System.Exception ex)
                     {
-                        dicVerticalPipes.Add(currentLevel, verticalPipe);
-                    }
 
-                    #endregion
-                    //计算风管
-                    DuctTerminalBll.DrawDuct();
+                        Console.WriteLine(ex.Message);
+                    }
+                    finally
+                    {
+                        doc.Close();
+                    }
                 }
-            }         
-            var pipeComputer = new ComputerVerticalPipe();
-            pipeComputer.Computer(dicVerticalPipes);
+            }
+            ComputerVerticalPipe.Computer(context);
         }
-     
     }
 }

+ 137 - 30
MBI/SAGA.GplotRelationComputerManage/ComputerVerticalPipe.cs

@@ -11,70 +11,177 @@ using SAGA.RevitUtils.Extends;
 using System.Collections.Generic;
 using System.Linq;
 using System.Windows.Media.Media3D;
+using Autodesk.Revit.DB.Mechanical;
+using Newtonsoft.Json.Linq;
+using SAGA.MBI.RequestData;
+using SAGA.RevitUtils;
+
 namespace SAGA.GplotRelationComputerManage
 {
-    public class ComputerVerticalPipe
+    /// <summary>
+    /// 计算上下文
+    /// </summary>
+    public class PipeCalcContext
     {
-        public void Computer(Dictionary<Level, List<Pipe>> dicPipes)
+        public PipeCalcContext()
         {
-            List<VerticalPipe> pipes = new List<VerticalPipe>();
-            foreach (var dicPipe in dicPipes)
+            VerticalPipes = new List<VerticalPipe>();
+            Levels = new List<LevelData>();
+        }
+        #region 空间缓存信息
+        /// <summary>
+        /// 缓存空间对象
+        /// </summary>
+        private Dictionary<string, RoomItem> m_Rooms = null;
+        /// <summary>
+        /// 获取根据指定bimId,获取空间信息
+        /// </summary>
+        /// <param name="bimId"></param>
+        /// <returns></returns>
+        public RoomItem GetRoomItem(string bimId)
+        {
+            if (m_Rooms == null)
             {
-                   var vps = ConvertTo(dicPipe.Key,dicPipe.Value);
-                pipes.AddRange(vps);
+                m_Rooms = new Dictionary<string, RoomItem>();
+                var str = new string[] { MBIBuiltInCategory.Si };//元空间为Si
+                List<JObject> datas = CommonConvert.QueryObjectInfoByTypes(str);
+                foreach (var data in datas)
+                {
+                    var roomItem = MBIItemFactory.Create<RoomItem>(data);
+                    m_Rooms[roomItem.BimId] = roomItem;
+                }
             }
 
-            var levels = dicPipes.Keys.ToList();
-            levels.Sort((l1, l2) => l1.Elevation.CompareTo(l2.Elevation));
-            var levelDatas = levels.Select(t => new LevelData()
-            {
-                Id = t.Id.ToString(),
-                Name = t.Name.Replace("-saga",""),
-                Elevation = t.Elevation
-            }).ToList();
+            m_Rooms.TryGetValue(bimId, out RoomItem resultItem);
+            return resultItem;
+        }
 
 
-            var datas = new VerticalPipeData()
+        #endregion
+        #region 空间缓存约束
+        public string GetSpaceDisplay(Space space)
+        {
+            if (space == null)
+                return string.Empty;
+            string bimId = space.GetBimId();
+            var room = GetRoomItem(bimId);
+            string useName = space.Name;
+            if (room != null&&!string.IsNullOrWhiteSpace(room.LocalName))
             {
-                Datas = pipes,
-                Levels = levelDatas
-            };
+                useName = room.LocalName;
+            }
 
-            //保存数据到本地
-            DrawDataServer.SaveAsFile(datas);
+            //此类缓存所有空间信息
+            //本地名称为null的话要使用Name
+            return useName;
+        }
+        public string GetSpaceDisplay(Space space,out string tip)
+        {
+            tip = string.Empty;
+            if (space == null)
+                return string.Empty;
+            string bimId = space.GetBimId();
+            var room = GetRoomItem(bimId);
+            string useName = space.Name;
+            tip =$"空间模型名称:BIMID编码";
+            if (room != null && !string.IsNullOrWhiteSpace(room.LocalName))
+            {
+                tip = $"空间本地名称:BIMID编码";
+                useName = room.LocalName;
+            }
+
+            //此类缓存所有空间信息
+            //本地名称为null的话要使用Name
+            return useName;
         }
+        #endregion
 
-        private List<VerticalPipe> ConvertTo(Level refLevel,List<Pipe> data)
+        public List<VerticalPipe> VerticalPipes { get; private set; }
+        public List<LevelData> Levels { get; private set; }
+    }
+
+    public class ComputerVerticalPipe
+    {
+        public Document Document { get; private set; }
+        public ComputerVerticalPipe(Document document)
+        {
+            Document = document;
+        }
+        #region 修订函数
+        /// <summary>
+        /// 计算立管信息
+        /// </summary>
+        /// <param name="refLevel"></param>
+        /// <param name="pipes"></param>
+        /// <param name="context"></param>
+        public void ComputerVerticalPipes(Level refLevel, List<Pipe> pipes, PipeCalcContext context)
         {
             var result = new List<VerticalPipe>();
-
-            foreach (var pipe in data)
+            var spaces = Document.GetElements<SpatialElement>(BuiltInCategory.OST_MEPSpaces).OfType<Space>();
+            foreach (var pipe in pipes)
             {
-                var level =refLevel;
-
+                if (pipe == null)
+                    continue;
+                var level = refLevel;
                 var vp = new VerticalPipe
                 {
-                    Id = pipe.Id.IntegerValue.ToString(),
-                    LevelName = level.Name.Replace("-saga",""),
+                    Id=pipe.Id.IntegerValue.ToString(),
+                    LevelName = level.Name.Replace("-saga", ""),
                     LevelElevation = level.Elevation,
                     UpPoint3D = Convert3DToWin(pipe.GetVerticalTopPoint()),
                     DownPoint3D = Convert3DToWin(pipe.GetVerticalBottomPoint()),
                     PipeSytemType = pipe.GetParameterString(BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM)
                 };
+                //获取立管关联控件
+                var locationCurve = pipe.GetLocationCurve();
+                var midPoint = (locationCurve.StartPoint() + locationCurve.EndPoint()) / 2;
+                Space refSpace = spaces.FirstOrDefault(s => s.IsPointInSpace(midPoint));//关联
+                var display = context.GetSpaceDisplay(refSpace, out string tip);
+                vp.Display = $"{display}:{pipe.Id.IntegerValue.ToString()}";
+                vp.DisplayTip = tip ?? string.Empty;
                 result.Add(vp);
             }
+            LevelData levelData = new LevelData()
+            {
+                Id = refLevel.Id.ToString(),
+                Name = refLevel.Name.Replace("-saga", ""),
+                Elevation = refLevel.Elevation
+            };
+            context.VerticalPipes.AddRange(result);
+            context.Levels.Add(levelData);
+        }
 
-            return result;
+        /// <summary>
+        /// 计算整体信息
+        /// </summary>
+        /// <param name="context"></param>
+        public static void Computer(PipeCalcContext context)
+        {
+            var verticalPipes = context.VerticalPipes;
+            if (verticalPipes == null)
+                return;
+            List<VerticalPipe> pipes = new List<VerticalPipe>(verticalPipes);
+            var levels = new List<LevelData>(context.Levels);
+            levels.Sort((l1, l2) => l1.Elevation.CompareTo(l2.Elevation));
+
+            var datas = new VerticalPipeData()
+            {
+                Datas = pipes,
+                Levels = levels
+            };
+            //保存数据到本地
+            DrawDataServer.SaveAsFile(datas);
         }
+        #endregion
 
 
 
-        Point3D Convert3DToWin(XYZ xyz)
+        private static Point3D Convert3DToWin(XYZ xyz)
         {
             return new Point3D(xyz.X, xyz.Y, xyz.Z);
         }
 
-        XYZ Convert3DToRevit(Point3D point)
+        private static XYZ Convert3DToRevit(Point3D point)
         {
             return new XYZ(point.X, point.Y, point.Z);
         }

+ 3 - 1
MBI/SAGA.GplotRelationComputerManage/ReadSpaceCommand.cs

@@ -11,6 +11,7 @@ using SAGA.DotNetUtils.Extend;
 using SAGA.MBI.DataArrange;
 using SAGA.MBI.Model;
 using SAGA.MBI.RequestData;
+using SAGA.MBI.Tools;
 using SAGA.Models;
 using SAGA.RevitUtils;
 using SAGA.RevitUtils.Extends;
@@ -108,7 +109,8 @@ namespace SAGA.GplotRelationComputerManage
                    // var doc = uiApp.OpenDocumentFile(fileInfo);
                     FloorSpaceItems floorItems = context.GetFloorItems(fileInfo);
                     floorItems.Parse(context);
-                    floorItems.Document.Close();
+                    //if(floorItems.Document.Application.Creat)
+                    floorItems.Document.CloseDocSimple();
                     //ComputerSpace(doc);
                 }
             }

+ 20 - 0
MBI/SAGA.MBI/Extend/DocExtend.cs

@@ -80,6 +80,26 @@ namespace SAGA.MBI.Tools
             Element elem = null;
             return CloseDoc(doc.PathName);
         }
+        /// <summary>
+        /// 简单关闭模型不保存
+        /// </summary>
+        /// <param name="doc"></param>
+        /// <returns></returns>
+        public static bool CloseDocSimple(this Document doc)
+        {
+            bool result = true;
+            var basePath = doc.PathName;
+            var uiApp = ExternalDataWrapper.Current.UiApp;
+            if (uiApp.ActiveUIDocument != null && uiApp.ActiveUIDocument.Document.PathName == basePath)
+            {
+                result= false;
+            }
+            else
+            {
+                result= doc.Close();
+            }
+            return result;
+        }
 
         /// <summary>
         /// 获取当前层的MFloor对象

+ 1 - 0
MBI/SAGA.MBI/Interaction/MBILocalNameTrigger.cs

@@ -41,6 +41,7 @@ namespace SAGA.MBI.Interaction
 
         protected override RevitUpdater GetUpdater()
         {
+            //当触发器返回空时,自动不进行属性监控
             var  addInId= RevitEventsBingding.CurrentApp.ActiveAddInId;
             RevitUpdater updaer = new RevitUpdater(new UpdaterId(addInId, GUID), (data) =>
             {

+ 5 - 0
MBI/SAGA.Models/Graphs/VElements/GVElement.cs

@@ -20,5 +20,10 @@ namespace SAGA.Models.Graphs
         /// 楼层信息
         /// </summary>
         public string FloorId { get; set; }
+
+        /// <summary>
+        /// 描述信息
+        /// </summary>
+        public string Tip { get; set; }
     }
 }

+ 2 - 0
MBI/SAGA.Models/VerticalPipe.cs

@@ -21,6 +21,8 @@ namespace SAGA.Models
 
         public Point CPoint { get; set; }
         public string PipeSytemType { get; set; }
+        public string Display { get; set; }
+        public string DisplayTip { get; set; }
     }
     [TableName("VerticalPipeDatass")]
     public class VerticalPipeData