Parcourir la source

xls:增加空间安层解析

xulisong il y a 6 ans
Parent
commit
4c6a6e0dd1

BIN
MBI/Dlls/FirmLibDll/FWindSoft.Wpf.dll


BIN
MBI/Dlls/FirmLibDll/FWindSoft.Wpf.pdb


BIN
MBI/Dlls/FirmLibDll/FWindSoft.dll


BIN
MBI/Dlls/FirmLibDll/FWindSoft.pdb


+ 2 - 33
MBI/SAGA.GplotRelationComputerManage/ReadSpaceCommand.cs

@@ -4,7 +4,6 @@ using System.Diagnostics;
 using System.IO;
 using System.Linq;
 using System.Text.RegularExpressions;
-using System.Threading;
 using Autodesk.Revit.DB;
 using Autodesk.Revit.DB.Mechanical;
 using Newtonsoft.Json.Linq;
@@ -179,8 +178,7 @@ namespace SAGA.GplotRelationComputerManage
                 if (jo != null)
                 {
                     localName = GetValue(jo, "RoomLocalName");
-                    spaceType=GetValue(jo, "RoomFuncType");
-                  
+                    spaceType=GetValue(jo, "RoomFuncType");                
                 }
                
                 sgSpace = new SgSpace()
@@ -353,7 +351,6 @@ namespace SAGA.GplotRelationComputerManage
             var datas = eleDatas.ToDictionary(t => t.Key, t => t.ToList()).ToList();
             for (int i = datas.Count - 1; i >= 0; i--)
             {
-                i = Math.Min(datas.Count-1, i);
                 var d1 = datas[i];
                 var e1 = d1.Value.FirstOrDefault().EdgeElement;
 
@@ -442,7 +439,6 @@ namespace SAGA.GplotRelationComputerManage
 
             return Line.CreateBound(startPoint, endPoint);
         }
-
         /// <summary>
         /// 判断当前两个空间是否有门窗
         /// </summary>
@@ -477,34 +473,7 @@ namespace SAGA.GplotRelationComputerManage
             return spaceRelated;
         }
 
-        /// <summary>
-        /// 判断当前两个空间是否有门窗
-        /// </summary>
-        /// <param name="wall"></param>
-        /// <param name="curve1"></param>
-        /// <param name="curve2"></param>
-        /// <returns></returns>
-        private FamilyInstance JudgeIsHaveDoor(Element wall, Curve curve1, Curve curve2)
-        {
-            var wallId = wall.Id;
-            var wallWidth = (wall as Wall)?.WallType.Width;
-
-            var z = curve1.StartPoint().Z;
-
-            var doors = m_doors.Where(t => t.Host.Id.IsEqual(wallId));
-
-            Predicate<XYZ> isHost = (point) =>
-            {
-                point = point.NewZ(z);
-                //向两个线上做投影
-                var point1 = curve1.GetProjectPt(point, false);
-                var point2 = curve2.GetProjectPt(point, false);
-                //定位点到两个投影的必须小于墙厚
-                return (point - point1).GetLength() < wallWidth && (point - point2).GetLength() < wallWidth;
-            };
-
-            return doors.FirstOrDefault(t => isHost(t.GetLocationPoint()));
-        }
+       
 
 
         /// <summary>

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

@@ -30,6 +30,10 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="FWindSoft, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\Dlls\FirmLibDll\FWindSoft.dll</HintPath>
+    </Reference>
     <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
       <HintPath>..\Dlls\Newtonsoft.Json.dll</HintPath>
@@ -104,6 +108,7 @@
     <Compile Include="RevitSystemParse\Handler\SystemParseSetting.cs" />
     <Compile Include="RevitSystemParse\StartElementsManager.cs" />
     <Compile Include="SpaceEdgeInfo.cs" />
+    <Compile Include="SpaceRelation\FloorSpaceItems.cs" />
     <Compile Include="SpaceRelation\SpaceComputerContext.cs" />
     <Compile Include="SpaceRelation\SpaceComputerHandler.cs" />
     <Compile Include="SpaceRelation\SpaceComputerManager.cs" />

+ 238 - 0
MBI/SAGA.GplotRelationComputerManage/SpaceRelation/FloorSpaceItems.cs

@@ -0,0 +1,238 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:FloorSpaceItems
+ * 作者:xulisong
+ * 创建时间: 2018/12/21 14:41:27
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Autodesk.Revit.DB;
+using Autodesk.Revit.DB.Mechanical;
+using FWindSoft.Data;
+using SAGA.DotNetUtils.Extend;
+using SAGA.RevitUtils.Extends;
+
+namespace SAGA.GplotRelationComputerManage.SpaceRelation
+{
+    /// <summary>
+    ///模型解析对应的楼层空间数据
+    /// </summary>
+    public  class FloorSpaceItems
+    {
+        #region 构造函数
+        /// <summary>
+        /// 初始化解析类
+        /// </summary>
+        /// <param name="doc"></param>
+        public FloorSpaceItems(Document doc)
+        {
+            Document = doc;
+            Doors = new List<FamilyInstance>();
+            Windows = new List<FamilyInstance>();
+            Spaces = new List<Space>();
+        } 
+        #endregion
+
+        #region 属性相关
+        /// <summary>
+        /// 关联模型信息
+        /// </summary>
+        public Document Document { get; private set; }
+        /// <summary>
+        /// 关联门信息
+        /// </summary>
+        public List<FamilyInstance> Doors { get; private set; }
+        /// <summary>
+        /// 关联窗体信息
+        /// </summary>
+        public List<FamilyInstance> Windows { get; private set; }
+        /// <summary>
+        /// 关联空间信息
+        /// </summary>
+        public List<Space> Spaces { get; private set; } 
+        #endregion
+
+        /// <summary>
+        /// 解析
+        /// </summary>
+        public void Parse()
+        {
+            var doc = Document;
+            Doors = doc.GetElements<FamilyInstance>(BuiltInCategory.OST_Doors);
+            Windows = doc.GetElements<FamilyInstance>(BuiltInCategory.OST_Windows);
+            Spaces = doc.GetElements<SpatialElement>(BuiltInCategory.OST_MEPSpaces).OfType<Space>().ToList();
+            //展开空间关系数据
+            var flatSpaceItems = FlatSpaceEdges(Spaces);
+            var groupSpaces = flatSpaceItems.GroupBy(t => t.EdgeElement.Id.IntegerValue).ToList();
+            var relation = CalcCombineRelations(groupSpaces.ToList().Select(g=>g.Key).ToList());
+        }
+
+        #region 展开空间与边界的关联关系
+        /// <summary>
+        /// 展开空间与边的关系
+        /// </summary>
+        /// <param name="spaces"></param>
+        /// <returns></returns>
+        private List<SpaceEdgeInfo> FlatSpaceEdges(List<Space> spaces)
+        {
+            var lSpaces = new List<SpaceEdgeInfo>();
+            Document doc = Document;
+            foreach (var space in spaces)
+            {
+                IList<IList<BoundarySegment>> segments = space.GetBoundarySegments(new SpatialElementBoundaryOptions());
+                foreach (IList<BoundarySegment> boundarySegments in segments)
+                {
+                    foreach (var segment in boundarySegments)
+                    {
+                        //去除不能构成边的元素
+                        if (segment.ElementId.IntegerValue != -1)
+                        {
+                            Curve wallLine = null;
+                            var elem = doc.GetElement(segment.ElementId);
+                            var type = typeof(object);
+                            //这里只处理墙和分隔符,跨长度处理
+                            #region 增加关系对象
+                            if (elem is Wall wall)
+                            {
+                                wallLine = wall.Location.GetCurve();
+                                type = typeof(Wall);
+                            }
+                            else if (elem is ModelCurve modelCurve)
+                            {
+                                wallLine = modelCurve.GetCurve();
+                                type = typeof(ModelCurve);
+                            }
+                            else
+                            {
+                                continue;
+                            }
+                            Curve segCurve1 = segment.GetCurve();
+                            lSpaces.Add(new SpaceEdgeInfo()
+                            {
+                                Space = space,
+                                Edge = wallLine,
+                                SegEdge = segCurve1,
+                                EdgeElement = elem,
+                                EType = type
+                            });
+                            #endregion
+                        }
+                    }
+                }
+            }
+            return lSpaces;
+        } 
+        #endregion
+
+        #region 构件合并整合
+        /*
+        * 1、合并间距较小的构件看成一个构件关系
+        * 2、可合并构件关系为两两关系,且关系不支持传递。如a->b,b->c 不能推导出 a->c
+         * 3、在计算空间关系时,动态关联上相关id去计算空间关系
+        */
+        /// <summary>
+        /// 计算可合并关联
+        /// </summary>
+        /// <param name="ids"></param>
+        private BinaryRelationCollection<int> CalcCombineRelations(List<int> ids)
+        {
+            BinaryRelationCollection<int> relations = new BinaryRelationCollection<int>(false);
+            if (!ids.Any() || ids.Count < 2)
+                return relations;
+            var doc = Document;
+            FilteredElementCollector collectors =
+                new FilteredElementCollector(doc, ids.Select(id => new ElementId(id)).ToList());
+            var calcElements = collectors.ToElements();
+            Dictionary<int, ElementGraphicItem> tempItems = new Dictionary<int, ElementGraphicItem>();
+            for (int i = 0; i < calcElements.Count; i++)
+            {
+                var outElement = calcElements[i];
+                var outItem = GetGraphicItem(tempItems, outElement);
+                if (outItem == null)
+                {
+                    continue;
+                }
+                #region 内部循环
+                for (int j = i + 1; j < calcElements.Count; j++)
+                {
+                    var inElement = calcElements[j];
+                    var inItem = GetGraphicItem(tempItems, inElement);
+                    if (inItem == null)
+                    {
+                        continue;
+                    }
+                    if (outItem.Location.IsParallel(inItem.Location)) //平行
+                    {
+                        //间距小于两个厚度之和的一半
+                        var basePoint = outItem.Location.StartPoint();
+                        var project = inItem.Location.GetProjectPt(basePoint);
+                        var length = (basePoint - project).GetLength();
+                        if (((outItem.Width + inItem.Width) / 2.0d).IsThanEq(length))
+                        {
+                            relations.Add(new BinaryRelationItem<int>(outElement.Id.IntegerValue,
+                                outElement.Id.IntegerValue));
+                        }
+                    }
+                    #endregion
+                }
+            }
+
+            return relations;
+        }
+
+        private ElementGraphicItem GetGraphicItem(Dictionary<int, ElementGraphicItem> dic, Element ele)
+        {
+            if (dic.TryGetValue(ele.Id.IntegerValue, out ElementGraphicItem item))
+            {
+                return item;
+            }
+
+            item = ElementGraphicItem.CreateItem(ele);
+            if (item != null)
+            {
+                dic[ele.Id.IntegerValue] = item;
+            }
+            return item;
+        }
+
+        /// <summary>
+        /// 元素集合条目【内部算法使用】
+        /// </summary>
+        private class ElementGraphicItem
+        {
+            /// <summary>
+            /// 位置
+            /// </summary>
+            public Line Location { get; set; }
+            /// <summary>
+            /// 宽度
+            /// </summary>
+            public double Width { get; set; }
+            /// <summary>
+            /// 创建几何使用Item.
+            /// </summary>
+            /// <param name="element"></param>
+            /// <returns></returns>
+            public static ElementGraphicItem CreateItem(Element element)
+            {
+                double width = 0;
+                if (element is Wall wall)
+                {
+                    width = wall.WallType.GetParameterDouble(BuiltInParameter.WALL_ATTR_WIDTH_PARAM);
+                }
+
+                Line line= element.GetLocationCurve().GetLine();
+                if (line != null)
+                {
+                    return new ElementGraphicItem() {Width = width, Location = line};
+                }
+                return null;
+            }
+        }
+
+        #endregion
+    }
+}

+ 0 - 1
MBI/SAGA.GplotRelationComputerManage/SpaceRelation/SpaceComputerContext.cs

@@ -45,7 +45,6 @@ namespace SAGA.GplotRelationComputerManage
             m_Rooms.TryGetValue(bimId, out RoomItem resultItem);
             return resultItem;
         }
-
         #endregion
     }
 }