Просмотр исходного кода

xls:增加普通FamilyInstance,拥有连接件的解析对象

xulisong 5 лет назад
Родитель
Сommit
d80e1408d5

+ 23 - 0
JBIM/JBIM/Component/Column.cs

@@ -0,0 +1,23 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:Column
+ * 作者:xulisong
+ * 创建时间: 2019/6/24 9:26:43
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using JBIM.Common;
+using JBIM.Definition;
+
+namespace JBIM.Component
+{
+    [TypeDefiniton(TypeDefinition.Column)]
+    public class Column : VisibleComponentObject
+    {
+        //是否加上,建筑结构,是否是房间判断等枚举
+    }
+}

+ 30 - 0
JBIM/JBIM/Component/OtherJoinObject.cs

@@ -0,0 +1,30 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:OtherJoinObject
+ * 作者:xulisong
+ * 创建时间: 2019/6/24 9:25:47
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using JBIM.Common;
+using JBIM.Definition;
+
+namespace JBIM.Component
+{
+    [TypeDefiniton(TypeDefinition.Other)]
+    public class OtherJoinObject : VisibleComponentObject
+    {
+        public OtherJoinObject()
+        {
+            ConnectedIds = new List<BimId>();
+        }
+        /// <summary>
+        /// Connector连接的connectorIds
+        /// </summary>
+        public List<BimId> ConnectedIds { get; private set; }
+    }
+}

+ 2 - 0
JBIM/JBIM/Definition/TypeDefinition.cs

@@ -41,6 +41,8 @@ namespace JBIM.Definition
         EquipPart,
         [Description("Column")]
         Column,
+        [Description("Other")]
+        Other,
         #region 关系类型相关
         [Description("Relationship")]
         Relationship = -25000,

+ 2 - 0
JBIM/JBIM/JBIM.csproj

@@ -60,11 +60,13 @@
     <Compile Include="Common\TypeDefinitonAttribute.cs" />
     <Compile Include="Common\TypeDefinitonUtil.cs" />
     <Compile Include="Component\BoundarySegment.cs" />
+    <Compile Include="Component\Column.cs" />
     <Compile Include="Component\ComponentObject.cs" />
     <Compile Include="Component\Connector.cs" />
     <Compile Include="Component\Duct.cs" />
     <Compile Include="Component\MepSystem.cs" />
     <Compile Include="Component\MepSystemType.cs" />
+    <Compile Include="Component\OtherJoinObject.cs" />
     <Compile Include="Component\Pipe.cs" />
     <Compile Include="Component\Space.cs" />
     <Compile Include="Component\VisibleComponentObject.cs" />

+ 26 - 0
JBIM/RevitToJBim/Common/CategoryGenerator.cs

@@ -0,0 +1,26 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:ElementWrapperGenerator
+ * 作者:xulisong
+ * 创建时间: 2019/6/24 9:03:15
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace RevitToJBim.Common
+{
+    /// <summary>
+    /// 构件分类生成器
+    /// </summary>
+    public static class CategoryGenerator
+    {
+        public static string BuildingCategory(Enum e)
+        {
+            return $"{e.GetType()}.{e}";
+        }
+    }
+}

+ 99 - 0
JBIM/RevitToJBim/Common/ElementWrapperFactory.cs

@@ -0,0 +1,99 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:ElementWrapperFactory
+ * 作者:xulisong
+ * 创建时间: 2019/6/24 8:44:46
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+using RevitExport;
+using RevitExport.Export;
+using SAGA.RevitUtils.Extends;
+using SAGA.RevitUtils.MEP;
+
+namespace RevitToJBim.Common
+{
+    /// <summary>
+    /// 解析对象创建工厂
+    /// </summary>
+    public class ElementWrapperFactory
+    {
+        /// <summary>
+        /// 根据element创建带分类对象的解析信息。便于快速过滤
+        /// </summary>
+        /// <param name="element"></param>
+        /// <returns></returns>
+        public static ElementWrapper CreateWrapper(Element element)
+        {
+            if (element is FamilyInstance fi)
+            {
+                CreateWrapper(fi);
+            }
+            return new ElementWrapper(element);
+        }
+        /// <summary>
+        /// 创建FamilyInstance的wrapper
+        /// </summary>
+        /// <param name="familyInstance"></param>
+        /// <returns></returns>
+        public static ElementWrapper CreateWrapper(FamilyInstance familyInstance)
+        {
+            var useFamilyType = FamilyType.Undefine;
+            var category = familyInstance.Category;          
+            if (category != null)
+            {
+                var enumValue = (BuiltInCategory)category.Id.IntegerValue;
+                #region category转换
+                switch (enumValue)
+                {
+                    case BuiltInCategory.OST_Doors:
+                        {
+                            useFamilyType = FamilyType.Door;
+                            break;
+                        }
+                    case BuiltInCategory.OST_Windows:
+                        {
+                            useFamilyType = FamilyType.Window;
+                            break;
+                        }
+                    case BuiltInCategory.OST_Columns:
+                        {
+                            useFamilyType = FamilyType.Column;
+                            break;
+                        }
+                } 
+                #endregion
+            }
+
+            if (useFamilyType == FamilyType.Undefine)
+            {
+                //判断部件和设备
+                var family = familyInstance.GetFamily();
+                ///todo
+            }
+            if (useFamilyType == FamilyType.Undefine)
+            {
+                var connectors = familyInstance.GetAllConnectors();
+                if (connectors.Any(c => c.Domain == Domain.DomainHvac || c.Domain == Domain.DomainPiping))
+                {
+                    useFamilyType = FamilyType.Other;
+                }
+            }
+
+            if (useFamilyType == FamilyType.Undefine)
+            {
+                return null;
+            }
+
+            ElementWrapper wrapper = new ElementWrapper(familyInstance);
+            wrapper.Category = CategoryGenerator.BuildingCategory(useFamilyType);
+            return wrapper;
+
+        }
+    }
+}

+ 30 - 0
JBIM/RevitToJBim/Common/FamilyType.cs

@@ -0,0 +1,30 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:FamilyType
+ * 作者:xulisong
+ * 创建时间: 2019/6/24 8:50:06
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace RevitToJBim.Common
+{
+    /// <summary>
+    /// family构件类型
+    /// </summary>
+    public enum FamilyType
+    {
+        Undefine,
+        Equipment,
+        EquipPart,
+        Window,
+        Door,
+        Column,
+        Other,
+
+    }
+}

+ 1 - 1
JBIM/RevitToJBim/ComponentParse/ParseConnector.cs

@@ -72,7 +72,7 @@ namespace RevitToJBim.ComponentParse
             //这里只维护关联,不进行递归
             var refConnectors = connector.GetReferenceConnectors();
             ElementOneToManyRel relMany = new ElementOneToManyRel(connectorId){RelatedObjects=new List<string>()};
-            relMany.SetElementType(TypeDefinition.Property_MepSystem);
+            relMany.SetElementType(TypeDefinition.Property_ConnectedIds);
             foreach (var refConnector in refConnectors)
             {
                 relMany.RelatedObjects.Add(RevitIdGenerator.GetConnectorId(refConnector));

+ 79 - 0
JBIM/RevitToJBim/ComponentParse/ParseFamilyJoinObject.cs

@@ -0,0 +1,79 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:ParseFamilyJoinObject
+ * 作者:xulisong
+ * 创建时间: 2019/6/24 9:29:00
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+using JBIM;
+using JBIM.Component;
+using JBIM.Definition;
+using RevitExport.Export;
+using RevitToJBim.Common;
+using JFamilyType=RevitToJBim.Common.FamilyType;
+using RevitToJBim.ParseData;
+using SAGA.RevitUtils.MEP;
+
+namespace RevitToJBim.ComponentParse
+{
+    [UsableParse]
+    public class ParseFamilyJoinObject : ParseBase
+    {
+        public override List<string> FastIndex()
+        {
+            return new List<string>() { CategoryGenerator .BuildingCategory(JFamilyType.Other)};
+        }
+        public override bool Match(ElementWrapper wrapper)
+        {
+            return wrapper.Category == CategoryGenerator.BuildingCategory(JFamilyType.Other);
+        }
+
+        protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
+        {
+            if (!(wrapper.RefElement is FamilyInstance familyInstance))
+            {
+                return null;
+            }
+            OtherJoinObject jObject = new OtherJoinObject();
+            ParseCore.AttachObject(jObject, wrapper);
+            context.AddBimObject(jObject);
+            #region Connector连接关系
+            var connectors = familyInstance.GetAllConnectors();
+            ElementOneToManyRel relMany = new ElementOneToManyRel(familyInstance.Id.ToString()) { RelatedObjects = new List<string>() };
+            relMany.SetElementType(TypeDefinition.Property_ConnectedIds);
+            foreach (var refConnector in connectors)
+            {
+                relMany.RelatedObjects.Add(RevitIdGenerator.GetConnectorId(refConnector));
+            }
+
+            if (relMany.RelatedObjects.Any())
+            {
+                context.RelationShips.Add(relMany);
+            }
+            #endregion
+            return new List<BimId>() { jObject.Id };
+        }
+
+        public override List<ElementWrapper> ArrangeRefElements(ElementWrapper wrapper, JBimParseContext context)
+        {
+            if (!(wrapper.RefElement is FamilyInstance fi))
+            {
+                return null;
+            }
+
+            var wrappers = new List<ElementWrapper>() { };
+            var connectors = fi.GetAllConnectors();
+            foreach (var connector in connectors)
+            {
+                wrappers.Add(ParseCore.GetConnectorWrapper(connector));
+            }
+            return wrappers;
+        }
+    }
+}

+ 4 - 0
JBIM/RevitToJBim/RevitToJBim.csproj

@@ -59,13 +59,17 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Common\CategoryGenerator.cs" />
     <Compile Include="Common\Converter.cs" />
+    <Compile Include="Common\ElementWrapperFactory.cs" />
     <Compile Include="Common\ExceptionUtil.cs" />
+    <Compile Include="Common\FamilyType.cs" />
     <Compile Include="Common\RevitIdGenerator.cs" />
     <Compile Include="ComponentParse\ParseBase.cs" />
     <Compile Include="ComponentParse\ParseConnector.cs" />
     <Compile Include="ComponentParse\ParseCore.cs" />
     <Compile Include="ComponentParse\ParseDuct.cs" />
+    <Compile Include="ComponentParse\ParseFamilyJoinObject.cs" />
     <Compile Include="ComponentParse\ParseMepSystem.cs" />
     <Compile Include="ComponentParse\ParsePipe.cs" />
     <Compile Include="ComponentParse\ParseSpace.cs" />